X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8e72b8b51770b59a83eb32f4d766b89f6c4dc615..a83e14751f3b4bb86da3ac2edea09c7f78f3ca3e:/include/wx/event.h diff --git a/include/wx/event.h b/include/wx/event.h index 67958bb136..b96e4458be 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -359,8 +359,10 @@ public: // exists only for optimization purposes. bool IsCommandEvent() const { return m_isCommandEvent; } - // specialized clone function since it is done a lot - virtual wxEvent *Clone() const { return new wxEvent(*this); } + // this function is used to create a copy of the event polymorphically and + // all derived classes must implement it because otherwise wxPostEvent() + // for them wouldn't work (it needs to do a copy of the event) + virtual wxEvent *Clone() const = 0; public: wxObject* m_eventObject; @@ -440,7 +442,7 @@ public: long m_extraLong; // Additional information (e.g. select/deselect) void* m_clientData; // Arbitrary client data wxClientData* m_clientObject; // Arbitrary client object - + private: DECLARE_DYNAMIC_CLASS(wxCommandEvent) }; @@ -494,9 +496,9 @@ public: int GetPosition() const { return m_commandInt ; } void SetOrientation(int orient) { m_extraLong = (long) orient; } void SetPosition(int pos) { m_commandInt = pos; } - + virtual wxEvent *Clone() const { return new wxScrollEvent(*this); } - + private: DECLARE_DYNAMIC_CLASS(wxScrollEvent) }; @@ -743,11 +745,11 @@ public: bool HasCursor() const { return m_cursor.Ok(); } virtual wxEvent *Clone() const { return new wxSetCursorEvent(*this); } - + private: wxCoord m_x, m_y; wxCursor m_cursor; - + private: DECLARE_DYNAMIC_CLASS(wxSetCursorEvent) }; @@ -808,7 +810,25 @@ public: long KeyCode() const { return m_keyCode; } virtual wxEvent *Clone() const { return new wxKeyEvent(*this); } - + + // we do need to copy wxKeyEvent sometimes (in wxTreeCtrl code, for + // example) + wxKeyEvent& operator=(const wxKeyEvent& evt) + { + m_x = evt.m_x; + m_y = evt.m_y; + + m_keyCode = evt.m_keyCode; + + m_controlDown = evt.m_controlDown; + m_shiftDown = evt.m_shiftDown; + m_altDown = evt.m_altDown; + m_metaDown = evt.m_metaDown; + m_scanCode = evt.m_scanCode; + + return *this; + } + public: wxCoord m_x, m_y; @@ -819,7 +839,7 @@ public: bool m_altDown; bool m_metaDown; bool m_scanCode; - + private: DECLARE_DYNAMIC_CLASS(wxKeyEvent) }; @@ -844,7 +864,7 @@ public: public: wxSize m_size; -private: +private: DECLARE_DYNAMIC_CLASS(wxSizeEvent) }; @@ -865,9 +885,9 @@ public: wxPoint GetPosition() const { return m_pos; } virtual wxEvent *Clone() const { return new wxMoveEvent(*this); } - + wxPoint m_pos; - + private: DECLARE_DYNAMIC_CLASS(wxMoveEvent) }; @@ -906,7 +926,7 @@ public: #endif // debug virtual wxEvent *Clone() const { return new wxPaintEvent(*this); } - + private: DECLARE_DYNAMIC_CLASS(wxPaintEvent) }; @@ -915,7 +935,7 @@ class WXDLLEXPORT wxNcPaintEvent : public wxEvent { public: wxNcPaintEvent(int id = 0) : wxEvent(id) { SetEventType(wxEVT_NC_PAINT); } - + virtual wxEvent *Clone() const { return new wxNcPaintEvent(*this); } private: @@ -932,11 +952,11 @@ class WXDLLEXPORT wxEraseEvent : public wxEvent public: wxEraseEvent(int Id = 0, wxDC *dc = (wxDC *) NULL) { m_eventType = wxEVT_ERASE_BACKGROUND; m_id = Id; m_dc = dc; } - + wxDC *GetDC() const { return m_dc; } virtual wxEvent *Clone() const { return new wxEraseEvent(*this); } - + wxDC *m_dc; private: @@ -962,7 +982,7 @@ public: void SetWindow(wxWindow *win) { m_win = win; } virtual wxEvent *Clone() const { return new wxFocusEvent(*this); } - + private: wxWindow *m_win; @@ -980,7 +1000,7 @@ public: wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); } virtual wxEvent *Clone() const { return new wxChildFocusEvent(*this); } - + private: DECLARE_DYNAMIC_CLASS(wxChildFocusEvent) }; @@ -996,7 +1016,7 @@ class WXDLLEXPORT wxActivateEvent : public wxEvent public: wxActivateEvent(wxEventType type = wxEVT_NULL, bool active = TRUE, int Id = 0) { m_eventType = type; m_active = active; m_id = Id; } - + bool GetActive() const { return m_active; } virtual wxEvent *Clone() const { return new wxActivateEvent(*this); } @@ -1020,8 +1040,8 @@ public: { m_eventType = wxEVT_INIT_DIALOG; m_id = Id; } virtual wxEvent *Clone() const { return new wxInitDialogEvent(*this); } - -private: + +private: DECLARE_DYNAMIC_CLASS(wxInitDialogEvent) }; @@ -1042,10 +1062,10 @@ public: int GetMenuId() const { return m_menuId; } virtual wxEvent *Clone() const { return new wxMenuEvent(*this); } - + private: int m_menuId; - + private: DECLARE_DYNAMIC_CLASS(wxMenuEvent) }; @@ -1147,7 +1167,7 @@ public: bool Iconized() const { return m_iconized; } virtual wxEvent *Clone() const { return new wxIconizeEvent(*this); } - + protected: bool m_iconized; @@ -1165,7 +1185,7 @@ public: { m_eventType = wxEVT_MAXIMIZE; m_id = id; } virtual wxEvent *Clone() const { return new wxMaximizeEvent(*this); } - + private: DECLARE_DYNAMIC_CLASS(wxMaximizeEvent) }; @@ -1249,7 +1269,7 @@ public: ((m_buttonState & but) == but)); } virtual wxEvent *Clone() const { return new wxJoystickEvent(*this); } - + private: DECLARE_DYNAMIC_CLASS(wxJoystickEvent) }; @@ -1264,19 +1284,36 @@ class WXDLLEXPORT wxDropFilesEvent : public wxEvent public: int m_noFiles; wxPoint m_pos; - wxString* m_files; // Memory (de)allocated by code calling ProcessEvent + wxString* m_files; wxDropFilesEvent(wxEventType type = wxEVT_NULL, int noFiles = 0, wxString *files = (wxString *) NULL) { m_eventType = type; m_noFiles = noFiles; m_files = files; } + // we need a copy ctor to avoid deleting m_files pointer twice + wxDropFilesEvent(const wxDropFilesEvent& other) + : m_pos(other.m_pos) + { + m_noFiles = other.m_noFiles; + m_files = new wxString[m_noFiles]; + for ( int n = 0; n < m_noFiles; n++ ) + { + m_files[n] = other.m_files[n]; + } + } + + virtual ~wxDropFilesEvent() + { + delete [] m_files; + } + wxPoint GetPosition() const { return m_pos; } int GetNumberOfFiles() const { return m_noFiles; } wxString *GetFiles() const { return m_files; } - virtual wxEvent *Clone() const { wxFAIL_MSG("error"); return NULL; } - + virtual wxEvent *Clone() const { return new wxDropFilesEvent(*this); } + private: DECLARE_DYNAMIC_CLASS(wxDropFilesEvent) }; @@ -1321,7 +1358,7 @@ protected: bool m_setText; bool m_setChecked; wxString m_text; - + private: DECLARE_DYNAMIC_CLASS(wxUpdateUIEvent) }; @@ -1336,9 +1373,9 @@ class WXDLLEXPORT wxSysColourChangedEvent : public wxEvent public: wxSysColourChangedEvent() { m_eventType = wxEVT_SYS_COLOUR_CHANGED; } - + virtual wxEvent *Clone() const { return new wxSysColourChangedEvent(*this); } - + private: DECLARE_DYNAMIC_CLASS(wxSysColourChangedEvent) }; @@ -1387,7 +1424,7 @@ public: protected: bool m_paletteRealized; - + private: DECLARE_DYNAMIC_CLASS(wxQueryNewPaletteEvent) }; @@ -1467,9 +1504,9 @@ public: wxWindowCreateEvent(wxWindow *win = NULL); wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); } - + virtual wxEvent *Clone() const { return new wxWindowCreateEvent(*this); } - + private: DECLARE_DYNAMIC_CLASS(wxWindowCreateEvent) }; @@ -1480,7 +1517,7 @@ public: wxWindowDestroyEvent(wxWindow *win = NULL); wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); } - + virtual wxEvent *Clone() const { return new wxWindowDestroyEvent(*this); } private: @@ -1518,7 +1555,7 @@ public: void SetTarget(const wxString& target) { m_target = target; } virtual wxEvent *Clone() const { return new wxHelpEvent(*this); } - + protected: wxPoint m_pos; wxString m_target; @@ -1553,7 +1590,7 @@ public: void SetPosition(const wxPoint& pos) { m_pos = pos; } virtual wxEvent *Clone() const { return new wxContextMenuEvent(*this); } - + protected: wxPoint m_pos; @@ -1579,7 +1616,7 @@ public: protected: bool m_requestMore; - + private: DECLARE_DYNAMIC_CLASS(wxIdleEvent) };