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

Last change on this file since 5280 was 5141, checked in by sandervl, 25 years ago

save dialog fix (OFN_FILEMUSTEXIST)

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