X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cb59313ce503d859beafb94025a1c6822f59dbd6..3f3dc2efd04fae213a225331f8533665fc4cf9b8:/src/generic/treectlg.cpp diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 11b04eb171..6d56dc596d 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -112,7 +112,7 @@ class WXDLLEXPORT wxTreeRenameTimer: public wxTimer public: // start editing the current item after half a second (if the mouse hasn't // been clicked/moved) - static const int DELAY = 500; + enum { DELAY = 500 }; wxTreeRenameTimer( wxGenericTreeCtrl *owner ); @@ -158,7 +158,7 @@ class WXDLLEXPORT wxTreeFindTimer : public wxTimer { public: // reset the current prefix after half a second of inactivity - static const int DELAY = 500; + enum { DELAY = 500 }; wxTreeFindTimer( wxGenericTreeCtrl *owner ) { m_owner = owner; } @@ -1195,13 +1195,40 @@ wxTreeItemId wxGenericTreeCtrl::FindItem(const wxTreeItemId& idParent, // would be too bothersome wxString prefix = prefixOrig.Lower(); + // determine the starting point: we shouldn't take the current item (this + // allows to switch between two items starting with the same letter just by + // pressing it) but we shouldn't jump to the next one if the user is + // continuing to type as otherwise he might easily skip the item he wanted wxTreeItemId id = idParent; + if ( prefix.length() == 1 ) + { + id = GetNext(id); + } + // look for the item starting with the given prefix after it while ( id.IsOk() && !GetItemText(id).Lower().StartsWith(prefix) ) { id = GetNext(id); } + // if we haven't found anything... + if ( !id.IsOk() ) + { + // ... wrap to the beginning + id = GetRootItem(); + if ( HasFlag(wxTR_HIDE_ROOT) ) + { + // can't select virtual root + id = GetNext(id); + } + + // and try all the items (stop when we get to the one we started from) + while ( id != idParent && !GetItemText(id).Lower().StartsWith(prefix) ) + { + id = GetNext(id); + } + } + return id; } @@ -1406,7 +1433,7 @@ void wxGenericTreeCtrl::Expand(const wxTreeItemId& itemId) wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem; wxCHECK_RET( item, _T("invalid item in wxGenericTreeCtrl::Expand") ); - wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT) || itemId != GetRootItem(), + wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT) || itemId != GetRootItem(), _T("can't expand hidden root") ); if ( !item->HasPlus() ) @@ -1452,7 +1479,7 @@ void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId& item) void wxGenericTreeCtrl::Collapse(const wxTreeItemId& itemId) { - wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT) || itemId != GetRootItem(), + wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT) || itemId != GetRootItem(), _T("can't collapse hidden root") ); wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem; @@ -2589,12 +2616,15 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event ) default: // do not use wxIsalnum() here - if ( !event.HasModifiers() && isalnum(keyCode) ) + if ( !event.HasModifiers() && + ((keyCode >= '0' && keyCode <= '9') || + (keyCode >= 'a' && keyCode <= 'z') || + (keyCode >= 'A' && keyCode <= 'Z' ))) { // find the next item starting with the given prefix char ch = (char)keyCode; - - wxTreeItemId id = FindItem(m_current, m_findPrefix + ch); + + wxTreeItemId id = FindItem(m_current, m_findPrefix + (wxChar)ch); if ( !id.IsOk() ) { // no such item