| @@ -61,6 +61,15 @@ type | |||
| constructor Create(aType: TutlEventType; aClientPos, aScreenPos: TPoint); | |||
| end; | |||
| TutlMouseWheelEvent = class(TutlMouseEvent) | |||
| protected | |||
| function CreateInstance: TutlInputEvent; override; | |||
| procedure Assign(const aEvent: TutlInputEvent); override; | |||
| public | |||
| WheelDelta: Integer; | |||
| constructor Create(aType: TutlEventType; aWheelDelta: Integer; aClientPos, aScreenPos: TPoint); | |||
| end; | |||
| { TutlKeyEvent } | |||
| TutlKeyEvent = class(TutlInputEvent) | |||
| @@ -172,7 +181,7 @@ type | |||
| public | |||
| property CanonicalState: TInputState read fCanonicalState; | |||
| procedure AttachEvents(const fControl: TCustomForm; aEventMask: TutlEventTypes); | |||
| procedure AttachEvents(const aControl: TWinControl; aEventMask: TutlEventTypes); | |||
| function IsKeyDown(const aChar: Char): Boolean; | |||
| procedure RegisterListener(const aEventMask: TutlEventTypes; const aHandler: TutlInputEventHandler; const aSynchronous: Boolean = false); | |||
| @@ -198,7 +207,7 @@ implementation | |||
| uses uutlKeyCodes, uutlLogger, LCLIntf; | |||
| type | |||
| TCustomFormVisibilityClass = class(TCustomForm) | |||
| TWinControlVisibilityClass = class(TWinControl) | |||
| published | |||
| property OnMouseDown; | |||
| property OnMouseMove; | |||
| @@ -206,12 +215,16 @@ type | |||
| property OnMouseWheel; | |||
| property OnMouseEnter; | |||
| property OnMouseLeave; | |||
| property OnActivate; | |||
| property OnDeactivate; | |||
| property OnClick; | |||
| property OnDblClick; | |||
| end; | |||
| TCustomFormVisibilityClass = class(TCustomForm) | |||
| published | |||
| property OnActivate; | |||
| property OnDeactivate; | |||
| end; | |||
| var | |||
| utlEventManager_Singleton: TutlEventManager; | |||
| @@ -329,6 +342,25 @@ begin | |||
| ScreenPos:= aScreenPos; | |||
| end; | |||
| { TutlMouseWheelEvent } | |||
| function TutlMouseWheelEvent.CreateInstance: TutlInputEvent; | |||
| begin | |||
| result := TutlMouseWheelEvent.Create(EventType, WheelDelta, ClientPos, ScreenPos); | |||
| end; | |||
| procedure TutlMouseWheelEvent.Assign(const aEvent: TutlInputEvent); | |||
| begin | |||
| inherited Assign(aEvent); | |||
| WheelDelta := (aEvent as TutlMouseWheelEvent).WheelDelta; | |||
| end; | |||
| constructor TutlMouseWheelEvent.Create(aType: TutlEventType; aWheelDelta: Integer; aClientPos, aScreenPos: TPoint); | |||
| begin | |||
| inherited Create(aType, aClientPos, aScreenPos); | |||
| WheelDelta := aWheelDelta; | |||
| end; | |||
| { TutlKeyEvent } | |||
| function TutlKeyEvent.CreateInstance: TutlInputEvent; | |||
| @@ -433,9 +465,9 @@ end; | |||
| procedure TutlEventManager.EventHandlerMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); | |||
| begin | |||
| if WheelDelta < 0 then | |||
| QueuePush(TutlMouseEvent.Create(MOUSE_WHEEL_DOWN, MousePos, TWinControl(Sender).ClientToScreen(MousePos))) | |||
| QueuePush(TutlMouseWheelEvent.Create(MOUSE_WHEEL_DOWN, WheelDelta, MousePos, TWinControl(Sender).ClientToScreen(MousePos))) | |||
| else | |||
| QueuePush(TutlMouseEvent.Create(MOUSE_WHEEL_UP, MousePos, TWinControl(Sender).ClientToScreen(MousePos))); | |||
| QueuePush(TutlMouseWheelEvent.Create(MOUSE_WHEEL_UP, WheelDelta, MousePos, TWinControl(Sender).ClientToScreen(MousePos))); | |||
| Handled:= false; | |||
| end; | |||
| @@ -621,28 +653,35 @@ begin | |||
| end; | |||
| end; | |||
| procedure TutlEventManager.AttachEvents(const fControl: TCustomForm; aEventMask: TutlEventTypes); | |||
| procedure TutlEventManager.AttachEvents(const aControl: TWinControl; aEventMask: TutlEventTypes); | |||
| var | |||
| ctl: TCustomFormVisibilityClass; | |||
| begin | |||
| ctl:= TCustomFormVisibilityClass(fControl); | |||
| ctl.KeyPreview:= true; | |||
| if MOUSE_DOWN in aEventMask then ctl.OnMouseDown:= @EventHandlerMouseDown; | |||
| if MOUSE_UP in aEventMask then ctl.OnMouseUp:= @EventHandlerMouseUp; | |||
| if (MOUSE_WHEEL_DOWN in aEventMask) or | |||
| (MOUSE_WHEEL_UP in aEventMask) then ctl.OnMouseWheel:= @EventHandlerMouseWheel; | |||
| if MOUSE_MOVE in aEventMask then ctl.OnMouseMove:= @EventHandlerMouseMove; | |||
| if MOUSE_ENTER in aEventMask then ctl.OnMouseEnter := @EventHandlerMouseEnter; | |||
| if MOUSE_LEAVE in aEventMask then ctl.OnMouseLeave := @EventHandlerMouseLeave; | |||
| if MOUSE_CLICK in aEventMask then ctl.OnClick := @EventHandlerClick; | |||
| if MOUSE_DBL_CLICK in aEventMask then ctl.OnDblClick := @EventHandlerDblClick; | |||
| if KEY_DOWN in aEventMask then ctl.OnKeyDown:= @EventHandlerKeyDown; | |||
| if KEY_UP in aEventMask then ctl.OnKeyUp:= @EventHandlerKeyUp; | |||
| if WINDOW_RESIZE in aEventMask then ctl.OnResize:= @EventHandlerResize; | |||
| if WINDOW_ACTIVATE in aEventMask then ctl.OnActivate:= @EventHandlerActivate; | |||
| if WINDOW_DEACTIVATE in aEventMask then ctl.OnDeactivate:= @EventHandlerDeactivate; | |||
| ctl: TWinControlVisibilityClass; | |||
| frm: TCustomFormVisibilityClass; | |||
| begin | |||
| ctl := TWinControlVisibilityClass(aControl); | |||
| // mouse events | |||
| if (MOUSE_DOWN in aEventMask) then ctl.OnMouseDown := @EventHandlerMouseDown; | |||
| if (MOUSE_UP in aEventMask) then ctl.OnMouseUp := @EventHandlerMouseUp; | |||
| if (MOUSE_WHEEL_DOWN in aEventMask) or | |||
| (MOUSE_WHEEL_UP in aEventMask) then ctl.OnMouseWheel := @EventHandlerMouseWheel; | |||
| if (MOUSE_MOVE in aEventMask) then ctl.OnMouseMove := @EventHandlerMouseMove; | |||
| if (MOUSE_ENTER in aEventMask) then ctl.OnMouseEnter := @EventHandlerMouseEnter; | |||
| if (MOUSE_LEAVE in aEventMask) then ctl.OnMouseLeave := @EventHandlerMouseLeave; | |||
| if (MOUSE_CLICK in aEventMask) then ctl.OnClick := @EventHandlerClick; | |||
| if (MOUSE_DBL_CLICK in aEventMask) then ctl.OnDblClick := @EventHandlerDblClick; | |||
| // key events | |||
| if (KEY_DOWN in aEventMask) then ctl.OnKeyDown := @EventHandlerKeyDown; | |||
| if (KEY_UP in aEventMask) then ctl.OnKeyUp := @EventHandlerKeyUp; | |||
| // window events | |||
| if (WINDOW_RESIZE in aEventMask) then ctl.OnResize := @EventHandlerResize; | |||
| if Supports(aControl, TCustomFormVisibilityClass, frm) then begin | |||
| frm.KeyPreview := true; | |||
| if (WINDOW_ACTIVATE in aEventMask) then frm.OnActivate := @EventHandlerActivate; | |||
| if (WINDOW_DEACTIVATE in aEventMask) then frm.OnDeactivate := @EventHandlerDeactivate; | |||
| end; | |||
| end; | |||
| function TutlEventManager.IsKeyDown(const aChar: Char): Boolean; | |||