Explorar el Código

* added sender to TutlEvent

master
Bergmann89 hace 10 años
padre
commit
c6789dc465
Se han modificado 2 ficheros con 53 adiciones y 36 borrados
  1. +20
    -11
      uutlEvent.pas
  2. +33
    -25
      uutlEventManager.pas

+ 20
- 11
uutlEvent.pas Ver fichero

@@ -27,20 +27,22 @@ type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TutlEvent = class(TInterfacedObject, IutlEvent) TutlEvent = class(TInterfacedObject, IutlEvent)
private private
fSender: TObject;
fEventType: TutlEventType; fEventType: TutlEventType;
fTimestamp: Single; fTimestamp: Single;


public public
property Sender: TObject read fSender;
property EventType: TutlEventType read fEventType; property EventType: TutlEventType read fEventType;
property Timestamp: Single read fTimestamp; property Timestamp: Single read fTimestamp;


constructor Create(const aEventType: TutlEventType);
constructor Create(const aSender: TObject; const aEventType: TutlEventType);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
IutlEventListener = interface(IUnknown) IutlEventListener = interface(IUnknown)
['{BC45E26B-96F7-4151-87F1-C330C8C668E5}'] ['{BC45E26B-96F7-4151-87F1-C330C8C668E5}']
procedure DispatchEvent(const aEvent: IutlEvent);
procedure DispatchEvent(aEvent: IutlEvent);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -54,7 +56,7 @@ type
public public
property Empty: Boolean read GetEmpty; property Empty: Boolean read GetEmpty;


procedure DispatchEvent(const aEvent: IutlEvent); virtual;
procedure DispatchEvent(aEvent: IutlEvent); virtual;


function RegisterListener(const aListener: IutlEventListener): Boolean; function RegisterListener(const aListener: IutlEventListener): Boolean;
function UnregisterListener(const aListener: IutlEventListener): Boolean; function UnregisterListener(const aListener: IutlEventListener): Boolean;
@@ -65,11 +67,11 @@ type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TutlEventListenerCallback = class(TInterfacedObject, IutlEventListener) TutlEventListenerCallback = class(TInterfacedObject, IutlEventListener)
public type public type
TCallback = procedure(const aEvent: IutlEvent) of object;
TCallback = procedure(aEvent: IutlEvent) of object;
private private
fCallback: TCallback; fCallback: TCallback;
private { IEventListener } private { IEventListener }
procedure DispatchEvent(const aEvent: IutlEvent);
procedure DispatchEvent(aEvent: IutlEvent);
public public
constructor Create(const aCallback: TCallback); constructor Create(const aCallback: TCallback);
end; end;
@@ -85,7 +87,7 @@ type
function PopEvent: IutlEvent; function PopEvent: IutlEvent;


private { IEventListener } private { IEventListener }
procedure DispatchEvent(const aEvent: IutlEvent);
procedure DispatchEvent(aEvent: IutlEvent);


public public
function RegisterListener(const aListener: IutlEventListener): Boolean; function RegisterListener(const aListener: IutlEventListener): Boolean;
@@ -100,6 +102,9 @@ type
implementation implementation


uses uses
{$IFDEF LOG_DEBUG}
uutlLogger,
{$ENDIF}
uutlTiming; uutlTiming;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -113,11 +118,15 @@ end;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TutlEvent////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TutlEvent//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TutlEvent.Create(const aEventType: TutlEventType);
constructor TutlEvent.Create(const aSender: TObject; const aEventType: TutlEventType);
begin begin
inherited Create; inherited Create;
fTimestamp := GetMicroTime / 1000000;
fSender := aSender;
fEventType := aEventType; fEventType := aEventType;
fTimestamp := GetMicroTime / 1000000;
{$IFDEF LOG_DEBUG}
utlLogger.Debug(self, 'dispatch event (Sender=%s[%p]; EventType=%0.10d; Timestamp=%10.5f)', [ fSender.ClassName, Pointer(fSender), fEventType, fTimestamp ]);
{$ENDIF}
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -142,7 +151,7 @@ begin
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEventListenerSet.DispatchEvent(const aEvent: IutlEvent);
procedure TutlEventListenerSet.DispatchEvent(aEvent: IutlEvent);
var var
l: IutlEventListener; l: IutlEventListener;
begin begin
@@ -180,7 +189,7 @@ end;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TutlEventListenerCallback////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TutlEventListenerCallback//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEventListenerCallback.DispatchEvent(const aEvent: IutlEvent);
procedure TutlEventListenerCallback.DispatchEvent(aEvent: IutlEvent);
begin begin
fCallback(aEvent); fCallback(aEvent);
end; end;
@@ -210,7 +219,7 @@ begin
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEventListenerAsync.DispatchEvent(const aEvent: IutlEvent);
procedure TutlEventListenerAsync.DispatchEvent(aEvent: IutlEvent);
begin begin
fEventLock.Enter; fEventLock.Enter;
try try


