-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathCaptionedDockTree.pas
1600 lines (1457 loc) · 46.2 KB
/
CaptionedDockTree.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
{*******************************************************}
{ }
{ CodeGear Delphi Visual Component Library }
{ }
{ Copyright (c) 1995-2007 CodeGear }
{ }
{*******************************************************}
unit CaptionedDockTree;
interface
uses Windows, Controls, Graphics, Messages, SysUtils, TypInfo, Forms, Classes;
type
/// <summary>
/// TParentFormState: stores information about the parent dock form for
/// use in drawing the dock site
/// </summary>
TParentFormState = record
Caption: string;
StartColor, EndColor, FontColor: TColor;
Focused: Boolean;
Icon: TIcon;
end;
type
TDockFormClass = class of TCustomDockForm;
TDockCaptionOrientation = (dcoHorizontal, dcoVertical);
/// <summary>
/// Hit tests for the caption. Note: The custom values allow you
/// to return your own hit test results for your own drawer.
/// </summary>
TDockCaptionHitTest = Cardinal;
/// <summary>
/// The pin button style to draw, if any.
/// </summary>
TDockCaptionPinButton = (dcpbNone, dcpbUp, dcpbDown);
TDockCaptionDrawer = class(TObject)
private
FDockCaptionOrientation: TDockCaptionOrientation;
FDockCaptionPinButton: TDockCaptionPinButton;
function GetCloseRect(const CaptionRect: TRect): TRect;
function GetPinRect(const CaptionRect: TRect): TRect;
function CalcButtonSize(const CaptionRect: TRect): Integer;
public
procedure DrawDockCaption(const Canvas: TCanvas;
CaptionRect: TRect; State: TParentFormState); virtual;
function DockCaptionHitTest(const CaptionRect: TRect;
const MousePos: TPoint): TDockCaptionHitTest; virtual;
/// <summary>
/// Creates an instance of the TDockCaptionDrawer. It is virtual so the
/// call to TCaptionedDockTree.GetDockCaptionDrawer.Create(..) will
/// be called on the correct type.
/// </summary>
constructor Create(DockCaptionOrientation: TDockCaptionOrientation); virtual;
property DockCaptionPinButton: TDockCaptionPinButton read FDockCaptionPinButton write FDockCaptionPinButton;
end;
TDockCaptionDrawerClass = class of TDockCaptionDrawer;
TCaptionedDockTree = class(TDockTree)
private
FGrabberSize: Integer;
FDockCaptionOrientation: TDockCaptionOrientation;
FDockCaptionDrawer: TDockCaptionDrawer;
procedure InvalidateDockSite(const Client: TControl);
protected
function AdjustCaptionRect(const ARect: TRect): TRect; virtual;
procedure AdjustDockRect(Control: TControl; var ARect: TRect); override;
function InternalCaptionHitTest(const Zone: TDockZone;
const MousePos: TPoint): TDockCaptionHitTest;
procedure PaintDockFrame(Canvas: TCanvas; Control: TControl;
const ARect: TRect); override;
function ZoneCaptionHitTest(const Zone: TDockZone;
const MousePos: TPoint; var HTFlag: Integer): Boolean; override;
property DockCaptionOrientation: TDockCaptionOrientation read FDockCaptionOrientation;
property DockCaptionDrawer: TDockCaptionDrawer read FDockCaptionDrawer;
procedure WndProc(var Message: TMessage); override;
public
constructor Create(DockSite: TWinControl); overload; override;
constructor Create(DockSite: TWinControl;
ADockCaptionOrientation: TDockCaptionOrientation); reintroduce; overload;
destructor Destroy; override;
class function GetParentFormState(const Control: TControl): TParentFormState; virtual;
class function GetDockCaptionDrawer: TDockCaptionDrawerClass; virtual;
end;
// Êëàññ TFloatTreeCep óïðàâëÿåò ðàñïîëîæåíèåì ôîðì-íîñèòåëåé
const
SignStreamFloatTreeCep:integer = 3;
type
TCoordsFloat =record
csSize:integer;
R: TRect;
Visible: boolean;
end;
TFloatTreeCep = class
private
fList: TStringList;
fCoords:array of TCoordsFloat;
fEnabled: boolean;
function GetCount: integer;
procedure DoAdd(const Names: String; const Coord: TCoordsFloat);
procedure SetEnabled(const Value: boolean);
public
constructor Create; virtual;
destructor Destroy; override;
procedure SaveControl(Control:TControl; R:TRect; Visible:boolean);
function CoordsByControl(Control:TControl; var Coord: TCoordsFloat):boolean;
function RestoreForm(Form: TCustomDockForm):boolean;
procedure SaveForm(Form: TCustomDockForm);
property Count:integer read GetCount;
procedure SaveToStream(Stream: TStream); virtual;
procedure LoadFromStream(Stream: TStream); virtual;
procedure RestoreAllForm;
procedure SaveAllForm;
property Enabled:boolean read fEnabled write SetEnabled;
end;
TCustomDockFormEx = class (TCustomDockForm)
private
fTimerVisible: boolean;
fCaption: String;
procedure CMVISIBLECHANGED(var Message:TMessage); message CM_VISIBLECHANGED;
procedure WMACTIVATEAPP(var Message: TWMACTIVATEAPP); message WM_ACTIVATEAPP;
procedure SetTimerVisible(const Value: boolean);
protected
procedure DoAddDockClient(Client: TControl; const ARect: TRect); override;
public
constructor Create(AOwner: TComponent); override;
//Åñëè TimerVisible íå ðàâíî Visible, òî ÷åðåç êîðîòêèé ïðîìåæóòîê âðåìåíè
//áóäåò óñòàíîâåëíî ñîîòâåòñòâóþùåå çíà÷åíèå ñâîéñòâà Visible
property TimerVisible:boolean read fTimerVisible write SetTimerVisible;
procedure DoShow; override;
procedure DoHide; override;
destructor Destroy; override;
end;
// Ýòî êëàññ îêíà íîñèòåëÿ, ñ ïîääåðæêîé Ctl3d=false;
// (èñïîëüçóåòñÿ ñîáñòâåííàÿ îòðèñîâêà íåêëèåíòñêîé îáëàñòè)
TCustomDockFormCep = class (TCustomDockFormEx)
private
fInClose: boolean;
fCloseDown: boolean;
procedure WMACTIVATE(var Message: TWMACTIVATE); message WM_ACTIVATE;
procedure WMNCPAINT(var Message: TWMNCPAINT); message WM_NCPAINT;
procedure WMNCHITTEST(var Message: TWMNCHITTEST); message WM_NCHITTEST;
procedure WMNCLBUTTONDOWN(var Message: TWMNCLBUTTONDOWN); message WM_NCLBUTTONDOWN;
procedure WMNCLBUTTONUP(var Message: TWMNCLBUTTONUP); message WM_NCLBUTTONUP;
procedure WM_SETTEXT(var Message: TWMSETTEXT); message WM_SETTEXT;
procedure CalcRect(var WindowRect, ClientRect, CaptionRect, CloseRect:TRect; var Pt: TPoint);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
//Ýòîò êëàññ óïðàâëÿåò èçîáðàæåíèåì âî âðåìÿ ïåðåìåùåíèÿ êîíòðîëà
TDragDockObjectCep = class {$IFDEF VER130}(TDragDockObject){$ELSE}(TDragDockObjectEx){$ENDIF}
private
fDockOvered: boolean;
fOveredTimer: boolean;
procedure SetDockOvered(const Value: boolean);
protected
procedure AdjustDockRect(ARect: TRect); override;
procedure DrawDragDockImage; override;
procedure EraseDragDockImage; override;
published
public
destructor Destroy; override;
//Åñëè óñòàíîâëåíî ýòî ñâîéñòâî, òî ïðè ñáðîñå DockOvered, ïðîèñõîäèò
//îòëîæåííîå ñîêðûòèå ôîðìû-íîñèòåëÿ.
property OveredTimer:boolean read fOveredTimer write fOveredTimer;
//Ýòî ñâîéñòâî óêàçûâàåò íà òî, ÷òî ïåðåòàñêèâàåìûé îáúåêò íàõîäèòñÿ âíóòðè
//îáúåêòà ê êîòîðîìó ìîæåò áûòü ïðèñòûêîâàí è èçîáðàæàåòñÿ ïîëóïðîçðà÷íàÿ
//ðàìêà.  ïðîòèâíîì ñëó÷àå îáúåêò ïåðåìåùàåòñÿ ïî ñâîáîäíîìó ýêðàíó
//è èçîáðàæàåòñÿ ïîëóïðîçðà÷íàÿ ôîðìà.
property DockOvered:boolean read fDockOvered write SetDockOvered;
end;
TCaptionedDockTreeClass = class of TCaptionedDockTree;
var TmpBitmap: TBitmap;
CountUsedBMP: integer;
_FloatTreeCep: TFloatTreeCep;
RestoredDockForm:boolean;
IdTimer:THandle;
DefaultDockFormClass: TDockFormClass;
const
/// <summary>
/// TDockCaptionHitTest constant values used. You can use your own values,
/// but start at the dchtCustom value. Items 4-9 are reserved for future
/// VCL use, and the value of dchtCustom may change.
/// </summary>
dchtNone = 0;
dchtCaption = 1;
dchtClose = 2;
dchtPin = 3;
dchtCustom = 10;
// Âîçâðàùàåò ýêçåìïëÿð êëàññà óïðàâëÿþùåãî ïîëîæåíèåì ôîðì-íîñèòåëåé
function FloatTreeCep: TFloatTreeCep;
//Íàõîäèò îðãàí óïðàâëåíèÿ ñ èìåíåì AControlName, êîòîðûé ðåêóðñèâíî
//ïðèíàäëåæèò ëþáîìó êîìïîíåíòó âíóòðè AOwn
//function findComponentEx(const AControlName: string; AOwn:TComponent):TControl;
//Âîçâðàùàåò ïîëíîå íàçâàíèÿ è òèïû îðãàíà óïðàâëåíèÿ è âñåõ åãî âëàäåëüöåâ,
//ðàçäåëåííûõ òî÷êîé.
procedure GetFullName(Control: TControl; var Types: string; var Names: string); overload;
function GetFullName(Control:TControl):string; overload;
implementation
uses Types, GraphUtil;
{ TCaptionedDockTree }
procedure TCaptionedDockTree.AdjustDockRect(Control: TControl;
var ARect: TRect);
begin
if FDockCaptionOrientation = dcoHorizontal then
Inc(ARect.Top, FGrabberSize)
else
Inc(ARect.Left, FGrabberSize)
end;
constructor TCaptionedDockTree.Create(DockSite: TWinControl);
begin
inherited;
FGrabberSize := GetSystemMetrics(SM_CYMENUSIZE) + 4;
FDockCaptionDrawer := GetDockCaptionDrawer.Create(FDockCaptionOrientation);
end;
constructor TCaptionedDockTree.Create(DockSite: TWinControl;
ADockCaptionOrientation: TDockCaptionOrientation);
begin
FDockCaptionOrientation := ADockCaptionOrientation;
Create(DockSite);
end;
class function TCaptionedDockTree.GetParentFormState(const Control: TControl): TParentFormState;
begin
if Control is TCustomForm then
begin
Result.Caption := TCustomForm(Control).Caption;
Result.Focused := (Screen.ActiveControl <> nil) and
Screen.ActiveControl.Focused and
(TWinControl(Control).ContainsControl(Screen.ActiveControl));
if Control is TForm then
Result.Icon := TForm(Control).Icon
else
Result.Icon := nil;
end
else
begin
Result.Caption := Control.Hint;
Result.Focused := False;
Result.Icon := nil;
end;
if Result.Focused then
begin
Result.StartColor := clActiveBorder;
Result.EndColor := GetHighlightColor(clActiveBorder, 22);
Result.FontColor := clBtnText;
end
else
begin
Result.StartColor := GetHighlightColor(clBtnFace, 5);
Result.EndColor := GetHighlightColor(clBtnFace, 15);
Result.FontColor := clBtnText;
end;
end;
procedure TCaptionedDockTree.InvalidateDockSite(const Client: TControl);
var
ParentForm: TCustomForm;
Rect: TRect;
begin
ParentForm := GetParentForm(Client, False);
{ Just invalidate the parent form's rect in the HostDockSite
so that we can "follow focus" on docked items. }
if (ParentForm <> nil) and (ParentForm.HostDockSite <> nil) then
begin
with ParentForm.HostDockSite do
if UseDockManager and (DockManager <> nil) then
begin
DockManager.GetControlBounds(ParentForm, Rect);
InvalidateRect(Handle, @Rect, False);
end;
end;
end;
function TCaptionedDockTree.AdjustCaptionRect(const ARect: TRect): TRect;
begin
Result := ARect;
if FDockCaptionOrientation = dcoHorizontal then
begin
Result.Bottom := Result.Top + FGrabberSize - 1;
Result.Top := Result.Top + 1;
Result.Right := Result.Right - 3; { Shrink the rect a little }
end
else
begin
Result.Right := Result.Left + FGrabberSize - 1;
Result.Left := Result.Left + 1;
Result.Bottom := Result.Bottom - 3;
end;
end;
procedure TCaptionedDockTree.PaintDockFrame(Canvas: TCanvas;
Control: TControl; const ARect: TRect);
begin
FDockCaptionDrawer.DrawDockCaption(Canvas,
AdjustCaptionRect(ARect),
GetParentFormState(Control));
end;
procedure TCaptionedDockTree.WndProc(var Message: TMessage);
begin
if Message.Msg = CM_DOCKNOTIFICATION then
begin
with TCMDockNotification(Message) do
begin
if NotifyRec.ClientMsg = CM_INVALIDATEDOCKHOST then
InvalidateDockSite(TControl(NotifyRec.MsgWParam))
else
inherited;
end;
end
else
inherited;
end;
function TCaptionedDockTree.InternalCaptionHitTest(const Zone: TDockZone;
const MousePos: TPoint): TDockCaptionHitTest;
var
FrameRect, CaptionRect: TRect;
begin
FrameRect := Zone.ChildControl.BoundsRect;
AdjustDockRect(Zone.ChildControl, FrameRect);
AdjustFrameRect(Zone.ChildControl, FrameRect);
CaptionRect := AdjustCaptionRect(FrameRect);
Result := FDockCaptionDrawer.DockCaptionHitTest(CaptionRect, MousePos);
end;
function TCaptionedDockTree.ZoneCaptionHitTest(const Zone: TDockZone;
const MousePos: TPoint; var HTFlag: Integer): Boolean;
var
HitTest: TDockCaptionHitTest;
begin
HitTest := InternalCaptionHitTest(Zone, MousePos);
if HitTest = dchtNone then
Result := False
else
begin
Result := True;
if HitTest = dchtClose then
HTFlag := HTCLOSE
else if HitTest = dchtCaption then
HTFlag := HTCAPTION;
end;
end;
destructor TCaptionedDockTree.Destroy;
begin
FDockCaptionDrawer.Free;
inherited;
end;
class function TCaptionedDockTree.GetDockCaptionDrawer: TDockCaptionDrawerClass;
begin
Result := TDockCaptionDrawer;
end;
{ TDockCaptionDrawer }
function TDockCaptionDrawer.CalcButtonSize(
const CaptionRect: TRect): Integer;
const
cButtonBuffer = 8;
begin
if FDockCaptionOrientation = dcoHorizontal then
Result := CaptionRect.Bottom - CaptionRect.Top - cButtonBuffer
else
Result := CaptionRect.Right - CaptionRect.Left - cButtonBuffer;
end;
constructor TDockCaptionDrawer.Create(
DockCaptionOrientation: TDockCaptionOrientation);
begin
FDockCaptionOrientation := DockCaptionOrientation;
end;
function TDockCaptionDrawer.DockCaptionHitTest(const CaptionRect: TRect;
const MousePos: TPoint): TDockCaptionHitTest;
var
CloseRect, PinRect: TRect;
begin
if PtInRect(CaptionRect, MousePos) then
begin
CloseRect := GetCloseRect(CaptionRect);
{ Make the rect vertically the same size as the captionrect }
if FDockCaptionOrientation = dcoHorizontal then
begin
CloseRect.Top := CaptionRect.Top;
CloseRect.Bottom := CaptionRect.Bottom;
Inc(CloseRect.Right);
end
else
begin
CloseRect.Left := CaptionRect.Left;
CloseRect.Right := CaptionRect.Right;
Inc(CloseRect.Bottom);
end;
if PtInRect(CloseRect, MousePos) then
Result := dchtClose
else if FDockCaptionPinButton <> dcpbNone then
begin
{ did it hit the pin? }
if FDockCaptionOrientation = dcoHorizontal then
begin
PinRect := GetPinRect(CaptionRect);
PinRect.Top := CaptionRect.Top;
PinRect.Bottom := CaptionRect.Bottom;
Inc(PinRect.Right);
end
else
begin
PinRect := GetPinRect(CaptionRect);
PinRect.Left := CaptionRect.Left;
PinRect.Right := CaptionRect.Right;
Inc(PinRect.Bottom);
end;
if PtInRect(PinRect, MousePos) then
Result := dchtPin
else
Result := dchtCaption;
end
else
Result := dchtCaption
end
else
Result := dchtNone;
end;
procedure TDockCaptionDrawer.DrawDockCaption(const Canvas: TCanvas;
CaptionRect: TRect; State: TParentFormState);
procedure DrawCloseButton(const ARect: TRect);
begin
with ARect do
begin
Canvas.Pen.Color := Canvas.Font.Color;
Canvas.Pen.Style := psSolid;
Canvas.Pen.Width := 2;
Canvas.MoveTo(Left+1, Top+1);
Canvas.LineTo(Right-1, Bottom-1);
Canvas.MoveTo(Left+1, Bottom-1);
Canvas.LineTo(Right-1, Top+1);
end;
end;
procedure DrawPinButton(const ARect: TRect);
var
Left, Top: Integer;
begin
Left := ARect.Left;
Top := ARect.Top;
Canvas.Pen.Color := Canvas.Font.Color;
Canvas.Pen.Style := psSolid;
Canvas.Pen.Width := 1;
if FDockCaptionPinButton = dcpbDown then
begin
Inc(Top);
{ Draw the top box }
Canvas.MoveTo(Left + 1, Top + 4);
Canvas.LineTo(Left + 1, Top);
Canvas.LineTo(Left + 5, Top);
Canvas.LineTo(Left + 5, Top + 5);
{ Draw the middle line }
Canvas.MoveTo(Left, Top + 5);
Canvas.LineTo(Left + 7, Top + 5);
{ Draw a depth line }
Canvas.MoveTo(Left + 4, Top + 1);
Canvas.LineTo(Left + 4, Top + 5);
Canvas.MoveTo(Left + 3, Top + 6);
Canvas.LineTo(Left + 3, Top + 6 + 4);
end
else
begin
{ Draw the right box }
Canvas.MoveTo(Left + 4, Top + 1);
Canvas.LineTo(Left + 9, Top + 1);
Canvas.LineTo(Left + 9, Top + 5);
Canvas.LineTo(Left + 3, Top + 5);
{ Draw the middle line }
Canvas.MoveTo(Left + 3, Top);
Canvas.LineTo(Left + 3, Top + 7);
{ Draw a depth line }
Canvas.MoveTo(Left + 4, Top + 4);
Canvas.LineTo(Left + 9, Top + 4);
Canvas.MoveTo(Left, Top + 3);
Canvas.LineTo(Left + 3, Top + 3);
end;
end;
function RectWidth(const Rect: TRect): Integer;
begin
Result := Rect.Right - Rect.Left;
end;
procedure DrawIcon;
var
FormBitmap: TBitmap;
DestBitmap: TBitmap;
ImageSize: Integer;
X, Y: Integer;
begin
if (State.Icon <> nil) and (State.Icon.HandleAllocated) then
begin
if FDockCaptionOrientation = dcoHorizontal then
begin
ImageSize := CaptionRect.Bottom - CaptionRect.Top - 3;
X := CaptionRect.Left;
Y := CaptionRect.Top + 2;
end
else
begin
ImageSize := CaptionRect.Right - CaptionRect.Left - 3;
X := CaptionRect.Left + 1;
Y := CaptionRect.Top;
end;
FormBitmap := nil;
DestBitmap := TBitmap.Create;
try
FormBitmap := TBitmap.Create;
DestBitmap.Width := ImageSize;
DestBitmap.Height := ImageSize;
DestBitmap.Canvas.Brush.Color := clFuchsia;
DestBitmap.Canvas.FillRect(Rect(0, 0, DestBitmap.Width, DestBitmap.Height));
FormBitmap.Width := State.Icon.Width;
FormBitmap.Height := State.Icon.Height;
FormBitmap.Canvas.Draw(0, 0, State.Icon);
ScaleImage(FormBitmap, DestBitmap, DestBitmap.Width / FormBitmap.Width);
DestBitmap.TransparentColor := DestBitmap.Canvas.Pixels[0, DestBitmap.Height - 1];
DestBitmap.Transparent := True;
Canvas.Draw(X, Y, DestBitmap);
finally
FormBitmap.Free;
DestBitmap.Free;
end;
if FDockCaptionOrientation = dcoHorizontal then
CaptionRect.Left := CaptionRect.Left + 6 + ImageSize
else
CaptionRect.Top := CaptionRect.Top + 6 + ImageSize;
end;
end;
var
ShouldDrawClose: Boolean;
CloseRect, PinRect: TRect;
begin
Canvas.Font.Color := State.FontColor;
Canvas.Pen.Width := 1;
Canvas.Pen.Color := State.StartColor;
if FDockCaptionOrientation = dcoHorizontal then
begin
CaptionRect.Top := CaptionRect.Top + 1;
{ Give a rounded effect, draw a slightly smaller line on the left }
Canvas.MoveTo(CaptionRect.Left + 2, CaptionRect.Top + 2);
Canvas.LineTo(CaptionRect.Left + 2, CaptionRect.Bottom - 1);
{ Fill the middle with a gradient }
GradientFillCanvas(Canvas, State.StartColor, State.EndColor,
Rect(CaptionRect.Left+3, CaptionRect.Top, CaptionRect.Right,
CaptionRect.Bottom), gdVertical);
{ Draw a slight outline }
Canvas.Pen.Color := GetShadowColor(Canvas.Pen.Color, -20);
with CaptionRect do
Canvas.Polyline([Point(Left + 3, Top),
Point(Right - 2, Top), { Top line }
Point(Right, Top + 2), { Top right curve }
Point(Right, Bottom - 2), { Right side line }
Point(Right - 2, Bottom), { Bottom right curve }
Point(Left + 3, Bottom), { Bottom line }
Point(Left+1, Bottom - 2), { Bottom left curve }
Point(Left+1, Top + 2), { Left side line }
Point(Left + 3, Top)]); { Top left curve }
{ Get the close rect size/position }
CloseRect := GetCloseRect(CaptionRect);
{ Does it have the pin button? Make some room for it, and draw it. }
if FDockCaptionPinButton <> dcpbNone then
begin
PinRect := GetPinRect(CaptionRect);
if FDockCaptionPinButton = dcpbUp then
Inc(PinRect.Top); { Down a little further - better looks }
DrawPinButton(PinRect);
CaptionRect.Right := PinRect.Right - 2;
end
else
{ Shrink the rect to consider the close button on the right, and
not draw text in it. }
CaptionRect.Right := CloseRect.Right - 2;
{ Move away from the left edge a little before drawing text }
CaptionRect.Left := CaptionRect.Left + 6;
{ Draw the icon, if found. }
DrawIcon;
ShouldDrawClose := CloseRect.Left >= CaptionRect.Left;
end
else
begin
{ Give a rounded effect }
Canvas.MoveTo(CaptionRect.Left + 1, CaptionRect.Top + 1);
Canvas.LineTo(CaptionRect.Right - 1, CaptionRect.Top + 1);
GradientFillCanvas(Canvas, State.StartColor, State.EndColor,
Rect(CaptionRect.Left, CaptionRect.Top+2, CaptionRect.Right,
CaptionRect.Bottom), gdVertical);
Canvas.Pen.Color := State.EndColor;
Canvas.MoveTo(CaptionRect.Left + 1, CaptionRect.Bottom);
Canvas.LineTo(CaptionRect.Right - 1, CaptionRect.Bottom);
Canvas.Font.Orientation := 900; { 90 degrees upwards }
{ Get the close rect size/position }
CloseRect := GetCloseRect(CaptionRect);
{ Does it have the pin button? Make some room for it, and draw it. }
if FDockCaptionPinButton <> dcpbNone then
begin
PinRect := GetPinRect(CaptionRect);
DrawPinButton(PinRect);
CaptionRect.Top := PinRect.Bottom + 2;
end
else
{ Add a little spacing between the close button and the text }
CaptionRect.Top := CloseRect.Bottom + 2;
ShouldDrawClose := CaptionRect.Top < CaptionRect.Bottom;
{ Make the captionrect horizontal for proper clipping }
CaptionRect.Right := CaptionRect.Left + (CaptionRect.Bottom - CaptionRect.Top - 2);
{ Position the caption starting position at most at the bottom of the
rectangle }
CaptionRect.Top := CaptionRect.Top + Canvas.TextWidth(State.Caption) + 2;
if CaptionRect.Top > CaptionRect.Bottom then
CaptionRect.Top := CaptionRect.Bottom;
end;
Canvas.Brush.Style := bsClear; { For drawing the font }
if State.Caption <> '' then
begin
if State.Focused then
Canvas.Font.Style := Canvas.Font.Style + [fsBold]
else
Canvas.Font.Style := Canvas.Font.Style - [fsBold];
if ShouldDrawClose then
CaptionRect.Right := CaptionRect.Right - (CloseRect.Right - CloseRect.Left) - 4;
Canvas.TextRect(CaptionRect, State.Caption,
[tfEndEllipsis, tfVerticalCenter, tfSingleLine]);
end;
if ShouldDrawClose then
DrawCloseButton(CloseRect);
end;
const
cSideBuffer = 4;
function TDockCaptionDrawer.GetCloseRect(const CaptionRect: TRect): TRect;
var
CloseSize: Integer;
begin
CloseSize := CalcButtonSize(CaptionRect);
if FDockCaptionOrientation = dcoHorizontal then
begin
Result.Left := CaptionRect.Right - CloseSize - cSideBuffer;
Result.Top := CaptionRect.Top + ((CaptionRect.Bottom - CaptionRect.Top) - CloseSize) div 2;
end
else
begin
Result.Left := CaptionRect.Left + ((CaptionRect.Right - CaptionRect.Left) - CloseSize) div 2;
Result.Top := CaptionRect.Top + 2*cSideBuffer;
end;
Result.Right := Result.Left + CloseSize;
Result.Bottom := Result.Top + CloseSize;
end;
function TDockCaptionDrawer.GetPinRect(const CaptionRect: TRect): TRect;
var
PinSize: Integer;
begin
PinSize := CalcButtonSize(CaptionRect);
if FDockCaptionOrientation = dcoHorizontal then
begin
Result.Left := CaptionRect.Right - 2*PinSize - 2*cSideBuffer;
Result.Top := CaptionRect.Top + ((CaptionRect.Bottom - CaptionRect.Top) - PinSize) div 2;
end
else
begin
Result.Left := CaptionRect.Left + ((CaptionRect.Right - CaptionRect.Left) - PinSize) div 2;
Result.Top := CaptionRect.Top + 2*cSideBuffer + 2*PinSize;
end;
Result.Right := Result.Left + PinSize + 2;
Result.Bottom := Result.Top + PinSize;
end;
{ TFloatTreeCep }
//×òîáû èñêëþ÷èòü ìåðöàíèå ôîðì-íîñèòåëåé, óñòàíàâëèâàåì ñâîéñòâî Visible
//ðàâíûì TimerVisible ïî òàéìåðó. Ò.å. ñíà÷àëà ïðîèçâîäèòñÿ çàãðóçêà âñåõ
//ôðåéìîâ, à ïîòîì îòîáðàæàþòñÿ òîëüêî òå ôîðìû-íîñèòåëè, ó êîòîðûõ
//êîíòðîëû íè ê ÷åìó íå ïðèñòûêîâàíû.
procedure StopVisibleChanged;
begin
if IdTimer<>0 then
if not KillTimer(0,IdTimer) then raise Exception.Create(SysErrorMessage(GetLastError))
else IdTimer := 0;
end;
procedure VisibleChangedFunc(Wnd: HWND;
Msg: UINT;
idEvent: PINTEGER;
dwTime: DWORD);stdcall;
var i: integer;
begin
if Application<>nil then
begin
for I := 0 to Application.ComponentCount - 1 do
if Application.Components[i] is TCustomDockFormEx then
with TCustomDockFormEx(Application.Components[i]) do
begin
if TimerVisible<>Visible then Visible := TimerVisible;
end;
end;
StopVisibleChanged;
end;
procedure StartVisibleChanged;
begin
if IdTimer=0 then
begin
IdTimer := SetTimer(0,98790,100,@VisibleChangedFunc);
end;
end;
//Ìåíÿåì ïðÿìîóãîëüíèê, òàê ÷òîáû îí âëåçàë â ýêðàí
procedure UpdateRectFromScreen(var ARect: TRect);
var W,H: integer;
begin
with ARect do
begin
W := Right-Left;
H := Bottom-Top;
if Right<(W)div(2) then OffsetRect(ARect,-Left-(W)div(2),0);
if Bottom<(H)div(2) then OffsetRect(ARect,0,-Top-(H)div(2));
if Right-(W)div(2)>Screen.Width then OffsetRect(ARect,Screen.Width-Right+(W)div(2),0);
if Bottom-(H)div(2)>Screen.Height then OffsetRect(ARect,0,Screen.Height-Bottom+(H)div(2));
end;
end;
// Èçîáðàæàåì êðàâèâûé ïðÿìîóãîëüíèê, ñ îáðóáëåííûìè êðàÿìè
procedure DrawCapRect(DC:HDC; R:TRect; Size:Byte; StartColor,EndColor,BorderColor:TColor; Hor:boolean);
type
COLOR16 = Word;
PTriVertex = ^TTriVertex;
_TRIVERTEX = packed record
x: Longint;
y: Longint;
Red: COLOR16;
Green: COLOR16;
Blue: COLOR16;
Alpha: COLOR16;
end;
TTriVertex = _TRIVERTEX;
procedure RtoArrayPoint(R:TRect; Size:Byte; var A:Array of TPoint);
begin
if High(A)<8 then exit;
A[0].x := R.Left+Size; A[0].y := R.Top;
A[1].x := R.Right-Size-1; A[1].y := R.Top;
A[2].x := R.Right-1; A[2].y := R.Top+Size;
A[3].x := R.Right-1; A[3].y := R.Bottom-Size-1;
A[4].x := R.Right-Size-1; A[4].y := R.Bottom-1;
A[5].x := R.Left+Size; A[5].y := R.Bottom-1;
A[6].x := R.Left; A[6].y := R.Bottom-Size-1;
A[7].x := R.Left; A[7].y := R.Top+Size;
A[8].x := R.Left+Size; A[8].y := R.Top;
end;
var
P: array [0..8] of TPoint;
Br: HBrush;
Pen,OldPen:HPen;
Vertexes: array[0..1] of TTriVertex;
GradientRect: TGradientRect;
p2: Windows.TTriVertex absolute Vertexes;
begin
RtoArrayPoint(R,Size,P);
StartColor := ColorToRGB(StartColor);
EndColor := ColorToRGB(EndColor);
if GetDeviceCaps(DC,BITSPIXEL)<16 then EndColor := StartColor;
InflateRect(R,-1,-1);
if StartColor<>EndColor then
begin
Vertexes[0].Red := Word(GetRValue(StartColor)) shl 8;
Vertexes[0].Blue := Word(GetBValue(StartColor)) shl 8;
Vertexes[0].Green := Word(GetGValue(StartColor)) shl 8;
Vertexes[0].Alpha := 0;
Vertexes[0].x := R.Left;
Vertexes[0].y := R.Top;
Vertexes[1].Red := Word(GetRValue(EndColor)) shl 8;
Vertexes[1].Blue := Word(GetBValue(EndColor)) shl 8;
Vertexes[1].Green := Word(GetGValue(EndColor)) shl 8;
Vertexes[1].Alpha := 0;
Vertexes[1].x := R.Right;
Vertexes[1].y := R.Bottom;
GradientRect.UpperLeft := 0;
GradientRect.LowerRight := 1;
if Hor then
GradientFill(DC, {$IFDEF VER130}P2{$ELSE}@P2{$ENDIF}, 2, @GradientRect, 1, GRADIENT_FILL_RECT_V)
else
GradientFill(DC, {$IFDEF VER130}P2{$ELSE}@P2{$ENDIF}, 2, @GradientRect, 1, GRADIENT_FILL_RECT_H);
end else
begin
Br := CreateSolidBrush(ColorToRGB(StartColor));
FillRect(DC,R,Br);
DeleteObject(Br);
end;
if BorderColor<>clNone then
begin
if BorderColor=clDefault then
begin
BorderColor := ((Word(GetRValue(StartColor))+Word(GetRValue(EndColor)))div(3))shl(0) +
((Word(GetGValue(StartColor))+Word(GetGValue(EndColor)))div(3))shl(8) +
((Word(GetBValue(StartColor))+Word(GetBValue(EndColor)))div(3))shl(16);
end;
Pen := CreatePen(ps_Solid,1,ColorToRGB(BorderColor));
OldPen := SelectObject(DC,Pen);
try
Windows.Polyline(DC,P,9);
finally
SelectObject(DC,OldPen);
DeleteObject(Pen);
end;
end;
end;
function FloatTreeCep: TFloatTreeCep;
begin
if _FloatTreeCep=nil then _FloatTreeCep := TFloatTreeCep.Create;
result := _FloatTreeCep;
end;
function TFloatTreeCep.CoordsByControl(Control: TControl;
var Coord: TCoordsFloat): boolean;
var Names:String;
i:integer;
begin
result := false;
Names:='';
Names := GetFullName(Control);
if Names<>'' then
begin
i := fList.IndexOf(Names);
result := i>=0;
if result then
begin
i := integer(fList.Objects[i]);
Coord := fCoords[i]
end;
end;
end;
procedure TFloatTreeCep.DoAdd(const Names:String; const Coord:TCoordsFloat);
var i:integer;
begin
with Coord do
begin
i := fList.IndexOf(Names);
if i=-1 then
begin
i := Length(fCoords);
setlength(fCoords,i+1);
try
fCoords[i].csSize := SizeOf(fCoords[i]);
fCoords[i].R := R;
fCoords[i].Visible := Visible;
fList.AddObject(Names,TObject(i));
except
setlength(fCoords,i);
raise;
end;
fList.Sort;
end else
begin
i := integer(fList.Objects[i]);
fCoords[i].csSize := SizeOf(fCoords[i]);
fCoords[i].R := R;
fCoords[i].Visible := Visible;
end;
end;
end;
procedure TFloatTreeCep.SaveControl(Control: TControl; R: TRect; Visible:boolean);
var Names,Types:String;
Coord: TCoordsFloat;
begin
if not Enabled then Exit;
Names:='';
Types:='';
GetFullName(Control, Types, Names);
if Names<>'' then
begin
Names := Names+';'+Types;
Coord.csSize := SizeOf(Coord);
Coord.R := R;
Coord.Visible := Visible;
DoAdd(Names,Coord);
end;
end;
procedure TFloatTreeCep.SaveForm(Form: TCustomDockForm);
begin
if (Form<>nil) and (Form.ControlCount>0) then
begin
SaveControl(Form.Controls[0],Form.BoundsRect,Form.Controls[0].Visible);
end;
end;
function TFloatTreeCep.RestoreForm(Form: TCustomDockForm): boolean;
var Coord:TCoordsFloat;
begin
result := false;
if (Form<>nil) and (Form.ControlCount>0) then
begin
result := CoordsByControl(Form.Controls[0],Coord);
if result then
with Coord.R do begin
UpdateRectFromScreen(Coord.R);
Form.SetBounds(Left,Top,Right-Left,Bottom-Top);
if Form IS TCustomDockFormEx then
TCustomDockFormEx(Form).TimerVisible := Coord.Visible
else
Form.Visible := Coord.Visible;
end;
end;
end;
procedure TFloatTreeCep.RestoreAllForm;
var i: integer;
OldRestoredDockForm: boolean;
begin
OldRestoredDockForm := RestoredDockForm;
try
for i := 0 to Application.ComponentCount - 1 do
if Application.Components[i] is TCustomDockForm then
RestoreForm(TCustomDockForm(Application.Components[i]));
finally
RestoredDockForm := OldRestoredDockForm;
end;
end;
procedure TFloatTreeCep.SaveAllForm;
var i: integer;
begin
for i := 0 to Application.ComponentCount - 1 do