-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFCMCmds.cpp
701 lines (594 loc) · 16 KB
/
FCMCmds.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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: FCMCMDS.CPP
** COMPONENT: The Application.
** DESCRIPTION: CFCMCmds class definition.
**
*******************************************************************************
*/
#include "Common.hpp"
#include "FCMCmds.hpp"
#include "FCMApp.hpp"
#include "AboutDlg.hpp"
#include "ClubDetailsDlg.hpp"
#include <WCL/Clipboard.hpp>
#include <WCL/StreamException.hpp>
#include <WCL/File.hpp>
// The cmd ID range of the views.
const int ID_VIEW_FIRST = ID_VIEW_MEMBERS;
const int ID_VIEW_LAST = ID_VIEW_REFEREES;
// Range of data view commands.
const int ID_VIEW_POPUP_CMD = ID_OPTIONS_POPUP;
const int ID_VIEW_FIRST_CMD = ID_OPTIONS_POPUP + 1;
const int ID_VIEW_LAST_CMD = ID_OPTIONS_POPUP + 90;
// Start index of view specific icons.
const int VIEW_ICONS_BASE = 3;
// View specific hints offsets.
const int VIEW_HINTS_BASE = 10000;
const int VIEW_HINTS_DELTA = 100;
// Range of MRU commands.
const int ID_MRU_FIRST = ID_FILE_MRU_1;
const int ID_MRU_LAST = ID_FILE_MRU_4;
// Position of top level menu items.
const int FILE_MENU_POS = 0;
const int VIEW_MENU_POS = 1;
const int CLUB_MENU_POS = 2;
const int OPTIONS_MENU_POS = 3;
const int REPORTS_MENU_POS = 4;
const int DEBUG_MENU_POS = 5;
const int HELP_MENU_POS = 6;
/******************************************************************************
** Method: Constructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CFCMCmds::CFCMCmds(CFCMMainWnd& appWnd)
: CSDICmds(appWnd, IDR_APPTOOLBAR)
{
// Define the command table.
DEFINE_CMD_TABLE
// File menu.
CMD_ENTRY(ID_FILE_NEW, &CFCMCmds::OnFileNew, NULL, 0)
CMD_ENTRY(ID_FILE_OPEN, &CFCMCmds::OnFileOpen, NULL, 1)
CMD_ENTRY(ID_FILE_SAVE, &CFCMCmds::OnFileSave, &CFCMCmds::OnUIFileSave, 2)
CMD_ENTRY(ID_FILE_SAVEAS, &CFCMCmds::OnFileSaveAs, &CFCMCmds::OnUIFileSaveAs, -1)
CMD_ENTRY(ID_FILE_CLOSE, &CFCMCmds::OnFileClose, &CFCMCmds::OnUIFileClose, 1)
CMD_RANGE(ID_MRU_FIRST, ID_MRU_LAST, &CFCMCmds::OnFileOpenMRU, &CFCMCmds::OnUIFileOpenMRU, -1)
CMD_ENTRY(ID_FILE_EXIT, &CFCMCmds::OnFileExit, NULL, -1)
// View menu.
CMD_RANGE(ID_VIEW_FIRST, ID_VIEW_LAST, &CFCMCmds::OnViewDataView, &CFCMCmds::OnUIViewDataView, -1)
// Club menu.
CMD_ENTRY(ID_CLUB_DETAILS, &CFCMCmds::OnClubDetails, &CFCMCmds::OnUIClubDetails, -1)
// Data View menu.
CMD_RANGE(ID_VIEW_FIRST_CMD, ID_VIEW_LAST_CMD, &CFCMCmds::OnDataViewCmd, &CFCMCmds::OnUIDataViewCmds, -1)
// Report menu.
CMD_ENTRY(ID_REPORTS_MEMBERS, &CFCMCmds::OnReportMembers, &CFCMCmds::OnUIReportMembers, -1)
CMD_ENTRY(ID_REPORTS_FIXTURES, &CFCMCmds::OnReportFixtures, &CFCMCmds::OnUIReportFixtures, -1)
CMD_ENTRY(ID_REPORTS_OPPONENTS, &CFCMCmds::OnReportOpponents, &CFCMCmds::OnUIReportOpponents, -1)
CMD_ENTRY(ID_REPORTS_REFEREES, &CFCMCmds::OnReportReferees, &CFCMCmds::OnUIReportReferees, -1)
// Debug menu.
CMD_ENTRY(ID_DEBUG_DBCLIPBOARD, &CFCMCmds::OnDebugClipboard, &CFCMCmds::OnUIDebugClipboard, -1)
CMD_ENTRY(ID_DEBUG_DBFILE, &CFCMCmds::OnDebugFile, &CFCMCmds::OnUIDebugFile, -1)
// Help menu.
CMD_ENTRY(ID_HELP_ABOUT, &CFCMCmds::OnHelpAbout, NULL, 10)
END_CMD_TABLE
}
/******************************************************************************
** Method: Destructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CFCMCmds::~CFCMCmds()
{
}
/******************************************************************************
** Method: Destructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnFileNew()
{
NewFile();
}
/******************************************************************************
** Method: OnFileCreated()
**
** Description: New file created.
**
** Parameters: oDoc The doc affected.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnFileCreated(CSDIDoc& oDoc)
{
OnFileOpened(oDoc);
OnClubDetails();
}
/******************************************************************************
** Method: OnFileOpen()
**
** Description: Open a new file, saving the current one first if necessary.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnFileOpen()
{
OpenFile();
}
/******************************************************************************
** Method: OnFileOpened()
**
** Description: File opened.
**
** Parameters: oDoc The doc affected.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnFileOpened(CSDIDoc&)
{
// Select a default view.
SelectView(MEMBERS_VIEW);
}
/******************************************************************************
** Method: OnFileSave()
**
** Description: Save the current file, asking the user for a file name if
** it has not being set yet.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnFileSave()
{
SaveFile();
}
/******************************************************************************
** Method: OnFileSaveAs()
**
** Description: Save the file to a new file name.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnFileSaveAs()
{
SaveFileAs();
}
/******************************************************************************
** Method: OnFileClose()
**
** Description: Close the current file, saving it if necessary.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnFileClose()
{
CloseFile();
}
/******************************************************************************
** Method: OnFileOpenMRU()
**
** Description: Open a MRU file from the MRU list.
**
** Parameters: iCmdID The ID of the command.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnFileOpenMRU(uint iCmdID)
{
if (OpenMRUFile(iCmdID - ID_MRU_FIRST))
{
// Select a default view.
SelectView(MEMBERS_VIEW);
}
}
/******************************************************************************
** Method: OnFileExit()
**
** Description: Terminate the app.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnFileExit()
{
ExitApp();
}
/******************************************************************************
** Method: OnViewDataView()
**
** Description: Selects one of the views in the view bar.
**
** Parameters: iCmdID The ID of the command.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnViewDataView(uint iCmdID)
{
SelectView(static_cast<DataView>(iCmdID - ID_VIEW_FIRST));
}
/******************************************************************************
** Method: OnClubDetails()
**
** Description: Show the dialog used to edit the clubs core details.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnClubDetails()
{
ASSERT(App.Doc() != NULL);
CClubDetailsDlg Dlg(App.Doc()->m_oDB.m_oDetails[0]);
if (Dlg.RunModal(App.m_rMainWnd) == IDOK)
UpdateUI();
}
/******************************************************************************
** Method: OnDataViewCmd()
**
** Description: Forwards the command to the current data view.
**
** Parameters: iCmdID The ID of the command to execute.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnDataViewCmd(uint iCmdID)
{
ASSERT(App.View() != NULL);
App.View()->m_ViewsMgr.OnCommand(iCmdID);
}
/******************************************************************************
** Method: OnReport*()
**
** Description: Execute a report.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnReportMembers()
{
}
void CFCMCmds::OnReportFixtures()
{
}
void CFCMCmds::OnReportOpponents()
{
}
void CFCMCmds::OnReportReferees()
{
}
/******************************************************************************
** Method: OnDebugClipboard()
**
** Description: Dump the database to the clipboard.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnDebugClipboard()
{
try
{
CClipboard oStream;
oStream.Open(GENERIC_WRITE, CF_TEXT);
App.Doc()->m_oDB.Dump(oStream);
oStream.Close();
}
catch(const CStreamException& e)
{
// Notify user.
App.m_AppWnd.AlertMsg(TXT("%s"), e.twhat());
}
}
/******************************************************************************
** Method: OnDebugFile()
**
** Description: Dump the database to a text file.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnDebugFile()
{
CPath strPath;
// The file extensions.
static tchar szExts[] = { TXT("Text Files (*.txt)\0*.txt\0")
TXT("All Files (*.*)\0*.*\0")
TXT("\0\0") };
static tchar szDefExt[] = { TXT("txt") };
// Get the output filename.
if (strPath.Select(App.m_AppWnd, CPath::SaveFile, szExts, szDefExt))
{
try
{
CFile oStream;
oStream.Create(strPath);
App.Doc()->m_oDB.Dump(oStream);
/*
CResultSet oRS = App.Doc()->m_oDB.m_oMembers.SelectAll();
CSortColumns oCols;
oCols.Add(1, CSortColumns::ASC);
oCols.Add(2, CSortColumns::DESC);
oRS.OrderBy(oCols);
oRS.Dump(oStream);
*/
oStream.Close();
}
catch(const CStreamException& e)
{
// Notify user.
App.m_AppWnd.AlertMsg(TXT("%s"), e.twhat());
}
}
}
/******************************************************************************
** Method: OnHelpAbout()
**
** Description: Show the about dialog.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnHelpAbout()
{
CAboutDlg Dlg;
Dlg.RunModal(App.m_rMainWnd);
}
/******************************************************************************
** Method: OnUI...()
**
** Description: UI update handlers.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::OnUIFileSave()
{
bool bDocOpen = (App.m_pDoc != NULL);
bool bModified = (bDocOpen && App.m_pDoc->Modified());
App.m_AppWnd.m_Menu.EnableCmd(ID_FILE_SAVE, (bDocOpen && bModified));
App.m_AppWnd.m_ToolBar.m_SaveBtn.Enable(bDocOpen && bModified);
}
void CFCMCmds::OnUIFileSaveAs()
{
bool bDocOpen = (App.m_pDoc != NULL);
App.m_AppWnd.m_Menu.EnableCmd(ID_FILE_SAVEAS, bDocOpen);
}
void CFCMCmds::OnUIFileClose()
{
bool bDocOpen = (App.m_pDoc != NULL);
App.m_AppWnd.m_Menu.EnableCmd(ID_FILE_CLOSE, bDocOpen);
}
void CFCMCmds::OnUIFileOpenMRU()
{
App.m_MRUList.UpdateMenu(App.m_AppWnd.m_Menu, ID_MRU_FIRST);
}
void CFCMCmds::OnUIViewDataView()
{
bool bDocOpen = (App.m_pDoc != NULL);
App.m_AppWnd.m_Menu.EnableItem(VIEW_MENU_POS, bDocOpen);
if (!bDocOpen)
{
for (int i = ID_VIEW_FIRST; i <= ID_VIEW_LAST; i++)
App.m_AppWnd.m_Menu.CheckCmd(i, false);
}
}
void CFCMCmds::OnUIClubDetails()
{
bool bDocOpen = (App.m_pDoc != NULL);
App.m_AppWnd.m_Menu.EnableItem(CLUB_MENU_POS, bDocOpen);
}
void CFCMCmds::OnUIDataViewCmds()
{
bool bDocOpen = (App.m_pDoc != NULL);
App.m_AppWnd.m_Menu.EnableItem(OPTIONS_MENU_POS, bDocOpen);
if (bDocOpen)
{
App.View()->m_ViewsMgr.OnUIUpdate();
}
else
{
App.m_AppWnd.m_ToolBar.m_AddBtn.Enable(false);
App.m_AppWnd.m_ToolBar.m_EditBtn.Enable(false);
App.m_AppWnd.m_ToolBar.m_DeleteBtn.Enable(false);
App.m_AppWnd.m_ToolBar.m_PrintBtn.Enable(false);
App.m_AppWnd.m_ToolBar.m_ImportBtn.Enable(false);
App.m_AppWnd.m_ToolBar.m_ExportBtn.Enable(false);
}
}
void CFCMCmds::OnUIReportMembers()
{
bool bDocOpen = (App.m_pDoc != NULL);
App.m_AppWnd.m_Menu.EnableItem(REPORTS_MENU_POS, bDocOpen);
}
void CFCMCmds::OnUIReportFixtures()
{
}
void CFCMCmds::OnUIReportOpponents()
{
}
void CFCMCmds::OnUIReportReferees()
{
}
void CFCMCmds::OnUIDebugClipboard()
{
bool bDocOpen = (App.m_pDoc != NULL);
App.m_AppWnd.m_Menu.EnableItem(DEBUG_MENU_POS, bDocOpen);
}
void CFCMCmds::OnUIDebugFile()
{
}
/******************************************************************************
** Method: SelectView()
**
** Description: Selects one of the data views.
**
** Parameters: eNewView The view to select.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::SelectView(DataView eNewView)
{
ASSERT(eNewView > NO_VIEW);
ASSERT(eNewView < NUM_DATAVIEWS);
CFCMView* pView = App.View();
ASSERT(pView != NULL);
// Get the current view.
DataView eOldView = pView->m_ViewsMgr.CurrentView();
// Ignore if not changing.
if (eNewView == eOldView)
return;
// Change the check mark from the old view to the new one.
App.m_AppWnd.m_Menu.CheckCmd(ID_VIEW_FIRST + eOldView, false);
App.m_AppWnd.m_Menu.CheckCmd(ID_VIEW_FIRST + eNewView, true);
// Switch the view dialogs.
pView->m_ViewsMgr.SelectView(eNewView);
}
/******************************************************************************
** Method: CmdBmpIndex()
**
** Description: Get the commands' bitmap index.
**
** Parameters: iCmdID The command.
**
** Returns: The index or -1 if there isn't one.
**
*******************************************************************************
*/
int CFCMCmds::CmdBmpIndex(uint iCmdID) const
{
// Is view based command?
if ( (iCmdID >= ID_VIEW_FIRST_CMD) && (iCmdID <= ID_VIEW_LAST_CMD) )
return (iCmdID - ID_VIEW_FIRST_CMD) + VIEW_ICONS_BASE;
// Pass to base class.
return CCmdControl::CmdBmpIndex(iCmdID);
}
/******************************************************************************
** Method: CmdHintID()
**
** Description: Get the commands' hint resource ID.
**
** Parameters: iCmdID The command.
**
** Returns: The hint resource ID.
**
*******************************************************************************
*/
int CFCMCmds::CmdHintID(uint iCmdID) const
{
// Is view based command?
if ( (iCmdID >= ID_VIEW_POPUP_CMD) && (iCmdID <= ID_VIEW_LAST_CMD) )
{
CFCMView* pView = App.View();
if (pView != NULL)
{
// Get the current view.
int nCurView = pView->m_ViewsMgr.CurrentView();
return (nCurView * VIEW_HINTS_DELTA) + (iCmdID - ID_VIEW_POPUP_CMD) + VIEW_HINTS_BASE;
}
}
return CCmdControl::CmdHintID(iCmdID);
}
/******************************************************************************
** Method: CmdToolTipID()
**
** Description: Get the commands' tool tip resource ID. This is the same as the
** hint resource ID.
**
** Parameters: iCmdID The command.
**
** Returns: The tool tip resource ID.
**
*******************************************************************************
*/
int CFCMCmds::CmdToolTipID(uint iCmdID) const
{
return CFCMCmds::CmdHintID(iCmdID);
}
/******************************************************************************
** Method: SetFocus()
**
** Description: Sets the focus to the current view.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFCMCmds::SetFocus()
{
// Doc loaded?
if (App.m_pDoc != NULL)
{
CFCMView* pView = App.View();
// Pass focus to view, if created.
if (pView != NULL)
pView->m_ViewsMgr.SetFocus();
}
}