source: trunk/src/comdlg32/filedlg95.c@ 7029

Last change on this file since 7029 was 6708, checked in by sandervl, 24 years ago

wine update + removed tags

File size: 84.2 KB
Line 
1/*
2 * COMMDLG - File Open Dialogs Win95 look and feel
3 *
4 * FIXME: The whole concept of handling unicode is badly broken.
5 * many hook-messages expecting a pointer to a
6 * OPENFILENAMEA or W structure. With the current architecture
7 * we would have to convert the beast at every call to a hook.
8 * we have to find a better solution but if would likely cause
9 * a complete rewrite with after we shouldhandle the
10 * OPENFILENAME structure without any converting (jsch).
11 *
12 * FIXME: any hook gets a OPENFILENAMEA structure
13 *
14 * FIXME: CDN_FILEOK is wrong implemented, other CDN_ messages likely too
15 *
16 * FIXME: old style hook messages are not implemented (except FILEOKSTRING)
17 *
18 * FIXME: lpstrCustomFilter not handled
19 *
20 * FIXME: if the size of lpstrFile (nMaxFile) is too small the first
21 * two bytes of lpstrFile should contain the needed size
22 *
23 * FIXME: algorithm for selecting the initial directory is too simple
24 *
25 * FIXME: add to recent docs
26 *
27 * FIXME: flags not implemented: OFN_CREATEPROMPT, OFN_DONTADDTORECENT,
28 * OFN_ENABLEINCLUDENOTIFY, OFN_ENABLESIZING, OFN_EXTENSIONDIFFERENT,
29 * OFN_NODEREFERENCELINKS, OFN_NOREADONLYRETURN,
30 * OFN_NOTESTFILECREATE, OFN_OVERWRITEPROMPT, OFN_USEMONIKERS
31 *
32 * FIXME: lCustData for lpfnHook (WM_INITDIALOG)
33 *
34 *
35 */
36#ifdef __WIN32OS2__
37#include <windef.h>
38#include <winbase.h>
39#include <wingdi.h>
40#include <winuser.h>
41#include <heapstring.h>
42#include <misc.h>
43#include <win\shlwapi.h>
44
45#define MapHModuleSL(a) a
46#define MapHModuleLS(a) a
47#define snprintf wsnprintfA
48#endif
49
50#include <ctype.h>
51#include <stdlib.h>
52#include <stdio.h>
53#include <string.h>
54
55#include "winbase.h"
56#include "ntddk.h"
57#include "winnls.h"
58#include "heap.h"
59#include "commdlg.h"
60#include "dlgs.h"
61#include "cdlg.h"
62#include "debugtools.h"
63#include "cderr.h"
64#include "shellapi.h"
65#include "shlguid.h"
66#include "filedlgbrowser.h"
67#include "shlwapi.h"
68#include "wine/obj_contextmenu.h"
69
70DEFAULT_DEBUG_CHANNEL(commdlg);
71
72#define UNIMPLEMENTED_FLAGS \
73(OFN_CREATEPROMPT | OFN_DONTADDTORECENT |\
74OFN_ENABLEINCLUDENOTIFY | OFN_ENABLESIZING | OFN_EXTENSIONDIFFERENT |\
75OFN_NODEREFERENCELINKS | OFN_NOREADONLYRETURN |\
76OFN_NOTESTFILECREATE | OFN_OVERWRITEPROMPT /*| OFN_USEMONIKERS*/)
77
78#define IsHooked(fodInfos) \
79 ((fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook)
80/***********************************************************************
81 * Data structure and global variables
82 */
83typedef struct SFolder
84{
85 int m_iImageIndex; /* Index of picture in image list */
86 HIMAGELIST hImgList;
87 int m_iIndent; /* Indentation index */
88 LPITEMIDLIST pidlItem; /* absolute pidl of the item */
89
90} SFOLDER,*LPSFOLDER;
91
92typedef struct tagLookInInfo
93{
94 int iMaxIndentation;
95 UINT uSelectedItem;
96} LookInInfos;
97
98
99/***********************************************************************
100 * Defines and global variables
101 */
102
103/* Draw item constant */
104#define ICONWIDTH 18
105#define XTEXTOFFSET 3
106
107/* AddItem flags*/
108#define LISTEND -1
109
110/* SearchItem methods */
111#define SEARCH_PIDL 1
112#define SEARCH_EXP 2
113#define ITEM_NOTFOUND -1
114
115/* Undefined windows message sent by CreateViewObject*/
116#define WM_GETISHELLBROWSER WM_USER+7
117
118/* NOTE
119 * Those macros exist in windowsx.h. However, you can't really use them since
120 * they rely on the UNICODE defines and can't be used inside Wine itself.
121 */
122
123/* Combo box macros */
124#define CBAddString(hwnd,str) \
125 SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str);
126
127#define CBInsertString(hwnd,str,pos) \
128 SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str);
129
130#define CBDeleteString(hwnd,pos) \
131 SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0);
132
133#define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
134 SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr);
135
136#define CBGetItemDataPtr(hwnd,iItemId) \
137 SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0)
138
139#define CBGetLBText(hwnd,iItemId,str) \
140 SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str);
141
142#define CBGetCurSel(hwnd) \
143 SendMessageA(hwnd,CB_GETCURSEL,0,0);
144
145#define CBSetCurSel(hwnd,pos) \
146 SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0);
147
148#define CBGetCount(hwnd) \
149 SendMessageA(hwnd,CB_GETCOUNT,0,0);
150#define CBShowDropDown(hwnd,show) \
151 SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0);
152#define CBSetItemHeight(hwnd,index,height) \
153 SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height);
154
155
156const char *FileOpenDlgInfosStr = "FileOpenDlgInfos"; /* windows property description string */
157const char *LookInInfosStr = "LookInInfos"; /* LOOKIN combo box property */
158
159static const char defaultFilter[] = "*.*";
160
161/***********************************************************************
162 * Prototypes
163 */
164
165/* Internal functions used by the dialog */
166static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam);
167static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
168static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd);
169 BOOL FILEDLG95_OnOpen(HWND hwnd);
170static LRESULT FILEDLG95_InitControls(HWND hwnd);
171static void FILEDLG95_Clean(HWND hwnd);
172
173/* Functions used by the shell navigation */
174static LRESULT FILEDLG95_SHELL_Init(HWND hwnd);
175static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd);
176static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb);
177static void FILEDLG95_SHELL_Clean(HWND hwnd);
178static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd);
179
180/* Functions used by the filetype combo box */
181static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd);
182static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode);
183static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt);
184static void FILEDLG95_FILETYPE_Clean(HWND hwnd);
185
186/* Functions used by the Look In combo box */
187static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo);
188static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);
189static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);
190static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);
191static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod);
192static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl);
193static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd);
194 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
195static void FILEDLG95_LOOKIN_Clean(HWND hwnd);
196
197/* Miscellaneous tool functions */
198HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
199HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
200IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
201LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
202LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
203
204/* Shell memory allocation */
205static void *MemAlloc(UINT size);
206static void MemFree(void *mem);
207
208BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos);
209HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
210HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
211HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
212BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);
213static BOOL BrowseSelectedFolder(HWND hwnd);
214
215/***********************************************************************
216 * GetFileName95
217 *
218 * Creates an Open common dialog box that lets the user select
219 * the drive, directory, and the name of a file or set of files to open.
220 *
221 * IN : The FileOpenDlgInfos structure associated with the dialog
222 * OUT : TRUE on success
223 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
224 */
225BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)
226{
227
228 LRESULT lRes;
229 LPCVOID template;
230 HRSRC hRes;
231 HANDLE hDlgTmpl = 0;
232
233 /* test for missing functionality */
234 if (fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS)
235 {
236 FIXME("Flags 0x%08lx not yet implemented\n",
237 fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS);
238 }
239
240 /* Create the dialog from a template */
241
242 if(!(hRes = FindResourceA(COMMDLG_hInstance32,MAKEINTRESOURCEA(NEWFILEOPENORD),RT_DIALOGA)))
243 {
244 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
245 return FALSE;
246 }
247 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hRes )) ||
248 !(template = LockResource( hDlgTmpl )))
249 {
250 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
251 return FALSE;
252 }
253
254 /* old style hook messages */
255 if (IsHooked(fodInfos))
256 {
257 fodInfos->HookMsg.fileokstring = RegisterWindowMessageA(FILEOKSTRINGA);
258 fodInfos->HookMsg.lbselchstring = RegisterWindowMessageA(LBSELCHSTRINGA);
259 fodInfos->HookMsg.helpmsgstring = RegisterWindowMessageA(HELPMSGSTRINGA);
260 fodInfos->HookMsg.sharevistring = RegisterWindowMessageA(SHAREVISTRINGA);
261 }
262
263 lRes = DialogBoxIndirectParamA(COMMDLG_hInstance32,
264 (LPDLGTEMPLATEA) template,
265 fodInfos->ofnInfos->hwndOwner,
266 (DLGPROC) FileOpenDlgProc95,
267 (LPARAM) fodInfos);
268
269 /* Unable to create the dialog */
270 if( lRes == -1)
271 return FALSE;
272
273 return lRes;
274}
275
276/***********************************************************************
277 * GetFileDialog95A
278 *
279 * Call GetFileName95 with this structure and clean the memory.
280 *
281 * IN : The OPENFILENAMEA initialisation structure passed to
282 * GetOpenFileNameA win api function (see filedlg.c)
283 */
284BOOL WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
285{
286
287 BOOL ret;
288 FileOpenDlgInfos *fodInfos;
289 HINSTANCE hInstance;
290 LPCSTR lpstrInitialDir = (LPCSTR)-1;
291 LPSTR lpstrSavDir = NULL;
292 DWORD dwFlags = 0;
293
294 /* Initialise FileOpenDlgInfos structure*/
295 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
296 ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
297
298 /* Pass in the original ofn */
299 fodInfos->ofnInfos = ofn;
300
301 /* Save original hInstance value */
302 hInstance = ofn->hInstance;
303 fodInfos->ofnInfos->hInstance = MapHModuleLS(ofn->hInstance);
304
305 /* save current directory */
306 if (ofn->Flags & OFN_NOCHANGEDIR)
307 {
308 lpstrSavDir = MemAlloc(MAX_PATH);
309 GetCurrentDirectoryA(MAX_PATH, lpstrSavDir);
310 }
311
312 dwFlags = ofn->Flags;
313 ofn->Flags = ofn->Flags|OFN_WINE;
314
315 /* Initialise the dialog property */
316 fodInfos->DlgInfos.dwDlgProp = 0;
317 fodInfos->DlgInfos.hwndCustomDlg = (HWND)NULL;
318
319 switch(iDlgType)
320 {
321 case OPEN_DIALOG :
322 ret = GetFileName95(fodInfos);
323 break;
324 case SAVE_DIALOG :
325 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
326#ifdef __WIN32OS2__
327 //NT4 seems to ignore this flag (fixes ElstarFormular save dialog)
328 ofn->Flags &= ~OFN_FILEMUSTEXIST;
329#endif
330 ret = GetFileName95(fodInfos);
331 break;
332 default :
333 ret = 0;
334 }
335
336 if (lpstrSavDir)
337 {
338 SetCurrentDirectoryA(lpstrSavDir);
339 MemFree(lpstrSavDir);
340 }
341
342 if (lpstrInitialDir != (LPCSTR)-1)
343 {
344 MemFree((LPVOID)(ofn->lpstrInitialDir));
345 ofn->lpstrInitialDir = lpstrInitialDir;
346 }
347
348 ofn->Flags = dwFlags;
349 ofn->hInstance = hInstance;
350 MemFree((LPVOID)(fodInfos));
351 return ret;
352}
353
354/***********************************************************************
355 * GetFileDialog95W
356 *
357 * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
358 * Call GetFileName95 with this structure and clean the memory.
359 *
360 * FIXME: lpstrCustomFilter has to converted back
361 *
362 */
363
364/* converting IN arguments */
365#define AllocInArgWtoA(arg, save) \
366 if(arg) \
367 { \
368 DWORD _len = WideCharToMultiByte( CP_ACP, 0, arg, -1, NULL, 0, NULL, NULL ); \
369 save = arg; \
370 arg = MemAlloc(_len); \
371 WideCharToMultiByte( CP_ACP, 0, save, -1, (LPSTR)arg, _len, NULL, NULL ); \
372 }
373
374#define FreeInArg(arg, save) \
375 if(arg) \
376 { \
377 MemFree((LPSTR)arg); \
378 arg = save; \
379 }
380
381/* converting OUT arguments */
382#define AllocOutArgWtoA(arg, save, len) \
383 if(arg) \
384 { \
385 save = arg; \
386 arg = MemAlloc(len); \
387 }
388
389#define FreeOutArg(arg, save, len) \
390 if(arg) \
391 { \
392 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)(arg), -1, (save), (len) ); \
393 MemFree(arg); \
394 arg = save; \
395 }
396
397BOOL WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
398{
399 BOOL ret;
400 FileOpenDlgInfos *fodInfos;
401 HINSTANCE hInstance;
402
403 /* out arguments */
404 LPWSTR lpstrFile = NULL;
405 LPWSTR lpstrFileTitle = NULL;
406#ifdef __WIN32OS2__
407 LPSTR lpstrSavDir = NULL;
408#endif
409
410 /* in/out arguments */
411 LPWSTR lpstrCustomFilter = NULL;
412
413 /* input arguments */
414 LPCWSTR lpstrFilter = NULL;
415 LPCWSTR lpstrInitialDir = NULL;
416 LPCWSTR lpstrTitle = NULL;
417 LPCWSTR lpstrDefExt = NULL;
418 LPCWSTR lpTemplateName = NULL;
419 DWORD dwFlags;
420
421 /* Initialise FileOpenDlgInfos structure*/
422 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
423 ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
424
425 /* Pass in the original ofn */
426 fodInfos->ofnInfos = (LPOPENFILENAMEA) ofn;
427
428 /* convert lpstrFilter */
429 if (ofn->lpstrFilter)
430 {
431 LPCWSTR s;
432 LPSTR y;
433 int n, len;
434
435 lpstrFilter = ofn->lpstrFilter;
436
437 /* filter is a list... title\0ext\0......\0\0 */
438 s = ofn->lpstrFilter;
439
440 while (*s) s = s+strlenW(s)+1;
441 s++;
442 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
443 len = WideCharToMultiByte( CP_ACP, 0, ofn->lpstrFilter, n, NULL, 0, NULL, NULL );
444 y = (LPSTR)MemAlloc(len);
445 WideCharToMultiByte( CP_ACP, 0, ofn->lpstrFilter, n, y, len, NULL, NULL );
446#ifdef __WIN32OS2__
447 ofn->lpstrFilter = (LPWSTR)y;
448#else
449 (LPSTR)ofn->lpstrFilter = y;
450#endif
451 }
452
453 /* convert lpstrCustomFilter */
454 if (ofn->lpstrCustomFilter)
455 {
456 LPWSTR s;
457 LPSTR y;
458 int n, len;
459
460 lpstrCustomFilter = ofn->lpstrCustomFilter;
461 /* filter is a list... title\0ext\0......\0\0 */
462 s = ofn->lpstrCustomFilter;
463 while (*s) s = s+strlenW(s)+1;
464 s++;
465 n = s - ofn->lpstrCustomFilter;
466 len = WideCharToMultiByte( CP_ACP, 0, ofn->lpstrCustomFilter, n, NULL, 0, NULL, NULL );
467 y = (LPSTR)MemAlloc(len);
468 WideCharToMultiByte( CP_ACP, 0, ofn->lpstrCustomFilter, n, y, len, NULL, NULL );
469#ifdef __WIN32OS2__
470 ofn->lpstrCustomFilter = (LPWSTR)y;
471#else
472 (LPSTR)ofn->lpstrCustomFilter = y;
473#endif
474 }
475
476 /* convert string arguments, save others */
477 AllocOutArgWtoA(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
478 AllocOutArgWtoA(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
479 AllocInArgWtoA(ofn->lpstrInitialDir, lpstrInitialDir);
480 AllocInArgWtoA(ofn->lpstrTitle, lpstrTitle);
481 AllocInArgWtoA(ofn->lpstrDefExt, lpstrDefExt);
482 AllocInArgWtoA(ofn->lpTemplateName, lpTemplateName);
483 dwFlags = ofn->Flags;
484 hInstance = ofn->hInstance;
485
486#ifdef __WIN32OS2__
487 /* save current directory */
488 if (ofn->Flags & OFN_NOCHANGEDIR)
489 {
490 lpstrSavDir = MemAlloc(MAX_PATH);
491 GetCurrentDirectoryA(MAX_PATH, lpstrSavDir);
492 }
493#endif
494
495 ofn->Flags = ofn->Flags|OFN_WINE|OFN_UNICODE;
496 ofn->hInstance = MapHModuleLS(ofn->hInstance);
497
498 switch(iDlgType)
499 {
500 case OPEN_DIALOG :
501 ret = GetFileName95(fodInfos);
502 break;
503 case SAVE_DIALOG :
504 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
505#ifdef __WIN32OS2__
506 //NT4 seems to ignore this flag (fixes ElstarFormular save dialog)
507 ofn->Flags &= ~OFN_FILEMUSTEXIST;
508#endif
509 ret = GetFileName95(fodInfos);
510 break;
511 default :
512 ret = 0;
513 }
514
515#ifdef __WIN32OS2__
516 if (lpstrSavDir)
517 {
518 SetCurrentDirectoryA(lpstrSavDir);
519 MemFree(lpstrSavDir);
520 }
521#endif
522
523 /* restore saved IN arguments and convert OUT arguments back */
524 ofn->Flags = dwFlags;
525 ofn->hInstance = hInstance;
526 FreeInArg(ofn->lpstrFilter, lpstrFilter);
527 FreeInArg(ofn->lpstrCustomFilter, lpstrCustomFilter);
528 FreeOutArg(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
529 FreeOutArg(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
530 FreeInArg(ofn->lpstrInitialDir, lpstrInitialDir);
531 FreeInArg(ofn->lpstrTitle, lpstrTitle);
532 FreeInArg(ofn->lpstrDefExt, lpstrDefExt);
533 FreeInArg(ofn->lpTemplateName, lpTemplateName);
534
535 MemFree((LPVOID)(fodInfos));
536 return ret;
537}
538
539void ArrangeCtrlPositions( HWND hwndChildDlg, HWND hwndParentDlg)
540{
541 HWND hwndChild,hwndStc32;
542 RECT rectParent, rectChild, rectCtrl, rectStc32, rectTemp;
543 POINT ptMoveCtl;
544 POINT ptParentClient;
545
546 TRACE("\n");
547
548 ptMoveCtl.x = ptMoveCtl.y = 0;
549 hwndStc32=GetDlgItem(hwndChildDlg,stc32);
550 GetClientRect(hwndParentDlg,&rectParent);
551 GetClientRect(hwndChildDlg,&rectChild);
552
553 if(hwndStc32)
554 {
555 GetWindowRect(hwndStc32,&rectStc32);
556 MapWindowPoints(0, hwndChildDlg,(LPPOINT)&rectStc32,2);
557 CopyRect(&rectTemp,&rectStc32);
558
559 SetRect(&rectStc32,rectStc32.left,rectStc32.top,rectStc32.left + (rectParent.right-rectParent.left),rectStc32.top+(rectParent.bottom-rectParent.top));
560 SetWindowPos(hwndStc32,0,rectStc32.left,rectStc32.top,rectStc32.right-rectStc32.left,rectStc32.bottom-rectStc32.top,SWP_NOMOVE|SWP_NOZORDER | SWP_NOACTIVATE);
561
562 if(rectStc32.right < rectTemp.right)
563 {
564 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
565 ptMoveCtl.x = 0;
566 }
567 else
568 {
569 ptMoveCtl.x = (rectStc32.right - rectTemp.right);
570 ptParentClient.x = max((rectParent.right-rectParent.left),((rectChild.right-rectChild.left)+rectStc32.right-rectTemp.right));
571 }
572
573 if(rectStc32.bottom < rectTemp.bottom)
574 {
575 ptParentClient.y = max((rectParent.bottom-rectParent.top),(rectChild.bottom-rectChild.top));
576 ptMoveCtl.y = 0;
577 }
578 else
579 {
580 ptMoveCtl.y = (rectStc32.bottom - rectTemp.bottom);
581 ptParentClient.y = max((rectParent.bottom-rectParent.top),((rectChild.bottom-rectChild.top)+rectStc32.bottom-rectTemp.bottom));
582 }
583 }
584 else
585 {
586 if( (GetWindow(hwndChildDlg,GW_CHILD)) == (HWND) NULL) return;
587
588 SetRectEmpty(&rectTemp);
589 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
590 ptParentClient.y = (rectParent.bottom-rectParent.top) + (rectChild.bottom-rectChild.top);
591 ptMoveCtl.y = rectParent.bottom-rectParent.top;
592 ptMoveCtl.x=0;
593 }
594 SetRect(&rectParent,rectParent.left,rectParent.top,rectParent.left+ptParentClient.x,rectParent.top+ptParentClient.y);
595 AdjustWindowRectEx( &rectParent,GetWindowLongA(hwndParentDlg,GWL_STYLE),FALSE,GetWindowLongA(hwndParentDlg,GWL_EXSTYLE));
596
597 SetWindowPos(hwndChildDlg, 0, 0,0, ptParentClient.x,ptParentClient.y, SWP_NOZORDER );
598 SetWindowPos(hwndParentDlg, 0, rectParent.left,rectParent.top, (rectParent.right- rectParent.left),
599 (rectParent.bottom-rectParent.top),SWP_NOMOVE | SWP_NOZORDER);
600
601 hwndChild = GetWindow(hwndChildDlg,GW_CHILD);
602 if(hwndStc32)
603 {
604 GetWindowRect(hwndStc32,&rectStc32);
605 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
606 }
607 else
608 SetRect(&rectStc32,0,0,0,0);
609
610 if (hwndChild )
611 {
612 do
613 {
614 if(hwndChild != hwndStc32)
615 {
616 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
617 continue;
618 GetWindowRect(hwndChild,&rectCtrl);
619 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
620
621 /*
622 Check the initial position of the controls relative to the initial
623 position and size of stc32 (before it is expanded).
624 */
625 if (rectCtrl.left >= rectTemp.right && rectCtrl.top >= rectTemp.bottom)
626 {
627 rectCtrl.left += ptMoveCtl.x;
628 rectCtrl.top += ptMoveCtl.y;
629 }
630 else if (rectCtrl.left >= rectTemp.right)
631 {
632 rectCtrl.left += ptMoveCtl.x;
633 }
634 else if (rectCtrl.top >= rectTemp.bottom)
635 {
636 rectCtrl.top += ptMoveCtl.y;
637 }
638
639 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
640 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
641 SWP_NOSIZE | SWP_NOZORDER );
642 }
643 } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
644 }
645 hwndChild = GetWindow(hwndParentDlg,GW_CHILD);
646
647 if(hwndStc32)
648 {
649 GetWindowRect(hwndStc32,&rectStc32);
650 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
651 ptMoveCtl.x = rectStc32.left - 0;
652 ptMoveCtl.y = rectStc32.top - 0;
653 if (hwndChild )
654 {
655 do
656 {
657 if(hwndChild != hwndChildDlg)
658 {
659 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
660 continue;
661 GetWindowRect(hwndChild,&rectCtrl);
662 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
663
664 rectCtrl.left += ptMoveCtl.x;
665 rectCtrl.top += ptMoveCtl.y;
666
667 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
668 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
669 SWP_NOSIZE |SWP_NOZORDER );
670 }
671 } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
672 }
673 }
674}
675
676
677HRESULT WINAPI FileOpenDlgProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
678{
679 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(GetParent(hwnd),FileOpenDlgInfosStr);
680
681#if 0
682 TRACE("0x%04x\n", uMsg);
683#endif
684
685 switch(uMsg)
686 {
687 case WM_INITDIALOG:
688 {
689 fodInfos = (FileOpenDlgInfos *)lParam;
690 lParam = (LPARAM) fodInfos->ofnInfos;
691 ArrangeCtrlPositions(hwnd,GetParent(hwnd));
692
693 if(fodInfos && IsHooked(fodInfos))
694 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
695 return 0;
696 }
697 }
698
699 if(fodInfos && IsHooked(fodInfos))
700 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
701
702 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
703}
704
705HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos, HWND hwnd)
706{
707 LPCVOID template;
708 HRSRC hRes;
709 HANDLE hDlgTmpl = 0;
710 HWND hChildDlg = 0;
711
712 TRACE("\n");
713
714 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATE ||
715 fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
716 {
717 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
718 {
719 if( !(template = LockResource( fodInfos->ofnInfos->hInstance)))
720 {
721 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
722 return (HWND)NULL;
723 }
724 }
725 else
726 {
727 if (!(hRes = FindResourceA(MapHModuleSL(fodInfos->ofnInfos->hInstance),
728 (fodInfos->ofnInfos->lpTemplateName), RT_DIALOGA)))
729 {
730 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
731 return (HWND)NULL;
732 }
733 if (!(hDlgTmpl = LoadResource( MapHModuleSL(fodInfos->ofnInfos->hInstance),
734 hRes )) || !(template = LockResource( hDlgTmpl )))
735 {
736 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
737 return (HWND)NULL;
738 }
739 }
740
741 hChildDlg= CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,template,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
742 if(hChildDlg)
743 {
744 ShowWindow(hChildDlg,SW_SHOW);
745 return hChildDlg;
746 }
747 }
748 else if( IsHooked(fodInfos))
749 {
750 RECT rectHwnd;
751 DLGTEMPLATE tmplate;
752 GetClientRect(hwnd,&rectHwnd);
753 tmplate.style = WS_CHILD | WS_CLIPSIBLINGS;
754 tmplate.dwExtendedStyle = 0;
755 tmplate.cdit = 0;
756 tmplate.x = 0;
757 tmplate.y = 0;
758 tmplate.cx = rectHwnd.right-rectHwnd.left;
759 tmplate.cy = rectHwnd.bottom-rectHwnd.top;
760
761 return CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,&tmplate,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
762 }
763 return (HWND)NULL;
764}
765
766/***********************************************************************
767* SendCustomDlgNotificationMessage
768*
769* Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
770*/
771
772HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
773{
774 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndParentDlg,FileOpenDlgInfosStr);
775
776 TRACE("0x%04x 0x%04x\n",hwndParentDlg, uCode);
777
778 if(!fodInfos) return 0;
779
780 if(fodInfos->ofnInfos->Flags & OFN_UNICODE)
781 FIXME("sending OPENFILENAMEA structure. Hook is expecting OPENFILENAMEW!\n");
782
783 if(fodInfos->DlgInfos.hwndCustomDlg)
784 {
785 OFNOTIFYA ofnNotify;
786 HRESULT ret;
787 ofnNotify.hdr.hwndFrom=hwndParentDlg;
788 ofnNotify.hdr.idFrom=0;
789 ofnNotify.hdr.code = uCode;
790 ofnNotify.lpOFN = fodInfos->ofnInfos;
791 TRACE("CALL NOTIFY for %x\n", uCode);
792 ret = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);
793 TRACE("RET NOTIFY\n");
794 return ret;
795 }
796 return TRUE;
797}
798
799/***********************************************************************
800* FILEDLG95_HandleCustomDialogMessages
801*
802* Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
803*/
804HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
805{
806 LPSTR lpstrFileSpec;
807 int reqSize;
808 char lpstrPath[MAX_PATH];
809 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
810 if(!fodInfos) return -1;
811
812 switch(uMsg)
813 {
814 case CDM_GETFILEPATH:
815 GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
816 lpstrFileSpec = (LPSTR)PathFindFileNameA(lpstrPath);
817 if (lpstrFileSpec==lpstrPath)
818 {
819 char lpstrCurrentDir[MAX_PATH];
820 /* Prepend the current path */
821 SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrCurrentDir);
822 if ((LPSTR)lParam!=NULL)
823 snprintf((LPSTR)lParam,(int)wParam,"%s\\%s",lpstrCurrentDir,lpstrPath);
824 reqSize=strlen(lpstrCurrentDir)+1+strlen(lpstrPath)+1;
825 }
826 else
827 {
828 lstrcpynA((LPSTR)lParam,(LPSTR)lpstrPath,(int)wParam);
829 reqSize=strlen(lpstrPath);
830 }
831 /* return the required buffer size */
832 return reqSize;
833
834 case CDM_GETFOLDERPATH:
835 SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);
836 if ((LPSTR)lParam!=NULL)
837 lstrcpynA((LPSTR)lParam,lpstrPath,(int)wParam);
838 return strlen(lpstrPath);
839
840 case CDM_GETSPEC:
841 reqSize=GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
842 lpstrFileSpec = (LPSTR)PathFindFileNameA(lpstrPath);
843 if ((LPSTR)lParam!=NULL)
844 lstrcpynA((LPSTR)lParam, lpstrFileSpec, (int)wParam);
845 return strlen(lpstrFileSpec);
846
847 case CDM_SETCONTROLTEXT:
848 if ( 0 != lParam )
849 SetDlgItemTextA( hwnd, (UINT) wParam, (LPSTR) lParam );
850 return TRUE;
851
852 case CDM_HIDECONTROL:
853 case CDM_SETDEFEXT:
854 FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");
855 return -1;
856 }
857 return TRUE;
858}
859
860/***********************************************************************
861 * FileOpenDlgProc95
862 *
863 * File open dialog procedure
864 */
865HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
866{
867#if 0
868 TRACE("0x%04x 0x%04x\n", hwnd, uMsg);
869#endif
870
871 switch(uMsg)
872 {
873 case WM_INITDIALOG:
874 {
875 FileOpenDlgInfos * fodInfos = (FileOpenDlgInfos *)lParam;
876
877 /* Adds the FileOpenDlgInfos in the property list of the dialog
878 so it will be easily accessible through a GetPropA(...) */
879 SetPropA(hwnd, FileOpenDlgInfosStr, (HANDLE) fodInfos);
880
881 fodInfos->DlgInfos.hwndCustomDlg =
882 CreateTemplateDialog((FileOpenDlgInfos *)lParam, hwnd);
883
884 FILEDLG95_InitControls(hwnd);
885 SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE);
886 FILEDLG95_FillControls(hwnd, wParam, lParam);
887 SendCustomDlgNotificationMessage(hwnd,CDN_SELCHANGE);
888 SetWindowPos(fodInfos->DlgInfos.hwndCustomDlg, HWND_BOTTOM,
889 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE);
890 return 0;
891 }
892 case WM_COMMAND:
893 return FILEDLG95_OnWMCommand(hwnd, wParam, lParam);
894 case WM_DRAWITEM:
895 {
896 switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
897 {
898 case IDC_LOOKIN:
899 FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT) lParam);
900 return TRUE;
901 }
902 }
903 return FALSE;
904
905 case WM_GETISHELLBROWSER:
906 return FILEDLG95_OnWMGetIShellBrowser(hwnd);
907
908 case WM_DESTROY:
909 RemovePropA(hwnd, FileOpenDlgInfosStr);
910 return FALSE;
911
912 case WM_NOTIFY:
913 {
914 LPNMHDR lpnmh = (LPNMHDR)lParam;
915 UINT stringId = -1;
916
917 /* set up the button tooltips strings */
918 if(TTN_GETDISPINFOA == lpnmh->code )
919 {
920 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
921 switch(lpnmh->idFrom )
922 {
923 /* Up folder button */
924 case FCIDM_TB_UPFOLDER:
925 stringId = IDS_UPFOLDER;
926 break;
927 /* New folder button */
928 case FCIDM_TB_NEWFOLDER:
929 stringId = IDS_NEWFOLDER;
930 break;
931 /* List option button */
932 case FCIDM_TB_SMALLICON:
933 stringId = IDS_LISTVIEW;
934 break;
935 /* Details option button */
936 case FCIDM_TB_REPORTVIEW:
937 stringId = IDS_REPORTVIEW;
938 break;
939 /* Desktop button */
940 case FCIDM_TB_DESKTOP:
941 stringId = IDS_TODESKTOP;
942 break;
943 default:
944 stringId = 0;
945 }
946 lpdi->hinst = COMMDLG_hInstance32;
947 lpdi->lpszText = (LPSTR) stringId;
948 }
949 return FALSE;
950 }
951 default :
952 if(uMsg >= CDM_FIRST && uMsg <= CDM_LAST)
953 return FILEDLG95_HandleCustomDialogMessages(hwnd, uMsg, wParam, lParam);
954 return FALSE;
955 }
956}
957
958/***********************************************************************
959 * FILEDLG95_InitControls
960 *
961 * WM_INITDIALOG message handler (before hook notification)
962 */
963static LRESULT FILEDLG95_InitControls(HWND hwnd)
964{
965 TBBUTTON tbb[] =
966 {
967 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
968 {VIEW_PARENTFOLDER, FCIDM_TB_UPFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
969 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
970 {VIEW_NEWFOLDER+1, FCIDM_TB_DESKTOP, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
971 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
972 {VIEW_NEWFOLDER, FCIDM_TB_NEWFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
973 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
974 {VIEW_LIST, FCIDM_TB_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
975 {VIEW_DETAILS, FCIDM_TB_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
976 };
977 TBADDBITMAP tba[] =
978 {
979 { HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR },
980 { COMDLG32_hInstance, 800 } // desktop icon
981 };
982
983 RECT rectTB;
984
985 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
986
987 TRACE("%p\n", fodInfos);
988
989 /* Get the hwnd of the controls */
990 fodInfos->DlgInfos.hwndFileName = GetDlgItem(hwnd,IDC_FILENAME);
991 fodInfos->DlgInfos.hwndFileTypeCB = GetDlgItem(hwnd,IDC_FILETYPE);
992 fodInfos->DlgInfos.hwndLookInCB = GetDlgItem(hwnd,IDC_LOOKIN);
993
994 /* construct the toolbar */
995 GetWindowRect(GetDlgItem(hwnd,IDC_TOOLBARSTATIC),&rectTB);
996 MapWindowPoints( 0, hwnd,(LPPOINT)&rectTB,2);
997
998 fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, (LPSTR) NULL,
999 WS_CHILD | WS_GROUP | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE,
1000 0, 0, 150, 26, hwnd, (HMENU) IDC_TOOLBAR, COMMDLG_hInstance32, NULL);
1001
1002 SetWindowPos(fodInfos->DlgInfos.hwndTB, 0,
1003 rectTB.left,rectTB.top, rectTB.right-rectTB.left, rectTB.bottom-rectTB.top,
1004 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
1005
1006 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
1007
1008/* fixme: use TB_LOADIMAGES when implemented */
1009/* SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/
1010 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 12, (LPARAM) &tba[0]);
1011 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 1, (LPARAM) &tba[1]);
1012
1013 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSA, (WPARAM) 9,(LPARAM) &tbb);
1014 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_AUTOSIZE, 0, 0);
1015
1016 /* Set the window text with the text specified in the OPENFILENAME structure */
1017 if(fodInfos->ofnInfos->lpstrTitle)
1018 {
1019 SetWindowTextA(hwnd,fodInfos->ofnInfos->lpstrTitle);
1020 }
1021 else if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
1022 {
1023 SetWindowTextA(hwnd,"Save");
1024 }
1025
1026 /* Initialise the file name edit control */
1027 if(fodInfos->ofnInfos->lpstrFile)
1028 {
1029 LPSTR lpstrFile = PathFindFileNameA(fodInfos->ofnInfos->lpstrFile);
1030 SetDlgItemTextA(hwnd, IDC_FILENAME, lpstrFile);
1031 }
1032
1033 /* Must the open as read only check box be checked ?*/
1034 if(fodInfos->ofnInfos->Flags & OFN_READONLY)
1035 {
1036 SendDlgItemMessageA(hwnd,IDC_OPENREADONLY,BM_SETCHECK,(WPARAM)TRUE,0);
1037 }
1038
1039 /* Must the open as read only check box be hid ?*/
1040 if(fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY)
1041 {
1042 ShowWindow(GetDlgItem(hwnd,IDC_OPENREADONLY),SW_HIDE);
1043 }
1044
1045 /* Must the help button be hid ?*/
1046 if (!(fodInfos->ofnInfos->Flags & OFN_SHOWHELP))
1047 {
1048 ShowWindow(GetDlgItem(hwnd, pshHelp), SW_HIDE);
1049 }
1050
1051 /* Resize the height, if open as read only checkbox ad help button
1052 are hidden and we are not using a custom template */
1053 if ( (fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) &&
1054 (!(fodInfos->ofnInfos->Flags &
1055 (OFN_SHOWHELP|OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE))))
1056 {
1057 RECT rectDlg, rectHelp, rectCancel;
1058 GetWindowRect(hwnd, &rectDlg);
1059 GetWindowRect(GetDlgItem(hwnd, pshHelp), &rectHelp);
1060 GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rectCancel);
1061 /* subtract the height of the help button plus the space between
1062 the help button and the cancel button to the height of the dialog */
1063 SetWindowPos(hwnd, 0, 0, 0, rectDlg.right-rectDlg.left,
1064 (rectDlg.bottom-rectDlg.top) - (rectHelp.bottom - rectCancel.bottom),
1065 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
1066 }
1067
1068 /* change Open to Save FIXME: use resources */
1069 if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
1070 {
1071 SetDlgItemTextA(hwnd,IDOK,"&Save");
1072 SetDlgItemTextA(hwnd,IDC_LOOKINSTATIC,"Save &in");
1073 }
1074 return 0;
1075}
1076
1077/***********************************************************************
1078 * FILEDLG95_FillControls
1079 *
1080 * WM_INITDIALOG message handler (after hook notification)
1081 */
1082static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam)
1083{
1084 LPITEMIDLIST pidlItemId = NULL;
1085
1086 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) lParam;
1087
1088 TRACE("dir=%s file=%s\n",
1089 fodInfos->ofnInfos->lpstrInitialDir, fodInfos->ofnInfos->lpstrFile);
1090
1091 /* Get the initial directory pidl */
1092
1093 if(!(pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,fodInfos->ofnInfos->lpstrInitialDir)))
1094 {
1095 char path[MAX_PATH];
1096
1097 GetCurrentDirectoryA(MAX_PATH,path);
1098 pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder, path);
1099 }
1100
1101 /* Initialise shell objects */
1102 FILEDLG95_SHELL_Init(hwnd);
1103
1104 /* Initialize the Look In combo box */
1105 FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB);
1106
1107 /* Initialize the filter combo box */
1108 FILEDLG95_FILETYPE_Init(hwnd);
1109
1110 /* Browse to the initial directory */
1111 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,pidlItemId, SBSP_ABSOLUTE);
1112
1113 /* Free pidlItem memory */
1114 COMDLG32_SHFree(pidlItemId);
1115
1116 return TRUE;
1117}
1118/***********************************************************************
1119 * FILEDLG95_Clean
1120 *
1121 * Regroups all the cleaning functions of the filedlg
1122 */
1123void FILEDLG95_Clean(HWND hwnd)
1124{
1125 FILEDLG95_FILETYPE_Clean(hwnd);
1126 FILEDLG95_LOOKIN_Clean(hwnd);
1127 FILEDLG95_SHELL_Clean(hwnd);
1128}
1129/***********************************************************************
1130 * FILEDLG95_OnWMCommand
1131 *
1132 * WM_COMMAND message handler
1133 */
1134static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
1135{
1136 WORD wNotifyCode = HIWORD(wParam); /* notification code */
1137 WORD wID = LOWORD(wParam); /* item, control, or accelerator identifier */
1138 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1139
1140 switch(wID)
1141 {
1142 /* OK button */
1143 case IDOK:
1144 if(FILEDLG95_OnOpen(hwnd))
1145 SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK);
1146 break;
1147 /* Cancel button */
1148 case IDCANCEL:
1149 FILEDLG95_Clean(hwnd);
1150 EndDialog(hwnd, FALSE);
1151 break;
1152 /* Filetype combo box */
1153 case IDC_FILETYPE:
1154 FILEDLG95_FILETYPE_OnCommand(hwnd,wNotifyCode);
1155 break;
1156 /* LookIn combo box */
1157 case IDC_LOOKIN:
1158 FILEDLG95_LOOKIN_OnCommand(hwnd,wNotifyCode);
1159 break;
1160
1161 /* --- toolbar --- */
1162 /* Up folder button */
1163 case FCIDM_TB_UPFOLDER:
1164 FILEDLG95_SHELL_UpFolder(hwnd);
1165 break;
1166 /* New folder button */
1167 case FCIDM_TB_NEWFOLDER:
1168 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_NEWFOLDER);
1169 break;
1170 /* List option button */
1171 case FCIDM_TB_SMALLICON:
1172 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWLIST);
1173 break;
1174 /* Details option button */
1175 case FCIDM_TB_REPORTVIEW:
1176 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWDETAILS);
1177 break;
1178 /* Details option button */
1179 case FCIDM_TB_DESKTOP:
1180 FILEDLG95_SHELL_BrowseToDesktop(hwnd);
1181 break;
1182
1183 case IDC_FILENAME:
1184 break;
1185
1186 }
1187 /* Do not use the listview selection anymore */
1188 fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
1189 return 0;
1190}
1191
1192/***********************************************************************
1193 * FILEDLG95_OnWMGetIShellBrowser
1194 *
1195 * WM_GETISHELLBROWSER message handler
1196 */
1197static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd)
1198{
1199
1200 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1201
1202 TRACE("\n");
1203
1204 SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)fodInfos->Shell.FOIShellBrowser);
1205
1206 return TRUE;
1207}
1208
1209
1210/***********************************************************************
1211 * FILEDLG95_OnOpenMultipleFiles
1212 *
1213 * Handles the opening of multiple files.
1214 *
1215 * FIXME
1216 * check destination buffer size
1217 */
1218BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed)
1219{
1220 CHAR lpstrPathSpec[MAX_PATH] = "";
1221 LPSTR lpstrFile;
1222 UINT nCount, nSizePath;
1223 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1224
1225 TRACE("\n");
1226
1227 lpstrFile = fodInfos->ofnInfos->lpstrFile;
1228 lpstrFile[0] = '\0';
1229
1230 SHGetPathFromIDListA( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec );
1231
1232 if ( !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE) &&
1233 ( fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST))
1234 {
1235 LPSTR lpstrTemp = lpstrFileList;
1236
1237 for ( nCount = 0; nCount < nFileCount; nCount++ )
1238 {
1239 LPITEMIDLIST pidl;
1240
1241 pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder, lpstrTemp);
1242 if (!pidl)
1243 {
1244 CHAR lpstrNotFound[100];
1245 CHAR lpstrMsg[100];
1246 CHAR tmp[400];
1247
1248 LoadStringA(COMMDLG_hInstance32, IDS_FILENOTFOUND, lpstrNotFound, 100);
1249 LoadStringA(COMMDLG_hInstance32, IDS_VERIFYFILE, lpstrMsg, 100);
1250
1251 strcpy(tmp, lpstrTemp);
1252 strcat(tmp, "\n");
1253 strcat(tmp, lpstrNotFound);
1254 strcat(tmp, "\n");
1255 strcat(tmp, lpstrMsg);
1256
1257 MessageBoxA(hwnd, tmp, fodInfos->ofnInfos->lpstrTitle, MB_OK | MB_ICONEXCLAMATION);
1258 return FALSE;
1259 }
1260
1261 /* move to the next file in the list of files */
1262 lpstrTemp += strlen(lpstrTemp) + 1;
1263 COMDLG32_SHFree(pidl);
1264 }
1265 }
1266
1267 nSizePath = strlen(lpstrPathSpec);
1268 strcpy( lpstrFile, lpstrPathSpec);
1269 memcpy( lpstrFile + nSizePath + 1, lpstrFileList, sizeUsed );
1270
1271 fodInfos->ofnInfos->nFileOffset = nSizePath + 1;
1272 fodInfos->ofnInfos->nFileExtension = 0;
1273
1274 /* clean and exit */
1275 FILEDLG95_Clean(hwnd);
1276 return EndDialog(hwnd,TRUE);
1277}
1278
1279/***********************************************************************
1280 * FILEDLG95_OnOpen
1281 *
1282 * Ok button WM_COMMAND message handler
1283 *
1284 * If the function succeeds, the return value is nonzero.
1285 */
1286#define ONOPEN_BROWSE 1
1287#define ONOPEN_OPEN 2
1288#define ONOPEN_SEARCH 3
1289static void FILEDLG95_OnOpenMessage(HWND hwnd, int idCaption, int idText)
1290{
1291 char strMsgTitle[MAX_PATH];
1292 char strMsgText [MAX_PATH];
1293 if (idCaption)
1294 LoadStringA(COMDLG32_hInstance, idCaption, strMsgTitle, sizeof(strMsgTitle));
1295 else
1296 strMsgTitle[0] = '\0';
1297 LoadStringA(COMDLG32_hInstance, idText, strMsgText, sizeof(strMsgText));
1298 MessageBoxA(hwnd,strMsgText, strMsgTitle, MB_OK | MB_ICONHAND);
1299}
1300
1301BOOL FILEDLG95_OnOpen(HWND hwnd)
1302{
1303 char * lpstrFileList;
1304 UINT nFileCount = 0;
1305 UINT sizeUsed = 0;
1306 BOOL ret = TRUE;
1307 char lpstrPathAndFile[MAX_PATH];
1308 char lpstrTemp[MAX_PATH];
1309 LPSHELLFOLDER lpsf = NULL;
1310 int nOpenAction;
1311 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1312
1313 TRACE("hwnd=0x%04x\n", hwnd);
1314
1315 /* get the files from the edit control */
1316 nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed);
1317
1318 /* try if the user selected a folder in the shellview */
1319 if(nFileCount == 0)
1320 {
1321 BrowseSelectedFolder(hwnd);
1322 return FALSE;
1323 }
1324
1325 if(nFileCount > 1)
1326 {
1327 ret = FILEDLG95_OnOpenMultipleFiles(hwnd, lpstrFileList, nFileCount, sizeUsed);
1328 goto ret;
1329 }
1330
1331 TRACE("count=%u len=%u file=%s\n", nFileCount, sizeUsed, lpstrFileList);
1332
1333/*
1334 Step 1: Build a complete path name from the current folder and
1335 the filename or path in the edit box.
1336 Special cases:
1337 - the path in the edit box is a root path
1338 (with or without drive letter)
1339 - the edit box contains ".." (or a path with ".." in it)
1340*/
1341
1342 /* Get the current directory name */
1343 if (!SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathAndFile))
1344 {
1345 /* we are in a special folder, default to desktop */
1346 if(FAILED(COMDLG32_SHGetFolderPathA(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, 0, 0, lpstrPathAndFile)))
1347 {
1348 /* last fallback */
1349 GetCurrentDirectoryA(MAX_PATH, lpstrPathAndFile);
1350 }
1351 }
1352 PathAddBackslashA(lpstrPathAndFile);
1353
1354 TRACE("current directory=%s\n", lpstrPathAndFile);
1355
1356 /* if the user specifyed a fully qualified path use it */
1357 if(PathIsRelativeA(lpstrFileList))
1358 {
1359 strcat(lpstrPathAndFile, lpstrFileList);
1360 }
1361 else
1362 {
1363 /* does the path have a drive letter? */
1364 if (PathGetDriveNumberA(lpstrFileList) == -1)
1365 strcpy(lpstrPathAndFile+2, lpstrFileList);
1366 else
1367 strcpy(lpstrPathAndFile, lpstrFileList);
1368 }
1369
1370 /* resolve "." and ".." */
1371 PathCanonicalizeA(lpstrTemp, lpstrPathAndFile );
1372 strcpy(lpstrPathAndFile, lpstrTemp);
1373 TRACE("canon=%s\n", lpstrPathAndFile);
1374
1375 MemFree(lpstrFileList);
1376
1377/*
1378 Step 2: here we have a cleaned up path
1379
1380 We have to parse the path step by step to see if we have to browse
1381 to a folder if the path points to a directory or the last
1382 valid element is a directory.
1383
1384 valid variables:
1385 lpstrPathAndFile: cleaned up path
1386 */
1387
1388 nOpenAction = ONOPEN_BROWSE;
1389
1390#ifdef __WIN32OS2__
1391 /* @@@AH 2001-06-02 moved out of !OFN_NONVALIDATE block - needs to be set */
1392 if (FAILED (SHGetDesktopFolder(&lpsf))) return FALSE;
1393#endif
1394
1395 /* dont apply any checks with OFN_NOVALIDATE */
1396 if(!(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE))
1397 {
1398 LPSTR lpszTemp, lpszTemp1;
1399 LPITEMIDLIST pidl = NULL;
1400
1401 /* check for invalid chars */
1402 if(strpbrk(lpstrPathAndFile+3, "/:<>|") != NULL)
1403 {
1404 FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_FILENAME);
1405 ret = FALSE;
1406 goto ret;
1407 }
1408#ifndef __WIN32OS2__
1409 if (FAILED (SHGetDesktopFolder(&lpsf))) return FALSE;
1410#endif
1411 lpszTemp1 = lpszTemp = lpstrPathAndFile;
1412 while (lpszTemp1)
1413 {
1414 LPSHELLFOLDER lpsfChild;
1415 WCHAR lpwstrTemp[MAX_PATH];
1416 DWORD dwEaten, dwAttributes;
1417
1418 lpszTemp = PathFindNextComponentA(lpszTemp);
1419
1420 if (!lpszTemp) break; /* end of path */
1421
1422 if(*lpszTemp)
1423 {
1424 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpszTemp1, lpszTemp - lpszTemp1,
1425 lpwstrTemp, MAX_PATH );
1426 lpwstrTemp[len] = 0;
1427 }
1428 else
1429 {
1430 MultiByteToWideChar( CP_ACP, 0, lpszTemp1, -1,
1431 lpwstrTemp, sizeof(lpwstrTemp)/sizeof(WCHAR) );
1432
1433 /* if the last element is a wildcard do a search */
1434 if(strpbrk(lpszTemp1, "*?") != NULL)
1435 {
1436 nOpenAction = ONOPEN_SEARCH;
1437 break;
1438 }
1439 }
1440 lpszTemp1 = lpszTemp;
1441
1442 TRACE("parse now=%s next=%s sf=%p\n",debugstr_w(lpwstrTemp), debugstr_a(lpszTemp), lpsf);
1443
1444 if(lstrlenW(lpwstrTemp)==2) PathAddBackslashW(lpwstrTemp);
1445
1446 dwAttributes = SFGAO_FOLDER;
1447 if(SUCCEEDED(IShellFolder_ParseDisplayName(lpsf, hwnd, NULL, lpwstrTemp, &dwEaten, &pidl, &dwAttributes)))
1448 {
1449 /* the path component is valid, we have a pidl of the next path component */
1450 TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes, pidl);
1451 if(dwAttributes & SFGAO_FOLDER)
1452 {
1453 if(FAILED(IShellFolder_BindToObject(lpsf, pidl, 0, &IID_IShellFolder, (LPVOID*)&lpsfChild)))
1454 {
1455 ERR("bind to failed\n"); /* should not fail */
1456 break;
1457 }
1458 IShellFolder_Release(lpsf);
1459 lpsf = lpsfChild;
1460 lpsfChild = NULL;
1461 }
1462 else
1463 {
1464 TRACE("value\n");
1465
1466 /* end dialog, return value */
1467 nOpenAction = ONOPEN_OPEN;
1468 break;
1469 }
1470 COMDLG32_SHFree(pidl);
1471 pidl = NULL;
1472 }
1473 else
1474 {
1475 if(*lpszTemp) /* points to trailing null for last path element */
1476 {
1477 if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
1478 {
1479 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_PATHNOTEXISTING);
1480 break;
1481 }
1482 }
1483 else
1484 {
1485 if(fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST)
1486 {
1487 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_FILENOTEXISTING);
1488 break;
1489 }
1490 }
1491 /* change to the current folder */
1492 nOpenAction = ONOPEN_OPEN;
1493 break;
1494 }
1495 }
1496 if(pidl) COMDLG32_SHFree(pidl);
1497 }
1498#ifdef __WIN32OS2__
1499 else
1500 {
1501 // @@@AH 2001-06-02 when we are in OFN_NOVALIDATE mode, the action
1502 // must be to open the specified file when pressing open button
1503 TRACE("OFN_NOVALIDATE mode, set open action to ONOPEN_OPEN\n");
1504 nOpenAction = ONOPEN_OPEN;
1505 }
1506#endif
1507
1508/*
1509 Step 3: here we have a cleaned up and validated path
1510
1511 valid variables:
1512 lpsf: ShellFolder bound to the rightmost valid path component
1513 lpstrPathAndFile: cleaned up path
1514 nOpenAction: action to do
1515*/
1516 TRACE("end validate sf=%p\n", lpsf);
1517
1518 switch(nOpenAction)
1519 {
1520 case ONOPEN_SEARCH: /* set the current filter to the file mask and refresh */
1521 TRACE("ONOPEN_SEARCH %s\n", lpstrPathAndFile);
1522 {
1523 int iPos;
1524 LPSTR lpszTemp = PathFindFileNameA(lpstrPathAndFile);
1525 DWORD len;
1526
1527 /* replace the current filter */
1528 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1529 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1530 len = MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1, NULL, 0 );
1531 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc(len * sizeof(WCHAR));
1532 MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1,
1533 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1534
1535 /* set the filter cb to the extension when possible */
1536 if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB, lpszTemp)))
1537 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, iPos);
1538 }
1539 /* fall through */
1540 case ONOPEN_BROWSE: /* browse to the highest folder we could bind to */
1541 TRACE("ONOPEN_BROWSE\n");
1542 {
1543 IPersistFolder2 * ppf2;
1544 if(SUCCEEDED(IShellFolder_QueryInterface( lpsf, &IID_IPersistFolder2, (LPVOID*)&ppf2)))
1545 {
1546 LPITEMIDLIST pidlCurrent;
1547 IPersistFolder2_GetCurFolder(ppf2, &pidlCurrent);
1548 IPersistFolder2_Release(ppf2);
1549 if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent, fodInfos->ShellInfos.pidlAbsCurrent))
1550 {
1551 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE);
1552 }
1553 else if( nOpenAction == ONOPEN_SEARCH )
1554 {
1555 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1556 }
1557 COMDLG32_SHFree(pidlCurrent);
1558 }
1559 }
1560 ret = FALSE;
1561 break;
1562 case ONOPEN_OPEN: /* fill in the return struct and close the dialog */
1563 TRACE("ONOPEN_OPEN %s\n", lpstrPathAndFile);
1564 {
1565 /* add default extension */
1566 if (fodInfos->ofnInfos->lpstrDefExt)
1567 {
1568 if (! *PathFindExtensionA(lpstrPathAndFile))
1569 {
1570 /* only add "." in case a default extension does exist */
1571 if (*fodInfos->ofnInfos->lpstrDefExt != '\0')
1572 {
1573 strcat(lpstrPathAndFile, ".");
1574 strcat(lpstrPathAndFile, fodInfos->ofnInfos->lpstrDefExt);
1575 }
1576 }
1577 }
1578
1579 /* Check that the size of the file does not exceed buffer size.
1580 (Allow for extra \0 if OFN_MULTISELECT is set.) */
1581 if(strlen(lpstrPathAndFile) < fodInfos->ofnInfos->nMaxFile -
1582 ((fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT) ? 1 : 0))
1583 {
1584 LPSTR lpszTemp;
1585
1586 /* fill destination buffer */
1587 strcpy(fodInfos->ofnInfos->lpstrFile, lpstrPathAndFile);
1588 if (fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT)
1589 fodInfos->ofnInfos->lpstrFile[strlen(fodInfos->ofnInfos->lpstrFile)
1590 + 1] = '\0';
1591
1592 /* set filename offset */
1593 lpszTemp = PathFindFileNameA(lpstrPathAndFile);
1594 fodInfos->ofnInfos->nFileOffset = lpszTemp - lpstrPathAndFile;
1595
1596 /* set extension offset */
1597 lpszTemp = PathFindExtensionA(lpstrPathAndFile);
1598 fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? lpszTemp - lpstrPathAndFile + 1 : 0;
1599
1600 /* set the lpstrFileTitle */
1601 if(fodInfos->ofnInfos->lpstrFileTitle)
1602 {
1603 LPSTR lpstrFileTitle = PathFindFileNameA(lpstrPathAndFile);
1604 strncpy(fodInfos->ofnInfos->lpstrFileTitle, lpstrFileTitle, fodInfos->ofnInfos->nMaxFileTitle);
1605 }
1606
1607 /* ask the hook if we can close */
1608 if(IsHooked(fodInfos))
1609 {
1610 /* FIXME we are sending ASCII-structures. Does not work with NT */
1611 /* first old style */
1612 TRACE("---\n");
1613 CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,
1614 fodInfos->DlgInfos.hwndCustomDlg,
1615 fodInfos->HookMsg.fileokstring, 0, (LPARAM)fodInfos->ofnInfos);
1616 if (GetWindowLongA(hwnd, DWL_MSGRESULT))
1617 {
1618 TRACE("cancled\n");
1619 ret = FALSE;
1620 goto ret;
1621 }
1622 }
1623
1624 TRACE("close\n");
1625 FILEDLG95_Clean(hwnd);
1626 ret = EndDialog(hwnd, TRUE);
1627 }
1628 else
1629 {
1630 /* FIXME set error FNERR_BUFFERTOSMALL */
1631 FILEDLG95_Clean(hwnd);
1632 ret = EndDialog(hwnd, FALSE);
1633 }
1634 goto ret;
1635 }
1636 break;
1637 }
1638
1639ret:
1640 if(lpsf) IShellFolder_Release(lpsf);
1641 return ret;
1642}
1643
1644/***********************************************************************
1645 * FILEDLG95_SHELL_Init
1646 *
1647 * Initialisation of the shell objects
1648 */
1649static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
1650{
1651 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1652
1653 TRACE("\n");
1654
1655 /*
1656 * Initialisation of the FileOpenDialogInfos structure
1657 */
1658
1659 /* Shell */
1660
1661 /*ShellInfos */
1662 fodInfos->ShellInfos.hwndOwner = hwnd;
1663
1664 /* Disable multi-select if flag not set */
1665 if (!(fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT))
1666 {
1667 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_SINGLESEL;
1668 }
1669 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_AUTOARRANGE | FWF_ALIGNLEFT;
1670 fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
1671
1672 GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
1673 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
1674 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
1675
1676 /* Construct the IShellBrowser interface */
1677 fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
1678
1679 return NOERROR;
1680}
1681
1682/***********************************************************************
1683 * FILEDLG95_SHELL_ExecuteCommand
1684 *
1685 * Change the folder option and refresh the view
1686 * If the function succeeds, the return value is nonzero.
1687 */
1688static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
1689{
1690 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1691
1692 IContextMenu * pcm;
1693 TRACE("(0x%08x,%p)\n", hwnd, lpVerb);
1694
1695 if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
1696 SVGIO_BACKGROUND,
1697 &IID_IContextMenu,
1698 (LPVOID*)&pcm)))
1699 {
1700 CMINVOKECOMMANDINFO ci;
1701 ZeroMemory(&ci, sizeof(CMINVOKECOMMANDINFO));
1702 ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
1703 ci.lpVerb = lpVerb;
1704 ci.hwnd = hwnd;
1705
1706 IContextMenu_InvokeCommand(pcm, &ci);
1707 IContextMenu_Release(pcm);
1708 }
1709
1710 return FALSE;
1711}
1712
1713/***********************************************************************
1714 * FILEDLG95_SHELL_UpFolder
1715 *
1716 * Browse to the specified object
1717 * If the function succeeds, the return value is nonzero.
1718 */
1719static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
1720{
1721 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1722
1723 TRACE("\n");
1724
1725 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1726 NULL,
1727 SBSP_PARENT)))
1728 {
1729 return TRUE;
1730 }
1731 return FALSE;
1732}
1733
1734/***********************************************************************
1735 * FILEDLG95_SHELL_BrowseToDesktop
1736 *
1737 * Browse to the Desktop
1738 * If the function succeeds, the return value is nonzero.
1739 */
1740static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd)
1741{
1742 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1743 LPITEMIDLIST pidl;
1744 HRESULT hres;
1745
1746 TRACE("\n");
1747
1748 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidl);
1749 hres = IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidl, SBSP_ABSOLUTE);
1750 COMDLG32_SHFree(pidl);
1751 return SUCCEEDED(hres);
1752}
1753/***********************************************************************
1754 * FILEDLG95_SHELL_Clean
1755 *
1756 * Cleans the memory used by shell objects
1757 */
1758static void FILEDLG95_SHELL_Clean(HWND hwnd)
1759{
1760 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1761
1762 TRACE("\n");
1763
1764 COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent);
1765
1766 /* clean Shell interfaces */
1767 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
1768 IShellView_Release(fodInfos->Shell.FOIShellView);
1769 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
1770 IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
1771 if (fodInfos->Shell.FOIDataObject)
1772 IDataObject_Release(fodInfos->Shell.FOIDataObject);
1773}
1774
1775/***********************************************************************
1776 * FILEDLG95_FILETYPE_Init
1777 *
1778 * Initialisation of the file type combo box
1779 */
1780static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
1781{
1782 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1783
1784 TRACE("\n");
1785
1786 if(fodInfos->ofnInfos->lpstrFilter)
1787 {
1788 int nFilters = 0; /* number of filters */
1789 LPSTR lpstrFilter;
1790 LPCSTR lpstrPos = fodInfos->ofnInfos->lpstrFilter;
1791
1792 for(;;)
1793 {
1794 /* filter is a list... title\0ext\0......\0\0
1795 * Set the combo item text to the title and the item data
1796 * to the ext
1797 */
1798 LPCSTR lpstrDisplay;
1799 LPSTR lpstrExt;
1800
1801 /* Get the title */
1802 if(! *lpstrPos) break; /* end */
1803 lpstrDisplay = lpstrPos;
1804 lpstrPos += strlen(lpstrPos) + 1;
1805
1806 /* Copy the extensions */
1807 if (! *lpstrPos) return E_FAIL; /* malformed filter */
1808 if (!(lpstrExt = (LPSTR) MemAlloc(strlen(lpstrPos)+1))) return E_FAIL;
1809 strcpy(lpstrExt,lpstrPos);
1810 lpstrPos += strlen(lpstrPos) + 1;
1811
1812 /* Add the item at the end of the combo */
1813 CBAddString(fodInfos->DlgInfos.hwndFileTypeCB, lpstrDisplay);
1814 CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt);
1815 nFilters++;
1816 }
1817 /*
1818 * Set the current filter to the one specified
1819 * in the initialisation structure
1820 * FIXME: lpstrCustomFilter not handled at all
1821 */
1822
1823 /* set default filter index */
1824 if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->ofnInfos->lpstrCustomFilter == NULL)
1825 fodInfos->ofnInfos->nFilterIndex = 1;
1826
1827 /* First, check to make sure our index isn't out of bounds. */
1828 if ( fodInfos->ofnInfos->nFilterIndex > nFilters )
1829 fodInfos->ofnInfos->nFilterIndex = nFilters;
1830
1831 /* Set the current index selection. */
1832 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->ofnInfos->nFilterIndex-1);
1833
1834 /* Get the corresponding text string from the combo box. */
1835 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1836 fodInfos->ofnInfos->nFilterIndex-1);
1837
1838 if ((INT)lpstrFilter == CB_ERR) /* control is empty */
1839 lpstrFilter = NULL;
1840
1841 if(lpstrFilter)
1842 {
1843 DWORD len;
1844 _strlwr(lpstrFilter); /* lowercase */
1845 len = MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1, NULL, 0 );
1846 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
1847 MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1,
1848 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1849 }
1850 }
1851 return NOERROR;
1852}
1853
1854/***********************************************************************
1855 * FILEDLG95_FILETYPE_OnCommand
1856 *
1857 * WM_COMMAND of the file type combo box
1858 * If the function succeeds, the return value is nonzero.
1859 */
1860static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
1861{
1862 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1863
1864 switch(wNotifyCode)
1865 {
1866 case CBN_SELENDOK:
1867 {
1868 LPSTR lpstrFilter;
1869
1870 /* Get the current item of the filetype combo box */
1871 int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1872
1873 /* set the current filter index - indexed from 1 */
1874 fodInfos->ofnInfos->nFilterIndex = iItem + 1;
1875
1876 /* Set the current filter with the current selection */
1877 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1878 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1879
1880 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1881 iItem);
1882 if((int)lpstrFilter != CB_ERR)
1883 {
1884 DWORD len;
1885 _strlwr(lpstrFilter); /* lowercase */
1886 len = MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1, NULL, 0 );
1887 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
1888 MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1,
1889 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1890 SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
1891 }
1892
1893 /* Refresh the actual view to display the included items*/
1894 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1895 }
1896 }
1897 return FALSE;
1898}
1899/***********************************************************************
1900 * FILEDLG95_FILETYPE_SearchExt
1901 *
1902 * searches for a extension in the filetype box
1903 */
1904static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt)
1905{
1906 int i, iCount = CBGetCount(hwnd);
1907
1908 TRACE("%s\n", lpstrExt);
1909
1910 if(iCount != CB_ERR)
1911 {
1912 for(i=0;i<iCount;i++)
1913 {
1914 if(!strcasecmp(lpstrExt,(LPSTR)CBGetItemDataPtr(hwnd,i)))
1915 return i;
1916 }
1917 }
1918 return -1;
1919}
1920
1921/***********************************************************************
1922 * FILEDLG95_FILETYPE_Clean
1923 *
1924 * Clean the memory used by the filetype combo box
1925 */
1926static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
1927{
1928 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1929 int iPos;
1930 int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
1931
1932 TRACE("\n");
1933
1934 /* Delete each string of the combo and their associated data */
1935 if(iCount != CB_ERR)
1936 {
1937 for(iPos = iCount-1;iPos>=0;iPos--)
1938 {
1939 MemFree((LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos));
1940 CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1941 }
1942 }
1943 /* Current filter */
1944 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1945 MemFree(fodInfos->ShellInfos.lpstrCurrentFilter);
1946
1947}
1948
1949/***********************************************************************
1950 * FILEDLG95_LOOKIN_Init
1951 *
1952 * Initialisation of the look in combo box
1953 */
1954static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
1955{
1956 IShellFolder *psfRoot, *psfDrives;
1957 IEnumIDList *lpeRoot, *lpeDrives;
1958 LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
1959
1960 LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
1961
1962 TRACE("\n");
1963
1964 liInfos->iMaxIndentation = 0;
1965
1966 SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
1967
1968 /* set item height for both text field and listbox */
1969 CBSetItemHeight(hwndCombo,-1,GetSystemMetrics(SM_CYSMICON));
1970 CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
1971
1972 /* Initialise data of Desktop folder */
1973 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
1974 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1975 COMDLG32_SHFree(pidlTmp);
1976
1977 SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
1978
1979 SHGetDesktopFolder(&psfRoot);
1980
1981 if (psfRoot)
1982 {
1983 /* enumerate the contents of the desktop */
1984 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
1985 {
1986 while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
1987 {
1988 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1989
1990 /* special handling for CSIDL_DRIVES */
1991 if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
1992 {
1993 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
1994 {
1995 /* enumerate the drives */
1996 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
1997 {
1998 while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
1999 {
2000 pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
2001 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
2002 COMDLG32_SHFree(pidlAbsTmp);
2003 COMDLG32_SHFree(pidlTmp1);
2004 }
2005 IEnumIDList_Release(lpeDrives);
2006 }
2007 IShellFolder_Release(psfDrives);
2008 }
2009 }
2010 COMDLG32_SHFree(pidlTmp);
2011 }
2012 IEnumIDList_Release(lpeRoot);
2013 }
2014 }
2015
2016 IShellFolder_Release(psfRoot);
2017 COMDLG32_SHFree(pidlDrives);
2018 return NOERROR;
2019}
2020
2021/***********************************************************************
2022 * FILEDLG95_LOOKIN_DrawItem
2023 *
2024 * WM_DRAWITEM message handler
2025 */
2026static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
2027{
2028 COLORREF crWin = GetSysColor(COLOR_WINDOW);
2029 COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
2030 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
2031 RECT rectText;
2032 RECT rectIcon;
2033 SHFILEINFOA sfi;
2034 HIMAGELIST ilItemImage;
2035 int iIndentation;
2036 TEXTMETRICA tm;
2037 LPSFOLDER tmpFolder;
2038
2039
2040 LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
2041
2042 TRACE("\n");
2043
2044 if(pDIStruct->itemID == -1)
2045 return 0;
2046
2047 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
2048 pDIStruct->itemID)))
2049 return 0;
2050
2051
2052 if(pDIStruct->itemID == liInfos->uSelectedItem)
2053 {
2054 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2055 0,
2056 &sfi,
2057 sizeof (SHFILEINFOA),
2058 SHGFI_PIDL | SHGFI_SMALLICON |
2059 SHGFI_OPENICON | SHGFI_SYSICONINDEX |
2060 SHGFI_DISPLAYNAME );
2061 }
2062 else
2063 {
2064 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2065 0,
2066 &sfi,
2067 sizeof (SHFILEINFOA),
2068 SHGFI_PIDL | SHGFI_SMALLICON |
2069 SHGFI_SYSICONINDEX |
2070 SHGFI_DISPLAYNAME);
2071 }
2072
2073 /* Is this item selected ? */
2074 if(pDIStruct->itemState & ODS_SELECTED)
2075 {
2076 SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
2077 SetBkColor(pDIStruct->hDC,crHighLight);
2078 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight);
2079 }
2080 else
2081 {
2082 SetTextColor(pDIStruct->hDC,crText);
2083 SetBkColor(pDIStruct->hDC,crWin);
2084 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin);
2085 }
2086
2087 /* Do not indent item if drawing in the edit of the combo */
2088 if(pDIStruct->itemState & ODS_COMBOBOXEDIT)
2089 {
2090 iIndentation = 0;
2091 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2092 0,
2093 &sfi,
2094 sizeof (SHFILEINFOA),
2095 SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON
2096 | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME );
2097
2098 }
2099 else
2100 {
2101 iIndentation = tmpFolder->m_iIndent;
2102 }
2103 /* Draw text and icon */
2104
2105 /* Initialise the icon display area */
2106 rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
2107 rectIcon.top = pDIStruct->rcItem.top;
2108 rectIcon.right = rectIcon.left + ICONWIDTH;
2109 rectIcon.bottom = pDIStruct->rcItem.bottom;
2110
2111 /* Initialise the text display area */
2112 GetTextMetricsA(pDIStruct->hDC, &tm);
2113 rectText.left = rectIcon.right;
2114 rectText.top =
2115 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom - tm.tmHeight) / 2;
2116 rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
2117 rectText.bottom =
2118 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom + tm.tmHeight) / 2;
2119
2120 /* Draw the icon from the image list */
2121 ImageList_Draw(ilItemImage,
2122 sfi.iIcon,
2123 pDIStruct->hDC,
2124 rectIcon.left,
2125 rectIcon.top,
2126 ILD_TRANSPARENT );
2127
2128 /* Draw the associated text */
2129 if(sfi.szDisplayName)
2130 TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName));
2131
2132
2133 return NOERROR;
2134}
2135
2136/***********************************************************************
2137 * FILEDLG95_LOOKIN_OnCommand
2138 *
2139 * LookIn combo box WM_COMMAND message handler
2140 * If the function succeeds, the return value is nonzero.
2141 */
2142static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
2143{
2144 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2145
2146 TRACE("%p\n", fodInfos);
2147
2148 switch(wNotifyCode)
2149 {
2150 case CBN_SELENDOK:
2151 {
2152 LPSFOLDER tmpFolder;
2153 int iItem;
2154
2155 iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
2156
2157 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
2158 iItem)))
2159 return FALSE;
2160
2161
2162 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
2163 tmpFolder->pidlItem,
2164 SBSP_ABSOLUTE)))
2165 {
2166 return TRUE;
2167 }
2168 break;
2169 }
2170
2171 }
2172 return FALSE;
2173}
2174
2175/***********************************************************************
2176 * FILEDLG95_LOOKIN_AddItem
2177 *
2178 * Adds an absolute pidl item to the lookin combo box
2179 * returns the index of the inserted item
2180 */
2181static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
2182{
2183 LPITEMIDLIST pidlNext;
2184 SHFILEINFOA sfi;
2185 SFOLDER *tmpFolder;
2186 LookInInfos *liInfos;
2187
2188 TRACE("%08x\n", iInsertId);
2189
2190 if(!pidl)
2191 return -1;
2192
2193 if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
2194 return -1;
2195
2196 tmpFolder = MemAlloc(sizeof(SFOLDER));
2197 tmpFolder->m_iIndent = 0;
2198
2199 /* Calculate the indentation of the item in the lookin*/
2200 pidlNext = pidl;
2201 while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
2202 {
2203 tmpFolder->m_iIndent++;
2204 }
2205
2206 tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl); /* FIXME: memory leak*/
2207
2208 if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
2209 liInfos->iMaxIndentation = tmpFolder->m_iIndent;
2210
2211 sfi.dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM;
2212 SHGetFileInfoA((LPSTR)pidl,
2213 0,
2214 &sfi,
2215 sizeof(sfi),
2216 SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX
2217 | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED);
2218
2219 TRACE("-- Add %s attr=%08lx\n", sfi.szDisplayName, sfi.dwAttributes);
2220
2221 if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
2222 {
2223 int iItemID;
2224
2225 TRACE("-- Add %s at %u\n", sfi.szDisplayName, tmpFolder->m_iIndent);
2226
2227 /* Add the item at the end of the list */
2228 if(iInsertId < 0)
2229 {
2230 iItemID = CBAddString(hwnd,sfi.szDisplayName);
2231 }
2232 /* Insert the item at the iInsertId position*/
2233 else
2234 {
2235 iItemID = CBInsertString(hwnd,sfi.szDisplayName,iInsertId);
2236 }
2237
2238 CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
2239 return iItemID;
2240 }
2241
2242 MemFree( tmpFolder );
2243 return -1;
2244
2245}
2246
2247/***********************************************************************
2248 * FILEDLG95_LOOKIN_InsertItemAfterParent
2249 *
2250 * Insert an item below its parent
2251 */
2252static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
2253{
2254
2255 LPITEMIDLIST pidlParent = GetParentPidl(pidl);
2256 int iParentPos;
2257
2258 TRACE("\n");
2259
2260 iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
2261
2262 if(iParentPos < 0)
2263 {
2264 iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
2265 }
2266
2267 /* Free pidlParent memory */
2268 COMDLG32_SHFree((LPVOID)pidlParent);
2269
2270 return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
2271}
2272
2273/***********************************************************************
2274 * FILEDLG95_LOOKIN_SelectItem
2275 *
2276 * Adds an absolute pidl item to the lookin combo box
2277 * returns the index of the inserted item
2278 */
2279int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
2280{
2281 int iItemPos;
2282 LookInInfos *liInfos;
2283
2284 TRACE("\n");
2285
2286 iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
2287
2288 liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2289
2290 if(iItemPos < 0)
2291 {
2292 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
2293 iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
2294 }
2295
2296 else
2297 {
2298 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2299 while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
2300 {
2301 int iRemovedItem;
2302
2303 if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
2304 break;
2305 if(iRemovedItem < iItemPos)
2306 iItemPos--;
2307 }
2308 }
2309
2310 CBSetCurSel(hwnd,iItemPos);
2311 liInfos->uSelectedItem = iItemPos;
2312
2313 return 0;
2314
2315}
2316
2317/***********************************************************************
2318 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2319 *
2320 * Remove the item with an expansion level over iExpansionLevel
2321 */
2322static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
2323{
2324 int iItemPos;
2325
2326 LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2327
2328 TRACE("\n");
2329
2330 if(liInfos->iMaxIndentation <= 2)
2331 return -1;
2332
2333 if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
2334 {
2335 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2336 COMDLG32_SHFree(tmpFolder->pidlItem);
2337 MemFree(tmpFolder);
2338 CBDeleteString(hwnd,iItemPos);
2339 liInfos->iMaxIndentation--;
2340
2341 return iItemPos;
2342 }
2343
2344 return -1;
2345}
2346
2347/***********************************************************************
2348 * FILEDLG95_LOOKIN_SearchItem
2349 *
2350 * Search for pidl in the lookin combo box
2351 * returns the index of the found item
2352 */
2353static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
2354{
2355 int i = 0;
2356 int iCount = CBGetCount(hwnd);
2357
2358 TRACE("0x%08x 0x%x\n",searchArg, iSearchMethod);
2359
2360 if (iCount != CB_ERR)
2361 {
2362 for(;i<iCount;i++)
2363 {
2364 LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
2365
2366 if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
2367 return i;
2368 if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
2369 return i;
2370 }
2371 }
2372
2373 return -1;
2374}
2375
2376/***********************************************************************
2377 * FILEDLG95_LOOKIN_Clean
2378 *
2379 * Clean the memory used by the lookin combo box
2380 */
2381static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
2382{
2383 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2384 int iPos;
2385 int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
2386
2387 TRACE("\n");
2388
2389 /* Delete each string of the combo and their associated data */
2390 if (iCount != CB_ERR)
2391 {
2392 for(iPos = iCount-1;iPos>=0;iPos--)
2393 {
2394 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos);
2395 COMDLG32_SHFree(tmpFolder->pidlItem);
2396 MemFree(tmpFolder);
2397 CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
2398 }
2399 }
2400
2401 /* LookInInfos structure */
2402 RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
2403
2404}
2405/***********************************************************************
2406 * FILEDLG95_FILENAME_FillFromSelection
2407 *
2408 * fills the edit box from the cached DataObject
2409 */
2410void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd)
2411{
2412 FileOpenDlgInfos *fodInfos;
2413 LPITEMIDLIST pidl;
2414 UINT nFiles = 0, nFileToOpen, nFileSelected, nLength = 0;
2415 char lpstrTemp[MAX_PATH];
2416 LPSTR lpstrAllFile = NULL, lpstrCurrFile = NULL;
2417
2418 TRACE("\n");
2419 fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2420
2421 /* Count how many files we have */
2422 nFileSelected = GetNumSelected( fodInfos->Shell.FOIDataObject );
2423
2424 /* calculate the string length, count files */
2425 if (nFileSelected >= 1)
2426 {
2427 nLength += 3; /* first and last quotes, trailing \0 */
2428 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2429 {
2430 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2431
2432 if (pidl)
2433 {
2434 /* get the total length of the selected file names*/
2435 lpstrTemp[0] = '\0';
2436 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2437
2438 if ( ! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl) ) /* Ignore folders */
2439 {
2440 nLength += strlen( lpstrTemp ) + 3;
2441 nFiles++;
2442 }
2443 COMDLG32_SHFree( pidl );
2444 }
2445 }
2446 }
2447
2448 /* allocate the buffer */
2449 if (nFiles <= 1) nLength = MAX_PATH;
2450 lpstrAllFile = (LPSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength);
2451 lpstrAllFile[0] = '\0';
2452
2453 /* Generate the string for the edit control */
2454 if(nFiles >= 1)
2455 {
2456 lpstrCurrFile = lpstrAllFile;
2457 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2458 {
2459 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2460
2461 if (pidl)
2462 {
2463 /* get the file name */
2464 lpstrTemp[0] = '\0';
2465 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2466
2467 if (! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl)) /* Ignore folders */
2468 {
2469 if ( nFiles > 1)
2470 {
2471 *lpstrCurrFile++ = '\"';
2472 strcpy( lpstrCurrFile, lpstrTemp );
2473 lpstrCurrFile += strlen( lpstrTemp );
2474 strcpy( lpstrCurrFile, "\" " );
2475 lpstrCurrFile += 2;
2476 }
2477 else
2478 {
2479 strcpy( lpstrAllFile, lpstrTemp );
2480 }
2481 }
2482 COMDLG32_SHFree( (LPVOID) pidl );
2483 }
2484 }
2485 }
2486#ifdef __WIN32OS2__
2487 //Selecting a directory previously erased the last selected file
2488 if(nFiles) {
2489 SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile );
2490 }
2491#else
2492 SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile );
2493#endif
2494 HeapFree(GetProcessHeap(),0, lpstrAllFile );
2495}
2496
2497
2498/* copied from shell32 to avoid linking to it */
2499static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
2500{
2501 switch (src->uType)
2502 {
2503 case STRRET_WSTR:
2504 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL);
2505 COMDLG32_SHFree(src->u.pOleStr);
2506 break;
2507
2508 case STRRET_CSTRA:
2509 lstrcpynA((LPSTR)dest, src->u.cStr, len);
2510 break;
2511
2512 case STRRET_OFFSETA:
2513 lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
2514 break;
2515
2516 default:
2517 FIXME("unknown type!\n");
2518 if (len)
2519 {
2520 *(LPSTR)dest = '\0';
2521 }
2522 return(FALSE);
2523 }
2524 return S_OK;
2525}
2526
2527/***********************************************************************
2528 * FILEDLG95_FILENAME_GetFileNames
2529 *
2530 * copies the filenames to a 0-delimited string list (A\0B\0C\0\0)
2531 */
2532int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPSTR * lpstrFileList, UINT * sizeUsed)
2533{
2534 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2535 UINT nStrCharCount = 0; /* index in src buffer */
2536 UINT nFileIndex = 0; /* index in dest buffer */
2537 UINT nFileCount = 0; /* number of files */
2538 UINT nStrLen = 0; /* length of string in edit control */
2539 LPSTR lpstrEdit; /* buffer for string from edit control */
2540
2541 TRACE("\n");
2542
2543 /* get the filenames from the edit control */
2544 nStrLen = SendMessageA(fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0);
2545 lpstrEdit = MemAlloc(nStrLen+1);
2546 GetDlgItemTextA(hwnd, IDC_FILENAME, lpstrEdit, nStrLen+1);
2547
2548 TRACE("nStrLen=%u str=%s\n", nStrLen, lpstrEdit);
2549
2550 /* we might get single filename without any '"',
2551 * so we need nStrLen + terminating \0 + end-of-list \0 */
2552 *lpstrFileList = MemAlloc(nStrLen+2);
2553 *sizeUsed = 0;
2554
2555 /* build 0-delimited file list from filenames */
2556 while ( nStrCharCount <= nStrLen )
2557 {
2558 if ( lpstrEdit[nStrCharCount]=='"' )
2559 {
2560 nStrCharCount++;
2561 while ((lpstrEdit[nStrCharCount]!='"') && (nStrCharCount <= nStrLen))
2562 {
2563 (*lpstrFileList)[nFileIndex++] = lpstrEdit[nStrCharCount];
2564 (*sizeUsed)++;
2565 nStrCharCount++;
2566 }
2567 (*lpstrFileList)[nFileIndex++] = '\0';
2568 (*sizeUsed)++;
2569 nFileCount++;
2570 }
2571 nStrCharCount++;
2572 }
2573
2574 /* single, unquoted string */
2575 if ((nStrLen > 0) && (*sizeUsed == 0) )
2576 {
2577 strcpy(*lpstrFileList, lpstrEdit);
2578 nFileIndex = strlen(lpstrEdit) + 1;
2579 (*sizeUsed) = nFileIndex;
2580 nFileCount = 1;
2581 }
2582
2583 /* trailing \0 */
2584 (*lpstrFileList)[nFileIndex] = '\0';
2585 (*sizeUsed)++;
2586
2587 MemFree(lpstrEdit);
2588 return nFileCount;
2589}
2590
2591#define SETDefFormatEtc(fe,cf,med) \
2592{ \
2593 (fe).cfFormat = cf;\
2594 (fe).dwAspect = DVASPECT_CONTENT; \
2595 (fe).ptd =NULL;\
2596 (fe).tymed = med;\
2597 (fe).lindex = -1;\
2598};
2599
2600/*
2601 * DATAOBJECT Helper functions
2602 */
2603
2604/***********************************************************************
2605 * COMCTL32_ReleaseStgMedium
2606 *
2607 * like ReleaseStgMedium from ole32
2608 */
2609static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium)
2610{
2611 if(medium.pUnkForRelease)
2612 {
2613 IUnknown_Release(medium.pUnkForRelease);
2614 }
2615 else
2616 {
2617 GlobalUnlock(medium.u.hGlobal);
2618 GlobalFree(medium.u.hGlobal);
2619 }
2620}
2621
2622/***********************************************************************
2623 * GetPidlFromDataObject
2624 *
2625 * Return pidl(s) by number from the cached DataObject
2626 *
2627 * nPidlIndex=0 gets the fully qualified root path
2628 */
2629LPITEMIDLIST GetPidlFromDataObject ( IDataObject *doSelected, UINT nPidlIndex)
2630{
2631
2632 STGMEDIUM medium;
2633 FORMATETC formatetc;
2634 LPITEMIDLIST pidl = NULL;
2635
2636 TRACE("sv=%p index=%u\n", doSelected, nPidlIndex);
2637
2638 /* Set the FORMATETC structure*/
2639 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2640
2641 /* Get the pidls from IDataObject */
2642 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2643 {
2644 LPIDA cida = GlobalLock(medium.u.hGlobal);
2645 if(nPidlIndex <= cida->cidl)
2646 {
2647 pidl = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[nPidlIndex]]));
2648 }
2649 COMCTL32_ReleaseStgMedium(medium);
2650 }
2651 return pidl;
2652}
2653
2654/***********************************************************************
2655 * GetNumSelected
2656 *
2657 * Return the number of selected items in the DataObject.
2658 *
2659*/
2660UINT GetNumSelected( IDataObject *doSelected )
2661{
2662 UINT retVal = 0;
2663 STGMEDIUM medium;
2664 FORMATETC formatetc;
2665
2666 TRACE("sv=%p\n", doSelected);
2667
2668 if (!doSelected) return 0;
2669
2670 /* Set the FORMATETC structure*/
2671 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2672
2673 /* Get the pidls from IDataObject */
2674 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2675 {
2676 LPIDA cida = GlobalLock(medium.u.hGlobal);
2677 retVal = cida->cidl;
2678 COMCTL32_ReleaseStgMedium(medium);
2679 return retVal;
2680 }
2681 return 0;
2682}
2683
2684/*
2685 * TOOLS
2686 */
2687
2688/***********************************************************************
2689 * GetName
2690 *
2691 * Get the pidl's display name (relative to folder) and
2692 * put it in lpstrFileName.
2693 *
2694 * Return NOERROR on success,
2695 * E_FAIL otherwise
2696 */
2697
2698HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
2699{
2700 STRRET str;
2701 HRESULT hRes;
2702
2703 TRACE("sf=%p pidl=%p\n", lpsf, pidl);
2704
2705 if(!lpsf)
2706 {
2707 HRESULT hRes;
2708 SHGetDesktopFolder(&lpsf);
2709 hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
2710 IShellFolder_Release(lpsf);
2711 return hRes;
2712 }
2713
2714 /* Get the display name of the pidl relative to the folder */
2715 if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf, pidl, dwFlags, &str)))
2716 {
2717 return COMDLG32_StrRetToStrNA(lpstrFileName, MAX_PATH, &str, pidl);
2718 }
2719 return E_FAIL;
2720}
2721
2722/***********************************************************************
2723 * GetShellFolderFromPidl
2724 *
2725 * pidlRel is the item pidl relative
2726 * Return the IShellFolder of the absolute pidl
2727 */
2728IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
2729{
2730 IShellFolder *psf = NULL,*psfParent;
2731
2732 TRACE("%p\n", pidlAbs);
2733
2734 if(SUCCEEDED(SHGetDesktopFolder(&psfParent)))
2735 {
2736 psf = psfParent;
2737 if(pidlAbs && pidlAbs->mkid.cb)
2738 {
2739 if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
2740 {
2741 IShellFolder_Release(psfParent);
2742 return psf;
2743 }
2744 }
2745 /* return the desktop */
2746 return psfParent;
2747 }
2748 return NULL;
2749}
2750
2751/***********************************************************************
2752 * GetParentPidl
2753 *
2754 * Return the LPITEMIDLIST to the parent of the pidl in the list
2755 */
2756LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
2757{
2758 LPITEMIDLIST pidlParent;
2759
2760 TRACE("%p\n", pidl);
2761
2762 pidlParent = COMDLG32_PIDL_ILClone(pidl);
2763 COMDLG32_PIDL_ILRemoveLastID(pidlParent);
2764
2765 return pidlParent;
2766}
2767
2768/***********************************************************************
2769 * GetPidlFromName
2770 *
2771 * returns the pidl of the file name relative to folder
2772 * NULL if an error occurred
2773 */
2774LPITEMIDLIST GetPidlFromName(IShellFolder *lpsf,LPCSTR lpcstrFileName)
2775{
2776 LPITEMIDLIST pidl;
2777 ULONG ulEaten;
2778 WCHAR lpwstrDirName[MAX_PATH];
2779
2780 TRACE("sf=%p file=%s\n", lpsf, lpcstrFileName);
2781
2782 if(!lpcstrFileName) return NULL;
2783 if(!*lpcstrFileName) return NULL;
2784
2785 MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,lpcstrFileName,-1,(LPWSTR)lpwstrDirName,MAX_PATH);
2786
2787 if(!lpsf)
2788 {
2789 SHGetDesktopFolder(&lpsf);
2790 pidl = GetPidlFromName(lpsf, lpcstrFileName);
2791 IShellFolder_Release(lpsf);
2792 }
2793 else
2794 {
2795 IShellFolder_ParseDisplayName(lpsf, 0, NULL, (LPWSTR)lpwstrDirName, &ulEaten, &pidl, NULL);
2796 }
2797 return pidl;
2798}
2799
2800/*
2801*/
2802BOOL IsPidlFolder (LPSHELLFOLDER psf, LPITEMIDLIST pidl)
2803{
2804 ULONG uAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
2805 HRESULT ret;
2806
2807 TRACE("%p, %p\n", psf, pidl);
2808
2809 ret = IShellFolder_GetAttributesOf( psf, 1, &pidl, &uAttr );
2810
2811 TRACE("-- 0x%08lx 0x%08lx\n", uAttr, ret);
2812 /* see documentation shell 4.1*/
2813 return uAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER);
2814}
2815
2816/***********************************************************************
2817 * BrowseSelectedFolder
2818 */
2819static BOOL BrowseSelectedFolder(HWND hwnd)
2820{
2821 BOOL bBrowseSelFolder = FALSE;
2822 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2823
2824 TRACE("\n");
2825
2826 if (GetNumSelected(fodInfos->Shell.FOIDataObject) == 1)
2827 {
2828 LPITEMIDLIST pidlSelection;
2829
2830 /* get the file selected */
2831 pidlSelection = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, 1);
2832 if (IsPidlFolder (fodInfos->Shell.FOIShellFolder, pidlSelection))
2833 {
2834 if ( FAILED( IShellBrowser_BrowseObject( fodInfos->Shell.FOIShellBrowser,
2835 pidlSelection, SBSP_RELATIVE ) ) )
2836 {
2837 MessageBoxA( hwnd, "Path does not exist", fodInfos->ofnInfos->lpstrTitle,
2838 MB_OK | MB_ICONEXCLAMATION );
2839 }
2840
2841 bBrowseSelFolder = TRUE;
2842 }
2843 COMDLG32_SHFree( pidlSelection );
2844 }
2845
2846 return bBrowseSelFolder;
2847}
2848
2849/*
2850 * Memory allocation methods */
2851static void *MemAlloc(UINT size)
2852{
2853 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
2854}
2855
2856static void MemFree(void *mem)
2857{
2858 if(mem)
2859 {
2860 HeapFree(GetProcessHeap(),0,mem);
2861 }
2862}
2863
Note: See TracBrowser for help on using the repository browser.