/*
* This file is a part of hildon
*
- * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ * Copyright (C) 2008, 2009 Nokia Corporation, all rights reserved.
*
* Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
*
* SECTION:hildon-button
* @short_description: Two-label buttons in the Hildon framework.
*
- * The #HildonButton is a clickable button for Hildon applications.
- * It is derived from the #GtkButton widget and provides
- * additional commodities specific to the Hildon framework.
+ * #HildonButton is a clickable button for Hildon applications. It is
+ * derived from the #GtkButton widget and provides additional
+ * commodities specific to the Hildon framework.
*
* The height of a #HildonButton can be set to either "finger" height
* or "thumb" height. It can also be configured to use halfscreen or
* fullscreen width. Alternatively, either dimension can be set to
* "auto" so it behaves like a standard #GtkButton.
*
- * The #HildonButton can hold any valid child widget, but it usually
+ * A #HildonButton can hold any valid child widget, but it usually
* contains two labels, named title and value, and it can also contain
* an image. The contents of the button are packed together inside a
* #GtkAlignment and they do not expand by default (they don't use the
#include "hildon-button.h"
#include "hildon-enum-types.h"
#include "hildon-gtk.h"
-#include "hildon-helper.h"
G_DEFINE_TYPE (HildonButton, hildon_button, GTK_TYPE_BUTTON);
gfloat image_xalign;
gfloat image_yalign;
HildonButtonStyle style;
+ guint setting_style : 1;
};
enum {
}
static void
+set_logical_font (GtkWidget *button)
+{
+ HildonButtonPrivate *priv = HILDON_BUTTON_GET_PRIVATE (button);
+
+ /* In buttons with vertical arrangement, the 'value' label uses a
+ * different font */
+ if (GTK_IS_VBOX (priv->label_box)) {
+ GtkStyle *style = gtk_rc_get_style_by_paths (
+ gtk_settings_get_default (), "SmallSystemFont", NULL, G_TYPE_NONE);
+ if (style != NULL) {
+ PangoFontDescription *font_desc = style->font_desc;
+ if (font_desc != NULL) {
+ priv->setting_style = TRUE;
+ gtk_widget_modify_font (GTK_WIDGET (priv->value), font_desc);
+ priv->setting_style = FALSE;
+ }
+ }
+ }
+}
+
+static void
+set_logical_color (GtkWidget *button)
+{
+ GdkColor color;
+ const gchar *colorname;
+ HildonButtonPrivate *priv = HILDON_BUTTON_GET_PRIVATE (button);
+ GtkWidget *label = GTK_WIDGET (priv->value);
+
+ switch (priv->style) {
+ case HILDON_BUTTON_STYLE_NORMAL:
+ colorname = "SecondaryTextColor";
+ break;
+ case HILDON_BUTTON_STYLE_PICKER:
+ colorname = "ActiveTextColor";
+ break;
+ default:
+ g_return_if_reached ();
+ }
+
+ gtk_widget_ensure_style (label);
+ if (gtk_style_lookup_color (label->style, colorname, &color) == TRUE) {
+ priv->setting_style = TRUE;
+ gtk_widget_modify_fg (label, GTK_STATE_NORMAL, &color);
+ gtk_widget_modify_fg (label, GTK_STATE_PRELIGHT, &color);
+ priv->setting_style = FALSE;
+ }
+}
+
+static void
hildon_button_style_set (GtkWidget *widget,
GtkStyle *previous_style)
{
if (GTK_WIDGET_CLASS (hildon_button_parent_class)->style_set)
GTK_WIDGET_CLASS (hildon_button_parent_class)->style_set (widget, previous_style);
+ /* Prevent infinite recursion when calling set_logical_font() and
+ * set_logical_color() */
+ if (priv->setting_style)
+ return;
+
gtk_widget_style_get (widget,
"horizontal-spacing", &horizontal_spacing,
"vertical-spacing", &vertical_spacing,
if (GTK_IS_BOX (priv->hbox)) {
gtk_box_set_spacing (priv->hbox, image_spacing);
}
+
+ set_logical_font (widget);
+ set_logical_color (widget);
}
static void
priv->image_yalign = 0.5;
priv->hbox = NULL;
priv->label_box = NULL;
+ priv->style = HILDON_BUTTON_STYLE_NORMAL;
+ priv->setting_style = FALSE;
gtk_widget_set_name (GTK_WIDGET (priv->title), "hildon-button-title");
gtk_widget_set_name (GTK_WIDGET (priv->value), "hildon-button-value");
/* Pack everything */
if (arrangement == HILDON_BUTTON_ARRANGEMENT_VERTICAL) {
priv->label_box = gtk_vbox_new (FALSE, 0);
- hildon_helper_set_logical_font (GTK_WIDGET (priv->value), "SmallSystemFont");
+ set_logical_font (GTK_WIDGET (button));
} else {
priv->label_box = gtk_hbox_new (FALSE, 0);
}
* to change @xscale or @yscale you can just use
* gtk_button_set_alignment() instead.
*
- * Note that for this method to work properly the, child widget of
+ * Note that for this method to work properly, the child widget of
* @button must be a #GtkAlignment. That's what #HildonButton uses by
* default, so this function will work unless you add a custom widget
* to @button.
HildonButtonStyle style)
{
HildonButtonPrivate *priv;
- const gchar *color;
g_return_if_fail (HILDON_IS_BUTTON (button));
-
- switch (style) {
- case HILDON_BUTTON_STYLE_NORMAL:
- color = "SecondaryTextColor";
- break;
- case HILDON_BUTTON_STYLE_PICKER:
- color = "ActiveTextColor";
- break;
- default:
- g_return_if_reached ();
- }
-
priv = HILDON_BUTTON_GET_PRIVATE (button);
- hildon_helper_set_logical_color (GTK_WIDGET (priv->value), GTK_RC_FG, GTK_STATE_NORMAL, color);
- hildon_helper_set_logical_color (GTK_WIDGET (priv->value), GTK_RC_FG, GTK_STATE_PRELIGHT, color);
-
priv->style = style;
+ set_logical_color (GTK_WIDGET (button));
g_object_notify (G_OBJECT (button), "style");
}