This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
EvilWorks.Vcl.SplitPanel.pas
1446 lines (1283 loc) · 36.5 KB
/
EvilWorks.Vcl.SplitPanel.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 EvilWorks.Vcl.SplitPanel;
interface
uses
WinApi.Windows,
WinAPi.Messages,
System.Classes,
System.SysUtils,
System.Math,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms;
type
{ Forward declarations }
TSplitPanel = class;
{ Enums }
TAnimationType = (
atExpand,
atCollapse
);
TOrientation = (
orHorizontal,
orVertical
);
TResizeStyle = (
rsUpdate,
rsPattern,
rsCannotResize
);
TSplitterButton = (
sbTopLeft,
sbBottomRight,
sbCenter,
sbRestore
);
TButtonsSize = (
bsSmall,
bsNormal,
bsLarge
);
TMaximizeButtons = (
mbxTopLeft,
mbxBottomRight,
mbxBoth,
mbxNone
);
TButtonGlyph = (
bgLeft,
bgUp,
bgRight,
bgDown,
bgRestore
);
TMaximizeState = (
msTopLeft,
msBottomRight,
msCenter,
msRestore
);
{ Events }
TOnDrawButtonEvent = procedure(Sender: TObject; ACanvas: TCanvas; ButtonRect: TRect; ArrowDir: TButtonGlyph; Highlighted: boolean) of object;
TOnMaximizePaneEvent = procedure(Sender: TObject; MaximizeState: TMaximizeState) of object;
TOnSplitterMovedEvent = procedure(Sender: TObject; SplitterPosition: integer) of object;
TSplitPanel = class(TCustomControl)
private type
TAnimationThread = class(TThread)
private
FStart : integer;
FEnd : integer;
FDuration : word;
FAnimationType: TAnimationType;
FValue : integer;
FControl : TControl;
protected
procedure SetSize;
public
constructor Create(A, B, Duration: integer; AnimationType: TAnimationType; Finish: TNotifyEvent; Control: TSplitPanel);
procedure Execute; override;
end;
TPane = class(TCustomControl)
private
FDesignActive: boolean;
FIndex : byte;
FSplitPanel : TSplitPanel;
procedure SetIndex(const Value: byte);
procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
protected
procedure DefineProperties(Filer: TFiler); override;
procedure LoadIndex(Reader: TReader);
procedure SaveIndex(Writer: TWriter);
procedure CMDesignHitTest(var Msg: TCMDesignHitTest); message CM_DESIGNHITTEST;
property PaneIndex: byte read FIndex write SetIndex;
public
constructor Create(AOwner: TComponent); override;
procedure Paint; override;
published
property DoubleBuffered;
property ParentDoubleBuffered;
end;
private
FAnimated : boolean;
FAnimationThread : TAnimationThread;
FAnimationDuration : cardinal;
FSaveSize : integer;
FButtonsSize : TButtonsSize;
FMaximizeButtons : TMaximizeButtons;
FRestoreButton : boolean;
FDragging : boolean;
FTopLeftHighlight : boolean;
FBottomRightHighlight: boolean;
FRestoreHighlight : boolean;
FTopLeftClick : boolean;
FBottomRightClick : boolean;
FRestoreClick : boolean;
FOrientation : TOrientation;
FPaneA : TPane;
FPaneB : TPane;
FMaximizeState : TMaximizeState;
FMemBitmap : TBitmap;
FMinSizeTopLeft : integer;
FMinSizeBottomRight : integer;
FPaneControlListA : TStringList;
FPaneControlListB : TStringList;
FProportional : boolean;
FRatio : single;
FResizeStyle : TResizeStyle;
FSplitterColor : TColor;
FSplitterPosition : integer;
FSplitterSize : byte;
FPatternDC : HDC;
FPatternBrush : TBrush;
FLineVisible : boolean;
FPatternPosition : integer;
FOnDrawButtonEvent : TOnDrawButtonEvent;
FOnMaximizePaneEvent : TOnMaximizePaneEvent;
FOnSplitterMovedEvent : TOnSplitterMovedEvent;
FButtonNormalBackground: TColor;
FButtonNormalBorder : TColor;
FButtonHotBackground : TColor;
FButtonHotBorder : TColor;
FPaintPanes : boolean;
procedure SetButtonsSize(const Value: TButtonsSize);
procedure SetSplitterPosition(const Value: integer);
procedure SetSplitterColor(const Value: TColor);
procedure SetOrientation(const Value: TOrientation);
procedure SetProportional(const Value: boolean);
procedure SetSplitterSize(const Value: byte);
procedure SetMaximizeState(const Value: TMaximizeState);
procedure SetResizeStyle(const Value: TResizeStyle);
function GetSplitterRect: TRect;
function GetButtonRect(Button: TSplitterButton): TRect;
procedure AnimationFinished(Sender: TObject);
procedure Animate;
procedure CreatePanes;
procedure SplitButtonClick(AButton: TSplitterButton);
procedure ResetRatio;
procedure ResizePanes;
procedure UpdateSplitterPosition;
procedure CheckMaxMin;
procedure MaximizePane;
procedure AllocatePatternDC;
procedure ReleasePatternDC;
procedure DrawBackground;
procedure DrawSplitter(HighlightedTopLeft, HighlightedBottomRight, HighlightedRestore: boolean);
procedure DrawPattern;
procedure SetRestoreButton(const Value: boolean);
procedure SetButtonColor(const Index: integer; const Value: TColor);
function GetPaneA: TPane;
function GetPaneB: TPane;
procedure SetMaximizeButtons(const Value: TMaximizeButtons);
protected
procedure DefineProperties(Filer: TFiler); override;
procedure ReadPaneControlsA(Reader: TReader);
procedure ReadPaneControlsB(Reader: TReader);
procedure WritePaneControlsA(Writer: TWriter);
procedure WritePaneControlsB(Writer: TWriter);
procedure ReadSaveSize(Reader: TReader);
procedure WriteSaveSize(Writer: TWriter);
procedure Loaded; override;
procedure SetName(const Value: TComponentName); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X: integer; Y: integer); override;
procedure MouseMove(Shift: TShiftState; X: integer; Y: integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X: integer; Y: integer); override;
procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
procedure CMDesignHitTest(var Msg: TCMDesignHitTest); message CM_DESIGNHITTEST;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
procedure Paint; override;
procedure Resize; override;
procedure SwapPanes;
procedure MaximizeTopLeft;
procedure MaximizeBottomRight;
procedure MaximizeCenter;
procedure MaximizeRestore;
published
property Align;
property Anchors;
property PopupMenu;
property Padding;
property DoubleBuffered;
property ParentDoubleBuffered;
property Animated : boolean read FAnimated write FAnimated default True;
property AnimationDuration : cardinal read FAnimationDuration write FAnimationDuration default 250;
property ButtonsSize : TButtonsSize read FButtonsSize write SetButtonsSize default bsNormal;
property MaximizeState : TMaximizeState read FMaximizeState write SetMaximizeState default msRestore;
property MaximizeButtons : TMaximizeButtons read FMaximizeButtons write SetMaximizeButtons default mbxBoth;
property MinSizeTopLeft : integer read FMinSizeTopLeft write FMinSizeTopLeft default 20;
property MinSizeBottomRight : integer read FMinSizeBottomRight write FMinSizeBottomRight default 20;
property Orientation : TOrientation read FOrientation write SetOrientation default orHorizontal;
property Proportional : boolean read FProportional write SetProportional default True;
property ResizeStyle : TResizeStyle read FResizeStyle write SetResizeStyle default rsUpdate;
property RestoreButton : boolean read FRestoreButton write SetRestoreButton default True;
property SplitterColor : TColor read FSplitterColor write SetSplitterColor default clBtnFace;
property SplitterPosition : integer read FSplitterPosition write SetSplitterPosition;
property SplitterSize : byte read FSplitterSize write SetSplitterSize default 8;
property ButtonNormalBorder : TColor index 0 read FButtonNormalBorder write SetButtonColor default clHighlight;
property ButtonNormalBackground: TColor index 1 read FButtonNormalBackground write SetButtonColor default clHighlightText;
property ButtonHotBorder : TColor index 2 read FButtonHotBorder write SetButtonColor default clHighlightText;
property ButtonHotBackground : TColor index 3 read FButtonHotBackground write SetButtonColor default clHighlight;
property PaneA : TPane read GetPaneA;
property PaneB : TPane read GetPaneB;
property PaintPanes : boolean read FPaintPanes write FPaintPanes default True;
property OnClick;
property OnDblClick;
property OnContextPopup;
property OnMouseDown;
property OnMouseUp;
property OnResize;
property OnDrawButton : TOnDrawButtonEvent read FOnDrawButtonEvent write FOnDrawButtonEvent;
property OnMaximizePane : TOnMaximizePaneEvent read FOnMaximizePaneEvent write FOnMaximizePaneEvent;
property OnSplitterMoved: TOnSplitterMovedEvent read FOnSplitterMovedEvent write FOnSplitterMovedEvent;
end;
implementation
{ TSplitPanel.TAnimationThread }
constructor TSplitPanel.TAnimationThread.Create(A, B, Duration: integer; AnimationType: TAnimationType; Finish: TNotifyEvent; Control: TSplitPanel);
begin
inherited Create(True);
FStart := A;
FEnd := B;
FDuration := Duration;
FAnimationType := AnimationType;
Self.OnTerminate := Finish;
FControl := Control;
FreeOnTerminate := True;
Self.Suspended := False;
end;
procedure TSplitPanel.TAnimationThread.Execute;
var
StartTime, EndTime: TDateTime;
Percent : integer;
Delta, Chunk : extended;
begin
StartTime := Now;
EndTime := Now + (FDuration / (24 * 60 * 60 * 1000));
Delta := (FEnd - FStart);
Chunk := Delta / (Sqr(100));
while (Now < EndTime) and not (Terminated) do
begin
Percent := Trunc((100 * (Now - StartTime)) / (EndTime - StartTime));
if FAnimationType = atCollapse then
FValue := FStart + Trunc(Chunk * Sqr(Percent))
else
FValue := FStart + Trunc(( - Chunk) * Sqr(Percent - 100) + Delta);
Synchronize(SetSize);
end;
FValue := FEnd;
Synchronize(SetSize);
end;
procedure TSplitPanel.TAnimationThread.SetSize;
begin
TSplitPanel(FControl).SplitterPosition := FValue;
end;
{ TSplitPanel.TPane }
constructor TSplitPanel.TPane.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csAcceptsControls, csOpaque];
end;
procedure TSplitPanel.TPane.DefineProperties(Filer: TFiler);
begin
inherited;
Filer.DefineProperty('PaneIndex', LoadIndex, SaveIndex, True);
end;
procedure TSplitPanel.TPane.LoadIndex(Reader: TReader);
begin
PaneIndex := Reader.ReadInteger;
end;
procedure TSplitPanel.TPane.SaveIndex(Writer: TWriter);
begin
Writer.WriteInteger(PaneIndex);
end;
procedure TSplitPanel.TPane.SetIndex(const Value: byte);
begin
FIndex := Value;
end;
procedure TSplitPanel.TPane.Paint;
begin
if (FSplitPanel.FPaintPanes) then
Canvas.FillRect(GetClientRect);
if FDesignActive and (csDesigning in ComponentState) then
begin
Canvas.Pen.Style := psDash;
Canvas.Rectangle(GetClientRect);
end;
end;
procedure TSplitPanel.TPane.CMDesignHitTest(var Msg: TCMDesignHitTest);
var
State: TShiftState;
begin
State := KeysToShiftState(Msg.Keys);
if (ssLeft in State) then
begin
Msg.Result := 1;
if Self = FSplitPanel.FPaneA then
begin
FSplitPanel.FPaneB.FDesignActive := False;
FSplitPanel.FPaneB.BringToFront;
end
else
begin
FSplitPanel.FPaneA.FDesignActive := False;
FSplitPanel.FPaneA.BringToFront;
end;
Self.FDesignActive := True;
Invalidate;
FDesignActive := True;
end;
inherited;
end;
procedure TSplitPanel.TPane.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
begin
Msg.Result := 1;
end;
{ TSplitPanel }
constructor TSplitPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csOpaque, csDoubleClicks];
Height := 150;
Width := 250;
FOrientation := orHorizontal;
FProportional := True;
FResizeStyle := rsUpdate;
FSplitterColor := clBtnFace;
FSplitterPosition := Height div 2;
FSaveSize := FSplitterPosition;
FRatio := FSplitterPosition / Height;
FSplitterSize := 8;
FMinSizeTopLeft := 20;
FMinSizeBottomRight := 20;
FButtonsSize := bsNormal;
FMaximizeState := msRestore;
FMaximizeButtons := mbxBoth;
FRestoreButton := True;
FMemBitmap := TBitmap.Create;
FAnimated := True;
FAnimationDuration := 250;
FButtonNormalBorder := clHighlight;
FButtonNormalBackground := clHighlightText;
FButtonHotBorder := clHighlightText;
FButtonHotBackground := clHighlight;
FPaintPanes := True;
CreatePanes;
end;
destructor TSplitPanel.Destroy;
begin
FPaneA.Free;
FPaneB.Free;
FPaneControlListA.Free;
FPaneControlListB.Free;
FMemBitmap.Free;
inherited;
end;
procedure TSplitPanel.AllocatePatternDC;
begin
FPatternDC := GetDCEx(Parent.Handle, 0, DCX_CACHE or DCX_CLIPSIBLINGS or DCX_LOCKWINDOWUPDATE);
if FResizeStyle = rsPattern then
begin
if FPatternBrush = nil then
begin
FPatternBrush := TBrush.Create;
FPatternBrush.Bitmap := AllocPatternBitmap(clBlack, clWhite);
end;
//FPrevBrush := SelectObject(FLineDC, FPatternBrush.Handle);
end;
end;
procedure TSplitPanel.Animate;
begin
// if (FAnimationThread <> nil) then
// FAnimationThread.Free;
case FOrientation of
orHorizontal:
case FMaximizeState of
msTopLeft:
FAnimationThread := TAnimationThread.Create(FSplitterPosition, 0, FAnimationDuration, atCollapse, AnimationFinished, Self);
msBottomRight:
FAnimationThread := TAnimationThread.Create(FSplitterPosition, Height, FAnimationDuration, atCollapse, AnimationFinished, Self);
msCenter:
FAnimationThread := TAnimationThread.Create(FSplitterPosition, ClientHeight div 2, FAnimationDuration, atExpand, AnimationFinished, Self);
msRestore:
FAnimationThread := TAnimationThread.Create(FSplitterPosition, FSaveSize, FAnimationDuration, atExpand, AnimationFinished, Self);
end;
orVertical:
case FMaximizeState of
msTopLeft:
FAnimationThread := TAnimationThread.Create(FSplitterPosition, 0, FAnimationDuration, atCollapse, AnimationFinished, Self);
msBottomRight:
FAnimationThread := TAnimationThread.Create(FSplitterPosition, Width, FAnimationDuration, atCollapse, AnimationFinished, Self);
msCenter:
FAnimationThread := TAnimationThread.Create(FSplitterPosition, ClientWidth div 2, FAnimationDuration, atExpand, AnimationFinished, Self);
msRestore:
FAnimationThread := TAnimationThread.Create(FSplitterPosition, FSaveSize, FAnimationDuration, atExpand, AnimationFinished, Self);
end;
end;
if Assigned(FOnMaximizePaneEvent) then
FOnMaximizePaneEvent(Self, FMaximizeState);
end;
procedure TSplitPanel.AnimationFinished(Sender: TObject);
begin
FAnimationThread := nil;
if (FMaximizeState = msRestore) then
FSaveSize := FSplitterPosition;
end;
procedure TSplitPanel.CheckMaxMin;
begin
if FOrientation = orHorizontal then
begin
if FSplitterPosition < FMinSizeTopLeft then
FSplitterPosition := FMinSizeTopLeft;
if FSplitterPosition > Height - FMinSizeBottomRight then
FSplitterPosition := Height - FMinSizeBottomRight;
end
else
begin
if FSplitterPosition < FMinSizeTopLeft then
FSplitterPosition := FMinSizeTopLeft;
if FSplitterPosition > Width - FMinSizeBottomRight then
FSplitterPosition := Width - FMinSizeBottomRight;
end;
end;
procedure TSplitPanel.CreatePanes;
begin
FPaneA := TPane.Create(Self);
FPaneA.Parent := Self;
FPaneA.Name := Self.Name + 'PaneA';
FPaneA.PaneIndex := 0;
FPaneA.FSplitPanel := Self;
FPaneA.FDesignActive := True;
FPaneB := TPane.Create(Self);
FPaneB.Parent := Self;
FPaneB.Name := Self.Name + 'PaneB';
FPaneB.PaneIndex := 0;
FPaneB.FSplitPanel := Self;
FPaneB.FDesignActive := False;
FPaneControlListA := TStringList.Create;
FPaneControlListB := TStringList.Create;
end;
procedure TSplitPanel.SplitButtonClick(AButton: TSplitterButton);
begin
case AButton of
sbTopLeft:
begin
FTopLeftClick := False;
FMaximizeState := msTopLeft;
if FAnimated then
Animate
else
MaximizePane;
end;
sbBottomRight:
begin
FBottomRightClick := False;
FMaximizeState := msBottomRight;
if FAnimated then
Animate
else
MaximizePane;
end;
sbCenter:
begin
FTopLeftClick := False;
FMaximizeState := msCenter;
if FAnimated then
Animate
else
begin
SetSplitterPosition(ClientWidth div 2);
Invalidate;
if Assigned(FOnMaximizePaneEvent) then
FOnMaximizePaneEvent(Self, FMaximizeState);
FMaximizeState := msCenter;
end;
end;
sbRestore:
begin
FRestoreClick := False;
FMaximizeState := msRestore;
if FAnimated then
Animate
else
begin
SetSplitterPosition(FSaveSize);
Invalidate;
if Assigned(FOnMaximizePaneEvent) then
FOnMaximizePaneEvent(Self, FMaximizeState);
FMaximizeState := msRestore;
end;
end;
end;
end;
procedure TSplitPanel.DefineProperties(Filer: TFiler);
begin
// Define two string lists which will hold the controls contained in the panes. This will be used to search
// for those contols when Self is created, and set their parent to the respective panes.
Filer.DefineProperty('PaneControlListA', ReadPaneControlsA, WritePaneControlsA, True);
Filer.DefineProperty('PaneControlListB', ReadPaneControlsB, WritePaneControlsB, True);
Filer.DefineProperty('SaveSize', ReadSaveSize, WriteSaveSize, FSaveSize <> 0);
end;
procedure TSplitPanel.DrawBackground;
begin
//
end;
procedure TSplitPanel.DrawPattern;
begin
FLineVisible := not FLineVisible;
case FOrientation of
orHorizontal:
PatBlt(FPatternDC, Left, FPatternPosition - (FSplitterSize div 2), Width, FSplitterSize, PATINVERT);
orVertical:
PatBlt(FPatternDC, FPatternPosition - (FSplitterSize div 2), Top, FSplitterSize, Height, PATINVERT);
end;
end;
procedure TSplitPanel.DrawSplitter(HighlightedTopLeft, HighlightedBottomRight, HighlightedRestore: boolean);
procedure AdjustColors(Highlighted: boolean);
begin
with Canvas do
if Highlighted then
begin
Pen.Color := FButtonHotBorder;
Brush.Color := FButtonHotBackground;
end
else
begin
Pen.Color := FButtonNormalBorder;
Brush.Color := FButtonNormalBackground;
end;
end;
procedure DrawButtonGlyph(var ARect: TRect; AGlyph: TButtonGlyph);
var
n: integer;
begin
InflateRect(ARect, - 1, - 1);
Canvas.Brush.Color := FMemBitmap.Canvas.Pen.Color;
with ARect do
begin
case FOrientation of
orHorizontal:
begin
n := ARect.Bottom - ARect.Top;
ARect.Left := ARect.Left + ((ARect.Right - ARect.Left) div 2) - n;
ARect.Right := ARect.Left + n * 2;
if AGlyph = bgRestore then
InflateRect(ARect, - 1, 0);
end;
orVertical:
begin
n := ARect.Right - ARect.Left;
Top := ARect.Top + ((ARect.Bottom - ARect.Top) div 2) - n;
Bottom := ARect.Top + n * 2;
if AGlyph = bgRestore then
InflateRect(ARect, 0, - 1);
end;
end;
case AGlyph of
bgLeft:
Canvas.Polygon([Point(Right, Top), Point(Right, Bottom), Point(Left, Top + ((Bottom - Top) div 2)), Point(Right, Top)]);
bgUp:
Canvas.Polygon([Point(Left, Bottom), Point(Right + 1, Bottom + 1), Point(Left + ((Right - Left) div 2), Top), Point(Left, Bottom)]);
bgRight:
Canvas.Polygon([Point(Left - 1, Top), Point(Left - 1, Bottom), Point(Right - 1, Top + ((Bottom - Top) div 2)), Point(Left - 1, Top)]);
bgDown:
Canvas.Polygon([Point(Left, Top - 1), Point(Right, Top - 1), Point(Left + ((Right - Left) div 2), Bottom - 1), Point(Left, Top - 1)]);
bgRestore:
Canvas.FillRect(ARect);
end;
end;
end;
var
R: TRect;
begin
if (FResizeStyle = rsCannotResize) or (FMaximizeButtons = mbxNone) then
begin
Canvas.Brush.Color := FSplitterColor;
Canvas.FillRect(GetSplitterRect);
end
else
begin
with Canvas do
begin
Brush.Color := FSplitterColor;
FillRect(GetSplitterRect);
case FOrientation of
orHorizontal:
begin
R := GetButtonRect(sbTopLeft);
if Assigned(FOnDrawButtonEvent) then
FOnDrawButtonEvent(Self, Canvas, R, bgUp, HighlightedTopLeft)
else
begin
AdjustColors(HighlightedTopLeft);
Roundrect(R.Left, R.Top, R.Right, R.Bottom, 2, 2);
DrawButtonGlyph(R, bgUp);
end;
R := GetButtonRect(sbBottomRight);
if Assigned(FOnDrawButtonEvent) then
FOnDrawButtonEvent(Self, Canvas, R, bgDown, HighlightedBottomRight)
else
begin
AdjustColors(HighlightedBottomRight);
Roundrect(R.Left, R.Top, R.Right, R.Bottom, 2, 2);
DrawButtonGlyph(R, bgDown);
end;
if FRestoreButton then
begin
R := GetButtonRect(sbRestore);
if Assigned(FOnDrawButtonEvent) then
FOnDrawButtonEvent(Self, Canvas, R, bgDown, HighlightedRestore)
else
begin
AdjustColors(HighlightedRestore);
Roundrect(R.Left, R.Top, R.Right, R.Bottom, 2, 2);
DrawButtonGlyph(R, bgRestore);
end;
end;
end;
orVertical:
begin
R := GetButtonRect(sbTopLeft);
if Assigned(FOnDrawButtonEvent) then
FOnDrawButtonEvent(Self, Canvas, R, bgLeft, HighlightedTopLeft)
else
begin
AdjustColors(HighlightedTopLeft);
Roundrect(R.Left, R.Top, R.Right, R.Bottom, 2, 2);
DrawButtonGlyph(R, bgLeft);
end;
R := GetButtonRect(sbBottomRight);
if Assigned(FOnDrawButtonEvent) then
FOnDrawButtonEvent(Self, Canvas, R, bgRight, HighlightedBottomRight)
else
begin
AdjustColors(HighlightedBottomRight);
Roundrect(R.Left, R.Top, R.Right, R.Bottom, 2, 2);
DrawButtonGlyph(R, bgRight);
end;
if FRestoreButton then
begin
R := GetButtonRect(sbRestore);
if Assigned(FOnDrawButtonEvent) then
FOnDrawButtonEvent(Self, Canvas, R, bgRight, HighlightedRestore)
else
begin
AdjustColors(HighlightedRestore);
Roundrect(R.Left, R.Top, R.Right, R.Bottom, 2, 2);
DrawButtonGlyph(R, bgRestore);
end;
end;
end;
end;
end;
end;
// case FOrientation of
// orHorizontal:
// Canvas.Draw(0, FSplitterPosition - (FSplitterSize div 2), FMemBitmap);
// orVertical:
// Canvas.Draw(FSplitterPosition - (FSplitterSize div 2), 0, FMemBitmap);
// end;
end;
function TSplitPanel.GetButtonRect(Button: TSplitterButton): TRect;
var
Size : integer;
Center: integer;
begin
Center := IfThen(FOrientation = orHorizontal, Width, Height) div 2;
Size := 0;
case FButtonsSize of
bsSmall:
if FOrientation = orHorizontal then
Size := Width div 24
else
Size := Height div 24;
bsNormal:
if FOrientation = orHorizontal then
Size := Width div 16
else
Size := Height div 16;
bsLarge:
if FOrientation = orHorizontal then
Size := Width div 8
else
Size := Height div 8;
end;
Result := GetSplitterRect;
case FOrientation of
orHorizontal:
if Button = sbTopLeft then
begin
Result.Right := Center - (Size div 2);
Result.Left := Result.Right - Size;
end
else
if Button = sbBottomRight then
begin
Result.Left := Center + (Size div 2);
Result.Right := Result.Left + Size;
end
else
if Button = sbRestore then
begin
Result.Left := Center - (Size div 3);
Result.Right := Center + (Size div 3);
end;
orVertical:
if Button = sbTopLeft then
begin
Result.Bottom := Center - (Size div 2);
Result.Top := Result.Bottom - Size;
end
else
if Button = sbBottomRight then
begin
Result.Top := Center + (Size div 2);
Result.Bottom := Result.Top + Size;
end
else
if Button = sbRestore then
begin
Result.Top := Center - (Size div 3);
Result.Bottom := Center + (Size div 3);
end;
end;
end;
procedure TSplitPanel.GetChildren(Proc: TGetChildProc; Root: TComponent);
var
i: integer;
begin
inherited GetChildren(Proc, Root);
for i := 0 to FPaneA.ControlCount - 1 do
if FPaneA.Controls[i].Owner = GetParentForm(Self) then
Proc(FPaneA.Controls[i]);
for i := 0 to FPaneB.ControlCount - 1 do
if FPaneB.Controls[i].Owner = GetParentForm(Self) then
Proc(FPaneB.Controls[i]);
end;
function TSplitPanel.GetPaneA: TPane;
begin
Result := FPaneA;
end;
function TSplitPanel.GetPaneB: TPane;
begin
Result := FPaneB;
end;
function TSplitPanel.GetSplitterRect: TRect;
begin
case FOrientation of
orHorizontal:
Result :=
Rect(0, FSplitterPosition - (FSplitterSize div 2), Width, FSplitterPosition + (FSplitterSize div 2));
orVertical:
Result :=
Rect(FSplitterPosition - (FSplitterSize div 2), 0, FSplitterPosition + (FSplitterSize div 2), Height);
end;
end;
procedure TSplitPanel.Loaded;
var
i: integer;
C: TComponent;
begin
inherited Loaded;
// Iterate over the list of controls for the respective panes and set them to their original parents.
for i := 0 to FPaneControlListA.Count - 1 do
begin
C := GetParentForm(Self).FindComponent(FPaneControlListA[i]);
if C <> nil then
TControl(C).Parent := FPaneA;
end;
for i := 0 to FPaneControlListB.Count - 1 do
begin
C := GetParentForm(Self).FindComponent(FPaneControlListB[i]);
if C <> nil then
TControl(C).Parent := FPaneB;
end;
ResetRatio;
Invalidate;
end;
procedure TSplitPanel.MaximizePane;
begin
case FOrientation of
orHorizontal:
if FMaximizeState = msTopLeft then
SetSplitterPosition(0)
else
SetSplitterPosition(Height);
orVertical:
if FMaximizeState = msTopLeft then
SetSplitterPosition(0)
else
SetSplitterPosition(Width);
end;
if Assigned(FOnMaximizePaneEvent) then
FOnMaximizePaneEvent(Self, FMaximizeState);
end;
procedure TSplitPanel.MaximizeTopLeft;
begin
SplitButtonClick(sbTopLeft);
end;
procedure TSplitPanel.MaximizeBottomRight;
begin
SplitButtonClick(sbBottomRight);
end;
procedure TSplitPanel.MaximizeCenter;
begin
SplitButtonClick(sbCenter);
end;
procedure TSplitPanel.MaximizeRestore;
begin
SplitButtonClick(sbRestore);
end;
procedure TSplitPanel.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
inherited;
if (FResizeStyle = rsCannotResize) then
Exit;
// Begin drag
if PtInRect(GetSplitterRect, Point(X, Y)) and not PtInRect(GetButtonRect(sbTopLeft), Point(X, Y)) and not PtInRect(GetButtonRect(sbBottomRight), Point(X, Y)) and
not PtInRect(GetButtonRect(sbRestore), Point(X, Y)) and (FResizeStyle <> rsCannotResize) and (Button = mbLeft) then
FDragging := True;
if FResizeStyle <> rsCannotResize then
begin
// TopLeft click
if PtInRect(GetButtonRect(sbTopLeft), Point(X, Y)) then
FTopLeftClick := True;
// BottomRight click
if PtInRect(GetButtonRect(sbBottomRight), Point(X, Y)) then
FBottomRightClick := True;
// Restore click
if PtInRect(GetButtonRect(sbRestore), Point(X, Y)) then
FRestoreClick := True;
end;
if FDragging and (FResizeStyle = rsPattern) then
begin
AllocatePatternDC;
FPatternPosition := FSplitterPosition;
DrawPattern;
end;
end;
procedure TSplitPanel.MouseMove(Shift: TShiftState; X, Y: integer);
begin
inherited;
if (FResizeStyle = rsCannotResize) then
Exit;
// Do drag
if FDragging then
begin
if FOrientation = orHorizontal then
FSplitterPosition := Y
else
FSplitterPosition := X;
CheckMaxMin;
FMaximizeState := msRestore;
FSaveSize := FSplitterPosition;
if (FResizeStyle = rsUpdate) then
Repaint
else
begin
DrawPattern;
FPatternPosition := FSplitterPosition;
DrawPattern;
end;
if Assigned(FOnSplitterMovedEvent) then
FOnSplitterMovedEvent(Self, FSplitterPosition);
end