/
StandardDialog.prg
1464 lines (900 loc) · 27.1 KB
/
StandardDialog.prg
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
#ifdef __VULCAN__
USING System.Runtime.InteropServices
#endif
/// <include file="Gui.xml" path="doc/OpenDialog/*" />
CLASS OpenDialog INHERIT StandardFileDialog
/// <include file="Gui.xml" path="doc/OpenDialog.ctor/*" />
CONSTRUCTOR(oOwnWnd, cInitPath, dwFlag)
SUPER(oOwnWnd,cInitPath,dwFlag)
IsOpen := TRUE
IF (LoWord(GetVersion()) < 4)
Flags := _OR(OFN_SHOWHELP, OFN_FILEMUSTEXIST, OFN_PATHMUSTEXIST,OFN_ENABLESIZING)
ELSE
Flags := _OR(OFN_EXPLORER, OFN_SHOWHELP, OFN_FILEMUSTEXIST, OFN_PATHMUSTEXIST,OFN_ENABLEHOOK,OFN_ENABLESIZING)
ENDIF
RETURN
END CLASS
/// <include file="Gui.xml" path="doc/PaletteDialog/*" />
CLASS PaletteDialog INHERIT StandardColorDialog
/// <include file="Gui.xml" path="doc/PaletteDialog.ctor/*" />
CONSTRUCTOR(uOwner,oColor)
IF !IsNil(uOwner)
IF !(uOwner IS Window)
WCError{#Init,#PaletteDialog,__WCSTypeError,uOwner,1}:Throw()
ENDIF
ENDIF
IF (uOwner != NULL_OBJECT)
_hWnd := uOwner:Handle(4)
ELSE
_hWnd := NULL_PTR
ENDIF
SUPER(oColor)
liFlags := CC_RGBINIT
RETURN
END CLASS
/// <include file="Gui.xml" path="doc/SaveAsDialog/*" />
CLASS SaveAsDialog INHERIT StandardFileDialog
/// <include file="Gui.xml" path="doc/SaveAsDialog.ctor/*" />
CONSTRUCTOR(oOwnWnd, cInitPath, dwFlag)
SUPER(oOwnWnd,cInitPath, dwFlag)
IF (LoWord(GetVersion()) < 4)
Flags := _OR(OFN_SHOWHELP, OFN_PATHMUSTEXIST, OFN_HIDEREADONLY, OFN_ENABLESIZING)
ELSE
Flags := _OR(OFN_EXPLORER, OFN_SHOWHELP, OFN_PATHMUSTEXIST, OFN_HIDEREADONLY, OFN_ENABLESIZING, OFN_ENABLEHOOK)
ENDIF
RETURN
END CLASS
/// <include file="Gui.xml" path="doc/SelectDialog/*" />
CLASS SelectDialog INHERIT StandardColorDialog
/// <include file="Gui.xml" path="doc/SelectDialog.ctor/*" />
CONSTRUCTOR(uOwner,oColor)
IF !IsNil(uOwner)
IF !(uOwner IS Window)
WCError{#Init,#SelectDialog,__WCSTypeError,uOwner,1}:Throw()
ENDIF
ENDIF
IF (uOwner != NULL_OBJECT)
_hWnd := uOwner:Handle(4)
ELSE
_hWnd := NULL_PTR
ENDIF
SUPER(oColor)
liFlags := _OR(CC_PREVENTFULLOPEN, CC_RGBINIT)
RETURN
END CLASS
/// <include file="Gui.xml" path="doc/StandardColorDialog/*" />
CLASS StandardColorDialog INHERIT StandardDialog
PROTECT liFlags AS LONGINT
PROTECT dwDefColor AS DWORD
PROTECT pCustClr AS PTR
PROTECT _hWnd AS PTR
/// <include file="Gui.xml" path="doc/StandardColorDialog.Color/*" />
METHOD Color()
//PP-040425 Changed to use new capability of the Color class
RETURN Color{dwDefColor, -1}
/// <include file="Gui.xml" path="doc/StandardColorDialog.Destroy/*" />
METHOD Destroy() AS USUAL CLIPPER
IF (pCustClr != NULL_PTR)
MemFree(pCustClr)
ENDIF
IF !InCollect()
pCustClr := NULL_PTR
UnregisterAxit(SELF)
ENDIF
RETURN SELF
/// <include file="Gui.xml" path="doc/StandardColorDialog.ctor/*" />
CONSTRUCTOR(oColor)
LOCAL hDC AS PTR
LOCAL aCustClrs AS strColor
LOCAL oDefColor AS Color
//__LoadComDlgDLL()
SUPER()
oDefColor := Color{COLORBLACK}
IF !IsNil(oColor)
IF !(oColor IS Color)
WCError{#Init,#StandardColorDialog,__WCSTypeError,oColor,1}:Throw()
ENDIF
ENDIF
IF oColor != NULL_OBJECT
dwDefColor := oColor : ColorRef
ELSE
dwDefColor := odefColor : ColorRef
ENDIF
// Memory allocation for the structure of 16 DWORDs
aCustClrs := MemAlloc(_SIZEOF(strColor))
pCustClr := aCustClrs
hDC := GetDC(NULL_PTR)
aCustClrs:s2 := GetBkColor(hDC)
ReleaseDC(NULL_PTR, hDC)
aCustClrs:s1 := dwDefColor
aCustClrs:s3 := aCustClrs:s4 := aCustClrs:s5 := aCustClrs:s6 := ;
aCustClrs:s7 := aCustClrs:s8 := aCustClrs:s9 := aCustClrs:s10 := ;
aCustClrs:s11 := aCustClrs:s12 := aCustClrs:s13 := aCustClrs:s14 := ;
aCustClrs:s15 := aCustClrs:s16 := aCustClrs:s2
RETURN
/// <include file="Gui.xml" path="doc/StandardColorDialog.Show/*" />
METHOD Show()
LOCAL lRet AS LOGIC
LOCAL iSize := _SIZEOF(_winCHOOSECOLOR) AS DWORD
LOCAL cc AS _WINCHOOSECOLOR
cc := MemAlloc(iSize)
cc:lStructSize := iSize
cc:hwndOwner := _hWnd
cc:hInstance := 0
cc:rgbResult := dwDefColor
cc:lpCustColors := pCustClr
cc:Flags := DWORD(_CAST,liFlags)
//cc.Flags :=CC_FULLOPEN
cc:lCustData := 0
cc:lpfnHook := NULL_PTR
cc:lpTemplateName := NULL_PSZ
lRet := ChooseColor( cc)
IF lRet
dwDefColor := cc:rgbResult
ENDIF
MemFree(cc)
RETURN lRet
END CLASS
/// <include file="Gui.xml" path="doc/StandardDialog/*" />
CLASS StandardDialog INHERIT VObject
/// <include file="Gui.xml" path="doc/StandardDialog.ctor/*" />
CONSTRUCTOR()
SUPER()
RETURN
END CLASS
/// <include file="Gui.xml" path="doc/StandardFileDialog/*" />
CLASS StandardFileDialog INHERIT StandardDialog
PROTECT hWnd AS PTR
PROTECT cDefExt AS STRING
PROTECT Result AS USUAL
PROTECT InitDir, Title AS STRING
PROTECT pszFilters AS PSZ
PROTECT iFilterLen AS INT
PROTECT FltIndex, Size AS INT
PROTECT Flags AS DWORD
PROTECT FlagsEx AS DWORD
PROTECT IsOpen AS LOGIC
PROTECT pOpenFileName AS PTR
PROTECT oOwner AS OBJECT
PROTECT strucSelf AS SelfPtr
//PP-030828 Strong typing
/// <exclude />
METHOD __AddFilter(sFilter AS STRING, sFilterDesc AS STRING) AS VOID STRICT
//PP-030828 Strong typing
LOCAL pszNew AS PSZ
LOCAL pCurPos AS BYTE PTR
LOCAL iOldLen AS INT
iOldLen := iFilterLen
IF iFilterLen = 0
iFilterLen := 1
ENDIF
iFilterLen += INT(_CAST, SLen(sFilter) + SLen(sFilterDesc) + 2)
pszNew := MemAlloc(DWORD(iFilterLen))
MemSet(pszNew, 0, DWORD(iFilterLen))
pCurPos := pszNew
IF pszFilters != NULL_PSZ
MemCopy(pCurPos, pszFilters, DWORD(iOldLen-1))
MemFree(pszFilters)
pCurPos += iOldLen-1
ENDIF
MemCopyString(pCurPos, sFilterDesc, Len(sFilterDesc))
pCurPos += Len(sFilterDesc)+1
MemCopyString(pCurPos, sFilter, Len(sFilter))
pszFilters := pszNew
RETURN
/// <exclude />
METHOD __ClearFilters() AS VOID STRICT
//PP-030828 Strong typing
IF pszFilters != NULL_PSZ
MemFree(pszFilters)
pszFilters := NULL_PSZ
iFilterLen := 0
ENDIF
RETURN
/// <exclude />
ACCESS __Flags AS DWORD STRICT
//PP-030828 Strong typing
RETURN Flags
/// <include file="Gui.xml" path="doc/StandardFileDialog.Caption/*" />
ACCESS Caption
RETURN Title
/// <include file="Gui.xml" path="doc/StandardFileDialog.Caption/*" />
ASSIGN Caption(cNewCaption)
Title := AsString(cNewCaption)
RETURN
/// <include file="Gui.xml" path="doc/StandardFileDialog.DefExt/*" />
ACCESS DefExt
//PP-040101
RETURN SELF:cDefExt
/// <include file="Gui.xml" path="doc/StandardFileDialog.DefExt/*" />
ASSIGN DefExt( cNew )
//PP-040101
RETURN ( SELF:cDefExt := cNew )
/// <include file="Gui.xml" path="doc/StandardFileDialog.Destroy/*" />
METHOD Destroy() AS USUAL CLIPPER
IF (pOpenFileName != NULL_PTR)
MemFree(pOpenFileName)
pOpenFileName := NULL_PTR
ENDIF
IF pszFilters != NULL_PSZ
MemFree(pszFilters)
pszFilters := NULL_PSZ
ENDIF
IF !InCollect()
pOpenFileName := NULL_PTR
UnregisterAxit(SELF)
ENDIF
RETURN SELF
/// <include file="Gui.xml" path="doc/StandardFileDialog.Dispatch/*" />
METHOD Dispatch(oEvt, hDlg)
RETURN 0L
/// <include file="Gui.xml" path="doc/StandardFileDialog.DlgStyle/*" />
ASSIGN DlgStyle(flag)
IF LoWord(GetVersion()) >= 4
IF flag
Flags := _OR(Flags, DWORD(_CAST, OFN_EXPLORER))
ELSE
Flags := _AND(Flags, DWORD(_CAST, _NOT(OFN_EXPLORER)))
ENDIF
ENDIF
RETURN
/// <include file="Gui.xml" path="doc/StandardFileDialog.FileName/*" />
ACCESS FileName
IF (Len(Result) == 0)
RETURN NULL_STRING
ENDIF
RETURN Result
/// <include file="Gui.xml" path="doc/StandardFileDialog.FilterIndex/*" />
ACCESS FilterIndex
//PP-030910
RETURN fltindex
/// <include file="Gui.xml" path="doc/StandardFileDialog.help/*" />
METHOD help()
RETURN NIL
/// <include file="Gui.xml" path="doc/StandardFileDialog.HideReadOnly/*" />
ASSIGN HideReadOnly(flag)
IF flag
Flags := _OR(Flags, OFN_HIDEREADONLY)
ELSE
Flags := _AND(Flags, _NOT(OFN_HIDEREADONLY))
ENDIF
RETURN
/// <include file="Gui.xml" path="doc/StandardFileDialog.ctor/*" />
CONSTRUCTOR(uOwner, cInitPath)
LOCAL iPos/*, iRest*/ AS INT
LOCAL cTest, cRest, cAllFiles AS STRING
LOCAL lHasWildCard := FALSE AS LOGIC
LOCAL sOFN AS _WINOPENFILENAME
LOCAL sFilters AS STRING
LOCAL pVersionInfo IS _WINOSVERSIONINFO
//__LoadComDlgDLL()
SUPER()
IF !IsNil(uOwner)
IF !(uOwner IS Window)
WCError{#Init,#TextBox,__WCSTypeError,uOwner,1}:Throw()
ELSE
oOwner:=uOwner
ENDIF
ENDIF
IF oOwner != NULL_OBJECT
hWnd := oOwner:HANDLE()
ELSE
hWnd := NULL_PTR
ENDIF
pVersionInfo:dwOSVersionInfoSize := _SIZEOF(_WINOSVERSIONINFO)
GetVersionEx(@pVersionInfo)
IF pVersionInfo:dwMajorVersion >= 5
SELF:Size := _SIZEOF(_WINOPENFILENAME)
ELSE
SELF:size := OPENFILENAME_SIZE_VERSION_400
ENDIF
cDefExt := NULL_STRING
InitDir := NULL_STRING
Title := NULL_STRING
pszFilters := NULL_PSZ
FltIndex := 1
IsOpen := FALSE
// needed for changing dialog's style (by OFN_EXPLORER)
Flags := OFN_ALLOWMULTISELECT
sOFN := MemAlloc(DWORD(Size))
MemClear(sOFN, DWORD(Size))
pOpenFileName := sOFN
cAllFiles := ResourceString{__WCSAllFiles}:value
Result := IIF(IsNil(cInitPath), "*.*", cInitPath)
// Find default extension
iPos := INT(_CAST, RAt2(".", Result))
cTest := CharPos(Result, 2)
IF (iPos # 0 .AND. cTest # NULL_STRING)
cRest := SubStr(Result, ++iPos) // skip '.'
// iRest := INT(_CAST, SLen(cRest))
IF InStr("*", cRest) .OR. Instr("?", cRest)
lHasWildCard := FALSE
ENDIF
// Set as default extension if there are no wildcards
IF !lHasWildCard
cDefExt := cRest
ENDIF
// Set up filter string
IF !(cRest == "*") // its not the standard wildcard
cTest := "*." + cRest
sFilters := cTest + "|" + cTest + "|" + cAllFiles
ELSE
sFilters := cAllFiles
ENDIF
ELSE // Set up standard filter string
sFilters := cAllFiles
ENDIF
IF NULL_STRING != sFilters
iFilterLen := INT(_CAST, SLen(sFilters)+1)
cTest := SubStr(sFilters, -1) // Grab the string separator '|'
WHILE (TRUE)
iPos := INT(_CAST, RAt2(cTest, sFilters))
IF iPos == 0
EXIT
ENDIF
// Replace '|' for '\0'
sFilters := Stuff(sFilters, DWORD(iPos), 1, _CHR(0))
END
pszFilters := MemAlloc(DWORD(iFilterLen))
MemSet(pszFilters, 0, DWORD(iFilterLen))
MemCopy(pszFilters, String2Psz(sFilters), DWORD(iFilterLen-1) )
ENDIF
strucSelf :=__WCSelfPtrAlloc(SELF)
RETURN
/// <include file="Gui.xml" path="doc/StandardFileDialog.InitialDirectory/*" />
ACCESS InitialDirectory
RETURN InitDir
/// <include file="Gui.xml" path="doc/StandardFileDialog.InitialDirectory/*" />
ASSIGN InitialDirectory(cNewDir)
InitDir := AsString(cNewDir)
RETURN
/// <include file="Gui.xml" path="doc/StandardFileDialog.NoPlacesBar/*" />
ACCESS NoPlacesBar
RETURN LOGIC(_CAST, _AND(FlagsEx, OFN_EX_NOPLACESBAR))
/// <include file="Gui.xml" path="doc/StandardFileDialog.NoPlacesBar/*" />
ASSIGN NoPlacesBar(flag)
IF flag
FlagsEx := _OR(FlagsEx, OFN_EX_NOPLACESBAR)
ELSE
FlagsEx := _AND(FlagsEx, _NOT(OFN_EX_NOPLACESBAR))
ENDIF
RETURN
/// <include file="Gui.xml" path="doc/StandardFileDialog.ReadOnly/*" />
ACCESS ReadOnly
RETURN LOGIC(_CAST, _AND(Flags, OFN_READONLY))
/// <include file="Gui.xml" path="doc/StandardFileDialog.ReadOnly/*" />
ASSIGN ReadOnly(flag)
IF flag
Flags := _OR(Flags, OFN_READONLY)
ELSE
Flags := _AND(Flags, _NOT(OFN_READONLY))
ENDIF
RETURN
/// <include file="Gui.xml" path="doc/StandardFileDialog.SetFilter/*" />
METHOD SetFilter(uFilter, uFilterDesc, nIndex)
LOCAL i AS INT
IF IsLong(nIndex)
FltIndex := nIndex
ENDIF
IF IsString(uFilter) .AND. IsString(uFilterDesc)
SELF:__ClearFilters()
SELF:__AddFilter(uFilter, uFilterDesc)
ELSEIF IsArray(uFilter) .AND. IsArray(uFilterDesc)
SELF:__ClearFilters()
FOR i:=1 TO Min(ALen(uFilter), ALen(uFilterDesc))
SELF:__AddFilter(AsString(uFilter[i]), AsString(uFilterDesc[i]))
NEXT
ENDIF
RETURN NIL
/// <include file="Gui.xml" path="doc/StandardFileDialog.SetStyle/*" />
METHOD SetStyle(kStyle, lOnOff)
DEFAULT(@lOnOff, TRUE)
IF (lOnOff)
Flags := _OR(Flags, DWORD(kStyle))
ELSE
Flags := _AND(Flags, _NOT(DWORD(kStyle)))
ENDIF
RETURN NIL
/// <include file="Gui.xml" path="doc/StandardFileDialog.SetStyleEx/*" />
METHOD SetStyleEx(kStyle, lOnOff)
DEFAULT(@lOnOff, TRUE)
IF (lOnOff)
FlagsEx := _OR(Flags, DWORD(kStyle))
ELSE
FlagsEx := _AND(Flags, _NOT(DWORD(kStyle)))
ENDIF
RETURN NIL
/// <include file="Gui.xml" path="doc/StandardFileDialog.Show/*" />
METHOD Show()
LOCAL lRet := TRUE AS LOGIC
LOCAL sOFN AS _winOPENFILENAME
LOCAL pszRes AS PSZ
LOCAL cPathName AS STRING
LOCAL cDirName AS STRING
LOCAL pb AS BYTE PTR
LOCAL iPos, iNxPos AS INT
LOCAL aResults AS ARRAY
TRY
sOFN := pOpenFileName
pszRes := MemAlloc(MAX_LEN)
MemCopyString(pszRes, Result, MAX_LEN)
// Filling in ofn members:
sOFN:lStructSize := DWORD(SELF:Size)
sOFN:hwndOwner := hWnd
sOFN:lpstrFile := pszRes
sOFN:nMaxFile := MAX_LEN
sOFN:lpstrFileTitle := NULL_PSZ
sOFN:nMaxFileTitle := 0
sOFN:lpstrDefExt := StringAlloc(cDefExt)
sOFN:lpstrInitialDir:= StringAlloc(InitDir)
sOFN:lpstrTitle := StringAlloc(Title)
sOFN:Flags := Flags
sOFN:FlagsEx := FlagsEx
#ifdef __VULCAN__
LOCAL StdFileHookDelegate AS __StdFileHookDelegate
StdFileHookDelegate := __StdFileHookDelegate{ NULL, @__StdFileHook() }
sOFN:lpfnHook := System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate( (System.Delegate) StdFileHookDelegate )
#else
sOFN:lpfnHook := @__StdFileHook()
#endif
sOFN:lCustData := LONGINT(_CAST, strucSelf)
sOFN:lpstrFilter := pszFilters
sOFN:nFilterIndex := DWORD(FltIndex)
IF (sOFN:lpfnHook != NULL_PTR)
sOFN:Flags := _OR (sOFN:Flags, OFN_ENABLEHOOK)
ELSE
sOFN:Flags := _AND(sOFN:Flags, _NOT(OFN_ENABLEHOOK))
ENDIF
// IF (IsBiDi())
// sOFN.Flags := _OR(sOFN.Flags, OFN_BIDIDIALOG)
// ENDIF
IF IsOpen
IF GetOpenFileName( sOFN)
IF (_AND(sOFN:Flags, OFN_ALLOWMULTISELECT) != 0)
aResults := {}
IF (_AND(sOFN:Flags, DWORD(_CAST, OFN_EXPLORER)) != 0)
// Exlorer Style
cPathName := Psz2String(sOFN:lpstrFile)
pb := sOFN:lpstrFile
pb += PszLen(pb) + 1
IF (PszLen(pb) > 0)
IF (Right(cPathName, 1) == "\")
cPathName := Left(cPathName, SLen(cPathName) - 1)
ENDIF
WHILE(PszLen(pb) > 0)
AAdd(aResults, cPathName + "\" + Psz2String(pb))
pb += PszLen(pb) + 1
END
Result := aResults
ELSE
Result := cPathName
ENDIF
ELSE
cPathName := Psz2String(sOFN:lpstrFile)
// Win3 Style
iPos := LONGINT( At2(" ", cPathName))
IF (iPos == 0)
Result := cPathName
ELSE
cDirName := Left(cPathName, DWORD(iPos-1))
IF (Right(cDirName, 1) == "\")
cDirName := Left(cDirName, SLen(cDirName) - 1)
ENDIF
iNxPos := LONGINT( At3(" ", cPathName, DWORD(iPos+1)))
WHILE (iNxPos != 0)
AAdd(aResults, cDirName + "\" + SubStr(cPathName, iPos+1, iNxPos-iPos))
iPos := iNxPos
iNxPos := LONGINT( At3(" ", cPathName, DWORD(iPos+1)))
END
AAdd(aResults, cDirName + "\" + SubStr2(cPathName, DWORD(iPos+1)))
Result := aResults
ENDIF
ENDIF
ELSE
Result := Psz2String(sOFN:lpstrFile)
ENDIF
ELSE
Result := NULL_STRING
lRet := FALSE
ENDIF
ELSE
IF GetSaveFileName( sOFN) .AND. CommDlgExtendedError() = 0
Result := Psz2String(sOFN:lpstrFile)
ELSE
CommDlgExtendedError()
Result := NULL_STRING
lRet := FALSE
ENDIF
ENDIF
#ifdef __VULCAN__
// This is needed to prevent the GC from prematurely collecting the delegate
// while the native call to gpfnGetOpen/SaveFileName is active
GC.KeepAlive( StdFileHookDelegate )
#endif
FltIndex := INT(_CAST, sOFN:nFilterIndex)
Flags := sOFN:Flags
FINALLY
IF pszRes != NULL_PTR
MemFree(pszRes)
ENDIF
IF sOFN != NULL
sOFN:lpstrFile := NULL_PSZ
MemFree(sOFN:lpstrDefExt )
sOFN:lpstrDefExt := NULL_PSZ
MemFree(sOFN:lpstrInitialDir)
sOFN:lpstrInitialDir := NULL_PSZ
MemFree(sOFN:lpstrTitle )
sOFN:lpstrTitle := NULL_PSZ
ENDIF
END TRY
RETURN lRet
END CLASS
/// <include file="Gui.xml" path="doc/StandardFolderDialog/*" />
CLASS StandardFolderDialog INHERIT StandardDialog
PROTECT hwndParent AS PTR
PROTECT sTitle AS STRING
PROTECT sStart AS STRING
PROTECT dwType AS DWORD
PROTECT sResult AS STRING
//PP-030828 Strong typing
/// <exclude />
ACCESS __StartFolder AS STRING STRICT
//PP-030828 Strong typing
RETURN sStart
/// <include file="Gui.xml" path="doc/StandardFolderDialog.DialogCallBack/*" />
METHOD DialogCallBack(hWnd, uMsg, lParam, lpData)
//PP-030910 suggestion from S Ebert
IF uMsg = BFFM_INITIALIZED
IF ! Empty(sStart)
SendMessage(hWnd, BFFM_SETSELECTION, 1, LONGINT(String2Psz(sStart)))
ENDIF
ENDIF
RETURN SELF
/// <include file="Gui.xml" path="doc/StandardFolderDialog.FolderName/*" />
ACCESS FolderName
RETURN sResult
/// <include file="Gui.xml" path="doc/StandardFolderDialog.ctor/*" />
CONSTRUCTOR(oOwner, sCaption, sStartFolder, kType)
SUPER()
DEFAULT(@kType, BIF_RETURNONLYFSDIRS)
DEFAULT(@sCaption, "Browser Folder")
DEFAULT(@sStartFolder, "")
__LoadShellDll()
IF IsMethod(oOwner, #handle)
hwndParent := oOwner:Handle()
ENDIF
sTitle := sCaption
sStart := sStartFolder
IF IsNumeric(dwType)
dwType := kType
ENDIF
IF WinDLLVersion{"COMCTL32"}:MajorVersion >= 5
dwType := _OR(dwType, 0x0040 ) // BIF_NEWDIALOGSTYLE
ENDIF
RETURN
/// <include file="Gui.xml" path="doc/StandardFolderDialog.Result/*" />
ACCESS Result
RETURN sResult
/// <include file="Gui.xml" path="doc/StandardFolderDialog.Show/*" />
METHOD Show()
LOCAL bi IS _winBROWSEINFO
LOCAL pidl AS PTR
LOCAL DIM aName[MAX_PATH] AS BYTE
LOCAL lRet AS LOGIC
LOCAL p AS SelfPtr
bi:hwndOwner := hWndParent
bi:pidlRoot := NULL_PTR
bi:pszDisplayName := @(aName[1])
IF Empty(sTitle)
bi:lpszTitle := NULL_PTR
ELSE
bi:lpszTitle := String2Psz(sTitle)
ENDIF
bi:ulFlags := dwType
#ifdef __VULCAN__
LOCAL d AS __FolderDialogCallBackDelegate
d := __FolderDialogCallBackDelegate{ NULL, @__FolderDialogCallBack() }
bi:lpfn := Marshal.GetFunctionPointerForDelegate( (System.Delegate) d )
#else
bi:lpfn := @__FolderDialogCallBack()
#endif
p :=__WCSelfPtrAlloc(SELF)
//RvdH 100216 Changed. The original code does not work at all....
//bi:lParam := LONGINT(_CAST,@p)
bi:lParam := LONGINT(_CAST,p)
bi:iImage := 0
pidl := SHBrowseForFolder( @bi)
IF (pidl != NULL_PTR)
sResult := Psz2String(bi:pszDisplayName)
lRet := SHGetPathFromIDList( pidl, bi:pszDisplayName)
IF lRet
sResult := Psz2String(bi:pszDisplayName)
ENDIF
CoTaskMemFree( pidl )
ENDIF
__WCSelfPtrFree(p)
#ifdef __VULCAN__
// This is needed to prevent the GC from prematurely collecting the delegate
// while the native call to gpfnSHBrowseForFolder is active
GC.KeepAlive( d )
#endif
RETURN lRet