1 | /*
|
---|
2 | * COMMDLG - File Open Dialogs Win95 look and feel
|
---|
3 | *
|
---|
4 | * FIXME: The whole concept of handling unicode is badly broken.
|
---|
5 | * many hook-messages expecting a pointer to a
|
---|
6 | * OPENFILENAMEA or W structure. With the current architecture
|
---|
7 | * we would have to convert the beast at every call to a hook.
|
---|
8 | * we have to find a better solution but if would likely cause
|
---|
9 | * a complete rewrite with after we shouldhandle the
|
---|
10 | * OPENFILENAME structure without any converting (jsch).
|
---|
11 | *
|
---|
12 | * FIXME: any hook gets a OPENFILENAMEA structure
|
---|
13 | *
|
---|
14 | * FIXME: CDN_FILEOK is wrong implemented, other CDN_ messages likely too
|
---|
15 | *
|
---|
16 | * FIXME: old style hook messages are not implemented (except FILEOKSTRING)
|
---|
17 | *
|
---|
18 | * FIXME: lpstrCustomFilter not handled
|
---|
19 | *
|
---|
20 | * FIXME: if the size of lpstrFile (nMaxFile) is too small the first
|
---|
21 | * two bytes of lpstrFile should contain the needed size
|
---|
22 | *
|
---|
23 | * FIXME: algorithm for selecting the initial directory is too simple
|
---|
24 | *
|
---|
25 | * FIXME: add to recent docs
|
---|
26 | *
|
---|
27 | * FIXME: flags not implemented: OFN_CREATEPROMPT, OFN_DONTADDTORECENT,
|
---|
28 | * OFN_ENABLEINCLUDENOTIFY, OFN_ENABLESIZING, OFN_EXTENSIONDIFFERENT,
|
---|
29 | * OFN_NOCHANGEDIR, OFN_NODEREFERENCELINKS, OFN_NOREADONLYRETURN,
|
---|
30 | * OFN_NOTESTFILECREATE, OFN_OVERWRITEPROMPT, OFN_USEMONIKERS
|
---|
31 | *
|
---|
32 | * FIXME: lCustData for lpfnHook (WM_INITDIALOG)
|
---|
33 | *
|
---|
34 | *
|
---|
35 | */
|
---|
36 | #ifdef __WIN32OS2__
|
---|
37 | #include <windef.h>
|
---|
38 | #include <winbase.h>
|
---|
39 | #include <wingdi.h>
|
---|
40 | #include <winuser.h>
|
---|
41 | #include <heapstring.h>
|
---|
42 | #include <misc.h>
|
---|
43 | #include <win\shlwapi.h>
|
---|
44 |
|
---|
45 | #define MapHModuleSL(a) a
|
---|
46 | #define MapHModuleLS(a) a
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | #include <ctype.h>
|
---|
50 | #include <stdlib.h>
|
---|
51 | #include <stdio.h>
|
---|
52 | #include <string.h>
|
---|
53 |
|
---|
54 | #include "winbase.h"
|
---|
55 | #include "ntddk.h"
|
---|
56 | #include "wine/winestring.h"
|
---|
57 | #include "ldt.h"
|
---|
58 | #include "heap.h"
|
---|
59 | #include "commdlg.h"
|
---|
60 | #include "dlgs.h"
|
---|
61 | #include "cdlg.h"
|
---|
62 | #include "debugtools.h"
|
---|
63 | #include "cderr.h"
|
---|
64 | #include "tweak.h"
|
---|
65 | #include "winnls.h"
|
---|
66 | #include "shellapi.h"
|
---|
67 | #include "shlguid.h"
|
---|
68 | #include "filedlgbrowser.h"
|
---|
69 | #include "shlwapi.h"
|
---|
70 | #include "wine/obj_contextmenu.h"
|
---|
71 |
|
---|
72 | DEFAULT_DEBUG_CHANNEL(commdlg);
|
---|
73 |
|
---|
74 | #define UNIMPLEMENTED_FLAGS \
|
---|
75 | (OFN_CREATEPROMPT | OFN_DONTADDTORECENT |\
|
---|
76 | OFN_ENABLEINCLUDENOTIFY | OFN_ENABLESIZING | OFN_EXTENSIONDIFFERENT |\
|
---|
77 | OFN_NOCHANGEDIR | OFN_NODEREFERENCELINKS | OFN_NOREADONLYRETURN |\
|
---|
78 | OFN_NOTESTFILECREATE | OFN_OVERWRITEPROMPT /*| OFN_USEMONIKERS*/)
|
---|
79 |
|
---|
80 | #define IsHooked(fodInfos) \
|
---|
81 | ((fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook)
|
---|
82 | /***********************************************************************
|
---|
83 | * Data structure and global variables
|
---|
84 | */
|
---|
85 | typedef struct SFolder
|
---|
86 | {
|
---|
87 | int m_iImageIndex; /* Index of picture in image list */
|
---|
88 | HIMAGELIST hImgList;
|
---|
89 | int m_iIndent; /* Indentation index */
|
---|
90 | LPITEMIDLIST pidlItem; /* absolute pidl of the item */
|
---|
91 |
|
---|
92 | } SFOLDER,*LPSFOLDER;
|
---|
93 |
|
---|
94 | typedef struct tagLookInInfo
|
---|
95 | {
|
---|
96 | int iMaxIndentation;
|
---|
97 | UINT uSelectedItem;
|
---|
98 | } LookInInfos;
|
---|
99 |
|
---|
100 |
|
---|
101 | /***********************************************************************
|
---|
102 | * Defines and global variables
|
---|
103 | */
|
---|
104 |
|
---|
105 | /* Draw item constant */
|
---|
106 | #define ICONWIDTH 18
|
---|
107 | #define XTEXTOFFSET 3
|
---|
108 |
|
---|
109 | /* AddItem flags*/
|
---|
110 | #define LISTEND -1
|
---|
111 |
|
---|
112 | /* SearchItem methods */
|
---|
113 | #define SEARCH_PIDL 1
|
---|
114 | #define SEARCH_EXP 2
|
---|
115 | #define ITEM_NOTFOUND -1
|
---|
116 |
|
---|
117 | /* Undefined windows message sent by CreateViewObject*/
|
---|
118 | #define WM_GETISHELLBROWSER WM_USER+7
|
---|
119 |
|
---|
120 | /* NOTE
|
---|
121 | * Those macros exist in windowsx.h. However, you can't really use them since
|
---|
122 | * they rely on the UNICODE defines and can't be used inside Wine itself.
|
---|
123 | */
|
---|
124 |
|
---|
125 | /* Combo box macros */
|
---|
126 | #define CBAddString(hwnd,str) \
|
---|
127 | SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str);
|
---|
128 |
|
---|
129 | #define CBInsertString(hwnd,str,pos) \
|
---|
130 | SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str);
|
---|
131 |
|
---|
132 | #define CBDeleteString(hwnd,pos) \
|
---|
133 | SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0);
|
---|
134 |
|
---|
135 | #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
|
---|
136 | SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr);
|
---|
137 |
|
---|
138 | #define CBGetItemDataPtr(hwnd,iItemId) \
|
---|
139 | SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0)
|
---|
140 |
|
---|
141 | #define CBGetLBText(hwnd,iItemId,str) \
|
---|
142 | SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str);
|
---|
143 |
|
---|
144 | #define CBGetCurSel(hwnd) \
|
---|
145 | SendMessageA(hwnd,CB_GETCURSEL,0,0);
|
---|
146 |
|
---|
147 | #define CBSetCurSel(hwnd,pos) \
|
---|
148 | SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0);
|
---|
149 |
|
---|
150 | #define CBGetCount(hwnd) \
|
---|
151 | SendMessageA(hwnd,CB_GETCOUNT,0,0);
|
---|
152 | #define CBShowDropDown(hwnd,show) \
|
---|
153 | SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0);
|
---|
154 | #define CBSetItemHeight(hwnd,index,height) \
|
---|
155 | SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height);
|
---|
156 |
|
---|
157 |
|
---|
158 | const char *FileOpenDlgInfosStr = "FileOpenDlgInfos"; /* windows property description string */
|
---|
159 | const char *LookInInfosStr = "LookInInfos"; /* LOOKIN combo box property */
|
---|
160 |
|
---|
161 | static const char defaultFilter[] = "*.*";
|
---|
162 |
|
---|
163 | /***********************************************************************
|
---|
164 | * Prototypes
|
---|
165 | */
|
---|
166 |
|
---|
167 | /* Internal functions used by the dialog */
|
---|
168 | static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam);
|
---|
169 | static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
|
---|
170 | static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd);
|
---|
171 | BOOL FILEDLG95_OnOpen(HWND hwnd);
|
---|
172 | static LRESULT FILEDLG95_InitControls(HWND hwnd);
|
---|
173 | static void FILEDLG95_Clean(HWND hwnd);
|
---|
174 |
|
---|
175 | /* Functions used by the shell navigation */
|
---|
176 | static LRESULT FILEDLG95_SHELL_Init(HWND hwnd);
|
---|
177 | static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd);
|
---|
178 | static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb);
|
---|
179 | static void FILEDLG95_SHELL_Clean(HWND hwnd);
|
---|
180 | static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd);
|
---|
181 |
|
---|
182 | /* Functions used by the filetype combo box */
|
---|
183 | static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd);
|
---|
184 | static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode);
|
---|
185 | static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt);
|
---|
186 | static void FILEDLG95_FILETYPE_Clean(HWND hwnd);
|
---|
187 |
|
---|
188 | /* Functions used by the Look In combo box */
|
---|
189 | static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo);
|
---|
190 | static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);
|
---|
191 | static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);
|
---|
192 | static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);
|
---|
193 | static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod);
|
---|
194 | static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl);
|
---|
195 | static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd);
|
---|
196 | int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
|
---|
197 | static void FILEDLG95_LOOKIN_Clean(HWND hwnd);
|
---|
198 |
|
---|
199 | /* Miscellaneous tool functions */
|
---|
200 | HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
|
---|
201 | HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
|
---|
202 | IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
|
---|
203 | LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
|
---|
204 | LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
|
---|
205 |
|
---|
206 | /* Shell memory allocation */
|
---|
207 | static void *MemAlloc(UINT size);
|
---|
208 | static void MemFree(void *mem);
|
---|
209 |
|
---|
210 | BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos);
|
---|
211 | HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
---|
212 | HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
|
---|
213 | HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
---|
214 | BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);
|
---|
215 | static BOOL BrowseSelectedFolder(HWND hwnd);
|
---|
216 |
|
---|
217 | /***********************************************************************
|
---|
218 | * GetFileName95
|
---|
219 | *
|
---|
220 | * Creates an Open common dialog box that lets the user select
|
---|
221 | * the drive, directory, and the name of a file or set of files to open.
|
---|
222 | *
|
---|
223 | * IN : The FileOpenDlgInfos structure associated with the dialog
|
---|
224 | * OUT : TRUE on success
|
---|
225 | * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
|
---|
226 | */
|
---|
227 | BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)
|
---|
228 | {
|
---|
229 |
|
---|
230 | LRESULT lRes;
|
---|
231 | LPCVOID template;
|
---|
232 | HRSRC hRes;
|
---|
233 | HANDLE hDlgTmpl = 0;
|
---|
234 |
|
---|
235 | /* test for missing functionality */
|
---|
236 | if (fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS)
|
---|
237 | {
|
---|
238 | FIXME("Flags 0x%08lx not yet implemented\n",
|
---|
239 | fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS);
|
---|
240 | }
|
---|
241 |
|
---|
242 | /* Create the dialog from a template */
|
---|
243 |
|
---|
244 | if(!(hRes = FindResourceA(COMMDLG_hInstance32,MAKEINTRESOURCEA(NEWFILEOPENORD),RT_DIALOGA)))
|
---|
245 | {
|
---|
246 | COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
|
---|
247 | return FALSE;
|
---|
248 | }
|
---|
249 | if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hRes )) ||
|
---|
250 | !(template = LockResource( hDlgTmpl )))
|
---|
251 | {
|
---|
252 | COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
|
---|
253 | return FALSE;
|
---|
254 | }
|
---|
255 |
|
---|
256 | /* old style hook messages */
|
---|
257 | if (IsHooked(fodInfos))
|
---|
258 | {
|
---|
259 | fodInfos->HookMsg.fileokstring = RegisterWindowMessageA(FILEOKSTRING);
|
---|
260 | fodInfos->HookMsg.lbselchstring = RegisterWindowMessageA(LBSELCHSTRING);
|
---|
261 | fodInfos->HookMsg.helpmsgstring = RegisterWindowMessageA(HELPMSGSTRING);
|
---|
262 | fodInfos->HookMsg.sharevistring = RegisterWindowMessageA(SHAREVISTRING);
|
---|
263 | }
|
---|
264 |
|
---|
265 | lRes = DialogBoxIndirectParamA(COMMDLG_hInstance32,
|
---|
266 | (LPDLGTEMPLATEA) template,
|
---|
267 | fodInfos->ofnInfos->hwndOwner,
|
---|
268 | (DLGPROC) FileOpenDlgProc95,
|
---|
269 | (LPARAM) fodInfos);
|
---|
270 |
|
---|
271 | /* Unable to create the dialog */
|
---|
272 | if( lRes == -1)
|
---|
273 | return FALSE;
|
---|
274 |
|
---|
275 | return lRes;
|
---|
276 | }
|
---|
277 |
|
---|
278 | /***********************************************************************
|
---|
279 | * GetFileDialog95A
|
---|
280 | *
|
---|
281 | * Call GetFileName95 with this structure and clean the memory.
|
---|
282 | *
|
---|
283 | * IN : The OPENFILENAMEA initialisation structure passed to
|
---|
284 | * GetOpenFileNameA win api function (see filedlg.c)
|
---|
285 | */
|
---|
286 | BOOL WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
|
---|
287 | {
|
---|
288 |
|
---|
289 | BOOL ret;
|
---|
290 | FileOpenDlgInfos *fodInfos;
|
---|
291 | HINSTANCE hInstance;
|
---|
292 | LPCSTR lpstrInitialDir = (LPCSTR)-1;
|
---|
293 | LPSTR lpstrSavDir = NULL;
|
---|
294 | DWORD dwFlags = 0;
|
---|
295 |
|
---|
296 | /* Initialise FileOpenDlgInfos structure*/
|
---|
297 | fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
|
---|
298 | ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
|
---|
299 |
|
---|
300 | /* Pass in the original ofn */
|
---|
301 | fodInfos->ofnInfos = ofn;
|
---|
302 |
|
---|
303 | /* Save original hInstance value */
|
---|
304 | hInstance = ofn->hInstance;
|
---|
305 | fodInfos->ofnInfos->hInstance = MapHModuleLS(ofn->hInstance);
|
---|
306 |
|
---|
307 | /* save current directory */
|
---|
308 | if (ofn->Flags & OFN_NOCHANGEDIR)
|
---|
309 | {
|
---|
310 | lpstrSavDir = MemAlloc(MAX_PATH);
|
---|
311 | GetCurrentDirectoryA(MAX_PATH, lpstrSavDir);
|
---|
312 | }
|
---|
313 |
|
---|
314 | dwFlags = ofn->Flags;
|
---|
315 | ofn->Flags = ofn->Flags|OFN_WINE;
|
---|
316 |
|
---|
317 | /* Initialise the dialog property */
|
---|
318 | fodInfos->DlgInfos.dwDlgProp = 0;
|
---|
319 | fodInfos->DlgInfos.hwndCustomDlg = (HWND)NULL;
|
---|
320 |
|
---|
321 | switch(iDlgType)
|
---|
322 | {
|
---|
323 | case OPEN_DIALOG :
|
---|
324 | ret = GetFileName95(fodInfos);
|
---|
325 | break;
|
---|
326 | case SAVE_DIALOG :
|
---|
327 | fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
|
---|
328 | ret = GetFileName95(fodInfos);
|
---|
329 | break;
|
---|
330 | default :
|
---|
331 | ret = 0;
|
---|
332 | }
|
---|
333 |
|
---|
334 | if (lpstrSavDir)
|
---|
335 | {
|
---|
336 | SetCurrentDirectoryA(lpstrSavDir);
|
---|
337 | MemFree(lpstrSavDir);
|
---|
338 | }
|
---|
339 |
|
---|
340 | if (lpstrInitialDir != (LPCSTR)-1)
|
---|
341 | {
|
---|
342 | MemFree((LPVOID)(ofn->lpstrInitialDir));
|
---|
343 | ofn->lpstrInitialDir = lpstrInitialDir;
|
---|
344 | }
|
---|
345 |
|
---|
346 | ofn->Flags = dwFlags;
|
---|
347 | ofn->hInstance = hInstance;
|
---|
348 | MemFree((LPVOID)(fodInfos));
|
---|
349 | return ret;
|
---|
350 | }
|
---|
351 |
|
---|
352 | /***********************************************************************
|
---|
353 | * GetFileDialog95W
|
---|
354 | *
|
---|
355 | * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
|
---|
356 | * Call GetFileName95 with this structure and clean the memory.
|
---|
357 | *
|
---|
358 | * FIXME: lpstrCustomFilter has to converted back
|
---|
359 | *
|
---|
360 | */
|
---|
361 |
|
---|
362 | /* converting IN arguments */
|
---|
363 | #define AllocInArgWtoA(arg, save) \
|
---|
364 | if(arg) \
|
---|
365 | { \
|
---|
366 | save = arg; \
|
---|
367 | arg = MemAlloc(lstrlenW(arg)); \
|
---|
368 | lstrcpyWtoA((LPSTR)arg, save); \
|
---|
369 | }
|
---|
370 |
|
---|
371 | #define FreeInArg(arg, save) \
|
---|
372 | if(arg) \
|
---|
373 | { \
|
---|
374 | MemFree((LPSTR)arg); \
|
---|
375 | arg = save; \
|
---|
376 | }
|
---|
377 |
|
---|
378 | /* converting OUT arguments */
|
---|
379 | #define AllocOutArgWtoA(arg, save, len) \
|
---|
380 | if(arg) \
|
---|
381 | { \
|
---|
382 | save = arg; \
|
---|
383 | arg = MemAlloc(len); \
|
---|
384 | }
|
---|
385 |
|
---|
386 | #define FreeOutArg(arg, save, len) \
|
---|
387 | if(arg) \
|
---|
388 | { \
|
---|
389 | lstrcpynAtoW(save, (LPCSTR)arg, len); \
|
---|
390 | MemFree(arg); \
|
---|
391 | arg = save; \
|
---|
392 | }
|
---|
393 |
|
---|
394 | BOOL WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
|
---|
395 | {
|
---|
396 | BOOL ret;
|
---|
397 | FileOpenDlgInfos *fodInfos;
|
---|
398 | HINSTANCE hInstance;
|
---|
399 | #ifdef __WIN32OS2__
|
---|
400 | LPSTR lpstrSavDir = NULL;
|
---|
401 | #endif
|
---|
402 | /* out arguments */
|
---|
403 | LPWSTR lpstrFile = NULL;
|
---|
404 | LPWSTR lpstrFileTitle = NULL;
|
---|
405 |
|
---|
406 | /* in/out arguments */
|
---|
407 | LPWSTR lpstrCustomFilter = NULL;
|
---|
408 |
|
---|
409 | /* input arguments */
|
---|
410 | LPCWSTR lpstrFilter = NULL;
|
---|
411 | LPCWSTR lpstrInitialDir = NULL;
|
---|
412 | LPCWSTR lpstrTitle = NULL;
|
---|
413 | LPCWSTR lpstrDefExt = NULL;
|
---|
414 | LPCWSTR lpTemplateName = NULL;
|
---|
415 | DWORD dwFlags;
|
---|
416 |
|
---|
417 | /* Initialise FileOpenDlgInfos structure*/
|
---|
418 | fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
|
---|
419 | ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
|
---|
420 |
|
---|
421 | /* Pass in the original ofn */
|
---|
422 | fodInfos->ofnInfos = (LPOPENFILENAMEA) ofn;
|
---|
423 |
|
---|
424 | /* convert lpstrFilter */
|
---|
425 | if (ofn->lpstrFilter)
|
---|
426 | {
|
---|
427 | LPCWSTR s;
|
---|
428 | LPSTR x, y;
|
---|
429 | int n;
|
---|
430 |
|
---|
431 | lpstrFilter = ofn->lpstrFilter;
|
---|
432 |
|
---|
433 | /* filter is a list... title\0ext\0......\0\0 */
|
---|
434 | s = ofn->lpstrFilter;
|
---|
435 |
|
---|
436 | while (*s) s = s+lstrlenW(s)+1;
|
---|
437 | s++;
|
---|
438 | n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
|
---|
439 | x = y = (LPSTR)MemAlloc(n);
|
---|
440 | s = (LPWSTR)ofn->lpstrFilter;
|
---|
441 | while (*s)
|
---|
442 | {
|
---|
443 | lstrcpyWtoA(x,s);
|
---|
444 | x+=strlen(x)+1;
|
---|
445 | s+=lstrlenW(s)+1;
|
---|
446 | }
|
---|
447 | *x=0;
|
---|
448 | #ifdef __WIN32OS2__
|
---|
449 | ofn->lpstrFilter = (LPWSTR)y;
|
---|
450 | #else
|
---|
451 | (LPSTR)ofn->lpstrFilter = y;
|
---|
452 | #endif
|
---|
453 | }
|
---|
454 |
|
---|
455 | /* convert lpstrCustomFilter */
|
---|
456 | if (ofn->lpstrCustomFilter)
|
---|
457 | {
|
---|
458 | LPWSTR s;
|
---|
459 | LPSTR x,y;
|
---|
460 | int n;
|
---|
461 |
|
---|
462 | lpstrCustomFilter = ofn->lpstrCustomFilter;
|
---|
463 | /* filter is a list... title\0ext\0......\0\0 */
|
---|
464 | s = ofn->lpstrCustomFilter;
|
---|
465 | while (*s) s = s+lstrlenW(s)+1;
|
---|
466 | s++;
|
---|
467 | n = s - ofn->lpstrCustomFilter;
|
---|
468 | x = y = (LPSTR)MemAlloc(n);
|
---|
469 | s = ofn->lpstrCustomFilter;
|
---|
470 | while (*s)
|
---|
471 | {
|
---|
472 | lstrcpyWtoA(x,s);
|
---|
473 | x+=strlen(x)+1;
|
---|
474 | s+=lstrlenW(s)+1;
|
---|
475 | }
|
---|
476 | *x=0;
|
---|
477 | #ifdef __WIN32OS2__
|
---|
478 | ofn->lpstrCustomFilter = (LPWSTR)y;
|
---|
479 | #else
|
---|
480 | (LPSTR)ofn->lpstrCustomFilter = y;
|
---|
481 | #endif
|
---|
482 | }
|
---|
483 |
|
---|
484 | /* convert string arguments, save others */
|
---|
485 | AllocOutArgWtoA(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
|
---|
486 | AllocOutArgWtoA(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
|
---|
487 | AllocInArgWtoA(ofn->lpstrInitialDir, lpstrInitialDir);
|
---|
488 | AllocInArgWtoA(ofn->lpstrTitle, lpstrTitle);
|
---|
489 | AllocInArgWtoA(ofn->lpstrDefExt, lpstrDefExt);
|
---|
490 | AllocInArgWtoA(ofn->lpTemplateName, lpTemplateName);
|
---|
491 | dwFlags = ofn->Flags;
|
---|
492 | hInstance = ofn->hInstance;
|
---|
493 |
|
---|
494 | #ifdef __WIN32OS2__
|
---|
495 | /* save current directory */
|
---|
496 | if (ofn->Flags & OFN_NOCHANGEDIR)
|
---|
497 | {
|
---|
498 | lpstrSavDir = MemAlloc(MAX_PATH);
|
---|
499 | GetCurrentDirectoryA(MAX_PATH, lpstrSavDir);
|
---|
500 | }
|
---|
501 | #endif
|
---|
502 |
|
---|
503 | ofn->Flags = ofn->Flags|OFN_WINE|OFN_UNICODE;
|
---|
504 | ofn->hInstance = MapHModuleLS(ofn->hInstance);
|
---|
505 |
|
---|
506 | switch(iDlgType)
|
---|
507 | {
|
---|
508 | case OPEN_DIALOG :
|
---|
509 | ret = GetFileName95(fodInfos);
|
---|
510 | break;
|
---|
511 | case SAVE_DIALOG :
|
---|
512 | fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
|
---|
513 | ret = GetFileName95(fodInfos);
|
---|
514 | break;
|
---|
515 | default :
|
---|
516 | ret = 0;
|
---|
517 | }
|
---|
518 |
|
---|
519 | #ifdef __WIN32OS2__
|
---|
520 | if (lpstrSavDir)
|
---|
521 | {
|
---|
522 | SetCurrentDirectoryA(lpstrSavDir);
|
---|
523 | MemFree(lpstrSavDir);
|
---|
524 | }
|
---|
525 | #endif
|
---|
526 |
|
---|
527 | /* restore saved IN arguments and convert OUT arguments back */
|
---|
528 | ofn->Flags = dwFlags;
|
---|
529 | ofn->hInstance = hInstance;
|
---|
530 | FreeInArg(ofn->lpstrFilter, lpstrFilter);
|
---|
531 | FreeInArg(ofn->lpstrCustomFilter, lpstrCustomFilter);
|
---|
532 | FreeOutArg(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
|
---|
533 | FreeOutArg(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
|
---|
534 | FreeInArg(ofn->lpstrInitialDir, lpstrInitialDir);
|
---|
535 | FreeInArg(ofn->lpstrTitle, lpstrTitle);
|
---|
536 | FreeInArg(ofn->lpstrDefExt, lpstrDefExt);
|
---|
537 | FreeInArg(ofn->lpTemplateName, lpTemplateName);
|
---|
538 |
|
---|
539 | MemFree((LPVOID)(fodInfos));
|
---|
540 | return ret;
|
---|
541 | }
|
---|
542 |
|
---|
543 | void ArrangeCtrlPositions( HWND hwndChildDlg, HWND hwndParentDlg)
|
---|
544 | {
|
---|
545 | HWND hwndChild,hwndStc32;
|
---|
546 | RECT rectParent, rectChild, rectCtrl, rectStc32, rectTemp;
|
---|
547 | POINT ptMoveCtl;
|
---|
548 | POINT ptParentClient;
|
---|
549 |
|
---|
550 | TRACE("\n");
|
---|
551 |
|
---|
552 | ptMoveCtl.x = ptMoveCtl.y = 0;
|
---|
553 | hwndStc32=GetDlgItem(hwndChildDlg,stc32);
|
---|
554 | GetClientRect(hwndParentDlg,&rectParent);
|
---|
555 | GetClientRect(hwndChildDlg,&rectChild);
|
---|
556 |
|
---|
557 | if(hwndStc32)
|
---|
558 | {
|
---|
559 | GetWindowRect(hwndStc32,&rectStc32);
|
---|
560 | MapWindowPoints(0, hwndChildDlg,(LPPOINT)&rectStc32,2);
|
---|
561 | CopyRect(&rectTemp,&rectStc32);
|
---|
562 |
|
---|
563 | SetRect(&rectStc32,rectStc32.left,rectStc32.top,rectStc32.left + (rectParent.right-rectParent.left),rectStc32.top+(rectParent.bottom-rectParent.top));
|
---|
564 | SetWindowPos(hwndStc32,0,rectStc32.left,rectStc32.top,rectStc32.right-rectStc32.left,rectStc32.bottom-rectStc32.top,SWP_NOMOVE|SWP_NOZORDER | SWP_NOACTIVATE);
|
---|
565 |
|
---|
566 | if(rectStc32.right < rectTemp.right)
|
---|
567 | {
|
---|
568 | ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
|
---|
569 | ptMoveCtl.x = 0;
|
---|
570 | }
|
---|
571 | else
|
---|
572 | {
|
---|
573 | ptMoveCtl.x = (rectStc32.right - rectTemp.right);
|
---|
574 | ptParentClient.x = max((rectParent.right-rectParent.left),((rectChild.right-rectChild.left)+rectStc32.right-rectTemp.right));
|
---|
575 | }
|
---|
576 |
|
---|
577 | if(rectStc32.bottom < rectTemp.bottom)
|
---|
578 | {
|
---|
579 | ptParentClient.y = max((rectParent.bottom-rectParent.top),(rectChild.bottom-rectChild.top));
|
---|
580 | ptMoveCtl.y = 0;
|
---|
581 | }
|
---|
582 | else
|
---|
583 | {
|
---|
584 | ptMoveCtl.y = (rectStc32.bottom - rectTemp.bottom);
|
---|
585 | ptParentClient.y = max((rectParent.bottom-rectParent.top),((rectChild.bottom-rectChild.top)+rectStc32.bottom-rectTemp.bottom));
|
---|
586 | }
|
---|
587 | }
|
---|
588 | else
|
---|
589 | {
|
---|
590 | if( (GetWindow(hwndChildDlg,GW_CHILD)) == (HWND) NULL) return;
|
---|
591 |
|
---|
592 | SetRectEmpty(&rectTemp);
|
---|
593 | ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
|
---|
594 | ptParentClient.y = (rectParent.bottom-rectParent.top) + (rectChild.bottom-rectChild.top);
|
---|
595 | ptMoveCtl.y = rectParent.bottom-rectParent.top;
|
---|
596 | ptMoveCtl.x=0;
|
---|
597 | }
|
---|
598 | SetRect(&rectParent,rectParent.left,rectParent.top,rectParent.left+ptParentClient.x,rectParent.top+ptParentClient.y);
|
---|
599 | AdjustWindowRectEx( &rectParent,GetWindowLongA(hwndParentDlg,GWL_STYLE),FALSE,GetWindowLongA(hwndParentDlg,GWL_EXSTYLE));
|
---|
600 |
|
---|
601 | SetWindowPos(hwndChildDlg, 0, 0,0, ptParentClient.x,ptParentClient.y, SWP_NOZORDER );
|
---|
602 | SetWindowPos(hwndParentDlg, 0, rectParent.left,rectParent.top, (rectParent.right- rectParent.left),
|
---|
603 | (rectParent.bottom-rectParent.top),SWP_NOMOVE | SWP_NOZORDER);
|
---|
604 |
|
---|
605 | hwndChild = GetWindow(hwndChildDlg,GW_CHILD);
|
---|
606 | if(hwndStc32)
|
---|
607 | {
|
---|
608 | GetWindowRect(hwndStc32,&rectStc32);
|
---|
609 | MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
|
---|
610 | }
|
---|
611 | else
|
---|
612 | SetRect(&rectStc32,0,0,0,0);
|
---|
613 |
|
---|
614 | if (hwndChild )
|
---|
615 | {
|
---|
616 | do
|
---|
617 | {
|
---|
618 | if(hwndChild != hwndStc32)
|
---|
619 | {
|
---|
620 | if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
|
---|
621 | continue;
|
---|
622 | GetWindowRect(hwndChild,&rectCtrl);
|
---|
623 | MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
|
---|
624 |
|
---|
625 | /*
|
---|
626 | Check the initial position of the controls relative to the initial
|
---|
627 | position and size of stc32 (before it is expanded).
|
---|
628 | */
|
---|
629 | if (rectCtrl.left >= rectTemp.right && rectCtrl.top >= rectTemp.bottom)
|
---|
630 | {
|
---|
631 | rectCtrl.left += ptMoveCtl.x;
|
---|
632 | rectCtrl.top += ptMoveCtl.y;
|
---|
633 | }
|
---|
634 | else if (rectCtrl.left >= rectTemp.right)
|
---|
635 | {
|
---|
636 | rectCtrl.left += ptMoveCtl.x;
|
---|
637 | }
|
---|
638 | else if (rectCtrl.top >= rectTemp.bottom)
|
---|
639 | {
|
---|
640 | rectCtrl.top += ptMoveCtl.y;
|
---|
641 | }
|
---|
642 |
|
---|
643 | SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
|
---|
644 | rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
|
---|
645 | SWP_NOSIZE | SWP_NOZORDER );
|
---|
646 | }
|
---|
647 | } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
|
---|
648 | }
|
---|
649 | hwndChild = GetWindow(hwndParentDlg,GW_CHILD);
|
---|
650 |
|
---|
651 | if(hwndStc32)
|
---|
652 | {
|
---|
653 | GetWindowRect(hwndStc32,&rectStc32);
|
---|
654 | MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
|
---|
655 | ptMoveCtl.x = rectStc32.left - 0;
|
---|
656 | ptMoveCtl.y = rectStc32.top - 0;
|
---|
657 | if (hwndChild )
|
---|
658 | {
|
---|
659 | do
|
---|
660 | {
|
---|
661 | if(hwndChild != hwndChildDlg)
|
---|
662 | {
|
---|
663 | if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
|
---|
664 | continue;
|
---|
665 | GetWindowRect(hwndChild,&rectCtrl);
|
---|
666 | MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
|
---|
667 |
|
---|
668 | rectCtrl.left += ptMoveCtl.x;
|
---|
669 | rectCtrl.top += ptMoveCtl.y;
|
---|
670 |
|
---|
671 | SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
|
---|
672 | rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
|
---|
673 | SWP_NOSIZE |SWP_NOZORDER );
|
---|
674 | }
|
---|
675 | } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
|
---|
676 | }
|
---|
677 | }
|
---|
678 | }
|
---|
679 |
|
---|
680 |
|
---|
681 | HRESULT WINAPI FileOpenDlgProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
682 | {
|
---|
683 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(GetParent(hwnd),FileOpenDlgInfosStr);
|
---|
684 |
|
---|
685 | #if 0
|
---|
686 | TRACE("0x%04x\n", uMsg);
|
---|
687 | #endif
|
---|
688 |
|
---|
689 | switch(uMsg)
|
---|
690 | {
|
---|
691 | case WM_INITDIALOG:
|
---|
692 | {
|
---|
693 | fodInfos = (FileOpenDlgInfos *)lParam;
|
---|
694 | lParam = (LPARAM) fodInfos->ofnInfos;
|
---|
695 | ArrangeCtrlPositions(hwnd,GetParent(hwnd));
|
---|
696 |
|
---|
697 | if(fodInfos && IsHooked(fodInfos))
|
---|
698 | return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
|
---|
699 | return 0;
|
---|
700 | }
|
---|
701 | }
|
---|
702 |
|
---|
703 | if(fodInfos && IsHooked(fodInfos))
|
---|
704 | return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
|
---|
705 |
|
---|
706 | return DefWindowProcA(hwnd,uMsg,wParam,lParam);
|
---|
707 | }
|
---|
708 |
|
---|
709 | HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos, HWND hwnd)
|
---|
710 | {
|
---|
711 | LPCVOID template;
|
---|
712 | HRSRC hRes;
|
---|
713 | HANDLE hDlgTmpl = 0;
|
---|
714 | HWND hChildDlg = 0;
|
---|
715 |
|
---|
716 | TRACE("\n");
|
---|
717 |
|
---|
718 | if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATE ||
|
---|
719 | fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
|
---|
720 | {
|
---|
721 | if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
|
---|
722 | {
|
---|
723 | if( !(template = LockResource( fodInfos->ofnInfos->hInstance)))
|
---|
724 | {
|
---|
725 | COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
|
---|
726 | return (HWND)NULL;
|
---|
727 | }
|
---|
728 | }
|
---|
729 | else
|
---|
730 | {
|
---|
731 | if (!(hRes = FindResourceA(MapHModuleSL(fodInfos->ofnInfos->hInstance),
|
---|
732 | (fodInfos->ofnInfos->lpTemplateName), RT_DIALOGA)))
|
---|
733 | {
|
---|
734 | COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
|
---|
735 | return (HWND)NULL;
|
---|
736 | }
|
---|
737 | if (!(hDlgTmpl = LoadResource( MapHModuleSL(fodInfos->ofnInfos->hInstance),
|
---|
738 | hRes )) || !(template = LockResource( hDlgTmpl )))
|
---|
739 | {
|
---|
740 | COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
|
---|
741 | return (HWND)NULL;
|
---|
742 | }
|
---|
743 | }
|
---|
744 |
|
---|
745 | hChildDlg= CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,template,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
|
---|
746 | if(hChildDlg)
|
---|
747 | {
|
---|
748 | ShowWindow(hChildDlg,SW_SHOW);
|
---|
749 | return hChildDlg;
|
---|
750 | }
|
---|
751 | }
|
---|
752 | else if( IsHooked(fodInfos))
|
---|
753 | {
|
---|
754 | RECT rectHwnd;
|
---|
755 | DLGTEMPLATE tmplate;
|
---|
756 | GetClientRect(hwnd,&rectHwnd);
|
---|
757 | tmplate.style = WS_CHILD | WS_CLIPSIBLINGS;
|
---|
758 | tmplate.dwExtendedStyle = 0;
|
---|
759 | tmplate.cdit = 0;
|
---|
760 | tmplate.x = 0;
|
---|
761 | tmplate.y = 0;
|
---|
762 | tmplate.cx = rectHwnd.right-rectHwnd.left;
|
---|
763 | tmplate.cy = rectHwnd.bottom-rectHwnd.top;
|
---|
764 |
|
---|
765 | return CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,&tmplate,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
|
---|
766 | }
|
---|
767 | return (HWND)NULL;
|
---|
768 | }
|
---|
769 |
|
---|
770 | /***********************************************************************
|
---|
771 | * SendCustomDlgNotificationMessage
|
---|
772 | *
|
---|
773 | * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
|
---|
774 | */
|
---|
775 |
|
---|
776 | HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
|
---|
777 | {
|
---|
778 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndParentDlg,FileOpenDlgInfosStr);
|
---|
779 |
|
---|
780 | TRACE("0x%04x 0x%04x\n",hwndParentDlg, uCode);
|
---|
781 |
|
---|
782 | if(!fodInfos) return 0;
|
---|
783 |
|
---|
784 | if(fodInfos->ofnInfos->Flags & OFN_UNICODE)
|
---|
785 | FIXME("sending OPENFILENAMEA structure. Hook is expecting OPENFILENAMEW!");
|
---|
786 |
|
---|
787 | if(fodInfos->DlgInfos.hwndCustomDlg)
|
---|
788 | {
|
---|
789 | OFNOTIFYA ofnNotify;
|
---|
790 | HRESULT ret;
|
---|
791 | ofnNotify.hdr.hwndFrom=hwndParentDlg;
|
---|
792 | ofnNotify.hdr.idFrom=0;
|
---|
793 | ofnNotify.hdr.code = uCode;
|
---|
794 | ofnNotify.lpOFN = fodInfos->ofnInfos;
|
---|
795 | TRACE("CALL NOTIFY for %x\n", uCode);
|
---|
796 | ret = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);
|
---|
797 | TRACE("RET NOTIFY\n");
|
---|
798 | return ret;
|
---|
799 | }
|
---|
800 | return TRUE;
|
---|
801 | }
|
---|
802 |
|
---|
803 | /***********************************************************************
|
---|
804 | * FILEDLG95_HandleCustomDialogMessages
|
---|
805 | *
|
---|
806 | * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
|
---|
807 | */
|
---|
808 | HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
809 | {
|
---|
810 | LPSTR lpstrFileSpec;
|
---|
811 | int reqSize;
|
---|
812 | char lpstrPath[MAX_PATH];
|
---|
813 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
814 | if(!fodInfos) return -1;
|
---|
815 |
|
---|
816 | switch(uMsg)
|
---|
817 | {
|
---|
818 | case CDM_GETFILEPATH:
|
---|
819 | GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
|
---|
820 | lpstrFileSpec = (LPSTR)COMDLG32_PathFindFileNameA(lpstrPath);
|
---|
821 | if (lpstrFileSpec==lpstrPath)
|
---|
822 | {
|
---|
823 | char lpstrCurrentDir[MAX_PATH];
|
---|
824 | /* Prepend the current path */
|
---|
825 | COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrCurrentDir);
|
---|
826 | if ((LPSTR)lParam!=NULL)
|
---|
827 | wsnprintfA((LPSTR)lParam,(int)wParam,"%s\\%s",lpstrCurrentDir,lpstrPath);
|
---|
828 | reqSize=strlen(lpstrCurrentDir)+1+strlen(lpstrPath)+1;
|
---|
829 | }
|
---|
830 | else
|
---|
831 | {
|
---|
832 | lstrcpynA((LPSTR)lParam,(LPSTR)lpstrPath,(int)wParam);
|
---|
833 | reqSize=strlen(lpstrPath);
|
---|
834 | }
|
---|
835 | /* return the required buffer size */
|
---|
836 | return reqSize;
|
---|
837 |
|
---|
838 | case CDM_GETFOLDERPATH:
|
---|
839 | COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);
|
---|
840 | if ((LPSTR)lParam!=NULL)
|
---|
841 | lstrcpynA((LPSTR)lParam,lpstrPath,(int)wParam);
|
---|
842 | return strlen(lpstrPath);
|
---|
843 |
|
---|
844 | case CDM_GETSPEC:
|
---|
845 | reqSize=GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
|
---|
846 | lpstrFileSpec = (LPSTR)COMDLG32_PathFindFileNameA(lpstrPath);
|
---|
847 | if ((LPSTR)lParam!=NULL)
|
---|
848 | lstrcpynA((LPSTR)lParam, lpstrFileSpec, (int)wParam);
|
---|
849 | return strlen(lpstrFileSpec);
|
---|
850 |
|
---|
851 | case CDM_SETCONTROLTEXT:
|
---|
852 | if ( 0 != lParam )
|
---|
853 | SetDlgItemTextA( hwnd, (UINT) wParam, (LPSTR) lParam );
|
---|
854 | return TRUE;
|
---|
855 |
|
---|
856 | case CDM_HIDECONTROL:
|
---|
857 | case CDM_SETDEFEXT:
|
---|
858 | FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");
|
---|
859 | return -1;
|
---|
860 | }
|
---|
861 | return TRUE;
|
---|
862 | }
|
---|
863 |
|
---|
864 | /***********************************************************************
|
---|
865 | * FileOpenDlgProc95
|
---|
866 | *
|
---|
867 | * File open dialog procedure
|
---|
868 | */
|
---|
869 | HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
870 | {
|
---|
871 | #if 0
|
---|
872 | TRACE("0x%04x 0x%04x\n", hwnd, uMsg);
|
---|
873 | #endif
|
---|
874 |
|
---|
875 | switch(uMsg)
|
---|
876 | {
|
---|
877 | case WM_INITDIALOG:
|
---|
878 | {
|
---|
879 | FileOpenDlgInfos * fodInfos = (FileOpenDlgInfos *)lParam;
|
---|
880 |
|
---|
881 | /* Adds the FileOpenDlgInfos in the property list of the dialog
|
---|
882 | so it will be easily accessible through a GetPropA(...) */
|
---|
883 | SetPropA(hwnd, FileOpenDlgInfosStr, (HANDLE) fodInfos);
|
---|
884 |
|
---|
885 | fodInfos->DlgInfos.hwndCustomDlg =
|
---|
886 | CreateTemplateDialog((FileOpenDlgInfos *)lParam, hwnd);
|
---|
887 |
|
---|
888 | FILEDLG95_InitControls(hwnd);
|
---|
889 | SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE);
|
---|
890 | FILEDLG95_FillControls(hwnd, wParam, lParam);
|
---|
891 | SendCustomDlgNotificationMessage(hwnd,CDN_SELCHANGE);
|
---|
892 | return 0;
|
---|
893 | }
|
---|
894 | case WM_COMMAND:
|
---|
895 | return FILEDLG95_OnWMCommand(hwnd, wParam, lParam);
|
---|
896 | case WM_DRAWITEM:
|
---|
897 | {
|
---|
898 | switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
|
---|
899 | {
|
---|
900 | case IDC_LOOKIN:
|
---|
901 | FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT) lParam);
|
---|
902 | return TRUE;
|
---|
903 | }
|
---|
904 | }
|
---|
905 | return FALSE;
|
---|
906 |
|
---|
907 | case WM_GETISHELLBROWSER:
|
---|
908 | return FILEDLG95_OnWMGetIShellBrowser(hwnd);
|
---|
909 |
|
---|
910 | case WM_DESTROY:
|
---|
911 | RemovePropA(hwnd, FileOpenDlgInfosStr);
|
---|
912 | return FALSE;
|
---|
913 |
|
---|
914 | case WM_NOTIFY:
|
---|
915 | {
|
---|
916 | LPNMHDR lpnmh = (LPNMHDR)lParam;
|
---|
917 | UINT stringId = -1;
|
---|
918 |
|
---|
919 | /* set up the button tooltips strings */
|
---|
920 | if(TTN_GETDISPINFOA == lpnmh->code )
|
---|
921 | {
|
---|
922 | LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
|
---|
923 | switch(lpnmh->idFrom )
|
---|
924 | {
|
---|
925 | /* Up folder button */
|
---|
926 | case FCIDM_TB_UPFOLDER:
|
---|
927 | stringId = IDS_UPFOLDER;
|
---|
928 | break;
|
---|
929 | /* New folder button */
|
---|
930 | case FCIDM_TB_NEWFOLDER:
|
---|
931 | stringId = IDS_NEWFOLDER;
|
---|
932 | break;
|
---|
933 | /* List option button */
|
---|
934 | case FCIDM_TB_SMALLICON:
|
---|
935 | stringId = IDS_LISTVIEW;
|
---|
936 | break;
|
---|
937 | /* Details option button */
|
---|
938 | case FCIDM_TB_REPORTVIEW:
|
---|
939 | stringId = IDS_REPORTVIEW;
|
---|
940 | break;
|
---|
941 | /* Desktop button */
|
---|
942 | case FCIDM_TB_DESKTOP:
|
---|
943 | stringId = IDS_TODESKTOP;
|
---|
944 | break;
|
---|
945 | default:
|
---|
946 | stringId = 0;
|
---|
947 | }
|
---|
948 | lpdi->hinst = COMMDLG_hInstance32;
|
---|
949 | lpdi->lpszText = (LPSTR) stringId;
|
---|
950 | }
|
---|
951 | return FALSE;
|
---|
952 | }
|
---|
953 | default :
|
---|
954 | if(uMsg >= CDM_FIRST && uMsg <= CDM_LAST)
|
---|
955 | return FILEDLG95_HandleCustomDialogMessages(hwnd, uMsg, wParam, lParam);
|
---|
956 | return FALSE;
|
---|
957 | }
|
---|
958 | }
|
---|
959 |
|
---|
960 | /***********************************************************************
|
---|
961 | * FILEDLG95_InitControls
|
---|
962 | *
|
---|
963 | * WM_INITDIALOG message handler (before hook notification)
|
---|
964 | */
|
---|
965 | static LRESULT FILEDLG95_InitControls(HWND hwnd)
|
---|
966 | {
|
---|
967 | TBBUTTON tbb[] =
|
---|
968 | {
|
---|
969 | {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
|
---|
970 | {VIEW_PARENTFOLDER, FCIDM_TB_UPFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
|
---|
971 | {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
|
---|
972 | {VIEW_NEWFOLDER+1, FCIDM_TB_DESKTOP, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
|
---|
973 | {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
|
---|
974 | {VIEW_NEWFOLDER, FCIDM_TB_NEWFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
|
---|
975 | {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
|
---|
976 | {VIEW_LIST, FCIDM_TB_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
|
---|
977 | {VIEW_DETAILS, FCIDM_TB_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
|
---|
978 | };
|
---|
979 | TBADDBITMAP tba[] =
|
---|
980 | {
|
---|
981 | { HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR },
|
---|
982 | { COMDLG32_hInstance, 800 } // desktop icon
|
---|
983 | };
|
---|
984 |
|
---|
985 | RECT rectTB;
|
---|
986 |
|
---|
987 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
988 |
|
---|
989 | TRACE("%p\n", fodInfos);
|
---|
990 |
|
---|
991 | /* Get the hwnd of the controls */
|
---|
992 | fodInfos->DlgInfos.hwndFileName = GetDlgItem(hwnd,IDC_FILENAME);
|
---|
993 | fodInfos->DlgInfos.hwndFileTypeCB = GetDlgItem(hwnd,IDC_FILETYPE);
|
---|
994 | fodInfos->DlgInfos.hwndLookInCB = GetDlgItem(hwnd,IDC_LOOKIN);
|
---|
995 |
|
---|
996 | /* construct the toolbar */
|
---|
997 | GetWindowRect(GetDlgItem(hwnd,IDC_TOOLBARSTATIC),&rectTB);
|
---|
998 | MapWindowPoints( 0, hwnd,(LPPOINT)&rectTB,2);
|
---|
999 |
|
---|
1000 | fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, (LPSTR) NULL,
|
---|
1001 | WS_CHILD | WS_GROUP | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE,
|
---|
1002 | 0, 0, 150, 26, hwnd, (HMENU) IDC_TOOLBAR, COMMDLG_hInstance32, NULL);
|
---|
1003 |
|
---|
1004 | SetWindowPos(fodInfos->DlgInfos.hwndTB, 0,
|
---|
1005 | rectTB.left,rectTB.top, rectTB.right-rectTB.left, rectTB.bottom-rectTB.top,
|
---|
1006 | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
|
---|
1007 |
|
---|
1008 | SendMessageA(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
|
---|
1009 |
|
---|
1010 | /* fixme: use TB_LOADIMAGES when implemented */
|
---|
1011 | /* SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/
|
---|
1012 | SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 12, (LPARAM) &tba[0]);
|
---|
1013 | SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 1, (LPARAM) &tba[1]);
|
---|
1014 |
|
---|
1015 | SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSA, (WPARAM) 9,(LPARAM) &tbb);
|
---|
1016 | SendMessageA(fodInfos->DlgInfos.hwndTB, TB_AUTOSIZE, 0, 0);
|
---|
1017 |
|
---|
1018 | /* Set the window text with the text specified in the OPENFILENAME structure */
|
---|
1019 | if(fodInfos->ofnInfos->lpstrTitle)
|
---|
1020 | {
|
---|
1021 | SetWindowTextA(hwnd,fodInfos->ofnInfos->lpstrTitle);
|
---|
1022 | }
|
---|
1023 | else if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
|
---|
1024 | {
|
---|
1025 | SetWindowTextA(hwnd,"Save");
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | /* Initialise the file name edit control */
|
---|
1029 | if(fodInfos->ofnInfos->lpstrFile)
|
---|
1030 | {
|
---|
1031 | LPSTR lpstrFile = COMDLG32_PathFindFileNameA(fodInfos->ofnInfos->lpstrFile);
|
---|
1032 | SetDlgItemTextA(hwnd, IDC_FILENAME, lpstrFile);
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | /* Must the open as read only check box be checked ?*/
|
---|
1036 | if(fodInfos->ofnInfos->Flags & OFN_READONLY)
|
---|
1037 | {
|
---|
1038 | SendDlgItemMessageA(hwnd,IDC_OPENREADONLY,BM_SETCHECK,(WPARAM)TRUE,0);
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | /* Must the open as read only check box be hid ?*/
|
---|
1042 | if(fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY)
|
---|
1043 | {
|
---|
1044 | ShowWindow(GetDlgItem(hwnd,IDC_OPENREADONLY),SW_HIDE);
|
---|
1045 | }
|
---|
1046 |
|
---|
1047 | /* Must the help button be hid ?*/
|
---|
1048 | if (!(fodInfos->ofnInfos->Flags & OFN_SHOWHELP))
|
---|
1049 | {
|
---|
1050 | ShowWindow(GetDlgItem(hwnd, pshHelp), SW_HIDE);
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | /* Resize the height, if open as read only checkbox ad help button
|
---|
1054 | are hidden and we are not using a custom template */
|
---|
1055 | if ( (fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) &&
|
---|
1056 | (!(fodInfos->ofnInfos->Flags &
|
---|
1057 | (OFN_SHOWHELP|OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE))))
|
---|
1058 | {
|
---|
1059 | RECT rectDlg, rectHelp, rectCancel;
|
---|
1060 | GetWindowRect(hwnd, &rectDlg);
|
---|
1061 | GetWindowRect(GetDlgItem(hwnd, pshHelp), &rectHelp);
|
---|
1062 | GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rectCancel);
|
---|
1063 | /* subtract the height of the help button plus the space between
|
---|
1064 | the help button and the cancel button to the height of the dialog */
|
---|
1065 | SetWindowPos(hwnd, 0, 0, 0, rectDlg.right-rectDlg.left,
|
---|
1066 | (rectDlg.bottom-rectDlg.top) - (rectHelp.bottom - rectCancel.bottom),
|
---|
1067 | SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 | /* change Open to Save FIXME: use resources */
|
---|
1071 | if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
|
---|
1072 | {
|
---|
1073 | SetDlgItemTextA(hwnd,IDOK,"&Save");
|
---|
1074 | SetDlgItemTextA(hwnd,IDC_LOOKINSTATIC,"Save &in");
|
---|
1075 | }
|
---|
1076 | return 0;
|
---|
1077 | }
|
---|
1078 |
|
---|
1079 | /***********************************************************************
|
---|
1080 | * FILEDLG95_FillControls
|
---|
1081 | *
|
---|
1082 | * WM_INITDIALOG message handler (after hook notification)
|
---|
1083 | */
|
---|
1084 | static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1085 | {
|
---|
1086 | LPITEMIDLIST pidlItemId = NULL;
|
---|
1087 |
|
---|
1088 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) lParam;
|
---|
1089 |
|
---|
1090 | TRACE("dir=%s file=%s\n",
|
---|
1091 | fodInfos->ofnInfos->lpstrInitialDir, fodInfos->ofnInfos->lpstrFile);
|
---|
1092 |
|
---|
1093 | /* Get the initial directory pidl */
|
---|
1094 |
|
---|
1095 | if(!(pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,fodInfos->ofnInfos->lpstrInitialDir)))
|
---|
1096 | {
|
---|
1097 | char path[MAX_PATH];
|
---|
1098 |
|
---|
1099 | GetCurrentDirectoryA(MAX_PATH,path);
|
---|
1100 | pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder, path);
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | /* Initialise shell objects */
|
---|
1104 | FILEDLG95_SHELL_Init(hwnd);
|
---|
1105 |
|
---|
1106 | /* Initialize the Look In combo box */
|
---|
1107 | FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB);
|
---|
1108 |
|
---|
1109 | /* Initialize the filter combo box */
|
---|
1110 | FILEDLG95_FILETYPE_Init(hwnd);
|
---|
1111 |
|
---|
1112 | /* Browse to the initial directory */
|
---|
1113 | IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,pidlItemId, SBSP_ABSOLUTE);
|
---|
1114 |
|
---|
1115 | /* Free pidlItem memory */
|
---|
1116 | COMDLG32_SHFree(pidlItemId);
|
---|
1117 |
|
---|
1118 | return TRUE;
|
---|
1119 | }
|
---|
1120 | /***********************************************************************
|
---|
1121 | * FILEDLG95_Clean
|
---|
1122 | *
|
---|
1123 | * Regroups all the cleaning functions of the filedlg
|
---|
1124 | */
|
---|
1125 | void FILEDLG95_Clean(HWND hwnd)
|
---|
1126 | {
|
---|
1127 | FILEDLG95_FILETYPE_Clean(hwnd);
|
---|
1128 | FILEDLG95_LOOKIN_Clean(hwnd);
|
---|
1129 | FILEDLG95_SHELL_Clean(hwnd);
|
---|
1130 | }
|
---|
1131 | /***********************************************************************
|
---|
1132 | * FILEDLG95_OnWMCommand
|
---|
1133 | *
|
---|
1134 | * WM_COMMAND message handler
|
---|
1135 | */
|
---|
1136 | static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1137 | {
|
---|
1138 | WORD wNotifyCode = HIWORD(wParam); /* notification code */
|
---|
1139 | WORD wID = LOWORD(wParam); /* item, control, or accelerator identifier */
|
---|
1140 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1141 |
|
---|
1142 | switch(wID)
|
---|
1143 | {
|
---|
1144 | /* OK button */
|
---|
1145 | case IDOK:
|
---|
1146 | if(FILEDLG95_OnOpen(hwnd))
|
---|
1147 | SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK);
|
---|
1148 | break;
|
---|
1149 | /* Cancel button */
|
---|
1150 | case IDCANCEL:
|
---|
1151 | FILEDLG95_Clean(hwnd);
|
---|
1152 | EndDialog(hwnd, FALSE);
|
---|
1153 | break;
|
---|
1154 | /* Filetype combo box */
|
---|
1155 | case IDC_FILETYPE:
|
---|
1156 | FILEDLG95_FILETYPE_OnCommand(hwnd,wNotifyCode);
|
---|
1157 | break;
|
---|
1158 | /* LookIn combo box */
|
---|
1159 | case IDC_LOOKIN:
|
---|
1160 | FILEDLG95_LOOKIN_OnCommand(hwnd,wNotifyCode);
|
---|
1161 | break;
|
---|
1162 |
|
---|
1163 | /* --- toolbar --- */
|
---|
1164 | /* Up folder button */
|
---|
1165 | case FCIDM_TB_UPFOLDER:
|
---|
1166 | FILEDLG95_SHELL_UpFolder(hwnd);
|
---|
1167 | break;
|
---|
1168 | /* New folder button */
|
---|
1169 | case FCIDM_TB_NEWFOLDER:
|
---|
1170 | FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_NEWFOLDER);
|
---|
1171 | break;
|
---|
1172 | /* List option button */
|
---|
1173 | case FCIDM_TB_SMALLICON:
|
---|
1174 | FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWLIST);
|
---|
1175 | break;
|
---|
1176 | /* Details option button */
|
---|
1177 | case FCIDM_TB_REPORTVIEW:
|
---|
1178 | FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWDETAILS);
|
---|
1179 | break;
|
---|
1180 | /* Details option button */
|
---|
1181 | case FCIDM_TB_DESKTOP:
|
---|
1182 | FILEDLG95_SHELL_BrowseToDesktop(hwnd);
|
---|
1183 | break;
|
---|
1184 |
|
---|
1185 | case IDC_FILENAME:
|
---|
1186 | break;
|
---|
1187 |
|
---|
1188 | }
|
---|
1189 | /* Do not use the listview selection anymore */
|
---|
1190 | fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
|
---|
1191 | return 0;
|
---|
1192 | }
|
---|
1193 |
|
---|
1194 | /***********************************************************************
|
---|
1195 | * FILEDLG95_OnWMGetIShellBrowser
|
---|
1196 | *
|
---|
1197 | * WM_GETISHELLBROWSER message handler
|
---|
1198 | */
|
---|
1199 | static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd)
|
---|
1200 | {
|
---|
1201 |
|
---|
1202 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1203 |
|
---|
1204 | TRACE("\n");
|
---|
1205 |
|
---|
1206 | SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)fodInfos->Shell.FOIShellBrowser);
|
---|
1207 |
|
---|
1208 | return TRUE;
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 |
|
---|
1212 | /***********************************************************************
|
---|
1213 | * FILEDLG95_OnOpenMultipleFiles
|
---|
1214 | *
|
---|
1215 | * Handles the opening of multiple files.
|
---|
1216 | *
|
---|
1217 | * FIXME
|
---|
1218 | * check destination buffer size
|
---|
1219 | */
|
---|
1220 | BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed)
|
---|
1221 | {
|
---|
1222 | CHAR lpstrPathSpec[MAX_PATH] = "";
|
---|
1223 | LPSTR lpstrFile;
|
---|
1224 | UINT nCount, nSizePath;
|
---|
1225 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1226 |
|
---|
1227 | TRACE("\n");
|
---|
1228 |
|
---|
1229 | lpstrFile = fodInfos->ofnInfos->lpstrFile;
|
---|
1230 | lpstrFile[0] = '\0';
|
---|
1231 |
|
---|
1232 | COMDLG32_SHGetPathFromIDListA( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec );
|
---|
1233 |
|
---|
1234 | if ( !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE) &&
|
---|
1235 | ( fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST))
|
---|
1236 | {
|
---|
1237 | LPSTR lpstrTemp = lpstrFileList;
|
---|
1238 |
|
---|
1239 | for ( nCount = 0; nCount < nFileCount; nCount++ )
|
---|
1240 | {
|
---|
1241 | LPITEMIDLIST pidl;
|
---|
1242 |
|
---|
1243 | pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder, lpstrTemp);
|
---|
1244 | if (!pidl)
|
---|
1245 | {
|
---|
1246 | CHAR lpstrNotFound[100];
|
---|
1247 | CHAR lpstrMsg[100];
|
---|
1248 | CHAR tmp[400];
|
---|
1249 |
|
---|
1250 | LoadStringA(COMMDLG_hInstance32, IDS_FILENOTFOUND, lpstrNotFound, 100);
|
---|
1251 | LoadStringA(COMMDLG_hInstance32, IDS_VERIFYFILE, lpstrMsg, 100);
|
---|
1252 |
|
---|
1253 | strcpy(tmp, lpstrTemp);
|
---|
1254 | strcat(tmp, "\n");
|
---|
1255 | strcat(tmp, lpstrNotFound);
|
---|
1256 | strcat(tmp, "\n");
|
---|
1257 | strcat(tmp, lpstrMsg);
|
---|
1258 |
|
---|
1259 | MessageBoxA(hwnd, tmp, fodInfos->ofnInfos->lpstrTitle, MB_OK | MB_ICONEXCLAMATION);
|
---|
1260 | return FALSE;
|
---|
1261 | }
|
---|
1262 |
|
---|
1263 | /* move to the next file in the list of files */
|
---|
1264 | lpstrTemp += strlen(lpstrTemp) + 1;
|
---|
1265 | COMDLG32_SHFree(pidl);
|
---|
1266 | }
|
---|
1267 | }
|
---|
1268 |
|
---|
1269 | nSizePath = strlen(lpstrPathSpec);
|
---|
1270 | strcpy( lpstrFile, lpstrPathSpec);
|
---|
1271 | memcpy( lpstrFile + nSizePath + 1, lpstrFileList, sizeUsed );
|
---|
1272 |
|
---|
1273 | fodInfos->ofnInfos->nFileOffset = nSizePath + 1;
|
---|
1274 | fodInfos->ofnInfos->nFileExtension = 0;
|
---|
1275 |
|
---|
1276 | /* clean and exit */
|
---|
1277 | FILEDLG95_Clean(hwnd);
|
---|
1278 | return EndDialog(hwnd,TRUE);
|
---|
1279 | }
|
---|
1280 |
|
---|
1281 | /***********************************************************************
|
---|
1282 | * FILEDLG95_OnOpen
|
---|
1283 | *
|
---|
1284 | * Ok button WM_COMMAND message handler
|
---|
1285 | *
|
---|
1286 | * If the function succeeds, the return value is nonzero.
|
---|
1287 | */
|
---|
1288 | #define ONOPEN_BROWSE 1
|
---|
1289 | #define ONOPEN_OPEN 2
|
---|
1290 | #define ONOPEN_SEARCH 3
|
---|
1291 | static void FILEDLG95_OnOpenMessage(HWND hwnd, int idCaption, int idText)
|
---|
1292 | {
|
---|
1293 | char strMsgTitle[MAX_PATH];
|
---|
1294 | char strMsgText [MAX_PATH];
|
---|
1295 | if (idCaption)
|
---|
1296 | LoadStringA(COMDLG32_hInstance, idCaption, strMsgTitle, sizeof(strMsgTitle));
|
---|
1297 | else
|
---|
1298 | strMsgTitle[0] = '\0';
|
---|
1299 | LoadStringA(COMDLG32_hInstance, idText, strMsgText, sizeof(strMsgText));
|
---|
1300 | MessageBoxA(hwnd,strMsgText, strMsgTitle, MB_OK | MB_ICONHAND);
|
---|
1301 | }
|
---|
1302 |
|
---|
1303 | BOOL FILEDLG95_OnOpen(HWND hwnd)
|
---|
1304 | {
|
---|
1305 | char * lpstrFileList;
|
---|
1306 | UINT nFileCount = 0;
|
---|
1307 | UINT sizeUsed = 0;
|
---|
1308 | BOOL ret = TRUE;
|
---|
1309 | char lpstrPathAndFile[MAX_PATH];
|
---|
1310 | char lpstrTemp[MAX_PATH];
|
---|
1311 | LPSHELLFOLDER lpsf = NULL;
|
---|
1312 | int nOpenAction;
|
---|
1313 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1314 |
|
---|
1315 | TRACE("hwnd=0x%04x\n", hwnd);
|
---|
1316 |
|
---|
1317 | /* get the files from the edit control */
|
---|
1318 | nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed);
|
---|
1319 |
|
---|
1320 | /* try if the user selected a folder in the shellview */
|
---|
1321 | if(nFileCount == 0)
|
---|
1322 | {
|
---|
1323 | BrowseSelectedFolder(hwnd);
|
---|
1324 | return FALSE;
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | if(nFileCount > 1)
|
---|
1328 | {
|
---|
1329 | ret = FILEDLG95_OnOpenMultipleFiles(hwnd, lpstrFileList, nFileCount, sizeUsed);
|
---|
1330 | goto ret;
|
---|
1331 | }
|
---|
1332 |
|
---|
1333 | TRACE("count=%u len=%u file=%s\n", nFileCount, sizeUsed, lpstrFileList);
|
---|
1334 |
|
---|
1335 | /*
|
---|
1336 | Step 1: Build a complete path name from the current folder and
|
---|
1337 | the filename or path in the edit box.
|
---|
1338 | Special cases:
|
---|
1339 | - the path in the edit box is a root path
|
---|
1340 | (with or without drive letter)
|
---|
1341 | - the edit box contains ".." (or a path with ".." in it)
|
---|
1342 | */
|
---|
1343 |
|
---|
1344 | /* Get the current directory name */
|
---|
1345 | if (!COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathAndFile))
|
---|
1346 | {
|
---|
1347 | /* we are in a special folder, default to desktop */
|
---|
1348 | if(FAILED(COMDLG32_SHGetFolderPathA(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, NULL, 0, lpstrPathAndFile)))
|
---|
1349 | {
|
---|
1350 | /* last fallback */
|
---|
1351 | GetCurrentDirectoryA(MAX_PATH, lpstrPathAndFile);
|
---|
1352 | }
|
---|
1353 | }
|
---|
1354 | COMDLG32_PathAddBackslashA(lpstrPathAndFile);
|
---|
1355 |
|
---|
1356 | TRACE("current directory=%s\n", lpstrPathAndFile);
|
---|
1357 |
|
---|
1358 | /* if the user specifyed a fully qualified path use it */
|
---|
1359 | if(COMDLG32_PathIsRelativeA(lpstrFileList))
|
---|
1360 | {
|
---|
1361 | strcat(lpstrPathAndFile, lpstrFileList);
|
---|
1362 | }
|
---|
1363 | else
|
---|
1364 | {
|
---|
1365 | /* does the path have a drive letter? */
|
---|
1366 | if (COMDLG32_PathGetDriveNumberA(lpstrFileList) == -1)
|
---|
1367 | strcpy(lpstrPathAndFile+2, lpstrFileList);
|
---|
1368 | else
|
---|
1369 | strcpy(lpstrPathAndFile, lpstrFileList);
|
---|
1370 | }
|
---|
1371 |
|
---|
1372 | /* resolve "." and ".." */
|
---|
1373 | COMDLG32_PathCanonicalizeA(lpstrTemp, lpstrPathAndFile );
|
---|
1374 | strcpy(lpstrPathAndFile, lpstrTemp);
|
---|
1375 | TRACE("canon=%s\n", lpstrPathAndFile);
|
---|
1376 |
|
---|
1377 | MemFree(lpstrFileList);
|
---|
1378 |
|
---|
1379 | /*
|
---|
1380 | Step 2: here we have a cleaned up path
|
---|
1381 |
|
---|
1382 | We have to parse the path step by step to see if we have to browse
|
---|
1383 | to a folder if the path points to a directory or the last
|
---|
1384 | valid element is a directory.
|
---|
1385 |
|
---|
1386 | valid variables:
|
---|
1387 | lpstrPathAndFile: cleaned up path
|
---|
1388 | */
|
---|
1389 |
|
---|
1390 | nOpenAction = ONOPEN_BROWSE;
|
---|
1391 |
|
---|
1392 | /* dont apply any checks with OFN_NOVALIDATE */
|
---|
1393 | if(!(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE))
|
---|
1394 | {
|
---|
1395 | LPSTR lpszTemp, lpszTemp1;
|
---|
1396 | LPITEMIDLIST pidl = NULL;
|
---|
1397 |
|
---|
1398 | /* check for invalid chars */
|
---|
1399 | if(strpbrk(lpstrPathAndFile+3, "/:<>|") != NULL)
|
---|
1400 | {
|
---|
1401 | FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_FILENAME);
|
---|
1402 | ret = FALSE;
|
---|
1403 | goto ret;
|
---|
1404 | }
|
---|
1405 |
|
---|
1406 | if (FAILED (COMDLG32_SHGetDesktopFolder(&lpsf))) return FALSE;
|
---|
1407 |
|
---|
1408 | lpszTemp1 = lpszTemp = lpstrPathAndFile;
|
---|
1409 | while (lpszTemp1)
|
---|
1410 | {
|
---|
1411 | LPSHELLFOLDER lpsfChild;
|
---|
1412 | WCHAR lpwstrTemp[MAX_PATH];
|
---|
1413 | DWORD dwEaten, dwAttributes;
|
---|
1414 |
|
---|
1415 | lpszTemp = COMDLG32_PathFindNextComponentA(lpszTemp);
|
---|
1416 |
|
---|
1417 | if (!lpszTemp) break; /* end of path */
|
---|
1418 |
|
---|
1419 | if(*lpszTemp)
|
---|
1420 | lstrcpynAtoW(lpwstrTemp, lpszTemp1, lpszTemp - lpszTemp1);
|
---|
1421 | else
|
---|
1422 | {
|
---|
1423 | lstrcpyAtoW(lpwstrTemp, lpszTemp1); /* last element */
|
---|
1424 |
|
---|
1425 | /* if the last element is a wildcard do a search */
|
---|
1426 | if(strpbrk(lpszTemp1, "*?") != NULL)
|
---|
1427 | {
|
---|
1428 | nOpenAction = ONOPEN_SEARCH;
|
---|
1429 | break;
|
---|
1430 | }
|
---|
1431 | }
|
---|
1432 | lpszTemp1 = lpszTemp;
|
---|
1433 |
|
---|
1434 | TRACE("parse now=%s next=%s sf=%p\n",debugstr_w(lpwstrTemp), debugstr_a(lpszTemp), lpsf);
|
---|
1435 |
|
---|
1436 | if(lstrlenW(lpwstrTemp)==2) COMDLG32_PathAddBackslashW(lpwstrTemp);
|
---|
1437 |
|
---|
1438 | dwAttributes = SFGAO_FOLDER;
|
---|
1439 | if(SUCCEEDED(IShellFolder_ParseDisplayName(lpsf, hwnd, NULL, lpwstrTemp, &dwEaten, &pidl, &dwAttributes)))
|
---|
1440 | {
|
---|
1441 | /* the path component is valid, we have a pidl of the next path component */
|
---|
1442 | TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes, pidl);
|
---|
1443 | if(dwAttributes & SFGAO_FOLDER)
|
---|
1444 | {
|
---|
1445 | if(FAILED(IShellFolder_BindToObject(lpsf, pidl, 0, &IID_IShellFolder, (LPVOID*)&lpsfChild)))
|
---|
1446 | {
|
---|
1447 | ERR("bind to failed\n"); /* should not fail */
|
---|
1448 | break;
|
---|
1449 | }
|
---|
1450 | IShellFolder_Release(lpsf);
|
---|
1451 | lpsf = lpsfChild;
|
---|
1452 | lpsfChild = NULL;
|
---|
1453 | }
|
---|
1454 | else
|
---|
1455 | {
|
---|
1456 | TRACE("value\n");
|
---|
1457 |
|
---|
1458 | /* end dialog, return value */
|
---|
1459 | nOpenAction = ONOPEN_OPEN;
|
---|
1460 | break;
|
---|
1461 | }
|
---|
1462 | COMDLG32_SHFree(pidl);
|
---|
1463 | pidl = NULL;
|
---|
1464 | }
|
---|
1465 | else
|
---|
1466 | {
|
---|
1467 | if(*lpszTemp) /* points to trailing null for last path element */
|
---|
1468 | {
|
---|
1469 | if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
|
---|
1470 | {
|
---|
1471 | FILEDLG95_OnOpenMessage(hwnd, 0, IDS_PATHNOTEXISTING);
|
---|
1472 | break;
|
---|
1473 | }
|
---|
1474 | }
|
---|
1475 | else
|
---|
1476 | {
|
---|
1477 | if(fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST)
|
---|
1478 | {
|
---|
1479 | FILEDLG95_OnOpenMessage(hwnd, 0, IDS_FILENOTEXISTING);
|
---|
1480 | break;
|
---|
1481 | }
|
---|
1482 | }
|
---|
1483 | /* change to the current folder */
|
---|
1484 | nOpenAction = ONOPEN_OPEN;
|
---|
1485 | break;
|
---|
1486 | }
|
---|
1487 | }
|
---|
1488 | if(pidl) COMDLG32_SHFree(pidl);
|
---|
1489 | }
|
---|
1490 |
|
---|
1491 | /*
|
---|
1492 | Step 3: here we have a cleaned up and validated path
|
---|
1493 |
|
---|
1494 | valid variables:
|
---|
1495 | lpsf: ShellFolder bound to the rightmost valid path component
|
---|
1496 | lpstrPathAndFile: cleaned up path
|
---|
1497 | nOpenAction: action to do
|
---|
1498 | */
|
---|
1499 | TRACE("end validate sf=%p\n", lpsf);
|
---|
1500 |
|
---|
1501 | switch(nOpenAction)
|
---|
1502 | {
|
---|
1503 | case ONOPEN_SEARCH: /* set the current filter to the file mask and refresh */
|
---|
1504 | TRACE("ONOPEN_SEARCH %s\n", lpstrPathAndFile);
|
---|
1505 | {
|
---|
1506 | int iPos;
|
---|
1507 | LPSTR lpszTemp = COMDLG32_PathFindFileNameA(lpstrPathAndFile);
|
---|
1508 |
|
---|
1509 | /* replace the current filter */
|
---|
1510 | if(fodInfos->ShellInfos.lpstrCurrentFilter)
|
---|
1511 | MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
|
---|
1512 | fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpszTemp)+1)*sizeof(WCHAR));
|
---|
1513 | lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter, lpszTemp);
|
---|
1514 |
|
---|
1515 | /* set the filter cb to the extension when possible */
|
---|
1516 | if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB, lpszTemp)))
|
---|
1517 | CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, iPos);
|
---|
1518 | }
|
---|
1519 | /* fall through */
|
---|
1520 | case ONOPEN_BROWSE: /* browse to the highest folder we could bind to */
|
---|
1521 | TRACE("ONOPEN_BROWSE\n");
|
---|
1522 | {
|
---|
1523 | IPersistFolder2 * ppf2;
|
---|
1524 | if(SUCCEEDED(IShellFolder_QueryInterface( lpsf, &IID_IPersistFolder2, (LPVOID*)&ppf2)))
|
---|
1525 | {
|
---|
1526 | LPITEMIDLIST pidlCurrent;
|
---|
1527 | IPersistFolder2_GetCurFolder(ppf2, &pidlCurrent);
|
---|
1528 | IPersistFolder2_Release(ppf2);
|
---|
1529 | if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent, fodInfos->ShellInfos.pidlAbsCurrent))
|
---|
1530 | {
|
---|
1531 | IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE);
|
---|
1532 | }
|
---|
1533 | else if( nOpenAction == ONOPEN_SEARCH )
|
---|
1534 | {
|
---|
1535 | IShellView_Refresh(fodInfos->Shell.FOIShellView);
|
---|
1536 | }
|
---|
1537 | COMDLG32_SHFree(pidlCurrent);
|
---|
1538 | }
|
---|
1539 | }
|
---|
1540 | ret = FALSE;
|
---|
1541 | break;
|
---|
1542 | case ONOPEN_OPEN: /* fill in the return struct and close the dialog */
|
---|
1543 | TRACE("ONOPEN_OPEN %s\n", lpstrPathAndFile);
|
---|
1544 | {
|
---|
1545 | /* add default extension */
|
---|
1546 | if (fodInfos->ofnInfos->lpstrDefExt)
|
---|
1547 | {
|
---|
1548 | if (! *COMDLG32_PathFindExtensionA(lpstrPathAndFile))
|
---|
1549 | {
|
---|
1550 | strcat(lpstrPathAndFile, ".");
|
---|
1551 | strcat(lpstrPathAndFile, fodInfos->ofnInfos->lpstrDefExt);
|
---|
1552 | }
|
---|
1553 | }
|
---|
1554 |
|
---|
1555 | /* Check that size size of the file does not exceed buffer size */
|
---|
1556 | if(strlen(lpstrPathAndFile) < fodInfos->ofnInfos->nMaxFile)
|
---|
1557 | {
|
---|
1558 | LPSTR lpszTemp;
|
---|
1559 |
|
---|
1560 | /* fill destination buffer */
|
---|
1561 | strcpy(fodInfos->ofnInfos->lpstrFile, lpstrPathAndFile);
|
---|
1562 |
|
---|
1563 | /* set filename offset */
|
---|
1564 | lpszTemp = COMDLG32_PathFindFileNameA(lpstrPathAndFile);
|
---|
1565 | fodInfos->ofnInfos->nFileOffset = lpszTemp - lpstrPathAndFile;
|
---|
1566 |
|
---|
1567 | /* set extension offset */
|
---|
1568 | lpszTemp = COMDLG32_PathFindExtensionA(lpstrPathAndFile);
|
---|
1569 | fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? lpszTemp - lpstrPathAndFile + 1 : 0;
|
---|
1570 |
|
---|
1571 | /* set the lpstrFileTitle */
|
---|
1572 | if(fodInfos->ofnInfos->lpstrFileTitle)
|
---|
1573 | {
|
---|
1574 | LPSTR lpstrFileTitle = COMDLG32_PathFindFileNameA(lpstrPathAndFile);
|
---|
1575 | strncpy(fodInfos->ofnInfos->lpstrFileTitle, lpstrFileTitle, fodInfos->ofnInfos->nMaxFileTitle);
|
---|
1576 | }
|
---|
1577 |
|
---|
1578 | /* ask the hook if we can close */
|
---|
1579 | if(IsHooked(fodInfos))
|
---|
1580 | {
|
---|
1581 | /* FIXME we are sending ASCII-structures. Does not work with NT */
|
---|
1582 | /* first old style */
|
---|
1583 | TRACE("---\n");
|
---|
1584 | CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,
|
---|
1585 | fodInfos->DlgInfos.hwndCustomDlg,
|
---|
1586 | fodInfos->HookMsg.fileokstring, 0, (LPARAM)fodInfos->ofnInfos);
|
---|
1587 | if (GetWindowLongA(hwnd, DWL_MSGRESULT))
|
---|
1588 | {
|
---|
1589 | TRACE("cancled\n");
|
---|
1590 | ret = FALSE;
|
---|
1591 | goto ret;
|
---|
1592 | }
|
---|
1593 | }
|
---|
1594 |
|
---|
1595 | TRACE("close\n");
|
---|
1596 | FILEDLG95_Clean(hwnd);
|
---|
1597 | ret = EndDialog(hwnd, TRUE);
|
---|
1598 | }
|
---|
1599 | else
|
---|
1600 | {
|
---|
1601 | /* FIXME set error FNERR_BUFFERTOSMALL */
|
---|
1602 | FILEDLG95_Clean(hwnd);
|
---|
1603 | ret = EndDialog(hwnd, FALSE);
|
---|
1604 | }
|
---|
1605 | goto ret;
|
---|
1606 | }
|
---|
1607 | break;
|
---|
1608 | }
|
---|
1609 |
|
---|
1610 | ret:
|
---|
1611 | if(lpsf) IShellFolder_Release(lpsf);
|
---|
1612 | return ret;
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 | /***********************************************************************
|
---|
1616 | * FILEDLG95_SHELL_Init
|
---|
1617 | *
|
---|
1618 | * Initialisation of the shell objects
|
---|
1619 | */
|
---|
1620 | static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
|
---|
1621 | {
|
---|
1622 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1623 |
|
---|
1624 | TRACE("\n");
|
---|
1625 |
|
---|
1626 | /*
|
---|
1627 | * Initialisation of the FileOpenDialogInfos structure
|
---|
1628 | */
|
---|
1629 |
|
---|
1630 | /* Shell */
|
---|
1631 |
|
---|
1632 | /*ShellInfos */
|
---|
1633 | fodInfos->ShellInfos.hwndOwner = hwnd;
|
---|
1634 |
|
---|
1635 | /* Disable multi-select if flag not set */
|
---|
1636 | if (!(fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT))
|
---|
1637 | {
|
---|
1638 | fodInfos->ShellInfos.folderSettings.fFlags |= FWF_SINGLESEL;
|
---|
1639 | }
|
---|
1640 | fodInfos->ShellInfos.folderSettings.fFlags |= FWF_AUTOARRANGE | FWF_ALIGNLEFT;
|
---|
1641 | fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
|
---|
1642 |
|
---|
1643 | GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
|
---|
1644 | ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
|
---|
1645 | ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
|
---|
1646 |
|
---|
1647 | /* Construct the IShellBrowser interface */
|
---|
1648 | fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
|
---|
1649 |
|
---|
1650 | return NOERROR;
|
---|
1651 | }
|
---|
1652 |
|
---|
1653 | /***********************************************************************
|
---|
1654 | * FILEDLG95_SHELL_ExecuteCommand
|
---|
1655 | *
|
---|
1656 | * Change the folder option and refresh the view
|
---|
1657 | * If the function succeeds, the return value is nonzero.
|
---|
1658 | */
|
---|
1659 | static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
|
---|
1660 | {
|
---|
1661 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1662 |
|
---|
1663 | IContextMenu * pcm;
|
---|
1664 | TRACE("(0x%08x,%p)\n", hwnd, lpVerb);
|
---|
1665 |
|
---|
1666 | if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
|
---|
1667 | SVGIO_BACKGROUND,
|
---|
1668 | &IID_IContextMenu,
|
---|
1669 | (LPVOID*)&pcm)))
|
---|
1670 | {
|
---|
1671 | CMINVOKECOMMANDINFO ci;
|
---|
1672 | ZeroMemory(&ci, sizeof(CMINVOKECOMMANDINFO));
|
---|
1673 | ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
|
---|
1674 | ci.lpVerb = lpVerb;
|
---|
1675 | ci.hwnd = hwnd;
|
---|
1676 |
|
---|
1677 | IContextMenu_InvokeCommand(pcm, &ci);
|
---|
1678 | IContextMenu_Release(pcm);
|
---|
1679 | }
|
---|
1680 |
|
---|
1681 | return FALSE;
|
---|
1682 | }
|
---|
1683 |
|
---|
1684 | /***********************************************************************
|
---|
1685 | * FILEDLG95_SHELL_UpFolder
|
---|
1686 | *
|
---|
1687 | * Browse to the specified object
|
---|
1688 | * If the function succeeds, the return value is nonzero.
|
---|
1689 | */
|
---|
1690 | static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
|
---|
1691 | {
|
---|
1692 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1693 |
|
---|
1694 | TRACE("\n");
|
---|
1695 |
|
---|
1696 | if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
|
---|
1697 | NULL,
|
---|
1698 | SBSP_PARENT)))
|
---|
1699 | {
|
---|
1700 | return TRUE;
|
---|
1701 | }
|
---|
1702 | return FALSE;
|
---|
1703 | }
|
---|
1704 |
|
---|
1705 | /***********************************************************************
|
---|
1706 | * FILEDLG95_SHELL_BrowseToDesktop
|
---|
1707 | *
|
---|
1708 | * Browse to the Desktop
|
---|
1709 | * If the function succeeds, the return value is nonzero.
|
---|
1710 | */
|
---|
1711 | static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd)
|
---|
1712 | {
|
---|
1713 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1714 | LPITEMIDLIST pidl;
|
---|
1715 | HRESULT hres;
|
---|
1716 |
|
---|
1717 | TRACE("\n");
|
---|
1718 |
|
---|
1719 | COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidl);
|
---|
1720 | hres = IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidl, SBSP_ABSOLUTE);
|
---|
1721 | COMDLG32_SHFree(pidl);
|
---|
1722 | return SUCCEEDED(hres);
|
---|
1723 | }
|
---|
1724 | /***********************************************************************
|
---|
1725 | * FILEDLG95_SHELL_Clean
|
---|
1726 | *
|
---|
1727 | * Cleans the memory used by shell objects
|
---|
1728 | */
|
---|
1729 | static void FILEDLG95_SHELL_Clean(HWND hwnd)
|
---|
1730 | {
|
---|
1731 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1732 |
|
---|
1733 | TRACE("\n");
|
---|
1734 |
|
---|
1735 | COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent);
|
---|
1736 |
|
---|
1737 | /* clean Shell interfaces */
|
---|
1738 | IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
|
---|
1739 | IShellView_Release(fodInfos->Shell.FOIShellView);
|
---|
1740 | IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
|
---|
1741 | IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
|
---|
1742 | if (fodInfos->Shell.FOIDataObject)
|
---|
1743 | IDataObject_Release(fodInfos->Shell.FOIDataObject);
|
---|
1744 | }
|
---|
1745 |
|
---|
1746 | /***********************************************************************
|
---|
1747 | * FILEDLG95_FILETYPE_Init
|
---|
1748 | *
|
---|
1749 | * Initialisation of the file type combo box
|
---|
1750 | */
|
---|
1751 | static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
|
---|
1752 | {
|
---|
1753 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1754 |
|
---|
1755 | TRACE("\n");
|
---|
1756 |
|
---|
1757 | if(fodInfos->ofnInfos->lpstrFilter)
|
---|
1758 | {
|
---|
1759 | int nFilters = 0; /* number of filters */
|
---|
1760 | LPSTR lpstrFilter;
|
---|
1761 | LPCSTR lpstrPos = fodInfos->ofnInfos->lpstrFilter;
|
---|
1762 |
|
---|
1763 | for(;;)
|
---|
1764 | {
|
---|
1765 | /* filter is a list... title\0ext\0......\0\0
|
---|
1766 | * Set the combo item text to the title and the item data
|
---|
1767 | * to the ext
|
---|
1768 | */
|
---|
1769 | LPCSTR lpstrDisplay;
|
---|
1770 | LPSTR lpstrExt;
|
---|
1771 |
|
---|
1772 | /* Get the title */
|
---|
1773 | if(! *lpstrPos) break; /* end */
|
---|
1774 | lpstrDisplay = lpstrPos;
|
---|
1775 | lpstrPos += strlen(lpstrPos) + 1;
|
---|
1776 |
|
---|
1777 | /* Copy the extensions */
|
---|
1778 | if (! *lpstrPos) return E_FAIL; /* malformed filter */
|
---|
1779 | if (!(lpstrExt = (LPSTR) MemAlloc(strlen(lpstrPos)+1))) return E_FAIL;
|
---|
1780 | strcpy(lpstrExt,lpstrPos);
|
---|
1781 | lpstrPos += strlen(lpstrPos) + 1;
|
---|
1782 |
|
---|
1783 | /* Add the item at the end of the combo */
|
---|
1784 | CBAddString(fodInfos->DlgInfos.hwndFileTypeCB, lpstrDisplay);
|
---|
1785 | CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt);
|
---|
1786 | nFilters++;
|
---|
1787 | }
|
---|
1788 | /*
|
---|
1789 | * Set the current filter to the one specified
|
---|
1790 | * in the initialisation structure
|
---|
1791 | * FIXME: lpstrCustomFilter not handled at all
|
---|
1792 | */
|
---|
1793 |
|
---|
1794 | /* set default filter index */
|
---|
1795 | if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->ofnInfos->lpstrCustomFilter == NULL)
|
---|
1796 | fodInfos->ofnInfos->nFilterIndex = 1;
|
---|
1797 |
|
---|
1798 | /* First, check to make sure our index isn't out of bounds. */
|
---|
1799 | if ( fodInfos->ofnInfos->nFilterIndex > nFilters )
|
---|
1800 | fodInfos->ofnInfos->nFilterIndex = nFilters;
|
---|
1801 |
|
---|
1802 | /* Set the current index selection. */
|
---|
1803 | CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->ofnInfos->nFilterIndex-1);
|
---|
1804 |
|
---|
1805 | /* Get the corresponding text string from the combo box. */
|
---|
1806 | lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
|
---|
1807 | fodInfos->ofnInfos->nFilterIndex-1);
|
---|
1808 |
|
---|
1809 | if ((INT)lpstrFilter == CB_ERR) /* control is empty */
|
---|
1810 | lpstrFilter = NULL;
|
---|
1811 |
|
---|
1812 | if(lpstrFilter)
|
---|
1813 | {
|
---|
1814 | _strlwr(lpstrFilter); /* lowercase */
|
---|
1815 | fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
|
---|
1816 | lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter, lpstrFilter);
|
---|
1817 | }
|
---|
1818 | }
|
---|
1819 | return NOERROR;
|
---|
1820 | }
|
---|
1821 |
|
---|
1822 | /***********************************************************************
|
---|
1823 | * FILEDLG95_FILETYPE_OnCommand
|
---|
1824 | *
|
---|
1825 | * WM_COMMAND of the file type combo box
|
---|
1826 | * If the function succeeds, the return value is nonzero.
|
---|
1827 | */
|
---|
1828 | static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
|
---|
1829 | {
|
---|
1830 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1831 |
|
---|
1832 | switch(wNotifyCode)
|
---|
1833 | {
|
---|
1834 | case CBN_SELENDOK:
|
---|
1835 | {
|
---|
1836 | LPSTR lpstrFilter;
|
---|
1837 |
|
---|
1838 | /* Get the current item of the filetype combo box */
|
---|
1839 | int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
|
---|
1840 |
|
---|
1841 | /* set the current filter index - indexed from 1 */
|
---|
1842 | fodInfos->ofnInfos->nFilterIndex = iItem + 1;
|
---|
1843 |
|
---|
1844 | /* Set the current filter with the current selection */
|
---|
1845 | if(fodInfos->ShellInfos.lpstrCurrentFilter)
|
---|
1846 | MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
|
---|
1847 |
|
---|
1848 | lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
|
---|
1849 | iItem);
|
---|
1850 | if((int)lpstrFilter != CB_ERR)
|
---|
1851 | {
|
---|
1852 | fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
|
---|
1853 | lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,_strlwr(lpstrFilter));
|
---|
1854 | SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
|
---|
1855 | }
|
---|
1856 |
|
---|
1857 | /* Refresh the actual view to display the included items*/
|
---|
1858 | IShellView_Refresh(fodInfos->Shell.FOIShellView);
|
---|
1859 | }
|
---|
1860 | }
|
---|
1861 | return FALSE;
|
---|
1862 | }
|
---|
1863 | /***********************************************************************
|
---|
1864 | * FILEDLG95_FILETYPE_SearchExt
|
---|
1865 | *
|
---|
1866 | * searches for a extension in the filetype box
|
---|
1867 | */
|
---|
1868 | static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt)
|
---|
1869 | {
|
---|
1870 | int i, iCount = CBGetCount(hwnd);
|
---|
1871 |
|
---|
1872 | TRACE("%s\n", lpstrExt);
|
---|
1873 |
|
---|
1874 | if(iCount != CB_ERR)
|
---|
1875 | {
|
---|
1876 | for(i=0;i<iCount;i++)
|
---|
1877 | {
|
---|
1878 | if(!strcasecmp(lpstrExt,(LPSTR)CBGetItemDataPtr(hwnd,i)))
|
---|
1879 | return i;
|
---|
1880 | }
|
---|
1881 | }
|
---|
1882 | return -1;
|
---|
1883 | }
|
---|
1884 |
|
---|
1885 | /***********************************************************************
|
---|
1886 | * FILEDLG95_FILETYPE_Clean
|
---|
1887 | *
|
---|
1888 | * Clean the memory used by the filetype combo box
|
---|
1889 | */
|
---|
1890 | static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
|
---|
1891 | {
|
---|
1892 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
1893 | int iPos;
|
---|
1894 | int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
|
---|
1895 |
|
---|
1896 | TRACE("\n");
|
---|
1897 |
|
---|
1898 | /* Delete each string of the combo and their associated data */
|
---|
1899 | if(iCount != CB_ERR)
|
---|
1900 | {
|
---|
1901 | for(iPos = iCount-1;iPos>=0;iPos--)
|
---|
1902 | {
|
---|
1903 | MemFree((LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos));
|
---|
1904 | CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
|
---|
1905 | }
|
---|
1906 | }
|
---|
1907 | /* Current filter */
|
---|
1908 | if(fodInfos->ShellInfos.lpstrCurrentFilter)
|
---|
1909 | MemFree(fodInfos->ShellInfos.lpstrCurrentFilter);
|
---|
1910 |
|
---|
1911 | }
|
---|
1912 |
|
---|
1913 | /***********************************************************************
|
---|
1914 | * FILEDLG95_LOOKIN_Init
|
---|
1915 | *
|
---|
1916 | * Initialisation of the look in combo box
|
---|
1917 | */
|
---|
1918 | static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
|
---|
1919 | {
|
---|
1920 | IShellFolder *psfRoot, *psfDrives;
|
---|
1921 | IEnumIDList *lpeRoot, *lpeDrives;
|
---|
1922 | LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
|
---|
1923 |
|
---|
1924 | LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
|
---|
1925 |
|
---|
1926 | TRACE("\n");
|
---|
1927 |
|
---|
1928 | liInfos->iMaxIndentation = 0;
|
---|
1929 |
|
---|
1930 | SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
|
---|
1931 |
|
---|
1932 | /* set item height for both text field and listbox */
|
---|
1933 | CBSetItemHeight(hwndCombo,-1,GetSystemMetrics(SM_CYSMICON));
|
---|
1934 | CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
|
---|
1935 |
|
---|
1936 | /* Initialise data of Desktop folder */
|
---|
1937 | COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
|
---|
1938 | FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
|
---|
1939 | COMDLG32_SHFree(pidlTmp);
|
---|
1940 |
|
---|
1941 | COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
|
---|
1942 |
|
---|
1943 | COMDLG32_SHGetDesktopFolder(&psfRoot);
|
---|
1944 |
|
---|
1945 | if (psfRoot)
|
---|
1946 | {
|
---|
1947 | /* enumerate the contents of the desktop */
|
---|
1948 | if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
|
---|
1949 | {
|
---|
1950 | while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
|
---|
1951 | {
|
---|
1952 | FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
|
---|
1953 |
|
---|
1954 | /* special handling for CSIDL_DRIVES */
|
---|
1955 | if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
|
---|
1956 | {
|
---|
1957 | if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
|
---|
1958 | {
|
---|
1959 | /* enumerate the drives */
|
---|
1960 | if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
|
---|
1961 | {
|
---|
1962 | while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
|
---|
1963 | {
|
---|
1964 | pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
|
---|
1965 | FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
|
---|
1966 | COMDLG32_SHFree(pidlAbsTmp);
|
---|
1967 | COMDLG32_SHFree(pidlTmp1);
|
---|
1968 | }
|
---|
1969 | IEnumIDList_Release(lpeDrives);
|
---|
1970 | }
|
---|
1971 | IShellFolder_Release(psfDrives);
|
---|
1972 | }
|
---|
1973 | }
|
---|
1974 | COMDLG32_SHFree(pidlTmp);
|
---|
1975 | }
|
---|
1976 | IEnumIDList_Release(lpeRoot);
|
---|
1977 | }
|
---|
1978 | }
|
---|
1979 |
|
---|
1980 | IShellFolder_Release(psfRoot);
|
---|
1981 | COMDLG32_SHFree(pidlDrives);
|
---|
1982 | return NOERROR;
|
---|
1983 | }
|
---|
1984 |
|
---|
1985 | /***********************************************************************
|
---|
1986 | * FILEDLG95_LOOKIN_DrawItem
|
---|
1987 | *
|
---|
1988 | * WM_DRAWITEM message handler
|
---|
1989 | */
|
---|
1990 | static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
|
---|
1991 | {
|
---|
1992 | COLORREF crWin = GetSysColor(COLOR_WINDOW);
|
---|
1993 | COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
|
---|
1994 | COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
|
---|
1995 | RECT rectText;
|
---|
1996 | RECT rectIcon;
|
---|
1997 | SHFILEINFOA sfi;
|
---|
1998 | HIMAGELIST ilItemImage;
|
---|
1999 | int iIndentation;
|
---|
2000 | TEXTMETRICA tm;
|
---|
2001 | LPSFOLDER tmpFolder;
|
---|
2002 |
|
---|
2003 |
|
---|
2004 | LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
|
---|
2005 |
|
---|
2006 | TRACE("\n");
|
---|
2007 |
|
---|
2008 | if(pDIStruct->itemID == -1)
|
---|
2009 | return 0;
|
---|
2010 |
|
---|
2011 | if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
|
---|
2012 | pDIStruct->itemID)))
|
---|
2013 | return 0;
|
---|
2014 |
|
---|
2015 |
|
---|
2016 | if(pDIStruct->itemID == liInfos->uSelectedItem)
|
---|
2017 | {
|
---|
2018 | ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
|
---|
2019 | 0,
|
---|
2020 | &sfi,
|
---|
2021 | sizeof (SHFILEINFOA),
|
---|
2022 | SHGFI_PIDL | SHGFI_SMALLICON |
|
---|
2023 | SHGFI_OPENICON | SHGFI_SYSICONINDEX |
|
---|
2024 | SHGFI_DISPLAYNAME );
|
---|
2025 | }
|
---|
2026 | else
|
---|
2027 | {
|
---|
2028 | ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
|
---|
2029 | 0,
|
---|
2030 | &sfi,
|
---|
2031 | sizeof (SHFILEINFOA),
|
---|
2032 | SHGFI_PIDL | SHGFI_SMALLICON |
|
---|
2033 | SHGFI_SYSICONINDEX |
|
---|
2034 | SHGFI_DISPLAYNAME);
|
---|
2035 | }
|
---|
2036 |
|
---|
2037 | /* Is this item selected ? */
|
---|
2038 | if(pDIStruct->itemState & ODS_SELECTED)
|
---|
2039 | {
|
---|
2040 | SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
|
---|
2041 | SetBkColor(pDIStruct->hDC,crHighLight);
|
---|
2042 | FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight);
|
---|
2043 | }
|
---|
2044 | else
|
---|
2045 | {
|
---|
2046 | SetTextColor(pDIStruct->hDC,crText);
|
---|
2047 | SetBkColor(pDIStruct->hDC,crWin);
|
---|
2048 | FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin);
|
---|
2049 | }
|
---|
2050 |
|
---|
2051 | /* Do not indent item if drawing in the edit of the combo */
|
---|
2052 | if(pDIStruct->itemState & ODS_COMBOBOXEDIT)
|
---|
2053 | {
|
---|
2054 | iIndentation = 0;
|
---|
2055 | ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
|
---|
2056 | 0,
|
---|
2057 | &sfi,
|
---|
2058 | sizeof (SHFILEINFOA),
|
---|
2059 | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON
|
---|
2060 | | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME );
|
---|
2061 |
|
---|
2062 | }
|
---|
2063 | else
|
---|
2064 | {
|
---|
2065 | iIndentation = tmpFolder->m_iIndent;
|
---|
2066 | }
|
---|
2067 | /* Draw text and icon */
|
---|
2068 |
|
---|
2069 | /* Initialise the icon display area */
|
---|
2070 | rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
|
---|
2071 | rectIcon.top = pDIStruct->rcItem.top;
|
---|
2072 | rectIcon.right = rectIcon.left + ICONWIDTH;
|
---|
2073 | rectIcon.bottom = pDIStruct->rcItem.bottom;
|
---|
2074 |
|
---|
2075 | /* Initialise the text display area */
|
---|
2076 | GetTextMetricsA(pDIStruct->hDC, &tm);
|
---|
2077 | rectText.left = rectIcon.right;
|
---|
2078 | rectText.top =
|
---|
2079 | (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom - tm.tmHeight) / 2;
|
---|
2080 | rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
|
---|
2081 | rectText.bottom =
|
---|
2082 | (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom + tm.tmHeight) / 2;
|
---|
2083 |
|
---|
2084 | /* Draw the icon from the image list */
|
---|
2085 | COMDLG32_ImageList_Draw(ilItemImage,
|
---|
2086 | sfi.iIcon,
|
---|
2087 | pDIStruct->hDC,
|
---|
2088 | rectIcon.left,
|
---|
2089 | rectIcon.top,
|
---|
2090 | ILD_TRANSPARENT );
|
---|
2091 |
|
---|
2092 | /* Draw the associated text */
|
---|
2093 | if(sfi.szDisplayName)
|
---|
2094 | TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName));
|
---|
2095 |
|
---|
2096 |
|
---|
2097 | return NOERROR;
|
---|
2098 | }
|
---|
2099 |
|
---|
2100 | /***********************************************************************
|
---|
2101 | * FILEDLG95_LOOKIN_OnCommand
|
---|
2102 | *
|
---|
2103 | * LookIn combo box WM_COMMAND message handler
|
---|
2104 | * If the function succeeds, the return value is nonzero.
|
---|
2105 | */
|
---|
2106 | static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
|
---|
2107 | {
|
---|
2108 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
2109 |
|
---|
2110 | TRACE("%p\n", fodInfos);
|
---|
2111 |
|
---|
2112 | switch(wNotifyCode)
|
---|
2113 | {
|
---|
2114 | case CBN_SELENDOK:
|
---|
2115 | {
|
---|
2116 | LPSFOLDER tmpFolder;
|
---|
2117 | int iItem;
|
---|
2118 |
|
---|
2119 | iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
|
---|
2120 |
|
---|
2121 | if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
|
---|
2122 | iItem)))
|
---|
2123 | return FALSE;
|
---|
2124 |
|
---|
2125 |
|
---|
2126 | if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
|
---|
2127 | tmpFolder->pidlItem,
|
---|
2128 | SBSP_ABSOLUTE)))
|
---|
2129 | {
|
---|
2130 | return TRUE;
|
---|
2131 | }
|
---|
2132 | break;
|
---|
2133 | }
|
---|
2134 |
|
---|
2135 | }
|
---|
2136 | return FALSE;
|
---|
2137 | }
|
---|
2138 |
|
---|
2139 | /***********************************************************************
|
---|
2140 | * FILEDLG95_LOOKIN_AddItem
|
---|
2141 | *
|
---|
2142 | * Adds an absolute pidl item to the lookin combo box
|
---|
2143 | * returns the index of the inserted item
|
---|
2144 | */
|
---|
2145 | static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
|
---|
2146 | {
|
---|
2147 | LPITEMIDLIST pidlNext;
|
---|
2148 | SHFILEINFOA sfi;
|
---|
2149 | SFOLDER *tmpFolder;
|
---|
2150 | LookInInfos *liInfos;
|
---|
2151 |
|
---|
2152 | TRACE("%08x\n", iInsertId);
|
---|
2153 |
|
---|
2154 | if(!pidl)
|
---|
2155 | return -1;
|
---|
2156 |
|
---|
2157 | if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
|
---|
2158 | return -1;
|
---|
2159 |
|
---|
2160 | tmpFolder = MemAlloc(sizeof(SFOLDER));
|
---|
2161 | tmpFolder->m_iIndent = 0;
|
---|
2162 |
|
---|
2163 | /* Calculate the indentation of the item in the lookin*/
|
---|
2164 | pidlNext = pidl;
|
---|
2165 | while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
|
---|
2166 | {
|
---|
2167 | tmpFolder->m_iIndent++;
|
---|
2168 | }
|
---|
2169 |
|
---|
2170 | tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl); /* FIXME: memory leak*/
|
---|
2171 |
|
---|
2172 | if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
|
---|
2173 | liInfos->iMaxIndentation = tmpFolder->m_iIndent;
|
---|
2174 |
|
---|
2175 | sfi.dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM;
|
---|
2176 | COMDLG32_SHGetFileInfoA((LPSTR)pidl,
|
---|
2177 | 0,
|
---|
2178 | &sfi,
|
---|
2179 | sizeof(sfi),
|
---|
2180 | SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX
|
---|
2181 | | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED);
|
---|
2182 |
|
---|
2183 | TRACE("-- Add %s attr=%08lx\n", sfi.szDisplayName, sfi.dwAttributes);
|
---|
2184 |
|
---|
2185 | if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
|
---|
2186 | {
|
---|
2187 | int iItemID;
|
---|
2188 |
|
---|
2189 | TRACE("-- Add %s at %u\n", sfi.szDisplayName, tmpFolder->m_iIndent);
|
---|
2190 |
|
---|
2191 | /* Add the item at the end of the list */
|
---|
2192 | if(iInsertId < 0)
|
---|
2193 | {
|
---|
2194 | iItemID = CBAddString(hwnd,sfi.szDisplayName);
|
---|
2195 | }
|
---|
2196 | /* Insert the item at the iInsertId position*/
|
---|
2197 | else
|
---|
2198 | {
|
---|
2199 | iItemID = CBInsertString(hwnd,sfi.szDisplayName,iInsertId);
|
---|
2200 | }
|
---|
2201 |
|
---|
2202 | CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
|
---|
2203 | return iItemID;
|
---|
2204 | }
|
---|
2205 |
|
---|
2206 | MemFree( tmpFolder );
|
---|
2207 | return -1;
|
---|
2208 |
|
---|
2209 | }
|
---|
2210 |
|
---|
2211 | /***********************************************************************
|
---|
2212 | * FILEDLG95_LOOKIN_InsertItemAfterParent
|
---|
2213 | *
|
---|
2214 | * Insert an item below its parent
|
---|
2215 | */
|
---|
2216 | static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
|
---|
2217 | {
|
---|
2218 |
|
---|
2219 | LPITEMIDLIST pidlParent = GetParentPidl(pidl);
|
---|
2220 | int iParentPos;
|
---|
2221 |
|
---|
2222 | TRACE("\n");
|
---|
2223 |
|
---|
2224 | iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
|
---|
2225 |
|
---|
2226 | if(iParentPos < 0)
|
---|
2227 | {
|
---|
2228 | iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
|
---|
2229 | }
|
---|
2230 |
|
---|
2231 | /* Free pidlParent memory */
|
---|
2232 | COMDLG32_SHFree((LPVOID)pidlParent);
|
---|
2233 |
|
---|
2234 | return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
|
---|
2235 | }
|
---|
2236 |
|
---|
2237 | /***********************************************************************
|
---|
2238 | * FILEDLG95_LOOKIN_SelectItem
|
---|
2239 | *
|
---|
2240 | * Adds an absolute pidl item to the lookin combo box
|
---|
2241 | * returns the index of the inserted item
|
---|
2242 | */
|
---|
2243 | int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
|
---|
2244 | {
|
---|
2245 | int iItemPos;
|
---|
2246 | LookInInfos *liInfos;
|
---|
2247 |
|
---|
2248 | TRACE("\n");
|
---|
2249 |
|
---|
2250 | iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
|
---|
2251 |
|
---|
2252 | liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
|
---|
2253 |
|
---|
2254 | if(iItemPos < 0)
|
---|
2255 | {
|
---|
2256 | while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
|
---|
2257 | iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
|
---|
2258 | }
|
---|
2259 |
|
---|
2260 | else
|
---|
2261 | {
|
---|
2262 | SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
|
---|
2263 | while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
|
---|
2264 | {
|
---|
2265 | int iRemovedItem;
|
---|
2266 |
|
---|
2267 | if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
|
---|
2268 | break;
|
---|
2269 | if(iRemovedItem < iItemPos)
|
---|
2270 | iItemPos--;
|
---|
2271 | }
|
---|
2272 | }
|
---|
2273 |
|
---|
2274 | CBSetCurSel(hwnd,iItemPos);
|
---|
2275 | liInfos->uSelectedItem = iItemPos;
|
---|
2276 |
|
---|
2277 | return 0;
|
---|
2278 |
|
---|
2279 | }
|
---|
2280 |
|
---|
2281 | /***********************************************************************
|
---|
2282 | * FILEDLG95_LOOKIN_RemoveMostExpandedItem
|
---|
2283 | *
|
---|
2284 | * Remove the item with an expansion level over iExpansionLevel
|
---|
2285 | */
|
---|
2286 | static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
|
---|
2287 | {
|
---|
2288 | int iItemPos;
|
---|
2289 |
|
---|
2290 | LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
|
---|
2291 |
|
---|
2292 | TRACE("\n");
|
---|
2293 |
|
---|
2294 | if(liInfos->iMaxIndentation <= 2)
|
---|
2295 | return -1;
|
---|
2296 |
|
---|
2297 | if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
|
---|
2298 | {
|
---|
2299 | SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
|
---|
2300 | COMDLG32_SHFree(tmpFolder->pidlItem);
|
---|
2301 | MemFree(tmpFolder);
|
---|
2302 | CBDeleteString(hwnd,iItemPos);
|
---|
2303 | liInfos->iMaxIndentation--;
|
---|
2304 |
|
---|
2305 | return iItemPos;
|
---|
2306 | }
|
---|
2307 |
|
---|
2308 | return -1;
|
---|
2309 | }
|
---|
2310 |
|
---|
2311 | /***********************************************************************
|
---|
2312 | * FILEDLG95_LOOKIN_SearchItem
|
---|
2313 | *
|
---|
2314 | * Search for pidl in the lookin combo box
|
---|
2315 | * returns the index of the found item
|
---|
2316 | */
|
---|
2317 | static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
|
---|
2318 | {
|
---|
2319 | int i = 0;
|
---|
2320 | int iCount = CBGetCount(hwnd);
|
---|
2321 |
|
---|
2322 | TRACE("0x%08x 0x%x\n",searchArg, iSearchMethod);
|
---|
2323 |
|
---|
2324 | if (iCount != CB_ERR)
|
---|
2325 | {
|
---|
2326 | for(;i<iCount;i++)
|
---|
2327 | {
|
---|
2328 | LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
|
---|
2329 |
|
---|
2330 | if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
|
---|
2331 | return i;
|
---|
2332 | if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
|
---|
2333 | return i;
|
---|
2334 | }
|
---|
2335 | }
|
---|
2336 |
|
---|
2337 | return -1;
|
---|
2338 | }
|
---|
2339 |
|
---|
2340 | /***********************************************************************
|
---|
2341 | * FILEDLG95_LOOKIN_Clean
|
---|
2342 | *
|
---|
2343 | * Clean the memory used by the lookin combo box
|
---|
2344 | */
|
---|
2345 | static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
|
---|
2346 | {
|
---|
2347 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
2348 | int iPos;
|
---|
2349 | int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
|
---|
2350 |
|
---|
2351 | TRACE("\n");
|
---|
2352 |
|
---|
2353 | /* Delete each string of the combo and their associated data */
|
---|
2354 | if (iCount != CB_ERR)
|
---|
2355 | {
|
---|
2356 | for(iPos = iCount-1;iPos>=0;iPos--)
|
---|
2357 | {
|
---|
2358 | SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos);
|
---|
2359 | COMDLG32_SHFree(tmpFolder->pidlItem);
|
---|
2360 | MemFree(tmpFolder);
|
---|
2361 | CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
|
---|
2362 | }
|
---|
2363 | }
|
---|
2364 |
|
---|
2365 | /* LookInInfos structure */
|
---|
2366 | RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
|
---|
2367 |
|
---|
2368 | }
|
---|
2369 | /***********************************************************************
|
---|
2370 | * FILEDLG95_FILENAME_FillFromSelection
|
---|
2371 | *
|
---|
2372 | * fills the edit box from the cached DataObject
|
---|
2373 | */
|
---|
2374 | void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd)
|
---|
2375 | {
|
---|
2376 | FileOpenDlgInfos *fodInfos;
|
---|
2377 | LPITEMIDLIST pidl;
|
---|
2378 | UINT nFiles = 0, nFileToOpen, nFileSelected, nLength = 0;
|
---|
2379 | char lpstrTemp[MAX_PATH];
|
---|
2380 | LPSTR lpstrAllFile = NULL, lpstrCurrFile = NULL;
|
---|
2381 |
|
---|
2382 | TRACE("\n");
|
---|
2383 | fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
2384 |
|
---|
2385 | /* Count how many files we have */
|
---|
2386 | nFileSelected = GetNumSelected( fodInfos->Shell.FOIDataObject );
|
---|
2387 |
|
---|
2388 | /* calculate the string length, count files */
|
---|
2389 | if (nFileSelected >= 1)
|
---|
2390 | {
|
---|
2391 | nLength += 3; /* first and last quotes, trailing \0 */
|
---|
2392 | for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
|
---|
2393 | {
|
---|
2394 | pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
|
---|
2395 |
|
---|
2396 | if (pidl)
|
---|
2397 | {
|
---|
2398 | /* get the total length of the selected file names*/
|
---|
2399 | lpstrTemp[0] = '\0';
|
---|
2400 | GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
|
---|
2401 |
|
---|
2402 | if ( ! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl) ) /* Ignore folders */
|
---|
2403 | {
|
---|
2404 | nLength += strlen( lpstrTemp ) + 3;
|
---|
2405 | nFiles++;
|
---|
2406 | }
|
---|
2407 | COMDLG32_SHFree( pidl );
|
---|
2408 | }
|
---|
2409 | }
|
---|
2410 | }
|
---|
2411 |
|
---|
2412 | /* allocate the buffer */
|
---|
2413 | if (nFiles <= 1) nLength = MAX_PATH;
|
---|
2414 | lpstrAllFile = (LPSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength);
|
---|
2415 | lpstrAllFile[0] = '\0';
|
---|
2416 |
|
---|
2417 | /* Generate the string for the edit control */
|
---|
2418 | if(nFiles >= 1)
|
---|
2419 | {
|
---|
2420 | lpstrCurrFile = lpstrAllFile;
|
---|
2421 | for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
|
---|
2422 | {
|
---|
2423 | pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
|
---|
2424 |
|
---|
2425 | if (pidl)
|
---|
2426 | {
|
---|
2427 | /* get the file name */
|
---|
2428 | lpstrTemp[0] = '\0';
|
---|
2429 | GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
|
---|
2430 |
|
---|
2431 | if (! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl)) /* Ignore folders */
|
---|
2432 | {
|
---|
2433 | if ( nFiles > 1)
|
---|
2434 | {
|
---|
2435 | *lpstrCurrFile++ = '\"';
|
---|
2436 | strcpy( lpstrCurrFile, lpstrTemp );
|
---|
2437 | lpstrCurrFile += strlen( lpstrTemp );
|
---|
2438 | strcpy( lpstrCurrFile, "\" " );
|
---|
2439 | lpstrCurrFile += 2;
|
---|
2440 | }
|
---|
2441 | else
|
---|
2442 | {
|
---|
2443 | strcpy( lpstrAllFile, lpstrTemp );
|
---|
2444 | }
|
---|
2445 | }
|
---|
2446 | COMDLG32_SHFree( (LPVOID) pidl );
|
---|
2447 | }
|
---|
2448 | }
|
---|
2449 | }
|
---|
2450 |
|
---|
2451 | SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile );
|
---|
2452 | HeapFree(GetProcessHeap(),0, lpstrAllFile );
|
---|
2453 | }
|
---|
2454 |
|
---|
2455 |
|
---|
2456 | /* copied from shell32 to avoid linking to it */
|
---|
2457 | static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
|
---|
2458 | {
|
---|
2459 | switch (src->uType)
|
---|
2460 | {
|
---|
2461 | case STRRET_WSTR:
|
---|
2462 | WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL);
|
---|
2463 | COMDLG32_SHFree(src->u.pOleStr);
|
---|
2464 | break;
|
---|
2465 |
|
---|
2466 | case STRRET_CSTRA:
|
---|
2467 | lstrcpynA((LPSTR)dest, src->u.cStr, len);
|
---|
2468 | break;
|
---|
2469 |
|
---|
2470 | case STRRET_OFFSETA:
|
---|
2471 | lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
|
---|
2472 | break;
|
---|
2473 |
|
---|
2474 | default:
|
---|
2475 | FIXME("unknown type!\n");
|
---|
2476 | if (len)
|
---|
2477 | {
|
---|
2478 | *(LPSTR)dest = '\0';
|
---|
2479 | }
|
---|
2480 | return(FALSE);
|
---|
2481 | }
|
---|
2482 | return S_OK;
|
---|
2483 | }
|
---|
2484 |
|
---|
2485 | /***********************************************************************
|
---|
2486 | * FILEDLG95_FILENAME_GetFileNames
|
---|
2487 | *
|
---|
2488 | * copies the filenames to a 0-delimited string list (A\0B\0C\0\0)
|
---|
2489 | */
|
---|
2490 | int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPSTR * lpstrFileList, UINT * sizeUsed)
|
---|
2491 | {
|
---|
2492 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
2493 | UINT nStrCharCount = 0; /* index in src buffer */
|
---|
2494 | UINT nFileIndex = 0; /* index in dest buffer */
|
---|
2495 | UINT nFileCount = 0; /* number of files */
|
---|
2496 | UINT nStrLen = 0; /* length of string in edit control */
|
---|
2497 | LPSTR lpstrEdit; /* buffer for string from edit control */
|
---|
2498 |
|
---|
2499 | TRACE("\n");
|
---|
2500 |
|
---|
2501 | /* get the filenames from the edit control */
|
---|
2502 | nStrLen = SendMessageA(fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0);
|
---|
2503 | lpstrEdit = MemAlloc(nStrLen+1);
|
---|
2504 | GetDlgItemTextA(hwnd, IDC_FILENAME, lpstrEdit, nStrLen+1);
|
---|
2505 |
|
---|
2506 | TRACE("nStrLen=%u str=%s\n", nStrLen, lpstrEdit);
|
---|
2507 |
|
---|
2508 | /* we might get single filename without any '"',
|
---|
2509 | * so we need nStrLen + terminating \0 + end-of-list \0 */
|
---|
2510 | *lpstrFileList = MemAlloc(nStrLen+2);
|
---|
2511 | *sizeUsed = 0;
|
---|
2512 |
|
---|
2513 | /* build 0-delimited file list from filenames */
|
---|
2514 | while ( nStrCharCount <= nStrLen )
|
---|
2515 | {
|
---|
2516 | if ( lpstrEdit[nStrCharCount]=='"' )
|
---|
2517 | {
|
---|
2518 | nStrCharCount++;
|
---|
2519 | while ((lpstrEdit[nStrCharCount]!='"') && (nStrCharCount <= nStrLen))
|
---|
2520 | {
|
---|
2521 | (*lpstrFileList)[nFileIndex++] = lpstrEdit[nStrCharCount];
|
---|
2522 | (*sizeUsed)++;
|
---|
2523 | nStrCharCount++;
|
---|
2524 | }
|
---|
2525 | (*lpstrFileList)[nFileIndex++] = '\0';
|
---|
2526 | (*sizeUsed)++;
|
---|
2527 | nFileCount++;
|
---|
2528 | }
|
---|
2529 | nStrCharCount++;
|
---|
2530 | }
|
---|
2531 |
|
---|
2532 | /* single, unquoted string */
|
---|
2533 | if ((nStrLen > 0) && (*sizeUsed == 0) )
|
---|
2534 | {
|
---|
2535 | strcpy(*lpstrFileList, lpstrEdit);
|
---|
2536 | nFileIndex = strlen(lpstrEdit) + 1;
|
---|
2537 | (*sizeUsed) = nFileIndex;
|
---|
2538 | nFileCount = 1;
|
---|
2539 | }
|
---|
2540 |
|
---|
2541 | /* trailing \0 */
|
---|
2542 | (*lpstrFileList)[nFileIndex] = '\0';
|
---|
2543 | (*sizeUsed)++;
|
---|
2544 |
|
---|
2545 | MemFree(lpstrEdit);
|
---|
2546 | return nFileCount;
|
---|
2547 | }
|
---|
2548 |
|
---|
2549 | #define SETDefFormatEtc(fe,cf,med) \
|
---|
2550 | { \
|
---|
2551 | (fe).cfFormat = cf;\
|
---|
2552 | (fe).dwAspect = DVASPECT_CONTENT; \
|
---|
2553 | (fe).ptd =NULL;\
|
---|
2554 | (fe).tymed = med;\
|
---|
2555 | (fe).lindex = -1;\
|
---|
2556 | };
|
---|
2557 |
|
---|
2558 | /*
|
---|
2559 | * DATAOBJECT Helper functions
|
---|
2560 | */
|
---|
2561 |
|
---|
2562 | /***********************************************************************
|
---|
2563 | * COMCTL32_ReleaseStgMedium
|
---|
2564 | *
|
---|
2565 | * like ReleaseStgMedium from ole32
|
---|
2566 | */
|
---|
2567 | static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium)
|
---|
2568 | {
|
---|
2569 | if(medium.pUnkForRelease)
|
---|
2570 | {
|
---|
2571 | IUnknown_Release(medium.pUnkForRelease);
|
---|
2572 | }
|
---|
2573 | else
|
---|
2574 | {
|
---|
2575 | GlobalUnlock(medium.u.hGlobal);
|
---|
2576 | GlobalFree(medium.u.hGlobal);
|
---|
2577 | }
|
---|
2578 | }
|
---|
2579 |
|
---|
2580 | /***********************************************************************
|
---|
2581 | * GetPidlFromDataObject
|
---|
2582 | *
|
---|
2583 | * Return pidl(s) by number from the cached DataObject
|
---|
2584 | *
|
---|
2585 | * nPidlIndex=0 gets the fully qualified root path
|
---|
2586 | */
|
---|
2587 | LPITEMIDLIST GetPidlFromDataObject ( IDataObject *doSelected, UINT nPidlIndex)
|
---|
2588 | {
|
---|
2589 |
|
---|
2590 | STGMEDIUM medium;
|
---|
2591 | FORMATETC formatetc;
|
---|
2592 | LPITEMIDLIST pidl = NULL;
|
---|
2593 |
|
---|
2594 | TRACE("sv=%p index=%u\n", doSelected, nPidlIndex);
|
---|
2595 |
|
---|
2596 | /* Set the FORMATETC structure*/
|
---|
2597 | SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
|
---|
2598 |
|
---|
2599 | /* Get the pidls from IDataObject */
|
---|
2600 | if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
|
---|
2601 | {
|
---|
2602 | LPIDA cida = GlobalLock(medium.u.hGlobal);
|
---|
2603 | if(nPidlIndex <= cida->cidl)
|
---|
2604 | {
|
---|
2605 | pidl = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[nPidlIndex]]));
|
---|
2606 | }
|
---|
2607 | COMCTL32_ReleaseStgMedium(medium);
|
---|
2608 | }
|
---|
2609 | return pidl;
|
---|
2610 | }
|
---|
2611 |
|
---|
2612 | /***********************************************************************
|
---|
2613 | * GetNumSelected
|
---|
2614 | *
|
---|
2615 | * Return the number of selected items in the DataObject.
|
---|
2616 | *
|
---|
2617 | */
|
---|
2618 | UINT GetNumSelected( IDataObject *doSelected )
|
---|
2619 | {
|
---|
2620 | UINT retVal = 0;
|
---|
2621 | STGMEDIUM medium;
|
---|
2622 | FORMATETC formatetc;
|
---|
2623 |
|
---|
2624 | TRACE("sv=%p\n", doSelected);
|
---|
2625 |
|
---|
2626 | if (!doSelected) return 0;
|
---|
2627 |
|
---|
2628 | /* Set the FORMATETC structure*/
|
---|
2629 | SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
|
---|
2630 |
|
---|
2631 | /* Get the pidls from IDataObject */
|
---|
2632 | if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
|
---|
2633 | {
|
---|
2634 | LPIDA cida = GlobalLock(medium.u.hGlobal);
|
---|
2635 | retVal = cida->cidl;
|
---|
2636 | COMCTL32_ReleaseStgMedium(medium);
|
---|
2637 | return retVal;
|
---|
2638 | }
|
---|
2639 | return 0;
|
---|
2640 | }
|
---|
2641 |
|
---|
2642 | /*
|
---|
2643 | * TOOLS
|
---|
2644 | */
|
---|
2645 |
|
---|
2646 | /***********************************************************************
|
---|
2647 | * GetName
|
---|
2648 | *
|
---|
2649 | * Get the pidl's display name (relative to folder) and
|
---|
2650 | * put it in lpstrFileName.
|
---|
2651 | *
|
---|
2652 | * Return NOERROR on success,
|
---|
2653 | * E_FAIL otherwise
|
---|
2654 | */
|
---|
2655 |
|
---|
2656 | HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
|
---|
2657 | {
|
---|
2658 | STRRET str;
|
---|
2659 | HRESULT hRes;
|
---|
2660 |
|
---|
2661 | TRACE("sf=%p pidl=%p\n", lpsf, pidl);
|
---|
2662 |
|
---|
2663 | if(!lpsf)
|
---|
2664 | {
|
---|
2665 | HRESULT hRes;
|
---|
2666 | COMDLG32_SHGetDesktopFolder(&lpsf);
|
---|
2667 | hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
|
---|
2668 | IShellFolder_Release(lpsf);
|
---|
2669 | return hRes;
|
---|
2670 | }
|
---|
2671 |
|
---|
2672 | /* Get the display name of the pidl relative to the folder */
|
---|
2673 | if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf, pidl, dwFlags, &str)))
|
---|
2674 | {
|
---|
2675 | return COMDLG32_StrRetToStrNA(lpstrFileName, MAX_PATH, &str, pidl);
|
---|
2676 | }
|
---|
2677 | return E_FAIL;
|
---|
2678 | }
|
---|
2679 |
|
---|
2680 | /***********************************************************************
|
---|
2681 | * GetShellFolderFromPidl
|
---|
2682 | *
|
---|
2683 | * pidlRel is the item pidl relative
|
---|
2684 | * Return the IShellFolder of the absolute pidl
|
---|
2685 | */
|
---|
2686 | IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
|
---|
2687 | {
|
---|
2688 | IShellFolder *psf = NULL,*psfParent;
|
---|
2689 |
|
---|
2690 | TRACE("%p\n", pidlAbs);
|
---|
2691 |
|
---|
2692 | if(SUCCEEDED(COMDLG32_SHGetDesktopFolder(&psfParent)))
|
---|
2693 | {
|
---|
2694 | psf = psfParent;
|
---|
2695 | if(pidlAbs && pidlAbs->mkid.cb)
|
---|
2696 | {
|
---|
2697 | if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
|
---|
2698 | {
|
---|
2699 | IShellFolder_Release(psfParent);
|
---|
2700 | return psf;
|
---|
2701 | }
|
---|
2702 | }
|
---|
2703 | /* return the desktop */
|
---|
2704 | return psfParent;
|
---|
2705 | }
|
---|
2706 | return NULL;
|
---|
2707 | }
|
---|
2708 |
|
---|
2709 | /***********************************************************************
|
---|
2710 | * GetParentPidl
|
---|
2711 | *
|
---|
2712 | * Return the LPITEMIDLIST to the parent of the pidl in the list
|
---|
2713 | */
|
---|
2714 | LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
|
---|
2715 | {
|
---|
2716 | LPITEMIDLIST pidlParent;
|
---|
2717 |
|
---|
2718 | TRACE("%p\n", pidl);
|
---|
2719 |
|
---|
2720 | pidlParent = COMDLG32_PIDL_ILClone(pidl);
|
---|
2721 | COMDLG32_PIDL_ILRemoveLastID(pidlParent);
|
---|
2722 |
|
---|
2723 | return pidlParent;
|
---|
2724 | }
|
---|
2725 |
|
---|
2726 | /***********************************************************************
|
---|
2727 | * GetPidlFromName
|
---|
2728 | *
|
---|
2729 | * returns the pidl of the file name relative to folder
|
---|
2730 | * NULL if an error occured
|
---|
2731 | */
|
---|
2732 | LPITEMIDLIST GetPidlFromName(IShellFolder *lpsf,LPCSTR lpcstrFileName)
|
---|
2733 | {
|
---|
2734 | LPITEMIDLIST pidl;
|
---|
2735 | ULONG ulEaten;
|
---|
2736 | WCHAR lpwstrDirName[MAX_PATH];
|
---|
2737 |
|
---|
2738 | TRACE("sf=%p file=%s\n", lpsf, lpcstrFileName);
|
---|
2739 |
|
---|
2740 | #ifdef __WIN32OS2__
|
---|
2741 | if(!lpcstrFileName || *lpcstrFileName == 0) return NULL;
|
---|
2742 | #else
|
---|
2743 | if(!lpcstrFileName) return NULL;
|
---|
2744 | #endif
|
---|
2745 |
|
---|
2746 | MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,lpcstrFileName,-1,(LPWSTR)lpwstrDirName,MAX_PATH);
|
---|
2747 |
|
---|
2748 | if(!lpsf)
|
---|
2749 | {
|
---|
2750 | COMDLG32_SHGetDesktopFolder(&lpsf);
|
---|
2751 | pidl = GetPidlFromName(lpsf, lpcstrFileName);
|
---|
2752 | IShellFolder_Release(lpsf);
|
---|
2753 | }
|
---|
2754 | else
|
---|
2755 | {
|
---|
2756 | IShellFolder_ParseDisplayName(lpsf, 0, NULL, (LPWSTR)lpwstrDirName, &ulEaten, &pidl, NULL);
|
---|
2757 | }
|
---|
2758 | return pidl;
|
---|
2759 | }
|
---|
2760 |
|
---|
2761 | /*
|
---|
2762 | */
|
---|
2763 | BOOL IsPidlFolder (LPSHELLFOLDER psf, LPITEMIDLIST pidl)
|
---|
2764 | {
|
---|
2765 | ULONG uAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
|
---|
2766 | HRESULT ret;
|
---|
2767 |
|
---|
2768 | TRACE("%p, %p\n", psf, pidl);
|
---|
2769 |
|
---|
2770 | ret = IShellFolder_GetAttributesOf( psf, 1, &pidl, &uAttr );
|
---|
2771 |
|
---|
2772 | TRACE("-- 0x%08lx 0x%08lx\n", uAttr, ret);
|
---|
2773 | /* see documentation shell 4.1*/
|
---|
2774 | return uAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER);
|
---|
2775 | }
|
---|
2776 |
|
---|
2777 | /***********************************************************************
|
---|
2778 | * BrowseSelectedFolder
|
---|
2779 | */
|
---|
2780 | static BOOL BrowseSelectedFolder(HWND hwnd)
|
---|
2781 | {
|
---|
2782 | BOOL bBrowseSelFolder = FALSE;
|
---|
2783 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
|
---|
2784 |
|
---|
2785 | TRACE("\n");
|
---|
2786 |
|
---|
2787 | if (GetNumSelected(fodInfos->Shell.FOIDataObject) == 1)
|
---|
2788 | {
|
---|
2789 | LPITEMIDLIST pidlSelection;
|
---|
2790 |
|
---|
2791 | /* get the file selected */
|
---|
2792 | pidlSelection = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, 1);
|
---|
2793 | if (IsPidlFolder (fodInfos->Shell.FOIShellFolder, pidlSelection))
|
---|
2794 | {
|
---|
2795 | if ( FAILED( IShellBrowser_BrowseObject( fodInfos->Shell.FOIShellBrowser,
|
---|
2796 | pidlSelection, SBSP_RELATIVE ) ) )
|
---|
2797 | {
|
---|
2798 | MessageBoxA( hwnd, "Path does not exist", fodInfos->ofnInfos->lpstrTitle,
|
---|
2799 | MB_OK | MB_ICONEXCLAMATION );
|
---|
2800 | }
|
---|
2801 |
|
---|
2802 | bBrowseSelFolder = TRUE;
|
---|
2803 | }
|
---|
2804 | COMDLG32_SHFree( pidlSelection );
|
---|
2805 | }
|
---|
2806 |
|
---|
2807 | return bBrowseSelFolder;
|
---|
2808 | }
|
---|
2809 |
|
---|
2810 | /*
|
---|
2811 | * Memory allocation methods */
|
---|
2812 | static void *MemAlloc(UINT size)
|
---|
2813 | {
|
---|
2814 | return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
|
---|
2815 | }
|
---|
2816 |
|
---|
2817 | static void MemFree(void *mem)
|
---|
2818 | {
|
---|
2819 | if(mem)
|
---|
2820 | {
|
---|
2821 | HeapFree(GetProcessHeap(),0,mem);
|
---|
2822 | }
|
---|
2823 | }
|
---|
2824 |
|
---|