-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainFrm.cpp
654 lines (536 loc) · 19.4 KB
/
MainFrm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "cedtHeader.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_FILE_TAB, OnViewFileTab)
ON_UPDATE_COMMAND_UI(ID_VIEW_FILE_TAB, OnUpdateViewFileTab)
ON_WM_ACTIVATEAPP()
ON_WM_CLOSE()
ON_COMMAND(ID_VIEW_DIRECTORY, OnViewDirectory)
ON_UPDATE_COMMAND_UI(ID_VIEW_DIRECTORY, OnUpdateViewDirectory)
ON_COMMAND(ID_VIEW_OUTPUT, OnViewOutput)
ON_UPDATE_COMMAND_UI(ID_VIEW_OUTPUT, OnUpdateViewOutput)
ON_COMMAND(ID_VIEW_PROJECT, OnViewProject)
ON_UPDATE_COMMAND_UI(ID_VIEW_PROJECT, OnUpdateViewProject)
ON_COMMAND(ID_WINDOW_LAST_VISITED, OnWindowLastVisited)
ON_COMMAND(ID_WINDOW_NEXT, OnWindowNext)
ON_COMMAND(ID_WINDOW_PREV, OnWindowPrev)
ON_WM_SIZE()
ON_COMMAND(ID_FILE_WINDOW_HIDE, OnFileWindowHide)
ON_COMMAND(ID_FILE_WINDOW_SYNC, OnFileWindowSync)
ON_COMMAND(ID_OUTPUT_WINDOW_HIDE, OnOutputWindowHide)
ON_COMMAND(ID_OUTPUT_WINDOW_COPY, OnOutputWindowCopy)
ON_COMMAND(ID_OUTPUT_WINDOW_CLEAR, OnOutputWindowClear)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators0[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_POS,
ID_INDICATOR_MAX,
ID_INDICATOR_FORMAT,
ID_INDICATOR_READONLY,
ID_INDICATOR_REC,
ID_INDICATOR_COL,
ID_INDICATOR_OVR,
};
static UINT indicators1[] =
{
ID_SEPARATOR, // status line indicator
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_bSwitchingChildFrame = FALSE;
m_bPrintPreviewMode = FALSE;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CString szText;
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if ( ! m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
! m_wndToolBar.LoadToolBar(IDR_MAINFRAME) ) {
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if ( ! m_wndStatusBar.Create(this) ||
! m_wndStatusBar.SetIndicators(indicators0, sizeof(indicators0)/sizeof(UINT)) ) {
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
szText.LoadString(IDS_TOOL_TOOLBAR);
m_wndToolBar.SetWindowText(szText);
// File Selector
if ( ! m_wndFileTab.Create(this) ) {
TRACE0("Failed to create file tab\n");
return -1;
}
m_wndFileTab.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
DockControlBar(&m_wndFileTab, AFX_IDW_DOCKBAR_TOP);
szText.LoadString(IDS_TOOL_FILE_TAB);
m_wndFileTab.SetWindowText(szText);
// File Window
if ( ! m_wndFileWindow.Create(this, CSize(200, 480), ID_FILE_WINDOW, WS_CHILD | CBRS_LEFT) ) {
TRACE0("Failed to create file window\n");
return -1;
}
m_wndFileWindow.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
DockControlBar( & m_wndFileWindow, AFX_IDW_DOCKBAR_LEFT );
szText.LoadString(IDS_TOOL_FILE_WINDOW);
m_wndFileWindow.SetWindowText(szText);
// Output Window
if ( ! m_wndOutputWindow.Create(this, CSize(640, 100), ID_OUTPUT_WINDOW, WS_CHILD | CBRS_BOTTOM) ) {
TRACE0("Failed to create output window\n");
return -1;
}
m_wndOutputWindow.EnableDocking(CBRS_ALIGN_BOTTOM | CBRS_ALIGN_TOP);
DockControlBar( & m_wndOutputWindow, AFX_IDW_DOCKBAR_BOTTOM );
szText.LoadString(IDS_TOOL_OUTPUT_WINDOW);
m_wndOutputWindow.SetWindowText(szText);
// Status Bar
m_wndStatusBar.SetPaneStyle(1, SBPS_DISABLED); // OWNER DRAW PANE
m_wndStatusBar.SetPaneStyle(2, SBPS_DISABLED); // OWNER DRAW PANE
m_wndStatusBar.SetPaneStyle(3, SBPS_DISABLED); // OWNER DRAW PANE
m_wndStatusBar.SetPaneStyle(4, SBPS_DISABLED); // OWNER DRAW PANE
m_wndStatusBar.SetPaneStyle(5, SBPS_DISABLED); // OWNER DRAW PANE
m_wndStatusBar.SetPaneStyle(6, SBPS_DISABLED); // OWNER DRAW PANE
m_wndStatusBar.SetPaneStyle(7, SBPS_DISABLED); // OWNER DRAW PANE
m_wndStatusBar.SetPaneTextColor(1, RGB( 0, 0, 128)); // POS
m_wndStatusBar.SetPaneTextColor(2, RGB( 0, 0, 128)); // MAX
m_wndStatusBar.SetPaneTextColor(3, RGB( 0, 0, 128)); // FORMAT
m_wndStatusBar.SetPaneTextColor(4, RGB(128, 128, 128)); // READONLY
m_wndStatusBar.SetPaneTextColor(5, RGB(160, 64, 64)); // REC
m_wndStatusBar.SetPaneTextColor(6, RGB( 64, 160, 64)); // COL
m_wndStatusBar.SetPaneTextColor(7, RGB( 64, 64, 160)); // OVR
SetCaretPositionInfo(0, 0, 0);
return 0;
}
// status bar
void CMainFrame::SetCaretPositionInfo(INT nLine, INT nCol, INT nMax)
{
if( m_bPrintPreviewMode ) return;
CString szPaneText; szPaneText.Format("Ln %d, Ch %d", nLine, nCol);
m_wndStatusBar.SetPaneText(1, szPaneText);
szPaneText.Format("%d", nMax);
m_wndStatusBar.SetPaneText(2, szPaneText);
}
void CMainFrame::SetFileStatusInfo(INT nEncodingType, INT nFileFormat, BOOL bReadOnly)
{
if( m_bPrintPreviewMode ) return;
CString szPaneText = ENCODING_TYPE_DESCRIPTION_SHORT[nEncodingType];
szPaneText += ", ";
szPaneText += FILE_FORMAT_DESCRIPTION_SHORT[nFileFormat];
m_wndStatusBar.SetPaneText(3, szPaneText);
m_wndStatusBar.SetPaneHighlight(4, bReadOnly);
}
void CMainFrame::SetMacroRecordingFlag(BOOL bRecording)
{
if( m_bPrintPreviewMode ) return;
m_wndStatusBar.SetPaneHighlight(5, bRecording);
}
void CMainFrame::SetColumnModeFlag(BOOL bColumnMode)
{
if( m_bPrintPreviewMode ) return;
m_wndStatusBar.SetPaneHighlight(6, bColumnMode);
}
void CMainFrame::SetOverwriteFlag(BOOL bOverwrite)
{
if( m_bPrintPreviewMode ) return;
m_wndStatusBar.SetPaneHighlight(7, bOverwrite);
}
// file tab
void CMainFrame::InsertMDIFileTab(CMDIChildWnd * pChild)
{
m_wndFileTab.InsertMDIFileTab(pChild);
m_lstChildFrame.AddHead(pChild);
}
void CMainFrame::DeleteMDIFileTab(CMDIChildWnd * pChild)
{
m_wndFileTab.DeleteMDIFileTab(pChild);
POSITION pos = m_lstChildFrame.Find(pChild);
if( pos ) m_lstChildFrame.RemoveAt(pos);
}
void CMainFrame::UpdateMDIFileTab(CMDIChildWnd * pChild)
{
m_wndFileTab.UpdateMDIFileTab(pChild);
}
void CMainFrame::SetActiveFileTab(CMDIChildWnd * pChild)
{
m_wndFileTab.SetActiveFileTab(pChild);
if( ! m_bSwitchingChildFrame ) BringChildFrameToTop(pChild);
}
// file window
void CMainFrame::ShowFileWindowCategory(INT nCategory)
{
INT nActivCat = m_wndFileWindow.GetActiveCategory();
BOOL bVisible = m_wndFileWindow.IsWindowVisible();
if( nActivCat == nCategory ) {
if( ! bVisible ) ShowControlBar( & m_wndFileWindow, TRUE, FALSE );
} else {
if( ! bVisible ) ShowControlBar( & m_wndFileWindow, TRUE, FALSE );
m_wndFileWindow.SetActiveCategory( nCategory );
}
}
void CMainFrame::ToggleFileWindowCategory(INT nCategory)
{
INT nActivCat = m_wndFileWindow.GetActiveCategory();
BOOL bVisible = m_wndFileWindow.IsWindowVisible();
if( nActivCat == nCategory ) {
ShowControlBar( & m_wndFileWindow, ! bVisible, FALSE );
} else {
if( ! bVisible ) ShowControlBar( & m_wndFileWindow, TRUE, FALSE );
m_wndFileWindow.SetActiveCategory( nCategory );
}
}
// child window
CDocument * CMainFrame::MDIGetActiveDocument()
{
CView * pView = MDIGetActiveView();
return pView ? pView->GetDocument() : NULL;
}
CView * CMainFrame::MDIGetActiveView()
{
CMDIChildWnd * pChild = (CMDIChildWnd *)GetActiveFrame();
return pChild ? pChild->GetActiveView() : NULL;
}
void CMainFrame::ActivateNextChildFrame()
{
CMDIChildWnd * pChild = m_wndFileTab.GetNextChildFrame();
if( pChild ) pChild->MDIActivate();
}
void CMainFrame::ActivatePrevChildFrame()
{
CMDIChildWnd * pChild = m_wndFileTab.GetPrevChildFrame();
if( pChild ) pChild->MDIActivate();
}
void CMainFrame::ActivateChildFrameInZOrder(INT nIndex)
{
INT nCount = m_lstChildFrame.GetCount();
if( nCount == 0 ) return;
nIndex = nIndex % nCount;
if( nIndex < 0 || nIndex > nCount-1 ) return;
POSITION pos = m_lstChildFrame.FindIndex(nIndex);
if( ! pos ) return;
CMDIChildWnd * pChild = m_lstChildFrame.GetAt(pos);
if( pChild ) pChild->MDIActivate();
}
void CMainFrame::BringChildFrameToTop(CMDIChildWnd * pChild)
{
if( pChild == NULL ) pChild = MDIGetActive();
POSITION pos = m_lstChildFrame.Find(pChild);
if( ! pos ) return;
m_lstChildFrame.RemoveAt(pos);
m_lstChildFrame.AddHead(pChild);
}
// others
void CMainFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
{
if ((GetStyle() & FWS_ADDTOTITLE) == 0)
return; // leave it alone!
UpdateFrameTitleForDocument(NULL);
}
BOOL CMainFrame::RefreshSyntaxTypeMenu()
{
CMenu * pMainMenu = GetMenu(); if( ! pMainMenu ) return FALSE;
CMenu * pParentMenu = FindParentMenuContaing(pMainMenu, ID_DOCU_SYNTAX_AUTO); if( ! pParentMenu ) return FALSE;
INT nInserted = 0, nMenuCount = pParentMenu->GetMenuItemCount();
for( INT i = nMenuCount-3; i >= 3; i-- ) pParentMenu->DeleteMenu(i, MF_BYPOSITION);
for( INT j = 0; j < MAX_SYNTAX_TYPE; j++ ) {
CString & szMenuText = CCedtDoc::m_clsSyntaxTypes[j].m_szDescription;
if( szMenuText.GetLength() ) {
pParentMenu->InsertMenu(3 + nInserted, MF_BYPOSITION, ID_DOCU_SYNTAX_TYPE0 + j, szMenuText);
nInserted++;
}
}
return TRUE;
}
BOOL CMainFrame::RefreshLoadUserToolsMenu()
{
CMenu * pMainMenu = GetMenu(); if( ! pMainMenu ) return FALSE;
CMenu * pParentMenu = FindParentMenuContaing(pMainMenu, ID_COMMAND_USER_FILE0); if( ! pParentMenu ) return FALSE;
INT nMenuCount = pParentMenu->GetMenuItemCount();
for( INT i = nMenuCount-1; i >= 1; i-- ) pParentMenu->DeleteMenu(i, MF_BYPOSITION);
for( INT j = 0; j < 8; j++ ) {
CString szMenuText = GetFileTitle(CCedtView::m_szUserCommandFilePath[j]);
if( j == 0 ) {
if( ! szMenuText.GetLength() ) szMenuText.LoadString(IDS_MENU_NO_FILE_AVAILABLE);
pParentMenu->ModifyMenu(j, MF_BYPOSITION, ID_COMMAND_USER_FILE0, szMenuText);
} else {
if( ! szMenuText.GetLength() ) continue;
pParentMenu->InsertMenu(j, MF_BYPOSITION, ID_COMMAND_USER_FILE0 + j, szMenuText);
}
}
return TRUE;
}
BOOL CMainFrame::RefreshLoadUserMacrosMenu()
{
CMenu * pMainMenu = GetMenu(); if( ! pMainMenu ) return FALSE;
CMenu * pParentMenu = FindParentMenuContaing(pMainMenu, ID_MACRO_USER_FILE0); if( ! pParentMenu ) return FALSE;
INT nMenuCount = pParentMenu->GetMenuItemCount();
for( INT i = nMenuCount-1; i >= 1; i-- ) pParentMenu->DeleteMenu(i, MF_BYPOSITION);
for( INT j = 0; j < 8; j++ ) {
CString szMenuText = GetFileTitle(CCedtView::m_szMacroBufferFilePath[j]);
if( j == 0 ) {
if( ! szMenuText.GetLength() ) szMenuText.LoadString(IDS_MENU_NO_FILE_AVAILABLE);
pParentMenu->ModifyMenu(j, MF_BYPOSITION, ID_MACRO_USER_FILE0, szMenuText);
} else {
if( ! szMenuText.GetLength() ) continue;
pParentMenu->InsertMenu(j, MF_BYPOSITION, ID_MACRO_USER_FILE0 + j, szMenuText);
}
}
return TRUE;
}
CMenu * CMainFrame::FindParentMenuContaing(CMenu * pParentMenu, UINT nFindMenuID)
{
INT nMenuCount = pParentMenu->GetMenuItemCount();
for(INT i = 0; i < nMenuCount; i++) {
UINT nMenuID = pParentMenu->GetMenuItemID(i);
if( nMenuID == nFindMenuID ) return pParentMenu;
if( (INT)nMenuID == -1 ) { // pop-up menu
CMenu * pMenu = FindParentMenuContaing( pParentMenu->GetSubMenu(i), nFindMenuID );
if( pMenu ) return pMenu;
}
}
return NULL;
}
// window placement
BOOL CMainFrame::SaveWindowPlacement(LPCTSTR lpszProfileName)
{
CCedtApp * pApp = (CCedtApp *)AfxGetApp();
WINDOWPLACEMENT wndpl; wndpl.length = sizeof(wndpl);
GetWindowPlacement( & wndpl );
pApp->WriteProfileInt(lpszProfileName, "flags", (INT)wndpl.flags);
pApp->WriteProfileInt(lpszProfileName, "showCmd", (INT)wndpl.showCmd);
pApp->WriteProfileInt(lpszProfileName, "minX", wndpl.ptMinPosition.x);
pApp->WriteProfileInt(lpszProfileName, "minY", wndpl.ptMinPosition.y);
pApp->WriteProfileInt(lpszProfileName, "maxX", wndpl.ptMaxPosition.x);
pApp->WriteProfileInt(lpszProfileName, "maxY", wndpl.ptMaxPosition.y);
pApp->WriteProfileInt(lpszProfileName, "left", wndpl.rcNormalPosition.left);
pApp->WriteProfileInt(lpszProfileName, "top", wndpl.rcNormalPosition.top);
pApp->WriteProfileInt(lpszProfileName, "right", wndpl.rcNormalPosition.right);
pApp->WriteProfileInt(lpszProfileName, "bottom", wndpl.rcNormalPosition.bottom);
SIZE szHorz, szVert, szFloat;
szHorz = m_wndFileWindow.GetHorzSize();
pApp->WriteProfileInt(lpszProfileName, "auxhcx", szHorz.cx);
pApp->WriteProfileInt(lpszProfileName, "auxhcy", szHorz.cy);
szVert = m_wndFileWindow.GetVertSize();
pApp->WriteProfileInt(lpszProfileName, "auxvcx", szVert.cx);
pApp->WriteProfileInt(lpszProfileName, "auxvcy", szVert.cy);
szFloat = m_wndFileWindow.GetFloatSize();
pApp->WriteProfileInt(lpszProfileName, "auxfcx", szFloat.cx);
pApp->WriteProfileInt(lpszProfileName, "auxfcy", szFloat.cy);
szHorz = m_wndOutputWindow.GetHorzSize();
pApp->WriteProfileInt(lpszProfileName, "outhcx", szHorz.cx);
pApp->WriteProfileInt(lpszProfileName, "outhcy", szHorz.cy);
szVert = m_wndOutputWindow.GetVertSize();
pApp->WriteProfileInt(lpszProfileName, "outvcx", szVert.cx);
pApp->WriteProfileInt(lpszProfileName, "outvcy", szVert.cy);
szFloat = m_wndOutputWindow.GetFloatSize();
pApp->WriteProfileInt(lpszProfileName, "outfcx", szFloat.cx);
pApp->WriteProfileInt(lpszProfileName, "outfcy", szFloat.cy);
pApp->WriteProfileInt(lpszProfileName, "saved", 1);
return TRUE;
}
BOOL CMainFrame::LoadWindowPlacement(LPCTSTR lpszProfileName)
{
CCedtApp * pApp = (CCedtApp *)AfxGetApp();
if( ! pApp->GetProfileInt(lpszProfileName, "saved", 0) ) return FALSE;
SIZE szHorz, szVert, szFloat;
szHorz.cx = pApp->GetProfileInt(lpszProfileName, "auxhcx", 200);
szHorz.cy = pApp->GetProfileInt(lpszProfileName, "auxhcy", 480);
m_wndFileWindow.SetHorzSize(szHorz);
szVert.cx = pApp->GetProfileInt(lpszProfileName, "auxvcx", 200);
szVert.cy = pApp->GetProfileInt(lpszProfileName, "auxvcy", 480);
m_wndFileWindow.SetVertSize(szVert);
szFloat.cx = pApp->GetProfileInt(lpszProfileName, "auxfcx", 200);
szFloat.cy = pApp->GetProfileInt(lpszProfileName, "auxfcy", 480);
m_wndFileWindow.SetFloatSize(szFloat);
szHorz.cx = pApp->GetProfileInt(lpszProfileName, "outhcx", 640);
szHorz.cy = pApp->GetProfileInt(lpszProfileName, "outhcy", 80);
m_wndOutputWindow.SetHorzSize(szHorz);
szVert.cx = pApp->GetProfileInt(lpszProfileName, "outvcx", 640);
szVert.cy = pApp->GetProfileInt(lpszProfileName, "outvcy", 80);
m_wndOutputWindow.SetVertSize(szVert);
szFloat.cx = pApp->GetProfileInt(lpszProfileName, "outfcx", 640);
szFloat.cy = pApp->GetProfileInt(lpszProfileName, "outfcy", 80);
m_wndOutputWindow.SetFloatSize(szFloat);
WINDOWPLACEMENT wndpl; wndpl.length = sizeof(wndpl);
wndpl.flags = pApp->GetProfileInt(lpszProfileName, "flags", 0);
wndpl.showCmd = pApp->GetProfileInt(lpszProfileName, "showCmd", 0);
wndpl.ptMinPosition.x = pApp->GetProfileInt(lpszProfileName, "minX", 0);
wndpl.ptMinPosition.y = pApp->GetProfileInt(lpszProfileName, "minY", 0);
wndpl.ptMaxPosition.x = pApp->GetProfileInt(lpszProfileName, "maxX", 0);
wndpl.ptMaxPosition.y = pApp->GetProfileInt(lpszProfileName, "maxY", 0);
wndpl.rcNormalPosition.left = pApp->GetProfileInt(lpszProfileName, "left", 0);
wndpl.rcNormalPosition.top = pApp->GetProfileInt(lpszProfileName, "top", 0);
wndpl.rcNormalPosition.right = pApp->GetProfileInt(lpszProfileName, "right", 0);
wndpl.rcNormalPosition.bottom = pApp->GetProfileInt(lpszProfileName, "bottom", 0);
SetWindowPlacement( & wndpl );
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState)
{
CMDIFrameWnd::OnSetPreviewMode(bPreview, pState);
m_bPrintPreviewMode = bPreview;
if( bPreview ) {
m_wndStatusBar.SetIndicators(indicators1, sizeof(indicators1)/sizeof(UINT));
} else {
m_wndStatusBar.SetIndicators(indicators0, sizeof(indicators0)/sizeof(UINT));
CRect rect; GetWindowRect( & rect );
PostMessage(WM_SIZE_MAIN_WINDOW, 0, MAKELONG(rect.Width(), rect.Height()));
}
}
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIFrameWnd::OnSize(nType, cx, cy);
// only call when it is not in print preview mode to avoid program crash
if( ! m_bPrintPreviewMode ) CCedtView::OnSizeMainWindow(cx, cy);
}
void CMainFrame::OnSizeMainWindow(int cx, int cy)
{
// when print preview is closed direct call to CCedtView::OnSizeMainWindow()
// causes program to crash...
if( ! m_bPrintPreviewMode ) CCedtView::OnSizeMainWindow(cx, cy);
// we need to update all the views again...
CCedtApp * pApp = (CCedtApp *)AfxGetApp(); ASSERT( pApp );
pApp->UpdateAllViews();
}
void CMainFrame::OnClose()
{
// user can *CANCEL* termination of mainframe window if there is any
// unsaved document and select *CANCEL* from dialog box
// so, don't call any termination procedure in this function.
if( ! m_bPrintPreviewMode ) {
// Save window placement & bar state
SaveBarState(REGKEY_BAR_STATE);
SaveWindowPlacement(REGKEY_WINDOW_PLACEMENT);
CCedtApp::SaveUserConfiguration();
CCedtApp * pApp = (CCedtApp *)AfxGetApp(); // get application pointer
pApp->SaveBrowsingDirectory(REGKEY_BROWSING_DIR);
// current working directory might differ from browsing directory
pApp->SaveWorkingDirectory(REGKEY_WORKING_DIR);
if( CCedtApp::m_bFirstInstance ) {
// save workspace file path
pApp->SaveWorkspaceFilePath(REGKEY_LAST_WORKSPACE);
// save working file list and user configuration
if( pApp->IsProjectLoaded() ) pApp->SaveProjectWorkspace();
else pApp->SaveRegularWorkspace();
}
}
CMDIFrameWnd::OnClose();
}
void CMainFrame::OnActivateApp(BOOL bActive, HTASK hTask)
{
CMDIFrameWnd::OnActivateApp(bActive, hTask);
if( bActive ) {
CCedtApp * pApp = (CCedtApp *)AfxGetApp();
pApp->CheckIfFilesModifiedOutside();
}
}
void CMainFrame::RecalcLayout(BOOL bNotify)
{
CMDIFrameWnd::RecalcLayout(bNotify);
CMDIFrameWnd::RecalcLayout(bNotify);
}
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
static INT nCount;
switch( pMsg->message ) {
case WM_KEYDOWN:
switch( pMsg->wParam ) {
case VK_CONTROL:
m_bSwitchingChildFrame = TRUE;
nCount = 0;
break;
case VK_TAB:
if( GetKeyState(VK_CONTROL) & 0xF0 ) {
ActivateChildFrameInZOrder(++nCount);
return TRUE;
}
break;
case VK_NEXT:
if( GetKeyState(VK_CONTROL) & 0xF0 ) {
ActivateNextChildFrame();
return TRUE;
}
break;
case VK_PRIOR:
if( GetKeyState(VK_CONTROL) & 0xF0 ) {
ActivatePrevChildFrame();
return TRUE;
}
break;
case VK_F5:
if( GetKeyState(VK_CONTROL) & 0xF0 ) {
if( GetKeyState(VK_SHIFT) & 0xF0 ) {
ActivateNextChildFrame();
return TRUE;
} else {
ActivatePrevChildFrame();
return TRUE;
}
}
break;
case VK_F6:
if( GetKeyState(VK_CONTROL) & 0xF0 ) {
if( GetKeyState(VK_SHIFT) & 0xF0 ) {
ActivatePrevChildFrame();
return TRUE;
} else {
ActivateNextChildFrame();
return TRUE;
}
}
break;
}
break;
case WM_KEYUP:
switch( pMsg->wParam ) {
case VK_CONTROL:
m_bSwitchingChildFrame = FALSE;
BringChildFrameToTop(NULL);
break;
}
break;
case WM_SIZE_MAIN_WINDOW:
OnSizeMainWindow(LOWORD(pMsg->lParam), HIWORD(pMsg->lParam));
return TRUE;
}
return CMDIFrameWnd::PreTranslateMessage(pMsg);
}