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)
55 #include "wine/port.h"
65 #include "wine/unicode.h"
69 #include "wine/debug.h"
73 #include "filedlgbrowser.h"
75 #include "wine/obj_contextmenu.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
79 #define UNIMPLEMENTED_FLAGS \
80 (OFN_CREATEPROMPT | OFN_DONTADDTORECENT |\
81 OFN_ENABLEINCLUDENOTIFY | OFN_ENABLESIZING | OFN_EXTENSIONDIFFERENT |\
82 OFN_NODEREFERENCELINKS | OFN_NOREADONLYRETURN |\
83 OFN_NOTESTFILECREATE | OFN_OVERWRITEPROMPT /*| OFN_USEMONIKERS*/)
85 #define IsHooked(fodInfos) \
86 ((fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook)
87 /***********************************************************************
88 * Data structure and global variables
90 typedef struct SFolder
92 int m_iImageIndex
; /* Index of picture in image list */
94 int m_iIndent
; /* Indentation index */
95 LPITEMIDLIST pidlItem
; /* absolute pidl of the item */
99 typedef struct tagLookInInfo
106 /***********************************************************************
107 * Defines and global variables
110 /* Draw item constant */
112 #define XTEXTOFFSET 3
117 /* SearchItem methods */
118 #define SEARCH_PIDL 1
120 #define ITEM_NOTFOUND -1
122 /* Undefined windows message sent by CreateViewObject*/
123 #define WM_GETISHELLBROWSER WM_USER+7
126 * Those macros exist in windowsx.h. However, you can't really use them since
127 * they rely on the UNICODE defines and can't be used inside Wine itself.
130 /* Combo box macros */
131 #define CBAddString(hwnd,str) \
132 SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str);
134 #define CBInsertString(hwnd,str,pos) \
135 SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str);
137 #define CBDeleteString(hwnd,pos) \
138 SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0);
140 #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
141 SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr);
143 #define CBGetItemDataPtr(hwnd,iItemId) \
144 SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0)
146 #define CBGetLBText(hwnd,iItemId,str) \
147 SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str);
149 #define CBGetCurSel(hwnd) \
150 SendMessageA(hwnd,CB_GETCURSEL,0,0);
152 #define CBSetCurSel(hwnd,pos) \
153 SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0);
155 #define CBGetCount(hwnd) \
156 SendMessageA(hwnd,CB_GETCOUNT,0,0);
157 #define CBShowDropDown(hwnd,show) \
158 SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0);
159 #define CBSetItemHeight(hwnd,index,height) \
160 SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height);
163 const char *FileOpenDlgInfosStr
= "FileOpenDlgInfos"; /* windows property description string */
164 const char *LookInInfosStr
= "LookInInfos"; /* LOOKIN combo box property */
166 static const char defaultFilter
[] = "*.*";
168 /***********************************************************************
172 /* Internal functions used by the dialog */
173 static LRESULT
FILEDLG95_FillControls(HWND hwnd
, WPARAM wParam
, LPARAM lParam
);
174 static LRESULT
FILEDLG95_OnWMCommand(HWND hwnd
, WPARAM wParam
, LPARAM lParam
);
175 static LRESULT
FILEDLG95_OnWMGetIShellBrowser(HWND hwnd
);
176 BOOL
FILEDLG95_OnOpen(HWND hwnd
);
177 static LRESULT
FILEDLG95_InitControls(HWND hwnd
);
178 static void FILEDLG95_Clean(HWND hwnd
);
180 /* Functions used by the shell navigation */
181 static LRESULT
FILEDLG95_SHELL_Init(HWND hwnd
);
182 static BOOL
FILEDLG95_SHELL_UpFolder(HWND hwnd
);
183 static BOOL
FILEDLG95_SHELL_ExecuteCommand(HWND hwnd
, LPCSTR lpVerb
);
184 static void FILEDLG95_SHELL_Clean(HWND hwnd
);
185 static BOOL
FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd
);
187 /* Functions used by the filetype combo box */
188 static HRESULT
FILEDLG95_FILETYPE_Init(HWND hwnd
);
189 static BOOL
FILEDLG95_FILETYPE_OnCommand(HWND hwnd
, WORD wNotifyCode
);
190 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd
,LPCSTR lpstrExt
);
191 static void FILEDLG95_FILETYPE_Clean(HWND hwnd
);
193 /* Functions used by the Look In combo box */
194 static HRESULT
FILEDLG95_LOOKIN_Init(HWND hwndCombo
);
195 static LRESULT
FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct
);
196 static BOOL
FILEDLG95_LOOKIN_OnCommand(HWND hwnd
, WORD wNotifyCode
);
197 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd
,LPITEMIDLIST pidl
, int iInsertId
);
198 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd
,WPARAM searchArg
,int iSearchMethod
);
199 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd
,LPITEMIDLIST pidl
);
200 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd
);
201 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd
,LPITEMIDLIST pidl
);
202 static void FILEDLG95_LOOKIN_Clean(HWND hwnd
);
204 /* Miscellaneous tool functions */
205 HRESULT
GetName(LPSHELLFOLDER lpsf
, LPITEMIDLIST pidl
,DWORD dwFlags
,LPSTR lpstrFileName
);
206 HRESULT
GetFileName(HWND hwnd
, LPITEMIDLIST pidl
, LPSTR lpstrFileName
);
207 IShellFolder
* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs
);
208 LPITEMIDLIST
GetParentPidl(LPITEMIDLIST pidl
);
209 LPITEMIDLIST
GetPidlFromName(IShellFolder
*psf
,LPCSTR lpcstrFileName
);
211 /* Shell memory allocation */
212 static void *MemAlloc(UINT size
);
213 static void MemFree(void *mem
);
215 BOOL WINAPI
GetFileName95(FileOpenDlgInfos
*fodInfos
);
216 HRESULT WINAPI
FileOpenDlgProc95(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
217 HRESULT
SendCustomDlgNotificationMessage(HWND hwndParentDlg
, UINT uCode
);
218 HRESULT
FILEDLG95_HandleCustomDialogMessages(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
219 BOOL
FILEDLG95_OnOpenMultipleFiles(HWND hwnd
, LPSTR lpstrFileList
, UINT nFileCount
, UINT sizeUsed
);
220 static BOOL
BrowseSelectedFolder(HWND hwnd
);
222 /***********************************************************************
225 * Creates an Open common dialog box that lets the user select
226 * the drive, directory, and the name of a file or set of files to open.
228 * IN : The FileOpenDlgInfos structure associated with the dialog
229 * OUT : TRUE on success
230 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
232 BOOL WINAPI
GetFileName95(FileOpenDlgInfos
*fodInfos
)
240 /* test for missing functionality */
241 if (fodInfos
->ofnInfos
->Flags
& UNIMPLEMENTED_FLAGS
)
243 FIXME("Flags 0x%08lx not yet implemented\n",
244 fodInfos
->ofnInfos
->Flags
& UNIMPLEMENTED_FLAGS
);
247 /* Create the dialog from a template */
249 if(!(hRes
= FindResourceA(COMMDLG_hInstance32
,MAKEINTRESOURCEA(NEWFILEOPENORD
),RT_DIALOGA
)))
251 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
254 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hRes
)) ||
255 !(template = LockResource( hDlgTmpl
)))
257 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
261 /* old style hook messages */
262 if (IsHooked(fodInfos
))
264 fodInfos
->HookMsg
.fileokstring
= RegisterWindowMessageA(FILEOKSTRINGA
);
265 fodInfos
->HookMsg
.lbselchstring
= RegisterWindowMessageA(LBSELCHSTRINGA
);
266 fodInfos
->HookMsg
.helpmsgstring
= RegisterWindowMessageA(HELPMSGSTRINGA
);
267 fodInfos
->HookMsg
.sharevistring
= RegisterWindowMessageA(SHAREVISTRINGA
);
270 lRes
= DialogBoxIndirectParamA(COMMDLG_hInstance32
,
271 (LPDLGTEMPLATEA
) template,
272 fodInfos
->ofnInfos
->hwndOwner
,
273 (DLGPROC
) FileOpenDlgProc95
,
276 /* Unable to create the dialog */
283 /***********************************************************************
286 * Call GetFileName95 with this structure and clean the memory.
288 * IN : The OPENFILENAMEA initialisation structure passed to
289 * GetOpenFileNameA win api function (see filedlg.c)
291 BOOL WINAPI
GetFileDialog95A(LPOPENFILENAMEA ofn
,UINT iDlgType
)
295 FileOpenDlgInfos
*fodInfos
;
297 LPCSTR lpstrInitialDir
= (LPCSTR
)-1;
298 LPSTR lpstrSavDir
= NULL
;
301 /* Initialize FileOpenDlgInfos structure */
302 fodInfos
= (FileOpenDlgInfos
*)MemAlloc(sizeof(FileOpenDlgInfos
));
303 ZeroMemory(fodInfos
, sizeof(FileOpenDlgInfos
));
305 /* Pass in the original ofn */
306 fodInfos
->ofnInfos
= ofn
;
308 /* Save original hInstance value */
309 hInstance
= ofn
->hInstance
;
310 fodInfos
->ofnInfos
->hInstance
= MapHModuleLS(ofn
->hInstance
);
312 /* save current directory */
313 if (ofn
->Flags
& OFN_NOCHANGEDIR
)
315 lpstrSavDir
= MemAlloc(MAX_PATH
);
316 GetCurrentDirectoryA(MAX_PATH
, lpstrSavDir
);
319 dwFlags
= ofn
->Flags
;
320 ofn
->Flags
= ofn
->Flags
|OFN_WINE
;
322 /* Initialize the dialog property */
323 fodInfos
->DlgInfos
.dwDlgProp
= 0;
324 fodInfos
->DlgInfos
.hwndCustomDlg
= (HWND
)NULL
;
329 ret
= GetFileName95(fodInfos
);
332 fodInfos
->DlgInfos
.dwDlgProp
|= FODPROP_SAVEDLG
;
333 ret
= GetFileName95(fodInfos
);
341 SetCurrentDirectoryA(lpstrSavDir
);
342 MemFree(lpstrSavDir
);
345 if (lpstrInitialDir
!= (LPCSTR
)-1)
347 MemFree((LPVOID
)(ofn
->lpstrInitialDir
));
348 ofn
->lpstrInitialDir
= lpstrInitialDir
;
351 ofn
->Flags
= dwFlags
;
352 ofn
->hInstance
= hInstance
;
353 MemFree((LPVOID
)(fodInfos
));
357 /***********************************************************************
360 * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
361 * Call GetFileName95 with this structure and clean the memory.
363 * FIXME: lpstrCustomFilter has to converted back
367 /* converting IN arguments */
368 #define AllocInArgWtoA(arg, save) \
371 DWORD _len = WideCharToMultiByte( CP_ACP, 0, arg, -1, NULL, 0, NULL, NULL ); \
373 arg = MemAlloc(_len); \
374 WideCharToMultiByte( CP_ACP, 0, save, -1, (LPSTR)arg, _len, NULL, NULL ); \
377 #define FreeInArg(arg, save) \
380 MemFree((LPSTR)arg); \
384 /* converting OUT arguments */
385 #define AllocOutArgWtoA(arg, save, len) \
389 arg = MemAlloc(len); \
392 #define FreeOutArg(arg, save, len) \
395 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)(arg), -1, (save), (len) ); \
400 BOOL WINAPI
GetFileDialog95W(LPOPENFILENAMEW ofn
,UINT iDlgType
)
403 FileOpenDlgInfos
*fodInfos
;
407 LPWSTR lpstrFile
= NULL
;
408 LPWSTR lpstrFileTitle
= NULL
;
410 /* in/out arguments */
411 LPWSTR lpstrCustomFilter
= NULL
;
413 /* input arguments */
414 LPCWSTR lpstrFilter
= NULL
;
415 LPCWSTR lpstrInitialDir
= NULL
;
416 LPCWSTR lpstrTitle
= NULL
;
417 LPCWSTR lpstrDefExt
= NULL
;
418 LPCWSTR lpTemplateName
= NULL
;
421 /* Initialize FileOpenDlgInfos structure */
422 fodInfos
= (FileOpenDlgInfos
*)MemAlloc(sizeof(FileOpenDlgInfos
));
423 ZeroMemory(fodInfos
, sizeof(FileOpenDlgInfos
));
425 /* Pass in the original ofn */
426 fodInfos
->ofnInfos
= (LPOPENFILENAMEA
) ofn
;
428 /* convert lpstrFilter */
429 if (ofn
->lpstrFilter
)
435 lpstrFilter
= ofn
->lpstrFilter
;
437 /* filter is a list... title\0ext\0......\0\0 */
438 s
= ofn
->lpstrFilter
;
440 while (*s
) s
= s
+strlenW(s
)+1;
442 n
= s
- ofn
->lpstrFilter
; /* already divides by 2. ptr magic */
443 len
= WideCharToMultiByte( CP_ACP
, 0, ofn
->lpstrFilter
, n
, NULL
, 0, NULL
, NULL
);
444 y
= (LPSTR
)MemAlloc(len
);
445 WideCharToMultiByte( CP_ACP
, 0, ofn
->lpstrFilter
, n
, y
, len
, NULL
, NULL
);
446 (LPSTR
)ofn
->lpstrFilter
= y
;
449 /* convert lpstrCustomFilter */
450 if (ofn
->lpstrCustomFilter
)
456 lpstrCustomFilter
= ofn
->lpstrCustomFilter
;
457 /* filter is a list... title\0ext\0......\0\0 */
458 s
= ofn
->lpstrCustomFilter
;
459 while (*s
) s
= s
+strlenW(s
)+1;
461 n
= s
- ofn
->lpstrCustomFilter
;
462 len
= WideCharToMultiByte( CP_ACP
, 0, ofn
->lpstrCustomFilter
, n
, NULL
, 0, NULL
, NULL
);
463 y
= (LPSTR
)MemAlloc(len
);
464 WideCharToMultiByte( CP_ACP
, 0, ofn
->lpstrCustomFilter
, n
, y
, len
, NULL
, NULL
);
465 (LPSTR
)ofn
->lpstrCustomFilter
= y
;
468 /* convert string arguments, save others */
469 AllocOutArgWtoA(ofn
->lpstrFile
, lpstrFile
, ofn
->nMaxFile
);
470 AllocOutArgWtoA(ofn
->lpstrFileTitle
, lpstrFileTitle
, ofn
->nMaxFileTitle
);
471 AllocInArgWtoA(ofn
->lpstrInitialDir
, lpstrInitialDir
);
472 AllocInArgWtoA(ofn
->lpstrTitle
, lpstrTitle
);
473 AllocInArgWtoA(ofn
->lpstrDefExt
, lpstrDefExt
);
474 AllocInArgWtoA(ofn
->lpTemplateName
, lpTemplateName
);
475 dwFlags
= ofn
->Flags
;
476 hInstance
= ofn
->hInstance
;
478 ofn
->Flags
= ofn
->Flags
|OFN_WINE
|OFN_UNICODE
;
479 ofn
->hInstance
= MapHModuleLS(ofn
->hInstance
);
484 ret
= GetFileName95(fodInfos
);
487 fodInfos
->DlgInfos
.dwDlgProp
|= FODPROP_SAVEDLG
;
488 ret
= GetFileName95(fodInfos
);
494 /* restore saved IN arguments and convert OUT arguments back */
495 ofn
->Flags
= dwFlags
;
496 ofn
->hInstance
= hInstance
;
497 FreeInArg(ofn
->lpstrFilter
, lpstrFilter
);
498 FreeInArg(ofn
->lpstrCustomFilter
, lpstrCustomFilter
);
499 FreeOutArg(ofn
->lpstrFile
, lpstrFile
, ofn
->nMaxFile
);
500 FreeOutArg(ofn
->lpstrFileTitle
, lpstrFileTitle
, ofn
->nMaxFileTitle
);
501 FreeInArg(ofn
->lpstrInitialDir
, lpstrInitialDir
);
502 FreeInArg(ofn
->lpstrTitle
, lpstrTitle
);
503 FreeInArg(ofn
->lpstrDefExt
, lpstrDefExt
);
504 FreeInArg(ofn
->lpTemplateName
, lpTemplateName
);
506 MemFree((LPVOID
)(fodInfos
));
510 void ArrangeCtrlPositions( HWND hwndChildDlg
, HWND hwndParentDlg
)
512 HWND hwndChild
,hwndStc32
;
513 RECT rectParent
, rectChild
, rectCtrl
, rectStc32
, rectTemp
;
515 POINT ptParentClient
;
519 ptMoveCtl
.x
= ptMoveCtl
.y
= 0;
520 hwndStc32
=GetDlgItem(hwndChildDlg
,stc32
);
521 GetClientRect(hwndParentDlg
,&rectParent
);
522 GetClientRect(hwndChildDlg
,&rectChild
);
526 GetWindowRect(hwndStc32
,&rectStc32
);
527 MapWindowPoints(0, hwndChildDlg
,(LPPOINT
)&rectStc32
,2);
528 CopyRect(&rectTemp
,&rectStc32
);
530 SetRect(&rectStc32
,rectStc32
.left
,rectStc32
.top
,rectStc32
.left
+ (rectParent
.right
-rectParent
.left
),rectStc32
.top
+(rectParent
.bottom
-rectParent
.top
));
531 SetWindowPos(hwndStc32
,0,rectStc32
.left
,rectStc32
.top
,rectStc32
.right
-rectStc32
.left
,rectStc32
.bottom
-rectStc32
.top
,SWP_NOMOVE
|SWP_NOZORDER
| SWP_NOACTIVATE
);
533 if(rectStc32
.right
< rectTemp
.right
)
535 ptParentClient
.x
= max((rectParent
.right
-rectParent
.left
),(rectChild
.right
-rectChild
.left
));
540 ptMoveCtl
.x
= (rectStc32
.right
- rectTemp
.right
);
541 ptParentClient
.x
= max((rectParent
.right
-rectParent
.left
),((rectChild
.right
-rectChild
.left
)+rectStc32
.right
-rectTemp
.right
));
544 if(rectStc32
.bottom
< rectTemp
.bottom
)
546 ptParentClient
.y
= max((rectParent
.bottom
-rectParent
.top
),(rectChild
.bottom
-rectChild
.top
));
551 ptMoveCtl
.y
= (rectStc32
.bottom
- rectTemp
.bottom
);
552 ptParentClient
.y
= max((rectParent
.bottom
-rectParent
.top
),((rectChild
.bottom
-rectChild
.top
)+rectStc32
.bottom
-rectTemp
.bottom
));
557 if( (GetWindow(hwndChildDlg
,GW_CHILD
)) == (HWND
) NULL
) return;
559 SetRectEmpty(&rectTemp
);
560 ptParentClient
.x
= max((rectParent
.right
-rectParent
.left
),(rectChild
.right
-rectChild
.left
));
561 ptParentClient
.y
= (rectParent
.bottom
-rectParent
.top
) + (rectChild
.bottom
-rectChild
.top
);
562 ptMoveCtl
.y
= rectParent
.bottom
-rectParent
.top
;
565 SetRect(&rectParent
,rectParent
.left
,rectParent
.top
,rectParent
.left
+ptParentClient
.x
,rectParent
.top
+ptParentClient
.y
);
566 AdjustWindowRectEx( &rectParent
,GetWindowLongA(hwndParentDlg
,GWL_STYLE
),FALSE
,GetWindowLongA(hwndParentDlg
,GWL_EXSTYLE
));
568 SetWindowPos(hwndChildDlg
, 0, 0,0, ptParentClient
.x
,ptParentClient
.y
, SWP_NOZORDER
);
569 SetWindowPos(hwndParentDlg
, 0, rectParent
.left
,rectParent
.top
, (rectParent
.right
- rectParent
.left
),
570 (rectParent
.bottom
-rectParent
.top
),SWP_NOMOVE
| SWP_NOZORDER
);
572 hwndChild
= GetWindow(hwndChildDlg
,GW_CHILD
);
575 GetWindowRect(hwndStc32
,&rectStc32
);
576 MapWindowPoints( 0, hwndChildDlg
,(LPPOINT
)&rectStc32
,2);
579 SetRect(&rectStc32
,0,0,0,0);
585 if(hwndChild
!= hwndStc32
)
587 if (GetWindowLongA( hwndChild
, GWL_STYLE
) & WS_MAXIMIZE
)
589 GetWindowRect(hwndChild
,&rectCtrl
);
590 MapWindowPoints( 0, hwndParentDlg
,(LPPOINT
)&rectCtrl
,2);
593 Check the initial position of the controls relative to the initial
594 position and size of stc32 (before it is expanded).
596 if (rectCtrl
.left
>= rectTemp
.right
&& rectCtrl
.top
>= rectTemp
.bottom
)
598 rectCtrl
.left
+= ptMoveCtl
.x
;
599 rectCtrl
.top
+= ptMoveCtl
.y
;
601 else if (rectCtrl
.left
>= rectTemp
.right
)
603 rectCtrl
.left
+= ptMoveCtl
.x
;
605 else if (rectCtrl
.top
>= rectTemp
.bottom
)
607 rectCtrl
.top
+= ptMoveCtl
.y
;
610 SetWindowPos( hwndChild
, 0, rectCtrl
.left
, rectCtrl
.top
,
611 rectCtrl
.right
-rectCtrl
.left
,rectCtrl
.bottom
-rectCtrl
.top
,
612 SWP_NOSIZE
| SWP_NOZORDER
);
614 } while ((hwndChild
=GetWindow( hwndChild
, GW_HWNDNEXT
)) != (HWND
)NULL
);
616 hwndChild
= GetWindow(hwndParentDlg
,GW_CHILD
);
620 GetWindowRect(hwndStc32
,&rectStc32
);
621 MapWindowPoints( 0, hwndChildDlg
,(LPPOINT
)&rectStc32
,2);
622 ptMoveCtl
.x
= rectStc32
.left
- 0;
623 ptMoveCtl
.y
= rectStc32
.top
- 0;
628 if(hwndChild
!= hwndChildDlg
)
630 if (GetWindowLongA( hwndChild
, GWL_STYLE
) & WS_MAXIMIZE
)
632 GetWindowRect(hwndChild
,&rectCtrl
);
633 MapWindowPoints( 0, hwndParentDlg
,(LPPOINT
)&rectCtrl
,2);
635 rectCtrl
.left
+= ptMoveCtl
.x
;
636 rectCtrl
.top
+= ptMoveCtl
.y
;
638 SetWindowPos( hwndChild
, 0, rectCtrl
.left
, rectCtrl
.top
,
639 rectCtrl
.right
-rectCtrl
.left
,rectCtrl
.bottom
-rectCtrl
.top
,
640 SWP_NOSIZE
|SWP_NOZORDER
);
642 } while ((hwndChild
=GetWindow( hwndChild
, GW_HWNDNEXT
)) != (HWND
)NULL
);
648 HRESULT WINAPI
FileOpenDlgProcUserTemplate(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
650 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(GetParent(hwnd
),FileOpenDlgInfosStr
);
653 TRACE("0x%04x\n", uMsg
);
660 /* Hide caption since some program may leave it */
661 DWORD Style
= GetWindowLongA(hwnd
, GWL_STYLE
);
662 if (Style
& WS_CAPTION
) SetWindowLongA(hwnd
, GWL_STYLE
, Style
& (~WS_CAPTION
));
664 fodInfos
= (FileOpenDlgInfos
*)lParam
;
665 lParam
= (LPARAM
) fodInfos
->ofnInfos
;
666 ArrangeCtrlPositions(hwnd
,GetParent(hwnd
));
668 if(fodInfos
&& IsHooked(fodInfos
))
669 return CallWindowProcA((WNDPROC
)fodInfos
->ofnInfos
->lpfnHook
,hwnd
,uMsg
,wParam
,lParam
);
674 if(fodInfos
&& IsHooked(fodInfos
))
675 return CallWindowProcA((WNDPROC
)fodInfos
->ofnInfos
->lpfnHook
,hwnd
,uMsg
,wParam
,lParam
);
677 return DefWindowProcA(hwnd
,uMsg
,wParam
,lParam
);
680 HWND
CreateTemplateDialog(FileOpenDlgInfos
*fodInfos
, HWND hwnd
)
689 if (fodInfos
->ofnInfos
->Flags
& OFN_ENABLETEMPLATE
||
690 fodInfos
->ofnInfos
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
692 if (fodInfos
->ofnInfos
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
694 if( !(template = LockResource( fodInfos
->ofnInfos
->hInstance
)))
696 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
702 if (!(hRes
= FindResourceA(MapHModuleSL(fodInfos
->ofnInfos
->hInstance
),
703 (fodInfos
->ofnInfos
->lpTemplateName
), RT_DIALOGA
)))
705 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
708 if (!(hDlgTmpl
= LoadResource( MapHModuleSL(fodInfos
->ofnInfos
->hInstance
),
709 hRes
)) || !(template = LockResource( hDlgTmpl
)))
711 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
716 hChildDlg
= CreateDialogIndirectParamA(fodInfos
->ofnInfos
->hInstance
,template,hwnd
,(DLGPROC
)FileOpenDlgProcUserTemplate
,(LPARAM
)fodInfos
);
719 ShowWindow(hChildDlg
,SW_SHOW
);
723 else if( IsHooked(fodInfos
))
728 WORD menu
,class,title
;
730 GetClientRect(hwnd
,&rectHwnd
);
731 temp
.tmplate
.style
= WS_CHILD
| WS_CLIPSIBLINGS
;
732 temp
.tmplate
.dwExtendedStyle
= 0;
733 temp
.tmplate
.cdit
= 0;
736 temp
.tmplate
.cx
= rectHwnd
.right
-rectHwnd
.left
;
737 temp
.tmplate
.cy
= rectHwnd
.bottom
-rectHwnd
.top
;
738 temp
.menu
= temp
.class = temp
.title
= 0;
739 hChildDlg
= CreateDialogIndirectParamA(fodInfos
->ofnInfos
->hInstance
,&temp
,
740 hwnd
,(DLGPROC
)FileOpenDlgProcUserTemplate
,(LPARAM
)fodInfos
);
746 /***********************************************************************
747 * SendCustomDlgNotificationMessage
749 * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
752 HRESULT
SendCustomDlgNotificationMessage(HWND hwndParentDlg
, UINT uCode
)
754 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwndParentDlg
,FileOpenDlgInfosStr
);
756 TRACE("0x%04x 0x%04x\n",hwndParentDlg
, uCode
);
758 if(!fodInfos
) return 0;
760 if(fodInfos
->ofnInfos
->Flags
& OFN_UNICODE
)
761 FIXME("sending OPENFILENAMEA structure. Hook is expecting OPENFILENAMEW!\n");
763 if(fodInfos
->DlgInfos
.hwndCustomDlg
)
767 ofnNotify
.hdr
.hwndFrom
=hwndParentDlg
;
768 ofnNotify
.hdr
.idFrom
=0;
769 ofnNotify
.hdr
.code
= uCode
;
770 ofnNotify
.lpOFN
= fodInfos
->ofnInfos
;
771 TRACE("CALL NOTIFY for %x\n", uCode
);
772 ret
= SendMessageA(fodInfos
->DlgInfos
.hwndCustomDlg
,WM_NOTIFY
,0,(LPARAM
)&ofnNotify
);
773 TRACE("RET NOTIFY\n");
779 /***********************************************************************
780 * FILEDLG95_HandleCustomDialogMessages
782 * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
784 HRESULT
FILEDLG95_HandleCustomDialogMessages(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
788 char lpstrPath
[MAX_PATH
];
789 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
790 if(!fodInfos
) return -1;
794 case CDM_GETFILEPATH
:
795 GetDlgItemTextA(hwnd
,IDC_FILENAME
,lpstrPath
, sizeof(lpstrPath
));
796 lpstrFileSpec
= (LPSTR
)PathFindFileNameA(lpstrPath
);
797 if (lpstrFileSpec
==lpstrPath
)
799 char lpstrCurrentDir
[MAX_PATH
];
800 /* Prepend the current path */
801 SHGetPathFromIDListA(fodInfos
->ShellInfos
.pidlAbsCurrent
,lpstrCurrentDir
);
802 if ((LPSTR
)lParam
!=NULL
)
803 snprintf((LPSTR
)lParam
,(int)wParam
,"%s\\%s",lpstrCurrentDir
,lpstrPath
);
804 reqSize
=strlen(lpstrCurrentDir
)+1+strlen(lpstrPath
)+1;
808 lstrcpynA((LPSTR
)lParam
,(LPSTR
)lpstrPath
,(int)wParam
);
809 reqSize
=strlen(lpstrPath
);
811 /* return the required buffer size */
814 case CDM_GETFOLDERPATH
:
815 SHGetPathFromIDListA(fodInfos
->ShellInfos
.pidlAbsCurrent
,lpstrPath
);
816 if ((LPSTR
)lParam
!=NULL
)
817 lstrcpynA((LPSTR
)lParam
,lpstrPath
,(int)wParam
);
818 return strlen(lpstrPath
);
821 reqSize
=GetDlgItemTextA(hwnd
,IDC_FILENAME
,lpstrPath
, sizeof(lpstrPath
));
822 lpstrFileSpec
= (LPSTR
)PathFindFileNameA(lpstrPath
);
823 if ((LPSTR
)lParam
!=NULL
)
824 lstrcpynA((LPSTR
)lParam
, lpstrFileSpec
, (int)wParam
);
825 return strlen(lpstrFileSpec
);
827 case CDM_SETCONTROLTEXT
:
829 SetDlgItemTextA( hwnd
, (UINT
) wParam
, (LPSTR
) lParam
);
832 case CDM_HIDECONTROL
:
834 FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");
840 /***********************************************************************
843 * File open dialog procedure
845 HRESULT WINAPI
FileOpenDlgProc95(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
848 TRACE("0x%04x 0x%04x\n", hwnd
, uMsg
);
855 FileOpenDlgInfos
* fodInfos
= (FileOpenDlgInfos
*)lParam
;
857 /* Adds the FileOpenDlgInfos in the property list of the dialog
858 so it will be easily accessible through a GetPropA(...) */
859 SetPropA(hwnd
, FileOpenDlgInfosStr
, (HANDLE
) fodInfos
);
861 fodInfos
->DlgInfos
.hwndCustomDlg
=
862 CreateTemplateDialog((FileOpenDlgInfos
*)lParam
, hwnd
);
864 FILEDLG95_InitControls(hwnd
);
865 SendCustomDlgNotificationMessage(hwnd
,CDN_INITDONE
);
866 FILEDLG95_FillControls(hwnd
, wParam
, lParam
);
867 SendCustomDlgNotificationMessage(hwnd
,CDN_SELCHANGE
);
868 SetWindowPos(fodInfos
->DlgInfos
.hwndCustomDlg
, HWND_BOTTOM
,
869 0,0,0,0, SWP_NOMOVE
|SWP_NOSIZE
);
873 return FILEDLG95_OnWMCommand(hwnd
, wParam
, lParam
);
876 switch(((LPDRAWITEMSTRUCT
)lParam
)->CtlID
)
879 FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT
) lParam
);
885 case WM_GETISHELLBROWSER
:
886 return FILEDLG95_OnWMGetIShellBrowser(hwnd
);
889 RemovePropA(hwnd
, FileOpenDlgInfosStr
);
894 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
897 /* set up the button tooltips strings */
898 if(TTN_GETDISPINFOA
== lpnmh
->code
)
900 LPNMTTDISPINFOA lpdi
= (LPNMTTDISPINFOA
)lParam
;
901 switch(lpnmh
->idFrom
)
903 /* Up folder button */
904 case FCIDM_TB_UPFOLDER
:
905 stringId
= IDS_UPFOLDER
;
907 /* New folder button */
908 case FCIDM_TB_NEWFOLDER
:
909 stringId
= IDS_NEWFOLDER
;
911 /* List option button */
912 case FCIDM_TB_SMALLICON
:
913 stringId
= IDS_LISTVIEW
;
915 /* Details option button */
916 case FCIDM_TB_REPORTVIEW
:
917 stringId
= IDS_REPORTVIEW
;
920 case FCIDM_TB_DESKTOP
:
921 stringId
= IDS_TODESKTOP
;
926 lpdi
->hinst
= COMMDLG_hInstance32
;
927 lpdi
->lpszText
= (LPSTR
) stringId
;
932 if(uMsg
>= CDM_FIRST
&& uMsg
<= CDM_LAST
)
933 return FILEDLG95_HandleCustomDialogMessages(hwnd
, uMsg
, wParam
, lParam
);
938 /***********************************************************************
939 * FILEDLG95_InitControls
941 * WM_INITDIALOG message handler (before hook notification)
943 static LRESULT
FILEDLG95_InitControls(HWND hwnd
)
947 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
, {0, 0}, 0, 0 },
948 {VIEW_PARENTFOLDER
, FCIDM_TB_UPFOLDER
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
, {0, 0}, 0, 0 },
949 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
, {0, 0}, 0, 0 },
950 {VIEW_NEWFOLDER
+1, FCIDM_TB_DESKTOP
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
, {0, 0}, 0, 0 },
951 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
, {0, 0}, 0, 0 },
952 {VIEW_NEWFOLDER
, FCIDM_TB_NEWFOLDER
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
, {0, 0}, 0, 0 },
953 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
, {0, 0}, 0, 0 },
954 {VIEW_LIST
, FCIDM_TB_SMALLICON
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
, {0, 0}, 0, 0 },
955 {VIEW_DETAILS
, FCIDM_TB_REPORTVIEW
, TBSTATE_ENABLED
, TBSTYLE_BUTTON
, {0, 0}, 0, 0 },
959 { HINST_COMMCTRL
, IDB_VIEW_SMALL_COLOR
},
960 { COMDLG32_hInstance
, 800 } /* desktop icon */
965 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
967 TRACE("%p\n", fodInfos
);
969 /* Get the hwnd of the controls */
970 fodInfos
->DlgInfos
.hwndFileName
= GetDlgItem(hwnd
,IDC_FILENAME
);
971 fodInfos
->DlgInfos
.hwndFileTypeCB
= GetDlgItem(hwnd
,IDC_FILETYPE
);
972 fodInfos
->DlgInfos
.hwndLookInCB
= GetDlgItem(hwnd
,IDC_LOOKIN
);
974 /* construct the toolbar */
975 GetWindowRect(GetDlgItem(hwnd
,IDC_TOOLBARSTATIC
),&rectTB
);
976 MapWindowPoints( 0, hwnd
,(LPPOINT
)&rectTB
,2);
978 fodInfos
->DlgInfos
.hwndTB
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, (LPSTR
) NULL
,
979 WS_CHILD
| WS_GROUP
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
| CCS_NORESIZE
,
980 0, 0, 150, 26, hwnd
, (HMENU
) IDC_TOOLBAR
, COMMDLG_hInstance32
, NULL
);
982 SetWindowPos(fodInfos
->DlgInfos
.hwndTB
, 0,
983 rectTB
.left
,rectTB
.top
, rectTB
.right
-rectTB
.left
, rectTB
.bottom
-rectTB
.top
,
984 SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
986 SendMessageA(fodInfos
->DlgInfos
.hwndTB
, TB_BUTTONSTRUCTSIZE
, (WPARAM
) sizeof(TBBUTTON
), 0);
988 /* FIXME: use TB_LOADIMAGES when implemented */
989 /* SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/
990 SendMessageA(fodInfos
->DlgInfos
.hwndTB
, TB_ADDBITMAP
, (WPARAM
) 12, (LPARAM
) &tba
[0]);
991 SendMessageA(fodInfos
->DlgInfos
.hwndTB
, TB_ADDBITMAP
, (WPARAM
) 1, (LPARAM
) &tba
[1]);
993 SendMessageA(fodInfos
->DlgInfos
.hwndTB
, TB_ADDBUTTONSA
, (WPARAM
) 9,(LPARAM
) &tbb
);
994 SendMessageA(fodInfos
->DlgInfos
.hwndTB
, TB_AUTOSIZE
, 0, 0);
996 /* Set the window text with the text specified in the OPENFILENAME structure */
997 if(fodInfos
->ofnInfos
->lpstrTitle
)
999 SetWindowTextA(hwnd
,fodInfos
->ofnInfos
->lpstrTitle
);
1001 else if (fodInfos
->DlgInfos
.dwDlgProp
& FODPROP_SAVEDLG
)
1003 SetWindowTextA(hwnd
,"Save");
1006 /* Initialise the file name edit control */
1007 if(fodInfos
->ofnInfos
->lpstrFile
)
1009 LPSTR lpstrFile
= PathFindFileNameA(fodInfos
->ofnInfos
->lpstrFile
);
1010 SetDlgItemTextA(hwnd
, IDC_FILENAME
, lpstrFile
);
1013 /* Must the open as read only check box be checked ?*/
1014 if(fodInfos
->ofnInfos
->Flags
& OFN_READONLY
)
1016 SendDlgItemMessageA(hwnd
,IDC_OPENREADONLY
,BM_SETCHECK
,(WPARAM
)TRUE
,0);
1019 /* Must the open as read only check box be hid ?*/
1020 if(fodInfos
->ofnInfos
->Flags
& OFN_HIDEREADONLY
)
1022 ShowWindow(GetDlgItem(hwnd
,IDC_OPENREADONLY
),SW_HIDE
);
1025 /* Must the help button be hid ?*/
1026 if (!(fodInfos
->ofnInfos
->Flags
& OFN_SHOWHELP
))
1028 ShowWindow(GetDlgItem(hwnd
, pshHelp
), SW_HIDE
);
1031 /* Resize the height, if open as read only checkbox ad help button
1032 are hidden and we are not using a custom template */
1033 if ( (fodInfos
->ofnInfos
->Flags
& OFN_HIDEREADONLY
) &&
1034 (!(fodInfos
->ofnInfos
->Flags
&
1035 (OFN_SHOWHELP
|OFN_ENABLETEMPLATE
|OFN_ENABLETEMPLATEHANDLE
))))
1037 RECT rectDlg
, rectHelp
, rectCancel
;
1038 GetWindowRect(hwnd
, &rectDlg
);
1039 GetWindowRect(GetDlgItem(hwnd
, pshHelp
), &rectHelp
);
1040 GetWindowRect(GetDlgItem(hwnd
, IDCANCEL
), &rectCancel
);
1041 /* subtract the height of the help button plus the space between
1042 the help button and the cancel button to the height of the dialog */
1043 SetWindowPos(hwnd
, 0, 0, 0, rectDlg
.right
-rectDlg
.left
,
1044 (rectDlg
.bottom
-rectDlg
.top
) - (rectHelp
.bottom
- rectCancel
.bottom
),
1045 SWP_NOACTIVATE
|SWP_NOMOVE
|SWP_NOZORDER
);
1048 /* change Open to Save FIXME: use resources */
1049 if (fodInfos
->DlgInfos
.dwDlgProp
& FODPROP_SAVEDLG
)
1051 SetDlgItemTextA(hwnd
,IDOK
,"&Save");
1052 SetDlgItemTextA(hwnd
,IDC_LOOKINSTATIC
,"Save &in");
1057 /***********************************************************************
1058 * FILEDLG95_FillControls
1060 * WM_INITDIALOG message handler (after hook notification)
1062 static LRESULT
FILEDLG95_FillControls(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1064 LPITEMIDLIST pidlItemId
= NULL
;
1066 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) lParam
;
1068 TRACE("dir=%s file=%s\n",
1069 fodInfos
->ofnInfos
->lpstrInitialDir
, fodInfos
->ofnInfos
->lpstrFile
);
1071 /* Get the initial directory pidl */
1073 if(!(pidlItemId
= GetPidlFromName(fodInfos
->Shell
.FOIShellFolder
,fodInfos
->ofnInfos
->lpstrInitialDir
)))
1075 char path
[MAX_PATH
];
1077 GetCurrentDirectoryA(MAX_PATH
,path
);
1078 pidlItemId
= GetPidlFromName(fodInfos
->Shell
.FOIShellFolder
, path
);
1081 /* Initialise shell objects */
1082 FILEDLG95_SHELL_Init(hwnd
);
1084 /* Initialize the Look In combo box */
1085 FILEDLG95_LOOKIN_Init(fodInfos
->DlgInfos
.hwndLookInCB
);
1087 /* Initialize the filter combo box */
1088 FILEDLG95_FILETYPE_Init(hwnd
);
1090 /* Browse to the initial directory */
1091 IShellBrowser_BrowseObject(fodInfos
->Shell
.FOIShellBrowser
,pidlItemId
, SBSP_ABSOLUTE
);
1093 /* Free pidlItem memory */
1094 COMDLG32_SHFree(pidlItemId
);
1098 /***********************************************************************
1101 * Regroups all the cleaning functions of the filedlg
1103 void FILEDLG95_Clean(HWND hwnd
)
1105 FILEDLG95_FILETYPE_Clean(hwnd
);
1106 FILEDLG95_LOOKIN_Clean(hwnd
);
1107 FILEDLG95_SHELL_Clean(hwnd
);
1109 /***********************************************************************
1110 * FILEDLG95_OnWMCommand
1112 * WM_COMMAND message handler
1114 static LRESULT
FILEDLG95_OnWMCommand(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1116 WORD wNotifyCode
= HIWORD(wParam
); /* notification code */
1117 WORD wID
= LOWORD(wParam
); /* item, control, or accelerator identifier */
1118 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1124 FILEDLG95_OnOpen(hwnd
);
1128 FILEDLG95_Clean(hwnd
);
1129 EndDialog(hwnd
, FALSE
);
1131 /* Filetype combo box */
1133 FILEDLG95_FILETYPE_OnCommand(hwnd
,wNotifyCode
);
1135 /* LookIn combo box */
1137 FILEDLG95_LOOKIN_OnCommand(hwnd
,wNotifyCode
);
1140 /* --- toolbar --- */
1141 /* Up folder button */
1142 case FCIDM_TB_UPFOLDER
:
1143 FILEDLG95_SHELL_UpFolder(hwnd
);
1145 /* New folder button */
1146 case FCIDM_TB_NEWFOLDER
:
1147 FILEDLG95_SHELL_ExecuteCommand(hwnd
,CMDSTR_NEWFOLDER
);
1149 /* List option button */
1150 case FCIDM_TB_SMALLICON
:
1151 FILEDLG95_SHELL_ExecuteCommand(hwnd
,CMDSTR_VIEWLIST
);
1153 /* Details option button */
1154 case FCIDM_TB_REPORTVIEW
:
1155 FILEDLG95_SHELL_ExecuteCommand(hwnd
,CMDSTR_VIEWDETAILS
);
1157 /* Details option button */
1158 case FCIDM_TB_DESKTOP
:
1159 FILEDLG95_SHELL_BrowseToDesktop(hwnd
);
1166 /* Do not use the listview selection anymore */
1167 fodInfos
->DlgInfos
.dwDlgProp
&= ~FODPROP_USEVIEW
;
1171 /***********************************************************************
1172 * FILEDLG95_OnWMGetIShellBrowser
1174 * WM_GETISHELLBROWSER message handler
1176 static LRESULT
FILEDLG95_OnWMGetIShellBrowser(HWND hwnd
)
1179 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1183 SetWindowLongA(hwnd
,DWL_MSGRESULT
,(LONG
)fodInfos
->Shell
.FOIShellBrowser
);
1189 /***********************************************************************
1190 * FILEDLG95_OnOpenMultipleFiles
1192 * Handles the opening of multiple files.
1195 * check destination buffer size
1197 BOOL
FILEDLG95_OnOpenMultipleFiles(HWND hwnd
, LPSTR lpstrFileList
, UINT nFileCount
, UINT sizeUsed
)
1199 CHAR lpstrPathSpec
[MAX_PATH
] = "";
1201 UINT nCount
, nSizePath
;
1202 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1206 lpstrFile
= fodInfos
->ofnInfos
->lpstrFile
;
1207 lpstrFile
[0] = '\0';
1209 SHGetPathFromIDListA( fodInfos
->ShellInfos
.pidlAbsCurrent
, lpstrPathSpec
);
1211 if ( !(fodInfos
->ofnInfos
->Flags
& OFN_NOVALIDATE
) &&
1212 ( fodInfos
->ofnInfos
->Flags
& OFN_FILEMUSTEXIST
))
1214 LPSTR lpstrTemp
= lpstrFileList
;
1216 for ( nCount
= 0; nCount
< nFileCount
; nCount
++ )
1220 pidl
= GetPidlFromName(fodInfos
->Shell
.FOIShellFolder
, lpstrTemp
);
1223 CHAR lpstrNotFound
[100];
1227 LoadStringA(COMMDLG_hInstance32
, IDS_FILENOTFOUND
, lpstrNotFound
, 100);
1228 LoadStringA(COMMDLG_hInstance32
, IDS_VERIFYFILE
, lpstrMsg
, 100);
1230 strcpy(tmp
, lpstrTemp
);
1232 strcat(tmp
, lpstrNotFound
);
1234 strcat(tmp
, lpstrMsg
);
1236 MessageBoxA(hwnd
, tmp
, fodInfos
->ofnInfos
->lpstrTitle
, MB_OK
| MB_ICONEXCLAMATION
);
1240 /* move to the next file in the list of files */
1241 lpstrTemp
+= strlen(lpstrTemp
) + 1;
1242 COMDLG32_SHFree(pidl
);
1246 nSizePath
= strlen(lpstrPathSpec
);
1247 strcpy( lpstrFile
, lpstrPathSpec
);
1248 memcpy( lpstrFile
+ nSizePath
+ 1, lpstrFileList
, sizeUsed
);
1250 fodInfos
->ofnInfos
->nFileOffset
= nSizePath
+ 1;
1251 fodInfos
->ofnInfos
->nFileExtension
= 0;
1253 /* clean and exit */
1254 FILEDLG95_Clean(hwnd
);
1255 return EndDialog(hwnd
,TRUE
);
1258 /***********************************************************************
1261 * Ok button WM_COMMAND message handler
1263 * If the function succeeds, the return value is nonzero.
1265 #define ONOPEN_BROWSE 1
1266 #define ONOPEN_OPEN 2
1267 #define ONOPEN_SEARCH 3
1268 static void FILEDLG95_OnOpenMessage(HWND hwnd
, int idCaption
, int idText
)
1270 char strMsgTitle
[MAX_PATH
];
1271 char strMsgText
[MAX_PATH
];
1273 LoadStringA(COMDLG32_hInstance
, idCaption
, strMsgTitle
, sizeof(strMsgTitle
));
1275 strMsgTitle
[0] = '\0';
1276 LoadStringA(COMDLG32_hInstance
, idText
, strMsgText
, sizeof(strMsgText
));
1277 MessageBoxA(hwnd
,strMsgText
, strMsgTitle
, MB_OK
| MB_ICONHAND
);
1280 BOOL
FILEDLG95_OnOpen(HWND hwnd
)
1282 char * lpstrFileList
;
1283 UINT nFileCount
= 0;
1286 char lpstrPathAndFile
[MAX_PATH
];
1287 char lpstrTemp
[MAX_PATH
];
1288 LPSHELLFOLDER lpsf
= NULL
;
1290 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1292 TRACE("hwnd=0x%04x\n", hwnd
);
1294 /* get the files from the edit control */
1295 nFileCount
= FILEDLG95_FILENAME_GetFileNames(hwnd
, &lpstrFileList
, &sizeUsed
);
1297 /* try if the user selected a folder in the shellview */
1300 BrowseSelectedFolder(hwnd
);
1306 ret
= FILEDLG95_OnOpenMultipleFiles(hwnd
, lpstrFileList
, nFileCount
, sizeUsed
);
1310 TRACE("count=%u len=%u file=%s\n", nFileCount
, sizeUsed
, lpstrFileList
);
1313 Step 1: Build a complete path name from the current folder and
1314 the filename or path in the edit box.
1316 - the path in the edit box is a root path
1317 (with or without drive letter)
1318 - the edit box contains ".." (or a path with ".." in it)
1321 /* Get the current directory name */
1322 if (!SHGetPathFromIDListA(fodInfos
->ShellInfos
.pidlAbsCurrent
, lpstrPathAndFile
))
1324 /* we are in a special folder, default to desktop */
1325 if(FAILED(COMDLG32_SHGetFolderPathA(hwnd
, CSIDL_DESKTOPDIRECTORY
|CSIDL_FLAG_CREATE
, 0, 0, lpstrPathAndFile
)))
1328 GetCurrentDirectoryA(MAX_PATH
, lpstrPathAndFile
);
1331 PathAddBackslashA(lpstrPathAndFile
);
1333 TRACE("current directory=%s\n", lpstrPathAndFile
);
1335 /* if the user specifyed a fully qualified path use it */
1336 if(PathIsRelativeA(lpstrFileList
))
1338 strcat(lpstrPathAndFile
, lpstrFileList
);
1342 /* does the path have a drive letter? */
1343 if (PathGetDriveNumberA(lpstrFileList
) == -1)
1344 strcpy(lpstrPathAndFile
+2, lpstrFileList
);
1346 strcpy(lpstrPathAndFile
, lpstrFileList
);
1349 /* resolve "." and ".." */
1350 PathCanonicalizeA(lpstrTemp
, lpstrPathAndFile
);
1351 strcpy(lpstrPathAndFile
, lpstrTemp
);
1352 TRACE("canon=%s\n", lpstrPathAndFile
);
1354 MemFree(lpstrFileList
);
1357 Step 2: here we have a cleaned up path
1359 We have to parse the path step by step to see if we have to browse
1360 to a folder if the path points to a directory or the last
1361 valid element is a directory.
1364 lpstrPathAndFile: cleaned up path
1367 nOpenAction
= ONOPEN_BROWSE
;
1369 /* dont apply any checks with OFN_NOVALIDATE */
1370 if(!(fodInfos
->ofnInfos
->Flags
& OFN_NOVALIDATE
))
1372 LPSTR lpszTemp
, lpszTemp1
;
1373 LPITEMIDLIST pidl
= NULL
;
1375 /* check for invalid chars */
1376 if(strpbrk(lpstrPathAndFile
+3, "/:<>|") != NULL
)
1378 FILEDLG95_OnOpenMessage(hwnd
, IDS_INVALID_FILENAME_TITLE
, IDS_INVALID_FILENAME
);
1383 if (FAILED (SHGetDesktopFolder(&lpsf
))) return FALSE
;
1385 lpszTemp1
= lpszTemp
= lpstrPathAndFile
;
1388 LPSHELLFOLDER lpsfChild
;
1389 WCHAR lpwstrTemp
[MAX_PATH
];
1390 DWORD dwEaten
, dwAttributes
;
1392 lpszTemp
= PathFindNextComponentA(lpszTemp
);
1394 if (!lpszTemp
) break; /* end of path */
1398 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpszTemp1
, lpszTemp
- lpszTemp1
,
1399 lpwstrTemp
, MAX_PATH
);
1400 lpwstrTemp
[len
] = 0;
1404 MultiByteToWideChar( CP_ACP
, 0, lpszTemp1
, -1,
1405 lpwstrTemp
, sizeof(lpwstrTemp
)/sizeof(WCHAR
) );
1407 /* if the last element is a wildcard do a search */
1408 if(strpbrk(lpszTemp1
, "*?") != NULL
)
1410 nOpenAction
= ONOPEN_SEARCH
;
1414 lpszTemp1
= lpszTemp
;
1416 TRACE("parse now=%s next=%s sf=%p\n",debugstr_w(lpwstrTemp
), debugstr_a(lpszTemp
), lpsf
);
1418 if(lstrlenW(lpwstrTemp
)==2) PathAddBackslashW(lpwstrTemp
);
1420 dwAttributes
= SFGAO_FOLDER
;
1421 if(SUCCEEDED(IShellFolder_ParseDisplayName(lpsf
, hwnd
, NULL
, lpwstrTemp
, &dwEaten
, &pidl
, &dwAttributes
)))
1423 /* the path component is valid, we have a pidl of the next path component */
1424 TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes
, pidl
);
1425 if(dwAttributes
& SFGAO_FOLDER
)
1427 if(FAILED(IShellFolder_BindToObject(lpsf
, pidl
, 0, &IID_IShellFolder
, (LPVOID
*)&lpsfChild
)))
1429 ERR("bind to failed\n"); /* should not fail */
1432 IShellFolder_Release(lpsf
);
1440 /* end dialog, return value */
1441 nOpenAction
= ONOPEN_OPEN
;
1444 COMDLG32_SHFree(pidl
);
1449 if(*lpszTemp
) /* points to trailing null for last path element */
1451 if(fodInfos
->ofnInfos
->Flags
& OFN_PATHMUSTEXIST
)
1453 FILEDLG95_OnOpenMessage(hwnd
, 0, IDS_PATHNOTEXISTING
);
1459 if(fodInfos
->ofnInfos
->Flags
& OFN_FILEMUSTEXIST
)
1461 FILEDLG95_OnOpenMessage(hwnd
, 0, IDS_FILENOTEXISTING
);
1465 /* change to the current folder */
1466 nOpenAction
= ONOPEN_OPEN
;
1470 if(pidl
) COMDLG32_SHFree(pidl
);
1474 Step 3: here we have a cleaned up and validated path
1477 lpsf: ShellFolder bound to the rightmost valid path component
1478 lpstrPathAndFile: cleaned up path
1479 nOpenAction: action to do
1481 TRACE("end validate sf=%p\n", lpsf
);
1485 case ONOPEN_SEARCH
: /* set the current filter to the file mask and refresh */
1486 TRACE("ONOPEN_SEARCH %s\n", lpstrPathAndFile
);
1489 LPSTR lpszTemp
= PathFindFileNameA(lpstrPathAndFile
);
1492 /* replace the current filter */
1493 if(fodInfos
->ShellInfos
.lpstrCurrentFilter
)
1494 MemFree((LPVOID
)fodInfos
->ShellInfos
.lpstrCurrentFilter
);
1495 len
= MultiByteToWideChar( CP_ACP
, 0, lpszTemp
, -1, NULL
, 0 );
1496 fodInfos
->ShellInfos
.lpstrCurrentFilter
= MemAlloc(len
* sizeof(WCHAR
));
1497 MultiByteToWideChar( CP_ACP
, 0, lpszTemp
, -1,
1498 fodInfos
->ShellInfos
.lpstrCurrentFilter
, len
);
1500 /* set the filter cb to the extension when possible */
1501 if(-1 < (iPos
= FILEDLG95_FILETYPE_SearchExt(fodInfos
->DlgInfos
.hwndFileTypeCB
, lpszTemp
)))
1502 CBSetCurSel(fodInfos
->DlgInfos
.hwndFileTypeCB
, iPos
);
1505 case ONOPEN_BROWSE
: /* browse to the highest folder we could bind to */
1506 TRACE("ONOPEN_BROWSE\n");
1508 IPersistFolder2
* ppf2
;
1509 if(SUCCEEDED(IShellFolder_QueryInterface( lpsf
, &IID_IPersistFolder2
, (LPVOID
*)&ppf2
)))
1511 LPITEMIDLIST pidlCurrent
;
1512 IPersistFolder2_GetCurFolder(ppf2
, &pidlCurrent
);
1513 IPersistFolder2_Release(ppf2
);
1514 if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent
, fodInfos
->ShellInfos
.pidlAbsCurrent
))
1516 IShellBrowser_BrowseObject(fodInfos
->Shell
.FOIShellBrowser
, pidlCurrent
, SBSP_ABSOLUTE
);
1518 else if( nOpenAction
== ONOPEN_SEARCH
)
1520 IShellView_Refresh(fodInfos
->Shell
.FOIShellView
);
1522 COMDLG32_SHFree(pidlCurrent
);
1527 case ONOPEN_OPEN
: /* fill in the return struct and close the dialog */
1528 TRACE("ONOPEN_OPEN %s\n", lpstrPathAndFile
);
1530 /* add default extension */
1531 if (fodInfos
->ofnInfos
->lpstrDefExt
)
1533 if (! *PathFindExtensionA(lpstrPathAndFile
))
1535 /* only add "." in case a default extension does exist */
1536 if (*fodInfos
->ofnInfos
->lpstrDefExt
!= '\0')
1539 PathLength
= strlen(lpstrPathAndFile
);
1541 strcat(lpstrPathAndFile
, ".");
1542 strcat(lpstrPathAndFile
, fodInfos
->ofnInfos
->lpstrDefExt
);
1544 /* if file does not exist try without extension */
1545 if (!PathFileExistsA(lpstrPathAndFile
))
1546 lpstrPathAndFile
[PathLength
] = '\0';
1551 /* Check that the size of the file does not exceed buffer size.
1552 (Allow for extra \0 if OFN_MULTISELECT is set.) */
1553 if(strlen(lpstrPathAndFile
) < fodInfos
->ofnInfos
->nMaxFile
-
1554 ((fodInfos
->ofnInfos
->Flags
& OFN_ALLOWMULTISELECT
) ? 1 : 0))
1558 /* fill destination buffer */
1559 strcpy(fodInfos
->ofnInfos
->lpstrFile
, lpstrPathAndFile
);
1560 if (fodInfos
->ofnInfos
->Flags
& OFN_ALLOWMULTISELECT
)
1561 fodInfos
->ofnInfos
->lpstrFile
[strlen(fodInfos
->ofnInfos
->lpstrFile
)
1564 /* set filename offset */
1565 lpszTemp
= PathFindFileNameA(lpstrPathAndFile
);
1566 fodInfos
->ofnInfos
->nFileOffset
= lpszTemp
- lpstrPathAndFile
;
1568 /* set extension offset */
1569 lpszTemp
= PathFindExtensionA(lpstrPathAndFile
);
1570 fodInfos
->ofnInfos
->nFileExtension
= (*lpszTemp
) ? lpszTemp
- lpstrPathAndFile
+ 1 : 0;
1572 /* set the lpstrFileTitle */
1573 if(fodInfos
->ofnInfos
->lpstrFileTitle
)
1575 LPSTR lpstrFileTitle
= PathFindFileNameA(lpstrPathAndFile
);
1576 strncpy(fodInfos
->ofnInfos
->lpstrFileTitle
, lpstrFileTitle
, fodInfos
->ofnInfos
->nMaxFileTitle
);
1579 /* ask the hook if we can close */
1580 if(IsHooked(fodInfos
))
1583 /* First send CDN_FILEOK as MSDN doc says */
1584 SendCustomDlgNotificationMessage(hwnd
,CDN_FILEOK
);
1586 /* FIXME we are sending ASCII-structures. Does not work with NT */
1587 CallWindowProcA((WNDPROC
)fodInfos
->ofnInfos
->lpfnHook
,
1588 fodInfos
->DlgInfos
.hwndCustomDlg
,
1589 fodInfos
->HookMsg
.fileokstring
, 0, (LPARAM
)fodInfos
->ofnInfos
);
1590 if (GetWindowLongA(fodInfos
->DlgInfos
.hwndCustomDlg
, DWL_MSGRESULT
))
1592 TRACE("canceled\n");
1599 FILEDLG95_Clean(hwnd
);
1600 ret
= EndDialog(hwnd
, TRUE
);
1604 /* FIXME set error FNERR_BUFFERTOSMALL */
1605 FILEDLG95_Clean(hwnd
);
1606 ret
= EndDialog(hwnd
, FALSE
);
1614 if(lpsf
) IShellFolder_Release(lpsf
);
1618 /***********************************************************************
1619 * FILEDLG95_SHELL_Init
1621 * Initialisation of the shell objects
1623 static HRESULT
FILEDLG95_SHELL_Init(HWND hwnd
)
1625 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1630 * Initialisation of the FileOpenDialogInfos structure
1636 fodInfos
->ShellInfos
.hwndOwner
= hwnd
;
1638 /* Disable multi-select if flag not set */
1639 if (!(fodInfos
->ofnInfos
->Flags
& OFN_ALLOWMULTISELECT
))
1641 fodInfos
->ShellInfos
.folderSettings
.fFlags
|= FWF_SINGLESEL
;
1643 fodInfos
->ShellInfos
.folderSettings
.fFlags
|= FWF_AUTOARRANGE
| FWF_ALIGNLEFT
;
1644 fodInfos
->ShellInfos
.folderSettings
.ViewMode
= FVM_LIST
;
1646 GetWindowRect(GetDlgItem(hwnd
,IDC_SHELLSTATIC
),&fodInfos
->ShellInfos
.rectView
);
1647 ScreenToClient(hwnd
,(LPPOINT
)&fodInfos
->ShellInfos
.rectView
.left
);
1648 ScreenToClient(hwnd
,(LPPOINT
)&fodInfos
->ShellInfos
.rectView
.right
);
1650 /* Construct the IShellBrowser interface */
1651 fodInfos
->Shell
.FOIShellBrowser
= IShellBrowserImpl_Construct(hwnd
);
1656 /***********************************************************************
1657 * FILEDLG95_SHELL_ExecuteCommand
1659 * Change the folder option and refresh the view
1660 * If the function succeeds, the return value is nonzero.
1662 static BOOL
FILEDLG95_SHELL_ExecuteCommand(HWND hwnd
, LPCSTR lpVerb
)
1664 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1667 TRACE("(0x%08x,%p)\n", hwnd
, lpVerb
);
1669 if(SUCCEEDED(IShellView_GetItemObject(fodInfos
->Shell
.FOIShellView
,
1674 CMINVOKECOMMANDINFO ci
;
1675 ZeroMemory(&ci
, sizeof(CMINVOKECOMMANDINFO
));
1676 ci
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
1680 IContextMenu_InvokeCommand(pcm
, &ci
);
1681 IContextMenu_Release(pcm
);
1687 /***********************************************************************
1688 * FILEDLG95_SHELL_UpFolder
1690 * Browse to the specified object
1691 * If the function succeeds, the return value is nonzero.
1693 static BOOL
FILEDLG95_SHELL_UpFolder(HWND hwnd
)
1695 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1699 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos
->Shell
.FOIShellBrowser
,
1708 /***********************************************************************
1709 * FILEDLG95_SHELL_BrowseToDesktop
1711 * Browse to the Desktop
1712 * If the function succeeds, the return value is nonzero.
1714 static BOOL
FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd
)
1716 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1722 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP
,&pidl
);
1723 hres
= IShellBrowser_BrowseObject(fodInfos
->Shell
.FOIShellBrowser
, pidl
, SBSP_ABSOLUTE
);
1724 COMDLG32_SHFree(pidl
);
1725 return SUCCEEDED(hres
);
1727 /***********************************************************************
1728 * FILEDLG95_SHELL_Clean
1730 * Cleans the memory used by shell objects
1732 static void FILEDLG95_SHELL_Clean(HWND hwnd
)
1734 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1738 COMDLG32_SHFree(fodInfos
->ShellInfos
.pidlAbsCurrent
);
1740 /* clean Shell interfaces */
1741 IShellView_DestroyViewWindow(fodInfos
->Shell
.FOIShellView
);
1742 IShellView_Release(fodInfos
->Shell
.FOIShellView
);
1743 IShellFolder_Release(fodInfos
->Shell
.FOIShellFolder
);
1744 IShellBrowser_Release(fodInfos
->Shell
.FOIShellBrowser
);
1745 if (fodInfos
->Shell
.FOIDataObject
)
1746 IDataObject_Release(fodInfos
->Shell
.FOIDataObject
);
1749 /***********************************************************************
1750 * FILEDLG95_FILETYPE_Init
1752 * Initialisation of the file type combo box
1754 static HRESULT
FILEDLG95_FILETYPE_Init(HWND hwnd
)
1756 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1760 if(fodInfos
->ofnInfos
->lpstrFilter
)
1762 int nFilters
= 0; /* number of filters */
1764 LPCSTR lpstrPos
= fodInfos
->ofnInfos
->lpstrFilter
;
1768 /* filter is a list... title\0ext\0......\0\0
1769 * Set the combo item text to the title and the item data
1772 LPCSTR lpstrDisplay
;
1776 if(! *lpstrPos
) break; /* end */
1777 lpstrDisplay
= lpstrPos
;
1778 lpstrPos
+= strlen(lpstrPos
) + 1;
1780 /* Copy the extensions */
1781 if (! *lpstrPos
) return E_FAIL
; /* malformed filter */
1782 if (!(lpstrExt
= (LPSTR
) MemAlloc(strlen(lpstrPos
)+1))) return E_FAIL
;
1783 strcpy(lpstrExt
,lpstrPos
);
1784 lpstrPos
+= strlen(lpstrPos
) + 1;
1786 /* Add the item at the end of the combo */
1787 CBAddString(fodInfos
->DlgInfos
.hwndFileTypeCB
, lpstrDisplay
);
1788 CBSetItemDataPtr(fodInfos
->DlgInfos
.hwndFileTypeCB
, nFilters
, lpstrExt
);
1792 * Set the current filter to the one specified
1793 * in the initialisation structure
1794 * FIXME: lpstrCustomFilter not handled at all
1797 /* set default filter index */
1798 if(fodInfos
->ofnInfos
->nFilterIndex
== 0 && fodInfos
->ofnInfos
->lpstrCustomFilter
== NULL
)
1799 fodInfos
->ofnInfos
->nFilterIndex
= 1;
1801 /* First, check to make sure our index isn't out of bounds. */
1802 if ( fodInfos
->ofnInfos
->nFilterIndex
> nFilters
)
1803 fodInfos
->ofnInfos
->nFilterIndex
= nFilters
;
1805 /* Set the current index selection. */
1806 CBSetCurSel(fodInfos
->DlgInfos
.hwndFileTypeCB
, fodInfos
->ofnInfos
->nFilterIndex
-1);
1808 /* Get the corresponding text string from the combo box. */
1809 lpstrFilter
= (LPSTR
) CBGetItemDataPtr(fodInfos
->DlgInfos
.hwndFileTypeCB
,
1810 fodInfos
->ofnInfos
->nFilterIndex
-1);
1812 if ((INT
)lpstrFilter
== CB_ERR
) /* control is empty */
1818 CharLowerA(lpstrFilter
); /* lowercase */
1819 len
= MultiByteToWideChar( CP_ACP
, 0, lpstrFilter
, -1, NULL
, 0 );
1820 fodInfos
->ShellInfos
.lpstrCurrentFilter
= MemAlloc( len
* sizeof(WCHAR
) );
1821 MultiByteToWideChar( CP_ACP
, 0, lpstrFilter
, -1,
1822 fodInfos
->ShellInfos
.lpstrCurrentFilter
, len
);
1828 /***********************************************************************
1829 * FILEDLG95_FILETYPE_OnCommand
1831 * WM_COMMAND of the file type combo box
1832 * If the function succeeds, the return value is nonzero.
1834 static BOOL
FILEDLG95_FILETYPE_OnCommand(HWND hwnd
, WORD wNotifyCode
)
1836 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1844 /* Get the current item of the filetype combo box */
1845 int iItem
= CBGetCurSel(fodInfos
->DlgInfos
.hwndFileTypeCB
);
1847 /* set the current filter index - indexed from 1 */
1848 fodInfos
->ofnInfos
->nFilterIndex
= iItem
+ 1;
1850 /* Set the current filter with the current selection */
1851 if(fodInfos
->ShellInfos
.lpstrCurrentFilter
)
1852 MemFree((LPVOID
)fodInfos
->ShellInfos
.lpstrCurrentFilter
);
1854 lpstrFilter
= (LPSTR
) CBGetItemDataPtr(fodInfos
->DlgInfos
.hwndFileTypeCB
,
1856 if((int)lpstrFilter
!= CB_ERR
)
1859 CharLowerA(lpstrFilter
); /* lowercase */
1860 len
= MultiByteToWideChar( CP_ACP
, 0, lpstrFilter
, -1, NULL
, 0 );
1861 fodInfos
->ShellInfos
.lpstrCurrentFilter
= MemAlloc( len
* sizeof(WCHAR
) );
1862 MultiByteToWideChar( CP_ACP
, 0, lpstrFilter
, -1,
1863 fodInfos
->ShellInfos
.lpstrCurrentFilter
, len
);
1864 SendCustomDlgNotificationMessage(hwnd
,CDN_TYPECHANGE
);
1867 /* Refresh the actual view to display the included items*/
1868 IShellView_Refresh(fodInfos
->Shell
.FOIShellView
);
1873 /***********************************************************************
1874 * FILEDLG95_FILETYPE_SearchExt
1876 * searches for a extension in the filetype box
1878 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd
,LPCSTR lpstrExt
)
1880 int i
, iCount
= CBGetCount(hwnd
);
1882 TRACE("%s\n", lpstrExt
);
1884 if(iCount
!= CB_ERR
)
1886 for(i
=0;i
<iCount
;i
++)
1888 if(!strcasecmp(lpstrExt
,(LPSTR
)CBGetItemDataPtr(hwnd
,i
)))
1895 /***********************************************************************
1896 * FILEDLG95_FILETYPE_Clean
1898 * Clean the memory used by the filetype combo box
1900 static void FILEDLG95_FILETYPE_Clean(HWND hwnd
)
1902 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
1904 int iCount
= CBGetCount(fodInfos
->DlgInfos
.hwndFileTypeCB
);
1908 /* Delete each string of the combo and their associated data */
1909 if(iCount
!= CB_ERR
)
1911 for(iPos
= iCount
-1;iPos
>=0;iPos
--)
1913 MemFree((LPSTR
) CBGetItemDataPtr(fodInfos
->DlgInfos
.hwndFileTypeCB
,iPos
));
1914 CBDeleteString(fodInfos
->DlgInfos
.hwndFileTypeCB
,iPos
);
1917 /* Current filter */
1918 if(fodInfos
->ShellInfos
.lpstrCurrentFilter
)
1919 MemFree(fodInfos
->ShellInfos
.lpstrCurrentFilter
);
1923 /***********************************************************************
1924 * FILEDLG95_LOOKIN_Init
1926 * Initialisation of the look in combo box
1928 static HRESULT
FILEDLG95_LOOKIN_Init(HWND hwndCombo
)
1930 IShellFolder
*psfRoot
, *psfDrives
;
1931 IEnumIDList
*lpeRoot
, *lpeDrives
;
1932 LPITEMIDLIST pidlDrives
, pidlTmp
, pidlTmp1
, pidlAbsTmp
;
1934 LookInInfos
*liInfos
= MemAlloc(sizeof(LookInInfos
));
1938 liInfos
->iMaxIndentation
= 0;
1940 SetPropA(hwndCombo
, LookInInfosStr
, (HANDLE
) liInfos
);
1942 /* set item height for both text field and listbox */
1943 CBSetItemHeight(hwndCombo
,-1,GetSystemMetrics(SM_CYSMICON
));
1944 CBSetItemHeight(hwndCombo
,0,GetSystemMetrics(SM_CYSMICON
));
1946 /* Initialise data of Desktop folder */
1947 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP
,&pidlTmp
);
1948 FILEDLG95_LOOKIN_AddItem(hwndCombo
, pidlTmp
,LISTEND
);
1949 COMDLG32_SHFree(pidlTmp
);
1951 SHGetSpecialFolderLocation(0,CSIDL_DRIVES
,&pidlDrives
);
1953 SHGetDesktopFolder(&psfRoot
);
1957 /* enumerate the contents of the desktop */
1958 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot
, hwndCombo
, SHCONTF_FOLDERS
, &lpeRoot
)))
1960 while (S_OK
== IEnumIDList_Next(lpeRoot
, 1, &pidlTmp
, NULL
))
1962 FILEDLG95_LOOKIN_AddItem(hwndCombo
, pidlTmp
,LISTEND
);
1964 /* special handling for CSIDL_DRIVES */
1965 if (COMDLG32_PIDL_ILIsEqual(pidlTmp
, pidlDrives
))
1967 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot
, pidlTmp
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfDrives
)))
1969 /* enumerate the drives */
1970 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives
, hwndCombo
,SHCONTF_FOLDERS
, &lpeDrives
)))
1972 while (S_OK
== IEnumIDList_Next(lpeDrives
, 1, &pidlTmp1
, NULL
))
1974 pidlAbsTmp
= COMDLG32_PIDL_ILCombine(pidlTmp
, pidlTmp1
);
1975 FILEDLG95_LOOKIN_AddItem(hwndCombo
, pidlAbsTmp
,LISTEND
);
1976 COMDLG32_SHFree(pidlAbsTmp
);
1977 COMDLG32_SHFree(pidlTmp1
);
1979 IEnumIDList_Release(lpeDrives
);
1981 IShellFolder_Release(psfDrives
);
1984 COMDLG32_SHFree(pidlTmp
);
1986 IEnumIDList_Release(lpeRoot
);
1990 IShellFolder_Release(psfRoot
);
1991 COMDLG32_SHFree(pidlDrives
);
1995 /***********************************************************************
1996 * FILEDLG95_LOOKIN_DrawItem
1998 * WM_DRAWITEM message handler
2000 static LRESULT
FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct
)
2002 COLORREF crWin
= GetSysColor(COLOR_WINDOW
);
2003 COLORREF crHighLight
= GetSysColor(COLOR_HIGHLIGHT
);
2004 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
2008 HIMAGELIST ilItemImage
;
2011 LPSFOLDER tmpFolder
;
2014 LookInInfos
*liInfos
= (LookInInfos
*)GetPropA(pDIStruct
->hwndItem
,LookInInfosStr
);
2018 if(pDIStruct
->itemID
== -1)
2021 if(!(tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(pDIStruct
->hwndItem
,
2022 pDIStruct
->itemID
)))
2026 if(pDIStruct
->itemID
== liInfos
->uSelectedItem
)
2028 ilItemImage
= (HIMAGELIST
) SHGetFileInfoA ((LPCSTR
) tmpFolder
->pidlItem
,
2031 sizeof (SHFILEINFOA
),
2032 SHGFI_PIDL
| SHGFI_SMALLICON
|
2033 SHGFI_OPENICON
| SHGFI_SYSICONINDEX
|
2034 SHGFI_DISPLAYNAME
);
2038 ilItemImage
= (HIMAGELIST
) SHGetFileInfoA ((LPCSTR
) tmpFolder
->pidlItem
,
2041 sizeof (SHFILEINFOA
),
2042 SHGFI_PIDL
| SHGFI_SMALLICON
|
2043 SHGFI_SYSICONINDEX
|
2047 /* Is this item selected ? */
2048 if(pDIStruct
->itemState
& ODS_SELECTED
)
2050 SetTextColor(pDIStruct
->hDC
,(0x00FFFFFF & ~(crText
)));
2051 SetBkColor(pDIStruct
->hDC
,crHighLight
);
2052 FillRect(pDIStruct
->hDC
,&pDIStruct
->rcItem
,GetSysColorBrush(COLOR_HIGHLIGHT
));
2056 SetTextColor(pDIStruct
->hDC
,crText
);
2057 SetBkColor(pDIStruct
->hDC
,crWin
);
2058 FillRect(pDIStruct
->hDC
,&pDIStruct
->rcItem
,GetSysColorBrush(COLOR_WINDOW
));
2061 /* Do not indent item if drawing in the edit of the combo */
2062 if(pDIStruct
->itemState
& ODS_COMBOBOXEDIT
)
2065 ilItemImage
= (HIMAGELIST
) SHGetFileInfoA ((LPCSTR
) tmpFolder
->pidlItem
,
2068 sizeof (SHFILEINFOA
),
2069 SHGFI_PIDL
| SHGFI_SMALLICON
| SHGFI_OPENICON
2070 | SHGFI_SYSICONINDEX
| SHGFI_DISPLAYNAME
);
2075 iIndentation
= tmpFolder
->m_iIndent
;
2077 /* Draw text and icon */
2079 /* Initialise the icon display area */
2080 rectIcon
.left
= pDIStruct
->rcItem
.left
+ ICONWIDTH
/2 * iIndentation
;
2081 rectIcon
.top
= pDIStruct
->rcItem
.top
;
2082 rectIcon
.right
= rectIcon
.left
+ ICONWIDTH
;
2083 rectIcon
.bottom
= pDIStruct
->rcItem
.bottom
;
2085 /* Initialise the text display area */
2086 GetTextMetricsA(pDIStruct
->hDC
, &tm
);
2087 rectText
.left
= rectIcon
.right
;
2089 (pDIStruct
->rcItem
.top
+ pDIStruct
->rcItem
.bottom
- tm
.tmHeight
) / 2;
2090 rectText
.right
= pDIStruct
->rcItem
.right
+ XTEXTOFFSET
;
2092 (pDIStruct
->rcItem
.top
+ pDIStruct
->rcItem
.bottom
+ tm
.tmHeight
) / 2;
2094 /* Draw the icon from the image list */
2095 ImageList_Draw(ilItemImage
,
2102 /* Draw the associated text */
2103 if(sfi
.szDisplayName
)
2104 TextOutA(pDIStruct
->hDC
,rectText
.left
,rectText
.top
,sfi
.szDisplayName
,strlen(sfi
.szDisplayName
));
2110 /***********************************************************************
2111 * FILEDLG95_LOOKIN_OnCommand
2113 * LookIn combo box WM_COMMAND message handler
2114 * If the function succeeds, the return value is nonzero.
2116 static BOOL
FILEDLG95_LOOKIN_OnCommand(HWND hwnd
, WORD wNotifyCode
)
2118 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
2120 TRACE("%p\n", fodInfos
);
2126 LPSFOLDER tmpFolder
;
2129 iItem
= CBGetCurSel(fodInfos
->DlgInfos
.hwndLookInCB
);
2131 if(!(tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(fodInfos
->DlgInfos
.hwndLookInCB
,
2136 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos
->Shell
.FOIShellBrowser
,
2137 tmpFolder
->pidlItem
,
2149 /***********************************************************************
2150 * FILEDLG95_LOOKIN_AddItem
2152 * Adds an absolute pidl item to the lookin combo box
2153 * returns the index of the inserted item
2155 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd
,LPITEMIDLIST pidl
, int iInsertId
)
2157 LPITEMIDLIST pidlNext
;
2160 LookInInfos
*liInfos
;
2162 TRACE("%08x\n", iInsertId
);
2167 if(!(liInfos
= (LookInInfos
*)GetPropA(hwnd
,LookInInfosStr
)))
2170 tmpFolder
= MemAlloc(sizeof(SFOLDER
));
2171 tmpFolder
->m_iIndent
= 0;
2173 /* Calculate the indentation of the item in the lookin*/
2175 while( (pidlNext
=COMDLG32_PIDL_ILGetNext(pidlNext
)) )
2177 tmpFolder
->m_iIndent
++;
2180 tmpFolder
->pidlItem
= COMDLG32_PIDL_ILClone(pidl
); /* FIXME: memory leak*/
2182 if(tmpFolder
->m_iIndent
> liInfos
->iMaxIndentation
)
2183 liInfos
->iMaxIndentation
= tmpFolder
->m_iIndent
;
2185 sfi
.dwAttributes
= SFGAO_FILESYSANCESTOR
| SFGAO_FILESYSTEM
;
2186 SHGetFileInfoA((LPSTR
)pidl
,
2190 SHGFI_DISPLAYNAME
| SHGFI_SYSICONINDEX
2191 | SHGFI_PIDL
| SHGFI_SMALLICON
| SHGFI_ATTRIBUTES
| SHGFI_ATTR_SPECIFIED
);
2193 TRACE("-- Add %s attr=%08lx\n", sfi
.szDisplayName
, sfi
.dwAttributes
);
2195 if((sfi
.dwAttributes
& SFGAO_FILESYSANCESTOR
) || (sfi
.dwAttributes
& SFGAO_FILESYSTEM
))
2199 TRACE("-- Add %s at %u\n", sfi
.szDisplayName
, tmpFolder
->m_iIndent
);
2201 /* Add the item at the end of the list */
2204 iItemID
= CBAddString(hwnd
,sfi
.szDisplayName
);
2206 /* Insert the item at the iInsertId position*/
2209 iItemID
= CBInsertString(hwnd
,sfi
.szDisplayName
,iInsertId
);
2212 CBSetItemDataPtr(hwnd
,iItemID
,tmpFolder
);
2216 MemFree( tmpFolder
);
2221 /***********************************************************************
2222 * FILEDLG95_LOOKIN_InsertItemAfterParent
2224 * Insert an item below its parent
2226 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd
,LPITEMIDLIST pidl
)
2229 LPITEMIDLIST pidlParent
= GetParentPidl(pidl
);
2234 iParentPos
= FILEDLG95_LOOKIN_SearchItem(hwnd
,(WPARAM
)pidlParent
,SEARCH_PIDL
);
2238 iParentPos
= FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd
,pidlParent
);
2241 /* Free pidlParent memory */
2242 COMDLG32_SHFree((LPVOID
)pidlParent
);
2244 return FILEDLG95_LOOKIN_AddItem(hwnd
,pidl
,iParentPos
+ 1);
2247 /***********************************************************************
2248 * FILEDLG95_LOOKIN_SelectItem
2250 * Adds an absolute pidl item to the lookin combo box
2251 * returns the index of the inserted item
2253 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd
,LPITEMIDLIST pidl
)
2256 LookInInfos
*liInfos
;
2260 iItemPos
= FILEDLG95_LOOKIN_SearchItem(hwnd
,(WPARAM
)pidl
,SEARCH_PIDL
);
2262 liInfos
= (LookInInfos
*)GetPropA(hwnd
,LookInInfosStr
);
2266 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd
) > -1);
2267 iItemPos
= FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd
,pidl
);
2272 SFOLDER
*tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(hwnd
,iItemPos
);
2273 while(liInfos
->iMaxIndentation
> tmpFolder
->m_iIndent
)
2277 if(-1 == (iRemovedItem
= FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd
)))
2279 if(iRemovedItem
< iItemPos
)
2284 CBSetCurSel(hwnd
,iItemPos
);
2285 liInfos
->uSelectedItem
= iItemPos
;
2291 /***********************************************************************
2292 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2294 * Remove the item with an expansion level over iExpansionLevel
2296 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd
)
2300 LookInInfos
*liInfos
= (LookInInfos
*)GetPropA(hwnd
,LookInInfosStr
);
2304 if(liInfos
->iMaxIndentation
<= 2)
2307 if((iItemPos
= FILEDLG95_LOOKIN_SearchItem(hwnd
,(WPARAM
)liInfos
->iMaxIndentation
,SEARCH_EXP
)) >=0)
2309 SFOLDER
*tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(hwnd
,iItemPos
);
2310 COMDLG32_SHFree(tmpFolder
->pidlItem
);
2312 CBDeleteString(hwnd
,iItemPos
);
2313 liInfos
->iMaxIndentation
--;
2321 /***********************************************************************
2322 * FILEDLG95_LOOKIN_SearchItem
2324 * Search for pidl in the lookin combo box
2325 * returns the index of the found item
2327 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd
,WPARAM searchArg
,int iSearchMethod
)
2330 int iCount
= CBGetCount(hwnd
);
2332 TRACE("0x%08x 0x%x\n",searchArg
, iSearchMethod
);
2334 if (iCount
!= CB_ERR
)
2338 LPSFOLDER tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(hwnd
,i
);
2340 if(iSearchMethod
== SEARCH_PIDL
&& COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST
)searchArg
,tmpFolder
->pidlItem
))
2342 if(iSearchMethod
== SEARCH_EXP
&& tmpFolder
->m_iIndent
== (int)searchArg
)
2350 /***********************************************************************
2351 * FILEDLG95_LOOKIN_Clean
2353 * Clean the memory used by the lookin combo box
2355 static void FILEDLG95_LOOKIN_Clean(HWND hwnd
)
2357 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
2359 int iCount
= CBGetCount(fodInfos
->DlgInfos
.hwndLookInCB
);
2363 /* Delete each string of the combo and their associated data */
2364 if (iCount
!= CB_ERR
)
2366 for(iPos
= iCount
-1;iPos
>=0;iPos
--)
2368 SFOLDER
*tmpFolder
= (LPSFOLDER
) CBGetItemDataPtr(fodInfos
->DlgInfos
.hwndLookInCB
,iPos
);
2369 COMDLG32_SHFree(tmpFolder
->pidlItem
);
2371 CBDeleteString(fodInfos
->DlgInfos
.hwndLookInCB
,iPos
);
2375 /* LookInInfos structure */
2376 RemovePropA(fodInfos
->DlgInfos
.hwndLookInCB
,LookInInfosStr
);
2379 /***********************************************************************
2380 * FILEDLG95_FILENAME_FillFromSelection
2382 * fills the edit box from the cached DataObject
2384 void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd
)
2386 FileOpenDlgInfos
*fodInfos
;
2388 UINT nFiles
= 0, nFileToOpen
, nFileSelected
, nLength
= 0;
2389 char lpstrTemp
[MAX_PATH
];
2390 LPSTR lpstrAllFile
= NULL
, lpstrCurrFile
= NULL
;
2393 fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
2395 /* Count how many files we have */
2396 nFileSelected
= GetNumSelected( fodInfos
->Shell
.FOIDataObject
);
2398 /* calculate the string length, count files */
2399 if (nFileSelected
>= 1)
2401 nLength
+= 3; /* first and last quotes, trailing \0 */
2402 for ( nFileToOpen
= 0; nFileToOpen
< nFileSelected
; nFileToOpen
++ )
2404 pidl
= GetPidlFromDataObject( fodInfos
->Shell
.FOIDataObject
, nFileToOpen
+1 );
2408 /* get the total length of the selected file names*/
2409 lpstrTemp
[0] = '\0';
2410 GetName( fodInfos
->Shell
.FOIShellFolder
, pidl
, SHGDN_INFOLDER
|SHGDN_FORPARSING
, lpstrTemp
);
2412 if ( ! IsPidlFolder(fodInfos
->Shell
.FOIShellFolder
, pidl
) ) /* Ignore folders */
2414 nLength
+= strlen( lpstrTemp
) + 3;
2417 COMDLG32_SHFree( pidl
);
2422 /* allocate the buffer */
2423 if (nFiles
<= 1) nLength
= MAX_PATH
;
2424 lpstrAllFile
= (LPSTR
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nLength
);
2425 lpstrAllFile
[0] = '\0';
2427 /* Generate the string for the edit control */
2430 lpstrCurrFile
= lpstrAllFile
;
2431 for ( nFileToOpen
= 0; nFileToOpen
< nFileSelected
; nFileToOpen
++ )
2433 pidl
= GetPidlFromDataObject( fodInfos
->Shell
.FOIDataObject
, nFileToOpen
+1 );
2437 /* get the file name */
2438 lpstrTemp
[0] = '\0';
2439 GetName( fodInfos
->Shell
.FOIShellFolder
, pidl
, SHGDN_INFOLDER
|SHGDN_FORPARSING
, lpstrTemp
);
2441 if (! IsPidlFolder(fodInfos
->Shell
.FOIShellFolder
, pidl
)) /* Ignore folders */
2445 *lpstrCurrFile
++ = '\"';
2446 strcpy( lpstrCurrFile
, lpstrTemp
);
2447 lpstrCurrFile
+= strlen( lpstrTemp
);
2448 strcpy( lpstrCurrFile
, "\" " );
2453 strcpy( lpstrAllFile
, lpstrTemp
);
2456 COMDLG32_SHFree( (LPVOID
) pidl
);
2461 SetWindowTextA( fodInfos
->DlgInfos
.hwndFileName
, lpstrAllFile
);
2462 HeapFree(GetProcessHeap(),0, lpstrAllFile
);
2466 /* copied from shell32 to avoid linking to it */
2467 static HRESULT
COMDLG32_StrRetToStrNA (LPVOID dest
, DWORD len
, LPSTRRET src
, LPITEMIDLIST pidl
)
2472 WideCharToMultiByte(CP_ACP
, 0, src
->u
.pOleStr
, -1, (LPSTR
)dest
, len
, NULL
, NULL
);
2473 COMDLG32_SHFree(src
->u
.pOleStr
);
2477 lstrcpynA((LPSTR
)dest
, src
->u
.cStr
, len
);
2480 case STRRET_OFFSETA
:
2481 lstrcpynA((LPSTR
)dest
, ((LPCSTR
)&pidl
->mkid
)+src
->u
.uOffset
, len
);
2485 FIXME("unknown type!\n");
2488 *(LPSTR
)dest
= '\0';
2495 /***********************************************************************
2496 * FILEDLG95_FILENAME_GetFileNames
2498 * copies the filenames to a 0-delimited string list (A\0B\0C\0\0)
2500 int FILEDLG95_FILENAME_GetFileNames (HWND hwnd
, LPSTR
* lpstrFileList
, UINT
* sizeUsed
)
2502 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
2503 UINT nStrCharCount
= 0; /* index in src buffer */
2504 UINT nFileIndex
= 0; /* index in dest buffer */
2505 UINT nFileCount
= 0; /* number of files */
2506 UINT nStrLen
= 0; /* length of string in edit control */
2507 LPSTR lpstrEdit
; /* buffer for string from edit control */
2511 /* get the filenames from the edit control */
2512 nStrLen
= SendMessageA(fodInfos
->DlgInfos
.hwndFileName
, WM_GETTEXTLENGTH
, 0, 0);
2513 lpstrEdit
= MemAlloc(nStrLen
+1);
2514 GetDlgItemTextA(hwnd
, IDC_FILENAME
, lpstrEdit
, nStrLen
+1);
2516 TRACE("nStrLen=%u str=%s\n", nStrLen
, lpstrEdit
);
2518 /* we might get single filename without any '"',
2519 * so we need nStrLen + terminating \0 + end-of-list \0 */
2520 *lpstrFileList
= MemAlloc(nStrLen
+2);
2523 /* build 0-delimited file list from filenames */
2524 while ( nStrCharCount
<= nStrLen
)
2526 if ( lpstrEdit
[nStrCharCount
]=='"' )
2529 while ((lpstrEdit
[nStrCharCount
]!='"') && (nStrCharCount
<= nStrLen
))
2531 (*lpstrFileList
)[nFileIndex
++] = lpstrEdit
[nStrCharCount
];
2535 (*lpstrFileList
)[nFileIndex
++] = '\0';
2542 /* single, unquoted string */
2543 if ((nStrLen
> 0) && (*sizeUsed
== 0) )
2545 strcpy(*lpstrFileList
, lpstrEdit
);
2546 nFileIndex
= strlen(lpstrEdit
) + 1;
2547 (*sizeUsed
) = nFileIndex
;
2552 (*lpstrFileList
)[nFileIndex
] = '\0';
2559 #define SETDefFormatEtc(fe,cf,med) \
2561 (fe).cfFormat = cf;\
2562 (fe).dwAspect = DVASPECT_CONTENT; \
2569 * DATAOBJECT Helper functions
2572 /***********************************************************************
2573 * COMCTL32_ReleaseStgMedium
2575 * like ReleaseStgMedium from ole32
2577 static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium
)
2579 if(medium
.pUnkForRelease
)
2581 IUnknown_Release(medium
.pUnkForRelease
);
2585 GlobalUnlock(medium
.u
.hGlobal
);
2586 GlobalFree(medium
.u
.hGlobal
);
2590 /***********************************************************************
2591 * GetPidlFromDataObject
2593 * Return pidl(s) by number from the cached DataObject
2595 * nPidlIndex=0 gets the fully qualified root path
2597 LPITEMIDLIST
GetPidlFromDataObject ( IDataObject
*doSelected
, UINT nPidlIndex
)
2601 FORMATETC formatetc
;
2602 LPITEMIDLIST pidl
= NULL
;
2604 TRACE("sv=%p index=%u\n", doSelected
, nPidlIndex
);
2606 /* Set the FORMATETC structure*/
2607 SETDefFormatEtc(formatetc
, RegisterClipboardFormatA(CFSTR_SHELLIDLIST
), TYMED_HGLOBAL
);
2609 /* Get the pidls from IDataObject */
2610 if(SUCCEEDED(IDataObject_GetData(doSelected
,&formatetc
,&medium
)))
2612 LPIDA cida
= GlobalLock(medium
.u
.hGlobal
);
2613 if(nPidlIndex
<= cida
->cidl
)
2615 pidl
= COMDLG32_PIDL_ILClone((LPITEMIDLIST
)(&((LPBYTE
)cida
)[cida
->aoffset
[nPidlIndex
]]));
2617 COMCTL32_ReleaseStgMedium(medium
);
2622 /***********************************************************************
2625 * Return the number of selected items in the DataObject.
2628 UINT
GetNumSelected( IDataObject
*doSelected
)
2632 FORMATETC formatetc
;
2634 TRACE("sv=%p\n", doSelected
);
2636 if (!doSelected
) return 0;
2638 /* Set the FORMATETC structure*/
2639 SETDefFormatEtc(formatetc
, RegisterClipboardFormatA(CFSTR_SHELLIDLIST
), TYMED_HGLOBAL
);
2641 /* Get the pidls from IDataObject */
2642 if(SUCCEEDED(IDataObject_GetData(doSelected
,&formatetc
,&medium
)))
2644 LPIDA cida
= GlobalLock(medium
.u
.hGlobal
);
2645 retVal
= cida
->cidl
;
2646 COMCTL32_ReleaseStgMedium(medium
);
2656 /***********************************************************************
2659 * Get the pidl's display name (relative to folder) and
2660 * put it in lpstrFileName.
2662 * Return NOERROR on success,
2666 HRESULT
GetName(LPSHELLFOLDER lpsf
, LPITEMIDLIST pidl
,DWORD dwFlags
,LPSTR lpstrFileName
)
2671 TRACE("sf=%p pidl=%p\n", lpsf
, pidl
);
2676 SHGetDesktopFolder(&lpsf
);
2677 hRes
= GetName(lpsf
,pidl
,dwFlags
,lpstrFileName
);
2678 IShellFolder_Release(lpsf
);
2682 /* Get the display name of the pidl relative to the folder */
2683 if (SUCCEEDED(hRes
= IShellFolder_GetDisplayNameOf(lpsf
, pidl
, dwFlags
, &str
)))
2685 return COMDLG32_StrRetToStrNA(lpstrFileName
, MAX_PATH
, &str
, pidl
);
2690 /***********************************************************************
2691 * GetShellFolderFromPidl
2693 * pidlRel is the item pidl relative
2694 * Return the IShellFolder of the absolute pidl
2696 IShellFolder
*GetShellFolderFromPidl(LPITEMIDLIST pidlAbs
)
2698 IShellFolder
*psf
= NULL
,*psfParent
;
2700 TRACE("%p\n", pidlAbs
);
2702 if(SUCCEEDED(SHGetDesktopFolder(&psfParent
)))
2705 if(pidlAbs
&& pidlAbs
->mkid
.cb
)
2707 if(SUCCEEDED(IShellFolder_BindToObject(psfParent
, pidlAbs
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psf
)))
2709 IShellFolder_Release(psfParent
);
2713 /* return the desktop */
2719 /***********************************************************************
2722 * Return the LPITEMIDLIST to the parent of the pidl in the list
2724 LPITEMIDLIST
GetParentPidl(LPITEMIDLIST pidl
)
2726 LPITEMIDLIST pidlParent
;
2728 TRACE("%p\n", pidl
);
2730 pidlParent
= COMDLG32_PIDL_ILClone(pidl
);
2731 COMDLG32_PIDL_ILRemoveLastID(pidlParent
);
2736 /***********************************************************************
2739 * returns the pidl of the file name relative to folder
2740 * NULL if an error occurred
2742 LPITEMIDLIST
GetPidlFromName(IShellFolder
*lpsf
,LPCSTR lpcstrFileName
)
2746 WCHAR lpwstrDirName
[MAX_PATH
];
2748 TRACE("sf=%p file=%s\n", lpsf
, lpcstrFileName
);
2750 if(!lpcstrFileName
) return NULL
;
2751 if(!*lpcstrFileName
) return NULL
;
2753 MultiByteToWideChar(CP_ACP
,MB_PRECOMPOSED
,lpcstrFileName
,-1,(LPWSTR
)lpwstrDirName
,MAX_PATH
);
2757 SHGetDesktopFolder(&lpsf
);
2758 pidl
= GetPidlFromName(lpsf
, lpcstrFileName
);
2759 IShellFolder_Release(lpsf
);
2763 IShellFolder_ParseDisplayName(lpsf
, 0, NULL
, (LPWSTR
)lpwstrDirName
, &ulEaten
, &pidl
, NULL
);
2770 BOOL
IsPidlFolder (LPSHELLFOLDER psf
, LPITEMIDLIST pidl
)
2772 ULONG uAttr
= SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
;
2775 TRACE("%p, %p\n", psf
, pidl
);
2777 ret
= IShellFolder_GetAttributesOf( psf
, 1, &pidl
, &uAttr
);
2779 TRACE("-- 0x%08lx 0x%08lx\n", uAttr
, ret
);
2780 /* see documentation shell 4.1*/
2781 return uAttr
& (SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
);
2784 /***********************************************************************
2785 * BrowseSelectedFolder
2787 static BOOL
BrowseSelectedFolder(HWND hwnd
)
2789 BOOL bBrowseSelFolder
= FALSE
;
2790 FileOpenDlgInfos
*fodInfos
= (FileOpenDlgInfos
*) GetPropA(hwnd
,FileOpenDlgInfosStr
);
2794 if (GetNumSelected(fodInfos
->Shell
.FOIDataObject
) == 1)
2796 LPITEMIDLIST pidlSelection
;
2798 /* get the file selected */
2799 pidlSelection
= GetPidlFromDataObject( fodInfos
->Shell
.FOIDataObject
, 1);
2800 if (IsPidlFolder (fodInfos
->Shell
.FOIShellFolder
, pidlSelection
))
2802 if ( FAILED( IShellBrowser_BrowseObject( fodInfos
->Shell
.FOIShellBrowser
,
2803 pidlSelection
, SBSP_RELATIVE
) ) )
2805 MessageBoxA( hwnd
, "Path does not exist", fodInfos
->ofnInfos
->lpstrTitle
,
2806 MB_OK
| MB_ICONEXCLAMATION
);
2809 bBrowseSelFolder
= TRUE
;
2811 COMDLG32_SHFree( pidlSelection
);
2814 return bBrowseSelFolder
;
2818 * Memory allocation methods */
2819 static void *MemAlloc(UINT size
)
2821 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,size
);
2824 static void MemFree(void *mem
)
2828 HeapFree(GetProcessHeap(),0,mem
);