mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-01 07:13:59 +02:00
Implements support for using TDBNavigator with the keyboard if the option noFocusableButtons is activated
git-svn-id: trunk@31874 -
This commit is contained in:
parent
bfd5cb4f0e
commit
4261fe84cb
@ -1094,6 +1094,7 @@ Type
|
||||
|
||||
type
|
||||
TDBNavButton = class;
|
||||
TDBNavFocusableButton = class;
|
||||
TDBNavDataLink = class;
|
||||
|
||||
TDBNavGlyph = (ngEnabled, ngDisabled);
|
||||
@ -1102,7 +1103,9 @@ type
|
||||
TDBNavButtonSet = set of TDBNavButtonType;
|
||||
TDBNavButtonStyle = set of (nsAllowTimer, nsFocusRect);
|
||||
TDBNavButtonDirection = (nbdHorizontal,nbdVertical);
|
||||
|
||||
TDBNavigatorOption = (noFocusableButtons);
|
||||
TDBNavigatorOptions = set of TDBNavigatorOption;
|
||||
|
||||
// for Delphi compatibility
|
||||
TNavigateBtn = TDBNavButtonType;
|
||||
|
||||
@ -1144,6 +1147,7 @@ type
|
||||
FUpdateButtonsNeeded: boolean;
|
||||
FUpdateButtonsLock: integer;
|
||||
FOriginalHints: String;
|
||||
FOptions: TDBNavigatorOptions;
|
||||
procedure DefaultHintsChanged(Sender: TObject);
|
||||
function GetDataSource: TDataSource;
|
||||
function GetHints: TStrings;
|
||||
@ -1156,6 +1160,7 @@ type
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
protected
|
||||
Buttons: array[TDBNavButtonType] of TDBNavButton;
|
||||
FocusableButtons: array[TDBNavButtonType] of TDBNavFocusableButton;
|
||||
procedure DataChanged; virtual;
|
||||
procedure EditingChanged; virtual;
|
||||
procedure ActiveChanged; virtual;
|
||||
@ -1182,6 +1187,7 @@ type
|
||||
property Direction: TDBNavButtonDirection read FDirection write SetDirection default nbdHorizontal;
|
||||
property Flat: Boolean read FFlat write SetFlat default False;
|
||||
property Hints: TStrings read GetHints write SetHints;
|
||||
property Options: TDBNavigatorOptions read FOptions write FOptions;
|
||||
property OnClick: TDBNavClickEvent read FOnNavClick write FOnNavClick;
|
||||
property VisibleButtons: TDBNavButtonSet read FVisibleButtons
|
||||
write SetVisibleButtons default DefaultDBNavigatorButtons;
|
||||
@ -1202,6 +1208,16 @@ type
|
||||
property Index: TDBNavButtonType read FIndex write FIndex;
|
||||
end;
|
||||
|
||||
{ TDBNavFocusableButton }
|
||||
|
||||
TDBNavFocusableButton = class(TBitBtn)
|
||||
private
|
||||
FIndex: TDBNavButtonType;
|
||||
FNavStyle: TDBNavButtonStyle;
|
||||
public
|
||||
property NavStyle: TDBNavButtonStyle read FNavStyle write FNavStyle;
|
||||
property Index: TDBNavButtonType read FIndex write FIndex;
|
||||
end;
|
||||
|
||||
{ TNavDataLink }
|
||||
|
||||
@ -1259,6 +1275,7 @@ type
|
||||
property OnMouseUp;
|
||||
property OnResize;
|
||||
property OnStartDrag;
|
||||
property Options;
|
||||
property ParentColor;
|
||||
property ParentFont;
|
||||
property ParentShowHint;
|
||||
|
@ -137,7 +137,10 @@ begin
|
||||
if FVisibleButtons=AValue then exit;
|
||||
FVisibleButtons:=AValue;
|
||||
for CurButton:=Low(Buttons) to High(Buttons) do
|
||||
begin
|
||||
Buttons[CurButton].Visible:=CurButton in FVisibleButtons;
|
||||
FocusableButtons[CurButton].Visible:=CurButton in FVisibleButtons;
|
||||
end;
|
||||
if not (csLoading in ComponentState) then
|
||||
UpdateButtons;
|
||||
end;
|
||||
@ -153,6 +156,7 @@ var
|
||||
begin
|
||||
PriorEnable:=Enabled and FDataLink.Active and not FDataLink.DataSet.BOF;
|
||||
NextEnable:=Enabled and FDataLink.Active and not FDataLink.DataSet.EOF;
|
||||
|
||||
Buttons[nbFirst].Enabled:=PriorEnable;
|
||||
Buttons[nbPrior].Enabled:=PriorEnable;
|
||||
Buttons[nbNext].Enabled:=NextEnable;
|
||||
@ -160,6 +164,12 @@ begin
|
||||
Buttons[nbDelete].Enabled:=Enabled and FDataLink.Active
|
||||
and FDataLink.DataSet.CanModify
|
||||
and (not (FDataLink.DataSet.BOF and FDataLink.DataSet.EOF));
|
||||
|
||||
FocusableButtons[nbFirst].Enabled:=PriorEnable;
|
||||
FocusableButtons[nbPrior].Enabled:=PriorEnable;
|
||||
FocusableButtons[nbNext].Enabled:=NextEnable;
|
||||
FocusableButtons[nbLast].Enabled:=NextEnable;
|
||||
FocusableButtons[nbDelete].Enabled:=Buttons[nbDelete].Enabled;
|
||||
end;
|
||||
|
||||
procedure TDBCustomNavigator.EditingChanged;
|
||||
@ -167,21 +177,34 @@ var
|
||||
CanModify: Boolean;
|
||||
begin
|
||||
CanModify:=Enabled and FDataLink.Active and FDataLink.DataSet.CanModify;
|
||||
|
||||
Buttons[nbInsert].Enabled:=CanModify;
|
||||
Buttons[nbEdit].Enabled:=CanModify and not FDataLink.Editing;
|
||||
Buttons[nbPost].Enabled:=CanModify and FDataLink.Editing;
|
||||
Buttons[nbCancel].Enabled:=CanModify and FDataLink.Editing;
|
||||
Buttons[nbRefresh].Enabled:=CanModify;
|
||||
|
||||
FocusableButtons[nbInsert].Enabled:=CanModify;
|
||||
FocusableButtons[nbEdit].Enabled:=CanModify and not FDataLink.Editing;
|
||||
FocusableButtons[nbPost].Enabled:=CanModify and FDataLink.Editing;
|
||||
FocusableButtons[nbCancel].Enabled:=CanModify and FDataLink.Editing;
|
||||
FocusableButtons[nbRefresh].Enabled:=CanModify;
|
||||
end;
|
||||
|
||||
procedure TDBCustomNavigator.ActiveChanged;
|
||||
var
|
||||
CurButton: TDBNavButtonType;
|
||||
begin
|
||||
if not (Enabled and FDataLink.Active) then begin
|
||||
if not (Enabled and FDataLink.Active) then
|
||||
begin
|
||||
for CurButton:=Low(Buttons) to High(Buttons) do
|
||||
Buttons[CurButton].Enabled:=False
|
||||
end else begin
|
||||
begin
|
||||
Buttons[CurButton].Enabled:=False;
|
||||
FocusableButtons[CurButton].Enabled:=False;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
DataChanged;
|
||||
EditingChanged;
|
||||
end;
|
||||
@ -209,6 +232,7 @@ procedure TDBCustomNavigator.UpdateButtons;
|
||||
var
|
||||
CurButtonType: TDBNavButtonType;
|
||||
CurButton: TDBNavButton;
|
||||
CurFocusableButton: TDBNavFocusableButton;
|
||||
begin
|
||||
if FUpdateButtonsLock>0
|
||||
then begin
|
||||
@ -223,6 +247,7 @@ begin
|
||||
else
|
||||
ChildSizing.Layout:=cclTopToBottomThenLeftToRight;
|
||||
|
||||
// not-focusable buttons
|
||||
for CurButtonType:=Low(Buttons) to High(Buttons) do
|
||||
begin
|
||||
// create/get button
|
||||
@ -245,7 +270,37 @@ begin
|
||||
CurButton.Flat:=Flat;
|
||||
CurButton.Index:=CurButtonType;
|
||||
CurButton.Visible:=CurButtonType in FVisibleButtons;
|
||||
if not (noFocusableButtons in FOptions) then CurButton.Parent := Self
|
||||
else CurButton.Parent := nil;
|
||||
end;
|
||||
|
||||
// focusable buttons
|
||||
for CurButtonType:=Low(Buttons) to High(Buttons) do
|
||||
begin
|
||||
// create/get button
|
||||
if FocusableButtons[CurButtonType]=nil then
|
||||
begin
|
||||
CurFocusableButton:=TDBNavFocusableButton.Create(Self);
|
||||
//CurFocusableButton.Name:=DBNavButtonResourceName[CurButtonType];
|
||||
FocusableButtons[CurButtonType]:=CurFocusableButton;
|
||||
if CurButtonType in [nbPrior,nbNext] then
|
||||
CurFocusableButton.NavStyle:=CurFocusableButton.NavStyle+[nsAllowTimer];
|
||||
CurFocusableButton.LoadGlyphFromLazarusResource(DBNavButtonResourceName[CurButtonType]);
|
||||
CurFocusableButton.NumGlyphs:=1;
|
||||
CurFocusableButton.TabStop := True;
|
||||
CurFocusableButton.Parent:=Self;
|
||||
CurFocusableButton.OnClick:=@ButtonClickHandler;
|
||||
CurFocusableButton.ControlStyle := CurFocusableButton.ControlStyle + [csNoDesignSelectable];
|
||||
end else
|
||||
CurFocusableButton:=FocusableButtons[CurButtonType];
|
||||
|
||||
// update button properties
|
||||
CurFocusableButton.Index:=CurButtonType;
|
||||
CurFocusableButton.Visible:=CurButtonType in FVisibleButtons;
|
||||
if (noFocusableButtons in FOptions) then CurFocusableButton.Parent := Self
|
||||
else CurFocusableButton.Parent := nil;
|
||||
end;
|
||||
|
||||
EnableAlign;
|
||||
ActiveChanged;
|
||||
end;
|
||||
@ -254,6 +309,7 @@ procedure TDBCustomNavigator.UpdateHints;
|
||||
var
|
||||
CurButton: TDBNavButtonType;
|
||||
DBNavButtonDefaultHint: array[TDBNavButtonType] of string;
|
||||
NewHint: string;
|
||||
|
||||
procedure AssignHintsCaptions;
|
||||
begin
|
||||
@ -282,10 +338,15 @@ begin
|
||||
for CurButton := Low(Buttons) to High(Buttons) do
|
||||
begin
|
||||
if FHints.Count > Ord(CurButton) then
|
||||
Buttons[CurButton].Hint := FHints[Ord(CurButton)]
|
||||
NewHint := FHints[Ord(CurButton)]
|
||||
else
|
||||
Buttons[CurButton].Hint := FDefaultHints[Ord(CurButton)];
|
||||
NewHint := FDefaultHints[Ord(CurButton)];
|
||||
|
||||
Buttons[CurButton].Hint := NewHint;
|
||||
Buttons[CurButton].ShowHint := ShowButtonHints;
|
||||
|
||||
FocusableButtons[CurButton].Hint := NewHint;
|
||||
FocusableButtons[CurButton].ShowHint := ShowButtonHints;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user