shlview.c 69.6 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3
/*
 *	ShellView
 *
4
 *	Copyright 1998,1999	<juergen.schmied@debitel.net>
5
 *
6
 * This is the view visualizing the data provied by the shellfolder.
7 8
 * No direct access to data from pidls should be done from here.
 *
9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
23 24
 * FIXME: The order by part of the background context menu should be
 * buily according to the columns shown.
25
 *
26 27 28 29 30 31 32 33 34 35
 * FIXME: Load/Save the view state from/into the stream provied 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
36
 * Release() ???
Alexandre Julliard's avatar
Alexandre Julliard committed
37 38
 */

39 40 41
#include "config.h"
#include "wine/port.h"

42
#include <stdarg.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
43 44
#include <stdlib.h>
#include <string.h>
45

46
#define COBJMACROS
47 48
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
49

50
#include "windef.h"
51
#include "winerror.h"
52
#include "winbase.h"
53
#include "winnls.h"
54
#include "objbase.h"
55
#include "servprov.h"
56
#include "shlguid.h"
57 58
#include "wingdi.h"
#include "winuser.h"
59
#include "shlobj.h"
60
#include "undocshell.h"
61
#include "shresdef.h"
62
#include "wine/debug.h"
63

64
#include "docobj.h"
65 66
#include "pidl.h"
#include "shell32_main.h"
67
#include "shellfolder.h"
68

69
WINE_DEFAULT_DEBUG_CHANNEL(shell);
70

71 72 73 74 75 76
typedef struct
{   BOOL    bIsAscending;
    INT     nHeaderID;
    INT     nLastHeaderID;
}LISTVIEW_SORT_INFO, *LPLISTVIEW_SORT_INFO;

77
typedef struct
78
{
79
	const IShellViewVtbl*	lpVtbl;
Mike McCormack's avatar
Mike McCormack committed
80
	LONG			ref;
81 82 83 84
	const IOleCommandTargetVtbl* lpvtblOleCommandTarget;
	const IDropTargetVtbl*	lpvtblDropTarget;
	const IDropSourceVtbl*	lpvtblDropSource;
	const IViewObjectVtbl*	lpvtblViewObject;
85
	IShellFolder*	pSFParent;
86
	IShellFolder2*	pSF2Parent;
87 88
	IShellBrowser*	pShellBrowser;
	ICommDlgBrowser*	pCommDlgBrowser;
89 90
	HWND		hWnd;		/* SHELLDLL_DefView */
	HWND		hWndList;	/* ListView control */
91 92 93 94
	HWND		hWndParent;
	FOLDERSETTINGS	FolderSettings;
	HMENU		hMenu;
	UINT		uState;
95 96
	UINT		cidl;
	LPITEMIDLIST	*apidl;
97
        LISTVIEW_SORT_INFO ListViewSortInfo;
98
	ULONG			hNotify;	/* change notification handle */
99
	HANDLE		hAccel;
100 101 102
	DWORD		dwAspects;
	DWORD		dwAdvf;
	IAdviseSink    *pAdvSink;
103 104 105
        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 */
106 107
        UINT            cScrollDelay;   /* Send a WM_*SCROLL msg every 250 ms during drag-scroll */
        POINT           ptLastMousePos; /* Mouse position at last DragOver call */
108 109
} IShellViewImpl;

110 111 112 113 114
static const IShellViewVtbl svvt;
static const IOleCommandTargetVtbl ctvt;
static const IDropTargetVtbl dtvt;
static const IDropSourceVtbl dsvt;
static const IViewObjectVtbl vovt;
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135


static inline IShellViewImpl *impl_from_IOleCommandTarget( IOleCommandTarget *iface )
{
    return (IShellViewImpl *)((char*)iface - FIELD_OFFSET(IShellViewImpl, lpvtblOleCommandTarget));
}

static inline IShellViewImpl *impl_from_IDropTarget( IDropTarget *iface )
{
    return (IShellViewImpl *)((char*)iface - FIELD_OFFSET(IShellViewImpl, lpvtblDropTarget));
}

static inline IShellViewImpl *impl_from_IDropSource( IDropSource *iface )
{
    return (IShellViewImpl *)((char*)iface - FIELD_OFFSET(IShellViewImpl, lpvtblDropSource));
}

static inline IShellViewImpl *impl_from_IViewObject( IViewObject *iface )
{
    return (IShellViewImpl *)((char*)iface - FIELD_OFFSET(IShellViewImpl, lpvtblViewObject));
}
136

137 138 139 140 141 142 143
/* ListView Header ID's */
#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

144
/*menu items */
Alexandre Julliard's avatar
Alexandre Julliard committed
145 146 147
#define IDM_VIEW_FILES  (FCIDM_SHVIEWFIRST + 0x500)
#define IDM_VIEW_IDW    (FCIDM_SHVIEWFIRST + 0x501)
#define IDM_MYFILEITEM  (FCIDM_SHVIEWFIRST + 0x502)
148

149
#define ID_LISTVIEW     1
150

151 152
#define SHV_CHANGE_NOTIFY WM_USER + 0x1111

153
/*windowsx.h */
Alexandre Julliard's avatar
Alexandre Julliard committed
154
#define GET_WM_COMMAND_ID(wp, lp)               LOWORD(wp)
155
#define GET_WM_COMMAND_HWND(wp, lp)             (HWND)(lp)
Alexandre Julliard's avatar
Alexandre Julliard committed
156
#define GET_WM_COMMAND_CMD(wp, lp)              HIWORD(wp)
157

158 159 160
/*
  Items merged into the toolbar and and the filemenu
*/
Alexandre Julliard's avatar
Alexandre Julliard committed
161 162 163 164 165 166 167 168 169
typedef struct
{  int   idCommand;
   int   iImage;
   int   idButtonString;
   int   idMenuString;
   BYTE  bState;
   BYTE  bStyle;
} MYTOOLINFO, *LPMYTOOLINFO;

170
MYTOOLINFO Tools[] =
171
{
172 173 174 175
{ 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 },
176
{ -1, 0, 0, 0, 0, 0}
Alexandre Julliard's avatar
Alexandre Julliard committed
177
};
178

179
typedef void (CALLBACK *PFNSHGETSETTINGSPROC)(LPSHELLFLAGSTATE lpsfs, DWORD dwMask);
Alexandre Julliard's avatar
Alexandre Julliard committed
180

181 182 183 184
/**********************************************************
 *	IShellView_Constructor
 */
IShellView * IShellView_Constructor( IShellFolder * pFolder)
185
{	IShellViewImpl * sv;
186
	sv=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IShellViewImpl));
187
	sv->ref=1;
188
	sv->lpVtbl=&svvt;
189 190
	sv->lpvtblOleCommandTarget=&ctvt;
	sv->lpvtblDropTarget=&dtvt;
191
	sv->lpvtblDropSource=&dsvt;
192
	sv->lpvtblViewObject=&vovt;
193

194 195 196
	sv->pSFParent = pFolder;
	if(pFolder) IShellFolder_AddRef(pFolder);
	IShellFolder_QueryInterface(sv->pSFParent, &IID_IShellFolder2, (LPVOID*)&sv->pSF2Parent);
197

198 199 200
        sv->pCurDropTarget = NULL;
        sv->pCurDataObject = NULL;
        sv->iDragOverItem = 0;
201 202 203
        sv->cScrollDelay = 0;
        sv->ptLastMousePos.x = 0;
        sv->ptLastMousePos.y = 0;
204

205
	TRACE("(%p)->(%p)\n",sv, pFolder);
206
	return (IShellView *) sv;
Alexandre Julliard's avatar
Alexandre Julliard committed
207
}
208 209 210 211 212

/**********************************************************
 *
 * ##### helperfunctions for communication with ICommDlgBrowser #####
 */
213 214
static BOOL IsInCommDlg(IShellViewImpl * This)
{	return(This->pCommDlgBrowser != NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
215
}
216

217 218
static HRESULT IncludeObject(IShellViewImpl * This, LPCITEMIDLIST pidl)
{
219
	HRESULT ret = S_OK;
220

221
	if ( IsInCommDlg(This) )
222 223 224
	{
	  TRACE("ICommDlgBrowser::IncludeObject pidl=%p\n", pidl);
	  ret = ICommDlgBrowser_IncludeObject(This->pCommDlgBrowser, (IShellView*)This, pidl);
Patrik Stridvall's avatar
Patrik Stridvall committed
225
	  TRACE("--0x%08lx\n", ret);
Alexandre Julliard's avatar
Alexandre Julliard committed
226
	}
227
	return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
228
}
229 230 231

static HRESULT OnDefaultCommand(IShellViewImpl * This)
{
232
	HRESULT ret = S_FALSE;
233

234
	if (IsInCommDlg(This))
235 236 237
	{
	  TRACE("ICommDlgBrowser::OnDefaultCommand\n");
	  ret = ICommDlgBrowser_OnDefaultCommand(This->pCommDlgBrowser, (IShellView*)This);
238
	  TRACE("-- returns %08lx\n", ret);
Alexandre Julliard's avatar
Alexandre Julliard committed
239
	}
240
	return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
241
}
242 243 244

static HRESULT OnStateChange(IShellViewImpl * This, UINT uFlags)
{
245 246
	HRESULT ret = S_FALSE;

247
	if (IsInCommDlg(This))
248 249 250 251
	{
	  TRACE("ICommDlgBrowser::OnStateChange flags=%x\n", uFlags);
	  ret = ICommDlgBrowser_OnStateChange(This->pCommDlgBrowser, (IShellView*)This, uFlags);
	  TRACE("--\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
252
	}
253
	return ret;
254
}
255
/**********************************************************
256
 *	set the toolbar of the filedialog buttons
257
 *
258
 * - activates the buttons from the shellbrowser according to
259
 *   the view state
260
 */
261
static void CheckToolbar(IShellViewImpl * This)
262 263
{
	LRESULT result;
264

265
	TRACE("\n");
266

267 268 269
	if (IsInCommDlg(This))
	{
	  IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_CHECKBUTTON,
270
		FCIDM_TB_SMALLICON, (This->FolderSettings.ViewMode==FVM_LIST)? TRUE : FALSE, &result);
271
	  IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_CHECKBUTTON,
272
		FCIDM_TB_REPORTVIEW, (This->FolderSettings.ViewMode==FVM_DETAILS)? TRUE : FALSE, &result);
273
	  IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_ENABLEBUTTON,
274
		FCIDM_TB_SMALLICON, TRUE, &result);
275
	  IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_TOOLBAR, TB_ENABLEBUTTON,
276
		FCIDM_TB_REPORTVIEW, TRUE, &result);
277
	}
278 279
}

280 281 282 283
/**********************************************************
 *
 * ##### helperfunctions for initializing the view #####
 */
284 285 286 287 288 289
/**********************************************************
 *	change the style of the listview control
 */
static void SetStyle(IShellViewImpl * This, DWORD dwAdd, DWORD dwRemove)
{
	DWORD tmpstyle;
290

291
	TRACE("(%p)\n", This);
292

293 294
	tmpstyle = GetWindowLongA(This->hWndList, GWL_STYLE);
	SetWindowLongA(This->hWndList, GWL_STYLE, dwAdd | (tmpstyle & ~dwRemove));
295
}
Alexandre Julliard's avatar
Alexandre Julliard committed
296

