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

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

* empty log message *

File size: 84.2 KB
Line 
1/* $Id: filedlg95.c,v 1.5 2000-03-27 15:07:22 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
1132 memset( lpstrFindFile, 0x0, MAX_PATH * sizeof(CHAR) );
1133
1134 lstrcpyA( lpstrFindFile, lpstrPathSpec );
1135 lstrcatA( lpstrFindFile, "\\" );
1136 lstrcatA( lpstrFindFile, lpstrTemp );
1137
1138 if ( FindFirstFileA( lpstrFindFile, &findData ) == INVALID_HANDLE_VALUE )
1139 {
1140 CHAR lpstrNotFound[100];
1141 CHAR lpstrMsg[100];
1142 CHAR tmp[400];
1143
1144 LoadStringA(COMMDLG_hInstance32, IDS_FILENOTFOUND, lpstrNotFound, 100);
1145 LoadStringA(COMMDLG_hInstance32, IDS_VERIFYFILE, lpstrMsg, 100);
1146
1147 strcpy(tmp, lpstrFindFile);
1148 strcat(tmp, "\n");
1149 strcat(tmp, lpstrNotFound);
1150 strcat(tmp, "\n");
1151 strcat(tmp, lpstrMsg);
1152
1153 MessageBoxA(hwnd,
1154 tmp,
1155 fodInfos->ofnInfos->lpstrTitle,
1156 MB_OK | MB_ICONEXCLAMATION);
1157 return FALSE;
1158 }
1159
1160 if (!(fodInfos->ofnInfos->Flags & OFN_EXPLORER ))
1161 {
1162 lstrcatA( lpstrTempFileList, findData.cAlternateFileName);
1163 if ( nCount + 1 < nFileCount)
1164 lstrcatA( lpstrTempFileList, " ");
1165 }
1166 lpstrTemp += strlen(lpstrFileList) + 1;
1167 }
1168 }
1169
1170 if ( fodInfos->ofnInfos->Flags & OFN_EXPLORER )
1171 {
1172 lstrcpyA( lpstrFile, lpstrPathSpec);
1173 memcpy( lpstrFile + sizePath + 1, lpstrFileList, sizeof(CHAR) * sizeUsed );
1174 }
1175 else
1176 {
1177 memcpy( lpstrFile, lpstrTempFileList, sizeof(CHAR) * strlen(lpstrTempFileList));
1178 }
1179
1180 fodInfos->ofnInfos->nFileOffset = sizePath + 1;
1181 fodInfos->ofnInfos->nFileExtension = 0;
1182
1183 /* clean and exit */
1184 return EndDialog(hwnd,TRUE);
1185}
1186
1187/***********************************************************************
1188 * FILEDLG95_OnOpen
1189 *
1190 * Ok button WM_COMMAND message handler
1191 *
1192 * If the function succeeds, the return value is nonzero.
1193 */
1194BOOL FILEDLG95_OnOpen(HWND hwnd)
1195{
1196 CHAR lpstrSpecifiedByUser[MAX_PATH] = "";
1197 CHAR lpstrFileList[MAX_PATH] = "";
1198 LPSTR lpstrFile;
1199 UINT nStrCharCount = 0;
1200 UINT nFileCount = 0;
1201 UINT nFileIndex = 0;
1202 UINT sizeUsed = 0;
1203 UINT nStrLen = 0;
1204
1205 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1206
1207 TRACE("\n");
1208//CB: optimize this function!
1209 /* If a folder is selected browse folder */
1210 if (BrowseSelectedFolder(hwnd))
1211 return FALSE;
1212
1213 lpstrFile = fodInfos->ofnInfos->lpstrFile;
1214
1215 GetDlgItemTextA(hwnd, IDC_FILENAME, lpstrSpecifiedByUser, MAX_PATH);
1216 nStrLen = strlen(lpstrSpecifiedByUser);
1217
1218 while ( nStrCharCount <= nStrLen )
1219 {
1220 if ( lpstrSpecifiedByUser[nStrCharCount]=='"' )
1221 {
1222 nStrCharCount++;
1223
1224 while ((lpstrSpecifiedByUser[nStrCharCount]!='"') &&
1225 (nStrCharCount <= nStrLen))
1226 {
1227 lpstrFileList[nFileIndex++] = lpstrSpecifiedByUser[nStrCharCount];
1228 nStrCharCount++;
1229 sizeUsed++;
1230 }
1231 lpstrFileList[nFileIndex++] = '\0';
1232 sizeUsed++;
1233 nFileCount++;
1234 }
1235 nStrCharCount++;
1236 }
1237
1238 if(nFileCount > 0)
1239 return FILEDLG95_OnOpenMultipleFiles(hwnd, lpstrFileList, nFileCount, sizeUsed);
1240
1241 if (nStrLen)
1242 {
1243 LPSHELLFOLDER psfDesktop;
1244 LPITEMIDLIST browsePidl;
1245 LPSTR lpstrFileSpec;
1246 LPSTR lpstrTemp;
1247 char lpstrPathSpec[MAX_PATH] = "";
1248 char lpstrCurrentDir[MAX_PATH] = "";
1249 char lpstrPathAndFile[MAX_PATH] = "";
1250
1251 /* Separate the file spec from the path spec
1252 e.g.:
1253 lpstrSpecifiedByUser lpstrPathSpec lpstrFileSpec
1254 C:\TEXT1\TEXT2 C:\TEXT1 TEXT2
1255 */
1256 if (nFileCount == 0)
1257 {
1258 lpstrFileSpec = (LPSTR)COMDLG32_PathFindFilenameA(lpstrSpecifiedByUser);
1259 strcpy(lpstrPathSpec,lpstrSpecifiedByUser);
1260 COMDLG32_PathRemoveFileSpecA(lpstrPathSpec);
1261 }
1262
1263 /* Get the index of the selected item in the filetype combo box */
1264 fodInfos->ofnInfos->nFilterIndex = (DWORD) CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1265 /* nFilterIndex is 1 based while combo GetCurSel return zero based index */
1266 fodInfos->ofnInfos->nFilterIndex++;
1267
1268 /* Get the current directory name */
1269 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,
1270 lpstrCurrentDir);
1271
1272 /* Create an absolute path name */
1273 if(lpstrSpecifiedByUser[1] != ':')
1274 {
1275 switch(lpstrSpecifiedByUser[0])
1276 {
1277 /* Add drive spec \TEXT => C:\TEXT */
1278 case '\\':
1279 {
1280 INT iCopy = 2;
1281 char lpstrTmp[MAX_PATH] = "";
1282 if(!strlen(lpstrPathSpec))
1283 iCopy = 3;
1284 strncpy(lpstrTmp,lpstrCurrentDir,iCopy);
1285 strcat(lpstrTmp,lpstrPathSpec);
1286 strcpy(lpstrPathSpec,lpstrTmp);
1287 }
1288 break;
1289 /* Go to parent ..\TEXT */
1290 case '.':
1291 {
1292 INT iSize;
1293 char lpstrTmp2[MAX_PATH] = "";
1294 LPSTR lpstrTmp = strrchr(lpstrCurrentDir,'\\');
1295 iSize = lpstrTmp - lpstrCurrentDir;
1296 strncpy(lpstrTmp2,lpstrCurrentDir,iSize + 1);
1297 if(strlen(lpstrSpecifiedByUser) <= 3)
1298 strcpy(lpstrFileSpec,"");
1299 if(strcmp(lpstrPathSpec,".."))
1300 strcat(lpstrTmp2,&lpstrPathSpec[3]);
1301 strcpy(lpstrPathSpec,lpstrTmp2);
1302 }
1303 break;
1304 default:
1305 {
1306 char lpstrTmp[MAX_PATH] = "";
1307 if(strcmp(&lpstrCurrentDir[strlen(lpstrCurrentDir)-1],"\\"))
1308 strcat(lpstrCurrentDir,"\\");
1309 strcpy(lpstrTmp,lpstrCurrentDir);
1310 strcat(lpstrTmp,lpstrPathSpec);
1311 strcpy(lpstrPathSpec,lpstrTmp);
1312 }
1313
1314 } /* end switch */
1315 }
1316
1317 if(strlen(lpstrPathSpec))
1318 {
1319 /* Browse to the right directory */
1320 COMDLG32_SHGetDesktopFolder(&psfDesktop);
1321 browsePidl = GetPidlFromName(psfDesktop,lpstrPathSpec);
1322 if(browsePidl)
1323 {
1324 /* Browse to directory */
1325 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1326 browsePidl,
1327 SBSP_ABSOLUTE);
1328 COMDLG32_SHFree(browsePidl);
1329 }
1330 else
1331 {
1332 /* Path does not exist */
1333 if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
1334 {
1335 MessageBoxA(hwnd,
1336 "Path does not exist",
1337 fodInfos->ofnInfos->lpstrTitle,
1338 MB_OK | MB_ICONEXCLAMATION);
1339 return FALSE;
1340 }
1341 }
1342
1343 strcat(lpstrPathAndFile,lpstrPathSpec);
1344 IShellFolder_Release(psfDesktop);
1345 }
1346 else
1347 {
1348 strcat(lpstrPathAndFile,lpstrCurrentDir);
1349 }
1350
1351 /* Create the path and file string */
1352 COMDLG32_PathAddBackslashA(lpstrPathAndFile);
1353 strcat(lpstrPathAndFile,lpstrFileSpec);
1354
1355 /* Update the edit field */
1356 SetDlgItemTextA(hwnd,IDC_FILENAME,lpstrFileSpec);
1357 SendDlgItemMessageA(hwnd,IDC_FILENAME,EM_SETSEL,0,-1);
1358
1359 /* Don't go further if we dont have a file spec */
1360 if(!strlen(lpstrFileSpec) || !strcmp(lpstrFileSpec,lpstrPathSpec))
1361 return FALSE;
1362
1363 /* Time to check lpstrFileSpec */
1364 /* search => contains * or ? */
1365 /* browse => contains a directory name */
1366 /* file => contains a file name */
1367
1368 /* Check if this is a search */
1369 if(strchr(lpstrFileSpec,'*') || strchr(lpstrFileSpec,'?'))
1370 {
1371 int iPos;
1372
1373 /* Set the current filter with the current selection */
1374 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1375 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1376
1377 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFileSpec)+1)*2);
1378 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,
1379 (LPSTR)strlwr((LPSTR)lpstrFileSpec));
1380
1381 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1382
1383 if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB,
1384 lpstrFileSpec)))
1385 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1386
1387 return FALSE;
1388 }
1389
1390 {
1391 HANDLE hFile;
1392 WIN32_FIND_DATAA stffile;
1393 /* browse if the user specified a directory */
1394 hFile = FindFirstFileA(lpstrFileSpec, &stffile);
1395 if ( hFile != INVALID_HANDLE_VALUE )
1396 {
1397 FindClose (hFile);
1398 if (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1399 browsePidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder,
1400 lpstrFileSpec);
1401 else
1402 {
1403 // if there is an extention, then get the Pidl otherwise
1404 // we are going to need to add the extention
1405 if(strrchr(lpstrFileSpec,'.'))
1406 browsePidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder,
1407 lpstrFileSpec);
1408 else
1409 browsePidl=NULL;
1410 }
1411 }
1412 else
1413 browsePidl=NULL;
1414 }
1415
1416 if (!browsePidl) /* not a directory check the specified file exists */
1417 {
1418 int i;
1419 int iExt;
1420 char lpstrFileSpecTemp[MAX_PATH] = "";
1421 LPSTR lpstrExt;
1422 LPSTR lpOrg;
1423 LPSTR lpBuf;
1424 iExt = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1425 lpOrg = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, iExt);
1426 if (lpOrg == (LPSTR)-1)
1427 lpOrg = NULL; // we get -1 if the filetype LB is empty
1428
1429 lpstrExt = lpOrg;
1430
1431 /*
1432 Simply take the first one of the list as default.
1433 Otherwise the user must specify which extention they want.
1434 Also, make sure we don't have a .*, in this case simply
1435 forget about the extention
1436 */
1437 lpstrExt = strchr(lpOrg, ';');
1438 if (lpstrExt)
1439 {
1440 i = lpstrExt - lpOrg;
1441 }
1442 else
1443 i = strlen(lpOrg);
1444 lpBuf = MemAlloc(i+1);
1445 strncpy(lpBuf, lpOrg, i);
1446 lpBuf[i] = 0;
1447 strcpy(lpstrFileSpecTemp, lpstrFileSpec);
1448 if (lpstrFileSpecTemp[strlen(lpstrFileSpecTemp)-1] == '.')
1449 {
1450 if (strchr(lpBuf, '.'))
1451 strcat(lpstrFileSpecTemp, (strchr(lpBuf, '.')) + 1);
1452 }
1453 else
1454 strcat(lpstrFileSpecTemp, strchr(lpBuf, '.'));
1455 browsePidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder,
1456 lpstrFileSpecTemp);
1457 MemFree((void *)lpBuf);
1458 if (browsePidl)
1459 strcpy(lpstrFileSpec,lpstrFileSpecTemp);
1460 if (lpstrExt)
1461 lpOrg = lpstrExt+1;
1462 else
1463 lpOrg = NULL;
1464 }
1465
1466 if (browsePidl)
1467 {
1468 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
1469 int nMsgBoxRet;
1470 char lpstrFileExist[MAX_PATH + 50];
1471
1472 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder,
1473 1,
1474 &browsePidl,
1475 &ulAttr);
1476
1477 /* Browse to directory if it is a folder */
1478 if (ulAttr & SFGAO_FOLDER)
1479 {
1480 if(FAILED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1481 browsePidl,
1482 SBSP_RELATIVE)))
1483 {
1484 if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
1485 {
1486 MessageBoxA(hwnd,
1487 "Path does not exist",
1488 fodInfos->ofnInfos->lpstrTitle,
1489 MB_OK | MB_ICONEXCLAMATION);
1490 COMDLG32_SHFree(browsePidl);
1491 return FALSE;
1492 }
1493 }
1494 COMDLG32_SHFree(browsePidl);
1495 return FALSE;
1496 }
1497
1498 /* The file does exist, so ask the user if we should overwrite it */
1499 if((fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) &&
1500 (fodInfos->ofnInfos->Flags & OFN_OVERWRITEPROMPT))
1501 {
1502 strcpy(lpstrFileExist, lpstrFileSpec);
1503 strcat(lpstrFileExist, " already exists.\nDo you want to replace it?");
1504
1505 nMsgBoxRet = MessageBoxA(hwnd,
1506 lpstrFileExist,
1507 fodInfos->ofnInfos->lpstrTitle,
1508 MB_YESNO | MB_ICONEXCLAMATION);
1509 if (nMsgBoxRet == IDNO)
1510 {
1511 COMDLG32_SHFree(browsePidl);
1512 return FALSE;
1513 }
1514 }
1515 COMDLG32_SHFree(browsePidl);
1516 }
1517 else
1518 {
1519 /* File does not exist in current directory */
1520
1521 /* The selected file does not exist */
1522 /* Tell the user the selected does not exist */
1523 if(fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST)
1524 {
1525 char lpstrNotFound[100];
1526 char lpstrMsg[100];
1527 char tmp[400];
1528
1529 LoadStringA(COMMDLG_hInstance32,
1530 IDS_FILENOTFOUND,
1531 lpstrNotFound,
1532 100);
1533 LoadStringA(COMMDLG_hInstance32,
1534 IDS_VERIFYFILE,
1535 lpstrMsg,
1536 100);
1537
1538 strcpy(tmp,fodInfos->ofnInfos->lpstrFile);
1539 strcat(tmp,"\n");
1540 strcat(tmp,lpstrNotFound);
1541 strcat(tmp,"\n");
1542 strcat(tmp,lpstrMsg);
1543
1544 MessageBoxA(hwnd,
1545 tmp,
1546 fodInfos->ofnInfos->lpstrTitle,
1547 MB_OK | MB_ICONEXCLAMATION);
1548 return FALSE;
1549 }
1550 /* Ask the user if he wants to create the file*/
1551 if(fodInfos->ofnInfos->Flags & OFN_CREATEPROMPT)
1552 {
1553 char tmp[100];
1554
1555 LoadStringA(COMMDLG_hInstance32,IDS_CREATEFILE,tmp,100);
1556
1557 if(IDYES == MessageBoxA(hwnd,tmp,fodInfos->ofnInfos->lpstrTitle,
1558 MB_YESNO | MB_ICONQUESTION))
1559 {
1560 /* Create the file, clean and exit */
1561 return EndDialog(hwnd,TRUE);
1562 }
1563 return FALSE;
1564 }
1565 }
1566 /* check the write access to the current directory before opening the selected file */
1567 if((fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) && (fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST))
1568 {
1569 HANDLE hfile;
1570 char testFile[MAX_PATH];
1571
1572 strcpy(testFile,lpstrPathSpec);
1573 strcat(testFile,"_tes_13.579");
1574
1575 hfile = CreateFileA(testFile,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
1576
1577 switch(GetLastError())
1578 {
1579 case ERROR_ACCESS_DENIED:
1580 case ERROR_WRITE_PROTECT:
1581 case ERROR_PATH_NOT_FOUND:
1582 case ERROR_FILE_NOT_FOUND:
1583 {
1584 char strAccessDenied[MAX_PATH + 100];
1585 strcpy(strAccessDenied,lpstrPathSpec);
1586 strcat(strAccessDenied,lpstrFileSpec);
1587 strcat(strAccessDenied,"\nWrite access denied for this file !");
1588 MessageBoxA(hwnd,strAccessDenied,fodInfos->ofnInfos->lpstrTitle,MB_OK | MB_ICONEXCLAMATION);
1589 return FALSE;
1590 }
1591 }
1592
1593 if (hfile != INVALID_HANDLE_VALUE)
1594 {
1595 CloseHandle(hfile);
1596 DeleteFileA(testFile);
1597 }
1598
1599 }
1600
1601 /* Open the selected file */
1602
1603 /* Check file extension */
1604 if(!strrchr(lpstrPathAndFile,'.'))
1605 {
1606 /* if the file has no extension, append the selected
1607 extension of the filetype combo box */
1608 int iExt;
1609 LPSTR lpstrExt;
1610 iExt = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1611 lpstrTemp = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iExt);
1612
1613 if((LPSTR)-1 != lpstrTemp)
1614 {
1615 lpstrExt = strchr(lpstrTemp,';');
1616 if(lpstrExt)
1617 {
1618 int i = lpstrExt - lpstrTemp;
1619 lpstrExt = MemAlloc(i);
1620 strncpy(lpstrExt,&lpstrTemp[1],i-1);
1621 }
1622 else
1623 {
1624 lpstrExt = MemAlloc(strlen(lpstrTemp));
1625 strcpy(lpstrExt,&lpstrTemp[1]);
1626 }
1627
1628 if(strcmp(lpstrExt,".*") != 0)
1629 {
1630 /* OPEN DIALOG: Let's see if the file exists with the current extention,
1631 if not return the file without the extention.
1632 SAVE DIALOG: Concatenate the extention to the file.
1633 */
1634
1635 if (!(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG))
1636 {
1637 LPSTR lpstrFindFile;
1638 WIN32_FIND_DATAA fd;
1639
1640 lpstrFindFile = MemAlloc(strlen(lpstrPathAndFile)+strlen(lpstrExt));
1641 strcpy(lpstrFindFile, lpstrPathAndFile);
1642 strcat(lpstrFindFile, lpstrExt);
1643 if(FindFirstFileA(lpstrFindFile, &fd) != INVALID_HANDLE_VALUE)
1644 strcat(lpstrPathAndFile,lpstrExt);
1645 MemFree(lpstrFindFile);
1646 }
1647 else
1648 strcat(lpstrPathAndFile,lpstrExt);
1649 }
1650 MemFree( lpstrExt );
1651 }
1652 }
1653 /* Check that size size of the file does not exceed buffer size */
1654 if(strlen(lpstrPathAndFile) > fodInfos->ofnInfos->nMaxFile)
1655 {
1656 /* set error FNERR_BUFFERTOSMALL */
1657 return EndDialog(hwnd,FALSE);
1658 }
1659 strcpy(fodInfos->ofnInfos->lpstrFile,lpstrPathAndFile);
1660 fodInfos->ofnInfos->lpstrFile[strlen(lpstrPathAndFile)] = '\0';
1661 fodInfos->ofnInfos->lpstrFile[strlen(lpstrPathAndFile)+1] = '\0';
1662
1663 /* Set the lpstrFileTitle of the OPENFILENAME structure */
1664 if(fodInfos->ofnInfos->lpstrFileTitle)
1665 strncpy(fodInfos->ofnInfos->lpstrFileTitle,
1666 lpstrFileSpec,
1667 fodInfos->ofnInfos->nMaxFileTitle);
1668
1669 /* Check if the file is to be opened as read only */
1670 if(BST_CHECKED == SendDlgItemMessageA(hwnd,
1671 IDC_OPENREADONLY,
1672 BM_GETSTATE,0,0))
1673 SetFileAttributesA(fodInfos->ofnInfos->lpstrFile,
1674 FILE_ATTRIBUTE_READONLY);
1675
1676 /* nFileExtension and nFileOffset of OPENFILENAME structure */
1677 lpstrTemp = strrchr(fodInfos->ofnInfos->lpstrFile,'\\');
1678 fodInfos->ofnInfos->nFileOffset = lpstrTemp - fodInfos->ofnInfos->lpstrFile + 1;
1679 lpstrTemp = strrchr(fodInfos->ofnInfos->lpstrFile,'.');
1680 fodInfos->ofnInfos->nFileExtension = lpstrTemp - fodInfos->ofnInfos->lpstrFile + 1;
1681
1682
1683 /* clean and exit */
1684 return EndDialog(hwnd,TRUE);
1685 }
1686
1687 return FALSE;
1688}
1689
1690/***********************************************************************
1691 * FILEDLG95_SHELL_Init
1692 *
1693 * Initialisation of the shell objects
1694 */
1695static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
1696{
1697 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1698
1699 TRACE("\n");
1700
1701 /*
1702 * Initialisation of the FileOpenDialogInfos structure
1703 */
1704
1705 /* Shell */
1706
1707 fodInfos->Shell.FOIShellView = NULL;
1708 if(FAILED(COMDLG32_SHGetDesktopFolder(&fodInfos->Shell.FOIShellFolder)))
1709 return E_FAIL;
1710
1711 /*ShellInfos */
1712 fodInfos->ShellInfos.hwndOwner = hwnd;
1713
1714 fodInfos->ShellInfos.folderSettings.fFlags = 0;
1715 /* Disable multi-select if flag not set */
1716 if (!(fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT))
1717 {
1718 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_SINGLESEL;
1719 }
1720 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_AUTOARRANGE | FWF_ALIGNLEFT;
1721 fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
1722
1723 GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
1724 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
1725 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
1726
1727 /* Construct the IShellBrowser interface */
1728 fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
1729
1730 return NOERROR;
1731}
1732
1733/***********************************************************************
1734 * FILEDLG95_SHELL_ExecuteCommand
1735 *
1736 * Change the folder option and refresh the view
1737 * If the function succeeds, the return value is nonzero.
1738 */
1739static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
1740{
1741 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1742
1743 IContextMenu * pcm;
1744 CMINVOKECOMMANDINFO ci;
1745 TRACE("\n");
1746
1747 if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
1748 SVGIO_BACKGROUND,
1749 &IID_IContextMenu,
1750 (LPVOID*)&pcm)))
1751 {
1752 ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
1753 ci.lpVerb = lpVerb;
1754 ci.hwnd = hwnd;
1755
1756 IContextMenu_InvokeCommand(pcm, &ci);
1757 IContextMenu_Release(pcm);
1758 }
1759
1760 return FALSE;
1761}
1762
1763/***********************************************************************
1764 * FILEDLG95_SHELL_UpFolder
1765 *
1766 * Browse to the specified object
1767 * If the function succeeds, the return value is nonzero.
1768 */
1769static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
1770{
1771 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1772
1773 TRACE("\n");
1774
1775 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1776 NULL,
1777 SBSP_PARENT)))
1778 {
1779 return TRUE;
1780 }
1781 return FALSE;
1782}
1783
1784/***********************************************************************
1785 * FILEDLG95_SHELL_NewFolder
1786 *
1787 * Creates a new directory with New folder as name
1788 * If the function succeeds, the return value is nonzero.
1789 * FIXME: let the contextmenu (CMDSTR_NEWFOLDER) do this thing
1790 */
1791static BOOL FILEDLG95_SHELL_NewFolder(HWND hwnd)
1792{
1793 char lpstrDirName[MAX_PATH] = "New Folder";
1794 char lpstrNewDir[MAX_PATH];
1795 BOOL bRes = FALSE;
1796 HANDLE hHandle;
1797 WIN32_FIND_DATAA FindData;
1798 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1799
1800 TRACE("\n");
1801
1802 /* Create the absolute path for "New Folder" */
1803 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent, lpstrNewDir);
1804 COMDLG32_PathAddBackslashA(lpstrNewDir);
1805 strcat(lpstrNewDir, lpstrDirName);
1806
1807 /* Find a Unique directory name */
1808 hHandle = FindFirstFileA(lpstrNewDir,&FindData);
1809 if(hHandle !=INVALID_HANDLE_VALUE)
1810 {
1811 int i;
1812 char lpstrDupNewDir[MAX_PATH];
1813 char lpstrDirNameExt[8];
1814 strcpy(lpstrDupNewDir, lpstrNewDir);
1815 for(i=0; i < 256 && hHandle != INVALID_HANDLE_VALUE; i++)
1816 {
1817 FindClose(hHandle);
1818 sprintf(lpstrNewDir,"%s (%d)", lpstrDupNewDir, i+1);
1819 hHandle = FindFirstFileA(lpstrNewDir,&FindData);
1820 }
1821 sprintf(lpstrDirNameExt," (%d)", i);
1822 strcat(lpstrDirName, lpstrDirNameExt);
1823 }
1824 /* Is Unique Found */
1825 if(hHandle == INVALID_HANDLE_VALUE)
1826 {
1827 bRes = CreateDirectoryA(lpstrNewDir,NULL);
1828
1829 if(bRes)
1830 {
1831 LPITEMIDLIST pidl;
1832 /* Refresh the list (this will update the pidl, to include the new directory) */
1833 /* Might want to only update the list (so the directory appears at the end */
1834 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1835 pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder,lpstrDirName);
1836
1837 IShellView_SelectItem(fodInfos->Shell.FOIShellView,
1838 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
1839 |SVSI_FOCUSED|SVSI_SELECT));
1840
1841 COMDLG32_SHFree(pidl);
1842 }
1843 else
1844 {
1845 char lpstrText[128+MAX_PATH];
1846 char lpstrTempText[128];
1847 char lpstrCaption[32];
1848
1849 /* Cannot Create folder because of permissions */
1850 LoadStringA(COMMDLG_hInstance32, IDS_CREATEFOLDER_DENIED, lpstrTempText, sizeof(lpstrTempText));
1851 LoadStringA(COMMDLG_hInstance32, IDS_FILEOPEN_CAPTION, lpstrCaption, sizeof(lpstrCaption));
1852 sprintf(lpstrText,lpstrTempText, lpstrDirName);
1853 MessageBoxA(hwnd,lpstrText, lpstrCaption, MB_OK | MB_ICONEXCLAMATION);
1854 }
1855 }
1856 return bRes;
1857}
1858
1859/***********************************************************************
1860 * FILEDLG95_SHELL_Clean
1861 *
1862 * Cleans the memory used by shell objects
1863 */
1864static void FILEDLG95_SHELL_Clean(HWND hwnd)
1865{
1866 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1867
1868 TRACE("\n");
1869
1870 /* clean Shell interfaces */
1871 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
1872 IShellView_Release(fodInfos->Shell.FOIShellView);
1873 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
1874 IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
1875}
1876
1877/***********************************************************************
1878 * FILEDLG95_FILETYPE_Init
1879 *
1880 * Initialisation of the file type combo box
1881 */
1882static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
1883{
1884 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1885
1886 TRACE("\n");
1887
1888 if(fodInfos->ofnInfos->lpstrFilter)
1889 {
1890 int iStrIndex = 0;
1891 int iPos = 0;
1892 LPSTR lpstrFilter;
1893 LPSTR lpstrTmp;
1894
1895 for(;;)
1896 {
1897 /* filter is a list... title\0ext\0......\0\0
1898 * Set the combo item text to the title and the item data
1899 * to the ext
1900 */
1901 char *lpstrExt = NULL;
1902 LPSTR lpstrExtTmp = NULL;
1903
1904 /* Get the title */
1905 lpstrTmp = (&((LPBYTE)fodInfos->ofnInfos->lpstrFilter)[iStrIndex]);
1906 if(!strlen(lpstrTmp))
1907 break;
1908 iStrIndex += strlen(lpstrTmp) +1;
1909 /* Get the extension */
1910 lpstrExtTmp = (&((LPBYTE)fodInfos->ofnInfos->lpstrFilter)[iStrIndex]);
1911 if(!lpstrExtTmp)
1912 break;
1913
1914 lpstrExt = (LPSTR) MemAlloc(strlen(lpstrExtTmp)+1);
1915 if(!lpstrExt)
1916 break;
1917
1918 strcpy(lpstrExt,lpstrExtTmp);
1919
1920 iStrIndex += strlen(lpstrExt) +1;
1921
1922 /* Add the item at the end of the combo */
1923 CBAddString(fodInfos->DlgInfos.hwndFileTypeCB,lpstrTmp);
1924 CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos++,lpstrExt);
1925 }
1926 /* Set the current filter to the one specified
1927 * in the initialisation structure
1928 */
1929
1930 /* set default filter index */
1931 if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->ofnInfos->lpstrCustomFilter == NULL)
1932 fodInfos->ofnInfos->nFilterIndex = 1;
1933 /* First, check to make sure our index isn't out of bounds. */
1934 if ( fodInfos->ofnInfos->nFilterIndex > iPos )
1935 fodInfos->ofnInfos->nFilterIndex = iPos;
1936
1937
1938 /* Get the current index selection. */
1939 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB,
1940 fodInfos->ofnInfos->nFilterIndex-1);
1941
1942 /* Get the corresponding text string from the combo box. */
1943 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1944 fodInfos->ofnInfos->nFilterIndex-1);
1945
1946 if ((INT)lpstrFilter == -1)
1947 lpstrFilter = NULL; // we get -1 if the control is empty
1948
1949 if(lpstrFilter)
1950 {
1951 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
1952 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,strlwr(lpstrFilter));
1953 }
1954 }
1955 return NOERROR;
1956}
1957
1958/***********************************************************************
1959 * FILEDLG95_FILETYPE_OnCommand
1960 *
1961 * WM_COMMAND of the file type combo box
1962 * If the function succeeds, the return value is nonzero.
1963 */
1964static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
1965{
1966 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1967
1968 switch(wNotifyCode)
1969 {
1970 case CBN_SELENDOK:
1971 {
1972 LPSTR lpstrFilter;
1973//CB: todo: check if selection really changed
1974 /* Get the current item of the filetype combo box */
1975 int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1976
1977 /* set the current filter index - indexed from 1 */
1978 fodInfos->ofnInfos->nFilterIndex = iItem + 1;
1979
1980 /* Set the current filter with the current selection */
1981 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1982 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1983
1984 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1985 iItem);
1986 if((int)lpstrFilter != CB_ERR)
1987 {
1988 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
1989 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,(LPSTR)strlwr((LPSTR)lpstrFilter));
1990 SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
1991 }
1992
1993 /* Refresh the actual view to display the included items*/
1994 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1995
1996 }
1997 }
1998 return FALSE;
1999}
2000/***********************************************************************
2001 * FILEDLG95_FILETYPE_SearchExt
2002 *
2003 * Search for pidl in the lookin combo box
2004 * returns the index of the found item
2005 */
2006static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPSTR lpstrExt)
2007{
2008 int i = 0;
2009 int iCount = CBGetCount(hwnd);
2010
2011 TRACE("\n");
2012
2013 for(;i<iCount;i++)
2014 {
2015 LPSTR ext = (LPSTR) CBGetItemDataPtr(hwnd,i);
2016
2017 if(!strcasecmp(lpstrExt,ext))
2018 return i;
2019 }
2020
2021 return -1;
2022}
2023
2024/***********************************************************************
2025 * FILEDLG95_FILETYPE_Clean
2026 *
2027 * Clean the memory used by the filetype combo box
2028 */
2029static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
2030{
2031 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2032 int iPos;
2033 int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
2034
2035 TRACE("\n");
2036
2037 /* Delete each string of the combo and their associated data */
2038 for(iPos = iCount-1;iPos>=0;iPos--)
2039 {
2040 MemFree((LPVOID)(CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos)));
2041 CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
2042 }
2043 /* Current filter */
2044 if(fodInfos->ShellInfos.lpstrCurrentFilter)
2045 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
2046
2047}
2048
2049/***********************************************************************
2050 * FILEDLG95_LOOKIN_Init
2051 *
2052 * Initialisation of the look in combo box
2053 */
2054static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
2055{
2056 IShellFolder *psfRoot, *psfDrives;
2057 IEnumIDList *lpeRoot, *lpeDrives;
2058 LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
2059
2060 LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
2061
2062 TRACE("\n");
2063
2064 liInfos->iMaxIndentation = 0;
2065
2066 SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
2067 CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
2068
2069#ifndef SHELL_NO_DESKTOP
2070 /* Initialise data of Desktop folder */
2071 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
2072 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
2073 COMDLG32_SHFree(pidlTmp);
2074#endif
2075
2076 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
2077
2078 COMDLG32_SHGetDesktopFolder(&psfRoot);
2079
2080 if (psfRoot)
2081 {
2082 /* enumerate the contents of the desktop */
2083 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
2084 {
2085 while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
2086 {
2087 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
2088
2089 /* special handling for CSIDL_DRIVES */
2090 if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
2091 {
2092 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
2093 {
2094 /* enumerate the drives */
2095 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
2096 {
2097 while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
2098 {
2099 pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
2100 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
2101 COMDLG32_SHFree(pidlAbsTmp);
2102 COMDLG32_SHFree(pidlTmp1);
2103 }
2104 IEnumIDList_Release(lpeDrives);
2105 }
2106 IShellFolder_Release(psfDrives);
2107 }
2108 }
2109 COMDLG32_SHFree(pidlTmp);
2110 }
2111 IEnumIDList_Release(lpeRoot);
2112 }
2113 }
2114
2115 IShellFolder_Release(psfRoot);
2116 COMDLG32_SHFree(pidlDrives);
2117
2118 return NOERROR;
2119}
2120
2121/***********************************************************************
2122 * FILEDLG95_LOOKIN_DrawItem
2123 *
2124 * WM_DRAWITEM message handler
2125 */
2126static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
2127{
2128 COLORREF crWin = GetSysColor(COLOR_WINDOW);
2129 COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
2130 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
2131 RECT rectText;
2132 RECT rectIcon;
2133 int iIndentation;
2134 LPSFOLDER tmpFolder;
2135 INT iIcon;
2136
2137 LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
2138
2139 TRACE("\n");
2140
2141 if(pDIStruct->itemID == -1)
2142 return 0;
2143
2144 if((LPSFOLDER)CB_ERR == (tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
2145 pDIStruct->itemID)))
2146 return 0;
2147
2148 if (!tmpFolder->szDisplayName)
2149 {
2150 SHFILEINFOA sfi;
2151 INT len;
2152
2153 //CB: skip A:,B: SHGFI_DISPLAYNAME for faster handling?
2154
2155 tmpFolder->ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR)tmpFolder->pidlItem,
2156 0,
2157 &sfi,
2158 sizeof (SHFILEINFOA),
2159 SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME);
2160 len = strlen(sfi.szDisplayName)+1;
2161 tmpFolder->szDisplayName = MemAlloc(len);
2162 strcpy(tmpFolder->szDisplayName,sfi.szDisplayName);
2163 tmpFolder->iIcon = sfi.iIcon;
2164 }
2165
2166 if((pDIStruct->itemID == liInfos->uSelectedItem) || (pDIStruct->itemState & ODS_COMBOBOXEDIT))
2167 {
2168 if (!tmpFolder->iSelIcon)
2169 {
2170 SHFILEINFOA sfi2;
2171
2172 COMDLG32_SHGetFileInfoA((LPCSTR)tmpFolder->pidlItem,0,&sfi2,sizeof(SHFILEINFOA),
2173 SHGFI_PIDL | SHGFI_SMALLICON |
2174 SHGFI_OPENICON | SHGFI_SYSICONINDEX);
2175 tmpFolder->iSelIcon = sfi2.iIcon;
2176 }
2177 iIcon = tmpFolder->iSelIcon;
2178 } else iIcon = tmpFolder->iIcon;
2179
2180
2181 /* Is this item selected ?*/
2182 if(pDIStruct->itemState & ODS_SELECTED)
2183 {
2184 SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
2185 SetBkColor(pDIStruct->hDC,crHighLight);
2186 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight);
2187 }
2188 else
2189 {
2190 SetTextColor(pDIStruct->hDC,crText);
2191 SetBkColor(pDIStruct->hDC,crWin);
2192 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin);
2193 }
2194
2195 /* Do not indent item if drawing in the edit of the combo*/
2196 if (pDIStruct->itemState & ODS_COMBOBOXEDIT)
2197 iIndentation = 0;
2198 else
2199 iIndentation = tmpFolder->m_iIndent;
2200
2201 /* Draw text and icon */
2202
2203 /* Initialise the icon display area */
2204 rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
2205 rectIcon.top = pDIStruct->rcItem.top;
2206 rectIcon.right = rectIcon.left + ICONWIDTH;
2207 rectIcon.bottom = pDIStruct->rcItem.bottom;
2208
2209 /* Initialise the text display area */
2210 rectText.left = rectIcon.right;
2211 rectText.top = pDIStruct->rcItem.top + YTEXTOFFSET;
2212 rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
2213 rectText.bottom = pDIStruct->rcItem.bottom;
2214
2215
2216 /* Draw the icon from the image list */
2217 COMDLG32_ImageList_Draw(tmpFolder->ilItemImage,
2218 iIcon,
2219 pDIStruct->hDC,
2220 rectIcon.left,
2221 rectIcon.top,
2222 ILD_TRANSPARENT );
2223
2224 /* Draw the associated text */
2225 if (tmpFolder->szDisplayName)
2226 TextOutA(pDIStruct->hDC,rectText.left,rectText.top,tmpFolder->szDisplayName,strlen(tmpFolder->szDisplayName));
2227
2228
2229 return NOERROR;
2230}
2231
2232/***********************************************************************
2233 * FILEDLG95_LOOKIN_OnCommand
2234 *
2235 * LookIn combo box WM_COMMAND message handler
2236 * If the function succeeds, the return value is nonzero.
2237 */
2238static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
2239{
2240 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2241
2242 TRACE("\n");
2243
2244 switch(wNotifyCode)
2245 {
2246 case CBN_SELENDOK:
2247 {
2248 LPSFOLDER tmpFolder;
2249 int iItem;
2250
2251 iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
2252
2253 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
2254 iItem)))
2255 return FALSE;
2256
2257
2258 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
2259 tmpFolder->pidlItem,
2260 SBSP_ABSOLUTE)))
2261 {
2262 return TRUE;
2263 }
2264 break;
2265 }
2266
2267 }
2268 return FALSE;
2269}
2270
2271/***********************************************************************
2272 * FILEDLG95_LOOKIN_AddItem
2273 *
2274 * Adds an absolute pidl item to the lookin combo box
2275 * returns the index of the inserted item
2276 */
2277static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
2278{
2279 LPITEMIDLIST pidlNext;
2280 SHFILEINFOA sfi;
2281 SFOLDER *tmpFolder;
2282 LookInInfos *liInfos;
2283
2284 TRACE("\n");
2285
2286 if(!pidl)
2287 return -1;
2288
2289 if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
2290 return -1;
2291
2292 tmpFolder = MemAlloc(sizeof(SFOLDER));
2293 tmpFolder->m_iIndent = 0;
2294 tmpFolder->szDisplayName = NULL;
2295
2296 /* Calculate the indentation of the item in the lookin*/
2297 pidlNext = pidl;
2298 while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
2299 {
2300 tmpFolder->m_iIndent++;
2301 }
2302
2303 tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl);
2304
2305 if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
2306 liInfos->iMaxIndentation = tmpFolder->m_iIndent;
2307
2308 COMDLG32_SHGetFileInfoA((LPSTR)pidl,
2309 0,
2310 &sfi,
2311 sizeof(sfi),
2312 SHGFI_PIDL | SHGFI_ATTRIBUTES);
2313
2314 if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
2315 {
2316 int iItemID;
2317
2318 /* Add the item at the end of the list */
2319 if(iInsertId < 0)
2320 {
2321 iItemID = CBAddString(hwnd,NULL);
2322 }
2323 /* Insert the item at the iInsertId position*/
2324 else
2325 {
2326 iItemID = CBInsertString(hwnd,NULL,iInsertId);
2327 }
2328
2329 CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
2330 return iItemID;
2331 }
2332
2333 MemFree(tmpFolder);
2334 return -1;
2335}
2336
2337/***********************************************************************
2338 * FILEDLG95_LOOKIN_InsertItemAfterParent
2339 *
2340 * Insert an item below its parent
2341 */
2342static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
2343{
2344
2345 LPITEMIDLIST pidlParent = GetParentPidl(pidl);
2346 int iParentPos;
2347
2348 TRACE("\n");
2349
2350 iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
2351
2352 if(iParentPos < 0)
2353 {
2354 iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
2355 }
2356
2357 /* Free pidlParent memory */
2358 COMDLG32_SHFree((LPVOID)pidlParent);
2359
2360 return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
2361}
2362
2363/***********************************************************************
2364 * FILEDLG95_LOOKIN_SelectItem
2365 *
2366 * Adds an absolute pidl item to the lookin combo box
2367 * returns the index of the inserted item
2368 */
2369int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
2370{
2371 int iItemPos;
2372 LookInInfos *liInfos;
2373
2374 TRACE("\n");
2375
2376 iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
2377
2378 liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2379
2380 if(iItemPos < 0)
2381 {
2382 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
2383 iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
2384 }
2385
2386 else
2387 {
2388 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2389 while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
2390 {
2391 int iRemovedItem;
2392
2393 if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
2394 break;
2395 if(iRemovedItem < iItemPos)
2396 iItemPos--;
2397 }
2398 }
2399
2400 CBSetCurSel(hwnd,iItemPos);
2401 liInfos->uSelectedItem = iItemPos;
2402
2403 return 0;
2404
2405}
2406
2407/***********************************************************************
2408 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2409 *
2410 * Remove the item with an expansion level over iExpansionLevel
2411 */
2412static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
2413{
2414 int iItemPos;
2415
2416 LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2417
2418 TRACE("\n");
2419
2420 if(liInfos->iMaxIndentation <= 2)
2421 return -1;
2422
2423 if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
2424 {
2425 SFOLDER *tmpFolder;
2426
2427 tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2428 if (tmpFolder->szDisplayName) MemFree(tmpFolder->szDisplayName);
2429 MemFree(tmpFolder);
2430 CBDeleteString(hwnd,iItemPos);
2431 liInfos->iMaxIndentation--;
2432
2433 return iItemPos;
2434 }
2435
2436 return -1;
2437}
2438
2439/***********************************************************************
2440 * FILEDLG95_LOOKIN_SearchItem
2441 *
2442 * Search for pidl in the lookin combo box
2443 * returns the index of the found item
2444 */
2445static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
2446{
2447 int i = 0;
2448 int iCount = CBGetCount(hwnd);
2449
2450 TRACE("\n");
2451
2452 for(;i<iCount;i++)
2453 {
2454 LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
2455
2456 if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
2457 return i;
2458 if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
2459 return i;
2460
2461 }
2462
2463 return -1;
2464}
2465
2466/***********************************************************************
2467 * FILEDLG95_LOOKIN_Clean
2468 *
2469 * Clean the memory used by the lookin combo box
2470 */
2471static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
2472{
2473 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2474 int iPos;
2475 int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
2476
2477 TRACE("\n");
2478
2479 /* Delete each string of the combo and their associated data */
2480 for(iPos = iCount-1;iPos>=0;iPos--)
2481 {
2482 SFOLDER *tmpFolder = (LPSFOLDER)CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos);
2483
2484 if (tmpFolder->szDisplayName) MemFree(tmpFolder->szDisplayName);
2485 MemFree(tmpFolder);
2486 CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
2487 }
2488 /* LookInInfos structure */
2489 RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
2490
2491}
2492/*
2493 * TOOLS
2494 */
2495
2496/***********************************************************************
2497 * GetName
2498 *
2499 * Get the pidl's display name (relative to folder) and
2500 * put it in lpstrFileName.
2501 *
2502 * Return NOERROR on success,
2503 * E_FAIL otherwise
2504 */
2505
2506HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
2507{
2508 STRRET str;
2509 HRESULT hRes;
2510
2511 TRACE("%p %p\n", lpsf, pidl);
2512
2513 if(!lpsf)
2514 {
2515 HRESULT hRes;
2516 COMDLG32_SHGetDesktopFolder(&lpsf);
2517 hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
2518 IShellFolder_Release(lpsf);
2519 return hRes;
2520 }
2521
2522 /* Get the display name of the pidl relative to the folder */
2523 if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf,
2524 pidl,
2525 dwFlags,
2526 &str)))
2527 {
2528 return StrRetToBufA(&str, pidl,lpstrFileName, MAX_PATH);
2529 }
2530 return E_FAIL;
2531}
2532
2533/***********************************************************************
2534 * GetShellFolderFromPidl
2535 *
2536 * pidlRel is the item pidl relative
2537 * Return the IShellFolder of the absolute pidl
2538 */
2539IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
2540{
2541 IShellFolder *psf = NULL,*psfParent;
2542
2543 TRACE("%p\n", pidlAbs);
2544
2545 if(SUCCEEDED(COMDLG32_SHGetDesktopFolder(&psfParent)))
2546 {
2547 psf = psfParent;
2548 if(pidlAbs && pidlAbs->mkid.cb)
2549 {
2550 if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
2551 {
2552 IShellFolder_Release(psfParent);
2553 return psf;
2554 }
2555 }
2556 /* return the desktop */
2557 return psfParent;
2558 }
2559 return NULL;
2560}
2561
2562/***********************************************************************
2563 * GetParentPidl
2564 *
2565 * Return the LPITEMIDLIST to the parent of the pidl in the list
2566 */
2567LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
2568{
2569 LPITEMIDLIST pidlParent;
2570
2571 TRACE("%p\n", pidl);
2572
2573 pidlParent = COMDLG32_PIDL_ILClone(pidl);
2574 COMDLG32_PIDL_ILRemoveLastID(pidlParent);
2575
2576 return pidlParent;
2577}
2578
2579/***********************************************************************
2580 * GetPidlFromName
2581 *
2582 * returns the pidl of the file name relative to folder
2583 * NULL if an error occured
2584 */
2585LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName)
2586{
2587 LPITEMIDLIST pidl;
2588 ULONG ulEaten;
2589 wchar_t lpwstrDirName[MAX_PATH];
2590
2591
2592 TRACE("sf=%p file=%s\n", psf, lpcstrFileName);
2593
2594 if(!lpcstrFileName)
2595 return NULL;
2596
2597 MultiByteToWideChar(CP_ACP,
2598 MB_PRECOMPOSED,
2599 lpcstrFileName,
2600 -1,
2601 (LPWSTR)lpwstrDirName,
2602 MAX_PATH);
2603
2604 IShellFolder_ParseDisplayName(psf, 0,
2605 NULL,
2606 (LPWSTR)lpwstrDirName,
2607 &ulEaten,
2608 &pidl,
2609 NULL);
2610
2611 return pidl;
2612}
2613
2614/***********************************************************************
2615 * GetFileExtension
2616 *
2617 */
2618BOOL GetFileExtension(IShellFolder *psf,LPITEMIDLIST pidl,LPSTR lpstrFileExtension)
2619{
2620 char FileName[MAX_PATH];
2621 int result;
2622 char *pdest;
2623 int ch = '.';
2624
2625 if(SUCCEEDED(GetName(psf,pidl,SHGDN_NORMAL,FileName)))
2626 {
2627 if(!(pdest = strrchr( FileName, ch )))
2628 return FALSE;
2629
2630 result = pdest - FileName + 1;
2631 strcpy(lpstrFileExtension,&FileName[result]);
2632 return TRUE;
2633 }
2634 return FALSE;
2635}
2636
2637/*
2638 * Memory allocation methods */
2639void *MemAlloc(UINT size)
2640{
2641 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
2642}
2643
2644void MemFree(void *mem)
2645{
2646 if(mem)
2647 {
2648 HeapFree(GetProcessHeap(),0,mem);
2649 }
2650}
2651
2652/***********************************************************************
2653 * BrowseSelectedFolder
2654 *
2655 */
2656static BOOL BrowseSelectedFolder(HWND hwnd)
2657{
2658 BOOL bBrowseSelFolder = FALSE;
2659
2660 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2661
2662 if (GetNumSelected(fodInfos->Shell.FOIShellView) == 1)
2663 {
2664 LPITEMIDLIST pidlSelection;
2665 ULONG uAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
2666
2667 /* get the file selected */
2668 EnumSelectedPidls( fodInfos->Shell.FOIShellView, 0, &pidlSelection );
2669 IShellFolder_GetAttributesOf( fodInfos->Shell.FOIShellFolder, 1, &pidlSelection, &uAttr );
2670 if ( uAttr & SFGAO_FOLDER )
2671 {
2672 if ( FAILED( IShellBrowser_BrowseObject( fodInfos->Shell.FOIShellBrowser,
2673 pidlSelection, SBSP_RELATIVE ) ) )
2674 {
2675 MessageBoxA( hwnd, "Path does not exist", fodInfos->ofnInfos->lpstrTitle,
2676 MB_OK | MB_ICONEXCLAMATION );
2677 }
2678
2679 bBrowseSelFolder = TRUE;
2680 }
2681 COMDLG32_SHFree( pidlSelection );
2682 }
2683
2684 return bBrowseSelFolder;
2685}
2686
Note: See TracBrowser for help on using the repository browser.