wxEvtHandler(3)

πŸ“¦
version 29.0.6 Β· 3 versions
, in ubuntu stonking

πŸ’– NAME πŸ’–

wxEvtHandler β€” literally THE Event handler, bestie. From the Erlang Module Definition corner of the wx universe. 🫢


✨ DESCRIPTION ✨

Okay so picture this: a class that can handle events from the windowing system. That's the whole vibe. wxWindow is derived from this class β€” and therefore all window classes are too. It's giving main character energy, fr fr. πŸ‘‘

To get events from wxwidgets objects you subscribe to them by calling connect/3. That's the move.

If the callback option is not supplied, events are sent as messages. πŸ“¬

Those messages will be #wx{} where EventRecord is a record that depends on the wxEventType. The records are defined in:

wx/include/wx.hrl

If a callback was supplied to connect, the callback will be invoked (in another process) to handle the event. The callback should be of arity 2.

fun Callback (EventRecord::wx(), EventObject::wxObject()).
⚠️ Note: the callback will be executed in a new process each and every time. Not the same process, a fresh one. Every single time. No cap. πŸŒ€

See: Overview events

wxWidgets docs: wxEvtHandler


🌈 DATA TYPES 🌈

πŸ¦‹ event()

event() ::
          wxActivateEvent:wxActivate() |
          wxAuiManagerEvent:wxAuiManager() |
          wxAuiNotebookEvent:wxAuiNotebook() |
          wxBookCtrlEvent:wxBookCtrl() |
          wxCalendarEvent:wxCalendar() |
          wxChildFocusEvent:wxChildFocus() |
          wxClipboardTextEvent:wxClipboardText() |
          wxCloseEvent:wxClose() |
          wxColourPickerEvent:wxColourPicker() |
          wxCommandEvent:wxCommand() |
          wxContextMenuEvent:wxContextMenu() |
          wxDateEvent:wxDate() |
          wxDisplayChangedEvent:wxDisplayChanged() |
          wxDropFilesEvent:wxDropFiles() |
          wxEraseEvent:wxErase() |
          wxFileDirPickerEvent:wxFileDirPicker() |
          wxFocusEvent:wxFocus() |
          wxFontPickerEvent:wxFontPicker() |
          wxGridEvent:wxGrid() |
          wxHelpEvent:wxHelp() |
          wxHtmlLinkEvent:wxHtmlLink() |
          wxIconizeEvent:wxIconize() |
          wxIdleEvent:wxIdle() |
          wxInitDialogEvent:wxInitDialog() |
          wxJoystickEvent:wxJoystick() |
          wxKeyEvent:wxKey() |
          wxListEvent:wxList() |
          wxMaximizeEvent:wxMaximize() |
          wxMenuEvent:wxMenu() |
          wxMouseCaptureChangedEvent:wxMouseCaptureChanged() |
          wxMouseCaptureLostEvent:wxMouseCaptureLost() |
          wxMouseEvent:wxMouse() |
          wxMoveEvent:wxMove() |
          wxNavigationKeyEvent:wxNavigationKey() |
          wxPaintEvent:wxPaint() |
          wxPaletteChangedEvent:wxPaletteChanged() |
          wxQueryNewPaletteEvent:wxQueryNewPalette() |
          wxSashEvent:wxSash() |
          wxScrollEvent:wxScroll() |
          wxScrollWinEvent:wxScrollWin() |
          wxSetCursorEvent:wxSetCursor() |
          wxShowEvent:wxShow() |
          wxSizeEvent:wxSize() |
          wxSpinEvent:wxSpin() |
          wxSplitterEvent:wxSplitter() |
          wxStyledTextEvent:wxStyledText() |
          wxSysColourChangedEvent:wxSysColourChanged() |
          wxTaskBarIconEvent:wxTaskBarIcon() |
          wxTreeEvent:wxTree() |
          wxUpdateUIEvent:wxUpdateUI() |
          wxWebViewEvent:wxWebView() |
          wxWindowCreateEvent:wxWindowCreate() |
          wxWindowDestroyEvent:wxWindowDestroy().

Like… the whole event buffet. Name your fave, they're all here. πŸ“

πŸ’œ wx()

wx() :: #wx{}.

🌸 wxEventType()