297
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
298 299
* ShellView_CreateList()
*
300
* - creates the list view window
Alexandre Julliard's avatar
Alexandre Julliard committed
301
*/
302
static BOOL ShellView_CreateList (IShellViewImpl * This)
303
{	DWORD dwStyle, dwExStyle;
Alexandre Julliard's avatar
Alexandre Julliard committed
304

305
	TRACE("%p\n",This);
Alexandre Julliard's avatar
Alexandre Julliard committed
306

307
	dwStyle = WS_TABSTOP | WS_VISIBLE | WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
308
		  LVS_SHAREIMAGELISTS | LVS_EDITLABELS | LVS_ALIGNLEFT | LVS_AUTOARRANGE;
309
        dwExStyle = WS_EX_CLIENTEDGE;
310

311
	switch (This->FolderSettings.ViewMode)
312 313
	{
	  case FVM_ICON:	dwStyle |= LVS_ICON;		break;
Juergen Schmied's avatar
Juergen Schmied committed
314
	  case FVM_DETAILS: 	dwStyle |= LVS_REPORT;		break;
Alexandre Julliard's avatar
Alexandre Julliard committed
315 316
	  case FVM_SMALLICON: 	dwStyle |= LVS_SMALLICON;	break;
	  case FVM_LIST: 	dwStyle |= LVS_LIST;		break;
Juergen Schmied's avatar
Juergen Schmied committed
317
	  default:		dwStyle |= LVS_LIST;		break;
Alexandre Julliard's avatar
Alexandre Julliard committed
318
	}
319

320
	if (This->FolderSettings.fFlags & FWF_AUTOARRANGE)	dwStyle |= LVS_AUTOARRANGE;
321 322
	if (This->FolderSettings.fFlags & FWF_DESKTOP)
	  This->FolderSettings.fFlags |= FWF_NOCLIENTEDGE | FWF_NOSCROLL;
323
	if (This->FolderSettings.fFlags & FWF_SINGLESEL)	dwStyle |= LVS_SINGLESEL;
324 325
	if (This->FolderSettings.fFlags & FWF_NOCLIENTEDGE)
	  dwExStyle &= ~WS_EX_CLIENTEDGE;
Alexandre Julliard's avatar
Alexandre Julliard committed
326

327
	This->hWndList=CreateWindowExA( dwExStyle,
328 329 330 331 332 333 334 335
					WC_LISTVIEWA,
					NULL,
					dwStyle,
					0,0,0,0,
					This->hWnd,
					(HMENU)ID_LISTVIEW,
					shell32_hInstance,
					NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
336

337
	if(!This->hWndList)
Alexandre Julliard's avatar
Alexandre Julliard committed
338 339
	  return FALSE;

340 341 342 343
        This->ListViewSortInfo.bIsAscending = TRUE;
        This->ListViewSortInfo.nHeaderID = -1;
        This->ListViewSortInfo.nLastHeaderID = -1;

344
       if (This->FolderSettings.fFlags & FWF_DESKTOP) {
345 346 347 348 349 350 351
         /*
          * 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);
352
         else
353
           SendMessageW(This->hWndList, LVM_SETTEXTBKCOLOR, 0, GetSysColor(COLOR_DESKTOP));
354

355
         SendMessageW(This->hWndList, LVM_SETTEXTCOLOR, 0, RGB(255,255,255));
356 357
       }

358
        /*  UpdateShellSettings(); */
Alexandre Julliard's avatar
Alexandre Julliard committed
359
	return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
360
}
361

362
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
363
* ShellView_InitList()
364
*
365
* - adds all needed columns to the shellview
Alexandre Julliard's avatar
Alexandre Julliard committed
366
*/
367 368
static BOOL ShellView_InitList(IShellViewImpl * This)
{
369 370 371 372
	LVCOLUMNA	lvColumn;
	SHELLDETAILS	sd;
	int	i;
	char	szTemp[50];
Alexandre Julliard's avatar
Alexandre Julliard committed
373

374
	TRACE("%p\n",This);
Alexandre Julliard's avatar
Alexandre Julliard committed
375

376
	SendMessageW(This->hWndList, LVM_DELETEALLITEMS, 0, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
377

378 379
	lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
	lvColumn.pszText = szTemp;
Alexandre Julliard's avatar
Alexandre Julliard committed
380

381 382 383 384 385 386 387 388 389
	if (This->pSF2Parent)
	{
	  for (i=0; 1; i++)
	  {
	    if (!SUCCEEDED(IShellFolder2_GetDetailsOf(This->pSF2Parent, NULL, i, &sd)))
	      break;
	    lvColumn.fmt = sd.fmt;
	    lvColumn.cx = sd.cxChar*8; /* chars->pixel */
	    StrRetToStrNA( szTemp, 50, &sd.str, NULL);
390
	    SendMessageW(This->hWndList, LVM_INSERTCOLUMNW, i, (LPARAM) &lvColumn);
391 392 393 394 395 396
	  }
	}
	else
	{
	  FIXME("no SF2\n");
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
397

398 399
	SendMessageW(This->hWndList, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)ShellSmallIconList);
	SendMessageW(This->hWndList, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)ShellBigIconList);
400

401
	return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
402
}
403
/**********************************************************
404
* ShellView_CompareItems()
Alexandre Julliard's avatar
Alexandre Julliard committed
405 406
*
* NOTES
407
*  internal, CALLBACK for DSA_Sort
408
*/
409 410 411
static INT CALLBACK ShellView_CompareItems(LPVOID lParam1, LPVOID lParam2, LPARAM lpData)
{
	int ret;
412
	TRACE("pidl1=%p pidl2=%p lpsf=%p\n", lParam1, lParam2, (LPVOID) lpData);
Alexandre Julliard's avatar
Alexandre Julliard committed
413

414 415
	if(!lpData) return 0;

416
	ret =  (SHORT) SCODE_CODE(IShellFolder_CompareIDs((LPSHELLFOLDER)lpData, 0, (LPITEMIDLIST)lParam1, (LPITEMIDLIST)lParam2));
417
	TRACE("ret=%i\n",ret);
418
	return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
419 420
}

421 422 423 424 425 426 427 428 429 430 431
/*************************************************************************
 * 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
432 433
 *     A negative value if the first item should precede the second,
 *     a positive value if the first item should follow the second,
434 435 436
 *     or zero if the two items are equivalent
 *
 * NOTES
437 438 439
 *	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
440
 *	move this code to IShellFolder.
441
 *	make LISTVIEW_SORT_INFO obsolete
442
 *	the way this function works is only usable if we had only
443
 *	filesystemfolders  (25/10/99 jsch)
444 445 446 447 448 449 450 451 452
 */
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 = (LPITEMIDLIST) lParam1;
    LPITEMIDLIST pItemIdList2 = (LPITEMIDLIST) lParam2;
453
    LISTVIEW_SORT_INFO *pSortInfo = (LPLISTVIEW_SORT_INFO) lpData;
454 455 456 457 458 459 460 461 462 463 464 465


    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
466
    {
467
        /* Sort by Time: Folders or Files can be sorted */
468

469
        if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_TIME)
470 471 472 473 474 475
        {
            _ILGetFileDateTime(pItemIdList1, &fd1);
            _ILGetFileDateTime(pItemIdList2, &fd2);
            nDiff = CompareFileTime(&fd2, &fd1);
        }
        /* Sort by Attribute: Folder or Files can be sorted */
476
        else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_ATTRIB)
477
        {
478 479
            _ILGetFileAttributes(pItemIdList1, strName1, MAX_PATH);
            _ILGetFileAttributes(pItemIdList2, strName2, MAX_PATH);
480
            nDiff = lstrcmpiA(strName1, strName2);
481 482
        }
        /* Sort by FileName: Folder or Files can be sorted */
483
        else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_NAME || bIsBothFolder)
484 485 486 487
        {
            /* Sort by Text */
            _ILSimpleGetText(pItemIdList1, strName1, MAX_PATH);
            _ILSimpleGetText(pItemIdList2, strName2, MAX_PATH);
488
            nDiff = lstrcmpiA(strName1, strName2);
489 490
        }
        /* Sort by File Size, Only valid for Files */
491
        else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_SIZE)
492
        {
493
            nDiff = (INT)(_ILGetFileSize(pItemIdList1, NULL, 0) - _ILGetFileSize(pItemIdList2, NULL, 0));
494 495
        }
        /* Sort by File Type, Only valid for Files */
496
        else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_TYPE)
497 498 499 500
        {
            /* Sort by Type */
            _ILGetFileType(pItemIdList1, strName1, MAX_PATH);
            _ILGetFileType(pItemIdList2, strName2, MAX_PATH);
501
            nDiff = lstrcmpiA(strName1, strName2);
502 503 504
        }
    }
    /*  If the Date, FileSize, FileType, Attrib was the same, sort by FileName */
505

506 507 508 509
    if(nDiff == 0)
    {
        _ILSimpleGetText(pItemIdList1, strName1, MAX_PATH);
        _ILSimpleGetText(pItemIdList2, strName2, MAX_PATH);
510
        nDiff = lstrcmpiA(strName1, strName2);
511 512
    }

513 514 515 516 517
    if(!pSortInfo->bIsAscending)
    {
        nDiff = -nDiff;
    }

518 519 520 521
    return nDiff;

}

522 523
/**********************************************************
*  LV_FindItemByPidl()
524
*/
525 526
static int LV_FindItemByPidl(
	IShellViewImpl * This,
Juergen Schmied's avatar
Juergen Schmied committed
527
	LPCITEMIDLIST pidl)
