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, 3))
170 MessageBox("There is problem creating the Leash Status Bar!",
172 TRACE0("Failed to create status bar\n");
173 return -1; // fail to create
178 // TODO: Remove this if you don't want tool tips or a resizeable toolbar
179 //m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() |
180 // CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
182 if (!CLeashApp::m_useRibbon) {
183 // TODO: Delete these three lines if you don't want the toolbar to
185 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
186 EnableDocking(CBRS_ALIGN_ANY);
187 DockPane(&m_wndToolBar);
193 BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
195 return CLeashFrame::PreTranslateMessage(pMsg);
198 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
200 // Use the specific class name we established earlier
201 // Remove the Minimize and Maximize buttons
202 cs.style &= ~WS_MINIMIZEBOX;
203 cs.style &= ~WS_MAXIMIZEBOX;
204 // Initialize the extended window style to display a TaskBar entry with WS_EX_APPWINDOW
205 cs.dwExStyle |= WS_EX_APPWINDOW;
206 // cs.dwExStyle |= WS_EX_OVERLAPPEDWINDOW ;
207 cs.lpszClass = _T("LEASH.0WNDCLASS");
208 cs.lpszName = _T("MIT Kerberos");
210 CString strText = AfxGetApp()->GetProfileString(CLeashFrame::s_profileHeading,
211 CLeashFrame::s_profileRect);
212 if (!strText.IsEmpty())
216 rect.left = atoi((const char*) strText);
217 rect.top = atoi((const char*) strText + 5);
218 rect.right = atoi((const char*) strText + 10);
219 rect.bottom = atoi((const char*) strText + 15);
223 cs.cx = rect.right - rect.left;
224 cs.cy = rect.bottom - rect.top;
227 cs.x = CW_USEDEFAULT;
229 cs.y = CW_USEDEFAULT;
231 cs.cx = CLeashFrame::s_rectDefault.right;
233 cs.cy = CLeashFrame::s_rectDefault.bottom;
237 cs.cx = CLeashFrame::s_rectDefault.right;
238 cs.cy = CLeashFrame::s_rectDefault.bottom;
239 cs.y = CW_USEDEFAULT;
240 cs.x = CW_USEDEFAULT;
243 // Change the following line to call
244 // CLeashFrame::PreCreateWindow(cs) if this is an SDI application.
245 if (!CLeashFrame::PreCreateWindow(cs))
248 // We create a parent window for our application to ensure that
249 // it has an owner. This way we can disable the TaskBar entry
250 // by removing the WS_EX_APPWINDOW style later on.
251 if ( !m_bOwnerCreated )
253 m_bOwnerCreated = m_MainFrameOwner.Create(IDD_FRAMEOWNER);
254 if ( m_bOwnerCreated )
255 m_MainFrameOwner.ShowWindow(SW_HIDE);
257 if ( m_bOwnerCreated )
258 cs.hwndParent = m_MainFrameOwner.GetSafeHwnd();
264 BOOL CMainFrame::ShowTaskBarButton(BOOL bVisible)
266 if (!m_bOwnerCreated)
271 ModifyStyleEx(0, WS_EX_APPWINDOW);
275 ModifyStyleEx(WS_EX_APPWINDOW, 0);
281 /////////////////////////////////////////////////////////////////////////////
282 // CMainFrame diagnostics
285 void CMainFrame::AssertValid() const
287 CLeashFrame::AssertValid();
290 void CMainFrame::Dump(CDumpContext& dc) const
292 CLeashFrame::Dump(dc);
297 /////////////////////////////////////////////////////////////////////////////
298 // CMainFrame message handlers
300 void CMainFrame::OnResetWindowSize()
302 WINDOWPLACEMENT wndpl;
303 wndpl.length = sizeof(WINDOWPLACEMENT);
305 if (!GetWindowPlacement(&wndpl))
307 MessageBox("There is a problem getting Leash Window size!",
312 wndpl.rcNormalPosition = CLeashFrame::s_rectDefault;
314 m_whatSide = SKIP_MINSIZE;
316 if (!SetWindowPlacement(&wndpl))
318 MessageBox("There is a problem setting Leash Window size!",
322 m_whatSide = RESET_MINSIZE;
325 void CMainFrame::OnSizing(UINT fwSide, LPRECT pRect)
326 { // Keeps track of Leash window size for function CMainFrame::RecalcLayout
327 m_winRectLeft = pRect->left;
328 m_winRectTop = pRect->top;
329 m_winRectRight = pRect->right;
330 m_winRectBottom = pRect->bottom;
335 CLeashFrame::OnSizing(fwSide, pRect);
338 void CMainFrame::RecalcLayout(BOOL bNotify)
339 { // MINSIZE - Insurance that we have a minimum Leash window size
340 int width = MIN_RIGHT - MIN_LEFT;
341 int height = MIN_BOTTOM - MIN_TOP;
342 LeashUIApplication *leashUI;
344 border.left = border.right = border.bottom = 0;
345 // Leave room for the ribbon.
346 leashUI = static_cast<LeashUIApplication*>(pApplication);
347 border.top = (leashUI != NULL) ? leashUI->GetRibbonHeight() : 0;
348 NegotiateBorderSpace(CFrameWnd::borderSet, &border);
351 WINDOWPLACEMENT wndpl;
352 wndpl.length = sizeof(WINDOWPLACEMENT);
354 if (!GetWindowPlacement(&wndpl))
356 MessageBox("There is a problem getting Leash Window size!",
363 if ((m_winRectRight - m_winRectLeft) < width)
365 if (m_whatSide == LEFT_SIDE) {
366 wndpl.rcNormalPosition.left = wndpl.rcNormalPosition.right - width;
368 } else if (m_whatSide == RIGHT_SIDE) {
369 wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left + width;
373 else if ((m_winRectBottom - m_winRectTop) < height)
375 if (m_whatSide == TOP_SIDE) {
376 wndpl.rcNormalPosition.top = wndpl.rcNormalPosition.bottom - height;
378 } else if (m_whatSide == BOTTOM_SIDE) {
379 wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top + height;
386 if (!SetWindowPlacement(&wndpl))
388 MessageBox("There is a problem setting Leash Window size!",
392 m_isBeingResized = TRUE;
394 CLeashFrame::RecalcLayout(bNotify);
398 void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
400 lpMMI->ptMinTrackSize.x = 650;
401 lpMMI->ptMinTrackSize.y = 240;
402 CLeashFrame::OnGetMinMaxInfo(lpMMI);
405 void CMainFrame::OnClose(void)
407 CLeashFrame::OnClose();
410 LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
412 BOOL oldMin = m_isMinimum;
413 //printf("CMainFrame::WindowProc() Msg: %x, WPARAM: %x, LPARAM: %x\n", message, wParam, lParam);
417 printf("received WM_CLOSE!");
430 case ID_OBTAIN_TGT_WITH_LPARAM:
431 GetActiveView()->SendMessage(ID_OBTAIN_TGT_WITH_LPARAM, wParam,
436 if ( oldMin != m_isMinimum ) {
438 ShowTaskBarButton(FALSE);
442 return CLeashFrame::WindowProc(message, wParam, lParam);
445 // Signalled by LeashUIApplication::OnViewChanged when the ribbon height
447 void CMainFrame::OnRibbonResize()
453 void CMainFrame::OnHelp()
460 void CMainFrame::OnContextHelp()