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

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

small optimization

  • Property svn:eol-style set to native
File size: 10.6 KB
Line 
1Unit ACLDialogs;
2// A variety of useful message box functions, including displaying
3// lists. They all allow specification of a caption.
4
5 Interface
6
7Uses
8 Classes,
9{$ifdef os2}
10 ACLMessageForm
11{$else}
12 Controls,
13 MessageFormWin
14{$endif}
15 ;
16
17// Shows a message box
18Procedure DoMessageDlg( Caption: String;
19 Message: string );
20
21// Shows an error message box
22Procedure DoErrorDlg( Caption: String;
23 Message: string );
24
25// Shows a warning message box
26Procedure DoWarningDlg( Caption: String;
27 Message: string );
28
29// Shows a long message box
30Procedure DoLongMessageDlg( Caption: String;
31 Message: PChar );
32
33// Shows a dialog with OK and cancel buttons
34// Returns true if OK pressed
35Function DoConfirmDlg( Caption: string;
36 Message: string ): boolean;
37
38// Returns true if confirmation given.
39Function DoConfirmListDlg( Caption: string;
40 Message: string;
41 List: TStrings ): boolean;
42
43// Shows a message containing a list
44Procedure DoMessageListDlg( Caption: string;
45 Message: string;
46 List: TStrings );
47
48// Shows an error message containing a list
49Procedure DoErrorListDlg( Caption: string;
50 Message: string;
51 List: TStrings );
52
53// Returns true if yes is clicked
54Function DoYesNoListDlg( Caption: string;
55 Message: string;
56 List: TStrings ): boolean;
57
58// Returns true if yes is clicked
59Function DoYesNoDlg( Caption: string;
60 Message: string ): boolean;
61
62// Shows a message containing a list
63// with a help callback for items in the list
64Procedure DoMessageListHelpDlg( Caption: string;
65 Message: string;
66 List: TStrings;
67 ListHelpCallback: TListHelpCallback );
68
69{$ifdef os2}
70Function DoInputQuery( Const ACaption: String;
71 Const APrompt: String;
72 Var Value: String ): Boolean;
73
74{$endif}
75
76Implementation
77
78uses
79 SysUtils,
80 Forms,
81 Dialogs,
82 StdCtrls,
83 Buttons,
84{$ifdef os2}
85 ACLLanguageUnit, ControlsUtility,
86{$endif}
87 CharUtilsUnit,
88 DebugUnit;
89
90// -------------------------------------------------
91
92Function DoACLDialog( const Caption: string;
93 const Message: string;
94 const List: TStrings;
95 const ShowCancel: boolean;
96 const IconType: TMessageIconType;
97 const ShowHelp: boolean;
98 const UseYesNo: boolean;
99 const ListHelpCallBack: TListHelpCallBack ): TModalResult;
100var
101 TheDialog: TMessageForm;
102 PMessage: PChar;
103Begin
104 TheDialog := TMessageForm.Create( nil );
105 TheDialog.Caption := Caption;
106 PMessage := NewPCharAsCopyOfStr(Message);
107 TheDialog.TheText := PMessage;
108
109 TheDialog.ShowCancel := ShowCancel;
110 TheDialog.IconType := IconType;
111 TheDialog.ShowHelp := ShowHelp;
112 TheDialog.UseYesNo := UseYesNo;
113 TheDialog.ListHelpCallBack := ListHelpCallBack;
114
115 if List <> nil then
116 begin
117 TheDialog.ShowList := true;
118 TheDialog.ListBox.Items.Assign( List );
119 end
120 else
121 begin
122 TheDialog.ShowList := false;
123 end;
124
125 Result := TheDialog.ShowModal;
126
127 TheDialog.Destroy;
128 StrDispose( PMessage );
129end;
130
131Procedure DoMessageListDlg( Caption: string;
132 Message: string;
133 List: TStrings );
134Begin
135 DoACLDialog( Caption,
136 Message,
137 List,
138 false, // show cancel
139 mitInfo,
140 false, // show help
141 false, // use yes no
142 nil
143 );
144End;
145
146Procedure DoMessageListHelpDlg( Caption: string;
147 Message: string;
148 List: TStrings;
149 ListHelpCallback: TListHelpCallback );
150Begin
151 DoACLDialog( Caption,
152 Message,
153 List,
154 false, // show cancel
155 mitInfo,
156 true, // show help
157 false, // use yes no
158 ListHelpCallBack
159 );
160End;
161
162Function DoConfirmListDlg( Caption: string;
163 Message: string;
164 List: TStrings ): boolean;
165Begin
166 Result :=
167 DoACLDialog( Caption,
168 Message,
169 List,
170 true, // show cancel
171 mitQuestion,
172 false, // show help
173 false, // use yes no
174 nil // no help callback
175 ) = mrOK;
176End;
177
178Function DoConfirmDlg( Caption: string;
179 Message: string ): boolean;
180Begin
181 Result :=
182 DoACLDialog( Caption,
183 Message,
184 nil, // no list
185 true, // show cancel
186 mitQuestion,
187 false, // show help
188 false, // use yes no
189 nil // no help callback
190 ) = mrOK;
191End;
192
193Procedure DoLongMessageDlg( Caption: String;
194 Message: PChar );
195Var
196 TheDialog: TMessageForm;
197Begin
198 TheDialog := TMessageForm.Create( nil );
199 TheDialog.Caption := Caption;
200 TheDialog.TheText := Message;
201
202 TheDialog.ShowList := false;
203 TheDialog.ShowCancel := false;
204 TheDialog.IconType := mitInfo;
205 TheDialog.ShowHelp := false;
206 TheDialog.UseYesNo := false;
207
208 TheDialog.ShowModal;
209 TheDialog.Destroy;
210End;
211
212Procedure DoMessageDlg( Caption: String;
213 Message: string );
214Begin
215 DoACLDialog( Caption,
216 Message,
217 nil, // no list
218 false, // show cancel
219 mitInfo,
220 false, // show help
221 false, // use yes no
222 nil // no help callback
223 );
224End;
225
226Procedure DoErrorListDlg( Caption: string;
227 Message: string;
228 List: TStrings );
229Begin
230 DoACLDialog( Caption,
231 Message,
232 List,
233 false, // show cancel
234 mitError,
235 false, // show help
236 false, // use yes no
237 nil // no help callback
238 );
239End;
240
241Procedure DoErrorDlg( Caption: String;
242 Message: string );
243Begin
244 DoACLDialog( Caption,
245 Message,
246 nil, // no list
247 false, // show cancel
248 mitError,
249 false, // show help
250 false, // use yes no
251 nil // no help callback
252 );
253End;
254
255Procedure DoWarningDlg( Caption: String;
256 Message: string );
257begin
258 DoACLDialog( Caption,
259 Message,
260 nil, // no list
261 false, // show cancel
262 mitWarning,
263 false, // show help
264 false, // use yes no
265 nil // no help callback
266 );
267end;
268
269Function DoYesNoListDlg( Caption: string;
270 Message: string;
271 List: TStrings ): boolean;
272Begin
273 Result :=
274 DoACLDialog( Caption,
275 Message,
276 List,
277 true, // show "cancel" (=no)
278 mitQuestion,
279 false, // show help
280 true, // use yes no
281 nil // no help callback
282 ) = mrYes;
283End;
284
285Function DoYesNoDlg( Caption: string;
286 Message: string ): boolean;
287Begin
288 Result :=
289 DoACLDialog( Caption,
290 Message,
291 nil, // no list
292 true, // show "cancel" (=no)
293 mitQuestion,
294 false, // show help
295 true, // use yes no
296 nil // no help callback
297 ) = mrYes;
298End;
299
300{$ifdef os2}
301
302var
303 OKButtonCaption: string;
304 CancelButtonCaption: string;
305
306Procedure OnLanguageEvent(Language: TLanguageFile; const Apply: boolean);
307var
308 tmpPrefix : String;
309begin
310 if Language = nil then
311 begin
312 OKButtonCaption := '~OK';
313 CancelButtonCaption :='~Cancel';
314 end
315 else
316 begin
317 tmpPrefix := 'TextInputForm' + LANGUAGE_LABEL_DELIMITER; // use messageform captions
318 Language.LL(Apply, OKButtonCaption, tmpPrefix + 'OKButtonCaption', '~OK');
319 Language.LL(Apply, CancelButtonCaption, tmpPrefix + 'CancelButtonCaption', '~Cancel');
320 end;
321end;
322
323type
324 TACLQueryDialog = class( TDialog )
325 FEdit: TEdit;
326 FMessageLabel: TLabel;
327 FOKButton: TButton;
328 FCancelButton: TButton;
329 procedure SetupComponent; override;
330 procedure SetupShow; override;
331 end;
332
333procedure TACLQueryDialog.SetupComponent;
334begin
335 inherited SetupComponent;
336
337 Name := 'TextInputForm';
338
339 ClientWidth := 340;
340 ClientHeight := 120;
341
342 FMessageLabel := InsertLabel( self, 10, 90, 320, 20, '' );
343
344 FEdit := TEdit.Create( self );
345 FEdit.SetWindowPos( 10, 60, 320, 20 );
346 FEdit.parent := self;
347 FEdit.TabOrder := 0;
348 FEdit.AutoSize := true;
349
350 FOKButton := InsertButton( self, 10, 10, 90, 30, OKButtonCaption, '' );
351 FOKButton.Name := 'OKButton';
352 FOKButton.ModalResult := mrOK;
353 FOKButton.Default := true;
354 FOKButton.TabOrder := 1;
355
356 FCancelButton := InsertButton( self, 120, 10, 90, 30, CancelButtonCaption, '' );
357 FCancelButton.Name := 'CancelButon';
358 FCancelButton.ModalResult := mrCancel;
359 FCancelButton.Cancel := true;
360 FCancelButton.TabOrder := 2;
361
362end;
363
364procedure TACLQueryDialog.SetupShow;
365begin
366 ScaleForm( self, 11, 16 );
367 FOKButton.Default := true;
368 FEdit.Focus;
369end;
370
371Var
372 QueryDlg: TACLQueryDialog;
373
374// This is a copy of InputQuery from SPCC with the following changes:
375// - slight layout mods
376// - normal buttons instead of bitmap buttons
377// - buttons are centered like my other popup dialogs
378Function DoInputQuery( Const ACaption: String;
379 Const APrompt: String;
380 Var Value: String ): Boolean;
381Begin
382 if QueryDlg = nil then
383 begin
384 QueryDlg := TACLQueryDialog.Create( Screen.ActiveForm );
385 end;
386
387 QueryDlg.Caption := ACaption;
388 QueryDlg.FMessageLabel.Caption := APrompt;
389 QueryDlg.FEdit.Text := Value;
390
391 QueryDlg.Execute;
392 Case QueryDlg.ModalResult Of
393 cmOk:
394 Begin
395 Value := QueryDlg.FEdit.Text;
396 Result := True;
397 End;
398
399 Else
400 Begin
401 Result := False;
402 End;
403 End; {Case}
404
405End;
406
407{$endif}
408
409{$ifdef os2}
410Initialization
411 RegisterProcForLanguages( OnLanguageEvent );
412
413 // load our defaults in case the app using us doesn't know about languages
414 OnLanguageEvent( nil, true );
415
416Finalization
417
418// I think application .Destroy will do this.
419// if QueryDlg <> nil then
420// QueryDlg.Destroy;
421
422{$endif}
423
424End.
Note: See TracBrowser for help on using the repository browser.