-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtkWinDialog.c
More file actions
3577 lines (3174 loc) · 103 KB
/
Copy pathtkWinDialog.c
File metadata and controls
3577 lines (3174 loc) · 103 KB
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
/*
* tkWinDialog.c --
*
* Contains the Windows implementation of the common dialog boxes.
*
* Copyright © 1996-1997 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tkWinInt.h"
#include "tkFileFilter.h"
#include "tkFont.h"
#include <commdlg.h> /* includes common dialog functionality */
#include <dlgs.h> /* includes common dialog template defines */
#include <cderr.h> /* includes the common dialog error codes */
#include <shlobj.h> /* includes SHBrowseForFolder */
#ifdef _MSC_VER
# pragma comment (lib, "shell32.lib")
# pragma comment (lib, "comdlg32.lib")
# pragma comment (lib, "uuid.lib")
#endif
/* These needed for compilation with VC++ 5.2 */
/* XXX - remove these since need at least VC 6 */
#ifndef BIF_EDITBOX
#define BIF_EDITBOX 0x10
#endif
#ifndef BIF_VALIDATE
#define BIF_VALIDATE 0x0020
#endif
/* This "new" dialog style is now actually the "old" dialog style post-Vista */
#ifndef BIF_NEWDIALOGSTYLE
#define BIF_NEWDIALOGSTYLE 0x0040
#endif
#ifndef BFFM_VALIDATEFAILEDW
#define BFFM_VALIDATEFAILEDW 4
#endif /* BFFM_VALIDATEFAILEDW */
typedef struct {
int debugFlag; /* Flags whether we should output debugging
* information while displaying a builtin
* dialog. */
Tcl_Interp *debugInterp; /* Interpreter to used for debugging. */
UINT WM_LBSELCHANGED; /* Holds a registered windows event used for
* communicating between the Directory Chooser
* dialog and its hook proc. */
HHOOK hMsgBoxHook; /* Hook proc for tk_messageBox and the */
HICON hSmallIcon; /* icons used by a parent to be used in */
HICON hBigIcon; /* the message box */
int newFileDialogsState;
#define FDLG_STATE_INIT 0 /* Uninitialized */
#define FDLG_STATE_USE_NEW 1 /* Use the new dialogs */
#define FDLG_STATE_USE_OLD 2 /* Use the old dialogs */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;
/*
* The following structures are used by Tk_MessageBoxCmd() to parse arguments
* and return results.
*/
static const TkStateMap iconMap[] = {
{MB_ICONERROR, "error"},
{MB_ICONINFORMATION, "info"},
{MB_ICONQUESTION, "question"},
{MB_ICONWARNING, "warning"},
{-1, NULL}
};
static const TkStateMap typeMap[] = {
{MB_ABORTRETRYIGNORE, "abortretryignore"},
{MB_OK, "ok"},
{MB_OKCANCEL, "okcancel"},
{MB_RETRYCANCEL, "retrycancel"},
{MB_YESNO, "yesno"},
{MB_YESNOCANCEL, "yesnocancel"},
{-1, NULL}
};
static const TkStateMap buttonMap[] = {
{IDABORT, "abort"},
{IDRETRY, "retry"},
{IDIGNORE, "ignore"},
{IDOK, "ok"},
{IDCANCEL, "cancel"},
{IDNO, "no"},
{IDYES, "yes"},
{-1, NULL}
};
static const int buttonFlagMap[] = {
MB_DEFBUTTON1, MB_DEFBUTTON2, MB_DEFBUTTON3, MB_DEFBUTTON4
};
static const struct {int type; int btnIds[3];} allowedTypes[] = {
{MB_ABORTRETRYIGNORE, {IDABORT, IDRETRY, IDIGNORE}},
{MB_OK, {IDOK, -1, -1 }},
{MB_OKCANCEL, {IDOK, IDCANCEL, -1 }},
{MB_RETRYCANCEL, {IDRETRY, IDCANCEL, -1 }},
{MB_YESNO, {IDYES, IDNO, -1 }},
{MB_YESNOCANCEL, {IDYES, IDNO, IDCANCEL}}
};
#define NUM_TYPES (sizeof(allowedTypes) / sizeof(allowedTypes[0]))
/*
* Abstract trivial differences between Win32 and Win64.
*/
#define TkWinGetHInstance(from) \
((HINSTANCE) GetWindowLongPtrW((from), GWLP_HINSTANCE))
#define TkWinGetUserData(from) \
GetWindowLongPtrW((from), GWLP_USERDATA)
#define TkWinSetUserData(to,what) \
SetWindowLongPtrW((to), GWLP_USERDATA, (LPARAM)(what))
/*
* The value of TK_MULTI_MAX_PATH dictates how many files can be retrieved
* with tk_get*File -multiple 1. It must be allocated on the stack, so make it
* large enough but not too large. - hobbs
*
* The data is stored as <dir>\0<file1>\0<file2>\0...<fileN>\0\0. Since
* MAX_PATH == 260 on Win2K/NT, *40 is ~10Kbytes.
*/
#define TK_MULTI_MAX_PATH (MAX_PATH*40)
/*
* The following structure is used to pass information between the directory
* chooser function, Tk_ChooseDirectoryObjCmd(), and its dialog hook proc.
*/
typedef struct {
WCHAR initDir[MAX_PATH]; /* Initial folder to use */
WCHAR retDir[MAX_PATH]; /* Returned folder to use */
Tcl_Interp *interp;
int mustExist; /* True if file must exist to return from
* callback */
} ChooseDir;
/*
* The following structure is used to pass information between GetFileName
* function and OFN dialog hook procedures. [Bug 2896501, Patch 2898255]
*/
typedef struct OFNData {
Tcl_Interp *interp; /* Interp, used only if debug is turned on,
* for setting the variable
* "::tk::test::dialog::testDialog". */
int dynFileBufferSize; /* Dynamic filename buffer size, stored to
* avoid shrinking and expanding the buffer
* when selection changes */
WCHAR *dynFileBuffer; /* Dynamic filename buffer */
} OFNData;
/*
* The following structure is used to gather options used by various
* file dialogs
*/
typedef struct OFNOpts {
Tk_Window tkwin; /* Owner window for dialog */
Tcl_Obj *extObj; /* Default extension */
Tcl_Obj *titleObj; /* Title for dialog */
Tcl_Obj *filterObj; /* File type filter list */
Tcl_Obj *typeVariableObj; /* Variable in which to store type selected */
Tcl_Obj *initialTypeObj; /* Initial value of above, or NULL */
Tcl_DString utfDirString; /* Initial dir */
int multi; /* Multiple selection enabled */
int confirmOverwrite; /* Confirm before overwriting */
int mustExist; /* Used only for */
int forceXPStyle; /* XXX - Force XP style even on newer systems */
WCHAR file[TK_MULTI_MAX_PATH]; /* File name
XXX - fixed size because it was so
historically. Why not malloc'ed ?
*/
} OFNOpts;
/* Define the operation for which option parsing is to be done. */
enum OFNOper {
OFN_FILE_SAVE, /* tk_getOpenFile */
OFN_FILE_OPEN, /* tk_getSaveFile */
OFN_DIR_CHOOSE /* tk_chooseDirectory */
};
/*
* The following definitions are required when using older versions of
* Visual C++ (like 6.0) and possibly MingW. Those headers do not contain
* required definitions for interfaces new to Vista that we need for
* the new file dialogs. Duplicating definitions is OK because they
* should forever remain unchanged.
*
* XXX - is there a better/easier way to use new data definitions with
* older compilers? Should we prefix definitions with Tcl_ instead
* of using the same names as in the SDK?
*/
#ifndef __IShellItem_INTERFACE_DEFINED__
# define __IShellItem_INTERFACE_DEFINED__
#ifdef __MSVCRT__
typedef struct IShellItem IShellItem;
typedef enum __MIDL_IShellItem_0001 {
SIGDN_NORMALDISPLAY = 0,SIGDN_PARENTRELATIVEPARSING = 0x80018001,SIGDN_PARENTRELATIVEFORADDRESSBAR = 0x8001c001,
SIGDN_DESKTOPABSOLUTEPARSING = 0x80028000,SIGDN_PARENTRELATIVEEDITING = 0x80031001,SIGDN_DESKTOPABSOLUTEEDITING = 0x8004c000,
SIGDN_FILESYSPATH = 0x80058000,SIGDN_URL = 0x80068000
} SIGDN;
typedef DWORD SICHINTF;
typedef struct IShellItemVtbl
{
BEGIN_INTERFACE
HRESULT (STDMETHODCALLTYPE *QueryInterface)(IShellItem *, REFIID, void **);
ULONG (STDMETHODCALLTYPE *AddRef)(IShellItem *);
ULONG (STDMETHODCALLTYPE *Release)(IShellItem *);
HRESULT (STDMETHODCALLTYPE *BindToHandler)(IShellItem *, IBindCtx *, REFGUID, REFIID, void **);
HRESULT (STDMETHODCALLTYPE *GetParent)(IShellItem *, IShellItem **);
HRESULT (STDMETHODCALLTYPE *GetDisplayName)(IShellItem *, SIGDN, LPOLESTR *);
HRESULT (STDMETHODCALLTYPE *GetAttributes)(IShellItem *, SFGAOF, SFGAOF *);
HRESULT (STDMETHODCALLTYPE *Compare)(IShellItem *, IShellItem *, SICHINTF, int *);
END_INTERFACE
} IShellItemVtbl;
struct IShellItem {
CONST_VTBL struct IShellItemVtbl *lpVtbl;
};
#endif
#endif
#ifndef __IShellItemArray_INTERFACE_DEFINED__
#define __IShellItemArray_INTERFACE_DEFINED__
typedef enum SIATTRIBFLAGS {
SIATTRIBFLAGS_AND = 0x1,
SIATTRIBFLAGS_OR = 0x2,
SIATTRIBFLAGS_APPCOMPAT = 0x3,
SIATTRIBFLAGS_MASK = 0x3,
SIATTRIBFLAGS_ALLITEMS = 0x4000
} SIATTRIBFLAGS;
#ifdef __MSVCRT__
typedef ULONG SFGAOF;
#endif /* __MSVCRT__ */
typedef struct IShellItemArray IShellItemArray;
typedef struct IShellItemArrayVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IShellItemArray *, REFIID riid,void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(IShellItemArray *);
ULONG ( STDMETHODCALLTYPE *Release )(IShellItemArray *);
HRESULT ( STDMETHODCALLTYPE *BindToHandler )(IShellItemArray *,
IBindCtx *, REFGUID, REFIID, void **);
/* flags is actually is enum GETPROPERTYSTOREFLAGS */
HRESULT ( STDMETHODCALLTYPE *GetPropertyStore )(
IShellItemArray *, int, REFIID, void **);
/* keyType actually REFPROPERTYKEY */
HRESULT ( STDMETHODCALLTYPE *GetPropertyDescriptionList )(
IShellItemArray *, void *, REFIID, void **);
HRESULT ( STDMETHODCALLTYPE *GetAttributes )(IShellItemArray *,
SIATTRIBFLAGS, SFGAOF, SFGAOF *);
HRESULT ( STDMETHODCALLTYPE *GetCount )(
IShellItemArray *, DWORD *);
HRESULT ( STDMETHODCALLTYPE *GetItemAt )(
IShellItemArray *, DWORD, IShellItem **);
/* ppenumShellItems actually (IEnumShellItems **) */
HRESULT ( STDMETHODCALLTYPE *EnumItems )(
IShellItemArray *, void **);
END_INTERFACE
} IShellItemArrayVtbl;
struct IShellItemArray {
CONST_VTBL struct IShellItemArrayVtbl *lpVtbl;
};
#endif /* __IShellItemArray_INTERFACE_DEFINED__ */
/*
* Older compilers do not define these CLSIDs so we do so here under
* a slightly different name so as to not clash with the definitions
* in new compilers
*/
static const CLSID ClsidFileOpenDialog = {
0xDC1C5A9C, 0xE88A, 0X4DDE, {0xA5, 0xA1, 0x60, 0xF8, 0x2A, 0x20, 0xAE, 0xF7}
};
static const CLSID ClsidFileSaveDialog = {
0xC0B4E2F3, 0xBA21, 0x4773, {0x8D, 0xBA, 0x33, 0x5E, 0xC9, 0x46, 0xEB, 0x8B}
};
static const IID IIDIFileOpenDialog = {
0xD57C7288, 0xD4AD, 0x4768, {0xBE, 0x02, 0x9D, 0x96, 0x95, 0x32, 0xD9, 0x60}
};
static const IID IIDIFileSaveDialog = {
0x84BCCD23, 0x5FDE, 0x4CDB, {0xAE, 0xA4, 0xAF, 0x64, 0xB8, 0x3D, 0x78, 0xAB}
};
static const IID IIDIShellItem = {
0x43826D1E, 0xE718, 0x42EE, {0xBC, 0x55, 0xA1, 0xE2, 0x61, 0xC3, 0x7B, 0xFE}
};
#ifdef __IFileDialog_INTERFACE_DEFINED__
# define TCLCOMDLG_FILTERSPEC COMDLG_FILTERSPEC
#else
/* Forward declarations for structs that are referenced but not used */
typedef struct IPropertyStore IPropertyStore;
typedef struct IPropertyDescriptionList IPropertyDescriptionList;
typedef struct IFileOperationProgressSink IFileOperationProgressSink;
typedef enum FDAP {
FDAP_BOTTOM = 0,
FDAP_TOP = 1
} FDAP;
typedef struct {
LPCWSTR pszName;
LPCWSTR pszSpec;
} TCLCOMDLG_FILTERSPEC;
enum _FILEOPENDIALOGOPTIONS {
FOS_OVERWRITEPROMPT = 0x2,
FOS_STRICTFILETYPES = 0x4,
FOS_NOCHANGEDIR = 0x8,
FOS_PICKFOLDERS = 0x20,
FOS_FORCEFILESYSTEM = 0x40,
FOS_ALLNONSTORAGEITEMS = 0x80,
FOS_NOVALIDATE = 0x100,
FOS_ALLOWMULTISELECT = 0x200,
FOS_PATHMUSTEXIST = 0x800,
FOS_FILEMUSTEXIST = 0x1000,
FOS_CREATEPROMPT = 0x2000,
FOS_SHAREAWARE = 0x4000,
FOS_NOREADONLYRETURN = 0x8000,
FOS_NOTESTFILECREATE = 0x10000,
FOS_HIDEMRUPLACES = 0x20000,
FOS_HIDEPINNEDPLACES = 0x40000,
FOS_NODEREFERENCELINKS = 0x100000,
FOS_DONTADDTORECENT = 0x2000000,
FOS_FORCESHOWHIDDEN = 0x10000000,
FOS_DEFAULTNOMINIMODE = 0x20000000,
FOS_FORCEPREVIEWPANEON = 0x40000000
} ;
typedef DWORD FILEOPENDIALOGOPTIONS;
typedef struct IFileDialog IFileDialog;
typedef struct IFileDialogVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IFileDialog *, REFIID, void **);
ULONG ( STDMETHODCALLTYPE *AddRef )( IFileDialog *);
ULONG ( STDMETHODCALLTYPE *Release )( IFileDialog *);
HRESULT ( STDMETHODCALLTYPE *Show )( IFileDialog *, HWND);
HRESULT ( STDMETHODCALLTYPE *SetFileTypes )( IFileDialog *,
UINT, const TCLCOMDLG_FILTERSPEC *);
HRESULT ( STDMETHODCALLTYPE *SetFileTypeIndex )(IFileDialog *, UINT);
HRESULT ( STDMETHODCALLTYPE *GetFileTypeIndex )(IFileDialog *, UINT *);
/* XXX - Actually pfde is IFileDialogEvents* but we do not use
this call and do not want to define IFileDialogEvents as that
pulls in a whole bunch of other stuff. */
HRESULT ( STDMETHODCALLTYPE *Advise )(
IFileDialog *, void *, DWORD *);
HRESULT ( STDMETHODCALLTYPE *Unadvise )(IFileDialog *, DWORD);
HRESULT ( STDMETHODCALLTYPE *SetOptions )(
IFileDialog *, FILEOPENDIALOGOPTIONS);
HRESULT ( STDMETHODCALLTYPE *GetOptions )(
IFileDialog *, FILEOPENDIALOGOPTIONS *);
HRESULT ( STDMETHODCALLTYPE *SetDefaultFolder )(
IFileDialog *, IShellItem *);
HRESULT ( STDMETHODCALLTYPE *SetFolder )(
IFileDialog *, IShellItem *);
HRESULT ( STDMETHODCALLTYPE *GetFolder )(
IFileDialog *, IShellItem **);
HRESULT ( STDMETHODCALLTYPE *GetCurrentSelection )(
IFileDialog *, IShellItem **);
HRESULT ( STDMETHODCALLTYPE *SetFileName )(
IFileDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *GetFileName )(
IFileDialog *, LPWSTR *);
HRESULT ( STDMETHODCALLTYPE *SetTitle )(
IFileDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *SetOkButtonLabel )(
IFileDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *SetFileNameLabel )(
IFileDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *GetResult )(
IFileDialog *, IShellItem **);
HRESULT ( STDMETHODCALLTYPE *AddPlace )(
IFileDialog *, IShellItem *, FDAP);
HRESULT ( STDMETHODCALLTYPE *SetDefaultExtension )(
IFileDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *Close )( IFileDialog *, HRESULT);
HRESULT ( STDMETHODCALLTYPE *SetClientGuid )(
IFileDialog *, REFGUID);
HRESULT ( STDMETHODCALLTYPE *ClearClientData )( IFileDialog *);
/* pFilter actually IShellItemFilter. But deprecated in Win7 AND we do
not use it anyways. So define as void* */
HRESULT ( STDMETHODCALLTYPE *SetFilter )(
IFileDialog *, void *);
END_INTERFACE
} IFileDialogVtbl;
struct IFileDialog {
CONST_VTBL struct IFileDialogVtbl *lpVtbl;
};
typedef struct IFileSaveDialog IFileSaveDialog;
typedef struct IFileSaveDialogVtbl {
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IFileSaveDialog *, REFIID, void **);
ULONG ( STDMETHODCALLTYPE *AddRef )( IFileSaveDialog *);
ULONG ( STDMETHODCALLTYPE *Release )( IFileSaveDialog *);
HRESULT ( STDMETHODCALLTYPE *Show )(
IFileSaveDialog *, HWND);
HRESULT ( STDMETHODCALLTYPE *SetFileTypes )( IFileSaveDialog *,
UINT, const TCLCOMDLG_FILTERSPEC *);
HRESULT ( STDMETHODCALLTYPE *SetFileTypeIndex )(
IFileSaveDialog *, UINT);
HRESULT ( STDMETHODCALLTYPE *GetFileTypeIndex )(
IFileSaveDialog *, UINT *);
/* Actually pfde is IFileSaveDialogEvents* */
HRESULT ( STDMETHODCALLTYPE *Advise )(
IFileSaveDialog *, void *, DWORD *);
HRESULT ( STDMETHODCALLTYPE *Unadvise )( IFileSaveDialog *, DWORD);
HRESULT ( STDMETHODCALLTYPE *SetOptions )(
IFileSaveDialog *, FILEOPENDIALOGOPTIONS);
HRESULT ( STDMETHODCALLTYPE *GetOptions )(
IFileSaveDialog *, FILEOPENDIALOGOPTIONS *);
HRESULT ( STDMETHODCALLTYPE *SetDefaultFolder )(
IFileSaveDialog *, IShellItem *);
HRESULT ( STDMETHODCALLTYPE *SetFolder )(
IFileSaveDialog *, IShellItem *);
HRESULT ( STDMETHODCALLTYPE *GetFolder )(
IFileSaveDialog *, IShellItem **);
HRESULT ( STDMETHODCALLTYPE *GetCurrentSelection )(
IFileSaveDialog *, IShellItem **);
HRESULT ( STDMETHODCALLTYPE *SetFileName )(
IFileSaveDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *GetFileName )(
IFileSaveDialog *, LPWSTR *);
HRESULT ( STDMETHODCALLTYPE *SetTitle )(
IFileSaveDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *SetOkButtonLabel )(
IFileSaveDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *SetFileNameLabel )(
IFileSaveDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *GetResult )(
IFileSaveDialog *, IShellItem **);
HRESULT ( STDMETHODCALLTYPE *AddPlace )(
IFileSaveDialog *, IShellItem *, FDAP);
HRESULT ( STDMETHODCALLTYPE *SetDefaultExtension )(
IFileSaveDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *Close )( IFileSaveDialog *, HRESULT);
HRESULT ( STDMETHODCALLTYPE *SetClientGuid )(
IFileSaveDialog *, REFGUID);
HRESULT ( STDMETHODCALLTYPE *ClearClientData )( IFileSaveDialog *);
/* pFilter Actually IShellItemFilter* */
HRESULT ( STDMETHODCALLTYPE *SetFilter )(
IFileSaveDialog *, void *);
HRESULT ( STDMETHODCALLTYPE *SetSaveAsItem )(
IFileSaveDialog *, IShellItem *);
HRESULT ( STDMETHODCALLTYPE *SetProperties )(
IFileSaveDialog *, IPropertyStore *);
HRESULT ( STDMETHODCALLTYPE *SetCollectedProperties )(
IFileSaveDialog *, IPropertyDescriptionList *, BOOL);
HRESULT ( STDMETHODCALLTYPE *GetProperties )(
IFileSaveDialog *, IPropertyStore **);
HRESULT ( STDMETHODCALLTYPE *ApplyProperties )(
IFileSaveDialog *, IShellItem *, IPropertyStore *,
HWND, IFileOperationProgressSink *);
END_INTERFACE
} IFileSaveDialogVtbl;
struct IFileSaveDialog {
CONST_VTBL struct IFileSaveDialogVtbl *lpVtbl;
};
typedef struct IFileOpenDialog IFileOpenDialog;
typedef struct IFileOpenDialogVtbl {
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IFileOpenDialog *, REFIID, void **);
ULONG ( STDMETHODCALLTYPE *AddRef )( IFileOpenDialog *);
ULONG ( STDMETHODCALLTYPE *Release )( IFileOpenDialog *);
HRESULT ( STDMETHODCALLTYPE *Show )( IFileOpenDialog *, HWND);
HRESULT ( STDMETHODCALLTYPE *SetFileTypes )( IFileOpenDialog *,
UINT, const TCLCOMDLG_FILTERSPEC *);
HRESULT ( STDMETHODCALLTYPE *SetFileTypeIndex )(
IFileOpenDialog *, UINT);
HRESULT ( STDMETHODCALLTYPE *GetFileTypeIndex )(
IFileOpenDialog *, UINT *);
/* Actually pfde is IFileDialogEvents* */
HRESULT ( STDMETHODCALLTYPE *Advise )(
IFileOpenDialog *, void *, DWORD *);
HRESULT ( STDMETHODCALLTYPE *Unadvise )( IFileOpenDialog *, DWORD);
HRESULT ( STDMETHODCALLTYPE *SetOptions )(
IFileOpenDialog *, FILEOPENDIALOGOPTIONS);
HRESULT ( STDMETHODCALLTYPE *GetOptions )(
IFileOpenDialog *, FILEOPENDIALOGOPTIONS *);
HRESULT ( STDMETHODCALLTYPE *SetDefaultFolder )(
IFileOpenDialog *, IShellItem *);
HRESULT ( STDMETHODCALLTYPE *SetFolder )(
IFileOpenDialog *, IShellItem *);
HRESULT ( STDMETHODCALLTYPE *GetFolder )(
IFileOpenDialog *, IShellItem **);
HRESULT ( STDMETHODCALLTYPE *GetCurrentSelection )(
IFileOpenDialog *, IShellItem **);
HRESULT ( STDMETHODCALLTYPE *SetFileName )(
IFileOpenDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *GetFileName )(
IFileOpenDialog *, LPWSTR *);
HRESULT ( STDMETHODCALLTYPE *SetTitle )(
IFileOpenDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *SetOkButtonLabel )(
IFileOpenDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *SetFileNameLabel )(
IFileOpenDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *GetResult )(
IFileOpenDialog *, IShellItem **);
HRESULT ( STDMETHODCALLTYPE *AddPlace )(
IFileOpenDialog *, IShellItem *, FDAP);
HRESULT ( STDMETHODCALLTYPE *SetDefaultExtension )(
IFileOpenDialog *, LPCWSTR);
HRESULT ( STDMETHODCALLTYPE *Close )( IFileOpenDialog *, HRESULT);
HRESULT ( STDMETHODCALLTYPE *SetClientGuid )(
IFileOpenDialog *, REFGUID);
HRESULT ( STDMETHODCALLTYPE *ClearClientData )(
IFileOpenDialog *);
HRESULT ( STDMETHODCALLTYPE *SetFilter )(
IFileOpenDialog *,
/* pFilter is actually IShellItemFilter */
void *);
HRESULT ( STDMETHODCALLTYPE *GetResults )(
IFileOpenDialog *, IShellItemArray **);
HRESULT ( STDMETHODCALLTYPE *GetSelectedItems )(
IFileOpenDialog *, IShellItemArray **);
END_INTERFACE
} IFileOpenDialogVtbl;
struct IFileOpenDialog
{
CONST_VTBL struct IFileOpenDialogVtbl *lpVtbl;
};
#endif /* __IFileDialog_INTERFACE_DEFINED__ */
/*
* Definitions of functions used only in this file.
*/
static UINT APIENTRY ChooseDirectoryValidateProc(HWND hdlg, UINT uMsg,
LPARAM wParam, LPARAM lParam);
static UINT CALLBACK ColorDlgHookProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
static void CleanupOFNOptions(OFNOpts *optsPtr);
static int ParseOFNOptions(void *clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[], enum OFNOper oper, OFNOpts *optsPtr);
static int GetFileNameXP(Tcl_Interp *interp, OFNOpts *optsPtr,
enum OFNOper oper);
static int GetFileNameVista(Tcl_Interp *interp, OFNOpts *optsPtr,
enum OFNOper oper);
static int GetFileName(void *clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[], enum OFNOper oper);
static int MakeFilterVista(Tcl_Interp *interp, OFNOpts *optsPtr,
DWORD *countPtr, TCLCOMDLG_FILTERSPEC **dlgFilterPtrPtr,
DWORD *defaultFilterIndexPtr);
static void FreeFilterVista(DWORD count, TCLCOMDLG_FILTERSPEC *dlgFilterPtr);
static int MakeFilter(Tcl_Interp *interp, Tcl_Obj *valuePtr,
Tcl_DString *dsPtr, Tcl_Obj *initialPtr,
int *indexPtr);
static UINT APIENTRY OFNHookProc(HWND hdlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
static LRESULT CALLBACK MsgBoxCBTProc(int nCode, WPARAM wParam, LPARAM lParam);
static void SetTestDialog(void *clientData);
static const char *ConvertExternalFilename(LPCWSTR, Tcl_DString *);
/*
*-------------------------------------------------------------------------
*
* EatSpuriousMessageBugFix --
*
* In the file open/save dialog, double clicking on a list item causes
* the dialog box to close, but an unwanted WM_LBUTTONUP message is sent
* to the window underneath. If the window underneath happens to be a
* windows control (eg a button) then it will be activated by accident.
*
* This problem does not occur in dialog boxes, because windows must do
* some special processing to solve the problem. (separate message
* processing functions are used to cope with keyboard navigation of
* controls.)
*
* Here is one solution. After returning, we flush all mouse events
* for 1/4 second. In 8.6.5 and earlier, the code used to
* poll the message queue consuming WM_LBUTTONUP messages.
* On seeing a WM_LBUTTONDOWN message, it would exit early, since the user
* must be doing something new. However this early exit does not work
* on Vista and later because the Windows sends both BUTTONDOWN and
* BUTTONUP after the DBLCLICK instead of just BUTTONUP as on XP.
* Rather than try and figure out version specific sequences, we
* ignore all mouse events in that interval.
*
* This fix only works for the current application, so the problem will
* still occur if the open dialog happens to be over another applications
* button. However this is a fairly rare occurrance.
*
* Results:
* None.
*
* Side effects:
* Consumes unwanted mouse related messages.
*
*-------------------------------------------------------------------------
*/
static void
EatSpuriousMessageBugFix(void)
{
MSG msg;
DWORD nTime = GetTickCount() + 250;
while (GetTickCount() < nTime) {
PeekMessageW(&msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE);
}
}
/*
*-------------------------------------------------------------------------
*
* TkWinDialogDebug --
*
* Function to turn on/off debugging support for common dialogs under
* windows. The variable "::tk::test::dialog::testDialog" is set to the
* identifier of the dialog window when the modal dialog window pops up
* and it is safe to send messages to the dialog.
*
* Results:
* None.
*
* Side effects:
* This variable only makes sense if just one dialog is up at a time.
*
*-------------------------------------------------------------------------
*/
void
TkWinDialogDebug(
int debug)
{
ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
tsdPtr->debugFlag = debug;
}
/*
*-------------------------------------------------------------------------
*
* Tk_ChooseColorObjCmd --
*
* This function implements the color dialog box for the Windows
* platform. See the user documentation for details on what it does.
*
* Results:
* See user documentation.
*
* Side effects:
* A dialog window is created the first time this function is called.
* This window is not destroyed and will be reused the next time the
* application invokes the "tk_chooseColor" command.
*
*-------------------------------------------------------------------------
*/
int
Tk_ChooseColorObjCmd(
void *clientData, /* Main window associated with interpreter. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
Tk_Window tkwin = (Tk_Window)clientData, parent;
HWND hWnd;
int i, oldMode, winCode, result;
CHOOSECOLORW chooseColor;
static int inited = 0;
static COLORREF dwCustColors[16];
static long oldColor; /* the color selected last time */
static const char *const optionStrings[] = {
"-initialcolor", "-parent", "-title", NULL
};
enum options {
COLOR_INITIAL, COLOR_PARENT, COLOR_TITLE
};
result = TCL_OK;
if (inited == 0) {
/*
* dwCustColors stores the custom color which the user can modify. We
* store these colors in a static array so that the next time the
* color dialog pops up, the same set of custom colors remain in the
* dialog.
*/
for (i = 0; i < 16; i++) {
dwCustColors[i] = RGB(255-i * 10, i, i * 10);
}
oldColor = RGB(0xa0, 0xa0, 0xa0);
inited = 1;
}
parent = tkwin;
chooseColor.lStructSize = sizeof(CHOOSECOLORW);
chooseColor.hwndOwner = NULL;
chooseColor.hInstance = NULL;
chooseColor.rgbResult = oldColor;
chooseColor.lpCustColors = dwCustColors;
chooseColor.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ENABLEHOOK;
chooseColor.lCustData = (LPARAM) NULL;
chooseColor.lpfnHook = (LPOFNHOOKPROC)(void *)ColorDlgHookProc;
chooseColor.lpTemplateName = (LPWSTR) interp;
for (i = 1; i < objc; i += 2) {
int index;
const char *string;
Tcl_Obj *optionPtr, *valuePtr;
optionPtr = objv[i];
valuePtr = objv[i + 1];
if (Tcl_GetIndexFromObj(interp, optionPtr, optionStrings,
"option", TCL_EXACT, &index) != TCL_OK) {
return TCL_ERROR;
}
if (i + 1 == objc) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"value for \"%s\" missing", Tcl_GetString(optionPtr)));
Tcl_SetErrorCode(interp, "TK", "COLORDIALOG", "VALUE", (char *)NULL);
return TCL_ERROR;
}
string = Tcl_GetString(valuePtr);
switch ((enum options) index) {
case COLOR_INITIAL: {
XColor *colorPtr;
colorPtr = Tk_AllocColorFromObj(interp, tkwin, valuePtr);
if (colorPtr == NULL) {
return TCL_ERROR;
}
chooseColor.rgbResult = RGB(colorPtr->red / 0x100,
colorPtr->green / 0x100, colorPtr->blue / 0x100);
break;
}
case COLOR_PARENT:
parent = Tk_NameToWindow(interp, string, tkwin);
if (parent == NULL) {
return TCL_ERROR;
}
break;
case COLOR_TITLE:
chooseColor.lCustData = (LPARAM) string;
break;
}
}
Tk_MakeWindowExist(parent);
chooseColor.hwndOwner = NULL;
hWnd = Tk_GetHWND(Tk_WindowId(parent));
chooseColor.hwndOwner = hWnd;
oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
winCode = ChooseColorW(&chooseColor);
(void) Tcl_SetServiceMode(oldMode);
/*
* Ensure that hWnd is enabled, because it can happen that we have updated
* the wrapper of the parent, which causes us to leave this child disabled
* (Windows loses sync).
*/
EnableWindow(hWnd, 1);
/*
* Clear the interp result since anything may have happened during the
* modal loop.
*/
Tcl_ResetResult(interp);
/*
* 3. Process the result of the dialog
*/
if (winCode) {
/*
* User has selected a color
*/
Tcl_SetObjResult(interp, Tcl_ObjPrintf("#%02x%02x%02x",
GetRValue(chooseColor.rgbResult),
GetGValue(chooseColor.rgbResult),
GetBValue(chooseColor.rgbResult)));
oldColor = chooseColor.rgbResult;
result = TCL_OK;
}
return result;
}
/*
*-------------------------------------------------------------------------
*
* ColorDlgHookProc --
*
* Provides special handling of messages for the Color common dialog box.
* Used to set the title when the dialog first appears.
*
* Results:
* The return value is 0 if the default dialog box function should handle
* the message, non-zero otherwise.
*
* Side effects:
* Changes the title of the dialog window.
*
*----------------------------------------------------------------------
*/
static UINT CALLBACK
ColorDlgHookProc(
HWND hDlg, /* Handle to the color dialog. */
UINT uMsg, /* Type of message. */
TCL_UNUSED(WPARAM), /* First message parameter. */
LPARAM lParam) /* Second message parameter. */
{
ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
const char *title;
CHOOSECOLORW *ccPtr;
if (WM_INITDIALOG == uMsg) {
/*
* Set the title string of the dialog.
*/
ccPtr = (CHOOSECOLORW *) lParam;
title = (const char *) ccPtr->lCustData;
if ((title != NULL) && (title[0] != '\0')) {
Tcl_DString ds;
Tcl_DStringInit(&ds);
SetWindowTextW(hDlg, Tcl_UtfToWCharDString(title, TCL_INDEX_NONE, &ds));
Tcl_DStringFree(&ds);
}
if (tsdPtr->debugFlag) {
tsdPtr->debugInterp = (Tcl_Interp *) ccPtr->lpTemplateName;
Tcl_DoWhenIdle(SetTestDialog, hDlg);
}
return TRUE;
}
return FALSE;
}
/*
*----------------------------------------------------------------------
*
* Tk_GetOpenFileObjCmd --
*
* This function implements the "open file" dialog box for the Windows
* platform. See the user documentation for details on what it does.
*
* Results:
* See user documentation.
*
* Side effects:
* A dialog window is created the first this function is called.
*
*----------------------------------------------------------------------
*/
int
Tk_GetOpenFileObjCmd(
void *clientData, /* Main window associated with interpreter. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
return GetFileName(clientData, interp, objc, objv, OFN_FILE_OPEN);
}
/*
*----------------------------------------------------------------------
*
* Tk_GetSaveFileObjCmd --
*
* Same as Tk_GetOpenFileObjCmd but opens a "save file" dialog box
* instead
*
* Results:
* Same as Tk_GetOpenFileObjCmd.
*
* Side effects:
* Same as Tk_GetOpenFileObjCmd.
*
*----------------------------------------------------------------------
*/
int
Tk_GetSaveFileObjCmd(
void *clientData, /* Main window associated with interpreter. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
return GetFileName(clientData, interp, objc, objv, OFN_FILE_SAVE);
}
/*
*----------------------------------------------------------------------
*
* CleanupOFNOptions --
*
* Cleans up any storage allocated by ParseOFNOptions
*
* Results:
* None.
*
* Side effects:
* Releases resources held by *optsPtr
*----------------------------------------------------------------------
*/
static void CleanupOFNOptions(OFNOpts *optsPtr)
{
Tcl_DStringFree(&optsPtr->utfDirString);
}
/*
*----------------------------------------------------------------------
*
* ParseOFNOptions --
*
* Option parsing for tk_get{Open,Save}File
*
* Results:
* TCL_OK on success, TCL_ERROR otherwise
*
* Side effects:
* Returns option values in *optsPtr. Note these may include string
* pointers into objv[]
*----------------------------------------------------------------------
*/
static int
ParseOFNOptions(
void *clientData, /* Main window associated with interpreter. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[], /* Argument objects. */
enum OFNOper oper, /* 1 for Open, 0 for Save */
OFNOpts *optsPtr) /* Output, uninitialized on entry */
{
int i;
Tcl_DString ds;
enum options {
FILE_DEFAULT, FILE_TYPES, FILE_INITDIR, FILE_INITFILE, FILE_PARENT,
FILE_TITLE, FILE_TYPEVARIABLE, FILE_MULTIPLE, FILE_CONFIRMOW,
FILE_MUSTEXIST,
};
struct Options {
const char *name;
enum options value;
};
static const struct Options saveOptions[] = {
{"-confirmoverwrite", FILE_CONFIRMOW},
{"-defaultextension", FILE_DEFAULT},
{"-filetypes", FILE_TYPES},
{"-initialdir", FILE_INITDIR},
{"-initialfile", FILE_INITFILE},
{"-parent", FILE_PARENT},