2 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "gtkmm2ext/keyboard.h"
22 #include "widgets/searchbar.h"
24 using namespace ArdourWidgets;
26 SearchBar::SearchBar (const std::string& label, bool icon_resets)
27 : placeholder_text (label)
28 , icon_click_resets (icon_resets)
30 set_text (placeholder_text);
31 set_alignment (Gtk::ALIGN_CENTER);
32 signal_key_press_event().connect (sigc::mem_fun (*this, &SearchBar::key_press_event));
33 signal_focus_in_event().connect (sigc::mem_fun (*this, &SearchBar::focus_in_event));
34 signal_focus_out_event().connect (sigc::mem_fun (*this, &SearchBar::focus_out_event));
35 signal_changed().connect (sigc::mem_fun (*this, &SearchBar::search_string_changed));
36 signal_icon_release().connect (sigc::mem_fun (*this, &SearchBar::icon_clicked_event));
40 SearchBar::focus_in_event (GdkEventFocus*)
42 if (get_text ().compare (placeholder_text) == 0) {
46 icon = get_icon_pixbuf ();
48 set_icon_from_pixbuf (Glib::RefPtr<Gdk::Pixbuf> ());
54 SearchBar::focus_out_event (GdkEventFocus*)
56 if (get_text ().empty ()) {
57 set_text (placeholder_text);
61 set_icon_from_pixbuf (icon);
65 search_string_changed ();
70 SearchBar::key_press_event (GdkEventKey* ev)
74 set_text (placeholder_text);
84 SearchBar::icon_clicked_event (Gtk::EntryIconPosition, const GdkEventButton*)
86 if (icon_click_resets) {
90 search_string_changed ();
95 SearchBar::search_string_changed () const
97 const std::string& text = get_text ();
98 if (text.empty() || text.compare (placeholder_text) == 0) {
99 sig_search_string_updated ("");
102 sig_search_string_updated (text);
108 set_text (placeholder_text);
109 search_string_changed ();