From: Vadim Zeitlin <vadim@wxwidgets.org> Date: Sun, 3 Apr 2005 00:27:52 +0000 (+0000) Subject: make it possible to change the text of the item being edited from OnBeginLabelEdit() X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/646a8a4d0e965993411ae958ffbd6e7a7d87678c make it possible to change the text of the item being edited from OnBeginLabelEdit() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33296 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 3a3f8d43e1..5ff0f681ff 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -1105,6 +1105,11 @@ void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent& event) event.Veto(); } + else if ( itemId == GetRootItem() ) + { + // test that it is possible to change the text of the item being edited + SetItemText(itemId, _T("Editing root item")); + } } void MyTreeCtrl::OnEndLabelEdit(wxTreeEvent& event) diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 4e277888cf..8cc634935e 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -2577,6 +2577,10 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) eventType = wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT; TV_DISPINFO *info = (TV_DISPINFO *)lParam; + // although the user event handler may still veto it, it is + // important to set it now so that calls to SetItemText() from + // the event handler would change the text controls contents + m_idEdited = event.m_item = info->item.hItem; event.m_label = info->item.pszText; event.m_editCancelled = false; @@ -2942,8 +2946,9 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) case TVN_BEGINLABELEDIT: // return true to cancel label editing *result = !event.IsAllowed(); + // set ES_WANTRETURN ( like we do in BeginLabelEdit ) - if(event.IsAllowed()) + if ( event.IsAllowed() ) { HWND hText = TreeView_GetEditControl(GetHwnd()); if(hText != NULL) @@ -2968,6 +2973,10 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) | wxTE_PROCESS_ENTER); } } + else // we had set m_idEdited before + { + m_idEdited.Unset(); + } break; case TVN_ENDLABELEDIT: