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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
| ///////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2015 by Charta Software B.V. //
// All rights reserved //
// //
// Version: 1.7.0.83525 //
// Web site: https://pascal.chartasoftware.com/ //
// //
// This code and information are provided "as is" without warranty of //
// any kind. Dissemination of this information or reproduction of //
// this material is strictly forbidden unless prior written permission //
// is obtained from Charta Software B.V.. //
// //
///////////////////////////////////////////////////////////////////////////
unit UserInterface.Control.Panel.Split;
interface
uses
Boolean,
Collection.List,
CumulativeSizes,
CumulativeSizes.Sizable,
Drawing.Canvas,
Event,
Geometry._2d.Integer32.Point,
Geometry._2d.Integer32.Rectangle,
Integer._32,
UserInterface.Control,
UserInterface.Control.Button.Glyph,
UserInterface.Control.Panel,
UserInterface.Control.Panel.Stack,
UserInterface.Control.Text.SingleLine,
UserInterface.Mouse.Event,
Windows.Gdi.Cursor;
type
TMouseSplitInformation = record
public
Splitter: TInteger32;
Panel: TInteger32;
InGrip: TBoolean;
procedure Clear();
end;
TSplitButtonPanel = class(THorizontalStackPanel)
private
function GetCaptionButtonVisible(): TBoolean;
protected
const
GlyphSize = 12;
procedure HasBeenBoundToLayout(); override;
function AddButton(Glyph: TGlyph): TGlyphButton;
procedure SetCaptionButtonVisible(Visible: TBoolean);
procedure UpdateSize();
public
CaptionButton: TGlyphButton;
TabButton: TGlyphButton;
VerticalSplitButton: TGlyphButton;
HorizontalSplitButton: TGlyphButton;
CloseButton: TGlyphButton;
constructor Create(); override;
destructor Destroy(); override;
property CaptionButtonVisible: TBoolean read GetCaptionButtonVisible write SetCaptionButtonVisible;
end;
TPanelInformation = class(TObject)
private
FBounds: TInteger32Rectangle;
FControl: TControl;
FCaptionControl: TSingleLineTextControl;
FButtons: TSplitButtonPanel;
FGrip: TInteger32Rectangle;
procedure SetControl(const Value: TControl);
procedure SetBounds(const Value: TInteger32Rectangle);
procedure AddCaptionControl(Target: TList<TControl>);
procedure UpdateCaptionButton();
procedure LayoutControls();
procedure PaintGrip(Canvas: TCanvas);
procedure PaintEmpty(Canvas: TCanvas);
public
constructor Create(); virtual;
destructor Destroy(); override;
procedure Paint(Canvas: TCanvas);
procedure AddControls(Target: TList<TControl>);
procedure RemoveControls(Target: TList<TControl>);
procedure UpdateControls(Target: TList<TControl>);
property Control: TControl read FControl write SetControl;
property CaptionControl: TSingleLineTextControl read FCaptionControl;
property Buttons: TSplitButtonPanel read FButtons;
property Bounds: TInteger32Rectangle read FBounds write SetBounds;
property Grip: TInteger32Rectangle read FGrip;
end;
TSplitPanelClass = class of TSplitPanel;
TSplitPanel = class(TOpaquePanel)
private
FSplitterRadius: TInteger32;
FMouseOverSplitter: TInteger32;
procedure SetMouseOverSplitter(const Value: TInteger32);
procedure SetSplitterRadius(const Value: TInteger32);
function GetSplitterLocation(Index: TInteger32): TInteger32;
function GetPanelSize(Index: TInteger32): TInteger32;
procedure SetPanelSize(Index: TInteger32; const Value: TInteger32);
function GetControlSize(Index: TInteger32): TInteger32;
procedure SetControlSize(Index: TInteger32; const Value: TInteger32);
function GetResizeWeight(Index: TInteger32): TInteger32;
procedure SetResizeWeight(Index: TInteger32; const Value: TInteger32);
procedure SetPanelCount(const Value: TInteger32);
function GetPanelCount(): TInteger32;
procedure SetPanels(Index: TInteger32; const Value: TControl);
function GetPanels(Index: TInteger32): TControl;
function GetGlueLast(): TBoolean;
procedure SetGlueLast(const Value: TBoolean);
protected
Resizing: TBoolean;
ResizeInformation: TMouseSplitInformation;
PreviousActiveControl: TControl;
PanelSizes: TCumulativeSizes;
PanelInformations: TList<TPanelInformation>;
function MouseSplitInformation(const Position: TInteger32Point): TMouseSplitInformation;
procedure SplitPanelInfo(Index: TInteger32);
function CreatePanelSizes(): TSizableCumulativeSizes;
protected
procedure HasBeenBoundToLayout(); override;
procedure EvenlyDistributeSize(Size: TInteger32);
procedure ConfigurePanelResizeWeight(Index: TInteger32; Control: TControl); virtual;
procedure ConfigurePanelSize(Index: TInteger32; Control: TControl); virtual;
procedure ConfigurePanelSizes();
procedure StartResize(Splitter: TInteger32; const Position: TInteger32Point); virtual;
procedure StopResize(); virtual;
procedure MoveSplitter(Splitter: TInteger32; const Position: TInteger32Point; Inplace: TBoolean); virtual;
procedure ResizeToPreferred(Splitter: TInteger32); virtual;
function MinimalSplitterLocation(Index: TInteger32): TInteger32; virtual;
function MaximalSplitterLocation(Index: TInteger32): TInteger32; virtual;
function SplitterWithLocation(const Position: TInteger32Point): TInteger32; virtual;
function TrailingSize(): TInteger32;
function ExtraPanelSize(Index: TInteger32): TInteger32; virtual;
function PanelWithLocation(const Position: TInteger32Point): TInteger32; virtual;
function CalculatePanelBounds(Index: TInteger32): TInteger32Rectangle; virtual;
function GetSplitCursorForXY(const Position: TInteger32Point): TCursor; virtual;
function GetSplitterRectangle(Splitter: TInteger32): TInteger32Rectangle; virtual;
procedure PaintHighlightedSplitter(Canvas: TCanvas; Splitter: TInteger32);
function GetPanelIndexWithButtonPanel(ButtonPanel: TSplitButtonPanel): TInteger32;
procedure DescendantFiresEvent(Descendant: TControl; Event: TEvent); override;
procedure LayoutPanel(Index: TInteger32);
function GetControlInFirstNonEmptyPanel(): TControl;
property MouseOverSplitter: TInteger32 read FMouseOverSplitter write SetMouseOverSplitter;
public
constructor Create(); override;
destructor Destroy(); override;
procedure Paint(Canvas: TCanvas); override;
function Embellish(): TControl; override;
function Split(Index: TInteger32; SplitPanelClass: TSplitPanelClass): TControl;
function ToggleCaption(Index: TInteger32): TControl;
function ToggleTabPanel(Index: TInteger32): TControl;
procedure ClosePanel(Index: TInteger32);
procedure CloseEmptyPanels();
procedure DeletePanel(Index: TInteger32);
function PanelIndexOf(Control: TControl): TInteger32;
procedure CloseControl(Control: TControl); override;
function DefaultControlToFocus(): TControl; override;
function DefaultControlToNavigate(): TControl; override;
function MouseLeftDown(Event: TMouseButtonEvent): TBoolean; override;
function MouseLeftUp(Event: TMouseButtonEvent): TBoolean; override;
function MouseMove(Event: TMouseMoveEvent): TBoolean; override;
function MouseLeave(Event: TMouseLeaveEvent): TBoolean; override;
function GetCursorForPosition(const Position: TInteger32Point): TCursor; override;
function GetDragControl(const Position: TInteger32Point): TControl; override;
function CreateDragSource(Control: TControl): TDragSite; override;
function CreateDragTarget(Source: TDragSite; const Position: TInteger32Point): TDragSite; override;
function IsDynamicContainer(): TBoolean; override;
property SplitterRadius: TInteger32 read FSplitterRadius write SetSplitterRadius;
property PanelCount: TInteger32 read GetPanelCount write SetPanelCount;
property Panels[Index: TInteger32]: TControl read GetPanels write SetPanels;
property SplitterLocation[Index: TInteger32]: TInteger32 read GetSplitterLocation;
property PanelSize[Index: TInteger32]: TInteger32 read GetPanelSize write SetPanelSize;
property ControlSize[Index: TInteger32]: TInteger32 read GetControlSize write SetControlSize;
property ResizeWeight[Index: TInteger32]: TInteger32 read GetResizeWeight write SetResizeWeight;
property GlueLast: TBoolean read GetGlueLast write SetGlueLast;
end;
TSplitPanelDragSite = class(TDragSite)
protected
SplitPanel: TSplitPanel;
PanelIndex: TInteger32;
public
constructor Create(SplitPanel: TSplitPanel; Control: TControl; PanelIndex: TInteger32); reintroduce; virtual;
procedure Attach(Control: TControl); override;
procedure Detach(); override;
end;
const
ButtonSize: TInteger32 = 9;
MinimalPanelSize: TInteger32 = 25;
implementation
uses
Color.Constants,
Drawing.Fill,
Drawing.Stroke,
Exception,
Exception.NotImplemented,
FloatingPoint._64,
Font.Purpose,
Geometry._2d.FloatingPoint64.Point,
Geometry._2d.FloatingPoint64.Rectangle,
Geometry._2d.Integer32.Size,
Mathematics,
Object_.List,
UserInterface.Control.Event,
UserInterface.Control.Mode,
UserInterface.Control.Panel.FixedSide,
UserInterface.Control.Panel.Paged,
UserInterface.Control.Panel.Split.SingleDimension.Horizontal,
UserInterface.Control.Panel.Split.SingleDimension.Vertical,
UserInterface.Control.Scroll.Panel,
UserInterface.DragAndDrop.Action,
UserInterface.Keyboard.Modifiers;
{ TSplitPanel }
constructor TSplitPanel.Create();
begin
inherited Create();
FMouseOverSplitter := -1;
PanelInformations := TObjectList<TPanelInformation>.Create();
PanelSizes := CreatePanelSizes();
SplitterRadius := 1;
CaptionVisible := False;
GlueLast := True;
end;
function TSplitPanel.CreateDragSource(Control: TControl): TDragSite;
var
PanelIndex: TInteger32;
begin
PanelIndex := PanelIndexOf(Control);
if PanelIndex <> -1 then
begin
Result := TSplitPanelDragSite.Create(Self, Control, PanelIndex);
Result.Actions := [TDragDropAction.Swap, TDragDropAction.Move];
end
else
Result := nil;
end;
function TSplitPanel.CreateDragTarget(Source: TDragSite; const Position: TInteger32Point): TDragSite;
var
SplitInformation: TMouseSplitInformation;
Control: TControl;
begin
Result := nil;
if not Source.Control.HierarchyContainsControl(Self) then
begin
SplitInformation := MouseSplitInformation(Position);
if (SplitInformation.Splitter = -1) and (SplitInformation.Panel <> -1) then
begin
Control := Panels[SplitInformation.Panel];
if Control = nil then
begin
Result := TSplitPanelDragSite.Create(Self, Control, SplitInformation.Panel);
Result.Actions := [TDragDropAction.Move];
end
else if SplitInformation.InGrip and not Panels[SplitInformation.Panel].HierarchyContainsControl(Source.Control) then
begin
if (Source.Container <> Self) or (SplitInformation.Panel <> PanelIndexOf(Source.Control)) then
begin
Result := TSplitPanelDragSite.Create(Self, Control, SplitInformation.Panel);
Result.Actions := [TDragDropAction.Swap];
end;
end;
end;
end;
end;
function TSplitPanel.CreatePanelSizes(): TSizableCumulativeSizes;
begin
Result := TSizableCumulativeSizes.Create();
Result.MinimumSize := 20;
end;
function TSplitPanel.MouseLeftDown(Event: TMouseButtonEvent): TBoolean;
var
SplitInformation: TMouseSplitInformation;
begin
Result := True;
SplitInformation := MouseSplitInformation(Event.Position);
ResizeInformation.Clear();
if IsInlineEditing then
StopInlineEditing(True)
else if SplitInformation.Splitter <> -1 then
begin
if Event.Count = 2 then
ResizeToPreferred(SplitInformation.Splitter)
else
begin
ResizeInformation := SplitInformation;
Resizing := True;
StartResize(SplitInformation.Splitter, Event.Position);
GetMouseManager().ControlWithCapture := Self;
end;
end;
end;
function TSplitPanel.MouseMove(Event: TMouseMoveEvent): TBoolean;
begin
Result := False;
if Resizing then
begin
Result := True;
MoveSplitter(ResizeInformation.Splitter, Event.Position, Event.KeyModifiers * [TKeyModifier.Control] = []);
LayoutControls();
Invalidate();
end
else
MouseOverSplitter := MouseSplitInformation(Event.Position).Splitter;
end;
function TSplitPanel.MouseLeftUp(Event: TMouseButtonEvent): TBoolean;
var
SplitInformation: TMouseSplitInformation;
begin
Result := True;
if not IsInlineEditing then
begin
if Resizing then
begin
Resizing := False;
StopResize();
end;
SplitInformation := MouseSplitInformation(Event.Position);
end;
Invalidate();
end;
procedure TSplitPanel.Paint(Canvas: TCanvas);
var
Panel: TPanelInformation;
begin
inherited Paint(Canvas);
for Panel in PanelInformations do
Panel.Paint(Canvas);
if Resizing then
PaintHighlightedSplitter(Canvas, ResizeInformation.Splitter)
else if MouseOverSplitter <> -1 then
PaintHighlightedSplitter(Canvas, MouseOverSplitter);
end;
procedure TSplitPanel.SetSplitterRadius(const Value: TInteger32);
begin
if Value <> SplitterRadius then
begin
FSplitterRadius := Value;
LayoutControls();
Invalidate();
end;
end;
procedure TSplitPanel.StartResize(Splitter: TInteger32; const Position: TInteger32Point);
begin
end;
function TSplitPanel.GetControlInFirstNonEmptyPanel: TControl;
var
i: TInteger32;
Control: TControl;
begin
Result := nil;
i := 0;
while (Result = nil) and (i < PanelCount) do
begin
Control := PanelInformations[i].Control;
if Control <> nil then
Result := Control;
Inc(i);
end;
end;
function TSplitPanel.GetGlueLast(): TBoolean;
begin
Result := PanelSizes.FixedTotal;
end;
procedure TSplitPanel.SetControlSize(Index: TInteger32; const Value: TInteger32);
begin
if Value <> ControlSize[Index] then
begin
PanelSizes.SetItemSizeAndRedistribute(Index, Value + ExtraPanelSize(Index));
LayoutControls();
Invalidate();
end;
end;
procedure TSplitPanel.SetGlueLast(const Value: TBoolean);
begin
PanelSizes.FixedTotal := Value;
end;
procedure TSplitPanel.SetMouseOverSplitter(const Value: TInteger32);
begin
if Value <> MouseOverSplitter then
begin
if MouseOverSplitter <> -1 then
InvalidateRectangle(GetSplitterRectangle(MouseOverSplitter));
FMouseOverSplitter := Value;
if MouseOverSplitter <> -1 then
InvalidateRectangle(GetSplitterRectangle(MouseOverSplitter));
end;
end;
function TSplitPanel.GetSplitterLocation(Index: TInteger32): TInteger32;
begin
Result := PanelSizes.RunningSize(Index);
end;
procedure TSplitPanel.SetResizeWeight(Index: TInteger32; const Value: TInteger32);
begin
PanelSizes.Weight[Index] := Value;
end;
function TSplitPanel.ToggleCaption(Index: TInteger32): TControl;
var
PanelInformation: TPanelInformation;
begin
PanelInformation := PanelInformations[Index];
Result := PanelInformation.Control;
Result.CaptionVisible := not Result.CaptionVisible;
PanelInformation.UpdateControls(ChildControls);
if IsBoundToLayout() then
LayoutPanel(Index);
Invalidate();
end;
function TSplitPanel.ToggleTabPanel(Index: TInteger32): TControl;
var
Control: TControl;
PagedPanel: TPagedPanel;
FixedTopPanel: TFixedTopPanel;
begin
Control := Panels[Index];
if (Control is TFixedTopPanel) and ((Control as TFixedTopPanel).PanelControl is TPagedPanel) then
begin
FixedTopPanel := Control as TFixedTopPanel;
PagedPanel := FixedTopPanel.PanelControl as TPagedPanel;
if PagedPanel.PageCount <= 1 then
begin
ChildControls.Remove(Control);
if PagedPanel.PageCount = 0 then
Panels[Index] := nil
else
begin
Control := PagedPanel.Pages[0];
PagedPanel.RemovePage(Control);
Panels[Index] := Control;
end;
FixedTopPanel.Free();
end;
end
else
begin
PagedPanel := TPagedPanel.Create();
PagedPanel.CaptionVisible := False;
PagedPanel.IsExplorerTarget := True;
if Control <> nil then
ChildControls.Remove(Control);
Panels[Index] := PagedPanel.Embellish();
if Control <> nil then
PagedPanel.AddPage(Control);
end;
Result := Panels[Index];
end;
function TSplitPanel.TrailingSize(): TInteger32;
begin
Result := SplitterRadius + 1;
end;
function TSplitPanel.MouseSplitInformation(const Position: TInteger32Point): TMouseSplitInformation;
var
Index: TInteger32;
begin
Result.Clear();
Result.Splitter := SplitterWithLocation(Position);
if Result.Splitter = -1 then
begin
Index := PanelWithLocation(Position);
if Index <> -1 then
begin
Result.Panel := Index;
Result.InGrip := PanelInformations[Index].Grip.Contains(Position);
end;
end;
end;
function TSplitPanel.Split(Index: TInteger32; SplitPanelClass: TSplitPanelClass): TControl;
var
SplitPanel: TSplitPanel;
begin
Result := Panels[Index];
if SplitPanelClass = ClassType then
begin
SplitPanelInfo(Index);
LayoutControls();
Invalidate();
end
else
begin
ChildControls.Remove(Result);
SplitPanel := SplitPanelClass.Create();
SplitPanel.PanelCount := 2;
SplitPanel.Panels[0] := Result;
SplitPanel.ResizeWeight[0] := 1;
SplitPanel.ResizeWeight[1] := 1;
Panels[Index] := SplitPanel;
end;
end;
procedure TSplitPanel.ClosePanel(Index: TInteger32);
var
Control: TControl;
ParentSplitPanel: TSplitPanel;
begin
if PanelCount > 0 then
begin
DeletePanel(Index);
if (PanelCount = 1) and (ParentControl is TSplitPanel) then
begin
ParentSplitPanel := ParentControl as TSplitPanel;
Control := Panels[0];
Panels[0] := nil;
ParentSplitPanel.Panels[ParentSplitPanel.PanelIndexOf(Self)] := Control;
Free();
end
else
begin
LayoutControls();
Invalidate();
end;
end;
end;
procedure TSplitPanel.ConfigurePanelResizeWeight(Index: TInteger32; Control: TControl);
begin
end;
procedure TSplitPanel.ConfigurePanelSize(Index: TInteger32; Control: TControl);
begin
end;
procedure TSplitPanel.ConfigurePanelSizes();
var
PanelInformation: TPanelInformation;
Index: TInteger32;
begin
if IsBoundToLayout() then
begin
for Index := 0 to PanelCount - 1 do
begin
PanelInformation := PanelInformations[Index];
LayoutPanel(Index);
if PanelInformation.Control <> nil then
ConfigurePanelSize(Index, PanelInformation.Control);
end;
end;
end;
function TSplitPanel.IsDynamicContainer(): TBoolean;
begin
Result := True;
end;
procedure TSplitPanel.LayoutPanel(Index: TInteger32);
begin
PanelInformations[Index].Bounds := CalculatePanelBounds(Index);
end;
procedure TSplitPanel.HasBeenBoundToLayout();
begin
inherited HasBeenBoundToLayout();
ConfigurePanelSizes();
end;
function TSplitPanel.DefaultControlToFocus(): TControl;
begin
Result := GetControlInFirstNonEmptyPanel();
if Result <> nil then
Result := Result.DefaultControlToFocus();
if Result = nil then
Result := Self;
end;
function TSplitPanel.DefaultControlToNavigate(): TControl;
begin
Result := GetControlInFirstNonEmptyPanel();
if Result <> nil then
Result := Result.DefaultControlToNavigate();
if Result = nil then
Result := Self;
end;
procedure TSplitPanel.DeletePanel(Index: TInteger32);
var
PanelSize: TInteger32;
PanelInformation: TPanelInformation;
begin
PanelSize := PanelSizes.Size(Index);
PanelInformation := PanelInformations[Index];
PanelInformation.RemoveControls(ChildControls);
PanelInformation.Control.Free();
PanelInformations.RemoveAt(Index);
PanelSizes.Remove(Index);
if Index > 0 then
PanelSizes.SetItemSizeAndRedistribute(Index - 1, PanelSizes.Size(Index - 1) + PanelSize, False);
Invalidate();
end;
procedure TSplitPanel.DescendantFiresEvent(Descendant: TControl; Event: TEvent);
var
ButtonPanel: TSplitButtonPanel;
PanelIndex: TInteger32;
begin
if (Descendant is TGlyphButton) and (Descendant.ParentControl is TSplitButtonPanel) and (Event is TControlDefaultActionExecutedEvent) then
begin
ButtonPanel := Descendant.ParentControl as TSplitButtonPanel;
PanelIndex := GetPanelIndexWithButtonPanel(ButtonPanel);
if Descendant = ButtonPanel.TabButton then
ToggleTabPanel(PanelIndex)
else if Descendant = ButtonPanel.CaptionButton then
ToggleCaption(PanelIndex)
else if Descendant = ButtonPanel.VerticalSplitButton then
Split(PanelIndex, TVerticalSplitPanel)
else if Descendant = ButtonPanel.HorizontalSplitButton then
Split(PanelIndex, THorizontalSplitPanel)
else if Descendant = ButtonPanel.CloseButton then
ClosePanel(PanelIndex);
end
else
inherited DescendantFiresEvent(Descendant, Event);
end;
destructor TSplitPanel.Destroy();
begin
PanelInformations.Free();
PanelSizes.Free();
inherited Destroy();
end;
function TSplitPanel.PanelIndexOf(Control: TControl): TInteger32;
var
i: TInteger32;
begin
Result := -1;
i := 0;
while (Result = -1) and (i < PanelInformations.Count) do
if PanelInformations[i].Control = Control then
Result := i
else
Inc(i);
end;
function TSplitPanel.GetPanelCount(): TInteger32;
begin
Result := PanelInformations.Count;
end;
function TSplitPanel.GetPanelIndexWithButtonPanel(ButtonPanel: TSplitButtonPanel): TInteger32;
var
i: TInteger32;
begin
Result := -1;
i := 0;
while (Result = -1) and (i < PanelInformations.Count) do
if PanelInformations[i].Buttons = ButtonPanel then
Result := i
else
Inc(i);
end;
function TSplitPanel.GetDragControl(const Position: TInteger32Point): TControl;
var
SplitInformation: TMouseSplitInformation;
begin
Result := nil;
if not IsInlineEditing then
begin
SplitInformation := MouseSplitInformation(Position);
if SplitInformation.InGrip then
Result := Panels[SplitInformation.Panel];
end;
end;
function TSplitPanel.GetControlSize(Index: TInteger32): TInteger32;
begin
Result := PanelSizes.Size(Index) - ExtraPanelSize(Index);
end;
function TSplitPanel.GetCursorForPosition(const Position: TInteger32Point): TCursor;
var
SplitInformation: TMouseSplitInformation;
begin
SplitInformation := MouseSplitInformation(Position);
Result := CursorManager.Arrow;
if SplitInformation.Splitter <> -1 then
begin
Result := GetSplitCursorForXY(Position);
MouseOverSplitter := SplitInformation.Splitter;
end
else
MouseOverSplitter := -1;
end;
function TSplitPanel.GetPanels(Index: TInteger32): TControl;
begin
Result := PanelInformations[Index].Control;
end;
procedure TSplitPanel.SetPanels(Index: TInteger32; const Value: TControl);
var
BoundToLayout: TBoolean;
PanelInformation: TPanelInformation;
begin
BoundToLayout := IsBoundToLayout();
PanelInformation := PanelInformations[Index];
PanelInformation.RemoveControls(ChildControls);
if Value <> nil then
begin
PanelInformation.Control := Value.Embellish();
if not BoundToLayout then
ConfigurePanelResizeWeight(Index, PanelInformation.Control);
end
else
PanelInformation.Control := nil;
PanelInformation.AddControls(ChildControls);
if BoundToLayout then
LayoutPanel(Index);
Invalidate();
end;
procedure TSplitPanel.SetPanelSize(Index: TInteger32; const Value: TInteger32);
begin
if Value <> PanelSize[Index] then
begin
PanelSizes.SetItemSizeAndRedistribute(Index, Value);
LayoutControls();
Invalidate();
end;
end;
procedure TSplitPanel.SetPanelCount(const Value: TInteger32);
var
Index: TInteger32;
PanelInformation: TPanelInformation;
begin
for Index := Value to PanelCount - 1 do
if PanelInformations[Index].Control <> nil then
ChildControls.Remove(PanelInformations[Index].Control);
for Index := 1 to Value - PanelCount do
begin
PanelInformation := TPanelInformation.Create();
PanelInformation.AddControls(ChildControls);
PanelInformations.Add(PanelInformation);
end;
PanelSizes.Count := Value;
end;
procedure TSplitPanel.SplitPanelInfo(Index: TInteger32);
var
Size: TInteger32;
HalfSize: TInteger32;
PanelInformation: TPanelInformation;
begin
Size := PanelSize[Index];
HalfSize := Size div 2;
PanelInformation := TPanelInformation.Create();
PanelInformation.AddControls(ChildControls);
PanelInformations.AddAt(Index + 1, PanelInformation);
PanelSizes.Insert(Index + 1, 0);
PanelSizes.SetItemSizeAndRedistribute(Index + 1, HalfSize, False);
PanelSizes.SetItemSizeAndRedistribute(Index, Size - HalfSize, False);
end;
procedure TSplitPanel.EvenlyDistributeSize(Size: TInteger32);
var
LocationDistance: TFloatingPoint64;
CurrentLocation: TFloatingPoint64;
Index: TInteger32;
begin
if Size > 0 then
begin
LocationDistance := (Size - TrailingSize()) / PanelCount;
CurrentLocation := 0;
PanelSizes.SetItemSize(0, RoundToNearest(LocationDistance), False);
for Index := 1 to PanelCount - 1 do
begin
CurrentLocation := CurrentLocation + LocationDistance;
PanelSizes.SetItemSize(Index, RoundToNearest(CurrentLocation - PanelSizes.RunningSize(Index - 1)), False);
end;
PanelSizes.SetTotalSize(Size - TrailingSize(), TDeltaSizeMethod.LastColumn);
LayoutControls();
end;
end;
function TSplitPanel.ExtraPanelSize(Index: TInteger32): TInteger32;
begin
Result := 0;
end;
function TSplitPanel.MaximalSplitterLocation(Index: TInteger32): TInteger32;
begin
raise ENotImplemented.Create(ClassType, 'MaximalSplitterLocation');
end;
function TSplitPanel.MinimalSplitterLocation(Index: TInteger32): TInteger32;
begin
raise ENotImplemented.Create(ClassType, 'MinimalSplitterLocation');
end;
procedure TSplitPanel.MoveSplitter(Splitter: TInteger32; const Position: TInteger32Point; Inplace: TBoolean);
begin
end;
function TSplitPanel.CalculatePanelBounds(Index: TInteger32): TInteger32Rectangle;
begin
raise ENotImplemented.Create(ClassType, 'CalculatePanelBounds');
end;
function TSplitPanel.GetPanelSize(Index: TInteger32): TInteger32;
begin
Result := PanelSizes.Size(Index);
end;
function TSplitPanel.GetResizeWeight(Index: TInteger32): TInteger32;
begin
Result := PanelSizes.Weight[Index];
end;
function TSplitPanel.PanelWithLocation(const Position: TInteger32Point): TInteger32;
begin
raise ENotImplemented.Create(ClassType, 'PanelWithLocation');
end;
procedure TSplitPanel.ResizeToPreferred(Splitter: TInteger32);
begin
end;
function TSplitPanel.SplitterWithLocation(const Position: TInteger32Point): TInteger32;
begin
raise EException.Create('SplitterWithLocation should be implemented for class ''' + ClassName + '''!');
end;
function TSplitPanel.GetSplitCursorForXY(const Position: TInteger32Point): TCursor;
begin
raise EException.Create('GetSplitCursorForXY should be implemented for class ''' + ClassName + '''!');
end;
procedure TSplitPanel.CloseControl(Control: TControl);
begin
ClosePanel(PanelIndexOf(Control));
end;
procedure TSplitPanel.CloseEmptyPanels();
var
i: TInteger32;
begin
for i := PanelCount - 1 downto 0 do
if Panels[i] = nil then
ClosePanel(i);
end;
procedure TSplitPanel.StopResize();
begin
end;
function TSplitPanel.Embellish(): TControl;
var
ScrollPanel: TScrollPanel;
begin
ScrollPanel := TScrollPanel.Create();
ScrollPanel.Panel[TInteger32Point.New(0, 0)] := Self;
Result := ScrollPanel;
end;
procedure TSplitPanel.PaintHighlightedSplitter(Canvas: TCanvas; Splitter: TInteger32);
var
Rectangle: T2dFloatingPoint64Rectangle;
begin
Rectangle := T2dFloatingPoint64Rectangle.New(GetSplitterRectangle(Splitter)).Offset(T2dFloatingPoint64Point.New(0.5, 0.5));
Canvas.Fill := TFill.Create(TPurposeColor.FocusedSelection);
Canvas.FillRectangle(Rectangle);
if (Splitter = PanelCount - 1) and GlueLast then
Canvas.Stroke := TStroke.Create(TNamedColor.MediumGreen, 1)
else
Canvas.Stroke := TStroke.Create(TNamedColor.Blue, 1);
Canvas.DrawRectangle(Rectangle);
end;
function TSplitPanel.MouseLeave(Event: TMouseLeaveEvent): TBoolean;
begin
Result := True;
MouseOverSplitter := -1;
end;
function TSplitPanel.GetSplitterRectangle(Splitter: TInteger32): TInteger32Rectangle;
begin
Result := TInteger32Rectangle.New(0, 0, 0, 0);
end;
{ TPanelInformation }
procedure TPanelInformation.AddCaptionControl(Target: TList<TControl>);
begin
CaptionControl.Text := Control.Caption;
Target.Add(CaptionControl);
end;
procedure TPanelInformation.AddControls(Target: TList<TControl>);
begin
if Control <> nil then
begin
Target.Add(Control);
if Control.CaptionVisible then
AddCaptionControl(Target);
end
else
Target.Add(Buttons);
UpdateCaptionButton();
end;
constructor TPanelInformation.Create();
begin
inherited Create();
FButtons := TSplitButtonPanel.Create();
FCaptionControl := TSingleLineTextControl.Create();
FCaptionControl.AllowedModes := [TControlMode.Display];
FCaptionControl.IsEditor := True;
FCaptionControl.Focusability := TFocusability.None;
FCaptionControl.Font := TPurposeFont.SmallCaption;
end;
destructor TPanelInformation.Destroy();
begin
Buttons.Free();
CaptionControl.Free();
inherited Destroy();
end;
procedure TPanelInformation.LayoutControls();
var
CurrentTop: TInteger32;
begin
if Control <> nil then
begin
if Control.CaptionVisible then
begin
FGrip := TInteger32Rectangle.New(
Bounds.TopLeft,
TInteger32Size.New(Bounds.Width, CaptionControl.GetPreferredSize(TInteger32Size.Maximum).Height + 8)
);
CaptionControl.Bounds := Grip.Inset(TInteger32Rectangle.New(5, 2, 5, 2));
CurrentTop := Grip.Bottom + 1;
end
else
begin
FGrip := TInteger32Rectangle.Null;
CurrentTop := Bounds.Top;
end;
Control.Bounds := TInteger32Rectangle.New(Bounds.Left, CurrentTop, Bounds.Right, Bounds.Bottom);
Buttons.Bounds := TInteger32Rectangle.New(
TInteger32Point.New(Bounds.Right - Buttons.Width, Bounds.Top + (Grip.Height - Buttons.Height) div 2),
Buttons.Size
);
end
else
begin
FGrip := TInteger32Rectangle.Null;
Buttons.Bounds := TInteger32Rectangle.New(
TInteger32Point.New(Bounds.Right - Buttons.Width - 4, Bounds.Top + 4),
Buttons.Size
);
end;
end;
procedure TPanelInformation.Paint(Canvas: TCanvas);
begin
if Control <> nil then
PaintGrip(Canvas)
else
PaintEmpty(Canvas);
end;
procedure TPanelInformation.PaintEmpty(Canvas: TCanvas);
begin
Canvas.Stroke := TStroke.Create(TNamedColor.Black, 1);
Canvas.DrawRectangle(T2dFloatingPoint64Rectangle.New(Bounds).Offset(T2dFloatingPoint64Point.New(0.5, 0.5)));
end;
procedure TPanelInformation.PaintGrip(Canvas: TCanvas);
var
CaptionRectangle: T2dFloatingPoint64Rectangle;
begin
if Control.CaptionVisible then
begin
CaptionRectangle := T2dFloatingPoint64Rectangle.New(Control.Left, Bounds.Top, Control.Bounds.Right, Control.Top - 2).Offset(T2dFloatingPoint64Point.New(0.5, 0.5));
Canvas.Stroke := TStroke.Create(TPurposeColor.GripBorder, 1);
Canvas.DrawRectangle(CaptionRectangle);
end;
end;
procedure TPanelInformation.RemoveControls(Target: TList<TControl>);
begin
if Control <> nil then
begin
if Control.CaptionVisible then
Target.Remove(CaptionControl);
Target.Remove(Control);
end
else
Target.Remove(Buttons);
end;
procedure TPanelInformation.SetBounds(const Value: TInteger32Rectangle);
begin
FBounds := Value;
LayoutControls();
end;
procedure TPanelInformation.SetControl(const Value: TControl);
begin
FControl := Value;
end;
procedure TPanelInformation.UpdateCaptionButton();
var
Glyph: TGlyph;
begin
if Control <> nil then
begin
if Control.CaptionVisible then
Glyph := TGlyph.UpwardTriangle
else
Glyph := TGlyph.DownwardTriangle;
Buttons.CaptionButton.Glyph := Glyph;
end;
Buttons.SetCaptionButtonVisible(Control <> nil);
end;
procedure TPanelInformation.UpdateControls(Target: TList<TControl>);
begin
if (Control <> nil) and Control.CaptionVisible then
AddCaptionControl(Target)
else
Target.Remove(CaptionControl);
UpdateCaptionButton();
end;
{ TSplitButtonPanel }
function TSplitButtonPanel.AddButton(Glyph: TGlyph): TGlyphButton;
begin
Result := TGlyphButton.Create();
Result.Glyph := Glyph;
Result.GlyphSize := GlyphSize;
Result.FocusAbility := TFocusability.None;
AddControl(Result);
end;
constructor TSplitButtonPanel.Create();
begin
inherited Create();
CaptionButton := AddButton(TGlyph.DownwardTriangle);
TabButton := AddButton(TGlyph.Square);
VerticalSplitButton := AddButton(TGlyph.HorizontalBar);
HorizontalSplitButton := AddButton(TGlyph.VerticalBar);
CloseButton := AddButton(TGlyph.Cross);
SetCaptionButtonVisible(False);
end;
destructor TSplitButtonPanel.Destroy();
begin
if not CaptionButtonVisible then
CaptionButton.Free();
inherited Destroy();
end;
function TSplitButtonPanel.GetCaptionButtonVisible(): TBoolean;
begin
Result := ChildControls[0] = CaptionButton;
end;
procedure TSplitButtonPanel.HasBeenBoundToLayout();
begin
inherited HasBeenBoundToLayout();
UpdateSize();
end;
procedure TSplitButtonPanel.SetCaptionButtonVisible(Visible: TBoolean);
begin
if Visible and not CaptionButtonVisible then
ChildControls.AddAt(0, CaptionButton)
else if not Visible and CaptionButtonVisible then
ChildControls.Remove(CaptionButton);
UpdateSize();
end;
procedure TSplitButtonPanel.UpdateSize();
begin
if IsBoundToLayout() then
Size := GetPreferredSize(TInteger32Size.Maximum);
end;
{ TMouseSplitInformation }
procedure TMouseSplitInformation.Clear();
begin
Splitter := -1;
Panel := -1;
InGrip := False;
end;
{ TSplitPanelDragSite }
procedure TSplitPanelDragSite.Attach(Control: TControl);
begin
SplitPanel.Panels[PanelIndex] := Control;
end;
constructor TSplitPanelDragSite.Create(SplitPanel: TSplitPanel; Control: TControl; PanelIndex: TInteger32);
begin
inherited Create(SplitPanel, Control);
Self.SplitPanel := SplitPanel;
Self.PanelIndex := PanelIndex;
end;
procedure TSplitPanelDragSite.Detach();
begin
SplitPanel.Panels[PanelIndex] := nil;
end;
end.
|