diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index bd6ae56b40..b5bdf2b7cc 100644 --- a/include/wx/generic/treectlg.h +++ b/include/wx/generic/treectlg.h @@ -370,6 +370,13 @@ private: // operation. void ResetFindState(); + // Find the next item, either looking inside the collapsed items or not. + enum + { + Next_Any = 0, + Next_Visible = 1 + }; + wxTreeItemId DoGetNext(const wxTreeItemId& item, int flags = 0) const; // True if we're using custom colours/font, respectively, or false if we're // using the default colours and should update them whenever system colours diff --git a/interface/wx/timer.h b/interface/wx/timer.h index 84bf360650..d2fdcba86c 100644 --- a/interface/wx/timer.h +++ b/interface/wx/timer.h @@ -126,8 +126,8 @@ public: To make your code more readable you may also use the following symbolic constants: - wxTIMER_CONTINUOUS: Start a normal, continuously running, timer - - wxTIMER_ONE_SHOT: Start a one shot timer - Alternatively, use StartOnce(). + - wxTIMER_ONE_SHOT: Start a one shot timer. Alternatively, and + preferably, call StartOnce() instead of this function. If the timer was already running, it will be stopped by this method before restarting it. diff --git a/samples/stc/stctest.cpp b/samples/stc/stctest.cpp index 09a468da6e..215be399d7 100644 --- a/samples/stc/stctest.cpp +++ b/samples/stc/stctest.cpp @@ -668,7 +668,7 @@ AppAbout::AppAbout (wxWindow *parent, m_timer = nullptr; if (milliseconds > 0) { m_timer = new wxTimer (this, myID_ABOUTTIMER); - m_timer->Start (milliseconds, wxTIMER_ONE_SHOT); + m_timer->StartOnce(milliseconds); } // Get version of Scintilla diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index b67277023c..9cadecd37c 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -2420,7 +2420,7 @@ void wxListMainWindow::OnRenameCancelled(size_t itemEdit) void wxListMainWindow::OnFindTimer() { m_findPrefix.clear(); - if ( m_findBell ) + if ( m_findBell == -1 ) m_findBell = 1; } @@ -3168,7 +3168,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) // Notice that we should start the timer even if we didn't find // anything to make sure we reset the search state later. - m_findTimer->Start(wxListFindTimer::DELAY, wxTIMER_ONE_SHOT); + m_findTimer->StartOnce(wxListFindTimer::DELAY); // restart timer even when there's no match so bell get's reset if ( item != (size_t)-1 ) @@ -3182,7 +3182,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) // Reset the bell flag if it had been temporarily disabled // before. - if ( m_findBell ) + if ( m_findBell == -1 ) m_findBell = 1; } else // No such item diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 50df9598e2..c86486d0d9 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -1489,29 +1489,36 @@ wxTreeItemId wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const // Only for internal use right now, but should probably be public wxTreeItemId wxGenericTreeCtrl::GetNext(const wxTreeItemId& item) const +{ + return DoGetNext(item, Next_Any); +} + +wxTreeItemId +wxGenericTreeCtrl::DoGetNext(const wxTreeItemId& item, int flags) const { wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); wxGenericTreeItem *i = (wxGenericTreeItem*) item.m_pItem; // First see if there are any children. - wxArrayGenericTreeItems& children = i->GetChildren(); - if (children.GetCount() > 0) + if ( !(flags & Next_Visible) || i->IsExpanded() ) { - return children.Item(0); - } - else - { - // Try a sibling of this or ancestor instead - wxTreeItemId p = item; - wxTreeItemId toFind; - do - { - toFind = GetNextSibling(p); - p = GetItemParent(p); - } while (p.IsOk() && !toFind.IsOk()); - return toFind; + wxArrayGenericTreeItems& children = i->GetChildren(); + if (children.GetCount() > 0) + { + return children.Item(0); + } } + + // Try a sibling of this or ancestor instead + wxTreeItemId p = item; + wxTreeItemId toFind; + do + { + toFind = GetNextSibling(p); + p = GetItemParent(p); + } while (p.IsOk() && !toFind.IsOk()); + return toFind; } wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const @@ -1535,16 +1542,7 @@ wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); wxASSERT_MSG( IsVisible(item), wxT("this item itself should be visible") ); - wxTreeItemId id = item; - if (id.IsOk()) - { - while (id = GetNext(id), id.IsOk()) - { - if (IsVisible(id)) - return id; - } - } - return wxTreeItemId(); + return DoGetNext(item, Next_Visible); } wxTreeItemId wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const @@ -1592,7 +1590,7 @@ void wxGenericTreeCtrl::ResetTextControl() void wxGenericTreeCtrl::ResetFindState() { m_findPrefix.clear(); - if ( m_findBell ) + if ( m_findBell == -1 ) m_findBell = 1; } @@ -1612,13 +1610,13 @@ wxTreeItemId wxGenericTreeCtrl::FindItem(const wxTreeItemId& idParent, wxTreeItemId itemid = idParent; if ( prefix.length() == 1 ) { - itemid = GetNext(itemid); + itemid = DoGetNext(itemid, Next_Visible); } // look for the item starting with the given prefix after it while ( itemid.IsOk() && !GetItemText(itemid).Lower().StartsWith(prefix) ) { - itemid = GetNext(itemid); + itemid = DoGetNext(itemid, Next_Visible); } // if we haven't found anything... @@ -1629,14 +1627,14 @@ wxTreeItemId wxGenericTreeCtrl::FindItem(const wxTreeItemId& idParent, if ( HasFlag(wxTR_HIDE_ROOT) ) { // can't select virtual root - itemid = GetNext(itemid); + itemid = DoGetNext(itemid, Next_Visible); } // and try all the items (stop when we get to the one we started from) while ( itemid.IsOk() && itemid != idParent && !GetItemText(itemid).Lower().StartsWith(prefix) ) { - itemid = GetNext(itemid); + itemid = DoGetNext(itemid, Next_Visible); } // If we haven't found the item but wrapped back to the one we started // from, id.IsOk() must be false @@ -3390,7 +3388,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event ) // Notice that we should start the timer even if we didn't find // anything to make sure we reset the search state later. - m_findTimer->Start(wxTreeFindTimer::DELAY, wxTIMER_ONE_SHOT); + m_findTimer->StartOnce(wxTreeFindTimer::DELAY); if ( id.IsOk() ) { @@ -3398,7 +3396,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event ) // Reset the bell flag if it had been temporarily disabled // before. - if ( m_findBell ) + if ( m_findBell == -1 ) m_findBell = 1; } else // No such item