Refactor wxKeyEvent copying code.

Avoid duplication between copy ctor and assignment operator.

Also extract the assignment of everything not including the event type in a
reusable function as this can be useful for key event generation code in wxGTK
and possibly other ports.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-12-02 00:50:16 +00:00
parent edf5822ace
commit dfc7216da7
2 changed files with 18 additions and 20 deletions

View File

@@ -1717,16 +1717,7 @@ public:
// implicitly defined operator=() so need to do it this way: // implicitly defined operator=() so need to do it this way:
*static_cast<wxKeyboardState *>(this) = evt; *static_cast<wxKeyboardState *>(this) = evt;
m_x = evt.m_x; DoAssignMembers(evt);
m_y = evt.m_y;
m_keyCode = evt.m_keyCode;
m_rawCode = evt.m_rawCode;
m_rawFlags = evt.m_rawFlags;
#if wxUSE_UNICODE
m_uniChar = evt.m_uniChar;
#endif
} }
return *this; return *this;
} }
@@ -1748,6 +1739,22 @@ public:
wxUint32 m_rawFlags; wxUint32 m_rawFlags;
private: private:
// Copy only the event data present in this class, this is used by
// AssignKeyData() and copy ctor.
void DoAssignMembers(const wxKeyEvent& evt)
{
m_x = evt.m_x;
m_y = evt.m_y;
m_keyCode = evt.m_keyCode;
m_rawCode = evt.m_rawCode;
m_rawFlags = evt.m_rawFlags;
#if wxUSE_UNICODE
m_uniChar = evt.m_uniChar;
#endif
}
DECLARE_DYNAMIC_CLASS(wxKeyEvent) DECLARE_DYNAMIC_CLASS(wxKeyEvent)
}; };

View File

@@ -741,16 +741,7 @@ wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt)
: wxEvent(evt), : wxEvent(evt),
wxKeyboardState(evt) wxKeyboardState(evt)
{ {
m_x = evt.m_x; DoAssignMembers(evt);
m_y = evt.m_y;
m_keyCode = evt.m_keyCode;
m_rawCode = evt.m_rawCode;
m_rawFlags = evt.m_rawFlags;
#if wxUSE_UNICODE
m_uniChar = evt.m_uniChar;
#endif
} }
bool wxKeyEvent::IsKeyInCategory(int category) const bool wxKeyEvent::IsKeyInCategory(int category) const