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

Last change on this file since 3204 was 3202, checked in by cbratschi, 26 years ago

faster file dialog combobox

File size: 77.0 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 if((browsePidl = GetPidlFromName(psfDesktop,lpstrPathSpec)))
1207 {
1208 /* Browse to directory */
1209 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1210 browsePidl,
1211 SBSP_ABSOLUTE);
1212 COMDLG32_SHFree(browsePidl);
1213 }
1214 else
1215 {
1216 /* Path does not exist */
1217 if(fodInfos->ofnInfos.Flags & OFN_PATHMUSTEXIST)
1218 {
1219 MessageBoxA(hwnd,
1220 "Path does not exist",
1221 fodInfos->ofnInfos.lpstrTitle,
1222 MB_OK | MB_ICONEXCLAMATION);
1223 return FALSE;
1224 }
1225 }
1226
1227 strcat(lpstrPathAndFile,lpstrPathSpec);
1228 IShellFolder_Release(psfDesktop);
1229 }
1230 else
1231 {
1232 strcat(lpstrPathAndFile,lpstrCurrentDir);
1233 }
1234
1235 /* Create the path and file string */
1236 COMDLG32_PathAddBackslashA(lpstrPathAndFile);
1237 strcat(lpstrPathAndFile,lpstrFileSpec);
1238
1239 /* Update the edit field */
1240 SetDlgItemTextA(hwnd,IDC_FILENAME,lpstrFileSpec);
1241 SendDlgItemMessageA(hwnd,IDC_FILENAME,EM_SETSEL,0,-1);
1242
1243 /* Don't go further if we dont have a file spec */
1244 if(!strlen(lpstrFileSpec) || !strcmp(lpstrFileSpec,lpstrPathSpec))
1245 return FALSE;
1246
1247 /* Time to check lpstrFileSpec */
1248 /* search => contains * or ? */
1249 /* browse => contains a directory name */
1250 /* file => contains a file name */
1251
1252 /* Check if this is a search */
1253 if(strchr(lpstrFileSpec,'*') || strchr(lpstrFileSpec,'?'))
1254 {
1255 int iPos;
1256
1257 /* Set the current filter with the current selection */
1258 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1259 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1260
1261 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFileSpec)+1)*2);
1262 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,
1263 (LPSTR)strlwr((LPSTR)lpstrFileSpec));
1264
1265 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1266
1267 if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB,
1268 lpstrFileSpec)))
1269 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1270
1271 return FALSE;
1272 }
1273
1274 /* browse if the user specified a directory */
1275 browsePidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder,
1276 lpstrFileSpec);
1277 if (!browsePidl) /* not a directory check the specified file exists */
1278 {
1279 int iExt;
1280 char lpstrFileSpecTemp[MAX_PATH] = "";
1281 LPSTR lpstrExt;
1282 LPSTR lpOrg;
1283 LPSTR lpBuf;
1284 iExt = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1285 lpOrg = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, iExt);
1286 lpstrExt = lpOrg;
1287
1288 /*
1289 add user specified extentions to the file one by one and
1290 check if the file exists
1291 */
1292 while(lpOrg)
1293 {
1294 int i;
1295 if ((lpstrExt = strchr(lpOrg, ';')))
1296 {
1297 i = lpstrExt - lpOrg;
1298 }
1299 else
1300 i = strlen(lpOrg);
1301 lpBuf = MemAlloc(i+1);
1302 strncpy(lpBuf, lpOrg, i);
1303 lpBuf[i] = 0;
1304 strcpy(lpstrFileSpecTemp, lpstrFileSpec);
1305 if (lpstrFileSpecTemp[strlen(lpstrFileSpecTemp)-1] == '.')
1306 {
1307 if (strchr(lpBuf, '.'))
1308 strcat(lpstrFileSpecTemp, (strchr(lpBuf, '.')) + 1);
1309 } else {
1310 if (strchr(lpBuf, '.'))
1311 strcat(lpstrFileSpecTemp, strchr(lpBuf, '.'));
1312 }
1313 browsePidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder,
1314 lpstrFileSpecTemp);
1315 MemFree((void *)lpBuf);
1316 if (browsePidl)
1317 {
1318 strcpy(lpstrFileSpec,lpstrFileSpecTemp);
1319 break;
1320 }
1321 if (lpstrExt)
1322 lpOrg = lpstrExt+1;
1323 else
1324 lpOrg = NULL;
1325 }
1326 }
1327
1328 if (browsePidl)
1329 {
1330 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
1331 int nMsgBoxRet;
1332 char lpstrFileExist[MAX_PATH + 50];
1333
1334 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder,
1335 1,
1336 &browsePidl,
1337 &ulAttr);
1338
1339 /* Browse to directory if it is a folder */
1340 if (ulAttr & SFGAO_FOLDER)
1341 {
1342 if(FAILED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1343 browsePidl,
1344 SBSP_RELATIVE)))
1345 {
1346 if(fodInfos->ofnInfos.Flags & OFN_PATHMUSTEXIST)
1347 {
1348 MessageBoxA(hwnd,
1349 "Path does not exist",
1350 fodInfos->ofnInfos.lpstrTitle,
1351 MB_OK | MB_ICONEXCLAMATION);
1352 COMDLG32_SHFree(browsePidl);
1353 return FALSE;
1354 }
1355 }
1356 COMDLG32_SHFree(browsePidl);
1357 return FALSE;
1358 }
1359
1360 /* The file does exist, so ask the user if we should overwrite it */
1361 if((fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) &&
1362 (fodInfos->ofnInfos.Flags & OFN_OVERWRITEPROMPT))
1363 {
1364 strcpy(lpstrFileExist, lpstrFileSpec);
1365 strcat(lpstrFileExist, " already exists.\nDo you want to replace it?");
1366
1367 nMsgBoxRet = MessageBoxA(hwnd,
1368 lpstrFileExist,
1369 fodInfos->ofnInfos.lpstrTitle,
1370 MB_YESNO | MB_ICONEXCLAMATION);
1371 if (nMsgBoxRet == IDNO)
1372 {
1373 COMDLG32_SHFree(browsePidl);
1374 return FALSE;
1375 }
1376 }
1377 COMDLG32_SHFree(browsePidl);
1378 }
1379 else
1380 {
1381 /* File does not exist in current directory */
1382
1383 /* The selected file does not exist */
1384 /* Tell the user the selected does not exist */
1385 if(fodInfos->ofnInfos.Flags & OFN_FILEMUSTEXIST)
1386 {
1387 char lpstrNotFound[100];
1388 char lpstrMsg[100];
1389 char tmp[400];
1390
1391 LoadStringA(COMMDLG_hInstance32,
1392 IDS_FILENOTFOUND,
1393 lpstrNotFound,
1394 100);
1395 LoadStringA(COMMDLG_hInstance32,
1396 IDS_VERIFYFILE,
1397 lpstrMsg,
1398 100);
1399
1400 strcpy(tmp,fodInfos->ofnInfos.lpstrFile);
1401 strcat(tmp,"\n");
1402 strcat(tmp,lpstrNotFound);
1403 strcat(tmp,"\n");
1404 strcat(tmp,lpstrMsg);
1405
1406 MessageBoxA(hwnd,
1407 tmp,
1408 fodInfos->ofnInfos.lpstrTitle,
1409 MB_OK | MB_ICONEXCLAMATION);
1410 return FALSE;
1411 }
1412 /* Ask the user if he wants to create the file*/
1413 if(fodInfos->ofnInfos.Flags & OFN_CREATEPROMPT)
1414 {
1415 char tmp[100];
1416
1417 LoadStringA(COMMDLG_hInstance32,IDS_CREATEFILE,tmp,100);
1418
1419 if(IDYES == MessageBoxA(hwnd,tmp,fodInfos->ofnInfos.lpstrTitle,
1420 MB_YESNO | MB_ICONQUESTION))
1421 {
1422 /* Create the file, clean and exit */
1423 FILEDLG95_Clean(hwnd);
1424 return EndDialog(hwnd,TRUE);
1425 }
1426 return FALSE;
1427 }
1428 }
1429
1430 /* Open the selected file */
1431
1432 /* Check file extension */
1433 if(!strrchr(lpstrPathAndFile,'.'))
1434 {
1435 /* if the file has no extension, append the selected
1436 extension of the filetype combo box */
1437 int iExt;
1438 LPSTR lpstrExt;
1439 iExt = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1440 lpstrTemp = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iExt);
1441
1442 if((LPSTR)-1 != lpstrTemp)
1443 {
1444 if((lpstrExt = strchr(lpstrTemp,';')))
1445 {
1446 int i = lpstrExt - lpstrTemp;
1447 lpstrExt = MemAlloc(i);
1448 strncpy(lpstrExt,&lpstrTemp[1],i-1);
1449 }
1450 else
1451 {
1452 lpstrExt = MemAlloc(strlen(lpstrTemp));
1453 strcpy(lpstrExt,&lpstrTemp[1]);
1454 }
1455
1456 if(!strcmp(&lpstrExt[1],"*") && fodInfos->ofnInfos.lpstrDefExt)
1457 {
1458 lpstrExt = MemAlloc(strlen(fodInfos->ofnInfos.lpstrDefExt)+2);
1459 strcat(lpstrExt,".");
1460 strcat(lpstrExt,(LPSTR) fodInfos->ofnInfos.lpstrDefExt);
1461 }
1462 strcat(lpstrPathAndFile,lpstrExt);
1463 }
1464 }
1465 /* Check that size size of the file does not exceed buffer size */
1466 if(strlen(lpstrPathAndFile) > fodInfos->ofnInfos.nMaxFile)
1467 {
1468 /* set error FNERR_BUFFERTOSMALL */
1469 FILEDLG95_Clean(hwnd);
1470 return EndDialog(hwnd,FALSE);
1471 }
1472 strcpy(fodInfos->ofnInfos.lpstrFile,lpstrPathAndFile);
1473
1474 /* Set the lpstrFileTitle of the OPENFILENAME structure */
1475 if(fodInfos->ofnInfos.lpstrFileTitle)
1476 strncpy(fodInfos->ofnInfos.lpstrFileTitle,
1477 lpstrFileSpec,
1478 fodInfos->ofnInfos.nMaxFileTitle);
1479
1480 /* Check if the file is to be opened as read only */
1481 if(BST_CHECKED == SendDlgItemMessageA(hwnd,
1482 IDC_OPENREADONLY,
1483 BM_GETSTATE,0,0))
1484 SetFileAttributesA(fodInfos->ofnInfos.lpstrFile,
1485 FILE_ATTRIBUTE_READONLY);
1486
1487 /* nFileExtension and nFileOffset of OPENFILENAME structure */
1488 lpstrTemp = strrchr(fodInfos->ofnInfos.lpstrFile,'\\');
1489 fodInfos->ofnInfos.nFileOffset = lpstrTemp - fodInfos->ofnInfos.lpstrFile + 1;
1490 lpstrTemp = strrchr(fodInfos->ofnInfos.lpstrFile,'.');
1491 fodInfos->ofnInfos.nFileExtension = lpstrTemp - fodInfos->ofnInfos.lpstrFile + 1;
1492
1493
1494 /* clean and exit */
1495 FILEDLG95_Clean(hwnd);
1496 return EndDialog(hwnd,TRUE);
1497 }
1498
1499 return FALSE;
1500}
1501
1502/***********************************************************************
1503 * FILEDLG95_SHELL_Init
1504 *
1505 * Initialisation of the shell objects
1506 */
1507static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
1508{
1509 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1510
1511 TRACE("\n");
1512
1513 /*
1514 * Initialisation of the FileOpenDialogInfos structure
1515 */
1516
1517 /* Shell */
1518
1519 fodInfos->Shell.FOIShellView = NULL;
1520 if(FAILED(COMDLG32_SHGetDesktopFolder(&fodInfos->Shell.FOIShellFolder)))
1521 return E_FAIL;
1522
1523 /*ShellInfos */
1524 fodInfos->ShellInfos.hwndOwner = hwnd;
1525
1526 fodInfos->ShellInfos.folderSettings.fFlags = FWF_AUTOARRANGE | FWF_ALIGNLEFT;
1527 fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
1528
1529 GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
1530 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
1531 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
1532
1533 /* Construct the IShellBrowser interface */
1534 fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
1535
1536 return NOERROR;
1537}
1538
1539/***********************************************************************
1540 * FILEDLG95_SHELL_ExecuteCommand
1541 *
1542 * Change the folder option and refresh the view
1543 * If the function succeeds, the return value is nonzero.
1544 */
1545static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
1546{
1547 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1548
1549 IContextMenu * pcm;
1550 CMINVOKECOMMANDINFO ci;
1551 TRACE("\n");
1552
1553 if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
1554 SVGIO_BACKGROUND,
1555 &IID_IContextMenu,
1556 (LPVOID*)&pcm)))
1557 {
1558 ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
1559 ci.lpVerb = lpVerb;
1560 ci.hwnd = hwnd;
1561
1562 IContextMenu_InvokeCommand(pcm, &ci);
1563 IContextMenu_Release(pcm);
1564 }
1565
1566 return FALSE;
1567}
1568
1569/***********************************************************************
1570 * FILEDLG95_SHELL_UpFolder
1571 *
1572 * Browse to the specified object
1573 * If the function succeeds, the return value is nonzero.
1574 */
1575static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
1576{
1577 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1578
1579 TRACE("\n");
1580
1581 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1582 NULL,
1583 SBSP_PARENT)))
1584 {
1585 return TRUE;
1586 }
1587 return FALSE;
1588}
1589
1590/***********************************************************************
1591 * FILEDLG95_SHELL_NewFolder
1592 *
1593 * Creates a new directory with New folder as name
1594 * If the function succeeds, the return value is nonzero.
1595 * FIXME: let the contextmenu (CMDSTR_NEWFOLDER) do this thing
1596 */
1597static BOOL FILEDLG95_SHELL_NewFolder(HWND hwnd)
1598{
1599 char lpstrDirName[MAX_PATH] = "New Folder";
1600 char lpstrNewDir[MAX_PATH];
1601 BOOL bRes = FALSE;
1602 HANDLE hHandle;
1603 WIN32_FIND_DATAA FindData;
1604 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1605
1606 TRACE("\n");
1607
1608 /* Create the absolute path for "New Folder" */
1609 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent, lpstrNewDir);
1610 COMDLG32_PathAddBackslashA(lpstrNewDir);
1611 strcat(lpstrNewDir, lpstrDirName);
1612
1613 /* Find a Unique directory name */
1614 hHandle = FindFirstFileA(lpstrNewDir,&FindData);
1615 if(hHandle !=INVALID_HANDLE_VALUE)
1616 {
1617 int i;
1618 char lpstrDupNewDir[MAX_PATH];
1619 char lpstrDirNameExt[8];
1620 strcpy(lpstrDupNewDir, lpstrNewDir);
1621 for(i=0; i < 256 && hHandle != INVALID_HANDLE_VALUE; i++)
1622 {
1623 FindClose(hHandle);
1624 sprintf(lpstrNewDir,"%s (%d)", lpstrDupNewDir, i+1);
1625 hHandle = FindFirstFileA(lpstrNewDir,&FindData);
1626 }
1627 sprintf(lpstrDirNameExt," (%d)", i);
1628 strcat(lpstrDirName, lpstrDirNameExt);
1629 }
1630 /* Is Unique Found */
1631 if(hHandle == INVALID_HANDLE_VALUE)
1632 {
1633 bRes = CreateDirectoryA(lpstrNewDir,NULL);
1634
1635 if(bRes)
1636 {
1637 LPITEMIDLIST pidl;
1638 /* Refresh the list (this will update the pidl, to include the new directory) */
1639 /* Might want to only update the list (so the directory appears at the end */
1640 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1641 pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder,lpstrDirName);
1642
1643 IShellView_SelectItem(fodInfos->Shell.FOIShellView,
1644 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
1645 |SVSI_FOCUSED|SVSI_SELECT));
1646
1647 COMDLG32_SHFree(pidl);
1648 }
1649 else
1650 {
1651 char lpstrText[128+MAX_PATH];
1652 char lpstrTempText[128];
1653 char lpstrCaption[256];
1654
1655 /* Cannot Create folder because of permissions */
1656 LoadStringA(COMMDLG_hInstance32, IDS_CREATEFOLDER_DENIED, lpstrTempText, sizeof(lpstrTempText));
1657 LoadStringA(COMMDLG_hInstance32, IDS_FILEOPEN_CAPTION, lpstrCaption, sizeof(lpstrCaption));
1658 sprintf(lpstrText,lpstrTempText, lpstrDirName);
1659 MessageBoxA(hwnd,lpstrText, lpstrCaption, MB_OK | MB_ICONEXCLAMATION);
1660 }
1661 }
1662 return bRes;
1663}
1664
1665/***********************************************************************
1666 * FILEDLG95_SHELL_Clean
1667 *
1668 * Cleans the memory used by shell objects
1669 */
1670static void FILEDLG95_SHELL_Clean(HWND hwnd)
1671{
1672 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1673
1674 TRACE("\n");
1675
1676 /* clean Shell interfaces */
1677 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
1678 IShellView_Release(fodInfos->Shell.FOIShellView);
1679 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
1680 IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
1681}
1682
1683/***********************************************************************
1684 * FILEDLG95_FILETYPE_Init
1685 *
1686 * Initialisation of the file type combo box
1687 */
1688static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
1689{
1690 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1691
1692 TRACE("\n");
1693
1694 if(fodInfos->ofnInfos.lpstrFilter)
1695 {
1696 int iStrIndex = 0;
1697 int iPos = 0;
1698 LPSTR lpstrFilter;
1699 LPSTR lpstrTmp;
1700
1701 for(;;)
1702 {
1703 /* filter is a list... title\0ext\0......\0\0
1704 * Set the combo item text to the title and the item data
1705 * to the ext
1706 */
1707 char *lpstrExt = NULL;
1708 LPSTR lpstrExtTmp = NULL;
1709
1710 /* Get the title */
1711 lpstrTmp = (&((LPBYTE)fodInfos->ofnInfos.lpstrFilter)[iStrIndex]);
1712 if(!strlen(lpstrTmp))
1713 break;
1714 iStrIndex += strlen(lpstrTmp) +1;
1715 /* Get the extension */
1716 lpstrExtTmp = (&((LPBYTE)fodInfos->ofnInfos.lpstrFilter)[iStrIndex]);
1717 if(!lpstrExtTmp)
1718 break;
1719
1720 lpstrExt = (LPSTR) MemAlloc(strlen(lpstrExtTmp)+1);
1721 if(!lpstrExt)
1722 break;
1723
1724 strcpy(lpstrExt,lpstrExtTmp);
1725
1726 iStrIndex += strlen(lpstrExt) +1;
1727
1728 /* Add the item at the end of the combo */
1729 CBAddString(fodInfos->DlgInfos.hwndFileTypeCB,lpstrTmp);
1730 CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos++,lpstrExt);
1731 }
1732 /* Set the current filter to the one specified
1733 * in the initialisation structure
1734 */
1735
1736 /* set default filter index */
1737 if(fodInfos->ofnInfos.nFilterIndex == 0 && fodInfos->ofnInfos.lpstrCustomFilter == NULL)
1738 fodInfos->ofnInfos.nFilterIndex = 1;
1739 /* First, check to make sure our index isn't out of bounds. */
1740 if ( fodInfos->ofnInfos.nFilterIndex > iPos )
1741 fodInfos->ofnInfos.nFilterIndex = iPos;
1742
1743
1744 /* Get the current index selection. */
1745 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB,
1746 fodInfos->ofnInfos.nFilterIndex-1);
1747
1748 /* Get the corresponding text string from the combo box. */
1749 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1750 fodInfos->ofnInfos.nFilterIndex-1);
1751
1752 if(lpstrFilter)
1753 {
1754 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
1755 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,strlwr(lpstrFilter));
1756 }
1757 }
1758 return NOERROR;
1759}
1760
1761/***********************************************************************
1762 * FILEDLG95_FILETYPE_OnCommand
1763 *
1764 * WM_COMMAND of the file type combo box
1765 * If the function succeeds, the return value is nonzero.
1766 */
1767static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
1768{
1769 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1770
1771 switch(wNotifyCode)
1772 {
1773 case CBN_CLOSEUP:
1774 {
1775 LPSTR lpstrFilter;
1776//CB: todo: check if selection really changed
1777 /* Get the current item of the filetype combo box */
1778 int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1779
1780 /* Set the current filter with the current selection */
1781 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1782 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1783
1784 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1785 iItem);
1786 if((int)lpstrFilter != CB_ERR)
1787 {
1788 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
1789 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,(LPSTR)strlwr((LPSTR)lpstrFilter));
1790 SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
1791 }
1792
1793 /* Refresh the actual view to display the included items*/
1794 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1795
1796 }
1797 }
1798 return FALSE;
1799}
1800/***********************************************************************
1801 * FILEDLG95_FILETYPE_SearchExt
1802 *
1803 * Search for pidl in the lookin combo box
1804 * returns the index of the found item
1805 */
1806static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPSTR lpstrExt)
1807{
1808 int i = 0;
1809 int iCount = CBGetCount(hwnd);
1810
1811 TRACE("\n");
1812
1813 for(;i<iCount;i++)
1814 {
1815 LPSTR ext = (LPSTR) CBGetItemDataPtr(hwnd,i);
1816
1817 if(!strcasecmp(lpstrExt,ext))
1818 return i;
1819 }
1820
1821 return -1;
1822}
1823
1824/***********************************************************************
1825 * FILEDLG95_FILETYPE_Clean
1826 *
1827 * Clean the memory used by the filetype combo box
1828 */
1829static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
1830{
1831 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1832 int iPos;
1833 int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
1834
1835 TRACE("\n");
1836
1837 /* Delete each string of the combo and their associated data */
1838 for(iPos = iCount-1;iPos>=0;iPos--)
1839 {
1840 MemFree((LPVOID)(CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos)));
1841 CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1842 }
1843 /* Current filter */
1844 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1845 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1846
1847}
1848
1849/***********************************************************************
1850 * FILEDLG95_LOOKIN_Init
1851 *
1852 * Initialisation of the look in combo box
1853 */
1854static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
1855{
1856 IShellFolder *psfRoot, *psfDrives;
1857 IEnumIDList *lpeRoot, *lpeDrives;
1858 LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
1859
1860 LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
1861
1862 TRACE("\n");
1863
1864 liInfos->iMaxIndentation = 0;
1865
1866 SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
1867 CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
1868
1869 /* Initialise data of Desktop folder */
1870 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
1871 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1872 COMDLG32_SHFree(pidlTmp);
1873
1874 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
1875
1876 COMDLG32_SHGetDesktopFolder(&psfRoot);
1877
1878 if (psfRoot)
1879 {
1880 /* enumerate the contents of the desktop */
1881 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
1882 {
1883 while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
1884 {
1885 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1886
1887 /* special handling for CSIDL_DRIVES */
1888 if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
1889 {
1890 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
1891 {
1892 /* enumerate the drives */
1893 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
1894 {
1895 while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
1896 {
1897 pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
1898 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
1899 COMDLG32_SHFree(pidlAbsTmp);
1900 COMDLG32_SHFree(pidlTmp1);
1901 }
1902 IEnumIDList_Release(lpeDrives);
1903 }
1904 IShellFolder_Release(psfDrives);
1905 }
1906 }
1907 COMDLG32_SHFree(pidlTmp);
1908 }
1909 IEnumIDList_Release(lpeRoot);
1910 }
1911 }
1912
1913 IShellFolder_Release(psfRoot);
1914 COMDLG32_SHFree(pidlDrives);
1915
1916 return NOERROR;
1917}
1918
1919/***********************************************************************
1920 * FILEDLG95_LOOKIN_DrawItem
1921 *
1922 * WM_DRAWITEM message handler
1923 */
1924static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
1925{
1926 COLORREF crWin = GetSysColor(COLOR_WINDOW);
1927 COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
1928 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1929 RECT rectText;
1930 RECT rectIcon;
1931 int iIndentation;
1932 LPSFOLDER tmpFolder;
1933
1934 LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
1935
1936 TRACE("\n");
1937
1938 if(pDIStruct->itemID == -1)
1939 return 0;
1940
1941 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
1942 pDIStruct->itemID)))
1943 return 0;
1944
1945 if (!tmpFolder->szDisplayName)
1946 {
1947 SHFILEINFOA sfi;
1948 INT len;
1949
1950 tmpFolder->ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR)tmpFolder->pidlItem,
1951 0,
1952 &sfi,
1953 sizeof (SHFILEINFOA),
1954 SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME);
1955 len = strlen(sfi.szDisplayName)+1;
1956 tmpFolder->szDisplayName = MemAlloc(len);
1957 strcpy(tmpFolder->szDisplayName,sfi.szDisplayName);
1958 tmpFolder->iIcon = sfi.iIcon;
1959 }
1960
1961 /* Is this item selected ?*/
1962 if(pDIStruct->itemState & ODS_SELECTED)
1963 {
1964 SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
1965 SetBkColor(pDIStruct->hDC,crHighLight);
1966 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight);
1967 }
1968 else
1969 {
1970 SetTextColor(pDIStruct->hDC,crText);
1971 SetBkColor(pDIStruct->hDC,crWin);
1972 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin);
1973 }
1974
1975 /* Do not indent item if drawing in the edit of the combo*/
1976 if (pDIStruct->itemState & ODS_COMBOBOXEDIT)
1977 iIndentation = 0;
1978 else
1979 iIndentation = tmpFolder->m_iIndent;
1980
1981 /* Draw text and icon */
1982
1983 /* Initialise the icon display area */
1984 rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
1985 rectIcon.top = pDIStruct->rcItem.top;
1986 rectIcon.right = rectIcon.left + ICONWIDTH;
1987 rectIcon.bottom = pDIStruct->rcItem.bottom;
1988
1989 /* Initialise the text display area */
1990 rectText.left = rectIcon.right;
1991 rectText.top = pDIStruct->rcItem.top + YTEXTOFFSET;
1992 rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
1993 rectText.bottom = pDIStruct->rcItem.bottom;
1994
1995
1996 /* Draw the icon from the image list */
1997 COMDLG32_ImageList_Draw(tmpFolder->ilItemImage,
1998 tmpFolder->iIcon,
1999 pDIStruct->hDC,
2000 rectIcon.left,
2001 rectIcon.top,
2002 ILD_TRANSPARENT );
2003
2004 /* Draw the associated text */
2005 if (tmpFolder->szDisplayName)
2006 TextOutA(pDIStruct->hDC,rectText.left,rectText.top,tmpFolder->szDisplayName,strlen(tmpFolder->szDisplayName));
2007
2008
2009 return NOERROR;
2010}
2011
2012/***********************************************************************
2013 * FILEDLG95_LOOKIN_OnCommand
2014 *
2015 * LookIn combo box WM_COMMAND message handler
2016 * If the function succeeds, the return value is nonzero.
2017 */
2018static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
2019{
2020 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2021
2022 TRACE("\n");
2023
2024 switch(wNotifyCode)
2025 {
2026 case CBN_CLOSEUP:
2027 {
2028 LPSFOLDER tmpFolder;
2029 int iItem;
2030
2031 iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
2032
2033 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
2034 iItem)))
2035 return FALSE;
2036
2037
2038 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
2039 tmpFolder->pidlItem,
2040 SBSP_ABSOLUTE)))
2041 {
2042 return TRUE;
2043 }
2044 break;
2045 }
2046
2047 }
2048 return FALSE;
2049}
2050
2051/***********************************************************************
2052 * FILEDLG95_LOOKIN_AddItem
2053 *
2054 * Adds an absolute pidl item to the lookin combo box
2055 * returns the index of the inserted item
2056 */
2057static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
2058{
2059 LPITEMIDLIST pidlNext;
2060 SHFILEINFOA sfi;
2061 SFOLDER *tmpFolder = MemAlloc(sizeof(SFOLDER));
2062 LookInInfos *liInfos;
2063
2064 TRACE("\n");
2065
2066 if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
2067 return -1;
2068
2069 tmpFolder->m_iIndent = 0;
2070 tmpFolder->szDisplayName = NULL;
2071
2072 if(!pidl)
2073 return -1;
2074
2075 /* Calculate the indentation of the item in the lookin*/
2076 pidlNext = pidl;
2077 while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
2078 {
2079 tmpFolder->m_iIndent++;
2080 }
2081
2082 tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl);
2083
2084 if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
2085 liInfos->iMaxIndentation = tmpFolder->m_iIndent;
2086
2087 COMDLG32_SHGetFileInfoA((LPSTR)pidl,
2088 0,
2089 &sfi,
2090 sizeof(sfi),
2091 SHGFI_ATTRIBUTES);
2092
2093 if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
2094 {
2095 int iItemID;
2096
2097 /* Add the item at the end of the list */
2098 if(iInsertId < 0)
2099 {
2100 iItemID = CBAddString(hwnd,NULL);
2101 }
2102 /* Insert the item at the iInsertId position*/
2103 else
2104 {
2105 iItemID = CBInsertString(hwnd,NULL,iInsertId);
2106 }
2107
2108 CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
2109 return iItemID;
2110 }
2111
2112 return -1;
2113
2114}
2115
2116/***********************************************************************
2117 * FILEDLG95_LOOKIN_InsertItemAfterParent
2118 *
2119 * Insert an item below its parent
2120 */
2121static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
2122{
2123
2124 LPITEMIDLIST pidlParent = GetParentPidl(pidl);
2125 int iParentPos;
2126
2127 TRACE("\n");
2128
2129 iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
2130
2131 if(iParentPos < 0)
2132 {
2133 iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
2134 }
2135
2136 /* Free pidlParent memory */
2137 COMDLG32_SHFree((LPVOID)pidlParent);
2138
2139 return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
2140}
2141
2142/***********************************************************************
2143 * FILEDLG95_LOOKIN_SelectItem
2144 *
2145 * Adds an absolute pidl item to the lookin combo box
2146 * returns the index of the inserted item
2147 */
2148int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
2149{
2150 int iItemPos;
2151 LookInInfos *liInfos;
2152
2153 TRACE("\n");
2154
2155 iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
2156
2157 liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2158
2159 if(iItemPos < 0)
2160 {
2161 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
2162 iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
2163 }
2164
2165 else
2166 {
2167 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2168 while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
2169 {
2170 int iRemovedItem;
2171
2172 if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
2173 break;
2174 if(iRemovedItem < iItemPos)
2175 iItemPos--;
2176 }
2177 }
2178
2179 CBSetCurSel(hwnd,iItemPos);
2180 liInfos->uSelectedItem = iItemPos;
2181
2182 return 0;
2183
2184}
2185
2186/***********************************************************************
2187 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2188 *
2189 * Remove the item with an expansion level over iExpansionLevel
2190 */
2191static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
2192{
2193 int iItemPos;
2194
2195 LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2196
2197 TRACE("\n");
2198
2199 if(liInfos->iMaxIndentation <= 2)
2200 return -1;
2201
2202 if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
2203 {
2204 SFOLDER *tmpFolder;
2205
2206 tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2207 if (tmpFolder->szDisplayName) MemFree(tmpFolder->szDisplayName);
2208 MemFree(tmpFolder);
2209 CBDeleteString(hwnd,iItemPos);
2210 liInfos->iMaxIndentation--;
2211
2212 return iItemPos;
2213 }
2214
2215 return -1;
2216}
2217
2218/***********************************************************************
2219 * FILEDLG95_LOOKIN_SearchItem
2220 *
2221 * Search for pidl in the lookin combo box
2222 * returns the index of the found item
2223 */
2224static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
2225{
2226 int i = 0;
2227 int iCount = CBGetCount(hwnd);
2228
2229 TRACE("\n");
2230
2231 for(;i<iCount;i++)
2232 {
2233 LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
2234
2235 if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
2236 return i;
2237 if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
2238 return i;
2239
2240 }
2241
2242 return -1;
2243}
2244
2245/***********************************************************************
2246 * FILEDLG95_LOOKIN_Clean
2247 *
2248 * Clean the memory used by the lookin combo box
2249 */
2250static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
2251{
2252 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2253 int iPos;
2254 int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
2255
2256 TRACE("\n");
2257
2258 /* Delete each string of the combo and their associated data */
2259 for(iPos = iCount-1;iPos>=0;iPos--)
2260 {
2261 SFOLDER *tmpFolder = (LPSFOLDER)CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos);
2262
2263 if (tmpFolder->szDisplayName) MemFree(tmpFolder->szDisplayName);
2264 MemFree(tmpFolder);
2265 CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
2266 }
2267 /* LookInInfos structure */
2268 RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
2269
2270}
2271/*
2272 * TOOLS
2273 */
2274
2275/***********************************************************************
2276 * GetName
2277 *
2278 * Get the pidl's display name (relative to folder) and
2279 * put it in lpstrFileName.
2280 *
2281 * Return NOERROR on success,
2282 * E_FAIL otherwise
2283 */
2284
2285HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
2286{
2287 STRRET str;
2288 HRESULT hRes;
2289
2290 TRACE("%p %p\n", lpsf, pidl);
2291
2292 if(!lpsf)
2293 {
2294 HRESULT hRes;
2295 COMDLG32_SHGetDesktopFolder(&lpsf);
2296 hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
2297 IShellFolder_Release(lpsf);
2298 return hRes;
2299 }
2300
2301 /* Get the display name of the pidl relative to the folder */
2302 if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf,
2303 pidl,
2304 dwFlags,
2305 &str)))
2306 {
2307 return StrRetToBufA(&str, pidl,lpstrFileName, MAX_PATH);
2308 }
2309 return E_FAIL;
2310}
2311
2312/***********************************************************************
2313 * GetShellFolderFromPidl
2314 *
2315 * pidlRel is the item pidl relative
2316 * Return the IShellFolder of the absolute pidl
2317 */
2318IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
2319{
2320 IShellFolder *psf = NULL,*psfParent;
2321
2322 TRACE("%p\n", pidlAbs);
2323
2324 if(SUCCEEDED(COMDLG32_SHGetDesktopFolder(&psfParent)))
2325 {
2326 psf = psfParent;
2327 if(pidlAbs && pidlAbs->mkid.cb)
2328 {
2329 if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
2330 {
2331 IShellFolder_Release(psfParent);
2332 return psf;
2333 }
2334 }
2335 /* return the desktop */
2336 return psfParent;
2337 }
2338 return NULL;
2339}
2340
2341/***********************************************************************
2342 * GetParentPidl
2343 *
2344 * Return the LPITEMIDLIST to the parent of the pidl in the list
2345 */
2346LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
2347{
2348 LPITEMIDLIST pidlParent;
2349
2350 TRACE("%p\n", pidl);
2351
2352 pidlParent = COMDLG32_PIDL_ILClone(pidl);
2353 COMDLG32_PIDL_ILRemoveLastID(pidlParent);
2354
2355 return pidlParent;
2356}
2357
2358/***********************************************************************
2359 * GetPidlFromName
2360 *
2361 * returns the pidl of the file name relative to folder
2362 * NULL if an error occured
2363 */
2364LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName)
2365{
2366 LPITEMIDLIST pidl;
2367 ULONG ulEaten;
2368 wchar_t lpwstrDirName[MAX_PATH];
2369
2370
2371 TRACE("sf=%p file=%s\n", psf, lpcstrFileName);
2372
2373 if(!lpcstrFileName)
2374 return NULL;
2375
2376 MultiByteToWideChar(CP_ACP,
2377 MB_PRECOMPOSED,
2378 lpcstrFileName,
2379 -1,
2380 (LPWSTR)lpwstrDirName,
2381 MAX_PATH);
2382
2383 IShellFolder_ParseDisplayName(psf, 0,
2384 NULL,
2385 (LPWSTR)lpwstrDirName,
2386 &ulEaten,
2387 &pidl,
2388 NULL);
2389
2390 return pidl;
2391}
2392
2393/***********************************************************************
2394 * GetFileExtension
2395 *
2396 */
2397BOOL GetFileExtension(IShellFolder *psf,LPITEMIDLIST pidl,LPSTR lpstrFileExtension)
2398{
2399 char FileName[MAX_PATH];
2400 int result;
2401 char *pdest;
2402 int ch = '.';
2403
2404 if(SUCCEEDED(GetName(psf,pidl,SHGDN_NORMAL,FileName)))
2405 {
2406 if(!(pdest = strrchr( FileName, ch )))
2407 return FALSE;
2408
2409 result = pdest - FileName + 1;
2410 strcpy(lpstrFileExtension,&FileName[result]);
2411 return TRUE;
2412 }
2413 return FALSE;
2414}
2415
2416/*
2417 * Memory allocation methods */
2418void *MemAlloc(UINT size)
2419{
2420 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
2421}
2422
2423void MemFree(void *mem)
2424{
2425 if(mem)
2426 {
2427 HeapFree(GetProcessHeap(),0,mem);
2428 }
2429}
Note: See TracBrowser for help on using the repository browser.