]> git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/overviews/eventhandling.h
use @subpage where possible instead of @ref
[wxWidgets.git] / docs / doxygen / overviews / eventhandling.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: eventhandling
3 // Purpose: topic overview
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /*!
10
11 @page eventhandling_overview Event handling overview
12
13 Classes: #wxEvtHandler, #wxWindow, #wxEvent
14 #Introduction
15 @ref eventprocessing_overview
16 @ref progevent_overview
17 @ref pluggablehandlers_overview
18 @ref windowids_overview
19 @ref eventmacros_overview
20 @ref customevents_overview
21
22
23 @section eventintroduction Introduction
24
25 Before version 2.0 of wxWidgets, events were handled by the application
26 either by supplying callback functions, or by overriding virtual member
27 functions such as @b OnSize.
28 From wxWidgets 2.0, @e event tables are used instead, with a few exceptions.
29 An event table is placed in an implementation file to tell wxWidgets how to map
30 events to member functions. These member functions are not virtual functions, but
31 they are all similar in form: they take a single wxEvent-derived argument, and have a void return
32 type.
33 Here's an example of an event table.
34
35 @code
36 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
37 EVT_MENU (wxID_EXIT, MyFrame::OnExit)
38 EVT_MENU (DO_TEST, MyFrame::DoTest)
39 EVT_SIZE ( MyFrame::OnSize)
40 EVT_BUTTON (BUTTON1, MyFrame::OnButton1)
41 END_EVENT_TABLE()
42 @endcode
43
44 The first two entries map menu commands to two different member functions. The
45 EVT_SIZE macro doesn't need a window identifier, since normally you are only
46 interested in the current window's size events.
47 The EVT_BUTTON macro demonstrates that the originating event does not have to
48 come from the window class implementing the event table -- if the event source
49 is a button within a panel within a frame, this will still work, because event
50 tables are searched up through the hierarchy of windows for the command events.
51 In this case, the button's event table will be searched, then the parent
52 panel's, then the frame's.
53 As mentioned before, the member functions that handle events do not have to be
54 virtual. Indeed, the member functions should not be virtual as the event
55 handler ignores that the functions are virtual, i.e. overriding a virtual
56 member function in a derived class will not have any effect. These member
57 functions take an event argument, and the class of event differs according to
58 the type of event and the class of the originating window. For size events,
59 #wxSizeEvent is used. For menu commands and most
60 control commands (such as button presses),
61 #wxCommandEvent is used. When controls get more
62 complicated, then specific event classes are used, such as
63 #wxTreeEvent for events from
64 #wxTreeCtrl windows.
65 As well as the event table in the implementation file, there must also be a
66 DECLARE_EVENT_TABLE macro somewhere in the class declaration. For example:
67
68 @code
69 class MyFrame : public wxFrame
70 {
71 public:
72 ...
73 void OnExit(wxCommandEvent& event);
74 void OnSize(wxSizeEvent& event);
75
76 protected:
77 int m_count;
78 ...
79
80 DECLARE_EVENT_TABLE()
81 };
82 @endcode
83
84 Note that this macro may occur in any section of the class (public, protected
85 or private) but that it is probably better to insert it at the end, as shown,
86 because this macro implicitly changes the access to protected which may be
87 quite unexpected if there is anything following it.
88 Finally, if you don't like using macros for static initialization of the event
89 tables you may also use wxEvtHandler::Connect to
90 connect the events to the handlers dynamically, during run-time. See the
91 @ref sampleevent_overview for an example of doing it.
92
93
94 @section eventprocessing How events are processed
95
96 When an event is received from the windowing system, wxWidgets calls
97 wxEvtHandler::ProcessEvent on the first
98 event handler object belonging to the window generating the event.
99 It may be noted that wxWidgets' event processing system implements something
100 very close to virtual methods in normal C++, i.e. it is possible to alter
101 the behaviour of a class by overriding its event handling functions. In
102 many cases this works even for changing the behaviour of native controls.
103 For example it is possible to filter out a number of key events sent by the
104 system to a native text control by overriding wxTextCtrl and defining a
105 handler for key events using EVT_KEY_DOWN. This would indeed prevent
106 any key events from being sent to the native control - which might not be
107 what is desired. In this case the event handler function has to call Skip()
108 so as to indicate that the search for the event handler should continue.
109 To summarize, instead of explicitly calling the base class version as you
110 would have done with C++ virtual functions (i.e. @e wxTextCtrl::OnChar()),
111 you should instead call #Skip.
112 In practice, this would look like this if the derived text control only
113 accepts 'a' to 'z' and 'A' to 'Z':
114
115 @code
116 void MyTextCtrl::OnChar(wxKeyEvent& event)
117 {
118 if ( isalpha( event.KeyCode() ) )
119 {
120 // key code is within legal range. we call event.Skip() so the
121 // event can be processed either in the base wxWidgets class
122 // or the native control.
123
124 event.Skip();
125 }
126 else
127 {
128 // illegal key hit. we don't call event.Skip() so the
129 // event is not processed anywhere else.
130
131 wxBell();
132 }
133 }
134 @endcode
135
136
137 The normal order of event table searching by ProcessEvent is as follows:
138
139
140 If the object is disabled (via a call to wxEvtHandler::SetEvtHandlerEnabled)
141 the function skips to step (6).
142 If the object is a wxWindow, @b ProcessEvent is recursively called on the window's
143 #wxValidator. If this returns @true, the function exits.
144 @b SearchEventTable is called for this event handler. If this fails, the base
145 class table is tried, and so on until no more tables exist or an appropriate function was found,
146 in which case the function exits.
147 The search is applied down the entire chain of event handlers (usually the chain has a length
148 of one). If this succeeds, the function exits.
149 If the object is a wxWindow and the event is set to set to propagate (in the library only
150 wxCommandEvent based events are set to propagate), @b ProcessEvent is recursively applied
151 to the parent window's event handler. If this returns @true, the function exits.
152 Finally, @b ProcessEvent is called on the wxApp object.
153
154
155 @b Pay close attention to Step 5. People often overlook or get
156 confused by this powerful feature of the wxWidgets event processing
157 system. To put it a different way, events set to propagate
158 (@ref eventshouldpropagate_overview)
159 (most likely derived either directly or indirectly from wxCommandEvent)
160 will travel up the containment hierarchy from child to parent until the
161 maximal propagation level is reached or an event handler is found that
162 doesn't call #event.Skip().
163 Finally, there is another additional complication (which, in fact, simplifies
164 life of wxWidgets programmers significantly): when propagating the command
165 events upwards to the parent window, the event propagation stops when it
166 reaches the parent dialog, if any. This means that you don't risk to get
167 unexpected events from the dialog controls (which might be left unprocessed by
168 the dialog itself because it doesn't care about them) when a modal dialog is
169 popped up. The events do propagate beyond the frames, however. The rationale
170 for this choice is that there are only a few frames in a typical application
171 and their parent-child relation are well understood by the programmer while it
172 may be very difficult, if not impossible, to track down all the dialogs which
173 may be popped up in a complex program (remember that some are created
174 automatically by wxWidgets). If you need to specify a different behaviour for
175 some reason, you can use
176 #SetExtraStyle(wxWS_EX_BLOCK_EVENTS)
177 explicitly to prevent the events from being propagated beyond the given window
178 or unset this flag for the dialogs which have it on by default.
179 Typically events that deal with a window as a window (size, motion,
180 paint, mouse, keyboard, etc.) are sent only to the window. Events
181 that have a higher level of meaning and/or are generated by the window
182 itself, (button click, menu select, tree expand, etc.) are command
183 events and are sent up to the parent to see if it is interested in the
184 event.
185 Note that your application may wish to override ProcessEvent to redirect processing of
186 events. This is done in the document/view framework, for example, to allow event handlers
187 to be defined in the document or view. To test for command events (which will probably
188 be the only events you wish to redirect), you may use
189 wxEvent::IsCommandEvent for efficiency,
190 instead of using the slower run-time type system.
191 As mentioned above, only command events are recursively applied to the parents event
192 handler in the library itself. As this quite often causes confusion for users,
193 here is a list of system events which will NOT get sent to the parent's event handler:
194
195
196
197
198
199
200 #wxEvent
201
202
203
204
205 The event base class
206
207
208
209
210
211 #wxActivateEvent
212
213
214
215
216 A window or application activation event
217
218
219
220
221
222 #wxCloseEvent
223
224
225
226
227 A close window or end session event
228
229
230
231
232
233 #wxEraseEvent
234
235
236
237
238 An erase background event
239
240
241
242
243
244 #wxFocusEvent
245
246
247
248
249 A window focus event
250
251
252
253
254
255 #wxKeyEvent
256
257
258
259
260 A keypress event
261
262
263
264
265
266 #wxIdleEvent
267
268
269
270
271 An idle event
272
273
274
275
276
277 #wxInitDialogEvent
278
279
280
281
282 A dialog initialisation event
283
284
285
286
287
288 #wxJoystickEvent
289
290
291
292
293 A joystick event
294
295
296
297
298
299 #wxMenuEvent
300
301
302
303
304 A menu event
305
306
307
308
309
310 #wxMouseEvent
311
312
313
314
315 A mouse event
316
317
318
319
320
321 #wxMoveEvent
322
323
324
325
326 A move event
327
328
329
330
331
332 #wxPaintEvent
333
334
335
336
337 A paint event
338
339
340
341
342
343 #wxQueryLayoutInfoEvent
344
345
346
347
348 Used to query layout information
349
350
351
352
353
354 #wxSetCursorEvent
355
356
357
358
359 Used for special cursor processing based on current mouse position
360
361
362
363
364
365 #wxSizeEvent
366
367
368
369
370 A size event
371
372
373
374
375
376 #wxScrollWinEvent
377
378
379
380
381 A scroll event sent by a scrolled window (not a scroll bar)
382
383
384
385
386
387 #wxSysColourChangedEvent
388
389
390
391
392 A system colour change event
393
394
395
396
397
398 In some cases, it might be desired by the programmer to get a certain number
399 of system events in a parent window, for example all key events sent to, but not
400 used by, the native controls in a dialog. In this case, a special event handler
401 will have to be written that will override ProcessEvent() in order to pass
402 all events (or any selection of them) to the parent window.
403
404
405 @section progevent Events generated by the user vs programmatically generated events
406
407 While generically #wxEvents can be generated both by user
408 actions (e.g. resize of a #wxWindow) and by calls to functions
409 (e.g. wxWindow::SetSize), wxWidgets controls
410 normally send #wxCommandEvent-derived events only for
411 the user-generated events. The only @b exceptions to this rule are:
412
413
414
415
416
417
418 wxNotebook::AddPage
419
420
421
422
423 No event-free alternatives
424
425
426
427
428
429 wxNotebook::AdvanceSelection
430
431
432
433
434 No event-free alternatives
435
436
437
438
439
440 wxNotebook::DeletePage
441
442
443
444
445 No event-free alternatives
446
447
448
449
450
451 wxNotebook::SetSelection
452
453
454
455
456 Use wxNotebook::ChangeSelection instead, as wxNotebook::SetSelection is deprecated
457
458
459
460
461
462 wxTreeCtrl::Delete
463
464
465
466
467 No event-free alternatives
468
469
470
471
472
473 wxTreeCtrl::DeleteAllItems
474
475
476
477
478 No event-free alternatives
479
480
481
482
483
484 wxTreeCtrl::EditLabel
485
486
487
488
489 No event-free alternatives
490
491
492
493
494
495 All #wxTextCtrl methods
496
497
498
499
500 wxTextCtrl::ChangeValue can be used instead
501 of wxTextCtrl::SetValue but the other functions,
502 such as #Replace or #WriteText
503 don't have event-free equivalents
504
505
506
507
508
509
510
511 @section pluggablehandlers Pluggable event handlers
512
513 In fact, you don't have to derive a new class from a window class
514 if you don't want to. You can derive a new class from wxEvtHandler instead,
515 defining the appropriate event table, and then call
516 wxWindow::SetEventHandler (or, preferably,
517 wxWindow::PushEventHandler) to make this
518 event handler the object that responds to events. This way, you can avoid
519 a lot of class derivation, and use instances of the same event handler class (but different
520 objects as the same event handler object shouldn't be used more than once) to
521 handle events from instances of different widget classes. If you ever have to call a window's event handler
522 manually, use the GetEventHandler function to retrieve the window's event handler and use that
523 to call the member function. By default, GetEventHandler returns a pointer to the window itself
524 unless an application has redirected event handling using SetEventHandler or PushEventHandler.
525 One use of PushEventHandler is to temporarily or permanently change the
526 behaviour of the GUI. For example, you might want to invoke a dialog editor
527 in your application that changes aspects of dialog boxes. You can
528 grab all the input for an existing dialog box, and edit it 'in situ',
529 before restoring its behaviour to normal. So even if the application
530 has derived new classes to customize behaviour, your utility can indulge
531 in a spot of body-snatching. It could be a useful technique for on-line
532 tutorials, too, where you take a user through a serious of steps and
533 don't want them to diverge from the lesson. Here, you can examine the events
534 coming from buttons and windows, and if acceptable, pass them through to
535 the original event handler. Use PushEventHandler/PopEventHandler
536 to form a chain of event handlers, where each handler processes a different
537 range of events independently from the other handlers.
538
539 @section windowids Window identifiers
540
541 Window identifiers are integers, and are used to
542 uniquely determine window identity in the event system (though you can use it
543 for other purposes). In fact, identifiers do not need to be unique
544 across your entire application just so long as they are unique within a
545 particular context you're interested in, such as a frame and its children. You
546 may use the @c wxID_OK identifier, for example, on any number of dialogs so
547 long as you don't have several within the same dialog.
548 If you pass @c wxID_ANY to a window constructor, an identifier will be
549 generated for you automatically by wxWidgets. This is useful when you don't
550 care about the exact identifier either because you're not going to process the
551 events from the control being created at all or because you process the events
552 from all controls in one place (in which case you should specify @c wxID_ANY
553 in the event table or wxEvtHandler::Connect call
554 as well. The automatically generated identifiers are always negative and so
555 will never conflict with the user-specified identifiers which must be always
556 positive.
557 The following standard identifiers are supplied. You can use wxID_HIGHEST to
558 determine the number above which it is safe to define your own identifiers. Or,
559 you can use identifiers below wxID_LOWEST.
560
561 @code
562 #define wxID_ANY -1
563
564 #define wxID_LOWEST 4999
565
566 #define wxID_OPEN 5000
567 #define wxID_CLOSE 5001
568 #define wxID_NEW 5002
569 #define wxID_SAVE 5003
570 #define wxID_SAVEAS 5004
571 #define wxID_REVERT 5005
572 #define wxID_EXIT 5006
573 #define wxID_UNDO 5007
574 #define wxID_REDO 5008
575 #define wxID_HELP 5009
576 #define wxID_PRINT 5010
577 #define wxID_PRINT_SETUP 5011
578 #define wxID_PREVIEW 5012
579 #define wxID_ABOUT 5013
580 #define wxID_HELP_CONTENTS 5014
581 #define wxID_HELP_COMMANDS 5015
582 #define wxID_HELP_PROCEDURES 5016
583 #define wxID_HELP_CONTEXT 5017
584
585 #define wxID_CUT 5030
586 #define wxID_COPY 5031
587 #define wxID_PASTE 5032
588 #define wxID_CLEAR 5033
589 #define wxID_FIND 5034
590 #define wxID_DUPLICATE 5035
591 #define wxID_SELECTALL 5036
592 #define wxID_DELETE 5037
593 #define wxID_REPLACE 5038
594 #define wxID_REPLACE_ALL 5039
595 #define wxID_PROPERTIES 5040
596
597 #define wxID_VIEW_DETAILS 5041
598 #define wxID_VIEW_LARGEICONS 5042
599 #define wxID_VIEW_SMALLICONS 5043
600 #define wxID_VIEW_LIST 5044
601 #define wxID_VIEW_SORTDATE 5045
602 #define wxID_VIEW_SORTNAME 5046
603 #define wxID_VIEW_SORTSIZE 5047
604 #define wxID_VIEW_SORTTYPE 5048
605
606 #define wxID_FILE1 5050
607 #define wxID_FILE2 5051
608 #define wxID_FILE3 5052
609 #define wxID_FILE4 5053
610 #define wxID_FILE5 5054
611 #define wxID_FILE6 5055
612 #define wxID_FILE7 5056
613 #define wxID_FILE8 5057
614 #define wxID_FILE9 5058
615
616 #define wxID_OK 5100
617 #define wxID_CANCEL 5101
618 #define wxID_APPLY 5102
619 #define wxID_YES 5103
620 #define wxID_NO 5104
621 #define wxID_STATIC 5105
622
623 #define wxID_HIGHEST 5999
624 @endcode
625
626
627 @section eventmacros Event macros summary
628
629 @b Macros listed by event class
630 The documentation for specific event macros is organised by event class. Please refer
631 to these sections for details.
632
633
634
635
636
637
638 #wxActivateEvent
639
640
641
642
643 The EVT_ACTIVATE and EVT_ACTIVATE_APP macros intercept
644 activation and deactivation events.
645
646
647
648
649
650 #wxCommandEvent
651
652
653
654
655 A range of commonly-used control events.
656
657
658
659
660
661 #wxCloseEvent
662
663
664
665
666 The EVT_CLOSE macro handles window closure
667 called via wxWindow::Close.
668
669
670
671
672
673 #wxDropFilesEvent
674
675
676
677
678 The EVT_DROP_FILES macros handles
679 file drop events.
680
681
682
683
684
685 #wxEraseEvent
686
687
688
689
690 The EVT_ERASE_BACKGROUND macro is used to handle window erase requests.
691
692
693
694
695
696 #wxFocusEvent
697
698
699
700
701 The EVT_SET_FOCUS and EVT_KILL_FOCUS macros are used to handle keyboard focus events.
702
703
704
705
706
707 #wxKeyEvent
708
709
710
711
712 EVT_CHAR, EVT_KEY_DOWN and
713 EVT_KEY_UP macros handle keyboard input for any window.
714
715
716
717
718
719 #wxIdleEvent
720
721
722
723
724 The EVT_IDLE macro handle application idle events
725 (to process background tasks, for example).
726
727
728
729
730
731 #wxInitDialogEvent
732
733
734
735
736 The EVT_INIT_DIALOG macro is used
737 to handle dialog initialisation.
738
739
740
741
742
743 #wxListEvent
744
745
746
747
748 These macros handle #wxListCtrl events.
749
750
751
752
753
754 #wxMenuEvent
755
756
757
758
759 These macros handle special menu events (not menu commands).
760
761
762
763
764
765 #wxMouseEvent
766
767
768
769
770 Mouse event macros can handle either individual
771 mouse events or all mouse events.
772
773
774
775
776
777 #wxMoveEvent
778
779
780
781
782 The EVT_MOVE macro is used to handle a window move.
783
784
785
786
787
788 #wxPaintEvent
789
790
791
792
793 The EVT_PAINT macro is used to handle window paint requests.
794
795
796
797
798
799 #wxScrollEvent
800
801
802
803
804 These macros are used to handle scroll events from
805 #wxScrollBar, #wxSlider,and #wxSpinButton.
806
807
808
809
810
811 #wxSetCursorEvent
812
813
814
815
816 The EVT_SET_CURSOR macro is used for special cursor processing.
817
818
819
820
821
822 #wxSizeEvent
823
824
825
826
827 The EVT_SIZE macro is used to handle a window resize.
828
829
830
831
832
833 #wxSplitterEvent
834
835
836
837
838 The EVT_SPLITTER_SASH_POS_CHANGED, EVT_SPLITTER_UNSPLIT
839 and EVT_SPLITTER_DCLICK macros are used to handle the various splitter window events.
840
841
842
843
844
845 #wxSysColourChangedEvent
846
847
848
849
850 The EVT_SYS_COLOUR_CHANGED macro is used to handle
851 events informing the application that the user has changed the system colours (Windows only).
852
853
854
855
856
857 #wxTreeEvent
858
859
860
861
862 These macros handle #wxTreeCtrl events.
863
864
865
866
867
868 #wxUpdateUIEvent
869
870
871
872
873 The EVT_UPDATE_UI macro is used to handle user interface
874 update pseudo-events, which are generated to give the application the chance to update the visual state of menus,
875 toolbars and controls.
876
877
878
879
880
881
882 @section customevents Custom event summary
883
884 @b General approach
885 Since version 2.2.x of wxWidgets, each event type is identified by ID which
886 is given to the event type @e at runtime which makes it possible to add
887 new event types to the library or application without risking ID clashes
888 (two different event types mistakingly getting the same event ID). This
889 event type ID is stored in a struct of type @b const wxEventType.
890 In order to define a new event type, there are principally two choices.
891 One is to define a entirely new event class (typically deriving from
892 #wxEvent or #wxCommandEvent.
893 The other is to use the existing event classes and give them an new event
894 type. You'll have to define and declare a new event type using either way,
895 and this is done using the following macros:
896
897 @code
898 // in the header of the source file
899 BEGIN_DECLARE_EVENT_TYPES()
900 DECLARE_EVENT_TYPE(name, value)
901 END_DECLARE_EVENT_TYPES()
902
903 // in the implementation
904 DEFINE_EVENT_TYPE(name)
905 @endcode
906
907 You can ignore the @e value parameter of the DECLARE_EVENT_TYPE macro
908 since it is used only for backwards compatibility with wxWidgets 2.0.x based
909 applications where you have to give the event type ID an explicit value.
910 See also the @ref sampleevent_overview for an example of code
911 defining and working with the custom event types.
912 @b Using existing event classes
913 If you just want to use a #wxCommandEvent with
914 a new event type, you can then use one of the generic event table macros
915 listed below, without having to define a new macro yourself. This also
916 has the advantage that you won't have to define a new wxEvent::Clone()
917 method for posting events between threads etc. This could look like this
918 in your code:
919
920 @code
921 DECLARE_EVENT_TYPE(wxEVT_MY_EVENT, -1)
922
923 DEFINE_EVENT_TYPE(wxEVT_MY_EVENT)
924
925 // user code intercepting the event
926
927 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
928 EVT_MENU (wxID_EXIT, MyFrame::OnExit)
929 // ....
930 EVT_COMMAND (ID_MY_WINDOW, wxEVT_MY_EVENT, MyFrame::OnMyEvent)
931 END_EVENT_TABLE()
932
933 void MyFrame::OnMyEvent( wxCommandEvent )
934 {
935 // do something
936 wxString text = event.GetText();
937 }
938
939
940 // user code sending the event
941
942 void MyWindow::SendEvent()
943 {
944 wxCommandEvent event( wxEVT_MY_EVENT, GetId() );
945 event.SetEventObject( this );
946 // Give it some contents
947 event.SetText( wxT("Hallo") );
948 // Send it
949 GetEventHandler()-ProcessEvent( event );
950 }
951 @endcode
952
953
954 @b Generic event table macros
955
956
957
958
959
960
961 @b EVT_CUSTOM(event, id, func)
962
963
964
965
966 Allows you to add a custom event table
967 entry by specifying the event identifier (such as wxEVT_SIZE), the window identifier,
968 and a member function to call.
969
970
971
972
973
974 @b EVT_CUSTOM_RANGE(event, id1, id2, func)
975
976
977
978
979 The same as EVT_CUSTOM,
980 but responds to a range of window identifiers.
981
982
983
984
985
986 @b EVT_COMMAND(id, event, func)
987
988
989
990
991 The same as EVT_CUSTOM, but
992 expects a member function with a wxCommandEvent argument.
993
994
995
996
997
998 @b EVT_COMMAND_RANGE(id1, id2, event, func)
999
1000
1001
1002
1003 The same as EVT_CUSTOM_RANGE, but
1004 expects a member function with a wxCommandEvent argument.
1005
1006
1007
1008
1009
1010 @b EVT_NOTIFY(event, id, func)
1011
1012
1013
1014
1015 The same as EVT_CUSTOM, but
1016 expects a member function with a wxNotifyEvent argument.
1017
1018
1019
1020
1021
1022 @b EVT_NOTIFY_RANGE(event, id1, id2, func)
1023
1024
1025
1026
1027 The same as EVT_CUSTOM_RANGE, but
1028 expects a member function with a wxNotifyEvent argument.
1029
1030
1031
1032
1033
1034
1035 @b Defining your own event class
1036 Under certain circumstances, it will be required to define your own event
1037 class e.g. for sending more complex data from one place to another. Apart
1038 from defining your event class, you will also need to define your own
1039 event table macro (which is quite long). Watch out to put in enough
1040 casts to the inherited event function. Here is an example:
1041
1042 @code
1043 // code defining event
1044
1045 class wxPlotEvent: public wxNotifyEvent
1046 {
1047 public:
1048 wxPlotEvent( wxEventType commandType = wxEVT_@NULL, int id = 0 );
1049
1050 // accessors
1051 wxPlotCurve *GetCurve()
1052 { return m_curve; }
1053
1054 // required for sending with wxPostEvent()
1055 virtual wxEvent *Clone() const;
1056
1057 private:
1058 wxPlotCurve *m_curve;
1059 };
1060
1061 DECLARE_EVENT_TYPE( wxEVT_PLOT_ACTION, -1 )
1062
1063 typedef void (wxEvtHandler::*wxPlotEventFunction)(wxPlotEvent&);
1064
1065 #define EVT_PLOT(id, fn) \
1066 DECLARE_EVENT_TABLE_ENTRY( wxEVT_PLOT_ACTION, id, -1, \
1067 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) \
1068 wxStaticCastEvent( wxPlotEventFunction, & fn ), (wxObject *) @NULL ),
1069
1070
1071 // code implementing the event type and the event class
1072
1073 DEFINE_EVENT_TYPE( wxEVT_PLOT_ACTION )
1074
1075 wxPlotEvent::wxPlotEvent( ...
1076
1077
1078 // user code intercepting the event
1079
1080 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
1081 EVT_PLOT (ID_MY_WINDOW, MyFrame::OnPlot)
1082 END_EVENT_TABLE()
1083
1084 void MyFrame::OnPlot( wxPlotEvent )
1085 {
1086 wxPlotCurve *curve = event.GetCurve();
1087 }
1088
1089
1090 // user code sending the event
1091
1092 void MyWindow::SendEvent()
1093 {
1094 wxPlotEvent event( wxEVT_PLOT_ACTION, GetId() );
1095 event.SetEventObject( this );
1096 event.SetCurve( m_curve );
1097 GetEventHandler()-ProcessEvent( event );
1098 }
1099 @endcode
1100
1101 */
1102
1103