Patterns for event handling Morphic?
I find it difficult to understand event handling in Morphic. I'm using both handleListenEvent: and mouseDown: and on:send:to: and haven't even started using announcements. What am I supposed to be using when, and what is supposed to be replaced in Bloc? Stephan
Hello Stephan, For user interaction events (mouse / keyboard events..., see MorphicEvent hierarchy, HandMorph, MorphicEventHandler...): - if you create your own morph class, then you implement mouseDown:, mouseUp: etc according to the event hierarchy. To allow a morph to manage an event, you have also to declare that the event is of interest. This is done by redefining the handlesXXX: methods. as an example, if you wants to redefine mouseDown:/mouseUp: you redefine handlesMouseDown: to return true. the event is passed as argument, you can decide to return true or false according to the state of your morph and the event argument. you have also the handleXXXX: methods. (do not mistake handleXXXX for handlesXXX). Their role is to manage incoming user interaction events. As an example, see handleMouseDown: , it removes a possible pending balloon, it manages the focus, it starts the mouse still down management, it sends mouseDown: to the receiver... Normally you should not have to redefine them. - if you wants to change or add an event management dynamically or without implementing specific methods (mouseDown:), then you can use the event handler and its protocol ( on:send:to: , limited to user interaction events though) - Additional event are implemented as Announcements such as MorphGotFocus. These âevents" are not necessarily related to the user interaction. Announcements are suited to define your own specific events. They allow the implementation of the Observer/Observable pattern nicely. - HandleListenEvent: is for particular purpose, used rarely. Bloc: only with event listeners and announcements A morph do not directly answer to events. Instead, a morph uses an event listener chain. Predefined events (user interactions and general purpose morph events as BlMorphGotFocus), are all managed through event listeners. One can also use announcements as in Morphic. We have implemented a lot of examples. We will explain event management in the Bloc documentation - @Sean, the doc will also include the rational ;) hope this helps. Cheers Alain
On 15 May 2015, at 22:41, Stephan Eggermont <stephan@stack.nl> wrote:
I find it difficult to understand event handling in Morphic. I'm using both handleListenEvent: and mouseDown: and on:send:to: and haven't even started using announcements. What am I supposed to be using when, and what is supposed to be replaced in Bloc?
Stephan
participants (2)
-
Alain Plantec -
Stephan Eggermont