Path: blob/main/crypto/krb5/src/windows/leash/MainFrm.cpp
34914 views
// **************************************************************************************1// File: MainFrm.cpp2// By: Arthur David Leather3// Created: 12/02/984// Copyright @1998 Massachusetts Institute of Technology - All rights reserved.5// Description: CPP file for MainFrm.h. Contains variables and functions6// for Leash7//8// History:9//10// MM/DD/YY Inits Description of Change11// 12/02/98 ADL Original12// **************************************************************************************131415#include "stdafx.h"16#include "LeashUIApplication.h"17#include "Leash.h"18#include "MainFrm.h"19#include "lglobals.h"20//#include "KrbRealmHostMaintenance.h"2122#ifdef _DEBUG23#define new DEBUG_NEW24#undef THIS_FILE25static char THIS_FILE[] = __FILE__;26#endif2728/////////////////////////////////////////////////////////////////////////////29// CMainFrame3031#define MIN_LEFT 17932#define MIN_TOP 6133#define MIN_RIGHT 53034#define MIN_BOTTOM 2803536#ifndef NO_STATUS_BAR37CMFCStatusBar CMainFrame::m_wndStatusBar;38#endif39CMFCToolBar CMainFrame::m_wndToolBar;40CImageList CMainFrame::m_imageList;41CImageList CMainFrame::m_disabledImageList;42BOOL CMainFrame::m_isMinimum;43BOOL CMainFrame::m_isBeingResized;44int CMainFrame::m_whatSide;4546IMPLEMENT_DYNCREATE(CMainFrame, CLeashFrame)4748BEGIN_MESSAGE_MAP(CMainFrame, CLeashFrame)49//{{AFX_MSG_MAP(CMainFrame)50ON_WM_CREATE()51ON_WM_SIZING()52ON_WM_CLOSE()53ON_WM_GETMINMAXINFO()54ON_COMMAND(ID_APP_EXIT, OnClose)55//}}AFX_MSG_MAP56// Global help commands57ON_COMMAND(ID_HELP_LEASH_, CMainFrame::OnHelpFinder)58ON_COMMAND(ID_HELP, CMainFrame::OnHelp)59ON_COMMAND(ID_CONTEXT_HELP, CMainFrame::OnContextHelp)60ON_MESSAGE_VOID(WM_RIBBON_RESIZE, OnRibbonResize)61END_MESSAGE_MAP()6263static UINT indicators[] =64{65ID_SEPARATOR, // status line indicator66ID_SEPARATOR,67ID_SEPARATOR,68ID_SEPARATOR69};707172/////////////////////////////////////////////////////////////////////////////73// CMainFrame construction/destruction7475CMainFrame::CMainFrame()76{77m_winRectLeft = 0;78m_winRectTop = 0;79m_winRectRight = 0;80m_winRectBottom = 0;81m_whatSide = RESET_MINSIZE;82m_isMinimum = FALSE;83m_isBeingResized = FALSE;84m_bOwnerCreated = FALSE;85pApplication = NULL;86}8788CMainFrame::~CMainFrame()89{90}9192int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)93{94if (CLeashApp::m_useRibbon) {95HWND hwnd;96HRESULT hr;97// Fixup tooltips (cribbed from http://social.msdn.microsoft.com/Forums/en/vcmfcatl/thread/5c5b4879-d278-4d79-8894-99e7f9b322df)9899CMFCToolTipInfo ttParams;100ttParams.m_bVislManagerTheme = TRUE;101ttParams.m_bVislManagerTheme = FALSE;102ttParams.m_bDrawSeparator = FALSE;103ttParams.m_clrFillGradient = afxGlobalData.clrBarFace;104ttParams.m_clrFill = RGB(255, 255, 255);105ttParams.m_clrBorder = afxGlobalData.clrBarShadow;106ttParams.m_clrText = afxGlobalData.clrBarText;107108theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,109RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);110111CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7));112CDockingManager::SetDockingMode(DT_SMART);113m_wndRibbonBar.SetWindows7Look(TRUE);114115// Initialize the ribbon, keeping a handle to the IUIApplication116// so that we can query the ribbon height and save space for it117// when calculating our layout.118hwnd = this->GetSafeHwnd();119if (hwnd == NULL)120printf("Failed to get HWND\n");121hr = LeashUIApplication::CreateInstance(&pApplication, hwnd);122if (FAILED(hr)) {123MessageBox("LeashUIApplication::CreateInstance!", "Error", MB_OK);124return -1;125}126}127128if (CLeashFrame::OnCreate(lpCreateStruct) == -1)129return -1;130131ShowWindow(SW_HIDE);132133/* NT4 and NT5 aren't shipped with a version of MFC that supports134// 'CreateEx()' as of 2/1/99135#if _MFC_VER > 0x0421136137if (!m_wndToolBar.CreateEx(this) ||138!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))139{140TRACE0("Failed to create toolbar\n");141return -1; // fail to create142}143144#else145146if (!m_wndToolBar.Create(this) ||147!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))148{149TRACE0("Failed to create toolbar\n");150return -1; // fail to create151}152153#endif154*/155if ((!CLeashApp::m_useRibbon) &&156(!m_wndToolBar.Create(this) ||157!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)))158{159MessageBox("There is problem creating the Leash Toolbar!",160"Error", MB_OK);161TRACE0("Failed to create toolbar\n");162return -1; // fail to create163}164165#ifndef NO_STATUS_BAR166if (!m_wndStatusBar.Create(this) ||167!m_wndStatusBar.SetIndicators(indicators, 3))168{169MessageBox("There is problem creating the Leash Status Bar!",170"Error", MB_OK);171TRACE0("Failed to create status bar\n");172return -1; // fail to create173}174#endif175176177// TODO: Remove this if you don't want tool tips or a resizable toolbar178//m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() |179// CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);180181if (!CLeashApp::m_useRibbon) {182// TODO: Delete these three lines if you don't want the toolbar to183// be dockable184m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);185EnableDocking(CBRS_ALIGN_ANY);186DockPane(&m_wndToolBar);187}188189return 0;190}191192BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)193{194return CLeashFrame::PreTranslateMessage(pMsg);195}196197BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)198{199// Use the specific class name we established earlier200// Remove the Minimize and Maximize buttons201cs.style &= ~WS_MINIMIZEBOX;202cs.style &= ~WS_MAXIMIZEBOX;203// Initialize the extended window style to display a TaskBar entry with WS_EX_APPWINDOW204cs.dwExStyle |= WS_EX_APPWINDOW;205// cs.dwExStyle |= WS_EX_OVERLAPPEDWINDOW ;206cs.lpszClass = _T("LEASH.0WNDCLASS");207cs.lpszName = _T("MIT Kerberos");208209CString strText = AfxGetApp()->GetProfileString(CLeashFrame::s_profileHeading,210CLeashFrame::s_profileRect);211if (!strText.IsEmpty())212{213CRect rect;214215rect.left = atoi((const char*) strText);216rect.top = atoi((const char*) strText + 5);217rect.right = atoi((const char*) strText + 10);218rect.bottom = atoi((const char*) strText + 15);219220cs.x = rect.left;221cs.y = rect.top;222cs.cx = rect.right - rect.left;223cs.cy = rect.bottom - rect.top;224225if ( cs.x < 0 )226cs.x = CW_USEDEFAULT;227if ( cs.y < 0 )228cs.y = CW_USEDEFAULT;229if ( cs.cx <= 0 )230cs.cx = CLeashFrame::s_rectDefault.right;231if ( cs.cy <= 0 )232cs.cy = CLeashFrame::s_rectDefault.bottom;233}234else235{236cs.cx = CLeashFrame::s_rectDefault.right;237cs.cy = CLeashFrame::s_rectDefault.bottom;238cs.y = CW_USEDEFAULT;239cs.x = CW_USEDEFAULT;240}241242// Change the following line to call243// CLeashFrame::PreCreateWindow(cs) if this is an SDI application.244if (!CLeashFrame::PreCreateWindow(cs))245return FALSE;246247// We create a parent window for our application to ensure that248// it has an owner. This way we can disable the TaskBar entry249// by removing the WS_EX_APPWINDOW style later on.250if ( !m_bOwnerCreated )251{252m_bOwnerCreated = m_MainFrameOwner.Create(IDD_FRAMEOWNER);253if ( m_bOwnerCreated )254m_MainFrameOwner.ShowWindow(SW_HIDE);255}256if ( m_bOwnerCreated )257cs.hwndParent = m_MainFrameOwner.GetSafeHwnd();258259return TRUE;260}261262263BOOL CMainFrame::ShowTaskBarButton(BOOL bVisible)264{265if (!m_bOwnerCreated)266return FALSE;267268if (bVisible) {269ShowWindow(SW_HIDE);270ModifyStyleEx(0, WS_EX_APPWINDOW);271ShowWindow(SW_SHOW);272} else {273ShowWindow(SW_HIDE);274ModifyStyleEx(WS_EX_APPWINDOW, 0);275ShowWindow(SW_SHOW);276}277return TRUE;278}279280/////////////////////////////////////////////////////////////////////////////281// CMainFrame diagnostics282283#ifdef _DEBUG284void CMainFrame::AssertValid() const285{286CLeashFrame::AssertValid();287}288289void CMainFrame::Dump(CDumpContext& dc) const290{291CLeashFrame::Dump(dc);292}293294#endif //_DEBUG295296/////////////////////////////////////////////////////////////////////////////297// CMainFrame message handlers298299void CMainFrame::OnResetWindowSize()300{301WINDOWPLACEMENT wndpl;302wndpl.length = sizeof(WINDOWPLACEMENT);303304if (!GetWindowPlacement(&wndpl))305{306MessageBox("There is a problem getting Leash Window size!",307"Error", MB_OK);308return;309}310311wndpl.rcNormalPosition = CLeashFrame::s_rectDefault;312313m_whatSide = SKIP_MINSIZE;314315if (!SetWindowPlacement(&wndpl))316{317MessageBox("There is a problem setting Leash Window size!",318"Error", MB_OK);319}320321m_whatSide = RESET_MINSIZE;322}323324void CMainFrame::OnSizing(UINT fwSide, LPRECT pRect)325{ // Keeps track of Leash window size for function CMainFrame::RecalcLayout326m_winRectLeft = pRect->left;327m_winRectTop = pRect->top;328m_winRectRight = pRect->right;329m_winRectBottom = pRect->bottom;330331if (m_whatSide)332m_whatSide = fwSide;333334CLeashFrame::OnSizing(fwSide, pRect);335}336337void CMainFrame::RecalcLayout(BOOL bNotify)338{ // MINSIZE - Insurance that we have a minimum Leash window size339int width = MIN_RIGHT - MIN_LEFT;340int height = MIN_BOTTOM - MIN_TOP;341LeashUIApplication *leashUI;342RECT border;343border.left = border.right = border.bottom = 0;344// Leave room for the ribbon.345leashUI = static_cast<LeashUIApplication*>(pApplication);346border.top = (leashUI != NULL) ? leashUI->GetRibbonHeight() : 0;347NegotiateBorderSpace(CFrameWnd::borderSet, &border);348349BOOL change = FALSE;350WINDOWPLACEMENT wndpl;351wndpl.length = sizeof(WINDOWPLACEMENT);352353if (!GetWindowPlacement(&wndpl))354{355MessageBox("There is a problem getting Leash Window size!",356"Error", MB_OK);357return;358}359360if (m_whatSide)361{362if ((m_winRectRight - m_winRectLeft) < width)363{364if (m_whatSide == LEFT_SIDE) {365wndpl.rcNormalPosition.left = wndpl.rcNormalPosition.right - width;366change = TRUE;367} else if (m_whatSide == RIGHT_SIDE) {368wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left + width;369change = TRUE;370}371}372else if ((m_winRectBottom - m_winRectTop) < height)373{374if (m_whatSide == TOP_SIDE) {375wndpl.rcNormalPosition.top = wndpl.rcNormalPosition.bottom - height;376change = TRUE;377} else if (m_whatSide == BOTTOM_SIDE) {378wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top + height;379change = TRUE;380}381}382}383384if ( change ) {385if (!SetWindowPlacement(&wndpl))386{387MessageBox("There is a problem setting Leash Window size!",388"Error", MB_OK);389}390}391m_isBeingResized = TRUE;392393CLeashFrame::RecalcLayout(bNotify);394}395396397void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)398{399lpMMI->ptMinTrackSize.x = 650;400lpMMI->ptMinTrackSize.y = 240;401CLeashFrame::OnGetMinMaxInfo(lpMMI);402}403404void CMainFrame::OnClose(void)405{406CLeashFrame::OnClose();407}408409LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)410{411BOOL oldMin = m_isMinimum;412//printf("CMainFrame::WindowProc() Msg: %x, WPARAM: %x, LPARAM: %x\n", message, wParam, lParam);413switch(message)414{415case WM_CLOSE:416printf("received WM_CLOSE!");417break;418case WM_SIZE:419switch ( wParam ) {420case SIZE_MINIMIZED:421m_isMinimum = TRUE;422break;423case SIZE_MAXIMIZED:424case SIZE_RESTORED:425m_isMinimum = FALSE;426break;427}428break;429case ID_OBTAIN_TGT_WITH_LPARAM:430GetActiveView()->SendMessage(ID_OBTAIN_TGT_WITH_LPARAM, wParam,431lParam);432break;433}434435if ( oldMin != m_isMinimum ) {436if ( m_isMinimum ) {437ShowTaskBarButton(FALSE);438ShowWindow(SW_HIDE);439}440}441return CLeashFrame::WindowProc(message, wParam, lParam);442}443444// Signalled by LeashUIApplication::OnViewChanged when the ribbon height445// changes.446void CMainFrame::OnRibbonResize()447{448RecalcLayout(TRUE);449}450451/*452void CMainFrame::OnHelp()453{454455}456*/457458/*459void CMainFrame::OnContextHelp()460{461462}463*/464465466