source: branches/pre_reorg/Components/ACLDialogs.pas

Last change on this file was 401, checked in by RBRi, 9 years ago

remove usage of ACLStringUtility

  • Property svn:eol-style set to native
File size: 10.4 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);
307begin
308 if Language <> nil then
309 Language.Prefix := 'TextInputForm.';
310
311 LoadString( Language, Apply, OKButtonCaption, 'OKButtonCaption', '~OK' );
312 LoadString( Language, Apply, CancelButtonCaption, 'CancelButtonCaption', '~Cancel' );
313end;
314
315type
316 TACLQueryDialog = class( TDialog )
317 FEdit: TEdit;
318 FMessageLabel: TLabel;
319 FOKButton: TButton;
320 FCancelButton: TButton;
321 procedure SetupComponent; override;
322 procedure SetupShow; override;
323 end;
324
325procedure TACLQueryDialog.SetupComponent;
326begin
327 inherited SetupComponent;
328
329 Name := 'TextInputForm';
330
331 ClientWidth := 340;
332 ClientHeight := 120;
333
334 FMessageLabel := InsertLabel( self, 10, 90, 320, 20, '' );
335
336 FEdit := TEdit.Create( self );
337 FEdit.SetWindowPos( 10, 60, 320, 20 );
338 FEdit.parent := self;
339 FEdit.TabOrder := 0;
340 FEdit.AutoSize := true;
341
342 FOKButton := InsertButton( self, 10, 10, 90, 30, OKButtonCaption, '' );
343 FOKButton.Name := 'OKButton';
344 FOKButton.ModalResult := mrOK;
345 FOKButton.Default := true;
346 FOKButton.TabOrder := 1;
347
348 FCancelButton := InsertButton( self, 120, 10, 90, 30, CancelButtonCaption, '' );
349 FCancelButton.Name := 'CancelButon';
350 FCancelButton.ModalResult := mrCancel;
351 FCancelButton.Cancel := true;
352 FCancelButton.TabOrder := 2;
353
354end;
355
356procedure TACLQueryDialog.SetupShow;
357begin
358 ScaleForm( self, 11, 16 );
359 FOKButton.Default := true;
360 FEdit.Focus;
361end;
362
363Var
364 QueryDlg: TACLQueryDialog;
365
366// This is a copy of InputQuery from SPCC with the following changes:
367// - slight layout mods
368// - normal buttons instead of bitmap buttons
369// - buttons are centered like my other popup dialogs
370Function DoInputQuery( Const ACaption: String;
371 Const APrompt: String;
372 Var Value: String ): Boolean;
373Begin
374 if QueryDlg = nil then
375 begin
376 QueryDlg := TACLQueryDialog.Create( Screen.ActiveForm );
377 end;
378
379 QueryDlg.Caption := ACaption;
380 QueryDlg.FMessageLabel.Caption := APrompt;
381 QueryDlg.FEdit.Text := Value;
382
383 QueryDlg.Execute;
384 Case QueryDlg.ModalResult Of
385 cmOk:
386 Begin
387 Value := QueryDlg.FEdit.Text;
388 Result := True;
389 End;
390
391 Else
392 Begin
393 Result := False;
394 End;
395 End; {Case}
396
397End;
398
399{$endif}
400
401{$ifdef os2}
402Initialization
403 RegisterProcForLanguages( OnLanguageEvent );
404
405 // load our defaults in case the app using us doesn't know about languages
406 OnLanguageEvent( nil, true );
407
408Finalization
409
410// I think application .Destroy will do this.
411// if QueryDlg <> nil then
412// QueryDlg.Destroy;
413
414{$endif}
415
416End.
Note: See TracBrowser for help on using the repository browser.