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
This commit is contained in:
Vadim Zeitlin
2012-10-07 22:42:02 +00:00
parent e0dec8753a
commit 27bc919446
7 changed files with 68 additions and 2 deletions

View File

@@ -565,6 +565,7 @@ All (GUI):
- Add limited support for CSS styles for <a> tags too in wxHTML (gevorg). - 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 "inherit" to <font> XRC tag (Steffen Olszewski, Gero Meßsysteme GmbH).
- Add support for wxALWAYS_SHOW_SB style to wxScrolled<> (Catalin Raceanu). - Add support for wxALWAYS_SHOW_SB style to wxScrolled<> (Catalin Raceanu).
- Add wxTreeCtrl::EnableBellOnNoMatch() (Jonathan Dagresta).
wxGTK: wxGTK:

View File

@@ -65,7 +65,6 @@ public:
const wxValidator &validator = wxDefaultValidator, const wxValidator &validator = wxDefaultValidator,
const wxString& name = wxTreeCtrlNameStr); const wxString& name = wxTreeCtrlNameStr);
// implement base class pure virtuals // implement base class pure virtuals
// ---------------------------------- // ----------------------------------
@@ -169,6 +168,8 @@ public:
virtual void EndEditLabel(const wxTreeItemId& item, virtual void EndEditLabel(const wxTreeItemId& item,
bool discardChanges = false); bool discardChanges = false);
virtual void EnableBellOnNoMatch(bool on = true);
virtual void SortChildren(const wxTreeItemId& item); virtual void SortChildren(const wxTreeItemId& item);
// items geometry // items geometry
@@ -275,6 +276,10 @@ protected:
// incremental search data // incremental search data
wxString m_findPrefix; wxString m_findPrefix;
wxTimer *m_findTimer; 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; bool m_dropEffectAboveItem;
@@ -352,6 +357,10 @@ protected:
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;
private: private:
// Reset the state of the last find (i.e. keyboard incremental search)
// operation.
void ResetFindState();
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxGenericTreeCtrl) DECLARE_DYNAMIC_CLASS(wxGenericTreeCtrl)
wxDECLARE_NO_COPY_CLASS(wxGenericTreeCtrl); wxDECLARE_NO_COPY_CLASS(wxGenericTreeCtrl);

View File

@@ -349,6 +349,10 @@ public:
virtual void EndEditLabel(const wxTreeItemId& item, virtual void EndEditLabel(const wxTreeItemId& item,
bool discardChanges = false) = 0; 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 // sorting
// ------- // -------

View File

@@ -339,6 +339,18 @@ public:
virtual wxTextCtrl *EditLabel(const wxTreeItemId& item, virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
wxClassInfo* textCtrlClass = wxCLASSINFO(wxTextCtrl)); 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 Ends label editing. If @a cancelEdit is @true, the edit will be
cancelled. cancelled.

View File

@@ -113,6 +113,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
MENU_LINK(Recreate) MENU_LINK(Recreate)
MENU_LINK(ToggleImages) MENU_LINK(ToggleImages)
MENU_LINK(ToggleStates) MENU_LINK(ToggleStates)
MENU_LINK(ToggleBell)
MENU_LINK(ToggleAlternateImages) MENU_LINK(ToggleAlternateImages)
MENU_LINK(ToggleAlternateStates) MENU_LINK(ToggleAlternateStates)
MENU_LINK(ToggleButtons) MENU_LINK(ToggleButtons)
@@ -247,6 +248,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
#endif // NO_MULTIPLE_SELECTION #endif // NO_MULTIPLE_SELECTION
style_menu->AppendCheckItem(TreeTest_ToggleImages, wxT("Toggle show ima&ges")); style_menu->AppendCheckItem(TreeTest_ToggleImages, wxT("Toggle show ima&ges"));
style_menu->AppendCheckItem(TreeTest_ToggleStates, wxT("Toggle show st&ates")); 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_ToggleAlternateImages, wxT("Toggle alternate images"));
style_menu->AppendCheckItem(TreeTest_ToggleAlternateStates, wxT("Toggle alternate state images")); style_menu->AppendCheckItem(TreeTest_ToggleAlternateStates, wxT("Toggle alternate state images"));
style_menu->Append(TreeTest_SetImageSize, wxT("Set image si&ze...")); 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)) void MyFrame::OnToggleAlternateImages(wxCommandEvent& WXUNUSED(event))
{ {
bool alternateImages = m_treeCtrl->AlternateImages(); bool alternateImages = m_treeCtrl->AlternateImages();

View File

@@ -222,6 +222,7 @@ public:
void OnToggleButtons(wxCommandEvent& event); void OnToggleButtons(wxCommandEvent& event);
void OnToggleImages(wxCommandEvent& event); void OnToggleImages(wxCommandEvent& event);
void OnToggleStates(wxCommandEvent& event); void OnToggleStates(wxCommandEvent& event);
void OnToggleBell(wxCommandEvent& event);
void OnToggleAlternateImages(wxCommandEvent& event); void OnToggleAlternateImages(wxCommandEvent& event);
void OnToggleAlternateStates(wxCommandEvent& event); void OnToggleAlternateStates(wxCommandEvent& event);
void OnSetImageSize(wxCommandEvent& event); void OnSetImageSize(wxCommandEvent& event);
@@ -339,6 +340,7 @@ enum
TreeTest_Recreate, TreeTest_Recreate,
TreeTest_ToggleImages, TreeTest_ToggleImages,
TreeTest_ToggleStates, TreeTest_ToggleStates,
TreeTest_ToggleBell,
TreeTest_ToggleAlternateImages, TreeTest_ToggleAlternateImages,
TreeTest_ToggleAlternateStates, TreeTest_ToggleAlternateStates,
TreeTest_ToggleButtons, TreeTest_ToggleButtons,

View File

@@ -127,7 +127,7 @@ public:
wxTreeFindTimer( wxGenericTreeCtrl *owner ) { m_owner = owner; } wxTreeFindTimer( wxGenericTreeCtrl *owner ) { m_owner = owner; }
virtual void Notify() { m_owner->m_findPrefix.clear(); } virtual void Notify() { m_owner->ResetFindState(); }
private: private:
wxGenericTreeCtrl *m_owner; wxGenericTreeCtrl *m_owner;
@@ -956,6 +956,7 @@ void wxGenericTreeCtrl::Init()
m_renameTimer = NULL; m_renameTimer = NULL;
m_findTimer = NULL; m_findTimer = NULL;
m_findBell = 0; // default is to not ring bell at all
m_dropEffectAboveItem = false; m_dropEffectAboveItem = false;
@@ -1045,6 +1046,11 @@ wxGenericTreeCtrl::~wxGenericTreeCtrl()
delete m_imageListButtons; delete m_imageListButtons;
} }
void wxGenericTreeCtrl::EnableBellOnNoMatch( bool on )
{
m_findBell = on;
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// accessors // accessors
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -1557,6 +1563,13 @@ void wxGenericTreeCtrl::ResetTextControl()
m_textCtrl = NULL; 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 // find the first item starting with the given prefix after the given item
wxTreeItemId wxGenericTreeCtrl::FindItem(const wxTreeItemId& idParent, wxTreeItemId wxGenericTreeCtrl::FindItem(const wxTreeItemId& idParent,
const wxString& prefixOrig) const const wxString& prefixOrig) const
@@ -3347,6 +3360,24 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
if ( id.IsOk() ) if ( id.IsOk() )
{ {
SelectItem(id); 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 else