528 529 530 531
{
	LVITEMA lvItem;
	ZeroMemory(&lvItem, sizeof(LVITEMA));
	lvItem.mask = LVIF_PARAM;
532 533 534
	for(lvItem.iItem = 0;
		SendMessageA(This->hWndList, LVM_GETITEMA, 0, (LPARAM) &lvItem);
		lvItem.iItem++)
535 536 537 538 539 540 541 542 543 544 545 546 547 548
	{
	  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()
*/
Juergen Schmied's avatar
Juergen Schmied committed
549
static BOOLEAN LV_AddItem(IShellViewImpl * This, LPCITEMIDLIST pidl)
550 551 552
{
	LVITEMA	lvItem;

Juergen Schmied's avatar
Juergen Schmied committed
553
	TRACE("(%p)(pidl=%p)\n", This, pidl);
554 555 556 557 558 559 560 561 562 563 564 565 566

	ZeroMemory(&lvItem, sizeof(lvItem));	/* create the listview item*/
	lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;	/*set the mask*/
	lvItem.iItem = ListView_GetItemCount(This->hWndList);	/*add the item to the end of the list*/
	lvItem.lParam = (LPARAM) ILClone(ILFindLastID(pidl));				/*set the item's data*/
	lvItem.pszText = LPSTR_TEXTCALLBACKA;			/*get text on a callback basis*/
	lvItem.iImage = I_IMAGECALLBACK;			/*get the image on a callback basis*/
	return (-1==ListView_InsertItemA(This->hWndList, &lvItem))? FALSE: TRUE;
}

/**********************************************************
* LV_DeleteItem()
*/
Juergen Schmied's avatar
Juergen Schmied committed
567
static BOOLEAN LV_DeleteItem(IShellViewImpl * This, LPCITEMIDLIST pidl)
568 569 570
{
	int nIndex;

Juergen Schmied's avatar
Juergen Schmied committed
571
	TRACE("(%p)(pidl=%p)\n", This, pidl);
572 573 574 575 576 577 578 579

	nIndex = LV_FindItemByPidl(This, ILFindLastID(pidl));
	return (-1==ListView_DeleteItem(This->hWndList, nIndex))? FALSE: TRUE;
}

/**********************************************************
* LV_RenameItem()
*/
Juergen Schmied's avatar
Juergen Schmied committed
580
static BOOLEAN LV_RenameItem(IShellViewImpl * This, LPCITEMIDLIST pidlOld, LPCITEMIDLIST pidlNew )
581 582 583 584
{
	int nItem;
	LVITEMA lvItem;

Juergen Schmied's avatar
Juergen Schmied committed
585
	TRACE("(%p)(pidlold=%p pidlnew=%p)\n", This, pidlOld, pidlNew);
586 587 588 589 590 591 592

	nItem = LV_FindItemByPidl(This, ILFindLastID(pidlOld));
	if ( -1 != nItem )
	{
	  ZeroMemory(&lvItem, sizeof(lvItem));	/* create the listview item*/
	  lvItem.mask = LVIF_PARAM;		/* only the pidl */
	  lvItem.iItem = nItem;
593
	  SendMessageA(This->hWndList, LVM_GETITEMA, 0, (LPARAM) &lvItem);
594 595 596 597 598

	  SHFree((LPITEMIDLIST)lvItem.lParam);
	  lvItem.mask = LVIF_PARAM;
	  lvItem.iItem = nItem;
	  lvItem.lParam = (LPARAM) ILClone(ILFindLastID(pidlNew));	/* set the item's data */
599 600
	  SendMessageA(This->hWndList, LVM_SETITEMA, 0, (LPARAM) &lvItem);
	  SendMessageA(This->hWndList, LVM_UPDATE, nItem, 0);
601
	  return TRUE;					/* FIXME: better handling */
602 603 604
	}
	return FALSE;
}
605
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
606 607
* ShellView_FillList()
*
608 609 610
* - gets the objectlist from the shellfolder
* - sorts the list
* - fills the list into the view
611
*/
Alexandre Julliard's avatar
Alexandre Julliard committed
612

613 614 615 616 617 618 619 620 621 622
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;
}

623
static HRESULT ShellView_FillList(IShellViewImpl * This)
624 625
{
	LPENUMIDLIST	pEnumIDList;
626 627 628 629
	LPITEMIDLIST	pidl;
	DWORD		dwFetched;
	HRESULT		hRes;
	HDPA		hdpa;
Alexandre Julliard's avatar
Alexandre Julliard committed
630

631
	TRACE("%p\n",This);
Alexandre Julliard's avatar
Alexandre Julliard committed
632

633
	/* get the itemlist from the shfolder*/
634 635
	hRes = IShellFolder_EnumObjects(This->pSFParent,This->hWnd, SHCONTF_NONFOLDERS | SHCONTF_FOLDERS, &pEnumIDList);
	if (hRes != S_OK)
636 637
	{
	  if (hRes==S_FALSE)
638 639
	    return(NOERROR);
	  return(hRes);
640
	}
641

642
	/* create a pointer array */
643
	hdpa = DPA_Create(16);
644
	if (!hdpa)
645 646
	{
	  return(E_OUTOFMEMORY);
647
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
648

649
	/* copy the items into the array*/
650
	while((S_OK == IEnumIDList_Next(pEnumIDList,1, &pidl, &dwFetched)) && dwFetched)
651
	{
652
	  if (DPA_InsertPtr(hdpa, 0x7fff, pidl) == -1)
653 654
	  {
	    SHFree(pidl);
655
	  }
656
	}
657

658
	/* sort the array */
659
	DPA_Sort(hdpa, ShellView_CompareItems, (LPARAM)This->pSFParent);
660 661

	/*turn the listview's redrawing off*/
662
	SendMessageA(This->hWndList, WM_SETREDRAW, FALSE, 0);
663

664
        DPA_DestroyCallback( hdpa, fill_list, This );
665 666

	/*turn the listview's redrawing back on and force it to draw*/
667
	SendMessageA(This->hWndList, WM_SETREDRAW, TRUE, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
668

669
	IEnumIDList_Release(pEnumIDList); /* destroy the list*/
670

671
	return S_OK;
Alexandre Julliard's avatar
Alexandre Julliard committed
672 673
}

674
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
675
*  ShellView_OnCreate()
676
*/
677 678
static LRESULT ShellView_OnCreate(IShellViewImpl * This)
{
679
	IDropTarget* pdt;
680
	SHChangeNotifyEntry ntreg;
681
	IPersistFolder2 * ppf2 = NULL;
682

683
	TRACE("%p\n",This);
Alexandre Julliard's avatar
Alexandre Julliard committed
684

685 686 687 688 689 690
	if(ShellView_CreateList(This))
	{
	  if(ShellView_InitList(This))
	  {
	    ShellView_FillList(This);
	  }
Alexandre Julliard's avatar
Alexandre Julliard committed
691
	}
692

693
        if (SUCCEEDED(IUnknown_QueryInterface((IUnknown*)&This->lpVtbl, &IID_IDropTarget, (LPVOID*)&pdt)))
694
	{
695
	    RegisterDragDrop(This->hWnd, pdt);
696
	    IDropTarget_Release(pdt);
697
	}
698 699 700 701 702

	/* register for receiving notifications */
	IShellFolder_QueryInterface(This->pSFParent, &IID_IPersistFolder2, (LPVOID*)&ppf2);
	if (ppf2)
	{
703
	  IPersistFolder2_GetCurFolder(ppf2, (LPITEMIDLIST*)&ntreg.pidl);
704
	  ntreg.fRecursive = TRUE;
705
	  This->hNotify = SHChangeNotifyRegister(This->hWnd, SHCNF_IDLIST, SHCNE_ALLEVENTS, SHV_CHANGE_NOTIFY, 1, &ntreg);
706
	  SHFree((LPITEMIDLIST)ntreg.pidl);
707 708 709 710
	  IPersistFolder2_Release(ppf2);
	}

	This->hAccel = LoadAcceleratorsA(shell32_hInstance, "shv_accel");
711

Alexandre Julliard's avatar
Alexandre Julliard committed
712
	return S_OK;
Alexandre Julliard's avatar
Alexandre Julliard committed
713
}
714 715 716 717 718 719

/**********************************************************
 *	#### Handling of the menus ####
 */

/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
720
* ShellView_BuildFileMenu()
721 722
*/
static HMENU ShellView_BuildFileMenu(IShellViewImpl * This)
723
{	CHAR	szText[MAX_PATH];
724
	MENUITEMINFOA	mii;
725
	int	nTools,i;
726
	HMENU	hSubMenu;
Alexandre Julliard's avatar
Alexandre Julliard committed
727

728
	TRACE("(%p)\n",This);
Alexandre Julliard's avatar
Alexandre Julliard committed
729

730
	hSubMenu = CreatePopupMenu();
Alexandre Julliard's avatar
Alexandre Julliard committed
731 732
	if(hSubMenu)
	{ /*get the number of items in our global array*/
733
	  for(nTools = 0; Tools[nTools].idCommand != -1; nTools++){}
Alexandre Julliard's avatar
Alexandre Julliard committed
734

Alexandre Julliard's avatar
Alexandre Julliard committed
735
	  /*add the menu items*/
Alexandre Julliard's avatar
Alexandre Julliard committed
736
	  for(i = 0; i < nTools; i++)
737
	  {
738 739
	    LoadStringA(shell32_hInstance, Tools[i].idMenuString, szText, MAX_PATH);

Alexandre Julliard's avatar
Alexandre Julliard committed
740 741 742 743
	    ZeroMemory(&mii, sizeof(mii));
	    mii.cbSize = sizeof(mii);
	    mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;

744
	    if(BTNS_SEP != Tools[i].bStyle) /* no separator*/
745 746
	    {
	      mii.fType = MFT_STRING;
Alexandre Julliard's avatar
Alexandre Julliard committed
747 748
	      mii.fState = MFS_ENABLED;
	      mii.dwTypeData = szText;
749
	      mii.wID = Tools[i].idCommand;
Alexandre Julliard's avatar
Alexandre Julliard committed
750
	    }
Alexandre Julliard's avatar
Alexandre Julliard committed
751
	    else
752 753
	    {
	      mii.fType = MFT_SEPARATOR;
Alexandre Julliard's avatar
Alexandre Julliard committed
754
	    }
755
	    /* tack This item onto the end of the menu */
756
	    InsertMenuItemA(hSubMenu, (UINT)-1, TRUE, &mii);
Alexandre Julliard's avatar
Alexandre Julliard committed
757
	  }
Alexandre Julliard's avatar
Alexandre Julliard committed
758
	}
759
	TRACE("-- return (menu=%p)\n",hSubMenu);
Alexandre Julliard's avatar
Alexandre Julliard committed
760 761
	return hSubMenu;
}
762
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
763
* ShellView_MergeFileMenu()
764 765
*/
static void ShellView_MergeFileMenu(IShellViewImpl * This, HMENU hSubMenu)
766
{	TRACE("(%p)->(submenu=%p) stub\n",This,hSubMenu);
Alexandre Julliard's avatar
Alexandre Julliard committed
767 768

	if(hSubMenu)
769
	{ /*insert This item at the beginning of the menu */
770
	  _InsertMenuItem(hSubMenu, 0, TRUE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED);
771
	  _InsertMenuItem(hSubMenu, 0, TRUE, IDM_MYFILEITEM, MFT_STRING, "dummy45", MFS_ENABLED);
Alexandre Julliard's avatar
Alexandre Julliard committed
772 773

	}
774
	TRACE("--\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
775 776
}

777
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
778
* ShellView_MergeViewMenu()
779
*/
780

781
static void ShellView_MergeViewMenu(IShellViewImpl * This, HMENU hSubMenu)
782
{	MENUITEMINFOA	mii;
783

784
	TRACE("(%p)->(submenu=%p)\n",This,hSubMenu);
785

Alexandre Julliard's avatar
Alexandre Julliard committed
786
	if(hSubMenu)
787 788
	{ /*add a separator at the correct position in the menu*/
	  _InsertMenuItem(hSubMenu, FCIDM_MENU_VIEW_SEP_OPTIONS, FALSE, 0, MFT_SEPARATOR, NULL, MFS_ENABLED);
789 790 791

	  ZeroMemory(&mii, sizeof(mii));
	  mii.cbSize = sizeof(mii);
792
	  mii.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_DATA;
793 794
	  mii.fType = MFT_STRING;
	  mii.dwTypeData = "View";
795
	  mii.hSubMenu = LoadMenuA(shell32_hInstance, "MENU_001");
796
	  InsertMenuItemA(hSubMenu, FCIDM_MENU_VIEW_SEP_OPTIONS, FALSE, &mii);
Alexandre Julliard's avatar
Alexandre Julliard committed
797 798
	}
}
799

800 801 802
/**********************************************************
*   ShellView_GetSelections()
*
803 804
* - fills the this->apidl list with the selected objects
*
805 806
* RETURNS
*  number of selected items
807
*/
808 809 810 811 812 813 814 815 816 817 818 819 820 821
static UINT ShellView_GetSelections(IShellViewImpl * This)
{
	LVITEMA	lvItem;
	UINT	i = 0;

	if (This->apidl)
	{
	  SHFree(This->apidl);
	}

	This->cidl = ListView_GetSelectedCount(This->hWndList);
	This->apidl = (LPITEMIDLIST*)SHAlloc(This->cidl * sizeof(LPITEMIDLIST));

	TRACE("selected=%i\n", This->cidl);
822

823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
	if(This->apidl)
	{
	  TRACE("-- Items selected =%u\n", This->cidl);

	  ZeroMemory(&lvItem, sizeof(lvItem));
	  lvItem.mask = LVIF_STATE | LVIF_PARAM;
	  lvItem.stateMask = LVIS_SELECTED;

	  while(ListView_GetItemA(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;

}
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

/**********************************************************
 *	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;
	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 = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
	}
	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]);
	for (i = pIDList->cidl; i > 0; --i)
	{
	  LPCITEMIDLIST pidl;
	  SFGAOF attribs;

	  pidl = (LPCITEMIDLIST)((LPBYTE)pIDList+pIDList->aoffset[i]);

	  attribs = SFGAO_FOLDER;
	  hr = IShellFolder_GetAttributesOf(This->pSFParent, 1, &pidl, &attribs);

	  if (SUCCEEDED(hr) && ! (attribs & SFGAO_FOLDER))
	  {
	    SHELLEXECUTEINFOA shexinfo;

	    shexinfo.cbSize = sizeof(SHELLEXECUTEINFOA);
	    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 = NULL;
	    shexinfo.nShow = SW_NORMAL;
	    shexinfo.lpIDList = ILCombine(parent_pidl, pidl);

	    ShellExecuteExA(&shexinfo);    /* Discard error/success info */

	    ILFree((LPITEMIDLIST)shexinfo.lpIDList);
	  }
	}

	GlobalUnlock(stgm.u.hGlobal);
	ReleaseStgMedium(&stgm);

	IDataObject_Release(selection);

	return S_OK;
}

929 930 931 932 933 934 935 936 937 938
/**********************************************************
 *	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;
939
	IContextMenu2 *pCM = NULL;
940
	CMINVOKECOMMANDINFO	cmi;
941

942 943 944 945 946
	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) )
	{
947
	  IShellFolder_GetUIObjectOf( This->pSFParent, This->hWndParent, This->cidl, (LPCITEMIDLIST*)This->apidl,
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
					(REFIID)&IID_IContextMenu, NULL, (LPVOID *)&pContextMenu);

	  if(pContextMenu)
	  {
	    TRACE("-- pContextMenu\n");
	    hMenu = CreatePopupMenu();

	    if( hMenu )
	    {
	      /* See if we are in Explore or Open mode. If the browser's tree is present, we are in Explore mode.*/
	      if(SUCCEEDED(IShellBrowser_GetControlWindow(This->pShellBrowser,FCW_TREE, &hwndTree)) && hwndTree)
	      {
	        TRACE("-- explore mode\n");
	        fExplore = TRUE;
	      }

	      /* build the flags depending on what we can do with the selected item */
	      wFlags = CMF_NORMAL | (This->cidl != 1 ? 0 : CMF_CANRENAME) | (fExplore ? CMF_EXPLORE : 0);

	      /* let the ContextMenu merge its items in */
	      if (SUCCEEDED(IContextMenu_QueryContextMenu( pContextMenu, hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, wFlags )))
	      {
970 971 972
	        if (This->FolderSettings.fFlags & FWF_DESKTOP)
		  SetMenuDefaultItem(hMenu, FCIDM_SHVIEW_OPEN, MF_BYCOMMAND);

973 974 975 976 977 978 979 980 981
		if( bDefault )
		{
		  TRACE("-- get menu default command\n");
		  uCommand = GetMenuDefaultItem(hMenu, FALSE, GMDI_GOINTOPOPUPS);
		}
		else
		{
		  TRACE("-- track popup\n");
		  uCommand = TrackPopupMenu( hMenu,TPM_LEFTALIGN | TPM_RETURNCMD,x,y,0,This->hWnd,NULL);
982
		}
983 984 985 986

		if(uCommand > 0)
		{
		  TRACE("-- uCommand=%u\n", uCommand);
987
		  if (uCommand==FCIDM_SHVIEW_OPEN && IsInCommDlg(This))
988 989
		  {
		    TRACE("-- dlg: OnDefaultCommand\n");
990
		    if (OnDefaultCommand(This) != S_OK)
991 992 993
		    {
		      ShellView_OpenSelectedItems(This);
		    }
994 995 996 997 998 999
		  }
		  else
		  {
		    TRACE("-- explore -- invoke command\n");
		    ZeroMemory(&cmi, sizeof(cmi));
		    cmi.cbSize = sizeof(cmi);
1000
		    cmi.hwnd = This->hWndParent; /* this window has to answer CWM_GETISHELLBROWSER */
1001 1002 1003 1004 1005 1006 1007 1008 1009
		    cmi.lpVerb = (LPCSTR)MAKEINTRESOURCEA(uCommand);
		    IContextMenu_InvokeCommand(pContextMenu, &cmi);
		  }
		}
		DestroyMenu(hMenu);
	      }
	    }
	    if (pContextMenu)
	      IContextMenu_Release(pContextMenu);
1010 1011
	  }
	}
1012
	else	/* background context menu */
1013
	{
1014 1015
	  hMenu = CreatePopupMenu();

1016
	  pCM = ISvBgCm_Constructor(This->pSFParent, FALSE);
1017
	  IContextMenu2_QueryContextMenu(pCM, hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, 0);
1018 1019 1020 1021

	  uCommand = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_RETURNCMD,x,y,0,This->hWnd,NULL);
	  DestroyMenu(hMenu);

1022
	  TRACE("-- (%p)->(uCommand=0x%08x )\n",This, uCommand);
1023 1024 1025 1026 1027

	  ZeroMemory(&cmi, sizeof(cmi));
	  cmi.cbSize = sizeof(cmi);
	  cmi.lpVerb = (LPCSTR)MAKEINTRESOURCEA(uCommand);
	  cmi.hwnd = This->hWndParent;
1028
	  IContextMenu2_InvokeCommand(pCM, &cmi);
1029

1030
	  IContextMenu2_Release(pCM);
1031
	}
1032 1033
}

1034 1035 1036 1037 1038 1039
/**********************************************************
 *	##### message handling #####
 */

