-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathKOLDirDlgEx.pas
1369 lines (1290 loc) · 42.7 KB
/
KOLDirDlgEx.pas
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
unit KOLDirDlgEx;
interface
uses Windows, Messages, KOL {$IFDEF USE_GRUSH}, ToGrush, KOLGRushControls {$ENDIF};
{$I KOLDEF.INC}
{$I DELPHIDEF.INC}
{$IFDEF EXTERNAL_DEFINES}
{$INCLUDE EXTERNAL_DEFINES.INC}
{$ENDIF EXTERNAL_DEFINES}
//{$DEFINE NO_DEFAULT_FASTSCAN}
{ if you add such option, all icons for removable and remote drives
are obtained by default accessing these drives, slow. }
//{$DEFINE DIRDLGEX_NO_DBLCLK_ON_NODE_OK}
{ if this option is on, double clicks in the directories tree
is used only to expand/collapse children nodes. By default,
double click on a node w/o children selects it and
finishes the dialog as in case when OK is clicked. }
//{$DEFINE DIRDLGEX_LINKSPANEL}
{ if this option is on, links panel is available (on the left side).
Also USE_MENU_CURCTL symbol must be added! }
//{$DEFINE DIRDLGEX_STDFONT}
{ add this option to use standard font size in a links panel
(otherwise Arial, 14 is used) }
{$DEFINE DIRDLGEX_BIGGERPANEL}
{ a bit bigger links panel with bigger buttons on it }
{ ----------------------------------------------------------------------
TOpenDirDialogEx
----------------------------------------------------------------------- }
{ TOpenDirDialogEx - àëüòåðíàòèâà ñòàíäàðòíîìó äèàëîãó âûáîðà ïàïêè.
(c) by Vladimir Kladov, 2005, 14 Dec.
Íåîáõîäèìîñòü: ñòàíäàðòíûé äèàëîã ðàáîòàåò ìåäëåííî, äëÿ êàæäîé îïåðàöèè
âûáîðà ïàïêè ïîëüçîâàòåëåì îòêðûâàåòñÿ çàíîâî, ñòðîÿ çàíîâî
äåðåâî ïàïîê, ïðè ýòîì ãëþ÷èò: ðåãóëÿðíî âîçíèêàåò ñèòóàöèÿ,
êîãäà ðîäèòåëüñêèé óçåë äëÿ ïåðâîíà÷àëüíîé ïàïêè ìîæåò ïîêàçàòü
òîëüêî òåêóùóþ âëîæåííóþ ïàïêó, õîòÿ òàì åñòü åùå ïàïêè.
Íå ãîâîðÿ óæå î ìåëêèõ ãëóïîñòÿõ, âðîäå òîé, ÷òî òåêóùèé óçåë
â ìîìåíò îòêðûòèÿ ìîæåò ïðîñòî îêàçàòüñÿ âíå ïîëÿ çðåíèÿ, èëè
òîé, ÷òî â ñòàíäàðòíîì äèàëîãå àêòèâíûì îêàçûâàåòñÿ íå äåðåâî
âûáîðà ïàïîê, à êíîïêà ÎÊ (èëè êòî-òî äóìàåò, ÷òî ïîëüçîâàòåëü
îòêðûë äèàëîã äëÿ òîãî, ÷òîáû íàæàòü ÎÊ, íå âûáèðàÿ ïàïêó?).
Îñîáåííîñòè TOpenDirDialogEx: ðàáîòàåò áûñòðî. Ïðè ïîâòîðíîì âûïîëíåíèè
Execute ïåðåñêàíèðóåòñÿ òîëüêî òà ÷àñòü äåðåâà, êîòîðàÿ âûøå òåêóùåé ïàïêè
(ò.å. ïîâòîðíîå îòêðûòèå âûïîëíÿåòñÿ ïðàêòè÷åñêè ìãíîâåííî). Ïåðâîíà÷àëüíî
îòêðûâàåòñÿ òîëüêî ÷àñòü äåðåâà ïàïîê, êîòîðàÿ íåîáõîäèìà, ÷òîáû ïîëíîñòü
îòêðûòü âñå ïàïêè íà ïóòè îò êîðíÿ äèñêà äî òåêóùåé ïàïêè. Ïðî÷èå ïàïêè
îòêðûâàþòñÿ è ïåðåñêàíèðóþòñÿ ïðè èõ îòêðûòèè (ðàñïàõèâàíèè). Ïîâòîðíîå
ðàñïàõèâàíèå ïàïêè ïåðåñêàíèðóåò åå (êàê àëüòåðíàòèâà àâòîìàòè÷åñêîìó
îáíîâëåíèþ, êîòîðîå íå ðåàëèçîâàíî - õîòÿ è îñîáîé íåîáõîäèìîñòè â àâòîìàòèêå
íà ïðàêòèêå íåò, è êðîìå äîïîëíèòåëüíîé íàãðóçêè íà ñèñòåìó òîëêó îò òàêîãî
àâòîìàòà òîæå íå âèäíî).
Îñîáåííî áûñòðî äèàëîã îòêðûòèÿ ðàáîòàåò â íîâûõ âåðñèÿõ OS Windows,
ò.ê. èñïîëüçóåò â ýòîì ñëó÷àå API-ôóíêöèè âåðñèè Unicode.
Äîïîëíèòåëüíûå âêóñíîñòè:
Åñòü âîçìîæíîñòü ïîìåíÿòü íàäïèñè íà êíîïêàõ, çàãîëîâîê äèàëîãà.
Åñòü âîçìîæíîñòü îòôèëüòðîâàòü äèðåêòîðèè ïî àòðèáóòàì (FilterAttrs), íàïðèìåð,
åñëè ïðèñâîèòü FILE_ATTRIBUTE_HIDDEN, òî ñêðûòûå ïàïêè â äåðåâå ïîêàçàíû íå áóäóò.
}
const
WM_USER_RESCANTREE = WM_USER;
type
TFindFirstFileEx = function(lpFileName: PKOLChar; fInfoLevelId: TFindexInfoLevels;
lpFindFileData: Pointer; fSearchOp: TFindexSearchOps; lpSearchFilter: Pointer;
dwAdditionalFlags: DWORD): THandle; stdcall;
TFindFirstFileExW = function(lpFileName: PWideChar; fInfoLevelId: TFindexInfoLevels;
lpFindFileData: Pointer; fSearchOp: TFindexSearchOps; lpSearchFilter: Pointer;
dwAdditionalFlags: DWORD): THandle; stdcall;
TFindNextFileW = function( hFindFile: THandle; lpFindFileData: Pointer ):
BOOL; stdcall;
POpenDirDialogEx = ^TOpenDirDialogEx;
TOpenDirDialogEx = object( TObj )
protected
FFastScan: Boolean;
DlgClient: PControl;
DirTree: PControl;
BtnPanel: PControl;
RescanningNode, RescanningTree: Boolean;
FPath, FRecycledName: KOLString;
FRemoteIconSysIdx: Integer;
FFindFirstFileEx: TFindFirstFileEx;
FFindFirstFileExW: TFindFirstFileExW;
FFindNextFileW: TFindNextFileW;
k32: THandle;
DialogForm, MsgPanel: PControl;
function GetFindFirstFileEx: TFindFirstFileEx;
function GetFindFirstFileExW: TFindFirstFileExW;
procedure SetPath(const Value: KOLString);
function GetDialogForm: PControl;
procedure DoOK( Sender: PObj );
procedure DoCancel( Sender: PObj );
procedure DoNotClose( Sender: PObj; var Accept: Boolean );
procedure DoShow( Sender: PObj );
function DoMsg( var Msg: TMsg; var Rslt: Integer ): Boolean;
function DoExpanding( Sender: PControl; Item: THandle; Expand: Boolean )
: Boolean;
function DoFilterAttrs( Attrs: DWORD; const APath: KOLString ): Boolean;
procedure Rescantree;
procedure RescanNode( node: Integer );
procedure RescanDisks;
function RemoteIconSysIdx: Integer;
procedure CheckNodeHasChildren( node: Integer );
procedure CreateDialogForm;
property _FindFirstFileEx: TFindFirstFileEx read GetFindFirstFileEx;
function _FindFirstFileExW: Boolean;
procedure SelChanged( Sender: PObj );
procedure DeleteNode( node: Integer );
procedure DestroyingForm( Sender: PObj );
public
OKCaption, CancelCaption: KOLString;
FilterAttrs: DWORD;
FilterRecycled: Boolean;
Title: String;
property Form: PControl read GetDialogForm;
{* DialogForm object. Though it is possible to do anything since it is
in public section, do this only if you understand possible consequences.
E.g., use it to change DialogForm bounding rectangle on screen or to
add your own controls, event handlers and so on. }
destructor Destroy; virtual;
function Execute: Boolean;
property InitialPath: KOLString read FPath write SetPath;
property Path: KOLString read FPath write SetPath;
property FastScan: Boolean read FFastScan write FFastScan;
procedure DoubleClick( Sender: PControl; var M: TMouseEventData );
{$IFDEF DIRDLGEX_LINKSPANEL}
protected
LinksPanel, LinksBox, LinksTape: PControl;
LinksUp, LinksDn, LinksAdd: PControl;
LinksList: PStrListEx;
LinksImgList: PImageList;
LinksRollTimer: PTimer;
LinksPopupMenu: PMenu;
procedure CreateLinksPanel;
function GetLinksPanelOn: Boolean;
procedure SetLinksPanelOn( const Value: Boolean );
function GetLinksCount: Integer;
function GetLinks(idx: Integer): KOLString;
procedure SetLinks(idx: Integer; const Value: KOLString);
procedure SetupLinksTapeHeight;
procedure SetUpTaborders;
procedure LinksUpClick( Sender: PControl; var Mouse: TMouseEventData );
procedure LinksDnClick( Sender: PControl; var Mouse: TMouseEventData );
procedure LinksUpDnStop( Sender: PControl; var Mouse: TMouseEventData );
procedure LinksAddClick( Sender: PObj );
procedure LinkClick( Sender: PObj );
procedure LinksRollTimerTimer( Sender: PObj );
procedure LinksBtnDnEvt( Sender: PControl; var Mouse: TMouseEventData );
//procedure LinksPanelShowEvent( Sender: PObj );
procedure RemoveLinkClick( Sender: PMenu; Item: Integer );
public
property LinksPanelOn: Boolean read GetLinksPanelOn write SetLinksPanelOn;
property LinksCount: Integer read GetLinksCount;
property Links[ idx: Integer ]: KOLString read GetLinks write SetLinks;
procedure AddLinks( SL: PStrList );
function CollectLinks: PStrList;
function LinkPresent( const s: KOLString ): Boolean;
procedure RemoveLink( const s: KOLString );
procedure ClearLinks;
{$ENDIF DIRDLGEX_LINKSPANEL}
function GetBetterPixelFormat: TPixelFormat;
end;
function NewOpenDirDialogEx: POpenDirDialogEx;
{$IFDEF KOL_MCK}
{$IFNDEF DIRDLGEX_OPTIONAL} { add this symbol if you want use
both types of the open directory dialog in your application
(and in such case, call a constructor of the TOpenDirDialogEx
object manually). }
type TKOLOpenDirDialog = POpenDirDialogEx;
{$ENDIF}
{$ENDIF}
implementation
function NewOpenDirDialogEx: POpenDirDialogEx;
begin
new( Result, Create );
{$IFNDEF NO_DEFAULT_FASTSCAN}
Result.FastScan := TRUE;
{$ENDIF}
end;
procedure NewPanelWithSingleButtonToolbar( AParent: PControl; W, H: Integer;
A: TControlAlign; Bmp: PBitmap; const C, T: KOLString; var Pn, Bar: PControl;
const ClickEvent: TOnEvent; DownEvent, ReleaseEvent, BarMouseDnEvent: TOnMouse;
P: PMenu );
var i: Integer;
Buffer: PKOLChar;
Wbmp, Hbmp: Integer;
begin
Pn := NewPanel( AParent, esNone ).SetSize( 0, H ).SetAlign( A );
Pn.Border := 0;
Wbmp := Bmp.Width;
Hbmp := Bmp.Height;
Bar := NewToolbar( Pn, caClient, [
tboNoDivider, tboTextBottom {, tboFlat} ],
Bmp.ReleaseHandle,
[ PKOLChar( {$IFDEF TOOLBAR_DOT_NOAUTOSIZE_BUTTON} '.' + {$ENDIF} C ) ], [ 0 ] );
Buffer := AllocMem( Length( T ) + 1 );
if T <> '' then
{$IFDEF UNICODE_CTRLS} WStrCopy
{$ELSE} StrCopy
{$ENDIF} ( Buffer, PKOLChar( T ) );
{$IFDEF USE_GRUSH}
i := 0;
{$IFDEF TOGRUSH_OPTIONAL}
if NoGrush then
begin
i := Bar.TBIndex2Item(0);
Bar.Perform( TB_SETBITMAPSIZE, 0, MakeLong( Wbmp, Hbmp ) );
end;
if not NoGrush then
{$ENDIF}
begin
PGRushControl( Bar.Children[0] ).All_GlyphVAlign := vaTop;
if C = '' then
begin
PGRushControl( Bar.Children[0] ).All_GlyphVAlign := vaCenter;
PGRushControl( Bar.Children[0] ).All_ContentOffsets := MakeRect( -4, -4, 4, 4 );
end;
PGRushControl( Bar.Children[0] ).All_GlyphHAlign := haCenter;
PGRushControl( Bar.Children[0] ).All_GlyphWidth := Bmp.Width;
PGRushControl( Bar.Children[0] ).All_Spacing := 2;
PGRushControl( Bar.Children[0] ).Width := W;
if not Assigned( DownEvent ) then
PGRushControl( Bar.Children[0] ).OnClick := ClickEvent
else
begin
PGRushControl( Bar.Children[0] ).OnMouseDown := DownEvent;
PGRushControl( Bar.Children[0] ).OnMouseUp := ReleaseEvent;
end;
PGRushControl( Bar.Children[0] ).CustomData := Buffer;
if P <> nil then
Pn.SetAutoPopupMenu( P );
end
{$IFDEF TOGRUSH_OPTIONAL}
else
begin
i := Bar.TBIndex2Item(0);
Bar.TBButtonWidth[ i ] := W;
Bar.Perform( TB_SETBITMAPSIZE, 0, MakeLong( Wbmp, Hbmp ) );
if not Assigned( ReleaseEvent ) then
Bar.OnClick := ClickEvent
else
begin
Bar.OnMouseDown := DownEvent;
Bar.OnMouseUp := ReleaseEvent;
end;
Bar.CustomData := Buffer;
if P <> nil then
Bar.OnMouseDown := BarMouseDnEvent;
end
{$ENDIF TOGRUSH_OPTIONAL}
;
{$ELSE}
i := Bar.TBIndex2Item(0);
Bar.TBButtonWidth[ i ] := W;
Bar.Perform( TB_SETBITMAPSIZE, 0, MakeLong( Wbmp, Hbmp ) );
if not Assigned( ReleaseEvent ) then
Bar.OnClick := ClickEvent
else
begin
Bar.OnMouseDown := DownEvent;
Bar.OnMouseUp := ReleaseEvent;
end;
Bar.CustomData := Buffer;
{$ENDIF USE_GRUSH}
ToolbarSetTooltips( Bar, i, [ PKOLChar( T ) ] );
Bmp.Free;
end;
{ TOpenDirDialogEx }
{$IFDEF DIRDLGEX_LINKSPANEL}
procedure TOpenDirDialogEx.AddLinks(SL: PStrList);
var i: Integer;
begin
for i := 0 to SL.Count-1 do
if not LinkPresent( SL.Items[ i ] ) then
Links[ LinksCount ] := SL.Items[ i ];
end;
{$ENDIF DIRDLGEX_LINKSPANEL}
procedure TOpenDirDialogEx.CheckNodeHasChildren(node: Integer);
var HasSubDirs: Boolean;
txt: KOLString;
F: THandle;
Find32: TWin32FindData;
{$IFnDEF DONTTRY_FINDFILEEXW}
Find32W: TWin32FindDataW;
{$ENDIF}
ii, n: Integer;
begin
HasSubDirs := FALSE;
txt := DirTree.TVItemText[ node ];
if (Length( txt ) = 2) then
if (txt[ 2 ] = ':') then
begin
ii := GetDriveType( PKOLChar( txt + '\' ) );
if IntIn( ii, [ DRIVE_REMOVABLE, DRIVE_REMOTE, DRIVE_CDROM ] ) then
HasSubDirs := TRUE;
end;
if not HasSubDirs then
begin
{$IFnDEF DONTTRY_FINDFILEEXW}
if (WinVer >= wvNT) and _FindFirstFileExW then
begin
F := FFindFirstFileExW( PWideChar(
WideString( DirTree.TVItemPath( node, '\' ) + '\*.*' ) ),
FindExInfoStandard, @ Find32W, FindExSearchLimitToDirectories, nil, 0 );
if F <> INVALID_HANDLE_VALUE then
begin
while TRUE do
begin
if Find32W.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then
if (Find32W.cFileName <> WideString( '.' )) and (Find32W.cFileName <> WideString('..')) then
if DoFilterAttrs( Find32W.dwFileAttributes, Find32W.cAlternateFileName ) then
begin
HasSubDirs := TRUE;
break;
end;
if not FindNextFileW( F, Find32W ) then break;
end;
if not FindClose( F ) then
{begin
asm
nop
end;
end};
end;
end
else
{$ENDIF}
begin
F := FindFirstFile( PKOLChar( DirTree.TVItemPath( node, '\' ) + '\*.*' ), Find32 );
if F <> INVALID_HANDLE_VALUE then
begin
while TRUE do
begin
if Find32.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then
if (Find32.cFileName <> String( '.' )) and (Find32.cFileName <> '..') then
begin
HasSubDirs := TRUE;
break;
end;
if not FindNextFile( F, Find32 ) then break;
end;
FindClose( F );
end;
end;
end;
if not HasSubDirs then
begin
DirTree.TVExpand( node, TVE_COLLAPSE );
n := DirTree.TVItemChild[ node ];
while n <> 0 do
begin
ii := n;
n := DirTree.TVItemNext[ n ];
//DirTree.TVDelete( ii );
DeleteNode( ii );
end;
end;
if DirTree.TVItemParent[ node ] = 0 then HasSubDirs := TRUE;
DirTree.TVItemHasChildren[ node ] := HasSubDirs;
end;
{$IFDEF DIRDLGEX_LINKSPANEL}
procedure TOpenDirDialogEx.ClearLinks;
var i: Integer;
begin
if LinksList = nil then Exit;
LinksList.Clear;
for i := LinksTape.ChildCount-1 downto 0 do
LinksTape.Children[ i ].Free;
LinksTape.Height := 8;
LinksTape.Top := 0;
end;
function TOpenDirDialogEx.CollectLinks: PStrList;
var i: Integer;
begin
Result := NewStrList;
for i := 0 to LinksCount-1 do
Result.Add( Links[ i ] );
end;
{$ENDIF DIRDLGEX_LINKSPANEL}
procedure TOpenDirDialogEx.CreateDialogForm;
var Sysimages: PImageList;
BtOk, BtCancel: PControl;
DTSubPanel: PControl;
s: String;
begin
if not Assigned( DialogForm ) then
begin
OleInit;
DialogForm := NewForm( Applet, '' ).SetSize( 324, 330 ).CenterOnParent;
DialogForm.OnDestroy := DestroyingForm;
DialogForm.Border := 6;
DialogForm.OnClose := DoNotClose;
DialogForm.Tabulate;
DialogForm.MinWidth := 324;
DialogForm.MinHeight := 330;
DialogForm.ExStyle := DialogForm.ExStyle or
WS_EX_DLGMODALFRAME or WS_EX_WINDOWEDGE;
DialogForm.Style := DialogForm.Style and
not (WS_MINIMIZEBOX or WS_MAXIMIZEBOX);
Sysimages := NewImageList( DialogForm );
Sysimages.LoadSystemIcons( TRUE );
//DlgClient := NewPanel( DialogForm, esNone ).SetAlign(caClient);
{$IFDEF USE_GRUSH}
{$IFDEF TOGRUSH_OPTIONAL}
if not NoGrush then
{$ENDIF TOGRUSH_OPTIONAL}
begin
DialogForm.Color := clGRushLight;
DlgClient := NewPanel( DialogForm, esNone ).SetAlign(caClient);
//DlgClient.Border := 2;
end
{$IFDEF TOGRUSH_OPTIONAL}
else DlgClient := DialogForm;
{$ENDIF TOGRUSH_OPTIONAL}
;
{$ELSE}
DlgClient := DialogForm;
{$ENDIF}
{$IFDEF USE_GRUSH}
{$IFDEF TOGRUSH_OPTIONAL}
if not NoGrush then
{$ENDIF TOGRUSH_OPTIONAL}
begin
DTSubPanel := KOL.NewPanel( DlgClient, esNone );
DTSubPanel.Color := clWindow;
DTSubPanel.Border := 2;
BtnPanel := NewPanel( DlgClient, esTransparent )
.SetSize( 0, 26 ).SetAlign(caBottom );
//BtnPanel.Color := clGRushMedium;
BtnPanel.Border := 2;
DTSubPanel.SetAlign( caClient );
DirTree := NewTreeView( DTSubPanel, [ tvoLinesRoot ], Sysimages, nil );
DirTree.Color := clWindow;
DirTree.OnTVExpanding := DoExpanding;
DirTree.SetAlign( caClient );
MsgPanel := DTSubPanel;
end
{$IFDEF TOGRUSH_OPTIONAL}
else
begin
DTSubPanel := DlgClient;
DirTree := NewTreeView( DTSubPanel, [ tvoLinesRoot ], Sysimages, nil );
DirTree.Color := clWindow;
DirTree.OnTVExpanding := DoExpanding;
BtnPanel := NewPanel( DlgClient, esTransparent )
.SetSize( 0, 26 ).SetAlign(caBottom );
BtnPanel.Border := 2;
DirTree.SetAlign( caClient );
MsgPanel := DlgClient;
end
{$ENDIF TOGRUSH_OPTIONAL}
;
{$ELSE}
DTSubPanel := DlgClient;
DirTree := NewTreeView( DTSubPanel, [ tvoLinesRoot ], Sysimages, nil );
DirTree.Color := clWindow;
DirTree.OnTVExpanding := DoExpanding;
BtnPanel := NewPanel( DlgClient, esTransparent )
.SetSize( 0, 26 ).SetAlign(caBottom );
BtnPanel.Border := 2;
DirTree.SetAlign( caClient );
MsgPanel := DlgClient;
{$ENDIF}
{$IFNDEF DIRDLGEX_NO_DBLCLK_ON_NODE_OK}
DirTree.OnMouseDblClk := DoubleClick;
{$ENDIF}
MsgPanel.OnMessage := DoMsg;
DirTree.OnSelChange := SelChanged;
DlgClient := DTSubPanel; // !!!
s := CancelCaption; if s = '' then s := 'Cancel';
BtCancel := NewButton( BtnPanel, s );
BtCancel.MinWidth := 75; BtCancel.OnClick := DoCancel;
BtCancel.AutoSize( TRUE ).SetAlign( caRight );
s := OKCaption; if s = '' then s := 'OK';
BtOK := NewButton( BtnPanel, s );
BtOK.MinWidth := 75; BtOK.OnClick := DoOK;
BtOK.AutoSize( TRUE ).SetAlign( caRight );
BtOK.TabOrder := 0;
BtOK.DefaultBtn := TRUE;
BtCancel.CancelBtn := TRUE;
DialogForm.OnShow := DoShow;
{$IFDEF USE_GRUSH}
{$IFDEF TOGRUSH_OPTIONAL}
if not NoGrush then
{$ENDIF TOGRUSH_OPTIONAL}
begin
BtOK.Transparent := TRUE;
BtCancel.Transparent := TRUE;
end;
{$ENDIF USE_GRUSH}
end;
end;
{$IFDEF DIRDLGEX_LINKSPANEL}
procedure TOpenDirDialogEx.CreateLinksPanel;
var BUp, BDn, BLt: PBitmap;
{$IFDEF USE_GRUSH}
cFrom: TColor;
{$ENDIF USE_GRUSH}
function NewArrowBitmap( const Pts: array of Integer ): PBitmap;
var pf: TPixelFormat;
begin
pf := GetBetterPixelFormat;
Result := NewDibBitmap( 16, 8, pf );
Result.Canvas.Brush.Color := clBtnFace;
Result.Canvas.FillRect( Result.BoundsRect );
Result.Canvas.Brush.Color := clBlack;
Result.Canvas.Polygon( [ MakePoint( Pts[ 0 ], Pts[ 1 ] ),
MakePoint( Pts[ 2 ], Pts[ 3 ] ),
MakePoint( Pts[ 4 ], Pts[ 5 ] ),
MakePoint( Pts[ 6 ], Pts[ 7 ] ) ] );
//Result.SaveToFile( GetStartDir + 'arrow_bitmap' + Int2Hex( Integer( Result ), 8 ) + '.bmp' );
end;
var PnUp, LUp, PnDn, LDn, PnLt, LLt: PControl;
d: Integer;
begin
if LinksPanel <> nil then Exit;
GetDialogForm;
BUp := NewArrowBitmap( [ 2, 6, 7, 1, 8, 1, 13, 6 ] );
BDn := NewArrowBitmap( [ 2, 1, 7, 6, 8, 6, 13, 1 ] );
BLt := NewArrowBitmap( [ 11, 0, 4, 3, 4, 4, 11, 7 ] );
LinksPanel := NewPanel( DlgClient, esLowered )
.SetSize( {$IFDEF DIRDLGEX_BIGGERPANEL} 14 + {$ENDIF} 64, 0 )
.SetAlign( caLeft );
//LinksPanel.OnShow := LinksPanelShowEvent;
LinksPanel.Border := 2;
{$IFNDEF DIRDLGEX_STDFONT}
LinksPanel.Font.FontName := 'Arial';
LinksPanel.Font.FontHeight := 14;
{$ENDIF DIRDLGEX_STDFONT}
d := 0;
{$IFDEF USE_GRUSH}
{$IFDEF TOGRUSH_OPTIONAL}
if not NoGrush then
{$ENDIF TOGRUSH_OPTIONAL}
d := 2;
{$ENDIF USE_GRUSH}
NewPanelWithSingleButtonToolbar( LinksPanel, LinksPanel.Width-6+d, 15, caTop,
BUp, '', '', PnUp, LUp, nil, LinksUpClick, LinksUpDnStop, nil, nil );
NewPanelWithSingleButtonToolbar( LinksPanel, LinksPanel.Width-6+d, 15, caBottom,
BDn, '', '', PnDn, LDn, nil, LinksDnClick, LinksUpDnStop, nil, nil );
NewPanelWithSingleButtonToolbar( BtnPanel, 20, 16, caNone,
BLt, '', '', PnLt, LLt, LinksAddClick, nil, nil, nil, nil ); PnLt.Width := 20;
PnLt.SetPosition( 68, 0 );
PnLt.Transparent := TRUE;
LLt.Transparent := TRUE;
LinksBox := NewPaintBox( LinksPanel ).SetAlign(caClient);
LinksBox.Border := 0;
LinksTape := NewPaintBox( LinksBox ).SetSize( LinksBox.Width, 0 );
//LinksTape.DoubleBuffered := TRUE;
{$IFDEF USE_GRUSH}
{$IFDEF TOGRUSH_OPTIONAL}
if not NoGrush then
{$ENDIF TOGRUSH_OPTIONAL}
begin
LinksTape.Border := 2;
LinksTape.MarginLeft := -2;
LinksTape.MarginRight := -2;
LinksTape.MarginTop := 2;
LinksTape.MarginBottom := 2;
//LinksPanel.Transparent := TRUE;
PGRushControl( LinksPanel ).All_GradientStyle := gsHorizontal;
cFrom := PGRushControl( LinksPanel ).Def_ColorFrom;
PGRushControl( LinksPanel ).All_ColorTo := {
PGRushControl( LinksPanel ).Def_ColorFrom;
PGRushControl( LinksPanel ).All_ColorFrom :=} cFrom;
LinksBox.Color := cFrom;
//LinksAdd.Left := LinksAdd.Left + 6;
end
{$IFDEF TOGRUSH_OPTIONAL}
else
begin
//LinksTape.Border := 0;
end
{$ENDIF TOGRUSH_OPTIONAL}
;
{$ELSE not USE_GRUSH}
LinksTape.Border := 0;
//LinksTape.MarginLeft := -2;
LinksTape.MarginRight := -4;
{$ENDIF USE_GRUSH}
LinksPanel.Visible := FALSE;
LinksRollTimer := NewTimer( 50 );
//LinksRollTimer.Enabled := FALSE;
LinksRollTimer.OnTimer := LinksRollTimerTimer;
LinksPanel.Add2AutoFree( LinksRollTimer );
end;
{$ENDIF DIRDLGEX_LINKSPANEL}
procedure TOpenDirDialogEx.DeleteNode(node: Integer);
function NodeIsParentOf( node, parent: Integer ): Boolean;
begin
Result := TRUE;
while node <> 0 do
begin
if node = parent then Exit;
node := DirTree.TVItemParent[ node ];
end;
Result := FALSE;
end;
var sel, n: Integer;
begin
sel := DirTree.TVSelected;
if (sel <> 0) and NodeIsParentOf( sel, node ) then
begin
n := DirTree.TVItemPrevious[ node ];
if n = 0 then
n := DirTree.TVItemNext[ node ];
DirTree.TVSelected := n;
end;
DirTree.TVDelete( node );
end;
destructor TOpenDirDialogEx.Destroy;
begin
Free_And_Nil( DialogForm );
FPath := '';
FRecycledName := '';
OKCaption := '';
CancelCaption := '';
Title := '';
{$IFDEF DIRDLGEX_LINKSPANEL}
LinksList.Free;
{$ENDIF DIRDLGEX_LINKSPANEL}
inherited;
OleUnInit;
end;
procedure TOpenDirDialogEx.DestroyingForm(Sender: PObj);
begin
DialogForm := nil;
end;
procedure TOpenDirDialogEx.DoCancel(Sender: PObj);
begin
DialogForm.ModalResult := -1;
end;
function TOpenDirDialogEx.DoExpanding(Sender: PControl; Item: THandle;
Expand: Boolean): Boolean;
begin
Result := FALSE;
if RescanningNode or RescanningTree then Exit;
if Expand then
RescanNode( Item );
end;
function TOpenDirDialogEx.DoFilterAttrs(Attrs: DWORD; const APath: KOLString): Boolean;
begin
Result := (Attrs and FilterAttrs = 0);
if not Result then Exit;
if FilterRecycled then
begin
if (Attrs and (FILE_ATTRIBUTE_SYSTEM or FILE_ATTRIBUTE_HIDDEN) =
(FILE_ATTRIBUTE_SYSTEM or FILE_ATTRIBUTE_HIDDEN))
then
//if StrEq( APath, 'RECYCLED' ) then
Result := FALSE;
end;
end;
function TOpenDirDialogEx.DoMsg(var Msg: TMsg; var Rslt: Integer): Boolean;
var NMHdr: PNMHdr;
NMCustomDraw: PNMCustomDraw;
i: Integer;
begin
Result := FALSE;
if DialogForm = nil then Exit;
if Msg.message = WM_USER_RESCANTREE then
begin
Rescantree;
DirTree.Focused := TRUE;
Result := TRUE;
end
else
if Msg.message = WM_NOTIFY then
begin // îòëàâëèâàåòñÿ ìîìåíò îòðèñîâêè êàæäîãî óçëà, ÷òîáû ïðîâåðèòü íàëè÷èå
// â íåì äî÷åðíèõ ïàïîê, è "ïîêàçàòü" êíîïêó [+], åñëè åñòü
NMHdr := Pointer( Msg.lParam );
if DirTree = nil then Exit;
if NMHdr.hwndFrom = DirTree.Handle then
CASE NMHdr.code OF
NM_CUSTOMDRAW:
begin
NMCustomDraw := Pointer( NMHdr );
if NMCustomDraw.dwDrawStage = CDDS_ITEMPOSTPAINT then
begin
i := NMCustomDraw.dwItemSpec;
if DirTree.TVItemData[ i ] = nil then // óçåë åùå íå ïðîâåðÿëñÿ
begin
CheckNodeHasChildren( i ); // ïðîâåðèòü óçåë
DirTree.TVItemData[ i ] := Pointer( 1 ); // ôëàã = "ïðîâåðåí"
end;
Rslt := CDRF_DODEFAULT; // ïóñòü ðèñóåò ñåáÿ ñàì êàê îáû÷íî
end
else
if NMCustomDraw.dwDrawStage = CDDS_PREPAINT then
Rslt := CDRF_NOTIFYITEMDRAW // ñîîáùèòü äëÿ êàæäîãî óçëà íà ñòàäèè CDDS_ITEMPREPAINT
else
Rslt := CDRF_NOTIFYPOSTPAINT; // ïðè CDDS_ITEMPREPAINT: ñîîáùèòü î CDDS_ITEMPOSTPAINT
Result := TRUE;
end;
END;
end;
end;
procedure TOpenDirDialogEx.DoNotClose(Sender: PObj;
var Accept: Boolean);
begin
Accept := FALSE;
DialogForm.Hide;
end;
procedure TOpenDirDialogEx.DoOK(Sender: PObj);
begin
DialogForm.ModalResult := 1;
end;
procedure TOpenDirDialogEx.DoShow(Sender: PObj);
begin
MsgPanel.PostMsg( WM_USER_RESCANTREE, 0, 0 );
{$IFDEF DIRDLGEX_LINKSPANEL}
if LinksPanelOn and Assigned( LinksTape ) then
begin
Global_Align( LinksTape );
SetupLinksTapeHeight;
end;
{$ENDIF DIRDLGEX_LINKSPANEL}
end;
type
PControl_ = ^TControl_;
TControl_ = object( TControl )
end;
procedure TOpenDirDialogEx.DoubleClick(Sender: PControl;
var M: TMouseEventData);
var N: DWORD;
Where: DWORD;
begin
N := DirTree.TVItemAtPos( M.X, M.Y, Where );
if (N = DirTree.TVSelected) and
not DirTree.TVItemHasChildren[ N ] then
Form.ModalResult := 1;
end;
function TOpenDirDialogEx.Execute: Boolean;
var s: String;
ParentForm: PControl_;
begin
CreateDialogForm;
DlgClient.ActiveControl := DirTree;
s := Title; if s = '' then s := 'Select directory';
DialogForm.Caption := s;
ParentForm := PControl_( Applet.ActiveControl );
if ParentForm <> nil then
begin
if {$IFDEF USE_FLAGS} not(G3_IsForm in ParentForm.fFlagsG3)
{$ELSE} not ParentForm.fIsForm {$ENDIF} then
ParentForm := PControl_( Applet );
end;
if ParentForm <> nil then
DialogForm.StayOnTop := ParentForm.StayOnTop;
DialogForm.ShowModal;
DialogForm.Hide;
if ParentForm <> nil then
SetForegroundWindow( ParentForm.Handle );
Result := DialogForm.ModalResult >= 0;
if Result then
begin
Path := IncludeTrailingPathDelimiter(
DirTree.TVItemPath( DirTree.TVSelected, '\' ) );
end;
end;
function TOpenDirDialogEx.GetBetterPixelFormat: TPixelFormat;
var DC: HDC;
i: Integer;
PF: TPixelFormat;
begin
DC := GetDC( 0 );
i := GetDeviceCaps( DC, BITSPIXEL );
ReleaseDC( 0, DC );
CASE i OF
16: PF := pf16bit;
else PF := pf32bit;
END;
Result := PF;
end;
function TOpenDirDialogEx.GetDialogForm: PControl;
begin
CreateDialogForm;
Result := DialogForm;
end;
function TOpenDirDialogEx.GetFindFirstFileEx: TFindFirstFileEx;
begin
if not Assigned( FFindFirstFileEx ) then
begin
k32 := GetModuleHandle( 'kernel32.dll' );
FFindFirstFileEx := GetProcAddress( k32, 'FindFirstFileExA' );
end;
Result := FFindFirstFileEx;
end;
function TOpenDirDialogEx.GetFindFirstFileExW: TFindFirstFileExW;
begin
if not Assigned( FFindFirstFileExW ) then
begin
k32 := GetModuleHandle( 'kernel32.dll' );
FFindFirstFileExW := GetProcAddress( k32, 'FindFirstFileExW' );
FFindNextFileW := GetProcAddress( k32, 'FindNextFileW' );
end;
Result := FFindFirstFileExW;
end;
{$IFDEF DIRDLGEX_LINKSPANEL}
function TOpenDirDialogEx.GetLinks(idx: Integer): KOLString;
begin
Result := '';
if (LinksList <> nil) and (LinksList.Count > idx) then
Result := LinksList.Items[ idx ];
end;
function TOpenDirDialogEx.GetLinksCount: Integer;
begin
Result := 0;
if LinksList <> nil then Result := LinksList.Count;
end;
function TOpenDirDialogEx.GetLinksPanelOn: Boolean;
begin
Result := (LinksPanel <> nil) and (LinksPanel.Visible);
end;
procedure TOpenDirDialogEx.LinkClick(Sender: PObj);
var s, CurPath: String;
begin
s := IncludeTrailingPathDelimiter(
PChar( PControl( Sender ).CustomData ) );
if PControl( Sender ).RightClick then
begin
RemoveLink( s );
end else
begin
if DirectoryExists( s ) then
begin
CurPath := IncludeTrailingPathDelimiter(
DirTree.TVItemPath( DirTree.TVSelected, '\' ) );
if StrEq( CurPath, s ) then
Form.ModalResult := 1
else Path := s;
end;
end;
end;
function TOpenDirDialogEx.LinkPresent(const s: KOLString): Boolean;
begin
Result := (LinksList <> nil) and
(LinksList.IndexOf_NoCase(
IncludeTrailingPathDelimiter( s ) ) >= 0);
end;
procedure TOpenDirDialogEx.LinksAddClick(Sender: PObj);
var SL: PStrList;
CurPath: String;
begin
CurPath := IncludeTrailingPathDelimiter(
DirTree.TVItemPath( DirTree.TVSelected, '\' ) );
SL := NewStrList;
if DirectoryExists( CurPath ) then
begin
SL.Add( CurPath );
AddLinks( SL );
end;
SL.Free;
end;
procedure TOpenDirDialogEx.LinksBtnDnEvt(Sender: PControl;
var Mouse: TMouseEventData);
var P: TPoint;
begin
if Mouse.Button = mbRight then
begin
P.X := Mouse.X;
P.Y := Mouse.Y;
P := Sender.Client2Screen( P );
LinksPopupMenu.CurCtl := Sender.Parent;
LinksPopupMenu.Popup( P.X, P.Y );
Mouse.StopHandling := TRUE;
end;
end;
procedure TOpenDirDialogEx.LinksDnClick(Sender: PControl; var Mouse: TMouseEventData);
begin
LinksRollTimer.Tag := 1;
LinksRollTimer.Enabled := TRUE;
end;
{procedure TOpenDirDialogEx.LinksPanelShowEvent(Sender: PObj);
begin
end;}
procedure TOpenDirDialogEx.LinksRollTimerTimer(Sender: PObj);
var NewTop, d: Integer;
begin
d := Integer( LinksRollTimer.Tag );
LinksRollTimer.Tag := Integer( LinksRollTimer.Tag ) + Sgn( d );
NewTop := LinksTape.Top - (Sgn( d ) + d div 4) * 2;
if (d > 0) and
(NewTop + LinksTape.Height < LinksBox.Height) and
(LinksTape.Top <= 0) then
begin
NewTop := LinksBox.Height - LinksTape.Height;
if NewTop > 0 then
NewTop := 0;
end;
if (d < 0) and (NewTop > 0) then NewTop := 0;
if (NewTop = LinksTape.Top) or not Form.Visible then
LinksRollTimer.Enabled := FALSE;
LinksTape.Top := NewTop;
LinksTape.Update;
end;
procedure TOpenDirDialogEx.LinksUpClick(Sender: PControl; var Mouse: TMouseEventData);
begin
LinksRollTimer.Tag := DWORD( -1 );
LinksRollTimer.Enabled := TRUE;
end;
procedure TOpenDirDialogEx.LinksUpDnStop(Sender: PControl; var Mouse: TMouseEventData);
begin
LinksRollTimer.Enabled := FALSE;
end;
{$ENDIF DIRDLGEX_LINKSPANEL}
function TOpenDirDialogEx.RemoteIconSysIdx: Integer;
begin
if FRemoteIconSysIdx = 0 then
begin
if DirectoryExists( '\\localhost\' ) then
FRemoteIconSysIdx := DirIconSysIdxOffline( '\\localhost\' )
else
FRemoteIconSysIdx := DirIconSysIdxOffline( 'C:\' );
end;
Result := FRemoteIconSysIdx;
end;
{$IFDEF DIRDLGEX_LINKSPANEL}
procedure TOpenDirDialogEx.RemoveLink(const s: KOLString);
var i: Integer;
Pn: PControl;
begin
i := LinksList.IndexOf( IncludeTrailingPathDelimiter( s ) );
if i >= 0 then
begin
Pn := Pointer( LinksList.Objects[ i ] );
Pn.Free;
LinksList.Delete( i );
end;
//LinksTape.Height := LinksTape.Height + 1;
//LinksTape.Height := LinksTape.Height - 1;
SetupLinksTapeHeight;
end;
procedure TOpenDirDialogEx.RemoveLinkClick(Sender: PMenu; Item: Integer);
var Pn: PControl;
i: Integer;
begin
Form.ModalResult := 0; //????
Pn := Sender.CurCtl;
if Pn <> nil then
begin