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

Last change on this file since 4602 was 4561, checked in by sandervl, 25 years ago

merged with latest Wine (11-05-2000)

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