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