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

Last change on this file since 5655 was 5583, checked in by sandervl, 24 years ago

Wine resync

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