mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-09 20:47:58 +02:00
lcl: add helper function to get stock button and dialog images and captions:
- GetButtonCaption, - GetButtonIcon - GetDialogCaption - GetDialogIcon git-svn-id: trunk@19784 -
This commit is contained in:
parent
97ab0c3f82
commit
beb1e199bb
@ -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]);
|
||||
|
@ -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}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user