2 * COMMDLG - File Open Dialogs Win95 look and feel
4 * FIXME: lpstrCustomFilter not handeled
6 * FIXME: if the size of lpstrFile (nMaxFile) is to small the first
7 * two bytes of lpstrFile should contain the needed size
9 * FIXME: algorithm for selecting the initial directory is to simple
11 * FIXME: add to recent docs
13 * FIXME: flags not implemented: OFN_CREATEPROMPT, OFN_DONTADDTORECENT,
14 * OFN_ENABLEINCLUDENOTIFY, OFN_ENABLESIZING, OFN_EXTENSIONDIFFERENT,
15 * OFN_NOCHANGEDIR, OFN_NODEREFERENCELINKS, OFN_READONLYRETURN,
16 * OFN_NOTESTFILECREATE, OFN_OVERWRITEPROMPT, OFN_USEMONIKERS
18 * FIXME: lCustData for lpfnHook (WM_INITDIALOG)
33 #include "debugtools.h"
38 #include "filedlgbrowser.h"
40 #include "wine/obj_contextmenu.h"
42 DEFAULT_DEBUG_CHANNEL(commdlg
);
44 /***********************************************************************
45 * Data structure and global variables
47 typedef struct SFolder
49 int m_iImageIndex
; /* Index of picture in image list */
51 int m_iIndent
; /* Indentation index */
52 LPITEMIDLIST pidlItem
; /* absolute pidl of the item */
56 typedef struct tagLookInInfo
63 /***********************************************************************
64 * Defines and global variables
67 /* Draw item constant */
75 /* SearchItem methods */
78 #define ITEM_NOTFOUND -1
80 /* Undefined windows message sent by CreateViewObject*/
81 #define WM_GETISHELLBROWSER WM_USER+7
84 * Those macros exist in windowsx.h. However, you can't really use them since
85 * they rely on the UNICODE defines and can't be use inside Wine itself.
88 /* Combo box macros */
89 #define CBAddString(hwnd,str) \
90 SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str);
92 #define CBInsertString(hwnd,str,pos) \
93 SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str);
95 #define CBDeleteString(hwnd,pos) \
96 SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0);
98 #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
99 SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr);
101 #define CBGetItemDataPtr(hwnd,iItemId) \
102 SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0)
104 #define CBGetLBText(hwnd,iItemId,str) \
105 SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str);
107 #define CBGetCurSel(hwnd) \
108 SendMessageA(hwnd,CB_GETCURSEL,0,0);
110 #define CBSetCurSel(hwnd,pos) \
111 SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0);
113 #define CBGetCount(hwnd) \
114 SendMessageA(hwnd,CB_GETCOUNT,0,0);
115 #define CBShowDropDown(hwnd,show) \
116 SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0);
117 #define CBSetItemHeight(hwnd,index,height) \
118 SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height);
121 const char *FileOpenDlgInfosStr
= "FileOpenDlgInfos"; /* windows property description string */
122 const char *LookInInfosStr
= "LookInInfos"; /* LOOKIN combo box property */
124 static const char defaultFilter
[] = "*.*";
126 /***********************************************************************
130 /* Internal functions used by the dialog */
131 static LRESULT
FILEDLG95_OnWMInitDialog(HWND hwnd
, WPARAM wParam
, LPARAM lParam
);
132 static LRESULT
FILEDLG95_OnWMCommand(HWND hwnd
, WPARAM wParam
, LPARAM lParam
);
133 static LRESULT
FILEDLG95_OnWMGetIShellBrowser(HWND hwnd
);
134 BOOL
FILEDLG95_OnOpen(HWND hwnd
);
135 static LRESULT
FILEDLG95_InitUI(HWND hwnd
);
136 static void FILEDLG95_Clean(HWND hwnd
);
138 /* Functions used by the shell navigation */
139 static LRESULT
FILEDLG95_SHELL_Init(HWND hwnd
);
140 static BOOL
FILEDLG95_SHELL_UpFolder(HWND hwnd
);
141 static BOOL
FILEDLG95_SHELL_ExecuteCommand(HWND hwnd
, LPCSTR lpVerb
);
142 static void FILEDLG95_SHELL_Clean(HWND hwnd
);
143 static BOOL
FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd
);
145 /* Functions used by the filetype combo box */
146 static HRESULT
FILEDLG95_FILETYPE_Init(HWND hwnd
);
147 static BOOL
FILEDLG95_FILETYPE_OnCommand(HWND hwnd
, WORD wNotifyCode
);
148 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd
,LPCSTR lpstrExt
);
149 static void FILEDLG95_FILETYPE_Clean(HWND hwnd
);
151 /* Functions used by the Look In combo box */
152 static HRESULT
FILEDLG95_LOOKIN_Init(HWND hwndCombo
);
153 static LRESULT
FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct
);
154 static BOOL
FILEDLG95_LOOKIN_OnCommand(HWND hwnd
, WORD wNotifyCode
);
155 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd
,LPITEMIDLIST pidl
, int iInsertId
);
156 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd
,WPARAM searchArg
,int iSearchMethod
);
157 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd
,LPITEMIDLIST pidl
);
158 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd
);
159 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd
,LPITEMIDLIST pidl
);
160 static void FILEDLG95_LOOKIN_Clean(HWND hwnd
);
162 /* Miscellaneous tool functions */
163 HRESULT
GetName(LPSHELLFOLDER lpsf
, LPITEMIDLIST pidl
,DWORD dwFlags
,LPSTR lpstrFileName
);
164 HRESULT
GetFileName(HWND hwnd
, LPITEMIDLIST pidl
, LPSTR lpstrFileName
);
165 IShellFolder
* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs
);
166 LPITEMIDLIST
GetParentPidl(LPITEMIDLIST pidl
);
167 LPITEMIDLIST
GetPidlFromName(IShellFolder
*psf
,LPCSTR lpcstrFileName
);
169 /* Shell memory allocation */
170 static void *MemAlloc(UINT size
);
171 static void MemFree(void *mem
);
173 BOOL WINAPI
GetFileName95(FileOpenDlgInfos
*fodInfos
);
174 HRESULT WINAPI
FileOpenDlgProc95(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
175 HRESULT
SendCustomDlgNotificationMessage(HWND hwndParentDlg
, UINT uCode
);
176 HRESULT
FILEDLG95_HandleCustomDialogMessages(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
177 BOOL
FILEDLG95_OnOpenMultipleFiles(HWND hwnd
, LPSTR lpstrFileList
, UINT nFileCount
, UINT sizeUsed
);
178 static BOOL
BrowseSelectedFolder(HWND hwnd
);
180 extern LPSTR
_strlwr( LPSTR str
);
182 /***********************************************************************
185 * Creates an Open common dialog box that lets the user select
186 * the drive, directory, and the name of a file or set of files to open.
188 * IN : The FileOpenDlgInfos structure associated with the dialog
189 * OUT : TRUE on success
190 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
192 BOOL WINAPI
GetFileName95(FileOpenDlgInfos
*fodInfos
)
200 /* Create the dialog from a template */
202 if(!(hRes
= FindResourceA(COMMDLG_hInstance32
,MAKEINTRESOURCEA(NEWFILEOPENORD
),RT_DIALOGA
)))
204 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
207 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hRes
)) ||
208 !(template = LockResource( hDlgTmpl
)))
210 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
213 lRes
= DialogBoxIndirectParamA(COMMDLG_hInstance32
,
214 (LPDLGTEMPLATEA
) template,
215 fodInfos
->ofnInfos
->hwndOwner
,
216 (DLGPROC
) FileOpenDlgProc95
,
219 /* Unable to create the dialog*/
226 /***********************************************************************
229 * Call GetFileName95 with this structure and clean the memory.
231 * IN : The OPENFILENAMEA initialisation structure passed to
232 * GetOpenFileNameA win api function (see filedlg.c)
234 BOOL WINAPI
GetFileDialog95A(LPOPENFILENAMEA ofn
,UINT iDlgType
)
238 FileOpenDlgInfos
*fodInfos
;
240 LPCSTR lpstrInitialDir
= NULL
;
243 /* Initialise FileOpenDlgInfos structure*/
244 fodInfos
= (FileOpenDlgInfos
*)MemAlloc(sizeof(FileOpenDlgInfos
));
245 ZeroMemory(fodInfos
, sizeof(FileOpenDlgInfos
));
247 /* Pass in the original ofn */
248 fodInfos
->ofnInfos
= ofn
;
250 /* Save original hInstance value */
251 hInstance
= ofn
->hInstance
;
252 fodInfos
->ofnInfos
->hInstance
= MapHModuleLS(ofn
->hInstance
);
254 dwFlags
= ofn
->Flags
;
255 ofn
->Flags
= ofn
->Flags
|OFN_WINE
;
257 /* Replace the NULL lpstrInitialDir by the current folder */
258 if(!ofn
->lpstrInitialDir
)
260 lpstrInitialDir
= ofn
->lpstrInitialDir
;
261 ofn
->lpstrInitialDir
= MemAlloc(MAX_PATH
);
262 GetCurrentDirectoryA(MAX_PATH
,(LPSTR
)ofn
->lpstrInitialDir
);
265 /* Initialise the dialog property */
266 fodInfos
->DlgInfos
.dwDlgProp
= 0;
267 fodInfos
->DlgInfos
.hwndCustomDlg
= (HWND
)NULL
;
272 ret
= GetFileName95(fodInfos
);
275 fodInfos
->DlgInfos
.dwDlgProp
|= FODPROP_SAVEDLG
;
276 ret
= GetFileName95(fodInfos
);
284 MemFree((LPVOID
)(ofn
->lpstrInitialDir
));
285 ofn
->lpstrInitialDir
= lpstrInitialDir
;
288 ofn
->Flags
= dwFlags
;
289 ofn
->hInstance
= hInstance
;
290 MemFree((LPVOID
)(fodInfos
));
294 /***********************************************************************
297 * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
298 * Call GetFileName95 with this structure and clean the memory.
300 * IN : The OPENFILENAMEW initialisation structure passed to
301 * GetOpenFileNameW win api function (see filedlg.c)
304 * some more strings are needing to be convertet AtoW
306 BOOL WINAPI
GetFileDialog95W(LPOPENFILENAMEW ofn
,UINT iDlgType
)
309 FileOpenDlgInfos
*fodInfos
;
311 LPCSTR lpstrFilter
= NULL
;
312 LPSTR lpstrCustomFilter
= NULL
;
313 LPWSTR lpstrFile
= NULL
;
316 /* Initialise FileOpenDlgInfos structure*/
317 fodInfos
= (FileOpenDlgInfos
*)MemAlloc(sizeof(FileOpenDlgInfos
));
318 ZeroMemory(fodInfos
, sizeof(FileOpenDlgInfos
));
320 /* Pass in the original ofn */
321 fodInfos
->ofnInfos
= (LPOPENFILENAMEA
) ofn
;
324 hInstance
= fodInfos
->ofnInfos
->hInstance
;
325 fodInfos
->ofnInfos
->hInstance
= MapHModuleLS(ofn
->hInstance
);
327 /* Save lpstrFilter */
328 if (ofn
->lpstrFilter
)
334 lpstrFilter
= fodInfos
->ofnInfos
->lpstrFilter
;
336 /* filter is a list... title\0ext\0......\0\0 */
337 s
= (LPWSTR
)ofn
->lpstrFilter
;
342 n
= s
- ofn
->lpstrFilter
; /* already divides by 2. ptr magic */
343 x
= y
= (LPSTR
)MemAlloc(n
);
344 s
= (LPWSTR
)ofn
->lpstrFilter
;
351 fodInfos
->ofnInfos
->lpstrFilter
= (LPSTR
)y
;
353 /* Save lpstrCustomFilter */
354 if (ofn
->lpstrCustomFilter
)
360 lpstrCustomFilter
= fodInfos
->ofnInfos
->lpstrCustomFilter
;
361 /* filter is a list... title\0ext\0......\0\0 */
362 s
= (LPWSTR
)ofn
->lpstrCustomFilter
;
366 n
= s
- ofn
->lpstrCustomFilter
;
367 x
= y
= (LPSTR
)MemAlloc(n
);
368 s
= (LPWSTR
)ofn
->lpstrCustomFilter
;
375 fodInfos
->ofnInfos
->lpstrCustomFilter
= (LPSTR
)y
;
379 dwFlags
= fodInfos
->ofnInfos
->Flags
;
380 fodInfos
->ofnInfos
->Flags
= ofn
->Flags
|OFN_WINE
|OFN_UNICODE
;
382 /* Initialise the dialog property */
383 fodInfos
->DlgInfos
.dwDlgProp
= 0;
385 /* allocate ansi filename buffer */
386 lpstrFile
= ofn
->lpstrFile
;
387 ofn
->lpstrFile
= MemAlloc(ofn
->nMaxFile
);
392 ret
= GetFileName95(fodInfos
);
395 fodInfos
->DlgInfos
.dwDlgProp
|= FODPROP_SAVEDLG
;
396 ret
= GetFileName95(fodInfos
);
404 fodInfos
->ofnInfos
->Flags
= dwFlags
;
406 /* Restore lpstrFilter */
407 if (fodInfos
->ofnInfos
->lpstrFilter
)
409 MemFree((LPVOID
)(fodInfos
->ofnInfos
->lpstrFilter
));
410 fodInfos
->ofnInfos
->lpstrFilter
= lpstrFilter
;
412 if (fodInfos
->ofnInfos
->lpstrCustomFilter
)
414 MemFree((LPVOID
)(fodInfos
->ofnInfos
->lpstrCustomFilter
));
415 fodInfos
->ofnInfos
->lpstrCustomFilter
= lpstrCustomFilter
;
418 /* Restore hInstance */
419 fodInfos
->ofnInfos
->hInstance
= hInstance
;
420 MemFree((LPVOID
)(fodInfos
));
423 lstrcpynAtoW(lpstrFile
, (LPCSTR
)ofn
->lpstrFile
, ofn
->nMaxFile
);
424 MemFree(ofn
->lpstrFile
);
425 ofn
->lpstrFile
= lpstrFile
;
430 void ArrangeCtrlPositions( HWND hwndChildDlg
, HWND hwndParentDlg
)
433 HWND hwndChild
,hwndStc32
;
434 RECT rectParent
, rectChild
, rectCtrl
, rectStc32
, rectTemp
;
436 POINT ptParentClient
;
438 ptMoveCtl
.x
= ptMoveCtl
.y
= 0;
439 hwndStc32
=GetDlgItem(hwndChildDlg
,stc32
);
440 GetClientRect(hwndParentDlg
,&rectParent
);
441 GetClientRect(hwndChildDlg
,&rectChild
);
444 GetWindowRect(hwndStc32
,&rectStc32
);
445 MapWindowPoints(0, hwndChildDlg
,(LPPOINT
)&rectStc32
,2);
446 CopyRect(&rectTemp
,&rectStc32
);
448 SetRect(&rectStc32
,rectStc32
.left
,rectStc32
.top
,rectStc32
.left
+ (rectParent
.right
-rectParent
.left
),rectStc32
.top
+(rectParent
.bottom
-rectParent
.top
));
449 SetWindowPos(hwndStc32
,0,rectStc32
.left
,rectStc32
.top
,rectStc32
.right
-rectStc32
.left
,rectStc32
.bottom
-rectStc32
.top
,SWP_NOMOVE
|SWP_NOZORDER
| SWP_NOACTIVATE
);
451 if(rectStc32
.right
< rectTemp
.right
)
453 ptParentClient
.x
= max((rectParent
.right
-rectParent
.left
),(rectChild
.right
-rectChild
.left
));
458 ptMoveCtl
.x
= (rectStc32
.right
- rectTemp
.right
);
459 ptParentClient
.x
= max((rectParent
.right
-rectParent
.left
),((rectChild
.right
-rectChild
.left
)+rectStc32
.right
-rectTemp
.right
));
461 if(rectStc32
.bottom
< rectTemp
.bottom
)
463 ptParentClient
.y
= max((rectParent
.bottom
-rectParent
.top
),(rectChild
.bottom
-rectChild
.top
));
468 ptMoveCtl
.y
= (rectStc32
.bottom
- rectTemp
.bottom
);
469 ptParentClient
.y
= max((rectParent
.bottom
-rectParent
.top
),((rectChild
.bottom
-rectChild
.top
)+rectStc32
.bottom
-rectTemp
.bottom
));
474 if( (GetWindow(hwndChildDlg
,GW_CHILD
)) == (HWND
) NULL
)
476 SetRectEmpty(&rectTemp
);
477 ptParentClient
.x
= max((rectParent
.right
-rectParent
.left
),(rectChild
.right
-rectChild
.left
));
478 ptParentClient
.y
= (rectParent
.bottom
-rectParent
.top
) + (rectChild
.bottom
-rectChild
.top
);
479 ptMoveCtl
.y
= rectParent
.bottom
-rectParent
.top
;
482 SetRect(&rectParent
,rectParent
.left
,rectParent
.top
,rectParent
.left
+ptParentClient
.x
,rectParent
.top
+ptParentClient
.y
);
483 AdjustWindowRectEx( &rectParent
,GetWindowLongA(hwndParentDlg
,GWL_STYLE
),FALSE
,GetWindowLongA(hwndParentDlg
,GWL_EXSTYLE
));
485 SetWindowPos(hwndChildDlg
, 0, 0,0, ptParentClient
.x
,ptParentClient
.y
,
487 SetWindowPos(hwndParentDlg
, 0, rectParent
.left
,rectParent
.top
, (rectParent
.right
- rectParent
.left
),
488 (rectParent
.bottom
-rectParent
.top
),SWP_NOMOVE
| SWP_NOZORDER
);
490 hwndChild
= GetWindow(hwndChildDlg
,GW_CHILD
);
493 GetWindowRect(hwndStc32
,&rectStc32
);
494 MapWindowPoints( 0, hwndChildDlg
,(LPPOINT
)&rectStc32
,2);
497 SetRect(&rectStc32
,0,0,0,0);
503 if(hwndChild
!= hwndStc32
)
505 if (GetWindowLongA( hwndChild
, GWL_STYLE
) & WS_MAXIMIZE
)
507 GetWindowRect(hwndChild
,&rectCtrl
);
508 MapWindowPoints( 0, hwndParentDlg
,(LPPOINT
)&rectCtrl
,2);
511 Check the initial position of the controls relative to the initial
512 position and size of stc32 (before it is expanded).
514 if (rectCtrl
.left
>= rectTemp
.right
&& rectCtrl
.top
>= rectTemp
.bottom
)
516 rectCtrl
.left
+= ptMoveCtl
.x
;
517 rectCtrl
.top
+= ptMoveCtl
.y
;
519 else if (rectCtrl
.left
>= rectTemp
.right
)
520 rectCtrl
.left
+= ptMoveCtl
.x
;
521 else if (rectCtrl
.top
>= rectTemp
.bottom
)
522 rectCtrl
.top
+= ptMoveCtl
.y
;
524 SetWindowPos( hwndChild
, 0, rectCtrl
.left
, rectCtrl
.top
,
525 rectCtrl
.right
-rectCtrl
.left
,rectCtrl
.bottom
-rectCtrl
.top
,
526 SWP_NOSIZE
| SWP_NOZORDER
);
529 while ((hwndChild
=GetWindow( hwndChild
, GW_HWNDNEXT
)) != (HWND
)NULL
);
531 hwndChild
= GetWindow(hwndParentDlg
,GW_CHILD
);
535 GetWindowRect(hwndStc32
,&rectStc32
);
536 MapWindowPoints( 0, hwndChildDlg
,(LPPOINT
)&rectStc32
,2);
537 ptMoveCtl
.x
= rectStc32
.left
- 0;
538 ptMoveCtl
.y
= rectStc32
.top
- 0;
543 if(hwndChild
!= hwndChildDlg
)
546 if (GetWindowLongA( hwndChild
, GWL_STYLE
) & WS_MAXIMIZE
)
548 GetWindowRect(hwndChild
,&rectCtrl
);
549 MapWindowPoints( 0, hwndParentDlg
,(LPPOINT
)&rectCtrl
,2);
551 rectCtrl
.left
+= ptMoveCtl
.x
;
552 rectCtrl
.top
+= ptMoveCtl
.y
;
554 SetWindowPos( hwndChild
, 0, rectCtrl
.left
, rectCtrl
.top
,
555 rectCtrl
.right
-rectCtrl
.left
,rectCtrl
.bottom
-rectCtrl
.top
,
556 SWP_NOSIZE
|SWP_NOZORDER
);
559 while ((hwndChild
=GetWindow( hwndChild
, GW_HWNDNEXT
)) != (HWND
)NULL
);
566 HRESULT WINAPI
FileOpenDlgProcUserTemplate(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
568 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(GetParent(hwnd
),FileOpenDlgInfosStr
);
573 fodInfos
= (FileOpenDlgInfos
*)lParam
;
574 lParam
= (LPARAM
) fodInfos
->ofnInfos
;
575 ArrangeCtrlPositions(hwnd
,GetParent(hwnd
));
576 if(fodInfos
&& (fodInfos
->ofnInfos
->Flags
& OFN_ENABLEHOOK
) && fodInfos
->ofnInfos
->lpfnHook
)
577 return CallWindowProcA((WNDPROC
)fodInfos
->ofnInfos
->lpfnHook
,hwnd
,uMsg
,wParam
,lParam
);
581 if(fodInfos
&& (fodInfos
->ofnInfos
->Flags
& OFN_ENABLEHOOK
) && fodInfos
->ofnInfos
->lpfnHook
)
582 return CallWindowProcA((WNDPROC
)fodInfos
->ofnInfos
->lpfnHook
,hwnd
,uMsg
,wParam
,lParam
);
583 return DefWindowProcA(hwnd
,uMsg
,wParam
,lParam
);
586 HWND
CreateTemplateDialog(FileOpenDlgInfos
*fodInfos
,HWND hwnd
)
592 if (fodInfos
->ofnInfos
->Flags
& OFN_ENABLETEMPLATE
|| fodInfos
->ofnInfos
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
594 if (fodInfos
->ofnInfos
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
596 if( !(template = LockResource( fodInfos
->ofnInfos
->hInstance
)))
598 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
605 if (!(hRes
= FindResourceA(MapHModuleSL(fodInfos
->ofnInfos
->hInstance
),
606 (fodInfos
->ofnInfos
->lpTemplateName
), RT_DIALOGA
)))
608 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
611 if (!(hDlgTmpl
= LoadResource( MapHModuleSL(fodInfos
->ofnInfos
->hInstance
),
613 !(template = LockResource( hDlgTmpl
)))
615 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
620 hChildDlg
= CreateDialogIndirectParamA(fodInfos
->ofnInfos
->hInstance
,template,hwnd
,(DLGPROC
)FileOpenDlgProcUserTemplate
,(LPARAM
)fodInfos
);
623 ShowWindow(hChildDlg
,SW_SHOW
);
627 else if(fodInfos
->ofnInfos
->Flags
& OFN_ENABLEHOOK
&& fodInfos
->ofnInfos
->lpfnHook
)
631 GetClientRect(hwnd
,&rectHwnd
);
632 tmplate
.style
= WS_CHILD
| WS_CLIPSIBLINGS
;
633 tmplate
.dwExtendedStyle
= 0;
637 tmplate
.cx
= rectHwnd
.right
-rectHwnd
.left
;
638 tmplate
.cy
= rectHwnd
.bottom
-rectHwnd
.top
;
640 return CreateDialogIndirectParamA(fodInfos
->ofnInfos
->hInstance
,&tmplate
,hwnd
,(DLGPROC
)FileOpenDlgProcUserTemplate
,(LPARAM
)fodInfos
);
645 /***********************************************************************
646 * SendCustomDlgNotificationMessage
648 * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
651 HRESULT
SendCustomDlgNotificationMessage(HWND hwndParentDlg
, UINT uCode
)
653 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwndParentDlg
,FileOpenDlgInfosStr
);
656 if(fodInfos
->DlgInfos
.hwndCustomDlg
)
659 ofnNotify
.hdr
.hwndFrom
=hwndParentDlg
;
660 ofnNotify
.hdr
.idFrom
=0;
661 ofnNotify
.hdr
.code
= uCode
;
662 ofnNotify
.lpOFN
= fodInfos
->ofnInfos
;
663 return SendMessageA(fodInfos
->DlgInfos
.hwndCustomDlg
,WM_NOTIFY
,0,(LPARAM
)&ofnNotify
);
668 /***********************************************************************
669 * FILEDLG95_HandleCustomDialogMessages
671 * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
673 HRESULT
FILEDLG95_HandleCustomDialogMessages(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
677 char lpstrPath
[MAX_PATH
];
678 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
679 if(!fodInfos
) return -1;
683 case CDM_GETFILEPATH
:
684 GetDlgItemTextA(hwnd
,IDC_FILENAME
,lpstrPath
, sizeof(lpstrPath
));
685 lpstrFileSpec
= (LPSTR
)COMDLG32_PathFindFileNameA(lpstrPath
);
686 if (lpstrFileSpec
==lpstrPath
)
688 char lpstrCurrentDir
[MAX_PATH
];
689 /* Prepend the current path */
690 COMDLG32_SHGetPathFromIDListA(fodInfos
->ShellInfos
.pidlAbsCurrent
,lpstrCurrentDir
);
691 if ((LPSTR
)lParam
!=NULL
)
692 wsnprintfA((LPSTR
)lParam
,(int)wParam
,"%s\\%s",lpstrCurrentDir
,lpstrPath
);
693 reqSize
=strlen(lpstrCurrentDir
)+1+strlen(lpstrPath
)+1;
697 lstrcpynA((LPSTR
)lParam
,(LPSTR
)lpstrPath
,(int)wParam
);
698 reqSize
=strlen(lpstrPath
);
700 /* return the required buffer size */
703 case CDM_GETFOLDERPATH
:
704 COMDLG32_SHGetPathFromIDListA(fodInfos
->ShellInfos
.pidlAbsCurrent
,lpstrPath
);
705 if ((LPSTR
)lParam
!=NULL
)
706 lstrcpynA((LPSTR
)lParam
,lpstrPath
,(int)wParam
);
707 return strlen(lpstrPath
);
710 reqSize
=GetDlgItemTextA(hwnd
,IDC_FILENAME
,lpstrPath
, sizeof(lpstrPath
));
711 lpstrFileSpec
= (LPSTR
)COMDLG32_PathFindFileNameA(lpstrPath
);
712 if ((LPSTR
)lParam
!=NULL
)
713 lstrcpynA((LPSTR
)lParam
, lpstrFileSpec
, (int)wParam
);
714 return strlen(lpstrFileSpec
);
716 case CDM_SETCONTROLTEXT
:
718 SetDlgItemTextA( hwnd
, (UINT
) wParam
, (LPSTR
) lParam
);
721 case CDM_HIDECONTROL
:
723 FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");
729 /***********************************************************************
732 * File open dialog procedure
734 HRESULT WINAPI
FileOpenDlgProc95(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
739 /* Adds the FileOpenDlgInfos in the property list of the dialog
740 so it will be easily accessible through a GetPropA(...) */
741 SetPropA(hwnd
, FileOpenDlgInfosStr
, (HANDLE
) lParam
);
743 FILEDLG95_OnWMInitDialog(hwnd
, wParam
, lParam
);
744 ((FileOpenDlgInfos
*)lParam
)->DlgInfos
.hwndCustomDlg
=
745 CreateTemplateDialog((FileOpenDlgInfos
*)lParam
,hwnd
);
746 SendCustomDlgNotificationMessage(hwnd
,CDN_INITDONE
);
749 return FILEDLG95_OnWMCommand(hwnd
, wParam
, lParam
);
752 switch(((LPDRAWITEMSTRUCT
)lParam
)->CtlID
)
755 FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT
) lParam
);
761 case WM_GETISHELLBROWSER
:
762 return FILEDLG95_OnWMGetIShellBrowser(hwnd
);
765 RemovePropA(hwnd
, FileOpenDlgInfosStr
);
770 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
773 /* set up the button tooltips strings */
774 if(TTN_GETDISPINFOA
== lpnmh
->code
)
776 LPNMTTDISPINFOA lpdi
= (LPNMTTDISPINFOA
)lParam
;
777 switch(lpnmh
->idFrom
)
779 /* Up folder button */
780 case FCIDM_TB_UPFOLDER
:
781 stringId
= IDS_UPFOLDER
;
783 /* New folder button */
784 case FCIDM_TB_NEWFOLDER
:
785 stringId
= IDS_NEWFOLDER
;
787 /* List option button */
788 case FCIDM_TB_SMALLICON
:
789 stringId
= IDS_LISTVIEW
;
791 /* Details option button */
792 case FCIDM_TB_REPORTVIEW
:
793 stringId
= IDS_REPORTVIEW
;
796 case FCIDM_TB_DESKTOP
:
797 stringId
= IDS_TODESKTOP
;
802 lpdi
->hinst
= COMMDLG_hInstance32
;
803 lpdi
->lpszText
= (LPSTR
) stringId
;
808 if(uMsg
>= CDM_FIRST
&& uMsg
<= CDM_LAST
)
809 return FILEDLG95_HandleCustomDialogMessages(hwnd
, uMsg
, wParam
, lParam
);
814 /***********************************************************************
815 * FILEDLG95_OnWMInitDialog
817 * WM_INITDIALOG message handler
819 static LRESULT
FILEDLG95_OnWMInitDialog(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
821 LPITEMIDLIST pidlItemId
;
822 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) lParam
;
824 TRACE("dir=%s file=%s\n",
825 fodInfos
->ofnInfos
->lpstrInitialDir
, fodInfos
->ofnInfos
->lpstrFile
);
827 /* Get the initial directory pidl */
829 if(!(pidlItemId
= GetPidlFromName(fodInfos
->Shell
.FOIShellFolder
,fodInfos
->ofnInfos
->lpstrInitialDir
)))
833 GetCurrentDirectoryA(MAX_PATH
,path
);
834 pidlItemId
= GetPidlFromName(fodInfos
->Shell
.FOIShellFolder
, path
);
838 /* Initialise shell objects */
839 FILEDLG95_SHELL_Init(hwnd
);
841 /* Initialise dialog UI */
842 FILEDLG95_InitUI(hwnd
);
844 /* Initialize the Look In combo box*/
845 FILEDLG95_LOOKIN_Init(fodInfos
->DlgInfos
.hwndLookInCB
);
847 /* Initialize the filter combo box */
848 FILEDLG95_FILETYPE_Init(hwnd
);
850 /* Browse to the initial directory */
851 IShellBrowser_BrowseObject(fodInfos
->Shell
.FOIShellBrowser
,pidlItemId
, SBSP_ABSOLUTE
);
853 /* Free pidlItem memory */
854 COMDLG32_SHFree(pidlItemId
);
858 /***********************************************************************
861 * Regroups all the cleaning functions of the filedlg
863 void FILEDLG95_Clean(HWND hwnd
)
865 FILEDLG95_FILETYPE_Clean(hwnd
);
866 FILEDLG95_LOOKIN_Clean(hwnd
);
867 FILEDLG95_SHELL_Clean(hwnd
);
869 /***********************************************************************
870 * FILEDLG95_OnWMCommand
872 * WM_COMMAND message handler
874 static LRESULT
FILEDLG95_OnWMCommand(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
876 WORD wNotifyCode
= HIWORD(wParam
); /* notification code */
877 WORD wID
= LOWORD(wParam
); /* item, control, or accelerator identifier */
878 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
884 if(FILEDLG95_OnOpen(hwnd
))
885 SendCustomDlgNotificationMessage(hwnd
,CDN_FILEOK
);
889 FILEDLG95_Clean(hwnd
);
890 EndDialog(hwnd
, FALSE
);
892 /* Filetype combo box */
894 FILEDLG95_FILETYPE_OnCommand(hwnd
,wNotifyCode
);
896 /* LookIn combo box */
898 FILEDLG95_LOOKIN_OnCommand(hwnd
,wNotifyCode
);
901 /* --- toolbar --- */
902 /* Up folder button */
903 case FCIDM_TB_UPFOLDER
:
904 FILEDLG95_SHELL_UpFolder(hwnd
);
906 /* New folder button */
907 case FCIDM_TB_NEWFOLDER
:
908 FILEDLG95_SHELL_ExecuteCommand(hwnd
,CMDSTR_NEWFOLDER
);
910 /* List option button */
911 case FCIDM_TB_SMALLICON
:
912 FILEDLG95_SHELL_ExecuteCommand(hwnd
,CMDSTR_VIEWLIST
);
914 /* Details option button */
915 case FCIDM_TB_REPORTVIEW
:
916 FILEDLG95_SHELL_ExecuteCommand(hwnd
,CMDSTR_VIEWDETAILS
);
918 /* Details option button */
919 case FCIDM_TB_DESKTOP
:
920 FILEDLG95_SHELL_BrowseToDesktop(hwnd
);
927 /* Do not use the listview selection anymore */
928 fodInfos
->DlgInfos
.dwDlgProp
&= ~FODPROP_USEVIEW
;
932 /***********************************************************************
933 * FILEDLG95_OnWMGetIShellBrowser
935 * WM_GETISHELLBROWSER message handler
937 static LRESULT
FILEDLG95_OnWMGetIShellBrowser(HWND hwnd
)
940 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
944 SetWindowLongA(hwnd
,DWL_MSGRESULT
,(LONG
)fodInfos
->Shell
.FOIShellBrowser
);
950 /***********************************************************************
954 static LRESULT
FILEDLG95_InitUI(HWND hwnd
)
958 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
, {0, 0}, 0, 0 },
959 {VIEW_PARENTFOLDER
, FCIDM_TB_UPFOLDER
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
, {0, 0}, 0, 0 },
960 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
, {0, 0}, 0, 0 },
961 {VIEW_NEWFOLDER
+1, FCIDM_TB_DESKTOP
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
, {0, 0}, 0, 0 },
962 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
, {0, 0}, 0, 0 },
963 {VIEW_NEWFOLDER
, FCIDM_TB_NEWFOLDER
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
, {0, 0}, 0, 0 },
964 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
, {0, 0}, 0, 0 },
965 {VIEW_LIST
, FCIDM_TB_SMALLICON
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
, {0, 0}, 0, 0 },
966 {VIEW_DETAILS
, FCIDM_TB_REPORTVIEW
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
, {0, 0}, 0, 0 },
970 { HINST_COMMCTRL
, IDB_VIEW_SMALL_COLOR
},
971 { COMDLG32_hInstance
, 800 } // desktop icon
976 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
978 TRACE("%p\n", fodInfos
);
980 /* Get the hwnd of the controls */
981 fodInfos
->DlgInfos
.hwndFileName
= GetDlgItem(hwnd
,IDC_FILENAME
);
982 fodInfos
->DlgInfos
.hwndFileTypeCB
= GetDlgItem(hwnd
,IDC_FILETYPE
);
983 fodInfos
->DlgInfos
.hwndLookInCB
= GetDlgItem(hwnd
,IDC_LOOKIN
);
985 /* construct the toolbar */
986 GetWindowRect(GetDlgItem(hwnd
,IDC_TOOLBARSTATIC
),&rectTB
);
987 MapWindowPoints( 0, hwnd
,(LPPOINT
)&rectTB
,2);
989 fodInfos
->DlgInfos
.hwndTB
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, (LPSTR
) NULL
,
990 WS_CHILD
| WS_GROUP
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
| CCS_NORESIZE
,
992 hwnd
, (HMENU
) IDC_TOOLBAR
, COMMDLG_hInstance32
, NULL
);
994 SetWindowPos(fodInfos
->DlgInfos
.hwndTB
, 0,
995 rectTB
.left
,rectTB
.top
, rectTB
.right
-rectTB
.left
, rectTB
.bottom
-rectTB
.top
,
996 SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
998 SendMessageA(fodInfos
->DlgInfos
.hwndTB
, TB_BUTTONSTRUCTSIZE
, (WPARAM
) sizeof(TBBUTTON
), 0);
1000 /* fixme: use TB_LOADIMAGES when implemented */
1001 /* SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/
1002 SendMessageA(fodInfos
->DlgInfos
.hwndTB
, TB_ADDBITMAP
, (WPARAM
) 12, (LPARAM
) &tba
[0]);
1003 SendMessageA(fodInfos
->DlgInfos
.hwndTB
, TB_ADDBITMAP
, (WPARAM
) 1, (LPARAM
) &tba
[1]);
1005 SendMessageA(fodInfos
->DlgInfos
.hwndTB
, TB_ADDBUTTONSA
, (WPARAM
) 9,(LPARAM
) &tbb
);
1006 SendMessageA(fodInfos
->DlgInfos
.hwndTB
, TB_AUTOSIZE
, 0, 0);
1008 /* Set the window text with the text specified in the OPENFILENAME structure */
1009 if(fodInfos
->ofnInfos
->lpstrTitle
)
1011 SetWindowTextA(hwnd
,fodInfos
->ofnInfos
->lpstrTitle
);
1013 else if (fodInfos
->DlgInfos
.dwDlgProp
& FODPROP_SAVEDLG
)
1015 SetWindowTextA(hwnd
,"Save");
1018 /* Initialise the file name edit control */
1019 if(fodInfos
->ofnInfos
->lpstrFile
)
1021 LPSTR lpstrFile
= COMDLG32_PathFindFileNameA(fodInfos
->ofnInfos
->lpstrFile
);
1022 SetDlgItemTextA(hwnd
, IDC_FILENAME
, lpstrFile
);
1025 /* Must the open as read only check box be checked ?*/
1026 if(fodInfos
->ofnInfos
->Flags
& OFN_READONLY
)
1028 SendDlgItemMessageA(hwnd
,IDC_OPENREADONLY
,BM_SETCHECK
,(WPARAM
)TRUE
,0);
1031 /* Must the open as read only check box be hid ?*/
1032 if(fodInfos
->ofnInfos
->Flags
& OFN_HIDEREADONLY
)
1034 ShowWindow(GetDlgItem(hwnd
,IDC_OPENREADONLY
),SW_HIDE
);
1037 /* Must the help button be hid ?*/
1038 if (!(fodInfos
->ofnInfos
->Flags
& OFN_SHOWHELP
))
1040 ShowWindow(GetDlgItem(hwnd
, pshHelp
), SW_HIDE
);
1043 /* Resize the height, if open as read only checkbox ad help button
1045 if ( (fodInfos
->ofnInfos
->Flags
& OFN_HIDEREADONLY
) &&
1046 (!(fodInfos
->ofnInfos
->Flags
& OFN_SHOWHELP
)) )
1048 RECT rectDlg
, rectHelp
, rectCancel
;
1049 GetWindowRect(hwnd
, &rectDlg
);
1050 GetWindowRect(GetDlgItem(hwnd
, pshHelp
), &rectHelp
);
1051 GetWindowRect(GetDlgItem(hwnd
, IDCANCEL
), &rectCancel
);
1052 /* subtract the height of the help button plus the space between
1053 the help button and the cancel button to the height of the dialog */
1054 SetWindowPos(hwnd
, 0, 0, 0, rectDlg
.right
-rectDlg
.left
,
1055 (rectDlg
.bottom
-rectDlg
.top
) - (rectHelp
.bottom
- rectCancel
.bottom
),
1056 SWP_NOACTIVATE
|SWP_NOMOVE
|SWP_NOZORDER
);
1059 /* change Open to Save FIXME: use resources */
1060 if (fodInfos
->DlgInfos
.dwDlgProp
& FODPROP_SAVEDLG
)
1062 SetDlgItemTextA(hwnd
,IDOK
,"&Save");
1063 SetDlgItemTextA(hwnd
,IDC_LOOKINSTATIC
,"Save &in");
1068 /***********************************************************************
1069 * FILEDLG95_OnOpenMultipleFiles
1071 * Handles the opening of multiple files.
1074 * check destination buffer size
1076 BOOL
FILEDLG95_OnOpenMultipleFiles(HWND hwnd
, LPSTR lpstrFileList
, UINT nFileCount
, UINT sizeUsed
)
1078 CHAR lpstrPathSpec
[MAX_PATH
] = "";
1080 UINT nCount
, nSizePath
;
1081 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1085 lpstrFile
= fodInfos
->ofnInfos
->lpstrFile
;
1086 lpstrFile
[0] = '\0';
1088 COMDLG32_SHGetPathFromIDListA( fodInfos
->ShellInfos
.pidlAbsCurrent
, lpstrPathSpec
);
1090 if ( !(fodInfos
->ofnInfos
->Flags
& OFN_NOVALIDATE
) &&
1091 ( fodInfos
->ofnInfos
->Flags
& OFN_FILEMUSTEXIST
))
1093 LPSTR lpstrTemp
= lpstrFileList
;
1095 for ( nCount
= 0; nCount
< nFileCount
; nCount
++ )
1099 pidl
= GetPidlFromName(fodInfos
->Shell
.FOIShellFolder
, lpstrTemp
);
1102 CHAR lpstrNotFound
[100];
1106 LoadStringA(COMMDLG_hInstance32
, IDS_FILENOTFOUND
, lpstrNotFound
, 100);
1107 LoadStringA(COMMDLG_hInstance32
, IDS_VERIFYFILE
, lpstrMsg
, 100);
1109 strcpy(tmp
, lpstrTemp
);
1111 strcat(tmp
, lpstrNotFound
);
1113 strcat(tmp
, lpstrMsg
);
1115 MessageBoxA(hwnd
, tmp
, fodInfos
->ofnInfos
->lpstrTitle
, MB_OK
| MB_ICONEXCLAMATION
);
1119 lpstrTemp
+= strlen(lpstrFileList
) + 1;
1120 COMDLG32_SHFree(pidl
);
1124 nSizePath
= lstrlenA(lpstrPathSpec
);
1125 lstrcpyA( lpstrFile
, lpstrPathSpec
);
1126 memcpy( lpstrFile
+ nSizePath
+ 1, lpstrFileList
, sizeUsed
);
1128 fodInfos
->ofnInfos
->nFileOffset
= nSizePath
+ 1;
1129 fodInfos
->ofnInfos
->nFileExtension
= 0;
1131 /* clean and exit */
1132 FILEDLG95_Clean(hwnd
);
1133 return EndDialog(hwnd
,TRUE
);
1136 /***********************************************************************
1139 * Ok button WM_COMMAND message handler
1141 * If the function succeeds, the return value is nonzero.
1143 #define ONOPEN_BROWSE 1
1144 #define ONOPEN_OPEN 2
1145 #define ONOPEN_SEARCH 3
1146 static void FILEDLG95_OnOpenMessage(HWND hwnd
, int idCaption
, int idText
)
1148 char strMsgTitle
[MAX_PATH
];
1149 char strMsgText
[MAX_PATH
];
1151 LoadStringA(COMDLG32_hInstance
, idCaption
, strMsgTitle
, sizeof(strMsgTitle
));
1153 strMsgTitle
[0] = '\0';
1154 LoadStringA(COMDLG32_hInstance
, idText
, strMsgText
, sizeof(strMsgText
));
1155 MessageBoxA(hwnd
,strMsgText
, strMsgTitle
, MB_OK
| MB_ICONHAND
);
1158 BOOL
FILEDLG95_OnOpen(HWND hwnd
)
1160 char * lpstrFileList
;
1161 UINT nFileCount
= 0;
1164 char lpstrPathAndFile
[MAX_PATH
];
1165 char lpstrTemp
[MAX_PATH
];
1166 LPSHELLFOLDER lpsf
= NULL
;
1168 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1171 TRACE("hwnd=0x%04x\n", hwnd
);
1173 /* get the files from the edit control */
1174 nFileCount
= FILEDLG95_FILENAME_GetFileNames(hwnd
, &lpstrFileList
, &sizeUsed
);
1176 /* try if the user selected a folder in the shellview */
1179 if (BrowseSelectedFolder(hwnd
))
1185 ret
= FILEDLG95_OnOpenMultipleFiles(hwnd
, lpstrFileList
, nFileCount
, sizeUsed
);
1189 TRACE("count=%u len=%u file=%s\n", nFileCount
, sizeUsed
, lpstrFileList
);
1192 Step 1: Build a complete path name from the current folder and
1193 the filename or path in the edit box.
1195 - the path in the edit box is a root path
1196 (with or without drive letter)
1197 - the edit box contains ".." (or a path with ".." in it)
1200 /* Get the current directory name */
1201 if (!COMDLG32_SHGetPathFromIDListA(fodInfos
->ShellInfos
.pidlAbsCurrent
, lpstrPathAndFile
))
1203 /* we are in a special folder, default to desktop */
1204 if(FAILED(COMDLG32_SHGetFolderPathA(hwnd
, CSIDL_DESKTOPDIRECTORY
|CSIDL_FLAG_CREATE
, NULL
, 0, lpstrPathAndFile
)))
1207 GetCurrentDirectoryA(MAX_PATH
, lpstrPathAndFile
);
1210 COMDLG32_PathAddBackslashA(lpstrPathAndFile
);
1212 TRACE("current directory=%s\n", lpstrPathAndFile
);
1214 /* if the user specifyed a fully qualified path use it */
1215 if(COMDLG32_PathIsRelativeA(lpstrFileList
))
1217 strcat(lpstrPathAndFile
, lpstrFileList
);
1221 /* does the path have a drive letter? */
1222 if (COMDLG32_PathGetDriveNumberA(lpstrFileList
) == -1)
1223 strcpy(lpstrPathAndFile
+2, lpstrFileList
);
1225 strcpy(lpstrPathAndFile
, lpstrFileList
);
1228 /* resolve "." and ".." */
1229 COMDLG32_PathCanonicalizeA(lpstrTemp
, lpstrPathAndFile
);
1230 strcpy(lpstrPathAndFile
, lpstrTemp
);
1231 TRACE("canon=%s\n", lpstrPathAndFile
);
1233 MemFree(lpstrFileList
);
1236 Step 2: here we have a cleaned up path
1238 We have to parse the path step by step to see if we have to browse
1239 to a folder if the path points to a directory or the last
1240 valid element is a directory.
1243 lpstrPathAndFile: cleaned up path
1246 nOpenAction
= ONOPEN_BROWSE
;
1248 /* dont apply any checks with OFN_NOVALIDATE */
1249 if(!(fodInfos
->ofnInfos
->Flags
& OFN_NOVALIDATE
))
1251 LPSTR lpszTemp
, lpszTemp1
;
1252 LPITEMIDLIST pidl
= NULL
;
1254 /* check for invalid chars */
1255 if(strpbrk(lpstrPathAndFile
+3, "/:<>|") != NULL
)
1257 FILEDLG95_OnOpenMessage(hwnd
, IDS_INVALID_FILENAME_TITLE
, IDS_INVALID_FILENAME
);
1262 if (FAILED (COMDLG32_SHGetDesktopFolder(&lpsf
))) return FALSE
;
1264 lpszTemp1
= lpszTemp
= lpstrPathAndFile
;
1267 LPSHELLFOLDER lpsfChild
;
1268 WCHAR lpwstrTemp
[MAX_PATH
];
1269 DWORD dwEaten
, dwAttributes
;
1271 lpszTemp
= COMDLG32_PathFindNextComponentA(lpszTemp
);
1273 lstrcpynAtoW(lpwstrTemp
, lpszTemp1
, lpszTemp
- lpszTemp1
);
1276 lstrcpyAtoW(lpwstrTemp
, lpszTemp1
); /* last element */
1277 if(strpbrk(lpszTemp1
, "*?") != NULL
)
1279 nOpenAction
= ONOPEN_SEARCH
;
1283 lpszTemp1
= lpszTemp
;
1285 TRACE("parse now=%s next=%s sf=%p\n",debugstr_w(lpwstrTemp
), debugstr_a(lpszTemp
), lpsf
);
1287 if(lstrlenW(lpwstrTemp
)==2) COMDLG32_PathAddBackslashW(lpwstrTemp
);
1289 dwAttributes
= SFGAO_FOLDER
;
1290 if(FAILED(IShellFolder_ParseDisplayName(lpsf
, hwnd
, NULL
, lpwstrTemp
, &dwEaten
, &pidl
, &dwAttributes
)))
1292 if(*lpszTemp
) /* points to trailing null for last path element */
1294 if(fodInfos
->ofnInfos
->Flags
& OFN_PATHMUSTEXIST
)
1296 FILEDLG95_OnOpenMessage(hwnd
, 0, IDS_PATHNOTEXISTING
);
1302 if(fodInfos
->ofnInfos
->Flags
& OFN_FILEMUSTEXIST
)
1304 FILEDLG95_OnOpenMessage(hwnd
, 0, IDS_FILENOTEXISTING
);
1308 /* change to the current folder */
1309 nOpenAction
= ONOPEN_OPEN
;
1314 /* the path component is valid */
1315 TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes
, pidl
);
1316 if(dwAttributes
& SFGAO_FOLDER
)
1318 if(FAILED(IShellFolder_BindToObject(lpsf
, pidl
, 0, &IID_IShellFolder
, (LPVOID
*)&lpsfChild
)))
1320 ERR("bind to failed\n"); /* should not fail */
1323 IShellFolder_Release(lpsf
);
1331 /* end dialog, return value */
1332 nOpenAction
= ONOPEN_OPEN
;
1335 COMDLG32_SHFree(pidl
);
1339 if(pidl
) COMDLG32_SHFree(pidl
);
1342 /* path is valid, clean the edit box */
1343 SetDlgItemTextA(hwnd
,IDC_FILENAME
,"");
1346 Step 3: here we have a cleaned up and validated path
1349 lpsf: ShellFolder bound to the rightmost valid path component
1350 lpstrPathAndFile: cleaned up path
1351 nOpenAction: action to do
1353 TRACE("end validate sf=%p\n", lpsf
);
1357 case ONOPEN_SEARCH
: /* set the current filter to the file mask and refresh */
1358 TRACE("ONOPEN_SEARCH %s\n", lpstrPathAndFile
);
1361 LPSTR lpszTemp
= COMDLG32_PathFindFileNameA(lpstrPathAndFile
);
1363 /* replace the current filter */
1364 if(fodInfos
->ShellInfos
.lpstrCurrentFilter
)
1365 MemFree((LPVOID
)fodInfos
->ShellInfos
.lpstrCurrentFilter
);
1366 fodInfos
->ShellInfos
.lpstrCurrentFilter
= MemAlloc((strlen(lpszTemp
)+1)*sizeof(WCHAR
));
1367 lstrcpyAtoW(fodInfos
->ShellInfos
.lpstrCurrentFilter
, lpszTemp
);
1369 /* set the filter cb to the extension when possible */
1370 if(-1 < (iPos
= FILEDLG95_FILETYPE_SearchExt(fodInfos
->DlgInfos
.hwndFileTypeCB
, lpszTemp
)))
1371 CBSetCurSel(fodInfos
->DlgInfos
.hwndFileTypeCB
, iPos
);
1374 case ONOPEN_BROWSE
: /* browse to the highest folder we could bind to */
1375 TRACE("ONOPEN_BROWSE\n");
1377 IPersistFolder2
* ppf2
;
1378 if(SUCCEEDED(IShellFolder_QueryInterface( lpsf
, &IID_IPersistFolder2
, (LPVOID
*)&ppf2
)))
1380 LPITEMIDLIST pidlCurrent
;
1381 IPersistFolder2_GetCurFolder(ppf2
, &pidlCurrent
);
1382 IPersistFolder2_Release(ppf2
);
1383 if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent
, fodInfos
->ShellInfos
.pidlAbsCurrent
))
1385 IShellBrowser_BrowseObject(fodInfos
->Shell
.FOIShellBrowser
, pidlCurrent
, SBSP_ABSOLUTE
);
1387 else if( nOpenAction
== ONOPEN_SEARCH
)
1389 IShellView_Refresh(fodInfos
->Shell
.FOIShellView
);
1391 COMDLG32_SHFree(pidlCurrent
);
1396 case ONOPEN_OPEN
: /* fill in the return struct and close the dialog */
1397 TRACE("ONOPEN_OPEN %s\n", lpstrPathAndFile
);
1399 /* add default extension */
1400 if (fodInfos
->ofnInfos
->lpstrDefExt
)
1402 if (! *COMDLG32_PathFindExtensionA(lpstrPathAndFile
))
1404 strcat(lpstrPathAndFile
, ".");
1405 strcat(lpstrPathAndFile
, fodInfos
->ofnInfos
->lpstrDefExt
);
1409 /* Check that size size of the file does not exceed buffer size */
1410 if(strlen(lpstrPathAndFile
) < fodInfos
->ofnInfos
->nMaxFile
)
1414 /* fill destination buffer */
1415 strcpy(fodInfos
->ofnInfos
->lpstrFile
, lpstrPathAndFile
);
1417 /* set filename offset */
1418 lpszTemp
= COMDLG32_PathFindFileNameA(lpstrPathAndFile
);
1419 fodInfos
->ofnInfos
->nFileOffset
= lpszTemp
- lpstrPathAndFile
;
1421 /* set extension offset */
1422 lpszTemp
= COMDLG32_PathFindExtensionA(lpstrPathAndFile
);
1423 fodInfos
->ofnInfos
->nFileExtension
= (*lpszTemp
) ? lpszTemp
- lpstrPathAndFile
+ 1 : 0;
1425 /* set the lpstrFileTitle */
1426 if(fodInfos
->ofnInfos
->lpstrFileTitle
)
1428 LPSTR lpstrFileTitle
= COMDLG32_PathFindFileNameA(lpstrPathAndFile
);
1429 strncpy(fodInfos
->ofnInfos
->lpstrFileTitle
, lpstrFileTitle
, fodInfos
->ofnInfos
->nMaxFileTitle
);
1432 FILEDLG95_Clean(hwnd
);
1433 ret
= EndDialog(hwnd
, TRUE
);
1437 /* FIXME set error FNERR_BUFFERTOSMALL */
1438 FILEDLG95_Clean(hwnd
);
1439 ret
= EndDialog(hwnd
, FALSE
);
1447 if(lpsf
) IShellFolder_Release(lpsf
);
1451 /***********************************************************************
1452 * FILEDLG95_SHELL_Init
1454 * Initialisation of the shell objects
1456 static HRESULT
FILEDLG95_SHELL_Init(HWND hwnd
)
1458 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1463 * Initialisation of the FileOpenDialogInfos structure
1469 fodInfos
->ShellInfos
.hwndOwner
= hwnd
;
1471 /* Disable multi-select if flag not set */
1472 if (!(fodInfos
->ofnInfos
->Flags
& OFN_ALLOWMULTISELECT
))
1474 fodInfos
->ShellInfos
.folderSettings
.fFlags
|= FWF_SINGLESEL
;
1476 fodInfos
->ShellInfos
.folderSettings
.fFlags
|= FWF_AUTOARRANGE
| FWF_ALIGNLEFT
;
1477 fodInfos
->ShellInfos
.folderSettings
.ViewMode
= FVM_LIST
;
1479 GetWindowRect(GetDlgItem(hwnd
,IDC_SHELLSTATIC
),&fodInfos
->ShellInfos
.rectView
);
1480 ScreenToClient(hwnd
,(LPPOINT
)&fodInfos
->ShellInfos
.rectView
.left
);
1481 ScreenToClient(hwnd
,(LPPOINT
)&fodInfos
->ShellInfos
.rectView
.right
);
1483 /* Construct the IShellBrowser interface */
1484 fodInfos
->Shell
.FOIShellBrowser
= IShellBrowserImpl_Construct(hwnd
);
1489 /***********************************************************************
1490 * FILEDLG95_SHELL_ExecuteCommand
1492 * Change the folder option and refresh the view
1493 * If the function succeeds, the return value is nonzero.
1495 static BOOL
FILEDLG95_SHELL_ExecuteCommand(HWND hwnd
, LPCSTR lpVerb
)
1497 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1500 TRACE("(0x%08x,%p)\n", hwnd
, lpVerb
);
1502 if(SUCCEEDED(IShellView_GetItemObject(fodInfos
->Shell
.FOIShellView
,
1507 CMINVOKECOMMANDINFO ci
;
1508 ZeroMemory(&ci
, sizeof(CMINVOKECOMMANDINFO
));
1509 ci
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
1513 IContextMenu_InvokeCommand(pcm
, &ci
);
1514 IContextMenu_Release(pcm
);
1520 /***********************************************************************
1521 * FILEDLG95_SHELL_UpFolder
1523 * Browse to the specified object
1524 * If the function succeeds, the return value is nonzero.
1526 static BOOL
FILEDLG95_SHELL_UpFolder(HWND hwnd
)
1528 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1532 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos
->Shell
.FOIShellBrowser
,
1541 /***********************************************************************
1542 * FILEDLG95_SHELL_BrowseToDesktop
1544 * Browse to the Desktop
1545 * If the function succeeds, the return value is nonzero.
1547 static BOOL
FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd
)
1549 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1555 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP
,&pidl
);
1556 hres
= IShellBrowser_BrowseObject(fodInfos
->Shell
.FOIShellBrowser
, pidl
, SBSP_ABSOLUTE
);
1557 COMDLG32_SHFree(pidl
);
1558 return SUCCEEDED(hres
);
1560 /***********************************************************************
1561 * FILEDLG95_SHELL_Clean
1563 * Cleans the memory used by shell objects
1565 static void FILEDLG95_SHELL_Clean(HWND hwnd
)
1567 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1571 COMDLG32_SHFree(fodInfos
->ShellInfos
.pidlAbsCurrent
);
1573 /* clean Shell interfaces */
1574 IShellView_DestroyViewWindow(fodInfos
->Shell
.FOIShellView
);
1575 IShellView_Release(fodInfos
->Shell
.FOIShellView
);
1576 IShellFolder_Release(fodInfos
->Shell
.FOIShellFolder
);
1577 IShellBrowser_Release(fodInfos
->Shell
.FOIShellBrowser
);
1578 if (fodInfos
->Shell
.FOIDataObject
)
1579 IDataObject_Release(fodInfos
->Shell
.FOIDataObject
);
1582 /***********************************************************************
1583 * FILEDLG95_FILETYPE_Init
1585 * Initialisation of the file type combo box
1587 static HRESULT
FILEDLG95_FILETYPE_Init(HWND hwnd
)
1589 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1593 if(fodInfos
->ofnInfos
->lpstrFilter
)
1595 int nFilters
= 0; /* number of filters */
1597 LPCSTR lpstrPos
= fodInfos
->ofnInfos
->lpstrFilter
;
1601 /* filter is a list... title\0ext\0......\0\0
1602 * Set the combo item text to the title and the item data
1605 LPCSTR lpstrDisplay
;
1609 if(! *lpstrPos
) break; /* end */
1610 lpstrDisplay
= lpstrPos
;
1611 lpstrPos
+= strlen(lpstrPos
) + 1;
1613 /* Copy the extensions */
1614 if (! *lpstrPos
) return E_FAIL
; /* malformed filter */
1615 if (!(lpstrExt
= (LPSTR
) MemAlloc(strlen(lpstrPos
)+1))) return E_FAIL
;
1616 strcpy(lpstrExt
,lpstrPos
);
1617 lpstrPos
+= strlen(lpstrPos
) + 1;
1619 /* Add the item at the end of the combo */
1620 CBAddString(fodInfos
->DlgInfos
.hwndFileTypeCB
, lpstrDisplay
);
1621 CBSetItemDataPtr(fodInfos
->DlgInfos
.hwndFileTypeCB
, nFilters
, lpstrExt
);
1625 * Set the current filter to the one specified
1626 * in the initialisation structure
1627 * FIXME: lpstrCustomFilter not handled at all
1630 /* set default filter index */
1631 if(fodInfos
->ofnInfos
->nFilterIndex
== 0 && fodInfos
->ofnInfos
->lpstrCustomFilter
== NULL
)
1632 fodInfos
->ofnInfos
->nFilterIndex
= 1;
1634 /* First, check to make sure our index isn't out of bounds. */
1635 if ( fodInfos
->ofnInfos
->nFilterIndex
> nFilters
)
1636 fodInfos
->ofnInfos
->nFilterIndex
= nFilters
;
1638 /* Set the current index selection. */
1639 CBSetCurSel(fodInfos
->DlgInfos
.hwndFileTypeCB
, fodInfos
->ofnInfos
->nFilterIndex
-1);
1641 /* Get the corresponding text string from the combo box. */
1642 lpstrFilter
= (LPSTR
) CBGetItemDataPtr(fodInfos
->DlgInfos
.hwndFileTypeCB
,
1643 fodInfos
->ofnInfos
->nFilterIndex
-1);
1645 if ((INT
)lpstrFilter
== CB_ERR
) /* control is empty */
1650 _strlwr(lpstrFilter
); /* lowercase */
1651 fodInfos
->ShellInfos
.lpstrCurrentFilter
= MemAlloc((strlen(lpstrFilter
)+1)*2);
1652 lstrcpyAtoW(fodInfos
->ShellInfos
.lpstrCurrentFilter
, lpstrFilter
);
1658 /***********************************************************************
1659 * FILEDLG95_FILETYPE_OnCommand
1661 * WM_COMMAND of the file type combo box
1662 * If the function succeeds, the return value is nonzero.
1664 static BOOL
FILEDLG95_FILETYPE_OnCommand(HWND hwnd
, WORD wNotifyCode
)
1666 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1674 /* Get the current item of the filetype combo box */
1675 int iItem
= CBGetCurSel(fodInfos
->DlgInfos
.hwndFileTypeCB
);
1677 /* set the current filter index - indexed from 1 */
1678 fodInfos
->ofnInfos
->nFilterIndex
= iItem
+ 1;
1680 /* Set the current filter with the current selection */
1681 if(fodInfos
->ShellInfos
.lpstrCurrentFilter
)
1682 MemFree((LPVOID
)fodInfos
->ShellInfos
.lpstrCurrentFilter
);
1684 lpstrFilter
= (LPSTR
) CBGetItemDataPtr(fodInfos
->DlgInfos
.hwndFileTypeCB
,
1686 if((int)lpstrFilter
!= CB_ERR
)
1688 fodInfos
->ShellInfos
.lpstrCurrentFilter
= MemAlloc((strlen(lpstrFilter
)+1)*2);
1689 lstrcpyAtoW(fodInfos
->ShellInfos
.lpstrCurrentFilter
,_strlwr(lpstrFilter
));
1690 SendCustomDlgNotificationMessage(hwnd
,CDN_TYPECHANGE
);
1693 /* Refresh the actual view to display the included items*/
1694 IShellView_Refresh(fodInfos
->Shell
.FOIShellView
);
1699 /***********************************************************************
1700 * FILEDLG95_FILETYPE_SearchExt
1702 * searches for a extension in the filetype box
1704 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd
,LPCSTR lpstrExt
)
1706 int i
, iCount
= CBGetCount(hwnd
);
1708 TRACE("%s\n", lpstrExt
);
1710 if(iCount
!= CB_ERR
)
1712 for(i
=0;i
<iCount
;i
++)
1714 if(!strcasecmp(lpstrExt
,(LPSTR
)CBGetItemDataPtr(hwnd
,i
)))
1721 /***********************************************************************
1722 * FILEDLG95_FILETYPE_Clean
1724 * Clean the memory used by the filetype combo box
1726 static void FILEDLG95_FILETYPE_Clean(HWND hwnd
)
1728 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1730 int iCount
= CBGetCount(fodInfos
->DlgInfos
.hwndFileTypeCB
);
1734 /* Delete each string of the combo and their associated data */
1735 if(iCount
!= CB_ERR
)
1737 for(iPos
= iCount
-1;iPos
>=0;iPos
--)
1739 MemFree((LPSTR
) CBGetItemDataPtr(fodInfos
->DlgInfos
.hwndFileTypeCB
,iPos
));
1740 CBDeleteString(fodInfos
->DlgInfos
.hwndFileTypeCB
,iPos
);
1743 /* Current filter */
1744 if(fodInfos
->ShellInfos
.lpstrCurrentFilter
)
1745 MemFree(fodInfos
->ShellInfos
.lpstrCurrentFilter
);
1749 /***********************************************************************
1750 * FILEDLG95_LOOKIN_Init
1752 * Initialisation of the look in combo box
1754 static HRESULT
FILEDLG95_LOOKIN_Init(HWND hwndCombo
)
1756 IShellFolder
*psfRoot
, *psfDrives
;
1757 IEnumIDList
*lpeRoot
, *lpeDrives
;
1758 LPITEMIDLIST pidlDrives
, pidlTmp
, pidlTmp1
, pidlAbsTmp
;
1760 LookInInfos
*liInfos
= MemAlloc(sizeof(LookInInfos
));
1764 liInfos
->iMaxIndentation
= 0;
1766 SetPropA(hwndCombo
, LookInInfosStr
, (HANDLE
) liInfos
);
1767 CBSetItemHeight(hwndCombo
,0,GetSystemMetrics(SM_CYSMICON
));
1769 /* Initialise data of Desktop folder */
1770 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP
,&pidlTmp
);
1771 FILEDLG95_LOOKIN_AddItem(hwndCombo
, pidlTmp
,LISTEND
);
1772 COMDLG32_SHFree(pidlTmp
);
1774 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DRIVES
,&pidlDrives
);
1776 COMDLG32_SHGetDesktopFolder(&psfRoot
);
1780 /* enumerate the contents of the desktop */
1781 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot
, hwndCombo
, SHCONTF_FOLDERS
, &lpeRoot
)))
1783 while (S_OK
== IEnumIDList_Next(lpeRoot
, 1, &pidlTmp
, NULL
))
1785 FILEDLG95_LOOKIN_AddItem(hwndCombo
, pidlTmp
,LISTEND
);
1787 /* special handling for CSIDL_DRIVES */
1788 if (COMDLG32_PIDL_ILIsEqual(pidlTmp
, pidlDrives
))
1790 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot
, pidlTmp
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfDrives
)))
1792 /* enumerate the drives */
1793 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives
, hwndCombo
,SHCONTF_FOLDERS
, &lpeDrives
)))
1795 while (S_OK
== IEnumIDList_Next(lpeDrives
, 1, &pidlTmp1
, NULL
))
1797 pidlAbsTmp
= COMDLG32_PIDL_ILCombine(pidlTmp
, pidlTmp1
);
1798 FILEDLG95_LOOKIN_AddItem(hwndCombo
, pidlAbsTmp
,LISTEND
);
1799 COMDLG32_SHFree(pidlAbsTmp
);
1800 COMDLG32_SHFree(pidlTmp1
);
1802 IEnumIDList_Release(lpeDrives
);
1804 IShellFolder_Release(psfDrives
);
1807 COMDLG32_SHFree(pidlTmp
);
1809 IEnumIDList_Release(lpeRoot
);
1813 IShellFolder_Release(psfRoot
);
1814 COMDLG32_SHFree(pidlDrives
);
1818 /***********************************************************************
1819 * FILEDLG95_LOOKIN_DrawItem
1821 * WM_DRAWITEM message handler
1823 static LRESULT
FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct
)
1825 COLORREF crWin
= GetSysColor(COLOR_WINDOW
);
1826 COLORREF crHighLight
= GetSysColor(COLOR_HIGHLIGHT
);
1827 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1831 HIMAGELIST ilItemImage
;
1833 LPSFOLDER tmpFolder
;
1836 LookInInfos
*liInfos
= (LookInInfos
*)GetPropA(pDIStruct
->hwndItem
,LookInInfosStr
);
1840 if(pDIStruct
->itemID
== -1)
1843 if(!(tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(pDIStruct
->hwndItem
,
1844 pDIStruct
->itemID
)))
1848 if(pDIStruct
->itemID
== liInfos
->uSelectedItem
)
1850 ilItemImage
= (HIMAGELIST
) COMDLG32_SHGetFileInfoA ((LPCSTR
) tmpFolder
->pidlItem
,
1853 sizeof (SHFILEINFOA
),
1854 SHGFI_PIDL
| SHGFI_SMALLICON
|
1855 SHGFI_OPENICON
| SHGFI_SYSICONINDEX
|
1856 SHGFI_DISPLAYNAME
);
1860 ilItemImage
= (HIMAGELIST
) COMDLG32_SHGetFileInfoA ((LPCSTR
) tmpFolder
->pidlItem
,
1863 sizeof (SHFILEINFOA
),
1864 SHGFI_PIDL
| SHGFI_SMALLICON
|
1865 SHGFI_SYSICONINDEX
|
1869 /* Is this item selected ?*/
1870 if(pDIStruct
->itemState
& ODS_SELECTED
)
1872 SetTextColor(pDIStruct
->hDC
,(0x00FFFFFF & ~(crText
)));
1873 SetBkColor(pDIStruct
->hDC
,crHighLight
);
1874 FillRect(pDIStruct
->hDC
,&pDIStruct
->rcItem
,(HBRUSH
)crHighLight
);
1878 SetTextColor(pDIStruct
->hDC
,crText
);
1879 SetBkColor(pDIStruct
->hDC
,crWin
);
1880 FillRect(pDIStruct
->hDC
,&pDIStruct
->rcItem
,(HBRUSH
)crWin
);
1883 /* Do not indent item if drawing in the edit of the combo*/
1884 if(pDIStruct
->itemState
& ODS_COMBOBOXEDIT
)
1887 ilItemImage
= (HIMAGELIST
) COMDLG32_SHGetFileInfoA ((LPCSTR
) tmpFolder
->pidlItem
,
1890 sizeof (SHFILEINFOA
),
1891 SHGFI_PIDL
| SHGFI_SMALLICON
| SHGFI_OPENICON
1892 | SHGFI_SYSICONINDEX
| SHGFI_DISPLAYNAME
);
1897 iIndentation
= tmpFolder
->m_iIndent
;
1899 /* Draw text and icon */
1901 /* Initialise the icon display area */
1902 rectIcon
.left
= pDIStruct
->rcItem
.left
+ ICONWIDTH
/2 * iIndentation
;
1903 rectIcon
.top
= pDIStruct
->rcItem
.top
;
1904 rectIcon
.right
= rectIcon
.left
+ ICONWIDTH
;
1905 rectIcon
.bottom
= pDIStruct
->rcItem
.bottom
;
1907 /* Initialise the text display area */
1908 rectText
.left
= rectIcon
.right
;
1909 rectText
.top
= pDIStruct
->rcItem
.top
+ YTEXTOFFSET
;
1910 rectText
.right
= pDIStruct
->rcItem
.right
+ XTEXTOFFSET
;
1911 rectText
.bottom
= pDIStruct
->rcItem
.bottom
;
1914 /* Draw the icon from the image list */
1915 COMDLG32_ImageList_Draw(ilItemImage
,
1922 /* Draw the associated text */
1923 if(sfi
.szDisplayName
)
1924 TextOutA(pDIStruct
->hDC
,rectText
.left
,rectText
.top
,sfi
.szDisplayName
,strlen(sfi
.szDisplayName
));
1930 /***********************************************************************
1931 * FILEDLG95_LOOKIN_OnCommand
1933 * LookIn combo box WM_COMMAND message handler
1934 * If the function succeeds, the return value is nonzero.
1936 static BOOL
FILEDLG95_LOOKIN_OnCommand(HWND hwnd
, WORD wNotifyCode
)
1938 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1940 TRACE("%p\n", fodInfos
);
1946 LPSFOLDER tmpFolder
;
1949 iItem
= CBGetCurSel(fodInfos
->DlgInfos
.hwndLookInCB
);
1951 if(!(tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(fodInfos
->DlgInfos
.hwndLookInCB
,
1956 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos
->Shell
.FOIShellBrowser
,
1957 tmpFolder
->pidlItem
,
1969 /***********************************************************************
1970 * FILEDLG95_LOOKIN_AddItem
1972 * Adds an absolute pidl item to the lookin combo box
1973 * returns the index of the inserted item
1975 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd
,LPITEMIDLIST pidl
, int iInsertId
)
1977 LPITEMIDLIST pidlNext
;
1980 LookInInfos
*liInfos
;
1987 if(!(liInfos
= (LookInInfos
*)GetPropA(hwnd
,LookInInfosStr
)))
1990 tmpFolder
= MemAlloc(sizeof(SFOLDER
));
1991 tmpFolder
->m_iIndent
= 0;
1993 /* Calculate the indentation of the item in the lookin*/
1995 while( (pidlNext
=COMDLG32_PIDL_ILGetNext(pidlNext
)) )
1997 tmpFolder
->m_iIndent
++;
2000 tmpFolder
->pidlItem
= COMDLG32_PIDL_ILClone(pidl
); /* FIXME: memory leak*/
2002 if(tmpFolder
->m_iIndent
> liInfos
->iMaxIndentation
)
2003 liInfos
->iMaxIndentation
= tmpFolder
->m_iIndent
;
2005 sfi
.dwAttributes
= SFGAO_FILESYSANCESTOR
| SFGAO_FILESYSTEM
;
2006 COMDLG32_SHGetFileInfoA((LPSTR
)pidl
,
2010 SHGFI_DISPLAYNAME
| SHGFI_SYSICONINDEX
2011 | SHGFI_PIDL
| SHGFI_SMALLICON
| SHGFI_ATTRIBUTES
| SHGFI_ATTR_SPECIFIED
);
2014 if((sfi
.dwAttributes
& SFGAO_FILESYSANCESTOR
) || (sfi
.dwAttributes
& SFGAO_FILESYSTEM
))
2018 /* Add the item at the end of the list */
2021 iItemID
= CBAddString(hwnd
,sfi
.szDisplayName
);
2023 /* Insert the item at the iInsertId position*/
2026 iItemID
= CBInsertString(hwnd
,sfi
.szDisplayName
,iInsertId
);
2029 CBSetItemDataPtr(hwnd
,iItemID
,tmpFolder
);
2033 MemFree( tmpFolder
);
2038 /***********************************************************************
2039 * FILEDLG95_LOOKIN_InsertItemAfterParent
2041 * Insert an item below its parent
2043 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd
,LPITEMIDLIST pidl
)
2046 LPITEMIDLIST pidlParent
= GetParentPidl(pidl
);
2051 iParentPos
= FILEDLG95_LOOKIN_SearchItem(hwnd
,(WPARAM
)pidlParent
,SEARCH_PIDL
);
2055 iParentPos
= FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd
,pidlParent
);
2058 /* Free pidlParent memory */
2059 COMDLG32_SHFree((LPVOID
)pidlParent
);
2061 return FILEDLG95_LOOKIN_AddItem(hwnd
,pidl
,iParentPos
+ 1);
2064 /***********************************************************************
2065 * FILEDLG95_LOOKIN_SelectItem
2067 * Adds an absolute pidl item to the lookin combo box
2068 * returns the index of the inserted item
2070 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd
,LPITEMIDLIST pidl
)
2073 LookInInfos
*liInfos
;
2077 iItemPos
= FILEDLG95_LOOKIN_SearchItem(hwnd
,(WPARAM
)pidl
,SEARCH_PIDL
);
2079 liInfos
= (LookInInfos
*)GetPropA(hwnd
,LookInInfosStr
);
2083 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd
) > -1);
2084 iItemPos
= FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd
,pidl
);
2089 SFOLDER
*tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(hwnd
,iItemPos
);
2090 while(liInfos
->iMaxIndentation
> tmpFolder
->m_iIndent
)
2094 if(-1 == (iRemovedItem
= FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd
)))
2096 if(iRemovedItem
< iItemPos
)
2101 CBSetCurSel(hwnd
,iItemPos
);
2102 liInfos
->uSelectedItem
= iItemPos
;
2108 /***********************************************************************
2109 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2111 * Remove the item with an expansion level over iExpansionLevel
2113 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd
)
2117 LookInInfos
*liInfos
= (LookInInfos
*)GetPropA(hwnd
,LookInInfosStr
);
2121 if(liInfos
->iMaxIndentation
<= 2)
2124 if((iItemPos
= FILEDLG95_LOOKIN_SearchItem(hwnd
,(WPARAM
)liInfos
->iMaxIndentation
,SEARCH_EXP
)) >=0)
2126 SFOLDER
*tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(hwnd
,iItemPos
);
2127 COMDLG32_SHFree(tmpFolder
->pidlItem
);
2129 CBDeleteString(hwnd
,iItemPos
);
2130 liInfos
->iMaxIndentation
--;
2138 /***********************************************************************
2139 * FILEDLG95_LOOKIN_SearchItem
2141 * Search for pidl in the lookin combo box
2142 * returns the index of the found item
2144 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd
,WPARAM searchArg
,int iSearchMethod
)
2147 int iCount
= CBGetCount(hwnd
);
2151 if (iCount
!= CB_ERR
)
2155 LPSFOLDER tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(hwnd
,i
);
2157 if(iSearchMethod
== SEARCH_PIDL
&& COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST
)searchArg
,tmpFolder
->pidlItem
))
2159 if(iSearchMethod
== SEARCH_EXP
&& tmpFolder
->m_iIndent
== (int)searchArg
)
2167 /***********************************************************************
2168 * FILEDLG95_LOOKIN_Clean
2170 * Clean the memory used by the lookin combo box
2172 static void FILEDLG95_LOOKIN_Clean(HWND hwnd
)
2174 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
2176 int iCount
= CBGetCount(fodInfos
->DlgInfos
.hwndLookInCB
);
2180 /* Delete each string of the combo and their associated data */
2181 if (iCount
!= CB_ERR
)
2183 for(iPos
= iCount
-1;iPos
>=0;iPos
--)
2185 SFOLDER
*tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(fodInfos
->DlgInfos
.hwndLookInCB
,iPos
);
2186 COMDLG32_SHFree(tmpFolder
->pidlItem
);
2188 CBDeleteString(fodInfos
->DlgInfos
.hwndLookInCB
,iPos
);
2192 /* LookInInfos structure */
2193 RemovePropA(fodInfos
->DlgInfos
.hwndLookInCB
,LookInInfosStr
);
2196 /***********************************************************************
2197 * FILEDLG95_FILENAME_FillFromSelection
2199 * fills the edit box from the cached DataObject
2201 void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd
)
2203 FileOpenDlgInfos
*fodInfos
;
2205 UINT nFiles
= 0, nFileToOpen
, nFileSelected
, nLength
= 0;
2206 char lpstrTemp
[MAX_PATH
];
2207 LPSTR lpstrAllFile
= NULL
, lpstrCurrFile
= NULL
;
2210 fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
2212 /* Count how many files we have */
2213 nFileSelected
= GetNumSelected( fodInfos
->Shell
.FOIDataObject
);
2215 /* calculate the string length, count files */
2216 if (nFileSelected
>= 1)
2218 nLength
+= 3; /* first and last quotes, trailing \0 */
2219 for ( nFileToOpen
= 0; nFileToOpen
< nFileSelected
; nFileToOpen
++ )
2221 pidl
= GetPidlFromDataObject( fodInfos
->Shell
.FOIDataObject
, nFileToOpen
+1 );
2225 /* get the total length of the selected file names*/
2226 lpstrTemp
[0] = '\0';
2227 GetName( fodInfos
->Shell
.FOIShellFolder
, pidl
, SHGDN_INFOLDER
, lpstrTemp
);
2229 if ( ! IsPidlFolder(fodInfos
->Shell
.FOIShellFolder
, pidl
) ) /* Ignore folders */
2231 nLength
+= lstrlenA( lpstrTemp
) + 3;
2234 COMDLG32_SHFree( pidl
);
2239 /* allocate the buffer */
2240 if (nFiles
<= 1) nLength
= MAX_PATH
;
2241 lpstrAllFile
= (LPSTR
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nLength
);
2242 lpstrAllFile
[0] = '\0';
2244 /* Generate the string for the edit control */
2247 lpstrCurrFile
= lpstrAllFile
;
2248 for ( nFileToOpen
= 0; nFileToOpen
< nFileSelected
; nFileToOpen
++ )
2250 pidl
= GetPidlFromDataObject( fodInfos
->Shell
.FOIDataObject
, nFileToOpen
+1 );
2254 /* get the file name */
2255 lpstrTemp
[0] = '\0';
2256 GetName( fodInfos
->Shell
.FOIShellFolder
, pidl
, SHGDN_INFOLDER
, lpstrTemp
);
2258 if (! IsPidlFolder(fodInfos
->Shell
.FOIShellFolder
, pidl
)) /* Ignore folders */
2262 *lpstrCurrFile
++ = '\"';
2263 lstrcpyA( lpstrCurrFile
, lpstrTemp
);
2264 lpstrCurrFile
+= lstrlenA( lpstrTemp
);
2265 lstrcpyA( lpstrCurrFile
, "\" " );
2270 lstrcpyA( lpstrAllFile
, lpstrTemp
);
2273 COMDLG32_SHFree( (LPVOID
) pidl
);
2278 SetWindowTextA( fodInfos
->DlgInfos
.hwndFileName
, lpstrAllFile
);
2279 HeapFree(GetProcessHeap(),0, lpstrAllFile
);
2283 /* copied from shell32 to avoid linking to it */
2284 static HRESULT
COMDLG32_StrRetToStrNA (LPVOID dest
, DWORD len
, LPSTRRET src
, LPITEMIDLIST pidl
)
2289 WideCharToMultiByte(CP_ACP
, 0, src
->u
.pOleStr
, -1, (LPSTR
)dest
, len
, NULL
, NULL
);
2290 COMDLG32_SHFree(src
->u
.pOleStr
);
2294 lstrcpynA((LPSTR
)dest
, src
->u
.cStr
, len
);
2297 case STRRET_OFFSETA
:
2298 lstrcpynA((LPSTR
)dest
, ((LPCSTR
)&pidl
->mkid
)+src
->u
.uOffset
, len
);
2302 FIXME("unknown type!\n");
2305 *(LPSTR
)dest
= '\0';
2312 /***********************************************************************
2313 * FILEDLG95_FILENAME_GetFileNames
2315 * copys the filenames to a 0-delimited string
2317 int FILEDLG95_FILENAME_GetFileNames (HWND hwnd
, LPSTR
* lpstrFileList
, UINT
* sizeUsed
)
2319 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
2320 UINT nStrCharCount
= 0; /* index in src buffer */
2321 UINT nFileIndex
= 0; /* index in dest buffer */
2322 UINT nFileCount
= 0; /* number of files */
2323 UINT nStrLen
= 0; /* length of string in edit control */
2324 LPSTR lpstrEdit
; /* buffer for string from edit control */
2328 /* get the filenames from the edit control */
2329 nStrLen
= SendMessageA(fodInfos
->DlgInfos
.hwndFileName
, WM_GETTEXTLENGTH
, 0, 0);
2330 lpstrEdit
= MemAlloc(nStrLen
+1);
2331 GetDlgItemTextA(hwnd
, IDC_FILENAME
, lpstrEdit
, nStrLen
+1);
2333 TRACE("nStrLen=%u str=%s\n", nStrLen
, lpstrEdit
);
2335 *lpstrFileList
= MemAlloc(nStrLen
);
2338 /* build 0-delimited file list from filenames*/
2339 while ( nStrCharCount
<= nStrLen
)
2341 if ( lpstrEdit
[nStrCharCount
]=='"' )
2344 while ((lpstrEdit
[nStrCharCount
]!='"') && (nStrCharCount
<= nStrLen
))
2346 (*lpstrFileList
)[nFileIndex
++] = lpstrEdit
[nStrCharCount
];
2350 (*lpstrFileList
)[nFileIndex
++] = '\0';
2357 /* single, unquoted string */
2358 if ((nStrLen
> 0) && (*sizeUsed
== 0) )
2360 strcpy(*lpstrFileList
, lpstrEdit
);
2361 nFileIndex
= strlen(lpstrEdit
) + 1;
2362 (*sizeUsed
) = nFileIndex
;
2367 (*lpstrFileList
)[nFileIndex
] = '\0';
2374 #define SETDefFormatEtc(fe,cf,med) \
2376 (fe).cfFormat = cf;\
2377 (fe).dwAspect = DVASPECT_CONTENT; \
2384 * DATAOBJECT Helper functions
2387 /***********************************************************************
2388 * COMCTL32_ReleaseStgMedium
2390 * like ReleaseStgMedium from ole32
2392 static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium
)
2394 if(medium
.pUnkForRelease
)
2396 IUnknown_Release(medium
.pUnkForRelease
);
2400 GlobalUnlock(medium
.u
.hGlobal
);
2401 GlobalFree(medium
.u
.hGlobal
);
2405 /***********************************************************************
2406 * GetPidlFromDataObject
2408 * Return pidl(s) by number from the cached DataObject
2410 * nPidlIndex=0 gets the fully qualified root path
2412 LPITEMIDLIST
GetPidlFromDataObject ( IDataObject
*doSelected
, UINT nPidlIndex
)
2416 FORMATETC formatetc
;
2417 LPITEMIDLIST pidl
= NULL
;
2419 TRACE("sv=%p index=%u\n", doSelected
, nPidlIndex
);
2421 /* Set the FORMATETC structure*/
2422 SETDefFormatEtc(formatetc
, RegisterClipboardFormatA(CFSTR_SHELLIDLIST
), TYMED_HGLOBAL
);
2424 /* Get the pidls from IDataObject */
2425 if(SUCCEEDED(IDataObject_GetData(doSelected
,&formatetc
,&medium
)))
2427 LPIDA cida
= GlobalLock(medium
.u
.hGlobal
);
2428 if(nPidlIndex
<= cida
->cidl
)
2430 pidl
= COMDLG32_PIDL_ILClone((LPITEMIDLIST
)(&((LPBYTE
)cida
)[cida
->aoffset
[nPidlIndex
]]));
2432 COMCTL32_ReleaseStgMedium(medium
);
2437 /***********************************************************************
2440 * Return the number of selected items in the DataObject.
2443 UINT
GetNumSelected( IDataObject
*doSelected
)
2447 FORMATETC formatetc
;
2449 TRACE("sv=%p\n", doSelected
);
2451 if (!doSelected
) return 0;
2453 /* Set the FORMATETC structure*/
2454 SETDefFormatEtc(formatetc
, RegisterClipboardFormatA(CFSTR_SHELLIDLIST
), TYMED_HGLOBAL
);
2456 /* Get the pidls from IDataObject */
2457 if(SUCCEEDED(IDataObject_GetData(doSelected
,&formatetc
,&medium
)))
2459 LPIDA cida
= GlobalLock(medium
.u
.hGlobal
);
2460 retVal
= cida
->cidl
;
2461 COMCTL32_ReleaseStgMedium(medium
);
2471 /***********************************************************************
2474 * Get the pidl's display name (relative to folder) and
2475 * put it in lpstrFileName.
2477 * Return NOERROR on success,
2481 HRESULT
GetName(LPSHELLFOLDER lpsf
, LPITEMIDLIST pidl
,DWORD dwFlags
,LPSTR lpstrFileName
)
2486 TRACE("sf=%p pidl=%p\n", lpsf
, pidl
);
2491 COMDLG32_SHGetDesktopFolder(&lpsf
);
2492 hRes
= GetName(lpsf
,pidl
,dwFlags
,lpstrFileName
);
2493 IShellFolder_Release(lpsf
);
2497 /* Get the display name of the pidl relative to the folder */
2498 if (SUCCEEDED(hRes
= IShellFolder_GetDisplayNameOf(lpsf
, pidl
, dwFlags
, &str
)))
2500 return COMDLG32_StrRetToStrNA(lpstrFileName
, MAX_PATH
, &str
, pidl
);
2505 /***********************************************************************
2506 * GetShellFolderFromPidl
2508 * pidlRel is the item pidl relative
2509 * Return the IShellFolder of the absolute pidl
2511 IShellFolder
*GetShellFolderFromPidl(LPITEMIDLIST pidlAbs
)
2513 IShellFolder
*psf
= NULL
,*psfParent
;
2515 TRACE("%p\n", pidlAbs
);
2517 if(SUCCEEDED(COMDLG32_SHGetDesktopFolder(&psfParent
)))
2520 if(pidlAbs
&& pidlAbs
->mkid
.cb
)
2522 if(SUCCEEDED(IShellFolder_BindToObject(psfParent
, pidlAbs
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psf
)))
2524 IShellFolder_Release(psfParent
);
2528 /* return the desktop */
2534 /***********************************************************************
2537 * Return the LPITEMIDLIST to the parent of the pidl in the list
2539 LPITEMIDLIST
GetParentPidl(LPITEMIDLIST pidl
)
2541 LPITEMIDLIST pidlParent
;
2543 TRACE("%p\n", pidl
);
2545 pidlParent
= COMDLG32_PIDL_ILClone(pidl
);
2546 COMDLG32_PIDL_ILRemoveLastID(pidlParent
);
2551 /***********************************************************************
2554 * returns the pidl of the file name relative to folder
2555 * NULL if an error occured
2557 LPITEMIDLIST
GetPidlFromName(IShellFolder
*lpsf
,LPCSTR lpcstrFileName
)
2561 WCHAR lpwstrDirName
[MAX_PATH
];
2563 TRACE("sf=%p file=%s\n", lpsf
, lpcstrFileName
);
2565 if(!lpcstrFileName
) return NULL
;
2567 MultiByteToWideChar(CP_ACP
,MB_PRECOMPOSED
,lpcstrFileName
,-1,(LPWSTR
)lpwstrDirName
,MAX_PATH
);
2571 COMDLG32_SHGetDesktopFolder(&lpsf
);
2572 pidl
= GetPidlFromName(lpsf
, lpcstrFileName
);
2573 IShellFolder_Release(lpsf
);
2577 IShellFolder_ParseDisplayName(lpsf
, 0, NULL
, (LPWSTR
)lpwstrDirName
, &ulEaten
, &pidl
, NULL
);
2584 BOOL
IsPidlFolder (LPSHELLFOLDER psf
, LPITEMIDLIST pidl
)
2586 ULONG uAttr
= SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
;
2589 TRACE("%p, %p\n", psf
, pidl
);
2591 ret
= IShellFolder_GetAttributesOf( psf
, 1, &pidl
, &uAttr
);
2593 TRACE("-- 0x%08lx 0x%08lx\n", uAttr
, ret
);
2594 /* see documentation shell 4.1*/
2595 return uAttr
& (SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
);
2598 /***********************************************************************
2599 * BrowseSelectedFolder
2601 static BOOL
BrowseSelectedFolder(HWND hwnd
)
2603 BOOL bBrowseSelFolder
= FALSE
;
2604 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
2608 if (GetNumSelected(fodInfos
->Shell
.FOIDataObject
) == 1)
2610 LPITEMIDLIST pidlSelection
;
2612 /* get the file selected */
2613 pidlSelection
= GetPidlFromDataObject( fodInfos
->Shell
.FOIDataObject
, 1);
2614 if (IsPidlFolder (fodInfos
->Shell
.FOIShellFolder
, pidlSelection
))
2616 if ( FAILED( IShellBrowser_BrowseObject( fodInfos
->Shell
.FOIShellBrowser
,
2617 pidlSelection
, SBSP_RELATIVE
) ) )
2619 MessageBoxA( hwnd
, "Path does not exist", fodInfos
->ofnInfos
->lpstrTitle
,
2620 MB_OK
| MB_ICONEXCLAMATION
);
2623 bBrowseSelFolder
= TRUE
;
2625 COMDLG32_SHFree( pidlSelection
);
2628 return bBrowseSelFolder
;
2632 * Memory allocation methods */
2633 static void *MemAlloc(UINT size
)
2635 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,size
);
2638 static void MemFree(void *mem
)
2642 HeapFree(GetProcessHeap(),0,mem
);