[15] | 1 | unit ACLMessageForm;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | Uses
|
---|
| 6 | CustomMemo,
|
---|
| 7 | Classes, Forms, Graphics, StdCtrls,
|
---|
| 8 | Buttons, ExtCtrls, Dialogs,
|
---|
| 9 | SystemIconUnit;
|
---|
| 10 |
|
---|
| 11 | Type
|
---|
| 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 | Implementation
|
---|
| 43 |
|
---|
| 44 | Uses
|
---|
| 45 | SysUtils,
|
---|
| 46 | ACLLanguageUnit;
|
---|
| 47 |
|
---|
| 48 | {$R DialogIcons}
|
---|
| 49 |
|
---|
| 50 | const
|
---|
| 51 | spc = 10; // spacing
|
---|
| 52 |
|
---|
| 53 | var
|
---|
| 54 | OKButtonCaption: string;
|
---|
| 55 | CancelButtonCaption: string;
|
---|
| 56 | HelpButtonCaption: string;
|
---|
| 57 | YesButtonCaption: string;
|
---|
| 58 | NoButtonCaption: string;
|
---|
| 59 |
|
---|
| 60 | Procedure OnLanguageEvent( Language: TLanguageFile;
|
---|
| 61 | const Apply: boolean );
|
---|
| 62 | begin
|
---|
| 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' );
|
---|
| 71 | end;
|
---|
| 72 |
|
---|
| 73 | Procedure TMessageForm.SetupComponent;
|
---|
| 74 | begin
|
---|
| 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 |
|
---|
| 103 | end;
|
---|
| 104 |
|
---|
| 105 | Procedure TMessageForm.HelpButtonOnClick (Sender: TObject);
|
---|
| 106 | Var
|
---|
| 107 | ListObject: TObject;
|
---|
| 108 | Index: longint;
|
---|
| 109 | Begin
|
---|
| 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;
|
---|
| 120 | End;
|
---|
| 121 |
|
---|
| 122 | destructor TMessageForm.Destroy;
|
---|
| 123 | Begin
|
---|
| 124 | Inherited Destroy;
|
---|
| 125 | End;
|
---|
| 126 |
|
---|
| 127 | Procedure TMessageForm.SetupShow;
|
---|
| 128 | Var
|
---|
| 129 | TextHeight: longint;
|
---|
| 130 | ImageHeight: longint;
|
---|
| 131 | MessageHeight: longint;
|
---|
| 132 | TotalButtonWidth: longint;
|
---|
| 133 | X: longint;
|
---|
| 134 | DesiredClientHeight: longint;
|
---|
| 135 | Begin
|
---|
| 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 |
|
---|
| 222 | End;
|
---|
| 223 |
|
---|
| 224 | Initialization
|
---|
| 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 |
|
---|
| 233 | end.
|
---|