1 // **************************************************************************************
3 // By: Arthur David Leather
5 // Copyright @1998 Massachusetts Institute of Technology - All rights reserved.
6 // Description: CPP file for MainFrm.h. Contains variables and functions
11 // MM/DD/YY Inits Description of Change
12 // 12/02/98 ADL Original
13 // **************************************************************************************
17 #include "LeashUIApplication.h"
21 //#include "KrbRealmHostMaintenance.h"
26 static char THIS_FILE[] = __FILE__;
29 /////////////////////////////////////////////////////////////////////////////
35 #define MIN_BOTTOM 280
38 CMFCStatusBar CMainFrame::m_wndStatusBar;
40 CMFCToolBar CMainFrame::m_wndToolBar;
41 CImageList CMainFrame::m_imageList;
42 CImageList CMainFrame::m_disabledImageList;
43 BOOL CMainFrame::m_isMinimum;
44 BOOL CMainFrame::m_isBeingResized;
45 int CMainFrame::m_whatSide;
47 IMPLEMENT_DYNCREATE(CMainFrame, CLeashFrame)
49 BEGIN_MESSAGE_MAP(CMainFrame, CLeashFrame)
50 //{{AFX_MSG_MAP(CMainFrame)
55 ON_COMMAND(ID_APP_EXIT, OnClose)
57 // Global help commands
58 ON_COMMAND(ID_HELP_LEASH_, CMainFrame::OnHelpFinder)
59 ON_COMMAND(ID_HELP, CMainFrame::OnHelp)
60 ON_COMMAND(ID_CONTEXT_HELP, CMainFrame::OnContextHelp)
61 ON_MESSAGE_VOID(WM_RIBBON_RESIZE, OnRibbonResize)
64 static UINT indicators[] =
66 ID_SEPARATOR, // status line indicator
73 /////////////////////////////////////////////////////////////////////////////
74 // CMainFrame construction/destruction
76 CMainFrame::CMainFrame()
82 m_whatSide = RESET_MINSIZE;
84 m_isBeingResized = FALSE;
85 m_bOwnerCreated = FALSE;
89 CMainFrame::~CMainFrame()
93 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
95 if (CLeashApp::m_useRibbon) {
98 // Fixup tooltips (cribbed from http://social.msdn.microsoft.com/Forums/en/vcmfcatl/thread/5c5b4879-d278-4d79-8894-99e7f9b322df)
100 CMFCToolTipInfo ttParams;
101 ttParams.m_bVislManagerTheme = TRUE;
102 ttParams.m_bVislManagerTheme = FALSE;
103 ttParams.m_bDrawSeparator = FALSE;
104 ttParams.m_clrFillGradient = afxGlobalData.clrBarFace;
105 ttParams.m_clrFill = RGB(255, 255, 255);
106 ttParams.m_clrBorder = afxGlobalData.clrBarShadow;
107 ttParams.m_clrText = afxGlobalData.clrBarText;
109 theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
110 RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
112 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7));
113 CDockingManager::SetDockingMode(DT_SMART);
114 m_wndRibbonBar.SetWindows7Look(TRUE);
116 // Initialize the ribbon, keeping a handle to the IUIApplication
117 // so that we can query the ribbon height and save space for it
118 // when calculating our layout.
119 hwnd = this->GetSafeHwnd();
121 printf("Failed to get HWND\n");
122 hr = LeashUIApplication::CreateInstance(&pApplication, hwnd);
124 MessageBox("LeashUIApplication::CreateInstance!", "Error", MB_OK);
129 if (CLeashFrame::OnCreate(lpCreateStruct) == -1)
134 /* NT4 and NT5 aren't shipped with a version of MFC that supports
135 // 'CreateEx()' as of 2/1/99
136 #if _MFC_VER > 0x0421
138 if (!m_wndToolBar.CreateEx(this) ||
139 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
141 TRACE0("Failed to create toolbar\n");
142 return -1; // fail to create
147 if (!m_wndToolBar.Create(this) ||
148 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
150 TRACE0("Failed to create toolbar\n");
151 return -1; // fail to create
156 if ((!CLeashApp::m_useRibbon) &&
157 (!m_wndToolBar.Create(this) ||
158 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)))
160 MessageBox("There is problem creating the Leash Toolbar!",
162 TRACE0("Failed to create toolbar\n");
163 return -1; // fail to create
166 #ifndef NO_STATUS_BAR
167 if (!m_wndStatusBar.Create(this) ||
168 !m_wndStatusBar.SetIndicators(indicators,
169 (CLeashApp::m_hAfsDLL ? 4 : 3)))
171 MessageBox("There is problem creating the Leash Status Bar!",
173 TRACE0("Failed to create status bar\n");
174 return -1; // fail to create
179 // TODO: Remove this if you don't want tool tips or a resizeable toolbar
180 //m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() |
181 // CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
183 if (!CLeashApp::m_useRibbon) {
184 // TODO: Delete these three lines if you don't want the toolbar to
186 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
187 EnableDocking(CBRS_ALIGN_ANY);
188 DockPane(&m_wndToolBar);
194 BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
196 return CLeashFrame::PreTranslateMessage(pMsg);
199 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
201 // Use the specific class name we established earlier
202 // Remove the Minimize and Maximize buttons
203 cs.style &= ~WS_MINIMIZEBOX;
204 cs.style &= ~WS_MAXIMIZEBOX;
205 // Initialize the extended window style to display a TaskBar entry with WS_EX_APPWINDOW
206 cs.dwExStyle |= WS_EX_APPWINDOW;
207 // cs.dwExStyle |= WS_EX_OVERLAPPEDWINDOW ;
208 cs.lpszClass = _T("LEASH.0WNDCLASS");
209 cs.lpszName = _T("MIT Kerberos");
211 CString strText = AfxGetApp()->GetProfileString(CLeashFrame::s_profileHeading,
212 CLeashFrame::s_profileRect);
213 if (!strText.IsEmpty())
217 rect.left = atoi((const char*) strText);
218 rect.top = atoi((const char*) strText + 5);
219 rect.right = atoi((const char*) strText + 10);
220 rect.bottom = atoi((const char*) strText + 15);
224 cs.cx = rect.right - rect.left;
225 cs.cy = rect.bottom - rect.top;
228 cs.x = CW_USEDEFAULT;
230 cs.y = CW_USEDEFAULT;
232 cs.cx = CLeashFrame::s_rectDefault.right;
234 cs.cy = CLeashFrame::s_rectDefault.bottom;
238 cs.cx = CLeashFrame::s_rectDefault.right;
239 cs.cy = CLeashFrame::s_rectDefault.bottom;
240 cs.y = CW_USEDEFAULT;
241 cs.x = CW_USEDEFAULT;
244 // Change the following line to call
245 // CLeashFrame::PreCreateWindow(cs) if this is an SDI application.
246 if (!CLeashFrame::PreCreateWindow(cs))
249 // We create a parent window for our application to ensure that
250 // it has an owner. This way we can disable the TaskBar entry
251 // by removing the WS_EX_APPWINDOW style later on.
252 if ( !m_bOwnerCreated )
254 m_bOwnerCreated = m_MainFrameOwner.Create(IDD_FRAMEOWNER);
255 if ( m_bOwnerCreated )
256 m_MainFrameOwner.ShowWindow(SW_HIDE);
258 if ( m_bOwnerCreated )
259 cs.hwndParent = m_MainFrameOwner.GetSafeHwnd();
265 BOOL CMainFrame::ShowTaskBarButton(BOOL bVisible)
267 if (!m_bOwnerCreated)
272 ModifyStyleEx(0, WS_EX_APPWINDOW);
276 ModifyStyleEx(WS_EX_APPWINDOW, 0);
282 /////////////////////////////////////////////////////////////////////////////
283 // CMainFrame diagnostics
286 void CMainFrame::AssertValid() const
288 CLeashFrame::AssertValid();
291 void CMainFrame::Dump(CDumpContext& dc) const
293 CLeashFrame::Dump(dc);
298 /////////////////////////////////////////////////////////////////////////////
299 // CMainFrame message handlers
301 void CMainFrame::OnResetWindowSize()
303 WINDOWPLACEMENT wndpl;
304 wndpl.length = sizeof(WINDOWPLACEMENT);
306 if (!GetWindowPlacement(&wndpl))
308 MessageBox("There is a problem getting Leash Window size!",
313 wndpl.rcNormalPosition = CLeashFrame::s_rectDefault;
315 m_whatSide = SKIP_MINSIZE;
317 if (!SetWindowPlacement(&wndpl))
319 MessageBox("There is a problem setting Leash Window size!",
323 m_whatSide = RESET_MINSIZE;
326 void CMainFrame::OnSizing(UINT fwSide, LPRECT pRect)
327 { // Keeps track of Leash window size for function CMainFrame::RecalcLayout
328 m_winRectLeft = pRect->left;
329 m_winRectTop = pRect->top;
330 m_winRectRight = pRect->right;
331 m_winRectBottom = pRect->bottom;
336 CLeashFrame::OnSizing(fwSide, pRect);
339 void CMainFrame::RecalcLayout(BOOL bNotify)
340 { // MINSIZE - Insurance that we have a minimum Leash window size
341 int width = MIN_RIGHT - MIN_LEFT;
342 int height = MIN_BOTTOM - MIN_TOP;
343 LeashUIApplication *leashUI;
345 border.left = border.right = border.bottom = 0;
346 // Leave room for the ribbon.
347 leashUI = static_cast<LeashUIApplication*>(pApplication);
348 border.top = (leashUI != NULL) ? leashUI->GetRibbonHeight() : 0;
349 NegotiateBorderSpace(CFrameWnd::borderSet, &border);
352 WINDOWPLACEMENT wndpl;
353 wndpl.length = sizeof(WINDOWPLACEMENT);
355 if (!GetWindowPlacement(&wndpl))
357 MessageBox("There is a problem getting Leash Window size!",
364 if ((m_winRectRight - m_winRectLeft) < width)
366 if (m_whatSide == LEFT_SIDE) {
367 wndpl.rcNormalPosition.left = wndpl.rcNormalPosition.right - width;
369 } else if (m_whatSide == RIGHT_SIDE) {
370 wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left + width;
374 else if ((m_winRectBottom - m_winRectTop) < height)
376 if (m_whatSide == TOP_SIDE) {
377 wndpl.rcNormalPosition.top = wndpl.rcNormalPosition.bottom - height;
379 } else if (m_whatSide == BOTTOM_SIDE) {
380 wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top + height;
387 if (!SetWindowPlacement(&wndpl))
389 MessageBox("There is a problem setting Leash Window size!",
393 m_isBeingResized = TRUE;
395 CLeashFrame::RecalcLayout(bNotify);
399 void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
401 lpMMI->ptMinTrackSize.x = 650;
402 lpMMI->ptMinTrackSize.y = 240;
403 CLeashFrame::OnGetMinMaxInfo(lpMMI);
406 void CMainFrame::OnClose(void)
408 CLeashFrame::OnClose();
411 LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
413 BOOL oldMin = m_isMinimum;
414 //printf("CMainFrame::WindowProc() Msg: %x, WPARAM: %x, LPARAM: %x\n", message, wParam, lParam);
418 printf("received WM_CLOSE!");
431 case ID_OBTAIN_TGT_WITH_LPARAM:
432 GetActiveView()->SendMessage(ID_OBTAIN_TGT_WITH_LPARAM, wParam,
437 if ( oldMin != m_isMinimum ) {
439 ShowTaskBarButton(FALSE);
443 return CLeashFrame::WindowProc(message, wParam, lParam);
446 // Signalled by LeashUIApplication::OnViewChanged when the ribbon height
448 void CMainFrame::OnRibbonResize()
454 void CMainFrame::OnHelp()
461 void CMainFrame::OnContextHelp()