summaryrefslogtreecommitdiff
path: root/src/corelib
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2010-09-20 13:03:22 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-09-20 13:03:22 +0200
commit51d6e695e7c311afc3cbe9bc4ac17ba405388d09 (patch)
tree6ff88f92d81ff80c27f4e03641a958bf33308688 /src/corelib
parent7fdb64b3d30f2efa05b69f860802a24c947b3d0d (diff)
downloadfpGUI-51d6e695e7c311afc3cbe9bc4ac17ba405388d09.tar.xz
KeyPress events is now distributed to Widgets, then Form, then fpgApplication
* KeyPress is first offered to the focused widget * If not consumed, then to parent, then parent.parent etc.. * if still not consumed, then to top level form * if still not consumed, then to fpgApplication If anywhere in the sequence Consumed = True, then distribution of that event is stopped. This is the basic foundation required for various keyboard shortcut handling, actions shortcut handling, and especially in menus. The latter still needs some work though.
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/fpg_main.pas2
-rw-r--r--src/corelib/fpg_widget.pas18
2 files changed, 19 insertions, 1 deletions
diff --git a/src/corelib/fpg_main.pas b/src/corelib/fpg_main.pas
index 0e2f5384..a83c5590 100644
--- a/src/corelib/fpg_main.pas
+++ b/src/corelib/fpg_main.pas
@@ -229,6 +229,7 @@ type
FHintTimer: TfpgTimer;
FHintWidget: TfpgWindow;
FHintPos: TPoint;
+ FOnKeyPress: TKeyPressEvent;
procedure SetHintPause(const AValue: Integer);
procedure SetupLocalizationStrings;
procedure InternalMsgFreeMe(var msg: TfpgMessageRec); message FPGM_FREEME;
@@ -270,6 +271,7 @@ type
property ShowHint: boolean read FShowHint write SetShowHint default True;
property StopOnException: Boolean read FStopOnException write FStopOnException;
property OnException: TExceptionEvent read FOnException write FOnException;
+ property OnKeyPress: TKeyPressEvent read FOnKeyPress write FOnKeyPress;
end;
diff --git a/src/corelib/fpg_widget.pas b/src/corelib/fpg_widget.pas
index 1d51a7ad..4e48aa75 100644
--- a/src/corelib/fpg_widget.pas
+++ b/src/corelib/fpg_widget.pas
@@ -179,7 +179,8 @@ implementation
uses
fpg_constants,
- fpg_menu;
+ fpg_menu,
+ fpg_form; { for OnKeyPress handling }
var
@@ -475,6 +476,7 @@ var
ss: TShiftState;
consumed: boolean;
wg: TfpgWidget;
+ wlast: TfpgWidget;
begin
if InDesigner then
begin
@@ -490,13 +492,27 @@ begin
HandleKeyPress(key, ss, consumed);
if not consumed then
begin
+ { work it's way to one before top level form - forms are not focusable remember }
wg := Parent;
+ wlast := wg;
while (not consumed) and (wg <> nil) do
begin
wg.HandleKeyPress(key, ss, consumed);
+ wlast := wg;
wg := wg.Parent;
end;
end;
+ { we should now be at the top level form }
+ if (not consumed) and (wlast <> nil) then
+ begin
+ if (wlast is TfpgForm) and Assigned(wlast.OnKeyPress) then
+ wlast.OnKeyPress(self, key, ss, consumed);
+ end;
+ { now finaly, lets give fpgApplication a chance }
+ if (not consumed) and Assigned(fpgApplication.OnKeyPress) then
+ begin
+ fpgApplication.OnKeyPress(self, key, ss, consumed);
+ end;
end;
procedure TfpgWidget.MsgKeyRelease(var msg: TfpgMessageRec);