/
shlview.c
3764 lines (3165 loc) · 110 KB
/
shlview.c
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
/*
* ShellView
*
* Copyright 1998,1999 <juergen.schmied@debitel.net>
*
* This is the view visualizing the data provided by the shellfolder.
* No direct access to data from pidls should be done from here.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* FIXME: The order by part of the background context menu should be
* built according to the columns shown.
*
* FIXME: Load/Save the view state from/into the stream provided by
* the ShellBrowser
*
* FIXME: CheckToolbar: handle the "new folder" and "folder up" button
*
* FIXME: ShellView_FillList: consider sort orders
*
* FIXME: implement the drag and drop in the old (msg-based) way
*
* FIXME: when the ShellView_WndProc gets a WM_NCDESTROY should we do a
* Release() ???
*/
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#define COBJMACROS
#define NONAMELESSUNION
#include "windef.h"
#include "winerror.h"
#include "winbase.h"
#include "winnls.h"
#include "objbase.h"
#include "servprov.h"
#include "shlguid.h"
#include "wingdi.h"
#include "winuser.h"
#include "shlobj.h"
#include "shobjidl.h"
#include "undocshell.h"
#include "shresdef.h"
#include "wine/debug.h"
#include "docobj.h"
#include "pidl.h"
#include "shell32_main.h"
#include "shellfolder.h"
WINE_DEFAULT_DEBUG_CHANNEL(shell);
static const WCHAR SV_CLASS_NAME[] = {'S','H','E','L','L','D','L','L','_','D','e','f','V','i','e','w',0};
typedef struct
{ BOOL bIsAscending;
INT nHeaderID;
INT nLastHeaderID;
}LISTVIEW_SORT_INFO, *LPLISTVIEW_SORT_INFO;
typedef struct
{
IShellView3 IShellView3_iface;
IOleCommandTarget IOleCommandTarget_iface;
IDropTarget IDropTarget_iface;
IDropSource IDropSource_iface;
IViewObject IViewObject_iface;
IFolderView2 IFolderView2_iface;
IShellFolderView IShellFolderView_iface;
IShellFolderViewDual3 IShellFolderViewDual3_iface;
LONG ref;
IShellFolder* pSFParent;
IShellFolder2* pSF2Parent;
IShellBrowser* pShellBrowser;
ICommDlgBrowser* pCommDlgBrowser;
HWND hWnd; /* SHELLDLL_DefView */
HWND hWndList; /* ListView control */
HWND hWndParent;
FOLDERSETTINGS FolderSettings;
HMENU hMenu;
UINT uState;
UINT cidl;
LPITEMIDLIST *apidl;
LISTVIEW_SORT_INFO ListViewSortInfo;
ULONG hNotify; /* change notification handle */
HANDLE hAccel;
DWORD dwAspects;
DWORD dwAdvf;
IAdviseSink *pAdvSink;
IDropTarget* pCurDropTarget; /* The sub-item, which is currently dragged over */
IDataObject* pCurDataObject; /* The dragged data-object */
LONG iDragOverItem; /* Dragged over item's index, iff pCurDropTarget != NULL */
UINT cScrollDelay; /* Send a WM_*SCROLL msg every 250 ms during drag-scroll */
POINT ptLastMousePos; /* Mouse position at last DragOver call */
} IShellViewImpl;
static inline IShellViewImpl *impl_from_IShellView3(IShellView3 *iface)
{
return CONTAINING_RECORD(iface, IShellViewImpl, IShellView3_iface);
}
static inline IShellViewImpl *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
{
return CONTAINING_RECORD(iface, IShellViewImpl, IOleCommandTarget_iface);
}
static inline IShellViewImpl *impl_from_IDropTarget(IDropTarget *iface)
{
return CONTAINING_RECORD(iface, IShellViewImpl, IDropTarget_iface);
}
static inline IShellViewImpl *impl_from_IDropSource(IDropSource *iface)
{
return CONTAINING_RECORD(iface, IShellViewImpl, IDropSource_iface);
}
static inline IShellViewImpl *impl_from_IViewObject(IViewObject *iface)
{
return CONTAINING_RECORD(iface, IShellViewImpl, IViewObject_iface);
}
static inline IShellViewImpl *impl_from_IFolderView2(IFolderView2 *iface)
{
return CONTAINING_RECORD(iface, IShellViewImpl, IFolderView2_iface);
}
static inline IShellViewImpl *impl_from_IShellFolderView(IShellFolderView *iface)
{
return CONTAINING_RECORD(iface, IShellViewImpl, IShellFolderView_iface);
}
static inline IShellViewImpl *impl_from_IShellFolderViewDual3(IShellFolderViewDual3 *iface)
{
return CONTAINING_RECORD(iface, IShellViewImpl, IShellFolderViewDual3_iface);
}
/* ListView Header IDs */
#define LISTVIEW_COLUMN_NAME 0
#define LISTVIEW_COLUMN_SIZE 1
#define LISTVIEW_COLUMN_TYPE 2
#define LISTVIEW_COLUMN_TIME 3
#define LISTVIEW_COLUMN_ATTRIB 4
/*menu items */
#define IDM_VIEW_FILES (FCIDM_SHVIEWFIRST + 0x500)
#define IDM_VIEW_IDW (FCIDM_SHVIEWFIRST + 0x501)
#define IDM_MYFILEITEM (FCIDM_SHVIEWFIRST + 0x502)
#define ID_LISTVIEW 1
#define SHV_CHANGE_NOTIFY WM_USER + 0x1111
/*windowsx.h */
#define GET_WM_COMMAND_ID(wp, lp) LOWORD(wp)
#define GET_WM_COMMAND_HWND(wp, lp) (HWND)(lp)
#define GET_WM_COMMAND_CMD(wp, lp) HIWORD(wp)
/*
Items merged into the toolbar and the filemenu
*/
typedef struct
{ int idCommand;
int iImage;
int idButtonString;
int idMenuString;
BYTE bState;
BYTE bStyle;
} MYTOOLINFO, *LPMYTOOLINFO;
static const MYTOOLINFO Tools[] =
{
{ FCIDM_SHVIEW_BIGICON, 0, 0, IDS_VIEW_LARGE, TBSTATE_ENABLED, BTNS_BUTTON },
{ FCIDM_SHVIEW_SMALLICON, 0, 0, IDS_VIEW_SMALL, TBSTATE_ENABLED, BTNS_BUTTON },
{ FCIDM_SHVIEW_LISTVIEW, 0, 0, IDS_VIEW_LIST, TBSTATE_ENABLED, BTNS_BUTTON },
{ FCIDM_SHVIEW_REPORTVIEW, 0, 0, IDS_VIEW_DETAILS, TBSTATE_ENABLED, BTNS_BUTTON },
{ -1, 0, 0, 0, 0, 0}
};
typedef void (CALLBACK *PFNSHGETSETTINGSPROC)(LPSHELLFLAGSTATE lpsfs, DWORD dwMask);
/**********************************************************
*
* ##### helperfunctions for communication with ICommDlgBrowser #####
*/
static BOOL IsInCommDlg(IShellViewImpl * This)
{ return(This->pCommDlgBrowser != NULL);
}
static HRESULT IncludeObject(IShellViewImpl * This, LPCITEMIDLIST pidl)
{
HRESULT ret = S_OK;
if ( IsInCommDlg(This) )
{
TRACE("ICommDlgBrowser::IncludeObject pidl=%p\n", pidl);
ret = ICommDlgBrowser_IncludeObject(This->pCommDlgBrowser, (IShellView*)This, pidl);
TRACE("--0x%08x\n", ret);
}
return ret;
}
static HRESULT OnDefaultCommand(IShellViewImpl * This)
{
HRESULT ret = S_FALSE;
if (IsInCommDlg(This))
{
TRACE("ICommDlgBrowser::OnDefaultCommand\n");
ret = ICommDlgBrowser_OnDefaultCommand(This->pCommDlgBrowser, (IShellView*)This);
TRACE("-- returns %08x\n", ret);
}
return ret;
}
static HRESULT OnStateChange(IShellViewImpl * This, UINT uFlags)
{
HRESULT ret = S_FALSE;
if (IsInCommDlg(This))
{
TRACE("ICommDlgBrowser::OnStateChange flags=%x\n", uFlags);
ret = ICommDlgBrowser_OnStateChange(This->pCommDlgBrowser, (IShellView*)This, uFlags);
TRACE("--\n");
}
return ret;
}
/**********************************************************
* set the toolbar of the filedialog buttons
*
* - activates the buttons from the shellbrowser according to
* the view state
*/
static void CheckToolbar(IShellViewImpl * This)
{
LRESULT result;
TRACE("\n");
if (IsInCommDlg(This))
{
IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_CHECKBUTTON,
FCIDM_TB_SMALLICON, This->FolderSettings.ViewMode == FVM_LIST, &result);
IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_CHECKBUTTON,
FCIDM_TB_REPORTVIEW, This->FolderSettings.ViewMode == FVM_DETAILS, &result);
IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_ENABLEBUTTON,
FCIDM_TB_SMALLICON, TRUE, &result);
IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_ENABLEBUTTON,
FCIDM_TB_REPORTVIEW, TRUE, &result);
}
}
/**********************************************************
*
* ##### helperfunctions for initializing the view #####
*/
/**********************************************************
* change the style of the listview control
*/
static void SetStyle(IShellViewImpl * This, DWORD dwAdd, DWORD dwRemove)
{
DWORD tmpstyle;
TRACE("(%p)\n", This);
tmpstyle = GetWindowLongW(This->hWndList, GWL_STYLE);
SetWindowLongW(This->hWndList, GWL_STYLE, dwAdd | (tmpstyle & ~dwRemove));
}
static DWORD ViewModeToListStyle(UINT ViewMode)
{
DWORD dwStyle;
TRACE("%d\n", ViewMode);
switch (ViewMode)
{
case FVM_ICON: dwStyle = LVS_ICON; break;
case FVM_DETAILS: dwStyle = LVS_REPORT; break;
case FVM_SMALLICON: dwStyle = LVS_SMALLICON; break;
case FVM_LIST: dwStyle = LVS_LIST; break;
default:
{
FIXME("ViewMode %d not implemented\n", ViewMode);
dwStyle = LVS_LIST;
break;
}
}
return dwStyle;
}
/**********************************************************
* ShellView_CreateList()
*
* - creates the list view window
*/
static BOOL ShellView_CreateList (IShellViewImpl * This)
{ DWORD dwStyle, dwExStyle;
TRACE("%p\n",This);
dwStyle = WS_TABSTOP | WS_VISIBLE | WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
LVS_SHAREIMAGELISTS | LVS_EDITLABELS | LVS_ALIGNLEFT | LVS_AUTOARRANGE;
dwExStyle = WS_EX_CLIENTEDGE;
dwStyle |= ViewModeToListStyle(This->FolderSettings.ViewMode);
if (This->FolderSettings.fFlags & FWF_AUTOARRANGE) dwStyle |= LVS_AUTOARRANGE;
if (This->FolderSettings.fFlags & FWF_DESKTOP)
This->FolderSettings.fFlags |= FWF_NOCLIENTEDGE | FWF_NOSCROLL;
if (This->FolderSettings.fFlags & FWF_SINGLESEL) dwStyle |= LVS_SINGLESEL;
if (This->FolderSettings.fFlags & FWF_NOCLIENTEDGE)
dwExStyle &= ~WS_EX_CLIENTEDGE;
This->hWndList=CreateWindowExW( dwExStyle,
WC_LISTVIEWW,
NULL,
dwStyle,
0,0,0,0,
This->hWnd,
(HMENU)ID_LISTVIEW,
shell32_hInstance,
NULL);
if(!This->hWndList)
return FALSE;
This->ListViewSortInfo.bIsAscending = TRUE;
This->ListViewSortInfo.nHeaderID = -1;
This->ListViewSortInfo.nLastHeaderID = -1;
if (This->FolderSettings.fFlags & FWF_DESKTOP) {
/*
* FIXME: look at the registry value
* HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ListviewShadow
* and activate drop shadows if necessary
*/
if (0)
SendMessageW(This->hWndList, LVM_SETTEXTBKCOLOR, 0, CLR_NONE);
else
SendMessageW(This->hWndList, LVM_SETTEXTBKCOLOR, 0, GetSysColor(COLOR_DESKTOP));
SendMessageW(This->hWndList, LVM_SETTEXTCOLOR, 0, RGB(255,255,255));
}
/* UpdateShellSettings(); */
return TRUE;
}
/**********************************************************
* ShellView_InitList()
*
* - adds all needed columns to the shellview
*/
static void ShellView_InitList(IShellViewImpl *This)
{
IShellDetails *details = NULL;
HIMAGELIST big_icons, small_icons;
LVCOLUMNW lvColumn;
SHELLDETAILS sd;
WCHAR nameW[50];
HRESULT hr;
INT i;
TRACE("(%p)\n", This);
Shell_GetImageLists( &big_icons, &small_icons );
SendMessageW(This->hWndList, LVM_DELETEALLITEMS, 0, 0);
SendMessageW(This->hWndList, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)small_icons);
SendMessageW(This->hWndList, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)big_icons);
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
lvColumn.pszText = nameW;
if (!This->pSF2Parent)
{
hr = IShellFolder_QueryInterface(This->pSFParent, &IID_IShellDetails, (void**)&details);
if (hr != S_OK)
{
WARN("IShellFolder2/IShellDetails not supported\n");
return;
}
}
for (i = 0; 1; i++)
{
if (This->pSF2Parent)
hr = IShellFolder2_GetDetailsOf(This->pSF2Parent, NULL, i, &sd);
else
hr = IShellDetails_GetDetailsOf(details, NULL, i, &sd);
if (FAILED(hr)) break;
lvColumn.fmt = sd.fmt;
lvColumn.cx = sd.cxChar*8; /* chars->pixel */
StrRetToStrNW(nameW, sizeof(nameW)/sizeof(WCHAR), &sd.str, NULL);
SendMessageW(This->hWndList, LVM_INSERTCOLUMNW, i, (LPARAM) &lvColumn);
}
if (details) IShellDetails_Release(details);
}
/**********************************************************
* ShellView_CompareItems()
*
* NOTES
* internal, CALLBACK for DSA_Sort
*/
static INT CALLBACK ShellView_CompareItems(LPVOID lParam1, LPVOID lParam2, LPARAM lpData)
{
int ret;
TRACE("pidl1=%p pidl2=%p lpsf=%p\n", lParam1, lParam2, (LPVOID) lpData);
if(!lpData) return 0;
ret = (SHORT) SCODE_CODE(IShellFolder_CompareIDs((LPSHELLFOLDER)lpData, 0, (LPITEMIDLIST)lParam1, (LPITEMIDLIST)lParam2));
TRACE("ret=%i\n",ret);
return ret;
}
/*************************************************************************
* ShellView_ListViewCompareItems
*
* Compare Function for the Listview (FileOpen Dialog)
*
* PARAMS
* lParam1 [I] the first ItemIdList to compare with
* lParam2 [I] the second ItemIdList to compare with
* lpData [I] The column ID for the header Ctrl to process
*
* RETURNS
* A negative value if the first item should precede the second,
* a positive value if the first item should follow the second,
* or zero if the two items are equivalent
*
* NOTES
* FIXME: function does what ShellView_CompareItems is supposed to do.
* unify it and figure out how to use the undocumented first parameter
* of IShellFolder_CompareIDs to do the job this function does and
* move this code to IShellFolder.
* make LISTVIEW_SORT_INFO obsolete
* the way this function works is only usable if we had only
* filesystemfolders (25/10/99 jsch)
*/
static INT CALLBACK ShellView_ListViewCompareItems(LPVOID lParam1, LPVOID lParam2, LPARAM lpData)
{
INT nDiff=0;
FILETIME fd1, fd2;
char strName1[MAX_PATH], strName2[MAX_PATH];
BOOL bIsFolder1, bIsFolder2,bIsBothFolder;
LPITEMIDLIST pItemIdList1 = lParam1;
LPITEMIDLIST pItemIdList2 = lParam2;
LISTVIEW_SORT_INFO *pSortInfo = (LPLISTVIEW_SORT_INFO) lpData;
bIsFolder1 = _ILIsFolder(pItemIdList1);
bIsFolder2 = _ILIsFolder(pItemIdList2);
bIsBothFolder = bIsFolder1 && bIsFolder2;
/* When sorting between a File and a Folder, the Folder gets sorted first */
if( (bIsFolder1 || bIsFolder2) && !bIsBothFolder)
{
nDiff = bIsFolder1 ? -1 : 1;
}
else
{
/* Sort by Time: Folders or Files can be sorted */
if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_TIME)
{
_ILGetFileDateTime(pItemIdList1, &fd1);
_ILGetFileDateTime(pItemIdList2, &fd2);
nDiff = CompareFileTime(&fd2, &fd1);
}
/* Sort by Attribute: Folder or Files can be sorted */
else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_ATTRIB)
{
_ILGetFileAttributes(pItemIdList1, strName1, MAX_PATH);
_ILGetFileAttributes(pItemIdList2, strName2, MAX_PATH);
nDiff = lstrcmpiA(strName1, strName2);
}
/* Sort by FileName: Folder or Files can be sorted */
else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_NAME || bIsBothFolder)
{
/* Sort by Text */
_ILSimpleGetText(pItemIdList1, strName1, MAX_PATH);
_ILSimpleGetText(pItemIdList2, strName2, MAX_PATH);
nDiff = lstrcmpiA(strName1, strName2);
}
/* Sort by File Size, Only valid for Files */
else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_SIZE)
{
nDiff = (INT)(_ILGetFileSize(pItemIdList1, NULL, 0) - _ILGetFileSize(pItemIdList2, NULL, 0));
}
/* Sort by File Type, Only valid for Files */
else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_TYPE)
{
/* Sort by Type */
_ILGetFileType(pItemIdList1, strName1, MAX_PATH);
_ILGetFileType(pItemIdList2, strName2, MAX_PATH);
nDiff = lstrcmpiA(strName1, strName2);
}
}
/* If the Date, FileSize, FileType, Attrib was the same, sort by FileName */
if(nDiff == 0)
{
_ILSimpleGetText(pItemIdList1, strName1, MAX_PATH);
_ILSimpleGetText(pItemIdList2, strName2, MAX_PATH);
nDiff = lstrcmpiA(strName1, strName2);
}
if(!pSortInfo->bIsAscending)
{
nDiff = -nDiff;
}
return nDiff;
}
/**********************************************************
* LV_FindItemByPidl()
*/
static int LV_FindItemByPidl(
IShellViewImpl * This,
LPCITEMIDLIST pidl)
{
LVITEMW lvItem;
lvItem.iSubItem = 0;
lvItem.mask = LVIF_PARAM;
for(lvItem.iItem = 0;
SendMessageW(This->hWndList, LVM_GETITEMW, 0, (LPARAM) &lvItem);
lvItem.iItem++)
{
LPITEMIDLIST currentpidl = (LPITEMIDLIST) lvItem.lParam;
HRESULT hr = IShellFolder_CompareIDs(This->pSFParent, 0, pidl, currentpidl);
if(SUCCEEDED(hr) && !HRESULT_CODE(hr))
{
return lvItem.iItem;
}
}
return -1;
}
/**********************************************************
* LV_AddItem()
*/
static BOOLEAN LV_AddItem(IShellViewImpl * This, LPCITEMIDLIST pidl)
{
LVITEMW lvItem;
TRACE("(%p)(pidl=%p)\n", This, pidl);
lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; /*set the mask*/
lvItem.iItem = SendMessageW(This->hWndList, LVM_GETITEMCOUNT, 0, 0); /*add the item to the end of the list*/
lvItem.iSubItem = 0;
lvItem.lParam = (LPARAM) ILClone(ILFindLastID(pidl)); /*set the item's data*/
lvItem.pszText = LPSTR_TEXTCALLBACKW; /*get text on a callback basis*/
lvItem.iImage = I_IMAGECALLBACK; /*get the image on a callback basis*/
return ListView_InsertItemW(This->hWndList, &lvItem) != -1;
}
/**********************************************************
* LV_RenameItem()
*/
static BOOLEAN LV_RenameItem(IShellViewImpl * This, LPCITEMIDLIST pidlOld, LPCITEMIDLIST pidlNew )
{
int nItem;
LVITEMW lvItem;
TRACE("(%p)(pidlold=%p pidlnew=%p)\n", This, pidlOld, pidlNew);
nItem = LV_FindItemByPidl(This, ILFindLastID(pidlOld));
if ( -1 != nItem )
{
lvItem.mask = LVIF_PARAM; /* only the pidl */
lvItem.iItem = nItem;
SendMessageW(This->hWndList, LVM_GETITEMW, 0, (LPARAM) &lvItem);
SHFree((LPITEMIDLIST)lvItem.lParam);
lvItem.mask = LVIF_PARAM;
lvItem.iItem = nItem;
lvItem.lParam = (LPARAM) ILClone(ILFindLastID(pidlNew)); /* set the item's data */
SendMessageW(This->hWndList, LVM_SETITEMW, 0, (LPARAM) &lvItem);
SendMessageW(This->hWndList, LVM_UPDATE, nItem, 0);
return TRUE; /* FIXME: better handling */
}
return FALSE;
}
/**********************************************************
* ShellView_FillList()
*
* - gets the objectlist from the shellfolder
* - sorts the list
* - fills the list into the view
*/
static INT CALLBACK fill_list( LPVOID ptr, LPVOID arg )
{
LPITEMIDLIST pidl = ptr;
IShellViewImpl *This = arg;
/* in a commdlg This works as a filemask*/
if ( IncludeObject(This, pidl)==S_OK ) LV_AddItem(This, pidl);
SHFree(pidl);
return TRUE;
}
static HRESULT ShellView_FillList(IShellViewImpl *This)
{
IFolderView2 *folderview = &This->IFolderView2_iface;
LPENUMIDLIST pEnumIDList;
LPITEMIDLIST pidl;
DWORD fetched;
HRESULT hr;
HDPA hdpa;
TRACE("(%p)\n", This);
/* get the itemlist from the shfolder*/
hr = IShellFolder_EnumObjects(This->pSFParent, This->hWnd, SHCONTF_NONFOLDERS | SHCONTF_FOLDERS, &pEnumIDList);
if (hr != S_OK) return hr;
/* create a pointer array */
hdpa = DPA_Create(16);
if (!hdpa)
{
IEnumIDList_Release(pEnumIDList);
return E_OUTOFMEMORY;
}
/* copy the items into the array*/
while((S_OK == IEnumIDList_Next(pEnumIDList, 1, &pidl, &fetched)) && fetched)
{
if (DPA_InsertPtr(hdpa, DPA_GetPtrCount(hdpa), pidl) == -1)
{
SHFree(pidl);
}
}
/* sort the array */
DPA_Sort(hdpa, ShellView_CompareItems, (LPARAM)This->pSFParent);
IFolderView2_SetRedraw(folderview, FALSE);
DPA_DestroyCallback(hdpa, fill_list, This);
IFolderView2_SetRedraw(folderview, TRUE);
IEnumIDList_Release(pEnumIDList);
return S_OK;
}
/**********************************************************
* ShellView_OnCreate()
*/
static LRESULT ShellView_OnCreate(IShellViewImpl *This)
{
IShellView3 *iface = &This->IShellView3_iface;
static const WCHAR accel_nameW[] = {'s','h','v','_','a','c','c','e','l',0};
IPersistFolder2 *ppf2;
IDropTarget* pdt;
HRESULT hr;
TRACE("(%p)\n", This);
if (ShellView_CreateList(This))
{
ShellView_InitList(This);
ShellView_FillList(This);
}
hr = IShellView3_QueryInterface(iface, &IID_IDropTarget, (void**)&pdt);
if (hr == S_OK)
{
RegisterDragDrop(This->hWnd, pdt);
IDropTarget_Release(pdt);
}
/* register for receiving notifications */
hr = IShellFolder_QueryInterface(This->pSFParent, &IID_IPersistFolder2, (LPVOID*)&ppf2);
if (hr == S_OK)
{
LPITEMIDLIST raw_pidl;
SHChangeNotifyEntry ntreg;
hr = IPersistFolder2_GetCurFolder(ppf2, &raw_pidl);
if(SUCCEEDED(hr))
{
LPITEMIDLIST computer_pidl;
SHGetFolderLocation(NULL,CSIDL_DRIVES,NULL,0,&computer_pidl);
if(ILIsParent(computer_pidl,raw_pidl,FALSE))
{
/* Normalize the pidl to unixfs to workaround an issue with
* sending notifications on dos paths
*/
WCHAR path[MAX_PATH];
SHGetPathFromIDListW(raw_pidl,path);
SHParseDisplayName(path,NULL,(LPITEMIDLIST*)&ntreg.pidl,0,NULL);
SHFree(raw_pidl);
}
else
ntreg.pidl = raw_pidl;
ntreg.fRecursive = TRUE;
This->hNotify = SHChangeNotifyRegister(This->hWnd, SHCNRF_InterruptLevel, SHCNE_ALLEVENTS,
SHV_CHANGE_NOTIFY, 1, &ntreg);
SHFree((LPITEMIDLIST)ntreg.pidl);
SHFree(computer_pidl);
}
IPersistFolder2_Release(ppf2);
}
This->hAccel = LoadAcceleratorsW(shell32_hInstance, accel_nameW);
return S_OK;
}
/**********************************************************
* #### Handling of the menus ####
*/
/**********************************************************
* ShellView_BuildFileMenu()
*/
static HMENU ShellView_BuildFileMenu(IShellViewImpl * This)
{ WCHAR szText[MAX_PATH];
MENUITEMINFOW mii;
int nTools,i;
HMENU hSubMenu;
TRACE("(%p)\n",This);
hSubMenu = CreatePopupMenu();
if(hSubMenu)
{ /*get the number of items in our global array*/
for(nTools = 0; Tools[nTools].idCommand != -1; nTools++){}
/*add the menu items*/
for(i = 0; i < nTools; i++)
{
LoadStringW(shell32_hInstance, Tools[i].idMenuString, szText, MAX_PATH);
ZeroMemory(&mii, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
if(BTNS_SEP != Tools[i].bStyle) /* no separator*/
{
mii.fType = MFT_STRING;
mii.fState = MFS_ENABLED;
mii.dwTypeData = szText;
mii.wID = Tools[i].idCommand;
}
else
{
mii.fType = MFT_SEPARATOR;
}
/* tack This item onto the end of the menu */
InsertMenuItemW(hSubMenu, (UINT)-1, TRUE, &mii);
}
}
TRACE("-- return (menu=%p)\n",hSubMenu);
return hSubMenu;
}
/**********************************************************
* ShellView_MergeFileMenu()
*/
static void ShellView_MergeFileMenu(IShellViewImpl *This, HMENU hSubMenu)
{
TRACE("(%p)->(submenu=%p) stub\n",This,hSubMenu);
if (hSubMenu)
{
static const WCHAR dummyW[] = {'d','u','m','m','y','4','5',0};
MENUITEMINFOW mii;
/* insert This item at the beginning of the menu */
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_ID | MIIM_TYPE;
mii.wID = 0;
mii.fType = MFT_SEPARATOR;
InsertMenuItemW(hSubMenu, 0, TRUE, &mii);
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
mii.dwTypeData = (LPWSTR)dummyW;
mii.fState = MFS_ENABLED;
mii.wID = IDM_MYFILEITEM;
mii.fType = MFT_STRING;
InsertMenuItemW(hSubMenu, 0, TRUE, &mii);
}
TRACE("--\n");
}
/**********************************************************
* ShellView_MergeViewMenu()
*/
static void ShellView_MergeViewMenu(IShellViewImpl *This, HMENU hSubMenu)
{
TRACE("(%p)->(submenu=%p)\n",This,hSubMenu);
/* add a separator at the correct position in the menu */
if (hSubMenu)
{
static const WCHAR menuW[] = {'M','E','N','U','_','0','0','1',0};
static const WCHAR viewW[] = {'V','i','e','w',0};
MENUITEMINFOW mii;
memset(&mii, 0, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_ID | MIIM_TYPE;
mii.wID = 0;
mii.fType = MFT_SEPARATOR;
InsertMenuItemW(hSubMenu, FCIDM_MENU_VIEW_SEP_OPTIONS, FALSE, &mii);
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_DATA;
mii.fType = MFT_STRING;
mii.dwTypeData = (LPWSTR)viewW;
mii.hSubMenu = LoadMenuW(shell32_hInstance, menuW);
InsertMenuItemW(hSubMenu, FCIDM_MENU_VIEW_SEP_OPTIONS, FALSE, &mii);
}
}
/**********************************************************
* ShellView_GetSelections()
*
* - fills the this->apidl list with the selected objects
*
* RETURNS
* number of selected items
*/
static UINT ShellView_GetSelections(IShellViewImpl * This)
{
LVITEMW lvItem;
UINT i = 0;
SHFree(This->apidl);
This->cidl = SendMessageW(This->hWndList, LVM_GETSELECTEDCOUNT, 0, 0);
This->apidl = SHAlloc(This->cidl * sizeof(LPITEMIDLIST));
TRACE("selected=%i\n", This->cidl);
if(This->apidl)
{
TRACE("-- Items selected =%u\n", This->cidl);
lvItem.mask = LVIF_STATE | LVIF_PARAM;
lvItem.stateMask = LVIS_SELECTED;
lvItem.iItem = 0;
lvItem.iSubItem = 0;
while(ListView_GetItemW(This->hWndList, &lvItem) && (i < This->cidl))
{
if(lvItem.state & LVIS_SELECTED)
{
This->apidl[i] = (LPITEMIDLIST)lvItem.lParam;
i++;
TRACE("-- selected Item found\n");
}
lvItem.iItem++;
}
}
return This->cidl;
}
/**********************************************************
* ShellView_OpenSelectedItems()
*/
static HRESULT ShellView_OpenSelectedItems(IShellViewImpl * This)
{
static UINT CF_IDLIST = 0;
HRESULT hr;
IDataObject* selection;
FORMATETC fetc;
STGMEDIUM stgm;
LPIDA pIDList;
LPCITEMIDLIST parent_pidl;
WCHAR parent_path[MAX_PATH];
LPCWSTR parent_dir = NULL;
SFGAOF attribs;
int i;
if (0 == ShellView_GetSelections(This))
{
return S_OK;
}
hr = IShellFolder_GetUIObjectOf(This->pSFParent, This->hWnd, This->cidl,
(LPCITEMIDLIST*)This->apidl, &IID_IDataObject,
0, (LPVOID *)&selection);
if (FAILED(hr))
return hr;
if (0 == CF_IDLIST)
{
CF_IDLIST = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
}
fetc.cfFormat = CF_IDLIST;
fetc.ptd = NULL;
fetc.dwAspect = DVASPECT_CONTENT;
fetc.lindex = -1;
fetc.tymed = TYMED_HGLOBAL;
hr = IDataObject_QueryGetData(selection, &fetc);
if (FAILED(hr))
return hr;
hr = IDataObject_GetData(selection, &fetc, &stgm);
if (FAILED(hr))
return hr;
pIDList = GlobalLock(stgm.u.hGlobal);
parent_pidl = (LPCITEMIDLIST) ((LPBYTE)pIDList+pIDList->aoffset[0]);
hr = IShellFolder_GetAttributesOf(This->pSFParent, 1, &parent_pidl, &attribs);
if (SUCCEEDED(hr) && (attribs & SFGAO_FILESYSTEM) &&
SHGetPathFromIDListW(parent_pidl, parent_path))
{
parent_dir = parent_path;
}
for (i = pIDList->cidl; i > 0; --i)
{
LPCITEMIDLIST pidl;
pidl = (LPCITEMIDLIST)((LPBYTE)pIDList+pIDList->aoffset[i]);
attribs = SFGAO_FOLDER;
hr = IShellFolder_GetAttributesOf(This->pSFParent, 1, &pidl, &attribs);
if (SUCCEEDED(hr) && ! (attribs & SFGAO_FOLDER))
{
SHELLEXECUTEINFOW shexinfo;
shexinfo.cbSize = sizeof(SHELLEXECUTEINFOW);
shexinfo.fMask = SEE_MASK_INVOKEIDLIST; /* SEE_MASK_IDLIST is also possible. */
shexinfo.hwnd = NULL;
shexinfo.lpVerb = NULL;
shexinfo.lpFile = NULL;
shexinfo.lpParameters = NULL;
shexinfo.lpDirectory = parent_dir;
shexinfo.nShow = SW_NORMAL;
shexinfo.lpIDList = ILCombine(parent_pidl, pidl);
ShellExecuteExW(&shexinfo); /* Discard error/success info */
ILFree(shexinfo.lpIDList);
}
}
GlobalUnlock(stgm.u.hGlobal);
ReleaseStgMedium(&stgm);
IDataObject_Release(selection);
return S_OK;
}
/**********************************************************
* ShellView_DoContextMenu()
*/
static void ShellView_DoContextMenu(IShellViewImpl * This, WORD x, WORD y, BOOL bDefault)
{ UINT uCommand;
DWORD wFlags;
HMENU hMenu;
BOOL fExplore = FALSE;
HWND hwndTree = 0;
LPCONTEXTMENU pContextMenu = NULL;
CMINVOKECOMMANDINFO cmi;
TRACE("(%p)->(0x%08x 0x%08x 0x%08x) stub\n",This, x, y, bDefault);
/* look, what's selected and create a context menu object of it*/
if( ShellView_GetSelections(This) )
{
IShellFolder_GetUIObjectOf( This->pSFParent, This->hWndParent, This->cidl, (LPCITEMIDLIST*)This->apidl,
&IID_IContextMenu, NULL, (LPVOID *)&pContextMenu);
if(pContextMenu)