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
|
{
fpGUI - Free Pascal Graphical User Interface
Copyright (C) 2006 by Graeme Geldenhuys
member of the fpGUI development team.
Panel class declarations
See the file COPYING.fpGUI, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
{%mainunit fpgui.pp}
{
Panel implementation. I mixture of Delphi's TPanel and TBevel. The class
name might change to Frame.
}
{$IFDEF read_interface}
TCustomPanel = class(TBinWidget)
private
FBevelStyle: TBevelStyle;
procedure SetBevelStyle(const AValue: TBevelStyle);
protected
procedure Paint(Canvas: TFCanvas); override;
procedure CalcSizes; override;
procedure Resized; override;
property BevelStyle: TBevelStyle read FBevelStyle write SetBevelStyle;
{$Note Still outstanding is the Shape and Color properties for starters }
public
constructor Create(const pText: string; pOwner: TComponent); overload;
end;
TPanel = class(TCustomPanel)
published
property CanExpandWidth;
property CanExpandHeight;
property Enabled;
property Text;
property BevelStyle;
end;
{$ENDIF read_interface}
{$IFDEF read_implementation}
procedure TCustomPanel.SetBevelStyle(const AValue: TBevelStyle);
begin
if FBevelStyle = AValue then exit;
FBevelStyle := AValue;
Redraw;
end;
procedure TCustomPanel.Paint(Canvas: TFCanvas);
var
Pt: TPoint;
begin
Style.DrawPanel(Canvas, Rect(0, 0, Width, Height), FBevelStyle);
if Text <> '' then
begin
Canvas.SetColor(Style.GetUIColor(clBtnText));
Pt.x := (BoundsSize.cx - Canvas.TextWidth(Text)) div 2;
Pt.y := (BoundsSize.cy - Canvas.FontCellHeight) div 2;
Style.DrawText(Canvas, Pt, Text, WidgetState);
end;
end;
procedure TCustomPanel.CalcSizes;
var
Borders: TRect;
LabelWidth: Integer;
begin
Borders := Style.GetGroupBoxBorders(TFCanvas(FindForm.Wnd.Canvas), Text, LabelWidth);
FMinSize.cx := Borders.Left + Borders.Right + LabelWidth;
FMinSize.cy := Borders.Top + Borders.Bottom;
if Assigned(Child) then
begin
if Child.MinSize.cx > LabelWidth then
FMinSize.cx := Borders.Left + Borders.Right + Child.MinSize.cx;
Inc(FMinSize.cy, Child.MinSize.cy);
if Child.DefSize.cx > LabelWidth then
FDefSize.cx := Borders.Left + Borders.Right + Child.MinSize.cx;
Inc(FDefSize.cy, Child.DefSize.cy);
if Child.MaxSize.cx > LabelWidth then
FMaxSize.cx := Min(Borders.Left + Borders.Right + Child.MaxSize.cx, InfiniteSize);
FMaxSize.cy := Min(MaxSize.cy + Child.MaxSize.cy, InfiniteSize);
end;
end;
procedure TCustomPanel.Resized;
var
LabelWidth: Integer;
Borders: TRect;
begin
LabelWidth := 0;
if Assigned(Child) then
begin
Borders := Style.GetGroupBoxBorders(TFCanvas(FindForm.Wnd.Canvas), Text, LabelWidth);
Child.SetBounds(Borders.TopLeft, Size(Width - Borders.Left - Borders.Right,
Height - Borders.Top - Borders.Bottom));
end;
end;
constructor TCustomPanel.Create(const pText: string; pOwner: TComponent);
begin
Create(pOwner);
FCanExpandWidth := True;
FCanExpandHeight := True;
Text := pText;
FBevelStyle := bsRaised;
end;
{$ENDIF read_implementation}
|