Mercurial > pidgin
annotate finch/libgnt/gntcheckbox.c @ 26716:911a325116d5
merge of '55577fa653435bea0213ccd380f914790714f8a1'
and 'd7236accdb3567e97b006e952e0ca3a1a49cc913'
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Mon, 27 Apr 2009 16:25:57 +0000 |
parents | c67d43408daa |
children | 8356e2f2486a |
rev | line source |
---|---|
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18873
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
22 |
15817 | 23 #include "gntcheckbox.h" |
24 | |
25 enum | |
26 { | |
27 SIG_TOGGLED = 1, | |
28 SIGS, | |
29 }; | |
30 | |
31 static GntButtonClass *parent_class = NULL; | |
32 static guint signals[SIGS] = { 0 }; | |
33 | |
34 static void | |
35 gnt_check_box_draw(GntWidget *widget) | |
36 { | |
37 GntCheckBox *cb = GNT_CHECK_BOX(widget); | |
38 GntColorType type; | |
39 char *text; | |
40 | |
41 if (gnt_widget_has_focus(widget)) | |
42 type = GNT_COLOR_HIGHLIGHT; | |
43 else | |
44 type = GNT_COLOR_NORMAL; | |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
45 |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
46 wbkgdset(widget->window, '\0' | gnt_color_pair(type)); |
15817 | 47 |
48 text = g_strdup_printf("[%c]", cb->checked ? 'X' : ' '); | |
49 mvwaddstr(widget->window, 0, 0, text); | |
50 g_free(text); | |
51 | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
52 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); |
15817 | 53 mvwaddstr(widget->window, 0, 4, GNT_BUTTON(cb)->priv->text); |
26439
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
54 wmove(widget->window, 0, 1); |
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
55 |
15817 | 56 GNTDEBUG; |
57 } | |
58 | |
59 static void | |
60 toggle_selection(GntWidget *widget) | |
61 { | |
62 GNT_CHECK_BOX(widget)->checked = !GNT_CHECK_BOX(widget)->checked; | |
63 g_signal_emit(widget, signals[SIG_TOGGLED], 0); | |
64 gnt_widget_draw(widget); | |
65 } | |
66 | |
67 static gboolean | |
68 gnt_check_box_key_pressed(GntWidget *widget, const char *text) | |
69 { | |
70 if (text[0] == ' ' && text[1] == '\0') | |
71 { | |
72 toggle_selection(widget); | |
73 return TRUE; | |
74 } | |
75 | |
76 return FALSE; | |
77 } | |
78 | |
79 static gboolean | |
80 gnt_check_box_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
81 { | |
82 if (event == GNT_LEFT_MOUSE_DOWN) { | |
83 toggle_selection(widget); | |
84 return TRUE; | |
85 } | |
86 return FALSE; | |
87 } | |
88 | |
89 static void | |
90 gnt_check_box_class_init(GntCheckBoxClass *klass) | |
91 { | |
92 GntWidgetClass *wclass = GNT_WIDGET_CLASS(klass); | |
93 | |
94 parent_class = GNT_BUTTON_CLASS(klass); | |
95 /*parent_class->destroy = gnt_check_box_destroy;*/ | |
96 wclass->draw = gnt_check_box_draw; | |
97 /*parent_class->map = gnt_check_box_map;*/ | |
98 /*parent_class->size_request = gnt_check_box_size_request;*/ | |
99 wclass->key_pressed = gnt_check_box_key_pressed; | |
100 wclass->clicked = gnt_check_box_clicked; | |
101 | |
102 signals[SIG_TOGGLED] = | |
103 g_signal_new("toggled", | |
104 G_TYPE_FROM_CLASS(klass), | |
105 G_SIGNAL_RUN_LAST, | |
106 G_STRUCT_OFFSET(GntCheckBoxClass, toggled), | |
107 NULL, NULL, | |
108 g_cclosure_marshal_VOID__VOID, | |
109 G_TYPE_NONE, 0); | |
110 GNTDEBUG; | |
111 } | |
112 | |
113 static void | |
114 gnt_check_box_init(GTypeInstance *instance, gpointer class) | |
115 { | |
116 GntWidget *widget = GNT_WIDGET(instance); | |
117 widget->priv.minh = 1; | |
118 widget->priv.minw = 4; | |
119 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
120 GNTDEBUG; | |
121 } | |
122 | |
123 /****************************************************************************** | |
124 * GntCheckBox API | |
125 *****************************************************************************/ | |
126 GType | |
127 gnt_check_box_get_gtype(void) | |
128 { | |
129 static GType type = 0; | |
130 | |
131 if(type == 0) | |
132 { | |
133 static const GTypeInfo info = { | |
134 sizeof(GntCheckBoxClass), | |
135 NULL, /* base_init */ | |
136 NULL, /* base_finalize */ | |
137 (GClassInitFunc)gnt_check_box_class_init, | |
138 NULL, /* class_finalize */ | |
139 NULL, /* class_data */ | |
140 sizeof(GntCheckBox), | |
141 0, /* n_preallocs */ | |
142 gnt_check_box_init, /* instance_init */ | |
143 NULL /* value_table */ | |
144 }; | |
145 | |
146 type = g_type_register_static(GNT_TYPE_BUTTON, | |
147 "GntCheckBox", | |
148 &info, 0); | |
149 } | |
150 | |
151 return type; | |
152 } | |
153 | |
154 GntWidget *gnt_check_box_new(const char *text) | |
155 { | |
156 GntWidget *widget = g_object_new(GNT_TYPE_CHECK_BOX, NULL); | |
157 | |
158 GNT_BUTTON(widget)->priv->text = g_strdup(text); | |
159 gnt_widget_set_take_focus(widget, TRUE); | |
160 | |
161 return widget; | |
162 } | |
163 | |
164 void gnt_check_box_set_checked(GntCheckBox *box, gboolean set) | |
165 { | |
166 if (set != box->checked) | |
167 { | |
168 box->checked = set; | |
169 g_signal_emit(box, signals[SIG_TOGGLED], 0); | |
170 } | |
171 } | |
172 | |
173 gboolean gnt_check_box_get_checked(GntCheckBox *box) | |
174 { | |
175 return box->checked; | |
176 } | |
177 | |
178 | |
179 |