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_NOCHANGEDIR, OFN_NODEREFERENCELINKS, OFN_NOREADONLYRETURN,
30 * OFN_NOTESTFILECREATE, OFN_OVERWRITEPROMPT, OFN_USEMONIKERS
32 * FIXME: lCustData for lpfnHook (WM_INITDIALOG)
49 #include "debugtools.h"
53 #include "filedlgbrowser.h"
55 #include "wine/obj_contextmenu.h"
57 DEFAULT_DEBUG_CHANNEL(commdlg);
59 #define UNIMPLEMENTED_FLAGS \
60 (OFN_CREATEPROMPT | OFN_DONTADDTORECENT |\
61 OFN_ENABLEINCLUDENOTIFY | OFN_ENABLESIZING | OFN_EXTENSIONDIFFERENT |\
62 OFN_NOCHANGEDIR | OFN_NODEREFERENCELINKS | OFN_NOREADONLYRETURN |\
63 OFN_NOTESTFILECREATE | OFN_OVERWRITEPROMPT /*| OFN_USEMONIKERS*/)
65 #define IsHooked(fodInfos) \
66 ((fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook)
67 /***********************************************************************
68 * Data structure and global variables
70 typedef struct SFolder
72 int m_iImageIndex; /* Index of picture in image list */
74 int m_iIndent; /* Indentation index */
75 LPITEMIDLIST pidlItem; /* absolute pidl of the item */
79 typedef struct tagLookInInfo
86 /***********************************************************************
87 * Defines and global variables
90 /* Draw item constant */
97 /* SearchItem methods */
100 #define ITEM_NOTFOUND -1
102 /* Undefined windows message sent by CreateViewObject*/
103 #define WM_GETISHELLBROWSER WM_USER+7
106 * Those macros exist in windowsx.h. However, you can't really use them since
107 * they rely on the UNICODE defines and can't be used inside Wine itself.
110 /* Combo box macros */
111 #define CBAddString(hwnd,str) \
112 SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str);
114 #define CBInsertString(hwnd,str,pos) \
115 SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str);
117 #define CBDeleteString(hwnd,pos) \
118 SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0);
120 #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
121 SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr);
123 #define CBGetItemDataPtr(hwnd,iItemId) \
124 SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0)
126 #define CBGetLBText(hwnd,iItemId,str) \
127 SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str);
129 #define CBGetCurSel(hwnd) \
130 SendMessageA(hwnd,CB_GETCURSEL,0,0);
132 #define CBSetCurSel(hwnd,pos) \
133 SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0);
135 #define CBGetCount(hwnd) \
136 SendMessageA(hwnd,CB_GETCOUNT,0,0);
137 #define CBShowDropDown(hwnd,show) \
138 SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0);
139 #define CBSetItemHeight(hwnd,index,height) \
140 SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height);
143 const char *FileOpenDlgInfosStr = "FileOpenDlgInfos"; /* windows property description string */
144 const char *LookInInfosStr = "LookInInfos"; /* LOOKIN combo box property */
146 static const char defaultFilter[] = "*.*";
148 /***********************************************************************
152 /* Internal functions used by the dialog */
153 static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam);
154 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
155 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd);
156 BOOL FILEDLG95_OnOpen(HWND hwnd);
157 static LRESULT FILEDLG95_InitControls(HWND hwnd);
158 static void FILEDLG95_Clean(HWND hwnd);
160 /* Functions used by the shell navigation */
161 static LRESULT FILEDLG95_SHELL_Init(HWND hwnd);
162 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd);
163 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb);
164 static void FILEDLG95_SHELL_Clean(HWND hwnd);
165 static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd);
167 /* Functions used by the filetype combo box */
168 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd);
169 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode);
170 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt);
171 static void FILEDLG95_FILETYPE_Clean(HWND hwnd);
173 /* Functions used by the Look In combo box */
174 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo);
175 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);
176 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);
177 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);
178 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod);
179 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl);
180 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd);
181 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
182 static void FILEDLG95_LOOKIN_Clean(HWND hwnd);
184 /* Miscellaneous tool functions */
185 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
186 HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
187 IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
188 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
189 LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
191 /* Shell memory allocation */
192 static void *MemAlloc(UINT size);
193 static void MemFree(void *mem);
195 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos);
196 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
197 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
198 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
199 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);
200 static BOOL BrowseSelectedFolder(HWND hwnd);
202 /***********************************************************************
205 * Creates an Open common dialog box that lets the user select
206 * the drive, directory, and the name of a file or set of files to open.
208 * IN : The FileOpenDlgInfos structure associated with the dialog
209 * OUT : TRUE on success
210 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
212 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)
220 /* test for missing functionality */
221 if (fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS)
223 FIXME("Flags 0x%08lx not yet implemented\n",
224 fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS);
227 /* Create the dialog from a template */
229 if(!(hRes = FindResourceA(COMMDLG_hInstance32,MAKEINTRESOURCEA(NEWFILEOPENORD),RT_DIALOGA)))
231 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
234 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hRes )) ||
235 !(template = LockResource( hDlgTmpl )))
237 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
241 /* old style hook messages */
242 if (IsHooked(fodInfos))
244 fodInfos->HookMsg.fileokstring = RegisterWindowMessageA(FILEOKSTRING);
245 fodInfos->HookMsg.lbselchstring = RegisterWindowMessageA(LBSELCHSTRING);
246 fodInfos->HookMsg.helpmsgstring = RegisterWindowMessageA(HELPMSGSTRING);
247 fodInfos->HookMsg.sharevistring = RegisterWindowMessageA(SHAREVISTRING);
250 lRes = DialogBoxIndirectParamA(COMMDLG_hInstance32,
251 (LPDLGTEMPLATEA) template,
252 fodInfos->ofnInfos->hwndOwner,
253 (DLGPROC) FileOpenDlgProc95,
256 /* Unable to create the dialog */
263 /***********************************************************************
266 * Call GetFileName95 with this structure and clean the memory.
268 * IN : The OPENFILENAMEA initialisation structure passed to
269 * GetOpenFileNameA win api function (see filedlg.c)
271 BOOL WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
275 FileOpenDlgInfos *fodInfos;
277 LPCSTR lpstrInitialDir = (LPCSTR)-1;
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 dwFlags = ofn->Flags;
292 ofn->Flags = ofn->Flags|OFN_WINE;
294 /* Initialise the dialog property */
295 fodInfos->DlgInfos.dwDlgProp = 0;
296 fodInfos->DlgInfos.hwndCustomDlg = (HWND)NULL;
301 ret = GetFileName95(fodInfos);
304 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
305 ret = GetFileName95(fodInfos);
311 if (lpstrInitialDir != (LPCSTR)-1)
313 MemFree((LPVOID)(ofn->lpstrInitialDir));
314 ofn->lpstrInitialDir = lpstrInitialDir;
317 ofn->Flags = dwFlags;
318 ofn->hInstance = hInstance;
319 MemFree((LPVOID)(fodInfos));
323 /***********************************************************************
326 * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
327 * Call GetFileName95 with this structure and clean the memory.
329 * FIXME: lpstrCustomFilter has to converted back
333 /* converting IN arguments */
334 #define AllocInArgWtoA(arg, save) \
337 DWORD _len = WideCharToMultiByte( CP_ACP, 0, arg, -1, NULL, 0, NULL, NULL ); \
339 arg = MemAlloc(_len); \
340 WideCharToMultiByte( CP_ACP, 0, save, -1, (LPSTR)arg, _len, NULL, NULL ); \
343 #define FreeInArg(arg, save) \
346 MemFree((LPSTR)arg); \
350 /* converting OUT arguments */
351 #define AllocOutArgWtoA(arg, save, len) \
355 arg = MemAlloc(len); \
358 #define FreeOutArg(arg, save, len) \
361 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)(arg), -1, (save), (len) ); \
366 BOOL WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
369 FileOpenDlgInfos *fodInfos;
373 LPWSTR lpstrFile = NULL;
374 LPWSTR lpstrFileTitle = NULL;
376 /* in/out arguments */
377 LPWSTR lpstrCustomFilter = NULL;
379 /* input arguments */
380 LPCWSTR lpstrFilter = NULL;
381 LPCWSTR lpstrInitialDir = NULL;
382 LPCWSTR lpstrTitle = NULL;
383 LPCWSTR lpstrDefExt = NULL;
384 LPCWSTR lpTemplateName = NULL;
387 /* Initialise FileOpenDlgInfos structure*/
388 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
389 ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
391 /* Pass in the original ofn */
392 fodInfos->ofnInfos = (LPOPENFILENAMEA) ofn;
394 /* convert lpstrFilter */
395 if (ofn->lpstrFilter)
401 lpstrFilter = ofn->lpstrFilter;
403 /* filter is a list... title\0ext\0......\0\0 */
404 s = ofn->lpstrFilter;
406 while (*s) s = s+strlenW(s)+1;
408 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
409 len = WideCharToMultiByte( CP_ACP, 0, ofn->lpstrFilter, n, NULL, 0, NULL, NULL );
410 y = (LPSTR)MemAlloc(len);
411 WideCharToMultiByte( CP_ACP, 0, ofn->lpstrFilter, n, y, len, NULL, NULL );
412 (LPSTR)ofn->lpstrFilter = y;
415 /* convert lpstrCustomFilter */
416 if (ofn->lpstrCustomFilter)
422 lpstrCustomFilter = ofn->lpstrCustomFilter;
423 /* filter is a list... title\0ext\0......\0\0 */
424 s = ofn->lpstrCustomFilter;
425 while (*s) s = s+strlenW(s)+1;
427 n = s - ofn->lpstrCustomFilter;
428 len = WideCharToMultiByte( CP_ACP, 0, ofn->lpstrCustomFilter, n, NULL, 0, NULL, NULL );
429 y = (LPSTR)MemAlloc(len);
430 WideCharToMultiByte( CP_ACP, 0, ofn->lpstrCustomFilter, n, y, len, NULL, NULL );
431 (LPSTR)ofn->lpstrCustomFilter = y;
434 /* convert string arguments, save others */
435 AllocOutArgWtoA(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
436 AllocOutArgWtoA(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
437 AllocInArgWtoA(ofn->lpstrInitialDir, lpstrInitialDir);
438 AllocInArgWtoA(ofn->lpstrTitle, lpstrTitle);
439 AllocInArgWtoA(ofn->lpstrDefExt, lpstrDefExt);
440 AllocInArgWtoA(ofn->lpTemplateName, lpTemplateName);
441 dwFlags = ofn->Flags;
442 hInstance = ofn->hInstance;
444 ofn->Flags = ofn->Flags|OFN_WINE|OFN_UNICODE;
445 ofn->hInstance = MapHModuleLS(ofn->hInstance);
450 ret = GetFileName95(fodInfos);
453 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
454 ret = GetFileName95(fodInfos);
460 /* restore saved IN arguments and convert OUT arguments back */
461 ofn->Flags = dwFlags;
462 ofn->hInstance = hInstance;
463 FreeInArg(ofn->lpstrFilter, lpstrFilter);
464 FreeInArg(ofn->lpstrCustomFilter, lpstrCustomFilter);
465 FreeOutArg(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
466 FreeOutArg(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
467 FreeInArg(ofn->lpstrInitialDir, lpstrInitialDir);
468 FreeInArg(ofn->lpstrTitle, lpstrTitle);
469 FreeInArg(ofn->lpstrDefExt, lpstrDefExt);
470 FreeInArg(ofn->lpTemplateName, lpTemplateName);
472 MemFree((LPVOID)(fodInfos));
476 void ArrangeCtrlPositions( HWND hwndChildDlg, HWND hwndParentDlg)
478 HWND hwndChild,hwndStc32;
479 RECT rectParent, rectChild, rectCtrl, rectStc32, rectTemp;
481 POINT ptParentClient;
485 ptMoveCtl.x = ptMoveCtl.y = 0;
486 hwndStc32=GetDlgItem(hwndChildDlg,stc32);
487 GetClientRect(hwndParentDlg,&rectParent);
488 GetClientRect(hwndChildDlg,&rectChild);
492 GetWindowRect(hwndStc32,&rectStc32);
493 MapWindowPoints(0, hwndChildDlg,(LPPOINT)&rectStc32,2);
494 CopyRect(&rectTemp,&rectStc32);
496 SetRect(&rectStc32,rectStc32.left,rectStc32.top,rectStc32.left + (rectParent.right-rectParent.left),rectStc32.top+(rectParent.bottom-rectParent.top));
497 SetWindowPos(hwndStc32,0,rectStc32.left,rectStc32.top,rectStc32.right-rectStc32.left,rectStc32.bottom-rectStc32.top,SWP_NOMOVE|SWP_NOZORDER | SWP_NOACTIVATE);
499 if(rectStc32.right < rectTemp.right)
501 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
506 ptMoveCtl.x = (rectStc32.right - rectTemp.right);
507 ptParentClient.x = max((rectParent.right-rectParent.left),((rectChild.right-rectChild.left)+rectStc32.right-rectTemp.right));
510 if(rectStc32.bottom < rectTemp.bottom)
512 ptParentClient.y = max((rectParent.bottom-rectParent.top),(rectChild.bottom-rectChild.top));
517 ptMoveCtl.y = (rectStc32.bottom - rectTemp.bottom);
518 ptParentClient.y = max((rectParent.bottom-rectParent.top),((rectChild.bottom-rectChild.top)+rectStc32.bottom-rectTemp.bottom));
523 if( (GetWindow(hwndChildDlg,GW_CHILD)) == (HWND) NULL) return;
525 SetRectEmpty(&rectTemp);
526 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
527 ptParentClient.y = (rectParent.bottom-rectParent.top) + (rectChild.bottom-rectChild.top);
528 ptMoveCtl.y = rectParent.bottom-rectParent.top;
531 SetRect(&rectParent,rectParent.left,rectParent.top,rectParent.left+ptParentClient.x,rectParent.top+ptParentClient.y);
532 AdjustWindowRectEx( &rectParent,GetWindowLongA(hwndParentDlg,GWL_STYLE),FALSE,GetWindowLongA(hwndParentDlg,GWL_EXSTYLE));
534 SetWindowPos(hwndChildDlg, 0, 0,0, ptParentClient.x,ptParentClient.y, SWP_NOZORDER );
535 SetWindowPos(hwndParentDlg, 0, rectParent.left,rectParent.top, (rectParent.right- rectParent.left),
536 (rectParent.bottom-rectParent.top),SWP_NOMOVE | SWP_NOZORDER);
538 hwndChild = GetWindow(hwndChildDlg,GW_CHILD);
541 GetWindowRect(hwndStc32,&rectStc32);
542 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
545 SetRect(&rectStc32,0,0,0,0);
551 if(hwndChild != hwndStc32)
553 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
555 GetWindowRect(hwndChild,&rectCtrl);
556 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
559 Check the initial position of the controls relative to the initial
560 position and size of stc32 (before it is expanded).
562 if (rectCtrl.left >= rectTemp.right && rectCtrl.top >= rectTemp.bottom)
564 rectCtrl.left += ptMoveCtl.x;
565 rectCtrl.top += ptMoveCtl.y;
567 else if (rectCtrl.left >= rectTemp.right)
569 rectCtrl.left += ptMoveCtl.x;
571 else if (rectCtrl.top >= rectTemp.bottom)
573 rectCtrl.top += ptMoveCtl.y;
576 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
577 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
578 SWP_NOSIZE | SWP_NOZORDER );
580 } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
582 hwndChild = GetWindow(hwndParentDlg,GW_CHILD);
586 GetWindowRect(hwndStc32,&rectStc32);
587 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
588 ptMoveCtl.x = rectStc32.left - 0;
589 ptMoveCtl.y = rectStc32.top - 0;
594 if(hwndChild != hwndChildDlg)
596 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
598 GetWindowRect(hwndChild,&rectCtrl);
599 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
601 rectCtrl.left += ptMoveCtl.x;
602 rectCtrl.top += ptMoveCtl.y;
604 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
605 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
606 SWP_NOSIZE |SWP_NOZORDER );
608 } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
614 HRESULT WINAPI FileOpenDlgProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
616 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(GetParent(hwnd),FileOpenDlgInfosStr);
619 TRACE("0x%04x\n", uMsg);
626 fodInfos = (FileOpenDlgInfos *)lParam;
627 lParam = (LPARAM) fodInfos->ofnInfos;
628 ArrangeCtrlPositions(hwnd,GetParent(hwnd));
630 if(fodInfos && IsHooked(fodInfos))
631 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
636 if(fodInfos && IsHooked(fodInfos))
637 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
639 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
642 HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos, HWND hwnd)
651 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATE ||
652 fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
654 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
656 if( !(template = LockResource( fodInfos->ofnInfos->hInstance)))
658 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
664 if (!(hRes = FindResourceA(MapHModuleSL(fodInfos->ofnInfos->hInstance),
665 (fodInfos->ofnInfos->lpTemplateName), RT_DIALOGA)))
667 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
670 if (!(hDlgTmpl = LoadResource( MapHModuleSL(fodInfos->ofnInfos->hInstance),
671 hRes )) || !(template = LockResource( hDlgTmpl )))
673 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
678 hChildDlg= CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,template,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
681 ShowWindow(hChildDlg,SW_SHOW);
685 else if( IsHooked(fodInfos))
689 GetClientRect(hwnd,&rectHwnd);
690 tmplate.style = WS_CHILD | WS_CLIPSIBLINGS;
691 tmplate.dwExtendedStyle = 0;
695 tmplate.cx = rectHwnd.right-rectHwnd.left;
696 tmplate.cy = rectHwnd.bottom-rectHwnd.top;
698 return CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,&tmplate,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
703 /***********************************************************************
704 * SendCustomDlgNotificationMessage
706 * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
709 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
711 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndParentDlg,FileOpenDlgInfosStr);
713 TRACE("0x%04x 0x%04x\n",hwndParentDlg, uCode);
715 if(!fodInfos) return 0;
717 if(fodInfos->ofnInfos->Flags & OFN_UNICODE)
718 FIXME("sending OPENFILENAMEA structure. Hook is expecting OPENFILENAMEW!");
720 if(fodInfos->DlgInfos.hwndCustomDlg)
724 ofnNotify.hdr.hwndFrom=hwndParentDlg;
725 ofnNotify.hdr.idFrom=0;
726 ofnNotify.hdr.code = uCode;
727 ofnNotify.lpOFN = fodInfos->ofnInfos;
728 TRACE("CALL NOTIFY for %x\n", uCode);
729 ret = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);
730 TRACE("RET NOTIFY\n");
736 /***********************************************************************
737 * FILEDLG95_HandleCustomDialogMessages
739 * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
741 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
745 char lpstrPath[MAX_PATH];
746 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
747 if(!fodInfos) return -1;
751 case CDM_GETFILEPATH:
752 GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
753 lpstrFileSpec = (LPSTR)COMDLG32_PathFindFileNameA(lpstrPath);
754 if (lpstrFileSpec==lpstrPath)
756 char lpstrCurrentDir[MAX_PATH];
757 /* Prepend the current path */
758 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrCurrentDir);
759 if ((LPSTR)lParam!=NULL)
760 snprintf((LPSTR)lParam,(int)wParam,"%s\\%s",lpstrCurrentDir,lpstrPath);
761 reqSize=strlen(lpstrCurrentDir)+1+strlen(lpstrPath)+1;
765 lstrcpynA((LPSTR)lParam,(LPSTR)lpstrPath,(int)wParam);
766 reqSize=strlen(lpstrPath);
768 /* return the required buffer size */
771 case CDM_GETFOLDERPATH:
772 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);
773 if ((LPSTR)lParam!=NULL)
774 lstrcpynA((LPSTR)lParam,lpstrPath,(int)wParam);
775 return strlen(lpstrPath);
778 reqSize=GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
779 lpstrFileSpec = (LPSTR)COMDLG32_PathFindFileNameA(lpstrPath);
780 if ((LPSTR)lParam!=NULL)
781 lstrcpynA((LPSTR)lParam, lpstrFileSpec, (int)wParam);
782 return strlen(lpstrFileSpec);
784 case CDM_SETCONTROLTEXT:
786 SetDlgItemTextA( hwnd, (UINT) wParam, (LPSTR) lParam );
789 case CDM_HIDECONTROL:
791 FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");
797 /***********************************************************************
800 * File open dialog procedure
802 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
805 TRACE("0x%04x 0x%04x\n", hwnd, uMsg);
812 FileOpenDlgInfos * fodInfos = (FileOpenDlgInfos *)lParam;
814 /* Adds the FileOpenDlgInfos in the property list of the dialog
815 so it will be easily accessible through a GetPropA(...) */
816 SetPropA(hwnd, FileOpenDlgInfosStr, (HANDLE) fodInfos);
818 fodInfos->DlgInfos.hwndCustomDlg =
819 CreateTemplateDialog((FileOpenDlgInfos *)lParam, hwnd);
821 FILEDLG95_InitControls(hwnd);
822 SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE);
823 FILEDLG95_FillControls(hwnd, wParam, lParam);
824 SendCustomDlgNotificationMessage(hwnd,CDN_SELCHANGE);
828 return FILEDLG95_OnWMCommand(hwnd, wParam, lParam);
831 switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
834 FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT) lParam);
840 case WM_GETISHELLBROWSER:
841 return FILEDLG95_OnWMGetIShellBrowser(hwnd);
844 RemovePropA(hwnd, FileOpenDlgInfosStr);
849 LPNMHDR lpnmh = (LPNMHDR)lParam;
852 /* set up the button tooltips strings */
853 if(TTN_GETDISPINFOA == lpnmh->code )
855 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
856 switch(lpnmh->idFrom )
858 /* Up folder button */
859 case FCIDM_TB_UPFOLDER:
860 stringId = IDS_UPFOLDER;
862 /* New folder button */
863 case FCIDM_TB_NEWFOLDER:
864 stringId = IDS_NEWFOLDER;
866 /* List option button */
867 case FCIDM_TB_SMALLICON:
868 stringId = IDS_LISTVIEW;
870 /* Details option button */
871 case FCIDM_TB_REPORTVIEW:
872 stringId = IDS_REPORTVIEW;
875 case FCIDM_TB_DESKTOP:
876 stringId = IDS_TODESKTOP;
881 lpdi->hinst = COMMDLG_hInstance32;
882 lpdi->lpszText = (LPSTR) stringId;
887 if(uMsg >= CDM_FIRST && uMsg <= CDM_LAST)
888 return FILEDLG95_HandleCustomDialogMessages(hwnd, uMsg, wParam, lParam);
893 /***********************************************************************
894 * FILEDLG95_InitControls
896 * WM_INITDIALOG message handler (before hook notification)
898 static LRESULT FILEDLG95_InitControls(HWND hwnd)
902 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
903 {VIEW_PARENTFOLDER, FCIDM_TB_UPFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
904 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
905 {VIEW_NEWFOLDER+1, FCIDM_TB_DESKTOP, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
906 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
907 {VIEW_NEWFOLDER, FCIDM_TB_NEWFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
908 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
909 {VIEW_LIST, FCIDM_TB_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
910 {VIEW_DETAILS, FCIDM_TB_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
914 { HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR },
915 { COMDLG32_hInstance, 800 } // desktop icon
920 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
922 TRACE("%p\n", fodInfos);
924 /* Get the hwnd of the controls */
925 fodInfos->DlgInfos.hwndFileName = GetDlgItem(hwnd,IDC_FILENAME);
926 fodInfos->DlgInfos.hwndFileTypeCB = GetDlgItem(hwnd,IDC_FILETYPE);
927 fodInfos->DlgInfos.hwndLookInCB = GetDlgItem(hwnd,IDC_LOOKIN);
929 /* construct the toolbar */
930 GetWindowRect(GetDlgItem(hwnd,IDC_TOOLBARSTATIC),&rectTB);
931 MapWindowPoints( 0, hwnd,(LPPOINT)&rectTB,2);
933 fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, (LPSTR) NULL,
934 WS_CHILD | WS_GROUP | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE,
935 0, 0, 150, 26, hwnd, (HMENU) IDC_TOOLBAR, COMMDLG_hInstance32, NULL);
937 SetWindowPos(fodInfos->DlgInfos.hwndTB, 0,
938 rectTB.left,rectTB.top, rectTB.right-rectTB.left, rectTB.bottom-rectTB.top,
939 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
941 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
943 /* fixme: use TB_LOADIMAGES when implemented */
944 /* SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/
945 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 12, (LPARAM) &tba[0]);
946 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 1, (LPARAM) &tba[1]);
948 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSA, (WPARAM) 9,(LPARAM) &tbb);
949 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_AUTOSIZE, 0, 0);
951 /* Set the window text with the text specified in the OPENFILENAME structure */
952 if(fodInfos->ofnInfos->lpstrTitle)
954 SetWindowTextA(hwnd,fodInfos->ofnInfos->lpstrTitle);
956 else if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
958 SetWindowTextA(hwnd,"Save");
961 /* Initialise the file name edit control */
962 if(fodInfos->ofnInfos->lpstrFile)
964 LPSTR lpstrFile = COMDLG32_PathFindFileNameA(fodInfos->ofnInfos->lpstrFile);
965 SetDlgItemTextA(hwnd, IDC_FILENAME, lpstrFile);
968 /* Must the open as read only check box be checked ?*/
969 if(fodInfos->ofnInfos->Flags & OFN_READONLY)
971 SendDlgItemMessageA(hwnd,IDC_OPENREADONLY,BM_SETCHECK,(WPARAM)TRUE,0);
974 /* Must the open as read only check box be hid ?*/
975 if(fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY)
977 ShowWindow(GetDlgItem(hwnd,IDC_OPENREADONLY),SW_HIDE);
980 /* Must the help button be hid ?*/
981 if (!(fodInfos->ofnInfos->Flags & OFN_SHOWHELP))
983 ShowWindow(GetDlgItem(hwnd, pshHelp), SW_HIDE);
986 /* Resize the height, if open as read only checkbox ad help button
987 are hidden and we are not using a custom template */
988 if ( (fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) &&
989 (!(fodInfos->ofnInfos->Flags &
990 (OFN_SHOWHELP|OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE))))
992 RECT rectDlg, rectHelp, rectCancel;
993 GetWindowRect(hwnd, &rectDlg);
994 GetWindowRect(GetDlgItem(hwnd, pshHelp), &rectHelp);
995 GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rectCancel);
996 /* subtract the height of the help button plus the space between
997 the help button and the cancel button to the height of the dialog */
998 SetWindowPos(hwnd, 0, 0, 0, rectDlg.right-rectDlg.left,
999 (rectDlg.bottom-rectDlg.top) - (rectHelp.bottom - rectCancel.bottom),
1000 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
1003 /* change Open to Save FIXME: use resources */
1004 if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
1006 SetDlgItemTextA(hwnd,IDOK,"&Save");
1007 SetDlgItemTextA(hwnd,IDC_LOOKINSTATIC,"Save &in");
1012 /***********************************************************************
1013 * FILEDLG95_FillControls
1015 * WM_INITDIALOG message handler (after hook notification)
1017 static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam)
1019 LPITEMIDLIST pidlItemId = NULL;
1021 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) lParam;
1023 TRACE("dir=%s file=%s\n",
1024 fodInfos->ofnInfos->lpstrInitialDir, fodInfos->ofnInfos->lpstrFile);
1026 /* Get the initial directory pidl */
1028 if(!(pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,fodInfos->ofnInfos->lpstrInitialDir)))
1030 char path[MAX_PATH];
1032 GetCurrentDirectoryA(MAX_PATH,path);
1033 pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder, path);
1036 /* Initialise shell objects */
1037 FILEDLG95_SHELL_Init(hwnd);
1039 /* Initialize the Look In combo box */
1040 FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB);
1042 /* Initialize the filter combo box */
1043 FILEDLG95_FILETYPE_Init(hwnd);
1045 /* Browse to the initial directory */
1046 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,pidlItemId, SBSP_ABSOLUTE);
1048 /* Free pidlItem memory */
1049 COMDLG32_SHFree(pidlItemId);
1053 /***********************************************************************
1056 * Regroups all the cleaning functions of the filedlg
1058 void FILEDLG95_Clean(HWND hwnd)
1060 FILEDLG95_FILETYPE_Clean(hwnd);
1061 FILEDLG95_LOOKIN_Clean(hwnd);
1062 FILEDLG95_SHELL_Clean(hwnd);
1064 /***********************************************************************
1065 * FILEDLG95_OnWMCommand
1067 * WM_COMMAND message handler
1069 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
1071 WORD wNotifyCode = HIWORD(wParam); /* notification code */
1072 WORD wID = LOWORD(wParam); /* item, control, or accelerator identifier */
1073 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1079 if(FILEDLG95_OnOpen(hwnd))
1080 SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK);
1084 FILEDLG95_Clean(hwnd);
1085 EndDialog(hwnd, FALSE);
1087 /* Filetype combo box */
1089 FILEDLG95_FILETYPE_OnCommand(hwnd,wNotifyCode);
1091 /* LookIn combo box */
1093 FILEDLG95_LOOKIN_OnCommand(hwnd,wNotifyCode);
1096 /* --- toolbar --- */
1097 /* Up folder button */
1098 case FCIDM_TB_UPFOLDER:
1099 FILEDLG95_SHELL_UpFolder(hwnd);
1101 /* New folder button */
1102 case FCIDM_TB_NEWFOLDER:
1103 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_NEWFOLDER);
1105 /* List option button */
1106 case FCIDM_TB_SMALLICON:
1107 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWLIST);
1109 /* Details option button */
1110 case FCIDM_TB_REPORTVIEW:
1111 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWDETAILS);
1113 /* Details option button */
1114 case FCIDM_TB_DESKTOP:
1115 FILEDLG95_SHELL_BrowseToDesktop(hwnd);
1122 /* Do not use the listview selection anymore */
1123 fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
1127 /***********************************************************************
1128 * FILEDLG95_OnWMGetIShellBrowser
1130 * WM_GETISHELLBROWSER message handler
1132 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd)
1135 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1139 SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)fodInfos->Shell.FOIShellBrowser);
1145 /***********************************************************************
1146 * FILEDLG95_OnOpenMultipleFiles
1148 * Handles the opening of multiple files.
1151 * check destination buffer size
1153 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed)
1155 CHAR lpstrPathSpec[MAX_PATH] = "";
1157 UINT nCount, nSizePath;
1158 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1162 lpstrFile = fodInfos->ofnInfos->lpstrFile;
1163 lpstrFile[0] = '\0';
1165 COMDLG32_SHGetPathFromIDListA( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec );
1167 if ( !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE) &&
1168 ( fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST))
1170 LPSTR lpstrTemp = lpstrFileList;
1172 for ( nCount = 0; nCount < nFileCount; nCount++ )
1176 pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder, lpstrTemp);
1179 CHAR lpstrNotFound[100];
1183 LoadStringA(COMMDLG_hInstance32, IDS_FILENOTFOUND, lpstrNotFound, 100);
1184 LoadStringA(COMMDLG_hInstance32, IDS_VERIFYFILE, lpstrMsg, 100);
1186 strcpy(tmp, lpstrTemp);
1188 strcat(tmp, lpstrNotFound);
1190 strcat(tmp, lpstrMsg);
1192 MessageBoxA(hwnd, tmp, fodInfos->ofnInfos->lpstrTitle, MB_OK | MB_ICONEXCLAMATION);
1196 /* move to the next file in the list of files */
1197 lpstrTemp += strlen(lpstrTemp) + 1;
1198 COMDLG32_SHFree(pidl);
1202 nSizePath = strlen(lpstrPathSpec);
1203 strcpy( lpstrFile, lpstrPathSpec);
1204 memcpy( lpstrFile + nSizePath + 1, lpstrFileList, sizeUsed );
1206 fodInfos->ofnInfos->nFileOffset = nSizePath + 1;
1207 fodInfos->ofnInfos->nFileExtension = 0;
1209 /* clean and exit */
1210 FILEDLG95_Clean(hwnd);
1211 return EndDialog(hwnd,TRUE);
1214 /***********************************************************************
1217 * Ok button WM_COMMAND message handler
1219 * If the function succeeds, the return value is nonzero.
1221 #define ONOPEN_BROWSE 1
1222 #define ONOPEN_OPEN 2
1223 #define ONOPEN_SEARCH 3
1224 static void FILEDLG95_OnOpenMessage(HWND hwnd, int idCaption, int idText)
1226 char strMsgTitle[MAX_PATH];
1227 char strMsgText [MAX_PATH];
1229 LoadStringA(COMDLG32_hInstance, idCaption, strMsgTitle, sizeof(strMsgTitle));
1231 strMsgTitle[0] = '\0';
1232 LoadStringA(COMDLG32_hInstance, idText, strMsgText, sizeof(strMsgText));
1233 MessageBoxA(hwnd,strMsgText, strMsgTitle, MB_OK | MB_ICONHAND);
1236 BOOL FILEDLG95_OnOpen(HWND hwnd)
1238 char * lpstrFileList;
1239 UINT nFileCount = 0;
1242 char lpstrPathAndFile[MAX_PATH];
1243 char lpstrTemp[MAX_PATH];
1244 LPSHELLFOLDER lpsf = NULL;
1246 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1248 TRACE("hwnd=0x%04x\n", hwnd);
1250 /* get the files from the edit control */
1251 nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed);
1253 /* try if the user selected a folder in the shellview */
1256 BrowseSelectedFolder(hwnd);
1262 ret = FILEDLG95_OnOpenMultipleFiles(hwnd, lpstrFileList, nFileCount, sizeUsed);
1266 TRACE("count=%u len=%u file=%s\n", nFileCount, sizeUsed, lpstrFileList);
1269 Step 1: Build a complete path name from the current folder and
1270 the filename or path in the edit box.
1272 - the path in the edit box is a root path
1273 (with or without drive letter)
1274 - the edit box contains ".." (or a path with ".." in it)
1277 /* Get the current directory name */
1278 if (!COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathAndFile))
1280 /* we are in a special folder, default to desktop */
1281 if(FAILED(COMDLG32_SHGetFolderPathA(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, 0, 0, lpstrPathAndFile)))
1284 GetCurrentDirectoryA(MAX_PATH, lpstrPathAndFile);
1287 COMDLG32_PathAddBackslashA(lpstrPathAndFile);
1289 TRACE("current directory=%s\n", lpstrPathAndFile);
1291 /* if the user specifyed a fully qualified path use it */
1292 if(COMDLG32_PathIsRelativeA(lpstrFileList))
1294 strcat(lpstrPathAndFile, lpstrFileList);
1298 /* does the path have a drive letter? */
1299 if (COMDLG32_PathGetDriveNumberA(lpstrFileList) == -1)
1300 strcpy(lpstrPathAndFile+2, lpstrFileList);
1302 strcpy(lpstrPathAndFile, lpstrFileList);
1305 /* resolve "." and ".." */
1306 COMDLG32_PathCanonicalizeA(lpstrTemp, lpstrPathAndFile );
1307 strcpy(lpstrPathAndFile, lpstrTemp);
1308 TRACE("canon=%s\n", lpstrPathAndFile);
1310 MemFree(lpstrFileList);
1313 Step 2: here we have a cleaned up path
1315 We have to parse the path step by step to see if we have to browse
1316 to a folder if the path points to a directory or the last
1317 valid element is a directory.
1320 lpstrPathAndFile: cleaned up path
1323 nOpenAction = ONOPEN_BROWSE;
1325 /* dont apply any checks with OFN_NOVALIDATE */
1326 if(!(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE))
1328 LPSTR lpszTemp, lpszTemp1;
1329 LPITEMIDLIST pidl = NULL;
1331 /* check for invalid chars */
1332 if(strpbrk(lpstrPathAndFile+3, "/:<>|") != NULL)
1334 FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_FILENAME);
1339 if (FAILED (COMDLG32_SHGetDesktopFolder(&lpsf))) return FALSE;
1341 lpszTemp1 = lpszTemp = lpstrPathAndFile;
1344 LPSHELLFOLDER lpsfChild;
1345 WCHAR lpwstrTemp[MAX_PATH];
1346 DWORD dwEaten, dwAttributes;
1348 lpszTemp = COMDLG32_PathFindNextComponentA(lpszTemp);
1350 if (!lpszTemp) break; /* end of path */
1354 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpszTemp1, lpszTemp - lpszTemp1,
1355 lpwstrTemp, MAX_PATH );
1356 lpwstrTemp[len] = 0;
1360 MultiByteToWideChar( CP_ACP, 0, lpszTemp1, -1,
1361 lpwstrTemp, sizeof(lpwstrTemp)/sizeof(WCHAR) );
1363 /* if the last element is a wildcard do a search */
1364 if(strpbrk(lpszTemp1, "*?") != NULL)
1366 nOpenAction = ONOPEN_SEARCH;
1370 lpszTemp1 = lpszTemp;
1372 TRACE("parse now=%s next=%s sf=%p\n",debugstr_w(lpwstrTemp), debugstr_a(lpszTemp), lpsf);
1374 if(lstrlenW(lpwstrTemp)==2) COMDLG32_PathAddBackslashW(lpwstrTemp);
1376 dwAttributes = SFGAO_FOLDER;
1377 if(SUCCEEDED(IShellFolder_ParseDisplayName(lpsf, hwnd, NULL, lpwstrTemp, &dwEaten, &pidl, &dwAttributes)))
1379 /* the path component is valid, we have a pidl of the next path component */
1380 TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes, pidl);
1381 if(dwAttributes & SFGAO_FOLDER)
1383 if(FAILED(IShellFolder_BindToObject(lpsf, pidl, 0, &IID_IShellFolder, (LPVOID*)&lpsfChild)))
1385 ERR("bind to failed\n"); /* should not fail */
1388 IShellFolder_Release(lpsf);
1396 /* end dialog, return value */
1397 nOpenAction = ONOPEN_OPEN;
1400 COMDLG32_SHFree(pidl);
1405 if(*lpszTemp) /* points to trailing null for last path element */
1407 if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
1409 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_PATHNOTEXISTING);
1415 if(fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST)
1417 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_FILENOTEXISTING);
1421 /* change to the current folder */
1422 nOpenAction = ONOPEN_OPEN;
1426 if(pidl) COMDLG32_SHFree(pidl);
1430 Step 3: here we have a cleaned up and validated path
1433 lpsf: ShellFolder bound to the rightmost valid path component
1434 lpstrPathAndFile: cleaned up path
1435 nOpenAction: action to do
1437 TRACE("end validate sf=%p\n", lpsf);
1441 case ONOPEN_SEARCH: /* set the current filter to the file mask and refresh */
1442 TRACE("ONOPEN_SEARCH %s\n", lpstrPathAndFile);
1445 LPSTR lpszTemp = COMDLG32_PathFindFileNameA(lpstrPathAndFile);
1448 /* replace the current filter */
1449 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1450 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1451 len = MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1, NULL, 0 );
1452 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc(len * sizeof(WCHAR));
1453 MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1,
1454 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1456 /* set the filter cb to the extension when possible */
1457 if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB, lpszTemp)))
1458 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, iPos);
1461 case ONOPEN_BROWSE: /* browse to the highest folder we could bind to */
1462 TRACE("ONOPEN_BROWSE\n");
1464 IPersistFolder2 * ppf2;
1465 if(SUCCEEDED(IShellFolder_QueryInterface( lpsf, &IID_IPersistFolder2, (LPVOID*)&ppf2)))
1467 LPITEMIDLIST pidlCurrent;
1468 IPersistFolder2_GetCurFolder(ppf2, &pidlCurrent);
1469 IPersistFolder2_Release(ppf2);
1470 if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent, fodInfos->ShellInfos.pidlAbsCurrent))
1472 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE);
1474 else if( nOpenAction == ONOPEN_SEARCH )
1476 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1478 COMDLG32_SHFree(pidlCurrent);
1483 case ONOPEN_OPEN: /* fill in the return struct and close the dialog */
1484 TRACE("ONOPEN_OPEN %s\n", lpstrPathAndFile);
1486 /* add default extension */
1487 if (fodInfos->ofnInfos->lpstrDefExt)
1489 if (! *COMDLG32_PathFindExtensionA(lpstrPathAndFile))
1491 strcat(lpstrPathAndFile, ".");
1492 strcat(lpstrPathAndFile, fodInfos->ofnInfos->lpstrDefExt);
1496 /* Check that the size of the file does not exceed buffer size.
1497 (Allow for extra \0 if OFN_MULTISELECT is set.) */
1498 if(strlen(lpstrPathAndFile) < fodInfos->ofnInfos->nMaxFile -
1499 ((fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT) ? 1 : 0))
1503 /* fill destination buffer */
1504 strcpy(fodInfos->ofnInfos->lpstrFile, lpstrPathAndFile);
1505 if (fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT)
1506 fodInfos->ofnInfos->lpstrFile[strlen(fodInfos->ofnInfos->lpstrFile)
1509 /* set filename offset */
1510 lpszTemp = COMDLG32_PathFindFileNameA(lpstrPathAndFile);
1511 fodInfos->ofnInfos->nFileOffset = lpszTemp - lpstrPathAndFile;
1513 /* set extension offset */
1514 lpszTemp = COMDLG32_PathFindExtensionA(lpstrPathAndFile);
1515 fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? lpszTemp - lpstrPathAndFile + 1 : 0;
1517 /* set the lpstrFileTitle */
1518 if(fodInfos->ofnInfos->lpstrFileTitle)
1520 LPSTR lpstrFileTitle = COMDLG32_PathFindFileNameA(lpstrPathAndFile);
1521 strncpy(fodInfos->ofnInfos->lpstrFileTitle, lpstrFileTitle, fodInfos->ofnInfos->nMaxFileTitle);
1524 /* ask the hook if we can close */
1525 if(IsHooked(fodInfos))
1527 /* FIXME we are sending ASCII-structures. Does not work with NT */
1528 /* first old style */
1530 CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,
1531 fodInfos->DlgInfos.hwndCustomDlg,
1532 fodInfos->HookMsg.fileokstring, 0, (LPARAM)fodInfos->ofnInfos);
1533 if (GetWindowLongA(hwnd, DWL_MSGRESULT))
1542 FILEDLG95_Clean(hwnd);
1543 ret = EndDialog(hwnd, TRUE);
1547 /* FIXME set error FNERR_BUFFERTOSMALL */
1548 FILEDLG95_Clean(hwnd);
1549 ret = EndDialog(hwnd, FALSE);
1557 if(lpsf) IShellFolder_Release(lpsf);
1561 /***********************************************************************
1562 * FILEDLG95_SHELL_Init
1564 * Initialisation of the shell objects
1566 static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
1568 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1573 * Initialisation of the FileOpenDialogInfos structure
1579 fodInfos->ShellInfos.hwndOwner = hwnd;
1581 /* Disable multi-select if flag not set */
1582 if (!(fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT))
1584 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_SINGLESEL;
1586 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_AUTOARRANGE | FWF_ALIGNLEFT;
1587 fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
1589 GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
1590 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
1591 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
1593 /* Construct the IShellBrowser interface */
1594 fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
1599 /***********************************************************************
1600 * FILEDLG95_SHELL_ExecuteCommand
1602 * Change the folder option and refresh the view
1603 * If the function succeeds, the return value is nonzero.
1605 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
1607 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1610 TRACE("(0x%08x,%p)\n", hwnd, lpVerb);
1612 if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
1617 CMINVOKECOMMANDINFO ci;
1618 ZeroMemory(&ci, sizeof(CMINVOKECOMMANDINFO));
1619 ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
1623 IContextMenu_InvokeCommand(pcm, &ci);
1624 IContextMenu_Release(pcm);
1630 /***********************************************************************
1631 * FILEDLG95_SHELL_UpFolder
1633 * Browse to the specified object
1634 * If the function succeeds, the return value is nonzero.
1636 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
1638 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1642 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1651 /***********************************************************************
1652 * FILEDLG95_SHELL_BrowseToDesktop
1654 * Browse to the Desktop
1655 * If the function succeeds, the return value is nonzero.
1657 static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd)
1659 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1665 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidl);
1666 hres = IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidl, SBSP_ABSOLUTE);
1667 COMDLG32_SHFree(pidl);
1668 return SUCCEEDED(hres);
1670 /***********************************************************************
1671 * FILEDLG95_SHELL_Clean
1673 * Cleans the memory used by shell objects
1675 static void FILEDLG95_SHELL_Clean(HWND hwnd)
1677 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1681 COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent);
1683 /* clean Shell interfaces */
1684 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
1685 IShellView_Release(fodInfos->Shell.FOIShellView);
1686 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
1687 IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
1688 if (fodInfos->Shell.FOIDataObject)
1689 IDataObject_Release(fodInfos->Shell.FOIDataObject);
1692 /***********************************************************************
1693 * FILEDLG95_FILETYPE_Init
1695 * Initialisation of the file type combo box
1697 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
1699 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1703 if(fodInfos->ofnInfos->lpstrFilter)
1705 int nFilters = 0; /* number of filters */
1707 LPCSTR lpstrPos = fodInfos->ofnInfos->lpstrFilter;
1711 /* filter is a list... title\0ext\0......\0\0
1712 * Set the combo item text to the title and the item data
1715 LPCSTR lpstrDisplay;
1719 if(! *lpstrPos) break; /* end */
1720 lpstrDisplay = lpstrPos;
1721 lpstrPos += strlen(lpstrPos) + 1;
1723 /* Copy the extensions */
1724 if (! *lpstrPos) return E_FAIL; /* malformed filter */
1725 if (!(lpstrExt = (LPSTR) MemAlloc(strlen(lpstrPos)+1))) return E_FAIL;
1726 strcpy(lpstrExt,lpstrPos);
1727 lpstrPos += strlen(lpstrPos) + 1;
1729 /* Add the item at the end of the combo */
1730 CBAddString(fodInfos->DlgInfos.hwndFileTypeCB, lpstrDisplay);
1731 CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt);
1735 * Set the current filter to the one specified
1736 * in the initialisation structure
1737 * FIXME: lpstrCustomFilter not handled at all
1740 /* set default filter index */
1741 if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->ofnInfos->lpstrCustomFilter == NULL)
1742 fodInfos->ofnInfos->nFilterIndex = 1;
1744 /* First, check to make sure our index isn't out of bounds. */
1745 if ( fodInfos->ofnInfos->nFilterIndex > nFilters )
1746 fodInfos->ofnInfos->nFilterIndex = nFilters;
1748 /* Set the current index selection. */
1749 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->ofnInfos->nFilterIndex-1);
1751 /* Get the corresponding text string from the combo box. */
1752 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1753 fodInfos->ofnInfos->nFilterIndex-1);
1755 if ((INT)lpstrFilter == CB_ERR) /* control is empty */
1761 _strlwr(lpstrFilter); /* lowercase */
1762 len = MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1, NULL, 0 );
1763 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
1764 MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1,
1765 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1771 /***********************************************************************
1772 * FILEDLG95_FILETYPE_OnCommand
1774 * WM_COMMAND of the file type combo box
1775 * If the function succeeds, the return value is nonzero.
1777 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
1779 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1787 /* Get the current item of the filetype combo box */
1788 int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1790 /* set the current filter index - indexed from 1 */
1791 fodInfos->ofnInfos->nFilterIndex = iItem + 1;
1793 /* Set the current filter with the current selection */
1794 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1795 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1797 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1799 if((int)lpstrFilter != CB_ERR)
1802 _strlwr(lpstrFilter); /* lowercase */
1803 len = MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1, NULL, 0 );
1804 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
1805 MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1,
1806 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1807 SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
1810 /* Refresh the actual view to display the included items*/
1811 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1816 /***********************************************************************
1817 * FILEDLG95_FILETYPE_SearchExt
1819 * searches for a extension in the filetype box
1821 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt)
1823 int i, iCount = CBGetCount(hwnd);
1825 TRACE("%s\n", lpstrExt);
1827 if(iCount != CB_ERR)
1829 for(i=0;i<iCount;i++)
1831 if(!strcasecmp(lpstrExt,(LPSTR)CBGetItemDataPtr(hwnd,i)))
1838 /***********************************************************************
1839 * FILEDLG95_FILETYPE_Clean
1841 * Clean the memory used by the filetype combo box
1843 static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
1845 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1847 int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
1851 /* Delete each string of the combo and their associated data */
1852 if(iCount != CB_ERR)
1854 for(iPos = iCount-1;iPos>=0;iPos--)
1856 MemFree((LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos));
1857 CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1860 /* Current filter */
1861 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1862 MemFree(fodInfos->ShellInfos.lpstrCurrentFilter);
1866 /***********************************************************************
1867 * FILEDLG95_LOOKIN_Init
1869 * Initialisation of the look in combo box
1871 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
1873 IShellFolder *psfRoot, *psfDrives;
1874 IEnumIDList *lpeRoot, *lpeDrives;
1875 LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
1877 LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
1881 liInfos->iMaxIndentation = 0;
1883 SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
1885 /* set item height for both text field and listbox */
1886 CBSetItemHeight(hwndCombo,-1,GetSystemMetrics(SM_CYSMICON));
1887 CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
1889 /* Initialise data of Desktop folder */
1890 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
1891 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1892 COMDLG32_SHFree(pidlTmp);
1894 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
1896 COMDLG32_SHGetDesktopFolder(&psfRoot);
1900 /* enumerate the contents of the desktop */
1901 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
1903 while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
1905 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1907 /* special handling for CSIDL_DRIVES */
1908 if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
1910 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
1912 /* enumerate the drives */
1913 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
1915 while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
1917 pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
1918 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
1919 COMDLG32_SHFree(pidlAbsTmp);
1920 COMDLG32_SHFree(pidlTmp1);
1922 IEnumIDList_Release(lpeDrives);
1924 IShellFolder_Release(psfDrives);
1927 COMDLG32_SHFree(pidlTmp);
1929 IEnumIDList_Release(lpeRoot);
1933 IShellFolder_Release(psfRoot);
1934 COMDLG32_SHFree(pidlDrives);
1938 /***********************************************************************
1939 * FILEDLG95_LOOKIN_DrawItem
1941 * WM_DRAWITEM message handler
1943 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
1945 COLORREF crWin = GetSysColor(COLOR_WINDOW);
1946 COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
1947 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1951 HIMAGELIST ilItemImage;
1954 LPSFOLDER tmpFolder;
1957 LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
1961 if(pDIStruct->itemID == -1)
1964 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
1965 pDIStruct->itemID)))
1969 if(pDIStruct->itemID == liInfos->uSelectedItem)
1971 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1974 sizeof (SHFILEINFOA),
1975 SHGFI_PIDL | SHGFI_SMALLICON |
1976 SHGFI_OPENICON | SHGFI_SYSICONINDEX |
1977 SHGFI_DISPLAYNAME );
1981 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1984 sizeof (SHFILEINFOA),
1985 SHGFI_PIDL | SHGFI_SMALLICON |
1986 SHGFI_SYSICONINDEX |
1990 /* Is this item selected ? */
1991 if(pDIStruct->itemState & ODS_SELECTED)
1993 SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
1994 SetBkColor(pDIStruct->hDC,crHighLight);
1995 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight);
1999 SetTextColor(pDIStruct->hDC,crText);
2000 SetBkColor(pDIStruct->hDC,crWin);
2001 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin);
2004 /* Do not indent item if drawing in the edit of the combo */
2005 if(pDIStruct->itemState & ODS_COMBOBOXEDIT)
2008 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2011 sizeof (SHFILEINFOA),
2012 SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON
2013 | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME );
2018 iIndentation = tmpFolder->m_iIndent;
2020 /* Draw text and icon */
2022 /* Initialise the icon display area */
2023 rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
2024 rectIcon.top = pDIStruct->rcItem.top;
2025 rectIcon.right = rectIcon.left + ICONWIDTH;
2026 rectIcon.bottom = pDIStruct->rcItem.bottom;
2028 /* Initialise the text display area */
2029 GetTextMetricsA(pDIStruct->hDC, &tm);
2030 rectText.left = rectIcon.right;
2032 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom - tm.tmHeight) / 2;
2033 rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
2035 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom + tm.tmHeight) / 2;
2037 /* Draw the icon from the image list */
2038 COMDLG32_ImageList_Draw(ilItemImage,
2045 /* Draw the associated text */
2046 if(sfi.szDisplayName)
2047 TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName));
2053 /***********************************************************************
2054 * FILEDLG95_LOOKIN_OnCommand
2056 * LookIn combo box WM_COMMAND message handler
2057 * If the function succeeds, the return value is nonzero.
2059 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
2061 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2063 TRACE("%p\n", fodInfos);
2069 LPSFOLDER tmpFolder;
2072 iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
2074 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
2079 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
2080 tmpFolder->pidlItem,
2092 /***********************************************************************
2093 * FILEDLG95_LOOKIN_AddItem
2095 * Adds an absolute pidl item to the lookin combo box
2096 * returns the index of the inserted item
2098 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
2100 LPITEMIDLIST pidlNext;
2103 LookInInfos *liInfos;
2105 TRACE("%08x\n", iInsertId);
2110 if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
2113 tmpFolder = MemAlloc(sizeof(SFOLDER));
2114 tmpFolder->m_iIndent = 0;
2116 /* Calculate the indentation of the item in the lookin*/
2118 while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
2120 tmpFolder->m_iIndent++;
2123 tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl); /* FIXME: memory leak*/
2125 if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
2126 liInfos->iMaxIndentation = tmpFolder->m_iIndent;
2128 sfi.dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM;
2129 COMDLG32_SHGetFileInfoA((LPSTR)pidl,
2133 SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX
2134 | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED);
2136 TRACE("-- Add %s attr=%08lx\n", sfi.szDisplayName, sfi.dwAttributes);
2138 if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
2142 TRACE("-- Add %s at %u\n", sfi.szDisplayName, tmpFolder->m_iIndent);
2144 /* Add the item at the end of the list */
2147 iItemID = CBAddString(hwnd,sfi.szDisplayName);
2149 /* Insert the item at the iInsertId position*/
2152 iItemID = CBInsertString(hwnd,sfi.szDisplayName,iInsertId);
2155 CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
2159 MemFree( tmpFolder );
2164 /***********************************************************************
2165 * FILEDLG95_LOOKIN_InsertItemAfterParent
2167 * Insert an item below its parent
2169 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
2172 LPITEMIDLIST pidlParent = GetParentPidl(pidl);
2177 iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
2181 iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
2184 /* Free pidlParent memory */
2185 COMDLG32_SHFree((LPVOID)pidlParent);
2187 return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
2190 /***********************************************************************
2191 * FILEDLG95_LOOKIN_SelectItem
2193 * Adds an absolute pidl item to the lookin combo box
2194 * returns the index of the inserted item
2196 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
2199 LookInInfos *liInfos;
2203 iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
2205 liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2209 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
2210 iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
2215 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2216 while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
2220 if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
2222 if(iRemovedItem < iItemPos)
2227 CBSetCurSel(hwnd,iItemPos);
2228 liInfos->uSelectedItem = iItemPos;
2234 /***********************************************************************
2235 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2237 * Remove the item with an expansion level over iExpansionLevel
2239 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
2243 LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2247 if(liInfos->iMaxIndentation <= 2)
2250 if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
2252 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2253 COMDLG32_SHFree(tmpFolder->pidlItem);
2255 CBDeleteString(hwnd,iItemPos);
2256 liInfos->iMaxIndentation--;
2264 /***********************************************************************
2265 * FILEDLG95_LOOKIN_SearchItem
2267 * Search for pidl in the lookin combo box
2268 * returns the index of the found item
2270 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
2273 int iCount = CBGetCount(hwnd);
2275 TRACE("0x%08x 0x%x\n",searchArg, iSearchMethod);
2277 if (iCount != CB_ERR)
2281 LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
2283 if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
2285 if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
2293 /***********************************************************************
2294 * FILEDLG95_LOOKIN_Clean
2296 * Clean the memory used by the lookin combo box
2298 static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
2300 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2302 int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
2306 /* Delete each string of the combo and their associated data */
2307 if (iCount != CB_ERR)
2309 for(iPos = iCount-1;iPos>=0;iPos--)
2311 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos);
2312 COMDLG32_SHFree(tmpFolder->pidlItem);
2314 CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
2318 /* LookInInfos structure */
2319 RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
2322 /***********************************************************************
2323 * FILEDLG95_FILENAME_FillFromSelection
2325 * fills the edit box from the cached DataObject
2327 void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd)
2329 FileOpenDlgInfos *fodInfos;
2331 UINT nFiles = 0, nFileToOpen, nFileSelected, nLength = 0;
2332 char lpstrTemp[MAX_PATH];
2333 LPSTR lpstrAllFile = NULL, lpstrCurrFile = NULL;
2336 fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2338 /* Count how many files we have */
2339 nFileSelected = GetNumSelected( fodInfos->Shell.FOIDataObject );
2341 /* calculate the string length, count files */
2342 if (nFileSelected >= 1)
2344 nLength += 3; /* first and last quotes, trailing \0 */
2345 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2347 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2351 /* get the total length of the selected file names*/
2352 lpstrTemp[0] = '\0';
2353 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2355 if ( ! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl) ) /* Ignore folders */
2357 nLength += strlen( lpstrTemp ) + 3;
2360 COMDLG32_SHFree( pidl );
2365 /* allocate the buffer */
2366 if (nFiles <= 1) nLength = MAX_PATH;
2367 lpstrAllFile = (LPSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength);
2368 lpstrAllFile[0] = '\0';
2370 /* Generate the string for the edit control */
2373 lpstrCurrFile = lpstrAllFile;
2374 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2376 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2380 /* get the file name */
2381 lpstrTemp[0] = '\0';
2382 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2384 if (! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl)) /* Ignore folders */
2388 *lpstrCurrFile++ = '\"';
2389 strcpy( lpstrCurrFile, lpstrTemp );
2390 lpstrCurrFile += strlen( lpstrTemp );
2391 strcpy( lpstrCurrFile, "\" " );
2396 strcpy( lpstrAllFile, lpstrTemp );
2399 COMDLG32_SHFree( (LPVOID) pidl );
2404 SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile );
2405 HeapFree(GetProcessHeap(),0, lpstrAllFile );
2409 /* copied from shell32 to avoid linking to it */
2410 static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
2415 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL);
2416 COMDLG32_SHFree(src->u.pOleStr);
2420 lstrcpynA((LPSTR)dest, src->u.cStr, len);
2423 case STRRET_OFFSETA:
2424 lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
2428 FIXME("unknown type!\n");
2431 *(LPSTR)dest = '\0';
2438 /***********************************************************************
2439 * FILEDLG95_FILENAME_GetFileNames
2441 * copies the filenames to a 0-delimited string list (A\0B\0C\0\0)
2443 int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPSTR * lpstrFileList, UINT * sizeUsed)
2445 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2446 UINT nStrCharCount = 0; /* index in src buffer */
2447 UINT nFileIndex = 0; /* index in dest buffer */
2448 UINT nFileCount = 0; /* number of files */
2449 UINT nStrLen = 0; /* length of string in edit control */
2450 LPSTR lpstrEdit; /* buffer for string from edit control */
2454 /* get the filenames from the edit control */
2455 nStrLen = SendMessageA(fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0);
2456 lpstrEdit = MemAlloc(nStrLen+1);
2457 GetDlgItemTextA(hwnd, IDC_FILENAME, lpstrEdit, nStrLen+1);
2459 TRACE("nStrLen=%u str=%s\n", nStrLen, lpstrEdit);
2461 /* we might get single filename without any '"',
2462 * so we need nStrLen + terminating \0 + end-of-list \0 */
2463 *lpstrFileList = MemAlloc(nStrLen+2);
2466 /* build 0-delimited file list from filenames */
2467 while ( nStrCharCount <= nStrLen )
2469 if ( lpstrEdit[nStrCharCount]=='"' )
2472 while ((lpstrEdit[nStrCharCount]!='"') && (nStrCharCount <= nStrLen))
2474 (*lpstrFileList)[nFileIndex++] = lpstrEdit[nStrCharCount];
2478 (*lpstrFileList)[nFileIndex++] = '\0';
2485 /* single, unquoted string */
2486 if ((nStrLen > 0) && (*sizeUsed == 0) )
2488 strcpy(*lpstrFileList, lpstrEdit);
2489 nFileIndex = strlen(lpstrEdit) + 1;
2490 (*sizeUsed) = nFileIndex;
2495 (*lpstrFileList)[nFileIndex] = '\0';
2502 #define SETDefFormatEtc(fe,cf,med) \
2504 (fe).cfFormat = cf;\
2505 (fe).dwAspect = DVASPECT_CONTENT; \
2512 * DATAOBJECT Helper functions
2515 /***********************************************************************
2516 * COMCTL32_ReleaseStgMedium
2518 * like ReleaseStgMedium from ole32
2520 static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium)
2522 if(medium.pUnkForRelease)
2524 IUnknown_Release(medium.pUnkForRelease);
2528 GlobalUnlock(medium.u.hGlobal);
2529 GlobalFree(medium.u.hGlobal);
2533 /***********************************************************************
2534 * GetPidlFromDataObject
2536 * Return pidl(s) by number from the cached DataObject
2538 * nPidlIndex=0 gets the fully qualified root path
2540 LPITEMIDLIST GetPidlFromDataObject ( IDataObject *doSelected, UINT nPidlIndex)
2544 FORMATETC formatetc;
2545 LPITEMIDLIST pidl = NULL;
2547 TRACE("sv=%p index=%u\n", doSelected, nPidlIndex);
2549 /* Set the FORMATETC structure*/
2550 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2552 /* Get the pidls from IDataObject */
2553 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2555 LPIDA cida = GlobalLock(medium.u.hGlobal);
2556 if(nPidlIndex <= cida->cidl)
2558 pidl = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[nPidlIndex]]));
2560 COMCTL32_ReleaseStgMedium(medium);
2565 /***********************************************************************
2568 * Return the number of selected items in the DataObject.
2571 UINT GetNumSelected( IDataObject *doSelected )
2575 FORMATETC formatetc;
2577 TRACE("sv=%p\n", doSelected);
2579 if (!doSelected) return 0;
2581 /* Set the FORMATETC structure*/
2582 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2584 /* Get the pidls from IDataObject */
2585 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2587 LPIDA cida = GlobalLock(medium.u.hGlobal);
2588 retVal = cida->cidl;
2589 COMCTL32_ReleaseStgMedium(medium);
2599 /***********************************************************************
2602 * Get the pidl's display name (relative to folder) and
2603 * put it in lpstrFileName.
2605 * Return NOERROR on success,
2609 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
2614 TRACE("sf=%p pidl=%p\n", lpsf, pidl);
2619 COMDLG32_SHGetDesktopFolder(&lpsf);
2620 hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
2621 IShellFolder_Release(lpsf);
2625 /* Get the display name of the pidl relative to the folder */
2626 if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf, pidl, dwFlags, &str)))
2628 return COMDLG32_StrRetToStrNA(lpstrFileName, MAX_PATH, &str, pidl);
2633 /***********************************************************************
2634 * GetShellFolderFromPidl
2636 * pidlRel is the item pidl relative
2637 * Return the IShellFolder of the absolute pidl
2639 IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
2641 IShellFolder *psf = NULL,*psfParent;
2643 TRACE("%p\n", pidlAbs);
2645 if(SUCCEEDED(COMDLG32_SHGetDesktopFolder(&psfParent)))
2648 if(pidlAbs && pidlAbs->mkid.cb)
2650 if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
2652 IShellFolder_Release(psfParent);
2656 /* return the desktop */
2662 /***********************************************************************
2665 * Return the LPITEMIDLIST to the parent of the pidl in the list
2667 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
2669 LPITEMIDLIST pidlParent;
2671 TRACE("%p\n", pidl);
2673 pidlParent = COMDLG32_PIDL_ILClone(pidl);
2674 COMDLG32_PIDL_ILRemoveLastID(pidlParent);
2679 /***********************************************************************
2682 * returns the pidl of the file name relative to folder
2683 * NULL if an error occured
2685 LPITEMIDLIST GetPidlFromName(IShellFolder *lpsf,LPCSTR lpcstrFileName)
2689 WCHAR lpwstrDirName[MAX_PATH];
2691 TRACE("sf=%p file=%s\n", lpsf, lpcstrFileName);
2693 if(!lpcstrFileName) return NULL;
2695 MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,lpcstrFileName,-1,(LPWSTR)lpwstrDirName,MAX_PATH);
2699 COMDLG32_SHGetDesktopFolder(&lpsf);
2700 pidl = GetPidlFromName(lpsf, lpcstrFileName);
2701 IShellFolder_Release(lpsf);
2705 IShellFolder_ParseDisplayName(lpsf, 0, NULL, (LPWSTR)lpwstrDirName, &ulEaten, &pidl, NULL);
2712 BOOL IsPidlFolder (LPSHELLFOLDER psf, LPITEMIDLIST pidl)
2714 ULONG uAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
2717 TRACE("%p, %p\n", psf, pidl);
2719 ret = IShellFolder_GetAttributesOf( psf, 1, &pidl, &uAttr );
2721 TRACE("-- 0x%08lx 0x%08lx\n", uAttr, ret);
2722 /* see documentation shell 4.1*/
2723 return uAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER);
2726 /***********************************************************************
2727 * BrowseSelectedFolder
2729 static BOOL BrowseSelectedFolder(HWND hwnd)
2731 BOOL bBrowseSelFolder = FALSE;
2732 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2736 if (GetNumSelected(fodInfos->Shell.FOIDataObject) == 1)
2738 LPITEMIDLIST pidlSelection;
2740 /* get the file selected */
2741 pidlSelection = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, 1);
2742 if (IsPidlFolder (fodInfos->Shell.FOIShellFolder, pidlSelection))
2744 if ( FAILED( IShellBrowser_BrowseObject( fodInfos->Shell.FOIShellBrowser,
2745 pidlSelection, SBSP_RELATIVE ) ) )
2747 MessageBoxA( hwnd, "Path does not exist", fodInfos->ofnInfos->lpstrTitle,
2748 MB_OK | MB_ICONEXCLAMATION );
2751 bBrowseSelFolder = TRUE;
2753 COMDLG32_SHFree( pidlSelection );
2756 return bBrowseSelFolder;
2760 * Memory allocation methods */
2761 static void *MemAlloc(UINT size)
2763 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
2766 static void MemFree(void *mem)
2770 HeapFree(GetProcessHeap(),0,mem);