]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/events.i
Added IsEditCancelled/SetEditCanceled
[wxWidgets.git] / wxPython / src / events.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: events.i
3 // Purpose: SWIGgable Event classes for wxPython
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 5/24/98
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13
14 %module events
15
16 %{
17 #include "helpers.h"
18 #include <wx/spinbutt.h>
19 %}
20
21 //----------------------------------------------------------------------
22
23 %include typemaps.i
24 %include my_typemaps.i
25
26 // Import some definitions of other classes, etc.
27 %import _defs.i
28 %import misc.i
29 %import gdi.i
30
31 //---------------------------------------------------------------------------
32
33 enum Propagation_state
34 {
35 // don't propagate it at all
36 wxEVENT_PROPAGATE_NONE = 0,
37
38 // propagate it until it is processed
39 wxEVENT_PROPAGATE_MAX = INT_MAX
40 };
41
42
43 int wxNewEventType();
44
45
46
47 class wxEvent : public wxObject {
48 public:
49 // wxEvent(int winid = 0, wxEventType commandType = wxEVT_NULL); // *** This class is now an ABC
50 ~wxEvent();
51
52 void SetEventType(wxEventType typ);
53 wxEventType GetEventType() const;
54 wxObject *GetEventObject() const;
55 void SetEventObject(wxObject *obj);
56 long GetTimestamp() const;
57 void SetTimestamp(long ts = 0);
58 int GetId() const;
59 void SetId(int Id);
60
61
62 bool IsCommandEvent() const;
63
64 // Can instruct event processor that we wish to ignore this event
65 // (treat as if the event table entry had not been found): this must be done
66 // to allow the event processing by the base classes (calling event.Skip()
67 // is the analog of calling the base class verstion of a virtual function)
68 void Skip(bool skip = TRUE);
69 bool GetSkipped() const;
70
71 // Determine if this event should be propagating to the parent window.
72 bool ShouldPropagate() const;
73
74 // Stop an event from propagating to its parent window, returns the old
75 // propagation level value
76 int StopPropagation();
77
78 // Resume the event propagation by restoring the propagation level
79 // (returned by StopPropagation())
80 void ResumePropagation(int propagationLevel);
81
82 // this function is used to create a copy of the event polymorphically and
83 // all derived classes must implement it because otherwise wxPostEvent()
84 // for them wouldn't work (it needs to do a copy of the event)
85 virtual wxEvent *Clone() /* =0*/;
86 };
87
88 //---------------------------------------------------------------------------
89
90 // Helper class to temporarily change an event not to propagate.
91 class wxPropagationDisabler
92 {
93 public:
94 wxPropagationDisabler(wxEvent& event);
95 ~wxPropagationDisabler();
96 };
97
98
99 // Another one to temporarily lower propagation level.
100 class wxPropagateOnce
101 {
102 public:
103 wxPropagateOnce(wxEvent& event);
104 ~wxPropagateOnce();
105 };
106
107 //---------------------------------------------------------------------------
108
109 class wxSizeEvent : public wxEvent {
110 public:
111 wxSizeEvent(const wxSize& sz, int id = 0);
112 wxSize GetSize();
113 wxRect GetRect() const;
114 void SetRect(wxRect rect);
115 };
116
117 //---------------------------------------------------------------------------
118
119 class wxCloseEvent : public wxEvent {
120 public:
121 wxCloseEvent(int commandEventType = 0, int id = 0);
122
123 void SetLoggingOff(bool loggingOff);
124 bool GetLoggingOff();
125 void Veto(bool veto = TRUE);
126 bool CanVeto();
127 bool GetVeto();
128 void SetCanVeto(bool canVeto);
129 };
130
131 //---------------------------------------------------------------------------
132
133 class wxCommandEvent : public wxEvent {
134 public:
135 wxCommandEvent(int commandEventType = 0, int id = 0);
136
137 bool IsChecked();
138 %name(Checked)bool IsChecked();
139 long GetExtraLong();
140 int GetInt();
141 int GetSelection();
142 wxString GetString();
143 bool IsSelection();
144 void SetString(const wxString& s);
145 void SetExtraLong(long extraLong);
146 void SetInt(int i);
147
148 %addmethods {
149 PyObject* GetClientData() {
150 wxPyClientData* data = (wxPyClientData*)self->GetClientObject();
151 if (data) {
152 Py_INCREF(data->m_obj);
153 return data->m_obj;
154 } else {
155 Py_INCREF(Py_None);
156 return Py_None;
157 }
158 }
159 }
160 };
161
162
163 //---------------------------------------------------------------------------
164
165 class wxScrollEvent: public wxCommandEvent {
166 public:
167 wxScrollEvent(int commandType = 0, int id = 0, int pos = 0,
168 int orientation = 0);
169
170 int GetOrientation();
171 int GetPosition();
172 };
173
174 //---------------------------------------------------------------------------
175
176 class wxScrollWinEvent: public wxEvent {
177 public:
178 wxScrollWinEvent(int commandType = 0, int pos = 0,
179 int orientation = 0);
180
181 int GetOrientation();
182 int GetPosition();
183 };
184
185 //---------------------------------------------------------------------------
186
187 class wxSpinEvent : public wxScrollEvent {
188 public:
189 wxSpinEvent(int commandType = 0, int id = 0);
190
191 };
192
193 //---------------------------------------------------------------------------
194
195 class wxMouseEvent: public wxEvent {
196 public:
197 wxMouseEvent(int mouseEventType = 0);
198
199 bool IsButton();
200 bool ButtonDown(int but = -1);
201 bool ButtonDClick(int but = -1);
202 bool ButtonUp(int but = -1);
203 bool Button(int but);
204 bool ButtonIsDown(int but);
205 bool ControlDown();
206 bool MetaDown();
207 bool AltDown();
208 bool ShiftDown();
209 bool LeftDown();
210 bool MiddleDown();
211 bool RightDown();
212 bool LeftUp();
213 bool MiddleUp();
214 bool RightUp();
215 bool LeftDClick();
216 bool MiddleDClick();
217 bool RightDClick();
218 bool LeftIsDown();
219 bool MiddleIsDown();
220 bool RightIsDown();
221 bool Dragging();
222 bool Moving();
223 bool Entering();
224 bool Leaving();
225 wxPoint GetPosition();
226 %name(GetPositionTuple)void GetPosition(long *OUTPUT, long *OUTPUT);
227 wxPoint GetLogicalPosition(const wxDC& dc);
228 long GetX();
229 long GetY();
230
231 int GetWheelRotation() const { return m_wheelRotation; }
232 int GetWheelDelta() const { return m_wheelDelta; }
233 int GetLinesPerAction() const { return m_linesPerAction; }
234
235 long m_x, m_y;
236 bool m_leftDown;
237 bool m_middleDown;
238 bool m_rightDown;
239 bool m_controlDown;
240 bool m_shiftDown;
241 bool m_altDown;
242 bool m_metaDown;
243 int m_wheelRotation;
244 int m_wheelDelta;
245 int m_linesPerAction;
246 };
247
248 //---------------------------------------------------------------------------
249
250 class wxMouseCaptureChangedEvent : public wxEvent
251 {
252 public:
253 wxMouseCaptureChangedEvent(wxWindowID id = 0, wxWindow* gainedCapture = NULL);
254 wxWindow* GetCapturedWindow() const;
255 };
256
257 //---------------------------------------------------------------------------
258
259 class wxSetCursorEvent : public wxEvent
260 {
261 public:
262 wxSetCursorEvent(wxCoord x = 0, wxCoord y = 0);
263
264 wxCoord GetX() const;
265 wxCoord GetY() const;
266
267 void SetCursor(const wxCursor& cursor);
268 const wxCursor& GetCursor() const;
269 bool HasCursor() const;
270 };
271
272 //---------------------------------------------------------------------------
273
274 class wxKeyEvent: public wxEvent {
275 public:
276 wxKeyEvent(int keyEventType);
277
278 bool ControlDown();
279 bool MetaDown();
280 bool AltDown();
281 bool ShiftDown();
282
283 long GetKeyCode();
284 %pragma(python) addtoclass = "KeyCode = GetKeyCode"
285 bool HasModifiers();
286
287 // get the raw key code (platform-dependent)
288 long GetRawKeyCode() const;
289
290 // get the raw key flags (platform-dependent)
291 long GetRawKeyFlags() const;
292
293 long GetX();
294 long GetY();
295 wxPoint GetPosition();
296 %name(GetPositionTuple) void GetPosition(long* OUTPUT, long* OUTPUT);
297
298 long m_x, m_y;
299 long m_keyCode;
300 bool m_controlDown;
301 bool m_shiftDown;
302 bool m_altDown;
303 bool m_metaDown;
304 bool m_scanCode;
305 long m_rawCode;
306 long m_rawFlags;
307
308 };
309
310 //---------------------------------------------------------------------------
311
312 class wxNavigationKeyEvent : public wxEvent {
313 public:
314 wxNavigationKeyEvent();
315
316 bool GetDirection();
317 void SetDirection(bool bForward);
318 bool IsWindowChange();
319 void SetWindowChange(bool bIs);
320 wxWindow* GetCurrentFocus();
321 void SetCurrentFocus(wxWindow *win);
322 };
323
324
325 //---------------------------------------------------------------------------
326
327 class wxMoveEvent: public wxEvent {
328 public:
329 wxMoveEvent(const wxPoint& pt, int id = 0);
330 wxPoint GetPosition();
331 wxRect GetRect() const;
332 void SetRect(wxRect rect);
333 };
334
335 //---------------------------------------------------------------------------
336
337 class wxPaintEvent: public wxEvent {
338 public:
339 wxPaintEvent(int id = 0);
340
341 };
342
343 //---------------------------------------------------------------------------
344
345 class wxEraseEvent: public wxEvent {
346 public:
347 wxEraseEvent(int id = 0, wxDC* dc = NULL);
348
349 wxDC *GetDC();
350 };
351
352 //---------------------------------------------------------------------------
353
354 class wxFocusEvent: public wxEvent {
355 public:
356 wxFocusEvent(int eventType = 0, int id = 0);
357 };
358
359 //---------------------------------------------------------------------------
360
361 // wxChildFocusEvent notifies the parent that a child has got the focus: unlike
362 // wxFocusEvent it is propgated upwards the window chain
363 class wxChildFocusEvent : public wxCommandEvent
364 {
365 public:
366 wxChildFocusEvent(wxWindow *win = NULL);
367 wxWindow *GetWindow() const;
368 };
369
370
371 //---------------------------------------------------------------------------
372
373 class wxActivateEvent: public wxEvent{
374 public:
375 wxActivateEvent(int eventType = 0, int active = TRUE, int id = 0);
376 bool GetActive();
377 };
378
379 //---------------------------------------------------------------------------
380
381 class wxInitDialogEvent: public wxEvent {
382 public:
383 wxInitDialogEvent(int id = 0);
384 };
385
386 //---------------------------------------------------------------------------
387
388 class wxMenuEvent: public wxEvent {
389 public:
390 wxMenuEvent(int id = 0, int winid = 0, wxMenu* menu = NULL);
391 int GetMenuId();
392 bool IsPopup();
393 wxMenu* GetMenu() const;
394 };
395
396 //---------------------------------------------------------------------------
397
398 class wxShowEvent: public wxEvent {
399 public:
400 wxShowEvent(int id = 0, int show = FALSE);
401 void SetShow(bool show);
402 bool GetShow();
403 };
404
405 //---------------------------------------------------------------------------
406
407 class wxIconizeEvent: public wxEvent {
408 public:
409 wxIconizeEvent(int id = 0, bool iconized = TRUE);
410 bool Iconized();
411 };
412
413 //---------------------------------------------------------------------------
414
415 class wxMaximizeEvent: public wxEvent {
416 public:
417 wxMaximizeEvent(int id = 0);
418 };
419
420 //---------------------------------------------------------------------------
421
422 class wxJoystickEvent: public wxEvent {
423 public:
424 wxJoystickEvent(int type = wxEVT_NULL,
425 int state = 0,
426 int joystick = wxJOYSTICK1,
427 int change = 0);
428 wxPoint GetPosition();
429 int GetZPosition();
430 int GetButtonState();
431 int GetButtonChange();
432 int GetJoystick();
433 void SetJoystick(int stick);
434 void SetButtonState(int state);
435 void SetButtonChange(int change);
436 void SetPosition(const wxPoint& pos);
437 void SetZPosition(int zPos);
438 bool IsButton();
439 bool IsMove();
440 bool IsZMove();
441 bool ButtonDown(int but = wxJOY_BUTTON_ANY);
442 bool ButtonUp(int but = wxJOY_BUTTON_ANY);
443 bool ButtonIsDown(int but = wxJOY_BUTTON_ANY);
444 };
445
446 //---------------------------------------------------------------------------
447
448 class wxDropFilesEvent: public wxEvent {
449 public:
450 wxPoint GetPosition();
451 int GetNumberOfFiles();
452
453 %addmethods {
454 PyObject* GetFiles() {
455 int count = self->GetNumberOfFiles();
456 wxString* files = self->GetFiles();
457 PyObject* list = PyList_New(count);
458
459 if (!list) {
460 PyErr_SetString(PyExc_MemoryError, "Can't allocate list of files!");
461 return NULL;
462 }
463
464 for (int i=0; i<count; i++) {
465 #if wxUSE_UNICODE
466 PyList_SetItem(list, i, PyUnicode_FromWideChar(files[i], files[i].Len()));
467 #else
468 PyList_SetItem(list, i, PyString_FromString((const char*)files[i]));
469 #endif
470 }
471 return list;
472 }
473 }
474 };
475
476 //---------------------------------------------------------------------------
477
478 // Whether to always send idle events to windows, or
479 // to only send update events to those with the
480 // wxWS_EX_PROCESS_IDLE style.
481
482 enum wxIdleMode
483 {
484 // Send idle events to all windows
485 wxIDLE_PROCESS_ALL,
486
487 // Send idle events to windows that have
488 // the wxWS_EX_PROCESS_IDLE flag specified
489 wxIDLE_PROCESS_SPECIFIED
490 };
491
492
493 class wxIdleEvent: public wxEvent {
494 public:
495 wxIdleEvent();
496 void RequestMore(bool needMore = TRUE);
497 bool MoreRequested();
498
499 // Specify how wxWindows will send idle events: to
500 // all windows, or only to those which specify that they
501 // will process the events.
502 static void SetMode(wxIdleMode mode) { sm_idleMode = mode; }
503
504 // Returns the idle event mode
505 static wxIdleMode GetMode() { return sm_idleMode ; }
506
507 // Can we send an idle event?
508 static bool CanSend(wxWindow* win) ;
509
510 };
511
512 //---------------------------------------------------------------------------
513
514 // Whether to always send update events to windows, or
515 // to only send update events to those with the
516 // wxWS_EX_PROCESS_UI_UPDATES style.
517
518 enum wxUpdateUIMode
519 {
520 // Send UI update events to all windows
521 wxUPDATE_UI_PROCESS_ALL,
522
523 // Send UI update events to windows that have
524 // the wxWS_EX_PROCESS_UI_UPDATES flag specified
525 wxUPDATE_UI_PROCESS_SPECIFIED
526 };
527
528
529 class wxUpdateUIEvent: public wxEvent {
530 public:
531 wxUpdateUIEvent(wxWindowID commandId = 0);
532 bool GetChecked();
533 bool GetEnabled();
534 wxString GetText();
535 bool GetSetText();
536 bool GetSetChecked();
537 bool GetSetEnabled();
538
539 void Check(bool check);
540 void Enable(bool enable);
541 void SetText(const wxString& text);
542
543
544 // Sets the interval between updates in milliseconds.
545 // Set to -1 to disable updates, or to 0 to update as frequently as possible.
546 static void SetUpdateInterval(long updateInterval);
547
548 // Returns the current interval between updates in milliseconds
549 static long GetUpdateInterval();
550
551 // Can we update this window?
552 static bool CanUpdate(wxWindow* win);
553
554 // Reset the update time to provide a delay until the next
555 // time we should update
556 static void ResetUpdateTime();
557
558 // Specify how wxWindows will send update events: to
559 // all windows, or only to those which specify that they
560 // will process the events.
561 static void SetMode(wxUpdateUIMode mode);
562
563 // Returns the UI update mode
564 static wxUpdateUIMode GetMode();
565 };
566
567 //---------------------------------------------------------------------------
568
569 class wxSysColourChangedEvent: public wxEvent {
570 public:
571 wxSysColourChangedEvent();
572 };
573
574 //---------------------------------------------------------------------------
575
576
577 class wxNotifyEvent : public wxCommandEvent {
578 public:
579 wxNotifyEvent(int commandType = wxEVT_NULL, int id = 0);
580 bool IsAllowed();
581 void Allow();
582 void Veto();
583 };
584
585
586 //---------------------------------------------------------------------------
587
588 class wxDisplayChangedEvent : public wxEvent
589 {
590 public:
591 wxDisplayChangedEvent();
592 };
593
594
595 //---------------------------------------------------------------------------
596
597 class wxPaletteChangedEvent : public wxEvent {
598 public:
599 wxPaletteChangedEvent(wxWindowID id = 0);
600
601 void SetChangedWindow(wxWindow* win);
602 wxWindow* GetChangedWindow();
603
604 };
605
606 //---------------------------------------------------------------------------
607
608 class wxQueryNewPaletteEvent : public wxEvent {
609 public:
610 wxQueryNewPaletteEvent(wxWindowID id = 0);
611
612 void SetPaletteRealized(bool realized);
613 bool GetPaletteRealized();
614 };
615
616
617 //---------------------------------------------------------------------------
618
619 class wxWindowCreateEvent : public wxCommandEvent {
620 public:
621 wxWindowCreateEvent(wxWindow *win = NULL);
622
623 wxWindow *GetWindow();
624 };
625
626 class wxWindowDestroyEvent : public wxCommandEvent {
627 public:
628 wxWindowDestroyEvent(wxWindow *win = NULL);
629
630 wxWindow *GetWindow();
631 };
632
633 //---------------------------------------------------------------------------
634
635 class wxContextMenuEvent : public wxCommandEvent
636 {
637 public:
638 wxContextMenuEvent(wxEventType type = wxEVT_NULL,
639 wxWindowID id = 0,
640 const wxPoint& pt = wxDefaultPosition);
641 const wxPoint& GetPosition();
642 void SetPosition(const wxPoint& pos);
643 };
644
645 //----------------------------------------------------------------------
646
647 class wxTimerEvent : public wxEvent
648 {
649 public:
650 wxTimerEvent(int id = 0, int interval = 0);
651 int GetInterval();
652 };
653
654 //---------------------------------------------------------------------------
655
656 class wxTextUrlEvent : public wxCommandEvent
657 {
658 public:
659 wxTextUrlEvent(int id, const wxMouseEvent& evtMouse,
660 long start, long end);
661 const wxMouseEvent& GetMouseEvent();
662 long GetURLStart();
663 long GetURLEnd();
664 };
665
666 //---------------------------------------------------------------------------
667 //---------------------------------------------------------------------------
668 // These classes can be derived from in Python and passed through the event
669 // system without loosing anything. They do this by keeping a reference to
670 // themselves and some special case handling in wxPyCallback::EventThunker.
671
672 class wxPyEvent : public wxEvent {
673 public:
674 wxPyEvent(int winid=0, wxEventType commandType = wxEVT_NULL );
675 ~wxPyEvent();
676
677 %pragma(python) addtomethod = "__init__:self.SetSelf(self)"
678
679 void SetSelf(PyObject* self);
680 PyObject* GetSelf();
681 };
682
683
684 class wxPyCommandEvent : public wxCommandEvent {
685 public:
686 wxPyCommandEvent(wxEventType commandType = wxEVT_NULL, int id=0);
687 ~wxPyCommandEvent();
688
689 %pragma(python) addtomethod = "__init__:self.SetSelf(self)"
690
691 void SetSelf(PyObject* self);
692 PyObject* GetSelf();
693 };
694
695
696
697
698 //---------------------------------------------------------------------------
699 //---------------------------------------------------------------------------
700