3
Copyright (C) 2011 Avi Romanoff <aviromanoff@gmail.com>
4
This program is free software: you can redistribute it and/or modify it
5
under the terms of the GNU Lesser General Public License version 2.1, as published
6
by the Free Software Foundation.
8
This program is distributed in the hope that it will be useful, but
9
WITHOUT ANY WARRANTY; without even the implied warranties of
10
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
PURPOSE.\ See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along
14
with this program. If not, see <http://www.gnu.org/licenses/>.
18
namespace ElementaryWidgets {
21
public class ElementaryEntry : Gtk.Entry {
23
public string hint_string;
25
public ElementaryEntry (string hint_string) {
27
this.hint_string = hint_string;
30
this.focus_in_event.connect (on_focus_in);
31
this.focus_out_event.connect (on_focus_out);
35
private bool on_focus_in () {
37
if (get_text () == "") {
44
private bool on_focus_out () {
46
if (get_text () == "") {
53
protected void hint () {
55
this.text = this.hint_string;
60
protected void unhint () {
68
private void grey_out () {
70
var color = Gdk.Color ();
71
Gdk.Color.parse ("#999", out color);
72
this.modify_text (Gtk.StateType.NORMAL, color);
73
this.modify_font (Pango.FontDescription.from_string ("italic"));
77
private void reset_font () {
79
var color = Gdk.Color ();
80
Gdk.Color.parse ("#444", out color);
81
this.modify_text (Gtk.StateType.NORMAL, color);
82
this.modify_font (Pango.FontDescription.from_string ("normal"));
86
public new string get_text () {
89
if (text == this.hint_string) {
98
public new void set_text(string text) {
109
public class ElementarySearchEntry : ElementaryEntry {
111
public bool is_searching;
113
public ElementarySearchEntry (string hint_string) {
116
this.set_icon_from_stock(Gtk.EntryIconPosition.PRIMARY, "gtk-find");
117
this.changed.connect (manage_icon);
118
this.focus_in_event.connect (on_focus_in);
119
this.focus_out_event.connect (on_focus_out);
120
this.icon_press.connect (icon_pressed);
122
this.is_searching = true;
126
private void setup_clear_icon () {
128
var stock_item = Gtk.StockItem ();
129
stock_item.stock_id = "edit-clear-symbolic";
130
stock_item.label = null;
131
stock_item.modifier = 0;
132
stock_item.keyval = 0;
133
stock_item.translation_domain = Gtk.Stock.CLEAR;
134
var factory = new Gtk.IconFactory ();
135
var icon_set = new Gtk.IconSet ();
136
var icon_source = new Gtk.IconSource ();
137
icon_source.set_icon_name (Gtk.Stock.CLEAR);
138
icon_set.add_source (icon_source);
139
icon_source.set_icon_name ("edit-clear-symbolic");
140
icon_set.add_source (icon_source);
141
factory.add ("edit-clear-symbolic", icon_set);
142
Gtk.Stock.add ({stock_item});
143
factory.add_default ();
147
private new void hint () {
149
this.is_searching = false;
150
this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, null);
155
private new bool on_focus_in () {
157
if (!this.is_searching) {
159
this.is_searching = false;
165
private new bool on_focus_out () {
167
if (this.get_text() == "") {
169
this.is_searching = false;
175
private void manage_icon () {
177
if (this.text != "") {
178
this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, "edit-clear-symbolic");
181
this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, null);
186
private void icon_pressed (Gtk.EntryIconPosition icon_position) {
188
if (icon_position == Gtk.EntryIconPosition.SECONDARY) {
189
this.is_searching = false;
191
this.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, null);
192
this.is_searching = true;
195
if (!this.is_focus) {
196
this.is_searching = false;