2 * COMMDLG - File Open Dialogs Win95 look and feel
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).
12 * FIXME: any hook gets a OPENFILENAMEA structure
14 * FIXME: CDN_FILEOK is wrong implemented, other CDN_ messages likely too
16 * FIXME: old style hook messages are not implemented (except FILEOKSTRING)
18 * FIXME: lpstrCustomFilter not handled
20 * FIXME: if the size of lpstrFile (nMaxFile) is too small the first
21 * two bytes of lpstrFile should contain the needed size
23 * FIXME: algorithm for selecting the initial directory is too simple
25 * FIXME: add to recent docs
27 * FIXME: flags not implemented: OFN_CREATEPROMPT, OFN_DONTADDTORECENT,
28 * OFN_ENABLEINCLUDENOTIFY, OFN_ENABLESIZING, OFN_EXTENSIONDIFFERENT,
29 * OFN_NODEREFERENCELINKS, OFN_NOREADONLYRETURN,
30 * OFN_NOTESTFILECREATE, OFN_OVERWRITEPROMPT, OFN_USEMONIKERS
32 * FIXME: lCustData for lpfnHook (WM_INITDIALOG)
48 #include "debugtools.h"
52 #include "filedlgbrowser.h"
54 #include "wine/obj_contextmenu.h"
56 DEFAULT_DEBUG_CHANNEL(commdlg);
58 #define UNIMPLEMENTED_FLAGS \
59 (OFN_CREATEPROMPT | OFN_DONTADDTORECENT |\
60 OFN_ENABLEINCLUDENOTIFY | OFN_ENABLESIZING | OFN_EXTENSIONDIFFERENT |\
61 OFN_NODEREFERENCELINKS | OFN_NOREADONLYRETURN |\
62 OFN_NOTESTFILECREATE | OFN_OVERWRITEPROMPT /*| OFN_USEMONIKERS*/)
64 #define IsHooked(fodInfos) \
65 ((fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook)
66 /***********************************************************************
67 * Data structure and global variables
69 typedef struct SFolder
71 int m_iImageIndex; /* Index of picture in image list */
73 int m_iIndent; /* Indentation index */
74 LPITEMIDLIST pidlItem; /* absolute pidl of the item */
78 typedef struct tagLookInInfo
85 /***********************************************************************
86 * Defines and global variables
89 /* Draw item constant */
96 /* SearchItem methods */
99 #define ITEM_NOTFOUND -1
101 /* Undefined windows message sent by CreateViewObject*/
102 #define WM_GETISHELLBROWSER WM_USER+7
105 * Those macros exist in windowsx.h. However, you can't really use them since
106 * they rely on the UNICODE defines and can't be used inside Wine itself.
109 /* Combo box macros */
110 #define CBAddString(hwnd,str) \
111 SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str);
113 #define CBInsertString(hwnd,str,pos) \
114 SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str);
116 #define CBDeleteString(hwnd,pos) \
117 SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0);
119 #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
120 SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr);
122 #define CBGetItemDataPtr(hwnd,iItemId) \
123 SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0)
125 #define CBGetLBText(hwnd,iItemId,str) \
126 SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str);
128 #define CBGetCurSel(hwnd) \
129 SendMessageA(hwnd,CB_GETCURSEL,0,0);
131 #define CBSetCurSel(hwnd,pos) \
132 SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0);
134 #define CBGetCount(hwnd) \
135 SendMessageA(hwnd,CB_GETCOUNT,0,0);
136 #define CBShowDropDown(hwnd,show) \
137 SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0);
138 #define CBSetItemHeight(hwnd,index,height) \
139 SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height);
142 const char *FileOpenDlgInfosStr = "FileOpenDlgInfos"; /* windows property description string */
143 const char *LookInInfosStr = "LookInInfos"; /* LOOKIN combo box property */
145 static const char defaultFilter[] = "*.*";
147 /***********************************************************************
151 /* Internal functions used by the dialog */
152 static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam);
153 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
154 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd);
155 BOOL FILEDLG95_OnOpen(HWND hwnd);
156 static LRESULT FILEDLG95_InitControls(HWND hwnd);
157 static void FILEDLG95_Clean(HWND hwnd);
159 /* Functions used by the shell navigation */
160 static LRESULT FILEDLG95_SHELL_Init(HWND hwnd);
161 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd);
162 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb);
163 static void FILEDLG95_SHELL_Clean(HWND hwnd);
164 static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd);
166 /* Functions used by the filetype combo box */
167 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd);
168 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode);
169 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt);
170 static void FILEDLG95_FILETYPE_Clean(HWND hwnd);
172 /* Functions used by the Look In combo box */
173 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo);
174 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);
175 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);
176 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);
177 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod);
178 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl);
179 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd);
180 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
181 static void FILEDLG95_LOOKIN_Clean(HWND hwnd);
183 /* Miscellaneous tool functions */
184 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
185 HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
186 IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
187 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
188 LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
190 /* Shell memory allocation */
191 static void *MemAlloc(UINT size);
192 static void MemFree(void *mem);
194 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos);
195 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
196 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
197 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
198 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);
199 static BOOL BrowseSelectedFolder(HWND hwnd);
201 /***********************************************************************
204 * Creates an Open common dialog box that lets the user select
205 * the drive, directory, and the name of a file or set of files to open.
207 * IN : The FileOpenDlgInfos structure associated with the dialog
208 * OUT : TRUE on success
209 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
211 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)
219 /* test for missing functionality */
220 if (fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS)
222 FIXME("Flags 0x%08lx not yet implemented\n",
223 fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS);
226 /* Create the dialog from a template */
228 if(!(hRes = FindResourceA(COMMDLG_hInstance32,MAKEINTRESOURCEA(NEWFILEOPENORD),RT_DIALOGA)))
230 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
233 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hRes )) ||
234 !(template = LockResource( hDlgTmpl )))
236 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
240 /* old style hook messages */
241 if (IsHooked(fodInfos))
243 fodInfos->HookMsg.fileokstring = RegisterWindowMessageA(FILEOKSTRINGA);
244 fodInfos->HookMsg.lbselchstring = RegisterWindowMessageA(LBSELCHSTRINGA);
245 fodInfos->HookMsg.helpmsgstring = RegisterWindowMessageA(HELPMSGSTRINGA);
246 fodInfos->HookMsg.sharevistring = RegisterWindowMessageA(SHAREVISTRINGA);
249 lRes = DialogBoxIndirectParamA(COMMDLG_hInstance32,
250 (LPDLGTEMPLATEA) template,
251 fodInfos->ofnInfos->hwndOwner,
252 (DLGPROC) FileOpenDlgProc95,
255 /* Unable to create the dialog */
262 /***********************************************************************
265 * Call GetFileName95 with this structure and clean the memory.
267 * IN : The OPENFILENAMEA initialisation structure passed to
268 * GetOpenFileNameA win api function (see filedlg.c)
270 BOOL WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
274 FileOpenDlgInfos *fodInfos;
276 LPCSTR lpstrInitialDir = (LPCSTR)-1;
277 LPSTR lpstrSavDir = NULL;
280 /* Initialise FileOpenDlgInfos structure*/
281 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
282 ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
284 /* Pass in the original ofn */
285 fodInfos->ofnInfos = ofn;
287 /* Save original hInstance value */
288 hInstance = ofn->hInstance;
289 fodInfos->ofnInfos->hInstance = MapHModuleLS(ofn->hInstance);
291 /* save current directory */
292 if (ofn->Flags & OFN_NOCHANGEDIR)
294 lpstrSavDir = MemAlloc(MAX_PATH);
295 GetCurrentDirectoryA(MAX_PATH, lpstrSavDir);
298 dwFlags = ofn->Flags;
299 ofn->Flags = ofn->Flags|OFN_WINE;
301 /* Initialise the dialog property */
302 fodInfos->DlgInfos.dwDlgProp = 0;
303 fodInfos->DlgInfos.hwndCustomDlg = (HWND)NULL;
308 ret = GetFileName95(fodInfos);
311 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
312 ret = GetFileName95(fodInfos);
320 SetCurrentDirectoryA(lpstrSavDir);
321 MemFree(lpstrSavDir);
324 if (lpstrInitialDir != (LPCSTR)-1)
326 MemFree((LPVOID)(ofn->lpstrInitialDir));
327 ofn->lpstrInitialDir = lpstrInitialDir;
330 ofn->Flags = dwFlags;
331 ofn->hInstance = hInstance;
332 MemFree((LPVOID)(fodInfos));
336 /***********************************************************************
339 * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
340 * Call GetFileName95 with this structure and clean the memory.
342 * FIXME: lpstrCustomFilter has to converted back
346 /* converting IN arguments */
347 #define AllocInArgWtoA(arg, save) \
350 DWORD _len = WideCharToMultiByte( CP_ACP, 0, arg, -1, NULL, 0, NULL, NULL ); \
352 arg = MemAlloc(_len); \
353 WideCharToMultiByte( CP_ACP, 0, save, -1, (LPSTR)arg, _len, NULL, NULL ); \
356 #define FreeInArg(arg, save) \
359 MemFree((LPSTR)arg); \
363 /* converting OUT arguments */
364 #define AllocOutArgWtoA(arg, save, len) \
368 arg = MemAlloc(len); \
371 #define FreeOutArg(arg, save, len) \
374 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)(arg), -1, (save), (len) ); \
379 BOOL WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
382 FileOpenDlgInfos *fodInfos;
386 LPWSTR lpstrFile = NULL;
387 LPWSTR lpstrFileTitle = NULL;
389 /* in/out arguments */
390 LPWSTR lpstrCustomFilter = NULL;
392 /* input arguments */
393 LPCWSTR lpstrFilter = NULL;
394 LPCWSTR lpstrInitialDir = NULL;
395 LPCWSTR lpstrTitle = NULL;
396 LPCWSTR lpstrDefExt = NULL;
397 LPCWSTR lpTemplateName = NULL;
400 /* Initialise FileOpenDlgInfos structure*/
401 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
402 ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
404 /* Pass in the original ofn */
405 fodInfos->ofnInfos = (LPOPENFILENAMEA) ofn;
407 /* convert lpstrFilter */
408 if (ofn->lpstrFilter)
414 lpstrFilter = ofn->lpstrFilter;
416 /* filter is a list... title\0ext\0......\0\0 */
417 s = ofn->lpstrFilter;
419 while (*s) s = s+strlenW(s)+1;
421 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
422 len = WideCharToMultiByte( CP_ACP, 0, ofn->lpstrFilter, n, NULL, 0, NULL, NULL );
423 y = (LPSTR)MemAlloc(len);
424 WideCharToMultiByte( CP_ACP, 0, ofn->lpstrFilter, n, y, len, NULL, NULL );
425 (LPSTR)ofn->lpstrFilter = y;
428 /* convert lpstrCustomFilter */
429 if (ofn->lpstrCustomFilter)
435 lpstrCustomFilter = ofn->lpstrCustomFilter;
436 /* filter is a list... title\0ext\0......\0\0 */
437 s = ofn->lpstrCustomFilter;
438 while (*s) s = s+strlenW(s)+1;
440 n = s - ofn->lpstrCustomFilter;
441 len = WideCharToMultiByte( CP_ACP, 0, ofn->lpstrCustomFilter, n, NULL, 0, NULL, NULL );
442 y = (LPSTR)MemAlloc(len);
443 WideCharToMultiByte( CP_ACP, 0, ofn->lpstrCustomFilter, n, y, len, NULL, NULL );
444 (LPSTR)ofn->lpstrCustomFilter = y;
447 /* convert string arguments, save others */
448 AllocOutArgWtoA(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
449 AllocOutArgWtoA(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
450 AllocInArgWtoA(ofn->lpstrInitialDir, lpstrInitialDir);
451 AllocInArgWtoA(ofn->lpstrTitle, lpstrTitle);
452 AllocInArgWtoA(ofn->lpstrDefExt, lpstrDefExt);
453 AllocInArgWtoA(ofn->lpTemplateName, lpTemplateName);
454 dwFlags = ofn->Flags;
455 hInstance = ofn->hInstance;
457 ofn->Flags = ofn->Flags|OFN_WINE|OFN_UNICODE;
458 ofn->hInstance = MapHModuleLS(ofn->hInstance);
463 ret = GetFileName95(fodInfos);
466 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
467 ret = GetFileName95(fodInfos);
473 /* restore saved IN arguments and convert OUT arguments back */
474 ofn->Flags = dwFlags;
475 ofn->hInstance = hInstance;
476 FreeInArg(ofn->lpstrFilter, lpstrFilter);
477 FreeInArg(ofn->lpstrCustomFilter, lpstrCustomFilter);
478 FreeOutArg(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
479 FreeOutArg(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
480 FreeInArg(ofn->lpstrInitialDir, lpstrInitialDir);
481 FreeInArg(ofn->lpstrTitle, lpstrTitle);
482 FreeInArg(ofn->lpstrDefExt, lpstrDefExt);
483 FreeInArg(ofn->lpTemplateName, lpTemplateName);
485 MemFree((LPVOID)(fodInfos));
489 void ArrangeCtrlPositions( HWND hwndChildDlg, HWND hwndParentDlg)
491 HWND hwndChild,hwndStc32;
492 RECT rectParent, rectChild, rectCtrl, rectStc32, rectTemp;
494 POINT ptParentClient;
498 ptMoveCtl.x = ptMoveCtl.y = 0;
499 hwndStc32=GetDlgItem(hwndChildDlg,stc32);
500 GetClientRect(hwndParentDlg,&rectParent);
501 GetClientRect(hwndChildDlg,&rectChild);
505 GetWindowRect(hwndStc32,&rectStc32);
506 MapWindowPoints(0, hwndChildDlg,(LPPOINT)&rectStc32,2);
507 CopyRect(&rectTemp,&rectStc32);
509 SetRect(&rectStc32,rectStc32.left,rectStc32.top,rectStc32.left + (rectParent.right-rectParent.left),rectStc32.top+(rectParent.bottom-rectParent.top));
510 SetWindowPos(hwndStc32,0,rectStc32.left,rectStc32.top,rectStc32.right-rectStc32.left,rectStc32.bottom-rectStc32.top,SWP_NOMOVE|SWP_NOZORDER | SWP_NOACTIVATE);
512 if(rectStc32.right < rectTemp.right)
514 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
519 ptMoveCtl.x = (rectStc32.right - rectTemp.right);
520 ptParentClient.x = max((rectParent.right-rectParent.left),((rectChild.right-rectChild.left)+rectStc32.right-rectTemp.right));
523 if(rectStc32.bottom < rectTemp.bottom)
525 ptParentClient.y = max((rectParent.bottom-rectParent.top),(rectChild.bottom-rectChild.top));
530 ptMoveCtl.y = (rectStc32.bottom - rectTemp.bottom);
531 ptParentClient.y = max((rectParent.bottom-rectParent.top),((rectChild.bottom-rectChild.top)+rectStc32.bottom-rectTemp.bottom));
536 if( (GetWindow(hwndChildDlg,GW_CHILD)) == (HWND) NULL) return;
538 SetRectEmpty(&rectTemp);
539 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
540 ptParentClient.y = (rectParent.bottom-rectParent.top) + (rectChild.bottom-rectChild.top);
541 ptMoveCtl.y = rectParent.bottom-rectParent.top;
544 SetRect(&rectParent,rectParent.left,rectParent.top,rectParent.left+ptParentClient.x,rectParent.top+ptParentClient.y);
545 AdjustWindowRectEx( &rectParent,GetWindowLongA(hwndParentDlg,GWL_STYLE),FALSE,GetWindowLongA(hwndParentDlg,GWL_EXSTYLE));
547 SetWindowPos(hwndChildDlg, 0, 0,0, ptParentClient.x,ptParentClient.y, SWP_NOZORDER );
548 SetWindowPos(hwndParentDlg, 0, rectParent.left,rectParent.top, (rectParent.right- rectParent.left),
549 (rectParent.bottom-rectParent.top),SWP_NOMOVE | SWP_NOZORDER);
551 hwndChild = GetWindow(hwndChildDlg,GW_CHILD);
554 GetWindowRect(hwndStc32,&rectStc32);
555 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
558 SetRect(&rectStc32,0,0,0,0);
564 if(hwndChild != hwndStc32)
566 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
568 GetWindowRect(hwndChild,&rectCtrl);
569 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
572 Check the initial position of the controls relative to the initial
573 position and size of stc32 (before it is expanded).
575 if (rectCtrl.left >= rectTemp.right && rectCtrl.top >= rectTemp.bottom)
577 rectCtrl.left += ptMoveCtl.x;
578 rectCtrl.top += ptMoveCtl.y;
580 else if (rectCtrl.left >= rectTemp.right)
582 rectCtrl.left += ptMoveCtl.x;
584 else if (rectCtrl.top >= rectTemp.bottom)
586 rectCtrl.top += ptMoveCtl.y;
589 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
590 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
591 SWP_NOSIZE | SWP_NOZORDER );
593 } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
595 hwndChild = GetWindow(hwndParentDlg,GW_CHILD);
599 GetWindowRect(hwndStc32,&rectStc32);
600 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
601 ptMoveCtl.x = rectStc32.left - 0;
602 ptMoveCtl.y = rectStc32.top - 0;
607 if(hwndChild != hwndChildDlg)
609 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
611 GetWindowRect(hwndChild,&rectCtrl);
612 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
614 rectCtrl.left += ptMoveCtl.x;
615 rectCtrl.top += ptMoveCtl.y;
617 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
618 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
619 SWP_NOSIZE |SWP_NOZORDER );
621 } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
627 HRESULT WINAPI FileOpenDlgProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
629 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(GetParent(hwnd),FileOpenDlgInfosStr);
632 TRACE("0x%04x\n", uMsg);
639 fodInfos = (FileOpenDlgInfos *)lParam;
640 lParam = (LPARAM) fodInfos->ofnInfos;
641 ArrangeCtrlPositions(hwnd,GetParent(hwnd));
643 if(fodInfos && IsHooked(fodInfos))
644 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
649 if(fodInfos && IsHooked(fodInfos))
650 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
652 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
655 HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos, HWND hwnd)
664 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATE ||
665 fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
667 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
669 if( !(template = LockResource( fodInfos->ofnInfos->hInstance)))
671 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
677 if (!(hRes = FindResourceA(MapHModuleSL(fodInfos->ofnInfos->hInstance),
678 (fodInfos->ofnInfos->lpTemplateName), RT_DIALOGA)))
680 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
683 if (!(hDlgTmpl = LoadResource( MapHModuleSL(fodInfos->ofnInfos->hInstance),
684 hRes )) || !(template = LockResource( hDlgTmpl )))
686 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
691 hChildDlg= CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,template,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
694 ShowWindow(hChildDlg,SW_SHOW);
698 else if( IsHooked(fodInfos))
702 GetClientRect(hwnd,&rectHwnd);
703 tmplate.style = WS_CHILD | WS_CLIPSIBLINGS;
704 tmplate.dwExtendedStyle = 0;
708 tmplate.cx = rectHwnd.right-rectHwnd.left;
709 tmplate.cy = rectHwnd.bottom-rectHwnd.top;
711 return CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,&tmplate,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
716 /***********************************************************************
717 * SendCustomDlgNotificationMessage
719 * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
722 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
724 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndParentDlg,FileOpenDlgInfosStr);
726 TRACE("0x%04x 0x%04x\n",hwndParentDlg, uCode);
728 if(!fodInfos) return 0;
730 if(fodInfos->ofnInfos->Flags & OFN_UNICODE)
731 FIXME("sending OPENFILENAMEA structure. Hook is expecting OPENFILENAMEW!\n");
733 if(fodInfos->DlgInfos.hwndCustomDlg)
737 ofnNotify.hdr.hwndFrom=hwndParentDlg;
738 ofnNotify.hdr.idFrom=0;
739 ofnNotify.hdr.code = uCode;
740 ofnNotify.lpOFN = fodInfos->ofnInfos;
741 TRACE("CALL NOTIFY for %x\n", uCode);
742 ret = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);
743 TRACE("RET NOTIFY\n");
749 /***********************************************************************
750 * FILEDLG95_HandleCustomDialogMessages
752 * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
754 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
758 char lpstrPath[MAX_PATH];
759 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
760 if(!fodInfos) return -1;
764 case CDM_GETFILEPATH:
765 GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
766 lpstrFileSpec = (LPSTR)PathFindFileNameA(lpstrPath);
767 if (lpstrFileSpec==lpstrPath)
769 char lpstrCurrentDir[MAX_PATH];
770 /* Prepend the current path */
771 SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrCurrentDir);
772 if ((LPSTR)lParam!=NULL)
773 snprintf((LPSTR)lParam,(int)wParam,"%s\\%s",lpstrCurrentDir,lpstrPath);
774 reqSize=strlen(lpstrCurrentDir)+1+strlen(lpstrPath)+1;
778 lstrcpynA((LPSTR)lParam,(LPSTR)lpstrPath,(int)wParam);
779 reqSize=strlen(lpstrPath);
781 /* return the required buffer size */
784 case CDM_GETFOLDERPATH:
785 SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);
786 if ((LPSTR)lParam!=NULL)
787 lstrcpynA((LPSTR)lParam,lpstrPath,(int)wParam);
788 return strlen(lpstrPath);
791 reqSize=GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
792 lpstrFileSpec = (LPSTR)PathFindFileNameA(lpstrPath);
793 if ((LPSTR)lParam!=NULL)
794 lstrcpynA((LPSTR)lParam, lpstrFileSpec, (int)wParam);
795 return strlen(lpstrFileSpec);
797 case CDM_SETCONTROLTEXT:
799 SetDlgItemTextA( hwnd, (UINT) wParam, (LPSTR) lParam );
802 case CDM_HIDECONTROL:
804 FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");
810 /***********************************************************************
813 * File open dialog procedure
815 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
818 TRACE("0x%04x 0x%04x\n", hwnd, uMsg);
825 FileOpenDlgInfos * fodInfos = (FileOpenDlgInfos *)lParam;
827 /* Adds the FileOpenDlgInfos in the property list of the dialog
828 so it will be easily accessible through a GetPropA(...) */
829 SetPropA(hwnd, FileOpenDlgInfosStr, (HANDLE) fodInfos);
831 fodInfos->DlgInfos.hwndCustomDlg =
832 CreateTemplateDialog((FileOpenDlgInfos *)lParam, hwnd);
834 FILEDLG95_InitControls(hwnd);
835 SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE);
836 FILEDLG95_FillControls(hwnd, wParam, lParam);
837 SendCustomDlgNotificationMessage(hwnd,CDN_SELCHANGE);
841 return FILEDLG95_OnWMCommand(hwnd, wParam, lParam);
844 switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
847 FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT) lParam);
853 case WM_GETISHELLBROWSER:
854 return FILEDLG95_OnWMGetIShellBrowser(hwnd);
857 RemovePropA(hwnd, FileOpenDlgInfosStr);
862 LPNMHDR lpnmh = (LPNMHDR)lParam;
865 /* set up the button tooltips strings */
866 if(TTN_GETDISPINFOA == lpnmh->code )
868 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
869 switch(lpnmh->idFrom )
871 /* Up folder button */
872 case FCIDM_TB_UPFOLDER:
873 stringId = IDS_UPFOLDER;
875 /* New folder button */
876 case FCIDM_TB_NEWFOLDER:
877 stringId = IDS_NEWFOLDER;
879 /* List option button */
880 case FCIDM_TB_SMALLICON:
881 stringId = IDS_LISTVIEW;
883 /* Details option button */
884 case FCIDM_TB_REPORTVIEW:
885 stringId = IDS_REPORTVIEW;
888 case FCIDM_TB_DESKTOP:
889 stringId = IDS_TODESKTOP;
894 lpdi->hinst = COMMDLG_hInstance32;
895 lpdi->lpszText = (LPSTR) stringId;
900 if(uMsg >= CDM_FIRST && uMsg <= CDM_LAST)
901 return FILEDLG95_HandleCustomDialogMessages(hwnd, uMsg, wParam, lParam);
906 /***********************************************************************
907 * FILEDLG95_InitControls
909 * WM_INITDIALOG message handler (before hook notification)
911 static LRESULT FILEDLG95_InitControls(HWND hwnd)
915 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
916 {VIEW_PARENTFOLDER, FCIDM_TB_UPFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
917 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
918 {VIEW_NEWFOLDER+1, FCIDM_TB_DESKTOP, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
919 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
920 {VIEW_NEWFOLDER, FCIDM_TB_NEWFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
921 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
922 {VIEW_LIST, FCIDM_TB_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
923 {VIEW_DETAILS, FCIDM_TB_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
927 { HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR },
928 { COMDLG32_hInstance, 800 } // desktop icon
933 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
935 TRACE("%p\n", fodInfos);
937 /* Get the hwnd of the controls */
938 fodInfos->DlgInfos.hwndFileName = GetDlgItem(hwnd,IDC_FILENAME);
939 fodInfos->DlgInfos.hwndFileTypeCB = GetDlgItem(hwnd,IDC_FILETYPE);
940 fodInfos->DlgInfos.hwndLookInCB = GetDlgItem(hwnd,IDC_LOOKIN);
942 /* construct the toolbar */
943 GetWindowRect(GetDlgItem(hwnd,IDC_TOOLBARSTATIC),&rectTB);
944 MapWindowPoints( 0, hwnd,(LPPOINT)&rectTB,2);
946 fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, (LPSTR) NULL,
947 WS_CHILD | WS_GROUP | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE,
948 0, 0, 150, 26, hwnd, (HMENU) IDC_TOOLBAR, COMMDLG_hInstance32, NULL);
950 SetWindowPos(fodInfos->DlgInfos.hwndTB, 0,
951 rectTB.left,rectTB.top, rectTB.right-rectTB.left, rectTB.bottom-rectTB.top,
952 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
954 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
956 /* fixme: use TB_LOADIMAGES when implemented */
957 /* SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/
958 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 12, (LPARAM) &tba[0]);
959 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 1, (LPARAM) &tba[1]);
961 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSA, (WPARAM) 9,(LPARAM) &tbb);
962 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_AUTOSIZE, 0, 0);
964 /* Set the window text with the text specified in the OPENFILENAME structure */
965 if(fodInfos->ofnInfos->lpstrTitle)
967 SetWindowTextA(hwnd,fodInfos->ofnInfos->lpstrTitle);
969 else if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
971 SetWindowTextA(hwnd,"Save");
974 /* Initialise the file name edit control */
975 if(fodInfos->ofnInfos->lpstrFile)
977 LPSTR lpstrFile = PathFindFileNameA(fodInfos->ofnInfos->lpstrFile);
978 SetDlgItemTextA(hwnd, IDC_FILENAME, lpstrFile);
981 /* Must the open as read only check box be checked ?*/
982 if(fodInfos->ofnInfos->Flags & OFN_READONLY)
984 SendDlgItemMessageA(hwnd,IDC_OPENREADONLY,BM_SETCHECK,(WPARAM)TRUE,0);
987 /* Must the open as read only check box be hid ?*/
988 if(fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY)
990 ShowWindow(GetDlgItem(hwnd,IDC_OPENREADONLY),SW_HIDE);
993 /* Must the help button be hid ?*/
994 if (!(fodInfos->ofnInfos->Flags & OFN_SHOWHELP))
996 ShowWindow(GetDlgItem(hwnd, pshHelp), SW_HIDE);
999 /* Resize the height, if open as read only checkbox ad help button
1000 are hidden and we are not using a custom template */
1001 if ( (fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) &&
1002 (!(fodInfos->ofnInfos->Flags &
1003 (OFN_SHOWHELP|OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE))))
1005 RECT rectDlg, rectHelp, rectCancel;
1006 GetWindowRect(hwnd, &rectDlg);
1007 GetWindowRect(GetDlgItem(hwnd, pshHelp), &rectHelp);
1008 GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rectCancel);
1009 /* subtract the height of the help button plus the space between
1010 the help button and the cancel button to the height of the dialog */
1011 SetWindowPos(hwnd, 0, 0, 0, rectDlg.right-rectDlg.left,
1012 (rectDlg.bottom-rectDlg.top) - (rectHelp.bottom - rectCancel.bottom),
1013 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
1016 /* change Open to Save FIXME: use resources */
1017 if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
1019 SetDlgItemTextA(hwnd,IDOK,"&Save");
1020 SetDlgItemTextA(hwnd,IDC_LOOKINSTATIC,"Save &in");
1025 /***********************************************************************
1026 * FILEDLG95_FillControls
1028 * WM_INITDIALOG message handler (after hook notification)
1030 static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam)
1032 LPITEMIDLIST pidlItemId = NULL;
1034 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) lParam;
1036 TRACE("dir=%s file=%s\n",
1037 fodInfos->ofnInfos->lpstrInitialDir, fodInfos->ofnInfos->lpstrFile);
1039 /* Get the initial directory pidl */
1041 if(!(pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,fodInfos->ofnInfos->lpstrInitialDir)))
1043 char path[MAX_PATH];
1045 GetCurrentDirectoryA(MAX_PATH,path);
1046 pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder, path);
1049 /* Initialise shell objects */
1050 FILEDLG95_SHELL_Init(hwnd);
1052 /* Initialize the Look In combo box */
1053 FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB);
1055 /* Initialize the filter combo box */
1056 FILEDLG95_FILETYPE_Init(hwnd);
1058 /* Browse to the initial directory */
1059 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,pidlItemId, SBSP_ABSOLUTE);
1061 /* Free pidlItem memory */
1062 COMDLG32_SHFree(pidlItemId);
1066 /***********************************************************************
1069 * Regroups all the cleaning functions of the filedlg
1071 void FILEDLG95_Clean(HWND hwnd)
1073 FILEDLG95_FILETYPE_Clean(hwnd);
1074 FILEDLG95_LOOKIN_Clean(hwnd);
1075 FILEDLG95_SHELL_Clean(hwnd);
1077 /***********************************************************************
1078 * FILEDLG95_OnWMCommand
1080 * WM_COMMAND message handler
1082 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
1084 WORD wNotifyCode = HIWORD(wParam); /* notification code */
1085 WORD wID = LOWORD(wParam); /* item, control, or accelerator identifier */
1086 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1092 if(FILEDLG95_OnOpen(hwnd))
1093 SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK);
1097 FILEDLG95_Clean(hwnd);
1098 EndDialog(hwnd, FALSE);
1100 /* Filetype combo box */
1102 FILEDLG95_FILETYPE_OnCommand(hwnd,wNotifyCode);
1104 /* LookIn combo box */
1106 FILEDLG95_LOOKIN_OnCommand(hwnd,wNotifyCode);
1109 /* --- toolbar --- */
1110 /* Up folder button */
1111 case FCIDM_TB_UPFOLDER:
1112 FILEDLG95_SHELL_UpFolder(hwnd);
1114 /* New folder button */
1115 case FCIDM_TB_NEWFOLDER:
1116 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_NEWFOLDER);
1118 /* List option button */
1119 case FCIDM_TB_SMALLICON:
1120 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWLIST);
1122 /* Details option button */
1123 case FCIDM_TB_REPORTVIEW:
1124 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWDETAILS);
1126 /* Details option button */
1127 case FCIDM_TB_DESKTOP:
1128 FILEDLG95_SHELL_BrowseToDesktop(hwnd);
1135 /* Do not use the listview selection anymore */
1136 fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
1140 /***********************************************************************
1141 * FILEDLG95_OnWMGetIShellBrowser
1143 * WM_GETISHELLBROWSER message handler
1145 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd)
1148 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1152 SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)fodInfos->Shell.FOIShellBrowser);
1158 /***********************************************************************
1159 * FILEDLG95_OnOpenMultipleFiles
1161 * Handles the opening of multiple files.
1164 * check destination buffer size
1166 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed)
1168 CHAR lpstrPathSpec[MAX_PATH] = "";
1170 UINT nCount, nSizePath;
1171 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1175 lpstrFile = fodInfos->ofnInfos->lpstrFile;
1176 lpstrFile[0] = '\0';
1178 SHGetPathFromIDListA( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec );
1180 if ( !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE) &&
1181 ( fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST))
1183 LPSTR lpstrTemp = lpstrFileList;
1185 for ( nCount = 0; nCount < nFileCount; nCount++ )
1189 pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder, lpstrTemp);
1192 CHAR lpstrNotFound[100];
1196 LoadStringA(COMMDLG_hInstance32, IDS_FILENOTFOUND, lpstrNotFound, 100);
1197 LoadStringA(COMMDLG_hInstance32, IDS_VERIFYFILE, lpstrMsg, 100);
1199 strcpy(tmp, lpstrTemp);
1201 strcat(tmp, lpstrNotFound);
1203 strcat(tmp, lpstrMsg);
1205 MessageBoxA(hwnd, tmp, fodInfos->ofnInfos->lpstrTitle, MB_OK | MB_ICONEXCLAMATION);
1209 /* move to the next file in the list of files */
1210 lpstrTemp += strlen(lpstrTemp) + 1;
1211 COMDLG32_SHFree(pidl);
1215 nSizePath = strlen(lpstrPathSpec);
1216 strcpy( lpstrFile, lpstrPathSpec);
1217 memcpy( lpstrFile + nSizePath + 1, lpstrFileList, sizeUsed );
1219 fodInfos->ofnInfos->nFileOffset = nSizePath + 1;
1220 fodInfos->ofnInfos->nFileExtension = 0;
1222 /* clean and exit */
1223 FILEDLG95_Clean(hwnd);
1224 return EndDialog(hwnd,TRUE);
1227 /***********************************************************************
1230 * Ok button WM_COMMAND message handler
1232 * If the function succeeds, the return value is nonzero.
1234 #define ONOPEN_BROWSE 1
1235 #define ONOPEN_OPEN 2
1236 #define ONOPEN_SEARCH 3
1237 static void FILEDLG95_OnOpenMessage(HWND hwnd, int idCaption, int idText)
1239 char strMsgTitle[MAX_PATH];
1240 char strMsgText [MAX_PATH];
1242 LoadStringA(COMDLG32_hInstance, idCaption, strMsgTitle, sizeof(strMsgTitle));
1244 strMsgTitle[0] = '\0';
1245 LoadStringA(COMDLG32_hInstance, idText, strMsgText, sizeof(strMsgText));
1246 MessageBoxA(hwnd,strMsgText, strMsgTitle, MB_OK | MB_ICONHAND);
1249 BOOL FILEDLG95_OnOpen(HWND hwnd)
1251 char * lpstrFileList;
1252 UINT nFileCount = 0;
1255 char lpstrPathAndFile[MAX_PATH];
1256 char lpstrTemp[MAX_PATH];
1257 LPSHELLFOLDER lpsf = NULL;
1259 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1261 TRACE("hwnd=0x%04x\n", hwnd);
1263 /* get the files from the edit control */
1264 nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed);
1266 /* try if the user selected a folder in the shellview */
1269 BrowseSelectedFolder(hwnd);
1275 ret = FILEDLG95_OnOpenMultipleFiles(hwnd, lpstrFileList, nFileCount, sizeUsed);
1279 TRACE("count=%u len=%u file=%s\n", nFileCount, sizeUsed, lpstrFileList);
1282 Step 1: Build a complete path name from the current folder and
1283 the filename or path in the edit box.
1285 - the path in the edit box is a root path
1286 (with or without drive letter)
1287 - the edit box contains ".." (or a path with ".." in it)
1290 /* Get the current directory name */
1291 if (!SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathAndFile))
1293 /* we are in a special folder, default to desktop */
1294 if(FAILED(COMDLG32_SHGetFolderPathA(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, 0, 0, lpstrPathAndFile)))
1297 GetCurrentDirectoryA(MAX_PATH, lpstrPathAndFile);
1300 PathAddBackslashA(lpstrPathAndFile);
1302 TRACE("current directory=%s\n", lpstrPathAndFile);
1304 /* if the user specifyed a fully qualified path use it */
1305 if(PathIsRelativeA(lpstrFileList))
1307 strcat(lpstrPathAndFile, lpstrFileList);
1311 /* does the path have a drive letter? */
1312 if (PathGetDriveNumberA(lpstrFileList) == -1)
1313 strcpy(lpstrPathAndFile+2, lpstrFileList);
1315 strcpy(lpstrPathAndFile, lpstrFileList);
1318 /* resolve "." and ".." */
1319 PathCanonicalizeA(lpstrTemp, lpstrPathAndFile );
1320 strcpy(lpstrPathAndFile, lpstrTemp);
1321 TRACE("canon=%s\n", lpstrPathAndFile);
1323 MemFree(lpstrFileList);
1326 Step 2: here we have a cleaned up path
1328 We have to parse the path step by step to see if we have to browse
1329 to a folder if the path points to a directory or the last
1330 valid element is a directory.
1333 lpstrPathAndFile: cleaned up path
1336 nOpenAction = ONOPEN_BROWSE;
1338 /* dont apply any checks with OFN_NOVALIDATE */
1339 if(!(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE))
1341 LPSTR lpszTemp, lpszTemp1;
1342 LPITEMIDLIST pidl = NULL;
1344 /* check for invalid chars */
1345 if(strpbrk(lpstrPathAndFile+3, "/:<>|") != NULL)
1347 FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_FILENAME);
1352 if (FAILED (SHGetDesktopFolder(&lpsf))) return FALSE;
1354 lpszTemp1 = lpszTemp = lpstrPathAndFile;
1357 LPSHELLFOLDER lpsfChild;
1358 WCHAR lpwstrTemp[MAX_PATH];
1359 DWORD dwEaten, dwAttributes;
1361 lpszTemp = PathFindNextComponentA(lpszTemp);
1363 if (!lpszTemp) break; /* end of path */
1367 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpszTemp1, lpszTemp - lpszTemp1,
1368 lpwstrTemp, MAX_PATH );
1369 lpwstrTemp[len] = 0;
1373 MultiByteToWideChar( CP_ACP, 0, lpszTemp1, -1,
1374 lpwstrTemp, sizeof(lpwstrTemp)/sizeof(WCHAR) );
1376 /* if the last element is a wildcard do a search */
1377 if(strpbrk(lpszTemp1, "*?") != NULL)
1379 nOpenAction = ONOPEN_SEARCH;
1383 lpszTemp1 = lpszTemp;
1385 TRACE("parse now=%s next=%s sf=%p\n",debugstr_w(lpwstrTemp), debugstr_a(lpszTemp), lpsf);
1387 if(lstrlenW(lpwstrTemp)==2) PathAddBackslashW(lpwstrTemp);
1389 dwAttributes = SFGAO_FOLDER;
1390 if(SUCCEEDED(IShellFolder_ParseDisplayName(lpsf, hwnd, NULL, lpwstrTemp, &dwEaten, &pidl, &dwAttributes)))
1392 /* the path component is valid, we have a pidl of the next path component */
1393 TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes, pidl);
1394 if(dwAttributes & SFGAO_FOLDER)
1396 if(FAILED(IShellFolder_BindToObject(lpsf, pidl, 0, &IID_IShellFolder, (LPVOID*)&lpsfChild)))
1398 ERR("bind to failed\n"); /* should not fail */
1401 IShellFolder_Release(lpsf);
1409 /* end dialog, return value */
1410 nOpenAction = ONOPEN_OPEN;
1413 COMDLG32_SHFree(pidl);
1418 if(*lpszTemp) /* points to trailing null for last path element */
1420 if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
1422 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_PATHNOTEXISTING);
1428 if(fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST)
1430 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_FILENOTEXISTING);
1434 /* change to the current folder */
1435 nOpenAction = ONOPEN_OPEN;
1439 if(pidl) COMDLG32_SHFree(pidl);
1443 Step 3: here we have a cleaned up and validated path
1446 lpsf: ShellFolder bound to the rightmost valid path component
1447 lpstrPathAndFile: cleaned up path
1448 nOpenAction: action to do
1450 TRACE("end validate sf=%p\n", lpsf);
1454 case ONOPEN_SEARCH: /* set the current filter to the file mask and refresh */
1455 TRACE("ONOPEN_SEARCH %s\n", lpstrPathAndFile);
1458 LPSTR lpszTemp = PathFindFileNameA(lpstrPathAndFile);
1461 /* replace the current filter */
1462 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1463 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1464 len = MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1, NULL, 0 );
1465 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc(len * sizeof(WCHAR));
1466 MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1,
1467 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1469 /* set the filter cb to the extension when possible */
1470 if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB, lpszTemp)))
1471 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, iPos);
1474 case ONOPEN_BROWSE: /* browse to the highest folder we could bind to */
1475 TRACE("ONOPEN_BROWSE\n");
1477 IPersistFolder2 * ppf2;
1478 if(SUCCEEDED(IShellFolder_QueryInterface( lpsf, &IID_IPersistFolder2, (LPVOID*)&ppf2)))
1480 LPITEMIDLIST pidlCurrent;
1481 IPersistFolder2_GetCurFolder(ppf2, &pidlCurrent);
1482 IPersistFolder2_Release(ppf2);
1483 if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent, fodInfos->ShellInfos.pidlAbsCurrent))
1485 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE);
1487 else if( nOpenAction == ONOPEN_SEARCH )
1489 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1491 COMDLG32_SHFree(pidlCurrent);
1496 case ONOPEN_OPEN: /* fill in the return struct and close the dialog */
1497 TRACE("ONOPEN_OPEN %s\n", lpstrPathAndFile);
1499 /* add default extension */
1500 if (fodInfos->ofnInfos->lpstrDefExt)
1502 if (! *PathFindExtensionA(lpstrPathAndFile))
1504 strcat(lpstrPathAndFile, ".");
1505 strcat(lpstrPathAndFile, fodInfos->ofnInfos->lpstrDefExt);
1509 /* Check that the size of the file does not exceed buffer size.
1510 (Allow for extra \0 if OFN_MULTISELECT is set.) */
1511 if(strlen(lpstrPathAndFile) < fodInfos->ofnInfos->nMaxFile -
1512 ((fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT) ? 1 : 0))
1516 /* fill destination buffer */
1517 strcpy(fodInfos->ofnInfos->lpstrFile, lpstrPathAndFile);
1518 if (fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT)
1519 fodInfos->ofnInfos->lpstrFile[strlen(fodInfos->ofnInfos->lpstrFile)
1522 /* set filename offset */
1523 lpszTemp = PathFindFileNameA(lpstrPathAndFile);
1524 fodInfos->ofnInfos->nFileOffset = lpszTemp - lpstrPathAndFile;
1526 /* set extension offset */
1527 lpszTemp = PathFindExtensionA(lpstrPathAndFile);
1528 fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? lpszTemp - lpstrPathAndFile + 1 : 0;
1530 /* set the lpstrFileTitle */
1531 if(fodInfos->ofnInfos->lpstrFileTitle)
1533 LPSTR lpstrFileTitle = PathFindFileNameA(lpstrPathAndFile);
1534 strncpy(fodInfos->ofnInfos->lpstrFileTitle, lpstrFileTitle, fodInfos->ofnInfos->nMaxFileTitle);
1537 /* ask the hook if we can close */
1538 if(IsHooked(fodInfos))
1540 /* FIXME we are sending ASCII-structures. Does not work with NT */
1541 /* first old style */
1543 CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,
1544 fodInfos->DlgInfos.hwndCustomDlg,
1545 fodInfos->HookMsg.fileokstring, 0, (LPARAM)fodInfos->ofnInfos);
1546 if (GetWindowLongA(hwnd, DWL_MSGRESULT))
1555 FILEDLG95_Clean(hwnd);
1556 ret = EndDialog(hwnd, TRUE);
1560 /* FIXME set error FNERR_BUFFERTOSMALL */
1561 FILEDLG95_Clean(hwnd);
1562 ret = EndDialog(hwnd, FALSE);
1570 if(lpsf) IShellFolder_Release(lpsf);
1574 /***********************************************************************
1575 * FILEDLG95_SHELL_Init
1577 * Initialisation of the shell objects
1579 static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
1581 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1586 * Initialisation of the FileOpenDialogInfos structure
1592 fodInfos->ShellInfos.hwndOwner = hwnd;
1594 /* Disable multi-select if flag not set */
1595 if (!(fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT))
1597 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_SINGLESEL;
1599 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_AUTOARRANGE | FWF_ALIGNLEFT;
1600 fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
1602 GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
1603 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
1604 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
1606 /* Construct the IShellBrowser interface */
1607 fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
1612 /***********************************************************************
1613 * FILEDLG95_SHELL_ExecuteCommand
1615 * Change the folder option and refresh the view
1616 * If the function succeeds, the return value is nonzero.
1618 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
1620 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1623 TRACE("(0x%08x,%p)\n", hwnd, lpVerb);
1625 if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
1630 CMINVOKECOMMANDINFO ci;
1631 ZeroMemory(&ci, sizeof(CMINVOKECOMMANDINFO));
1632 ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
1636 IContextMenu_InvokeCommand(pcm, &ci);
1637 IContextMenu_Release(pcm);
1643 /***********************************************************************
1644 * FILEDLG95_SHELL_UpFolder
1646 * Browse to the specified object
1647 * If the function succeeds, the return value is nonzero.
1649 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
1651 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1655 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1664 /***********************************************************************
1665 * FILEDLG95_SHELL_BrowseToDesktop
1667 * Browse to the Desktop
1668 * If the function succeeds, the return value is nonzero.
1670 static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd)
1672 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1678 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidl);
1679 hres = IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidl, SBSP_ABSOLUTE);
1680 COMDLG32_SHFree(pidl);
1681 return SUCCEEDED(hres);
1683 /***********************************************************************
1684 * FILEDLG95_SHELL_Clean
1686 * Cleans the memory used by shell objects
1688 static void FILEDLG95_SHELL_Clean(HWND hwnd)
1690 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1694 COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent);
1696 /* clean Shell interfaces */
1697 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
1698 IShellView_Release(fodInfos->Shell.FOIShellView);
1699 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
1700 IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
1701 if (fodInfos->Shell.FOIDataObject)
1702 IDataObject_Release(fodInfos->Shell.FOIDataObject);
1705 /***********************************************************************
1706 * FILEDLG95_FILETYPE_Init
1708 * Initialisation of the file type combo box
1710 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
1712 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1716 if(fodInfos->ofnInfos->lpstrFilter)
1718 int nFilters = 0; /* number of filters */
1720 LPCSTR lpstrPos = fodInfos->ofnInfos->lpstrFilter;
1724 /* filter is a list... title\0ext\0......\0\0
1725 * Set the combo item text to the title and the item data
1728 LPCSTR lpstrDisplay;
1732 if(! *lpstrPos) break; /* end */
1733 lpstrDisplay = lpstrPos;
1734 lpstrPos += strlen(lpstrPos) + 1;
1736 /* Copy the extensions */
1737 if (! *lpstrPos) return E_FAIL; /* malformed filter */
1738 if (!(lpstrExt = (LPSTR) MemAlloc(strlen(lpstrPos)+1))) return E_FAIL;
1739 strcpy(lpstrExt,lpstrPos);
1740 lpstrPos += strlen(lpstrPos) + 1;
1742 /* Add the item at the end of the combo */
1743 CBAddString(fodInfos->DlgInfos.hwndFileTypeCB, lpstrDisplay);
1744 CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt);
1748 * Set the current filter to the one specified
1749 * in the initialisation structure
1750 * FIXME: lpstrCustomFilter not handled at all
1753 /* set default filter index */
1754 if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->ofnInfos->lpstrCustomFilter == NULL)
1755 fodInfos->ofnInfos->nFilterIndex = 1;
1757 /* First, check to make sure our index isn't out of bounds. */
1758 if ( fodInfos->ofnInfos->nFilterIndex > nFilters )
1759 fodInfos->ofnInfos->nFilterIndex = nFilters;
1761 /* Set the current index selection. */
1762 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->ofnInfos->nFilterIndex-1);
1764 /* Get the corresponding text string from the combo box. */
1765 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1766 fodInfos->ofnInfos->nFilterIndex-1);
1768 if ((INT)lpstrFilter == CB_ERR) /* control is empty */
1774 _strlwr(lpstrFilter); /* lowercase */
1775 len = MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1, NULL, 0 );
1776 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
1777 MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1,
1778 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1784 /***********************************************************************
1785 * FILEDLG95_FILETYPE_OnCommand
1787 * WM_COMMAND of the file type combo box
1788 * If the function succeeds, the return value is nonzero.
1790 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
1792 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1800 /* Get the current item of the filetype combo box */
1801 int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1803 /* set the current filter index - indexed from 1 */
1804 fodInfos->ofnInfos->nFilterIndex = iItem + 1;
1806 /* Set the current filter with the current selection */
1807 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1808 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1810 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1812 if((int)lpstrFilter != CB_ERR)
1815 _strlwr(lpstrFilter); /* lowercase */
1816 len = MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1, NULL, 0 );
1817 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
1818 MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1,
1819 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1820 SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
1823 /* Refresh the actual view to display the included items*/
1824 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1829 /***********************************************************************
1830 * FILEDLG95_FILETYPE_SearchExt
1832 * searches for a extension in the filetype box
1834 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt)
1836 int i, iCount = CBGetCount(hwnd);
1838 TRACE("%s\n", lpstrExt);
1840 if(iCount != CB_ERR)
1842 for(i=0;i<iCount;i++)
1844 if(!strcasecmp(lpstrExt,(LPSTR)CBGetItemDataPtr(hwnd,i)))
1851 /***********************************************************************
1852 * FILEDLG95_FILETYPE_Clean
1854 * Clean the memory used by the filetype combo box
1856 static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
1858 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1860 int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
1864 /* Delete each string of the combo and their associated data */
1865 if(iCount != CB_ERR)
1867 for(iPos = iCount-1;iPos>=0;iPos--)
1869 MemFree((LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos));
1870 CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1873 /* Current filter */
1874 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1875 MemFree(fodInfos->ShellInfos.lpstrCurrentFilter);
1879 /***********************************************************************
1880 * FILEDLG95_LOOKIN_Init
1882 * Initialisation of the look in combo box
1884 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
1886 IShellFolder *psfRoot, *psfDrives;
1887 IEnumIDList *lpeRoot, *lpeDrives;
1888 LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
1890 LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
1894 liInfos->iMaxIndentation = 0;
1896 SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
1898 /* set item height for both text field and listbox */
1899 CBSetItemHeight(hwndCombo,-1,GetSystemMetrics(SM_CYSMICON));
1900 CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
1902 /* Initialise data of Desktop folder */
1903 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
1904 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1905 COMDLG32_SHFree(pidlTmp);
1907 SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
1909 SHGetDesktopFolder(&psfRoot);
1913 /* enumerate the contents of the desktop */
1914 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
1916 while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
1918 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1920 /* special handling for CSIDL_DRIVES */
1921 if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
1923 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
1925 /* enumerate the drives */
1926 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
1928 while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
1930 pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
1931 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
1932 COMDLG32_SHFree(pidlAbsTmp);
1933 COMDLG32_SHFree(pidlTmp1);
1935 IEnumIDList_Release(lpeDrives);
1937 IShellFolder_Release(psfDrives);
1940 COMDLG32_SHFree(pidlTmp);
1942 IEnumIDList_Release(lpeRoot);
1946 IShellFolder_Release(psfRoot);
1947 COMDLG32_SHFree(pidlDrives);
1951 /***********************************************************************
1952 * FILEDLG95_LOOKIN_DrawItem
1954 * WM_DRAWITEM message handler
1956 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
1958 COLORREF crWin = GetSysColor(COLOR_WINDOW);
1959 COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
1960 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1964 HIMAGELIST ilItemImage;
1967 LPSFOLDER tmpFolder;
1970 LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
1974 if(pDIStruct->itemID == -1)
1977 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
1978 pDIStruct->itemID)))
1982 if(pDIStruct->itemID == liInfos->uSelectedItem)
1984 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1987 sizeof (SHFILEINFOA),
1988 SHGFI_PIDL | SHGFI_SMALLICON |
1989 SHGFI_OPENICON | SHGFI_SYSICONINDEX |
1990 SHGFI_DISPLAYNAME );
1994 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1997 sizeof (SHFILEINFOA),
1998 SHGFI_PIDL | SHGFI_SMALLICON |
1999 SHGFI_SYSICONINDEX |
2003 /* Is this item selected ? */
2004 if(pDIStruct->itemState & ODS_SELECTED)
2006 SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
2007 SetBkColor(pDIStruct->hDC,crHighLight);
2008 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight);
2012 SetTextColor(pDIStruct->hDC,crText);
2013 SetBkColor(pDIStruct->hDC,crWin);
2014 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin);
2017 /* Do not indent item if drawing in the edit of the combo */
2018 if(pDIStruct->itemState & ODS_COMBOBOXEDIT)
2021 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2024 sizeof (SHFILEINFOA),
2025 SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON
2026 | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME );
2031 iIndentation = tmpFolder->m_iIndent;
2033 /* Draw text and icon */
2035 /* Initialise the icon display area */
2036 rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
2037 rectIcon.top = pDIStruct->rcItem.top;
2038 rectIcon.right = rectIcon.left + ICONWIDTH;
2039 rectIcon.bottom = pDIStruct->rcItem.bottom;
2041 /* Initialise the text display area */
2042 GetTextMetricsA(pDIStruct->hDC, &tm);
2043 rectText.left = rectIcon.right;
2045 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom - tm.tmHeight) / 2;
2046 rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
2048 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom + tm.tmHeight) / 2;
2050 /* Draw the icon from the image list */
2051 ImageList_Draw(ilItemImage,
2058 /* Draw the associated text */
2059 if(sfi.szDisplayName)
2060 TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName));
2066 /***********************************************************************
2067 * FILEDLG95_LOOKIN_OnCommand
2069 * LookIn combo box WM_COMMAND message handler
2070 * If the function succeeds, the return value is nonzero.
2072 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
2074 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2076 TRACE("%p\n", fodInfos);
2082 LPSFOLDER tmpFolder;
2085 iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
2087 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
2092 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
2093 tmpFolder->pidlItem,
2105 /***********************************************************************
2106 * FILEDLG95_LOOKIN_AddItem
2108 * Adds an absolute pidl item to the lookin combo box
2109 * returns the index of the inserted item
2111 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
2113 LPITEMIDLIST pidlNext;
2116 LookInInfos *liInfos;
2118 TRACE("%08x\n", iInsertId);
2123 if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
2126 tmpFolder = MemAlloc(sizeof(SFOLDER));
2127 tmpFolder->m_iIndent = 0;
2129 /* Calculate the indentation of the item in the lookin*/
2131 while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
2133 tmpFolder->m_iIndent++;
2136 tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl); /* FIXME: memory leak*/
2138 if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
2139 liInfos->iMaxIndentation = tmpFolder->m_iIndent;
2141 sfi.dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM;
2142 SHGetFileInfoA((LPSTR)pidl,
2146 SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX
2147 | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED);
2149 TRACE("-- Add %s attr=%08lx\n", sfi.szDisplayName, sfi.dwAttributes);
2151 if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
2155 TRACE("-- Add %s at %u\n", sfi.szDisplayName, tmpFolder->m_iIndent);
2157 /* Add the item at the end of the list */
2160 iItemID = CBAddString(hwnd,sfi.szDisplayName);
2162 /* Insert the item at the iInsertId position*/
2165 iItemID = CBInsertString(hwnd,sfi.szDisplayName,iInsertId);
2168 CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
2172 MemFree( tmpFolder );
2177 /***********************************************************************
2178 * FILEDLG95_LOOKIN_InsertItemAfterParent
2180 * Insert an item below its parent
2182 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
2185 LPITEMIDLIST pidlParent = GetParentPidl(pidl);
2190 iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
2194 iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
2197 /* Free pidlParent memory */
2198 COMDLG32_SHFree((LPVOID)pidlParent);
2200 return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
2203 /***********************************************************************
2204 * FILEDLG95_LOOKIN_SelectItem
2206 * Adds an absolute pidl item to the lookin combo box
2207 * returns the index of the inserted item
2209 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
2212 LookInInfos *liInfos;
2216 iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
2218 liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2222 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
2223 iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
2228 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2229 while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
2233 if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
2235 if(iRemovedItem < iItemPos)
2240 CBSetCurSel(hwnd,iItemPos);
2241 liInfos->uSelectedItem = iItemPos;
2247 /***********************************************************************
2248 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2250 * Remove the item with an expansion level over iExpansionLevel
2252 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
2256 LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2260 if(liInfos->iMaxIndentation <= 2)
2263 if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
2265 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2266 COMDLG32_SHFree(tmpFolder->pidlItem);
2268 CBDeleteString(hwnd,iItemPos);
2269 liInfos->iMaxIndentation--;
2277 /***********************************************************************
2278 * FILEDLG95_LOOKIN_SearchItem
2280 * Search for pidl in the lookin combo box
2281 * returns the index of the found item
2283 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
2286 int iCount = CBGetCount(hwnd);
2288 TRACE("0x%08x 0x%x\n",searchArg, iSearchMethod);
2290 if (iCount != CB_ERR)
2294 LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
2296 if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
2298 if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
2306 /***********************************************************************
2307 * FILEDLG95_LOOKIN_Clean
2309 * Clean the memory used by the lookin combo box
2311 static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
2313 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2315 int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
2319 /* Delete each string of the combo and their associated data */
2320 if (iCount != CB_ERR)
2322 for(iPos = iCount-1;iPos>=0;iPos--)
2324 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos);
2325 COMDLG32_SHFree(tmpFolder->pidlItem);
2327 CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
2331 /* LookInInfos structure */
2332 RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
2335 /***********************************************************************
2336 * FILEDLG95_FILENAME_FillFromSelection
2338 * fills the edit box from the cached DataObject
2340 void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd)
2342 FileOpenDlgInfos *fodInfos;
2344 UINT nFiles = 0, nFileToOpen, nFileSelected, nLength = 0;
2345 char lpstrTemp[MAX_PATH];
2346 LPSTR lpstrAllFile = NULL, lpstrCurrFile = NULL;
2349 fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2351 /* Count how many files we have */
2352 nFileSelected = GetNumSelected( fodInfos->Shell.FOIDataObject );
2354 /* calculate the string length, count files */
2355 if (nFileSelected >= 1)
2357 nLength += 3; /* first and last quotes, trailing \0 */
2358 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2360 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2364 /* get the total length of the selected file names*/
2365 lpstrTemp[0] = '\0';
2366 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2368 if ( ! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl) ) /* Ignore folders */
2370 nLength += strlen( lpstrTemp ) + 3;
2373 COMDLG32_SHFree( pidl );
2378 /* allocate the buffer */
2379 if (nFiles <= 1) nLength = MAX_PATH;
2380 lpstrAllFile = (LPSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength);
2381 lpstrAllFile[0] = '\0';
2383 /* Generate the string for the edit control */
2386 lpstrCurrFile = lpstrAllFile;
2387 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2389 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2393 /* get the file name */
2394 lpstrTemp[0] = '\0';
2395 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2397 if (! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl)) /* Ignore folders */
2401 *lpstrCurrFile++ = '\"';
2402 strcpy( lpstrCurrFile, lpstrTemp );
2403 lpstrCurrFile += strlen( lpstrTemp );
2404 strcpy( lpstrCurrFile, "\" " );
2409 strcpy( lpstrAllFile, lpstrTemp );
2412 COMDLG32_SHFree( (LPVOID) pidl );
2417 SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile );
2418 HeapFree(GetProcessHeap(),0, lpstrAllFile );
2422 /* copied from shell32 to avoid linking to it */
2423 static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
2428 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL);
2429 COMDLG32_SHFree(src->u.pOleStr);
2433 lstrcpynA((LPSTR)dest, src->u.cStr, len);
2436 case STRRET_OFFSETA:
2437 lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
2441 FIXME("unknown type!\n");
2444 *(LPSTR)dest = '\0';
2451 /***********************************************************************
2452 * FILEDLG95_FILENAME_GetFileNames
2454 * copies the filenames to a 0-delimited string list (A\0B\0C\0\0)
2456 int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPSTR * lpstrFileList, UINT * sizeUsed)
2458 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2459 UINT nStrCharCount = 0; /* index in src buffer */
2460 UINT nFileIndex = 0; /* index in dest buffer */
2461 UINT nFileCount = 0; /* number of files */
2462 UINT nStrLen = 0; /* length of string in edit control */
2463 LPSTR lpstrEdit; /* buffer for string from edit control */
2467 /* get the filenames from the edit control */
2468 nStrLen = SendMessageA(fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0);
2469 lpstrEdit = MemAlloc(nStrLen+1);
2470 GetDlgItemTextA(hwnd, IDC_FILENAME, lpstrEdit, nStrLen+1);
2472 TRACE("nStrLen=%u str=%s\n", nStrLen, lpstrEdit);
2474 /* we might get single filename without any '"',
2475 * so we need nStrLen + terminating \0 + end-of-list \0 */
2476 *lpstrFileList = MemAlloc(nStrLen+2);
2479 /* build 0-delimited file list from filenames */
2480 while ( nStrCharCount <= nStrLen )
2482 if ( lpstrEdit[nStrCharCount]=='"' )
2485 while ((lpstrEdit[nStrCharCount]!='"') && (nStrCharCount <= nStrLen))
2487 (*lpstrFileList)[nFileIndex++] = lpstrEdit[nStrCharCount];
2491 (*lpstrFileList)[nFileIndex++] = '\0';
2498 /* single, unquoted string */
2499 if ((nStrLen > 0) && (*sizeUsed == 0) )
2501 strcpy(*lpstrFileList, lpstrEdit);
2502 nFileIndex = strlen(lpstrEdit) + 1;
2503 (*sizeUsed) = nFileIndex;
2508 (*lpstrFileList)[nFileIndex] = '\0';
2515 #define SETDefFormatEtc(fe,cf,med) \
2517 (fe).cfFormat = cf;\
2518 (fe).dwAspect = DVASPECT_CONTENT; \
2525 * DATAOBJECT Helper functions
2528 /***********************************************************************
2529 * COMCTL32_ReleaseStgMedium
2531 * like ReleaseStgMedium from ole32
2533 static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium)
2535 if(medium.pUnkForRelease)
2537 IUnknown_Release(medium.pUnkForRelease);
2541 GlobalUnlock(medium.u.hGlobal);
2542 GlobalFree(medium.u.hGlobal);
2546 /***********************************************************************
2547 * GetPidlFromDataObject
2549 * Return pidl(s) by number from the cached DataObject
2551 * nPidlIndex=0 gets the fully qualified root path
2553 LPITEMIDLIST GetPidlFromDataObject ( IDataObject *doSelected, UINT nPidlIndex)
2557 FORMATETC formatetc;
2558 LPITEMIDLIST pidl = NULL;
2560 TRACE("sv=%p index=%u\n", doSelected, nPidlIndex);
2562 /* Set the FORMATETC structure*/
2563 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2565 /* Get the pidls from IDataObject */
2566 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2568 LPIDA cida = GlobalLock(medium.u.hGlobal);
2569 if(nPidlIndex <= cida->cidl)
2571 pidl = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[nPidlIndex]]));
2573 COMCTL32_ReleaseStgMedium(medium);
2578 /***********************************************************************
2581 * Return the number of selected items in the DataObject.
2584 UINT GetNumSelected( IDataObject *doSelected )
2588 FORMATETC formatetc;
2590 TRACE("sv=%p\n", doSelected);
2592 if (!doSelected) return 0;
2594 /* Set the FORMATETC structure*/
2595 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2597 /* Get the pidls from IDataObject */
2598 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2600 LPIDA cida = GlobalLock(medium.u.hGlobal);
2601 retVal = cida->cidl;
2602 COMCTL32_ReleaseStgMedium(medium);
2612 /***********************************************************************
2615 * Get the pidl's display name (relative to folder) and
2616 * put it in lpstrFileName.
2618 * Return NOERROR on success,
2622 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
2627 TRACE("sf=%p pidl=%p\n", lpsf, pidl);
2632 SHGetDesktopFolder(&lpsf);
2633 hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
2634 IShellFolder_Release(lpsf);
2638 /* Get the display name of the pidl relative to the folder */
2639 if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf, pidl, dwFlags, &str)))
2641 return COMDLG32_StrRetToStrNA(lpstrFileName, MAX_PATH, &str, pidl);
2646 /***********************************************************************
2647 * GetShellFolderFromPidl
2649 * pidlRel is the item pidl relative
2650 * Return the IShellFolder of the absolute pidl
2652 IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
2654 IShellFolder *psf = NULL,*psfParent;
2656 TRACE("%p\n", pidlAbs);
2658 if(SUCCEEDED(SHGetDesktopFolder(&psfParent)))
2661 if(pidlAbs && pidlAbs->mkid.cb)
2663 if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
2665 IShellFolder_Release(psfParent);
2669 /* return the desktop */
2675 /***********************************************************************
2678 * Return the LPITEMIDLIST to the parent of the pidl in the list
2680 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
2682 LPITEMIDLIST pidlParent;
2684 TRACE("%p\n", pidl);
2686 pidlParent = COMDLG32_PIDL_ILClone(pidl);
2687 COMDLG32_PIDL_ILRemoveLastID(pidlParent);
2692 /***********************************************************************
2695 * returns the pidl of the file name relative to folder
2696 * NULL if an error occured
2698 LPITEMIDLIST GetPidlFromName(IShellFolder *lpsf,LPCSTR lpcstrFileName)
2702 WCHAR lpwstrDirName[MAX_PATH];
2704 TRACE("sf=%p file=%s\n", lpsf, lpcstrFileName);
2706 if(!lpcstrFileName) return NULL;
2708 MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,lpcstrFileName,-1,(LPWSTR)lpwstrDirName,MAX_PATH);
2712 SHGetDesktopFolder(&lpsf);
2713 pidl = GetPidlFromName(lpsf, lpcstrFileName);
2714 IShellFolder_Release(lpsf);
2718 IShellFolder_ParseDisplayName(lpsf, 0, NULL, (LPWSTR)lpwstrDirName, &ulEaten, &pidl, NULL);
2725 BOOL IsPidlFolder (LPSHELLFOLDER psf, LPITEMIDLIST pidl)
2727 ULONG uAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
2730 TRACE("%p, %p\n", psf, pidl);
2732 ret = IShellFolder_GetAttributesOf( psf, 1, &pidl, &uAttr );
2734 TRACE("-- 0x%08lx 0x%08lx\n", uAttr, ret);
2735 /* see documentation shell 4.1*/
2736 return uAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER);
2739 /***********************************************************************
2740 * BrowseSelectedFolder
2742 static BOOL BrowseSelectedFolder(HWND hwnd)
2744 BOOL bBrowseSelFolder = FALSE;
2745 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2749 if (GetNumSelected(fodInfos->Shell.FOIDataObject) == 1)
2751 LPITEMIDLIST pidlSelection;
2753 /* get the file selected */
2754 pidlSelection = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, 1);
2755 if (IsPidlFolder (fodInfos->Shell.FOIShellFolder, pidlSelection))
2757 if ( FAILED( IShellBrowser_BrowseObject( fodInfos->Shell.FOIShellBrowser,
2758 pidlSelection, SBSP_RELATIVE ) ) )
2760 MessageBoxA( hwnd, "Path does not exist", fodInfos->ofnInfos->lpstrTitle,
2761 MB_OK | MB_ICONEXCLAMATION );
2764 bBrowseSelFolder = TRUE;
2766 COMDLG32_SHFree( pidlSelection );
2769 return bBrowseSelFolder;
2773 * Memory allocation methods */
2774 static void *MemAlloc(UINT size)
2776 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
2779 static void MemFree(void *mem)
2783 HeapFree(GetProcessHeap(),0,mem);