1 | //kt -- Modified with SourceScanner on 8/8/2007
|
---|
2 | unit mTemplateFieldButton;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | uses
|
---|
7 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
8 | StdCtrls, ExtCtrls;
|
---|
9 |
|
---|
10 | type
|
---|
11 | TfraTemplateFieldButton = class(TFrame)
|
---|
12 | pnlBtn: TPanel;
|
---|
13 | lblText: TLabel;
|
---|
14 | pbFocus: TPaintBox;
|
---|
15 | procedure pnlBtnMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
16 | Shift: TShiftState; X, Y: Integer);
|
---|
17 | procedure pnlBtnMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
18 | Shift: TShiftState; X, Y: Integer);
|
---|
19 | procedure pnlBtnEnter(Sender: TObject);
|
---|
20 | procedure pnlBtnExit(Sender: TObject);
|
---|
21 | procedure pbFocusPaint(Sender: TObject);
|
---|
22 | private
|
---|
23 | FBtnDown: boolean;
|
---|
24 | FItems: TStringList;
|
---|
25 | FOnChange: TNotifyEvent;
|
---|
26 | procedure ButtonKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
---|
27 | procedure ButtonKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
|
---|
28 | function GetButtonText: string;
|
---|
29 | procedure SetButtonText(const Value: string);
|
---|
30 | public
|
---|
31 | constructor Create(AOwner: TComponent); override;
|
---|
32 | destructor Destroy; override;
|
---|
33 | property ButtonText: string read GetButtonText write SetButtonText;
|
---|
34 | property Items: TStringList read FItems;
|
---|
35 | property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
---|
36 | end;
|
---|
37 |
|
---|
38 | implementation
|
---|
39 |
|
---|
40 | {$R *.DFM}
|
---|
41 |
|
---|
42 | uses
|
---|
43 | ORFn;
|
---|
44 |
|
---|
45 | procedure TfraTemplateFieldButton.pnlBtnMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
46 | Shift: TShiftState; X, Y: Integer);
|
---|
47 | var
|
---|
48 | txt: string;
|
---|
49 | i, idx: integer;
|
---|
50 |
|
---|
51 | begin
|
---|
52 | if(not FBtnDown) then
|
---|
53 | begin
|
---|
54 | FBtnDown := TRUE;
|
---|
55 | pnlBtn.BevelOuter := bvLowered;
|
---|
56 | if(FItems.Count > 0) then
|
---|
57 | begin
|
---|
58 | txt := ButtonText;
|
---|
59 | idx := FItems.Count-1;
|
---|
60 | for i := 0 to FItems.Count-1 do
|
---|
61 | begin
|
---|
62 | if(txt = FItems[i]) then
|
---|
63 | begin
|
---|
64 | idx := i;
|
---|
65 | break;
|
---|
66 | end;
|
---|
67 | end;
|
---|
68 | inc(idx);
|
---|
69 | if(idx >= FItems.Count) then
|
---|
70 | idx := 0;
|
---|
71 | ButtonText := FItems[idx];
|
---|
72 | if assigned(FOnChange) then
|
---|
73 | FOnChange(Self);
|
---|
74 | end;
|
---|
75 | SetFocus;
|
---|
76 | end;
|
---|
77 | end;
|
---|
78 |
|
---|
79 | procedure TfraTemplateFieldButton.pnlBtnMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
80 | Shift: TShiftState; X, Y: Integer);
|
---|
81 | begin
|
---|
82 | if(FBtnDown) then
|
---|
83 | begin
|
---|
84 | FBtnDown := FALSE;
|
---|
85 | pnlBtn.BevelOuter := bvRaised;
|
---|
86 | end;
|
---|
87 | end;
|
---|
88 |
|
---|
89 | procedure TfraTemplateFieldButton.pnlBtnEnter(Sender: TObject);
|
---|
90 | begin
|
---|
91 | pbFocus.Invalidate;
|
---|
92 | end;
|
---|
93 |
|
---|
94 | procedure TfraTemplateFieldButton.pnlBtnExit(Sender: TObject);
|
---|
95 | begin
|
---|
96 | pbFocus.Invalidate;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | constructor TfraTemplateFieldButton.Create(AOwner: TComponent);
|
---|
100 | begin
|
---|
101 | inherited;
|
---|
102 | FItems := TStringList.Create;
|
---|
103 | OnKeyDown := ButtonKeyDown;
|
---|
104 | OnKeyUp := ButtonKeyUp;
|
---|
105 | Font.Size := MainFontSize;
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TfraTemplateFieldButton.ButtonKeyDown(Sender: TObject; var Key: Word;
|
---|
109 | Shift: TShiftState);
|
---|
110 | begin
|
---|
111 | if Key = VK_SPACE then
|
---|
112 | pnlBtnMouseDown(Sender, mbLeft, [], 0, 0);
|
---|
113 | end;
|
---|
114 |
|
---|
115 | procedure TfraTemplateFieldButton.ButtonKeyUp(Sender: TObject; var Key: Word;
|
---|
116 | Shift: TShiftState);
|
---|
117 | begin
|
---|
118 | pnlBtnMouseUp(Sender, mbLeft, [], 0, 0);
|
---|
119 | end;
|
---|
120 |
|
---|
121 | function TfraTemplateFieldButton.GetButtonText: string;
|
---|
122 | begin
|
---|
123 | Result := lblText.Caption;
|
---|
124 | end;
|
---|
125 |
|
---|
126 | procedure TfraTemplateFieldButton.SetButtonText(const Value: string);
|
---|
127 | begin
|
---|
128 | lblText.Caption := Value;
|
---|
129 | end;
|
---|
130 |
|
---|
131 | procedure TfraTemplateFieldButton.pbFocusPaint(Sender: TObject);
|
---|
132 | var
|
---|
133 | R: TRect;
|
---|
134 | begin
|
---|
135 | if(Focused) then
|
---|
136 | begin
|
---|
137 | R := Rect(1, 0, pnlBtn.Width - 3, pnlBtn.Height-2);
|
---|
138 | pbFocus.Canvas.DrawFocusRect(R);
|
---|
139 | end;
|
---|
140 | end;
|
---|
141 |
|
---|
142 | destructor TfraTemplateFieldButton.Destroy;
|
---|
143 | begin
|
---|
144 | FItems.Free;
|
---|
145 | inherited;
|
---|
146 | end;
|
---|
147 |
|
---|
148 | end.
|
---|