summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext/gtkmm2ext/searchbar.h
blob: b8a209c346ddfad3d74e3135f6a593f9c288d9f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once

#include <gtkmm/entry.h>
#include <string>

#include "gtkmm2ext/visibility.h"

namespace Gtkmm2ext {

class LIBGTKMM2EXT_API SearchBar : public Gtk::Entry
{
public:
	SearchBar(
		const std::string& placeholder_text = "Search...",
		bool icon_click_resets = true);

	// resets the searchbar to the initial state
	void reset ();
	// emitted when the filter has been updated
	sigc::signal<void, const std::string&> signal_search_string_updated () { return sig_search_string_updated; }
protected:
	bool focus_in_event (GdkEventFocus*);
	bool focus_out_event (GdkEventFocus*);

	bool key_press_event (GdkEventKey*);
	void icon_clicked_event (Gtk::EntryIconPosition, const GdkEventButton*);

	const std::string placeholder_text;
	sigc::signal<void, const std::string&> sig_search_string_updated;
private:
	void search_string_changed () const;

	Glib::RefPtr<Gdk::Pixbuf> icon;
	bool icon_click_resets;
};

}