DBNavigator: start implementing customizable images (issue )

git-svn-id: trunk@39065 -
This commit is contained in:
bart 2012-10-13 12:11:48 +00:00
parent 5a129e09c3
commit 1e136f3133
2 changed files with 37 additions and 1 deletions

View File

@ -39,7 +39,7 @@ uses
Types, Classes, SysUtils, DB,
LCLStrConsts, LCLProc, LMessages, LCLType, LResources, GraphType,
Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons, MaskEdit, ExtCtrls,
Calendar, Variants;
Calendar, Variants, ImgList;
Type
{ TFieldDataLink }
@ -1138,6 +1138,8 @@ type
FConfirmDelete: Boolean;
FUpdateButtonsNeeded: boolean;
FShowButtonHints: boolean;
FImages: TCustomImageList;
FImageChangeLink: TChangeLink;
procedure DefaultHintsChanged(Sender: TObject);
function GetDataSource: TDataSource;
function GetHints: TStrings;
@ -1145,10 +1147,12 @@ type
procedure SetDirection(const AValue: TDBNavButtonDirection);
procedure SetFlat(const AValue: Boolean);
procedure SetHints(const AValue: TStrings);
procedure SetImages(AValue: TCustomImageList);
procedure SetOptions(AValue: TDBNavigatorOptions);
procedure SetShowButtonHints(const AValue: boolean);
procedure SetVisibleButtons(const AValue: TDBNavButtonSet);
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
procedure ImageListChange(Sender: TObject);
protected
Buttons: array[TDBNavButtonType] of TDBNavButton;
FocusableButtons: array[TDBNavButtonType] of TDBNavFocusableButton;
@ -1182,6 +1186,7 @@ type
property VisibleButtons: TDBNavButtonSet read FVisibleButtons
write SetVisibleButtons default DefaultDBNavigatorButtons;
property ShowButtonHints: boolean read FShowButtonHints write SetShowButtonHints default true;
property Images: TCustomImageList read FImages write SetImages;
end;
@ -1276,6 +1281,7 @@ type
property TabStop default False;
property Visible;
property VisibleButtons;
property Images;
end;

View File

@ -116,6 +116,20 @@ begin
FHints.Assign(AValue);
end;
procedure TDBCustomNavigator.SetImages(AValue: TCustomImageList);
begin
if FImages = AValue then Exit;
if FImages <> nil then
FImages.UnRegisterChanges(FImageChangeLink);
FImages := AValue;
if FImages <> nil then
begin
FImages.RegisterChanges(FImageChangeLink);
FImages.FreeNotification(Self);
end;
UpdateButtons; //?????
end;
procedure TDBCustomNavigator.SetOptions(AValue: TDBNavigatorOptions);
begin
if FOptions=AValue then Exit;
@ -152,6 +166,11 @@ begin
Message.Result := PtrUInt(FDataLink);
end;
procedure TDBCustomNavigator.ImageListChange(Sender: TObject);
begin
UpdateButtons; //????
end;
procedure TDBCustomNavigator.DataChanged;
var
PriorEnable, NextEnable: Boolean;
@ -266,7 +285,11 @@ begin
Buttons[CurButtonType]:=CurButton;
if CurButtonType in [nbPrior,nbNext] then
CurButton.NavStyle:=CurButton.NavStyle+[nsAllowTimer];
//Load default images
CurButton.LoadGlyphFromLazarusResource(DBNavButtonResourceName[CurButtonType]);
//Apply custom images if available
if Assigned(FImages) and (Ord(CurButtontype) < FImages.Count) then
FImages.GetBitmap(Ord(CurButtonType), CurButton.Glyph);
CurButton.NumGlyphs:=1;
CurButton.Parent:=Self;
CurButton.OnClick:=@ButtonClickHandler;
@ -295,7 +318,11 @@ begin
FocusableButtons[CurButtonType]:=CurFocusableButton;
if CurButtonType in [nbPrior,nbNext] then
CurFocusableButton.NavStyle:=CurFocusableButton.NavStyle+[nsAllowTimer];
//Load default images
CurFocusableButton.LoadGlyphFromLazarusResource(DBNavButtonResourceName[CurButtonType]);
//Apply custom images if available
if Assigned(FImages) and (Ord(CurButtontype) < FImages.Count) then
FImages.GetBitmap(Ord(CurButtonType), CurFocusableButton.Glyph);
CurFocusableButton.NumGlyphs:=1;
CurFocusableButton.TabStop := True;
CurFocusableButton.Parent:=Self;
@ -421,6 +448,8 @@ begin
FShowButtonHints:=true;
TStringList(FHints).OnChange:=@HintsChanged;
FDefaultHints:=TStringList.Create;
FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := @ImageListChange;
BevelOuter:=bvNone;
BevelInner:=bvNone;
FConfirmDelete:=True;
@ -436,6 +465,7 @@ begin
FDataLink.Destroy;
FHints.Destroy;
FDefaultHints.Destroy;
FImageChangeLink.Destroy;
inherited Destroy;
end;