From beb1e199bbeff1c6ff198e693e7a33ecc0552753 Mon Sep 17 00:00:00 2001 From: paul Date: Sun, 3 May 2009 14:59:50 +0000 Subject: [PATCH] lcl: add helper function to get stock button and dialog images and captions: - GetButtonCaption, - GetButtonIcon - GetDialogCaption - GetDialogIcon git-svn-id: trunk@19784 - --- lcl/buttons.pp | 85 ++++++++++++++++++++++++++++-------- lcl/dialogs.pp | 55 +++++++++++++++++++++++ lcl/include/bitbtn.inc | 36 +++++---------- lcl/include/promptdialog.inc | 50 +-------------------- lcl/lclstrconsts.pas | 4 ++ 5 files changed, 139 insertions(+), 91 deletions(-) diff --git a/lcl/buttons.pp b/lcl/buttons.pp index 306a1fa3a6..276fc1d03f 100644 --- a/lcl/buttons.pp +++ b/lcl/buttons.pp @@ -150,7 +150,7 @@ type procedure SetSpacing(AValue: Integer); procedure RealizeKind; //Return the caption associated with the aKind value. - function GetCaptionOfKind(aKind: TBitBtnKind): String; + function GetCaptionOfKind(AKind: TBitBtnKind): String; protected FButtonGlyph: TButtonGlyph; class procedure WSRegisterClass; override; @@ -395,6 +395,11 @@ var function GetLCLDefaultBtnGlyph(Kind: TBitBtnKind): TGraphic; procedure LoadGlyphFromLazarusResource(AGlyph: TButtonGlyph; const AName: String); +// helper functions (search LCLType for idButton) +function GetButtonCaption(idButton: Integer): String; +function GetDefaultButtonIcon(idButton: Integer): TCustomBitmap; +function GetButtonIcon(idButton: Integer): TCustomBitmap; + procedure Register; implementation @@ -409,33 +414,39 @@ const mrNoToAll, mrYesToAll); BitBtnImages: array[TBitBtnKind] of Longint = ( - idButtonOk, idButtonOk, idButtonCancel, idButtonHelp, idButtonYes, + idButtonBase, idButtonOk, idButtonCancel, idButtonHelp, idButtonYes, idButtonNo, idButtonClose, idButtonAbort, idButtonRetry, idButtonIgnore, idButtonAll, idButtonNoToAll, idButtonYesToAll); - BitBtnResNames: array[TBitBtnKind] of String = + BitBtnResNames: array[idButtonOk..idButtonNoToAll] of String = ( -{bkCustom } '', -{bkOK } 'btn_ok', -{bkCancel } 'btn_cancel', -{bkHelp } 'btn_help', -{bkYes } 'btn_yes', -{bkNo } 'btn_no', -{bkClose } 'btn_close', -{bkAbort } 'btn_abort', -{bkRetry } 'btn_retry', -{bkIgnore } 'btn_ignore', -{bkAll } 'btn_all', -{bkNoToAll } 'btn_no', -{bkYesToAll} 'btn_all' +{idButtonOk } 'btn_ok', +{idButtonCancel } 'btn_cancel', +{idButtonHelp } 'btn_help', +{idButtonYes } 'btn_yes', +{idButtonNo } 'btn_no', +{idButtonClose } 'btn_close', +{idButtonAbort } 'btn_abort', +{idButtonRetry } 'btn_retry', +{idButtonIgnore } 'btn_ignore', +{idButtonAll } 'btn_all', +{idButtonYesToAll} 'btn_all', +{idButtonNoToAll } 'btn_no' ); function GetLCLDefaultBtnGlyph(Kind: TBitBtnKind): TGraphic; +begin + Result := GetDefaultButtonIcon(BitBtnImages[Kind]); +end; + +function GetDefaultButtonIcon(idButton: Integer): TCustomBitmap; begin Result := nil; - if BitBtnResNames[Kind] = '' then + if (idButton < Low(BitBtnResNames)) or (idButton > High(BitBtnResNames)) then Exit; - Result := CreateBitmapFromLazarusResource(BitBtnResNames[Kind]); + if BitBtnResNames[idButton] = '' then + Exit; + Result := CreateBitmapFromLazarusResource(BitBtnResNames[idButton]); end; procedure LoadGlyphFromLazarusResource(AGlyph: TButtonGlyph; const AName: String); @@ -472,6 +483,44 @@ begin end; end; +function GetButtonCaption(idButton: Integer): String; +begin + case idButton of + idButtonOk : Result := rsmbOK; + idButtonCancel : Result := rsmbCancel; + idButtonHelp : Result := rsmbHelp; + idButtonYes : Result := rsmbYes; + idButtonNo : Result := rsmbNo; + idButtonClose : Result := rsmbClose; + idButtonAbort : Result := rsmbAbort; + idButtonRetry : Result := rsmbRetry; + idButtonIgnore : Result := rsmbIgnore; + idButtonAll : Result := rsmbAll; + idButtonYesToAll : Result := rsmbYesToAll; + idButtonNoToAll : Result := rsmbNoToAll; + idButtonOpen : Result := rsmbOpen; + idButtonSave : Result := rsmbSave; + idButtonShield : Result := rsmbUnlock; + else + Result := '?'; + end; +end; + +function GetButtonIcon(idButton: Integer): TCustomBitmap; +var + BitmapHandle, MaskHandle: HBitmap; +begin + if ThemeServices.GetStockImage(idButton, BitmapHandle, MaskHandle) then + begin + Result := TBitmap.Create; + Result.Handle := BitmapHandle; + if MaskHandle <> 0 then + Result.MaskHandle := MaskHandle; + end + else + Result := GetDefaultButtonIcon(idButton); +end; + procedure Register; begin RegisterComponents('Additional',[TBitBtn,TSpeedButton]); diff --git a/lcl/dialogs.pp b/lcl/dialogs.pp index 3adae3d2d8..39ca7f9304 100644 --- a/lcl/dialogs.pp +++ b/lcl/dialogs.pp @@ -529,6 +529,9 @@ function SelectDirectory(out Directory: string; function ExtractColorIndexAndColor(const AColorList: TStrings; const AIndex: Integer; out ColorIndex: Integer; out ColorValue: TColor): Boolean; +// helper functions (search LCLType for idDiag) +function GetDialogCaption(idDiag: Integer): String; +function GetDialogIcon(idDiag: Integer): TCustomBitmap; procedure Register; @@ -547,6 +550,27 @@ const cBitmapY = 10; // y-position for bitmap in messagedialog cLabelSpacing = 10; // distance between icon & label + DialogResult : Array[mrNone..mrYesToAll] of Longint = ( + -1, idButtonOK, idButtonCancel, idButtonAbort, idButtonRetry, + idButtonIgnore, idButtonYes,idButtonNo, idButtonAll, idButtonNoToAll, + idButtonYesToAll); + + DialogButtonKind : Array[idButtonOK..idButtonNoToAll] of TBitBtnKind = ( + bkOk, bkCancel, bkHelp, bkYes, bkNo, bkClose, bkAbort, bkRetry, + bkIgnore, bkAll, bkYesToAll, bkNoToAll); + + MsgDlgCaptions: Array[mtWarning..mtCustom] of String = (rsMtWarning, rsMtError, + rsMtInformation, rsMtConfirmation, rsMtCustom); + + DialogResName: array[idDialogWarning..idDialogConfirm] of String = + ( +{idDialogWarning} 'dialog_warning', +{idDialogError } 'dialog_error', +{idDialogInfo } 'dialog_information', +{idDialogConfirm} 'dialog_confirmation' + ); + + type TBitBtnAccess = class(TBitBtn); @@ -621,6 +645,37 @@ begin Result := MessageDlg(Caption, Text, DlgType, Buttons, 0, DefButton); end; +{** Return the localized or not title of dialog} +function GetDialogCaption(idDiag: Integer): String; +begin + case idDiag of + idDialogWarning : Result := rsMtWarning; + idDialogError : Result := rsMtError; + idDialogInfo : Result := rsMtInformation; + idDialogConfirm : Result := rsMtConfirmation; + idDialogShield : Result := rsMtAuthentication; + else + Result := '?'; + end; +end; + +function GetDialogIcon(idDiag: Integer): TCustomBitmap; +var + BitmapHandle, MaskHandle: HBitmap; +begin + if ThemeServices.GetStockImage(idDiag, BitmapHandle, MaskHandle) then + begin + Result := TBitmap.Create; + Result.Handle := BitmapHandle; + if MaskHandle <> 0 then + Result.MaskHandle := MaskHandle; + end + else + if (idDiag < Low(DialogResName)) or (idDiag > High(DialogResName)) then + Result := nil + else + Result := CreateBitmapFromLazarusResource(DialogResName[idDiag]); +end; {$I colordialog.inc} {$I commondialog.inc} diff --git a/lcl/include/bitbtn.inc b/lcl/include/bitbtn.inc index 27b870c592..cdeb6cccff 100644 --- a/lcl/include/bitbtn.inc +++ b/lcl/include/bitbtn.inc @@ -161,9 +161,9 @@ var CustomGlyph: TGraphic; BitmapHandle, MaskHandle: HBitmap; begin - if (Kind<>bkCustom) then + if (Kind <> bkCustom) then begin - GlyphValid:=false; + GlyphValid := False; // first let the user override if GetDefaultBitBtnGlyph <> nil then @@ -181,11 +181,11 @@ begin // then ask the widgetset if not GlyphValid then begin - if ThemeServices.GetStockImage(BitBtnImages[FKind], BitmapHandle, MaskHandle) then + if ThemeServices.GetStockImage(BitBtnImages[Kind], BitmapHandle, MaskHandle) then begin Glyph.Handle := BitmapHandle; Glyph.MaskHandle := MaskHandle; - GlyphValid := true; + GlyphValid := True; end; end; @@ -203,33 +203,21 @@ begin if not (csLoading in ComponentState) then begin - Caption := GetCaptionOfKind(fKind); - ModalResult := BitBtnModalResults[FKind]; - Default := FKind in [bkOk, bkYes]; - Cancel := FKind in [bkCancel, bkNo]; + Caption := GetCaptionOfKind(Kind); + ModalResult := BitBtnModalResults[Kind]; + Default := Kind in [bkOk, bkYes]; + Cancel := Kind in [bkCancel, bkNo]; end; end; { Return the caption associated with the akind value. This function replaces BitBtnCaption const because the localizing dont work with an const array } -function TCustomBitBtn.GetCaptionOfKind(aKind: TBitBtnKind): String; +function TCustomBitBtn.GetCaptionOfKind(AKind: TBitBtnKind): String; begin - Result:=''; - case aKind of - bkOK : Result:=rsmbOK; - bkCancel : Result:=rsmbCancel; - bkHelp : Result:=rsmbHelp; - bkYes : Result:=rsmbYes; - bkNo : Result:=rsmbNo; - bkClose : Result:=rsmbClose; - bkAbort : Result:=rsmbAbort; - bkRetry : Result:=rsmbRetry; - bkIgnore : Result:=rsmbIgnore; - bkAll : Result:=rsmbAll; - bkNoToAll : Result:=rsmbNoToAll; - bkYesToAll : Result:=rsmbYesToAll; - end; + Result := GetButtonCaption(BitBtnImages[Kind]); + if Result = '?' then + Result := ''; end; class procedure TCustomBitBtn.WSRegisterClass; diff --git a/lcl/include/promptdialog.inc b/lcl/include/promptdialog.inc index b4cf19e99c..49c241e1b9 100644 --- a/lcl/include/promptdialog.inc +++ b/lcl/include/promptdialog.inc @@ -14,27 +14,6 @@ * * ***************************************************************************** } -const - DialogResult : Array[mrNone..mrYesToAll] of Longint = ( - -1, idButtonOK, idButtonCancel, idButtonAbort, idButtonRetry, - idButtonIgnore, idButtonYes,idButtonNo, idButtonAll, idButtonNoToAll, - idButtonYesToAll); - - DialogButtonKind : Array[idButtonOK..idButtonNoToAll] of TBitBtnKind = ( - bkOk, bkCancel, bkHelp, bkYes, bkNo, bkClose, bkAbort, bkRetry, - bkIgnore, bkAll, bkYesToAll, bkNoToAll); - - DialogResName: array[idDialogWarning..idDialogConfirm] of String = - ( -{idDialogWarning} 'dialog_warning', -{idDialogError } 'dialog_error', -{idDialogInfo } 'dialog_information', -{idDialogConfirm} 'dialog_confirmation' - ); - - MsgDlgCaptions: Array[mtWarning..mtCustom] of String = (rsMtWarning, rsMtError, - rsMtInformation, rsMtConfirmation, rsMtCustom); - type @@ -67,33 +46,6 @@ type destructor Destroy; override; end; -{** Return the localized or not title of dialog} -function GetDialogCaption(idDiag: Integer): String; -begin - Result:='?'; - case idDiag of - idDialogWarning : Result:=rsMtWarning; - idDialogError : Result:=rsMtError; - idDialogInfo : Result:=rsMtInformation; - idDialogConfirm : Result:=rsMtConfirmation; - end; -end; - -function GetDialogIcon(idDiag: Integer): TCustomBitmap; -var - BitmapHandle, MaskHandle: HBitmap; -begin - if ThemeServices.GetStockImage(idDiag, BitmapHandle, MaskHandle) then - begin - Result := TBitmap.Create; - Result.Handle := BitmapHandle; - if MaskHandle <> 0 then - Result.MaskHandle := MaskHandle; - end - else - Result := CreateBitmapFromLazarusResource(DialogResName[idDiag]); -end; - procedure TPromptDialog.PromptDialogKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var @@ -873,7 +825,7 @@ begin case DlgType of mtWarning, mtError, mtInformation, mtConfirmation: begin - dlgId:=DialogIds[DlgType]; + dlgId := DialogIds[DlgType]; FBitmap := GetDialogIcon(dlgId); if NewCaption='' then NewCaption := GetDialogCaption(dlgId); diff --git a/lcl/lclstrconsts.pas b/lcl/lclstrconsts.pas index 7da84010e5..cbf3c5cea9 100644 --- a/lcl/lclstrconsts.pas +++ b/lcl/lclstrconsts.pas @@ -44,11 +44,15 @@ resourceString rsMbYesToAll = 'Yes to &All'; rsMbHelp = '&Help'; rsMbClose = '&Close'; + rsmbOpen = '&Open'; + rsmbSave = '&Save'; + rsmbUnlock = '&Unlock'; rsMtWarning = 'Warning'; rsMtError = 'Error'; rsMtInformation = 'Information'; rsMtConfirmation = 'Confirmation'; + rsMtAuthentication = 'Authentication'; rsMtCustom = 'Custom'; // file dialog