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

Last change on this file since 3265 was 3256, checked in by cbratschi, 26 years ago

* empty log message *

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