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

Last change on this file since 8266 was 7137, checked in by phaller, 24 years ago

fix crash in CDN_FILEOK

File size: 85.0 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#ifndef __WIN32OS2__
1145 if(FILEDLG95_OnOpen(hwnd))
1146 SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK);
1147 break;
1148#else
1149 {
1150 // 20011017 PH
1151 // some apps require the resources to be still there
1152 // for the CDN_ processing.
1153 BOOL fResult = FILEDLG95_OnOpen(hwnd);
1154 if(fResult)
1155 SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK);
1156
1157 FILEDLG95_Clean(hwnd);
1158 EndDialog(hwnd, fResult);
1159 break;
1160 }
1161#endif
1162 /* Cancel button */
1163 case IDCANCEL:
1164 FILEDLG95_Clean(hwnd);
1165 EndDialog(hwnd, FALSE);
1166 break;
1167 /* Filetype combo box */
1168 case IDC_FILETYPE:
1169 FILEDLG95_FILETYPE_OnCommand(hwnd,wNotifyCode);
1170 break;
1171 /* LookIn combo box */
1172 case IDC_LOOKIN:
1173 FILEDLG95_LOOKIN_OnCommand(hwnd,wNotifyCode);
1174 break;
1175
1176 /* --- toolbar --- */
1177 /* Up folder button */
1178 case FCIDM_TB_UPFOLDER:
1179 FILEDLG95_SHELL_UpFolder(hwnd);
1180 break;
1181 /* New folder button */
1182 case FCIDM_TB_NEWFOLDER:
1183 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_NEWFOLDER);
1184 break;
1185 /* List option button */
1186 case FCIDM_TB_SMALLICON:
1187 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWLIST);
1188 break;
1189 /* Details option button */
1190 case FCIDM_TB_REPORTVIEW:
1191 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWDETAILS);
1192 break;
1193 /* Details option button */
1194 case FCIDM_TB_DESKTOP:
1195 FILEDLG95_SHELL_BrowseToDesktop(hwnd);
1196 break;
1197
1198 case IDC_FILENAME:
1199 break;
1200
1201 }
1202 /* Do not use the listview selection anymore */
1203 fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
1204 return 0;
1205}
1206
1207/***********************************************************************
1208 * FILEDLG95_OnWMGetIShellBrowser
1209 *
1210 * WM_GETISHELLBROWSER message handler
1211 */
1212static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd)
1213{
1214
1215 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1216
1217 TRACE("\n");
1218
1219 SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)fodInfos->Shell.FOIShellBrowser);
1220
1221 return TRUE;
1222}
1223
1224
1225/***********************************************************************
1226 * FILEDLG95_OnOpenMultipleFiles
1227 *
1228 * Handles the opening of multiple files.
1229 *
1230 * FIXME
1231 * check destination buffer size
1232 */
1233BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed)
1234{
1235 CHAR lpstrPathSpec[MAX_PATH] = "";
1236 LPSTR lpstrFile;
1237 UINT nCount, nSizePath;
1238 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1239
1240 TRACE("\n");
1241
1242 lpstrFile = fodInfos->ofnInfos->lpstrFile;
1243 lpstrFile[0] = '\0';
1244
1245 SHGetPathFromIDListA( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec );
1246
1247 if ( !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE) &&
1248 ( fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST))
1249 {
1250 LPSTR lpstrTemp = lpstrFileList;
1251
1252 for ( nCount = 0; nCount < nFileCount; nCount++ )
1253 {
1254 LPITEMIDLIST pidl;
1255
1256 pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder, lpstrTemp);
1257 if (!pidl)
1258 {
1259 CHAR lpstrNotFound[100];
1260 CHAR lpstrMsg[100];
1261 CHAR tmp[400];
1262
1263 LoadStringA(COMMDLG_hInstance32, IDS_FILENOTFOUND, lpstrNotFound, 100);
1264 LoadStringA(COMMDLG_hInstance32, IDS_VERIFYFILE, lpstrMsg, 100);
1265
1266 strcpy(tmp, lpstrTemp);
1267 strcat(tmp, "\n");
1268 strcat(tmp, lpstrNotFound);
1269 strcat(tmp, "\n");
1270 strcat(tmp, lpstrMsg);
1271
1272 MessageBoxA(hwnd, tmp, fodInfos->ofnInfos->lpstrTitle, MB_OK | MB_ICONEXCLAMATION);
1273 return FALSE;
1274 }
1275
1276 /* move to the next file in the list of files */
1277 lpstrTemp += strlen(lpstrTemp) + 1;
1278 COMDLG32_SHFree(pidl);
1279 }
1280 }
1281
1282 nSizePath = strlen(lpstrPathSpec);
1283 strcpy( lpstrFile, lpstrPathSpec);
1284 memcpy( lpstrFile + nSizePath + 1, lpstrFileList, sizeUsed );
1285
1286 fodInfos->ofnInfos->nFileOffset = nSizePath + 1;
1287 fodInfos->ofnInfos->nFileExtension = 0;
1288
1289 /* clean and exit */
1290#ifndef __WIN32OS2__
1291 // 20011017 PH
1292 // some apps require the resources to be still there
1293 // for the CDN_ processing.
1294 FILEDLG95_Clean(hwnd);
1295 return EndDialog(hwnd,TRUE);
1296#else
1297 return TRUE;
1298#endif
1299}
1300
1301/***********************************************************************
1302 * FILEDLG95_OnOpen
1303 *
1304 * Ok button WM_COMMAND message handler
1305 *
1306 * If the function succeeds, the return value is nonzero.
1307 */
1308#define ONOPEN_BROWSE 1
1309#define ONOPEN_OPEN 2
1310#define ONOPEN_SEARCH 3
1311static void FILEDLG95_OnOpenMessage(HWND hwnd, int idCaption, int idText)
1312{
1313 char strMsgTitle[MAX_PATH];
1314 char strMsgText [MAX_PATH];
1315 if (idCaption)
1316 LoadStringA(COMDLG32_hInstance, idCaption, strMsgTitle, sizeof(strMsgTitle));
1317 else
1318 strMsgTitle[0] = '\0';
1319 LoadStringA(COMDLG32_hInstance, idText, strMsgText, sizeof(strMsgText));
1320 MessageBoxA(hwnd,strMsgText, strMsgTitle, MB_OK | MB_ICONHAND);
1321}
1322
1323BOOL FILEDLG95_OnOpen(HWND hwnd)
1324{
1325 char * lpstrFileList;
1326 UINT nFileCount = 0;
1327 UINT sizeUsed = 0;
1328 BOOL ret = TRUE;
1329 char lpstrPathAndFile[MAX_PATH];
1330 char lpstrTemp[MAX_PATH];
1331 LPSHELLFOLDER lpsf = NULL;
1332 int nOpenAction;
1333 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1334
1335 TRACE("hwnd=0x%04x\n", hwnd);
1336
1337 /* get the files from the edit control */
1338 nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed);
1339
1340 /* try if the user selected a folder in the shellview */
1341 if(nFileCount == 0)
1342 {
1343 BrowseSelectedFolder(hwnd);
1344 return FALSE;
1345 }
1346
1347 if(nFileCount > 1)
1348 {
1349 ret = FILEDLG95_OnOpenMultipleFiles(hwnd, lpstrFileList, nFileCount, sizeUsed);
1350 goto ret;
1351 }
1352
1353 TRACE("count=%u len=%u file=%s\n", nFileCount, sizeUsed, lpstrFileList);
1354
1355/*
1356 Step 1: Build a complete path name from the current folder and
1357 the filename or path in the edit box.
1358 Special cases:
1359 - the path in the edit box is a root path
1360 (with or without drive letter)
1361 - the edit box contains ".." (or a path with ".." in it)
1362*/
1363
1364 /* Get the current directory name */
1365 if (!SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathAndFile))
1366 {
1367 /* we are in a special folder, default to desktop */
1368 if(FAILED(COMDLG32_SHGetFolderPathA(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, 0, 0, lpstrPathAndFile)))
1369 {
1370 /* last fallback */
1371 GetCurrentDirectoryA(MAX_PATH, lpstrPathAndFile);
1372 }
1373 }
1374 PathAddBackslashA(lpstrPathAndFile);
1375
1376 TRACE("current directory=%s\n", lpstrPathAndFile);
1377
1378 /* if the user specifyed a fully qualified path use it */
1379 if(PathIsRelativeA(lpstrFileList))
1380 {
1381 strcat(lpstrPathAndFile, lpstrFileList);
1382 }
1383 else
1384 {
1385 /* does the path have a drive letter? */
1386 if (PathGetDriveNumberA(lpstrFileList) == -1)
1387 strcpy(lpstrPathAndFile+2, lpstrFileList);
1388 else
1389 strcpy(lpstrPathAndFile, lpstrFileList);
1390 }
1391
1392 /* resolve "." and ".." */
1393 PathCanonicalizeA(lpstrTemp, lpstrPathAndFile );
1394 strcpy(lpstrPathAndFile, lpstrTemp);
1395 TRACE("canon=%s\n", lpstrPathAndFile);
1396
1397 MemFree(lpstrFileList);
1398
1399/*
1400 Step 2: here we have a cleaned up path
1401
1402 We have to parse the path step by step to see if we have to browse
1403 to a folder if the path points to a directory or the last
1404 valid element is a directory.
1405
1406 valid variables:
1407 lpstrPathAndFile: cleaned up path
1408 */
1409
1410 nOpenAction = ONOPEN_BROWSE;
1411
1412#ifdef __WIN32OS2__
1413 /* @@@AH 2001-06-02 moved out of !OFN_NONVALIDATE block - needs to be set */
1414 if (FAILED (SHGetDesktopFolder(&lpsf))) return FALSE;
1415#endif
1416
1417 /* dont apply any checks with OFN_NOVALIDATE */
1418 if(!(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE))
1419 {
1420 LPSTR lpszTemp, lpszTemp1;
1421 LPITEMIDLIST pidl = NULL;
1422
1423 /* check for invalid chars */
1424 if(strpbrk(lpstrPathAndFile+3, "/:<>|") != NULL)
1425 {
1426 FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_FILENAME);
1427 ret = FALSE;
1428 goto ret;
1429 }
1430#ifndef __WIN32OS2__
1431 if (FAILED (SHGetDesktopFolder(&lpsf))) return FALSE;
1432#endif
1433 lpszTemp1 = lpszTemp = lpstrPathAndFile;
1434 while (lpszTemp1)
1435 {
1436 LPSHELLFOLDER lpsfChild;
1437 WCHAR lpwstrTemp[MAX_PATH];
1438 DWORD dwEaten, dwAttributes;
1439
1440 lpszTemp = PathFindNextComponentA(lpszTemp);
1441
1442 if (!lpszTemp) break; /* end of path */
1443
1444 if(*lpszTemp)
1445 {
1446 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpszTemp1, lpszTemp - lpszTemp1,
1447 lpwstrTemp, MAX_PATH );
1448 lpwstrTemp[len] = 0;
1449 }
1450 else
1451 {
1452 MultiByteToWideChar( CP_ACP, 0, lpszTemp1, -1,
1453 lpwstrTemp, sizeof(lpwstrTemp)/sizeof(WCHAR) );
1454
1455 /* if the last element is a wildcard do a search */
1456 if(strpbrk(lpszTemp1, "*?") != NULL)
1457 {
1458 nOpenAction = ONOPEN_SEARCH;
1459 break;
1460 }
1461 }
1462 lpszTemp1 = lpszTemp;
1463
1464 TRACE("parse now=%s next=%s sf=%p\n",debugstr_w(lpwstrTemp), debugstr_a(lpszTemp), lpsf);
1465
1466 if(lstrlenW(lpwstrTemp)==2) PathAddBackslashW(lpwstrTemp);
1467
1468 dwAttributes = SFGAO_FOLDER;
1469 if(SUCCEEDED(IShellFolder_ParseDisplayName(lpsf, hwnd, NULL, lpwstrTemp, &dwEaten, &pidl, &dwAttributes)))
1470 {
1471 /* the path component is valid, we have a pidl of the next path component */
1472 TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes, pidl);
1473 if(dwAttributes & SFGAO_FOLDER)
1474 {
1475 if(FAILED(IShellFolder_BindToObject(lpsf, pidl, 0, &IID_IShellFolder, (LPVOID*)&lpsfChild)))
1476 {
1477 ERR("bind to failed\n"); /* should not fail */
1478 break;
1479 }
1480 IShellFolder_Release(lpsf);
1481 lpsf = lpsfChild;
1482 lpsfChild = NULL;
1483 }
1484 else
1485 {
1486 TRACE("value\n");
1487
1488 /* end dialog, return value */
1489 nOpenAction = ONOPEN_OPEN;
1490 break;
1491 }
1492 COMDLG32_SHFree(pidl);
1493 pidl = NULL;
1494 }
1495 else
1496 {
1497 if(*lpszTemp) /* points to trailing null for last path element */
1498 {
1499 if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
1500 {
1501 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_PATHNOTEXISTING);
1502 break;
1503 }
1504 }
1505 else
1506 {
1507 if(fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST)
1508 {
1509 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_FILENOTEXISTING);
1510 break;
1511 }
1512 }
1513 /* change to the current folder */
1514 nOpenAction = ONOPEN_OPEN;
1515 break;
1516 }
1517 }
1518 if(pidl) COMDLG32_SHFree(pidl);
1519 }
1520#ifdef __WIN32OS2__
1521 else
1522 {
1523 // @@@AH 2001-06-02 when we are in OFN_NOVALIDATE mode, the action
1524 // must be to open the specified file when pressing open button
1525 TRACE("OFN_NOVALIDATE mode, set open action to ONOPEN_OPEN\n");
1526 nOpenAction = ONOPEN_OPEN;
1527 }
1528#endif
1529
1530/*
1531 Step 3: here we have a cleaned up and validated path
1532
1533 valid variables:
1534 lpsf: ShellFolder bound to the rightmost valid path component
1535 lpstrPathAndFile: cleaned up path
1536 nOpenAction: action to do
1537*/
1538 TRACE("end validate sf=%p\n", lpsf);
1539
1540 switch(nOpenAction)
1541 {
1542 case ONOPEN_SEARCH: /* set the current filter to the file mask and refresh */
1543 TRACE("ONOPEN_SEARCH %s\n", lpstrPathAndFile);
1544 {
1545 int iPos;
1546 LPSTR lpszTemp = PathFindFileNameA(lpstrPathAndFile);
1547 DWORD len;
1548
1549 /* replace the current filter */
1550 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1551 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1552 len = MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1, NULL, 0 );
1553 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc(len * sizeof(WCHAR));
1554 MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1,
1555 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1556
1557 /* set the filter cb to the extension when possible */
1558 if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB, lpszTemp)))
1559 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, iPos);
1560 }
1561 /* fall through */
1562 case ONOPEN_BROWSE: /* browse to the highest folder we could bind to */
1563 TRACE("ONOPEN_BROWSE\n");
1564 {
1565 IPersistFolder2 * ppf2;
1566 if(SUCCEEDED(IShellFolder_QueryInterface( lpsf, &IID_IPersistFolder2, (LPVOID*)&ppf2)))
1567 {
1568 LPITEMIDLIST pidlCurrent;
1569 IPersistFolder2_GetCurFolder(ppf2, &pidlCurrent);
1570 IPersistFolder2_Release(ppf2);
1571 if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent, fodInfos->ShellInfos.pidlAbsCurrent))
1572 {
1573 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE);
1574 }
1575 else if( nOpenAction == ONOPEN_SEARCH )
1576 {
1577 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1578 }
1579 COMDLG32_SHFree(pidlCurrent);
1580 }
1581 }
1582 ret = FALSE;
1583 break;
1584 case ONOPEN_OPEN: /* fill in the return struct and close the dialog */
1585 TRACE("ONOPEN_OPEN %s\n", lpstrPathAndFile);
1586 {
1587 /* add default extension */
1588 if (fodInfos->ofnInfos->lpstrDefExt)
1589 {
1590 if (! *PathFindExtensionA(lpstrPathAndFile))
1591 {
1592 /* only add "." in case a default extension does exist */
1593 if (*fodInfos->ofnInfos->lpstrDefExt != '\0')
1594 {
1595 strcat(lpstrPathAndFile, ".");
1596 strcat(lpstrPathAndFile, fodInfos->ofnInfos->lpstrDefExt);
1597 }
1598 }
1599 }
1600
1601 /* Check that the size of the file does not exceed buffer size.
1602 (Allow for extra \0 if OFN_MULTISELECT is set.) */
1603 if(strlen(lpstrPathAndFile) < fodInfos->ofnInfos->nMaxFile -
1604 ((fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT) ? 1 : 0))
1605 {
1606 LPSTR lpszTemp;
1607
1608 /* fill destination buffer */
1609 strcpy(fodInfos->ofnInfos->lpstrFile, lpstrPathAndFile);
1610 if (fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT)
1611 fodInfos->ofnInfos->lpstrFile[strlen(fodInfos->ofnInfos->lpstrFile)
1612 + 1] = '\0';
1613
1614 /* set filename offset */
1615 lpszTemp = PathFindFileNameA(lpstrPathAndFile);
1616 fodInfos->ofnInfos->nFileOffset = lpszTemp - lpstrPathAndFile;
1617
1618 /* set extension offset */
1619 lpszTemp = PathFindExtensionA(lpstrPathAndFile);
1620 fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? lpszTemp - lpstrPathAndFile + 1 : 0;
1621
1622 /* set the lpstrFileTitle */
1623 if(fodInfos->ofnInfos->lpstrFileTitle)
1624 {
1625 LPSTR lpstrFileTitle = PathFindFileNameA(lpstrPathAndFile);
1626 strncpy(fodInfos->ofnInfos->lpstrFileTitle, lpstrFileTitle, fodInfos->ofnInfos->nMaxFileTitle);
1627 }
1628
1629 /* ask the hook if we can close */
1630 if(IsHooked(fodInfos))
1631 {
1632 /* FIXME we are sending ASCII-structures. Does not work with NT */
1633 /* first old style */
1634 TRACE("---\n");
1635 CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,
1636 fodInfos->DlgInfos.hwndCustomDlg,
1637 fodInfos->HookMsg.fileokstring, 0, (LPARAM)fodInfos->ofnInfos);
1638 if (GetWindowLongA(hwnd, DWL_MSGRESULT))
1639 {
1640 TRACE("cancled\n");
1641 ret = FALSE;
1642 goto ret;
1643 }
1644 }
1645
1646#ifndef __WIN32OS2__
1647 // 20011017 PH
1648 // some apps require the resources to be still there
1649 // for the CDN_ processing.
1650
1651 TRACE("close\n");
1652 FILEDLG95_Clean(hwnd);
1653 ret = EndDialog(hwnd, TRUE);
1654#else
1655 ret = TRUE;
1656#endif
1657 }
1658 else
1659 {
1660 /* FIXME set error FNERR_BUFFERTOSMALL */
1661#ifndef __WIN32OS2__
1662 // 20011017 PH
1663 // some apps require the resources to be still there
1664 // for the CDN_ processing.
1665
1666 FILEDLG95_Clean(hwnd);
1667 ret = EndDialog(hwnd, FALSE);
1668#else
1669 ret = FALSE;
1670#endif
1671 }
1672 goto ret;
1673 }
1674 break;
1675 }
1676
1677ret:
1678 if(lpsf) IShellFolder_Release(lpsf);
1679 return ret;
1680}
1681
1682/***********************************************************************
1683 * FILEDLG95_SHELL_Init
1684 *
1685 * Initialisation of the shell objects
1686 */
1687static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
1688{
1689 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1690
1691 TRACE("\n");
1692
1693 /*
1694 * Initialisation of the FileOpenDialogInfos structure
1695 */
1696
1697 /* Shell */
1698
1699 /*ShellInfos */
1700 fodInfos->ShellInfos.hwndOwner = hwnd;
1701
1702 /* Disable multi-select if flag not set */
1703 if (!(fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT))
1704 {
1705 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_SINGLESEL;
1706 }
1707 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_AUTOARRANGE | FWF_ALIGNLEFT;
1708 fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
1709
1710 GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
1711 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
1712 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
1713
1714 /* Construct the IShellBrowser interface */
1715 fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
1716
1717 return NOERROR;
1718}
1719
1720/***********************************************************************
1721 * FILEDLG95_SHELL_ExecuteCommand
1722 *
1723 * Change the folder option and refresh the view
1724 * If the function succeeds, the return value is nonzero.
1725 */
1726static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
1727{
1728 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1729
1730 IContextMenu * pcm;
1731 TRACE("(0x%08x,%p)\n", hwnd, lpVerb);
1732
1733 if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
1734 SVGIO_BACKGROUND,
1735 &IID_IContextMenu,
1736 (LPVOID*)&pcm)))
1737 {
1738 CMINVOKECOMMANDINFO ci;
1739 ZeroMemory(&ci, sizeof(CMINVOKECOMMANDINFO));
1740 ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
1741 ci.lpVerb = lpVerb;
1742 ci.hwnd = hwnd;
1743
1744 IContextMenu_InvokeCommand(pcm, &ci);
1745 IContextMenu_Release(pcm);
1746 }
1747
1748 return FALSE;
1749}
1750
1751/***********************************************************************
1752 * FILEDLG95_SHELL_UpFolder
1753 *
1754 * Browse to the specified object
1755 * If the function succeeds, the return value is nonzero.
1756 */
1757static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
1758{
1759 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1760
1761 TRACE("\n");
1762
1763 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1764 NULL,
1765 SBSP_PARENT)))
1766 {
1767 return TRUE;
1768 }
1769 return FALSE;
1770}
1771
1772/***********************************************************************
1773 * FILEDLG95_SHELL_BrowseToDesktop
1774 *
1775 * Browse to the Desktop
1776 * If the function succeeds, the return value is nonzero.
1777 */
1778static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd)
1779{
1780 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1781 LPITEMIDLIST pidl;
1782 HRESULT hres;
1783
1784 TRACE("\n");
1785
1786 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidl);
1787 hres = IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidl, SBSP_ABSOLUTE);
1788 COMDLG32_SHFree(pidl);
1789 return SUCCEEDED(hres);
1790}
1791/***********************************************************************
1792 * FILEDLG95_SHELL_Clean
1793 *
1794 * Cleans the memory used by shell objects
1795 */
1796static void FILEDLG95_SHELL_Clean(HWND hwnd)
1797{
1798 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1799
1800 TRACE("\n");
1801
1802 COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent);
1803
1804 /* clean Shell interfaces */
1805 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
1806 IShellView_Release(fodInfos->Shell.FOIShellView);
1807 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
1808 IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
1809 if (fodInfos->Shell.FOIDataObject)
1810 IDataObject_Release(fodInfos->Shell.FOIDataObject);
1811}
1812
1813/***********************************************************************
1814 * FILEDLG95_FILETYPE_Init
1815 *
1816 * Initialisation of the file type combo box
1817 */
1818static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
1819{
1820 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1821
1822 TRACE("\n");
1823
1824 if(fodInfos->ofnInfos->lpstrFilter)
1825 {
1826 int nFilters = 0; /* number of filters */
1827 LPSTR lpstrFilter;
1828 LPCSTR lpstrPos = fodInfos->ofnInfos->lpstrFilter;
1829
1830 for(;;)
1831 {
1832 /* filter is a list... title\0ext\0......\0\0
1833 * Set the combo item text to the title and the item data
1834 * to the ext
1835 */
1836 LPCSTR lpstrDisplay;
1837 LPSTR lpstrExt;
1838
1839 /* Get the title */
1840 if(! *lpstrPos) break; /* end */
1841 lpstrDisplay = lpstrPos;
1842 lpstrPos += strlen(lpstrPos) + 1;
1843
1844 /* Copy the extensions */
1845 if (! *lpstrPos) return E_FAIL; /* malformed filter */
1846 if (!(lpstrExt = (LPSTR) MemAlloc(strlen(lpstrPos)+1))) return E_FAIL;
1847 strcpy(lpstrExt,lpstrPos);
1848 lpstrPos += strlen(lpstrPos) + 1;
1849
1850 /* Add the item at the end of the combo */
1851 CBAddString(fodInfos->DlgInfos.hwndFileTypeCB, lpstrDisplay);
1852 CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt);
1853 nFilters++;
1854 }
1855 /*
1856 * Set the current filter to the one specified
1857 * in the initialisation structure
1858 * FIXME: lpstrCustomFilter not handled at all
1859 */
1860
1861 /* set default filter index */
1862 if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->ofnInfos->lpstrCustomFilter == NULL)
1863 fodInfos->ofnInfos->nFilterIndex = 1;
1864
1865 /* First, check to make sure our index isn't out of bounds. */
1866 if ( fodInfos->ofnInfos->nFilterIndex > nFilters )
1867 fodInfos->ofnInfos->nFilterIndex = nFilters;
1868
1869 /* Set the current index selection. */
1870 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->ofnInfos->nFilterIndex-1);
1871
1872 /* Get the corresponding text string from the combo box. */
1873 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1874 fodInfos->ofnInfos->nFilterIndex-1);
1875
1876 if ((INT)lpstrFilter == CB_ERR) /* control is empty */
1877 lpstrFilter = NULL;
1878
1879 if(lpstrFilter)
1880 {
1881 DWORD len;
1882 _strlwr(lpstrFilter); /* lowercase */
1883 len = MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1, NULL, 0 );
1884 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
1885 MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1,
1886 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1887 }
1888 }
1889 return NOERROR;
1890}
1891
1892/***********************************************************************
1893 * FILEDLG95_FILETYPE_OnCommand
1894 *
1895 * WM_COMMAND of the file type combo box
1896 * If the function succeeds, the return value is nonzero.
1897 */
1898static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
1899{
1900 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1901
1902 switch(wNotifyCode)
1903 {
1904 case CBN_SELENDOK:
1905 {
1906 LPSTR lpstrFilter;
1907
1908 /* Get the current item of the filetype combo box */
1909 int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1910
1911 /* set the current filter index - indexed from 1 */
1912 fodInfos->ofnInfos->nFilterIndex = iItem + 1;
1913
1914 /* Set the current filter with the current selection */
1915 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1916 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1917
1918 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1919 iItem);
1920 if((int)lpstrFilter != CB_ERR)
1921 {
1922 DWORD len;
1923 _strlwr(lpstrFilter); /* lowercase */
1924 len = MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1, NULL, 0 );
1925 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
1926 MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1,
1927 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1928 SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
1929 }
1930
1931 /* Refresh the actual view to display the included items*/
1932 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1933 }
1934 }
1935 return FALSE;
1936}
1937/***********************************************************************
1938 * FILEDLG95_FILETYPE_SearchExt
1939 *
1940 * searches for a extension in the filetype box
1941 */
1942static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt)
1943{
1944 int i, iCount = CBGetCount(hwnd);
1945
1946 TRACE("%s\n", lpstrExt);
1947
1948 if(iCount != CB_ERR)
1949 {
1950 for(i=0;i<iCount;i++)
1951 {
1952 if(!strcasecmp(lpstrExt,(LPSTR)CBGetItemDataPtr(hwnd,i)))
1953 return i;
1954 }
1955 }
1956 return -1;
1957}
1958
1959/***********************************************************************
1960 * FILEDLG95_FILETYPE_Clean
1961 *
1962 * Clean the memory used by the filetype combo box
1963 */
1964static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
1965{
1966 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1967 int iPos;
1968 int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
1969
1970 TRACE("\n");
1971
1972 /* Delete each string of the combo and their associated data */
1973 if(iCount != CB_ERR)
1974 {
1975 for(iPos = iCount-1;iPos>=0;iPos--)
1976 {
1977 MemFree((LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos));
1978 CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1979 }
1980 }
1981 /* Current filter */
1982 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1983 MemFree(fodInfos->ShellInfos.lpstrCurrentFilter);
1984
1985}
1986
1987/***********************************************************************
1988 * FILEDLG95_LOOKIN_Init
1989 *
1990 * Initialisation of the look in combo box
1991 */
1992static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
1993{
1994 IShellFolder *psfRoot, *psfDrives;
1995 IEnumIDList *lpeRoot, *lpeDrives;
1996 LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
1997
1998 LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
1999
2000 TRACE("\n");
2001
2002 liInfos->iMaxIndentation = 0;
2003
2004 SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
2005
2006 /* set item height for both text field and listbox */
2007 CBSetItemHeight(hwndCombo,-1,GetSystemMetrics(SM_CYSMICON));
2008 CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
2009
2010 /* Initialise data of Desktop folder */
2011 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
2012 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
2013 COMDLG32_SHFree(pidlTmp);
2014
2015 SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
2016
2017 SHGetDesktopFolder(&psfRoot);
2018
2019 if (psfRoot)
2020 {
2021 /* enumerate the contents of the desktop */
2022 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
2023 {
2024 while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
2025 {
2026 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
2027
2028 /* special handling for CSIDL_DRIVES */
2029 if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
2030 {
2031 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
2032 {
2033 /* enumerate the drives */
2034 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
2035 {
2036 while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
2037 {
2038 pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
2039 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
2040 COMDLG32_SHFree(pidlAbsTmp);
2041 COMDLG32_SHFree(pidlTmp1);
2042 }
2043 IEnumIDList_Release(lpeDrives);
2044 }
2045 IShellFolder_Release(psfDrives);
2046 }
2047 }
2048 COMDLG32_SHFree(pidlTmp);
2049 }
2050 IEnumIDList_Release(lpeRoot);
2051 }
2052 }
2053
2054 IShellFolder_Release(psfRoot);
2055 COMDLG32_SHFree(pidlDrives);
2056 return NOERROR;
2057}
2058
2059/***********************************************************************
2060 * FILEDLG95_LOOKIN_DrawItem
2061 *
2062 * WM_DRAWITEM message handler
2063 */
2064static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
2065{
2066 COLORREF crWin = GetSysColor(COLOR_WINDOW);
2067 COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
2068 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
2069 RECT rectText;
2070 RECT rectIcon;
2071 SHFILEINFOA sfi;
2072 HIMAGELIST ilItemImage;
2073 int iIndentation;
2074 TEXTMETRICA tm;
2075 LPSFOLDER tmpFolder;
2076
2077
2078 LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
2079
2080 TRACE("\n");
2081
2082 if(pDIStruct->itemID == -1)
2083 return 0;
2084
2085 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
2086 pDIStruct->itemID)))
2087 return 0;
2088
2089
2090 if(pDIStruct->itemID == liInfos->uSelectedItem)
2091 {
2092 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2093 0,
2094 &sfi,
2095 sizeof (SHFILEINFOA),
2096 SHGFI_PIDL | SHGFI_SMALLICON |
2097 SHGFI_OPENICON | SHGFI_SYSICONINDEX |
2098 SHGFI_DISPLAYNAME );
2099 }
2100 else
2101 {
2102 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2103 0,
2104 &sfi,
2105 sizeof (SHFILEINFOA),
2106 SHGFI_PIDL | SHGFI_SMALLICON |
2107 SHGFI_SYSICONINDEX |
2108 SHGFI_DISPLAYNAME);
2109 }
2110
2111 /* Is this item selected ? */
2112 if(pDIStruct->itemState & ODS_SELECTED)
2113 {
2114 SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
2115 SetBkColor(pDIStruct->hDC,crHighLight);
2116 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight);
2117 }
2118 else
2119 {
2120 SetTextColor(pDIStruct->hDC,crText);
2121 SetBkColor(pDIStruct->hDC,crWin);
2122 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin);
2123 }
2124
2125 /* Do not indent item if drawing in the edit of the combo */
2126 if(pDIStruct->itemState & ODS_COMBOBOXEDIT)
2127 {
2128 iIndentation = 0;
2129 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2130 0,
2131 &sfi,
2132 sizeof (SHFILEINFOA),
2133 SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON
2134 | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME );
2135
2136 }
2137 else
2138 {
2139 iIndentation = tmpFolder->m_iIndent;
2140 }
2141 /* Draw text and icon */
2142
2143 /* Initialise the icon display area */
2144 rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
2145 rectIcon.top = pDIStruct->rcItem.top;
2146 rectIcon.right = rectIcon.left + ICONWIDTH;
2147 rectIcon.bottom = pDIStruct->rcItem.bottom;
2148
2149 /* Initialise the text display area */
2150 GetTextMetricsA(pDIStruct->hDC, &tm);
2151 rectText.left = rectIcon.right;
2152 rectText.top =
2153 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom - tm.tmHeight) / 2;
2154 rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
2155 rectText.bottom =
2156 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom + tm.tmHeight) / 2;
2157
2158 /* Draw the icon from the image list */
2159 ImageList_Draw(ilItemImage,
2160 sfi.iIcon,
2161 pDIStruct->hDC,
2162 rectIcon.left,
2163 rectIcon.top,
2164 ILD_TRANSPARENT );
2165
2166 /* Draw the associated text */
2167 if(sfi.szDisplayName)
2168 TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName));
2169
2170
2171 return NOERROR;
2172}
2173
2174/***********************************************************************
2175 * FILEDLG95_LOOKIN_OnCommand
2176 *
2177 * LookIn combo box WM_COMMAND message handler
2178 * If the function succeeds, the return value is nonzero.
2179 */
2180static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
2181{
2182 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2183
2184 TRACE("%p\n", fodInfos);
2185
2186 switch(wNotifyCode)
2187 {
2188 case CBN_SELENDOK:
2189 {
2190 LPSFOLDER tmpFolder;
2191 int iItem;
2192
2193 iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
2194
2195 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
2196 iItem)))
2197 return FALSE;
2198
2199
2200 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
2201 tmpFolder->pidlItem,
2202 SBSP_ABSOLUTE)))
2203 {
2204 return TRUE;
2205 }
2206 break;
2207 }
2208
2209 }
2210 return FALSE;
2211}
2212
2213/***********************************************************************
2214 * FILEDLG95_LOOKIN_AddItem
2215 *
2216 * Adds an absolute pidl item to the lookin combo box
2217 * returns the index of the inserted item
2218 */
2219static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
2220{
2221 LPITEMIDLIST pidlNext;
2222 SHFILEINFOA sfi;
2223 SFOLDER *tmpFolder;
2224 LookInInfos *liInfos;
2225
2226 TRACE("%08x\n", iInsertId);
2227
2228 if(!pidl)
2229 return -1;
2230
2231 if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
2232 return -1;
2233
2234 tmpFolder = MemAlloc(sizeof(SFOLDER));
2235 tmpFolder->m_iIndent = 0;
2236
2237 /* Calculate the indentation of the item in the lookin*/
2238 pidlNext = pidl;
2239 while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
2240 {
2241 tmpFolder->m_iIndent++;
2242 }
2243
2244 tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl); /* FIXME: memory leak*/
2245
2246 if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
2247 liInfos->iMaxIndentation = tmpFolder->m_iIndent;
2248
2249 sfi.dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM;
2250 SHGetFileInfoA((LPSTR)pidl,
2251 0,
2252 &sfi,
2253 sizeof(sfi),
2254 SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX
2255 | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED);
2256
2257 TRACE("-- Add %s attr=%08lx\n", sfi.szDisplayName, sfi.dwAttributes);
2258
2259 if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
2260 {
2261 int iItemID;
2262
2263 TRACE("-- Add %s at %u\n", sfi.szDisplayName, tmpFolder->m_iIndent);
2264
2265 /* Add the item at the end of the list */
2266 if(iInsertId < 0)
2267 {
2268 iItemID = CBAddString(hwnd,sfi.szDisplayName);
2269 }
2270 /* Insert the item at the iInsertId position*/
2271 else
2272 {
2273 iItemID = CBInsertString(hwnd,sfi.szDisplayName,iInsertId);
2274 }
2275
2276 CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
2277 return iItemID;
2278 }
2279
2280 MemFree( tmpFolder );
2281 return -1;
2282
2283}
2284
2285/***********************************************************************
2286 * FILEDLG95_LOOKIN_InsertItemAfterParent
2287 *
2288 * Insert an item below its parent
2289 */
2290static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
2291{
2292
2293 LPITEMIDLIST pidlParent = GetParentPidl(pidl);
2294 int iParentPos;
2295
2296 TRACE("\n");
2297
2298 iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
2299
2300 if(iParentPos < 0)
2301 {
2302 iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
2303 }
2304
2305 /* Free pidlParent memory */
2306 COMDLG32_SHFree((LPVOID)pidlParent);
2307
2308 return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
2309}
2310
2311/***********************************************************************
2312 * FILEDLG95_LOOKIN_SelectItem
2313 *
2314 * Adds an absolute pidl item to the lookin combo box
2315 * returns the index of the inserted item
2316 */
2317int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
2318{
2319 int iItemPos;
2320 LookInInfos *liInfos;
2321
2322 TRACE("\n");
2323
2324 iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
2325
2326 liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2327
2328 if(iItemPos < 0)
2329 {
2330 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
2331 iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
2332 }
2333
2334 else
2335 {
2336 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2337 while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
2338 {
2339 int iRemovedItem;
2340
2341 if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
2342 break;
2343 if(iRemovedItem < iItemPos)
2344 iItemPos--;
2345 }
2346 }
2347
2348 CBSetCurSel(hwnd,iItemPos);
2349 liInfos->uSelectedItem = iItemPos;
2350
2351 return 0;
2352
2353}
2354
2355/***********************************************************************
2356 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2357 *
2358 * Remove the item with an expansion level over iExpansionLevel
2359 */
2360static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
2361{
2362 int iItemPos;
2363
2364 LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2365
2366 TRACE("\n");
2367
2368 if(liInfos->iMaxIndentation <= 2)
2369 return -1;
2370
2371 if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
2372 {
2373 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2374 COMDLG32_SHFree(tmpFolder->pidlItem);
2375 MemFree(tmpFolder);
2376 CBDeleteString(hwnd,iItemPos);
2377 liInfos->iMaxIndentation--;
2378
2379 return iItemPos;
2380 }
2381
2382 return -1;
2383}
2384
2385/***********************************************************************
2386 * FILEDLG95_LOOKIN_SearchItem
2387 *
2388 * Search for pidl in the lookin combo box
2389 * returns the index of the found item
2390 */
2391static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
2392{
2393 int i = 0;
2394 int iCount = CBGetCount(hwnd);
2395
2396 TRACE("0x%08x 0x%x\n",searchArg, iSearchMethod);
2397
2398 if (iCount != CB_ERR)
2399 {
2400 for(;i<iCount;i++)
2401 {
2402 LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
2403
2404 if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
2405 return i;
2406 if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
2407 return i;
2408 }
2409 }
2410
2411 return -1;
2412}
2413
2414/***********************************************************************
2415 * FILEDLG95_LOOKIN_Clean
2416 *
2417 * Clean the memory used by the lookin combo box
2418 */
2419static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
2420{
2421 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2422 int iPos;
2423 int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
2424
2425 TRACE("\n");
2426
2427 /* Delete each string of the combo and their associated data */
2428 if (iCount != CB_ERR)
2429 {
2430 for(iPos = iCount-1;iPos>=0;iPos--)
2431 {
2432 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos);
2433 COMDLG32_SHFree(tmpFolder->pidlItem);
2434 MemFree(tmpFolder);
2435 CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
2436 }
2437 }
2438
2439 /* LookInInfos structure */
2440 RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
2441
2442}
2443/***********************************************************************
2444 * FILEDLG95_FILENAME_FillFromSelection
2445 *
2446 * fills the edit box from the cached DataObject
2447 */
2448void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd)
2449{
2450 FileOpenDlgInfos *fodInfos;
2451 LPITEMIDLIST pidl;
2452 UINT nFiles = 0, nFileToOpen, nFileSelected, nLength = 0;
2453 char lpstrTemp[MAX_PATH];
2454 LPSTR lpstrAllFile = NULL, lpstrCurrFile = NULL;
2455
2456 TRACE("\n");
2457 fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2458
2459 /* Count how many files we have */
2460 nFileSelected = GetNumSelected( fodInfos->Shell.FOIDataObject );
2461
2462 /* calculate the string length, count files */
2463 if (nFileSelected >= 1)
2464 {
2465 nLength += 3; /* first and last quotes, trailing \0 */
2466 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2467 {
2468 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2469
2470 if (pidl)
2471 {
2472 /* get the total length of the selected file names*/
2473 lpstrTemp[0] = '\0';
2474 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2475
2476 if ( ! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl) ) /* Ignore folders */
2477 {
2478 nLength += strlen( lpstrTemp ) + 3;
2479 nFiles++;
2480 }
2481 COMDLG32_SHFree( pidl );
2482 }
2483 }
2484 }
2485
2486 /* allocate the buffer */
2487 if (nFiles <= 1) nLength = MAX_PATH;
2488 lpstrAllFile = (LPSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength);
2489 lpstrAllFile[0] = '\0';
2490
2491 /* Generate the string for the edit control */
2492 if(nFiles >= 1)
2493 {
2494 lpstrCurrFile = lpstrAllFile;
2495 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2496 {
2497 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2498
2499 if (pidl)
2500 {
2501 /* get the file name */
2502 lpstrTemp[0] = '\0';
2503 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2504
2505 if (! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl)) /* Ignore folders */
2506 {
2507 if ( nFiles > 1)
2508 {
2509 *lpstrCurrFile++ = '\"';
2510 strcpy( lpstrCurrFile, lpstrTemp );
2511 lpstrCurrFile += strlen( lpstrTemp );
2512 strcpy( lpstrCurrFile, "\" " );
2513 lpstrCurrFile += 2;
2514 }
2515 else
2516 {
2517 strcpy( lpstrAllFile, lpstrTemp );
2518 }
2519 }
2520 COMDLG32_SHFree( (LPVOID) pidl );
2521 }
2522 }
2523 }
2524#ifdef __WIN32OS2__
2525 //Selecting a directory previously erased the last selected file
2526 if(nFiles) {
2527 SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile );
2528 }
2529#else
2530 SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile );
2531#endif
2532 HeapFree(GetProcessHeap(),0, lpstrAllFile );
2533}
2534
2535
2536/* copied from shell32 to avoid linking to it */
2537static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
2538{
2539 switch (src->uType)
2540 {
2541 case STRRET_WSTR:
2542 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL);
2543 COMDLG32_SHFree(src->u.pOleStr);
2544 break;
2545
2546 case STRRET_CSTRA:
2547 lstrcpynA((LPSTR)dest, src->u.cStr, len);
2548 break;
2549
2550 case STRRET_OFFSETA:
2551 lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
2552 break;
2553
2554 default:
2555 FIXME("unknown type!\n");
2556 if (len)
2557 {
2558 *(LPSTR)dest = '\0';
2559 }
2560 return(FALSE);
2561 }
2562 return S_OK;
2563}
2564
2565/***********************************************************************
2566 * FILEDLG95_FILENAME_GetFileNames
2567 *
2568 * copies the filenames to a 0-delimited string list (A\0B\0C\0\0)
2569 */
2570int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPSTR * lpstrFileList, UINT * sizeUsed)
2571{
2572 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2573 UINT nStrCharCount = 0; /* index in src buffer */
2574 UINT nFileIndex = 0; /* index in dest buffer */
2575 UINT nFileCount = 0; /* number of files */
2576 UINT nStrLen = 0; /* length of string in edit control */
2577 LPSTR lpstrEdit; /* buffer for string from edit control */
2578
2579 TRACE("\n");
2580
2581 /* get the filenames from the edit control */
2582 nStrLen = SendMessageA(fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0);
2583 lpstrEdit = MemAlloc(nStrLen+1);
2584 GetDlgItemTextA(hwnd, IDC_FILENAME, lpstrEdit, nStrLen+1);
2585
2586 TRACE("nStrLen=%u str=%s\n", nStrLen, lpstrEdit);
2587
2588 /* we might get single filename without any '"',
2589 * so we need nStrLen + terminating \0 + end-of-list \0 */
2590 *lpstrFileList = MemAlloc(nStrLen+2);
2591 *sizeUsed = 0;
2592
2593 /* build 0-delimited file list from filenames */
2594 while ( nStrCharCount <= nStrLen )
2595 {
2596 if ( lpstrEdit[nStrCharCount]=='"' )
2597 {
2598 nStrCharCount++;
2599 while ((lpstrEdit[nStrCharCount]!='"') && (nStrCharCount <= nStrLen))
2600 {
2601 (*lpstrFileList)[nFileIndex++] = lpstrEdit[nStrCharCount];
2602 (*sizeUsed)++;
2603 nStrCharCount++;
2604 }
2605 (*lpstrFileList)[nFileIndex++] = '\0';
2606 (*sizeUsed)++;
2607 nFileCount++;
2608 }
2609 nStrCharCount++;
2610 }
2611
2612 /* single, unquoted string */
2613 if ((nStrLen > 0) && (*sizeUsed == 0) )
2614 {
2615 strcpy(*lpstrFileList, lpstrEdit);
2616 nFileIndex = strlen(lpstrEdit) + 1;
2617 (*sizeUsed) = nFileIndex;
2618 nFileCount = 1;
2619 }
2620
2621 /* trailing \0 */
2622 (*lpstrFileList)[nFileIndex] = '\0';
2623 (*sizeUsed)++;
2624
2625 MemFree(lpstrEdit);
2626 return nFileCount;
2627}
2628
2629#define SETDefFormatEtc(fe,cf,med) \
2630{ \
2631 (fe).cfFormat = cf;\
2632 (fe).dwAspect = DVASPECT_CONTENT; \
2633 (fe).ptd =NULL;\
2634 (fe).tymed = med;\
2635 (fe).lindex = -1;\
2636};
2637
2638/*
2639 * DATAOBJECT Helper functions
2640 */
2641
2642/***********************************************************************
2643 * COMCTL32_ReleaseStgMedium
2644 *
2645 * like ReleaseStgMedium from ole32
2646 */
2647static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium)
2648{
2649 if(medium.pUnkForRelease)
2650 {
2651 IUnknown_Release(medium.pUnkForRelease);
2652 }
2653 else
2654 {
2655 GlobalUnlock(medium.u.hGlobal);
2656 GlobalFree(medium.u.hGlobal);
2657 }
2658}
2659
2660/***********************************************************************
2661 * GetPidlFromDataObject
2662 *
2663 * Return pidl(s) by number from the cached DataObject
2664 *
2665 * nPidlIndex=0 gets the fully qualified root path
2666 */
2667LPITEMIDLIST GetPidlFromDataObject ( IDataObject *doSelected, UINT nPidlIndex)
2668{
2669
2670 STGMEDIUM medium;
2671 FORMATETC formatetc;
2672 LPITEMIDLIST pidl = NULL;
2673
2674 TRACE("sv=%p index=%u\n", doSelected, nPidlIndex);
2675
2676 /* Set the FORMATETC structure*/
2677 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2678
2679 /* Get the pidls from IDataObject */
2680 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2681 {
2682 LPIDA cida = GlobalLock(medium.u.hGlobal);
2683 if(nPidlIndex <= cida->cidl)
2684 {
2685 pidl = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[nPidlIndex]]));
2686 }
2687 COMCTL32_ReleaseStgMedium(medium);
2688 }
2689 return pidl;
2690}
2691
2692/***********************************************************************
2693 * GetNumSelected
2694 *
2695 * Return the number of selected items in the DataObject.
2696 *
2697*/
2698UINT GetNumSelected( IDataObject *doSelected )
2699{
2700 UINT retVal = 0;
2701 STGMEDIUM medium;
2702 FORMATETC formatetc;
2703
2704 TRACE("sv=%p\n", doSelected);
2705
2706 if (!doSelected) return 0;
2707
2708 /* Set the FORMATETC structure*/
2709 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2710
2711 /* Get the pidls from IDataObject */
2712 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2713 {
2714 LPIDA cida = GlobalLock(medium.u.hGlobal);
2715 retVal = cida->cidl;
2716 COMCTL32_ReleaseStgMedium(medium);
2717 return retVal;
2718 }
2719 return 0;
2720}
2721
2722/*
2723 * TOOLS
2724 */
2725
2726/***********************************************************************
2727 * GetName
2728 *
2729 * Get the pidl's display name (relative to folder) and
2730 * put it in lpstrFileName.
2731 *
2732 * Return NOERROR on success,
2733 * E_FAIL otherwise
2734 */
2735
2736HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
2737{
2738 STRRET str;
2739 HRESULT hRes;
2740
2741 TRACE("sf=%p pidl=%p\n", lpsf, pidl);
2742
2743 if(!lpsf)
2744 {
2745 HRESULT hRes;
2746 SHGetDesktopFolder(&lpsf);
2747 hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
2748 IShellFolder_Release(lpsf);
2749 return hRes;
2750 }
2751
2752 /* Get the display name of the pidl relative to the folder */
2753 if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf, pidl, dwFlags, &str)))
2754 {
2755 return COMDLG32_StrRetToStrNA(lpstrFileName, MAX_PATH, &str, pidl);
2756 }
2757 return E_FAIL;
2758}
2759
2760/***********************************************************************
2761 * GetShellFolderFromPidl
2762 *
2763 * pidlRel is the item pidl relative
2764 * Return the IShellFolder of the absolute pidl
2765 */
2766IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
2767{
2768 IShellFolder *psf = NULL,*psfParent;
2769
2770 TRACE("%p\n", pidlAbs);
2771
2772 if(SUCCEEDED(SHGetDesktopFolder(&psfParent)))
2773 {
2774 psf = psfParent;
2775 if(pidlAbs && pidlAbs->mkid.cb)
2776 {
2777 if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
2778 {
2779 IShellFolder_Release(psfParent);
2780 return psf;
2781 }
2782 }
2783 /* return the desktop */
2784 return psfParent;
2785 }
2786 return NULL;
2787}
2788
2789/***********************************************************************
2790 * GetParentPidl
2791 *
2792 * Return the LPITEMIDLIST to the parent of the pidl in the list
2793 */
2794LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
2795{
2796 LPITEMIDLIST pidlParent;
2797
2798 TRACE("%p\n", pidl);
2799
2800 pidlParent = COMDLG32_PIDL_ILClone(pidl);
2801 COMDLG32_PIDL_ILRemoveLastID(pidlParent);
2802
2803 return pidlParent;
2804}
2805
2806/***********************************************************************
2807 * GetPidlFromName
2808 *
2809 * returns the pidl of the file name relative to folder
2810 * NULL if an error occurred
2811 */
2812LPITEMIDLIST GetPidlFromName(IShellFolder *lpsf,LPCSTR lpcstrFileName)
2813{
2814 LPITEMIDLIST pidl;
2815 ULONG ulEaten;
2816 WCHAR lpwstrDirName[MAX_PATH];
2817
2818 TRACE("sf=%p file=%s\n", lpsf, lpcstrFileName);
2819
2820 if(!lpcstrFileName) return NULL;
2821 if(!*lpcstrFileName) return NULL;
2822
2823 MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,lpcstrFileName,-1,(LPWSTR)lpwstrDirName,MAX_PATH);
2824
2825 if(!lpsf)
2826 {
2827 SHGetDesktopFolder(&lpsf);
2828 pidl = GetPidlFromName(lpsf, lpcstrFileName);
2829 IShellFolder_Release(lpsf);
2830 }
2831 else
2832 {
2833 IShellFolder_ParseDisplayName(lpsf, 0, NULL, (LPWSTR)lpwstrDirName, &ulEaten, &pidl, NULL);
2834 }
2835 return pidl;
2836}
2837
2838/*
2839*/
2840BOOL IsPidlFolder (LPSHELLFOLDER psf, LPITEMIDLIST pidl)
2841{
2842 ULONG uAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
2843 HRESULT ret;
2844
2845 TRACE("%p, %p\n", psf, pidl);
2846
2847 ret = IShellFolder_GetAttributesOf( psf, 1, &pidl, &uAttr );
2848
2849 TRACE("-- 0x%08lx 0x%08lx\n", uAttr, ret);
2850 /* see documentation shell 4.1*/
2851 return uAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER);
2852}
2853
2854/***********************************************************************
2855 * BrowseSelectedFolder
2856 */
2857static BOOL BrowseSelectedFolder(HWND hwnd)
2858{
2859 BOOL bBrowseSelFolder = FALSE;
2860 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2861
2862 TRACE("\n");
2863
2864 if (GetNumSelected(fodInfos->Shell.FOIDataObject) == 1)
2865 {
2866 LPITEMIDLIST pidlSelection;
2867
2868 /* get the file selected */
2869 pidlSelection = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, 1);
2870 if (IsPidlFolder (fodInfos->Shell.FOIShellFolder, pidlSelection))
2871 {
2872 if ( FAILED( IShellBrowser_BrowseObject( fodInfos->Shell.FOIShellBrowser,
2873 pidlSelection, SBSP_RELATIVE ) ) )
2874 {
2875 MessageBoxA( hwnd, "Path does not exist", fodInfos->ofnInfos->lpstrTitle,
2876 MB_OK | MB_ICONEXCLAMATION );
2877 }
2878
2879 bBrowseSelFolder = TRUE;
2880 }
2881 COMDLG32_SHFree( pidlSelection );
2882 }
2883
2884 return bBrowseSelFolder;
2885}
2886
2887/*
2888 * Memory allocation methods */
2889static void *MemAlloc(UINT size)
2890{
2891 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
2892}
2893
2894static void MemFree(void *mem)
2895{
2896 if(mem)
2897 {
2898 HeapFree(GetProcessHeap(),0,mem);
2899 }
2900}
2901
Note: See TracBrowser for help on using the repository browser.