+ 33
- 25
uutlEventManager.pas Ver fichero

@@ -17,12 +17,13 @@ type
TutlMouseButtons = set of TMouseButton; TutlMouseButtons = set of TMouseButton;
TutlWinControlEvent = class(TutlEvent) TutlWinControlEvent = class(TutlEvent)
private private
fSender: TControl;
function GetControl: TControl;

public public
property Sender: TControl read fSender;
property Control: TControl read GetControl;
constructor Create( constructor Create(
const aEventType: TutlEventType;
const aSender: TControl);
const aSender: TControl;
const aEventType: TutlEventType);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -38,8 +39,8 @@ type
property ScreenPos: TPoint read fScreenPos; property ScreenPos: TPoint read fScreenPos;


constructor Create( constructor Create(
const aEventType: TutlEventType;
const aSender: TControl; const aSender: TControl;
const aEventType: TutlEventType;
const aButtons: TutlMouseButtons; const aButtons: TutlMouseButtons;
const aClientPos: TPoint); const aClientPos: TPoint);
end; end;
@@ -73,8 +74,8 @@ type
property KeyCode: Word read fKeyCode; property KeyCode: Word read fKeyCode;


constructor Create( constructor Create(
const aEventType: TutlEventType;
const aSender: TControl; const aSender: TControl;
const aEventType: TutlEventType;
const aCharCode: WideChar; const aCharCode: WideChar;
const aKeyCode: Word); const aKeyCode: Word);
end; end;
@@ -92,8 +93,8 @@ type
property ClientHeight: Cardinal read fClientHeight; property ClientHeight: Cardinal read fClientHeight;


constructor Create( constructor Create(
const aEventType: TutlEventType;
const aSender: TControl; const aSender: TControl;
const aEventType: TutlEventType;
const aScreenRect: TRect; const aScreenRect: TRect;
const aClientWidth: Cardinal; const aClientWidth: Cardinal;
const aClientHeight: Cardinal); const aClientHeight: Cardinal);
@@ -208,7 +209,7 @@ type
property Mouse: TMouseState read fMouse; property Mouse: TMouseState read fMouse;
property Window: TWindowState read fWindow; property Window: TWindowState read fWindow;


procedure DispatchEvent(const aEvent: IutlEvent); override;
procedure DispatchEvent(aEvent: IutlEvent); override;
procedure AttachEvents(const aControl: TWinControl; const aTypes: TutlEventTypes); procedure AttachEvents(const aControl: TWinControl; const aTypes: TutlEventTypes);
end; end;


