Made the buttons in the filedlg change when selecting a different
[wine] / dlls / shell32 / shlview.c
1 /*
2  *      ShellView
3  *
4  *      Copyright 1998,1999     <juergen.schmied@debitel.net>
5  *
6  *  FIXME: when the ShellView_WndProc gets a WM_NCDESTROY should we do a
7  *  Release() ??? 
8  *
9  *  FIXME: There is still a design problem in this implementation. 
10  *      This implementation is more or less ok for file system folders
11  *      but there are many more kinds of folders.
12  *      The shellview is not supposed to know much about the colums
13  *      appearing in the view. To fix this it should use the IShellFolder2
14  *      interface when possible to get the informations dynamically
15  *      this will take a lot of work to implemet and wont likely not
16  *      be done in near future
17  *      Please considder this when code new features. Mail me if you
18  *      are in doubt how to do things. (jsch 25/10/99)
19  *
20  * FIXME: Set the buttons in the filedialog according to the view state
21  */
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "servprov.h"
27 #include "wine/obj_base.h"
28 #include "wine/obj_shellfolder.h"
29 #include "wine/obj_shellview.h"
30 #include "wine/obj_oleview.h"
31 #include "wine/obj_commdlgbrowser.h"
32 #include "wine/obj_shellbrowser.h"
33 #include "wine/obj_dockingwindowframe.h"
34 #include "wine/obj_extracticon.h"
35 #include "wine/obj_dragdrop.h"
36 #include "wine/undocshell.h"
37 #include "shresdef.h"
38 #include "spy.h"
39 #include "debugtools.h"
40 #include "winerror.h"
41
42 #include "docobj.h"
43 #include "pidl.h"
44 #include "shell32_main.h"
45
46 DEFAULT_DEBUG_CHANNEL(shell)
47
48 typedef struct
49 {   BOOL    bIsAscending;
50     INT     nHeaderID;
51     INT     nLastHeaderID;
52 }LISTVIEW_SORT_INFO, *LPLISTVIEW_SORT_INFO;
53
54 typedef struct 
55 {       ICOM_VFIELD(IShellView);
56         DWORD           ref;
57         ICOM_VTABLE(IOleCommandTarget)* lpvtblOleCommandTarget;
58         ICOM_VTABLE(IDropTarget)*       lpvtblDropTarget;
59         ICOM_VTABLE(IDropSource)*       lpvtblDropSource;
60         ICOM_VTABLE(IViewObject)*       lpvtblViewObject;
61         IShellFolder*   pSFParent;
62         IShellBrowser*  pShellBrowser;
63         ICommDlgBrowser*        pCommDlgBrowser;
64         HWND            hWnd;
65         HWND            hWndList;
66         HWND            hWndParent;
67         FOLDERSETTINGS  FolderSettings;
68         HMENU           hMenu;
69         UINT            uState;
70         UINT            cidl;
71         LPITEMIDLIST    *apidl;
72         LISTVIEW_SORT_INFO ListViewSortInfo;
73 } IShellViewImpl;
74
75 static struct ICOM_VTABLE(IShellView) svvt;
76
77 static struct ICOM_VTABLE(IOleCommandTarget) ctvt;
78 #define _IOleCommandTarget_Offset ((int)(&(((IShellViewImpl*)0)->lpvtblOleCommandTarget))) 
79 #define _ICOM_THIS_From_IOleCommandTarget(class, name) class* This = (class*)(((char*)name)-_IOleCommandTarget_Offset); 
80
81 static struct ICOM_VTABLE(IDropTarget) dtvt;
82 #define _IDropTarget_Offset ((int)(&(((IShellViewImpl*)0)->lpvtblDropTarget))) 
83 #define _ICOM_THIS_From_IDropTarget(class, name) class* This = (class*)(((char*)name)-_IDropTarget_Offset); 
84
85 static struct ICOM_VTABLE(IDropSource) dsvt;
86 #define _IDropSource_Offset ((int)(&(((IShellViewImpl*)0)->lpvtblDropSource))) 
87 #define _ICOM_THIS_From_IDropSource(class, name) class* This = (class*)(((char*)name)-_IDropSource_Offset); 
88
89 static struct ICOM_VTABLE(IViewObject) vovt;
90 #define _IViewObject_Offset ((int)(&(((IShellViewImpl*)0)->lpvtblViewObject))) 
91 #define _ICOM_THIS_From_IViewObject(class, name) class* This = (class*)(((char*)name)-_IViewObject_Offset); 
92
93 /* ListView Header ID's */
94 #define LISTVIEW_COLUMN_NAME 0
95 #define LISTVIEW_COLUMN_SIZE 1
96 #define LISTVIEW_COLUMN_TYPE 2
97 #define LISTVIEW_COLUMN_TIME 3
98 #define LISTVIEW_COLUMN_ATTRIB 4
99
100 /*menu items */
101 #define IDM_VIEW_FILES  (FCIDM_SHVIEWFIRST + 0x500)
102 #define IDM_VIEW_IDW    (FCIDM_SHVIEWFIRST + 0x501)
103 #define IDM_MYFILEITEM  (FCIDM_SHVIEWFIRST + 0x502)
104
105 #define ID_LISTVIEW     2000
106
107 #define TOOLBAR_ID   (L"SHELLDLL_DefView")
108 /*windowsx.h */
109 #define GET_WM_COMMAND_ID(wp, lp)               LOWORD(wp)
110 #define GET_WM_COMMAND_HWND(wp, lp)             (HWND)(lp)
111 #define GET_WM_COMMAND_CMD(wp, lp)              HIWORD(wp)
112 /* winuser.h */
113 #define WM_SETTINGCHANGE                WM_WININICHANGE
114 extern void WINAPI _InsertMenuItem (HMENU hmenu, UINT indexMenu, BOOL fByPosition, 
115                         UINT wID, UINT fType, LPSTR dwTypeData, UINT fState);
116
117 /*
118   Items merged into the toolbar and and the filemenu
119 */
120 typedef struct
121 {  int   idCommand;
122    int   iImage;
123    int   idButtonString;
124    int   idMenuString;
125    BYTE  bState;
126    BYTE  bStyle;
127 } MYTOOLINFO, *LPMYTOOLINFO;
128
129 MYTOOLINFO Tools[] = 
130 {
131 { FCIDM_SHVIEW_BIGICON,    0, 0, IDS_VIEW_LARGE,   TBSTATE_ENABLED, TBSTYLE_BUTTON },
132 { FCIDM_SHVIEW_SMALLICON,  0, 0, IDS_VIEW_SMALL,   TBSTATE_ENABLED, TBSTYLE_BUTTON },
133 { FCIDM_SHVIEW_LISTVIEW,   0, 0, IDS_VIEW_LIST,    TBSTATE_ENABLED, TBSTYLE_BUTTON },
134 { FCIDM_SHVIEW_REPORTVIEW, 0, 0, IDS_VIEW_DETAILS, TBSTATE_ENABLED, TBSTYLE_BUTTON },
135 { -1, 0, 0, 0, 0, 0}
136 };
137
138 typedef void (CALLBACK *PFNSHGETSETTINGSPROC)(LPSHELLFLAGSTATE lpsfs, DWORD dwMask);
139
140 /**********************************************************
141  *      IShellView_Constructor
142  */
143 IShellView * IShellView_Constructor( IShellFolder * pFolder)
144 {       IShellViewImpl * sv;
145         sv=(IShellViewImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IShellViewImpl));
146         sv->ref=1;
147         ICOM_VTBL(sv)=&svvt;
148         sv->lpvtblOleCommandTarget=&ctvt;
149         sv->lpvtblDropTarget=&dtvt;
150         sv->lpvtblDropSource=&dsvt;
151         sv->lpvtblViewObject=&vovt;
152
153         sv->pSFParent   = pFolder;
154
155         if(pFolder)
156           IShellFolder_AddRef(pFolder);
157
158         TRACE("(%p)->(%p)\n",sv, pFolder);
159         shell32_ObjCount++;
160         return (IShellView *) sv;
161 }
162
163 /**********************************************************
164  *
165  * ##### helperfunctions for communication with ICommDlgBrowser #####
166  */
167 static BOOL IsInCommDlg(IShellViewImpl * This)
168 {       return(This->pCommDlgBrowser != NULL);
169 }
170
171 static HRESULT IncludeObject(IShellViewImpl * This, LPCITEMIDLIST pidl)
172 {
173         HRESULT ret = S_OK;
174         
175         if ( IsInCommDlg(This) )
176         {
177           TRACE("ICommDlgBrowser::IncludeObject pidl=%p\n", pidl);
178           ret = ICommDlgBrowser_IncludeObject(This->pCommDlgBrowser, (IShellView*)This, pidl);
179           TRACE("--0x%08lx\n", ret);
180         }
181         return ret;
182 }
183
184 static HRESULT OnDefaultCommand(IShellViewImpl * This)
185 {
186         HRESULT ret = S_FALSE;
187         
188         if (IsInCommDlg(This))
189         {
190           TRACE("ICommDlgBrowser::OnDefaultCommand\n");
191           ret = ICommDlgBrowser_OnDefaultCommand(This->pCommDlgBrowser, (IShellView*)This);
192           TRACE("--\n");
193         }
194         return ret;
195 }
196
197 static HRESULT OnStateChange(IShellViewImpl * This, UINT uFlags)
198 {
199         HRESULT ret = S_FALSE;
200
201         if (IsInCommDlg(This))
202         {
203           TRACE("ICommDlgBrowser::OnStateChange flags=%x\n", uFlags);
204           ret = ICommDlgBrowser_OnStateChange(This->pCommDlgBrowser, (IShellView*)This, uFlags);
205           TRACE("--\n");
206         }
207         return ret;
208 }
209 /**********************************************************
210  *      set the toolbar of the filedialog buttons
211  */
212 static void CheckToolbar(IShellViewImpl * This)
213 {
214         LRESULT result;
215
216         TRACE("\n");
217         
218         if (IsInCommDlg(This))
219         {
220           IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_CHECKBUTTON,
221                 FCIDM_TB_SMALLICON, (This->FolderSettings.ViewMode==FVM_LIST)? TRUE : FALSE, &result);
222           IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_CHECKBUTTON,
223                 FCIDM_TB_REPORTVIEW, (This->FolderSettings.ViewMode==FVM_DETAILS)? TRUE : FALSE, &result);
224           IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_ENABLEBUTTON,
225                 FCIDM_TB_SMALLICON, TRUE, &result);
226           IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_ENABLEBUTTON,
227                 FCIDM_TB_REPORTVIEW, TRUE, &result);
228         }
229 }
230
231 /**********************************************************
232  *
233  * ##### helperfunctions for initializing the view #####
234  */
235 /**********************************************************
236  *      change the style of the listview control
237  */
238 static void SetStyle(IShellViewImpl * This, DWORD dwAdd, DWORD dwRemove)
239 {
240         DWORD tmpstyle;
241
242         TRACE("(%p)\n", This);
243
244         tmpstyle = GetWindowLongA(This->hWndList, GWL_STYLE);
245         SetWindowLongA(This->hWndList, GWL_STYLE, dwAdd | (tmpstyle & ~dwRemove));
246 }
247
248 /**********************************************************
249 * ShellView_CreateList()
250 *
251 */
252 static BOOL ShellView_CreateList (IShellViewImpl * This)
253 {       DWORD dwStyle;
254
255         TRACE("%p\n",This);
256
257         dwStyle = WS_TABSTOP | WS_VISIBLE | WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
258                   LVS_SHAREIMAGELISTS | LVS_EDITLABELS | LVS_ALIGNLEFT | LVS_AUTOARRANGE;
259
260         switch (This->FolderSettings.ViewMode)
261         {
262           case FVM_ICON:        dwStyle |= LVS_ICON;            break;
263           case FVM_DETAILS:     dwStyle |= LVS_REPORT;          break;
264           case FVM_SMALLICON:   dwStyle |= LVS_SMALLICON;       break;
265           case FVM_LIST:        dwStyle |= LVS_LIST;            break;
266           default:              dwStyle |= LVS_LIST;            break;
267         }
268
269         if (This->FolderSettings.fFlags && FWF_AUTOARRANGE)     dwStyle |= LVS_AUTOARRANGE;
270         /*if (This->FolderSettings.fFlags && FWF_DESKTOP); used from explorer*/
271         if (This->FolderSettings.fFlags && FWF_SINGLESEL)       dwStyle |= LVS_SINGLESEL;
272
273         This->hWndList=CreateWindowExA( WS_EX_CLIENTEDGE,
274                                         WC_LISTVIEWA,
275                                         NULL,
276                                         dwStyle,
277                                         0,0,0,0,
278                                         This->hWnd,
279                                         (HMENU)ID_LISTVIEW,
280                                         shell32_hInstance,
281                                         NULL);
282
283         if(!This->hWndList)
284           return FALSE;
285
286         This->ListViewSortInfo.bIsAscending = TRUE;
287         This->ListViewSortInfo.nHeaderID = -1;
288         This->ListViewSortInfo.nLastHeaderID = -1;
289
290         /*  UpdateShellSettings(); */
291         return TRUE;
292 }
293 /**********************************************************
294 * ShellView_InitList()
295 *
296 * NOTES
297 *       FIXME: the headers should depend on the kind of shellfolder
298 *       thats creating the shellview. this hack implements only the
299 *       correct headers for a filesystem folder (jsch 25/10/99)
300 */
301 static BOOL ShellView_InitList(IShellViewImpl * This)
302 {
303         LVCOLUMNA lvColumn;
304         CHAR        szString[50];
305
306         TRACE("%p\n",This);
307
308         ListView_DeleteAllItems(This->hWndList);
309
310         /*initialize the columns */
311         lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;      /*  |  LVCF_SUBITEM;*/
312         lvColumn.fmt = LVCFMT_LEFT;
313         lvColumn.pszText = szString;
314
315         lvColumn.cx = 120;
316         LoadStringA(shell32_hInstance, IDS_SHV_COLUMN1, szString, sizeof(szString));
317         ListView_InsertColumnA(This->hWndList, 0, &lvColumn);
318
319         lvColumn.cx = 60;
320         LoadStringA(shell32_hInstance, IDS_SHV_COLUMN2, szString, sizeof(szString));
321         ListView_InsertColumnA(This->hWndList, 1, &lvColumn);
322
323         lvColumn.cx = 120;
324         LoadStringA(shell32_hInstance, IDS_SHV_COLUMN3, szString, sizeof(szString));
325         ListView_InsertColumnA(This->hWndList, 2, &lvColumn);
326
327         lvColumn.cx = 60;
328         LoadStringA(shell32_hInstance, IDS_SHV_COLUMN4, szString, sizeof(szString));
329         ListView_InsertColumnA(This->hWndList, 3, &lvColumn);
330
331         ListView_SetImageList(This->hWndList, ShellSmallIconList, LVSIL_SMALL);
332         ListView_SetImageList(This->hWndList, ShellBigIconList, LVSIL_NORMAL);
333
334         return TRUE;
335 }
336 /**********************************************************
337 * ShellView_CompareItems() 
338 *
339 * NOTES
340 *  internal, CALLBACK for DSA_Sort
341 */   
342 static INT CALLBACK ShellView_CompareItems(LPVOID lParam1, LPVOID lParam2, LPARAM lpData)
343 {
344         int ret;
345         TRACE("pidl1=%p pidl2=%p lpsf=%p\n", lParam1, lParam2, (LPVOID) lpData);
346
347         if(!lpData) return 0;
348
349         ret =  (SHORT) SCODE_CODE(IShellFolder_CompareIDs((LPSHELLFOLDER)lpData, 0, (LPITEMIDLIST)lParam1, (LPITEMIDLIST)lParam2));  
350         TRACE("ret=%i\n",ret);
351         return ret;
352 }
353
354 /*************************************************************************
355  * ShellView_ListViewCompareItems
356  *
357  * Compare Function for the Listview (FileOpen Dialog)
358  *
359  * PARAMS
360  *     lParam1       [I] the first ItemIdList to compare with
361  *     lParam2       [I] the second ItemIdList to compare with
362  *     lpData        [I] The column ID for the header Ctrl to process
363  *
364  * RETURNS
365  *     A negative value if the first item should precede the second, 
366  *     a positive value if the first item should follow the second, 
367  *     or zero if the two items are equivalent
368  *
369  * NOTES
370  *      FIXME: function does what ShellView_CompareItems is supposed to do.
371  *      unify it and figure out how to use the undocumented first parameter
372  *      of IShellFolder_CompareIDs to do the job this function does and
373  *      move this code to IShellFolder. 
374  *      make LISTVIEW_SORT_INFO obsolete
375  *      the way this function works is only usable if we had only 
376  *      filesystemfolders  (25/10/99 jsch)
377  */
378 static INT CALLBACK ShellView_ListViewCompareItems(LPVOID lParam1, LPVOID lParam2, LPARAM lpData)
379 {
380     INT nDiff=0;
381     FILETIME fd1, fd2;
382     char strName1[MAX_PATH], strName2[MAX_PATH];
383     BOOL bIsFolder1, bIsFolder2,bIsBothFolder;
384     LPITEMIDLIST pItemIdList1 = (LPITEMIDLIST) lParam1;
385     LPITEMIDLIST pItemIdList2 = (LPITEMIDLIST) lParam2;
386     LISTVIEW_SORT_INFO *pSortInfo = (LPLISTVIEW_SORT_INFO) lpData;
387
388
389     bIsFolder1 = _ILIsFolder(pItemIdList1);
390     bIsFolder2 = _ILIsFolder(pItemIdList2);
391     bIsBothFolder = bIsFolder1 && bIsFolder2;
392
393     /* When sorting between a File and a Folder, the Folder gets sorted first */
394     if( (bIsFolder1 || bIsFolder2) && !bIsBothFolder)
395     {
396         nDiff = bIsFolder1 ? -1 : 1;
397     }
398     else
399     {   
400         /* Sort by Time: Folders or Files can be sorted */
401  
402         if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_TIME)
403         {
404             _ILGetFileDateTime(pItemIdList1, &fd1);
405             _ILGetFileDateTime(pItemIdList2, &fd2);
406             nDiff = CompareFileTime(&fd2, &fd1);
407         }
408         /* Sort by Attribute: Folder or Files can be sorted */
409         else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_ATTRIB)
410         {
411             _ILGetAttributeStr(pItemIdList1, strName1, MAX_PATH);
412             _ILGetAttributeStr(pItemIdList2, strName2, MAX_PATH);
413             nDiff = strcasecmp(strName1, strName2);
414         }
415         /* Sort by FileName: Folder or Files can be sorted */
416         else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_NAME || bIsBothFolder)
417         {
418             /* Sort by Text */
419             _ILSimpleGetText(pItemIdList1, strName1, MAX_PATH);
420             _ILSimpleGetText(pItemIdList2, strName2, MAX_PATH);
421             nDiff = strcasecmp(strName1, strName2);
422         }
423         /* Sort by File Size, Only valid for Files */
424         else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_SIZE)
425         {
426             nDiff = (INT)(_ILGetFileSize(pItemIdList1, NULL, 0) - _ILGetFileSize(pItemIdList2, NULL, 0));
427         }
428         /* Sort by File Type, Only valid for Files */
429         else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_TYPE)
430         {
431             /* Sort by Type */
432             _ILGetFileType(pItemIdList1, strName1, MAX_PATH);
433             _ILGetFileType(pItemIdList2, strName2, MAX_PATH);
434             nDiff = strcasecmp(strName1, strName2);
435         }
436     }
437     /*  If the Date, FileSize, FileType, Attrib was the same, sort by FileName */
438         
439     if(nDiff == 0)
440     {
441         _ILSimpleGetText(pItemIdList1, strName1, MAX_PATH);
442         _ILSimpleGetText(pItemIdList2, strName2, MAX_PATH);
443         nDiff = strcasecmp(strName1, strName2);
444     }
445
446     if(!pSortInfo->bIsAscending)
447     {
448         nDiff = -nDiff;
449     }
450
451     return nDiff;
452
453 }
454
455 /**********************************************************
456 * ShellView_FillList()
457 *
458 * NOTES
459 *  internal
460 */   
461
462 static HRESULT ShellView_FillList(IShellViewImpl * This)
463 {
464         LPENUMIDLIST    pEnumIDList;
465         LPITEMIDLIST    pidl;
466         DWORD           dwFetched;
467         UINT            i;
468         LVITEMA lvItem;
469         HRESULT         hRes;
470         HDPA            hdpa;
471
472         TRACE("%p\n",This);
473
474         /* get the itemlist from the shfolder*/  
475         hRes = IShellFolder_EnumObjects(This->pSFParent,This->hWnd, SHCONTF_NONFOLDERS | SHCONTF_FOLDERS, &pEnumIDList);
476         if (hRes != S_OK)
477         {
478           if (hRes==S_FALSE)
479             return(NOERROR);
480           return(hRes);
481         }
482
483         /* create a pointer array */    
484         hdpa = pDPA_Create(16);
485         if (!hdpa)
486         {
487           return(E_OUTOFMEMORY);
488         }
489
490         /* copy the items into the array*/
491         while((S_OK == IEnumIDList_Next(pEnumIDList,1, &pidl, &dwFetched)) && dwFetched)
492         {
493           if (pDPA_InsertPtr(hdpa, 0x7fff, pidl) == -1)
494           {
495             SHFree(pidl);
496           } 
497         }
498
499         /*sort the array*/
500         pDPA_Sort(hdpa, ShellView_CompareItems, (LPARAM)This->pSFParent);
501
502         /*turn the listview's redrawing off*/
503         SendMessageA(This->hWndList, WM_SETREDRAW, FALSE, 0); 
504
505         for (i=0; i < DPA_GetPtrCount(hdpa); ++i)       /* DPA_GetPtrCount is a macro*/
506         {
507           pidl = (LPITEMIDLIST)DPA_GetPtr(hdpa, i);
508           if (IncludeObject(This, pidl) == S_OK)        /* in a commdlg This works as a filemask*/
509           {
510             ZeroMemory(&lvItem, sizeof(lvItem));        /* create the listviewitem*/
511             lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;          /*set the mask*/
512             lvItem.iItem = ListView_GetItemCount(This->hWndList);       /*add the item to the end of the list*/
513             lvItem.lParam = (LPARAM) pidl;                              /*set the item's data*/
514             lvItem.pszText = LPSTR_TEXTCALLBACKA;                       /*get text on a callback basis*/
515             lvItem.iImage = I_IMAGECALLBACK;                            /*get the image on a callback basis*/
516             ListView_InsertItemA(This->hWndList, &lvItem);
517           }
518           else
519             SHFree(pidl);       /* the listview has the COPY*/
520         }
521
522         /*turn the listview's redrawing back on and force it to draw*/
523         SendMessageA(This->hWndList, WM_SETREDRAW, TRUE, 0);
524         InvalidateRect(This->hWndList, NULL, TRUE);
525         UpdateWindow(This->hWndList);
526
527         IEnumIDList_Release(pEnumIDList); /* destroy the list*/
528         pDPA_Destroy(hdpa);
529         
530         return S_OK;
531 }
532
533 /**********************************************************
534 *  ShellView_OnCreate()
535 */   
536 static LRESULT ShellView_OnCreate(IShellViewImpl * This)
537 {
538 #if 0
539         IDropTarget* pdt;
540 #endif
541         TRACE("%p\n",This);
542
543         if(ShellView_CreateList(This))
544         {
545           if(ShellView_InitList(This))
546           {
547             ShellView_FillList(This);
548           }
549         }
550         
551 #if 0
552         /* This makes a chrash since we havn't called OleInititialize. But if we
553         do this call in DllMain it breaks some apps. The native shell32 does not 
554         call OleInitialize and not even depend on ole32.dll. 
555         But for some apps it works...*/
556         if (SUCCEEDED(IShellFolder_CreateViewObject(This->pSFParent, This->hWnd, &IID_IDropTarget, (LPVOID*)&pdt)))
557         {
558           pRegisterDragDrop(This->hWnd, pdt);
559           IDropTarget_Release(pdt);
560         }
561 #endif
562         return S_OK;
563 }
564
565 /**********************************************************
566  *      #### Handling of the menus ####
567  */
568
569 /**********************************************************
570 * ShellView_BuildFileMenu()
571 */
572 static HMENU ShellView_BuildFileMenu(IShellViewImpl * This)
573 {       CHAR    szText[MAX_PATH];
574         MENUITEMINFOA   mii;
575         int     nTools,i;
576         HMENU   hSubMenu;
577
578         TRACE("(%p)\n",This);
579
580         hSubMenu = CreatePopupMenu();
581         if(hSubMenu)
582         { /*get the number of items in our global array*/
583           for(nTools = 0; Tools[nTools].idCommand != -1; nTools++){}
584
585           /*add the menu items*/
586           for(i = 0; i < nTools; i++)
587           { 
588             LoadStringA(shell32_hInstance, Tools[i].idMenuString, szText, MAX_PATH);
589
590             ZeroMemory(&mii, sizeof(mii));
591             mii.cbSize = sizeof(mii);
592             mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
593
594             if(TBSTYLE_SEP != Tools[i].bStyle) /* no seperator*/
595             {
596               mii.fType = MFT_STRING;
597               mii.fState = MFS_ENABLED;
598               mii.dwTypeData = szText;
599               mii.wID = Tools[i].idCommand;
600             }
601             else
602             {
603               mii.fType = MFT_SEPARATOR;
604             }
605             /* tack This item onto the end of the menu */
606             InsertMenuItemA(hSubMenu, (UINT)-1, TRUE, &mii);
607           }
608         }
609         TRACE("-- return (menu=0x%x)\n",hSubMenu);
610         return hSubMenu;
611 }
612 /**********************************************************
613 * ShellView_MergeFileMenu()
614 */
615 static void ShellView_MergeFileMenu(IShellViewImpl * This, HMENU hSubMenu)
616 {       TRACE("(%p)->(submenu=0x%08x) stub\n",This,hSubMenu);
617
618         if(hSubMenu)
619         { /*insert This item at the beginning of the menu */
620           _InsertMenuItem(hSubMenu, 0, TRUE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED);
621           _InsertMenuItem(hSubMenu, 0, TRUE, IDM_MYFILEITEM, MFT_STRING, "dummy45", MFS_ENABLED);
622
623         }
624         TRACE("--\n");  
625 }
626
627 /**********************************************************
628 * ShellView_MergeViewMenu()
629 */
630
631 static void ShellView_MergeViewMenu(IShellViewImpl * This, HMENU hSubMenu)
632 {       MENUITEMINFOA   mii;
633
634         TRACE("(%p)->(submenu=0x%08x)\n",This,hSubMenu);
635
636         if(hSubMenu)
637         { /*add a separator at the correct position in the menu*/
638           _InsertMenuItem(hSubMenu, FCIDM_MENU_VIEW_SEP_OPTIONS, FALSE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED);
639
640           ZeroMemory(&mii, sizeof(mii));
641           mii.cbSize = sizeof(mii);
642           mii.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_DATA;;
643           mii.fType = MFT_STRING;
644           mii.dwTypeData = "View";
645           mii.hSubMenu = LoadMenuA(shell32_hInstance, "MENU_001");
646           InsertMenuItemA(hSubMenu, FCIDM_MENU_VIEW_SEP_OPTIONS, FALSE, &mii);
647         }
648 }
649
650 /**********************************************************
651 *   ShellView_GetSelections()
652 *
653 * RETURNS
654 *  number of selected items
655 */   
656 static UINT ShellView_GetSelections(IShellViewImpl * This)
657 {
658         LVITEMA lvItem;
659         UINT    i = 0;
660
661         if (This->apidl)
662         {
663           SHFree(This->apidl);
664         }
665
666         This->cidl = ListView_GetSelectedCount(This->hWndList);
667         This->apidl = (LPITEMIDLIST*)SHAlloc(This->cidl * sizeof(LPITEMIDLIST));
668
669         TRACE("selected=%i\n", This->cidl);
670         
671         if(This->apidl)
672         {
673           TRACE("-- Items selected =%u\n", This->cidl);
674
675           ZeroMemory(&lvItem, sizeof(lvItem));
676           lvItem.mask = LVIF_STATE | LVIF_PARAM;
677           lvItem.stateMask = LVIS_SELECTED;
678
679           while(ListView_GetItemA(This->hWndList, &lvItem) && (i < This->cidl))
680           {
681             if(lvItem.state & LVIS_SELECTED)
682             {
683               This->apidl[i] = (LPITEMIDLIST)lvItem.lParam;
684               i++;
685               TRACE("-- selected Item found\n");
686             }
687             lvItem.iItem++;
688           }
689         }
690         return This->cidl;
691
692 }
693 /**********************************************************
694  *      ShellView_DoContextMenu()
695  */
696 static void ShellView_DoContextMenu(IShellViewImpl * This, WORD x, WORD y, BOOL bDefault)
697 {       UINT    uCommand;
698         DWORD   wFlags;
699         HMENU   hMenu;
700         BOOL    fExplore = FALSE;
701         HWND    hwndTree = 0;
702         LPCONTEXTMENU   pContextMenu = NULL;
703         IContextMenu *  pCM = NULL;
704         CMINVOKECOMMANDINFO     cmi;
705         
706         TRACE("(%p)->(0x%08x 0x%08x 0x%08x) stub\n",This, x, y, bDefault);
707
708         /* look, what's selected and create a context menu object of it*/
709         if( ShellView_GetSelections(This) )
710         {
711           IShellFolder_GetUIObjectOf( This->pSFParent, This->hWndParent, This->cidl, This->apidl, 
712                                         (REFIID)&IID_IContextMenu, NULL, (LPVOID *)&pContextMenu);
713
714           if(pContextMenu)
715           {
716             TRACE("-- pContextMenu\n");
717             hMenu = CreatePopupMenu();
718
719             if( hMenu )
720             {
721               /* See if we are in Explore or Open mode. If the browser's tree is present, we are in Explore mode.*/
722               if(SUCCEEDED(IShellBrowser_GetControlWindow(This->pShellBrowser,FCW_TREE, &hwndTree)) && hwndTree)
723               {
724                 TRACE("-- explore mode\n");
725                 fExplore = TRUE;
726               }
727
728               /* build the flags depending on what we can do with the selected item */
729               wFlags = CMF_NORMAL | (This->cidl != 1 ? 0 : CMF_CANRENAME) | (fExplore ? CMF_EXPLORE : 0);
730
731               /* let the ContextMenu merge its items in */
732               if (SUCCEEDED(IContextMenu_QueryContextMenu( pContextMenu, hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, wFlags )))
733               {
734                 if( bDefault )
735                 {
736                   TRACE("-- get menu default command\n");
737                   uCommand = GetMenuDefaultItem(hMenu, FALSE, GMDI_GOINTOPOPUPS);
738                 }
739                 else
740                 {
741                   TRACE("-- track popup\n");
742                   uCommand = TrackPopupMenu( hMenu,TPM_LEFTALIGN | TPM_RETURNCMD,x,y,0,This->hWnd,NULL);
743                 }               
744
745                 if(uCommand > 0)
746                 {
747                   TRACE("-- uCommand=%u\n", uCommand);
748                   if (IsInCommDlg(This) && ((uCommand==IDM_EXPLORE) || (uCommand==IDM_OPEN)))
749                   {
750                     TRACE("-- dlg: OnDefaultCommand\n");
751                     OnDefaultCommand(This);
752                   }
753                   else
754                   {
755                     TRACE("-- explore -- invoke command\n");
756                     ZeroMemory(&cmi, sizeof(cmi));
757                     cmi.cbSize = sizeof(cmi);
758                     cmi.hwnd = This->hWndParent;
759                     cmi.lpVerb = (LPCSTR)MAKEINTRESOURCEA(uCommand);
760                     IContextMenu_InvokeCommand(pContextMenu, &cmi);
761                   }
762                 }
763                 DestroyMenu(hMenu);
764               }
765             }
766             if (pContextMenu)
767               IContextMenu_Release(pContextMenu);
768           }
769         }
770         else    /* background context menu */
771         { 
772           hMenu = CreatePopupMenu();
773
774           pCM = ISvBgCm_Constructor();
775           IContextMenu_QueryContextMenu(pCM, hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, 0);
776
777           uCommand = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_RETURNCMD,x,y,0,This->hWnd,NULL);
778           DestroyMenu(hMenu);
779
780           TRACE("-- (%p)->(uCommand=0x%08x )\n",This, uCommand);
781
782           ZeroMemory(&cmi, sizeof(cmi));
783           cmi.cbSize = sizeof(cmi);
784           cmi.lpVerb = (LPCSTR)MAKEINTRESOURCEA(uCommand);
785           cmi.hwnd = This->hWndParent;
786           IContextMenu_InvokeCommand(pCM, &cmi);
787
788           IContextMenu_Release(pCM);
789         }
790 }
791
792 /**********************************************************
793  *      ##### message handling #####
794  */
795
796 /**********************************************************
797 *  ShellView_OnSize()
798 */
799 static LRESULT ShellView_OnSize(IShellViewImpl * This, WORD wWidth, WORD wHeight)
800 {
801         TRACE("%p width=%u height=%u\n",This, wWidth,wHeight);
802
803         /*resize the ListView to fit our window*/
804         if(This->hWndList)
805         {
806           MoveWindow(This->hWndList, 0, 0, wWidth, wHeight, TRUE);
807         }
808
809         return S_OK;
810 }
811 /**********************************************************
812 * ShellView_OnDeactivate()
813 *
814 * NOTES
815 *  internal
816 */   
817 static void ShellView_OnDeactivate(IShellViewImpl * This)
818 {
819         TRACE("%p\n",This);
820
821         if(This->uState != SVUIA_DEACTIVATE)
822         {
823           if(This->hMenu)
824           {
825             IShellBrowser_SetMenuSB(This->pShellBrowser,0, 0, 0);
826             IShellBrowser_RemoveMenusSB(This->pShellBrowser,This->hMenu);
827             DestroyMenu(This->hMenu);
828             This->hMenu = 0;
829           }
830
831           This->uState = SVUIA_DEACTIVATE;
832         }
833 }
834
835 /**********************************************************
836 * ShellView_OnActivate()
837 */   
838 static LRESULT ShellView_OnActivate(IShellViewImpl * This, UINT uState)
839 {       OLEMENUGROUPWIDTHS   omw = { {0, 0, 0, 0, 0, 0} };
840         MENUITEMINFOA         mii;
841         CHAR                szText[MAX_PATH];
842
843         TRACE("%p uState=%x\n",This,uState);    
844
845         /*don't do anything if the state isn't really changing */
846         if(This->uState == uState)
847         {
848           return S_OK;
849         }
850
851         ShellView_OnDeactivate(This);
852
853         /*only do This if we are active */
854         if(uState != SVUIA_DEACTIVATE)
855         {
856           /*merge the menus */
857           This->hMenu = CreateMenu();
858
859           if(This->hMenu)
860           {
861             IShellBrowser_InsertMenusSB(This->pShellBrowser, This->hMenu, &omw);
862             TRACE("-- after fnInsertMenusSB\n");    
863
864             /*build the top level menu get the menu item's text*/
865             strcpy(szText,"dummy 31");
866
867             ZeroMemory(&mii, sizeof(mii));
868             mii.cbSize = sizeof(mii);
869             mii.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_STATE;
870             mii.fType = MFT_STRING;
871             mii.fState = MFS_ENABLED;
872             mii.dwTypeData = szText;
873             mii.hSubMenu = ShellView_BuildFileMenu(This);
874
875             /*insert our menu into the menu bar*/
876             if(mii.hSubMenu)
877             {
878               InsertMenuItemA(This->hMenu, FCIDM_MENU_HELP, FALSE, &mii);
879             }
880
881             /*get the view menu so we can merge with it*/
882             ZeroMemory(&mii, sizeof(mii));
883             mii.cbSize = sizeof(mii);
884             mii.fMask = MIIM_SUBMENU;
885
886             if(GetMenuItemInfoA(This->hMenu, FCIDM_MENU_VIEW, FALSE, &mii))
887             {
888               ShellView_MergeViewMenu(This, mii.hSubMenu);
889             }
890
891             /*add the items that should only be added if we have the focus*/
892             if(SVUIA_ACTIVATE_FOCUS == uState)
893             {
894               /*get the file menu so we can merge with it */
895               ZeroMemory(&mii, sizeof(mii));
896               mii.cbSize = sizeof(mii);
897               mii.fMask = MIIM_SUBMENU;
898
899               if(GetMenuItemInfoA(This->hMenu, FCIDM_MENU_FILE, FALSE, &mii))
900               {
901                 ShellView_MergeFileMenu(This, mii.hSubMenu);
902               }
903             }
904             TRACE("-- before fnSetMenuSB\n");      
905             IShellBrowser_SetMenuSB(This->pShellBrowser, This->hMenu, 0, This->hWnd);
906           }
907         }
908         This->uState = uState;
909         TRACE("--\n");    
910         return S_OK;
911 }
912
913 /**********************************************************
914 *  ShellView_OnSetFocus()
915 *
916 */
917 static LRESULT ShellView_OnSetFocus(IShellViewImpl * This)
918 {
919         TRACE("%p\n",This);
920
921         /* Tell the browser one of our windows has received the focus. This
922         should always be done before merging menus (OnActivate merges the 
923         menus) if one of our windows has the focus.*/
924
925         IShellBrowser_OnViewWindowActive(This->pShellBrowser,(IShellView*) This);
926         ShellView_OnActivate(This, SVUIA_ACTIVATE_FOCUS);
927
928         /* Set the focus to the listview */
929         SetFocus(This->hWndList);
930
931         /* Notify the ICommDlgBrowser interface */
932         OnStateChange(This,CDBOSC_SETFOCUS);
933
934         return 0;
935 }
936
937 /**********************************************************
938 * ShellView_OnKillFocus()
939 */   
940 static LRESULT ShellView_OnKillFocus(IShellViewImpl * This)
941 {
942         TRACE("(%p) stub\n",This);
943
944         ShellView_OnActivate(This, SVUIA_ACTIVATE_NOFOCUS);
945         /* Notify the ICommDlgBrowser */
946         OnStateChange(This,CDBOSC_KILLFOCUS);
947
948         return 0;
949 }
950
951 /**********************************************************
952 * ShellView_OnCommand()
953 *
954 * NOTES
955 *       the CmdID's are the ones from the context menu
956 */   
957 static LRESULT ShellView_OnCommand(IShellViewImpl * This,DWORD dwCmdID, DWORD dwCmd, HWND hwndCmd)
958 {
959         TRACE("(%p)->(0x%08lx 0x%08lx 0x%08x) stub\n",This, dwCmdID, dwCmd, hwndCmd);
960
961         switch(dwCmdID)
962         {
963           case FCIDM_SHVIEW_SMALLICON:
964             This->FolderSettings.ViewMode = FVM_SMALLICON;
965             SetStyle (This, LVS_SMALLICON, LVS_TYPEMASK);
966             CheckToolbar(This);
967             break;
968
969           case FCIDM_SHVIEW_BIGICON:
970             This->FolderSettings.ViewMode = FVM_ICON;
971             SetStyle (This, LVS_ICON, LVS_TYPEMASK);
972             CheckToolbar(This);
973             break;
974
975           case FCIDM_SHVIEW_LISTVIEW:
976             This->FolderSettings.ViewMode = FVM_LIST;
977             SetStyle (This, LVS_LIST, LVS_TYPEMASK);
978             CheckToolbar(This);
979             break;
980
981           case FCIDM_SHVIEW_REPORTVIEW:
982             This->FolderSettings.ViewMode = FVM_DETAILS;
983             SetStyle (This, LVS_REPORT, LVS_TYPEMASK);
984             CheckToolbar(This);
985             break;
986
987           /* the menu-ID's for sorting are 0x30... see shrec.rc */
988           case 0x30:
989           case 0x31:
990           case 0x32:
991           case 0x33:
992             This->ListViewSortInfo.nHeaderID = (LPARAM) (dwCmdID - 0x30);
993             This->ListViewSortInfo.bIsAscending = TRUE;
994             This->ListViewSortInfo.nLastHeaderID = This->ListViewSortInfo.nHeaderID;
995             ListView_SortItems(This->hWndList, ShellView_ListViewCompareItems, (LPARAM) (&(This->ListViewSortInfo)));
996             break;
997             
998           default:
999             TRACE("-- COMMAND 0x%04lx unhandled\n", dwCmdID);
1000         }
1001         return 0;
1002 }
1003
1004 /**********************************************************
1005 * ShellView_OnNotify()
1006 */
1007    
1008 static LRESULT ShellView_OnNotify(IShellViewImpl * This, UINT CtlID, LPNMHDR lpnmh)
1009 {       LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lpnmh;
1010         NMLVDISPINFOA *lpdi = (NMLVDISPINFOA *)lpnmh;
1011         LPITEMIDLIST pidl;
1012         STRRET   str;  
1013
1014         TRACE("%p CtlID=%u lpnmh->code=%x\n",This,CtlID,lpnmh->code);
1015
1016         switch(lpnmh->code)
1017         {
1018           case NM_SETFOCUS:
1019             TRACE("-- NM_SETFOCUS %p\n",This);
1020             ShellView_OnSetFocus(This);
1021             break;
1022
1023           case NM_KILLFOCUS:
1024             TRACE("-- NM_KILLFOCUS %p\n",This);
1025             ShellView_OnDeactivate(This);
1026             /* Notify the ICommDlgBrowser interface */
1027             OnStateChange(This,CDBOSC_KILLFOCUS);
1028             break;
1029
1030           case HDN_ENDTRACKA:
1031             TRACE("-- HDN_ENDTRACKA %p\n",This);
1032             /*nColumn1 = ListView_GetColumnWidth(This->hWndList, 0);
1033             nColumn2 = ListView_GetColumnWidth(This->hWndList, 1);*/
1034             break;
1035
1036           case LVN_DELETEITEM:
1037             TRACE("-- LVN_DELETEITEM %p\n",This);
1038             SHFree((LPITEMIDLIST)lpnmlv->lParam);     /*delete the pidl because we made a copy of it*/
1039             break;
1040
1041           case LVN_ITEMACTIVATE:
1042             TRACE("-- LVN_ITEMACTIVATE %p\n",This);
1043             OnStateChange(This, CDBOSC_SELCHANGE);  /* the browser will get the IDataObject now */
1044             ShellView_DoContextMenu(This, 0, 0, TRUE);
1045             break;
1046
1047           case LVN_COLUMNCLICK:
1048             This->ListViewSortInfo.nHeaderID = lpnmlv->iSubItem;
1049             if(This->ListViewSortInfo.nLastHeaderID == This->ListViewSortInfo.nHeaderID)
1050             {
1051               This->ListViewSortInfo.bIsAscending = !This->ListViewSortInfo.bIsAscending;
1052             }
1053             else
1054             {
1055               This->ListViewSortInfo.bIsAscending = TRUE;
1056             }
1057             This->ListViewSortInfo.nLastHeaderID = This->ListViewSortInfo.nHeaderID;
1058
1059             ListView_SortItems(lpnmlv->hdr.hwndFrom, ShellView_ListViewCompareItems, (LPARAM) (&(This->ListViewSortInfo)));
1060             break;
1061         
1062           case LVN_GETDISPINFOA:
1063             TRACE("-- LVN_GETDISPINFOA %p\n",This);
1064             pidl = (LPITEMIDLIST)lpdi->item.lParam;
1065
1066
1067             if(lpdi->item.iSubItem)               /*is the sub-item information being requested?*/
1068             { if(lpdi->item.mask & LVIF_TEXT)    /*is the text being requested?*/
1069               { if(_ILIsValue(pidl))    /*is This a value or a folder?*/
1070                 { switch (lpdi->item.iSubItem)
1071                   { case 1:     /* size */
1072                       _ILGetFileSize (pidl, lpdi->item.pszText, lpdi->item.cchTextMax);
1073                       break;
1074                     case 2:     /* extension */
1075                       { char sTemp[64];
1076                         if (_ILGetExtension (pidl, sTemp, 64))
1077                         { if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
1078                                  && HCR_MapTypeToValue(sTemp, lpdi->item.pszText, lpdi->item.cchTextMax, FALSE )))
1079                           { lstrcpynA (lpdi->item.pszText, sTemp, lpdi->item.cchTextMax);
1080                             strncat (lpdi->item.pszText, "-file", lpdi->item.cchTextMax);
1081                           }
1082                         }
1083                         else    /* no extension found */
1084                         { lpdi->item.pszText[0]=0x00;
1085                         }    
1086                       }
1087                       break;
1088                     case 3:     /* date */
1089                       _ILGetFileDate (pidl, lpdi->item.pszText, lpdi->item.cchTextMax);
1090                       break;
1091                   }
1092                 }
1093                 else  /*its a folder*/
1094                 { switch (lpdi->item.iSubItem)
1095                   { case 1:
1096                       strcpy(lpdi->item.pszText, "");
1097                       break;
1098                     case 2:
1099                       lstrcpynA (lpdi->item.pszText, "Folder", lpdi->item.cchTextMax);
1100                       break;
1101                     case 3:  
1102                       _ILGetFileDate (pidl, lpdi->item.pszText, lpdi->item.cchTextMax);
1103                       break;
1104                   }
1105                 }
1106                 TRACE("-- text=%s\n",lpdi->item.pszText);               
1107               }
1108             }
1109             else           /*the item text is being requested*/
1110             { 
1111               if(lpdi->item.mask & LVIF_TEXT)      /*is the text being requested?*/
1112               {
1113                 if(SUCCEEDED(IShellFolder_GetDisplayNameOf(This->pSFParent,pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &str)))
1114                 {
1115                   StrRetToStrNA(lpdi->item.pszText, lpdi->item.cchTextMax, &str, pidl); 
1116                 }
1117                 TRACE("-- text=%s\n",lpdi->item.pszText);
1118               }
1119
1120               if(lpdi->item.mask & LVIF_IMAGE)          /*is the image being requested?*/
1121               {
1122                 lpdi->item.iImage = SHMapPIDLToSystemImageListIndex(This->pSFParent, pidl, 0);
1123               }
1124             }
1125             break;
1126
1127           case LVN_ITEMCHANGED:
1128             TRACE("-- LVN_ITEMCHANGED %p\n",This);
1129             OnStateChange(This, CDBOSC_SELCHANGE);  /* the browser will get the IDataObject now */
1130             break;
1131
1132           case LVN_BEGINDRAG:
1133           case LVN_BEGINRDRAG:
1134
1135             if (ShellView_GetSelections(This))
1136             {  
1137               IDataObject * pda;
1138               DWORD dwAttributes;
1139               DWORD dwEffect = DROPEFFECT_COPY | DROPEFFECT_MOVE;
1140               
1141               if (SUCCEEDED(IShellFolder_GetUIObjectOf(This->pSFParent, This->hWnd, This->cidl, This->apidl, &IID_IDataObject,0,(LPVOID *)&pda)))
1142               {
1143                 IDropSource * pds = (IDropSource*)&(This->lpvtblDropSource);    /* own DropSource interface */
1144
1145                 if (SUCCEEDED(IShellFolder_GetAttributesOf(This->pSFParent, This->cidl, This->apidl, &dwAttributes)))
1146                 {
1147                   if (dwAttributes & SFGAO_CANLINK)
1148                   {
1149                     dwEffect |= DROPEFFECT_LINK;
1150                   }
1151                 }
1152                 
1153                 if (pds)
1154                 {
1155                   DWORD dwEffect;
1156                   pDoDragDrop(pda, pds, dwEffect, &dwEffect);
1157                 }
1158
1159                 IDataObject_Release(pda);
1160               }
1161             }
1162             break;
1163
1164           case LVN_BEGINLABELEDITA:
1165           case LVN_ENDLABELEDITA:
1166              FIXME("labeledit\n");
1167              break;
1168           
1169           default:
1170             TRACE("-- %p WM_COMMAND %s unhandled\n", This, SPY_GetMsgName(lpnmh->code));
1171             break;;
1172         }
1173         return 0;
1174 }
1175
1176 /**********************************************************
1177 *  ShellView_WndProc
1178 */
1179
1180 static LRESULT CALLBACK ShellView_WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
1181 {
1182         IShellViewImpl * pThis = (IShellViewImpl*)GetWindowLongA(hWnd, GWL_USERDATA);
1183         LPCREATESTRUCTA lpcs;
1184
1185         TRACE("(hwnd=%x msg=%x wparm=%x lparm=%lx)\n",hWnd, uMessage, wParam, lParam);
1186
1187         switch (uMessage)
1188         {
1189           case WM_NCCREATE:
1190             lpcs = (LPCREATESTRUCTA)lParam;
1191             pThis = (IShellViewImpl*)(lpcs->lpCreateParams);
1192             SetWindowLongA(hWnd, GWL_USERDATA, (LONG)pThis);
1193             pThis->hWnd = hWnd;        /*set the window handle*/
1194             break;
1195
1196           case WM_SIZE:         return ShellView_OnSize(pThis,LOWORD(lParam), HIWORD(lParam));
1197           case WM_SETFOCUS:     return ShellView_OnSetFocus(pThis);
1198           case WM_KILLFOCUS:    return ShellView_OnKillFocus(pThis);
1199           case WM_CREATE:       return ShellView_OnCreate(pThis);
1200           case WM_ACTIVATE:     return ShellView_OnActivate(pThis, SVUIA_ACTIVATE_FOCUS);
1201           case WM_NOTIFY:       return ShellView_OnNotify(pThis,(UINT)wParam, (LPNMHDR)lParam);
1202           case WM_COMMAND:      return ShellView_OnCommand(pThis, 
1203                                         GET_WM_COMMAND_ID(wParam, lParam), 
1204                                         GET_WM_COMMAND_CMD(wParam, lParam), 
1205                                         GET_WM_COMMAND_HWND(wParam, lParam));
1206
1207           case WM_CONTEXTMENU:  ShellView_DoContextMenu(pThis, LOWORD(lParam), HIWORD(lParam), FALSE);
1208                                 return 0;
1209
1210           case WM_SHOWWINDOW:   UpdateWindow(pThis->hWndList);
1211                                 break;
1212
1213           case WM_GETDLGCODE:   return SendMessageA(pThis->hWndList,uMessage,0,0);
1214
1215           case WM_DESTROY:      pRevokeDragDrop(pThis->hWnd);
1216                                 break;
1217         }
1218
1219         return DefWindowProcA (hWnd, uMessage, wParam, lParam);
1220 }
1221 /**********************************************************
1222 *
1223 *
1224 *  The INTERFACE of the IShellView object
1225 *
1226 *
1227 **********************************************************
1228 *  IShellView_QueryInterface
1229 */
1230 static HRESULT WINAPI IShellView_fnQueryInterface(IShellView * iface,REFIID riid, LPVOID *ppvObj)
1231 {
1232         ICOM_THIS(IShellViewImpl, iface);
1233
1234         char    xriid[50];
1235         WINE_StringFromCLSID((LPCLSID)riid,xriid);
1236         TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
1237
1238         *ppvObj = NULL;
1239
1240         if(IsEqualIID(riid, &IID_IUnknown))
1241         {
1242           *ppvObj = This; 
1243         }
1244         else if(IsEqualIID(riid, &IID_IShellView))
1245         {
1246           *ppvObj = (IShellView*)This;
1247         }
1248         else if(IsEqualIID(riid, &IID_IOleCommandTarget))
1249         {
1250           *ppvObj = (IOleCommandTarget*)&(This->lpvtblOleCommandTarget);
1251         }
1252         else if(IsEqualIID(riid, &IID_IDropTarget))
1253         {
1254           *ppvObj = (IDropTarget*)&(This->lpvtblDropTarget);
1255         }
1256         else if(IsEqualIID(riid, &IID_IDropSource))
1257         {
1258           *ppvObj = (IDropSource*)&(This->lpvtblDropSource);
1259         }
1260         else if(IsEqualIID(riid, &IID_IViewObject))
1261         {
1262           *ppvObj = (IViewObject*)&(This->lpvtblViewObject);
1263         }
1264
1265         if(*ppvObj)
1266         {
1267           IUnknown_AddRef( (IUnknown*)*ppvObj );
1268           TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
1269           return S_OK;
1270         }
1271         TRACE("-- Interface: E_NOINTERFACE\n");
1272         return E_NOINTERFACE;
1273 }
1274
1275 /**********************************************************
1276 *  IShellView_AddRef
1277 */
1278 static ULONG WINAPI IShellView_fnAddRef(IShellView * iface)
1279 {
1280         ICOM_THIS(IShellViewImpl, iface);
1281
1282         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1283
1284         shell32_ObjCount++;
1285         return ++(This->ref);
1286 }
1287 /**********************************************************
1288 *  IShellView_Release
1289 */
1290 static ULONG WINAPI IShellView_fnRelease(IShellView * iface)
1291 {
1292         ICOM_THIS(IShellViewImpl, iface);
1293
1294         TRACE("(%p)->()\n",This);
1295
1296         shell32_ObjCount--;
1297
1298         if (!--(This->ref)) 
1299         {
1300           TRACE(" destroying IShellView(%p)\n",This);
1301
1302           if(This->pSFParent)
1303             IShellFolder_Release(This->pSFParent);
1304
1305           if (This->apidl)
1306             SHFree(This->apidl);
1307
1308           if (This->pCommDlgBrowser)
1309             ICommDlgBrowser_Release(This->pCommDlgBrowser);
1310
1311           HeapFree(GetProcessHeap(),0,This);
1312           return 0;
1313         }
1314         return This->ref;
1315 }
1316
1317 /**********************************************************
1318 *  ShellView_GetWindow
1319 */
1320 static HRESULT WINAPI IShellView_fnGetWindow(IShellView * iface,HWND * phWnd)
1321 {
1322         ICOM_THIS(IShellViewImpl, iface);
1323
1324         TRACE("(%p)\n",This);
1325
1326         *phWnd = This->hWnd;
1327
1328         return S_OK;
1329 }
1330
1331 static HRESULT WINAPI IShellView_fnContextSensitiveHelp(IShellView * iface,BOOL fEnterMode)
1332 {
1333         ICOM_THIS(IShellViewImpl, iface);
1334
1335         FIXME("(%p) stub\n",This);
1336
1337         return E_NOTIMPL;
1338 }
1339
1340 /**********************************************************
1341 * IShellView_TranslateAccelerator
1342 *
1343 * FIXME:
1344 *  use the accel functions
1345 */
1346 static HRESULT WINAPI IShellView_fnTranslateAccelerator(IShellView * iface,LPMSG lpmsg)
1347 {
1348         ICOM_THIS(IShellViewImpl, iface);
1349
1350 #if 0
1351         FIXME("(%p)->(%p: hwnd=%x msg=%x lp=%lx wp=%x) stub\n",This,lpmsg, lpmsg->hwnd, lpmsg->message, lpmsg->lParam, lpmsg->wParam);
1352 #endif
1353         
1354         if ((lpmsg->message>=WM_KEYFIRST) && (lpmsg->message>=WM_KEYLAST))
1355         {
1356           TRACE("-- key=0x04%x",lpmsg->wParam) ;
1357         }
1358         return S_FALSE; /* not handled */
1359 }
1360
1361 static HRESULT WINAPI IShellView_fnEnableModeless(IShellView * iface,BOOL fEnable)
1362 {
1363         ICOM_THIS(IShellViewImpl, iface);
1364
1365         FIXME("(%p) stub\n",This);
1366
1367         return E_NOTIMPL;
1368 }
1369
1370 static HRESULT WINAPI IShellView_fnUIActivate(IShellView * iface,UINT uState)
1371 {
1372         ICOM_THIS(IShellViewImpl, iface);
1373
1374 /*
1375         CHAR    szName[MAX_PATH];
1376 */
1377         LRESULT lResult;
1378         int     nPartArray[1] = {-1};
1379
1380         TRACE("(%p)->(state=%x) stub\n",This, uState);
1381
1382         /*don't do anything if the state isn't really changing*/
1383         if(This->uState == uState)
1384         {
1385           return S_OK;
1386         }
1387
1388         /*OnActivate handles the menu merging and internal state*/
1389         ShellView_OnActivate(This, uState);
1390
1391         /*only do This if we are active*/
1392         if(uState != SVUIA_DEACTIVATE)
1393         {
1394
1395 /*
1396           GetFolderPath is not a method of IShellFolder
1397           IShellFolder_GetFolderPath( This->pSFParent, szName, sizeof(szName) );
1398 */
1399           /* set the number of parts */
1400           IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_STATUS, SB_SETPARTS, 1,
1401                                                         (LPARAM)nPartArray, &lResult);
1402
1403           /* set the text for the parts */
1404 /*
1405           IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_STATUS, SB_SETTEXTA,
1406                                                         0, (LPARAM)szName, &lResult);
1407 */                                                      
1408         }
1409
1410         return S_OK;
1411 }
1412
1413 static HRESULT WINAPI IShellView_fnRefresh(IShellView * iface)
1414 {
1415         ICOM_THIS(IShellViewImpl, iface);
1416
1417         TRACE("(%p)\n",This);
1418
1419         ListView_DeleteAllItems(This->hWndList);
1420         ShellView_FillList(This);
1421
1422         return S_OK;
1423 }
1424
1425 static HRESULT WINAPI IShellView_fnCreateViewWindow(
1426         IShellView * iface,
1427         IShellView *lpPrevView,
1428         LPCFOLDERSETTINGS lpfs,
1429         IShellBrowser * psb,
1430         RECT * prcView,
1431         HWND  *phWnd)
1432 {
1433         ICOM_THIS(IShellViewImpl, iface);
1434
1435         WNDCLASSA wc;
1436         *phWnd = 0;
1437
1438         
1439         TRACE("(%p)->(shlview=%p set=%p shlbrs=%p rec=%p hwnd=%p) incomplete\n",This, lpPrevView,lpfs, psb, prcView, phWnd);
1440         TRACE("-- vmode=%x flags=%x left=%i top=%i right=%i bottom=%i\n",lpfs->ViewMode, lpfs->fFlags ,prcView->left,prcView->top, prcView->right, prcView->bottom);
1441
1442         /*set up the member variables*/
1443         This->pShellBrowser = psb;
1444         This->FolderSettings = *lpfs;
1445
1446         /*get our parent window*/
1447         IShellBrowser_AddRef(This->pShellBrowser);
1448         IShellBrowser_GetWindow(This->pShellBrowser, &(This->hWndParent));
1449
1450         /* try to get the ICommDlgBrowserInterface, adds a reference !!! */
1451         This->pCommDlgBrowser=NULL;
1452         if ( SUCCEEDED (IShellBrowser_QueryInterface( This->pShellBrowser, 
1453                         (REFIID)&IID_ICommDlgBrowser, (LPVOID*) &This->pCommDlgBrowser)))
1454         {
1455           TRACE("-- CommDlgBrowser\n");
1456         }
1457
1458         /*if our window class has not been registered, then do so*/
1459         if(!GetClassInfoA(shell32_hInstance, SV_CLASS_NAME, &wc))
1460         {
1461           ZeroMemory(&wc, sizeof(wc));
1462           wc.style              = CS_HREDRAW | CS_VREDRAW;
1463           wc.lpfnWndProc        = (WNDPROC) ShellView_WndProc;
1464           wc.cbClsExtra         = 0;
1465           wc.cbWndExtra         = 0;
1466           wc.hInstance          = shell32_hInstance;
1467           wc.hIcon              = 0;
1468           wc.hCursor            = LoadCursorA (0, IDC_ARROWA);
1469           wc.hbrBackground      = (HBRUSH) (COLOR_WINDOW + 1);
1470           wc.lpszMenuName       = NULL;
1471           wc.lpszClassName      = SV_CLASS_NAME;
1472
1473           if(!RegisterClassA(&wc))
1474             return E_FAIL;
1475         }
1476
1477         *phWnd = CreateWindowExA(0,
1478                                 SV_CLASS_NAME,
1479                                 NULL,
1480                                 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_TABSTOP,
1481                                 prcView->left,
1482                                 prcView->top,
1483                                 prcView->right - prcView->left,
1484                                 prcView->bottom - prcView->top,
1485                                 This->hWndParent,
1486                                 0,
1487                                 shell32_hInstance,
1488                                 (LPVOID)This);
1489
1490         CheckToolbar(This);
1491         
1492         if(!*phWnd)
1493           return E_FAIL;
1494
1495         return S_OK;
1496 }
1497
1498 static HRESULT WINAPI IShellView_fnDestroyViewWindow(IShellView * iface)
1499 {
1500         ICOM_THIS(IShellViewImpl, iface);
1501
1502         TRACE("(%p)\n",This);
1503
1504         /*Make absolutely sure all our UI is cleaned up.*/
1505         IShellView_UIActivate((IShellView*)This, SVUIA_DEACTIVATE);
1506
1507         if(This->hMenu)
1508         {
1509           DestroyMenu(This->hMenu);
1510         }
1511
1512         DestroyWindow(This->hWnd);
1513         IShellBrowser_Release(This->pShellBrowser);
1514
1515         return S_OK;
1516 }
1517
1518 static HRESULT WINAPI IShellView_fnGetCurrentInfo(IShellView * iface, LPFOLDERSETTINGS lpfs)
1519 {
1520         ICOM_THIS(IShellViewImpl, iface);
1521
1522         TRACE("(%p)->(%p) vmode=%x flags=%x\n",This, lpfs, 
1523                 This->FolderSettings.ViewMode, This->FolderSettings.fFlags);
1524
1525         if (!lpfs) return E_INVALIDARG;
1526
1527         *lpfs = This->FolderSettings;
1528         return NOERROR;
1529 }
1530
1531 static HRESULT WINAPI IShellView_fnAddPropertySheetPages(IShellView * iface, DWORD dwReserved,LPFNADDPROPSHEETPAGE lpfn, LPARAM lparam)
1532 {
1533         ICOM_THIS(IShellViewImpl, iface);
1534
1535         FIXME("(%p) stub\n",This);
1536
1537         return E_NOTIMPL;
1538 }
1539
1540 static HRESULT WINAPI IShellView_fnSaveViewState(IShellView * iface)
1541 {
1542         ICOM_THIS(IShellViewImpl, iface);
1543
1544         FIXME("(%p) stub\n",This);
1545
1546         return S_OK;
1547 }
1548
1549 static HRESULT WINAPI IShellView_fnSelectItem(IShellView * iface, LPCITEMIDLIST pidlItem, UINT uFlags)
1550 {       ICOM_THIS(IShellViewImpl, iface);
1551         
1552         FIXME("(%p)->(pidl=%p, 0x%08x) stub\n",This, pidlItem, uFlags);
1553
1554         return E_NOTIMPL;
1555 }
1556
1557 static HRESULT WINAPI IShellView_fnGetItemObject(IShellView * iface, UINT uItem, REFIID riid, LPVOID *ppvOut)
1558 {
1559         ICOM_THIS(IShellViewImpl, iface);
1560
1561         char    xriid[50];
1562         
1563         WINE_StringFromCLSID((LPCLSID)riid,xriid);
1564         TRACE("(%p)->(uItem=0x%08x,\n\tIID=%s, ppv=%p)\n",This, uItem, xriid, ppvOut);
1565
1566         *ppvOut = NULL;
1567
1568         switch(uItem)
1569         {
1570           case SVGIO_BACKGROUND:
1571             *ppvOut = ISvBgCm_Constructor();
1572             break;
1573
1574           case SVGIO_SELECTION:
1575             ShellView_GetSelections(This);
1576             IShellFolder_GetUIObjectOf(This->pSFParent, This->hWnd, This->cidl, This->apidl, riid, 0, ppvOut);
1577             break;
1578         }
1579         TRACE("-- (%p)->(interface=%p)\n",This, *ppvOut);
1580
1581         if(!*ppvOut) return E_OUTOFMEMORY;
1582
1583         return S_OK;
1584 }
1585
1586 static struct ICOM_VTABLE(IShellView) svvt = 
1587 {       
1588         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1589         IShellView_fnQueryInterface,
1590         IShellView_fnAddRef,
1591         IShellView_fnRelease,
1592         IShellView_fnGetWindow,
1593         IShellView_fnContextSensitiveHelp,
1594         IShellView_fnTranslateAccelerator,
1595         IShellView_fnEnableModeless,
1596         IShellView_fnUIActivate,
1597         IShellView_fnRefresh,
1598         IShellView_fnCreateViewWindow,
1599         IShellView_fnDestroyViewWindow,
1600         IShellView_fnGetCurrentInfo,
1601         IShellView_fnAddPropertySheetPages,
1602         IShellView_fnSaveViewState,
1603         IShellView_fnSelectItem,
1604         IShellView_fnGetItemObject
1605 };
1606
1607
1608 /**********************************************************
1609  * ISVOleCmdTarget_QueryInterface (IUnknown)
1610  */
1611 static HRESULT WINAPI ISVOleCmdTarget_QueryInterface(
1612         IOleCommandTarget *     iface,
1613         REFIID                  iid,
1614         LPVOID*                 ppvObj)
1615 {
1616         _ICOM_THIS_From_IOleCommandTarget(IShellViewImpl, iface);
1617
1618         return IShellFolder_QueryInterface((IShellFolder*)This, iid, ppvObj);
1619 }
1620
1621 /**********************************************************
1622  * ISVOleCmdTarget_AddRef (IUnknown)
1623  */
1624 static ULONG WINAPI ISVOleCmdTarget_AddRef(
1625         IOleCommandTarget *     iface)
1626 {
1627         _ICOM_THIS_From_IOleCommandTarget(IShellFolder, iface);
1628
1629         return IShellFolder_AddRef((IShellFolder*)This);
1630 }
1631
1632 /**********************************************************
1633  * ISVOleCmdTarget_Release (IUnknown)
1634  */
1635 static ULONG WINAPI ISVOleCmdTarget_Release(
1636         IOleCommandTarget *     iface)
1637 {
1638         _ICOM_THIS_From_IOleCommandTarget(IShellViewImpl, iface);
1639
1640         return IShellFolder_Release((IShellFolder*)This);
1641 }
1642
1643 /**********************************************************
1644  * ISVOleCmdTarget_QueryStatus (IOleCommandTarget)
1645  */
1646 static HRESULT WINAPI ISVOleCmdTarget_QueryStatus(
1647         IOleCommandTarget *iface,
1648         const GUID* pguidCmdGroup,
1649         ULONG cCmds, 
1650         OLECMD * prgCmds,
1651         OLECMDTEXT* pCmdText)
1652 {
1653         char    xguid[50];
1654
1655         _ICOM_THIS_From_IOleCommandTarget(IShellViewImpl, iface);
1656
1657         WINE_StringFromCLSID((LPCLSID)pguidCmdGroup,xguid);
1658
1659         FIXME("(%p)->(%p(%s) 0x%08lx %p %p\n", This, pguidCmdGroup, xguid, cCmds, prgCmds, pCmdText);
1660         return E_NOTIMPL;
1661 }
1662
1663 /**********************************************************
1664  * ISVOleCmdTarget_Exec (IOleCommandTarget)
1665  *
1666  * nCmdID is the OLECMDID_* enumeration
1667  */
1668 static HRESULT WINAPI ISVOleCmdTarget_Exec(
1669         IOleCommandTarget *iface,
1670         const GUID* pguidCmdGroup,
1671         DWORD nCmdID,
1672         DWORD nCmdexecopt,
1673         VARIANT* pvaIn,
1674         VARIANT* pvaOut)
1675 {
1676         char    xguid[50];
1677
1678         _ICOM_THIS_From_IOleCommandTarget(IShellViewImpl, iface);
1679
1680         WINE_StringFromCLSID((LPCLSID)pguidCmdGroup,xguid);
1681
1682         FIXME("(%p)->(\n\tTarget GUID:%s Command:0x%08lx Opt:0x%08lx %p %p)\n", This, xguid, nCmdID, nCmdexecopt, pvaIn, pvaOut);
1683         return E_NOTIMPL;
1684 }
1685
1686 static ICOM_VTABLE(IOleCommandTarget) ctvt = 
1687 {
1688         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1689         ISVOleCmdTarget_QueryInterface,
1690         ISVOleCmdTarget_AddRef,
1691         ISVOleCmdTarget_Release,
1692         ISVOleCmdTarget_QueryStatus,
1693         ISVOleCmdTarget_Exec
1694 };
1695
1696 /**********************************************************
1697  * ISVDropTarget implementation
1698  */
1699
1700 static HRESULT WINAPI ISVDropTarget_QueryInterface(
1701         IDropTarget *iface,
1702         REFIID riid,
1703         LPVOID *ppvObj)
1704 {
1705         char    xriid[50];
1706
1707         _ICOM_THIS_From_IDropTarget(IShellViewImpl, iface);
1708
1709         WINE_StringFromCLSID((LPCLSID)riid,xriid);
1710
1711         TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
1712
1713         return IShellFolder_QueryInterface((IShellFolder*)This, riid, ppvObj);
1714 }
1715
1716 static ULONG WINAPI ISVDropTarget_AddRef( IDropTarget *iface)
1717 {
1718         _ICOM_THIS_From_IDropTarget(IShellViewImpl, iface);
1719
1720         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1721
1722         return IShellFolder_AddRef((IShellFolder*)This);
1723 }
1724
1725 static ULONG WINAPI ISVDropTarget_Release( IDropTarget *iface)
1726 {
1727         _ICOM_THIS_From_IDropTarget(IShellViewImpl, iface);
1728
1729         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1730
1731         return IShellFolder_Release((IShellFolder*)This);
1732 }
1733
1734 static HRESULT WINAPI ISVDropTarget_DragEnter(
1735         IDropTarget     *iface,
1736         IDataObject     *pDataObject,
1737         DWORD           grfKeyState,
1738         POINTL          pt,
1739         DWORD           *pdwEffect)
1740 {       
1741
1742         _ICOM_THIS_From_IDropTarget(IShellViewImpl, iface);
1743
1744         FIXME("Stub: This=%p, DataObject=%p\n",This,pDataObject);
1745
1746         return E_NOTIMPL;
1747 }
1748
1749 static HRESULT WINAPI ISVDropTarget_DragOver(
1750         IDropTarget     *iface,
1751         DWORD           grfKeyState,
1752         POINTL          pt,
1753         DWORD           *pdwEffect)
1754 {
1755         _ICOM_THIS_From_IDropTarget(IShellViewImpl, iface);
1756
1757         FIXME("Stub: This=%p\n",This);
1758
1759         return E_NOTIMPL;
1760 }
1761
1762 static HRESULT WINAPI ISVDropTarget_DragLeave(
1763         IDropTarget     *iface)
1764 {
1765         _ICOM_THIS_From_IDropTarget(IShellViewImpl, iface);
1766
1767         FIXME("Stub: This=%p\n",This);
1768
1769         return E_NOTIMPL;
1770 }
1771
1772 static HRESULT WINAPI ISVDropTarget_Drop(
1773         IDropTarget     *iface,
1774         IDataObject*    pDataObject,
1775         DWORD           grfKeyState,
1776         POINTL          pt,
1777         DWORD           *pdwEffect)
1778 {
1779         _ICOM_THIS_From_IDropTarget(IShellViewImpl, iface);
1780
1781         FIXME("Stub: This=%p\n",This);
1782
1783         return E_NOTIMPL;
1784 }
1785
1786 static struct ICOM_VTABLE(IDropTarget) dtvt = 
1787 {
1788         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1789         ISVDropTarget_QueryInterface,
1790         ISVDropTarget_AddRef,
1791         ISVDropTarget_Release,
1792         ISVDropTarget_DragEnter,
1793         ISVDropTarget_DragOver,
1794         ISVDropTarget_DragLeave,
1795         ISVDropTarget_Drop
1796 };
1797
1798 /**********************************************************
1799  * ISVDropSource implementation
1800  */
1801
1802 static HRESULT WINAPI ISVDropSource_QueryInterface(
1803         IDropSource *iface,
1804         REFIID riid,
1805         LPVOID *ppvObj)
1806 {
1807         char    xriid[50];
1808
1809         _ICOM_THIS_From_IDropSource(IShellViewImpl, iface);
1810
1811         WINE_StringFromCLSID((LPCLSID)riid,xriid);
1812
1813         TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
1814
1815         return IShellFolder_QueryInterface((IShellFolder*)This, riid, ppvObj);
1816 }
1817
1818 static ULONG WINAPI ISVDropSource_AddRef( IDropSource *iface)
1819 {
1820         _ICOM_THIS_From_IDropSource(IShellViewImpl, iface);
1821
1822         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1823
1824         return IShellFolder_AddRef((IShellFolder*)This);
1825 }
1826
1827 static ULONG WINAPI ISVDropSource_Release( IDropSource *iface)
1828 {
1829         _ICOM_THIS_From_IDropSource(IShellViewImpl, iface);
1830
1831         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1832
1833         return IShellFolder_Release((IShellFolder*)This);
1834 }
1835 static HRESULT WINAPI ISVDropSource_QueryContinueDrag(
1836         IDropSource *iface,
1837         BOOL fEscapePressed,
1838         DWORD grfKeyState)
1839 {
1840         _ICOM_THIS_From_IDropSource(IShellViewImpl, iface);
1841         TRACE("(%p)\n",This);
1842
1843         if (fEscapePressed)
1844           return DRAGDROP_S_CANCEL;
1845         else if (!(grfKeyState & MK_LBUTTON) && !(grfKeyState & MK_RBUTTON))
1846           return DRAGDROP_S_DROP;
1847         else
1848           return NOERROR;
1849 }
1850
1851 static HRESULT WINAPI ISVDropSource_GiveFeedback(
1852         IDropSource *iface,
1853         DWORD dwEffect)
1854 {
1855         _ICOM_THIS_From_IDropSource(IShellViewImpl, iface);
1856         TRACE("(%p)\n",This);
1857
1858         return DRAGDROP_S_USEDEFAULTCURSORS;
1859 }
1860
1861 static struct ICOM_VTABLE(IDropSource) dsvt =
1862 {
1863         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1864         ISVDropSource_QueryInterface,
1865         ISVDropSource_AddRef,
1866         ISVDropSource_Release,
1867         ISVDropSource_QueryContinueDrag,
1868         ISVDropSource_GiveFeedback
1869 };
1870 /**********************************************************
1871  * ISVViewObject implementation
1872  */
1873
1874 static HRESULT WINAPI ISVViewObject_QueryInterface(
1875         IViewObject *iface,
1876         REFIID riid,
1877         LPVOID *ppvObj)
1878 {
1879         char    xriid[50];
1880
1881         _ICOM_THIS_From_IViewObject(IShellViewImpl, iface);
1882
1883         WINE_StringFromCLSID((LPCLSID)riid,xriid);
1884
1885         TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
1886
1887         return IShellFolder_QueryInterface((IShellFolder*)This, riid, ppvObj);
1888 }
1889
1890 static ULONG WINAPI ISVViewObject_AddRef( IViewObject *iface)
1891 {
1892         _ICOM_THIS_From_IViewObject(IShellViewImpl, iface);
1893
1894         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1895
1896         return IShellFolder_AddRef((IShellFolder*)This);
1897 }
1898
1899 static ULONG WINAPI ISVViewObject_Release( IViewObject *iface)
1900 {
1901         _ICOM_THIS_From_IViewObject(IShellViewImpl, iface);
1902
1903         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1904
1905         return IShellFolder_Release((IShellFolder*)This);
1906 }
1907
1908 static HRESULT WINAPI ISVViewObject_Draw(
1909         IViewObject     *iface,
1910         DWORD dwDrawAspect,
1911         LONG lindex,
1912         void* pvAspect,
1913         DVTARGETDEVICE* ptd,
1914         HDC hdcTargetDev,
1915         HDC hdcDraw,
1916         LPCRECTL lprcBounds,
1917         LPCRECTL lprcWBounds, 
1918         IVO_ContCallback pfnContinue,
1919         DWORD dwContinue)
1920 {       
1921
1922         _ICOM_THIS_From_IViewObject(IShellViewImpl, iface);
1923
1924         FIXME("Stub: This=%p\n",This);
1925
1926         return E_NOTIMPL;
1927 }
1928 static HRESULT WINAPI ISVViewObject_GetColorSet(
1929         IViewObject     *iface,
1930         DWORD dwDrawAspect,
1931         LONG lindex,
1932         void *pvAspect,
1933         DVTARGETDEVICE* ptd,
1934         HDC hicTargetDevice,
1935         LOGPALETTE** ppColorSet)
1936 {       
1937
1938         _ICOM_THIS_From_IViewObject(IShellViewImpl, iface);
1939
1940         FIXME("Stub: This=%p\n",This);
1941
1942         return E_NOTIMPL;
1943 }
1944 static HRESULT WINAPI ISVViewObject_Freeze(
1945         IViewObject     *iface,
1946         DWORD dwDrawAspect,
1947         LONG lindex,
1948         void* pvAspect,
1949         DWORD* pdwFreeze)
1950 {       
1951
1952         _ICOM_THIS_From_IViewObject(IShellViewImpl, iface);
1953
1954         FIXME("Stub: This=%p\n",This);
1955
1956         return E_NOTIMPL;
1957 }
1958 static HRESULT WINAPI ISVViewObject_Unfreeze(
1959         IViewObject     *iface,
1960         DWORD dwFreeze)
1961 {       
1962
1963         _ICOM_THIS_From_IViewObject(IShellViewImpl, iface);
1964
1965         FIXME("Stub: This=%p\n",This);
1966
1967         return E_NOTIMPL;
1968 }
1969 static HRESULT WINAPI ISVViewObject_SetAdvise(
1970         IViewObject     *iface,
1971         DWORD aspects,
1972         DWORD advf,
1973         IAdviseSink* pAdvSink)
1974 {       
1975
1976         _ICOM_THIS_From_IViewObject(IShellViewImpl, iface);
1977
1978         FIXME("Stub: This=%p\n",This);
1979
1980         return E_NOTIMPL;
1981 }
1982 static HRESULT WINAPI ISVViewObject_GetAdvise(
1983         IViewObject     *iface,
1984         DWORD* pAspects,
1985         DWORD* pAdvf,
1986         IAdviseSink** ppAdvSink)
1987 {       
1988
1989         _ICOM_THIS_From_IViewObject(IShellViewImpl, iface);
1990
1991         FIXME("Stub: This=%p\n",This);
1992
1993         return E_NOTIMPL;
1994 }
1995
1996
1997 static struct ICOM_VTABLE(IViewObject) vovt = 
1998 {
1999         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2000         ISVViewObject_QueryInterface,
2001         ISVViewObject_AddRef,
2002         ISVViewObject_Release,
2003         ISVViewObject_Draw,
2004         ISVViewObject_GetColorSet,
2005         ISVViewObject_Freeze,
2006         ISVViewObject_Unfreeze,
2007         ISVViewObject_SetAdvise,
2008         ISVViewObject_GetAdvise
2009 };
2010