1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | /* e-shell-folder-title-bar.c |
---|
3 | * |
---|
4 | * Copyright (C) 2000, 2001 Ximian, Inc. |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of version 2 of the GNU General Public |
---|
8 | * License as published by the Free Software Foundation. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | * General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public |
---|
16 | * License along with this program; if not, write to the |
---|
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
18 | * Boston, MA 02111-1307, USA. |
---|
19 | * |
---|
20 | * Author: Ettore Perazzoli |
---|
21 | */ |
---|
22 | |
---|
23 | #ifdef HAVE_CONFIG_H |
---|
24 | #include <config.h> |
---|
25 | #endif |
---|
26 | |
---|
27 | #include <gtk/gtklabel.h> |
---|
28 | #include <gtk/gtkpixmap.h> |
---|
29 | #include <gtk/gtkrc.h> |
---|
30 | #include <gtk/gtksignal.h> |
---|
31 | #include <gtk/gtktogglebutton.h> |
---|
32 | #include <libgnome/gnome-defs.h> |
---|
33 | #include <libgnome/gnome-i18n.h> |
---|
34 | #include <gdk-pixbuf/gdk-pixbuf.h> |
---|
35 | |
---|
36 | #include <gal/util/e-util.h> |
---|
37 | #include <gal/widgets/e-font.h> |
---|
38 | |
---|
39 | #include "widgets/misc/e-clipped-label.h" |
---|
40 | #include "e-shell-constants.h" |
---|
41 | #include "e-shell-folder-title-bar.h" |
---|
42 | |
---|
43 | |
---|
44 | #define PARENT_TYPE GTK_TYPE_HBOX |
---|
45 | static GtkHBox *parent_class = NULL; |
---|
46 | |
---|
47 | struct _EShellFolderTitleBarPrivate { |
---|
48 | GdkPixbuf *icon; |
---|
49 | |
---|
50 | /* We have an icon, a label and a button that contains an icon and a |
---|
51 | label. When the button is enabled, the stand-alone label icon get |
---|
52 | hidden; when the button is disabled, the button gets hidden and the |
---|
53 | label and the icon get shown. This is pretty ugly but it easier to |
---|
54 | manage the GTK layout this way. */ |
---|
55 | |
---|
56 | /* The stand-alone icon/label combo. */ |
---|
57 | GtkWidget *title_icon; |
---|
58 | GtkWidget *title_label; |
---|
59 | |
---|
60 | /* The button. */ |
---|
61 | GtkWidget *title_button; |
---|
62 | GtkWidget *title_button_icon; |
---|
63 | GtkWidget *title_button_label; |
---|
64 | GtkWidget *title_button_arrow; |
---|
65 | |
---|
66 | /* Holds extra information that is to be shown on the bar. */ |
---|
67 | GtkWidget *folder_bar_label; |
---|
68 | |
---|
69 | /* Navigation buttons. */ |
---|
70 | GtkWidget *back_button; |
---|
71 | GtkWidget *forward_button; |
---|
72 | |
---|
73 | gboolean title_clickable; |
---|
74 | }; |
---|
75 | |
---|
76 | enum { |
---|
77 | TITLE_TOGGLED, |
---|
78 | BACK_CLICKED, |
---|
79 | FORWARD_CLICKED, |
---|
80 | LAST_SIGNAL |
---|
81 | }; |
---|
82 | |
---|
83 | static guint signals[LAST_SIGNAL] = { 0 }; |
---|
84 | |
---|
85 | |
---|
86 | static const char *down_arrow_xpm[] = { |
---|
87 | "11 5 2 1", |
---|
88 | " c none", |
---|
89 | ". c #ffffffffffff", |
---|
90 | " ......... ", |
---|
91 | " ....... ", |
---|
92 | " ..... ", |
---|
93 | " ... ", |
---|
94 | " . ", |
---|
95 | }; |
---|
96 | |
---|
97 | static const char *left_arrow_xpm[] = { |
---|
98 | "11 7 2 1", |
---|
99 | " c none", |
---|
100 | ". c #ffffffffffff", |
---|
101 | " . ", |
---|
102 | " .. ", |
---|
103 | " ........ ", |
---|
104 | " ......... ", |
---|
105 | " ........ ", |
---|
106 | " .. ", |
---|
107 | " . ", |
---|
108 | }; |
---|
109 | |
---|
110 | static const char *right_arrow_xpm[] = { |
---|
111 | "11 7 2 1", |
---|
112 | " c none", |
---|
113 | ". c #ffffffffffff", |
---|
114 | " . ", |
---|
115 | " .. ", |
---|
116 | " ........ ", |
---|
117 | " ......... ", |
---|
118 | " ........ ", |
---|
119 | " .. ", |
---|
120 | " . ", |
---|
121 | }; |
---|
122 | |
---|
123 | |
---|
124 | /* Utility functions for managing icons and icon widgets. */ |
---|
125 | |
---|
126 | static GtkWidget * |
---|
127 | create_pixmap_widget_from_xpm (const char **xpm) |
---|
128 | { |
---|
129 | GdkPixbuf *pixbuf; |
---|
130 | GdkPixmap *pixmap; |
---|
131 | GdkBitmap *mask; |
---|
132 | GtkWidget *widget; |
---|
133 | |
---|
134 | pixbuf = gdk_pixbuf_new_from_xpm_data (xpm); |
---|
135 | |
---|
136 | gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &mask, 127); |
---|
137 | |
---|
138 | widget = gtk_pixmap_new (pixmap, mask); |
---|
139 | gtk_widget_show (widget); |
---|
140 | |
---|
141 | gdk_pixbuf_unref (pixbuf); |
---|
142 | |
---|
143 | return widget; |
---|
144 | } |
---|
145 | |
---|
146 | static GdkPixbuf * |
---|
147 | new_empty_pixbuf (void) |
---|
148 | { |
---|
149 | GdkPixbuf *empty_pixbuf; |
---|
150 | unsigned char *pixels; |
---|
151 | |
---|
152 | empty_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1); |
---|
153 | pixels = gdk_pixbuf_get_pixels (empty_pixbuf); |
---|
154 | |
---|
155 | memset (pixels, 0, 4); |
---|
156 | |
---|
157 | return empty_pixbuf; |
---|
158 | } |
---|
159 | |
---|
160 | static GtkWidget * |
---|
161 | new_empty_pixmap_widget (void) |
---|
162 | { |
---|
163 | GtkWidget *pixmap_widget; |
---|
164 | GdkPixmap *pixmap; |
---|
165 | GdkBitmap *mask; |
---|
166 | GdkPixbuf *empty_pixbuf; |
---|
167 | |
---|
168 | empty_pixbuf = new_empty_pixbuf (); |
---|
169 | |
---|
170 | gdk_pixbuf_render_pixmap_and_mask (empty_pixbuf, &pixmap, &mask, 127); |
---|
171 | pixmap_widget = gtk_pixmap_new (pixmap, mask); |
---|
172 | |
---|
173 | gdk_pixbuf_unref (empty_pixbuf); |
---|
174 | |
---|
175 | return pixmap_widget; |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | static void |
---|
180 | set_title_bar_label_style (GtkWidget *widget) |
---|
181 | { |
---|
182 | GtkRcStyle *rc_style; |
---|
183 | |
---|
184 | rc_style = gtk_rc_style_new(); |
---|
185 | |
---|
186 | rc_style->color_flags[GTK_STATE_NORMAL] |= GTK_RC_FG; |
---|
187 | rc_style->fg[GTK_STATE_NORMAL].red = 0xffff; |
---|
188 | rc_style->fg[GTK_STATE_NORMAL].green = 0xffff; |
---|
189 | rc_style->fg[GTK_STATE_NORMAL].blue = 0xffff; |
---|
190 | |
---|
191 | gtk_widget_modify_style (widget, rc_style); |
---|
192 | gtk_rc_style_unref (rc_style); |
---|
193 | } |
---|
194 | |
---|
195 | |
---|
196 | /* Utility functions. */ |
---|
197 | |
---|
198 | static int |
---|
199 | get_max_clipped_label_width (EClippedLabel *clipped_label) |
---|
200 | { |
---|
201 | GdkFont *font; |
---|
202 | int width; |
---|
203 | |
---|
204 | font = GTK_WIDGET (clipped_label)->style->font; |
---|
205 | |
---|
206 | width = gdk_string_width (font, clipped_label->label); |
---|
207 | width += 2 * GTK_MISC (clipped_label)->xpad; |
---|
208 | |
---|
209 | return width; |
---|
210 | } |
---|
211 | |
---|
212 | static void |
---|
213 | size_allocate_title_button (EShellFolderTitleBar *title_bar, |
---|
214 | GtkAllocation *allocation, |
---|
215 | int offset, |
---|
216 | int *available_width_inout) |
---|
217 | { |
---|
218 | EShellFolderTitleBarPrivate *priv; |
---|
219 | GtkAllocation child_allocation; |
---|
220 | GtkRequisition child_requisition; |
---|
221 | int border_width; |
---|
222 | |
---|
223 | priv = title_bar->priv; |
---|
224 | |
---|
225 | /* Keep a little distance from the navigation arrows. */ |
---|
226 | allocation->x += 2; |
---|
227 | |
---|
228 | border_width = GTK_CONTAINER (title_bar)->border_width; |
---|
229 | |
---|
230 | gtk_widget_get_child_requisition (priv->title_button, &child_requisition); |
---|
231 | child_allocation.x = allocation->x + border_width + offset; |
---|
232 | child_allocation.y = allocation->y + border_width; |
---|
233 | child_allocation.height = allocation->height - 2 * border_width; |
---|
234 | |
---|
235 | child_allocation.width = child_requisition.width; |
---|
236 | child_allocation.width += get_max_clipped_label_width (E_CLIPPED_LABEL (priv->title_button_label)); |
---|
237 | |
---|
238 | child_allocation.width = MIN (child_allocation.width, *available_width_inout); |
---|
239 | |
---|
240 | gtk_widget_size_allocate (priv->title_button, & child_allocation); |
---|
241 | |
---|
242 | *available_width_inout -= child_allocation.width; |
---|
243 | } |
---|
244 | |
---|
245 | static int |
---|
246 | size_allocate_navigation_buttons_and_title_icon (EShellFolderTitleBar *title_bar, |
---|
247 | GtkAllocation *allocation) |
---|
248 | { |
---|
249 | EShellFolderTitleBarPrivate *priv; |
---|
250 | GtkRequisition child_requisition; |
---|
251 | GtkAllocation child_allocation; |
---|
252 | int border_width; |
---|
253 | |
---|
254 | priv = title_bar->priv; |
---|
255 | |
---|
256 | border_width = GTK_CONTAINER (title_bar)->border_width; |
---|
257 | |
---|
258 | child_allocation.x = allocation->x + border_width; |
---|
259 | child_allocation.y = allocation->y + border_width; |
---|
260 | child_allocation.height = allocation->height - 2 * border_width; |
---|
261 | |
---|
262 | gtk_widget_size_request (priv->back_button, &child_requisition); |
---|
263 | child_allocation.width = child_requisition.width; |
---|
264 | gtk_widget_size_allocate (priv->back_button, &child_allocation); |
---|
265 | |
---|
266 | child_allocation.x += child_allocation.width; |
---|
267 | |
---|
268 | gtk_widget_size_request (priv->forward_button, &child_requisition); |
---|
269 | child_allocation.width = child_requisition.width; |
---|
270 | gtk_widget_size_allocate (priv->forward_button, &child_allocation); |
---|
271 | |
---|
272 | if (! priv->title_clickable) { |
---|
273 | /* Keep a little distance from the navigation arrows. */ |
---|
274 | child_allocation.x += child_allocation.width + 5; |
---|
275 | |
---|
276 | gtk_widget_size_request (priv->title_icon, &child_requisition); |
---|
277 | child_allocation.width = child_requisition.width; |
---|
278 | gtk_widget_size_allocate (priv->title_icon, &child_allocation); |
---|
279 | } |
---|
280 | |
---|
281 | return child_allocation.x + child_allocation.width; |
---|
282 | } |
---|
283 | |
---|
284 | static void |
---|
285 | size_allocate_label (EShellFolderTitleBar *title_bar, |
---|
286 | GtkAllocation *allocation, |
---|
287 | int offset, |
---|
288 | int *available_width_inout) |
---|
289 | { |
---|
290 | EShellFolderTitleBarPrivate *priv; |
---|
291 | GtkAllocation child_allocation; |
---|
292 | int border_width; |
---|
293 | |
---|
294 | priv = title_bar->priv; |
---|
295 | |
---|
296 | border_width = GTK_CONTAINER (title_bar)->border_width; |
---|
297 | |
---|
298 | child_allocation.x = allocation->x + border_width + offset; |
---|
299 | child_allocation.y = allocation->y + border_width; |
---|
300 | child_allocation.height = allocation->height - 2 * border_width; |
---|
301 | |
---|
302 | child_allocation.width = MIN (get_max_clipped_label_width (E_CLIPPED_LABEL (priv->title_label)), |
---|
303 | *available_width_inout); |
---|
304 | |
---|
305 | gtk_widget_size_allocate (priv->title_label, & child_allocation); |
---|
306 | |
---|
307 | *available_width_inout -= child_allocation.width; |
---|
308 | } |
---|
309 | |
---|
310 | |
---|
311 | /* The back/forward navigation buttons. */ |
---|
312 | |
---|
313 | static void |
---|
314 | back_button_clicked_callback (GtkButton *button, |
---|
315 | void *data) |
---|
316 | { |
---|
317 | EShellFolderTitleBar *folder_title_bar; |
---|
318 | |
---|
319 | folder_title_bar = E_SHELL_FOLDER_TITLE_BAR (data); |
---|
320 | |
---|
321 | gtk_signal_emit (GTK_OBJECT (folder_title_bar), signals[BACK_CLICKED]); |
---|
322 | } |
---|
323 | |
---|
324 | static void |
---|
325 | forward_button_clicked_callback (GtkButton *button, |
---|
326 | void *data) |
---|
327 | { |
---|
328 | EShellFolderTitleBar *folder_title_bar; |
---|
329 | |
---|
330 | folder_title_bar = E_SHELL_FOLDER_TITLE_BAR (data); |
---|
331 | |
---|
332 | gtk_signal_emit (GTK_OBJECT (folder_title_bar), signals[FORWARD_CLICKED]); |
---|
333 | } |
---|
334 | |
---|
335 | static void |
---|
336 | add_navigation_buttons (EShellFolderTitleBar *folder_title_bar) |
---|
337 | { |
---|
338 | EShellFolderTitleBarPrivate *priv; |
---|
339 | GtkWidget *back_pixmap; |
---|
340 | GtkWidget *forward_pixmap; |
---|
341 | |
---|
342 | priv = folder_title_bar->priv; |
---|
343 | |
---|
344 | priv->back_button = gtk_button_new (); |
---|
345 | gtk_button_set_relief (GTK_BUTTON (priv->back_button), GTK_RELIEF_NONE); |
---|
346 | GTK_WIDGET_UNSET_FLAGS (priv->back_button, GTK_CAN_FOCUS); |
---|
347 | |
---|
348 | back_pixmap = create_pixmap_widget_from_xpm (left_arrow_xpm); |
---|
349 | gtk_container_add (GTK_CONTAINER (priv->back_button), back_pixmap); |
---|
350 | |
---|
351 | gtk_signal_connect (GTK_OBJECT (priv->back_button), "clicked", |
---|
352 | GTK_SIGNAL_FUNC (back_button_clicked_callback), folder_title_bar); |
---|
353 | |
---|
354 | priv->forward_button = gtk_button_new (); |
---|
355 | gtk_button_set_relief (GTK_BUTTON (priv->forward_button), GTK_RELIEF_NONE); |
---|
356 | GTK_WIDGET_UNSET_FLAGS (priv->forward_button, GTK_CAN_FOCUS); |
---|
357 | |
---|
358 | forward_pixmap = create_pixmap_widget_from_xpm (right_arrow_xpm); |
---|
359 | gtk_container_add (GTK_CONTAINER (priv->forward_button), forward_pixmap); |
---|
360 | |
---|
361 | gtk_signal_connect (GTK_OBJECT (priv->forward_button), "clicked", |
---|
362 | GTK_SIGNAL_FUNC (forward_button_clicked_callback), folder_title_bar); |
---|
363 | |
---|
364 | gtk_box_pack_start (GTK_BOX (folder_title_bar), priv->back_button, FALSE, FALSE, 0); |
---|
365 | gtk_box_pack_start (GTK_BOX (folder_title_bar), priv->forward_button, FALSE, FALSE, 0); |
---|
366 | |
---|
367 | gtk_widget_show_all (priv->back_button); |
---|
368 | gtk_widget_show_all (priv->forward_button); |
---|
369 | } |
---|
370 | |
---|
371 | |
---|
372 | /* Popup button callback. */ |
---|
373 | |
---|
374 | static void |
---|
375 | title_button_toggled_cb (GtkToggleButton *title_button, |
---|
376 | void *data) |
---|
377 | { |
---|
378 | EShellFolderTitleBar *folder_title_bar; |
---|
379 | |
---|
380 | folder_title_bar = E_SHELL_FOLDER_TITLE_BAR (data); |
---|
381 | gtk_signal_emit (GTK_OBJECT (folder_title_bar), |
---|
382 | signals[TITLE_TOGGLED], |
---|
383 | gtk_toggle_button_get_active (title_button)); |
---|
384 | } |
---|
385 | |
---|
386 | |
---|
387 | /* GtkObject methods. */ |
---|
388 | |
---|
389 | static void |
---|
390 | impl_destroy (GtkObject *object) |
---|
391 | { |
---|
392 | EShellFolderTitleBar *folder_title_bar; |
---|
393 | EShellFolderTitleBarPrivate *priv; |
---|
394 | |
---|
395 | folder_title_bar = E_SHELL_FOLDER_TITLE_BAR (object); |
---|
396 | priv = folder_title_bar->priv; |
---|
397 | |
---|
398 | if (priv->icon != NULL) |
---|
399 | gdk_pixbuf_unref (priv->icon); |
---|
400 | g_free (priv); |
---|
401 | |
---|
402 | (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); |
---|
403 | } |
---|
404 | |
---|
405 | |
---|
406 | /* GTkWidget methods. */ |
---|
407 | |
---|
408 | static void |
---|
409 | impl_size_allocate (GtkWidget *widget, |
---|
410 | GtkAllocation *allocation) |
---|
411 | { |
---|
412 | EShellFolderTitleBar *title_bar; |
---|
413 | EShellFolderTitleBarPrivate *priv; |
---|
414 | GtkAllocation label_allocation; |
---|
415 | int border_width; |
---|
416 | int available_width; |
---|
417 | int width_before_icon; |
---|
418 | int offset; |
---|
419 | |
---|
420 | title_bar = E_SHELL_FOLDER_TITLE_BAR (widget); |
---|
421 | priv = title_bar->priv; |
---|
422 | |
---|
423 | border_width = GTK_CONTAINER (widget)->border_width; |
---|
424 | available_width = allocation->width - 2 * border_width; |
---|
425 | |
---|
426 | offset = size_allocate_navigation_buttons_and_title_icon (title_bar, allocation); |
---|
427 | available_width -= offset; |
---|
428 | |
---|
429 | width_before_icon = available_width; |
---|
430 | |
---|
431 | if (priv->title_clickable) |
---|
432 | size_allocate_title_button (title_bar, allocation, offset, & available_width); |
---|
433 | else |
---|
434 | size_allocate_label (title_bar, allocation, offset, & available_width); |
---|
435 | |
---|
436 | label_allocation.x = allocation->x + width_before_icon - available_width - border_width + offset; |
---|
437 | label_allocation.y = allocation->y + border_width; |
---|
438 | label_allocation.width = available_width - 2 * border_width; |
---|
439 | label_allocation.height = allocation->height - 2 * border_width; |
---|
440 | |
---|
441 | gtk_widget_size_allocate (priv->folder_bar_label, & label_allocation); |
---|
442 | |
---|
443 | widget->allocation = *allocation; |
---|
444 | } |
---|
445 | |
---|
446 | |
---|
447 | static void |
---|
448 | class_init (EShellFolderTitleBarClass *klass) |
---|
449 | { |
---|
450 | GtkObjectClass *object_class; |
---|
451 | GtkWidgetClass *widget_class; |
---|
452 | |
---|
453 | object_class = GTK_OBJECT_CLASS (klass); |
---|
454 | object_class->destroy = impl_destroy; |
---|
455 | |
---|
456 | widget_class = GTK_WIDGET_CLASS (klass); |
---|
457 | widget_class->size_allocate = impl_size_allocate; |
---|
458 | |
---|
459 | parent_class = gtk_type_class (PARENT_TYPE); |
---|
460 | |
---|
461 | signals[TITLE_TOGGLED] = gtk_signal_new ("title_toggled", |
---|
462 | GTK_RUN_FIRST, |
---|
463 | object_class->type, |
---|
464 | GTK_SIGNAL_OFFSET (EShellFolderTitleBarClass, title_toggled), |
---|
465 | gtk_marshal_NONE__BOOL, |
---|
466 | GTK_TYPE_NONE, 1, |
---|
467 | GTK_TYPE_BOOL); |
---|
468 | |
---|
469 | signals[BACK_CLICKED] = gtk_signal_new ("back_clicked", |
---|
470 | GTK_RUN_FIRST, |
---|
471 | object_class->type, |
---|
472 | GTK_SIGNAL_OFFSET (EShellFolderTitleBarClass, back_clicked), |
---|
473 | gtk_marshal_NONE__NONE, |
---|
474 | GTK_TYPE_NONE, 0); |
---|
475 | |
---|
476 | signals[FORWARD_CLICKED] = gtk_signal_new ("forward_clicked", |
---|
477 | GTK_RUN_FIRST, |
---|
478 | object_class->type, |
---|
479 | GTK_SIGNAL_OFFSET (EShellFolderTitleBarClass, forward_clicked), |
---|
480 | gtk_marshal_NONE__NONE, |
---|
481 | GTK_TYPE_NONE, 0); |
---|
482 | |
---|
483 | gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); |
---|
484 | } |
---|
485 | |
---|
486 | static void |
---|
487 | init (EShellFolderTitleBar *shell_folder_title_bar) |
---|
488 | { |
---|
489 | EShellFolderTitleBarPrivate *priv; |
---|
490 | |
---|
491 | priv = g_new (EShellFolderTitleBarPrivate, 1); |
---|
492 | |
---|
493 | priv->icon = NULL; |
---|
494 | |
---|
495 | priv->title_icon = NULL; |
---|
496 | priv->title_label = NULL; |
---|
497 | |
---|
498 | priv->title_button = NULL; |
---|
499 | priv->title_button_icon = NULL; |
---|
500 | priv->title_button_label = NULL; |
---|
501 | priv->title_button_arrow = NULL; |
---|
502 | |
---|
503 | priv->folder_bar_label = NULL; |
---|
504 | |
---|
505 | priv->back_button = NULL; |
---|
506 | priv->forward_button = NULL; |
---|
507 | |
---|
508 | priv->title_clickable = TRUE; |
---|
509 | |
---|
510 | shell_folder_title_bar->priv = priv; |
---|
511 | } |
---|
512 | |
---|
513 | |
---|
514 | /** |
---|
515 | * e_shell_folder_title_bar_construct: |
---|
516 | * @folder_title_bar: |
---|
517 | * |
---|
518 | * Construct the folder title bar widget. |
---|
519 | **/ |
---|
520 | void |
---|
521 | e_shell_folder_title_bar_construct (EShellFolderTitleBar *folder_title_bar) |
---|
522 | { |
---|
523 | EShellFolderTitleBarPrivate *priv; |
---|
524 | GtkWidget *title_button_hbox; |
---|
525 | GtkWidget *widget; |
---|
526 | |
---|
527 | g_return_if_fail (folder_title_bar != NULL); |
---|
528 | g_return_if_fail (E_IS_SHELL_FOLDER_TITLE_BAR (folder_title_bar)); |
---|
529 | |
---|
530 | priv = folder_title_bar->priv; |
---|
531 | widget = GTK_WIDGET (folder_title_bar); |
---|
532 | |
---|
533 | priv->title_icon = new_empty_pixmap_widget (); |
---|
534 | gtk_misc_set_alignment (GTK_MISC (priv->title_icon), 1.0, .5); |
---|
535 | gtk_misc_set_padding (GTK_MISC (priv->title_icon), 2, 0); |
---|
536 | gtk_widget_show (priv->title_icon); |
---|
537 | |
---|
538 | priv->title_label = e_clipped_label_new (""); |
---|
539 | gtk_misc_set_padding (GTK_MISC (priv->title_label), 0, 0); |
---|
540 | gtk_misc_set_alignment (GTK_MISC (priv->title_label), 0.0, 0.5); |
---|
541 | set_title_bar_label_style (priv->title_label); |
---|
542 | |
---|
543 | priv->title_button_label = e_clipped_label_new (""); |
---|
544 | gtk_misc_set_padding (GTK_MISC (priv->title_button_label), 2, 0); |
---|
545 | gtk_misc_set_alignment (GTK_MISC (priv->title_button_label), 0.0, 0.5); |
---|
546 | gtk_widget_show (priv->title_button_label); |
---|
547 | set_title_bar_label_style (priv->title_button_label); |
---|
548 | |
---|
549 | priv->folder_bar_label = e_clipped_label_new (""); |
---|
550 | gtk_misc_set_alignment (GTK_MISC (priv->folder_bar_label), 1.0, 0.5); |
---|
551 | gtk_widget_show (priv->folder_bar_label); |
---|
552 | set_title_bar_label_style (priv->folder_bar_label); |
---|
553 | |
---|
554 | priv->title_button_icon = new_empty_pixmap_widget (); |
---|
555 | gtk_widget_show (priv->title_button_icon); |
---|
556 | |
---|
557 | title_button_hbox = gtk_hbox_new (FALSE, 0); |
---|
558 | gtk_box_pack_start (GTK_BOX (title_button_hbox), priv->title_button_icon, |
---|
559 | FALSE, TRUE, 2); |
---|
560 | gtk_box_pack_start (GTK_BOX (title_button_hbox), priv->title_button_label, |
---|
561 | TRUE, TRUE, 0); |
---|
562 | gtk_box_pack_start (GTK_BOX (title_button_hbox), create_pixmap_widget_from_xpm (down_arrow_xpm), |
---|
563 | FALSE, TRUE, 2); |
---|
564 | gtk_widget_show (title_button_hbox); |
---|
565 | |
---|
566 | priv->title_button = gtk_toggle_button_new (); |
---|
567 | gtk_button_set_relief (GTK_BUTTON (priv->title_button), GTK_RELIEF_NONE); |
---|
568 | gtk_container_add (GTK_CONTAINER (priv->title_button), title_button_hbox); |
---|
569 | GTK_WIDGET_UNSET_FLAGS (priv->title_button, GTK_CAN_FOCUS); |
---|
570 | gtk_widget_show (priv->title_button); |
---|
571 | |
---|
572 | gtk_container_set_border_width (GTK_CONTAINER (folder_title_bar), 2); |
---|
573 | gtk_box_pack_start (GTK_BOX (folder_title_bar), priv->title_icon, FALSE, TRUE, 0); |
---|
574 | gtk_box_pack_start (GTK_BOX (folder_title_bar), priv->title_label, FALSE, FALSE, 0); |
---|
575 | gtk_box_pack_start (GTK_BOX (folder_title_bar), priv->title_button, FALSE, FALSE, 0); |
---|
576 | gtk_box_pack_start (GTK_BOX (folder_title_bar), priv->folder_bar_label, TRUE, TRUE, 0); |
---|
577 | |
---|
578 | /* Make the label have a border as large as the button's. |
---|
579 | FIXME: This is really hackish. The hardcoded numbers should be OK |
---|
580 | as the padding is hardcoded in GtkButton too (see CHILD_SPACING in |
---|
581 | gtkbutton.c). */ |
---|
582 | gtk_misc_set_padding (GTK_MISC (priv->title_label), |
---|
583 | GTK_WIDGET (priv->title_button)->style->klass->xthickness, |
---|
584 | GTK_WIDGET (priv->title_button)->style->klass->ythickness + 2); |
---|
585 | |
---|
586 | gtk_signal_connect (GTK_OBJECT (priv->title_button), "toggled", |
---|
587 | GTK_SIGNAL_FUNC (title_button_toggled_cb), folder_title_bar); |
---|
588 | |
---|
589 | add_navigation_buttons (folder_title_bar); |
---|
590 | |
---|
591 | e_shell_folder_title_bar_set_title (folder_title_bar, NULL); |
---|
592 | } |
---|
593 | |
---|
594 | /** |
---|
595 | * e_shell_folder_title_bar_new: |
---|
596 | * @void: |
---|
597 | * |
---|
598 | * Create a new title bar widget. |
---|
599 | * |
---|
600 | * Return value: |
---|
601 | **/ |
---|
602 | GtkWidget * |
---|
603 | e_shell_folder_title_bar_new (void) |
---|
604 | { |
---|
605 | EShellFolderTitleBar *new; |
---|
606 | |
---|
607 | gtk_widget_push_colormap (gdk_rgb_get_cmap ()); |
---|
608 | gtk_widget_push_visual (gdk_rgb_get_visual ()); |
---|
609 | new = gtk_type_new (e_shell_folder_title_bar_get_type ()); |
---|
610 | |
---|
611 | e_shell_folder_title_bar_construct (new); |
---|
612 | gtk_widget_pop_visual (); |
---|
613 | gtk_widget_pop_colormap (); |
---|
614 | |
---|
615 | return GTK_WIDGET (new); |
---|
616 | } |
---|
617 | |
---|
618 | /** |
---|
619 | * e_shell_folder_title_bar_set_title: |
---|
620 | * @folder_title_bar: |
---|
621 | * @title: |
---|
622 | * |
---|
623 | * Set the title for the title bar. |
---|
624 | **/ |
---|
625 | void |
---|
626 | e_shell_folder_title_bar_set_title (EShellFolderTitleBar *folder_title_bar, |
---|
627 | const char *title) |
---|
628 | { |
---|
629 | EShellFolderTitleBarPrivate *priv; |
---|
630 | |
---|
631 | g_return_if_fail (folder_title_bar != NULL); |
---|
632 | g_return_if_fail (E_IS_SHELL_FOLDER_TITLE_BAR (folder_title_bar)); |
---|
633 | |
---|
634 | priv = folder_title_bar->priv; |
---|
635 | |
---|
636 | if (title == NULL) { |
---|
637 | e_clipped_label_set_text (E_CLIPPED_LABEL (priv->title_button_label), _("(Untitled)")); |
---|
638 | e_clipped_label_set_text (E_CLIPPED_LABEL (priv->title_label), _("(Untitled)")); |
---|
639 | } else { |
---|
640 | e_clipped_label_set_text (E_CLIPPED_LABEL (priv->title_button_label), title); |
---|
641 | e_clipped_label_set_text (E_CLIPPED_LABEL (priv->title_label), title); |
---|
642 | } |
---|
643 | |
---|
644 | /* FIXME: There seems to be a bug in EClippedLabel, this is just a workaround. */ |
---|
645 | gtk_widget_queue_resize (GTK_WIDGET (folder_title_bar)); |
---|
646 | } |
---|
647 | |
---|
648 | /** |
---|
649 | * e_shell_folder_title_bar_set_folder_bar_label: |
---|
650 | * @folder_title_bar: |
---|
651 | * @text: Some text to show in the label. |
---|
652 | * |
---|
653 | * Sets the right-justified text label (to the left of the icon) for |
---|
654 | * the title bar. |
---|
655 | **/ |
---|
656 | void |
---|
657 | e_shell_folder_title_bar_set_folder_bar_label (EShellFolderTitleBar *folder_title_bar, |
---|
658 | const char *text) |
---|
659 | { |
---|
660 | EShellFolderTitleBarPrivate *priv; |
---|
661 | |
---|
662 | g_return_if_fail (folder_title_bar != NULL); |
---|
663 | g_return_if_fail (E_IS_SHELL_FOLDER_TITLE_BAR (folder_title_bar)); |
---|
664 | |
---|
665 | priv = folder_title_bar->priv; |
---|
666 | |
---|
667 | if (text == NULL) |
---|
668 | e_clipped_label_set_text (E_CLIPPED_LABEL (priv->folder_bar_label), ""); |
---|
669 | else |
---|
670 | e_clipped_label_set_text (E_CLIPPED_LABEL (priv->folder_bar_label), text); |
---|
671 | |
---|
672 | /* FIXME: Might want to set the styles somewhere in here too, |
---|
673 | black text on grey background isn't the best combination */ |
---|
674 | |
---|
675 | gtk_widget_queue_resize (GTK_WIDGET (folder_title_bar)); |
---|
676 | } |
---|
677 | |
---|
678 | /** |
---|
679 | * e_shell_folder_title_bar_set_icon: |
---|
680 | * @folder_title_bar: |
---|
681 | * @icon: |
---|
682 | * |
---|
683 | * Set the name of the icon for the title bar. |
---|
684 | **/ |
---|
685 | void |
---|
686 | e_shell_folder_title_bar_set_icon (EShellFolderTitleBar *folder_title_bar, |
---|
687 | GdkPixbuf *icon) |
---|
688 | { |
---|
689 | EShellFolderTitleBarPrivate *priv; |
---|
690 | GdkPixmap *pixmap; |
---|
691 | GdkBitmap *mask; |
---|
692 | |
---|
693 | g_return_if_fail (folder_title_bar != NULL); |
---|
694 | g_return_if_fail (E_IS_SHELL_FOLDER_TITLE_BAR (folder_title_bar)); |
---|
695 | |
---|
696 | priv = folder_title_bar->priv; |
---|
697 | |
---|
698 | if (icon == NULL) { |
---|
699 | if (priv->icon != NULL) |
---|
700 | gdk_pixbuf_unref (priv->icon); |
---|
701 | priv->icon = new_empty_pixbuf (); |
---|
702 | } else { |
---|
703 | gdk_pixbuf_ref (icon); |
---|
704 | if (priv->icon != NULL) |
---|
705 | gdk_pixbuf_unref (priv->icon); |
---|
706 | priv->icon = icon; |
---|
707 | } |
---|
708 | |
---|
709 | gdk_pixbuf_render_pixmap_and_mask (priv->icon, &pixmap, &mask, 127); |
---|
710 | gtk_pixmap_set (GTK_PIXMAP (priv->title_button_icon), pixmap, mask); |
---|
711 | |
---|
712 | gdk_pixbuf_render_pixmap_and_mask (priv->icon, &pixmap, &mask, 127); |
---|
713 | gtk_pixmap_set (GTK_PIXMAP (priv->title_icon), pixmap, mask); |
---|
714 | } |
---|
715 | |
---|
716 | |
---|
717 | /** |
---|
718 | * e_shell_folder_title_bar_set_toggle_state: |
---|
719 | * @folder_title_bar: |
---|
720 | * @state: |
---|
721 | * |
---|
722 | * Set whether the title bar's button is in pressed state (TRUE) or not (FALSE). |
---|
723 | **/ |
---|
724 | void |
---|
725 | e_shell_folder_title_bar_set_toggle_state (EShellFolderTitleBar *folder_title_bar, |
---|
726 | gboolean state) |
---|
727 | { |
---|
728 | EShellFolderTitleBarPrivate *priv; |
---|
729 | |
---|
730 | g_return_if_fail (folder_title_bar != NULL); |
---|
731 | g_return_if_fail (E_IS_SHELL_FOLDER_TITLE_BAR (folder_title_bar)); |
---|
732 | |
---|
733 | priv = folder_title_bar->priv; |
---|
734 | |
---|
735 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->title_button), state); |
---|
736 | } |
---|
737 | |
---|
738 | /** |
---|
739 | * e_shell_folder_title_bar_set_clickable: |
---|
740 | * @folder_title_bar: |
---|
741 | * @clickable: |
---|
742 | * |
---|
743 | * Specify whether the title in the @folder_title_bar is clickable. If not, |
---|
744 | * the arrow pixmap is not shown. |
---|
745 | **/ |
---|
746 | void |
---|
747 | e_shell_folder_title_bar_set_title_clickable (EShellFolderTitleBar *folder_title_bar, |
---|
748 | gboolean title_clickable) |
---|
749 | { |
---|
750 | EShellFolderTitleBarPrivate *priv; |
---|
751 | |
---|
752 | g_return_if_fail (folder_title_bar != NULL); |
---|
753 | g_return_if_fail (E_IS_SHELL_FOLDER_TITLE_BAR (folder_title_bar)); |
---|
754 | |
---|
755 | priv = folder_title_bar->priv; |
---|
756 | |
---|
757 | if ((priv->title_clickable && title_clickable) |
---|
758 | || (! priv->title_clickable && ! title_clickable)) |
---|
759 | return; |
---|
760 | |
---|
761 | if (title_clickable) { |
---|
762 | gtk_widget_hide (priv->title_label); |
---|
763 | gtk_widget_hide (priv->title_icon); |
---|
764 | |
---|
765 | gtk_widget_show_all (priv->title_button); |
---|
766 | } else { |
---|
767 | gtk_widget_hide (priv->title_button); |
---|
768 | |
---|
769 | gtk_widget_show (priv->title_icon); |
---|
770 | gtk_widget_show (priv->title_label); |
---|
771 | } |
---|
772 | |
---|
773 | priv->title_clickable = !! title_clickable; |
---|
774 | } |
---|
775 | |
---|
776 | |
---|
777 | void |
---|
778 | e_shell_folder_title_bar_update_navigation_buttons (EShellFolderTitleBar *folder_title_bar, |
---|
779 | gboolean can_go_back, |
---|
780 | gboolean can_go_forward) |
---|
781 | { |
---|
782 | EShellFolderTitleBarPrivate *priv; |
---|
783 | |
---|
784 | g_return_if_fail (folder_title_bar != NULL); |
---|
785 | g_return_if_fail (E_IS_SHELL_FOLDER_TITLE_BAR (folder_title_bar)); |
---|
786 | |
---|
787 | priv = folder_title_bar->priv; |
---|
788 | |
---|
789 | gtk_widget_set_sensitive (priv->back_button, can_go_back); |
---|
790 | gtk_widget_set_sensitive (priv->forward_button, can_go_forward); |
---|
791 | } |
---|
792 | |
---|
793 | |
---|
794 | E_MAKE_TYPE (e_shell_folder_title_bar, "EShellFolderTitleBar", EShellFolderTitleBar, class_init, init, PARENT_TYPE) |
---|