X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/422d0ff0bec79832494fe4605ffdcf8e87ba6c03..e11898f903183f897a2b2a50a4447ea73ba7273f:/src/generic/treectlg.cpp diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 4f7bb21448..b733643760 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -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(); @@ -361,6 +375,16 @@ wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl *owner, // FIXME: what are all these hardcoded 4, 8 and 11s really? x += image_w; w -= image_w + 4; +#ifdef __WXMAC__ + wxSize bs = DoGetBestSize() ; + // edit control height + if ( h > bs.y - 8 ) + { + int diff = h - ( bs.y - 8 ) ; + h -= diff ; + y += diff / 2 ; + } +#endif (void)Create(m_owner, wxID_ANY, m_startValue, wxPoint(x - 4, y - 4), wxSize(w + 11, h + 8)); @@ -413,12 +437,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: @@ -448,16 +470,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(); } // ----------------------------------------------------------------------------- @@ -1294,7 +1317,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 @@ -1494,6 +1517,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! @@ -2912,9 +2941,6 @@ void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem *item) GetEventHandler()->ProcessEvent( le ); } - - - void wxGenericTreeCtrl::OnRenameTimer() { Edit( m_current ); @@ -3460,6 +3486,15 @@ void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent &event ) } +wxSize wxGenericTreeCtrl::DoGetBestSize() const +{ + // something is better than nothing... + // 100x80 is what the MSW version will get from the default + // wxControl::DoGetBestSize + return wxSize(100,80); +} + + // NOTE: If using the wxListBox visual attributes works everywhere then this can // be removed, as well as the #else case below. #define _USE_VISATTR 0