forked from wine-mirror/wine
/
filedlg.c
4253 lines (3659 loc) · 134 KB
/
filedlg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* COMMDLG - File Open Dialogs Win95 look and feel
*
* Copyright 1999 Francois Boisvert
* Copyright 1999, 2000 Juergen Schmied
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* FIXME: The whole concept of handling unicode is badly broken.
* many hook-messages expect a pointer to a
* OPENFILENAMEA or W structure. With the current architecture
* we would have to convert the beast at every call to a hook.
* we have to find a better solution but it would likely cause
* a complete rewrite after which we should handle the
* OPENFILENAME structure without any converting (jsch).
*
* FIXME: any hook gets a OPENFILENAMEA structure
*
* FIXME: CDN_FILEOK is wrong implemented, other CDN_ messages likely too
*
* FIXME: old style hook messages are not implemented (except FILEOKSTRING)
*
* FIXME: algorithm for selecting the initial directory is too simple
*
* FIXME: add to recent docs
*
* FIXME: flags not implemented: OFN_DONTADDTORECENT,
* OFN_NODEREFERENCELINKS, OFN_NOREADONLYRETURN,
* OFN_NOTESTFILECREATE, OFN_USEMONIKERS
*
* FIXME: lCustData for lpfnHook (WM_INITDIALOG)
*
*
*/
#include "config.h"
#include "wine/port.h"
#include <ctype.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#define COBJMACROS
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "winnls.h"
#include "wingdi.h"
#include "winreg.h"
#include "winuser.h"
#include "commdlg.h"
#include "dlgs.h"
#include "cdlg.h"
#include "cderr.h"
#include "shellapi.h"
#include "shlobj.h"
#include "filedlgbrowser.h"
#include "shlwapi.h"
#include "wine/unicode.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
#define UNIMPLEMENTED_FLAGS \
(OFN_DONTADDTORECENT |\
OFN_NODEREFERENCELINKS | OFN_NOREADONLYRETURN |\
OFN_NOTESTFILECREATE /*| OFN_USEMONIKERS*/)
#define IsHooked(fodInfos) \
((fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook)
/***********************************************************************
* Data structure and global variables
*/
typedef struct SFolder
{
int m_iImageIndex; /* Index of picture in image list */
HIMAGELIST hImgList;
int m_iIndent; /* Indentation index */
LPITEMIDLIST pidlItem; /* absolute pidl of the item */
} SFOLDER,*LPSFOLDER;
typedef struct tagLookInInfo
{
int iMaxIndentation;
UINT uSelectedItem;
} LookInInfos;
/***********************************************************************
* Defines and global variables
*/
/* Draw item constant */
#define ICONWIDTH 18
#define XTEXTOFFSET 3
/* AddItem flags*/
#define LISTEND -1
/* SearchItem methods */
#define SEARCH_PIDL 1
#define SEARCH_EXP 2
#define ITEM_NOTFOUND -1
/* Undefined windows message sent by CreateViewObject*/
#define WM_GETISHELLBROWSER WM_USER+7
/* NOTE
* Those macros exist in windowsx.h. However, you can't really use them since
* they rely on the UNICODE defines and can't be used inside Wine itself.
*/
/* Combo box macros */
#define CBAddString(hwnd,str) \
SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)(str));
#define CBInsertString(hwnd,str,pos) \
SendMessageW(hwnd, CB_INSERTSTRING, (WPARAM)(pos), (LPARAM)(str));
#define CBDeleteString(hwnd,pos) \
SendMessageW(hwnd, CB_DELETESTRING, (WPARAM)(pos), 0);
#define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
SendMessageW(hwnd, CB_SETITEMDATA, (WPARAM)(iItemId), (LPARAM)(dataPtr));
#define CBGetItemDataPtr(hwnd,iItemId) \
SendMessageW(hwnd, CB_GETITEMDATA, (WPARAM)(iItemId), 0)
#define CBGetLBText(hwnd,iItemId,str) \
SendMessageW(hwnd, CB_GETLBTEXT, (WPARAM)(iItemId), (LPARAM)(str));
#define CBGetCurSel(hwnd) \
SendMessageW(hwnd, CB_GETCURSEL, 0, 0);
#define CBSetCurSel(hwnd,pos) \
SendMessageW(hwnd, CB_SETCURSEL, (WPARAM)(pos), 0);
#define CBGetCount(hwnd) \
SendMessageW(hwnd, CB_GETCOUNT, 0, 0);
#define CBShowDropDown(hwnd,show) \
SendMessageW(hwnd, CB_SHOWDROPDOWN, (WPARAM)(show), 0);
#define CBSetItemHeight(hwnd,index,height) \
SendMessageW(hwnd, CB_SETITEMHEIGHT, (WPARAM)(index), (LPARAM)(height));
#define CBSetExtendedUI(hwnd,flag) \
SendMessageW(hwnd, CB_SETEXTENDEDUI, (WPARAM)(flag), 0)
const char FileOpenDlgInfosStr[] = "FileOpenDlgInfos"; /* windows property description string */
static const char LookInInfosStr[] = "LookInInfos"; /* LOOKIN combo box property */
static SIZE MemDialogSize = { 0, 0}; /* keep size of the (resizable) dialog */
static const WCHAR LastVisitedMRUW[] =
{'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
'E','x','p','l','o','r','e','r','\\','C','o','m','D','l','g','3','2','\\',
'L','a','s','t','V','i','s','i','t','e','d','M','R','U',0};
static const WCHAR MRUListW[] = {'M','R','U','L','i','s','t',0};
/***********************************************************************
* Prototypes
*/
/* Internal functions used by the dialog */
static LRESULT FILEDLG95_ResizeControls(HWND hwnd, WPARAM wParam, LPARAM lParam);
static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam);
static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam);
static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd);
static BOOL FILEDLG95_OnOpen(HWND hwnd);
static LRESULT FILEDLG95_InitControls(HWND hwnd);
static void FILEDLG95_Clean(HWND hwnd);
/* Functions used by the shell navigation */
static LRESULT FILEDLG95_SHELL_Init(HWND hwnd);
static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd);
static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb);
static void FILEDLG95_SHELL_Clean(HWND hwnd);
static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd);
/* Functions used by the EDIT box */
static int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPWSTR * lpstrFileList, UINT * sizeUsed);
/* Functions used by the filetype combo box */
static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd);
static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode);
static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCWSTR lpstrExt);
static void FILEDLG95_FILETYPE_Clean(HWND hwnd);
/* Functions used by the Look In combo box */
static void FILEDLG95_LOOKIN_Init(HWND hwndCombo);
static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);
static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);
static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);
static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod);
static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl);
static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd);
int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
static void FILEDLG95_LOOKIN_Clean(HWND hwnd);
/* Functions for dealing with the most-recently-used registry keys */
static void FILEDLG95_MRU_load_filename(LPWSTR stored_path);
static WCHAR FILEDLG95_MRU_get_slot(LPCWSTR module_name, LPWSTR stored_path, PHKEY hkey_ret);
static void FILEDLG95_MRU_save_filename(LPCWSTR filename);
/* Miscellaneous tool functions */
static HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPWSTR lpstrFileName);
IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
static LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPWSTR lpcstrFileName);
static BOOL IsPidlFolder (LPSHELLFOLDER psf, LPCITEMIDLIST pidl);
static UINT GetNumSelected( IDataObject *doSelected );
/* Shell memory allocation */
static void *MemAlloc(UINT size);
static void MemFree(void *mem);
static INT_PTR CALLBACK FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static INT_PTR FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPWSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);
static BOOL BrowseSelectedFolder(HWND hwnd);
/***********************************************************************
* GetFileName95
*
* Creates an Open common dialog box that lets the user select
* the drive, directory, and the name of a file or set of files to open.
*
* IN : The FileOpenDlgInfos structure associated with the dialog
* OUT : TRUE on success
* FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
*/
static BOOL GetFileName95(FileOpenDlgInfos *fodInfos)
{
LRESULT lRes;
LPCVOID origTemplate;
DWORD dwSize;
LPDLGTEMPLATEW template;
HRSRC hRes;
HANDLE hDlgTmpl = 0;
HRESULT hr;
/* test for missing functionality */
if (fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS)
{
FIXME("Flags 0x%08x not yet implemented\n",
fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS);
}
/* Create the dialog from a template */
if(!(hRes = FindResourceW(COMDLG32_hInstance,MAKEINTRESOURCEW(NEWFILEOPENORD),(LPCWSTR)RT_DIALOG)))
{
COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
return FALSE;
}
if (!(dwSize = SizeofResource(COMDLG32_hInstance, hRes)) ||
!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hRes)) ||
!(origTemplate = LockResource(hDlgTmpl)))
{
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
return FALSE;
}
if (!(template = HeapAlloc(GetProcessHeap(), 0, dwSize)))
{
COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
return FALSE;
}
memcpy(template, origTemplate, dwSize);
/* msdn: explorer style dialogs permit sizing by default.
* The OFN_ENABLESIZING flag is only needed when a hook or
* custom tmeplate is provided */
if( (fodInfos->ofnInfos->Flags & OFN_EXPLORER) &&
!(fodInfos->ofnInfos->Flags & ( OFN_ENABLEHOOK | OFN_ENABLETEMPLATE | OFN_ENABLETEMPLATEHANDLE)))
fodInfos->ofnInfos->Flags |= OFN_ENABLESIZING;
if (fodInfos->ofnInfos->Flags & OFN_ENABLESIZING)
{
template->style |= WS_SIZEBOX;
fodInfos->sizedlg.cx = fodInfos->sizedlg.cy = 0;
fodInfos->initial_size.x = fodInfos->initial_size.y = 0;
}
else
template->style &= ~WS_SIZEBOX;
/* old style hook messages */
if (IsHooked(fodInfos))
{
fodInfos->HookMsg.fileokstring = RegisterWindowMessageW(FILEOKSTRINGW);
fodInfos->HookMsg.lbselchstring = RegisterWindowMessageW(LBSELCHSTRINGW);
fodInfos->HookMsg.helpmsgstring = RegisterWindowMessageW(HELPMSGSTRINGW);
fodInfos->HookMsg.sharevistring = RegisterWindowMessageW(SHAREVISTRINGW);
}
/* Some shell namespace extensions depend on COM being initialized. */
hr = OleInitialize(NULL);
if (fodInfos->unicode)
lRes = DialogBoxIndirectParamW(COMDLG32_hInstance,
template,
fodInfos->ofnInfos->hwndOwner,
FileOpenDlgProc95,
(LPARAM) fodInfos);
else
lRes = DialogBoxIndirectParamA(COMDLG32_hInstance,
template,
fodInfos->ofnInfos->hwndOwner,
FileOpenDlgProc95,
(LPARAM) fodInfos);
if (SUCCEEDED(hr))
OleUninitialize();
HeapFree(GetProcessHeap(), 0, template);
/* Unable to create the dialog */
if( lRes == -1)
return FALSE;
return lRes;
}
/***********************************************************************
* GetFileDialog95A
*
* Call GetFileName95 with this structure and clean the memory.
*
* IN : The OPENFILENAMEA initialisation structure passed to
* GetOpenFileNameA win api function (see filedlg.c)
*/
static BOOL GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
{
BOOL ret;
FileOpenDlgInfos fodInfos;
LPSTR lpstrSavDir = NULL;
LPWSTR title = NULL;
LPWSTR defext = NULL;
LPWSTR filter = NULL;
LPWSTR customfilter = NULL;
/* Initialize CommDlgExtendedError() */
COMDLG32_SetCommDlgExtendedError(0);
/* Initialize FileOpenDlgInfos structure */
ZeroMemory(&fodInfos, sizeof(FileOpenDlgInfos));
/* Pass in the original ofn */
fodInfos.ofnInfos = (LPOPENFILENAMEW)ofn;
/* save current directory */
if (ofn->Flags & OFN_NOCHANGEDIR)
{
lpstrSavDir = MemAlloc(MAX_PATH);
GetCurrentDirectoryA(MAX_PATH, lpstrSavDir);
}
fodInfos.unicode = FALSE;
/* convert all the input strings to unicode */
if(ofn->lpstrInitialDir)
{
DWORD len = MultiByteToWideChar( CP_ACP, 0, ofn->lpstrInitialDir, -1, NULL, 0 );
fodInfos.initdir = MemAlloc((len+1)*sizeof(WCHAR));
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrInitialDir, -1, fodInfos.initdir, len);
}
else
fodInfos.initdir = NULL;
if(ofn->lpstrFile)
{
fodInfos.filename = MemAlloc(ofn->nMaxFile*sizeof(WCHAR));
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrFile, -1, fodInfos.filename, ofn->nMaxFile);
}
else
fodInfos.filename = NULL;
if(ofn->lpstrDefExt)
{
DWORD len = MultiByteToWideChar( CP_ACP, 0, ofn->lpstrDefExt, -1, NULL, 0 );
defext = MemAlloc((len+1)*sizeof(WCHAR));
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrDefExt, -1, defext, len);
}
fodInfos.defext = defext;
if(ofn->lpstrTitle)
{
DWORD len = MultiByteToWideChar( CP_ACP, 0, ofn->lpstrTitle, -1, NULL, 0 );
title = MemAlloc((len+1)*sizeof(WCHAR));
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrTitle, -1, title, len);
}
fodInfos.title = title;
if (ofn->lpstrFilter)
{
LPCSTR s;
int n, len;
/* filter is a list... title\0ext\0......\0\0 */
s = ofn->lpstrFilter;
while (*s) s = s+strlen(s)+1;
s++;
n = s - ofn->lpstrFilter;
len = MultiByteToWideChar( CP_ACP, 0, ofn->lpstrFilter, n, NULL, 0 );
filter = MemAlloc(len*sizeof(WCHAR));
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrFilter, n, filter, len );
}
fodInfos.filter = filter;
/* convert lpstrCustomFilter */
if (ofn->lpstrCustomFilter)
{
LPCSTR s;
int n, len;
/* customfilter contains a pair of strings... title\0ext\0 */
s = ofn->lpstrCustomFilter;
if (*s) s = s+strlen(s)+1;
if (*s) s = s+strlen(s)+1;
n = s - ofn->lpstrCustomFilter;
len = MultiByteToWideChar( CP_ACP, 0, ofn->lpstrCustomFilter, n, NULL, 0 );
customfilter = MemAlloc(len*sizeof(WCHAR));
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrCustomFilter, n, customfilter, len );
}
fodInfos.customfilter = customfilter;
/* Initialize the dialog property */
fodInfos.DlgInfos.dwDlgProp = 0;
fodInfos.DlgInfos.hwndCustomDlg = NULL;
switch(iDlgType)
{
case OPEN_DIALOG :
ret = GetFileName95(&fodInfos);
break;
case SAVE_DIALOG :
fodInfos.DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
ret = GetFileName95(&fodInfos);
break;
default :
ret = 0;
}
if (lpstrSavDir)
{
SetCurrentDirectoryA(lpstrSavDir);
MemFree(lpstrSavDir);
}
MemFree(title);
MemFree(defext);
MemFree(filter);
MemFree(customfilter);
MemFree(fodInfos.initdir);
MemFree(fodInfos.filename);
TRACE("selected file: %s\n",ofn->lpstrFile);
return ret;
}
/***********************************************************************
* GetFileDialog95W
*
* Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
* Call GetFileName95 with this structure and clean the memory.
*
*/
static BOOL GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
{
BOOL ret;
FileOpenDlgInfos fodInfos;
LPWSTR lpstrSavDir = NULL;
/* Initialize CommDlgExtendedError() */
COMDLG32_SetCommDlgExtendedError(0);
/* Initialize FileOpenDlgInfos structure */
ZeroMemory(&fodInfos, sizeof(FileOpenDlgInfos));
/* Pass in the original ofn */
fodInfos.ofnInfos = ofn;
fodInfos.title = ofn->lpstrTitle;
fodInfos.defext = ofn->lpstrDefExt;
fodInfos.filter = ofn->lpstrFilter;
fodInfos.customfilter = ofn->lpstrCustomFilter;
/* convert string arguments, save others */
if(ofn->lpstrFile)
{
fodInfos.filename = MemAlloc(ofn->nMaxFile*sizeof(WCHAR));
lstrcpynW(fodInfos.filename,ofn->lpstrFile,ofn->nMaxFile);
}
else
fodInfos.filename = NULL;
if(ofn->lpstrInitialDir)
{
/* fodInfos.initdir = strdupW(ofn->lpstrInitialDir); */
DWORD len = lstrlenW(ofn->lpstrInitialDir)+1;
fodInfos.initdir = MemAlloc(len*sizeof(WCHAR));
memcpy(fodInfos.initdir,ofn->lpstrInitialDir,len*sizeof(WCHAR));
}
else
fodInfos.initdir = NULL;
/* save current directory */
if (ofn->Flags & OFN_NOCHANGEDIR)
{
lpstrSavDir = MemAlloc(MAX_PATH*sizeof(WCHAR));
GetCurrentDirectoryW(MAX_PATH, lpstrSavDir);
}
fodInfos.unicode = TRUE;
switch(iDlgType)
{
case OPEN_DIALOG :
ret = GetFileName95(&fodInfos);
break;
case SAVE_DIALOG :
fodInfos.DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
ret = GetFileName95(&fodInfos);
break;
default :
ret = 0;
}
if (lpstrSavDir)
{
SetCurrentDirectoryW(lpstrSavDir);
MemFree(lpstrSavDir);
}
/* restore saved IN arguments and convert OUT arguments back */
MemFree(fodInfos.filename);
MemFree(fodInfos.initdir);
return ret;
}
/******************************************************************************
* COMDLG32_GetDisplayNameOf [internal]
*
* Helper function to get the display name for a pidl.
*/
static BOOL COMDLG32_GetDisplayNameOf(LPCITEMIDLIST pidl, LPWSTR pwszPath) {
LPSHELLFOLDER psfDesktop;
STRRET strret;
if (FAILED(SHGetDesktopFolder(&psfDesktop)))
return FALSE;
if (FAILED(IShellFolder_GetDisplayNameOf(psfDesktop, pidl, SHGDN_FORPARSING, &strret))) {
IShellFolder_Release(psfDesktop);
return FALSE;
}
IShellFolder_Release(psfDesktop);
return SUCCEEDED(StrRetToBufW(&strret, pidl, pwszPath, MAX_PATH));
}
/******************************************************************************
* COMDLG32_GetCanonicalPath [internal]
*
* Helper function to get the canonical path.
*/
void COMDLG32_GetCanonicalPath(PCIDLIST_ABSOLUTE pidlAbsCurrent,
LPWSTR lpstrFile, LPWSTR lpstrPathAndFile)
{
WCHAR lpstrTemp[MAX_PATH];
/* Get the current directory name */
if (!COMDLG32_GetDisplayNameOf(pidlAbsCurrent, lpstrPathAndFile))
{
/* last fallback */
GetCurrentDirectoryW(MAX_PATH, lpstrPathAndFile);
}
PathAddBackslashW(lpstrPathAndFile);
TRACE("current directory=%s\n", debugstr_w(lpstrPathAndFile));
/* if the user specified a fully qualified path use it */
if(PathIsRelativeW(lpstrFile))
{
lstrcatW(lpstrPathAndFile, lpstrFile);
}
else
{
/* does the path have a drive letter? */
if (PathGetDriveNumberW(lpstrFile) == -1)
lstrcpyW(lpstrPathAndFile+2, lpstrFile);
else
lstrcpyW(lpstrPathAndFile, lpstrFile);
}
/* resolve "." and ".." */
PathCanonicalizeW(lpstrTemp, lpstrPathAndFile );
lstrcpyW(lpstrPathAndFile, lpstrTemp);
TRACE("canon=%s\n", debugstr_w(lpstrPathAndFile));
}
/***********************************************************************
* COMDLG32_SplitFileNames [internal]
*
* Creates a delimited list of filenames.
*/
int COMDLG32_SplitFileNames(LPWSTR lpstrEdit, UINT nStrLen, LPWSTR *lpstrFileList, UINT *sizeUsed)
{
UINT nStrCharCount = 0; /* index in src buffer */
UINT nFileIndex = 0; /* index in dest buffer */
UINT nFileCount = 0; /* number of files */
/* we might get single filename without any '"',
* so we need nStrLen + terminating \0 + end-of-list \0 */
*lpstrFileList = MemAlloc( (nStrLen+2)*sizeof(WCHAR) );
*sizeUsed = 0;
/* build delimited file list from filenames */
while ( nStrCharCount <= nStrLen )
{
if ( lpstrEdit[nStrCharCount]=='"' )
{
nStrCharCount++;
while ((lpstrEdit[nStrCharCount]!='"') && (nStrCharCount <= nStrLen))
{
(*lpstrFileList)[nFileIndex++] = lpstrEdit[nStrCharCount];
nStrCharCount++;
}
(*lpstrFileList)[nFileIndex++] = 0;
nFileCount++;
}
nStrCharCount++;
}
/* single, unquoted string */
if ((nStrLen > 0) && (nFileIndex == 0) )
{
lstrcpyW(*lpstrFileList, lpstrEdit);
nFileIndex = lstrlenW(lpstrEdit) + 1;
nFileCount = 1;
}
/* trailing \0 */
(*lpstrFileList)[nFileIndex++] = '\0';
*sizeUsed = nFileIndex;
return nFileCount;
}
/***********************************************************************
* ArrangeCtrlPositions [internal]
*
* NOTE: Make sure to add testcases for any changes made here.
*/
static void ArrangeCtrlPositions(HWND hwndChildDlg, HWND hwndParentDlg, BOOL hide_help)
{
HWND hwndChild, hwndStc32;
RECT rectParent, rectChild, rectStc32;
INT help_fixup = 0;
int chgx, chgy;
/* Take into account if open as read only checkbox and help button
* are hidden
*/
if (hide_help)
{
RECT rectHelp, rectCancel;
GetWindowRect(GetDlgItem(hwndParentDlg, pshHelp), &rectHelp);
GetWindowRect(GetDlgItem(hwndParentDlg, IDCANCEL), &rectCancel);
/* subtract the height of the help button plus the space between
* the help button and the cancel button to the height of the dialog
*/
help_fixup = rectHelp.bottom - rectCancel.bottom;
}
/*
There are two possibilities to add components to the default file dialog box.
By default, all the new components are added below the standard dialog box (the else case).
However, if there is a static text component with the stc32 id, a special case happens.
The x and y coordinates of stc32 indicate the top left corner where to place the standard file dialog box
in the window and the cx and cy indicate how to size the window.
Moreover, if the new component's coordinates are on the left of the stc32 , it is placed on the left
of the standard file dialog box. If they are above the stc32 component, it is placed above and so on....
*/
GetClientRect(hwndParentDlg, &rectParent);
/* when arranging controls we have to use fixed parent size */
rectParent.bottom -= help_fixup;
hwndStc32 = GetDlgItem(hwndChildDlg, stc32);
if (hwndStc32)
{
GetWindowRect(hwndStc32, &rectStc32);
MapWindowPoints(0, hwndChildDlg, (LPPOINT)&rectStc32, 2);
/* set the size of the stc32 control according to the size of
* client area of the parent dialog
*/
SetWindowPos(hwndStc32, 0,
0, 0,
rectParent.right, rectParent.bottom,
SWP_NOMOVE | SWP_NOZORDER);
}
else
SetRectEmpty(&rectStc32);
/* this part moves controls of the child dialog */
hwndChild = GetWindow(hwndChildDlg, GW_CHILD);
while (hwndChild)
{
if (hwndChild != hwndStc32)
{
GetWindowRect(hwndChild, &rectChild);
MapWindowPoints(0, hwndChildDlg, (LPPOINT)&rectChild, 2);
/* move only if stc32 exist */
if (hwndStc32 && rectChild.left > rectStc32.right)
{
/* move to the right of visible controls of the parent dialog */
rectChild.left += rectParent.right;
rectChild.left -= rectStc32.right;
}
/* move even if stc32 doesn't exist */
if (rectChild.top >= rectStc32.bottom)
{
/* move below visible controls of the parent dialog */
rectChild.top += rectParent.bottom;
rectChild.top -= rectStc32.bottom - rectStc32.top;
}
SetWindowPos(hwndChild, 0, rectChild.left, rectChild.top,
0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
hwndChild = GetWindow(hwndChild, GW_HWNDNEXT);
}
/* this part moves controls of the parent dialog */
hwndChild = GetWindow(hwndParentDlg, GW_CHILD);
while (hwndChild)
{
if (hwndChild != hwndChildDlg)
{
GetWindowRect(hwndChild, &rectChild);
MapWindowPoints(0, hwndParentDlg, (LPPOINT)&rectChild, 2);
/* left,top of stc32 marks the position of controls
* from the parent dialog
*/
rectChild.left += rectStc32.left;
rectChild.top += rectStc32.top;
SetWindowPos(hwndChild, 0, rectChild.left, rectChild.top,
0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
hwndChild = GetWindow(hwndChild, GW_HWNDNEXT);
}
/* calculate the size of the resulting dialog */
/* here we have to use original parent size */
GetClientRect(hwndParentDlg, &rectParent);
GetClientRect(hwndChildDlg, &rectChild);
TRACE( "parent %s child %s stc32 %s\n", wine_dbgstr_rect( &rectParent),
wine_dbgstr_rect( &rectChild), wine_dbgstr_rect( &rectStc32));
if (hwndStc32)
{
/* width */
if (rectParent.right > rectStc32.right - rectStc32.left)
chgx = rectChild.right - ( rectStc32.right - rectStc32.left);
else
chgx = rectChild.right - rectParent.right;
/* height */
if (rectParent.bottom > rectStc32.bottom - rectStc32.top)
chgy = rectChild.bottom - ( rectStc32.bottom - rectStc32.top) - help_fixup;
else
/* Unconditionally set new dialog
* height to that of the child
*/
chgy = rectChild.bottom - rectParent.bottom;
}
else
{
chgx = 0;
chgy = rectChild.bottom - help_fixup;
}
/* set the size of the parent dialog */
GetWindowRect(hwndParentDlg, &rectParent);
SetWindowPos(hwndParentDlg, 0,
0, 0,
rectParent.right - rectParent.left + chgx,
rectParent.bottom - rectParent.top + chgy,
SWP_NOMOVE | SWP_NOZORDER);
}
static INT_PTR CALLBACK FileOpenDlgProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_INITDIALOG:
return TRUE;
}
return FALSE;
}
static HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos, HWND hwnd)
{
LPCVOID template;
HRSRC hRes;
HANDLE hDlgTmpl = 0;
HWND hChildDlg = 0;
TRACE("\n");
/*
* If OFN_ENABLETEMPLATEHANDLE is specified, the OPENFILENAME
* structure's hInstance parameter is not a HINSTANCE, but
* instead a pointer to a template resource to use.
*/
if (fodInfos->ofnInfos->Flags & (OFN_ENABLETEMPLATE | OFN_ENABLETEMPLATEHANDLE))
{
HINSTANCE hinst;
if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
{
hinst = COMDLG32_hInstance;
if( !(template = LockResource( fodInfos->ofnInfos->hInstance)))
{
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
return NULL;
}
}
else
{
hinst = fodInfos->ofnInfos->hInstance;
if(fodInfos->unicode)
{
LPOPENFILENAMEW ofn = fodInfos->ofnInfos;
hRes = FindResourceW( hinst, ofn->lpTemplateName, (LPWSTR)RT_DIALOG);
}
else
{
LPOPENFILENAMEA ofn = (LPOPENFILENAMEA)fodInfos->ofnInfos;
hRes = FindResourceA( hinst, ofn->lpTemplateName, (LPSTR)RT_DIALOG);
}
if (!hRes)
{
COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
return NULL;
}
if (!(hDlgTmpl = LoadResource( hinst, hRes )) ||
!(template = LockResource( hDlgTmpl )))
{
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
return NULL;
}
}
if (fodInfos->unicode)
hChildDlg = CreateDialogIndirectParamW(hinst, template, hwnd,
IsHooked(fodInfos) ? (DLGPROC)fodInfos->ofnInfos->lpfnHook : FileOpenDlgProcUserTemplate,
(LPARAM)fodInfos->ofnInfos);
else
hChildDlg = CreateDialogIndirectParamA(hinst, template, hwnd,
IsHooked(fodInfos) ? (DLGPROC)fodInfos->ofnInfos->lpfnHook : FileOpenDlgProcUserTemplate,
(LPARAM)fodInfos->ofnInfos);
return hChildDlg;
}
else if( IsHooked(fodInfos))
{
RECT rectHwnd;
struct {
DLGTEMPLATE tmplate;
WORD menu,class,title;
} temp;
GetClientRect(hwnd,&rectHwnd);
temp.tmplate.style = WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | DS_CONTROL | DS_3DLOOK;
temp.tmplate.dwExtendedStyle = 0;
temp.tmplate.cdit = 0;
temp.tmplate.x = 0;
temp.tmplate.y = 0;
temp.tmplate.cx = 0;
temp.tmplate.cy = 0;
temp.menu = temp.class = temp.title = 0;
hChildDlg = CreateDialogIndirectParamA(COMDLG32_hInstance, &temp.tmplate,
hwnd, (DLGPROC)fodInfos->ofnInfos->lpfnHook, (LPARAM)fodInfos->ofnInfos);
return hChildDlg;
}
return NULL;
}
/***********************************************************************
* SendCustomDlgNotificationMessage
*
* Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
*/
LRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
{
LRESULT hook_result = 0;
FileOpenDlgInfos *fodInfos = GetPropA(hwndParentDlg,FileOpenDlgInfosStr);
TRACE("%p 0x%04x\n",hwndParentDlg, uCode);
if(!fodInfos) return 0;
if(fodInfos->DlgInfos.hwndCustomDlg)
{
TRACE("CALL NOTIFY for %x\n", uCode);
if(fodInfos->unicode)
{
OFNOTIFYW ofnNotify;
ofnNotify.hdr.hwndFrom=hwndParentDlg;
ofnNotify.hdr.idFrom=0;
ofnNotify.hdr.code = uCode;
ofnNotify.lpOFN = fodInfos->ofnInfos;
ofnNotify.pszFile = NULL;
hook_result = SendMessageW(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);
}
else
{
OFNOTIFYA ofnNotify;
ofnNotify.hdr.hwndFrom=hwndParentDlg;
ofnNotify.hdr.idFrom=0;
ofnNotify.hdr.code = uCode;
ofnNotify.lpOFN = (LPOPENFILENAMEA)fodInfos->ofnInfos;
ofnNotify.pszFile = NULL;
hook_result = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);
}
TRACE("RET NOTIFY\n");
}
TRACE("Retval: 0x%08lx\n", hook_result);
return hook_result;
}
static INT_PTR FILEDLG95_Handle_GetFilePath(HWND hwnd, DWORD size, LPVOID result)
{
UINT len, total;
WCHAR *p, *buffer;
FileOpenDlgInfos *fodInfos = GetPropA(hwnd,FileOpenDlgInfosStr);
TRACE("CDM_GETFILEPATH:\n");
if ( ! (fodInfos->ofnInfos->Flags & OFN_EXPLORER ) )
return -1;
/* get path and filenames */
len = SendMessageW( fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0 );
buffer = HeapAlloc( GetProcessHeap(), 0, (len + 2 + MAX_PATH) * sizeof(WCHAR) );
COMDLG32_GetDisplayNameOf( fodInfos->ShellInfos.pidlAbsCurrent, buffer );
if (len)
{
p = buffer + strlenW(buffer);
*p++ = '\\';
SendMessageW( fodInfos->DlgInfos.hwndFileName, WM_GETTEXT, len + 1, (LPARAM)p );
}
if (fodInfos->unicode)
{
total = strlenW( buffer) + 1;
if (result) lstrcpynW( result, buffer, size );
TRACE( "CDM_GETFILEPATH: returning %u %s\n", total, debugstr_w(result));
}
else
{
total = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
if (total <= size) WideCharToMultiByte( CP_ACP, 0, buffer, -1, result, size, NULL, NULL );
TRACE( "CDM_GETFILEPATH: returning %u %s\n", total, debugstr_a(result));
}
HeapFree( GetProcessHeap(), 0, buffer );
return total;
}
/***********************************************************************
* FILEDLG95_HandleCustomDialogMessages
*
* Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
*/
static INT_PTR FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)