wxEventType() ::
          wxActivateEvent:wxActivateEventType() |
          wxAuiManagerEvent:wxAuiManagerEventType() |
          wxAuiNotebookEvent:wxAuiNotebookEventType() |
          wxBookCtrlEvent:wxBookCtrlEventType() |
          wxCalendarEvent:wxCalendarEventType() |
          wxChildFocusEvent:wxChildFocusEventType() |
          wxClipboardTextEvent:wxClipboardTextEventType() |
          wxCloseEvent:wxCloseEventType() |
          wxColourPickerEvent:wxColourPickerEventType() |
          wxCommandEvent:wxCommandEventType() |
          wxContextMenuEvent:wxContextMenuEventType() |
          wxDateEvent:wxDateEventType() |
          wxDisplayChangedEvent:wxDisplayChangedEventType() |
          wxDropFilesEvent:wxDropFilesEventType() |
          wxEraseEvent:wxEraseEventType() |
          wxFileDirPickerEvent:wxFileDirPickerEventType() |
          wxFocusEvent:wxFocusEventType() |
          wxFontPickerEvent:wxFontPickerEventType() |
          wxGridEvent:wxGridEventType() |
          wxHelpEvent:wxHelpEventType() |
          wxHtmlLinkEvent:wxHtmlLinkEventType() |
          wxIconizeEvent:wxIconizeEventType() |
          wxIdleEvent:wxIdleEventType() |
          wxInitDialogEvent:wxInitDialogEventType() |
          wxJoystickEvent:wxJoystickEventType() |
          wxKeyEvent:wxKeyEventType() |
          wxListEvent:wxListEventType() |
          wxMaximizeEvent:wxMaximizeEventType() |
          wxMenuEvent:wxMenuEventType() |
          wxMouseCaptureChangedEvent:wxMouseCaptureChangedEventType() |
          wxMouseCaptureLostEvent:wxMouseCaptureLostEventType() |
          wxMouseEvent:wxMouseEventType() |
          wxMoveEvent:wxMoveEventType() |
          wxNavigationKeyEvent:wxNavigationKeyEventType() |
          wxPaintEvent:wxPaintEventType() |
          wxPaletteChangedEvent:wxPaletteChangedEventType() |
          wxQueryNewPaletteEvent:wxQueryNewPaletteEventType() |
          wxSashEvent:wxSashEventType() |
          wxScrollEvent:wxScrollEventType() |
          wxScrollWinEvent:wxScrollWinEventType() |
          wxSetCursorEvent:wxSetCursorEventType() |
          wxShowEvent:wxShowEventType() |
          wxSizeEvent:wxSizeEventType() |
          wxSpinEvent:wxSpinEventType() |
          wxSplitterEvent:wxSplitterEventType() |
          wxStyledTextEvent:wxStyledTextEventType() |
          wxSysColourChangedEvent:wxSysColourChangedEventType() |
          wxTaskBarIconEvent:wxTaskBarIconEventType() |
          wxTreeEvent:wxTreeEventType() |
          wxUpdateUIEvent:wxUpdateUIEventType() |
          wxWebViewEvent:wxWebViewEventType() |
          wxWindowCreateEvent:wxWindowCreateEventType() |
          wxWindowDestroyEvent:wxWindowDestroyEventType().

Every event type has a matching EventType. Chef's kiss. Matched set, slay. πŸ’…

πŸŽ€ wxEvtHandler()

wxEvtHandler() :: wx:wx_object().

πŸ‘‘ FUNCTIONS πŸ‘‘

🫢 connect/3

connect(This :: wxEvtHandler(),
             EventType :: wxEventType(),
             [Option]) ->
                ok
                when
                    Option ::
                        {id, integer()} |
                        {lastId, integer()} |
                        {skip, boolean()} |
                        callback |
                        {callback, function()} |
                        {userData, term()}.

This function subscribes to events. It's the whole point bestie, okay, like β€” you slide in and you subscribe. πŸŽ€

Subscribes to events of type EventType, in the range id, lastId.

The events will be received as messages if no callback is supplied. πŸ’Œ

✨ Options ✨

  • id:{id, integer()} β€” The identifier (or first of the identifier range) to be associated with this event handler. Default is ?wxID_ANY
  • lastid:{lastId,integer()} β€” The second part of the identifier range. If used 'id' must be set as the starting identifier range. Default is ?wxID_ANY
  • skip:{skip,boolean()} β€” If skip is true further event_handlers will be called. This is not used if the 'callback' option is used. Default is false.
  • callback:{callback,function()} β€” Use a callbackfun(EventRecord::wx(),EventObject::wxObject()) to process the event. Default not specified i.e. a message will be delivered to the process calling this function.
  • userData:{userData,term()} β€” An erlang term that will be sent with the event. Default: [].
πŸ™ˆ Bestie reminder: {skip,true} taps in more event_handlers, and it does absolutely nothing if you brought a callback. Pick a lane. πŸ’«

πŸ¦‹ disconnect/3

disconnect(This :: wxEvtHandler(),
                 EventType :: wxEventType(),
                 [Option]) ->
                    boolean()
                    when
                        Option ::
                            {id, integer()} |
                            {lastId, integer()} |
                            {callback, function()}.

This function unsubscribes the process or callback fun from the event handler. Yeah. Unsubscribing. It's giving "we need to talk" but make it wholesome. πŸ’”

EventType may be the atom 'null' to match any eventtype. Notice that the options skip and userdata is not used to match the eventhandler.

⚠️ Real talk: those two options don't participate in matching at all. They're just ✨there✨ for the ride. Don't expect them to filter anything.

and that's the page, periodt βœ¨πŸ’–

Mwah, ily for reading this far. 🫢 This masterpiece comes to you courtesy of Ericsson AB, plucked straight from the wx 2.6 era β€” like, vintage but make it iconic. πŸ’… Lowkey a whole time capsule fr fr. πŸŽ€

πŸ“¦ where this page comes from