-
Notifications
You must be signed in to change notification settings - Fork 76
/
genpropertypage.cpp
1848 lines (1375 loc) · 52.1 KB
/
genpropertypage.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
#include "stdafx.h"
#include "..\..\MUSHclient.h"
#include "..\..\mainfrm.h"
#include "..\..\doc.h"
#include "genpropertypage.h"
#include "..\EditMultiLine.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/*
The purpose of this class is to make a common place for handling the lists of:
* triggers
* aliases
* timers
* variables
All of these have similar behaviour:
* You see a list of them (or a tree view nowadays)
* You can add a new one
* You can delete one or more
* You can change an item
* You can copy one or more to the clipboard
* You can paste new items in from the clipboard
* You can find
* You can find next
So rather than repeating all that similar behaviour they are abstracted into
a generic type (where they are stored in an object map) and for each type
a class is derived from this one, overriding things like how to load/unload
a dialog (for adding/changing). The base class has pure virtual functions for
this sort of stuff, forcing us to override them to implement the actual behaviour.
*/
/////////////////////////////////////////////////////////////////////////////
// CGenPropertyPage property page
IMPLEMENT_DYNAMIC(CGenPropertyPage, CPropertyPage)
/////////////////////////////////////////////////////////////////////////////
// Constructor
CGenPropertyPage::CGenPropertyPage(const UINT nID) :
CPropertyPage(nID)
{
//{{AFX_DATA_INIT(CGenPropertyPage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_last_col = 0;
m_reverse = FALSE;
m_iColWidth = NULL;
m_iColJust = NULL;
m_strColumnHeadings = NULL;
m_iColumnCount = 0;
m_bWantTreeControl = false;
m_bReloadList = false;
} // end of CGenPropertyPage::CGenPropertyPage
/////////////////////////////////////////////////////////////////////////////
// Destructor
CGenPropertyPage::~CGenPropertyPage()
{
delete [] m_iColWidth;
delete [] m_strColumnHeadings;
delete [] m_iColJust;
} // end of CGenPropertyPage::~CGenPropertyPage
void CGenPropertyPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGenPropertyPage)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGenPropertyPage, CPropertyPage)
//{{AFX_MSG_MAP(CGenPropertyPage)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGenPropertyPage message handlers
/////////////////////////////////////////////////////////////////////////////
// SetUpPage
void CGenPropertyPage::SetUpPage (CString strObjectType,
CObjectMap * ObjectMap,
CListCtrl * ctlList,
CStatic * ctlSummary,
t_CompareObjects CompareObjects,
CFindInfo * pFindInfo,
const unsigned long iMask,
const bool bWantTreeControl)
{
m_strObjectType = strObjectType;
m_ObjectMap = ObjectMap;
m_ctlList = ctlList;
m_ctlSummary = ctlSummary;
m_CompareObjects = CompareObjects;
m_pObjectFindInfo = pFindInfo;
m_nUpdateNumber = App.GetUniqueNumber ();
m_iMask = iMask;
m_bWantTreeControl = bWantTreeControl;
} // end of CGenPropertyPage::SetUpPage
/////////////////////////////////////////////////////////////////////////////
// GetSelectedItemCount
int CGenPropertyPage::GetSelectedItemCount () const
{
int iCount = 0;
if (m_bWantTreeControl)
{
for (HTREEITEM hGroup = m_cTreeCtrl.GetRootItem ();
hGroup;
hGroup = m_cTreeCtrl.GetNextSiblingItem (hGroup))
{
for (HTREEITEM hItem = m_cTreeCtrl.GetChildItem (hGroup);
hItem;
hItem = m_cTreeCtrl.GetNextSiblingItem (hItem))
{
if (m_cTreeCtrl.GetItemState (hItem, TVIS_SELECTED) & TVIS_SELECTED)
iCount++;
} // end for each item
} // end for each group
return iCount;
} // end of tree control
// here for list view
return m_ctlList->GetSelectedCount ();
} // end of CGenPropertyPage::GetSelectedItemCount
/////////////////////////////////////////////////////////////////////////////
// GetSelectedGroupCount
int CGenPropertyPage::GetSelectedGroupCount () const
{
int iCount = 0;
if (m_bWantTreeControl)
{
for (HTREEITEM hGroup = m_cTreeCtrl.GetRootItem ();
hGroup;
hGroup = m_cTreeCtrl.GetNextSiblingItem (hGroup))
{
if (m_cTreeCtrl.GetItemState (hGroup, TVIS_SELECTED) & TVIS_SELECTED)
{
for (HTREEITEM hItem = m_cTreeCtrl.GetChildItem (hGroup);
hItem;
hItem = m_cTreeCtrl.GetNextSiblingItem (hItem))
iCount++;
return iCount;
} // end of group selected
} // end for each group
} // end of tree control
return 0; // no group selected, or not a tree view
}
/////////////////////////////////////////////////////////////////////////////
// GetItemCount
int CGenPropertyPage::GetItemCount () const
{
int iCount = 0;
if (m_bWantTreeControl)
{
for (HTREEITEM hGroup = m_cTreeCtrl.GetRootItem ();
hGroup;
hGroup = m_cTreeCtrl.GetNextSiblingItem (hGroup))
{
for (HTREEITEM hItem = m_cTreeCtrl.GetChildItem (hGroup);
hItem;
hItem = m_cTreeCtrl.GetNextSiblingItem (hItem))
iCount++;
} // end for each group
return iCount;
} // end of tree control
// here for list view
return m_ctlList->GetItemCount ();
} // end of CGenPropertyPage::GetSelectedItemCount
/////////////////////////////////////////////////////////////////////////////
// OnAddItem
void CGenPropertyPage::OnAddItem(CDialog & dlg)
{
// load dialog with default values
InitDialog (&dlg);
// display dialog, exit if cancelled
if (dlg.DoModal () != IDOK)
return;
// create the object's lookup name (label converted to lower case, or generated)
CObject * pItem;
CString strObjectName;
strObjectName = GetObjectName (&dlg);
if (strObjectName.IsEmpty ())
strObjectName.Format ("*%s%s", // e.g. *trigger100
(LPCTSTR) m_strObjectType,
(LPCTSTR) App.GetUniqueString ());
else
strObjectName.MakeLower();
// if already there (presumably not possible with un-named objects),
// then abort the add
if (m_ObjectMap->Lookup (strObjectName, pItem))
{
CString strMsg;
strMsg = TFormat ("The %s named \"%s\" is already in the %s list",
(LPCTSTR) m_strObjectType,
(LPCTSTR) GetObjectName (&dlg),
(LPCTSTR) m_strObjectType);
::UMessageBox (strMsg);
return;
}
// add new object to map
m_ObjectMap->SetAt (strObjectName, pItem = MakeNewObject ());
// unload from dialog into object's properties
UnloadDialog (&dlg, pItem);
// They can no longer cancel the property sheet, the document has changed
CancelToClose ();
// remember document modified if item is not temporary
if (!CheckIfTemporary (pItem))
m_doc->SetModifiedFlag (TRUE);
// create a CString for lookup purposes
CString * pstrObjectName = new CString (strObjectName);
// add this item to the list/tree view
if (m_bWantTreeControl)
{
HTREEITEM hItem = add_tree_item (pItem, pstrObjectName);
m_cTreeCtrl.SelectItem (hItem);
m_cTreeCtrl.EnsureVisible (hItem);
}
else
{
int nItem = add_list_item (pItem, pstrObjectName, 0, TRUE);
m_ctlList->SetItemState (nItem, LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);
m_ctlList->EnsureVisible (nItem, FALSE);
}
SetInternalName (pItem, strObjectName); // set name so we can delete one-shot items
m_strSelectedItem = strObjectName; // so it gets selected next time
// resort the list
SortItems ();
// redraw the list
if (GetFilterFlag ())
m_bReloadList = true; // full reload because it may have changed filter requirements
// get dispatch id from the script and put it into the item
if (m_doc->m_ScriptEngine)
{
CString strMessage;
SetDispatchID (pItem, m_doc->GetProcedureDispid (GetScriptName (pItem),
m_strObjectType,
GetLabel (pItem),
strMessage));
if (!strMessage.IsEmpty ())
::UMessageBox (strMessage, MB_ICONINFORMATION);
}
} // end of CGenPropertyPage::OnAddItem
/////////////////////////////////////////////////////////////////////////////
// CheckParentHasChildren
// If not - delete parent (empty group)
void CGenPropertyPage::CheckParentHasChildren (HTREEITEM hdlParent)
{
if (m_cTreeCtrl.GetChildItem (hdlParent) == NULL)
{
// get (old) group name
CString strParent = m_cTreeCtrl.GetItemText (hdlParent);
// delete group from tree view
m_cTreeCtrl.DeleteItem (hdlParent);
// find parent in map
map<CString, HTREEITEM>::iterator it = m_GroupsMap.find (strParent);
// delete from map of parents (groups) as well
if (it != m_GroupsMap.end ())
m_GroupsMap.erase (it);
} // end of no children
} // end of CGenPropertyPage::CheckParentHasChildren
/////////////////////////////////////////////////////////////////////////////
// ChangeOneItem
bool CGenPropertyPage::ChangeOneItem (CDialog & dlg, CString * pstrObjectName, const int nItem, HTREEITEM hdlItem)
{
CString strMsg;
ASSERT (pstrObjectName != NULL);
CObject * pItem;
// check object is still there (it might have gone while we looked at the list box)
if (!m_ObjectMap->Lookup (*pstrObjectName, pItem))
{
// item doesn't exist so delete from view
if (hdlItem)
{
HTREEITEM hdlParent = m_cTreeCtrl.GetParentItem (hdlItem);
m_cTreeCtrl.DeleteItem (hdlItem);
CheckParentHasChildren (hdlParent);
}
else
{
m_ctlList->DeleteItem (nItem); // it's gone, so delete it from the list view
m_ctlList->RedrawItems (0, m_ctlList->GetItemCount () - 1); // redraw the list
}
// in the case of one-shot timers, unnamed items might be removed from the list
if (pstrObjectName->Left (1) == "*")
strMsg = TFormat ("The %s you selected is no longer in the %s list",
(LPCTSTR) m_strObjectType,
(LPCTSTR) m_strObjectType);
else
strMsg = TFormat ("The %s named \"%s\" is no longer in the %s list",
(LPCTSTR) m_strObjectType,
(LPCTSTR) *pstrObjectName,
(LPCTSTR) m_strObjectType);
::UMessageBox (strMsg);
delete pstrObjectName; // and get rid of its name string
return false;
}
ASSERT_VALID (pItem);
ASSERT( pItem->IsKindOf( RUNTIME_CLASS( CObject ) ) );
// load dialog with values from the found item
LoadDialog (&dlg, pItem);
CString strOldObjectName = GetObjectName (&dlg);
// put up the dialog, give up if they cancel
if (dlg.DoModal () != IDOK)
return false;
// lookup this object, to make sure it still exists
if (!m_ObjectMap->Lookup (*pstrObjectName, pItem))
{
// item doesn't exist any more so delete from view
if (hdlItem)
{
HTREEITEM hdlParent = m_cTreeCtrl.GetParentItem (hdlItem);
m_cTreeCtrl.DeleteItem (hdlItem);
CheckParentHasChildren (hdlParent);
}
else
{
m_ctlList->DeleteItem (nItem); // it's gone, so delete it from the list view
m_ctlList->RedrawItems (0, m_ctlList->GetItemCount () - 1); // redraw the list
}
// in the case of one-shot timers, unnamed items might be removed from the list
if (pstrObjectName->Left (1) == "*")
strMsg = TFormat ("The %s you selected is no longer in the %s list",
(LPCTSTR) m_strObjectType,
(LPCTSTR) m_strObjectType);
else
strMsg = TFormat ("The %s named \"%s\" is no longer in the %s list",
(LPCTSTR) m_strObjectType,
(LPCTSTR) *pstrObjectName,
(LPCTSTR) m_strObjectType);
::UMessageBox (strMsg);
delete pstrObjectName; // and get rid of its name string
return false;
}
ASSERT_VALID (pItem);
ASSERT( pItem->IsKindOf( RUNTIME_CLASS( CObject ) ) );
if (CheckIfIncluded (pItem))
{
strMsg = TFormat ("The %s named \"%s\" has been included from an include file. You cannot modify it here.",
(LPCTSTR) m_strObjectType,
(LPCTSTR) *pstrObjectName);
::UMessageBox (strMsg);
return true; // can't modify included items
}
// check object still has the same modification number
// (it might have been modified while we looked at the list box)
if (GetModificationNumber (pItem) != m_nUpdateNumber)
{
strMsg = TFormat ("The %s named \"%s\" has already been modified by a script subroutine",
(LPCTSTR) m_strObjectType,
(LPCTSTR) *pstrObjectName);
::UMessageBox (strMsg);
return false;
}
// check for name change
CString strObjectName = GetObjectName (&dlg);
// they deleted the label - make one up for them
if (strObjectName.IsEmpty () && !strOldObjectName.IsEmpty ())
strObjectName.Format ("*%s%s",
(LPCTSTR) m_strObjectType,
(LPCTSTR) App.GetUniqueString ());
else
{
strObjectName.MakeLower ();
strOldObjectName.MakeLower ();
}
// if name changed, delete and re-add it
if (strObjectName != strOldObjectName) // has name changed?
{
// here if label has changed
CObject * new_pItem;
if (m_ObjectMap->Lookup (strObjectName, new_pItem))
{
strMsg = TFormat ("The %s named \"%s\" already exists in the %s list",
(LPCTSTR) m_strObjectType,
(LPCTSTR) strObjectName,
(LPCTSTR) m_strObjectType);
::UMessageBox (strMsg);
return false;
}
// remove old entry and re-add under new name
m_ObjectMap->RemoveKey (*pstrObjectName); // remove old entry
m_ObjectMap->SetAt (strObjectName, pItem); // insert under new name
// delete old name in the list
delete pstrObjectName;
// create a new CString for lookup purposes
pstrObjectName = new CString (strObjectName);
// record item's new name as the list object data
if (hdlItem)
m_cTreeCtrl.SetItemData (hdlItem, (DWORD) pstrObjectName);
else
m_ctlList->SetItemData (nItem, (DWORD) pstrObjectName);
} // end of label changing
// see if the user changed anything, anyway
if (CheckIfChanged (&dlg, pItem))
{
// unload from dialog into object's properties
UnloadDialog (&dlg, pItem);
// They can no longer cancel the property sheet, the document has changed
CancelToClose ();
if (!CheckIfTemporary (pItem))
m_doc->SetModifiedFlag (TRUE);
if (m_bWantTreeControl)
{
// group may have changed, delete and re-add
HTREEITEM hdlParent = m_cTreeCtrl.GetParentItem (hdlItem);
m_cTreeCtrl.DeleteItem (hdlItem);
hdlItem = add_tree_item (pItem, pstrObjectName);
// if deleting item deletes only one in group, remove group as well
CheckParentHasChildren (hdlParent);
// get its new parent
hdlParent = m_cTreeCtrl.GetParentItem (hdlItem);
m_cTreeCtrl.SetItemState (hdlParent, TVIS_EXPANDED, TVIS_EXPANDED); // expand group (parent)
// select the new item
m_cTreeCtrl.SelectItem (hdlItem);
m_cTreeCtrl.EnsureVisible (hdlItem); // may have changed groups
}
else
{
// re-setup list with amended details
int nNewItem = add_list_item (pItem, pstrObjectName, nItem, FALSE); // replace
m_ctlList->RedrawItems (nNewItem, nNewItem);
}
} // end of item changing
// Get dispatch id from the script and put it into the item.
// We do this even if nothing has changed, so that we can force re-evaluation
// of the dispatch ID, by just getting the item and pressing OK.
if (m_doc->m_ScriptEngine)
{
CString strMessage;
SetDispatchID (pItem, m_doc->GetProcedureDispid (GetScriptName (pItem),
m_strObjectType,
GetLabel (pItem),
strMessage));
if (!strMessage.IsEmpty ())
::UMessageBox (strMessage, MB_ICONINFORMATION);
}
return false;
} // end of CGenPropertyPage::ChangeOneItem
/////////////////////////////////////////////////////////////////////////////
// OnChangeItem
void CGenPropertyPage::OnChangeItem(CDialog & dlg)
{
GetSelectedItem (); // in case we re-load list
if (m_bWantTreeControl)
{
bool bFoundIt = false;
for (HTREEITEM hGroup = m_cTreeCtrl.GetRootItem ();
hGroup;
hGroup = m_cTreeCtrl.GetNextSiblingItem (hGroup))
{
for (HTREEITEM hItem = m_cTreeCtrl.GetChildItem (hGroup);
hItem;
hItem = m_cTreeCtrl.GetNextSiblingItem (hItem))
{
UINT iState = m_cTreeCtrl.GetItemState (hItem, TVIS_SELECTED);
if (iState & TVIS_SELECTED)
{
ChangeOneItem (dlg, (CString *) m_cTreeCtrl.GetItemData (hItem), 0, hItem);
bFoundIt = true;
break; // just change one, because handle may have changed
} // end if selected
} // end for each item
if (bFoundIt)
break;
} // end for each group
} // end of tree control
else
{
// iterate through list in case we implement multiple selection one day
for (int nItem = -1;
(nItem = m_ctlList->GetNextItem(nItem, LVNI_SELECTED)) != -1;)
{
ChangeOneItem (dlg, (CString *) m_ctlList->GetItemData (nItem), nItem, NULL);
break; // for consistency
} // end of dealing with each selected item
} // end of list control
// redraw the list
if (GetFilterFlag ())
m_bReloadList = true; // full reload because it may have changed filter requirements
// resort the list
SortItems ();
} // end of CGenPropertyPage::OnChangeItem
/////////////////////////////////////////////////////////////////////////////
// DeleteOneItem
bool CGenPropertyPage::DeleteOneItem(CString * pstrObjectName, int & iIncluded, int & iExecuting)
{
ASSERT (pstrObjectName != NULL);
CObject * pItem;
// see if in the map
if (!m_ObjectMap->Lookup (*pstrObjectName, pItem))
return false; // already deleted! (however that's OK)
ASSERT_VALID (pItem);
ASSERT( pItem->IsKindOf( RUNTIME_CLASS( CObject ) ) );
if (CheckIfIncluded (pItem))
{
iIncluded++; // don't do message here in case hundreds of them
return true;
}
if (CheckIfExecuting (pItem))
{
iExecuting++; // don't do message here in case hundreds of them
return true;
}
// They can no longer cancel the property sheet, the document has changed
CancelToClose ();
if (!CheckIfTemporary (pItem))
m_doc->SetModifiedFlag (TRUE);
// delete from the map
m_ObjectMap->RemoveKey (*pstrObjectName);
// delete the item itself
delete pItem;
// delete its item string
delete pstrObjectName;
return false; // OK return
}
/////////////////////////////////////////////////////////////////////////////
// OnDeleteItem
void CGenPropertyPage::OnDeleteItem()
{
int iCount = GetSelectedItemCount ();
int iGroupCount = GetSelectedGroupCount ();
int nItem,
i,
iIncluded = 0,
iExecuting = 0;
// nothing to delete so give up
if ((iCount + iGroupCount) == 0)
return;
// only warn if they want us to
if (App.m_bTriggerRemoveCheck)
{
// mucking around to make it plural properly
CString sName = m_strObjectType;
if ((iCount + iGroupCount) > 1)
if (sName == "alias")
sName += "es";
else
sName += "s";
if (::UMessageBox (TFormat ("Delete %i %s - are you sure?",
iCount + iGroupCount, sName), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2)
!= IDYES )
return;
} // end of wanting to confirm
// tree control ................
if (m_bWantTreeControl)
{
// go through entire tree control
for (HTREEITEM hGroup = m_cTreeCtrl.GetRootItem ();
hGroup;
hGroup = m_cTreeCtrl.GetNextSiblingItem (hGroup))
{
bool bGroupSelected = m_cTreeCtrl.GetItemState (hGroup, TVIS_SELECTED) & TVIS_SELECTED;
// remember which we deleted
list<HTREEITEM> deletedItems;
// find selected items
for (HTREEITEM hItem = m_cTreeCtrl.GetChildItem (hGroup);
hItem;
hItem = m_cTreeCtrl.GetNextSiblingItem (hItem))
if (bGroupSelected || m_cTreeCtrl.GetItemState (hItem, TVIS_SELECTED) & TVIS_SELECTED)
if (!DeleteOneItem ((CString *) m_cTreeCtrl.GetItemData (hItem), iIncluded, iExecuting))
deletedItems.push_back (hItem);
// loop doesn't work if we delete while going through it, so do it now
for (list<HTREEITEM>::const_iterator it = deletedItems.begin ();
it != deletedItems.end ();
++it)
m_cTreeCtrl.DeleteItem (*it);
CheckParentHasChildren (hGroup);
} // end for each group
} // end of tree control
else
// list control ................
{
CUIntArray arySelected;
arySelected.SetSize (iCount);
// first, remember selected items
for (nItem = -1, i = 0;
(nItem = m_ctlList->GetNextItem(nItem, LVNI_SELECTED)) != -1;)
arySelected [i++] = nItem;
// we do it this way because deleting items buggers up the position in the array
for (i = iCount - 1; i >= 0; i--)
{
nItem = arySelected [i];
// get the lower-case name of this item's object
CString * pstrObjectName = (CString *) m_ctlList->GetItemData (nItem);
if (!DeleteOneItem (pstrObjectName, iIncluded, iExecuting))
m_ctlList->DeleteItem (nItem);
} // end of dealing with each selected item
} // end of list control
if (iIncluded)
{
CString strMsg;
strMsg = TFormat ("%i item%s %s included from an include file. You cannot delete %s here.",
PLURAL (iIncluded),
iIncluded == 1 ? "was" : "were",
iIncluded == 1 ? "it" : "them");
::UMessageBox (strMsg);
}
if (iExecuting)
{
CString strMsg;
strMsg = TFormat ("%i item%s %s currently executing a script. You cannot delete %s now.",
PLURAL (iExecuting),
iExecuting == 1 ? "is" : "are",
iExecuting == 1 ? "it" : "them");
::UMessageBox (strMsg);
}
} // end of CGenPropertyPage::OnDeleteItem
/////////////////////////////////////////////////////////////////////////////
// OnColumnclickItemList
void CGenPropertyPage::OnColumnclickItemList(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int col = pNMListView->iSubItem;
if (col == m_last_col)
m_reverse = !m_reverse;
else
m_reverse = FALSE;
m_last_col = col;
t_gen_sort_param sort_param (m_ObjectMap, m_last_col, m_reverse, m_CompareObjects);
m_ctlList->SortItems (CompareFunc, (LPARAM) &sort_param);
*pResult = 0;
} // end of CGenPropertyPage::OnColumnclickItemList
/////////////////////////////////////////////////////////////////////////////
// add_list_item
int CGenPropertyPage::add_list_item (CObject * pItem,
const CString * pstrObjectName,
const int nItem,
const BOOL bInsert)
{
ASSERT_VALID (pItem);
ASSERT( pItem->IsKindOf( RUNTIME_CLASS( CObject ) ) );
ASSERT (pstrObjectName != NULL);
// add to control
int nNewItem = AddItem (pItem, nItem, bInsert);
// record item's name as the list object data
m_ctlList->SetItemData(nNewItem, (DWORD) pstrObjectName);
// stamp with a number so we know if it was updated without our knowledge
SetModificationNumber (pItem, m_nUpdateNumber);
return nNewItem;
} // end of CGenPropertyPage::add_list_item
/////////////////////////////////////////////////////////////////////////////
// add_tree_item
HTREEITEM CGenPropertyPage::add_tree_item (CObject * pItem,
const CString * pstrObjectName)
{
ASSERT_VALID (pItem);
ASSERT( pItem->IsKindOf( RUNTIME_CLASS( CObject ) ) );
ASSERT (pstrObjectName != NULL);
// get group name
CString strGroup = GetGroup (pItem);
if (strGroup.IsEmpty ())
strGroup = Translate ("(ungrouped)");
// see if group exists already
map<CString, HTREEITEM>::const_iterator it;
it = m_GroupsMap.find (strGroup);
HTREEITEM hParent;
// if it exists, find the group tree item (the parent)
// if not, create it
if (it == m_GroupsMap.end ())
{
hParent = m_cTreeCtrl.InsertItem (strGroup,TVI_ROOT);
m_GroupsMap [strGroup] = hParent;
}
else
hParent = it->second;
// get the description for the tree control
CString strDescription = GetDescription (pItem);
// truncate if ridiculously long
if (strDescription.GetLength () > 100)
strDescription = strDescription.Left (100) + " ...";
// insert it
HTREEITEM hNewItem = m_cTreeCtrl.InsertItem (strDescription, hParent);
// record item's name as the list object data
m_cTreeCtrl.SetItemData (hNewItem, (DWORD) pstrObjectName);
// stamp with a number so we know if it was updated without our knowledge
SetModificationNumber (pItem, m_nUpdateNumber);
return hNewItem;
} // end of CGenPropertyPage::add_tree_item
/////////////////////////////////////////////////////////////////////////////
// CompareFunc
// ... used in the sort
int CALLBACK CGenPropertyPage::CompareFunc ( LPARAM lParam1,
LPARAM lParam2,
LPARAM lParamSort)
{
ASSERT (lParamSort != NULL);
t_gen_sort_param * psort_param = (t_gen_sort_param *) lParamSort;
CString * pName1 = (CString *) lParam1;
CString * pName2 = (CString *) lParam2;
CObject * item1,
* item2;
ASSERT (pName1 != NULL);
ASSERT (pName2 != NULL);
if (psort_param->pObjectMap->Lookup(*pName1, item1) == 0)
return 0;
if (psort_param->pObjectMap->Lookup(*pName2, item2) == 0)
return 0;
ASSERT_VALID (item1);
ASSERT( item1->IsKindOf( RUNTIME_CLASS( CObject ) ) );
ASSERT_VALID (item2);
ASSERT( item2->IsKindOf( RUNTIME_CLASS( CObject ) ) );
t_CompareObjects pCompare = psort_param->CompareObjects;
int iResult = (*pCompare) (psort_param->sortkey, item1, item2);
// if reverse sort wanted, reverse sense of result
if (psort_param->reverse)
iResult *= -1;
return iResult;
} // end of CGenPropertyPage::CompareFunc
/////////////////////////////////////////////////////////////////////////////
// SortItems
void CGenPropertyPage::SortItems (void)
{
t_gen_sort_param sort_param (m_ObjectMap, m_last_col, m_reverse, m_CompareObjects);
if (m_bWantTreeControl)
{
// sort root level into groups
m_cTreeCtrl.SortChildren (TVI_ROOT);
// sort tree control - a group at a time
TVSORTCB cbinfo;
cbinfo.lpfnCompare = CompareFunc;
cbinfo.lParam = (LPARAM) &sort_param;
// sort each group individually (effectively into sequence order)
for (HTREEITEM hGroup = m_cTreeCtrl.GetRootItem ();
hGroup;
hGroup = m_cTreeCtrl.GetNextSiblingItem (hGroup))
{
cbinfo.hParent = hGroup;
m_cTreeCtrl.SortChildrenCB (&cbinfo);
}
} // end of tree control
else
m_ctlList->SortItems (CompareFunc, (LPARAM) &sort_param);
} // end of CGenPropertyPage::SortItems
/////////////////////////////////////////////////////////////////////////////
// LoadList
void CGenPropertyPage::LoadList (void)
{
long iCount = 0;
long iNotShown = 0;
// some stuff (like, sorting) won't work if tree controls aren't in column sequence
if (m_bWantTreeControl)
SetDefaultSequence ();
// for filtering
CScriptEngine * m_ScriptEngine = NULL; // for the filtering checks
bool bFiltering = GetFilterFlag ();
if (bFiltering)
{
m_ScriptEngine = new CScriptEngine (m_doc, "Lua");
if (m_ScriptEngine->CreateScriptEngine ())
bFiltering = false;