]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/treectlg.cpp
Code and warning cleaning.
[wxWidgets.git] / src / generic / treectlg.cpp
index 5dede2bf17856cab073f40d92c85cc865244dfe4..61cfce6b525ebd54b0696729fd849e6c3b79c6e1 100644 (file)
@@ -88,11 +88,25 @@ class WXDLLEXPORT wxTreeTextCtrl: public wxTextCtrl
 public:
     wxTreeTextCtrl(wxGenericTreeCtrl *owner, wxGenericTreeItem *item);
 
+    // wxGenericTreeCtrl can use this one to abandon editing the given item,
+    // it's not an error to call it if this item is not being edited
+    void StopEditing(wxGenericTreeItem *item)
+    {
+        if ( item == m_itemEdited )
+            DoStopEditing();
+    }
+
 protected:
     void OnChar( wxKeyEvent &event );
     void OnKeyUp( wxKeyEvent &event );
     void OnKillFocus( wxFocusEvent &event );
 
+    void DoStopEditing()
+    {
+        Finish();
+        m_owner->OnRenameCancelled(m_itemEdited);
+    }
+
     bool AcceptChanges();
     void Finish();
 
@@ -413,12 +427,10 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
                 Finish();
             }
             // else do nothing, do not accept and do not close
-
             break;
 
         case WXK_ESCAPE:
-            Finish();
-            m_owner->OnRenameCancelled(m_itemEdited);
+            DoStopEditing();
             break;
 
         default:
@@ -440,7 +452,7 @@ void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event )
             sx = parentSize.x - myPos.x;
         if (mySize.x > sx)
             sx = mySize.x;
-        SetSize(sx, wxDefaultSize.y);
+        SetSize(sx, wxDefaultCoord);
     }
 
     event.Skip();
@@ -448,16 +460,17 @@ void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event )
 
 void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &event )
 {
-    if ( m_finished )
-    {
-        event.Skip();
-        return;
-    }
-
-    if ( AcceptChanges() )
+    if ( !m_finished )
     {
+        AcceptChanges();
+        // We must finish regardless of success, otherwise we'll get
+        // focus problems:
         Finish();
     }
+
+    // We must let the native text control handle focus, too, otherwise
+    // it could have problems with the cursor (e.g., in wxGTK):
+    event.Skip();
 }
 
 // -----------------------------------------------------------------------------
@@ -791,9 +804,10 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
 #endif
 
     wxVisualAttributes attr = GetDefaultAttributes();
-    SetDefaultForegroundColour( attr.colFg );
-    SetDefaultBackgroundColour( attr.colBg );
-    SetDefaultFont(attr.font);
+    SetOwnForegroundColour( attr.colFg );
+    SetOwnBackgroundColour( attr.colBg );
+    if (!m_hasFont)
+        SetOwnFont(attr.font);
 
 //  m_dottedPen = wxPen( "grey", 0, wxDOT );  too slow under XFree86
     m_dottedPen = wxPen( wxT("grey"), 0, 0 );
@@ -1293,7 +1307,7 @@ wxTreeItemId wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const
 // called by wxTextTreeCtrl when it marks itself for deletion
 void wxGenericTreeCtrl::ResetTextControl()
 {
-  m_textCtrl = NULL;
+    m_textCtrl = NULL;
 }
 
 // find the first item starting with the given prefix after the given item
@@ -1493,6 +1507,12 @@ void wxGenericTreeCtrl::Delete(const wxTreeItemId& itemId)
 
     wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem;
 
+    if ( m_textCtrl )
+    {
+        // can't delete the item being edited, cancel editing it first
+        m_textCtrl->StopEditing(item);
+    }
+
     wxGenericTreeItem *parent = item->GetParent();
 
     // don't keep stale pointers around!
@@ -2768,9 +2788,9 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
                   (keyCode >= 'A' && keyCode <= 'Z' )))
             {
                 // find the next item starting with the given prefix
-                char ch = (char)keyCode;
+                wxChar ch = (wxChar)keyCode;
 
-                wxTreeItemId id = FindItem(m_current, m_findPrefix + (wxChar)ch);
+                wxTreeItemId id = FindItem(m_current, m_findPrefix + ch);
                 if ( !id.IsOk() )
                 {
                     // no such item
@@ -2911,9 +2931,6 @@ void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem *item)
     GetEventHandler()->ProcessEvent( le );
 }
 
-
-
-
 void wxGenericTreeCtrl::OnRenameTimer()
 {
     Edit( m_current );