/
TabbedMDISave.cpp
1808 lines (1578 loc) · 45 KB
/
TabbedMDISave.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
/////////////////////////////////////////////////////////////////////////////
// TabbedMDISave.cpp - Classes related to "saving" MDI children in the
// tabbed MDI environment.
//
// Classes:
// CTabbedMDIChildModifiedItem -
// Implements ITabbedMDIChildModifiedItem.
// CTabbedMDIChildModifiedList -
// Implements ITabbedMDIChildModifiedList.
//
// Written by Daniel Bowen (dbowen@es.com)
// Copyright (c) 2004 Daniel Bowen.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed by any means PROVIDING it is
// not sold for profit without the authors written consent, and
// providing that this notice and the authors name is included.
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability if it causes any damage to you or your
// computer whatsoever.
//
// If you find bugs, have suggestions for improvements, etc.,
// please contact the author.
//
// History (Date/Author/Description):
// ----------------------------------
//
// 2005/07/13: Daniel Bowen
// - Namespace qualify the use of more ATL and WTL classes.
//
// 2005/04/14: Daniel Bowen
// - CSaveModifiedItemsDialog -
// ImageUtil::CreateCheckboxImage now takes an HWND for the list control
//
// 2005/03/15: Daniel Bowen
// - CSaveModifiedItemsDialog -
// Handle the case when no display name is set for an item - have it show "(New)".
//
// 2005/01/14: Daniel Bowen
// - Fix AutoHideUnusedColumns so that it doesn't try to hide the name column
//
// 2004/08/26: Daniel Bowen
// - Break out checkbox image creation
// - Have CDynamicDialogImpl automatically call ConstructDialogResource
// after the constructor, but before the dialog is created
//
// 2004/06/28: Daniel Bowen
// - Support hiding the description and/or last modified columns
// in the "save modified items" dialog.
// - Clean up warnings on level 4
//
// 2004/04/29: Daniel Bowen
// - Original implementation
#define WTL_TABBED_MDI_SAVE_IMPLEMENTATION
#include "TabbedMDISave.h"
#if (_WIN32_WINNT >= 0x0501)
#include <atltheme.h>
#endif
#if (_ATL_VER < 0x0700)
#error TabbedMDISave.cpp requires ATL 7.0 or higher
#endif
#include <atlcomtime.h>
#include "ImageUtil.h"
/////////////////////////////////////////////////////////////////////////////
// CTabbedMDIChildModifiedList
CTabbedMDIChildModifiedList::CTabbedMDIChildModifiedList() :
m_parentItem(NULL)
{
}
HRESULT CTabbedMDIChildModifiedList::FinalConstruct()
{
return S_OK;
}
void CTabbedMDIChildModifiedList::FinalRelease()
{
this->Clear();
// Don't Release m_parentItem, because
// we only have a weak reference to it
m_parentItem = NULL;
}
STDMETHODIMP CTabbedMDIChildModifiedList::get_Item(long index, ITabbedMDIChildModifiedItem** item)
{
if(item == NULL)
{
return E_POINTER;
}
HRESULT hr = E_INVALIDARG;
*item = NULL;
POSITION pos = this->FindIndex(index);
if(pos != NULL)
{
hr = this->GetAt(pos)->QueryInterface(item);
}
return hr;
}
STDMETHODIMP CTabbedMDIChildModifiedList::get_Index(ITabbedMDIChildModifiedItem* item, long* index)
{
if(item == NULL || index == NULL)
{
return E_POINTER;
}
*index = -1;
ATL::CComPtr<IUnknown> punkItemToFind;
item->QueryInterface(IID_IUnknown, (void**)&punkItemToFind);
// If we tracked items by their identity IUnknown*, we could do
// a "Find". But we don't, so we'll just linearly search the list,
// and depend on the comparing IUnknown* values for identity.
// (It's not expected that this method would be called very frequently).
int currentIndex = 0;
POSITION pos = this->GetHeadPosition();
while(pos != NULL)
{
ATL::CComPtr<IUnknown> punkItem;
this->GetNext(pos)->QueryInterface(IID_IUnknown, (void**)&punkItem);
if(punkItemToFind == punkItem)
{
*index = currentIndex;
pos = NULL;
}
else
{
++currentIndex;
}
}
return ((*index) >= 0) ? S_OK : E_INVALIDARG;
}
STDMETHODIMP CTabbedMDIChildModifiedList::get_Count(long* count)
{
if(count == NULL)
{
return E_POINTER;
}
*count = (long)this->GetCount();
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedList::AddNew(
const wchar_t* name, const wchar_t* displayName, const wchar_t* description,
DATE lastModified, HICON icon,
ITabbedMDIChildModifiedItem** item)
{
HRESULT hr = E_FAIL;
ATL::CComObject<CTabbedMDIChildModifiedItem>* newItem = NULL;
hr = ATL::CComObject<CTabbedMDIChildModifiedItem>::CreateInstance(&newItem);
if(newItem != NULL)
{
newItem->AddRef();
HWND window = NULL;
if(m_parentItem)
{
m_parentItem->get_Window(&window);
}
hr = newItem->InitNew(window, name, displayName, description, lastModified, icon);
if(SUCCEEDED(hr))
{
ATL::CComPtr<ITabbedMDIChildModifiedItem> modifiedItem;
hr = newItem->QueryInterface(&modifiedItem);
this->AddTail(modifiedItem);
// Set the parent list as ourselves, but only after
// we really have added it to our collection of items
modifiedItem->putref_ParentList(this);
if(item != NULL)
{
*item = modifiedItem.Detach();
}
}
newItem->Release();
}
return hr;
}
STDMETHODIMP CTabbedMDIChildModifiedList::Insert(
long index, ITabbedMDIChildModifiedItem* item)
{
HRESULT hr = E_INVALIDARG;
POSITION pos = this->FindIndex(index);
if(pos != NULL)
{
this->InsertBefore(pos, item);
hr = S_OK;
}
else
{
this->AddTail(item);
hr = S_OK;
}
if(SUCCEEDED(hr))
{
// Set the parent list as ourselves, but only after
// we really have added it to our collection of items
item->putref_ParentList(this);
}
return hr;
}
STDMETHODIMP CTabbedMDIChildModifiedList::InsertList(
long index, ITabbedMDIChildModifiedList* list)
{
if(list == NULL)
{
return E_INVALIDARG;
}
HRESULT hr = S_OK;
long count = 0;
list->get_Count(&count);
if(index < 0)
{
index = count;
}
for(long i=0; i<count; ++i)
{
ATL::CComPtr<ITabbedMDIChildModifiedItem> item;
list->get_Item(i, &item);
this->Insert(index + i, item);
}
return hr;
}
STDMETHODIMP CTabbedMDIChildModifiedList::Remove(
long index, ITabbedMDIChildModifiedItem** item)
{
HRESULT hr = E_INVALIDARG;
POSITION pos = this->FindIndex(index);
if(pos != NULL)
{
ATL::CComPtr<ITabbedMDIChildModifiedItem> oldItem(this->GetAt(pos));
this->RemoveAt(pos);
if(oldItem)
{
oldItem->putref_ParentList(NULL);
if(item != NULL)
{
*item = oldItem.Detach();
}
}
}
return hr;
}
STDMETHODIMP CTabbedMDIChildModifiedList::Clear()
{
POSITION pos = this->GetHeadPosition();
while(pos != NULL)
{
ATL::CComPtr<ITabbedMDIChildModifiedItem> item(this->GetNext(pos));
if(item)
{
item->putref_ParentList(NULL);
}
}
this->RemoveAll();
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedList::get_ParentItem(ITabbedMDIChildModifiedItem** item)
{
ATLASSERT(item != NULL);
if(item == NULL)
{
return E_POINTER;
}
*item = m_parentItem;
if(m_parentItem)
{
m_parentItem->AddRef();
}
return S_OK;
}
// Methods not exposed over iterface:
STDMETHODIMP CTabbedMDIChildModifiedList::putref_ParentItem(ITabbedMDIChildModifiedItem* item)
{
m_parentItem = item;
return S_OK;
}
/////////////////////////////////////////////////////////////////////////////
// CTabbedMDIChildModifiedItem
CTabbedMDIChildModifiedItem::CTabbedMDIChildModifiedItem() :
m_window(NULL),
m_lastModified(0),
m_icon(NULL),
m_parentList(NULL)
{
}
HRESULT CTabbedMDIChildModifiedItem::FinalConstruct()
{
return S_OK;
}
void CTabbedMDIChildModifiedItem::FinalRelease()
{
if(m_icon)
{
::DestroyIcon(m_icon);
m_icon = NULL;
}
// Don't Release m_parentList, because
// we only have a weak reference to it
m_parentList = NULL;
m_window = NULL;
m_name.Empty();
m_displayName.Empty();
m_description.Empty();
m_userData.Release();
m_subItems.Release();
}
STDMETHODIMP CTabbedMDIChildModifiedItem::get_Window(
HWND* window)
{
ATLASSERT(window != NULL);
if (window == NULL)
{
return E_POINTER;
}
*window = m_window;
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::put_Window(
HWND window)
{
m_window = window;
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::get_Name(
BSTR* name)
{
return m_name.CopyTo(name);
}
STDMETHODIMP CTabbedMDIChildModifiedItem::put_Name(
const wchar_t* name)
{
m_name = name;
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::get_DisplayName(
BSTR* displayName)
{
return m_displayName.CopyTo(displayName);
}
STDMETHODIMP CTabbedMDIChildModifiedItem::put_DisplayName(
const wchar_t* displayName)
{
m_displayName = displayName;
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::get_Description(
BSTR* description)
{
return m_description.CopyTo(description);
}
STDMETHODIMP CTabbedMDIChildModifiedItem::put_Description(
const wchar_t* description)
{
m_description = description;
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::get_LastModifiedUTC(
DATE* lastModified)
{
ATLASSERT(lastModified != NULL);
if (lastModified == NULL)
{
return E_POINTER;
}
*lastModified = m_lastModified;
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::put_LastModifiedUTC(
DATE lastModified)
{
m_lastModified = lastModified;
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::get_Icon(
HICON* icon)
{
ATLASSERT(icon != NULL);
if (icon == NULL)
{
return E_POINTER;
}
*icon = m_icon;
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::put_Icon(
HICON icon)
{
if(m_icon)
{
::DestroyIcon(m_icon);
m_icon = NULL;
}
m_icon = ::CopyIcon(icon);
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::get_UserData(
IUnknown** userData)
{
return m_userData.CopyTo(userData);
}
STDMETHODIMP CTabbedMDIChildModifiedItem::putref_UserData(
IUnknown* userData)
{
m_userData = userData;
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::get_ParentList(
ITabbedMDIChildModifiedList** parentList)
{
ATLASSERT(parentList != NULL);
if(parentList == NULL)
{
return E_POINTER;
}
*parentList = m_parentList;
if(m_parentList)
{
m_parentList->AddRef();
}
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::putref_ParentList(
ITabbedMDIChildModifiedList* parentList)
{
if( m_parentList != NULL && parentList != NULL &&
m_parentList != parentList)
{
// Neither the current nor the new parent list is NULL.
// Remove ourselves from the old parent (?)
// (doing so would mess up the current InsertList)
//long index = -1;
//m_parentList->get_Index(this, &index);
//if(index >= 0)
//{
// m_parentList->Remove(index);
//}
}
m_parentList = parentList;
return S_OK;
}
STDMETHODIMP CTabbedMDIChildModifiedItem::get_SubItems(
ITabbedMDIChildModifiedList** subItems)
{
// The first time they ask for the sub items, we'll create it.
HRESULT hr = S_OK;
if(m_subItems == NULL)
{
ATL::CComObject<CTabbedMDIChildModifiedList>* newSubItems = NULL;
hr = ATL::CComObject<CTabbedMDIChildModifiedList>::CreateInstance(&newSubItems);
if(newSubItems != NULL)
{
newSubItems->AddRef();
newSubItems->putref_ParentItem(this);
m_subItems = newSubItems;
newSubItems->Release();
}
}
return m_subItems.CopyTo(subItems);
}
STDMETHODIMP CTabbedMDIChildModifiedItem::CopyTo(
ITabbedMDIChildModifiedItem* destination)
{
if(destination == NULL)
{
return E_INVALIDARG;
}
destination->put_Window(m_window);
destination->put_Name(m_name);
destination->put_DisplayName(m_displayName);
destination->put_Description(m_description);
destination->put_LastModifiedUTC(m_lastModified);
destination->put_Icon(m_icon);
destination->putref_UserData(m_userData);
// The destination keeps its current parent
//destination->putref_ParentList(m_parentList);
ATL::CComPtr<ITabbedMDIChildModifiedList> subItems;
destination->get_SubItems(&subItems);
if(subItems)
{
subItems->Clear();
if(m_subItems)
{
subItems->InsertList(-1, m_subItems);
}
}
return S_OK;
}
// Methods not exposed over iterface
STDMETHODIMP CTabbedMDIChildModifiedItem::InitNew(HWND window,
const wchar_t* name, const wchar_t* displayName, const wchar_t* description,
DATE lastModified, HICON icon)
{
this->put_Window(window);
this->put_Name(name);
this->put_DisplayName(displayName);
this->put_Description(description);
this->put_LastModifiedUTC(lastModified);
this->put_Icon(icon);
return S_OK;
}
/////////////////////////////////////////////////////////////////////////////
// Global functions
HRESULT CreateTabbedMDIChildModifiedList(ITabbedMDIChildModifiedList** list)
{
HRESULT hr = E_NOINTERFACE;
ATL::CComObject<CTabbedMDIChildModifiedList>* newItemList = NULL;
hr = ATL::CComObject<CTabbedMDIChildModifiedList>::CreateInstance(&newItemList);
if(newItemList != NULL)
{
hr = newItemList->QueryInterface(list);
}
return hr;
}
HRESULT CreateTabbedMDIChildModifiedItem(HWND window,
const wchar_t* name, const wchar_t* displayName, const wchar_t* description,
DATE lastModified, HICON icon,
ITabbedMDIChildModifiedItem** item)
{
HRESULT hr = E_NOINTERFACE;
ATL::CComObject<CTabbedMDIChildModifiedItem>* newItem = NULL;
hr = ATL::CComObject<CTabbedMDIChildModifiedItem>::CreateInstance(&newItem);
if(newItem != NULL)
{
newItem->AddRef();
hr = newItem->InitNew(window, name, displayName, description, lastModified, icon);
if(SUCCEEDED(hr))
{
hr = newItem->QueryInterface(item);
}
newItem->Release();
}
return hr;
}
HRESULT CreateEmptyTabbedMDIChildModifiedItem(ITabbedMDIChildModifiedItem** item)
{
HRESULT hr = E_NOINTERFACE;
ATL::CComObject<CTabbedMDIChildModifiedItem>* newItem = NULL;
hr = ATL::CComObject<CTabbedMDIChildModifiedItem>::CreateInstance(&newItem);
if(newItem != NULL)
{
hr = newItem->QueryInterface(item);
}
return hr;
}
/////////////////////////////////////////////////////////////////////////////
// CSaveModifiedItemsDialog
#include "commctrl.h"
CSaveModifiedItemsDialog::CSaveModifiedItemsDialog(ITabbedMDIChildModifiedList* list, bool canCancel) :
m_modifiedList(list),
m_canCancel(canCancel),
m_haveAtLeastOneModifiedDate(false),
m_list(this, 1),
m_dialogIcon(NULL),
m_imageUnchecked(-1),
m_imageChecked(-1),
m_imageIndeterminate(-1),
m_trackColumnWidth(0),
m_trackColumnIndex(-1),
m_lastVisibleColumn(eColumn_Last)
{
for(int i=0; i<eColumn_Count; ++i)
{
m_showColumn[i] = true;
}
}
CSaveModifiedItemsDialog::~CSaveModifiedItemsDialog()
{
}
bool CSaveModifiedItemsDialog::HideColumn(ColumnIndex column)
{
ATLASSERT(((!m_header.IsWindow()) || (m_header.IsWindow() && m_header.GetItemCount() < 1)) &&
"Please call this before InitializeColumns().");
if(column < 0 || column > eColumn_Last || column == eColumn_Name)
{
ATLASSERT(0 && "Invalid column index");
return false;
}
m_showColumn[column] = false;
if(column == m_lastVisibleColumn)
{
// Find the new last visible column
while((m_lastVisibleColumn > 0) && !m_showColumn[m_lastVisibleColumn])
{
m_lastVisibleColumn = (ColumnIndex)((int)m_lastVisibleColumn-1);
}
}
return true;
}
LRESULT CSaveModifiedItemsDialog::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CenterWindow(GetParent());
this->InitializeControls();
this->InitializeValues();
// NOTE: We need to do this init after InitializeValues, in
// case the default size of any control changes
this->DlgResize_Init(true, true, WS_THICKFRAME | WS_CLIPCHILDREN);
return 1; // Let the dialog manager set initial focus
}
LRESULT CSaveModifiedItemsDialog::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
LONG dwListStyle = m_list.GetWindowLong(GWL_STYLE);
if((dwListStyle & LVS_SHAREIMAGELISTS) == LVS_SHAREIMAGELISTS)
{
// We're responsible for cleaning up the list view's image list
if(!m_images.IsNull())
{
m_images.Destroy();
}
}
if(!m_stateImages.IsNull())
{
m_stateImages.Destroy();
}
if(m_dialogIcon != NULL)
{
::DestroyIcon(m_dialogIcon);
m_dialogIcon = NULL;
}
if(m_list.IsWindow())
{
m_list.UnsubclassWindow();
}
// Be sure others see the message (especially DefWindowProc)
bHandled = FALSE;
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnYes(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if(m_modifiedList)
{
int count = m_list.GetItemCount();
for(int i=0; i<count; ++i)
{
CheckState checkState = this->GetTristateCheckState(i);
if(checkState == eCheckState_Unchecked)
{
ATL::CComQIPtr<ITabbedMDIChildModifiedItem> item(this->GetIUnknownForItem(i));
if(item)
{
ATL::CComPtr<ITabbedMDIChildModifiedList> parentList;
item->get_ParentList(&parentList);
if(parentList)
{
long index = -1;
parentList->get_Index(item, &index);
if(index >= 0)
{
parentList->Remove(index);
}
}
}
}
}
}
this->EndDialog(wID);
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnEndDialog(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
this->EndDialog(wID);
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnListViewInsertItem(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
bHandled = TRUE;
LPNMLISTVIEW pnmLV = (LPNMLISTVIEW)pnmh;
if(pnmLV != NULL)
{
// It'd be nice if they set the lParam of NMLISTVIEW, but they don't.
// Only iItem is valid
//LPARAM lParam = pnmLV->lParam;
//if(lParam != NULL)
//{
// // Keep an AddRef around for the item, and Release in OnDeleteItem
// ((IUnknown*)lParam)->AddRef();
//}
IUnknown* punk = this->GetIUnknownForItem(pnmLV->iItem);
if(punk)
{
// Keep an AddRef around for the item, and Release in OnDeleteItem
punk->AddRef();
}
}
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnListViewDeleteItem(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
bHandled = TRUE;
LPNMLISTVIEW pnmLV = (LPNMLISTVIEW)pnmh;
if(pnmLV != NULL)
{
LPARAM lParam = pnmLV->lParam;
if(lParam != NULL)
{
((IUnknown*)lParam)->Release();
pnmLV->lParam = 0;
}
}
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnListViewKeyDownToToggleCheck(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
NMLVKEYDOWN* keyDown = (NMLVKEYDOWN*)pnmh;
if(keyDown && keyDown->wVKey == VK_SPACE)
{
int item = m_list.GetNextItem(-1, LVNI_FOCUSED);
if(item != -1 && ::GetKeyState(VK_CONTROL) >= 0)
{
this->ToggleCheckState(item);
}
}
bHandled = FALSE;
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnListViewClickToToggleCheck(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
NMITEMACTIVATE* itemActivate = (NMITEMACTIVATE*)pnmh;
if(itemActivate)
{
LVHITTESTINFO lvh = { 0 };
lvh.pt = itemActivate->ptAction;
if(m_list.HitTest(&lvh) != -1 && lvh.flags == LVHT_ONITEMSTATEICON && ::GetKeyState(VK_CONTROL) >= 0)
{
this->ToggleCheckState(lvh.iItem);
}
}
bHandled = FALSE;
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnListViewEraseBackground(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// Erase the background in OnListViewPaint
return 1;
}
LRESULT CSaveModifiedItemsDialog::OnListViewPaint(UINT uMsg, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
if(wParam != NULL)
{
WTL::CMemDC memdc((HDC)wParam, NULL);
//memdc.FillSolidRect(&memdc.m_rc, ::GetSysColor(COLOR_WINDOW));
m_list.DefWindowProc(WM_ERASEBKGND, (WPARAM)memdc.m_hDC, 0);
m_list.DefWindowProc(uMsg, (WPARAM)memdc.m_hDC, 0);
if(m_header.IsWindow())
{
m_header.SendMessage(WM_PAINT, (WPARAM)memdc.m_hDC, 0);
m_header.ValidateRect(&memdc.m_rc);
}
}
else
{
WTL::CPaintDC dc(m_list);
WTL::CMemDC memdc(dc.m_hDC, &dc.m_ps.rcPaint);
//memdc.FillSolidRect(&dc.m_ps.rcPaint, ::GetSysColor(COLOR_WINDOW));
m_list.DefWindowProc(WM_ERASEBKGND, (WPARAM)memdc.m_hDC, 0);
m_list.DefWindowProc(uMsg, (WPARAM)memdc.m_hDC, 0);
if(m_header.IsWindow())
{
m_header.SendMessage(WM_PAINT, (WPARAM)memdc.m_hDC, 0);
m_header.ValidateRect(&dc.m_ps.rcPaint);
}
}
return 0;
}
//LRESULT CSaveModifiedItemsDialog::OnHeaderPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
//{
// if( wParam != NULL )
// {
// WTL::CMemDC memdc((HDC)wParam, NULL);
// memdc.FillSolidRect(&memdc.m_rc, ::GetSysColor(COLOR_BTNFACE));
// m_header.DefWindowProc( uMsg, (WPARAM)memdc.m_hDC, 0);
// }
// else
// {
// WTL::CPaintDC dc(m_header);
// WTL::CMemDC memdc(dc.m_hDC, &dc.m_ps.rcPaint);
// memdc.FillSolidRect(&dc.m_ps.rcPaint, ::GetSysColor(COLOR_BTNFACE));
// m_header.DefWindowProc( uMsg, (WPARAM)memdc.m_hDC, 0);
// }
// return 0;
//}
LRESULT CSaveModifiedItemsDialog::OnHeaderBeginTrack(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
NMHEADER* headerInfo = (NMHEADER*)pnmh;
if(headerInfo)
{
m_trackColumnIndex = headerInfo->iItem;
m_trackColumnWidth = m_list.GetColumnWidth(m_trackColumnIndex);
if( (m_trackColumnIndex < 0) ||
(m_trackColumnIndex >= m_lastVisibleColumn) ||
!m_showColumn[m_trackColumnIndex])
{
// Don't allow resizing on the last column,
// or on a column we are hiding
m_trackColumnIndex = -1;
bHandled = TRUE;
return TRUE;
}
}
bHandled = FALSE;
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnHeaderTrack(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& bHandled)
{
// NOTE: See http://support.microsoft.com/?kbid=183258
// "INFO: HDN_TRACK Notifications and Full Window Drag Style"
// We only get this if the HDS_FULLDRAG style is not set
// (in which case, we won't get HDN_ITEMCHANGING).
// If HDS_FULLDRAG is NOT set, the list view won't show the contents
// as the user is dragging the divider to resize a column.
// So we won't update the column widths as they drag,
// but will in "End Track" when they're done
bHandled = FALSE;
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnHeaderEndTrack(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
if((m_header.GetStyle() & HDS_FULLDRAG) == 0)
{
// HDS_FULLDRAG is not set, so the contents aren't updated as they
// drag the column header divider until they let up on the mouse.
NMHEADER* headerInfo = (NMHEADER*)pnmh;
if( headerInfo &&
headerInfo->pitem &&
(headerInfo->pitem->mask & HDI_WIDTH) == HDI_WIDTH)
{
if(m_trackColumnIndex == headerInfo->iItem)
{
int columnRight = headerInfo->iItem + 1;
// Find the first column to the right that isn't being hidden.
while((columnRight < m_lastVisibleColumn) && !m_showColumn[columnRight])
{
++columnRight;
}
if(columnRight <= m_lastVisibleColumn)
{
int widthLeft = headerInfo->pitem->cxy;
int widthRight = m_list.GetColumnWidth(columnRight);
int newWidth = widthRight - (widthLeft - m_trackColumnWidth);
if((widthLeft > eMinimumColumnWidth) && (newWidth > eMinimumColumnWidth))
{
// TODO: When making the right column bigger before the
// left column has gotten smaller, the scroll bars flash
// visible. Do something to prevent that.
m_list.SetColumnWidth(columnRight, newWidth);
m_trackColumnWidth = widthLeft;
}
else
{
headerInfo->pitem->cxy = m_trackColumnWidth;
}
}
}
}
}
m_list.Invalidate();
m_trackColumnIndex = -1;
m_trackColumnWidth = 0;
bHandled = FALSE;
return 0;
}
LRESULT CSaveModifiedItemsDialog::OnHeaderItemChanging(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
if((m_header.GetStyle() & HDS_FULLDRAG) == HDS_FULLDRAG)
{
// HDS_FULLDRAG is set, so the contents are updated as they
// drag the column header divider.
NMHEADER* headerInfo = (NMHEADER*)pnmh;
if( headerInfo &&
headerInfo->pitem &&
(headerInfo->pitem->mask & HDI_WIDTH) == HDI_WIDTH)
{
if(m_trackColumnIndex == headerInfo->iItem)
{
int columnRight = headerInfo->iItem + 1;
// Find the first column to the right that isn't being hidden.
while((columnRight < m_lastVisibleColumn) && !m_showColumn[columnRight])
{
++columnRight;
}