-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCalculateValuesPg1.cpp
1119 lines (960 loc) · 29.2 KB
/
CalculateValuesPg1.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
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// CalculateValuesPg1.cpp : implementation file
//
// $Id$
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "CalculateValuesPg1.h"
#include "DDX_DDV.h"
#include "DelayUpdate.h"
#include "BasicObj.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CCalculateValuesPg1, baseCalculateValuesPg1)
//#define IDC_LB_ARGS IDC_TREE_ARGS
/////////////////////////////////////////////////////////////////////////////
// CCalculateValuesPg1 property page
CCalculateValuesPg1::CCalculateValuesPg1() : baseCalculateValuesPg1(CCalculateValuesPg1::IDD)
, m_basicDesc(GetDatabase(), IDC_LB_FUNCS, IDC_E_EXPLAN, IDC_TREE_ARGS)
{
m_bRenumbering = false;
//{{AFX_DATA_INIT(CCalculateValuesPg1)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CCalculateValuesPg1::~CCalculateValuesPg1()
{
}
void CCalculateValuesPg1::DoDataExchange(CDataExchange* pDX)
{
baseCalculateValuesPg1::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCalculateValuesPg1)
DDX_Control(pDX, IDC_TC_NAMES, m_tcNames);
DDX_Control(pDX, IDC_E_DESC_INPUT, m_eInputDesc);
DDX_Control(pDX, IDC_MSHFG_NAMES, m_egNames);
DDX_Control(pDX, IDC_MSHFG_BASIC, m_egBasic);
//}}AFX_DATA_MAP
m_basicDesc.DoDataExchange(pDX);
DDX_RateList(pDX);
}
void CCalculateValuesPg1::DDX_RateList(CDataExchange *pDX)
{
// validate state
ASSERT_VALID(this);
// avoid flashing grid
CDelayUpdate update(this, IDC_MSHFG_BASIC);
if (pDX->m_bSaveAndValidate)
{
// determine which XGridTabItem is being validated
int nCurSel = m_tcNames.GetCurSel();
if (nCurSel == -1)
{
// no rates defined
ASSERT(m_tcNames.GetItemCount() == 0);
ASSERT(m_listItems.empty());
// remove any current rates
m_listCalcValues.clear();
}
else
{
// rates have been defined
ASSERT(m_tcNames.GetItemCount() != 0);
ASSERT(!m_listItems.empty());
// rate name already validated by OnEndCellEdit
std::list<XGridTabItem>::iterator itemIter = m_listItems.begin();
std::list<XGridTabItem>::iterator foundItem = m_listItems.end();
for (; itemIter != foundItem; ++itemIter)
{
if (itemIter->nTabIndex == nCurSel)
{
foundItem = itemIter;
break;
}
}
ASSERT(foundItem != m_listItems.end()); // must be in the list
// create object to check basic
CBasicObj basicCheck;
CCalcValue updatedCalcValue;
updatedCalcValue.m_strName = foundItem->calcValue.m_strName;
// save view
long nRowSave = m_egBasic.GetRow();
long nTopRowSave = m_egBasic.GetTopRow();
for (long nRow = m_egBasic.GetFixedRows(); nRow < m_egBasic.GetRows(); ++nRow)
{
basic_command command;
basicCheck.DDX_BasicCommand(pDX, IDC_MSHFG_BASIC, nRow, 0, command);
if (command.strCommand.IsEmpty())
{
// don't add empty commands to list
continue;
}
updatedCalcValue.m_listCommands.push_back(command);
}
// check by running
basicCheck.DDV_BasicCommands(pDX, IDC_MSHFG_BASIC, updatedCalcValue.m_listCommands, m_bRenumbering);
// restore view
m_egBasic.SetRow(nRowSave);
m_egBasic.SetTopRow(nTopRowSave);
if (!m_bRenumbering)
{
m_egBasic.SetRow(0);
m_egBasic.SetTopRow(0);
// make sure contains SAVE token
basicCheck.DDV_ContainsSave(pDX, IDC_MSHFG_BASIC, updatedCalcValue.m_listCommands);
}
// restore view
m_egBasic.SetRow(nRowSave);
m_egBasic.SetTopRow(nTopRowSave);
// update commands
foundItem->calcValue = updatedCalcValue;
// copy rates to rate list
m_listCalcValues.clear();
itemIter = m_listItems.begin();
for (; itemIter != m_listItems.end(); ++itemIter)
{
m_listCalcValues.push_back(itemIter->calcValue);
}
}
}
else
{
if (m_bFirstSetActive)
{
// layout basic grid
CRect rect;
CDC* pDC = GetDC();
int nLogX = pDC->GetDeviceCaps(LOGPIXELSX);
m_egBasic.GetClientRect(&rect);
m_egBasic.SetColWidth(1, 0, MulDiv(rect.right, TWIPS_PER_INCH, nLogX) - 425 - 3);
std::list<CCalcValue>::iterator calcValueIter = m_listCalcValues.begin();
for (int i = 0; calcValueIter != m_listCalcValues.end(); ++calcValueIter, ++i)
{
InsertRate(i, (*calcValueIter));
}
if (m_listCalcValues.size())
{
ASSERT(m_tcNames.GetItemCount() > 0);
// enable and display basic input
DisplayTab(0);
}
else
{
// disable basic input
DisplayTab(-1);
}
}
}
// validate state
ASSERT_VALID(this);
}
BEGIN_MESSAGE_MAP(CCalculateValuesPg1, baseCalculateValuesPg1)
//{{AFX_MSG_MAP(CCalculateValuesPg1)
ON_LBN_SELCHANGE(IDC_LB_FUNCS, OnSelchangeLbFuncs)
ON_NOTIFY(TCN_SELCHANGE, IDC_TC_NAMES, OnSelchangeTcNames)
ON_NOTIFY(TCN_SELCHANGING, IDC_TC_NAMES, OnSelchangingTcNames)
ON_WM_SIZE()
ON_LBN_SETFOCUS(IDC_LB_FUNCS, OnSetfocusLbFuncs)
ON_EN_SETFOCUS(IDC_E_EXPLAN, OnSetfocusEExplan)
ON_LBN_SETFOCUS(IDC_LB_ARGS, OnSetfocusLbArgs)
ON_BN_CLICKED(IDC_B_RENUMBER, OnBRenumber)
ON_WM_HELPINFO()
ON_NOTIFY(NM_SETFOCUS, IDC_TREE_ARGS, OnSetfocusTreeArgs)
//}}AFX_MSG_MAP
// custom BN_SETFOCUS notifications
ON_BN_SETFOCUS(IDC_B_RENUMBER, OnSetfocusBRenumber)
// custom edit grid notifications
ON_MESSAGE(EGN_BEGINCELLEDIT, OnBeginCellEdit)
ON_MESSAGE(EGN_ENDCELLEDIT, OnEndCellEdit)
ON_MESSAGE(EGN_SETFOCUS, OnSetfocusGrid)
// COMMENT: {9/5/2001 7:27:37 PM} ON_MESSAGE(EGN_CHANGE, OnChange)
END_MESSAGE_MAP()
BOOL CCalculateValuesPg1::OnInitDialog()
{
baseCalculateValuesPg1::OnInitDialog();
CreateRoot(VERTICAL, 5, 6)
<< (pane(HORIZONTAL, GREEDY)
<< (pane(VERTICAL, ABSOLUTE_HORZ)
<< item(IDC_ST_NAMES, NORESIZE | ALIGN_BOTTOM)
<< item(IDC_MSHFG_NAMES, GREEDY)
)
<< (paneTab(&m_tcNames, VERTICAL, GREEDY, nDefaultBorder, 4, 15)
<< (pane(HORIZONTAL, GREEDY)
<< item(IDC_ST_BASIC, ABSOLUTE_VERT | ALIGN_BOTTOM)
<< item(IDC_B_RENUMBER, NORESIZE)
)
<< item(IDC_MSHFG_BASIC, GREEDY)
<< (pane(HORIZONTAL, GREEDY)
<< (pane(VERTICAL, ABSOLUTE_VERT | ALIGN_BOTTOM)
<< item(IDC_ST_FUNCS, ABSOLUTE_VERT | ALIGN_BOTTOM)
<< item(IDC_LB_FUNCS, ABSOLUTE_VERT | ALIGN_BOTTOM)
)
<< (pane(VERTICAL, ABSOLUTE_VERT | ALIGN_BOTTOM)
<< item(IDC_ST_EXPLAN, ABSOLUTE_VERT | ALIGN_BOTTOM)
<< item(IDC_E_EXPLAN, ABSOLUTE_VERT | ALIGN_BOTTOM)
)
<< (pane(VERTICAL, ABSOLUTE_VERT | ALIGN_BOTTOM)
<< item(IDC_ST_ARGS, ABSOLUTE_VERT | ALIGN_BOTTOM)
<< item(IDC_TREE_ARGS, ABSOLUTE_VERT | ALIGN_BOTTOM)
)
)
)
)
<< (paneCtrl(IDC_S_DESC_INPUT, HORIZONTAL, GREEDY, nDefaultBorder, 10, 10)
<< item(IDC_E_DESC_INPUT, ABSOLUTE_VERT)
);
UpdateLayout();
// Add extra initialization here
m_egBasic.SetTrimOnEntry(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
// COMMENT: {9/5/2001 7:27:47 PM}LRESULT CCalculateValuesPg1::OnChange(WPARAM wParam, LPARAM lParam)
// COMMENT: {9/5/2001 7:27:47 PM}{
// COMMENT: {9/5/2001 7:27:47 PM} TRACE("OnChange\n");
// COMMENT: {9/5/2001 7:27:47 PM}
// COMMENT: {9/5/2001 7:27:47 PM} NMEGINFO* pInfo = (NMEGINFO*)lParam;
// COMMENT: {9/5/2001 7:27:47 PM} UINT nID = wParam;
// COMMENT: {9/5/2001 7:27:47 PM}
// COMMENT: {9/5/2001 7:27:47 PM} ASSERT(m_bIgnoreChanges == true); // should have vbeen set in OnBeginCellEdit
// COMMENT: {9/5/2001 7:27:47 PM}
// COMMENT: {9/5/2001 7:27:47 PM} switch (nID)
// COMMENT: {9/5/2001 7:27:47 PM} {
// COMMENT: {9/5/2001 7:27:47 PM} case IDC_MSHFG_NAMES :
// COMMENT: {9/5/2001 7:27:47 PM} //{{
// COMMENT: {9/5/2001 7:27:47 PM} CRate rate;
// COMMENT: {9/5/2001 7:27:47 PM} rate.m_strName = pInfo->item.pszText;
// COMMENT: {9/5/2001 7:27:47 PM}
// COMMENT: {9/5/2001 7:27:47 PM} // replace spaces with underscores
// COMMENT: {9/5/2001 7:27:47 PM} rate.m_strName.TrimLeft();
// COMMENT: {9/5/2001 7:27:47 PM} rate.m_strName.TrimRight();
// COMMENT: {9/5/2001 7:27:47 PM} rate.m_strName.Replace(_T(' '), _T('_'));
// COMMENT: {9/5/2001 7:27:47 PM}
// COMMENT: {9/5/2001 7:27:47 PM} InsertRate(pInfo->item.iRow, rate);
// COMMENT: {9/5/2001 7:27:47 PM} return FALSE; // let InsertRate make change
// COMMENT: {9/5/2001 7:27:47 PM}
// COMMENT: {9/5/2001 7:27:47 PM} //}}
// COMMENT: {9/5/2001 7:27:47 PM} }
// COMMENT: {9/5/2001 7:27:47 PM} return 0;
// COMMENT: {9/5/2001 7:27:47 PM}}
void CCalculateValuesPg1::OnSize(UINT nType, int cx, int cy)
{
baseCalculateValuesPg1::OnSize(nType, cx, cy);
// resize the columns within the grid
if (m_egBasic.GetSafeHwnd())
{
long nCol0 = m_egBasic.GetColWidth(0, 0);
CRect rect;
CDC* pDC = GetDC();
int nLogX = pDC->GetDeviceCaps(LOGPIXELSX);
m_egBasic.GetClientRect(&rect);
m_egBasic.SetColWidth(1, 0, MulDiv(rect.right, TWIPS_PER_INCH, nLogX) - nCol0/* - 50*/);
}
}
void CCalculateValuesPg1::OnSelchangeLbFuncs()
{
m_basicDesc.OnSelchangeLbFuncs();
}
void CCalculateValuesPg1::OnSelchangeTcNames(NMHDR* pNMHDR, LRESULT* pResult)
{
// Note: OnSelchangingTcNames updates the rate
UNUSED(pNMHDR);
int nCurSel = m_tcNames.GetCurSel();
ASSERT(nCurSel != -1 || m_tcNames.GetItemCount() == 0);
DisplayTab(nCurSel);
*pResult = 0;
}
LRESULT CCalculateValuesPg1::OnBeginCellEdit(WPARAM wParam, LPARAM lParam)
{
NMEGINFO* pInfo = (NMEGINFO*)lParam;
UINT nID = wParam;
BOOL bDenyEdit = FALSE; // allow edit
//DDX_Control(pDX, IDC_MSHFG_NAMES, m_egNames);
//DDX_Control(pDX, IDC_MSHFG_BASIC, m_egBasic);
if (nID == IDC_MSHFG_NAMES)
{
// do nothing
}
return bDenyEdit;
}
LRESULT CCalculateValuesPg1::OnEndCellEdit(WPARAM wParam, LPARAM lParam)
{
NMEGINFO* pInfo = (NMEGINFO*)lParam;
UINT nID = wParam;
BOOL bMakeChange = TRUE;
// ignore if edit is cancelled
if ( pInfo->item.pszText == NULL ) return bMakeChange;
switch ( nID )
{
case IDC_MSHFG_NAMES :
{
CCalcValue calcValue;
calcValue.m_strName = pInfo->item.pszText;
// replace spaces with underscores
calcValue.m_strName.TrimLeft();
calcValue.m_strName.TrimRight();
calcValue.m_strName.Replace(_T(' '), _T('_'));
InsertRate(pInfo->item.iRow, calcValue);
return FALSE; // let InsertRate make change
}
break;
case IDC_MSHFG_BASIC :
// make sure grid has at least one empty row
if (pInfo->item.iRow >= m_egBasic.GetRows() - m_egBasic.GetFixedRows() - 1)
{
m_egBasic.SetRows(m_egBasic.GetRows() + 5);
// MAYBE number added lines
}
break;
default:
ASSERT(FALSE);
break;
}
return bMakeChange;
}
void CCalculateValuesPg1::OnSelchangingTcNames(NMHDR* pNMHDR, LRESULT* pResult)
{
UNUSED(pNMHDR);
ASSERT(m_tcNames.GetCurSel() != -1);
// validate basic and disallow tab change if (UpdateData != TRUE)
*pResult = !(UpdateData(TRUE));
}
CString CCalculateValuesPg1::GetRateName(long nRowIndex)const
{
ASSERT_VALID(this);
CString strName;
std::list<XGridTabItem>::const_iterator itemIter = m_listItems.begin();
for (; itemIter != m_listItems.end(); ++itemIter)
{
if (itemIter->nRowIndex == nRowIndex)
{
strName = itemIter->calcValue.m_strName;
// item found
break;
}
}
ASSERT_VALID(this);
return strName;
}
BOOL CCalculateValuesPg1::SetRateName(long nRowIndex, LPCTSTR lpszRateName)
{
ASSERT_VALID(this);
ASSERT(lpszRateName && lstrlen(lpszRateName));
BOOL bItemFound = FALSE;
std::list<XGridTabItem>::iterator itemIter = m_listItems.begin();
for (; itemIter != m_listItems.end(); ++itemIter)
{
if (itemIter->nRowIndex == nRowIndex)
{
// item found
bItemFound = TRUE;
// update list
itemIter->calcValue.m_strName = lpszRateName;
// update grid
m_egNames.SetTextMatrix(itemIter->nRowIndex, 0, lpszRateName);
// update tab
TCITEM item;
item.mask = TCIF_TEXT;
item.pszText = (LPTSTR)lpszRateName;
m_tcNames.SetItem(itemIter->nTabIndex, &item);
break;
}
}
ASSERT_VALID(this);
return bItemFound;
}
BOOL CCalculateValuesPg1::GetRate(long nRowIndex, CCalcValue* pCalcValue)const
{
ASSERT(pCalcValue != NULL);
ASSERT_VALID(this);
BOOL bItemFound = FALSE;
std::list<XGridTabItem>::const_iterator itemIter = m_listItems.begin();
for (; itemIter != m_listItems.end(); ++itemIter)
{
if (itemIter->nRowIndex == nRowIndex)
{
// item found
bItemFound = TRUE;
pCalcValue->m_strName = itemIter->calcValue.m_strName;
pCalcValue->m_listCommands.assign(itemIter->calcValue.m_listCommands.begin(), itemIter->calcValue.m_listCommands.end());
break;
}
}
ASSERT_VALID(this);
return bItemFound;
}
BOOL CCalculateValuesPg1::DeleteRate(long nRowIndex)
{
ASSERT_VALID(this);
BOOL bItemFound = FALSE;
XGridTabItem foundItem;
std::list<XGridTabItem>::iterator itemIter = m_listItems.begin();
for (; itemIter != m_listItems.end(); ++itemIter)
{
if (itemIter->nRowIndex == nRowIndex)
{
foundItem = (*itemIter);
// item found
bItemFound = TRUE;
// update grid
m_egNames.DeleteRow(itemIter->nRowIndex);
// update tab
// COMMENT: {7/13/2000 11:39:03 AM} //{{
// COMMENT: {7/13/2000 11:39:03 AM} int nCurSel = m_tcNames.GetCurSel();
// COMMENT: {7/13/2000 11:39:03 AM} VERIFY(m_tcNames.DeleteItem(itemIter->nTabIndex));
// COMMENT: {7/13/2000 11:39:03 AM} if (nCurSel == itemIter->nTabIndex)
// COMMENT: {7/13/2000 11:39:03 AM} {
// COMMENT: {7/13/2000 11:39:03 AM} if (m_tcNames.GetItemCount())
// COMMENT: {7/13/2000 11:39:03 AM} {
// COMMENT: {7/13/2000 11:39:03 AM} m_tcNames.SetCurSel(0);
// COMMENT: {7/13/2000 11:39:03 AM} }
// COMMENT: {7/13/2000 11:39:03 AM} OnSelchangeTcNames(NULL, NULL);
// COMMENT: {7/13/2000 11:39:03 AM} }
// COMMENT: {7/13/2000 11:39:03 AM} //}}
// remove from list
itemIter = m_listItems.erase(itemIter);
break;
}
}
for (; itemIter != m_listItems.end(); ++itemIter)
{
// update rates following the deleted rate
itemIter->nRowIndex--;
itemIter->nTabIndex--;
}
// update tab
//{{
int nCurSel = m_tcNames.GetCurSel();
VERIFY(m_tcNames.DeleteItem(foundItem.nTabIndex));
if (nCurSel == foundItem.nTabIndex)
{
if (m_tcNames.GetItemCount())
{
m_tcNames.SetCurSel(0);
}
// LRESULT* pResult
LRESULT result;
OnSelchangeTcNames(NULL, &result);
}
//}}
// Recalc Tab area
UpdateLayout();
ASSERT_VALID(this);
return bItemFound;
}
void CCalculateValuesPg1::InsertRate(long nRowIndex, CCalcValue& calcValue)
{
ASSERT_VALID(this);
// validate row
ASSERT(nRowIndex < m_egNames.GetRows());
ASSERT(nRowIndex >= m_egNames.GetFixedRows());
int nTabsBefore = m_tcNames.GetItemCount();
// find first item after new rate
std::list<XGridTabItem>::iterator itemIter = m_listItems.begin();
std::list<XGridTabItem>::iterator firstItemAfter = m_listItems.end();
std::list<XGridTabItem>::iterator oldItem = m_listItems.end();
for (; itemIter != firstItemAfter; ++itemIter)
{
if (itemIter->nRowIndex == nRowIndex)
{
oldItem = itemIter;
break;
}
if (itemIter->nRowIndex > nRowIndex)
{
firstItemAfter = itemIter;
break;
}
}
if (oldItem != m_listItems.end())
{
if (calcValue.m_strName.IsEmpty())
{
// save tab info before deleting
int nTabIndex = oldItem->nTabIndex;
// remove from list
itemIter = m_listItems.erase(oldItem);
// update items following the deleted rate
for (; itemIter != m_listItems.end(); ++itemIter)
{
itemIter->nTabIndex--;
}
// remove tab
int nCurSel = m_tcNames.GetCurSel();
VERIFY(m_tcNames.DeleteItem(nTabIndex));
if (nCurSel == nTabIndex)
{
if (m_tcNames.GetItemCount())
{
m_tcNames.SetCurSel(0);
}
LRESULT result;
OnSelchangeTcNames(NULL, &result);
}
// update grid
m_egNames.SetTextMatrix(nRowIndex, 0, _T(""));
}
else
{
// item already exists just update rate name
// update grid
m_egNames.SetTextMatrix(nRowIndex, 0, calcValue.m_strName);
// update tab
TCITEM item;
item.mask = TCIF_TEXT;
item.pszText = (LPTSTR)(LPCTSTR)calcValue.m_strName;
m_tcNames.SetItem(oldItem->nTabIndex, &item);
// update list
oldItem->calcValue.m_strName = calcValue.m_strName;
}
}
else
{
if (!calcValue.m_strName.IsEmpty())
{
// this is a new rate add to list
XGridTabItem item;
item.calcValue = calcValue;
item.nRowIndex = nRowIndex;
// make sure grid has at least one empty row
if (nRowIndex >= m_egNames.GetRows() - m_egNames.GetFixedRows() - 1)
{
m_egNames.SetRows(m_egNames.GetRows() + 1);
}
// add to grid
m_egNames.SetTextMatrix(nRowIndex, 0, item.calcValue.m_strName);
// add to list
if (firstItemAfter == m_listItems.end())
{
// add tab
item.nTabIndex = m_tcNames.InsertItem(item.nRowIndex, item.calcValue.m_strName);
m_listItems.push_back(item);
// should be last tab
ASSERT(item.nTabIndex + 1 == m_tcNames.GetItemCount());
// if this is the first tab display it
if (item.nTabIndex == 0)
{
DisplayTab(0);
}
}
else
{
if (firstItemAfter == m_listItems.begin())
{
item.nTabIndex = m_tcNames.InsertItem(0, item.calcValue.m_strName);
// should be first tab
ASSERT(item.nTabIndex == 0);
}
else
{
// get prev item
std::list<XGridTabItem>::iterator itemPrev = firstItemAfter;
itemPrev--;
// add tab
item.nTabIndex = m_tcNames.InsertItem(itemPrev->nTabIndex + 1, item.calcValue.m_strName);
// shouldn't be first tab
ASSERT(item.nTabIndex > 0);
// should be adjacent to previous tab
ASSERT(item.nTabIndex == itemPrev->nTabIndex + 1);
}
// shouldn't be last tab
ASSERT(item.nTabIndex + 1 < m_tcNames.GetItemCount());
// update tabs after this one
itemIter = m_listItems.insert(firstItemAfter, item);
for (itemIter++; itemIter != m_listItems.end(); ++itemIter)
{
itemIter->nTabIndex++;
}
}
}
}
if (nTabsBefore == 0 && m_tcNames.GetItemCount() > 0 ||
nTabsBefore != 0 && m_tcNames.GetItemCount() == 0)
{
// Recalc Tab area
UpdateLayout();
}
ASSERT_VALID(this);
}
//
// nTabIndex == -1 signifies no commands
//
void CCalculateValuesPg1::DisplayTab(int nTabIndex)
{
ASSERT_VALID(this);
std::list<XGridTabItem>::iterator itemIter = m_listItems.begin();
std::list<XGridTabItem>::iterator foundItem = m_listItems.end();
// find XGridTabItem
for (; itemIter != foundItem; ++itemIter)
{
if (itemIter->nTabIndex == nTabIndex)
{
foundItem = itemIter;
break;
}
}
if (nTabIndex != -1)
{
ASSERT(foundItem != m_listItems.end()); // must exist
}
// set line number column width
m_egBasic.SetColWidth(0, 0, 625);
if (nTabIndex != -1)
{
// init m_egBasic rows
long size = foundItem->calcValue.m_listCommands.size();
if (m_egBasic.GetRows() < size + 5)
{
m_egBasic.SetRows(size + 5);
}
}
CString str;
long nLastLineNumber = 0;
long nRow = 0;
if (nTabIndex != -1)
{
std::list<basic_command>::iterator cmdIter = foundItem->calcValue.m_listCommands.begin();
for (; cmdIter != foundItem->calcValue.m_listCommands.end(); ++cmdIter, ++nRow)
{
nLastLineNumber = cmdIter->nLine;
str.Format(_T("%d"), cmdIter->nLine);
m_egBasic.SetTextMatrix(nRow, 0, str);
m_egBasic.SetTextMatrix(nRow, 1, cmdIter->strCommand);
}
}
// determine next line number
long nLineNumber = ((nLastLineNumber / 10) + 1) * 10;
for (; nRow < m_egBasic.GetRows(); ++nRow, nLineNumber += 10)
{
str.Format(_T("%d"), nLineNumber);
m_egBasic.SetTextMatrix(nRow, 0, str);
m_egBasic.SetTextMatrix(nRow, 1, _T(""));
}
// reset grid
m_egBasic.SetTopRow(0);
m_egBasic.SetRow(0);
m_egBasic.SetCol(1);
// if nTabIndex == -1 then there shouldn't be any items
ASSERT(nTabIndex != -1 || m_listItems.size() == 0);
// if nTabIndex == -1 then there shouldn't be any tabs
ASSERT(nTabIndex != -1 || m_tcNames.GetItemCount() == 0);
m_egBasic.EnableWindow(nTabIndex != -1);
CWnd* pWnd = GetDlgItem(IDC_B_RENUMBER);
pWnd->EnableWindow(nTabIndex != -1);
pWnd = GetDlgItem(IDC_ST_BASIC);
pWnd->EnableWindow(nTabIndex != -1);
ASSERT_VALID(this);
}
/////////////////////////////////////////////////////////////////////////////
// CCalculateValuesPg1 diagnostics
#ifdef _DEBUG
void CCalculateValuesPg1::AssertValid() const
{
baseCalculateValuesPg1::AssertValid();
if (!m_tcNames.GetSafeHwnd())
return;
// verify state of tabctrl
ASSERT((int)m_listItems.size() == m_tcNames.GetItemCount());
// verify state of list
long nRowIndexPrev = -1;
int nTabIndexPrev = -1;
std::list<XGridTabItem>::const_iterator itemIter = m_listItems.begin();
for (; itemIter != m_listItems.end(); ++itemIter)
{
// Note: the list should be in the same order as tabs and the grid
ASSERT(itemIter->nRowIndex > nRowIndexPrev);
ASSERT(itemIter->nTabIndex > nTabIndexPrev);
// check tab
TCITEM item;
TCHAR buffer[80];
item.mask = TCIF_TEXT;
item.cchTextMax = 80;
item.pszText = buffer;
ASSERT(m_tcNames.GetItem(itemIter->nTabIndex, &item));
ASSERT(item.pszText);
ASSERT(itemIter->calcValue.m_strName == item.pszText);
// can't check grid since GetTextMatrix is not const
// ASSERT(itemIter->rate.m_strName == m_egNames.GetTextMatrix(itemIter->nRowIndex, 0));
nRowIndexPrev = itemIter->nRowIndex;
nTabIndexPrev = itemIter->nTabIndex;
}
}
void CCalculateValuesPg1::Dump(CDumpContext& dc) const
{
baseCalculateValuesPg1::Dump(dc);
dc << "Item list contains " << m_listItems.size() << " items\n";
std::list<XGridTabItem>::const_iterator itemIter = m_listItems.begin();
for (; itemIter != m_listItems.end(); ++itemIter)
{
dc << "Row = " << itemIter->nRowIndex << ", Tab = " << itemIter->nTabIndex <<
", Rate name = " << itemIter->calcValue.m_strName << "\n";
}
}
#endif //_DEBUG
//////////////////////////////////////////////////////////////////////
// CCalculateValuesPg1::XGridTabItem Class
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCalculateValuesPg1::XGridTabItem::XGridTabItem()
{
CRate rate;
nRowIndex = -1;
nTabIndex = -1;
}
BEGIN_EVENTSINK_MAP(CCalculateValuesPg1, baseCalculateValuesPg1)
//{{AFX_EVENTSINK_MAP(CCalculateValuesPg1)
ON_EVENT(CCalculateValuesPg1, IDC_MSHFG_NAMES, -602 /* KeyDown */, OnKeyDownMshfgNames, VTS_PI2 VTS_I2)
ON_EVENT(CCalculateValuesPg1, IDC_MSHFG_NAMES, 71 /* EnterCell */, OnEnterCellMshfgNames, VTS_NONE)
ON_EVENT(CCalculateValuesPg1, IDC_MSHFG_BASIC, 71 /* EnterCell */, OnEnterCellMshfgBasic, VTS_NONE)
ON_EVENT(CCalculateValuesPg1, IDC_MSHFG_BASIC, -602 /* KeyDown */, OnKeyDownMshfgBasic, VTS_PI2 VTS_I2)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CCalculateValuesPg1::OnKeyDownMshfgNames(short FAR* KeyCode, short Shift)
{
UNUSED(Shift);
switch (*KeyCode)
{
case VK_DELETE :
{
CString strRateName = m_egNames.GetTextMatrix(m_egNames.GetRow(), m_egNames.GetCol());
if (!strRateName.IsEmpty())
{
CString strMsg;
::AfxFormatString1(strMsg, IDS_REMOVE_RATE, strRateName);
if (AfxMessageBox(strMsg, MB_YESNOCANCEL) == IDYES)
{
CRate rate;
DeleteRate(m_egNames.GetRow());
//AfxMessageBox("%1 and the associated BASIC statements will be deleted.");
}
else
{
//AfxMessageBox("%1 and the associated BASIC statements will NOT be deleted.");
}
}
}
break;
}
}
void CCalculateValuesPg1::OnEnterCellMshfgNames()
{
CString strRes;
strRes.LoadString(IDS_RATE_254);
m_eInputDesc.SetWindowText(strRes);
}
void CCalculateValuesPg1::OnEnterCellMshfgBasic()
{
CString strRes;
switch (m_egBasic.GetCol())
{
case 0 :
strRes.LoadString(IDS_RATE_261);
break;
case 1 :
strRes.LoadString(IDS_RATE_262);
break;
}
m_eInputDesc.SetWindowText(strRes);
}
LRESULT CCalculateValuesPg1::OnSetfocusGrid(WPARAM wParam, LPARAM lParam)
{
UNUSED_ALWAYS(lParam);
int nID = wParam;
switch (nID)
{
case IDC_MSHFG_NAMES :
OnEnterCellMshfgNames();
break;
case IDC_MSHFG_BASIC :
OnEnterCellMshfgBasic();
break;
}
return 0;
}
void CCalculateValuesPg1::OnSetfocusLbFuncs()
{
CString strRes;
strRes.LoadString(IDS_RATE_258);
m_eInputDesc.SetWindowText(strRes);
}
void CCalculateValuesPg1::OnSetfocusEExplan()
{
CString strRes;
strRes.LoadString(IDS_RATE_259);
m_eInputDesc.SetWindowText(strRes);
}
void CCalculateValuesPg1::OnSetfocusLbArgs()
{
CString strRes;
strRes.LoadString(IDS_RATE_260);
m_eInputDesc.SetWindowText(strRes);
}
void CCalculateValuesPg1::OnSetfocusBRenumber()
{
CString strRes;
strRes.LoadString(IDS_STRING512);
m_eInputDesc.SetWindowText(strRes);
}
void CCalculateValuesPg1::OnKeyDownMshfgBasic(short FAR* KeyCode, short Shift)
{
UNUSED(Shift);
switch (*KeyCode)
{
case VK_DELETE:
{
CWaitCursor wait; // display hourglass cursor
m_egBasic.SetRedraw(FALSE);
long nCol = m_egBasic.GetCol();
long nColSel = m_egBasic.GetColSel();
// check if entire row is selected
if ((min(nCol, nColSel) == 0) && (1 == max(nCol, nColSel)))
{
long nRow = m_egBasic.GetRow();
long nRowSel = m_egBasic.GetRowSel();
// determine how many rows to delete
long cSelectedRows = abs(nRow - nRowSel) + 1;
// determine first row to delete
long iStartRow = min(nRow, nRowSel);
// delete each row
for (long i = 0; i < cSelectedRows; ++i)
{
m_egBasic.DeleteRow(iStartRow);
}
}
else
{
// just fill with empty strings
m_egBasic.SetFillStyle(flexFillRepeat);
m_egBasic.SetText(_T(""));
m_egBasic.SetFillStyle(flexFillSingle);
}
m_egBasic.SetRedraw(TRUE);
}
break;
}
}
void CCalculateValuesPg1::OnBRenumber()
{
m_bRenumbering = true;
int nRate = m_tcNames.GetCurSel();
ASSERT(nRate != -1);
if (UpdateData(TRUE))
{
// BASIC Ok
std::list<XGridTabItem>::iterator itemIter = m_listItems.begin();
for (int i = 0; i < nRate; ++i)
{
ASSERT(itemIter != m_listItems.end());
itemIter++;
}
ASSERT(itemIter != m_listItems.end());