File: kasbuttonpanel.pas

package info (click to toggle)
doublecmd 1.0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 44,380 kB
  • sloc: pascal: 368,788; ansic: 6,001; sh: 769; makefile: 196; python: 52; xml: 8
file content (84 lines) | stat: -rw-r--r-- 1,939 bytes parent folder | download | duplicates (3)
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
unit KASButtonPanel;

{$mode Delphi}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls;

type

  { TKASButtonPanel }

  TKASButtonPanel = class(TPanel)
  private
    FSameWidth: Boolean;
    FSameHeight: Boolean;
  protected
    procedure ButtonsAutoSize;
    procedure DoAutoSize; override;
  public
    constructor Create(TheOwner: TComponent); override;
  published
    property SameWidth: Boolean read FSameWidth write FSameWidth default True;
    property SameHeight: Boolean read FSameHeight write FSameHeight default True;
  end;

procedure Register;

implementation

uses
  StdCtrls;

procedure Register;
begin
  RegisterComponents('KASComponents', [TKASButtonPanel]);
end;

{ TKASButtonPanel }

procedure TKASButtonPanel.ButtonsAutoSize;
var
  Index: Integer;
  AControl: TControl;
  AMaxWidth, AMaxHeight: Integer;
begin
  AMaxWidth:= 0;
  AMaxHeight:= 0;
  for Index:= 0 to ControlCount - 1 do
  begin
    AControl:= Controls[Index];
    if AControl is TCustomButton then
    begin
      if FSameWidth and (AControl.Width > AMaxWidth) then AMaxWidth:= AControl.Width;
      if FSameHeight and (AControl.Height > AMaxHeight) then AMaxHeight:= AControl.Height;
    end;
  end;
  for Index:= 0 to ControlCount - 1 do
  begin
    AControl:= Controls[Index];
    if AControl is TCustomButton then
    begin
      if FSameWidth then AControl.Constraints.MinWidth:= AMaxWidth;
      if FSameHeight then AControl.Constraints.MinHeight:= AMaxHeight;
    end;
  end;
end;

procedure TKASButtonPanel.DoAutoSize;
begin
  inherited DoAutoSize;
  if csDesigning in ComponentState then Exit;
  if AutoSize and (FSameWidth or FSameHeight) then ButtonsAutosize;
end;

constructor TKASButtonPanel.Create(TheOwner: TComponent);
begin
  FSameWidth:= True;
  FSameHeight:= True;
  inherited Create(TheOwner);
end;

end.