From: Vadim Zeitlin Date: Mon, 24 Sep 2001 16:39:49 +0000 (+0000) Subject: added wxTreeEvent::GetKeyEvent() to allow to retrieve the key event flags from EVT_TR... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/b09bda689c8525886d217a9b171b354391cd6d78 added wxTreeEvent::GetKeyEvent() to allow to retrieve the key event flags from EVT_TREE_KEY_DOWN event git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11687 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/treeevt.tex b/docs/latex/wx/treeevt.tex index e62bc7da97..666dfb1595 100644 --- a/docs/latex/wx/treeevt.tex +++ b/docs/latex/wx/treeevt.tex @@ -48,33 +48,41 @@ functions that take a wxTreeEvent argument. Constructor. +\membersection{wxTreeEvent::GetCode} + +\constfunc{int}{GetCode}{} + +Returns the key code if the event was is a key event. Use +\helpref{GetKeyEvent}{wxtreeeventgetkeyevent} to get the values of the +modifier keys for this event (i.e. Shift or Ctrl). + \membersection{wxTreeEvent::GetItem} \constfunc{wxTreeItemId}{GetItem}{} Returns he item (valid for all events). -\membersection{wxTreeEvent::GetOldItem} +\membersection{wxTreeEvent::GetKeyEvent}\label{wxtreeeventgetkeyevent} -\constfunc{wxTreeItemId}{GetOldItem}{} +\constfunc{const wxKeyEvent\&}{GetKeyEvent}{} -Returns the old item index (valid for EVT\_TREE\_ITEM\_CHANGING and CHANGED events) +Returns the key event for {\tt EVT\_TREE\_KEY\_DOWN} events. -\membersection{wxTreeEvent::GetPoint()} +\membersection{wxTreeEvent::GetLabel} -\constfunc{wxPoint}{GetPoint}{} +\constfunc{const wxString\&}{GetLabel}{} -Returns the position of the mouse pointer if the event is a drag event. +Returns the label if the event was a begin or end edit label event. -\membersection{wxTreeEvent::GetCode} +\membersection{wxTreeEvent::GetOldItem} -\constfunc{int}{GetCode}{} +\constfunc{wxTreeItemId}{GetOldItem}{} -The key code if the event was is a key event. +Returns the old item index (valid for EVT\_TREE\_ITEM\_CHANGING and CHANGED events) -\membersection{wxTreeEvent::GetLabel} +\membersection{wxTreeEvent::GetPoint()} -\constfunc{const wxString\&}{GetLabel}{} +\constfunc{wxPoint}{GetPoint}{} -Returns the label if the event was a begin or end edit label event. +Returns the position of the mouse pointer if the event is a drag event. diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 3a77679b8a..65fd4641b6 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -435,6 +435,9 @@ protected: virtual void DoSetToolTip( wxToolTip *tip ); #endif // wxUSE_TOOLTIPS + // the helper functions used by HandleChar/KeyXXX methods + wxKeyEvent CreateKeyEvent(wxEventType evType, int id, WXLPARAM lp) const; + private: // common part of all ctors void Init(); @@ -447,9 +450,6 @@ private: bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); #endif // __WIN95__ - // the helper functions used by HandleChar/KeyXXX methods - wxKeyEvent CreateKeyEvent(wxEventType evType, int id, WXLPARAM lp) const; - DECLARE_DYNAMIC_CLASS(wxWindowMSW) DECLARE_NO_COPY_CLASS(wxWindowMSW) DECLARE_EVENT_TABLE() diff --git a/include/wx/treebase.h b/include/wx/treebase.h index 10f382f466..af9c822f9e 100644 --- a/include/wx/treebase.h +++ b/include/wx/treebase.h @@ -222,11 +222,6 @@ private: class WXDLLEXPORT wxTreeEvent : public wxNotifyEvent { - friend class WXDLLEXPORT wxTreeCtrl; - friend class WXDLLEXPORT wxGenericTreeCtrl; - - DECLARE_DYNAMIC_CLASS(wxTreeEvent); - public: wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0); @@ -243,19 +238,25 @@ public: // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) or click position wxPoint GetPoint() const { return m_pointDrag; } - // keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only) - int GetCode() const { return m_code; } + // keyboard data (for wxEVT_COMMAND_TREE_KEY_DOWN only) + const wxKeyEvent& GetKeyEvent() const { return m_evtKey; } + int GetCode() const { return m_evtKey.GetKeyCode(); } // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only) const wxString& GetLabel() const { return m_label; } private: - // we could probably save some space by using union here - int m_code; + // not all of the members are used (or initialized) for all events + wxKeyEvent m_evtKey; wxTreeItemId m_item, m_itemOld; wxPoint m_pointDrag; wxString m_label; + + friend class WXDLLEXPORT wxTreeCtrl; + friend class WXDLLEXPORT wxGenericTreeCtrl; + + DECLARE_DYNAMIC_CLASS(wxTreeEvent); }; typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); diff --git a/src/common/treebase.cpp b/src/common/treebase.cpp index 0a49f60cf8..7c83963ef9 100644 --- a/src/common/treebase.cpp +++ b/src/common/treebase.cpp @@ -73,7 +73,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxNotifyEvent) wxTreeEvent::wxTreeEvent(wxEventType commandType, int id) : wxNotifyEvent(commandType, id) { - m_code = 0; m_itemOld = 0l; } diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 8cb44c1142..34c4ccd440 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -360,21 +360,6 @@ void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) m_owner->OnRenameAccept(); } -#if 0 -// ----------------------------------------------------------------------------- -// wxTreeEvent -// ----------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxNotifyEvent) - -wxTreeEvent::wxTreeEvent( wxEventType commandType, int id ) - : wxNotifyEvent( commandType, id ) -{ - m_code = 0; - m_itemOld = (wxGenericTreeItem *)NULL; -} -#endif - // ----------------------------------------------------------------------------- // wxGenericTreeItem // ----------------------------------------------------------------------------- @@ -2172,7 +2157,7 @@ void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent &event ) void wxGenericTreeCtrl::OnChar( wxKeyEvent &event ) { wxTreeEvent te( wxEVT_COMMAND_TREE_KEY_DOWN, GetId() ); - te.m_code = (int)event.KeyCode(); + te.m_evtKey = event; te.SetEventObject( this ); if ( GetEventHandler()->ProcessEvent( te ) ) { @@ -2236,7 +2221,6 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event ) { wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() ); event.m_item = (long) m_current; - event.m_code = 0; event.SetEventObject( this ); GetEventHandler()->ProcessEvent( event ); } @@ -2661,7 +2645,6 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) { wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, GetId()); nevent.m_item = (long) item; - nevent.m_code = 0; CalcScrolledPosition(x, y, &nevent.m_pointDrag.x, &nevent.m_pointDrag.y); @@ -2725,7 +2708,6 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) // send activate event first wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() ); nevent.m_item = (long) item; - nevent.m_code = 0; CalcScrolledPosition(x, y, &nevent.m_pointDrag.x, &nevent.m_pointDrag.y); diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 5e20b78bb5..f281288391 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -2070,9 +2070,6 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) } case TVN_ITEMEXPANDING: - event.m_code = FALSE; - // fall through - case TVN_ITEMEXPANDED: { NM_TREEVIEW* tv = (NM_TREEVIEW*)lParam; @@ -2104,7 +2101,11 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) eventType = wxEVT_COMMAND_TREE_KEY_DOWN; TV_KEYDOWN *info = (TV_KEYDOWN *)lParam; - event.m_code = wxCharCodeMSWToWX(info->wVKey); + // we pass 0 as last CreateKeyEvent() parameter because we + // don't have access to the real key press flags here - but as + // it is only used to determin wxKeyEvent::m_altDown flag it's + // not too bad + event.m_evtKey = CreateKeyEvent(wxEVT_KEY_DOWN, info->wVKey, 0); // a separate event for Space/Return if ( !wxIsCtrlDown() && !wxIsShiftDown() && diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 5eb41c8715..228c270785 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -3810,8 +3810,8 @@ bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam) // create the key event of the given type for the given key - used by // HandleChar and HandleKeyDown/Up wxKeyEvent wxWindowMSW::CreateKeyEvent(wxEventType evType, - int id, - WXLPARAM lParam) const + int id, + WXLPARAM lParam) const { wxKeyEvent event(evType); event.SetId(GetId());