1 // **************************************************************************************
2 // File: MainFrm.cpp
3 // By: Arthur David Leather
4 // Created: 12/02/98
5 // Copyright @1998 Massachusetts Institute of Technology - All rights reserved.
6 // Description: CPP file for MainFrm.h. Contains variables and functions
7 // for Leash
8 //
9 // History:
10 //
11 // MM/DD/YY Inits Description of Change
12 // 12/02/98 ADL Original
13 // **************************************************************************************
14
15
16 #include "stdafx.h"
17 #include "LeashUIApplication.h"
18 #include "Leash.h"
19 #include "MainFrm.h"
20 #include "lglobals.h"
21 //#include "KrbRealmHostMaintenance.h"
22
23 #ifdef _DEBUG
24 #define new DEBUG_NEW
25 #undef THIS_FILE
26 static char THIS_FILE[] = __FILE__;
27 #endif
28
29 /////////////////////////////////////////////////////////////////////////////
30 // CMainFrame
31
32 #define MIN_LEFT 179
33 #define MIN_TOP 61
34 #define MIN_RIGHT 530
35 #define MIN_BOTTOM 280
36
37 #ifndef NO_STATUS_BAR
38 CMFCStatusBar CMainFrame::m_wndStatusBar;
39 #endif
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;
46
47 IMPLEMENT_DYNCREATE(CMainFrame, CLeashFrame)
48
49 BEGIN_MESSAGE_MAP(CMainFrame, CLeashFrame)
50 //{{AFX_MSG_MAP(CMainFrame)
51 ON_WM_CREATE()
52 ON_WM_SIZING()
53 ON_WM_CLOSE()
54 ON_WM_GETMINMAXINFO()
55 ON_COMMAND(ID_APP_EXIT, OnClose)
56 //}}AFX_MSG_MAP
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)
62 END_MESSAGE_MAP()
63
64 static UINT indicators[] =
65 {
66 ID_SEPARATOR, // status line indicator
67 ID_SEPARATOR,
68 ID_SEPARATOR,
69 ID_SEPARATOR
70 };
71
72
73 /////////////////////////////////////////////////////////////////////////////
74 // CMainFrame construction/destruction
75
CMainFrame()76 CMainFrame::CMainFrame()
77 {
78 m_winRectLeft = 0;
79 m_winRectTop = 0;
80 m_winRectRight = 0;
81 m_winRectBottom = 0;
82 m_whatSide = RESET_MINSIZE;
83 m_isMinimum = FALSE;
84 m_isBeingResized = FALSE;
85 m_bOwnerCreated = FALSE;
86 pApplication = NULL;
87 }
88
~CMainFrame()89 CMainFrame::~CMainFrame()
90 {
91 }
92
OnCreate(LPCREATESTRUCT lpCreateStruct)93 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
94 {
95 if (CLeashApp::m_useRibbon) {
96 HWND hwnd;
97 HRESULT hr;
98 // Fixup tooltips (cribbed from http://social.msdn.microsoft.com/Forums/en/vcmfcatl/thread/5c5b4879-d278-4d79-8894-99e7f9b322df)
99
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;
108
109 theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
110 RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
111
112 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7));
113 CDockingManager::SetDockingMode(DT_SMART);
114 m_wndRibbonBar.SetWindows7Look(TRUE);
115
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();
120 if (hwnd == NULL)
121 printf("Failed to get HWND\n");
122 hr = LeashUIApplication::CreateInstance(&pApplication, hwnd);
123 if (FAILED(hr)) {
124 MessageBox("LeashUIApplication::CreateInstance!", "Error", MB_OK);
125 return -1;
126 }
127 }
128
129 if (CLeashFrame::OnCreate(lpCreateStruct) == -1)
130 return -1;
131
132 ShowWindow(SW_HIDE);
133
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
137
138 if (!m_wndToolBar.CreateEx(this) ||
139 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
140 {
141 TRACE0("Failed to create toolbar\n");
142 return -1; // fail to create
143 }
144
145 #else
146
147 if (!m_wndToolBar.Create(this) ||
148 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
149 {
150 TRACE0("Failed to create toolbar\n");
151 return -1; // fail to create
152 }
153
154 #endif
155 */
156 if ((!CLeashApp::m_useRibbon) &&
157 (!m_wndToolBar.Create(this) ||
158 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)))
159 {
160 MessageBox("There is problem creating the Leash Toolbar!",
161 "Error", MB_OK);
162 TRACE0("Failed to create toolbar\n");
163 return -1; // fail to create
164 }
165
166 #ifndef NO_STATUS_BAR
167 if (!m_wndStatusBar.Create(this) ||
168 !m_wndStatusBar.SetIndicators(indicators, 3))
169 {
170 MessageBox("There is problem creating the Leash Status Bar!",
171 "Error", MB_OK);
172 TRACE0("Failed to create status bar\n");
173 return -1; // fail to create
174 }
175 #endif
176
177
178 // TODO: Remove this if you don't want tool tips or a resizable toolbar
179 //m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() |
180 // CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
181
182 if (!CLeashApp::m_useRibbon) {
183 // TODO: Delete these three lines if you don't want the toolbar to
184 // be dockable
185 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
186 EnableDocking(CBRS_ALIGN_ANY);
187 DockPane(&m_wndToolBar);
188 }
189
190 return 0;
191 }
192
PreTranslateMessage(MSG * pMsg)193 BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
194 {
195 return CLeashFrame::PreTranslateMessage(pMsg);
196 }
197
PreCreateWindow(CREATESTRUCT & cs)198 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
199 {
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");
209
210 CString strText = AfxGetApp()->GetProfileString(CLeashFrame::s_profileHeading,
211 CLeashFrame::s_profileRect);
212 if (!strText.IsEmpty())
213 {
214 CRect rect;
215
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);
220
221 cs.x = rect.left;
222 cs.y = rect.top;
223 cs.cx = rect.right - rect.left;
224 cs.cy = rect.bottom - rect.top;
225
226 if ( cs.x < 0 )
227 cs.x = CW_USEDEFAULT;
228 if ( cs.y < 0 )
229 cs.y = CW_USEDEFAULT;
230 if ( cs.cx <= 0 )
231 cs.cx = CLeashFrame::s_rectDefault.right;
232 if ( cs.cy <= 0 )
233 cs.cy = CLeashFrame::s_rectDefault.bottom;
234 }
235 else
236 {
237 cs.cx = CLeashFrame::s_rectDefault.right;
238 cs.cy = CLeashFrame::s_rectDefault.bottom;
239 cs.y = CW_USEDEFAULT;
240 cs.x = CW_USEDEFAULT;
241 }
242
243 // Change the following line to call
244 // CLeashFrame::PreCreateWindow(cs) if this is an SDI application.
245 if (!CLeashFrame::PreCreateWindow(cs))
246 return FALSE;
247
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 )
252 {
253 m_bOwnerCreated = m_MainFrameOwner.Create(IDD_FRAMEOWNER);
254 if ( m_bOwnerCreated )
255 m_MainFrameOwner.ShowWindow(SW_HIDE);
256 }
257 if ( m_bOwnerCreated )
258 cs.hwndParent = m_MainFrameOwner.GetSafeHwnd();
259
260 return TRUE;
261 }
262
263
ShowTaskBarButton(BOOL bVisible)264 BOOL CMainFrame::ShowTaskBarButton(BOOL bVisible)
265 {
266 if (!m_bOwnerCreated)
267 return FALSE;
268
269 if (bVisible) {
270 ShowWindow(SW_HIDE);
271 ModifyStyleEx(0, WS_EX_APPWINDOW);
272 ShowWindow(SW_SHOW);
273 } else {
274 ShowWindow(SW_HIDE);
275 ModifyStyleEx(WS_EX_APPWINDOW, 0);
276 ShowWindow(SW_SHOW);
277 }
278 return TRUE;
279 }
280
281 /////////////////////////////////////////////////////////////////////////////
282 // CMainFrame diagnostics
283
284 #ifdef _DEBUG
AssertValid() const285 void CMainFrame::AssertValid() const
286 {
287 CLeashFrame::AssertValid();
288 }
289
Dump(CDumpContext & dc) const290 void CMainFrame::Dump(CDumpContext& dc) const
291 {
292 CLeashFrame::Dump(dc);
293 }
294
295 #endif //_DEBUG
296
297 /////////////////////////////////////////////////////////////////////////////
298 // CMainFrame message handlers
299
OnResetWindowSize()300 void CMainFrame::OnResetWindowSize()
301 {
302 WINDOWPLACEMENT wndpl;
303 wndpl.length = sizeof(WINDOWPLACEMENT);
304
305 if (!GetWindowPlacement(&wndpl))
306 {
307 MessageBox("There is a problem getting Leash Window size!",
308 "Error", MB_OK);
309 return;
310 }
311
312 wndpl.rcNormalPosition = CLeashFrame::s_rectDefault;
313
314 m_whatSide = SKIP_MINSIZE;
315
316 if (!SetWindowPlacement(&wndpl))
317 {
318 MessageBox("There is a problem setting Leash Window size!",
319 "Error", MB_OK);
320 }
321
322 m_whatSide = RESET_MINSIZE;
323 }
324
OnSizing(UINT fwSide,LPRECT pRect)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;
331
332 if (m_whatSide)
333 m_whatSide = fwSide;
334
335 CLeashFrame::OnSizing(fwSide, pRect);
336 }
337
RecalcLayout(BOOL bNotify)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;
343 RECT border;
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);
349
350 BOOL change = FALSE;
351 WINDOWPLACEMENT wndpl;
352 wndpl.length = sizeof(WINDOWPLACEMENT);
353
354 if (!GetWindowPlacement(&wndpl))
355 {
356 MessageBox("There is a problem getting Leash Window size!",
357 "Error", MB_OK);
358 return;
359 }
360
361 if (m_whatSide)
362 {
363 if ((m_winRectRight - m_winRectLeft) < width)
364 {
365 if (m_whatSide == LEFT_SIDE) {
366 wndpl.rcNormalPosition.left = wndpl.rcNormalPosition.right - width;
367 change = TRUE;
368 } else if (m_whatSide == RIGHT_SIDE) {
369 wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left + width;
370 change = TRUE;
371 }
372 }
373 else if ((m_winRectBottom - m_winRectTop) < height)
374 {
375 if (m_whatSide == TOP_SIDE) {
376 wndpl.rcNormalPosition.top = wndpl.rcNormalPosition.bottom - height;
377 change = TRUE;
378 } else if (m_whatSide == BOTTOM_SIDE) {
379 wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top + height;
380 change = TRUE;
381 }
382 }
383 }
384
385 if ( change ) {
386 if (!SetWindowPlacement(&wndpl))
387 {
388 MessageBox("There is a problem setting Leash Window size!",
389 "Error", MB_OK);
390 }
391 }
392 m_isBeingResized = TRUE;
393
394 CLeashFrame::RecalcLayout(bNotify);
395 }
396
397
OnGetMinMaxInfo(MINMAXINFO FAR * lpMMI)398 void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
399 {
400 lpMMI->ptMinTrackSize.x = 650;
401 lpMMI->ptMinTrackSize.y = 240;
402 CLeashFrame::OnGetMinMaxInfo(lpMMI);
403 }
404
OnClose(void)405 void CMainFrame::OnClose(void)
406 {
407 CLeashFrame::OnClose();
408 }
409
WindowProc(UINT message,WPARAM wParam,LPARAM lParam)410 LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
411 {
412 BOOL oldMin = m_isMinimum;
413 //printf("CMainFrame::WindowProc() Msg: %x, WPARAM: %x, LPARAM: %x\n", message, wParam, lParam);
414 switch(message)
415 {
416 case WM_CLOSE:
417 printf("received WM_CLOSE!");
418 break;
419 case WM_SIZE:
420 switch ( wParam ) {
421 case SIZE_MINIMIZED:
422 m_isMinimum = TRUE;
423 break;
424 case SIZE_MAXIMIZED:
425 case SIZE_RESTORED:
426 m_isMinimum = FALSE;
427 break;
428 }
429 break;
430 case ID_OBTAIN_TGT_WITH_LPARAM:
431 GetActiveView()->SendMessage(ID_OBTAIN_TGT_WITH_LPARAM, wParam,
432 lParam);
433 break;
434 }
435
436 if ( oldMin != m_isMinimum ) {
437 if ( m_isMinimum ) {
438 ShowTaskBarButton(FALSE);
439 ShowWindow(SW_HIDE);
440 }
441 }
442 return CLeashFrame::WindowProc(message, wParam, lParam);
443 }
444
445 // Signalled by LeashUIApplication::OnViewChanged when the ribbon height
446 // changes.
OnRibbonResize()447 void CMainFrame::OnRibbonResize()
448 {
449 RecalcLayout(TRUE);
450 }
451
452 /*
453 void CMainFrame::OnHelp()
454 {
455
456 }
457 */
458
459 /*
460 void CMainFrame::OnContextHelp()
461 {
462
463 }
464 */
465