/**********************************************************
*  ShellView_OnSize()
Alexandre Julliard's avatar
Alexandre Julliard committed
1040
*/
1041 1042 1043
static LRESULT ShellView_OnSize(IShellViewImpl * This, WORD wWidth, WORD wHeight)
{
	TRACE("%p width=%u height=%u\n",This, wWidth,wHeight);
Alexandre Julliard's avatar
Alexandre Julliard committed
1044

1045 1046 1047 1048
	/*resize the ListView to fit our window*/
	if(This->hWndList)
	{
	  MoveWindow(This->hWndList, 0, 0, wWidth, wHeight, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1049
	}
1050

1051
	return S_OK;
Alexandre Julliard's avatar
Alexandre Julliard committed
1052
}
1053
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1054 1055 1056 1057
* ShellView_OnDeactivate()
*
* NOTES
*  internal
1058
*/
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
static void ShellView_OnDeactivate(IShellViewImpl * This)
{
	TRACE("%p\n",This);

	if(This->uState != SVUIA_DEACTIVATE)
	{
	  if(This->hMenu)
	  {
	    IShellBrowser_SetMenuSB(This->pShellBrowser,0, 0, 0);
	    IShellBrowser_RemoveMenusSB(This->pShellBrowser,This->hMenu);
	    DestroyMenu(This->hMenu);
	    This->hMenu = 0;
	  }

	  This->uState = SVUIA_DEACTIVATE;
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
1075 1076
}

1077
/**********************************************************
1078
* ShellView_OnActivate()
1079
*/
1080
static LRESULT ShellView_OnActivate(IShellViewImpl * This, UINT uState)
1081 1082
{	OLEMENUGROUPWIDTHS   omw = { {0, 0, 0, 0, 0, 0} };
	MENUITEMINFOA         mii;
Alexandre Julliard's avatar
Alexandre Julliard committed
1083
	CHAR                szText[MAX_PATH];
Alexandre Julliard's avatar
Alexandre Julliard committed
1084

1085
	TRACE("%p uState=%x\n",This,uState);
Alexandre Julliard's avatar
Alexandre Julliard committed
1086

1087
	/*don't do anything if the state isn't really changing */
1088
	if(This->uState == uState)
1089 1090
	{
	  return S_OK;
Alexandre Julliard's avatar
Alexandre Julliard committed
1091
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
1092

1093
	ShellView_OnDeactivate(This);
Alexandre Julliard's avatar
Alexandre Julliard committed
1094

1095
	/*only do This if we are active */
Alexandre Julliard's avatar
Alexandre Julliard committed
1096
	if(uState != SVUIA_DEACTIVATE)
1097 1098
	{
	  /*merge the menus */
1099
	  This->hMenu = CreateMenu();
1100

1101
	  if(This->hMenu)
1102 1103
	  {
	    IShellBrowser_InsertMenusSB(This->pShellBrowser, This->hMenu, &omw);
1104
	    TRACE("-- after fnInsertMenusSB\n");
1105

Alexandre Julliard's avatar
Alexandre Julliard committed
1106 1107
	    /*build the top level menu get the menu item's text*/
	    strcpy(szText,"dummy 31");
1108

Alexandre Julliard's avatar
Alexandre Julliard committed
1109 1110 1111 1112 1113 1114
	    ZeroMemory(&mii, sizeof(mii));
	    mii.cbSize = sizeof(mii);
	    mii.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_STATE;
	    mii.fType = MFT_STRING;
	    mii.fState = MFS_ENABLED;
	    mii.dwTypeData = szText;
1115
	    mii.hSubMenu = ShellView_BuildFileMenu(This);
Alexandre Julliard's avatar
Alexandre Julliard committed
1116 1117 1118

	    /*insert our menu into the menu bar*/
	    if(mii.hSubMenu)
1119 1120
	    {
	      InsertMenuItemA(This->hMenu, FCIDM_MENU_HELP, FALSE, &mii);
Alexandre Julliard's avatar
Alexandre Julliard committed
1121 1122 1123 1124 1125 1126
	    }

	    /*get the view menu so we can merge with it*/
	    ZeroMemory(&mii, sizeof(mii));
	    mii.cbSize = sizeof(mii);
	    mii.fMask = MIIM_SUBMENU;
1127

1128
	    if(GetMenuItemInfoA(This->hMenu, FCIDM_MENU_VIEW, FALSE, &mii))
1129 1130
	    {
	      ShellView_MergeViewMenu(This, mii.hSubMenu);
Alexandre Julliard's avatar
Alexandre Julliard committed
1131
	    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1132

Alexandre Julliard's avatar
Alexandre Julliard committed
1133 1134
	    /*add the items that should only be added if we have the focus*/
	    if(SVUIA_ACTIVATE_FOCUS == uState)
1135 1136
	    {
	      /*get the file menu so we can merge with it */
Alexandre Julliard's avatar
Alexandre Julliard committed
1137
	      ZeroMemory(&mii, sizeof(mii));
Alexandre Julliard's avatar
Alexandre Julliard committed
1138
	      mii.cbSize = sizeof(mii);
Alexandre Julliard's avatar
Alexandre Julliard committed
1139
	      mii.fMask = MIIM_SUBMENU;
1140

1141
	      if(GetMenuItemInfoA(This->hMenu, FCIDM_MENU_FILE, FALSE, &mii))
1142 1143
	      {
	        ShellView_MergeFileMenu(This, mii.hSubMenu);
Alexandre Julliard's avatar
Alexandre Julliard committed
1144 1145
	      }
	    }
1146
	    TRACE("-- before fnSetMenuSB\n");
1147
	    IShellBrowser_SetMenuSB(This->pShellBrowser, This->hMenu, 0, This->hWnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
1148 1149
	  }
	}
1150
	This->uState = uState;
1151
	TRACE("--\n");
1152
	return S_OK;
Alexandre Julliard's avatar
Alexandre Julliard committed
1153 1154
}

1155
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1156 1157 1158
*  ShellView_OnSetFocus()
*
*/
1159 1160 1161 1162 1163
static LRESULT ShellView_OnSetFocus(IShellViewImpl * This)
{
	TRACE("%p\n",This);

	/* Tell the browser one of our windows has received the focus. This
1164
	should always be done before merging menus (OnActivate merges the
1165 1166
	menus) if one of our windows has the focus.*/

1167 1168
	IShellBrowser_OnViewWindowActive(This->pShellBrowser,(IShellView*) This);
	ShellView_OnActivate(This, SVUIA_ACTIVATE_FOCUS);
Alexandre Julliard's avatar
Alexandre Julliard committed
1169

1170 1171 1172
	/* Set the focus to the listview */
	SetFocus(This->hWndList);

1173 1174 1175
	/* Notify the ICommDlgBrowser interface */
	OnStateChange(This,CDBOSC_SETFOCUS);

Alexandre Julliard's avatar
Alexandre Julliard committed
1176
	return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1177 1178
}

1179
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1180
* ShellView_OnKillFocus()
1181
*/
1182 1183 1184
static LRESULT ShellView_OnKillFocus(IShellViewImpl * This)
{
	TRACE("(%p) stub\n",This);
Alexandre Julliard's avatar
Alexandre Julliard committed
1185

1186
	ShellView_OnActivate(This, SVUIA_ACTIVATE_NOFOCUS);
1187 1188
	/* Notify the ICommDlgBrowser */
	OnStateChange(This,CDBOSC_KILLFOCUS);
Alexandre Julliard's avatar
Alexandre Julliard committed
1189 1190 1191

	return 0;
}
1192 1193

/**********************************************************
1194
* ShellView_OnCommand()
1195 1196 1197
*
* NOTES
*	the CmdID's are the ones from the context menu
1198
*/
1199 1200
static LRESULT ShellView_OnCommand(IShellViewImpl * This,DWORD dwCmdID, DWORD dwCmd, HWND hwndCmd)
{
1201
	TRACE("(%p)->(0x%08lx 0x%08lx %p) stub\n",This, dwCmdID, dwCmd, hwndCmd);
1202

1203 1204
	switch(dwCmdID)
	{
1205
	  case FCIDM_SHVIEW_SMALLICON:
1206 1207
	    This->FolderSettings.ViewMode = FVM_SMALLICON;
	    SetStyle (This, LVS_SMALLICON, LVS_TYPEMASK);
1208
	    CheckToolbar(This);
1209 1210 1211
	    break;

	  case FCIDM_SHVIEW_BIGICON:
1212 1213
	    This->FolderSettings.ViewMode = FVM_ICON;
	    SetStyle (This, LVS_ICON, LVS_TYPEMASK);
1214
	    CheckToolbar(This);
1215 1216 1217
	    break;

	  case FCIDM_SHVIEW_LISTVIEW:
1218 1219
	    This->FolderSettings.ViewMode = FVM_LIST;
	    SetStyle (This, LVS_LIST, LVS_TYPEMASK);
1220
	    CheckToolbar(This);
1221 1222 1223
	    break;

	  case FCIDM_SHVIEW_REPORTVIEW:
1224 1225
	    This->FolderSettings.ViewMode = FVM_DETAILS;
	    SetStyle (This, LVS_REPORT, LVS_TYPEMASK);
1226
	    CheckToolbar(This);
1227 1228
	    break;

1229 1230 1231 1232 1233
	  /* the menu-ID's for sorting are 0x30... see shrec.rc */
	  case 0x30:
	  case 0x31:
	  case 0x32:
	  case 0x33:
1234 1235 1236
	    This->ListViewSortInfo.nHeaderID = (LPARAM) (dwCmdID - 0x30);
	    This->ListViewSortInfo.bIsAscending = TRUE;
	    This->ListViewSortInfo.nLastHeaderID = This->ListViewSortInfo.nHeaderID;
1237
	    SendMessageA(This->hWndList, LVM_SORTITEMS, (WPARAM) &This->ListViewSortInfo, (LPARAM)ShellView_ListViewCompareItems);
1238
	    break;
1239

1240
	  default:
1241
	    TRACE("-- COMMAND 0x%04lx unhandled\n", dwCmdID);
1242 1243 1244 1245
	}
	return 0;
}

1246
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1247 1248
* ShellView_OnNotify()
*/
1249

1250
static LRESULT ShellView_OnNotify(IShellViewImpl * This, UINT CtlID, LPNMHDR lpnmh)
1251
{	LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lpnmh;
1252
	NMLVDISPINFOA *lpdi = (NMLVDISPINFOA *)lpnmh;
Alexandre Julliard's avatar
Alexandre Julliard committed
1253
	LPITEMIDLIST pidl;
1254

1255
	TRACE("%p CtlID=%u lpnmh->code=%x\n",This,CtlID,lpnmh->code);
1256

Alexandre Julliard's avatar
Alexandre Julliard committed
1257
	switch(lpnmh->code)
1258 1259
	{
	  case NM_SETFOCUS:
1260
	    TRACE("-- NM_SETFOCUS %p\n",This);
1261
	    ShellView_OnSetFocus(This);
Alexandre Julliard's avatar
Alexandre Julliard committed
1262 1263 1264
	    break;

	  case NM_KILLFOCUS:
1265
	    TRACE("-- NM_KILLFOCUS %p\n",This);
1266
	    ShellView_OnDeactivate(This);
1267 1268
	    /* Notify the ICommDlgBrowser interface */
	    OnStateChange(This,CDBOSC_KILLFOCUS);
Alexandre Julliard's avatar
Alexandre Julliard committed
1269 1270
	    break;

1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
	  case NM_CUSTOMDRAW:
	    TRACE("-- NM_CUSTOMDRAW %p\n",This);
	    return CDRF_DODEFAULT;

	  case NM_RELEASEDCAPTURE:
	    TRACE("-- NM_RELEASEDCAPTURE %p\n",This);
	    break;

	  case NM_CLICK:
	    TRACE("-- NM_CLICK %p\n",This);
	    break;

	  case NM_RCLICK:
	    TRACE("-- NM_RCLICK %p\n",This);
	    break;	    

1287 1288 1289 1290 1291 1292 1293 1294 1295 1296
          case NM_DBLCLK:
            TRACE("-- NM_DBLCLK %p\n",This);
            if (OnDefaultCommand(This) != S_OK) ShellView_OpenSelectedItems(This);
            break;

          case NM_RETURN:
            TRACE("-- NM_DBLCLK %p\n",This);
            if (OnDefaultCommand(This) != S_OK) ShellView_OpenSelectedItems(This);
            break;

1297
	  case HDN_ENDTRACKA:
1298
	    TRACE("-- HDN_ENDTRACKA %p\n",This);
1299 1300
	    /*nColumn1 = ListView_GetColumnWidth(This->hWndList, 0);
	    nColumn2 = ListView_GetColumnWidth(This->hWndList, 1);*/
Alexandre Julliard's avatar
Alexandre Julliard committed
1301
	    break;
1302

Alexandre Julliard's avatar
Alexandre Julliard committed
1303
	  case LVN_DELETEITEM:
1304
	    TRACE("-- LVN_DELETEITEM %p\n",This);
Alexandre Julliard's avatar
Alexandre Julliard committed
1305 1306
	    SHFree((LPITEMIDLIST)lpnmlv->lParam);     /*delete the pidl because we made a copy of it*/
	    break;
Alexandre Julliard's avatar
Alexandre Julliard committed
1307

1308 1309 1310 1311
	  case LVN_DELETEALLITEMS:
	    TRACE("-- LVN_DELETEALLITEMS %p\n",This);
	    return FALSE;

1312 1313 1314 1315
	  case LVN_INSERTITEM:
	    TRACE("-- LVN_INSERTITEM (STUB)%p\n",This);
	    break;

Alexandre Julliard's avatar
Alexandre Julliard committed
1316
	  case LVN_ITEMACTIVATE:
1317
	    TRACE("-- LVN_ITEMACTIVATE %p\n",This);
1318
	    OnStateChange(This, CDBOSC_SELCHANGE);  /* the browser will get the IDataObject now */
Alexandre Julliard's avatar
Alexandre Julliard committed
1319
	    break;
1320

1321
	  case LVN_COLUMNCLICK:
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331
	    This->ListViewSortInfo.nHeaderID = lpnmlv->iSubItem;
	    if(This->ListViewSortInfo.nLastHeaderID == This->ListViewSortInfo.nHeaderID)
	    {
	      This->ListViewSortInfo.bIsAscending = !This->ListViewSortInfo.bIsAscending;
	    }
	    else
	    {
	      This->ListViewSortInfo.bIsAscending = TRUE;
	    }
	    This->ListViewSortInfo.nLastHeaderID = This->ListViewSortInfo.nHeaderID;
1332

1333
	    SendMessageA(lpnmlv->hdr.hwndFrom, LVM_SORTITEMS, (WPARAM) &This->ListViewSortInfo, (LPARAM)ShellView_ListViewCompareItems);
1334
	    break;
1335

1336
	  case LVN_GETDISPINFOA:
1337 1338
          case LVN_GETDISPINFOW:
	    TRACE("-- LVN_GETDISPINFO %p\n",This);
Alexandre Julliard's avatar
Alexandre Julliard committed
1339 1340
	    pidl = (LPITEMIDLIST)lpdi->item.lParam;

1341 1342 1343
	    if(lpdi->item.mask & LVIF_TEXT)	/* text requested */
	    {
	      if (This->pSF2Parent)
1344
	      {
1345 1346
	        SHELLDETAILS sd;
	        IShellFolder2_GetDetailsOf(This->pSF2Parent, pidl, lpdi->item.iSubItem, &sd);
1347 1348 1349 1350 1351 1352 1353
                if (lpnmh->code == LVN_GETDISPINFOA)
                {
                    StrRetToStrNA( lpdi->item.pszText, lpdi->item.cchTextMax, &sd.str, NULL);
                    TRACE("-- text=%s\n",lpdi->item.pszText);
                }
                else /* LVN_GETDISPINFOW */
                {
1354
                    StrRetToStrNW( ((NMLVDISPINFOW *)lpdi)->item.pszText, lpdi->item.cchTextMax, &sd.str, NULL);
1355 1356
                    TRACE("-- text=%s\n",debugstr_w((WCHAR*)(lpdi->item.pszText)));
                }
Alexandre Julliard's avatar
Alexandre Julliard committed
1357
	      }
1358
	      else
1359
	      {
1360
	        FIXME("no SF2\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
1361 1362
	      }
	    }
1363 1364 1365 1366
	    if(lpdi->item.mask & LVIF_IMAGE)	/* image requested */
	    {
	      lpdi->item.iImage = SHMapPIDLToSystemImageListIndex(This->pSFParent, pidl, 0);
	    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1367
	    break;
Alexandre Julliard's avatar
Alexandre Julliard committed
1368

Alexandre Julliard's avatar
Alexandre Julliard committed
1369
	  case LVN_ITEMCHANGED:
1370
	    TRACE("-- LVN_ITEMCHANGED %p\n",This);
1371
	    OnStateChange(This, CDBOSC_SELCHANGE);  /* the browser will get the IDataObject now */
Alexandre Julliard's avatar
Alexandre Julliard committed
1372 1373
	    break;

1374 1375
	  case LVN_BEGINDRAG:
	  case LVN_BEGINRDRAG:
1376
	    TRACE("-- LVN_BEGINDRAG\n");
1377 1378

	    if (ShellView_GetSelections(This))
1379
	    {
1380
	      IDataObject * pda;
Juergen Schmied's avatar
Juergen Schmied committed
1381
	      DWORD dwAttributes = SFGAO_CANLINK;
1382
	      DWORD dwEffect = DROPEFFECT_COPY | DROPEFFECT_MOVE;
1383

1384
	      if (SUCCEEDED(IShellFolder_GetUIObjectOf(This->pSFParent, This->hWnd, This->cidl, (LPCITEMIDLIST*)This->apidl, &IID_IDataObject,0,(LPVOID *)&pda)))
1385
	      {
1386
	          IDropSource * pds = (IDropSource*)&(This->lpvtblDropSource);	/* own DropSource interface */
1387

1388
	  	  if (SUCCEEDED(IShellFolder_GetAttributesOf(This->pSFParent, This->cidl, (LPCITEMIDLIST*)This->apidl, &dwAttributes)))
1389
		  {
1390 1391 1392 1393
		    if (dwAttributes & SFGAO_CANLINK)
		    {
		      dwEffect |= DROPEFFECT_LINK;
		    }
1394
		  }
1395

1396 1397 1398
	          if (pds)
	          {
	            DWORD dwEffect;
1399
		    DoDragDrop(pda, pds, dwEffect, &dwEffect);
1400 1401
		  }
	          IDataObject_Release(pda);
1402 1403 1404 1405 1406
	      }
	    }
	    break;

	  case LVN_BEGINLABELEDITA:
1407 1408 1409 1410 1411 1412
	    {
	      DWORD dwAttr = SFGAO_CANRENAME;
	      pidl = (LPITEMIDLIST)lpdi->item.lParam;

	      TRACE("-- LVN_BEGINLABELEDITA %p\n",This);

1413
	      IShellFolder_GetAttributesOf(This->pSFParent, 1, (LPCITEMIDLIST*)&pidl, &dwAttr);
1414 1415 1416 1417 1418 1419 1420
	      if (SFGAO_CANRENAME & dwAttr)
	      {
	        return FALSE;
	      }
	      return TRUE;
	    }

1421
	  case LVN_ENDLABELEDITA:
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432
	    {
	      TRACE("-- LVN_ENDLABELEDITA %p\n",This);
	      if (lpdi->item.pszText)
	      {
	        HRESULT hr;
		WCHAR wszNewName[MAX_PATH];
		LVITEMA lvItem;

		ZeroMemory(&lvItem, sizeof(LVITEMA));
		lvItem.iItem = lpdi->item.iItem;
		lvItem.mask = LVIF_PARAM;
1433
		SendMessageA(This->hWndList, LVM_GETITEMA, 0, (LPARAM) &lvItem);
1434

1435
		pidl = (LPITEMIDLIST)lpdi->item.lParam;
1436 1437
                if (!MultiByteToWideChar( CP_ACP, 0, lpdi->item.pszText, -1, wszNewName, MAX_PATH ))
                    wszNewName[MAX_PATH-1] = 0;
1438
	        hr = IShellFolder_SetNameOf(This->pSFParent, 0, pidl, wszNewName, SHGDN_INFOLDER, &pidl);
1439

1440 1441 1442 1443
		if(SUCCEEDED(hr) && pidl)
		{
	          lvItem.mask = LVIF_PARAM;
		  lvItem.lParam = (LPARAM)pidl;
1444
		  SendMessageA(This->hWndList, LVM_SETITEMA, 0, (LPARAM) &lvItem);
1445 1446 1447 1448 1449
		  return TRUE;
		}
	      }
	      return FALSE;
	    }
1450

1451 1452 1453 1454 1455 1456 1457 1458 1459
	  case LVN_KEYDOWN:
	    {
	    /*  MSG msg;
	      msg.hwnd = This->hWnd;
	      msg.message = WM_KEYDOWN;
	      msg.wParam = plvKeyDown->wVKey;
	      msg.lParam = 0;
	      msg.time = 0;
	      msg.pt = 0;*/
1460

1461
	      LPNMLVKEYDOWN plvKeyDown = (LPNMLVKEYDOWN) lpnmh;
1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474

              /* initiate a rename of the selected file or directory */
              if(plvKeyDown->wVKey == VK_F2)
              {
                /* see how many files are selected */
                int i = ListView_GetSelectedCount(This->hWndList);

                /* get selected item */
                if(i == 1)
                {
                  /* get selected item */
                  i = ListView_GetNextItem(This->hWndList, -1,
			LVNI_SELECTED);
1475

1476 1477
                  SendMessageW(This->hWndList, LVM_ENSUREVISIBLE, i, 0);
                  SendMessageW(This->hWndList, LVM_EDITLABELW, i, 0);
1478 1479
                }
              }
1480 1481 1482
#if 0
	      TranslateAccelerator(This->hWnd, This->hAccel, &msg)
#endif
1483 1484
	      else if(plvKeyDown->wVKey == VK_DELETE)
              {
1485 1486
		UINT i;
		int item_index;
1487 1488 1489 1490 1491 1492 1493
		LVITEMA item;
		LPITEMIDLIST* pItems;
		ISFHelper *psfhlp;

		IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper,
		 	(LPVOID*)&psfhlp);

1494 1495 1496
		if (psfhlp == NULL)
		  break;

1497 1498
		if(!(i = ListView_GetSelectedCount(This->hWndList)))
		  break;
1499

1500
		/* allocate memory for the pidl array */
1501
		pItems = HeapAlloc(GetProcessHeap(), 0,
1502
			sizeof(LPITEMIDLIST) * i);
1503

1504 1505 1506 1507 1508 1509
		/* retrieve all selected items */
		i = 0;
		item_index = -1;
		while(ListView_GetSelectedCount(This->hWndList) > i)
		{
		  /* get selected item */
1510
		  item_index = ListView_GetNextItem(This->hWndList,
1511 1512
			item_index, LVNI_SELECTED);
		  item.iItem = item_index;
1513
		  item.mask |= LVIF_PARAM;
1514
		  SendMessageA(This->hWndList, LVM_GETITEMA, 0, (LPARAM) &item);
1515 1516 1517

		  /* get item pidl */
		  pItems[i] = (LPITEMIDLIST)item.lParam;
1518

1519 1520 1521 1522
		  i++;
		}

		/* perform the item deletion */
1523
		ISFHelper_DeleteItems(psfhlp, i, (LPCITEMIDLIST*)pItems);
1524 1525 1526 1527

		/* free pidl array memory */
		HeapFree(GetProcessHeap(), 0, pItems);
              }
1528 1529 1530 1531 1532 1533 1534

              /* Initiate a refresh */
              else if(plvKeyDown->wVKey == VK_F5)
              {
		IShellView_Refresh((IShellView*)This);
              }

1535
              else
1536
		FIXME("LVN_KEYDOWN key=0x%08x\n",plvKeyDown->wVKey);
1537 1538
	    }
	    break;
1539

Alexandre Julliard's avatar
Alexandre Julliard committed
1540
	  default:
1541
	    TRACE("-- %p WM_COMMAND %x unhandled\n", This, lpnmh->code);
1542
	    break;
Alexandre Julliard's avatar
Alexandre Julliard committed
1543 1544
	}
	return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1545 1546
}

1547 1548 1549 1550 1551 1552 1553 1554 1555
/**********************************************************
* ShellView_OnChange()
*/

static LRESULT ShellView_OnChange(IShellViewImpl * This, LPITEMIDLIST * Pidls, LONG wEventId)
{

	TRACE("(%p)(%p,%p,0x%08lx)\n", This, Pidls[0], Pidls[1], wEventId);
	switch(wEventId)
1556
	{
1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573
	  case SHCNE_MKDIR:
	  case SHCNE_CREATE:
	    LV_AddItem(This, Pidls[0]);
	    break;
	  case SHCNE_RMDIR:
	  case SHCNE_DELETE:
	    LV_DeleteItem(This, Pidls[0]);
	    break;
	  case SHCNE_RENAMEFOLDER:
	  case SHCNE_RENAMEITEM:
	    LV_RenameItem(This, Pidls[0], Pidls[1]);
	    break;
	  case SHCNE_UPDATEITEM:
	    break;
	}
	return TRUE;
}
1574
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1575 1576 1577
*  ShellView_WndProc
*/

1578 1579
static LRESULT CALLBACK ShellView_WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
1580
	IShellViewImpl * pThis = (IShellViewImpl*)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1581 1582
	LPCREATESTRUCTA lpcs;

1583
	TRACE("(hwnd=%p msg=%x wparm=%x lparm=%lx)\n",hWnd, uMessage, wParam, lParam);
1584 1585 1586 1587 1588 1589

	switch (uMessage)
	{
	  case WM_NCCREATE:
	    lpcs = (LPCREATESTRUCTA)lParam;
	    pThis = (IShellViewImpl*)(lpcs->lpCreateParams);
1590
	    SetWindowLongPtrW(hWnd, GWLP_USERDATA, (ULONG_PTR)pThis);
1591 1592 1593 1594 1595 1596 1597 1598 1599
	    pThis->hWnd = hWnd;        /*set the window handle*/
	    break;

	  case WM_SIZE:		return ShellView_OnSize(pThis,LOWORD(lParam), HIWORD(lParam));
	  case WM_SETFOCUS:	return ShellView_OnSetFocus(pThis);
	  case WM_KILLFOCUS:	return ShellView_OnKillFocus(pThis);
	  case WM_CREATE:	return ShellView_OnCreate(pThis);
	  case WM_ACTIVATE:	return ShellView_OnActivate(pThis, SVUIA_ACTIVATE_FOCUS);
	  case WM_NOTIFY:	return ShellView_OnNotify(pThis,(UINT)wParam, (LPNMHDR)lParam);
1600 1601 1602
	  case WM_COMMAND:      return ShellView_OnCommand(pThis,
					GET_WM_COMMAND_ID(wParam, lParam),
					GET_WM_COMMAND_CMD(wParam, lParam),
1603
					GET_WM_COMMAND_HWND(wParam, lParam));
1604
	  case SHV_CHANGE_NOTIFY: return ShellView_OnChange(pThis, (LPITEMIDLIST*)wParam, (LONG)lParam);
1605

1606 1607 1608
	  case WM_CONTEXTMENU:  ShellView_DoContextMenu(pThis, LOWORD(lParam), HIWORD(lParam), FALSE);
	                        return 0;

1609 1610 1611
	  case WM_SHOWWINDOW:	UpdateWindow(pThis->hWndList);
				break;

1612 1613
	  case WM_GETDLGCODE:   return SendMessageA(pThis->hWndList,uMessage,0,0);

1614 1615
	  case WM_DESTROY:	
	  			RevokeDragDrop(pThis->hWnd);
1616
				SHChangeNotifyDeregister(pThis->hNotify);
1617
	                        break;
1618 1619 1620 1621 1622 1623

	  case WM_ERASEBKGND:
	    if ((pThis->FolderSettings.fFlags & FWF_DESKTOP) ||
	        (pThis->FolderSettings.fFlags & FWF_TRANSPARENT))
	      return 1;
	    break;
1624 1625 1626
	}

	return DefWindowProcA (hWnd, uMessage, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
1627
}
1628
/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1629 1630 1631 1632 1633
*
*
*  The INTERFACE of the IShellView object
*
*
1634
**********************************************************
1635
*  IShellView_QueryInterface
Alexandre Julliard's avatar
Alexandre Julliard committed
1636
*/
1637 1638
static HRESULT WINAPI IShellView_fnQueryInterface(IShellView * iface,REFIID riid, LPVOID *ppvObj)
{
1639
	IShellViewImpl *This = (IShellViewImpl *)iface;
Alexandre Julliard's avatar
Alexandre Julliard committed
1640

1641
	TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
1642 1643 1644

	*ppvObj = NULL;

1645 1646
	if(IsEqualIID(riid, &IID_IUnknown))
	{
1647
	  *ppvObj = This;
1648 1649 1650 1651 1652 1653 1654 1655
	}
	else if(IsEqualIID(riid, &IID_IShellView))
	{
	  *ppvObj = (IShellView*)This;
	}
	else if(IsEqualIID(riid, &IID_IOleCommandTarget))
	{
	  *ppvObj = (IOleCommandTarget*)&(This->lpvtblOleCommandTarget);
1656
	}
1657 1658 1659 1660
	else if(IsEqualIID(riid, &IID_IDropTarget))
	{
	  *ppvObj = (IDropTarget*)&(This->lpvtblDropTarget);
	}
1661 1662 1663 1664
	else if(IsEqualIID(riid, &IID_IDropSource))
	{
	  *ppvObj = (IDropSource*)&(This->lpvtblDropSource);
	}
1665 1666 1667
	else if(IsEqualIID(riid, &IID_IViewObject))
	{
	  *ppvObj = (IViewObject*)&(This->lpvtblViewObject);
1668 1669 1670
	}

	if(*ppvObj)
1671 1672
	{
	  IUnknown_AddRef( (IUnknown*)*ppvObj );
1673
	  TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
1674 1675
	  return S_OK;
	}
1676
	TRACE("-- Interface: E_NOINTERFACE\n");
1677 1678
	return E_NOINTERFACE;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1679

1680
/**********************************************************
Juergen Schmied's avatar
Juergen Schmied committed
1681
*  IShellView_AddRef
Alexandre Julliard's avatar
Alexandre Julliard committed
1682
*/
1683 1684
static ULONG WINAPI IShellView_fnAddRef(IShellView * iface)
{
1685
	IShellViewImpl *This = (IShellViewImpl *)iface;
1686
	ULONG refCount = InterlockedIncrement(&This->ref);
1687

1688
	TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
1689

1690
	return refCount;
Alexandre Julliard's avatar
Alexandre Julliard committed
1691
}
1692
/**********************************************************
1693
*  IShellView_Release
Alexandre Julliard's avatar
Alexandre Julliard committed
1694
*/
1695 1696
static ULONG WINAPI IShellView_fnRelease(IShellView * iface)
{
1697
	IShellViewImpl *This = (IShellViewImpl *)iface;
1698
	ULONG refCount = InterlockedDecrement(&This->ref);
1699

1700
	TRACE("(%p)->(count=%li)\n", This, refCount + 1);
1701

1702
	if (!refCount)
1703 1704
	{
	  TRACE(" destroying IShellView(%p)\n",This);
Alexandre Julliard's avatar
Alexandre Julliard committed
1705

1706 1707
	  DestroyWindow(This->hWndList);

1708 1709
	  if(This->pSFParent)
	    IShellFolder_Release(This->pSFParent);
Alexandre Julliard's avatar
Alexandre Julliard committed
1710

1711 1712 1713
	  if(This->pSF2Parent)
	    IShellFolder2_Release(This->pSF2Parent);

1714
	  if(This->apidl)
1715
	    SHFree(This->apidl);
1716

1717 1718 1719
	  if(This->pAdvSink)
	    IAdviseSink_Release(This->pAdvSink);

1720
	  HeapFree(GetProcessHeap(),0,This);
1721
	}
1722
	return refCount;
Alexandre Julliard's avatar
Alexandre Julliard committed
1723
}
1724 1725

/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1726
*  ShellView_GetWindow
Alexandre Julliard's avatar
Alexandre Julliard committed
1727
*/
1728 1729
static HRESULT WINAPI IShellView_fnGetWindow(IShellView * iface,HWND * phWnd)
{
1730
	IShellViewImpl *This = (IShellViewImpl *)iface;
1731

1732
	TRACE("(%p)\n",This);
1733 1734

	*phWnd = This->hWnd;
Alexandre Julliard's avatar
Alexandre Julliard committed
1735

Alexandre Julliard's avatar
Alexandre Julliard committed
1736
	return S_OK;
Alexandre Julliard's avatar
Alexandre Julliard committed
1737
}
1738 1739 1740

static HRESULT WINAPI IShellView_fnContextSensitiveHelp(IShellView * iface,BOOL fEnterMode)
{
1741
	IShellViewImpl *This = (IShellViewImpl *)iface;
1742

1743
	FIXME("(%p) stub\n",This);
1744 1745

	return E_NOTIMPL;
Alexandre Julliard's avatar
Alexandre Julliard committed
1746
}
1747 1748

/**********************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
1749 1750 1751 1752 1753
* IShellView_TranslateAccelerator
*
* FIXME:
*  use the accel functions
*/
1754 1755
static HRESULT WINAPI IShellView_fnTranslateAccelerator(IShellView * iface,LPMSG lpmsg)
{
1756
#if 0
1757
	IShellViewImpl *This = (IShellViewImpl *)iface;
1758

1759
	FIXME("(%p)->(%p: hwnd=%x msg=%x lp=%lx wp=%x) stub\n",This,lpmsg, lpmsg->hwnd, lpmsg->message, lpmsg->lParam, lpmsg->wParam);
1760
#endif
1761

1762 1763
	if ((lpmsg->message>=WM_KEYFIRST) && (lpmsg->message>=WM_KEYLAST))
	{
1764
	  TRACE("-- key=0x04%x\n",lpmsg->wParam) ;
1765
	}
1766
	return S_FALSE; /* not handled */
Alexandre Julliard's avatar
Alexandre Julliard committed
1767
}
1768 1769 1770

static HRESULT WINAPI IShellView_fnEnableModeless(IShellView * iface,BOOL fEnable)
{
1771
	IShellViewImpl *This = (IShellViewImpl *)iface;
1772

1773
	FIXME("(%p) stub\n",This);
1774 1775

	return E_NOTIMPL;
Alexandre Julliard's avatar
Alexandre Julliard committed
1776
}
1777 1778 1779

static HRESULT WINAPI IShellView_fnUIActivate(IShellView * iface,UINT uState)
{
1780
	IShellViewImpl *This = (IShellViewImpl *)iface;
1781

1782
/*
1783
	CHAR	szName[MAX_PATH];
1784
*/
Alexandre Julliard's avatar
Alexandre Julliard committed
1785
	LRESULT	lResult;
1786
	int	nPartArray[1] = {-1};
Alexandre Julliard's avatar
Alexandre Julliard committed
1787

1788
	TRACE("(%p)->(state=%x) stub\n",This, uState);
1789

Alexandre Julliard's avatar
Alexandre Julliard committed
1790
	/*don't do anything if the state isn't really changing*/
1791
	if(This->uState == uState)
1792 1793
	{
	  return S_OK;
Alexandre Julliard's avatar
Alexandre Julliard committed
1794
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
1795

Alexandre Julliard's avatar
Alexandre Julliard committed
1796
	/*OnActivate handles the menu merging and internal state*/
1797
	ShellView_OnActivate(This, uState);
Alexandre Julliard's avatar
Alexandre Julliard committed
1798

1799
	/*only do This if we are active*/
Alexandre Julliard's avatar
Alexandre Julliard committed
1800
	if(uState != SVUIA_DEACTIVATE)
1801
	{
1802

1803 1804
/*
	  GetFolderPath is not a method of IShellFolder
1805
	  IShellFolder_GetFolderPath( This->pSFParent, szName, sizeof(szName) );
1806
*/
Alexandre Julliard's avatar
Alexandre Julliard committed
1807
	  /* set the number of parts */
1808
	  IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_STATUS, SB_SETPARTS, 1,
1809
	  						(LPARAM)nPartArray, &lResult);
Alexandre Julliard's avatar
Alexandre Julliard committed
1810 1811

	  /* set the text for the parts */
1812
/*
1813
	  IShellBrowser_SendControlMsg(This->pShellBrowser, FCW_STATUS, SB_SETTEXTA,
1814
							0, (LPARAM)szName, &lResult);
1815
*/
Alexandre Julliard's avatar
Alexandre Julliard committed
1816
	}
1817

Alexandre Julliard's avatar
Alexandre Julliard committed
1818 1819
	return S_OK;
}
1820

1821 1822
static HRESULT WINAPI IShellView_fnRefresh(IShellView * iface)
{
1823
	IShellViewImpl *This = (IShellViewImpl *)iface;
Alexandre Julliard's avatar
Alexandre Julliard committed
1824

1825
	TRACE("(%p)\n",This);
1826

1827
	SendMessageW(This->hWndList, LVM_DELETEALLITEMS, 0, 0);
1828
	ShellView_FillList(This);
Alexandre Julliard's avatar
Alexandre Julliard committed
1829

Alexandre Julliard's avatar
Alexandre Julliard committed
1830 1831
	return S_OK;
}
1832 1833 1834 1835 1836 1837 1838 1839

static HRESULT WINAPI IShellView_fnCreateViewWindow(
	IShellView * iface,
	IShellView *lpPrevView,
	LPCFOLDERSETTINGS lpfs,
	IShellBrowser * psb,
	RECT * prcView,
	HWND  *phWnd)
1840
{
1841
	IShellViewImpl *This = (IShellViewImpl *)iface;
1842 1843

	WNDCLASSA wc;
Alexandre Julliard's avatar
Alexandre Julliard committed
1844 1845
	*phWnd = 0;

1846

1847
	TRACE("(%p)->(shlview=%p set=%p shlbrs=%p rec=%p hwnd=%p) incomplete\n",This, lpPrevView,lpfs, psb, prcView, phWnd);
1848
	TRACE("-- vmode=%x flags=%x left=%li top=%li right=%li bottom=%li\n",lpfs->ViewMode, lpfs->fFlags ,prcView->left,prcView->top, prcView->right, prcView->bottom);
Alexandre Julliard's avatar
Alexandre Julliard committed
1849 1850

	/*set up the member variables*/
1851 1852
	This->pShellBrowser = psb;
	This->FolderSettings = *lpfs;
Alexandre Julliard's avatar
Alexandre Julliard committed
1853 1854

	/*get our parent window*/
1855 1856
	IShellBrowser_AddRef(This->pShellBrowser);
	IShellBrowser_GetWindow(This->pShellBrowser, &(This->hWndParent));
Alexandre Julliard's avatar
Alexandre Julliard committed
1857

1858
	/* try to get the ICommDlgBrowserInterface, adds a reference !!! */
1859
	This->pCommDlgBrowser=NULL;
1860
	if ( SUCCEEDED (IShellBrowser_QueryInterface( This->pShellBrowser,
1861
			(REFIID)&IID_ICommDlgBrowser, (LPVOID*) &This->pCommDlgBrowser)))
1862 1863
	{
	  TRACE("-- CommDlgBrowser\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
1864
	}
1865

Alexandre Julliard's avatar
Alexandre Julliard committed
1866
	/*if our window class has not been registered, then do so*/
1867
	if(!GetClassInfoA(shell32_hInstance, SV_CLASS_NAME, &wc))
1868 1869 1870
	{
	  ZeroMemory(&wc, sizeof(wc));
	  wc.style		= CS_HREDRAW | CS_VREDRAW;
1871
	  wc.lpfnWndProc	= ShellView_WndProc;
1872 1873 1874 1875
	  wc.cbClsExtra		= 0;
	  wc.cbWndExtra		= 0;
	  wc.hInstance		= shell32_hInstance;
	  wc.hIcon		= 0;
1876
	  wc.hCursor		= LoadCursorA (0, (LPSTR)IDC_ARROW);
1877 1878 1879
	  wc.hbrBackground	= (HBRUSH) (COLOR_WINDOW + 1);
	  wc.lpszMenuName	= NULL;
	  wc.lpszClassName	= SV_CLASS_NAME;
1880

1881
	  if(!RegisterClassA(&wc))
Alexandre Julliard's avatar
Alexandre Julliard committed
1882 1883
	    return E_FAIL;
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
1884

1885 1886 1887
	*phWnd = CreateWindowExA(0,
				SV_CLASS_NAME,
				NULL,
1888
				WS_CHILD | WS_TABSTOP,
1889 1890 1891 1892 1893 1894 1895 1896 1897 1898
				prcView->left,
				prcView->top,
				prcView->right - prcView->left,
				prcView->bottom - prcView->top,
				This->hWndParent,
				0,
				shell32_hInstance,
				(LPVOID)This);

	CheckToolbar(This);
1899

1900
	if(!*phWnd) return E_FAIL;
Alexandre Julliard's avatar
Alexandre Julliard committed
1901

1902 1903 1904
	SetWindowPos(*phWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
	UpdateWindow(*phWnd);

Alexandre Julliard's avatar
Alexandre Julliard committed
1905
	return S_OK;
Alexandre Julliard's avatar
Alexandre Julliard committed
1906 1907
}

1908 1909
static HRESULT WINAPI IShellView_fnDestroyViewWindow(IShellView * iface)
{
1910
	IShellViewImpl *This = (IShellViewImpl *)iface;
1911

1912
	TRACE("(%p)\n",This);
Alexandre Julliard's avatar
Alexandre Julliard committed
1913 1914

	/*Make absolutely sure all our UI is cleaned up.*/
1915
	IShellView_UIActivate((IShellView*)This, SVUIA_DEACTIVATE);
1916

1917
	if(This->hMenu)
1918 1919
	{
	  DestroyMenu(This->hMenu);
Alexandre Julliard's avatar
Alexandre Julliard committed
1920
	}
1921

1922
	DestroyWindow(This->hWnd);
1923 1924 1925
	if(This->pShellBrowser) IShellBrowser_Release(This->pShellBrowser);
	if(This->pCommDlgBrowser) ICommDlgBrowser_Release(This->pCommDlgBrowser);

1926

Alexandre Julliard's avatar
Alexandre Julliard committed
1927 1928
	return S_OK;
}
1929 1930 1931

static HRESULT WINAPI IShellView_fnGetCurrentInfo(IShellView * iface, LPFOLDERSETTINGS lpfs)
{
1932
	IShellViewImpl *This = (IShellViewImpl *)iface;
1933

1934
	TRACE("(%p)->(%p) vmode=%x flags=%x\n",This, lpfs,
1935 1936
		This->FolderSettings.ViewMode, This->FolderSettings.fFlags);

1937 1938 1939 1940
	if (!lpfs) return E_INVALIDARG;

	*lpfs = This->FolderSettings;
	return NOERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1941
}
1942 1943 1944

static HRESULT WINAPI IShellView_fnAddPropertySheetPages(IShellView * iface, DWORD dwReserved,LPFNADDPROPSHEETPAGE lpfn, LPARAM lparam)
{
1945
	IShellViewImpl *This = (IShellViewImpl *)iface;
1946

1947
	FIXME("(%p) stub\n",This);
1948 1949

	return E_NOTIMPL;
Alexandre Julliard's avatar
Alexandre Julliard committed
1950
}
1951 1952 1953

static HRESULT WINAPI IShellView_fnSaveViewState(IShellView * iface)
{
1954
	IShellViewImpl *This = (IShellViewImpl *)iface;
1955

1956
	FIXME("(%p) stub\n",This);
1957 1958

	return S_OK;
Alexandre Julliard's avatar
Alexandre Julliard committed
1959
}
1960

1961 1962 1963 1964 1965
static HRESULT WINAPI IShellView_fnSelectItem(
	IShellView * iface,
	LPCITEMIDLIST pidl,
	UINT uFlags)
{
1966
	IShellViewImpl *This = (IShellViewImpl *)iface;
1967
	int i;
1968

1969
	TRACE("(%p)->(pidl=%p, 0x%08x) stub\n",This, pidl, uFlags);
1970

1971
	i = LV_FindItemByPidl(This, pidl);
1972

1973 1974 1975
	if (i != -1)
	{
	  LVITEMA lvItem;
1976

1977
	  if(uFlags & SVSI_ENSUREVISIBLE)
1978
	    SendMessageW(This->hWndList, LVM_ENSUREVISIBLE, i, 0);
1979 1980 1981 1982 1983

          ZeroMemory(&lvItem, sizeof(LVITEMA));
	  lvItem.mask = LVIF_STATE;
	  lvItem.iItem = 0;

1984
          while(SendMessageA(This->hWndList, LVM_GETITEMA, 0, (LPARAM) &lvItem))
1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
	  {
	    if (lvItem.iItem == i)
	    {
	      if (uFlags & SVSI_SELECT)
	        lvItem.state |= LVIS_SELECTED;
	      else
		lvItem.state &= ~LVIS_SELECTED;

	      if(uFlags & SVSI_FOCUSED)
	        lvItem.state &= ~LVIS_FOCUSED;
	    }
	    else
	    {
	      if (uFlags & SVSI_DESELECTOTHERS)
	        lvItem.state &= ~LVIS_SELECTED;
	    }
2001
	    SendMessageA(This->hWndList, LVM_SETITEMA, 0, (LPARAM) &lvItem);
2002 2003 2004 2005 2006
	    lvItem.iItem++;
	  }


	  if(uFlags & SVSI_EDIT)
2007
	    SendMessageW(This->hWndList, LVM_EDITLABELW, i, 0);
2008 2009 2010

	}
	return S_OK;
Alexandre Julliard's avatar
Alexandre Julliard committed
2011
}
2012 2013 2014

static HRESULT WINAPI IShellView_fnGetItemObject(IShellView * iface, UINT uItem, REFIID riid, LPVOID *ppvOut)
{
2015
	IShellViewImpl *This = (IShellViewImpl *)iface;
2016

2017
	TRACE("(%p)->(uItem=0x%08x,\n\tIID=%s, ppv=%p)\n",This, uItem, debugstr_guid(riid), ppvOut);
Alexandre Julliard's avatar
Alexandre Julliard committed
2018

2019
	*ppvOut = NULL;
2020 2021 2022 2023

	switch(uItem)
	{
	  case SVGIO_BACKGROUND:
2024
	    *ppvOut = ISvBgCm_Constructor(This->pSFParent, FALSE);
2025 2026 2027 2028
	    break;

	  case SVGIO_SELECTION:
	    ShellView_GetSelections(This);
2029
	    IShellFolder_GetUIObjectOf(This->pSFParent, This->hWnd, This->cidl, (LPCITEMIDLIST*)This->apidl, riid, 0, ppvOut);
2030
	    break;
2031
	}
2032
	TRACE("-- (%p)->(interface=%p)\n",This, *ppvOut);
Alexandre Julliard's avatar
Alexandre Julliard committed
2033

2034
	if(!*ppvOut) return E_OUTOFMEMORY;
2035

2036
	return S_OK;
Alexandre Julliard's avatar
Alexandre Julliard committed
2037
}
2038

2039
static const IShellViewVtbl svvt =
2040
{
2041
	IShellView_fnQueryInterface,
2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055
	IShellView_fnAddRef,
	IShellView_fnRelease,
	IShellView_fnGetWindow,
	IShellView_fnContextSensitiveHelp,
	IShellView_fnTranslateAccelerator,
	IShellView_fnEnableModeless,
	IShellView_fnUIActivate,
	IShellView_fnRefresh,
	IShellView_fnCreateViewWindow,
	IShellView_fnDestroyViewWindow,
	IShellView_fnGetCurrentInfo,
	IShellView_fnAddPropertySheetPages,
	IShellView_fnSaveViewState,
	IShellView_fnSelectItem,
2056
	IShellView_fnGetItemObject
2057 2058
};

2059

2060
/**********************************************************
2061 2062 2063 2064 2065 2066 2067
 * ISVOleCmdTarget_QueryInterface (IUnknown)
 */
static HRESULT WINAPI ISVOleCmdTarget_QueryInterface(
	IOleCommandTarget *	iface,
	REFIID			iid,
	LPVOID*			ppvObj)
{
2068
	IShellViewImpl *This = impl_from_IOleCommandTarget(iface);
2069 2070 2071 2072

	return IShellFolder_QueryInterface((IShellFolder*)This, iid, ppvObj);
}

2073
/**********************************************************
2074 2075 2076 2077 2078
 * ISVOleCmdTarget_AddRef (IUnknown)
 */
static ULONG WINAPI ISVOleCmdTarget_AddRef(
	IOleCommandTarget *	iface)
{
2079
	IShellViewImpl *This = impl_from_IOleCommandTarget(iface);
2080 2081 2082 2083

	return IShellFolder_AddRef((IShellFolder*)This);
}

2084
/**********************************************************
2085 2086 2087 2088 2089
 * ISVOleCmdTarget_Release (IUnknown)
 */
static ULONG WINAPI ISVOleCmdTarget_Release(
	IOleCommandTarget *	iface)
{
2090
	IShellViewImpl *This = impl_from_IOleCommandTarget(iface);
2091 2092 2093 2094

	return IShellFolder_Release((IShellFolder*)This);
}

2095
/**********************************************************
Juergen Schmied's avatar
Juergen Schmied committed
2096
 * ISVOleCmdTarget_QueryStatus (IOleCommandTarget)
2097 2098 2099 2100
 */
static HRESULT WINAPI ISVOleCmdTarget_QueryStatus(
	IOleCommandTarget *iface,
	const GUID* pguidCmdGroup,
2101
	ULONG cCmds,
2102 2103 2104
	OLECMD * prgCmds,
	OLECMDTEXT* pCmdText)
{
Rolf Kalbermatter's avatar
Rolf Kalbermatter committed
2105
    UINT i;
2106
    IShellViewImpl *This = impl_from_IOleCommandTarget(iface);
2107

2108
    FIXME("(%p)->(%p(%s) 0x%08lx %p %p\n",
2109
              This, pguidCmdGroup, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
2110 2111 2112 2113 2114 2115 2116 2117 2118

    if (!prgCmds)
        return E_POINTER;
    for (i = 0; i < cCmds; i++)
    {
        FIXME("\tprgCmds[%d].cmdID = %ld\n", i, prgCmds[i].cmdID);
        prgCmds[i].cmdf = 0;
    }
    return OLECMDERR_E_UNKNOWNGROUP;
2119 2120
}

2121
/**********************************************************
2122
 * ISVOleCmdTarget_Exec (IOleCommandTarget)
Juergen Schmied's avatar
Juergen Schmied committed
2123 2124
 *
 * nCmdID is the OLECMDID_* enumeration
2125 2126 2127 2128 2129 2130 2131 2132 2133
 */
static HRESULT WINAPI ISVOleCmdTarget_Exec(
	IOleCommandTarget *iface,
	const GUID* pguidCmdGroup,
	DWORD nCmdID,
	DWORD nCmdexecopt,
	VARIANT* pvaIn,
	VARIANT* pvaOut)
{
2134
	IShellViewImpl *This = impl_from_IOleCommandTarget(iface);
2135

2136 2137
	FIXME("(%p)->(\n\tTarget GUID:%s Command:0x%08lx Opt:0x%08lx %p %p)\n",
              This, debugstr_guid(pguidCmdGroup), nCmdID, nCmdexecopt, pvaIn, pvaOut);
2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148

	if (IsEqualIID(pguidCmdGroup, &CGID_Explorer) &&
	   (nCmdID == 0x29) &&
	   (nCmdexecopt == 4) && pvaOut)
	   return S_OK;
	if (IsEqualIID(pguidCmdGroup, &CGID_ShellDocView) &&
	   (nCmdID == 9) &&
	   (nCmdexecopt == 0))
	   return 1;

	return OLECMDERR_E_UNKNOWNGROUP;
2149 2150
}

2151
static const IOleCommandTargetVtbl ctvt =
2152 2153 2154 2155 2156 2157 2158 2159
{
	ISVOleCmdTarget_QueryInterface,
	ISVOleCmdTarget_AddRef,
	ISVOleCmdTarget_Release,
	ISVOleCmdTarget_QueryStatus,
	ISVOleCmdTarget_Exec
};

2160
/**********************************************************
2161 2162 2163 2164 2165 2166 2167 2168
 * ISVDropTarget implementation
 */

static HRESULT WINAPI ISVDropTarget_QueryInterface(
	IDropTarget *iface,
	REFIID riid,
	LPVOID *ppvObj)
{
2169
	IShellViewImpl *This = impl_from_IDropTarget(iface);
2170

2171
	TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
2172 2173 2174 2175 2176 2177

	return IShellFolder_QueryInterface((IShellFolder*)This, riid, ppvObj);
}

static ULONG WINAPI ISVDropTarget_AddRef( IDropTarget *iface)
{
2178
	IShellViewImpl *This = impl_from_IDropTarget(iface);
2179

2180
	TRACE("(%p)->(count=%lu)\n",This,This->ref);
2181 2182 2183 2184 2185 2186

	return IShellFolder_AddRef((IShellFolder*)This);
}

static ULONG WINAPI ISVDropTarget_Release( IDropTarget *iface)
{
2187
	IShellViewImpl *This = impl_from_IDropTarget(iface);
2188

2189
	TRACE("(%p)->(count=%lu)\n",This,This->ref);
2190 2191 2192 2193

	return IShellFolder_Release((IShellFolder*)This);
}

2194 2195 2196 2197 2198 2199
/******************************************************************************
 * drag_notify_subitem [Internal]
 *
 * Figure out the shellfolder object, which is currently under the mouse cursor
 * and notify it via the IDropTarget interface.
 */
2200 2201 2202

#define SCROLLAREAWIDTH 20

2203 2204 2205 2206 2207 2208 2209
static HRESULT drag_notify_subitem(IShellViewImpl *This, DWORD grfKeyState, POINTL pt,
    DWORD *pdwEffect)
{
    LVHITTESTINFO htinfo;
    LVITEMA lvItem;
    LONG lResult;
    HRESULT hr;
2210
    RECT clientRect;
2211 2212 2213 2214 2215 2216

    /* Map from global to client coordinates and query the index of the listview-item, which is 
     * currently under the mouse cursor. */
    htinfo.pt.x = pt.x;
    htinfo.pt.y = pt.y;
    htinfo.flags = LVHT_ONITEM;
2217
    ScreenToClient(This->hWndList, &htinfo.pt);
2218 2219
    lResult = SendMessageW(This->hWndList, LVM_HITTEST, 0, (LPARAM)&htinfo);

2220
    /* Send WM_*SCROLL messages every 250 ms during drag-scrolling */
2221
    GetClientRect(This->hWndList, &clientRect);
2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241
    if (htinfo.pt.x == This->ptLastMousePos.x && htinfo.pt.y == This->ptLastMousePos.y &&
        (htinfo.pt.x < SCROLLAREAWIDTH || htinfo.pt.x > clientRect.right - SCROLLAREAWIDTH ||
         htinfo.pt.y < SCROLLAREAWIDTH || htinfo.pt.y > clientRect.bottom - SCROLLAREAWIDTH ))
    {
        This->cScrollDelay = (This->cScrollDelay + 1) % 5; /* DragOver is called every 50 ms */
        if (This->cScrollDelay == 0) { /* Mouse did hover another 250 ms over the scroll-area */
            if (htinfo.pt.x < SCROLLAREAWIDTH) 
                SendMessageW(This->hWndList, WM_HSCROLL, SB_LINEUP, 0);
            if (htinfo.pt.x > clientRect.right - SCROLLAREAWIDTH)
                SendMessageW(This->hWndList, WM_HSCROLL, SB_LINEDOWN, 0);
            if (htinfo.pt.y < SCROLLAREAWIDTH)
                SendMessageW(This->hWndList, WM_VSCROLL, SB_LINEUP, 0);
            if (htinfo.pt.y > clientRect.bottom - SCROLLAREAWIDTH)
                SendMessageW(This->hWndList, WM_VSCROLL, SB_LINEDOWN, 0);
        }
    } else {
        This->cScrollDelay = 0; /* Reset, if the cursor is not over the listview's scroll-area */
    }
    This->ptLastMousePos = htinfo.pt;
 
2242 2243 2244 2245 2246 2247 2248 2249 2250 2251
    /* If we are still over the previous sub-item, notify it via DragOver and return. */
    if (This->pCurDropTarget && lResult == This->iDragOverItem)
    return IDropTarget_DragOver(This->pCurDropTarget, grfKeyState, pt, pdwEffect);
  
    /* We've left the previous sub-item, notify it via DragLeave and Release it. */
    if (This->pCurDropTarget) {
        IDropTarget_DragLeave(This->pCurDropTarget);
        IDropTarget_Release(This->pCurDropTarget);
        This->pCurDropTarget = NULL;
    }
2252

2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264
    This->iDragOverItem = lResult;
    if (lResult == -1) {
        /* We are not above one of the listview's subitems. Bind to the parent folder's
         * DropTarget interface. */
        hr = IShellFolder_QueryInterface(This->pSFParent, &IID_IDropTarget, 
                                         (LPVOID*)&This->pCurDropTarget);
    } else {
        /* Query the relative PIDL of the shellfolder object represented by the currently
         * dragged over listview-item ... */
        ZeroMemory(&lvItem, sizeof(lvItem));
        lvItem.mask = LVIF_PARAM;
        lvItem.iItem = lResult;
2265
        SendMessageA(This->hWndList, LVM_GETITEMA, 0, (LPARAM) &lvItem);
2266

2267 2268 2269
        /* ... and bind pCurDropTarget to the IDropTarget interface of an UIObject of this object */
        hr = IShellFolder_GetUIObjectOf(This->pSFParent, This->hWndList, 1,
            (LPCITEMIDLIST*)&lvItem.lParam, &IID_IDropTarget, NULL, (LPVOID*)&This->pCurDropTarget);
2270
    }
2271

2272 2273 2274
    /* If anything failed, pCurDropTarget should be NULL now, which ought to be a save state. */
    if (FAILED(hr)) 
        return hr;
2275

2276 2277
    /* Notify the item just entered via DragEnter. */
    return IDropTarget_DragEnter(This->pCurDropTarget, This->pCurDataObject, grfKeyState, pt, pdwEffect);
2278 2279
}

2280 2281
static HRESULT WINAPI ISVDropTarget_DragEnter(IDropTarget *iface, IDataObject *pDataObject,
    DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
2282
{
2283
    IShellViewImpl *This = impl_from_IDropTarget(iface);
2284

2285 2286 2287
    /* Get a hold on the data object for later calls to DragEnter on the sub-folders */
    This->pCurDataObject = pDataObject;
    IDataObject_AddRef(pDataObject);
2288

2289
    return drag_notify_subitem(This, grfKeyState, pt, pdwEffect);
2290 2291
}

2292 2293
static HRESULT WINAPI ISVDropTarget_DragOver(IDropTarget *iface, DWORD grfKeyState, POINTL pt,
    DWORD *pdwEffect)
2294
{
2295 2296 2297
    IShellViewImpl *This = impl_from_IDropTarget(iface);
    return drag_notify_subitem(This, grfKeyState, pt, pdwEffect);
}
2298

2299 2300
static HRESULT WINAPI ISVDropTarget_DragLeave(IDropTarget *iface) {
    IShellViewImpl *This = impl_from_IDropTarget(iface);
2301

2302 2303 2304 2305 2306 2307 2308
    IDropTarget_DragLeave(This->pCurDropTarget);

    IDropTarget_Release(This->pCurDropTarget);
    IDataObject_Release(This->pCurDataObject);
    This->pCurDataObject = NULL;
    This->pCurDropTarget = NULL;
    This->iDragOverItem = 0;
2309
     
2310
    return S_OK;
2311 2312
}

2313 2314
static HRESULT WINAPI ISVDropTarget_Drop(IDropTarget *iface, IDataObject* pDataObject, 
    DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
2315
{
2316
    IShellViewImpl *This = impl_from_IDropTarget(iface);
2317

2318
    IDropTarget_Drop(This->pCurDropTarget, pDataObject, grfKeyState, pt, pdwEffect);
2319

2320 2321 2322 2323 2324 2325 2326
    IDropTarget_Release(This->pCurDropTarget);
    IDataObject_Release(This->pCurDataObject);
    This->pCurDataObject = NULL;
    This->pCurDropTarget = NULL;
    This->iDragOverItem = 0;

    return S_OK;
2327 2328
}

2329
static const IDropTargetVtbl dtvt =
2330 2331 2332 2333 2334 2335 2336 2337 2338 2339
{
	ISVDropTarget_QueryInterface,
	ISVDropTarget_AddRef,
	ISVDropTarget_Release,
	ISVDropTarget_DragEnter,
	ISVDropTarget_DragOver,
	ISVDropTarget_DragLeave,
	ISVDropTarget_Drop
};

2340 2341 2342 2343 2344 2345 2346 2347 2348
/**********************************************************
 * ISVDropSource implementation
 */

static HRESULT WINAPI ISVDropSource_QueryInterface(
	IDropSource *iface,
	REFIID riid,
	LPVOID *ppvObj)
{
2349
	IShellViewImpl *This = impl_from_IDropSource(iface);
2350

2351
	TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
2352 2353 2354 2355 2356 2357

	return IShellFolder_QueryInterface((IShellFolder*)This, riid, ppvObj);
}

static ULONG WINAPI ISVDropSource_AddRef( IDropSource *iface)
{
2358
	IShellViewImpl *This = impl_from_IDropSource(iface);
2359 2360 2361 2362 2363 2364 2365 2366

	TRACE("(%p)->(count=%lu)\n",This,This->ref);

	return IShellFolder_AddRef((IShellFolder*)This);
}

static ULONG WINAPI ISVDropSource_Release( IDropSource *iface)
{
2367
	IShellViewImpl *This = impl_from_IDropSource(iface);
2368 2369 2370 2371 2372 2373 2374 2375 2376 2377

	TRACE("(%p)->(count=%lu)\n",This,This->ref);

	return IShellFolder_Release((IShellFolder*)This);
}
static HRESULT WINAPI ISVDropSource_QueryContinueDrag(
	IDropSource *iface,
	BOOL fEscapePressed,
	DWORD grfKeyState)
{
2378
	IShellViewImpl *This = impl_from_IDropSource(iface);
2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392
	TRACE("(%p)\n",This);

	if (fEscapePressed)
	  return DRAGDROP_S_CANCEL;
	else if (!(grfKeyState & MK_LBUTTON) && !(grfKeyState & MK_RBUTTON))
	  return DRAGDROP_S_DROP;
	else
	  return NOERROR;
}

static HRESULT WINAPI ISVDropSource_GiveFeedback(
	IDropSource *iface,
	DWORD dwEffect)
{
2393
	IShellViewImpl *This = impl_from_IDropSource(iface);
2394 2395 2396 2397 2398
	TRACE("(%p)\n",This);

	return DRAGDROP_S_USEDEFAULTCURSORS;
}

2399
static const IDropSourceVtbl dsvt =
2400 2401 2402 2403 2404 2405 2406
{
	ISVDropSource_QueryInterface,
	ISVDropSource_AddRef,
	ISVDropSource_Release,
	ISVDropSource_QueryContinueDrag,
	ISVDropSource_GiveFeedback
};
2407
/**********************************************************
2408 2409 2410 2411 2412 2413 2414 2415
 * ISVViewObject implementation
 */

static HRESULT WINAPI ISVViewObject_QueryInterface(
	IViewObject *iface,
	REFIID riid,
	LPVOID *ppvObj)
{
2416
	IShellViewImpl *This = impl_from_IViewObject(iface);
2417

2418
	TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
2419 2420 2421 2422 2423 2424

	return IShellFolder_QueryInterface((IShellFolder*)This, riid, ppvObj);
}

static ULONG WINAPI ISVViewObject_AddRef( IViewObject *iface)
{
2425
	IShellViewImpl *This = impl_from_IViewObject(iface);
2426

2427
	TRACE("(%p)->(count=%lu)\n",This,This->ref);
2428 2429 2430 2431 2432 2433

	return IShellFolder_AddRef((IShellFolder*)This);
}

static ULONG WINAPI ISVViewObject_Release( IViewObject *iface)
{
2434
	IShellViewImpl *This = impl_from_IViewObject(iface);
2435

2436
	TRACE("(%p)->(count=%lu)\n",This,This->ref);
2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449

	return IShellFolder_Release((IShellFolder*)This);
}

static HRESULT WINAPI ISVViewObject_Draw(
	IViewObject 	*iface,
	DWORD dwDrawAspect,
	LONG lindex,
	void* pvAspect,
	DVTARGETDEVICE* ptd,
	HDC hdcTargetDev,
	HDC hdcDraw,
	LPCRECTL lprcBounds,
2450
	LPCRECTL lprcWBounds,
2451
	BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue),
2452
	ULONG_PTR dwContinue)
2453
{
2454

2455
	IShellViewImpl *This = impl_from_IViewObject(iface);
2456

2457
	FIXME("Stub: This=%p\n",This);
2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468

	return E_NOTIMPL;
}
static HRESULT WINAPI ISVViewObject_GetColorSet(
	IViewObject 	*iface,
	DWORD dwDrawAspect,
	LONG lindex,
	void *pvAspect,
	DVTARGETDEVICE* ptd,
	HDC hicTargetDevice,
	LOGPALETTE** ppColorSet)
2469
{
2470

2471
	IShellViewImpl *This = impl_from_IViewObject(iface);
2472

2473
	FIXME("Stub: This=%p\n",This);
2474 2475 2476 2477 2478 2479 2480 2481 2482

	return E_NOTIMPL;
}
static HRESULT WINAPI ISVViewObject_Freeze(
	IViewObject 	*iface,
	DWORD dwDrawAspect,
	LONG lindex,
	void* pvAspect,
	DWORD* pdwFreeze)
2483
{
2484

2485
	IShellViewImpl *This = impl_from_IViewObject(iface);
2486

2487
	FIXME("Stub: This=%p\n",This);
2488 2489 2490 2491 2492 2493

	return E_NOTIMPL;
}
static HRESULT WINAPI ISVViewObject_Unfreeze(
	IViewObject 	*iface,
	DWORD dwFreeze)
2494
{
2495

2496
	IShellViewImpl *This = impl_from_IViewObject(iface);
2497

2498
	FIXME("Stub: This=%p\n",This);
2499 2500 2501 2502 2503 2504 2505 2506

	return E_NOTIMPL;
}
static HRESULT WINAPI ISVViewObject_SetAdvise(
	IViewObject 	*iface,
	DWORD aspects,
	DWORD advf,
	IAdviseSink* pAdvSink)
2507
{
2508

2509
	IShellViewImpl *This = impl_from_IViewObject(iface);
2510

2511 2512
	FIXME("partial stub: %p %08lx %08lx %p\n",
              This, aspects, advf, pAdvSink);
2513

2514 2515 2516 2517 2518 2519
	/* FIXME: we set the AdviseSink, but never use it to send any advice */
	This->pAdvSink = pAdvSink;
	This->dwAspects = aspects;
	This->dwAdvf = advf;

	return S_OK;
2520
}
2521

2522 2523 2524 2525 2526
static HRESULT WINAPI ISVViewObject_GetAdvise(
	IViewObject 	*iface,
	DWORD* pAspects,
	DWORD* pAdvf,
	IAdviseSink** ppAdvSink)
2527
{
2528

2529
	IShellViewImpl *This = impl_from_IViewObject(iface);
2530

2531 2532
	TRACE("This=%p pAspects=%p pAdvf=%p ppAdvSink=%p\n",
              This, pAspects, pAdvf, ppAdvSink);
2533

2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544
	if( ppAdvSink )
	{
		IAdviseSink_AddRef( This->pAdvSink );
		*ppAdvSink = This->pAdvSink;
	}
	if( pAspects )
		*pAspects = This->dwAspects;
	if( pAdvf )
		*pAdvf = This->dwAdvf;

	return S_OK;
2545 2546 2547
}


2548
static const IViewObjectVtbl vovt =
2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559
{
	ISVViewObject_QueryInterface,
	ISVViewObject_AddRef,
	ISVViewObject_Release,
	ISVViewObject_Draw,
	ISVViewObject_GetColorSet,
	ISVViewObject_Freeze,
	ISVViewObject_Unfreeze,
	ISVViewObject_SetAdvise,
	ISVViewObject_GetAdvise
};