lcl: initial support for arrow keys, handle CM_WANTSPECIALKEY for tabs and arrows

git-svn-id: trunk@18461 -
This commit is contained in:
paul 2009-01-27 09:05:42 +00:00
parent 5980abdcec
commit 75fcdb8abe
6 changed files with 53 additions and 16 deletions

View File

@ -1029,6 +1029,7 @@ type
procedure CMParentShowHintChanged(var Message: TLMessage); message CM_PARENTSHOWHINTCHANGED; procedure CMParentShowHintChanged(var Message: TLMessage); message CM_PARENTSHOWHINTCHANGED;
procedure CMVisibleChanged(var Message: TLMessage); message CM_VISIBLECHANGED; procedure CMVisibleChanged(var Message: TLMessage); message CM_VISIBLECHANGED;
procedure CMTextChanged(var Message: TLMessage); message CM_TEXTCHANGED; procedure CMTextChanged(var Message: TLMessage); message CM_TEXTCHANGED;
procedure CMWantSpecialKey(var Message: TLMessage); message CM_WANTSPECIALKEY;
protected protected
// drag and drop // drag and drop
procedure CalculateDockSizes; procedure CalculateDockSizes;

View File

@ -930,7 +930,8 @@ type
anoTabToSelectNext, anoTabToSelectNext,
anoReturnForDefaultControl, anoReturnForDefaultControl,
anoEscapeForCancelControl, anoEscapeForCancelControl,
anoF1ForHelp anoF1ForHelp,
anoArrowToSelectNextInParent
); );
TApplicationNavigationOptions = set of TApplicationNavigationOption; TApplicationNavigationOptions = set of TApplicationNavigationOption;
@ -1160,11 +1161,14 @@ type
procedure IntfAppRestore; procedure IntfAppRestore;
procedure IntfDropFiles(const FileNames: Array of String); procedure IntfDropFiles(const FileNames: Array of String);
public public
procedure DoArrowKey(AControl: TWinControl; var Key: Word;
Shift: TShiftState);
procedure DoEscapeKey(AControl: TWinControl; var Key: Word; procedure DoEscapeKey(AControl: TWinControl; var Key: Word;
Shift: TShiftState); Shift: TShiftState);
procedure DoReturnKey(AControl: TWinControl; var Key: Word; procedure DoReturnKey(AControl: TWinControl; var Key: Word;
Shift: TShiftState); Shift: TShiftState);
procedure DoTabKey(AControl: TWinControl; var Key: Word;Shift: TShiftState); procedure DoTabKey(AControl: TWinControl; var Key: Word;
Shift: TShiftState);
property Active: boolean read GetActive; property Active: boolean read GetActive;
property ApplicationType : TApplicationType read FApplicationType write FApplicationType; property ApplicationType : TApplicationType read FApplicationType write FApplicationType;

View File

