source: branches/2.20_branch/Components/ACLMessageForm.pas

Last change on this file was 226, checked in by RBRi, 18 years ago

refactoring
unused things removed, unit tests written, save translations improved

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1unit ACLMessageForm;
2
3interface
4
5Uses
6 CustomMemo,
7 Classes, Forms, Graphics, StdCtrls,
8 Buttons, ExtCtrls, Dialogs,
9 SystemIconUnit;
10
11Type
12 TListHelpCallback=procedure( ListObjectRef: TObject );
13
14 TMessageIconType = ( mitInfo, mitQuestion, mitError, mitWarning );
15
16 TMessageForm = Class (TDialog)
17 OKButton: TButton;
18 CancelButton: TButton;
19 HelpButton: TButton;
20 Image: TSystemIcon;
21 MessageMemo: TCustomMemo;
22 ListBox: TListBox;
23 Procedure HelpButtonOnClick (Sender: TObject);
24 Procedure SetupShow; override;
25 Destructor Destroy; override;
26
27 public
28 TheText: PChar; // pointer to zero-terminated text to put in message memo
29 ShowList: boolean;
30 ShowCancel: boolean;
31 UseYesNo: boolean;
32
33 IconType: TMessageIconType;
34
35 ShowHelp: boolean;
36 ListHelpCallback: TListHelpCallback;
37
38 Procedure SetupComponent; Override;
39
40 End;
41
42
43
44
45Implementation
46
47Uses
48 SysUtils,
49 ACLLanguageUnit;
50
51{$R DialogIcons}
52
53const
54 spc = 10; // spacing
55
56var
57 OKButtonCaption: string;
58 CancelButtonCaption: string;
59 HelpButtonCaption: string;
60 YesButtonCaption: string;
61 NoButtonCaption: string;
62
63Procedure OnLanguageEvent(Language: TLanguageFile; const Apply: boolean);
64var
65 tmpPrefix : String;
66begin
67 tmpPrefix := '';
68 if Language = nil then
69 begin
70 OKButtonCaption := '~OK';
71 CancelButtonCaption := '~Cancel';
72 HelpButtonCaption := '~Help';
73 YesButtonCaption := '~Yes';
74 NoButtonCaption := '~No';
75 end
76 else
77 begin
78 tmpPrefix := 'MessageForm' + LANGUAGE_LABEL_DELIMITER; // use messageform captions
79
80 Language.LL(Apply, OKButtonCaption, tmpPrefix + 'OKButtonCaption', '~OK');
81 Language.LL(Apply, CancelButtonCaption, tmpPrefix + 'CancelButtonCaption', '~Cancel');
82 Language.LL(Apply, HelpButtonCaption, tmpPrefix + 'HelpButtonCaption', '~Help');
83 Language.LL(Apply, YesButtonCaption, tmpPrefix + 'YesButtonCaption', '~Yes');
84 Language.LL(Apply, NoButtonCaption, tmpPrefix + 'NoButtonCaption', '~No');
85 end;
86end;
87
88Procedure TMessageForm.SetupComponent;
89begin
90 Inherited SetupComponent;
91 Width := 375;
92 Height := 300;
93
94 OKButton := InsertButton( self, 0, spc, 80, 30, OKButtonCaption, '' );
95 CancelButton := InsertButton( self, 0, spc, 80, 30, CancelButtonCaption, '' );
96 HelpButton := InsertButton( self, 0, spc, 80, 30, HelpButtonCaption, '' );
97 HelpButton.OnClick := HelpButtonOnClick;
98
99 Image := TSystemIcon.Create( self );
100 Image.Parent := Self;
101 Image.Left := spc;
102 Image.Bottom := 220;
103
104 MessageMemo := TCustomMemo.Create( self );
105 MessageMemo.Parent := Self;
106 MessageMemo.Left := 55;
107 MessageMemo.Bottom := 160;
108 MessageMemo.Width := 300;
109 MessageMemo.Height := 105;
110 MessageMemo.ParentColor := true;
111 MessageMemo.BorderStyle := bsNone;
112 MessageMemo.ReadOnly := true;
113
114 ListBox := InsertListBox( self,
115 50, OKButton.Bottom + OKButton.Height + spc,
116 275, 110, '' );
117
118end;
119
120Procedure TMessageForm.HelpButtonOnClick (Sender: TObject);
121Var
122 ListObject: TObject;
123 Index: longint;
124Begin
125 Index := ListBox.ItemIndex;
126 if Index = -1 then
127 begin
128 ListHelpCallback( nil )
129 end
130 else
131 begin
132 ListObject := ListBox.Items.Objects[ Index ];
133 ListHelpCallback( ListObject );
134 end;
135End;
136
137destructor TMessageForm.Destroy;
138Begin
139 Inherited Destroy;
140End;
141
142Procedure TMessageForm.SetupShow;
143Var
144 TextHeight: longint;
145 ImageHeight: longint;
146 MessageHeight: longint;
147 TotalButtonWidth: longint;
148 X: longint;
149 DesiredClientHeight: longint;
150Begin
151 Inherited SetupShow;
152
153 MessageMemo.Lines.SetText( TheText );
154
155 TextHeight := MessageMemo.TotalHeight + 10;
156
157 case IconType of
158 mitInfo:
159 Image.ID := siIconInformation;
160 mitQuestion:
161 Image.ID := siIconQuestion;
162 mitError:
163 Image.ID := siIconError;
164 mitWarning:
165 Image.ID := siIconWarning;
166 end;
167
168 ImageHeight := Image.Height;
169
170 MessageHeight := TextHeight;
171 if ImageHeight > TextHeight then
172 MessageHeight := ImageHeight;
173
174 MessageMemo.Height := MessageHeight;
175
176 if ShowList then
177 begin
178 DesiredClientHeight := spc + OKButton.Height + spc + ListBox.Height + spc + MessageHeight + spc;
179 ListBox.Show;
180 end
181 else
182 begin
183 DesiredClientHeight := spc + OKButton.Height + spc + MessageHeight + spc;
184 ListBox.Hide;
185 end;
186
187 MessageMemo.Bottom := DesiredClientHeight - spc - MessageHeight;
188 Image.Bottom := MessageMemo.Bottom + ( MessageHeight - ImageHeight ) div 2; // centre vertically
189
190 MessageMemo.Left := spc + Image.Width + spc;
191 ListBox.Left := MessageMemo.Left;
192 ListBox.Width := ClientWidth - ( MessageMemo.Left * 2 );
193
194 ClientHeight := DesiredClientHeight;
195
196 TotalButtonWidth := OKButton.Width;
197 if ShowHelp then
198 inc( TotalButtonWidth, HelpButton.Width + spc );
199 if ShowCancel then
200 inc( TotalButtonWidth, CancelButton.Width + spc );
201 X := ClientWidth div 2 - TotalButtonWidth div 2;
202
203 HelpButton.Left := X;
204 if ShowHelp then
205 inc( X, HelpButton.Width + spc );
206
207 OKButton.Left := X;
208 inc( X, OKButton.Width + spc );
209
210 CancelButton.Left := X;
211
212 CancelButton.Visible := ShowCancel;
213 if ShowCancel then
214 CancelButton.Cancel := true
215 else
216 OKButton.Cancel := true; // so escape will finish the dialog
217
218 if UseYesNo then
219 begin
220 OKButton.Caption := YesButtonCaption;
221 OKButton.ModalResult := mrYes;
222 CancelButton.Caption := NoButtonCaption;
223 CancelButton.ModalResult := mrNo;
224 end
225 else
226 begin
227 OKButton.Caption := OKButtonCaption;
228 OKButton.ModalResult := mrOK;
229 CancelButton.Caption := CancelButtonCaption;
230 CancelButton.ModalResult := mrCancel;
231 end;
232
233 HelpButton.Visible := ShowHelp;
234
235 OKButton.Focus;
236
237End;
238
239Initialization
240 RegisterClasses ([TButton, TImage, TMessageForm, TCustomMemo, TListBox]);
241
242 RegisterProcForLanguages( OnLanguageEvent );
243
244 // load our defaults in case the app using us doesn't know about languages
245 OnLanguageEvent( nil, true );
246
247end.
Note: See TracBrowser for help on using the repository browser.