source: branches/pre_reorg/Components/ACLMessageForm.pas

Last change on this file was 15, checked in by RBRi, 19 years ago

+ components stuff

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