Event bubbling

33 views
Skip to first unread message

Joe Betz

unread,
Nov 1, 2021, 12:53:02 AM11/1/21
to
Does Dolphin have any mechanisms for bubbling up mouse events?

For example, I have a MessagePresenter which has a ContainerView which has a StaticText for the author name and another StaticText for the message content. I'd like for MessagePresenters to be able to handle all mouse events from all its subviews, but as is getting swallowed by the subviews.

I think there should be a flag in View objects for controlling whether events are bubbled up to their parents. Or perhaps there are existing mechanisms I haven't discovered yet?

john.a...@gmail.com

unread,
Nov 1, 2021, 7:08:23 AM11/1/21
to
I'm not aware of a mechanism for this other than configuring subviews to bubble up individual events of interest. For example (modifying the FlowLayout example from the other thread):

(shell := View desktop addSubView: ShellView new)
backcolor: Color face3d;
layoutManager: (layout := FlowLayout new);
extent: 300 @ 200.
shell insets: (10 @ 10 corner: 10 @ 10).
layout
verticalGap: 10;
horizontalGap: SmallInteger maximum. "Force one item per row"
entireArea := FramingConstraints new rightFraming: #fixedParentRight; bottomFraming: #fixedParentBottom.
1 to: 10 do:
[ :index || messageView label |
(messageView := shell addSubView: ContainerView new)
extent: 100@20;
layoutManager: FramingLayout new;
addSubView: (label := StaticText new).
label
arrangement: entireArea;
text: 'Label <1d>' << index;
when: #leftButtonPressed: send: #onLeftButtonPressed: to: messageView.
messageView
arrangement: entireArea;
when: #leftButtonPressed: send: #inspect to: messageView].
shell show.

Older versions of Dolphin included a View subclass named Shield which was used by the View Composer to detect mouse events in the composition area - class comment:

"Shield is a covering <view> that the View Composer uses to overlay its arena in order to capture appropriate mouse down events before they reach the windows in the underlying view being composed. The intercepted events are relayed to the Shield's target which, normally, will be a <ViewComposer>."

Shield doesn't exist in current Dolphin versions, however since you don't need the "events are relayed to the Shield's target" function you can implement a minimal version with a class and two methods as follows:

View subclass: #Shield
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''


defaultWindowExStyle
"Private - Answer the default extended window creation style"

^super defaultWindowExStyle bitOr: WS_EX_TRANSPARENT


onEraseRequired: aColorEvent
"Private - Handler for erase background"

^true

You can then use this to capture all mouse events before they reach other subview(s). To demonstrate replace the loop block in the above example:

[ :index || messageView label shield |
(messageView := shell addSubView: ContainerView new)
extent: 100@20;
layoutManager: FramingLayout new;
addSubView: (shield := Shield new);
addSubView: (label := StaticText new).
label
arrangement: entireArea;
text: 'Label <1d>' << index.
shield
arrangement: entireArea;
when: #leftButtonPressed: send: #inspect to: shield;
when: #rightButtonPressed: send: #inspect to: label;
when: #leftButtonDoubleClicked: send: #inspect to: messageView].

Hope this helps.

John

vin...@gmail.com

unread,
Nov 1, 2021, 7:11:08 AM11/1/21
to
Maybe you should look at #createSchematicWiring. With this you can 'listen' to events on an object you hold a reference to, such as a child component in a composite presenter. There are examples and explanations on its use in the Helpfile example (Tutorials > Creating a GUI Application).

Vince

Joe Betz

unread,
Nov 5, 2021, 4:09:51 AM11/5/21
to
> Hope this helps.

Yup, that helped. :)

> Maybe you should look at #createSchematicWiring. With this you can 'listen' to events on an object you hold a reference to, such as a child component in a composite presenter. There are examples and explanations on its use in the Helpfile example (Tutorials > Creating a GUI Application).

Makes sense. I had looked at the GUI tutorial but was missing examples of low level key and mouse events though. Good to know they're already being emitted from Dolphin view objects.
Reply all
Reply to author
Forward
0 new messages