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
protected new string get_text () {
89
if (text == this.hint_string) {
99
public class ElementarySearchEntry : ElementaryEntry {
103
public ElementarySearchEntry (string hint_string) {
106
this.set_icon_from_stock(Gtk.EntryIconPosition.PRIMARY, "gtk-find");
107
this.changed.connect (manage_icon);
108
this.focus_in_event.connect (on_focus_in);
109
this.focus_out_event.connect (on_focus_out);
110
this.icon_press.connect (icon_pressed);
112
this.is_searching = true;
116
private void setup_clear_icon () {
118
var stock_item = Gtk.StockItem ();
119
stock_item.stock_id = "edit-clear-symbolic";
120
stock_item.label = null;
121
stock_item.modifier = 0;
122
stock_item.keyval = 0;
123
stock_item.translation_domain = Gtk.Stock.CLEAR;
124
var factory = new Gtk.IconFactory ();
125
var icon_set = new Gtk.IconSet ();
126
var icon_source = new Gtk.IconSource ();
127
icon_source.set_icon_name (Gtk.Stock.CLEAR);
128
icon_set.add_source (icon_source);
129
icon_source.set_icon_name ("edit-clear-symbolic");
130
icon_set.add_source (icon_source);
131
factory.add ("edit-clear-symbolic", icon_set);
132
Gtk.Stock.add ({stock_item});
133
factory.add_default ();
137
private new void hint () {
139
this.is_searching = false;
140
this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, null);
145
private new bool on_focus_in () {
147
if (!this.is_searching) {
149
this.is_searching = false;
155
private new bool on_focus_out () {
157
if (this.get_text() == "") {
159
this.is_searching = false;
165
private void manage_icon () {
167
if (this.text != "") {
168
this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, "edit-clear-symbolic");
171
this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, null);
176
private void icon_pressed (Gtk.EntryIconPosition icon_position) {
178
if (icon_position == Gtk.EntryIconPosition.SECONDARY) {
179
this.is_searching = false;
181
this.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, null);
182
this.is_searching = true;
185
if (!this.is_focus) {
186
this.is_searching = false;