]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 605189 ] add edit cancel notify to wxTreeEvent
authorJulian Smart <julian@anthemion.co.uk>
Thu, 5 Sep 2002 19:50:41 +0000 (19:50 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Thu, 5 Sep 2002 19:50:41 +0000 (19:50 +0000)
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

docs/changes.txt
docs/latex/wx/treeevt.tex
include/wx/generic/treectlg.h
include/wx/treebase.h
src/common/treebase.cpp
src/generic/treectlg.cpp
src/msw/treectrl.cpp

index 30398ec0249333a1178eaef5111ac597549cc938..04d174c99125d901d5b5ac7c7d92dd7a06e5acbd 100644 (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).
 - 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:
 
 
 wxMSW:
 
index 45ddeccb8b52871636a2e133e6f6742e247d536e..3889143b0fb201a448574419968957b350ae1940 100644 (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.
 
 
 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.
+
index b5e4c2f5498dfa2c7ec0d5006f3f98fe02123db3..8d88362e3aac63705ce73c6e88cfd6b1c19082ac 100644 (file)
@@ -429,6 +429,7 @@ protected:
 
     void OnRenameTimer();
     bool OnRenameAccept(wxGenericTreeItem *item, const wxString& value);
 
     void OnRenameTimer();
     bool OnRenameAccept(wxGenericTreeItem *item, const wxString& value);
+    void OnRenameCancelled(wxGenericTreeItem *item);
 
     void FillArray(wxGenericTreeItem*, wxArrayTreeItemIds&) const;
     void SelectItemRange( wxGenericTreeItem *item1, wxGenericTreeItem *item2 );
 
     void FillArray(wxGenericTreeItem*, wxArrayTreeItemIds&) const;
     void SelectItemRange( wxGenericTreeItem *item1, wxGenericTreeItem *item2 );
index 1cce85d260f67c4add490d29bdb698da807064cb..4f1af7fb6597fcd9c1df8ef2d42a8f75cae256fe 100644 (file)
@@ -239,6 +239,9 @@ public:
         // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
     const wxString& GetLabel() const { return m_label; }
 
         // 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(); }
 #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;
                   m_itemOld;
     wxPoint       m_pointDrag;
     wxString      m_label;
+    bool          m_editCancelled;
 
     friend class WXDLLEXPORT wxTreeCtrl;
     friend class WXDLLEXPORT wxGenericTreeCtrl;
 
     friend class WXDLLEXPORT wxTreeCtrl;
     friend class WXDLLEXPORT wxGenericTreeCtrl;
index 7c83963ef97c5acf5dba0aec0bea23fd8db0b66f..6bf725823f8ebaee1c6adcaae6df23a7688e9899 100644 (file)
@@ -74,6 +74,7 @@ wxTreeEvent::wxTreeEvent(wxEventType commandType, int id)
            : wxNotifyEvent(commandType, id)
 {
     m_itemOld = 0l;
            : wxNotifyEvent(commandType, id)
 {
     m_itemOld = 0l;
+    m_editCancelled = FALSE;
 }
 
 #endif // wxUSE_TREECTRL
 }
 
 #endif // wxUSE_TREECTRL
index 8c71e9962dc2eeeed915dd9e313812d82903b97d..3fb31eb75031880381cdb0d3235a90b99981713d 100644 (file)
@@ -449,6 +449,7 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
 
         case WXK_ESCAPE:
             Finish();
 
         case WXK_ESCAPE:
             Finish();
+            m_owner->OnRenameCancelled(m_itemEdited);
             break;
 
         default:
             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_item = (long) item;
     le.SetEventObject( this );
     le.m_label = value;
+    le.m_editCancelled = FALSE;
 
     return !GetEventHandler()->ProcessEvent( le ) || le.IsAllowed();
 }
 
 
     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 );
 void wxGenericTreeCtrl::OnRenameTimer()
 {
     Edit( m_current );
index 187d568c380c9ffec4b8f69a47d0f13e4b36a772..97348c58ff37e1e33813c0032730440762121236 100644 (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_item = (WXHTREEITEM) info->item.hItem;
                 event.m_label = info->item.pszText;
+                event.m_editCancelled = FALSE;
             }
             break;
 
             }
             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)
                 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;
             }
 
                 break;
             }