2 * COMMDLG - File Open Dialogs Win95 look and feel
14 #include "debugtools.h"
20 #include "filedlgbrowser.h"
21 #include "wine/obj_contextmenu.h"
23 DEFAULT_DEBUG_CHANNEL(commdlg)
25 /***********************************************************************
26 * Data structure and global variables
28 typedef struct SFolder
30 int m_iImageIndex; /* Index of picture in image list */
32 int m_iIndent; /* Indentation index */
33 LPITEMIDLIST pidlItem; /* absolute pidl of the item */
37 typedef struct tagLookInInfo
44 /***********************************************************************
45 * Defines and global variables
48 /* Draw item constant */
56 /* SearchItem methods */
59 #define ITEM_NOTFOUND -1
61 /* Undefined windows message sent by CreateViewObject*/
62 #define WM_GETISHELLBROWSER WM_USER+7
65 * Those macros exist in windowsx.h. However, you can't really use them since
66 * they rely on the UNICODE defines and can't be use inside Wine itself.
69 /* Combo box macros */
70 #define CBAddString(hwnd,str) \
71 SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str);
73 #define CBInsertString(hwnd,str,pos) \
74 SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str);
76 #define CBDeleteString(hwnd,pos) \
77 SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0);
79 #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
80 SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr);
82 #define CBGetItemDataPtr(hwnd,iItemId) \
83 SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0)
85 #define CBGetLBText(hwnd,iItemId,str) \
86 SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str);
88 #define CBGetCurSel(hwnd) \
89 SendMessageA(hwnd,CB_GETCURSEL,0,0);
91 #define CBSetCurSel(hwnd,pos) \
92 SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0);
94 #define CBGetCount(hwnd) \
95 SendMessageA(hwnd,CB_GETCOUNT,0,0);
96 #define CBShowDropDown(hwnd,show) \
97 SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0);
98 #define CBSetItemHeight(hwnd,index,height) \
99 SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height);
102 const char *FileOpenDlgInfosStr = "FileOpenDlgInfos"; /* windows property description string */
103 const char *LookInInfosStr = "LookInInfos"; /* LOOKIN combo box property */
105 static const char defaultFilter[] = "*.*";
107 /***********************************************************************
111 /* Internal functions used by the dialog */
112 static LRESULT FILEDLG95_OnWMInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam);
113 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
114 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd);
115 BOOL FILEDLG95_OnOpen(HWND hwnd);
116 static LRESULT FILEDLG95_InitUI(HWND hwnd);
117 static void FILEDLG95_Clean(HWND hwnd);
119 /* Functions used by the shell object */
120 static LRESULT FILEDLG95_SHELL_Init(HWND hwnd);
121 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd);
122 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb);
123 static BOOL FILEDLG95_SHELL_NewFolder(HWND hwnd);
124 static void FILEDLG95_SHELL_Clean(HWND hwnd);
126 /* Functions used by the filetype combo box */
127 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd);
128 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode);
129 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPSTR lpstrExt);
130 static void FILEDLG95_FILETYPE_Clean(HWND hwnd);
132 /* Functions used by the Look In combo box */
133 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo);
134 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);
135 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);
136 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);
137 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod);
138 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl);
139 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd);
140 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
141 static void FILEDLG95_LOOKIN_Clean(HWND hwnd);
143 /* Miscellaneous tool functions */
144 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
145 HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
146 IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
147 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
148 LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
150 /* Shell memory allocation */
151 void *MemAlloc(UINT size);
152 void MemFree(void *mem);
154 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos);
155 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
156 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
157 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
159 /***********************************************************************
162 * Creates an Open common dialog box that lets the user select
163 * the drive, directory, and the name of a file or set of files to open.
165 * IN : The FileOpenDlgInfos structure associated with the dialog
166 * OUT : TRUE on success
167 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
169 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)
177 /* Create the dialog from a template */
179 if(!(hRes = FindResourceA(COMMDLG_hInstance32,MAKEINTRESOURCEA(NEWFILEOPENORD),RT_DIALOGA)))
181 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
184 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hRes )) ||
185 !(template = LockResource( hDlgTmpl )))
187 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
190 lRes = DialogBoxIndirectParamA(COMMDLG_hInstance32,
191 (LPDLGTEMPLATEA) template,
192 fodInfos->ofnInfos.hwndOwner,
193 (DLGPROC) FileOpenDlgProc95,
196 /* Unable to create the dialog*/
203 /***********************************************************************
206 * Copy the OPENFILENAMEA structure in a FileOpenDlgInfos structure.
207 * Call GetFileName95 with this structure and clean the memory.
209 * IN : The OPENFILENAMEA initialisation structure passed to
210 * GetOpenFileNameA win api function (see filedlg.c)
212 BOOL WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
216 FileOpenDlgInfos *fodInfos;
218 /* Initialise FileOpenDlgInfos structure*/
219 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
220 memset(&fodInfos->ofnInfos,'\0',sizeof(*ofn)); fodInfos->ofnInfos.lStructSize = sizeof(*ofn);
221 fodInfos->ofnInfos.hwndOwner = ofn->hwndOwner;
222 fodInfos->ofnInfos.hInstance = MapHModuleLS(ofn->hInstance);
223 if (ofn->lpstrFilter)
227 /* filter is a list... title\0ext\0......\0\0 */
228 s = (LPSTR)ofn->lpstrFilter;
232 x = (LPSTR)MemAlloc(s-ofn->lpstrFilter);
233 memcpy(x,ofn->lpstrFilter,s-ofn->lpstrFilter);
234 fodInfos->ofnInfos.lpstrFilter = (LPSTR)x;
236 if (ofn->lpstrCustomFilter)
240 /* filter is a list... title\0ext\0......\0\0 */
241 s = (LPSTR)ofn->lpstrCustomFilter;
245 x = MemAlloc(s-ofn->lpstrCustomFilter);
246 memcpy(x,ofn->lpstrCustomFilter,s-ofn->lpstrCustomFilter);
247 fodInfos->ofnInfos.lpstrCustomFilter = (LPSTR)x;
249 fodInfos->ofnInfos.nMaxCustFilter = ofn->nMaxCustFilter;
250 if(ofn->nFilterIndex)
251 fodInfos->ofnInfos.nFilterIndex = --ofn->nFilterIndex;
254 fodInfos->ofnInfos.lpstrFile = (LPSTR)MemAlloc(ofn->nMaxFile);
255 strcpy((LPSTR)fodInfos->ofnInfos.lpstrFile,ofn->lpstrFile);
257 fodInfos->ofnInfos.nMaxFile = ofn->nMaxFile;
258 fodInfos->ofnInfos.nMaxFileTitle = ofn->nMaxFileTitle;
259 if (fodInfos->ofnInfos.nMaxFileTitle)
260 fodInfos->ofnInfos.lpstrFileTitle = (LPSTR)MemAlloc(ofn->nMaxFileTitle);
261 if (ofn->lpstrInitialDir)
263 fodInfos->ofnInfos.lpstrInitialDir = (LPSTR)MemAlloc(strlen(ofn->lpstrInitialDir)+1);
264 strcpy((LPSTR)fodInfos->ofnInfos.lpstrInitialDir,ofn->lpstrInitialDir);
269 fodInfos->ofnInfos.lpstrTitle = (LPSTR)MemAlloc(strlen(ofn->lpstrTitle)+1);
270 strcpy((LPSTR)fodInfos->ofnInfos.lpstrTitle,ofn->lpstrTitle);
273 fodInfos->ofnInfos.Flags = ofn->Flags|OFN_WINE;
274 fodInfos->ofnInfos.nFileOffset = ofn->nFileOffset;
275 fodInfos->ofnInfos.nFileExtension = ofn->nFileExtension;
276 if (ofn->lpstrDefExt)
278 fodInfos->ofnInfos.lpstrDefExt = MemAlloc(strlen(ofn->lpstrDefExt)+1);
279 strcpy((LPSTR)fodInfos->ofnInfos.lpstrDefExt,ofn->lpstrDefExt);
281 fodInfos->ofnInfos.lCustData = ofn->lCustData;
282 fodInfos->ofnInfos.lpfnHook = (LPOFNHOOKPROC)ofn->lpfnHook;
284 if (ofn->lpTemplateName)
286 fodInfos->ofnInfos.lpTemplateName = ofn->lpTemplateName;
289 /* Replace the NULL lpstrInitialDir by the current folder */
290 if(!ofn->lpstrInitialDir)
292 fodInfos->ofnInfos.lpstrInitialDir = MemAlloc(MAX_PATH);
293 GetCurrentDirectoryA(MAX_PATH,(LPSTR)fodInfos->ofnInfos.lpstrInitialDir);
296 /* Initialise the dialog property */
297 fodInfos->DlgInfos.dwDlgProp = 0;
298 fodInfos->DlgInfos.hwndCustomDlg = (HWND)NULL;
303 ret = GetFileName95(fodInfos);
306 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
307 ret = GetFileName95(fodInfos);
313 ofn->nFileOffset = fodInfos->ofnInfos.nFileOffset;
314 ofn->nFileExtension = fodInfos->ofnInfos.nFileExtension;
317 Transfer the combo index in the OPENFILENAME structure;
318 No support for custom filters, so nFilterIndex must be one-based.
320 ofn->nFilterIndex = fodInfos->ofnInfos.nFilterIndex + 1;
322 if (fodInfos->ofnInfos.lpstrFilter)
323 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrFilter));
324 if (fodInfos->ofnInfos.lpTemplateName)
325 MemFree((LPVOID)(fodInfos->ofnInfos.lpTemplateName));
326 if (fodInfos->ofnInfos.lpstrDefExt)
327 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrDefExt));
328 if (fodInfos->ofnInfos.lpstrTitle)
329 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrTitle));
330 if (fodInfos->ofnInfos.lpstrInitialDir)
331 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrInitialDir));
332 if (fodInfos->ofnInfos.lpstrCustomFilter)
333 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrCustomFilter));
335 if (fodInfos->ofnInfos.lpstrFile)
337 strcpy(ofn->lpstrFile,fodInfos->ofnInfos.lpstrFile);
338 MemFree((LPVOID)fodInfos->ofnInfos.lpstrFile);
340 if (fodInfos->ofnInfos.lpstrFileTitle)
342 if (ofn->lpstrFileTitle)
343 strcpy(ofn->lpstrFileTitle,
344 fodInfos->ofnInfos.lpstrFileTitle);
345 MemFree((LPVOID)fodInfos->ofnInfos.lpstrFileTitle);
348 MemFree((LPVOID)(fodInfos));
352 /***********************************************************************
355 * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
356 * Call GetFileName95 with this structure and clean the memory.
358 * IN : The OPENFILENAMEW initialisation structure passed to
359 * GetOpenFileNameW win api function (see filedlg.c)
361 BOOL WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
364 FileOpenDlgInfos *fodInfos;
366 /* Initialise FileOpenDlgInfos structure*/
367 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
368 memset(&fodInfos->ofnInfos,'\0',sizeof(*ofn));
369 fodInfos->ofnInfos.lStructSize = sizeof(*ofn);
370 fodInfos->ofnInfos.hwndOwner = ofn->hwndOwner;
371 fodInfos->ofnInfos.hInstance = MapHModuleLS(ofn->hInstance);
372 if (ofn->lpstrFilter)
378 /* filter is a list... title\0ext\0......\0\0 */
379 s = (LPWSTR)ofn->lpstrFilter;
384 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
385 x = y = (LPSTR)MemAlloc(n);
386 s = (LPWSTR)ofn->lpstrFilter;
393 fodInfos->ofnInfos.lpstrFilter = (LPSTR)y;
395 if (ofn->lpstrCustomFilter) {
400 /* filter is a list... title\0ext\0......\0\0 */
401 s = (LPWSTR)ofn->lpstrCustomFilter;
405 n = s - ofn->lpstrCustomFilter;
406 x = y = (LPSTR)MemAlloc(n);
407 s = (LPWSTR)ofn->lpstrCustomFilter;
414 fodInfos->ofnInfos.lpstrCustomFilter = (LPSTR)y;
416 fodInfos->ofnInfos.nMaxCustFilter = ofn->nMaxCustFilter;
417 fodInfos->ofnInfos.nFilterIndex = ofn->nFilterIndex;
419 fodInfos->ofnInfos.lpstrFile = (LPSTR)MemAlloc(ofn->nMaxFile);
420 fodInfos->ofnInfos.nMaxFile = ofn->nMaxFile;
421 fodInfos->ofnInfos.nMaxFileTitle = ofn->nMaxFileTitle;
422 if (ofn->nMaxFileTitle)
423 fodInfos->ofnInfos.lpstrFileTitle = (LPSTR)MemAlloc(ofn->nMaxFileTitle);
424 if (ofn->lpstrInitialDir)
426 fodInfos->ofnInfos.lpstrInitialDir = (LPSTR)MemAlloc(lstrlenW(ofn->lpstrInitialDir)+1);
427 lstrcpyWtoA((LPSTR)fodInfos->ofnInfos.lpstrInitialDir,ofn->lpstrInitialDir);
431 fodInfos->ofnInfos.lpstrTitle = (LPSTR)MemAlloc(lstrlenW(ofn->lpstrTitle)+1);
432 lstrcpyWtoA((LPSTR)fodInfos->ofnInfos.lpstrTitle,ofn->lpstrTitle);
434 fodInfos->ofnInfos.Flags = ofn->Flags|OFN_WINE|OFN_UNICODE;
435 fodInfos->ofnInfos.nFileOffset = ofn->nFileOffset;
436 fodInfos->ofnInfos.nFileExtension = ofn->nFileExtension;
437 if (ofn->lpstrDefExt)
439 fodInfos->ofnInfos.lpstrDefExt = (LPSTR)MemAlloc(lstrlenW(ofn->lpstrDefExt)+1);
440 lstrcpyWtoA((LPSTR)fodInfos->ofnInfos.lpstrDefExt,ofn->lpstrDefExt);
442 fodInfos->ofnInfos.lCustData = ofn->lCustData;
443 fodInfos->ofnInfos.lpfnHook = (LPOFNHOOKPROC)ofn->lpfnHook;
444 if (ofn->lpTemplateName)
446 fodInfos->ofnInfos.lpTemplateName = (LPSTR)MemAlloc(lstrlenW(ofn->lpTemplateName)+1);
447 lstrcpyWtoA((LPSTR)fodInfos->ofnInfos.lpTemplateName,ofn->lpTemplateName);
449 /* Initialise the dialog property */
450 fodInfos->DlgInfos.dwDlgProp = 0;
455 ret = GetFileName95(fodInfos);
458 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
459 ret = GetFileName95(fodInfos);
466 ofn->nFileOffset = fodInfos->ofnInfos.nFileOffset;
467 ofn->nFileExtension = fodInfos->ofnInfos.nFileExtension;
470 Transfer the combo index in the OPENFILENAME structure;
471 No support for custom filters, so nFilterIndex must be one-based.
473 ofn->nFilterIndex = fodInfos->ofnInfos.nFilterIndex + 1;
475 if (fodInfos->ofnInfos.lpstrFilter)
476 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrFilter));
477 if (fodInfos->ofnInfos.lpTemplateName)
478 MemFree((LPVOID)(fodInfos->ofnInfos.lpTemplateName));
479 if (fodInfos->ofnInfos.lpstrDefExt)
480 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrDefExt));
481 if (fodInfos->ofnInfos.lpstrTitle)
482 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrTitle));
483 if (fodInfos->ofnInfos.lpstrInitialDir)
484 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrInitialDir));
485 if (fodInfos->ofnInfos.lpstrCustomFilter)
486 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrCustomFilter));
488 if (fodInfos->ofnInfos.lpstrFile) {
489 lstrcpyAtoW(ofn->lpstrFile,(fodInfos->ofnInfos.lpstrFile));
490 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrFile));
493 if (fodInfos->ofnInfos.lpstrFileTitle) {
494 if (ofn->lpstrFileTitle)
495 lstrcpyAtoW(ofn->lpstrFileTitle,
496 (fodInfos->ofnInfos.lpstrFileTitle));
497 MemFree((LPVOID)(fodInfos->ofnInfos.lpstrFileTitle));
499 MemFree((LPVOID)(fodInfos));
504 void ArrangeCtrlPositions( HWND hwndChildDlg, HWND hwndParentDlg)
507 HWND hwndChild,hwndStc32;
508 RECT rectParent, rectChild, rectCtrl, rectStc32, rectTemp;
511 POINT ptParentClient;
513 ptMoveCtl.x = ptMoveCtl.y = 0;
514 hwndStc32=GetDlgItem(hwndChildDlg,stc32);
515 GetClientRect(hwndParentDlg,&rectParent);
516 GetClientRect(hwndChildDlg,&rectChild);
519 GetWindowRect(hwndStc32,&rectStc32);
520 MapWindowPoints(0, hwndChildDlg,(LPPOINT)&rectStc32,2);
521 CopyRect(&rectTemp,&rectStc32);
523 SetRect(&rectStc32,rectStc32.left,rectStc32.top,rectStc32.left + (rectParent.right-rectParent.left),rectStc32.top+(rectParent.bottom-rectParent.top));
524 SetWindowPos(hwndStc32,0,rectStc32.left,rectStc32.top,rectStc32.right-rectStc32.left,rectStc32.bottom-rectStc32.top,SWP_NOMOVE|SWP_NOZORDER | SWP_NOACTIVATE);
526 if(rectStc32.right < rectTemp.right)
528 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
533 ptMoveCtl.x = (rectStc32.right - rectTemp.right);
534 ptParentClient.x = max((rectParent.right-rectParent.left),((rectChild.right-rectChild.left)+rectStc32.right-rectTemp.right));
536 if(rectStc32.bottom < rectTemp.bottom)
538 ptParentClient.y = max((rectParent.bottom-rectParent.top),(rectChild.bottom-rectChild.top));
543 ptMoveCtl.y = (rectStc32.bottom - rectTemp.bottom);
544 ptParentClient.y = max((rectParent.bottom-rectParent.top),((rectChild.bottom-rectChild.top)+rectStc32.bottom-rectTemp.bottom));
549 if( (GetWindow(hwndChildDlg,GW_CHILD)) == (HWND) NULL)
551 ptParentClient.x = rectParent.right-rectParent.left;
552 ptParentClient.y = (rectParent.bottom-rectParent.top) + (rectChild.bottom-rectChild.top);
553 ptMoveCtl.y = rectParent.bottom-rectParent.top;
556 SetRect(&rectParent,rectParent.left,rectParent.top,rectParent.left+ptParentClient.x,rectParent.top+ptParentClient.y);
557 AdjustWindowRectEx( &rectParent,GetWindowLongA(hwndParentDlg,GWL_STYLE),FALSE,GetWindowLongA(hwndParentDlg,GWL_EXSTYLE));
559 SetWindowPos(hwndChildDlg, 0, 0,0, ptParentClient.x,ptParentClient.y,
561 SetWindowPos(hwndParentDlg, 0, rectParent.left,rectParent.top, (rectParent.right- rectParent.left),
562 (rectParent.bottom-rectParent.top),SWP_NOMOVE | SWP_NOZORDER);
564 hwndChild = GetWindow(hwndChildDlg,GW_CHILD);
565 handle = BeginDeferWindowPos( 1 );
568 GetWindowRect(hwndStc32,&rectStc32);
569 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
572 SetRect(&rectStc32,0,0,0,0);
574 if (hwndChild && handle)
578 if(hwndChild != hwndStc32)
580 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
582 GetWindowRect(hwndChild,&rectCtrl);
583 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
586 Check the initial position of the controls relative to the initial
587 position and size of stc32 (before it is expanded).
589 if (rectCtrl.left > rectTemp.right && rectCtrl.top > rectTemp.bottom)
591 rectCtrl.left += ptMoveCtl.x;
592 rectCtrl.top += ptMoveCtl.y;
594 else if (rectCtrl.left > rectTemp.right)
595 rectCtrl.left += ptMoveCtl.x;
596 else if (rectCtrl.top > rectTemp.bottom)
597 rectCtrl.top += ptMoveCtl.y;
599 handle = DeferWindowPos(handle, hwndChild, 0, rectCtrl.left, rectCtrl.top,
600 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
601 SWP_NOSIZE | SWP_NOZORDER );
604 while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL && handle);
607 EndDeferWindowPos( handle );
608 handle = BeginDeferWindowPos( 1 );
609 hwndChild = GetWindow(hwndParentDlg,GW_CHILD);
613 GetWindowRect(hwndStc32,&rectStc32);
614 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
615 ptMoveCtl.x = rectStc32.left - 0;
616 ptMoveCtl.y = rectStc32.top - 0;
617 if (hwndChild && handle)
621 if(hwndChild != hwndChildDlg)
624 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
626 GetWindowRect(hwndChild,&rectCtrl);
627 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
629 rectCtrl.left += ptMoveCtl.x;
630 rectCtrl.top += ptMoveCtl.y;
632 handle = DeferWindowPos( handle, hwndChild, 0, rectCtrl.left, rectCtrl.top,
633 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
634 SWP_NOSIZE |SWP_NOZORDER );
637 while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
640 EndDeferWindowPos( handle );
646 HRESULT WINAPI FileOpenDlgProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
648 static WNDPROC procUserHook=NULL;
653 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *)lParam;
655 lParam = (LPARAM) &fodInfos->ofnInfos;
656 ArrangeCtrlPositions(hwnd,GetParent(hwnd));
657 if(fodInfos->ofnInfos.Flags & OFN_ENABLEHOOK)
658 procUserHook = (WNDPROC) fodInfos->ofnInfos.lpfnHook;
660 return CallWindowProcA(procUserHook,hwnd,uMsg,wParam,lParam);
664 return CallWindowProcA(procUserHook,hwnd,uMsg,wParam,lParam);
665 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
668 HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos,HWND hwnd)
674 if (fodInfos->ofnInfos.Flags & OFN_ENABLETEMPLATE || fodInfos->ofnInfos.Flags & OFN_ENABLETEMPLATEHANDLE)
676 if (fodInfos->ofnInfos.Flags & OFN_ENABLETEMPLATEHANDLE)
678 if( !(template = LockResource( fodInfos->ofnInfos.hInstance)))
680 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
687 if (!(hRes = FindResourceA(MapHModuleSL(fodInfos->ofnInfos.hInstance),
688 (fodInfos->ofnInfos.lpTemplateName), RT_DIALOGA)))
690 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
693 if (!(hDlgTmpl = LoadResource( MapHModuleSL(fodInfos->ofnInfos.hInstance),
695 !(template = LockResource( hDlgTmpl )))
697 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
702 hChildDlg= CreateDialogIndirectParamA(fodInfos->ofnInfos.hInstance,template,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
705 ShowWindow(hChildDlg,SW_SHOW);
709 else if(fodInfos->ofnInfos.Flags & OFN_ENABLEHOOK && fodInfos->ofnInfos.lpfnHook)
713 GetClientRect(hwnd,&rectHwnd);
714 tmplate.style = WS_CHILD | WS_CLIPSIBLINGS;
715 tmplate.dwExtendedStyle = 0;
719 tmplate.cx = rectHwnd.right-rectHwnd.left;
720 tmplate.cy = rectHwnd.bottom-rectHwnd.top;
722 return CreateDialogIndirectParamA(fodInfos->ofnInfos.hInstance,&tmplate,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
727 /***********************************************************************
728 * SendCustomDlgNotificationMessage
730 * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
733 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
735 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndParentDlg,FileOpenDlgInfosStr);
738 if(fodInfos->DlgInfos.hwndCustomDlg)
741 ofnNotify.hdr.hwndFrom=hwndParentDlg;
742 ofnNotify.hdr.idFrom=0;
743 ofnNotify.hdr.code = uCode;
744 ofnNotify.lpOFN = &fodInfos->ofnInfos;
745 return SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);
750 /***********************************************************************
751 * FILEDLG95_HandleCustomDialogMessages
753 * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
755 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
758 char lpstrCurrentDir[MAX_PATH]="";
759 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
764 case CDM_GETFILEPATH:
766 char lpstrPathSpec[MAX_PATH]="";
767 GetDlgItemTextA(hwnd,IDC_FILENAME,(LPSTR)lParam, (int)wParam);
768 lpstrFileSpec = (LPSTR)COMDLG32_PathFindFilenameA((LPSTR)lParam);
769 strcpy(lpstrPathSpec,(LPSTR)lParam);
770 COMDLG32_PathRemoveFileSpecA(lpstrPathSpec);
771 if(!lpstrPathSpec[0])
772 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,
774 strcat(lpstrPathSpec,"\\");
775 strcat(lpstrPathSpec,(LPSTR)lParam);
776 strcpy((LPSTR)lParam,(LPSTR)lpstrPathSpec);
779 case CDM_GETFOLDERPATH:
784 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,
786 strncpy((LPSTR)lParam,lpstrCurrentDir,(int)wParam);
795 GetDlgItemTextA(hwnd,IDC_FILENAME,(LPSTR)lParam, (int)wParam);
796 lpstrFileSpec = (LPSTR)COMDLG32_PathFindFilenameA((LPSTR)lParam);
798 strcpy((LPSTR)lParam, lpstrFileSpec);
803 case CDM_HIDECONTROL:
804 case CDM_SETCONTROLTEXT:
806 FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");
812 /***********************************************************************
815 * File open dialog procedure
817 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
823 ((FileOpenDlgInfos *)lParam)->DlgInfos.hwndCustomDlg =
824 CreateTemplateDialog((FileOpenDlgInfos *)lParam,hwnd);
825 FILEDLG95_OnWMInitDialog(hwnd, wParam, lParam);
826 SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE);
829 return FILEDLG95_OnWMCommand(hwnd, wParam, lParam);
832 switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
835 FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT) lParam);
841 case WM_GETISHELLBROWSER:
842 return FILEDLG95_OnWMGetIShellBrowser(hwnd);
845 RemovePropA(hwnd, FileOpenDlgInfosStr);
848 if(uMsg >= CDM_FIRST && uMsg <= CDM_LAST)
849 return FILEDLG95_HandleCustomDialogMessages(hwnd, uMsg, wParam, lParam);
854 /***********************************************************************
855 * FILEDLG95_OnWMInitDialog
857 * WM_INITDIALOG message handler
859 static LRESULT FILEDLG95_OnWMInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
861 LPITEMIDLIST pidlItemId;
862 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) lParam;
866 /* Adds the FileOpenDlgInfos in the property list of the dialog
867 so it will be easily accessible through a GetPropA(...) */
868 SetPropA(hwnd, FileOpenDlgInfosStr, (HANDLE) fodInfos);
870 /* Make sure the common control DLL is loaded */
871 InitCommonControls();
873 /* Initialise shell objects */
874 FILEDLG95_SHELL_Init(hwnd);
876 /* Initialise dialog UI */
877 FILEDLG95_InitUI(hwnd);
879 /* Initialize the Look In combo box*/
880 FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB);
882 /* Initialize the filter combo box */
883 FILEDLG95_FILETYPE_Init(hwnd);
885 /* Get the initial directory pidl */
887 if(!(pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,fodInfos->ofnInfos.lpstrInitialDir)))
891 GetCurrentDirectoryA(MAX_PATH,path);
892 pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,
897 /* Browse to the initial directory */
898 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,pidlItemId,SBSP_RELATIVE);
900 /* Free pidlItem memory */
901 COMDLG32_SHFree(pidlItemId);
905 /***********************************************************************
908 * Regroups all the cleaning functions of the filedlg
910 void FILEDLG95_Clean(HWND hwnd)
912 FILEDLG95_FILETYPE_Clean(hwnd);
913 FILEDLG95_LOOKIN_Clean(hwnd);
914 FILEDLG95_SHELL_Clean(hwnd);
916 /***********************************************************************
917 * FILEDLG95_OnWMCommand
919 * WM_COMMAND message handler
921 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
923 WORD wNotifyCode = HIWORD(wParam); /* notification code */
924 WORD wID = LOWORD(wParam); /* item, control, or accelerator identifier */
925 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
931 if(FILEDLG95_OnOpen(hwnd))
932 SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK);
936 FILEDLG95_Clean(hwnd);
937 EndDialog(hwnd, FALSE);
939 /* Filetype combo box */
941 FILEDLG95_FILETYPE_OnCommand(hwnd,wNotifyCode);
942 SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
944 /* LookIn combo box */
946 FILEDLG95_LOOKIN_OnCommand(hwnd,wNotifyCode);
949 /* --- toolbar --- */
950 /* Up folder button */
951 case FCIDM_TB_UPFOLDER:
952 FILEDLG95_SHELL_UpFolder(hwnd);
954 /* New folder button */
955 case FCIDM_TB_NEWFOLDER:
956 FILEDLG95_SHELL_NewFolder(hwnd);
958 /* List option button */
959 case FCIDM_TB_SMALLICON:
960 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWLIST);
962 /* Details option button */
963 case FCIDM_TB_REPORTVIEW:
964 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWDETAILS);
971 /* Do not use the listview selection anymore */
972 fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
976 /***********************************************************************
977 * FILEDLG95_OnWMGetIShellBrowser
979 * WM_GETISHELLBROWSER message handler
981 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd)
984 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
988 SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)fodInfos->Shell.FOIShellBrowser);
994 /***********************************************************************
998 static LRESULT FILEDLG95_InitUI(HWND hwnd)
1001 {{VIEW_PARENTFOLDER, FCIDM_TB_UPFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
1002 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
1003 {VIEW_NEWFOLDER, FCIDM_TB_NEWFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
1004 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
1005 {VIEW_LIST, FCIDM_TB_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
1006 {VIEW_DETAILS, FCIDM_TB_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
1010 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1012 TRACE("%p\n", fodInfos);
1014 /* Get the hwnd of the controls */
1015 fodInfos->DlgInfos.hwndFileName = GetDlgItem(hwnd,IDC_FILENAME);
1016 fodInfos->DlgInfos.hwndFileTypeCB = GetDlgItem(hwnd,IDC_FILETYPE);
1017 fodInfos->DlgInfos.hwndLookInCB = GetDlgItem(hwnd,IDC_LOOKIN);
1019 /* construct the toolbar */
1020 GetWindowRect(GetDlgItem(hwnd,IDC_TOOLBARSTATIC),&rectTB);
1021 MapWindowPoints( 0, hwnd,(LPPOINT)&rectTB,2);
1023 fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, (LPSTR) NULL,
1024 WS_CHILD | WS_GROUP | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE,
1026 hwnd, (HMENU) IDC_TOOLBAR, COMMDLG_hInstance32, NULL);
1028 SetWindowPos(fodInfos->DlgInfos.hwndTB, 0,
1029 rectTB.left,rectTB.top, rectTB.right-rectTB.left, rectTB.bottom-rectTB.top,
1030 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
1032 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
1033 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);
1034 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSA, (WPARAM) 6,(LPARAM) &tbb);
1035 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_AUTOSIZE, 0, 0);
1037 /* Set the window text with the text specified in the OPENFILENAME structure */
1038 if(fodInfos->ofnInfos.lpstrTitle)
1040 SetWindowTextA(hwnd,fodInfos->ofnInfos.lpstrTitle);
1042 else if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
1044 SetWindowTextA(hwnd,"Save");
1047 /* Initialise the file name edit control */
1048 if(strlen(fodInfos->ofnInfos.lpstrFile))
1050 SetDlgItemTextA(hwnd,IDC_FILENAME,fodInfos->ofnInfos.lpstrFile);
1052 /* Must the open as read only check box be checked ?*/
1053 if(fodInfos->ofnInfos.Flags & OFN_READONLY)
1055 SendDlgItemMessageA(hwnd,IDC_OPENREADONLY,BM_SETCHECK,(WPARAM)TRUE,0);
1057 /* Must the open as read only check box be hid ?*/
1058 if(fodInfos->ofnInfos.Flags & OFN_HIDEREADONLY)
1060 ShowWindow(GetDlgItem(hwnd,IDC_OPENREADONLY),SW_HIDE);
1062 /* change Open to Save */
1063 if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
1065 SetDlgItemTextA(hwnd,IDOK,"Save");
1070 /***********************************************************************
1073 * Ok button WM_COMMAND message handler
1075 * If the function succeeds, the return value is nonzero.
1077 BOOL FILEDLG95_OnOpen(HWND hwnd)
1079 char lpstrSpecifiedByUser[MAX_PATH] = "";
1080 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1081 LPITEMIDLIST pidlSelection;
1085 /* Check if there is a selected item in the listview */
1086 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_USEVIEW)
1088 pidlSelection = GetSelectedPidl(fodInfos->Shell.FOIShellView);
1089 GetName(fodInfos->Shell.FOIShellFolder,pidlSelection,SHGDN_NORMAL,lpstrSpecifiedByUser);
1090 COMDLG32_SHFree((LPVOID)pidlSelection);
1093 /* Get the text from the filename edit */
1094 GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrSpecifiedByUser,MAX_PATH);
1096 if(strlen(lpstrSpecifiedByUser))
1098 LPSHELLFOLDER psfDesktop;
1099 LPITEMIDLIST browsePidl;
1100 LPSTR lpstrFileSpec;
1102 char lpstrPathSpec[MAX_PATH] = "";
1103 char lpstrCurrentDir[MAX_PATH] = "";
1104 char lpstrPathAndFile[MAX_PATH] = "";
1106 /* Separate the file spec from the path spec
1108 lpstrSpecifiedByUser lpstrPathSpec lpstrFileSpec
1109 C:\TEXT1\TEXT2 C:\TEXT1 TEXT2
1111 lpstrFileSpec = (LPSTR)COMDLG32_PathFindFilenameA(lpstrSpecifiedByUser);
1112 strcpy(lpstrPathSpec,lpstrSpecifiedByUser);
1113 COMDLG32_PathRemoveFileSpecA(lpstrPathSpec);
1115 /* Get the index of the selected item in the filetype combo box */
1116 fodInfos->ofnInfos.nFilterIndex = (DWORD) CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1118 /* Get the current directory name */
1119 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,
1122 /* Create an absolute path name */
1123 if(lpstrSpecifiedByUser[1] != ':')
1125 switch(lpstrSpecifiedByUser[0])
1127 /* Add drive spec \TEXT => C:\TEXT */
1131 char lpstrTmp[MAX_PATH] = "";
1132 if(!strlen(lpstrPathSpec))
1134 strncpy(lpstrTmp,lpstrCurrentDir,iCopy);
1135 strcat(lpstrTmp,lpstrPathSpec);
1136 strcpy(lpstrPathSpec,lpstrTmp);
1139 /* Go to parent ..\TEXT */
1143 char lpstrTmp2[MAX_PATH] = "";
1144 LPSTR lpstrTmp = strrchr(lpstrCurrentDir,'\\');
1145 iSize = lpstrTmp - lpstrCurrentDir;
1146 strncpy(lpstrTmp2,lpstrCurrentDir,iSize + 1);
1147 if(strlen(lpstrSpecifiedByUser) <= 3)
1148 strcpy(lpstrFileSpec,"");
1149 if(strcmp(lpstrPathSpec,".."))
1150 strcat(lpstrTmp2,&lpstrPathSpec[3]);
1151 strcpy(lpstrPathSpec,lpstrTmp2);
1156 char lpstrTmp[MAX_PATH] = "";
1157 if(strcmp(&lpstrCurrentDir[strlen(lpstrCurrentDir)-1],"\\"))
1158 strcat(lpstrCurrentDir,"\\");
1159 strcpy(lpstrTmp,lpstrCurrentDir);
1160 strcat(lpstrTmp,lpstrPathSpec);
1161 strcpy(lpstrPathSpec,lpstrTmp);
1167 if(strlen(lpstrPathSpec))
1169 /* Browse to the right directory */
1170 COMDLG32_SHGetDesktopFolder(&psfDesktop);
1171 if((browsePidl = GetPidlFromName(psfDesktop,lpstrPathSpec)))
1173 /* Browse to directory */
1174 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1177 COMDLG32_SHFree(browsePidl);
1181 /* Path does not exist */
1182 if(fodInfos->ofnInfos.Flags & OFN_PATHMUSTEXIST)
1185 "Path does not exist",
1186 fodInfos->ofnInfos.lpstrTitle,
1187 MB_OK | MB_ICONEXCLAMATION);
1192 strcat(lpstrPathAndFile,lpstrPathSpec);
1193 IShellFolder_Release(psfDesktop);
1197 strcat(lpstrPathAndFile,lpstrCurrentDir);
1200 /* Create the path and file string */
1201 COMDLG32_PathAddBackslashA(lpstrPathAndFile);
1202 strcat(lpstrPathAndFile,lpstrFileSpec);
1204 /* Update the edit field */
1205 SetDlgItemTextA(hwnd,IDC_FILENAME,lpstrFileSpec);
1206 SendDlgItemMessageA(hwnd,IDC_FILENAME,EM_SETSEL,0,-1);
1208 /* Don't go further if we dont have a file spec */
1209 if(!strlen(lpstrFileSpec) || !strcmp(lpstrFileSpec,lpstrPathSpec))
1212 /* Time to check lpstrFileSpec */
1213 /* search => contains * or ? */
1214 /* browse => contains a directory name */
1215 /* file => contains a file name */
1217 /* Check if this is a search */
1218 if(strchr(lpstrFileSpec,'*') || strchr(lpstrFileSpec,'?'))
1222 /* Set the current filter with the current selection */
1223 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1224 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1226 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFileSpec)+1)*2);
1227 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,
1228 (LPSTR)strlwr((LPSTR)lpstrFileSpec));
1230 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1232 if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB,
1234 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1239 /* browse if the user specified a directory */
1240 if((browsePidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder,
1243 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
1245 char lpstrFileExist[MAX_PATH + 50];
1247 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder,
1252 /* The file does exist, so ask the user if we should overwrite it */
1253 if(fodInfos->ofnInfos.Flags & OFN_OVERWRITEPROMPT)
1255 strcpy(lpstrFileExist, lpstrFileSpec);
1256 strcat(lpstrFileExist, " already exists.\nDo you want to replace it?");
1258 nMsgBoxRet = MessageBoxA(hwnd,
1260 fodInfos->ofnInfos.lpstrTitle,
1261 MB_YESNO | MB_ICONEXCLAMATION);
1262 if(nMsgBoxRet == IDNO) return FALSE;
1265 /* Browse to directory */
1268 if(FAILED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1272 if(fodInfos->ofnInfos.Flags & OFN_PATHMUSTEXIST)
1275 "Path does not exist",
1276 fodInfos->ofnInfos.lpstrTitle,
1277 MB_OK | MB_ICONEXCLAMATION);
1278 COMDLG32_SHFree(browsePidl);
1282 COMDLG32_SHFree(browsePidl);
1285 COMDLG32_SHFree(browsePidl);
1289 /* File does not exist in current directory */
1291 /* The selected file does not exist */
1292 /* Tell the user the selected does not exist */
1293 if(fodInfos->ofnInfos.Flags & OFN_FILEMUSTEXIST)
1295 char lpstrNotFound[100];
1299 LoadStringA(COMMDLG_hInstance32,
1303 LoadStringA(COMMDLG_hInstance32,
1308 strcpy(tmp,fodInfos->ofnInfos.lpstrFile);
1310 strcat(tmp,lpstrNotFound);
1312 strcat(tmp,lpstrMsg);
1316 fodInfos->ofnInfos.lpstrTitle,
1317 MB_OK | MB_ICONEXCLAMATION);
1320 /* Ask the user if he wants to create the file*/
1321 if(fodInfos->ofnInfos.Flags & OFN_CREATEPROMPT)
1325 LoadStringA(COMMDLG_hInstance32,IDS_CREATEFILE,tmp,100);
1327 if(IDYES == MessageBoxA(hwnd,tmp,fodInfos->ofnInfos.lpstrTitle,
1328 MB_YESNO | MB_ICONQUESTION))
1330 /* Create the file, clean and exit */
1331 FILEDLG95_Clean(hwnd);
1332 return EndDialog(hwnd,TRUE);
1338 /* Open the selected file */
1340 /* Check file extension */
1341 if(!strrchr(lpstrPathAndFile,'.'))
1343 /* if the file has no extension, append the selected
1344 extension of the filetype combo box */
1347 iExt = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1348 lpstrTemp = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iExt);
1350 if((lpstrExt = strchr(lpstrTemp,';')))
1352 int i = lpstrExt - lpstrTemp;
1353 lpstrExt = MemAlloc(i);
1354 strncpy(lpstrExt,&lpstrTemp[1],i-1);
1358 lpstrExt = MemAlloc(strlen(lpstrTemp));
1359 strcpy(lpstrExt,&lpstrTemp[1]);
1362 if(!strcmp(&lpstrExt[1],"*") && fodInfos->ofnInfos.lpstrDefExt)
1364 lpstrExt = MemAlloc(strlen(fodInfos->ofnInfos.lpstrDefExt)+2);
1365 strcat(lpstrExt,".");
1366 strcat(lpstrExt,(LPSTR) fodInfos->ofnInfos.lpstrDefExt);
1368 strcat(lpstrPathAndFile,lpstrExt);
1370 /* Check that size size of the file does not exceed buffer size */
1371 if(strlen(lpstrPathAndFile) > fodInfos->ofnInfos.nMaxFile)
1373 /* set error FNERR_BUFFERTOSMALL */
1374 FILEDLG95_Clean(hwnd);
1375 return EndDialog(hwnd,FALSE);
1377 strcpy(fodInfos->ofnInfos.lpstrFile,lpstrPathAndFile);
1379 /* Set the lpstrFileTitle of the OPENFILENAME structure */
1380 if(fodInfos->ofnInfos.lpstrFileTitle)
1381 strncpy(fodInfos->ofnInfos.lpstrFileTitle,
1383 fodInfos->ofnInfos.nMaxFileTitle);
1385 /* Check if the file is to be opened as read only */
1386 if(BST_CHECKED == SendDlgItemMessageA(hwnd,
1389 SetFileAttributesA(fodInfos->ofnInfos.lpstrFile,
1390 FILE_ATTRIBUTE_READONLY);
1392 /* nFileExtension and nFileOffset of OPENFILENAME structure */
1393 lpstrTemp = strrchr(fodInfos->ofnInfos.lpstrFile,'\\');
1394 fodInfos->ofnInfos.nFileOffset = lpstrTemp - fodInfos->ofnInfos.lpstrFile + 1;
1395 lpstrTemp = strrchr(fodInfos->ofnInfos.lpstrFile,'.');
1396 fodInfos->ofnInfos.nFileExtension = lpstrTemp - fodInfos->ofnInfos.lpstrFile + 1;
1399 /* clean and exit */
1400 FILEDLG95_Clean(hwnd);
1401 return EndDialog(hwnd,TRUE);
1407 /***********************************************************************
1408 * FILEDLG95_SHELL_Init
1410 * Initialisation of the shell objects
1412 static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
1414 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1419 * Initialisation of the FileOpenDialogInfos structure
1424 fodInfos->Shell.FOIShellView = NULL;
1425 if(FAILED(COMDLG32_SHGetDesktopFolder(&fodInfos->Shell.FOIShellFolder)))
1429 fodInfos->ShellInfos.hwndOwner = hwnd;
1431 fodInfos->ShellInfos.folderSettings.fFlags = FWF_AUTOARRANGE | FWF_ALIGNLEFT;
1432 fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
1434 GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
1435 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
1436 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
1438 /* Construct the IShellBrowser interface */
1439 fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
1444 /***********************************************************************
1445 * FILEDLG95_SHELL_ExecuteCommand
1447 * Change the folder option and refresh the view
1448 * If the function succeeds, the return value is nonzero.
1450 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
1452 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1455 CMINVOKECOMMANDINFO ci;
1458 if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
1463 ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
1467 IContextMenu_InvokeCommand(pcm, &ci);
1468 IContextMenu_Release(pcm);
1474 /***********************************************************************
1475 * FILEDLG95_SHELL_UpFolder
1477 * Browse to the specified object
1478 * If the function succeeds, the return value is nonzero.
1480 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
1482 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1486 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1495 /***********************************************************************
1496 * FILEDLG95_SHELL_NewFolder
1498 * Creates a new directory with New folder as name
1499 * If the function succeeds, the return value is nonzero.
1500 * FIXME: let the contextmenu (CMDSTR_NEWFOLDER) do this thing
1502 static BOOL FILEDLG95_SHELL_NewFolder(HWND hwnd)
1504 char lpstrDirName[MAX_PATH] = "New folder";
1506 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1510 if((bRes = CreateDirectoryA(lpstrDirName,NULL)))
1512 LPITEMIDLIST pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder,lpstrDirName);
1513 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1514 IShellView_SelectItem(fodInfos->Shell.FOIShellView,
1516 (SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
1517 |SVSI_FOCUSED|SVSI_SELECT));
1525 /***********************************************************************
1526 * FILEDLG95_SHELL_Clean
1528 * Cleans the memory used by shell objects
1530 static void FILEDLG95_SHELL_Clean(HWND hwnd)
1532 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1536 /* clean Shell interfaces */
1537 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
1538 IShellView_Release(fodInfos->Shell.FOIShellView);
1539 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
1540 IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
1543 /***********************************************************************
1544 * FILEDLG95_FILETYPE_Init
1546 * Initialisation of the file type combo box
1548 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
1550 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1554 if(fodInfos->ofnInfos.lpstrFilter)
1563 /* filter is a list... title\0ext\0......\0\0 */
1564 /* Set the combo item text to the title and the item data
1566 char *lpstrExt = NULL;
1567 LPSTR lpstrExtTmp = NULL;
1569 lpstrTmp = (&((LPBYTE)fodInfos->ofnInfos.lpstrFilter)[iStrIndex]);
1570 if(!strlen(lpstrTmp))
1572 iStrIndex += strlen(lpstrTmp) +1;
1573 /* Get the extension */
1574 lpstrExtTmp = (&((LPBYTE)fodInfos->ofnInfos.lpstrFilter)[iStrIndex]);
1578 lpstrExt = (LPSTR) MemAlloc(strlen(lpstrExtTmp)+1);
1582 strcpy(lpstrExt,lpstrExtTmp);
1584 iStrIndex += strlen(lpstrExt) +1;
1586 /* Add the item at the end of the combo */
1587 CBAddString(fodInfos->DlgInfos.hwndFileTypeCB,lpstrTmp);
1588 CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos++,lpstrExt);
1590 /* Set the current filter to the one specified
1591 in the initialisation structure */
1592 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB,
1593 fodInfos->ofnInfos.nFilterIndex);
1595 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1596 fodInfos->ofnInfos.nFilterIndex);
1599 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
1600 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,strlwr(lpstrFilter));
1606 /***********************************************************************
1607 * FILEDLG95_FILETYPE_OnCommand
1609 * WM_COMMAND of the file type combo box
1610 * If the function succeeds, the return value is nonzero.
1612 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
1614 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1622 /* Get the current item of the filetype combo box */
1623 int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1625 /* Set the current filter with the current selection */
1626 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1627 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1629 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1633 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
1634 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,(LPSTR)strlwr((LPSTR)lpstrFilter));
1637 /* Refresh the actual view to display the included items*/
1638 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1644 /***********************************************************************
1645 * FILEDLG95_FILETYPE_SearchExt
1647 * Search for pidl in the lookin combo box
1648 * returns the index of the found item
1650 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPSTR lpstrExt)
1653 int iCount = CBGetCount(hwnd);
1659 LPSTR ext = (LPSTR) CBGetItemDataPtr(hwnd,i);
1661 if(!_stricmp(lpstrExt,ext))
1669 /***********************************************************************
1670 * FILEDLG95_FILETYPE_Clean
1672 * Clean the memory used by the filetype combo box
1674 static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
1676 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1678 int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
1682 /* Delete each string of the combo and their associated data */
1683 for(iPos = iCount-1;iPos>=0;iPos--)
1685 MemFree((LPVOID)(CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos)));
1686 CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1688 /* Current filter */
1689 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1690 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1694 /***********************************************************************
1695 * FILEDLG95_LOOKIN_Init
1697 * Initialisation of the look in combo box
1699 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
1701 IShellFolder *psfRoot, *psfDrives;
1702 IEnumIDList *lpeRoot, *lpeDrives;
1703 LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
1705 LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
1709 liInfos->iMaxIndentation = 0;
1711 SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
1712 CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
1714 /* Initialise data of Desktop folder */
1715 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
1716 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1717 COMDLG32_SHFree(pidlTmp);
1719 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
1721 COMDLG32_SHGetDesktopFolder(&psfRoot);
1725 /* enumerate the contents of the desktop */
1726 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
1728 while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
1730 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1732 /* special handling for CSIDL_DRIVES */
1733 if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
1735 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
1737 /* enumerate the drives */
1738 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
1740 while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
1742 pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
1743 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
1744 COMDLG32_SHFree(pidlAbsTmp);
1745 COMDLG32_SHFree(pidlTmp1);
1747 IEnumIDList_Release(lpeDrives);
1749 IShellFolder_Release(psfDrives);
1752 COMDLG32_SHFree(pidlTmp);
1754 IEnumIDList_Release(lpeRoot);
1758 IShellFolder_Release(psfRoot);
1759 COMDLG32_SHFree(pidlDrives);
1764 /***********************************************************************
1765 * FILEDLG95_LOOKIN_DrawItem
1767 * WM_DRAWITEM message handler
1769 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
1771 COLORREF crWin = GetSysColor(COLOR_WINDOW);
1772 COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
1773 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1777 HIMAGELIST ilItemImage;
1779 LPSFOLDER tmpFolder;
1782 LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
1786 if(pDIStruct->itemID == -1)
1789 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
1790 pDIStruct->itemID)))
1794 if(pDIStruct->itemID == liInfos->uSelectedItem)
1796 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1799 sizeof (SHFILEINFOA),
1800 SHGFI_PIDL | SHGFI_SMALLICON |
1801 SHGFI_OPENICON | SHGFI_SYSICONINDEX |
1802 SHGFI_DISPLAYNAME );
1806 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1809 sizeof (SHFILEINFOA),
1810 SHGFI_PIDL | SHGFI_SMALLICON |
1811 SHGFI_SYSICONINDEX |
1815 /* Is this item selected ?*/
1816 if(pDIStruct->itemState & ODS_SELECTED)
1818 SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
1819 SetBkColor(pDIStruct->hDC,crHighLight);
1820 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight);
1824 SetTextColor(pDIStruct->hDC,crText);
1825 SetBkColor(pDIStruct->hDC,crWin);
1826 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin);
1829 /* Do not indent item if drawing in the edit of the combo*/
1830 if(pDIStruct->itemState & ODS_COMBOBOXEDIT)
1833 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1836 sizeof (SHFILEINFOA),
1837 SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON
1838 | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME );
1843 iIndentation = tmpFolder->m_iIndent;
1845 /* Draw text and icon */
1847 /* Initialise the icon display area */
1848 rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
1849 rectIcon.top = pDIStruct->rcItem.top;
1850 rectIcon.right = rectIcon.left + ICONWIDTH;
1851 rectIcon.bottom = pDIStruct->rcItem.bottom;
1853 /* Initialise the text display area */
1854 rectText.left = rectIcon.right;
1855 rectText.top = pDIStruct->rcItem.top + YTEXTOFFSET;
1856 rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
1857 rectText.bottom = pDIStruct->rcItem.bottom;
1860 /* Draw the icon from the image list */
1861 COMDLG32_ImageList_Draw(ilItemImage,
1868 /* Draw the associated text */
1869 if(sfi.szDisplayName)
1870 TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName));
1876 /***********************************************************************
1877 * FILEDLG95_LOOKIN_OnCommand
1879 * LookIn combo box WM_COMMAND message handler
1880 * If the function succeeds, the return value is nonzero.
1882 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
1884 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1892 LPSFOLDER tmpFolder;
1895 iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
1897 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
1902 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1903 tmpFolder->pidlItem,
1915 /***********************************************************************
1916 * FILEDLG95_LOOKIN_AddItem
1918 * Adds an absolute pidl item to the lookin combo box
1919 * returns the index of the inserted item
1921 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
1923 LPITEMIDLIST pidlNext;
1925 SFOLDER *tmpFolder = MemAlloc(sizeof(SFOLDER));
1926 LookInInfos *liInfos;
1930 if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
1933 tmpFolder->m_iIndent = 0;
1938 /* Calculate the indentation of the item in the lookin*/
1940 while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
1942 tmpFolder->m_iIndent++;
1945 tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl);
1947 if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
1948 liInfos->iMaxIndentation = tmpFolder->m_iIndent;
1950 COMDLG32_SHGetFileInfoA((LPSTR)pidl,
1954 SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX
1955 | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES);
1958 if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
1961 /* Add the item at the end of the list */
1964 iItemID = CBAddString(hwnd,sfi.szDisplayName);
1966 /* Insert the item at the iInsertId position*/
1969 iItemID = CBInsertString(hwnd,sfi.szDisplayName,iInsertId);
1972 CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
1980 /***********************************************************************
1981 * FILEDLG95_LOOKIN_InsertItemAfterParent
1983 * Insert an item below its parent
1985 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
1988 LPITEMIDLIST pidlParent = GetParentPidl(pidl);
1993 iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
1997 iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
2000 /* Free pidlParent memory */
2001 COMDLG32_SHFree((LPVOID)pidlParent);
2003 return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
2006 /***********************************************************************
2007 * FILEDLG95_LOOKIN_SelectItem
2009 * Adds an absolute pidl item to the lookin combo box
2010 * returns the index of the inserted item
2012 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
2015 LookInInfos *liInfos;
2019 iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
2021 liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2025 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
2026 iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
2031 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2032 while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
2036 if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
2038 if(iRemovedItem < iItemPos)
2043 CBSetCurSel(hwnd,iItemPos);
2044 liInfos->uSelectedItem = iItemPos;
2050 /***********************************************************************
2051 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2053 * Remove the item with an expansion level over iExpansionLevel
2055 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
2059 LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2063 if(liInfos->iMaxIndentation <= 2)
2066 if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
2069 tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2070 CBDeleteString(hwnd,iItemPos);
2071 liInfos->iMaxIndentation--;
2079 /***********************************************************************
2080 * FILEDLG95_LOOKIN_SearchItem
2082 * Search for pidl in the lookin combo box
2083 * returns the index of the found item
2085 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
2088 int iCount = CBGetCount(hwnd);
2094 LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
2096 if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
2098 if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
2106 /***********************************************************************
2107 * FILEDLG95_LOOKIN_Clean
2109 * Clean the memory used by the lookin combo box
2111 static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
2113 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2115 int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
2119 /* Delete each string of the combo and their associated data */
2120 for(iPos = iCount-1;iPos>=0;iPos--)
2122 MemFree((LPVOID)(CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos)));
2123 CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
2125 /* LookInInfos structure */
2126 RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
2133 /***********************************************************************
2136 * Get the pidl's display name (relative to folder) and
2137 * put it in lpstrFileName.
2139 * Return NOERROR on success,
2143 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
2148 TRACE("%p %p\n", lpsf, pidl);
2153 COMDLG32_SHGetDesktopFolder(&lpsf);
2154 hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
2155 IShellFolder_Release(lpsf);
2159 /* Get the display name of the pidl relative to the folder */
2160 if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf,
2165 return StrRetToBufA(&str, pidl,lpstrFileName, MAX_PATH);
2170 /***********************************************************************
2171 * GetShellFolderFromPidl
2173 * pidlRel is the item pidl relative
2174 * Return the IShellFolder of the absolute pidl
2176 IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
2178 IShellFolder *psf = NULL,*psfParent;
2180 TRACE("%p\n", pidlAbs);
2182 if(SUCCEEDED(COMDLG32_SHGetDesktopFolder(&psfParent)))
2185 if(pidlAbs && pidlAbs->mkid.cb)
2187 if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
2189 IShellFolder_Release(psfParent);
2193 /* return the desktop */
2199 /***********************************************************************
2202 * Return the LPITEMIDLIST to the parent of the pidl in the list
2204 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
2206 LPITEMIDLIST pidlParent;
2208 TRACE("%p\n", pidl);
2210 pidlParent = COMDLG32_PIDL_ILClone(pidl);
2211 COMDLG32_PIDL_ILRemoveLastID(pidlParent);
2216 /***********************************************************************
2219 * returns the pidl of the file name relative to folder
2220 * NULL if an error occured
2222 LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName)
2226 wchar_t lpwstrDirName[MAX_PATH];
2229 TRACE("sf=%p file=%s\n", psf, lpcstrFileName);
2234 MultiByteToWideChar(CP_ACP,
2238 (LPWSTR)lpwstrDirName,
2241 IShellFolder_ParseDisplayName(psf, 0,
2243 (LPWSTR)lpwstrDirName,
2251 /***********************************************************************
2255 BOOL GetFileExtension(IShellFolder *psf,LPITEMIDLIST pidl,LPSTR lpstrFileExtension)
2257 char FileName[MAX_PATH];
2262 if(SUCCEEDED(GetName(psf,pidl,SHGDN_NORMAL,FileName)))
2264 if(!(pdest = strrchr( FileName, ch )))
2267 result = pdest - FileName + 1;
2268 strcpy(lpstrFileExtension,&FileName[result]);
2275 * Memory allocation methods */
2276 void *MemAlloc(UINT size)
2278 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
2281 void MemFree(void *mem)
2285 HeapFree(GetProcessHeap(),0,mem);