13
12
* Library General Public License for more details.
15
14
* You should have received a copy of the GNU Library General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
20
#ifdef HAVE_CONFIG_H
39
38
#define XFCE_HEADING_SPACING 12
40
39
#define XFCE_HEADING_ICON_SIZE 48
42
#define XFCE_HEADING_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XFCE_TYPE_HEADING, XfceHeadingPrivate))
46
/* Property identifiers */
58
42
static void _xfce_heading_finalize (GObject *object);
59
static void _xfce_heading_get_property (GObject *object,
63
static void _xfce_heading_set_property (GObject *object,
67
43
static void _xfce_heading_realize (GtkWidget *widget);
68
44
static void _xfce_heading_size_request (GtkWidget *widget,
69
GtkRequisition *requisition);
45
GtkRequisition *requisition);
70
46
static void _xfce_heading_style_set (GtkWidget *widget,
71
GtkStyle *previous_style);
47
GtkStyle *previous_style);
72
48
static gboolean _xfce_heading_expose_event (GtkWidget *widget,
73
GdkEventExpose *event);
49
GdkEventExpose *event);
74
50
static AtkObject *_xfce_heading_get_accessible (GtkWidget *widget);
75
51
static PangoLayout *_xfce_heading_make_layout (XfceHeading *heading);
76
52
static GdkPixbuf *_xfce_heading_make_pixbuf (XfceHeading *heading);
77
static GdkPixbuf *_xfce_heading_get_icon (XfceHeading *heading);
78
static const gchar *_xfce_heading_get_icon_name (XfceHeading *heading);
79
static const gchar *_xfce_heading_get_subtitle (XfceHeading *heading);
80
static const gchar *_xfce_heading_get_title (XfceHeading *heading);
84
struct _XfceHeadingPrivate
56
struct _XfceHeadingClass
59
GtkWidgetClass __parent__;
101
82
GtkWidgetClass *gtkwidget_class;
102
83
GObjectClass *gobject_class;
104
/* add our private data to the class */
105
g_type_class_add_private (klass, sizeof (XfceHeadingPrivate));
107
85
gobject_class = G_OBJECT_CLASS (klass);
108
86
gobject_class->finalize = _xfce_heading_finalize;
109
gobject_class->get_property = _xfce_heading_get_property;
110
gobject_class->set_property = _xfce_heading_set_property;
112
88
gtkwidget_class = GTK_WIDGET_CLASS (klass);
113
89
gtkwidget_class->realize = _xfce_heading_realize;
115
91
gtkwidget_class->style_set = _xfce_heading_style_set;
116
92
gtkwidget_class->expose_event = _xfce_heading_expose_event;
117
93
gtkwidget_class->get_accessible = _xfce_heading_get_accessible;
122
* The #GdkPixbuf to display as icon, or %NULL to use the
123
* "icon-name" property.
127
g_object_class_install_property (gobject_class,
129
g_param_spec_object ("icon",
134
| G_PARAM_STATIC_STRINGS));
137
* XfceHeading:icon-name:
139
* If the "icon" property value is %NULL this is the name of
140
* the icon to display instead (looked up using the icon theme).
141
* If this property is also %NULL or the specified icon does not
142
* exist in the selected icon theme, no icon will be displayed.
146
g_object_class_install_property (gobject_class,
148
g_param_spec_string ("icon-name",
153
| G_PARAM_STATIC_STRINGS));
156
* XfceHeading:subtitle:
158
* The sub title that should be displayed below the
159
* title. May be %NULL or the empty string to display
164
g_object_class_install_property (gobject_class,
166
g_param_spec_string ("subtitle",
171
| G_PARAM_STATIC_STRINGS));
176
* The title text to display in the heading.
180
g_object_class_install_property (gobject_class,
182
g_param_spec_string ("title",
187
| G_PARAM_STATIC_STRINGS));
193
99
_xfce_heading_init (XfceHeading *heading)
195
/* setup the private data */
196
heading->priv = XFCE_HEADING_GET_PRIVATE (heading);
198
101
/* setup the widget parameters */
199
102
GTK_WIDGET_UNSET_FLAGS (heading, GTK_NO_WINDOW);
207
110
XfceHeading *heading = XFCE_HEADING (object);
209
112
/* release the private data */
210
if (G_UNLIKELY (heading->priv->icon != NULL))
211
g_object_unref (G_OBJECT (heading->priv->icon));
113
if (G_UNLIKELY (heading->icon != NULL))
114
g_object_unref (G_OBJECT (heading->icon));
213
g_free (heading->priv->icon_name);
214
g_free (heading->priv->subtitle);
215
g_free (heading->priv->title);
116
g_free (heading->icon_name);
117
g_free (heading->subtitle);
118
g_free (heading->title);
217
120
(*G_OBJECT_CLASS (_xfce_heading_parent_class)->finalize) (object);
223
_xfce_heading_get_property (GObject *object,
228
XfceHeading *heading = XFCE_HEADING (object);
233
g_value_set_object (value, _xfce_heading_get_icon (heading));
237
g_value_set_string (value, _xfce_heading_get_icon_name (heading));
241
g_value_set_string (value, _xfce_heading_get_subtitle (heading));
245
g_value_set_string (value, _xfce_heading_get_title (heading));
249
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
257
_xfce_heading_set_property (GObject *object,
262
XfceHeading *heading = XFCE_HEADING (object);
267
_xfce_heading_set_icon (heading, g_value_get_object (value));
271
_xfce_heading_set_icon_name (heading, g_value_get_string (value));
275
_xfce_heading_set_subtitle (heading, g_value_get_string (value));
279
_xfce_heading_set_title (heading, g_value_get_string (value));
283
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
291
126
_xfce_heading_realize (GtkWidget *widget)
293
128
GdkWindowAttr attributes;
362
197
_xfce_heading_style_set (GtkWidget *widget,
363
GtkStyle *previous_style)
198
GtkStyle *previous_style)
365
200
/* check if we're already realized */
366
201
if (GTK_WIDGET_REALIZED (widget))
422
257
y = (widget->allocation.height - height) / 2;
424
259
/* render the title */
425
gtk_paint_layout (widget->style, widget->window, GTK_WIDGET_STATE (widget), TRUE, &event->area,
260
gtk_paint_layout (widget->style, widget->window,
261
GTK_WIDGET_STATE (widget), TRUE, &event->area,
426
262
widget, "heading", (rtl ? x - width : x), y, layout);
428
264
/* release the layout */
458
294
/* generate the full text */
459
295
text = g_string_sized_new (128);
460
if (G_LIKELY (heading->priv->title != NULL))
296
if (G_LIKELY (heading->title != NULL))
462
298
/* add the main title */
463
title_length = strlen (heading->priv->title);
464
g_string_append (text, heading->priv->title);
299
title_length = strlen (heading->title);
300
g_string_append (text, heading->title);
466
if (heading->priv->subtitle != NULL && *heading->priv->subtitle != '\0')
302
if (heading->subtitle != NULL && *heading->subtitle != '\0')
468
304
/* add an empty line between the title and the subtitle */
469
if (G_LIKELY (heading->priv->title != NULL))
305
if (G_LIKELY (heading->title != NULL))
470
306
g_string_append (text, "\n");
472
308
/* add the subtitle */
473
g_string_append (text, heading->priv->subtitle);
309
g_string_append (text, heading->subtitle);
476
312
/* allocate and setup a new layout from the widget's context */
503
339
GtkIconTheme *icon_theme;
504
340
GdkPixbuf *pixbuf = NULL;
505
341
GdkScreen *screen;
507
if (G_UNLIKELY (heading->priv->icon != NULL))
344
if (G_UNLIKELY (heading->icon != NULL))
509
346
/* just use the specified icon */
510
pixbuf = g_object_ref (G_OBJECT (heading->priv->icon));
347
pixbuf = g_object_ref (G_OBJECT (heading->icon));
512
else if (G_LIKELY (heading->priv->icon_name != NULL))
349
else if (G_LIKELY (heading->icon_name != NULL))
514
351
/* determine the icon theme for the current screen */
515
352
screen = gtk_widget_get_screen (GTK_WIDGET (heading));
516
353
icon_theme = gtk_icon_theme_get_for_screen (screen);
518
355
/* try to load the icon from the icon theme */
519
pixbuf = gtk_icon_theme_load_icon (icon_theme, heading->priv->icon_name,
356
pixbuf = gtk_icon_theme_load_icon (icon_theme, heading->icon_name,
520
357
XFCE_HEADING_ICON_SIZE,
521
358
GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
361
&& (gdk_pixbuf_get_height (pixbuf) > XFCE_HEADING_ICON_SIZE
362
|| gdk_pixbuf_get_width (pixbuf) > XFCE_HEADING_ICON_SIZE))
364
/* this doesn't happen often, so be stupid
365
* and assume icons are always squared */
366
scaled = gdk_pixbuf_scale_simple (pixbuf,
367
XFCE_HEADING_ICON_SIZE,
368
XFCE_HEADING_ICON_SIZE,
369
GDK_INTERP_BILINEAR);
370
g_object_unref (pixbuf);
374
/* cache the icon, this does not take theme changes in account,
375
* but because of the only use in the titled dialog, this works
376
* fine, since the window properties are emitted on icon changes */
377
if (heading->icon == NULL
379
heading->icon = g_object_ref (pixbuf);
532
* Allocates a new #XfceHeading instance.
534
* Return value: the newly allocated #XfceHeading.
537
_xfce_heading_new (void)
539
return g_object_new (XFCE_TYPE_HEADING, NULL);
545
* _xfce_heading_get_icon:
546
* @heading : a #XfceHeading.
548
* Returns the #GdkPixbuf that was set as icon for
549
* @heading or %NULL if no icon is set. The returned
550
* #GdkPixbuf object is owned by @heading.
552
* Return value: the icon for @heading, or %NULL.
555
_xfce_heading_get_icon (XfceHeading *heading)
557
g_return_val_if_fail (XFCE_IS_HEADING (heading), NULL);
558
return heading->priv->icon;
564
388
* _xfce_heading_set_icon:
565
389
* @heading : a #XfceHeading.
566
390
* @icon : the new icon or %NULL.
573
397
_xfce_heading_set_icon (XfceHeading *heading,
576
g_return_if_fail (XFCE_IS_HEADING (heading));
577
g_return_if_fail (icon == NULL || GDK_IS_PIXBUF (icon));
400
_libxfce4ui_return_if_fail (XFCE_IS_HEADING (heading));
401
_libxfce4ui_return_if_fail (icon == NULL || GDK_IS_PIXBUF (icon));
579
403
/* check if we have a new icon */
580
if (G_LIKELY (heading->priv->icon != icon))
404
if (G_LIKELY (heading->icon != icon))
582
406
/* disconnect from the previous icon */
583
if (G_LIKELY (heading->priv->icon != NULL))
584
g_object_unref (G_OBJECT (heading->priv->icon));
586
/* activate the new icon */
587
heading->priv->icon = icon;
589
/* connect to the new icon */
590
if (G_LIKELY (icon != NULL))
591
g_object_ref (G_OBJECT (icon));
593
/* schedule a resize */
407
if (G_LIKELY (heading->icon != NULL))
408
g_object_unref (G_OBJECT (heading->icon));
412
if (gdk_pixbuf_get_height (icon) > XFCE_HEADING_ICON_SIZE
413
|| gdk_pixbuf_get_width (icon) > XFCE_HEADING_ICON_SIZE)
415
/* this doesn't happen often, so be stupid
416
* and assume icons are always squared */
417
heading->icon = gdk_pixbuf_scale_simple (icon,
418
XFCE_HEADING_ICON_SIZE,
419
XFCE_HEADING_ICON_SIZE,
420
GDK_INTERP_BILINEAR);
424
heading->icon = g_object_ref (icon);
429
heading->icon = NULL;
594
432
gtk_widget_queue_resize (GTK_WIDGET (heading));
596
/* notify listeners */
597
g_object_notify (G_OBJECT (heading), "icon");
604
* _xfce_heading_get_icon_name:
605
* @heading : a #XfceHeading.
607
* Returns the icon name previously set by a call to
608
* _xfce_heading_set_icon_name() or %NULL if no icon name
609
* is set for @heading.
611
* Return value: the icon name for @heading, or %NULL.
614
_xfce_heading_get_icon_name (XfceHeading *heading)
616
g_return_val_if_fail (XFCE_IS_HEADING (heading), NULL);
617
return heading->priv->icon_name;
623
439
* _xfce_heading_set_icon_name:
624
440
* @heading : a #XfceHeading.
625
441
* @icon_name : the new icon name, or %NULL.
632
448
_xfce_heading_set_icon_name (XfceHeading *heading,
633
449
const gchar *icon_name)
635
g_return_if_fail (XFCE_IS_HEADING (heading));
637
/* release the previous icon name */
638
g_free (heading->priv->icon_name);
451
_libxfce4ui_return_if_fail (XFCE_IS_HEADING (heading));
640
453
/* activate the new icon name */
641
heading->priv->icon_name = g_strdup (icon_name);
454
g_free (heading->icon_name);
455
heading->icon_name = g_strdup (icon_name);
643
/* schedule a resize */
644
457
gtk_widget_queue_resize (GTK_WIDGET (heading));
646
/* notify listeners */
647
g_object_notify (G_OBJECT (heading), "icon-name");
653
* _xfce_heading_get_subtitle:
654
* @heading : a #XfceHeading.
656
* Returns the sub title displayed below the
657
* main title of the @heading, or %NULL if
658
* no subtitle is set.
660
* Return value: the subtitle of @heading, or %NULL.
663
_xfce_heading_get_subtitle (XfceHeading *heading)
665
g_return_val_if_fail (XFCE_IS_HEADING (heading), NULL);
666
return heading->priv->subtitle;
680
471
_xfce_heading_set_subtitle (XfceHeading *heading,
681
472
const gchar *subtitle)
683
g_return_if_fail (XFCE_IS_HEADING (heading));
684
g_return_if_fail (subtitle == NULL || g_utf8_validate (subtitle, -1, NULL));
686
/* release the previous subtitle */
687
g_free (heading->priv->subtitle);
474
_libxfce4ui_return_if_fail (XFCE_IS_HEADING (heading));
475
_libxfce4ui_return_if_fail (subtitle == NULL || g_utf8_validate (subtitle, -1, NULL));
689
477
/* activate the new subtitle */
690
heading->priv->subtitle = g_strdup (subtitle);
478
g_free (heading->subtitle);
479
heading->subtitle = g_strdup (subtitle);
692
/* schedule a resize */
693
481
gtk_widget_queue_resize (GTK_WIDGET (heading));
695
/* notify listeners */
696
g_object_notify (G_OBJECT (heading), "subtitle");
702
* _xfce_heading_get_title:
703
* @heading : a #XfceHeading.
705
* Returns the title displayed by the @heading.
707
* Return value: the title displayed by the @heading.
710
_xfce_heading_get_title (XfceHeading *heading)
712
g_return_val_if_fail (XFCE_IS_HEADING (heading), NULL);
713
return heading->priv->title;
727
495
_xfce_heading_set_title (XfceHeading *heading,
728
496
const gchar *title)
730
g_return_if_fail (XFCE_IS_HEADING (heading));
731
g_return_if_fail (title == NULL || g_utf8_validate (title, -1, NULL));
733
/* release the previous title */
734
g_free (heading->priv->title);
498
_libxfce4ui_return_if_fail (XFCE_IS_HEADING (heading));
499
_libxfce4ui_return_if_fail (title == NULL || g_utf8_validate (title, -1, NULL));
736
501
/* activate the new title */
737
heading->priv->title = g_strdup (title);
502
g_free (heading->title);
503
heading->title = g_strdup (title);
739
/* schedule a resize */
740
505
gtk_widget_queue_resize (GTK_WIDGET (heading));
742
/* notify listeners */
743
g_object_notify (G_OBJECT (heading), "title");