Remove old event type compatibility

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50857 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2007-12-20 11:24:44 +00:00
parent 8dba4c7230
commit ad684023c5
7 changed files with 4 additions and 144 deletions

View File

@ -53,47 +53,6 @@ typedef int wxEventType;
// handler only a function with proper parameter list can be given.
#define wxStaticCastEvent(type, val) wx_static_cast(type, val)
// in previous versions of wxWidgets the event types used to be constants
// which created difficulties with custom/user event types definition
//
// starting from wxWidgets 2.4 the event types are now dynamically assigned
// using wxNewEventType() which solves this problem, however at price of
// several incompatibilities:
//
// a) event table macros declaration changed, it now uses wxEventTableEntry
// ctor instead of initialisation from an agregate - the macro
// DECLARE_EVENT_TABLE_ENTRY may be used to write code which can compile
// with all versions of wxWidgets
//
// b) event types can't be used as switch() cases as they're not really
// constant any more - there is no magic solution here, you just have to
// change the switch()es to if()s
//
// if these are real problems for you, define WXWIN_COMPATIBILITY_EVENT_TYPES
// as 1 to get 100% old behaviour, however you won't be able to use the
// libraries using the new dynamic event type allocation in such case, so avoid
// it if possible.
#ifndef WXWIN_COMPATIBILITY_EVENT_TYPES
#define WXWIN_COMPATIBILITY_EVENT_TYPES 0
#endif
#if WXWIN_COMPATIBILITY_EVENT_TYPES
#define DECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \
{ type, winid, idLast, fn, obj }
#define BEGIN_DECLARE_EVENT_TYPES() enum {
#define END_DECLARE_EVENT_TYPES() };
#define DECLARE_EVENT_TYPE(name, value) name = wxEVT_FIRST + value,
#define DECLARE_LOCAL_EVENT_TYPE(name, value) name = wxEVT_USER_FIRST + value,
#define DECLARE_EXPORTED_EVENT_TYPE(expdecl, name, value) \
DECLARE_LOCAL_EVENT_TYPE(name, value)
#define DEFINE_EVENT_TYPE(name)
#define DEFINE_LOCAL_EVENT_TYPE(name)
#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
#define DECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \
wxEventTableEntry(type, winid, idLast, fn, obj)
@ -111,21 +70,12 @@ typedef int wxEventType;
// generate a new unique event type
extern WXDLLIMPEXP_BASE wxEventType wxNewEventType();
#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
BEGIN_DECLARE_EVENT_TYPES()
#if WXWIN_COMPATIBILITY_EVENT_TYPES
wxEVT_NULL = 0,
wxEVT_FIRST = 10000,
wxEVT_USER_FIRST = wxEVT_FIRST + 2000,
#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
// it is important to still have these as constants to avoid
// initialization order related problems
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_NULL, 0)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_FIRST, 10000)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_USER_FIRST, wxEVT_FIRST + 2000)
#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
DECLARE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED, 1)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED, 2)
@ -133,13 +83,6 @@ BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED, 4)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, 5)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, 6)
// now they are in wx/textctrl.h
#if WXWIN_COMPATIBILITY_EVENT_TYPES
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TEXT_UPDATED, 7)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TEXT_ENTER, 8)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TEXT_URL, 13)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TEXT_MAXLEN, 14)
#endif // WXWIN_COMPATIBILITY_EVENT_TYPES
DECLARE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED, 9)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED, 10)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED, 11)
@ -312,9 +255,7 @@ END_DECLARE_EVENT_TYPES()
// wx/textctrl.h in all ports [yet], so declare it here as well
//
// still, any new code using it should include wx/textctrl.h explicitly
#if !WXWIN_COMPATIBILITY_EVENT_TYPES
extern const wxEventType WXDLLIMPEXP_CORE wxEVT_COMMAND_TEXT_UPDATED;
#endif
extern const wxEventType WXDLLIMPEXP_CORE wxEVT_COMMAND_TEXT_UPDATED;
// the predefined constants for the number of times we propagate event
// upwards window child-parent chain
@ -994,11 +935,6 @@ public:
// Get Y position
wxCoord GetY() const { return m_y; }
#if WXWIN_COMPATIBILITY_2_6
// deprecated, Use GetKeyCode instead.
wxDEPRECATED( long KeyCode() const );
#endif // WXWIN_COMPATIBILITY_2_6
virtual wxEvent *Clone() const { return new wxKeyEvent(*this); }
// we do need to copy wxKeyEvent sometimes (in wxTreeCtrl code, for
@ -2169,25 +2105,6 @@ private:
// as a wxObject method even though it can only be a wxEvtHandler one
typedef void (wxObject::*wxObjectEventFunction)(wxEvent&);
// we can't have ctors nor base struct in backwards compatibility mode or
// otherwise we won't be able to initialize the objects with an agregate, so
// we have to keep both versions
#if WXWIN_COMPATIBILITY_EVENT_TYPES
struct WXDLLIMPEXP_BASE wxEventTableEntry
{
// For some reason, this can't be wxEventType, or VC++ complains.
int m_eventType; // main event type
int m_id; // control/menu/toolbar id
int m_lastId; // used for ranges of ids
wxObjectEventFunction m_fn; // function to call: not wxEventFunction,
// because of dependency problems
wxObject* m_callbackUserData;
};
#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
// struct containing the members common to static and dynamic event tables
// entries
struct WXDLLIMPEXP_BASE wxEventTableEntryBase
@ -2267,8 +2184,6 @@ struct WXDLLIMPEXP_BASE wxDynamicEventTableEntry : public wxEventTableEntryBase
DECLARE_NO_COPY_CLASS(wxDynamicEventTableEntry)
};
#endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
// ----------------------------------------------------------------------------
// wxEventTable: an array of event entries terminated with {0, 0, 0, 0, 0}
// ----------------------------------------------------------------------------

