]> git.saurik.com Git - wxWidgets.git/commitdiff
Add a possibility to beep on no match to wxGenericTreeCtrl.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 7 Oct 2012 22:42:02 +0000 (22:42 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 7 Oct 2012 22:42:02 +0000 (22:42 +0000)
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

docs/changes.txt
include/wx/generic/treectlg.h
include/wx/treectrl.h
interface/wx/treectrl.h
samples/treectrl/treetest.cpp
samples/treectrl/treetest.h
src/generic/treectlg.cpp

index 220a922f2538d61d2909083b6e9497a26379ca67..39af7ad56310310c27c90dcaa6897dd27ac30858 100644 (file)
@@ -565,6 +565,7 @@ All (GUI):
 - Add limited support for CSS styles for <a> tags too in wxHTML (gevorg).
 - Add "inherit" to <font> 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:
 
index c5010ecd0334a56804c4e0c39cfa7453fb209f85..168247c91cf81e052a945fa587ee53ef298c5732 100644 (file)
@@ -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);
index 5bc63827fc6993ff069ad0bbc2a64332356108db..c23920964e063795d1e2b2cf3a698fad1ee9a868 100644 (file)
@@ -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
     // -------
 
index 4587dfa9deba9f35d3dfecf236cd17c5c51b4b08..9b25d1a7e544e5d3ae442260fdc168cdb24682e4 100644 (file)
@@ -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.
index 229a9badb88f2ed9780e74ae4653a2a3a1105347..8e0064d1df25714601d0f770ca13c7ed360ed930 100644 (file)
@@ -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();
index 8ea3334298c25db3915e603e08663aa0e1d48cc3..8c29d7e2e93d6de12ead00590f6f733028832069 100644 (file)
@@ -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,
index 323aa53db444ef5a4bbfcb88fad57dbbfc81dfba..a48ff7003e44a4e66b02649eb7d7cfbc523d87e0 100644 (file)
@@ -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