Просмотр кода
Идентификатор: 30d3b5ea Описание: MetaDialogs.pas Код загружен: 3 июля 2011, 17:23 (mirt.steelwater)
unit MetaDialogs; {******************************************************************************} {* Meta Dialog Window Unit *} {* Revolutionary Confederation of Anarcho Syndicalists *} {* Written by: black.rabbit 2011 *} {******************************************************************************} interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Buttons, ImgList, acPNG, sSkinProvider, sSkinManager, sPanel, sButton, sBitBtn, acAlphaImageList, { kernel units } VarRecs, EClasses; { иконки } const dlgCustom = -1; dlgWarning = 0; dlgError = 1; dlgInformation = 2; dlgConfirmation = 3; dlgHelp = 4; dlgLogin = 5; dlgPassword = 6; dlgRandom = 7; dlgSettings = 8; dlgAdd = 9; dlgEdit = 10; dlgDelete = 11; { кнопки } const bntCustom = -1; btnOK = 0; btnCancel = 1; type { кнопка диалогового окна } {$M+} EDialogButton = class (EClass) end; CDialogButton = class of TDialogButton; PDialogButton = ^TDialogButton; TDialogButton = class (TsBitBtn) private f_ModalResult: Integer; public class procedure _raise (anArgs: array of const; const anEGUID: String = ''); overload; virtual; class procedure _raise (anArgs: array of const; anEGUID: array of const); overload; virtual; public constructor Create (anOwner: TComponent; aCaption: String = ''; anImageList: TCustomImageList = NIL; anImageIndex: Integer = dlgCustom; aModalResult: Integer = mrNone; anOnClick: TNotifyEvent = NIL); overload; virtual; constructor Create (anOwner: TComponent; anArgs: array of const; anImageList: TCustomImageList = NIL; anOnClick: TNotifyEvent = NIL); overload; virtual; destructor Destroy; override; public property ModalResult: Integer read f_ModalResult write f_ModalResult; end; {$M-} resourcestring ERR_TDIALOGBUTTON_CREATE = 'Ошибка создания!'; ERR_TDIALOGBUTTON_DESTROY = 'Ошибка уничтожения!'; type { диалоговое окно } {$M+} EMetaDialog = class (EClass) end; CMetaDialog = class of TMetaDialog; PMetaDialog = ^TMetaDialog; TMetaDialog = class (TForm) SkinBlack: TsSkinManager; SkinProvider: TsSkinProvider; pnlBack: TsPanel; imgIcon: TImage; imgIcons: TsAlphaImageList; pnlControl: TsPanel; imgButtons: TsAlphaImageList; private f_MinWidth: Integer; f_MaxWidth: Integer; f_MinHeight: Integer; f_MaxHeight: Integer; f_IconIndex: Integer; f_Buttons: TList; public class procedure _raise (anArgs: array of const; const anEGUID: String = ''); overload; virtual; class procedure _raise (anArgs: array of const; anEGUID: array of const); overload; virtual; protected procedure WMGetMinMaxInfo (var M: TWMGetMinMaxInfo); message WM_GETMINMAXINFO; procedure OnButtonClick (Sender: TObject); virtual; public procedure GetData (anArgs: array of const; aButtons: array of const); overload; virtual; procedure SetData (anIndex: Integer); overload; virtual; public constructor Create (anArgs: array of const; aButtons: array of const); virtual; destructor Destroy; override; class function Open (anArgs: array of const; aButtons: array of const) : Integer; overload; virtual; public property minWidth: Integer read f_MinWidth write f_MinWidth; property maxWidth: Integer read f_MaxWidth write f_MaxWidth; property minHeight: Integer read f_MinHeight write f_MinHeight; property maxHeight: Integer read f_MaxHeight write f_MaxHeight; property IconIndex: Integer read f_IconIndex write f_IconIndex; end; {$M-} resourcestring ERR_TMETADIALOG_CREATE = 'Ошибка создания!'; ERR_TMETADIALOG_DESTROY = 'Ошибка уничтожения!'; ERR_TMETADIALOG_NOTIFY = 'Ошибка обработки события!'; ERR_TMETADIALOG_RESIZE = 'Ошибка изменения размера!'; ERR_TMETADIALOG_GET_DATA = 'Ошибка чтения данных!'; ERR_TMETADIALOG_SET_DATA = 'Ошибка записи данных!'; implementation {$R *.dfm} class procedure TDialogButton._raise (anArgs: array of const; const anEGUID: String = ''); begin raise EDialogButton.Create ( _([self],anArgs), anEGUID ); end; class procedure TDialogButton._raise (anArgs: array of const; anEGUID: array of const); begin raise EDialogButton.Create ( _([self],anArgs), anEGUID ); end; constructor TDialogButton.Create (anOwner: TComponent; aCaption: String = ''; anImageList: TCustomImageList = NIL; anImageIndex: Integer = dlgCustom; aModalResult: Integer = mrNone; anOnClick: TNotifyEvent = NIL); begin try inherited Create (anOwner); Parent := TWinControl (Owner); Caption := aCaption; Width := Round ( Length (Caption) * Font.Size + 24 ); Align := alRight; AlignWithMargins := TRUE; Margins.Bottom := 5; Margins.Left := 5; Margins.Right := 5; Margins.Top := 5; Images := anImageList; ImageIndex := ImageIndex; if Assigned (Images) then Width := Width + Images.Width; ModalResult := aModalResult; OnClick := anOnClick; except on E: Exception do _raise (['Create',ERR_TDIALOGBUTTON_CREATE,E], ['{366A0B63-4F7A-46D3-8E91-0A0714376342}']); end; end; constructor TDialogButton.Create (anOwner: TComponent; anArgs: array of const; anImageList: TCustomImageList = NIL; anOnClick: TNotifyEvent = NIL); begin try Create (anOwner,'',anImageList,dlgCustom,mrNone,anOnClick); { первый параметр - заголовок } if notEmpty (0,anArgs) then Caption := toString (anArgs [0]); Width := Round ( Length (Caption) * Font.Size + 24 ); if Assigned (Images) then Width := Width + Images.Width; { второй параметр - иконка } if notEmpty (1,anArgs) then ImageIndex := toInteger (anArgs [1]); { третий параметр - результат } ModalResult := mrNone; if notEmpty (2,anArgs) then ModalResult := toInteger (anArgs [2]); except on E: Exception do _raise (['Create',ERR_TDIALOGBUTTON_CREATE,E], ['{F28E1C8D-DA29-4BA3-9004-473FA018C3B8}']); end; end; destructor TDialogButton.Destroy; begin try inherited Destroy; except on E: Exception do _raise (['Destroy',ERR_TDIALOGBUTTON_DESTROY,E], ['{BC9F7330-7CA8-41F6-BA1E-541B1F440F9C}']); end; end; class procedure TMetaDialog._raise (anArgs: array of const; const anEGUID: String = ''); begin raise EMetaDialog.Create ( _([self],anArgs), anEGUID ); end; class procedure TMetaDialog._raise (anArgs: array of const; anEGUID: array of const); begin raise EMetaDialog.Create ( _([self],anArgs), anEGUID ); end; procedure TMetaDialog.WMGetMinMaxInfo (var M: TWMGetMinMaxInfo); begin try with M.MinMaxInfo^ do begin PTMaxSize.X := maxWidth; PTMaxPosition.X := 0; PTMaxTrackSize.X := maxWidth; PTMinTrackSize.X := minWidth; PTMaxSize.Y := maxHeight; PTMaxPosition.Y := 0; PTMaxTrackSize.Y := maxHeight; PTMinTrackSize.Y := minHeight; end; except on E: Exception do _raise (['WMGetMinMaxInfo',ERR_TMETADIALOG_RESIZE,E], ['{A2DEF069-797D-472F-9F6B-05E35EAED098}']); end; end; procedure TMetaDialog.OnButtonClick (Sender: TObject); begin try SetData ( TDialogButton (Sender).ModalResult ); except on E: Exception do _raise (['OnButtonClick',ERR_TMETADIALOG_NOTIFY,E], ['{C0EC7356-493B-40EA-B5B3-28BEB743402C}']); end; end; procedure TMetaDialog.GetData (anArgs: array of const; aButtons: array of const); var I : Integer; Button : TDialogButton; begin try { первый параметр - заголовок } if not isEmpty (0,anArgs) then Caption := toString (anArgs [0]); { второй параметр - иконка } if not isEmpty (1,anArgs) then begin IconIndex := toInteger (anArgs [1]); if ( IconIndex > dlgCustom ) then imgIcons.GetBitmap32 (IconIndex, imgIcon.Picture.Bitmap); end; { остальные параметры - кнопки } for I := 0 to High (aButtons) do if not isEmpty (I,aButtons) then begin Button := TDialogButton.Create( pnlControl, toArrayOfConst (aButtons [I]), imgButtons, OnButtonClick ); f_Buttons.Add (Button); end; except on E: Exception do _raise (['GetData',ERR_TMETADIALOG_GET_DATA,E], ['{879F7E53-19B5-4EC1-B9B0-B1BA90BAAFA1}']); end; end; procedure TMetaDialog.SetData (anIndex: Integer); begin try case anIndex of mrNone : { do nothing }; else ModalResult := anIndex; end; except on E: Exception do _raise (['SetData',ERR_TMETADIALOG_SET_DATA,E], ['{03635422-DA19-4900-8573-3180F3C5560D}']); end; end; constructor TMetaDialog.Create (anArgs: array of const; aButtons: array of const); begin try inherited Create (NIL); minWidth := 400; maxWidth := Screen.Width; minHeight := 200; maxHeight := Screen.Height; Left := (Screen.Width - Width) div 2; Top := (Screen.Height - Height) div 2; Caption := ''; IconIndex := dlgCustom; f_Buttons := TList.Create; except on E: Exception do _raise (['Create',ERR_TMETADIALOG_CREATE,E], ['{17AE0EBC-7DA6-45E1-B0A4-37462556EBAF}']); end; end; destructor TMetaDialog.Destroy; var I : Integer; begin try for I := 0 to f_Buttons.Count - 1 do TDialogButton (f_Buttons.Items [I]).Free; f_Buttons.Clear; FreeAndNil (f_Buttons); inherited Destroy; except on E: Exception do _raise (['Destroy',ERR_TMETADIALOG_DESTROY,E], ['{1AE3B7BF-E68A-4D0F-9FB3-024FDA4B6741}']); end; end; class function TMetaDialog.Open (anArgs: array of const; aButtons: array of const) : Integer; begin with Create (anArgs,aButtons) do try GetData (anArgs,aButtons); Result := ShowModal; finally Free; end; end; end.