From: Vadim Zeitlin Date: Sun, 7 Oct 2012 22:42:02 +0000 (+0000) Subject: Add a possibility to beep on no match to wxGenericTreeCtrl. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/27bc919446f8b5ad1c52d1e998d01240c9f609df Add a possibility to beep on no match to wxGenericTreeCtrl. For consistency with Windows, allow to optionally generate a beep when incremental search in the tree control doesn't find anything. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72638 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 220a922f25..39af7ad563 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -565,6 +565,7 @@ All (GUI): - Add limited support for CSS styles for tags too in wxHTML (gevorg). - Add "inherit" to XRC tag (Steffen Olszewski, Gero Meßsysteme GmbH). - Add support for wxALWAYS_SHOW_SB style to wxScrolled<> (Catalin Raceanu). +- Add wxTreeCtrl::EnableBellOnNoMatch() (Jonathan Dagresta). wxGTK: diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index c5010ecd03..168247c91c 100644 --- a/include/wx/generic/treectlg.h +++ b/include/wx/generic/treectlg.h @@ -65,7 +65,6 @@ public: const wxValidator &validator = wxDefaultValidator, const wxString& name = wxTreeCtrlNameStr); - // implement base class pure virtuals // ---------------------------------- @@ -169,6 +168,8 @@ public: virtual void EndEditLabel(const wxTreeItemId& item, bool discardChanges = false); + virtual void EnableBellOnNoMatch(bool on = true); + virtual void SortChildren(const wxTreeItemId& item); // items geometry @@ -275,6 +276,10 @@ protected: // incremental search data wxString m_findPrefix; wxTimer *m_findTimer; + // This flag is set to 0 if the bell is disabled, 1 if it is enabled and -1 + // if it is globally enabled but has been temporarily disabled because we + // had already beeped for this particular search. + int m_findBell; bool m_dropEffectAboveItem; @@ -352,6 +357,10 @@ protected: virtual wxSize DoGetBestSize() const; private: + // Reset the state of the last find (i.e. keyboard incremental search) + // operation. + void ResetFindState(); + DECLARE_EVENT_TABLE() DECLARE_DYNAMIC_CLASS(wxGenericTreeCtrl) wxDECLARE_NO_COPY_CLASS(wxGenericTreeCtrl); diff --git a/include/wx/treectrl.h b/include/wx/treectrl.h index 5bc63827fc..c23920964e 100644 --- a/include/wx/treectrl.h +++ b/include/wx/treectrl.h @@ -349,6 +349,10 @@ public: virtual void EndEditLabel(const wxTreeItemId& item, bool discardChanges = false) = 0; + // Enable or disable beep when incremental match doesn't find any item. + // Only implemented in the generic version currently. + virtual void EnableBellOnNoMatch(bool WXUNUSED(on) = true) { } + // sorting // ------- diff --git a/interface/wx/treectrl.h b/interface/wx/treectrl.h index 4587dfa9de..9b25d1a7e5 100644 --- a/interface/wx/treectrl.h +++ b/interface/wx/treectrl.h @@ -339,6 +339,18 @@ public: virtual wxTextCtrl *EditLabel(const wxTreeItemId& item, wxClassInfo* textCtrlClass = wxCLASSINFO(wxTextCtrl)); + /** + Enable or disable a beep if there is no match for the currently + entered text when searching for the item from keyboard. + + The default is to not beep in this case except in wxMSW where the + beep is always generated by the native control and cannot be disabled, + i.e. calls to this function do nothing there. + + @since 2.9.5 + */ + void EnableBellOnNoMatch(bool on = true); + /** Ends label editing. If @a cancelEdit is @true, the edit will be cancelled. diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 229a9badb8..8e0064d1df 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -113,6 +113,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) MENU_LINK(Recreate) MENU_LINK(ToggleImages) MENU_LINK(ToggleStates) + MENU_LINK(ToggleBell) MENU_LINK(ToggleAlternateImages) MENU_LINK(ToggleAlternateStates) MENU_LINK(ToggleButtons) @@ -247,6 +248,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) #endif // NO_MULTIPLE_SELECTION style_menu->AppendCheckItem(TreeTest_ToggleImages, wxT("Toggle show ima&ges")); style_menu->AppendCheckItem(TreeTest_ToggleStates, wxT("Toggle show st&ates")); + style_menu->AppendCheckItem(TreeTest_ToggleBell, wxT("Toggle &bell on no match")); style_menu->AppendCheckItem(TreeTest_ToggleAlternateImages, wxT("Toggle alternate images")); style_menu->AppendCheckItem(TreeTest_ToggleAlternateStates, wxT("Toggle alternate state images")); style_menu->Append(TreeTest_SetImageSize, wxT("Set image si&ze...")); @@ -705,6 +707,11 @@ void MyFrame::OnToggleStates(wxCommandEvent& WXUNUSED(event)) } } +void MyFrame::OnToggleBell(wxCommandEvent& event) +{ + m_treeCtrl->EnableBellOnNoMatch(event.IsChecked()); +} + void MyFrame::OnToggleAlternateImages(wxCommandEvent& WXUNUSED(event)) { bool alternateImages = m_treeCtrl->AlternateImages(); diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h index 8ea3334298..8c29d7e2e9 100644 --- a/samples/treectrl/treetest.h +++ b/samples/treectrl/treetest.h @@ -222,6 +222,7 @@ public: void OnToggleButtons(wxCommandEvent& event); void OnToggleImages(wxCommandEvent& event); void OnToggleStates(wxCommandEvent& event); + void OnToggleBell(wxCommandEvent& event); void OnToggleAlternateImages(wxCommandEvent& event); void OnToggleAlternateStates(wxCommandEvent& event); void OnSetImageSize(wxCommandEvent& event); @@ -339,6 +340,7 @@ enum TreeTest_Recreate, TreeTest_ToggleImages, TreeTest_ToggleStates, + TreeTest_ToggleBell, TreeTest_ToggleAlternateImages, TreeTest_ToggleAlternateStates, TreeTest_ToggleButtons, diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 323aa53db4..a48ff7003e 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -127,7 +127,7 @@ public: wxTreeFindTimer( wxGenericTreeCtrl *owner ) { m_owner = owner; } - virtual void Notify() { m_owner->m_findPrefix.clear(); } + virtual void Notify() { m_owner->ResetFindState(); } private: wxGenericTreeCtrl *m_owner; @@ -956,6 +956,7 @@ void wxGenericTreeCtrl::Init() m_renameTimer = NULL; m_findTimer = NULL; + m_findBell = 0; // default is to not ring bell at all m_dropEffectAboveItem = false; @@ -1045,6 +1046,11 @@ wxGenericTreeCtrl::~wxGenericTreeCtrl() delete m_imageListButtons; } +void wxGenericTreeCtrl::EnableBellOnNoMatch( bool on ) +{ + m_findBell = on; +} + // ----------------------------------------------------------------------------- // accessors // ----------------------------------------------------------------------------- @@ -1557,6 +1563,13 @@ void wxGenericTreeCtrl::ResetTextControl() m_textCtrl = NULL; } +void wxGenericTreeCtrl::ResetFindState() +{ + m_findPrefix.clear(); + if ( m_findBell ) + m_findBell = 1; +} + // find the first item starting with the given prefix after the given item wxTreeItemId wxGenericTreeCtrl::FindItem(const wxTreeItemId& idParent, const wxString& prefixOrig) const @@ -3347,6 +3360,24 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event ) if ( id.IsOk() ) { SelectItem(id); + + // Reset the bell flag if it had been temporarily disabled + // before. + if ( m_findBell ) + m_findBell = 1; + } + else // No such item + { + // Signal it with a bell if enabled. + if ( m_findBell == 1 ) + { + ::wxBell(); + + // Disable it for the next unsuccessful match, we only + // beep once, this is usually enough and continuing to + // do it would be annoying. + m_findBell = -1; + } } } else