From 24cb9c806dfa5ae95dc87214da2b18cfcccf99ec Mon Sep 17 00:00:00 2001 From: Alberto Garcia Date: Thu, 2 Apr 2009 10:14:07 +0000 Subject: [PATCH] 2009-03-20 Alberto Garcia * doc/hildon-sections.txt * src/hildon-window-private.h * src/hildon-window.h * src/hildon-window.c (hildon_window_class_init) (hildon_window_init, hildon_window_finalize) (hildon_window_realize, hildon_window_get_property) (hildon_window_set_property, hildon_window_update_markup) (hildon_window_get_markup, hildon_window_set_markup): New "markup" property and hildon_window_{get,set}_markup() methods. * examples/hildon-stackable-window-example.c (new_window): Update example to use hildon_window_set_markup() Fixes: NB#106375 (Need API to retitle a window with a title including markup) --- ChangeLog | 18 ++++ doc/hildon-sections.txt | 2 + examples/hildon-stackable-window-example.c | 5 ++ src/hildon-window-private.h | 2 + src/hildon-window.c | 122 +++++++++++++++++++++++++++- src/hildon-window.h | 7 ++ 6 files changed, 155 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 10b48f8..7a36511 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2009-04-02 Alberto Garcia + + * doc/hildon-sections.txt + * src/hildon-window-private.h + * src/hildon-window.h + * src/hildon-window.c (hildon_window_class_init) + (hildon_window_init, hildon_window_finalize) + (hildon_window_realize, hildon_window_get_property) + (hildon_window_set_property, hildon_window_update_markup) + (hildon_window_get_markup, hildon_window_set_markup): + New "markup" property and hildon_window_{get,set}_markup() methods. + + * examples/hildon-stackable-window-example.c (new_window): + Update example to use hildon_window_set_markup() + + Fixes: NB#106375 (Need API to retitle a window with a title + including markup) + 2009-04-01 Alejandro G. Castro * src/hildon-pannable-area.c, diff --git a/doc/hildon-sections.txt b/doc/hildon-sections.txt index 58e2809..09806b7 100644 --- a/doc/hildon-sections.txt +++ b/doc/hildon-sections.txt @@ -695,6 +695,8 @@ hildon_window_add_toolbar hildon_window_remove_toolbar hildon_window_set_edit_toolbar hildon_window_get_is_topmost +hildon_window_set_markup +hildon_window_get_markup HILDON_WINDOW HILDON_IS_WINDOW diff --git a/examples/hildon-stackable-window-example.c b/examples/hildon-stackable-window-example.c index ef65859..566a2df 100644 --- a/examples/hildon-stackable-window-example.c +++ b/examples/hildon-stackable-window-example.c @@ -62,6 +62,11 @@ new_window (HildonStackableWindow *parent) gtk_window_set_title (GTK_WINDOW (window), text); g_free (text); + /* Marked up window title */ + text = g_strdup_printf ("Stack number %d - window %d", stack_number, win_number); + hildon_window_set_markup (HILDON_WINDOW (window), text); + g_free (text); + /* Main label */ text = g_strdup_printf ("Stack number %d\nWindow number %d", stack_number, win_number); label = gtk_label_new (text); diff --git a/src/hildon-window-private.h b/src/hildon-window-private.h index fc5493d..97034a6 100644 --- a/src/hildon-window-private.h +++ b/src/hildon-window-private.h @@ -45,6 +45,8 @@ struct _HildonWindowPrivate GtkAllocation allocation; + gchar *markup; + guint fullscreen; guint is_topmost; guint escape_timeout; diff --git a/src/hildon-window.c b/src/hildon-window.c index 73ef13f..ee1a08a 100644 --- a/src/hildon-window.c +++ b/src/hildon-window.c @@ -158,6 +158,15 @@ hildon_window_get_property (GObject *object, GParamSpec *pspec); static void +hildon_window_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); + +static void +hildon_window_update_markup (HildonWindow *window); + +static void hildon_window_destroy (GtkObject *obj); static void @@ -238,7 +247,8 @@ paint_edit_toolbar (GtkWidget *widget, enum { PROP_0, - PROP_IS_TOPMOST + PROP_IS_TOPMOST, + PROP_MARKUP }; enum @@ -259,6 +269,7 @@ hildon_window_class_init (HildonWindowClass * window_clas GtkContainerClass *container_class = GTK_CONTAINER_CLASS (window_class); object_class->get_property = hildon_window_get_property; + object_class->set_property = hildon_window_set_property; object_class->notify = hildon_window_notify; widget_class->size_allocate = hildon_window_size_allocate; widget_class->size_request = hildon_window_size_request; @@ -298,6 +309,13 @@ hildon_window_class_init (HildonWindowClass * window_clas FALSE, G_PARAM_READABLE)); + g_object_class_install_property (object_class, PROP_MARKUP, + g_param_spec_string ("markup", + "Marked up text for the window title", + "Marked up text for the window title", + NULL, + G_PARAM_READWRITE)); + gtk_widget_class_install_style_property (widget_class, g_param_spec_boxed ("borders", "Graphical borders", @@ -338,6 +356,7 @@ hildon_window_init (HildonWindow *self) priv->borders = NULL; priv->toolbar_borders = NULL; priv->escape_timeout = 0; + priv->markup = NULL; priv->fullscreen = FALSE; @@ -361,6 +380,8 @@ hildon_window_finalize (GObject * obj_self) priv = HILDON_WINDOW_GET_PRIVATE (obj_self); g_assert (priv != NULL); + g_free (priv->markup); + if (priv->escape_timeout) { g_source_remove (priv->escape_timeout); priv->escape_timeout = 0; @@ -427,6 +448,9 @@ hildon_window_realize (GtkWidget *widget) &can_hibernate); } + if (priv->markup) + hildon_window_update_markup (HILDON_WINDOW (widget)); + /* Update the topmost status */ active_window = hildon_window_get_active_window(); hildon_window_update_topmost (HILDON_WINDOW (widget), active_window); @@ -495,12 +519,34 @@ hildon_window_get_property (GObject *object, g_value_set_boolean (value, priv->is_topmost); break; + case PROP_MARKUP: + g_value_set_string (value, priv->markup); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; } } +static void +hildon_window_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + + case PROP_MARKUP: + hildon_window_set_markup (HILDON_WINDOW (object), g_value_get_string (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + /* * Retrieve the graphical borders size used by the themes */ @@ -2046,3 +2092,77 @@ hildon_window_get_app_menu (HildonWindow *self) return priv->app_menu; } + +static void +hildon_window_update_markup (HildonWindow *window) +{ + HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window); + GdkAtom markup_atom = gdk_atom_intern ("_HILDON_WM_NAME", FALSE); + GdkAtom utf8_atom = gdk_atom_intern ("UTF8_STRING", FALSE); + GdkWindow *gdkwin = GTK_WIDGET (window)->window; + + if (priv->markup) { + gdk_property_change (gdkwin, markup_atom, utf8_atom, 8, + GDK_PROP_MODE_REPLACE, (const guchar *) priv->markup, + strlen (priv->markup)); + } else { + gdk_property_delete (gdkwin, markup_atom); + } +} + +/** + * hildon_window_get_markup: + * @window: a #HildonWindow + * + * Gets the marked up title of the window title. See hildon_window_set_markup() + * + * Returns: the marked up title of the window, or %NULL if none has + * been set explicitely. The returned string is owned by the widget + * and must not be modified or freed. + **/ +const gchar * +hildon_window_get_markup (HildonWindow *window) +{ + HildonWindowPrivate *priv; + + g_return_val_if_fail (HILDON_IS_WINDOW (window), NULL); + + priv = HILDON_WINDOW_GET_PRIVATE (window); + + return priv->markup; +} + +/** + * hildon_window_set_markup: + * @window: a #HildonWindow + * @markup: the marked up title of the window, or %NULL to unset the + * current one + * + * Sets the marked up title of @window. The accepted format is the one + * used in Pango (see #PangoMarkupFormat) with the exception of + * <span>. + * + * Note that you need support from the window manager for this title + * to be used. See gtk_window_set_title() for the standard way of + * setting the title of a window. + **/ +void +hildon_window_set_markup (HildonWindow *window, + const gchar *markup) +{ + HildonWindowPrivate *priv; + gchar *new_markup; + + g_return_if_fail (HILDON_IS_WINDOW (window)); + + priv = HILDON_WINDOW_GET_PRIVATE (window); + + new_markup = g_strdup (markup); + g_free (priv->markup); + priv->markup = new_markup; + + if (GTK_WIDGET_REALIZED (window)) + hildon_window_update_markup (window); + + g_object_notify (G_OBJECT (window), "markup"); +} diff --git a/src/hildon-window.h b/src/hildon-window.h index 8dec729..e5d8d49 100644 --- a/src/hildon-window.h +++ b/src/hildon-window.h @@ -128,6 +128,13 @@ hildon_window_set_edit_toolbar (HildonWindow *self, gboolean hildon_window_get_is_topmost (HildonWindow *self); +const gchar * +hildon_window_get_markup (HildonWindow *window); + +void +hildon_window_set_markup (HildonWindow *window, + const gchar *markup); + G_END_DECLS #endif /* __HILDON_WINDOW_H__ */ -- 1.7.9.5