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