@ -118,7 +118,7 @@ begin
FIcon := TIcon.Create; FIcon := TIcon.Create;
FIcon.OnChange := @IconChanged; FIcon.OnChange := @IconChanged;
FNavigation := [anoTabToSelectNext,anoReturnForDefaultControl, FNavigation := [anoTabToSelectNext,anoReturnForDefaultControl,
anoEscapeForCancelControl,anoF1ForHelp]; anoEscapeForCancelControl,anoF1ForHelp,anoArrowToSelectNextInParent];
ApplicationActionComponent:=Self; ApplicationActionComponent:=Self;
OnMenuPopupHandler:=@MenuPopupHandler; OnMenuPopupHandler:=@MenuPopupHandler;
@ -1445,14 +1445,15 @@ procedure TApplication.ControlKeyDown(Sender: TObject; var Key: Word;
var var
AControl: TWinControl; AControl: TWinControl;
begin begin
if Sender is TWinControl then begin if Sender is TWinControl then
begin
AControl := TWinControl(Sender); AControl := TWinControl(Sender);
if AControl=nil then ;
//debugln('TApplication.ControlKeyDown A ',DbgSName(AControl)); //debugln('TApplication.ControlKeyDown A ',DbgSName(AControl));
FLastKeyDownSender := AControl; FLastKeyDownSender := AControl;
// handle navigation key // handle navigation key
DoTabKey(AControl, Key, Shift); DoTabKey(AControl, Key, Shift);
DoArrowKey(AControl, Key, Shift);
end else end else
FLastKeyDownSender := nil; FLastKeyDownSender := nil;
//DebugLn(['TApplication.ControlKeyDown Sender=',DbgSName(Sender),' Key=',Key,' Shift=',dbgs(Shift)]); //DebugLn(['TApplication.ControlKeyDown Sender=',DbgSName(Sender),' Key=',Key,' Shift=',dbgs(Shift)]);
@ -1730,6 +1731,20 @@ begin
TDropFilesEvent(FApplicationHandlers[ahtDropFiles][i])(Self,Filenames); TDropFilesEvent(FApplicationHandlers[ahtDropFiles][i])(Self,Filenames);
end; end;
procedure TApplication.DoArrowKey(AControl: TWinControl; var Key: Word;
Shift: TShiftState);
begin
if (Key in [VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN]) and (Shift = []) and
(anoArrowToSelectNextInParent in Navigation) and AControl.Focused and
(AControl.Parent <> nil) and
(AControl.Perform(CM_WANTSPECIALKEY, Key, 0) = 0) then
begin
// traverse controls inside parent
AControl.Parent.SelectNext(AControl, Key in [VK_RIGHT, VK_DOWN], False);
Key := VK_UNKNOWN;
end;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
procedure TApplication.DoBeforeMouseMessage(CurMouseControl: TControl); procedure TApplication.DoBeforeMouseMessage(CurMouseControl: TControl);
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -1823,12 +1838,13 @@ end;
procedure TApplication.DoTabKey(AControl: TWinControl; var Key: Word; procedure TApplication.DoTabKey(AControl: TWinControl; var Key: Word;
Shift: TShiftState); Shift: TShiftState);
begin begin
if (Key=VK_Tab) and ((Shift-[ssShift])=[]) if (Key = VK_TAB) and ((Shift - [ssShift]) = []) and
and (anoTabToSelectNext in Navigation) (anoTabToSelectNext in Navigation) and AControl.Focused and
and AControl.Focused then (AControl.Perform(CM_WANTSPECIALKEY, Key, 0) = 0) then
begin begin
Key:=VK_UNKNOWN; // traverse tabstop controls inside form
AControl.PerformTab(not (ssShift in Shift)); AControl.PerformTab(not (ssShift in Shift));
Key := VK_UNKNOWN;
end; end;
end; end;

View File

@ -51,6 +51,12 @@ begin
fLastCheckedOnChange:=Checked; fLastCheckedOnChange:=Checked;
end; end;
procedure TButtonControl.CMWantSpecialKey(var Message: TLMessage);
begin
// button controls dont want any special keys
Message.Result := 0;
end;
procedure TButtonControl.Click; procedure TButtonControl.Click;
begin begin
DoOnChange; DoOnChange;

View File

@ -708,6 +708,15 @@ begin
TextChanged; TextChanged;
end; end;
procedure TControl.CMWantSpecialKey(var Message: TLMessage);
begin
// by default control does not want to handle VK_TAB itself
if Message.wParam = VK_TAB then
Message.Result := 0
else
Message.Result := 1;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TControl.CMParentColorChanged TControl.CMParentColorChanged

View File

@ -1017,6 +1017,7 @@ type
procedure Click; override; procedure Click; override;
function ColorIsStored: boolean; override; function ColorIsStored: boolean; override;
procedure Loaded; override; procedure Loaded; override;
procedure CMWantSpecialKey(var Message: TLMessage); message CM_WANTSPECIALKEY;
protected protected
property Checked: Boolean read GetChecked write SetChecked stored IsCheckedStored default False; property Checked: Boolean read GetChecked write SetChecked stored IsCheckedStored default False;
property ClicksDisabled: Boolean read FClicksDisabled write FClicksDisabled; property ClicksDisabled: Boolean read FClicksDisabled write FClicksDisabled;