查看源代码 wxEvtHandler (wx v2.4.3)
事件处理程序
一个可以处理来自窗口系统的事件的类。wxWindow
(因此所有窗口类)都派生自此类。
要从 wxwidgets 对象获取事件,您需要通过调用 connect/3
来订阅它们。
如果未提供 callback
选项,则事件将作为消息发送。
这些消息将是 #wx{}
,其中 EventRecord
是一个取决于 wxEventType
的记录。这些记录定义在:wx/include/wx.hrl
中。
如果为 connect 提供了回调,则将调用该回调(在另一个进程中)来处理事件。回调应该有 2 个参数。
fun Callback (EventRecord::wx(), EventObject::wxObject()).
注意:回调每次都会在新进程中执行。
请参阅:事件概述
wxWidgets 文档:wxEvtHandler
摘要
类型
-type 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().
-type wx() :: #wx{id :: integer(), obj :: wx:wx_object(), userData :: term(), event :: event()}.
-type 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().
-type wxEvtHandler() :: wx:wx_object().
函数
-spec connect(This :: wxEvtHandler(), EventType :: wxEventType()) -> ok.
-spec connect(This :: wxEvtHandler(), EventType :: wxEventType(), [Option]) -> ok when Option :: {id, integer()} | {lastId, integer()} | {skip, boolean()} | callback | {callback, function()} | {userData, term()}.
此函数订阅事件。
订阅类型为 EventType
的事件,范围在 id
和 lastId
之间。
如果没有提供回调,事件将作为消息接收。
选项
id:{id, integer()}
与此事件处理程序关联的标识符(或标识符范围的第一个)。默认为 ?wxID_ANY
lastid:{lastId,integer()}
标识符范围的第二部分。如果使用,则必须将“id”设置为起始标识符范围。默认为 ?wxID_ANY
skip:{skip,boolean()}
如果 skip 为 true,则将调用进一步的 event_handlers。如果使用 'callback' 选项,则不使用此选项。默认为 false
。
callback:{callback,function()}
使用回调 fun(EventRecord::wx(),EventObject::wxObject())
来处理事件。默认情况下未指定,即消息将被传递到调用此函数的进程。
userData:{userData,term()}
一个将随事件一起发送的 Erlang 术语。默认值:[]。
-spec disconnect(This :: wxEvtHandler()) -> boolean().
-spec disconnect(This :: wxEvtHandler(), EventType :: wxEventType()) -> boolean().
-spec disconnect(This :: wxEvtHandler(), EventType :: wxEventType(), [Option]) -> boolean() when Option :: {id, integer()} | {lastId, integer()} | {callback, function()}.
此函数从事件处理程序中取消订阅进程或回调函数。
EventType 可以是原子 'null' 来匹配任何事件类型。请注意,选项 skip 和 userdata 不用于匹配事件处理程序。