Benjamin I. Williams
Currently there is no way of receiving notification
that a user cancelled an edit operation on a wxTreeCtrl
tree node label.
This patch adds a method "IsEditCancelled" to the
wxTreeEvent class. During an EVT_TREE_END_LABEL_EDIT
event, the programmer can now determine whether or not
the edit operation was cancelled by the user (by
pressing <ESC>).
This patch provides this implementation for both
wxMSW's wxTreeCtrl and the wxGenericTreeCtrl. Both
situations have been tested and work well.
The patch is not very invasive, and is much smaller
than I had expected.
Please see the relevent discussion on the wx-dev list
for more details.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16995
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
- generic wxListCtrl renamed to wxGenericListCtrl, wxImageList
renamed to wxGenericImageList, so they can be used on wxMSW
(Rene Rivera).
+- Added wxTreeEvent::IsEditCancelled so the application can tell
+ whether a label edit was cancelled.
wxMSW:
Returns the position of the mouse pointer if the event is a drag event.
+\membersection{wxTreeEvent::IsEditCancelled()}
+
+\constfunc{bool}{IsEditCancelled}{}
+
+Returns TRUE if the label edit was cancelled. This should be
+called from within an EVT\_TREE\_END\_LABEL\_EDIT handler.
+
void OnRenameTimer();
bool OnRenameAccept(wxGenericTreeItem *item, const wxString& value);
+ void OnRenameCancelled(wxGenericTreeItem *item);
void FillArray(wxGenericTreeItem*, wxArrayTreeItemIds&) const;
void SelectItemRange( wxGenericTreeItem *item1, wxGenericTreeItem *item2 );
// label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
const wxString& GetLabel() const { return m_label; }
+ // edit cancel flag (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
+ bool IsEditCancelled() const { return m_editCancelled; }
+
#if WXWIN_COMPATIBILITY_2_2
// for compatibility only, don't use
int GetCode() const { return m_evtKey.GetKeyCode(); }
m_itemOld;
wxPoint m_pointDrag;
wxString m_label;
+ bool m_editCancelled;
friend class WXDLLEXPORT wxTreeCtrl;
friend class WXDLLEXPORT wxGenericTreeCtrl;
: wxNotifyEvent(commandType, id)
{
m_itemOld = 0l;
+ m_editCancelled = FALSE;
}
#endif // wxUSE_TREECTRL
case WXK_ESCAPE:
Finish();
+ m_owner->OnRenameCancelled(m_itemEdited);
break;
default:
le.m_item = (long) item;
le.SetEventObject( this );
le.m_label = value;
+ le.m_editCancelled = FALSE;
return !GetEventHandler()->ProcessEvent( le ) || le.IsAllowed();
}
+void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem *item)
+{
+ // let owner know that the edit was cancelled
+ wxTreeEvent le( wxEVT_COMMAND_TREE_END_LABEL_EDIT, GetId() );
+ le.m_item = (long) item;
+ le.SetEventObject( this );
+ le.m_label = wxEmptyString;
+ le.m_editCancelled = FALSE;
+
+ GetEventHandler()->ProcessEvent( le );
+}
+
+
+
+
void wxGenericTreeCtrl::OnRenameTimer()
{
Edit( m_current );
event.m_item = (WXHTREEITEM) info->item.hItem;
event.m_label = info->item.pszText;
+ event.m_editCancelled = FALSE;
}
break;
event.m_item = (WXHTREEITEM)info->item.hItem;
event.m_label = info->item.pszText;
if (info->item.pszText == NULL)
- return FALSE;
+ {
+ event.m_editCancelled = TRUE;
+ }
+ else
+ {
+ event.m_editCancelled = FALSE;
+ }
break;
}