Mercurial > pidgin
annotate gtk/gtkcellrendererexpander.c @ 14940:28c7e23bcc7e
[gaim-migrate @ 17712]
SF Patch #1593370 from Will Thompson (resiak)
Adds a missing 'Neither' to the documentation.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 09 Nov 2006 19:58:15 +0000 |
parents | 063fe56aa427 |
children |
rev | line source |
---|---|
14561 | 1 /* |
2 * @file gtkcellrendererexpander.c GTK+ Cell Renderer Expander | |
3 * @ingroup gtkui | |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 * | |
25 */ | |
26 | |
27 /* This is taken largely from GtkCellRenderer[Text|Pixbuf|Toggle] by | |
28 * Jonathon Blandford <jrb@redhat.com> for RedHat, Inc. | |
29 */ | |
30 | |
14657 | 31 #include <gtk/gtk.h> |
14561 | 32 #include <gtk/gtktreeview.h> |
33 #include "gtkcellrendererexpander.h" | |
34 | |
35 static void gaim_gtk_cell_renderer_expander_get_property (GObject *object, | |
36 guint param_id, | |
37 GValue *value, | |
38 GParamSpec *pspec); | |
39 static void gaim_gtk_cell_renderer_expander_set_property (GObject *object, | |
40 guint param_id, | |
41 const GValue *value, | |
42 GParamSpec *pspec); | |
43 static void gaim_gtk_cell_renderer_expander_init (GaimGtkCellRendererExpander *cellexpander); | |
44 static void gaim_gtk_cell_renderer_expander_class_init (GaimGtkCellRendererExpanderClass *class); | |
45 static void gaim_gtk_cell_renderer_expander_get_size (GtkCellRenderer *cell, | |
46 GtkWidget *widget, | |
47 GdkRectangle *cell_area, | |
48 gint *x_offset, | |
49 gint *y_offset, | |
50 gint *width, | |
51 gint *height); | |
52 static void gaim_gtk_cell_renderer_expander_render (GtkCellRenderer *cell, | |
53 GdkWindow *window, | |
54 GtkWidget *widget, | |
55 GdkRectangle *background_area, | |
56 GdkRectangle *cell_area, | |
57 GdkRectangle *expose_area, | |
58 guint flags); | |
14891
063fe56aa427
[gaim-migrate @ 17663]
Richard Laager <rlaager@wiktel.com>
parents:
14798
diff
changeset
|
59 static gboolean gaim_gtk_cell_renderer_expander_activate (GtkCellRenderer *r, |
14561 | 60 GdkEvent *event, |
61 GtkWidget *widget, | |
14891
063fe56aa427
[gaim-migrate @ 17663]
Richard Laager <rlaager@wiktel.com>
parents:
14798
diff
changeset
|
62 const gchar *p, |
063fe56aa427
[gaim-migrate @ 17663]
Richard Laager <rlaager@wiktel.com>
parents:
14798
diff
changeset
|
63 GdkRectangle *bg, |
063fe56aa427
[gaim-migrate @ 17663]
Richard Laager <rlaager@wiktel.com>
parents:
14798
diff
changeset
|
64 GdkRectangle *cell, |
14798
a413bcb6f19a
[gaim-migrate @ 17563]
Richard Laager <rlaager@wiktel.com>
parents:
14657
diff
changeset
|
65 GtkCellRendererState flags); |
14561 | 66 static void gaim_gtk_cell_renderer_expander_finalize (GObject *gobject); |
67 | |
68 enum { | |
69 LAST_SIGNAL | |
70 }; | |
71 | |
72 enum { | |
73 PROP_0, | |
74 PROP_IS_EXPANDER | |
75 }; | |
76 | |
77 static gpointer parent_class; | |
78 /* static guint expander_cell_renderer_signals [LAST_SIGNAL]; */ | |
79 | |
80 GType gaim_gtk_cell_renderer_expander_get_type (void) | |
81 { | |
82 static GType cell_expander_type = 0; | |
83 | |
84 if (!cell_expander_type) | |
85 { | |
86 static const GTypeInfo cell_expander_info = | |
87 { | |
88 sizeof (GaimGtkCellRendererExpanderClass), | |
89 NULL, /* base_init */ | |
90 NULL, /* base_finalize */ | |
91 (GClassInitFunc) gaim_gtk_cell_renderer_expander_class_init, | |
92 NULL, /* class_finalize */ | |
93 NULL, /* class_data */ | |
94 sizeof (GaimGtkCellRendererExpander), | |
95 0, /* n_preallocs */ | |
96 (GInstanceInitFunc) gaim_gtk_cell_renderer_expander_init, | |
97 NULL /* value_table */ | |
98 }; | |
99 | |
100 cell_expander_type = | |
101 g_type_register_static (GTK_TYPE_CELL_RENDERER, | |
102 "GaimGtkCellRendererExpander", | |
103 &cell_expander_info, 0); | |
104 } | |
105 | |
106 return cell_expander_type; | |
107 } | |
108 | |
109 static void gaim_gtk_cell_renderer_expander_init (GaimGtkCellRendererExpander *cellexpander) | |
110 { | |
111 GTK_CELL_RENDERER(cellexpander)->mode = GTK_CELL_RENDERER_MODE_ACTIVATABLE; | |
14591 | 112 GTK_CELL_RENDERER(cellexpander)->xpad = 0; |
14561 | 113 GTK_CELL_RENDERER(cellexpander)->ypad = 2; |
114 } | |
115 | |
116 static void gaim_gtk_cell_renderer_expander_class_init (GaimGtkCellRendererExpanderClass *class) | |
117 { | |
118 GObjectClass *object_class = G_OBJECT_CLASS(class); | |
119 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(class); | |
120 | |
121 parent_class = g_type_class_peek_parent (class); | |
122 object_class->finalize = gaim_gtk_cell_renderer_expander_finalize; | |
123 | |
124 object_class->get_property = gaim_gtk_cell_renderer_expander_get_property; | |
125 object_class->set_property = gaim_gtk_cell_renderer_expander_set_property; | |
126 | |
127 cell_class->get_size = gaim_gtk_cell_renderer_expander_get_size; | |
128 cell_class->render = gaim_gtk_cell_renderer_expander_render; | |
129 cell_class->activate = gaim_gtk_cell_renderer_expander_activate; | |
130 | |
131 g_object_class_install_property (object_class, | |
132 PROP_IS_EXPANDER, | |
133 g_param_spec_boolean ("expander-visible", | |
134 "Is Expander", | |
135 "True if the renderer should draw an expander", | |
136 FALSE, | |
137 G_PARAM_READWRITE)); | |
138 } | |
139 | |
140 static void gaim_gtk_cell_renderer_expander_finalize (GObject *object) | |
141 { | |
142 /* | |
143 GaimGtkCellRendererExpander *cellexpander = GAIM_GTK_CELL_RENDERER_EXPANDER(object); | |
144 */ | |
145 | |
146 (* G_OBJECT_CLASS (parent_class)->finalize) (object); | |
147 } | |
148 | |
149 static void gaim_gtk_cell_renderer_expander_get_property (GObject *object, | |
150 guint param_id, | |
151 GValue *value, | |
152 GParamSpec *psec) | |
153 { | |
154 GaimGtkCellRendererExpander *cellexpander = GAIM_GTK_CELL_RENDERER_EXPANDER(object); | |
155 | |
156 switch (param_id) | |
157 { | |
158 case PROP_IS_EXPANDER: | |
159 g_value_set_boolean(value, cellexpander->is_expander); | |
160 break; | |
161 default: | |
162 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec); | |
163 break; | |
164 | |
165 } | |
166 } | |
167 | |
168 static void gaim_gtk_cell_renderer_expander_set_property (GObject *object, | |
169 guint param_id, | |
170 const GValue *value, | |
171 GParamSpec *pspec) | |
172 { | |
173 GaimGtkCellRendererExpander *cellexpander = GAIM_GTK_CELL_RENDERER_EXPANDER (object); | |
174 | |
175 switch (param_id) | |
176 { | |
177 case PROP_IS_EXPANDER: | |
178 cellexpander->is_expander = g_value_get_boolean(value); | |
179 break; | |
180 default: | |
181 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); | |
182 break; | |
183 } | |
184 } | |
185 | |
186 GtkCellRenderer *gaim_gtk_cell_renderer_expander_new(void) | |
187 { | |
188 return g_object_new(GAIM_TYPE_GTK_CELL_RENDERER_EXPANDER, NULL); | |
189 } | |
190 | |
191 static void gaim_gtk_cell_renderer_expander_get_size (GtkCellRenderer *cell, | |
192 GtkWidget *widget, | |
193 GdkRectangle *cell_area, | |
194 gint *x_offset, | |
195 gint *y_offset, | |
196 gint *width, | |
197 gint *height) | |
198 { | |
199 gint calc_width; | |
200 gint calc_height; | |
201 gint expander_size; | |
202 | |
203 gtk_widget_style_get(widget, "expander-size", &expander_size, NULL); | |
204 | |
205 calc_width = (gint) cell->xpad * 2 + expander_size; | |
206 calc_height = (gint) cell->ypad * 2 + expander_size; | |
207 | |
208 if (width) | |
209 *width = calc_width; | |
210 | |
211 if (height) | |
212 *height = calc_height; | |
213 | |
214 if (cell_area) | |
215 { | |
216 if (x_offset) | |
217 { | |
218 *x_offset = cell->xalign * (cell_area->width - calc_width); | |
219 *x_offset = MAX (*x_offset, 0); | |
220 } | |
221 if (y_offset) | |
222 { | |
223 *y_offset = cell->yalign * (cell_area->height - calc_height); | |
224 *y_offset = MAX (*y_offset, 0); | |
225 } | |
226 } | |
227 } | |
228 | |
229 | |
230 static void gaim_gtk_cell_renderer_expander_render (GtkCellRenderer *cell, | |
231 GdkWindow *window, | |
232 GtkWidget *widget, | |
233 GdkRectangle *background_area, | |
234 GdkRectangle *cell_area, | |
235 GdkRectangle *expose_area, | |
236 guint flags) | |
237 { | |
238 GaimGtkCellRendererExpander *cellexpander = (GaimGtkCellRendererExpander *) cell; | |
239 | |
240 gint width, height; | |
241 GtkStateType state; | |
242 | |
243 if (!cellexpander->is_expander) | |
244 return; | |
245 | |
246 width = cell_area->width; | |
247 height = cell_area->height; | |
248 | |
14657 | 249 #if GTK_CHECK_VERSION(2,6,0) |
14561 | 250 if (!cell->sensitive) |
251 state = GTK_STATE_INSENSITIVE; | |
14657 | 252 #else |
253 if (GTK_WIDGET_STATE(widget) == GTK_STATE_INSENSITIVE) | |
254 state = GTK_STATE_INSENSITIVE; | |
255 #endif | |
14561 | 256 else if (flags & GTK_CELL_RENDERER_PRELIT) |
257 state = GTK_STATE_PRELIGHT; | |
258 else if (GTK_WIDGET_HAS_FOCUS (widget) && flags & GTK_CELL_RENDERER_SELECTED) | |
259 state = GTK_STATE_ACTIVE; | |
260 else | |
261 state = GTK_STATE_NORMAL; | |
262 | |
263 width -= cell->xpad*2; | |
264 height -= cell->ypad*2; | |
265 | |
266 gtk_paint_expander (widget->style, | |
267 window, state, | |
268 NULL, widget, "treeview", | |
269 cell_area->x + cell->xpad + (width / 2), | |
270 cell_area->y + cell->ypad + (height / 2), | |
271 cell->is_expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED); | |
272 } | |
273 | |
14564
4c14862f7fcc
[gaim-migrate @ 17287]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14561
diff
changeset
|
274 static gboolean gaim_gtk_cell_renderer_expander_activate(GtkCellRenderer *r, |
14561 | 275 GdkEvent *event, |
276 GtkWidget *widget, | |
277 const gchar *p, | |
278 GdkRectangle *bg, | |
279 GdkRectangle *cell, | |
280 GtkCellRendererState flags) | |
281 { | |
282 GtkTreePath *path = gtk_tree_path_new_from_string(p); | |
283 if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(widget), path)) | |
284 gtk_tree_view_collapse_row(GTK_TREE_VIEW(widget), path); | |
285 else | |
286 gtk_tree_view_expand_row(GTK_TREE_VIEW(widget),path,FALSE); | |
287 gtk_tree_path_free(path); | |
14564
4c14862f7fcc
[gaim-migrate @ 17287]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14561
diff
changeset
|
288 return FALSE; |
14561 | 289 } |