View File

@ -703,8 +703,6 @@ protected:
// wxTextCtrl events
// ----------------------------------------------------------------------------
#if !WXWIN_COMPATIBILITY_EVENT_TYPES
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TEXT_UPDATED, 7)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TEXT_ENTER, 8)
@ -712,8 +710,6 @@ BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TEXT_MAXLEN, 14)
END_DECLARE_EVENT_TYPES()
#endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
class WXDLLEXPORT wxTextUrlEvent : public wxCommandEvent
{
public:

View File

@ -144,8 +144,6 @@ wxList *wxPendingEvents = (wxList *)NULL;
wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL;
#endif
#if !WXWIN_COMPATIBILITY_EVENT_TYPES
// common event types are defined here, other event types are defined by the
// components which use them
@ -157,14 +155,10 @@ DEFINE_EVENT_TYPE(wxEVT_IDLE)
DEFINE_EVENT_TYPE(wxEVT_SOCKET)
DEFINE_EVENT_TYPE(wxEVT_TIMER)
#endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
#endif // wxUSE_BASE
#if wxUSE_GUI
#if !WXWIN_COMPATIBILITY_EVENT_TYPES
DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED)
@ -318,8 +312,6 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER)
DEFINE_EVENT_TYPE(wxEVT_HELP)
DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP)
#endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
#endif // wxUSE_GUI
#if wxUSE_BASE
@ -778,13 +770,6 @@ wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt)
#endif
}
#if WXWIN_COMPATIBILITY_2_6
long wxKeyEvent::KeyCode() const
{
return m_keyCode;
}
#endif // WXWIN_COMPATIBILITY_2_6
wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
{
SetEventType(wxEVT_CREATE);
@ -1069,11 +1054,7 @@ wxEvtHandler::~wxEvtHandler()
it != end;
++it )
{
#if WXWIN_COMPATIBILITY_EVENT_TYPES
wxEventTableEntry *entry = (wxEventTableEntry*)*it;
#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)*it;
#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
if (entry->m_callbackUserData)
delete entry->m_callbackUserData;
@ -1376,17 +1357,8 @@ void wxEvtHandler::Connect( int id, int lastId,
wxObject *userData,
wxEvtHandler* eventSink )
{
#if WXWIN_COMPATIBILITY_EVENT_TYPES
wxEventTableEntry *entry = new wxEventTableEntry;
entry->m_eventType = eventType;
entry->m_id = id;
entry->m_lastId = lastId;
entry->m_fn = func;
entry->m_callbackUserData = userData;
#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
wxDynamicEventTableEntry *entry =
new wxDynamicEventTableEntry(eventType, id, lastId, func, userData, eventSink);
#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
if (!m_dynamicEvents)
m_dynamicEvents = new wxList;
@ -1406,11 +1378,7 @@ bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
while (node)
{
#if WXWIN_COMPATIBILITY_EVENT_TYPES
wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
if ((entry->m_id == id) &&
((entry->m_lastId == lastId) || (lastId == wxID_ANY)) &&
@ -1438,11 +1406,7 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
while (node)
{
#if WXWIN_COMPATIBILITY_EVENT_TYPES
wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
// get next node before (maybe) calling the event handler as it could
// call Disconnect() invalidating the current node
@ -1450,17 +1414,10 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
if ((event.GetEventType() == entry->m_eventType) && (entry->m_fn != 0))
{
wxEvtHandler *handler =
#if !WXWIN_COMPATIBILITY_EVENT_TYPES
entry->m_eventSink ? entry->m_eventSink
:
#endif
this;
wxEvtHandler *handler = entry->m_eventSink ? entry->m_eventSink
: this;
if ( ProcessEventIfMatches(*entry, handler, event) )
{
return true;
}
}
}

View File

@ -50,10 +50,8 @@
IMPLEMENT_DYNAMIC_CLASS(wxChoicebook, wxBookCtrlBase)
IMPLEMENT_DYNAMIC_CLASS(wxChoicebookEvent, wxNotifyEvent)
#if !WXWIN_COMPATIBILITY_EVENT_TYPES
const wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING = wxNewEventType();
const wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED = wxNewEventType();
#endif
BEGIN_EVENT_TABLE(wxChoicebook, wxBookCtrlBase)
EVT_CHOICE(wxID_ANY, wxChoicebook::OnChoiceSelected)

View File

@ -50,10 +50,8 @@
IMPLEMENT_DYNAMIC_CLASS(wxListbook, wxBookCtrlBase)
IMPLEMENT_DYNAMIC_CLASS(wxListbookEvent, wxNotifyEvent)
#if !WXWIN_COMPATIBILITY_EVENT_TYPES
const wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING = wxNewEventType();
const wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED = wxNewEventType();
#endif
BEGIN_EVENT_TABLE(wxListbook, wxBookCtrlBase)
EVT_SIZE(wxListbook::OnSize)

View File

@ -46,10 +46,8 @@
IMPLEMENT_DYNAMIC_CLASS(wxToolbook, wxBookCtrlBase)
IMPLEMENT_DYNAMIC_CLASS(wxToolbookEvent, wxNotifyEvent)
#if !WXWIN_COMPATIBILITY_EVENT_TYPES
const wxEventType wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING = wxNewEventType();
const wxEventType wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED = wxNewEventType();
#endif
BEGIN_EVENT_TABLE(wxToolbook, wxBookCtrlBase)
EVT_SIZE(wxToolbook::OnSize)

View File

@ -48,12 +48,10 @@
IMPLEMENT_DYNAMIC_CLASS(wxTreebook, wxBookCtrlBase)
IMPLEMENT_DYNAMIC_CLASS(wxTreebookEvent, wxNotifyEvent)
#if !WXWIN_COMPATIBILITY_EVENT_TYPES
const wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING = wxNewEventType();
const wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED = wxNewEventType();
const wxEventType wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED = wxNewEventType();
const wxEventType wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED = wxNewEventType();
#endif
BEGIN_EVENT_TABLE(wxTreebook, wxBookCtrlBase)
EVT_TREE_SEL_CHANGED (wxID_ANY, wxTreebook::OnTreeSelectionChange)