From fbb1226068b93ebee0de6a3c78c09a801265e9c8 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 11 Dec 2002 09:08:46 +0000 Subject: [PATCH] Applied patch [ 651287 ] adds missing wxTreeCtrl::GetEditControl This patch implements a missing member in the generic version of the wxTreeCtrl. The GetEditControl member is currently not implemented in the generic tree control used by wxGTK. This patch implements the feature by 1. adding a pointer to the wxTextTreeControl as a member (m_textCtrl) of the wxGenericTreeCtrl class 2. making sure pointer was initialized to 0 3. using the member variable instead of the stack variable in the wxGenericTreeCtrl::Edit member 4. making sure the new wxGenericTreeCtrl class member is set to 0 when the control is set up for deletion in Finish by calling a new protected member (ResetTextControl) of the wxGenericTreeCtrl class. These modification were discussed on the wx-dev list under the "wxGTK - wxTreeCtrl::GetEditControl status?" subject. I have tested, but I certainly welcome comments and further testing. Pete Stieber git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18192 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/treectlg.h | 9 +++++++++ src/generic/treectlg.cpp | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index 8cf87709b1..79a1a7e5da 100644 --- a/include/wx/generic/treectlg.h +++ b/include/wx/generic/treectlg.h @@ -33,6 +33,7 @@ class WXDLLEXPORT wxTreeItemData; class WXDLLEXPORT wxTreeRenameTimer; class WXDLLEXPORT wxTreeFindTimer; class WXDLLEXPORT wxTreeTextCtrl; +class WXDLLEXPORT wxTextCtrl; // ----------------------------------------------------------------------------- // wxGenericTreeCtrl - the tree control @@ -315,6 +316,10 @@ public: // been before. void EditLabel( const wxTreeItemId& item ) { Edit( item ); } void Edit( const wxTreeItemId& item ); + // returns a pointer to the text edit control if the item is being + // edited, NULL otherwise (it's assumed that no more than one item may + // be edited simultaneously) + wxTextCtrl* GetEditControl() const; // sorting // this function is called to compare 2 items and should return -1, 0 @@ -385,6 +390,7 @@ protected: wxGenericTreeItem *m_dropTarget; wxCursor m_oldCursor; // cursor is changed while dragging wxGenericTreeItem *m_oldSelection; + wxTreeTextCtrl *m_textCtrl; wxTimer *m_renameTimer; @@ -411,6 +417,9 @@ protected: int image, int selectedImage, wxTreeItemData *data); + // called by wxTextTreeCtrl when it marks itself for deletion + void ResetTextControl(); + // find the first item starting with the given prefix after the given item wxTreeItemId FindItem(const wxTreeItemId& id, const wxString& prefix) const; diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 10b2517c13..b8943bc4e6 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -427,6 +427,8 @@ void wxTreeTextCtrl::Finish() { if ( !m_finished ) { + m_owner->ResetTextControl(); + wxPendingDelete.Append(this); m_finished = TRUE; @@ -755,6 +757,7 @@ void wxGenericTreeCtrl::Init() m_dragCount = 0; m_isDragging = FALSE; m_dropTarget = m_oldSelection = (wxGenericTreeItem *)NULL; + m_textCtrl = NULL; m_renameTimer = NULL; m_findTimer = NULL; @@ -1265,6 +1268,12 @@ wxTreeItemId wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const return wxTreeItemId(); } +// called by wxTextTreeCtrl when it marks itself for deletion +void wxGenericTreeCtrl::ResetTextControl() +{ + m_textCtrl = NULL; +} + // find the first item starting with the given prefix after the given item wxTreeItemId wxGenericTreeCtrl::FindItem(const wxTreeItemId& idParent, const wxString& prefixOrig) const @@ -2809,9 +2818,17 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item ) if ( m_dirty ) wxYieldIfNeeded(); - wxTreeTextCtrl *text = new wxTreeTextCtrl(this, itemEdit); + m_textCtrl = new wxTreeTextCtrl(this, itemEdit); - text->SetFocus(); + m_textCtrl->SetFocus(); +} + +// returns a pointer to the text edit control if the item is being +// edited, NULL otherwise (it's assumed that no more than one item may +// be edited simultaneously) +wxTextCtrl* wxGenericTreeCtrl::GetEditControl() const +{ + return m_textCtrl; } bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem *item, -- 2.45.2