@@ -240,25 +241,32 @@ type
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TutlWinControlEvent//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TutlWinControlEvent////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TutlWinControlEvent.Create(const aEventType: TutlEventType; const aSender: TControl);
function TutlWinControlEvent.GetControl: TControl;
begin
result := (Sender as TControl);
end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TutlWinControlEvent.Create(
const aSender: TControl;
const aEventType: TutlEventType);
begin begin
inherited Create(aEventType);
fSender := aSender;
inherited Create(aSender, aEventType);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TutlMouseEvent///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TutlMouseEvent/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TutlMouseEvent.Create( constructor TutlMouseEvent.Create(
const aEventType: TutlEventType;
const aSender: TControl; const aSender: TControl;
const aEventType: TutlEventType;
const aButtons: TutlMouseButtons; const aButtons: TutlMouseButtons;
const aClientPos: TPoint); const aClientPos: TPoint);
begin begin
inherited Create(aEventType, aSender);
inherited Create(aSender, aEventType);
fButtons := aButtons; fButtons := aButtons;
fClientPos := aClientPos; fClientPos := aClientPos;
fScreenPos := fSender.ClientToScreen(fClientPos);
fScreenPos := Control.ClientToScreen(fClientPos);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -270,23 +278,23 @@ constructor TutlMouseWheelEvent.Create(
const aClientPos: TPoint); const aClientPos: TPoint);
begin begin
if (aWheelDelta < 0) if (aWheelDelta < 0)
then inherited Create(TutlWinControlEventManager.EVENT_MOUSE_WHEEL_DOWN, aSender)
else inherited Create(TutlWinControlEventManager.EVENT_MOUSE_WHEEL_UP, aSender);
then inherited Create(aSender, TutlWinControlEventManager.EVENT_MOUSE_WHEEL_DOWN)
else inherited Create(aSender, TutlWinControlEventManager.EVENT_MOUSE_WHEEL_UP);
fWheelDelta := aWheelDelta; fWheelDelta := aWheelDelta;
fClientPos := aClientPos; fClientPos := aClientPos;
fScreenPos := fSender.ClientToScreen(fClientPos);
fScreenPos := Control.ClientToScreen(fClientPos);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TutlKeyEvent/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TutlKeyEvent///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TutlKeyEvent.Create( constructor TutlKeyEvent.Create(
const aEventType: TutlEventType;
const aSender: TControl; const aSender: TControl;
const aEventType: TutlEventType;
const aCharCode: WideChar; const aCharCode: WideChar;
const aKeyCode: Word); const aKeyCode: Word);
begin begin
inherited Create(aEventType, aSender);
inherited Create(aSender, aEventType);
fCharCode := aCharCode; fCharCode := aCharCode;
fKeyCode := aKeyCode; fKeyCode := aKeyCode;
end; end;
@@ -295,13 +303,13 @@ end;
//TutlWindowEvent//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TutlWindowEvent////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TutlWindowEvent.Create( constructor TutlWindowEvent.Create(
const aEventType: TutlEventType;
const aSender: TControl; const aSender: TControl;
const aEventType: TutlEventType;
const aScreenRect: TRect; const aScreenRect: TRect;
const aClientWidth: Cardinal; const aClientWidth: Cardinal;
const aClientHeight: Cardinal); const aClientHeight: Cardinal);
begin begin
inherited Create(aEventType, aSender);
inherited Create(aSender, aEventType);
fScreenRect := aScreenRect; fScreenRect := aScreenRect;
fClientWidth := aClientWidth; fClientWidth := aClientWidth;
fClientHeight := aClientHeight; fClientHeight := aClientHeight;
@@ -472,8 +480,8 @@ function TutlWinControlEventManager.CreateMouseEvent(aSender: TObject; aType: Tu
aButtons: TutlMouseButtons; aClientPos: TPoint): TutlMouseEvent; aButtons: TutlMouseButtons; aClientPos: TPoint): TutlMouseEvent;
begin begin
result := TutlMouseEvent.Create( result := TutlMouseEvent.Create(
aType,
(aSender as TControl), (aSender as TControl),
aType,
aButtons, aButtons,
aClientPos); aClientPos);
end; end;
@@ -494,8 +502,8 @@ begin
if (aType = EVENT_KEY_DOWN) and fKeyboard.KeyState[aKey and $FF] then if (aType = EVENT_KEY_DOWN) and fKeyboard.KeyState[aKey and $FF] then
aType := EVENT_KEY_REPEAT; aType := EVENT_KEY_REPEAT;
result := TutlKeyEvent.Create( result := TutlKeyEvent.Create(
aType,
(aSender as TControl), (aSender as TControl),
aType,
VKCodeToCharCode(aKey, fKeyboard.Modifiers), VKCodeToCharCode(aKey, fKeyboard.Modifiers),
aKey); aKey);
end; end;
@@ -510,15 +518,15 @@ begin
p1 := ClientToScreen(Point(Width, Height)); p1 := ClientToScreen(Point(Width, Height));
end; end;
result := TutlWindowEvent.Create( result := TutlWindowEvent.Create(
aType,
(aSender as TControl), (aSender as TControl),
aType,
Rect(p0.x, p0.y, p1.x, p1.y), Rect(p0.x, p0.y, p1.x, p1.y),
(aSender as TWinControl).ClientWidth, (aSender as TWinControl).ClientWidth,
(aSender as TWinControl).ClientHeight); (aSender as TWinControl).ClientHeight);
end; end;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlWinControlEventManager.DispatchEvent(const aEvent: IutlEvent);
procedure TutlWinControlEventManager.DispatchEvent(aEvent: IutlEvent);
begin begin
RecordEvent(aEvent); RecordEvent(aEvent);
inherited DispatchEvent(aEvent); inherited DispatchEvent(aEvent);


Cargando…
Cancelar
Guardar