Applied patch [ 605189 ] add edit cancel notify to wxTreeEvent

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
This commit is contained in:
Julian Smart
2002-09-05 19:50:41 +00:00
parent 67a92fff32
commit dd23c25cde
7 changed files with 40 additions and 1 deletions

View File

@@ -240,6 +240,8 @@ All (GUI):
- 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:

View File

@@ -91,3 +91,10 @@ Returns the old item index (valid for EVT\_TREE\_ITEM\_CHANGING and CHANGED even
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.

View File

@@ -429,6 +429,7 @@ protected:
void OnRenameTimer();
bool OnRenameAccept(wxGenericTreeItem *item, const wxString& value);
void OnRenameCancelled(wxGenericTreeItem *item);
void FillArray(wxGenericTreeItem*, wxArrayTreeItemIds&) const;
void SelectItemRange( wxGenericTreeItem *item1, wxGenericTreeItem *item2 );

View File

@@ -239,6 +239,9 @@ public:
// 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(); }
@@ -251,6 +254,7 @@ private:
m_itemOld;
wxPoint m_pointDrag;
wxString m_label;
bool m_editCancelled;
friend class WXDLLEXPORT wxTreeCtrl;
friend class WXDLLEXPORT wxGenericTreeCtrl;

View File

@@ -74,6 +74,7 @@ wxTreeEvent::wxTreeEvent(wxEventType commandType, int id)
: wxNotifyEvent(commandType, id)
{
m_itemOld = 0l;
m_editCancelled = FALSE;
}
#endif // wxUSE_TREECTRL

View File

@@ -449,6 +449,7 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
case WXK_ESCAPE:
Finish();
m_owner->OnRenameCancelled(m_itemEdited);
break;
default:
@@ -2792,10 +2793,26 @@ bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem *item,
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 );

View File

@@ -2228,6 +2228,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
event.m_item = (WXHTREEITEM) info->item.hItem;
event.m_label = info->item.pszText;
event.m_editCancelled = FALSE;
}
break;
@@ -2254,7 +2255,13 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
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;
}