Difference between revisions of "Cocoa Internals/Input"

From Lazarus wiki
Jump to navigationJump to search
m
Line 14: Line 14:
  
 
If the actual control is found, the propagation of the event is stopped.
 
If the actual control is found, the propagation of the event is stopped.
 +
===Implemenation===
 +
The whole set of methods ''should be'' overridden for each sub-classed Objective-C control
 +
    function acceptsFirstMouse(event: NSEvent): Boolean; override;
 +
    procedure mouseDown(event: NSEvent); override;
 +
    procedure mouseUp(event: NSEvent); override;
 +
    procedure rightMouseDown(event: NSEvent); override;
 +
    procedure rightMouseUp(event: NSEvent); override;
 +
    procedure rightMouseDragged(event: NSEvent); override;
 +
    procedure otherMouseDown(event: NSEvent); override;
 +
    procedure otherMouseUp(event: NSEvent); override;
 +
    procedure otherMouseDragged(event: NSEvent); override;
 +
    procedure mouseDragged(event: NSEvent); override;
 +
    procedure mouseEntered(event: NSEvent); override;
 +
    procedure mouseExited(event: NSEvent); override;
 +
    procedure mouseMoved(event: NSEvent); override;
 +
    procedure scrollWheel(event: NSEvent); override;
 +
Even if a target LCL control doesn't publish the events (i.e. TScrollBar doesn't have any mouse events published), all those methods should still be overriden.
 +
The purpose is to give LCL control over that. For example, if a control is used at the design time, ALL of cocoa default handling should be blocked.
 +
 
==See Also==
 
==See Also==
 
* [[Cocoa Internals]]
 
* [[Cocoa Internals]]
  
 
[[Category:Cocoa]]
 
[[Category:Cocoa]]

Revision as of 06:14, 18 July 2018

Mouse

The biggest difference between Apple and LCL ideology is the way of handling MouseMove events.

According to Apple - mouse events are easily to flood the event queue and thus are disabled by default, unless a use presses and hold the button.

Apple provides a special NSWindow mode to allow MouseMove events to come through even with buttons unreleased. However, such MouseMove events would be reported to the focused controls (aka FirstResponder), rather than the control immediately under the cursor.

(MouseDown, MouseUp events are reported directly to the control under the cursor, similar to LCL).

Because of that, Widgetset mouse event processing routine first checks, if cursor is actually above the focused control, and if it's not, it would let Cocoa propagate the mouse event, down (from child to parent) the controls hierarchy.

Such propagation happens, when NSView inherited mouseMove event is called.

If the actual control is found, the propagation of the event is stopped.

Implemenation

The whole set of methods should be overridden for each sub-classed Objective-C control

   function acceptsFirstMouse(event: NSEvent): Boolean; override;
   procedure mouseDown(event: NSEvent); override;
   procedure mouseUp(event: NSEvent); override;
   procedure rightMouseDown(event: NSEvent); override;
   procedure rightMouseUp(event: NSEvent); override;
   procedure rightMouseDragged(event: NSEvent); override;
   procedure otherMouseDown(event: NSEvent); override;
   procedure otherMouseUp(event: NSEvent); override;
   procedure otherMouseDragged(event: NSEvent); override;
   procedure mouseDragged(event: NSEvent); override;
   procedure mouseEntered(event: NSEvent); override;
   procedure mouseExited(event: NSEvent); override;
   procedure mouseMoved(event: NSEvent); override;
   procedure scrollWheel(event: NSEvent); override;

Even if a target LCL control doesn't publish the events (i.e. TScrollBar doesn't have any mouse events published), all those methods should still be overriden. The purpose is to give LCL control over that. For example, if a control is used at the design time, ALL of cocoa default handling should be blocked.

See Also