2 * COMMDLG - File Open Dialogs Win95 look and feel
4 * Copyright 1999 Francois Boisvert
5 * Copyright 1999, 2000 Juergen Schmied
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * FIXME: The whole concept of handling unicode is badly broken.
22 * many hook-messages expecting a pointer to a
23 * OPENFILENAMEA or W structure. With the current architecture
24 * we would have to convert the beast at every call to a hook.
25 * we have to find a better solution but if would likely cause
26 * a complete rewrite with after we shouldhandle the
27 * OPENFILENAME structure without any converting (jsch).
29 * FIXME: any hook gets a OPENFILENAMEA structure
31 * FIXME: CDN_FILEOK is wrong implemented, other CDN_ messages likely too
33 * FIXME: old style hook messages are not implemented (except FILEOKSTRING)
35 * FIXME: lpstrCustomFilter not handled
37 * FIXME: if the size of lpstrFile (nMaxFile) is too small the first
38 * two bytes of lpstrFile should contain the needed size
40 * FIXME: algorithm for selecting the initial directory is too simple
42 * FIXME: add to recent docs
44 * FIXME: flags not implemented: OFN_CREATEPROMPT, OFN_DONTADDTORECENT,
45 * OFN_ENABLEINCLUDENOTIFY, OFN_ENABLESIZING, OFN_EXTENSIONDIFFERENT,
46 * OFN_NODEREFERENCELINKS, OFN_NOREADONLYRETURN,
47 * OFN_NOTESTFILECREATE, OFN_OVERWRITEPROMPT, OFN_USEMONIKERS
49 * FIXME: lCustData for lpfnHook (WM_INITDIALOG)
61 #include "wine/unicode.h"
65 #include "wine/debug.h"
69 #include "filedlgbrowser.h"
71 #include "wine/obj_contextmenu.h"
73 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
75 #define UNIMPLEMENTED_FLAGS \
76 (OFN_CREATEPROMPT | OFN_DONTADDTORECENT |\
77 OFN_ENABLEINCLUDENOTIFY | OFN_ENABLESIZING | OFN_EXTENSIONDIFFERENT |\
78 OFN_NODEREFERENCELINKS | OFN_NOREADONLYRETURN |\
79 OFN_NOTESTFILECREATE | OFN_OVERWRITEPROMPT /*| OFN_USEMONIKERS*/)
81 #define IsHooked(fodInfos) \
82 ((fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook)
83 /***********************************************************************
84 * Data structure and global variables
86 typedef struct SFolder
88 int m_iImageIndex; /* Index of picture in image list */
90 int m_iIndent; /* Indentation index */
91 LPITEMIDLIST pidlItem; /* absolute pidl of the item */
95 typedef struct tagLookInInfo
102 /***********************************************************************
103 * Defines and global variables
106 /* Draw item constant */
108 #define XTEXTOFFSET 3
113 /* SearchItem methods */
114 #define SEARCH_PIDL 1
116 #define ITEM_NOTFOUND -1
118 /* Undefined windows message sent by CreateViewObject*/
119 #define WM_GETISHELLBROWSER WM_USER+7
122 * Those macros exist in windowsx.h. However, you can't really use them since
123 * they rely on the UNICODE defines and can't be used inside Wine itself.
126 /* Combo box macros */
127 #define CBAddString(hwnd,str) \
128 SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str);
130 #define CBInsertString(hwnd,str,pos) \
131 SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str);
133 #define CBDeleteString(hwnd,pos) \
134 SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0);
136 #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
137 SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr);
139 #define CBGetItemDataPtr(hwnd,iItemId) \
140 SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0)
142 #define CBGetLBText(hwnd,iItemId,str) \
143 SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str);
145 #define CBGetCurSel(hwnd) \
146 SendMessageA(hwnd,CB_GETCURSEL,0,0);
148 #define CBSetCurSel(hwnd,pos) \
149 SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0);
151 #define CBGetCount(hwnd) \
152 SendMessageA(hwnd,CB_GETCOUNT,0,0);
153 #define CBShowDropDown(hwnd,show) \
154 SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0);
155 #define CBSetItemHeight(hwnd,index,height) \
156 SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height);
159 const char *FileOpenDlgInfosStr = "FileOpenDlgInfos"; /* windows property description string */
160 const char *LookInInfosStr = "LookInInfos"; /* LOOKIN combo box property */
162 static const char defaultFilter[] = "*.*";
164 /***********************************************************************
168 /* Internal functions used by the dialog */
169 static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam);
170 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
171 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd);
172 BOOL FILEDLG95_OnOpen(HWND hwnd);
173 static LRESULT FILEDLG95_InitControls(HWND hwnd);
174 static void FILEDLG95_Clean(HWND hwnd);
176 /* Functions used by the shell navigation */
177 static LRESULT FILEDLG95_SHELL_Init(HWND hwnd);
178 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd);
179 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb);
180 static void FILEDLG95_SHELL_Clean(HWND hwnd);
181 static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd);
183 /* Functions used by the filetype combo box */
184 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd);
185 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode);
186 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt);
187 static void FILEDLG95_FILETYPE_Clean(HWND hwnd);
189 /* Functions used by the Look In combo box */
190 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo);
191 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);
192 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);
193 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);
194 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod);
195 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl);
196 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd);
197 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
198 static void FILEDLG95_LOOKIN_Clean(HWND hwnd);
200 /* Miscellaneous tool functions */
201 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
202 HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
203 IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
204 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
205 LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
207 /* Shell memory allocation */
208 static void *MemAlloc(UINT size);
209 static void MemFree(void *mem);
211 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos);
212 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
213 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
214 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
215 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);
216 static BOOL BrowseSelectedFolder(HWND hwnd);
218 /***********************************************************************
221 * Creates an Open common dialog box that lets the user select
222 * the drive, directory, and the name of a file or set of files to open.
224 * IN : The FileOpenDlgInfos structure associated with the dialog
225 * OUT : TRUE on success
226 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
228 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)
236 /* test for missing functionality */
237 if (fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS)
239 FIXME("Flags 0x%08lx not yet implemented\n",
240 fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS);
243 /* Create the dialog from a template */
245 if(!(hRes = FindResourceA(COMMDLG_hInstance32,MAKEINTRESOURCEA(NEWFILEOPENORD),RT_DIALOGA)))
247 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
250 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hRes )) ||
251 !(template = LockResource( hDlgTmpl )))
253 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
257 /* old style hook messages */
258 if (IsHooked(fodInfos))
260 fodInfos->HookMsg.fileokstring = RegisterWindowMessageA(FILEOKSTRINGA);
261 fodInfos->HookMsg.lbselchstring = RegisterWindowMessageA(LBSELCHSTRINGA);
262 fodInfos->HookMsg.helpmsgstring = RegisterWindowMessageA(HELPMSGSTRINGA);
263 fodInfos->HookMsg.sharevistring = RegisterWindowMessageA(SHAREVISTRINGA);
266 lRes = DialogBoxIndirectParamA(COMMDLG_hInstance32,
267 (LPDLGTEMPLATEA) template,
268 fodInfos->ofnInfos->hwndOwner,
269 (DLGPROC) FileOpenDlgProc95,
272 /* Unable to create the dialog */
279 /***********************************************************************
282 * Call GetFileName95 with this structure and clean the memory.
284 * IN : The OPENFILENAMEA initialisation structure passed to
285 * GetOpenFileNameA win api function (see filedlg.c)
287 BOOL WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
291 FileOpenDlgInfos *fodInfos;
293 LPCSTR lpstrInitialDir = (LPCSTR)-1;
294 LPSTR lpstrSavDir = NULL;
297 /* Initialize FileOpenDlgInfos structure */
298 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
299 ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
301 /* Pass in the original ofn */
302 fodInfos->ofnInfos = ofn;
304 /* Save original hInstance value */
305 hInstance = ofn->hInstance;
306 fodInfos->ofnInfos->hInstance = MapHModuleLS(ofn->hInstance);
308 /* save current directory */
309 if (ofn->Flags & OFN_NOCHANGEDIR)
311 lpstrSavDir = MemAlloc(MAX_PATH);
312 GetCurrentDirectoryA(MAX_PATH, lpstrSavDir);
315 dwFlags = ofn->Flags;
316 ofn->Flags = ofn->Flags|OFN_WINE;
318 /* Initialize the dialog property */
319 fodInfos->DlgInfos.dwDlgProp = 0;
320 fodInfos->DlgInfos.hwndCustomDlg = (HWND)NULL;
325 ret = GetFileName95(fodInfos);
328 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
329 ret = GetFileName95(fodInfos);
337 SetCurrentDirectoryA(lpstrSavDir);
338 MemFree(lpstrSavDir);
341 if (lpstrInitialDir != (LPCSTR)-1)
343 MemFree((LPVOID)(ofn->lpstrInitialDir));
344 ofn->lpstrInitialDir = lpstrInitialDir;
347 ofn->Flags = dwFlags;
348 ofn->hInstance = hInstance;
349 MemFree((LPVOID)(fodInfos));
353 /***********************************************************************
356 * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
357 * Call GetFileName95 with this structure and clean the memory.
359 * FIXME: lpstrCustomFilter has to converted back
363 /* converting IN arguments */
364 #define AllocInArgWtoA(arg, save) \
367 DWORD _len = WideCharToMultiByte( CP_ACP, 0, arg, -1, NULL, 0, NULL, NULL ); \
369 arg = MemAlloc(_len); \
370 WideCharToMultiByte( CP_ACP, 0, save, -1, (LPSTR)arg, _len, NULL, NULL ); \
373 #define FreeInArg(arg, save) \
376 MemFree((LPSTR)arg); \
380 /* converting OUT arguments */
381 #define AllocOutArgWtoA(arg, save, len) \
385 arg = MemAlloc(len); \
388 #define FreeOutArg(arg, save, len) \
391 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)(arg), -1, (save), (len) ); \
396 BOOL WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
399 FileOpenDlgInfos *fodInfos;
403 LPWSTR lpstrFile = NULL;
404 LPWSTR lpstrFileTitle = NULL;
406 /* in/out arguments */
407 LPWSTR lpstrCustomFilter = NULL;
409 /* input arguments */
410 LPCWSTR lpstrFilter = NULL;
411 LPCWSTR lpstrInitialDir = NULL;
412 LPCWSTR lpstrTitle = NULL;
413 LPCWSTR lpstrDefExt = NULL;
414 LPCWSTR lpTemplateName = NULL;
417 /* Initialize FileOpenDlgInfos structure */
418 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
419 ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
421 /* Pass in the original ofn */
422 fodInfos->ofnInfos = (LPOPENFILENAMEA) ofn;
424 /* convert lpstrFilter */
425 if (ofn->lpstrFilter)
431 lpstrFilter = ofn->lpstrFilter;
433 /* filter is a list... title\0ext\0......\0\0 */
434 s = ofn->lpstrFilter;
436 while (*s) s = s+strlenW(s)+1;
438 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
439 len = WideCharToMultiByte( CP_ACP, 0, ofn->lpstrFilter, n, NULL, 0, NULL, NULL );
440 y = (LPSTR)MemAlloc(len);
441 WideCharToMultiByte( CP_ACP, 0, ofn->lpstrFilter, n, y, len, NULL, NULL );
442 (LPSTR)ofn->lpstrFilter = y;
445 /* convert lpstrCustomFilter */
446 if (ofn->lpstrCustomFilter)
452 lpstrCustomFilter = ofn->lpstrCustomFilter;
453 /* filter is a list... title\0ext\0......\0\0 */
454 s = ofn->lpstrCustomFilter;
455 while (*s) s = s+strlenW(s)+1;
457 n = s - ofn->lpstrCustomFilter;
458 len = WideCharToMultiByte( CP_ACP, 0, ofn->lpstrCustomFilter, n, NULL, 0, NULL, NULL );
459 y = (LPSTR)MemAlloc(len);
460 WideCharToMultiByte( CP_ACP, 0, ofn->lpstrCustomFilter, n, y, len, NULL, NULL );
461 (LPSTR)ofn->lpstrCustomFilter = y;
464 /* convert string arguments, save others */
465 AllocOutArgWtoA(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
466 AllocOutArgWtoA(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
467 AllocInArgWtoA(ofn->lpstrInitialDir, lpstrInitialDir);
468 AllocInArgWtoA(ofn->lpstrTitle, lpstrTitle);
469 AllocInArgWtoA(ofn->lpstrDefExt, lpstrDefExt);
470 AllocInArgWtoA(ofn->lpTemplateName, lpTemplateName);
471 dwFlags = ofn->Flags;
472 hInstance = ofn->hInstance;
474 ofn->Flags = ofn->Flags|OFN_WINE|OFN_UNICODE;
475 ofn->hInstance = MapHModuleLS(ofn->hInstance);
480 ret = GetFileName95(fodInfos);
483 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
484 ret = GetFileName95(fodInfos);
490 /* restore saved IN arguments and convert OUT arguments back */
491 ofn->Flags = dwFlags;
492 ofn->hInstance = hInstance;
493 FreeInArg(ofn->lpstrFilter, lpstrFilter);
494 FreeInArg(ofn->lpstrCustomFilter, lpstrCustomFilter);
495 FreeOutArg(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
496 FreeOutArg(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
497 FreeInArg(ofn->lpstrInitialDir, lpstrInitialDir);
498 FreeInArg(ofn->lpstrTitle, lpstrTitle);
499 FreeInArg(ofn->lpstrDefExt, lpstrDefExt);
500 FreeInArg(ofn->lpTemplateName, lpTemplateName);
502 MemFree((LPVOID)(fodInfos));
506 void ArrangeCtrlPositions( HWND hwndChildDlg, HWND hwndParentDlg)
508 HWND hwndChild,hwndStc32;
509 RECT rectParent, rectChild, rectCtrl, rectStc32, rectTemp;
511 POINT ptParentClient;
515 ptMoveCtl.x = ptMoveCtl.y = 0;
516 hwndStc32=GetDlgItem(hwndChildDlg,stc32);
517 GetClientRect(hwndParentDlg,&rectParent);
518 GetClientRect(hwndChildDlg,&rectChild);
522 GetWindowRect(hwndStc32,&rectStc32);
523 MapWindowPoints(0, hwndChildDlg,(LPPOINT)&rectStc32,2);
524 CopyRect(&rectTemp,&rectStc32);
526 SetRect(&rectStc32,rectStc32.left,rectStc32.top,rectStc32.left + (rectParent.right-rectParent.left),rectStc32.top+(rectParent.bottom-rectParent.top));
527 SetWindowPos(hwndStc32,0,rectStc32.left,rectStc32.top,rectStc32.right-rectStc32.left,rectStc32.bottom-rectStc32.top,SWP_NOMOVE|SWP_NOZORDER | SWP_NOACTIVATE);
529 if(rectStc32.right < rectTemp.right)
531 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
536 ptMoveCtl.x = (rectStc32.right - rectTemp.right);
537 ptParentClient.x = max((rectParent.right-rectParent.left),((rectChild.right-rectChild.left)+rectStc32.right-rectTemp.right));
540 if(rectStc32.bottom < rectTemp.bottom)
542 ptParentClient.y = max((rectParent.bottom-rectParent.top),(rectChild.bottom-rectChild.top));
547 ptMoveCtl.y = (rectStc32.bottom - rectTemp.bottom);
548 ptParentClient.y = max((rectParent.bottom-rectParent.top),((rectChild.bottom-rectChild.top)+rectStc32.bottom-rectTemp.bottom));
553 if( (GetWindow(hwndChildDlg,GW_CHILD)) == (HWND) NULL) return;
555 SetRectEmpty(&rectTemp);
556 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
557 ptParentClient.y = (rectParent.bottom-rectParent.top) + (rectChild.bottom-rectChild.top);
558 ptMoveCtl.y = rectParent.bottom-rectParent.top;
561 SetRect(&rectParent,rectParent.left,rectParent.top,rectParent.left+ptParentClient.x,rectParent.top+ptParentClient.y);
562 AdjustWindowRectEx( &rectParent,GetWindowLongA(hwndParentDlg,GWL_STYLE),FALSE,GetWindowLongA(hwndParentDlg,GWL_EXSTYLE));
564 SetWindowPos(hwndChildDlg, 0, 0,0, ptParentClient.x,ptParentClient.y, SWP_NOZORDER );
565 SetWindowPos(hwndParentDlg, 0, rectParent.left,rectParent.top, (rectParent.right- rectParent.left),
566 (rectParent.bottom-rectParent.top),SWP_NOMOVE | SWP_NOZORDER);
568 hwndChild = GetWindow(hwndChildDlg,GW_CHILD);
571 GetWindowRect(hwndStc32,&rectStc32);
572 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
575 SetRect(&rectStc32,0,0,0,0);
581 if(hwndChild != hwndStc32)
583 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
585 GetWindowRect(hwndChild,&rectCtrl);
586 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
589 Check the initial position of the controls relative to the initial
590 position and size of stc32 (before it is expanded).
592 if (rectCtrl.left >= rectTemp.right && rectCtrl.top >= rectTemp.bottom)
594 rectCtrl.left += ptMoveCtl.x;
595 rectCtrl.top += ptMoveCtl.y;
597 else if (rectCtrl.left >= rectTemp.right)
599 rectCtrl.left += ptMoveCtl.x;
601 else if (rectCtrl.top >= rectTemp.bottom)
603 rectCtrl.top += ptMoveCtl.y;
606 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
607 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
608 SWP_NOSIZE | SWP_NOZORDER );
610 } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
612 hwndChild = GetWindow(hwndParentDlg,GW_CHILD);
616 GetWindowRect(hwndStc32,&rectStc32);
617 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
618 ptMoveCtl.x = rectStc32.left - 0;
619 ptMoveCtl.y = rectStc32.top - 0;
624 if(hwndChild != hwndChildDlg)
626 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
628 GetWindowRect(hwndChild,&rectCtrl);
629 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
631 rectCtrl.left += ptMoveCtl.x;
632 rectCtrl.top += ptMoveCtl.y;
634 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
635 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
636 SWP_NOSIZE |SWP_NOZORDER );
638 } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
644 HRESULT WINAPI FileOpenDlgProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
646 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(GetParent(hwnd),FileOpenDlgInfosStr);
649 TRACE("0x%04x\n", uMsg);
656 fodInfos = (FileOpenDlgInfos *)lParam;
657 lParam = (LPARAM) fodInfos->ofnInfos;
658 ArrangeCtrlPositions(hwnd,GetParent(hwnd));
660 if(fodInfos && IsHooked(fodInfos))
661 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
666 if(fodInfos && IsHooked(fodInfos))
667 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
669 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
672 HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos, HWND hwnd)
681 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATE ||
682 fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
684 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
686 if( !(template = LockResource( fodInfos->ofnInfos->hInstance)))
688 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
694 if (!(hRes = FindResourceA(MapHModuleSL(fodInfos->ofnInfos->hInstance),
695 (fodInfos->ofnInfos->lpTemplateName), RT_DIALOGA)))
697 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
700 if (!(hDlgTmpl = LoadResource( MapHModuleSL(fodInfos->ofnInfos->hInstance),
701 hRes )) || !(template = LockResource( hDlgTmpl )))
703 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
708 hChildDlg= CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,template,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
711 ShowWindow(hChildDlg,SW_SHOW);
715 else if( IsHooked(fodInfos))
720 WORD menu,class,title;
722 GetClientRect(hwnd,&rectHwnd);
723 temp.tmplate.style = WS_CHILD | WS_CLIPSIBLINGS;
724 temp.tmplate.dwExtendedStyle = 0;
725 temp.tmplate.cdit = 0;
728 temp.tmplate.cx = rectHwnd.right-rectHwnd.left;
729 temp.tmplate.cy = rectHwnd.bottom-rectHwnd.top;
730 temp.menu = temp.class = temp.title = 0;
731 hChildDlg = CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,&temp,
732 hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
738 /***********************************************************************
739 * SendCustomDlgNotificationMessage
741 * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
744 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
746 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndParentDlg,FileOpenDlgInfosStr);
748 TRACE("0x%04x 0x%04x\n",hwndParentDlg, uCode);
750 if(!fodInfos) return 0;
752 if(fodInfos->ofnInfos->Flags & OFN_UNICODE)
753 FIXME("sending OPENFILENAMEA structure. Hook is expecting OPENFILENAMEW!\n");
755 if(fodInfos->DlgInfos.hwndCustomDlg)
759 ofnNotify.hdr.hwndFrom=hwndParentDlg;
760 ofnNotify.hdr.idFrom=0;
761 ofnNotify.hdr.code = uCode;
762 ofnNotify.lpOFN = fodInfos->ofnInfos;
763 TRACE("CALL NOTIFY for %x\n", uCode);
764 ret = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);
765 TRACE("RET NOTIFY\n");
771 /***********************************************************************
772 * FILEDLG95_HandleCustomDialogMessages
774 * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
776 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
780 char lpstrPath[MAX_PATH];
781 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
782 if(!fodInfos) return -1;
786 case CDM_GETFILEPATH:
787 GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
788 lpstrFileSpec = (LPSTR)PathFindFileNameA(lpstrPath);
789 if (lpstrFileSpec==lpstrPath)
791 char lpstrCurrentDir[MAX_PATH];
792 /* Prepend the current path */
793 SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrCurrentDir);
794 if ((LPSTR)lParam!=NULL)
795 snprintf((LPSTR)lParam,(int)wParam,"%s\\%s",lpstrCurrentDir,lpstrPath);
796 reqSize=strlen(lpstrCurrentDir)+1+strlen(lpstrPath)+1;
800 lstrcpynA((LPSTR)lParam,(LPSTR)lpstrPath,(int)wParam);
801 reqSize=strlen(lpstrPath);
803 /* return the required buffer size */
806 case CDM_GETFOLDERPATH:
807 SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);
808 if ((LPSTR)lParam!=NULL)
809 lstrcpynA((LPSTR)lParam,lpstrPath,(int)wParam);
810 return strlen(lpstrPath);
813 reqSize=GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
814 lpstrFileSpec = (LPSTR)PathFindFileNameA(lpstrPath);
815 if ((LPSTR)lParam!=NULL)
816 lstrcpynA((LPSTR)lParam, lpstrFileSpec, (int)wParam);
817 return strlen(lpstrFileSpec);
819 case CDM_SETCONTROLTEXT:
821 SetDlgItemTextA( hwnd, (UINT) wParam, (LPSTR) lParam );
824 case CDM_HIDECONTROL:
826 FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");
832 /***********************************************************************
835 * File open dialog procedure
837 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
840 TRACE("0x%04x 0x%04x\n", hwnd, uMsg);
847 FileOpenDlgInfos * fodInfos = (FileOpenDlgInfos *)lParam;
849 /* Adds the FileOpenDlgInfos in the property list of the dialog
850 so it will be easily accessible through a GetPropA(...) */
851 SetPropA(hwnd, FileOpenDlgInfosStr, (HANDLE) fodInfos);
853 fodInfos->DlgInfos.hwndCustomDlg =
854 CreateTemplateDialog((FileOpenDlgInfos *)lParam, hwnd);
856 FILEDLG95_InitControls(hwnd);
857 SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE);
858 FILEDLG95_FillControls(hwnd, wParam, lParam);
859 SendCustomDlgNotificationMessage(hwnd,CDN_SELCHANGE);
860 SetWindowPos(fodInfos->DlgInfos.hwndCustomDlg, HWND_BOTTOM,
861 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE);
865 return FILEDLG95_OnWMCommand(hwnd, wParam, lParam);
868 switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
871 FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT) lParam);
877 case WM_GETISHELLBROWSER:
878 return FILEDLG95_OnWMGetIShellBrowser(hwnd);
881 RemovePropA(hwnd, FileOpenDlgInfosStr);
886 LPNMHDR lpnmh = (LPNMHDR)lParam;
889 /* set up the button tooltips strings */
890 if(TTN_GETDISPINFOA == lpnmh->code )
892 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
893 switch(lpnmh->idFrom )
895 /* Up folder button */
896 case FCIDM_TB_UPFOLDER:
897 stringId = IDS_UPFOLDER;
899 /* New folder button */
900 case FCIDM_TB_NEWFOLDER:
901 stringId = IDS_NEWFOLDER;
903 /* List option button */
904 case FCIDM_TB_SMALLICON:
905 stringId = IDS_LISTVIEW;
907 /* Details option button */
908 case FCIDM_TB_REPORTVIEW:
909 stringId = IDS_REPORTVIEW;
912 case FCIDM_TB_DESKTOP:
913 stringId = IDS_TODESKTOP;
918 lpdi->hinst = COMMDLG_hInstance32;
919 lpdi->lpszText = (LPSTR) stringId;
924 if(uMsg >= CDM_FIRST && uMsg <= CDM_LAST)
925 return FILEDLG95_HandleCustomDialogMessages(hwnd, uMsg, wParam, lParam);
930 /***********************************************************************
931 * FILEDLG95_InitControls
933 * WM_INITDIALOG message handler (before hook notification)
935 static LRESULT FILEDLG95_InitControls(HWND hwnd)
939 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
940 {VIEW_PARENTFOLDER, FCIDM_TB_UPFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
941 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
942 {VIEW_NEWFOLDER+1, FCIDM_TB_DESKTOP, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
943 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
944 {VIEW_NEWFOLDER, FCIDM_TB_NEWFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
945 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
946 {VIEW_LIST, FCIDM_TB_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
947 {VIEW_DETAILS, FCIDM_TB_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
951 { HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR },
952 { COMDLG32_hInstance, 800 } // desktop icon
957 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
959 TRACE("%p\n", fodInfos);
961 /* Get the hwnd of the controls */
962 fodInfos->DlgInfos.hwndFileName = GetDlgItem(hwnd,IDC_FILENAME);
963 fodInfos->DlgInfos.hwndFileTypeCB = GetDlgItem(hwnd,IDC_FILETYPE);
964 fodInfos->DlgInfos.hwndLookInCB = GetDlgItem(hwnd,IDC_LOOKIN);
966 /* construct the toolbar */
967 GetWindowRect(GetDlgItem(hwnd,IDC_TOOLBARSTATIC),&rectTB);
968 MapWindowPoints( 0, hwnd,(LPPOINT)&rectTB,2);
970 fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, (LPSTR) NULL,
971 WS_CHILD | WS_GROUP | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE,
972 0, 0, 150, 26, hwnd, (HMENU) IDC_TOOLBAR, COMMDLG_hInstance32, NULL);
974 SetWindowPos(fodInfos->DlgInfos.hwndTB, 0,
975 rectTB.left,rectTB.top, rectTB.right-rectTB.left, rectTB.bottom-rectTB.top,
976 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
978 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
980 /* FIXME: use TB_LOADIMAGES when implemented */
981 /* SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/
982 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 12, (LPARAM) &tba[0]);
983 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 1, (LPARAM) &tba[1]);
985 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSA, (WPARAM) 9,(LPARAM) &tbb);
986 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_AUTOSIZE, 0, 0);
988 /* Set the window text with the text specified in the OPENFILENAME structure */
989 if(fodInfos->ofnInfos->lpstrTitle)
991 SetWindowTextA(hwnd,fodInfos->ofnInfos->lpstrTitle);
993 else if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
995 SetWindowTextA(hwnd,"Save");
998 /* Initialise the file name edit control */
999 if(fodInfos->ofnInfos->lpstrFile)
1001 LPSTR lpstrFile = PathFindFileNameA(fodInfos->ofnInfos->lpstrFile);
1002 SetDlgItemTextA(hwnd, IDC_FILENAME, lpstrFile);
1005 /* Must the open as read only check box be checked ?*/
1006 if(fodInfos->ofnInfos->Flags & OFN_READONLY)
1008 SendDlgItemMessageA(hwnd,IDC_OPENREADONLY,BM_SETCHECK,(WPARAM)TRUE,0);
1011 /* Must the open as read only check box be hid ?*/
1012 if(fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY)
1014 ShowWindow(GetDlgItem(hwnd,IDC_OPENREADONLY),SW_HIDE);
1017 /* Must the help button be hid ?*/
1018 if (!(fodInfos->ofnInfos->Flags & OFN_SHOWHELP))
1020 ShowWindow(GetDlgItem(hwnd, pshHelp), SW_HIDE);
1023 /* Resize the height, if open as read only checkbox ad help button
1024 are hidden and we are not using a custom template */
1025 if ( (fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) &&
1026 (!(fodInfos->ofnInfos->Flags &
1027 (OFN_SHOWHELP|OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE))))
1029 RECT rectDlg, rectHelp, rectCancel;
1030 GetWindowRect(hwnd, &rectDlg);
1031 GetWindowRect(GetDlgItem(hwnd, pshHelp), &rectHelp);
1032 GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rectCancel);
1033 /* subtract the height of the help button plus the space between
1034 the help button and the cancel button to the height of the dialog */
1035 SetWindowPos(hwnd, 0, 0, 0, rectDlg.right-rectDlg.left,
1036 (rectDlg.bottom-rectDlg.top) - (rectHelp.bottom - rectCancel.bottom),
1037 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
1040 /* change Open to Save FIXME: use resources */
1041 if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
1043 SetDlgItemTextA(hwnd,IDOK,"&Save");
1044 SetDlgItemTextA(hwnd,IDC_LOOKINSTATIC,"Save &in");
1049 /***********************************************************************
1050 * FILEDLG95_FillControls
1052 * WM_INITDIALOG message handler (after hook notification)
1054 static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam)
1056 LPITEMIDLIST pidlItemId = NULL;
1058 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) lParam;
1060 TRACE("dir=%s file=%s\n",
1061 fodInfos->ofnInfos->lpstrInitialDir, fodInfos->ofnInfos->lpstrFile);
1063 /* Get the initial directory pidl */
1065 if(!(pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,fodInfos->ofnInfos->lpstrInitialDir)))
1067 char path[MAX_PATH];
1069 GetCurrentDirectoryA(MAX_PATH,path);
1070 pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder, path);
1073 /* Initialise shell objects */
1074 FILEDLG95_SHELL_Init(hwnd);
1076 /* Initialize the Look In combo box */
1077 FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB);
1079 /* Initialize the filter combo box */
1080 FILEDLG95_FILETYPE_Init(hwnd);
1082 /* Browse to the initial directory */
1083 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,pidlItemId, SBSP_ABSOLUTE);
1085 /* Free pidlItem memory */
1086 COMDLG32_SHFree(pidlItemId);
1090 /***********************************************************************
1093 * Regroups all the cleaning functions of the filedlg
1095 void FILEDLG95_Clean(HWND hwnd)
1097 FILEDLG95_FILETYPE_Clean(hwnd);
1098 FILEDLG95_LOOKIN_Clean(hwnd);
1099 FILEDLG95_SHELL_Clean(hwnd);
1101 /***********************************************************************
1102 * FILEDLG95_OnWMCommand
1104 * WM_COMMAND message handler
1106 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
1108 WORD wNotifyCode = HIWORD(wParam); /* notification code */
1109 WORD wID = LOWORD(wParam); /* item, control, or accelerator identifier */
1110 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1116 if(FILEDLG95_OnOpen(hwnd))
1117 SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK);
1121 FILEDLG95_Clean(hwnd);
1122 EndDialog(hwnd, FALSE);
1124 /* Filetype combo box */
1126 FILEDLG95_FILETYPE_OnCommand(hwnd,wNotifyCode);
1128 /* LookIn combo box */
1130 FILEDLG95_LOOKIN_OnCommand(hwnd,wNotifyCode);
1133 /* --- toolbar --- */
1134 /* Up folder button */
1135 case FCIDM_TB_UPFOLDER:
1136 FILEDLG95_SHELL_UpFolder(hwnd);
1138 /* New folder button */
1139 case FCIDM_TB_NEWFOLDER:
1140 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_NEWFOLDER);
1142 /* List option button */
1143 case FCIDM_TB_SMALLICON:
1144 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWLIST);
1146 /* Details option button */
1147 case FCIDM_TB_REPORTVIEW:
1148 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWDETAILS);
1150 /* Details option button */
1151 case FCIDM_TB_DESKTOP:
1152 FILEDLG95_SHELL_BrowseToDesktop(hwnd);
1159 /* Do not use the listview selection anymore */
1160 fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
1164 /***********************************************************************
1165 * FILEDLG95_OnWMGetIShellBrowser
1167 * WM_GETISHELLBROWSER message handler
1169 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd)
1172 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1176 SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)fodInfos->Shell.FOIShellBrowser);
1182 /***********************************************************************
1183 * FILEDLG95_OnOpenMultipleFiles
1185 * Handles the opening of multiple files.
1188 * check destination buffer size
1190 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed)
1192 CHAR lpstrPathSpec[MAX_PATH] = "";
1194 UINT nCount, nSizePath;
1195 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1199 lpstrFile = fodInfos->ofnInfos->lpstrFile;
1200 lpstrFile[0] = '\0';
1202 SHGetPathFromIDListA( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec );
1204 if ( !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE) &&
1205 ( fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST))
1207 LPSTR lpstrTemp = lpstrFileList;
1209 for ( nCount = 0; nCount < nFileCount; nCount++ )
1213 pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder, lpstrTemp);
1216 CHAR lpstrNotFound[100];
1220 LoadStringA(COMMDLG_hInstance32, IDS_FILENOTFOUND, lpstrNotFound, 100);
1221 LoadStringA(COMMDLG_hInstance32, IDS_VERIFYFILE, lpstrMsg, 100);
1223 strcpy(tmp, lpstrTemp);
1225 strcat(tmp, lpstrNotFound);
1227 strcat(tmp, lpstrMsg);
1229 MessageBoxA(hwnd, tmp, fodInfos->ofnInfos->lpstrTitle, MB_OK | MB_ICONEXCLAMATION);
1233 /* move to the next file in the list of files */
1234 lpstrTemp += strlen(lpstrTemp) + 1;
1235 COMDLG32_SHFree(pidl);
1239 nSizePath = strlen(lpstrPathSpec);
1240 strcpy( lpstrFile, lpstrPathSpec);
1241 memcpy( lpstrFile + nSizePath + 1, lpstrFileList, sizeUsed );
1243 fodInfos->ofnInfos->nFileOffset = nSizePath + 1;
1244 fodInfos->ofnInfos->nFileExtension = 0;
1246 /* clean and exit */
1247 FILEDLG95_Clean(hwnd);
1248 return EndDialog(hwnd,TRUE);
1251 /***********************************************************************
1254 * Ok button WM_COMMAND message handler
1256 * If the function succeeds, the return value is nonzero.
1258 #define ONOPEN_BROWSE 1
1259 #define ONOPEN_OPEN 2
1260 #define ONOPEN_SEARCH 3
1261 static void FILEDLG95_OnOpenMessage(HWND hwnd, int idCaption, int idText)
1263 char strMsgTitle[MAX_PATH];
1264 char strMsgText [MAX_PATH];
1266 LoadStringA(COMDLG32_hInstance, idCaption, strMsgTitle, sizeof(strMsgTitle));
1268 strMsgTitle[0] = '\0';
1269 LoadStringA(COMDLG32_hInstance, idText, strMsgText, sizeof(strMsgText));
1270 MessageBoxA(hwnd,strMsgText, strMsgTitle, MB_OK | MB_ICONHAND);
1273 BOOL FILEDLG95_OnOpen(HWND hwnd)
1275 char * lpstrFileList;
1276 UINT nFileCount = 0;
1279 char lpstrPathAndFile[MAX_PATH];
1280 char lpstrTemp[MAX_PATH];
1281 LPSHELLFOLDER lpsf = NULL;
1283 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1285 TRACE("hwnd=0x%04x\n", hwnd);
1287 /* get the files from the edit control */
1288 nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed);
1290 /* try if the user selected a folder in the shellview */
1293 BrowseSelectedFolder(hwnd);
1299 ret = FILEDLG95_OnOpenMultipleFiles(hwnd, lpstrFileList, nFileCount, sizeUsed);
1303 TRACE("count=%u len=%u file=%s\n", nFileCount, sizeUsed, lpstrFileList);
1306 Step 1: Build a complete path name from the current folder and
1307 the filename or path in the edit box.
1309 - the path in the edit box is a root path
1310 (with or without drive letter)
1311 - the edit box contains ".." (or a path with ".." in it)
1314 /* Get the current directory name */
1315 if (!SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathAndFile))
1317 /* we are in a special folder, default to desktop */
1318 if(FAILED(COMDLG32_SHGetFolderPathA(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, 0, 0, lpstrPathAndFile)))
1321 GetCurrentDirectoryA(MAX_PATH, lpstrPathAndFile);
1324 PathAddBackslashA(lpstrPathAndFile);
1326 TRACE("current directory=%s\n", lpstrPathAndFile);
1328 /* if the user specifyed a fully qualified path use it */
1329 if(PathIsRelativeA(lpstrFileList))
1331 strcat(lpstrPathAndFile, lpstrFileList);
1335 /* does the path have a drive letter? */
1336 if (PathGetDriveNumberA(lpstrFileList) == -1)
1337 strcpy(lpstrPathAndFile+2, lpstrFileList);
1339 strcpy(lpstrPathAndFile, lpstrFileList);
1342 /* resolve "." and ".." */
1343 PathCanonicalizeA(lpstrTemp, lpstrPathAndFile );
1344 strcpy(lpstrPathAndFile, lpstrTemp);
1345 TRACE("canon=%s\n", lpstrPathAndFile);
1347 MemFree(lpstrFileList);
1350 Step 2: here we have a cleaned up path
1352 We have to parse the path step by step to see if we have to browse
1353 to a folder if the path points to a directory or the last
1354 valid element is a directory.
1357 lpstrPathAndFile: cleaned up path
1360 nOpenAction = ONOPEN_BROWSE;
1362 /* dont apply any checks with OFN_NOVALIDATE */
1363 if(!(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE))
1365 LPSTR lpszTemp, lpszTemp1;
1366 LPITEMIDLIST pidl = NULL;
1368 /* check for invalid chars */
1369 if(strpbrk(lpstrPathAndFile+3, "/:<>|") != NULL)
1371 FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_FILENAME);
1376 if (FAILED (SHGetDesktopFolder(&lpsf))) return FALSE;
1378 lpszTemp1 = lpszTemp = lpstrPathAndFile;
1381 LPSHELLFOLDER lpsfChild;
1382 WCHAR lpwstrTemp[MAX_PATH];
1383 DWORD dwEaten, dwAttributes;
1385 lpszTemp = PathFindNextComponentA(lpszTemp);
1387 if (!lpszTemp) break; /* end of path */
1391 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpszTemp1, lpszTemp - lpszTemp1,
1392 lpwstrTemp, MAX_PATH );
1393 lpwstrTemp[len] = 0;
1397 MultiByteToWideChar( CP_ACP, 0, lpszTemp1, -1,
1398 lpwstrTemp, sizeof(lpwstrTemp)/sizeof(WCHAR) );
1400 /* if the last element is a wildcard do a search */
1401 if(strpbrk(lpszTemp1, "*?") != NULL)
1403 nOpenAction = ONOPEN_SEARCH;
1407 lpszTemp1 = lpszTemp;
1409 TRACE("parse now=%s next=%s sf=%p\n",debugstr_w(lpwstrTemp), debugstr_a(lpszTemp), lpsf);
1411 if(lstrlenW(lpwstrTemp)==2) PathAddBackslashW(lpwstrTemp);
1413 dwAttributes = SFGAO_FOLDER;
1414 if(SUCCEEDED(IShellFolder_ParseDisplayName(lpsf, hwnd, NULL, lpwstrTemp, &dwEaten, &pidl, &dwAttributes)))
1416 /* the path component is valid, we have a pidl of the next path component */
1417 TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes, pidl);
1418 if(dwAttributes & SFGAO_FOLDER)
1420 if(FAILED(IShellFolder_BindToObject(lpsf, pidl, 0, &IID_IShellFolder, (LPVOID*)&lpsfChild)))
1422 ERR("bind to failed\n"); /* should not fail */
1425 IShellFolder_Release(lpsf);
1433 /* end dialog, return value */
1434 nOpenAction = ONOPEN_OPEN;
1437 COMDLG32_SHFree(pidl);
1442 if(*lpszTemp) /* points to trailing null for last path element */
1444 if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
1446 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_PATHNOTEXISTING);
1452 if(fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST)
1454 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_FILENOTEXISTING);
1458 /* change to the current folder */
1459 nOpenAction = ONOPEN_OPEN;
1463 if(pidl) COMDLG32_SHFree(pidl);
1467 Step 3: here we have a cleaned up and validated path
1470 lpsf: ShellFolder bound to the rightmost valid path component
1471 lpstrPathAndFile: cleaned up path
1472 nOpenAction: action to do
1474 TRACE("end validate sf=%p\n", lpsf);
1478 case ONOPEN_SEARCH: /* set the current filter to the file mask and refresh */
1479 TRACE("ONOPEN_SEARCH %s\n", lpstrPathAndFile);
1482 LPSTR lpszTemp = PathFindFileNameA(lpstrPathAndFile);
1485 /* replace the current filter */
1486 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1487 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1488 len = MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1, NULL, 0 );
1489 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc(len * sizeof(WCHAR));
1490 MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1,
1491 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1493 /* set the filter cb to the extension when possible */
1494 if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB, lpszTemp)))
1495 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, iPos);
1498 case ONOPEN_BROWSE: /* browse to the highest folder we could bind to */
1499 TRACE("ONOPEN_BROWSE\n");
1501 IPersistFolder2 * ppf2;
1502 if(SUCCEEDED(IShellFolder_QueryInterface( lpsf, &IID_IPersistFolder2, (LPVOID*)&ppf2)))
1504 LPITEMIDLIST pidlCurrent;
1505 IPersistFolder2_GetCurFolder(ppf2, &pidlCurrent);
1506 IPersistFolder2_Release(ppf2);
1507 if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent, fodInfos->ShellInfos.pidlAbsCurrent))
1509 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE);
1511 else if( nOpenAction == ONOPEN_SEARCH )
1513 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1515 COMDLG32_SHFree(pidlCurrent);
1520 case ONOPEN_OPEN: /* fill in the return struct and close the dialog */
1521 TRACE("ONOPEN_OPEN %s\n", lpstrPathAndFile);
1523 /* add default extension */
1524 if (fodInfos->ofnInfos->lpstrDefExt)
1526 if (! *PathFindExtensionA(lpstrPathAndFile))
1528 /* only add "." in case a default extension does exist */
1529 if (*fodInfos->ofnInfos->lpstrDefExt != '\0')
1531 strcat(lpstrPathAndFile, ".");
1532 strcat(lpstrPathAndFile, fodInfos->ofnInfos->lpstrDefExt);
1537 /* Check that the size of the file does not exceed buffer size.
1538 (Allow for extra \0 if OFN_MULTISELECT is set.) */
1539 if(strlen(lpstrPathAndFile) < fodInfos->ofnInfos->nMaxFile -
1540 ((fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT) ? 1 : 0))
1544 /* fill destination buffer */
1545 strcpy(fodInfos->ofnInfos->lpstrFile, lpstrPathAndFile);
1546 if (fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT)
1547 fodInfos->ofnInfos->lpstrFile[strlen(fodInfos->ofnInfos->lpstrFile)
1550 /* set filename offset */
1551 lpszTemp = PathFindFileNameA(lpstrPathAndFile);
1552 fodInfos->ofnInfos->nFileOffset = lpszTemp - lpstrPathAndFile;
1554 /* set extension offset */
1555 lpszTemp = PathFindExtensionA(lpstrPathAndFile);
1556 fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? lpszTemp - lpstrPathAndFile + 1 : 0;
1558 /* set the lpstrFileTitle */
1559 if(fodInfos->ofnInfos->lpstrFileTitle)
1561 LPSTR lpstrFileTitle = PathFindFileNameA(lpstrPathAndFile);
1562 strncpy(fodInfos->ofnInfos->lpstrFileTitle, lpstrFileTitle, fodInfos->ofnInfos->nMaxFileTitle);
1565 /* ask the hook if we can close */
1566 if(IsHooked(fodInfos))
1568 /* FIXME we are sending ASCII-structures. Does not work with NT */
1569 /* first old style */
1571 CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,
1572 fodInfos->DlgInfos.hwndCustomDlg,
1573 fodInfos->HookMsg.fileokstring, 0, (LPARAM)fodInfos->ofnInfos);
1574 if (GetWindowLongA(hwnd, DWL_MSGRESULT))
1583 FILEDLG95_Clean(hwnd);
1584 ret = EndDialog(hwnd, TRUE);
1588 /* FIXME set error FNERR_BUFFERTOSMALL */
1589 FILEDLG95_Clean(hwnd);
1590 ret = EndDialog(hwnd, FALSE);
1598 if(lpsf) IShellFolder_Release(lpsf);
1602 /***********************************************************************
1603 * FILEDLG95_SHELL_Init
1605 * Initialisation of the shell objects
1607 static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
1609 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1614 * Initialisation of the FileOpenDialogInfos structure
1620 fodInfos->ShellInfos.hwndOwner = hwnd;
1622 /* Disable multi-select if flag not set */
1623 if (!(fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT))
1625 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_SINGLESEL;
1627 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_AUTOARRANGE | FWF_ALIGNLEFT;
1628 fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
1630 GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
1631 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
1632 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
1634 /* Construct the IShellBrowser interface */
1635 fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
1640 /***********************************************************************
1641 * FILEDLG95_SHELL_ExecuteCommand
1643 * Change the folder option and refresh the view
1644 * If the function succeeds, the return value is nonzero.
1646 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
1648 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1651 TRACE("(0x%08x,%p)\n", hwnd, lpVerb);
1653 if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
1658 CMINVOKECOMMANDINFO ci;
1659 ZeroMemory(&ci, sizeof(CMINVOKECOMMANDINFO));
1660 ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
1664 IContextMenu_InvokeCommand(pcm, &ci);
1665 IContextMenu_Release(pcm);
1671 /***********************************************************************
1672 * FILEDLG95_SHELL_UpFolder
1674 * Browse to the specified object
1675 * If the function succeeds, the return value is nonzero.
1677 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
1679 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1683 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1692 /***********************************************************************
1693 * FILEDLG95_SHELL_BrowseToDesktop
1695 * Browse to the Desktop
1696 * If the function succeeds, the return value is nonzero.
1698 static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd)
1700 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1706 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidl);
1707 hres = IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidl, SBSP_ABSOLUTE);
1708 COMDLG32_SHFree(pidl);
1709 return SUCCEEDED(hres);
1711 /***********************************************************************
1712 * FILEDLG95_SHELL_Clean
1714 * Cleans the memory used by shell objects
1716 static void FILEDLG95_SHELL_Clean(HWND hwnd)
1718 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1722 COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent);
1724 /* clean Shell interfaces */
1725 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
1726 IShellView_Release(fodInfos->Shell.FOIShellView);
1727 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
1728 IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
1729 if (fodInfos->Shell.FOIDataObject)
1730 IDataObject_Release(fodInfos->Shell.FOIDataObject);
1733 /***********************************************************************
1734 * FILEDLG95_FILETYPE_Init
1736 * Initialisation of the file type combo box
1738 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
1740 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1744 if(fodInfos->ofnInfos->lpstrFilter)
1746 int nFilters = 0; /* number of filters */
1748 LPCSTR lpstrPos = fodInfos->ofnInfos->lpstrFilter;
1752 /* filter is a list... title\0ext\0......\0\0
1753 * Set the combo item text to the title and the item data
1756 LPCSTR lpstrDisplay;
1760 if(! *lpstrPos) break; /* end */
1761 lpstrDisplay = lpstrPos;
1762 lpstrPos += strlen(lpstrPos) + 1;
1764 /* Copy the extensions */
1765 if (! *lpstrPos) return E_FAIL; /* malformed filter */
1766 if (!(lpstrExt = (LPSTR) MemAlloc(strlen(lpstrPos)+1))) return E_FAIL;
1767 strcpy(lpstrExt,lpstrPos);
1768 lpstrPos += strlen(lpstrPos) + 1;
1770 /* Add the item at the end of the combo */
1771 CBAddString(fodInfos->DlgInfos.hwndFileTypeCB, lpstrDisplay);
1772 CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt);
1776 * Set the current filter to the one specified
1777 * in the initialisation structure
1778 * FIXME: lpstrCustomFilter not handled at all
1781 /* set default filter index */
1782 if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->ofnInfos->lpstrCustomFilter == NULL)
1783 fodInfos->ofnInfos->nFilterIndex = 1;
1785 /* First, check to make sure our index isn't out of bounds. */
1786 if ( fodInfos->ofnInfos->nFilterIndex > nFilters )
1787 fodInfos->ofnInfos->nFilterIndex = nFilters;
1789 /* Set the current index selection. */
1790 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->ofnInfos->nFilterIndex-1);
1792 /* Get the corresponding text string from the combo box. */
1793 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1794 fodInfos->ofnInfos->nFilterIndex-1);
1796 if ((INT)lpstrFilter == CB_ERR) /* control is empty */
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 );
1812 /***********************************************************************
1813 * FILEDLG95_FILETYPE_OnCommand
1815 * WM_COMMAND of the file type combo box
1816 * If the function succeeds, the return value is nonzero.
1818 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
1820 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1828 /* Get the current item of the filetype combo box */
1829 int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1831 /* set the current filter index - indexed from 1 */
1832 fodInfos->ofnInfos->nFilterIndex = iItem + 1;
1834 /* Set the current filter with the current selection */
1835 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1836 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1838 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1840 if((int)lpstrFilter != CB_ERR)
1843 _strlwr(lpstrFilter); /* lowercase */
1844 len = MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1, NULL, 0 );
1845 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
1846 MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1,
1847 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1848 SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
1851 /* Refresh the actual view to display the included items*/
1852 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1857 /***********************************************************************
1858 * FILEDLG95_FILETYPE_SearchExt
1860 * searches for a extension in the filetype box
1862 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt)
1864 int i, iCount = CBGetCount(hwnd);
1866 TRACE("%s\n", lpstrExt);
1868 if(iCount != CB_ERR)
1870 for(i=0;i<iCount;i++)
1872 if(!strcasecmp(lpstrExt,(LPSTR)CBGetItemDataPtr(hwnd,i)))
1879 /***********************************************************************
1880 * FILEDLG95_FILETYPE_Clean
1882 * Clean the memory used by the filetype combo box
1884 static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
1886 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1888 int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
1892 /* Delete each string of the combo and their associated data */
1893 if(iCount != CB_ERR)
1895 for(iPos = iCount-1;iPos>=0;iPos--)
1897 MemFree((LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos));
1898 CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1901 /* Current filter */
1902 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1903 MemFree(fodInfos->ShellInfos.lpstrCurrentFilter);
1907 /***********************************************************************
1908 * FILEDLG95_LOOKIN_Init
1910 * Initialisation of the look in combo box
1912 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
1914 IShellFolder *psfRoot, *psfDrives;
1915 IEnumIDList *lpeRoot, *lpeDrives;
1916 LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
1918 LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
1922 liInfos->iMaxIndentation = 0;
1924 SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
1926 /* set item height for both text field and listbox */
1927 CBSetItemHeight(hwndCombo,-1,GetSystemMetrics(SM_CYSMICON));
1928 CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
1930 /* Initialise data of Desktop folder */
1931 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
1932 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1933 COMDLG32_SHFree(pidlTmp);
1935 SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
1937 SHGetDesktopFolder(&psfRoot);
1941 /* enumerate the contents of the desktop */
1942 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
1944 while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
1946 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1948 /* special handling for CSIDL_DRIVES */
1949 if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
1951 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
1953 /* enumerate the drives */
1954 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
1956 while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
1958 pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
1959 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
1960 COMDLG32_SHFree(pidlAbsTmp);
1961 COMDLG32_SHFree(pidlTmp1);
1963 IEnumIDList_Release(lpeDrives);
1965 IShellFolder_Release(psfDrives);
1968 COMDLG32_SHFree(pidlTmp);
1970 IEnumIDList_Release(lpeRoot);
1974 IShellFolder_Release(psfRoot);
1975 COMDLG32_SHFree(pidlDrives);
1979 /***********************************************************************
1980 * FILEDLG95_LOOKIN_DrawItem
1982 * WM_DRAWITEM message handler
1984 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
1986 COLORREF crWin = GetSysColor(COLOR_WINDOW);
1987 COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
1988 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1992 HIMAGELIST ilItemImage;
1995 LPSFOLDER tmpFolder;
1998 LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
2002 if(pDIStruct->itemID == -1)
2005 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
2006 pDIStruct->itemID)))
2010 if(pDIStruct->itemID == liInfos->uSelectedItem)
2012 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2015 sizeof (SHFILEINFOA),
2016 SHGFI_PIDL | SHGFI_SMALLICON |
2017 SHGFI_OPENICON | SHGFI_SYSICONINDEX |
2018 SHGFI_DISPLAYNAME );
2022 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2025 sizeof (SHFILEINFOA),
2026 SHGFI_PIDL | SHGFI_SMALLICON |
2027 SHGFI_SYSICONINDEX |
2031 /* Is this item selected ? */
2032 if(pDIStruct->itemState & ODS_SELECTED)
2034 SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
2035 SetBkColor(pDIStruct->hDC,crHighLight);
2036 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,GetSysColorBrush(COLOR_HIGHLIGHT));
2040 SetTextColor(pDIStruct->hDC,crText);
2041 SetBkColor(pDIStruct->hDC,crWin);
2042 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,GetSysColorBrush(COLOR_WINDOW));
2045 /* Do not indent item if drawing in the edit of the combo */
2046 if(pDIStruct->itemState & ODS_COMBOBOXEDIT)
2049 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2052 sizeof (SHFILEINFOA),
2053 SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON
2054 | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME );
2059 iIndentation = tmpFolder->m_iIndent;
2061 /* Draw text and icon */
2063 /* Initialise the icon display area */
2064 rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
2065 rectIcon.top = pDIStruct->rcItem.top;
2066 rectIcon.right = rectIcon.left + ICONWIDTH;
2067 rectIcon.bottom = pDIStruct->rcItem.bottom;
2069 /* Initialise the text display area */
2070 GetTextMetricsA(pDIStruct->hDC, &tm);
2071 rectText.left = rectIcon.right;
2073 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom - tm.tmHeight) / 2;
2074 rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
2076 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom + tm.tmHeight) / 2;
2078 /* Draw the icon from the image list */
2079 ImageList_Draw(ilItemImage,
2086 /* Draw the associated text */
2087 if(sfi.szDisplayName)
2088 TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName));
2094 /***********************************************************************
2095 * FILEDLG95_LOOKIN_OnCommand
2097 * LookIn combo box WM_COMMAND message handler
2098 * If the function succeeds, the return value is nonzero.
2100 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
2102 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2104 TRACE("%p\n", fodInfos);
2110 LPSFOLDER tmpFolder;
2113 iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
2115 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
2120 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
2121 tmpFolder->pidlItem,
2133 /***********************************************************************
2134 * FILEDLG95_LOOKIN_AddItem
2136 * Adds an absolute pidl item to the lookin combo box
2137 * returns the index of the inserted item
2139 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
2141 LPITEMIDLIST pidlNext;
2144 LookInInfos *liInfos;
2146 TRACE("%08x\n", iInsertId);
2151 if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
2154 tmpFolder = MemAlloc(sizeof(SFOLDER));
2155 tmpFolder->m_iIndent = 0;
2157 /* Calculate the indentation of the item in the lookin*/
2159 while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
2161 tmpFolder->m_iIndent++;
2164 tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl); /* FIXME: memory leak*/
2166 if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
2167 liInfos->iMaxIndentation = tmpFolder->m_iIndent;
2169 sfi.dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM;
2170 SHGetFileInfoA((LPSTR)pidl,
2174 SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX
2175 | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED);
2177 TRACE("-- Add %s attr=%08lx\n", sfi.szDisplayName, sfi.dwAttributes);
2179 if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
2183 TRACE("-- Add %s at %u\n", sfi.szDisplayName, tmpFolder->m_iIndent);
2185 /* Add the item at the end of the list */
2188 iItemID = CBAddString(hwnd,sfi.szDisplayName);
2190 /* Insert the item at the iInsertId position*/
2193 iItemID = CBInsertString(hwnd,sfi.szDisplayName,iInsertId);
2196 CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
2200 MemFree( tmpFolder );
2205 /***********************************************************************
2206 * FILEDLG95_LOOKIN_InsertItemAfterParent
2208 * Insert an item below its parent
2210 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
2213 LPITEMIDLIST pidlParent = GetParentPidl(pidl);
2218 iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
2222 iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
2225 /* Free pidlParent memory */
2226 COMDLG32_SHFree((LPVOID)pidlParent);
2228 return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
2231 /***********************************************************************
2232 * FILEDLG95_LOOKIN_SelectItem
2234 * Adds an absolute pidl item to the lookin combo box
2235 * returns the index of the inserted item
2237 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
2240 LookInInfos *liInfos;
2244 iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
2246 liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2250 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
2251 iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
2256 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2257 while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
2261 if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
2263 if(iRemovedItem < iItemPos)
2268 CBSetCurSel(hwnd,iItemPos);
2269 liInfos->uSelectedItem = iItemPos;
2275 /***********************************************************************
2276 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2278 * Remove the item with an expansion level over iExpansionLevel
2280 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
2284 LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2288 if(liInfos->iMaxIndentation <= 2)
2291 if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
2293 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2294 COMDLG32_SHFree(tmpFolder->pidlItem);
2296 CBDeleteString(hwnd,iItemPos);
2297 liInfos->iMaxIndentation--;
2305 /***********************************************************************
2306 * FILEDLG95_LOOKIN_SearchItem
2308 * Search for pidl in the lookin combo box
2309 * returns the index of the found item
2311 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
2314 int iCount = CBGetCount(hwnd);
2316 TRACE("0x%08x 0x%x\n",searchArg, iSearchMethod);
2318 if (iCount != CB_ERR)
2322 LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
2324 if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
2326 if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
2334 /***********************************************************************
2335 * FILEDLG95_LOOKIN_Clean
2337 * Clean the memory used by the lookin combo box
2339 static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
2341 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2343 int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
2347 /* Delete each string of the combo and their associated data */
2348 if (iCount != CB_ERR)
2350 for(iPos = iCount-1;iPos>=0;iPos--)
2352 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos);
2353 COMDLG32_SHFree(tmpFolder->pidlItem);
2355 CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
2359 /* LookInInfos structure */
2360 RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
2363 /***********************************************************************
2364 * FILEDLG95_FILENAME_FillFromSelection
2366 * fills the edit box from the cached DataObject
2368 void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd)
2370 FileOpenDlgInfos *fodInfos;
2372 UINT nFiles = 0, nFileToOpen, nFileSelected, nLength = 0;
2373 char lpstrTemp[MAX_PATH];
2374 LPSTR lpstrAllFile = NULL, lpstrCurrFile = NULL;
2377 fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2379 /* Count how many files we have */
2380 nFileSelected = GetNumSelected( fodInfos->Shell.FOIDataObject );
2382 /* calculate the string length, count files */
2383 if (nFileSelected >= 1)
2385 nLength += 3; /* first and last quotes, trailing \0 */
2386 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2388 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2392 /* get the total length of the selected file names*/
2393 lpstrTemp[0] = '\0';
2394 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER|SHGDN_FORPARSING, lpstrTemp );
2396 if ( ! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl) ) /* Ignore folders */
2398 nLength += strlen( lpstrTemp ) + 3;
2401 COMDLG32_SHFree( pidl );
2406 /* allocate the buffer */
2407 if (nFiles <= 1) nLength = MAX_PATH;
2408 lpstrAllFile = (LPSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength);
2409 lpstrAllFile[0] = '\0';
2411 /* Generate the string for the edit control */
2414 lpstrCurrFile = lpstrAllFile;
2415 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2417 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2421 /* get the file name */
2422 lpstrTemp[0] = '\0';
2423 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER|SHGDN_FORPARSING, lpstrTemp );
2425 if (! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl)) /* Ignore folders */
2429 *lpstrCurrFile++ = '\"';
2430 strcpy( lpstrCurrFile, lpstrTemp );
2431 lpstrCurrFile += strlen( lpstrTemp );
2432 strcpy( lpstrCurrFile, "\" " );
2437 strcpy( lpstrAllFile, lpstrTemp );
2440 COMDLG32_SHFree( (LPVOID) pidl );
2445 SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile );
2446 HeapFree(GetProcessHeap(),0, lpstrAllFile );
2450 /* copied from shell32 to avoid linking to it */
2451 static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
2456 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL);
2457 COMDLG32_SHFree(src->u.pOleStr);
2461 lstrcpynA((LPSTR)dest, src->u.cStr, len);
2464 case STRRET_OFFSETA:
2465 lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
2469 FIXME("unknown type!\n");
2472 *(LPSTR)dest = '\0';
2479 /***********************************************************************
2480 * FILEDLG95_FILENAME_GetFileNames
2482 * copies the filenames to a 0-delimited string list (A\0B\0C\0\0)
2484 int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPSTR * lpstrFileList, UINT * sizeUsed)
2486 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2487 UINT nStrCharCount = 0; /* index in src buffer */
2488 UINT nFileIndex = 0; /* index in dest buffer */
2489 UINT nFileCount = 0; /* number of files */
2490 UINT nStrLen = 0; /* length of string in edit control */
2491 LPSTR lpstrEdit; /* buffer for string from edit control */
2495 /* get the filenames from the edit control */
2496 nStrLen = SendMessageA(fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0);
2497 lpstrEdit = MemAlloc(nStrLen+1);
2498 GetDlgItemTextA(hwnd, IDC_FILENAME, lpstrEdit, nStrLen+1);
2500 TRACE("nStrLen=%u str=%s\n", nStrLen, lpstrEdit);
2502 /* we might get single filename without any '"',
2503 * so we need nStrLen + terminating \0 + end-of-list \0 */
2504 *lpstrFileList = MemAlloc(nStrLen+2);
2507 /* build 0-delimited file list from filenames */
2508 while ( nStrCharCount <= nStrLen )
2510 if ( lpstrEdit[nStrCharCount]=='"' )
2513 while ((lpstrEdit[nStrCharCount]!='"') && (nStrCharCount <= nStrLen))
2515 (*lpstrFileList)[nFileIndex++] = lpstrEdit[nStrCharCount];
2519 (*lpstrFileList)[nFileIndex++] = '\0';
2526 /* single, unquoted string */
2527 if ((nStrLen > 0) && (*sizeUsed == 0) )
2529 strcpy(*lpstrFileList, lpstrEdit);
2530 nFileIndex = strlen(lpstrEdit) + 1;
2531 (*sizeUsed) = nFileIndex;
2536 (*lpstrFileList)[nFileIndex] = '\0';
2543 #define SETDefFormatEtc(fe,cf,med) \
2545 (fe).cfFormat = cf;\
2546 (fe).dwAspect = DVASPECT_CONTENT; \
2553 * DATAOBJECT Helper functions
2556 /***********************************************************************
2557 * COMCTL32_ReleaseStgMedium
2559 * like ReleaseStgMedium from ole32
2561 static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium)
2563 if(medium.pUnkForRelease)
2565 IUnknown_Release(medium.pUnkForRelease);
2569 GlobalUnlock(medium.u.hGlobal);
2570 GlobalFree(medium.u.hGlobal);
2574 /***********************************************************************
2575 * GetPidlFromDataObject
2577 * Return pidl(s) by number from the cached DataObject
2579 * nPidlIndex=0 gets the fully qualified root path
2581 LPITEMIDLIST GetPidlFromDataObject ( IDataObject *doSelected, UINT nPidlIndex)
2585 FORMATETC formatetc;
2586 LPITEMIDLIST pidl = NULL;
2588 TRACE("sv=%p index=%u\n", doSelected, nPidlIndex);
2590 /* Set the FORMATETC structure*/
2591 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2593 /* Get the pidls from IDataObject */
2594 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2596 LPIDA cida = GlobalLock(medium.u.hGlobal);
2597 if(nPidlIndex <= cida->cidl)
2599 pidl = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[nPidlIndex]]));
2601 COMCTL32_ReleaseStgMedium(medium);
2606 /***********************************************************************
2609 * Return the number of selected items in the DataObject.
2612 UINT GetNumSelected( IDataObject *doSelected )
2616 FORMATETC formatetc;
2618 TRACE("sv=%p\n", doSelected);
2620 if (!doSelected) return 0;
2622 /* Set the FORMATETC structure*/
2623 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2625 /* Get the pidls from IDataObject */
2626 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2628 LPIDA cida = GlobalLock(medium.u.hGlobal);
2629 retVal = cida->cidl;
2630 COMCTL32_ReleaseStgMedium(medium);
2640 /***********************************************************************
2643 * Get the pidl's display name (relative to folder) and
2644 * put it in lpstrFileName.
2646 * Return NOERROR on success,
2650 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
2655 TRACE("sf=%p pidl=%p\n", lpsf, pidl);
2660 SHGetDesktopFolder(&lpsf);
2661 hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
2662 IShellFolder_Release(lpsf);
2666 /* Get the display name of the pidl relative to the folder */
2667 if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf, pidl, dwFlags, &str)))
2669 return COMDLG32_StrRetToStrNA(lpstrFileName, MAX_PATH, &str, pidl);
2674 /***********************************************************************
2675 * GetShellFolderFromPidl
2677 * pidlRel is the item pidl relative
2678 * Return the IShellFolder of the absolute pidl
2680 IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
2682 IShellFolder *psf = NULL,*psfParent;
2684 TRACE("%p\n", pidlAbs);
2686 if(SUCCEEDED(SHGetDesktopFolder(&psfParent)))
2689 if(pidlAbs && pidlAbs->mkid.cb)
2691 if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
2693 IShellFolder_Release(psfParent);
2697 /* return the desktop */
2703 /***********************************************************************
2706 * Return the LPITEMIDLIST to the parent of the pidl in the list
2708 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
2710 LPITEMIDLIST pidlParent;
2712 TRACE("%p\n", pidl);
2714 pidlParent = COMDLG32_PIDL_ILClone(pidl);
2715 COMDLG32_PIDL_ILRemoveLastID(pidlParent);
2720 /***********************************************************************
2723 * returns the pidl of the file name relative to folder
2724 * NULL if an error occurred
2726 LPITEMIDLIST GetPidlFromName(IShellFolder *lpsf,LPCSTR lpcstrFileName)
2730 WCHAR lpwstrDirName[MAX_PATH];
2732 TRACE("sf=%p file=%s\n", lpsf, lpcstrFileName);
2734 if(!lpcstrFileName) return NULL;
2735 if(!*lpcstrFileName) return NULL;
2737 MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,lpcstrFileName,-1,(LPWSTR)lpwstrDirName,MAX_PATH);
2741 SHGetDesktopFolder(&lpsf);
2742 pidl = GetPidlFromName(lpsf, lpcstrFileName);
2743 IShellFolder_Release(lpsf);
2747 IShellFolder_ParseDisplayName(lpsf, 0, NULL, (LPWSTR)lpwstrDirName, &ulEaten, &pidl, NULL);
2754 BOOL IsPidlFolder (LPSHELLFOLDER psf, LPITEMIDLIST pidl)
2756 ULONG uAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
2759 TRACE("%p, %p\n", psf, pidl);
2761 ret = IShellFolder_GetAttributesOf( psf, 1, &pidl, &uAttr );
2763 TRACE("-- 0x%08lx 0x%08lx\n", uAttr, ret);
2764 /* see documentation shell 4.1*/
2765 return uAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER);
2768 /***********************************************************************
2769 * BrowseSelectedFolder
2771 static BOOL BrowseSelectedFolder(HWND hwnd)
2773 BOOL bBrowseSelFolder = FALSE;
2774 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2778 if (GetNumSelected(fodInfos->Shell.FOIDataObject) == 1)
2780 LPITEMIDLIST pidlSelection;
2782 /* get the file selected */
2783 pidlSelection = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, 1);
2784 if (IsPidlFolder (fodInfos->Shell.FOIShellFolder, pidlSelection))
2786 if ( FAILED( IShellBrowser_BrowseObject( fodInfos->Shell.FOIShellBrowser,
2787 pidlSelection, SBSP_RELATIVE ) ) )
2789 MessageBoxA( hwnd, "Path does not exist", fodInfos->ofnInfos->lpstrTitle,
2790 MB_OK | MB_ICONEXCLAMATION );
2793 bBrowseSelFolder = TRUE;
2795 COMDLG32_SHFree( pidlSelection );
2798 return bBrowseSelFolder;
2802 * Memory allocation methods */
2803 static void *MemAlloc(UINT size)
2805 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
2808 static void MemFree(void *mem)
2812 HeapFree(GetProcessHeap(),0,mem);