Debian Codegraph @

components/KASToolBar/kasbuttonpanel.pas

raw
1 unit KASButtonPanel;
2
3 {$mode Delphi}
4
5 interface
6
7 uses
8 Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls;
9
10 type
11
12 { TKASButtonPanel }
13
14 TKASButtonPanel = class(TPanel)
15 private
16 FSameWidth: Boolean;
17 FSameHeight: Boolean;
18 protected
19 procedure ButtonsAutoSize;
20 procedure DoAutoSize; override;
21 public
22 constructor Create(TheOwner: TComponent); override;
23 published
24 property SameWidth: Boolean read FSameWidth write FSameWidth default True;
25 property SameHeight: Boolean read FSameHeight write FSameHeight default True;
26 end;
27
28 procedure Register;
29
30 implementation
31
32 uses
33 StdCtrls;
34
35 procedure Register;
36 begin
37 RegisterComponents('KASComponents', [TKASButtonPanel]);
38 end;
39
40 { TKASButtonPanel }
41
42 procedure TKASButtonPanel.ButtonsAutoSize;
43 var
44 Index: Integer;
45 AControl: TControl;
46 AMaxWidth, AMaxHeight: Integer;
47 begin
48 AMaxWidth:= 0;
49 AMaxHeight:= 0;
50 for Index:= 0 to ControlCount - 1 do
51 begin
52 AControl:= Controls[Index];
53 if AControl is TCustomButton then
54 begin
55 if FSameWidth and (AControl.Width > AMaxWidth) then AMaxWidth:= AControl.Width;
56 if FSameHeight and (AControl.Height > AMaxHeight) then AMaxHeight:= AControl.Height;
57 end;
58 end;
59 for Index:= 0 to ControlCount - 1 do
60 begin
61 AControl:= Controls[Index];
62 if AControl is TCustomButton then
63 begin
64 if FSameWidth then AControl.Constraints.MinWidth:= AMaxWidth;
65 if FSameHeight then AControl.Constraints.MinHeight:= AMaxHeight;
66 end;
67 end;
68 end;
69
70 procedure TKASButtonPanel.DoAutoSize;
71 begin
72 inherited DoAutoSize;
73 if csDesigning in ComponentState then Exit;
74 if AutoSize and (FSameWidth or FSameHeight) then ButtonsAutosize;
75 end;
76
77 constructor TKASButtonPanel.Create(TheOwner: TComponent);
78 begin
79 FSameWidth:= True;
80 FSameHeight:= True;
81 inherited Create(TheOwner);
82 end;
83
84 end.