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