source: trunk/src/comdlg32/filedlg95.c@ 3232

Last change on this file since 3232 was 3216, checked in by cbratschi, 26 years ago

* empty log message *

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