2 * This file is part of hildon-libs
4 * Copyright (C) 2005 Nokia Corporation.
6 * Contact: Luc Pionchon <luc.pionchon@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 #include "hildon-defines.h"
28 HildonIconSizes *hildoniconsizes = NULL; /* FIXME: could be const */
29 HildonIconSizes hildoninternaliconsizes; /* FIXME: should be static */
32 * hildon_icon_sizes_init:
34 * Initializes the icon sizes. This is automatically
35 * called when the icon sizes have not been initialized
36 * and one is requested.
38 void hildon_icon_sizes_init (void)
40 if (hildoniconsizes != NULL)
43 hildoniconsizes = &hildoninternaliconsizes;
45 hildoniconsizes->icon_size_list = gtk_icon_size_register ("hildon_icon_size_list", 64, 64);
46 hildoniconsizes->icon_size_small = gtk_icon_size_register ("*icon_size_small", 26, 26);
47 hildoniconsizes->icon_size_toolbar = gtk_icon_size_register ("icon_size_toolbar", 26, 26);
48 hildoniconsizes->icon_size_widg = gtk_icon_size_register ("icon_size_widg", 26, 26);
49 hildoniconsizes->icon_size_widg_wizard = gtk_icon_size_register ("icon_size_widg_wizard", 50, 50);
50 hildoniconsizes->icon_size_grid = gtk_icon_size_register ("icon_size_grid", 64, 64);
51 hildoniconsizes->icon_size_big_note = gtk_icon_size_register ("icon_size_big_note", 50, 50);
52 hildoniconsizes->icon_size_note = gtk_icon_size_register ("icon_size_note", 26, 26);
53 hildoniconsizes->icon_size_statusbar = gtk_icon_size_register ("icon_size_statusbar", 40, 40);
54 hildoniconsizes->icon_size_indi_video_player_pre_roll = gtk_icon_size_register ("icon_size_indi_video_player_pre_roll", 64, 64);
55 hildoniconsizes->icon_size_indi_key_pad_lock = gtk_icon_size_register ("icon_size_indi_key_pad_lock", 50, 50);
56 hildoniconsizes->icon_size_indi_copy = gtk_icon_size_register ("icon_size_indi_copy", 64, 64);
57 hildoniconsizes->icon_size_indi_delete = gtk_icon_size_register ("icon_size_indi_delete", 64, 64);
58 hildoniconsizes->icon_size_indi_process = gtk_icon_size_register ("icon_size_indi_process", 64, 64);
59 hildoniconsizes->icon_size_indi_progressball = gtk_icon_size_register ("icon_size_indi_progressball", 64, 64);
60 hildoniconsizes->icon_size_indi_send = gtk_icon_size_register ("icon_size_indi_send", 64, 64);
61 hildoniconsizes->icon_size_indi_offmode_charging = gtk_icon_size_register ("icon_size_indi_offmode_charging", 50, 50);
62 hildoniconsizes->icon_size_indi_tap_and_hold = gtk_icon_size_register ("icon_size_indi_tap_and_hold", 34, 34);
63 hildoniconsizes->icon_size_indi_send_receive = gtk_icon_size_register ("icon_size_indi_send_receive", 64, 64);
64 hildoniconsizes->icon_size_indi_wlan_strength = gtk_icon_size_register ("icon_size_indi_wlan_strength", 64, 64);
66 hildoniconsizes->image_size_indi_nokia_logo = gtk_icon_size_register ("image_size_indi_nokia_logo", 64, 64);
67 hildoniconsizes->image_size_indi_startup_failed = gtk_icon_size_register ("image_size_indi_startup_failed", 64, 64);
68 hildoniconsizes->image_size_indi_startup_nokia_logo = gtk_icon_size_register ("image_size_indi_startup_nokia_logo", 64, 64);
69 hildoniconsizes->image_size_indi_nokia_hands = gtk_icon_size_register ("image_size_indi_nokia_hands", 64, 64);
72 typedef struct _HildonLogicalData HildonLogicalData;
74 struct _HildonLogicalData
78 gchar *logicalcolorstring;
79 gchar *logicalfontstring;
83 static void hildon_change_style_recursive_from_ld (GtkWidget *widget, GtkStyle *prev_style, HildonLogicalData *ld)
85 /* Change the style for child widgets */
86 if (GTK_IS_CONTAINER (widget))
87 gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback) (hildon_change_style_recursive_from_ld), ld);
89 /* gtk_widget_modify_*() emit "style_set" signals, so if we got here from
90 "style_set" signal, we need to block this function from being called
91 again or we get into inifinite loop.
93 Compiling with gcc > 3.3 and -pedantic won't allow conversion between
94 function and object pointers. GLib API however requires an object pointer
95 for a function, so we have to work around this. See
96 see http://bugzilla.gnome.org/show_bug.cgi?id=310175
98 FIXME: Use G_GNUC_EXTENSION instead of our own ifdef
103 g_signal_handlers_block_matched (G_OBJECT (widget), G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC,
104 g_signal_lookup ("style_set", G_TYPE_FROM_INSTANCE (widget)),
106 (gpointer) hildon_change_style_recursive_from_ld,
109 if (ld->logicalcolorstring != NULL)
111 /* Changing logical color */
113 if (gtk_style_lookup_logical_color (widget->style, ld->logicalcolorstring, &color) == TRUE)
117 gtk_widget_modify_fg (widget, ld->state, &color);
120 gtk_widget_modify_bg (widget, ld->state, &color);
123 gtk_widget_modify_text (widget, ld->state, &color);
126 gtk_widget_modify_base (widget, ld->state, &color);
131 if (ld->logicalfontstring != NULL)
133 /* Changing logical font */
134 GtkStyle *fontstyle = gtk_rc_get_style_by_paths (gtk_settings_get_default (), ld->logicalfontstring, NULL, G_TYPE_NONE);
135 if (fontstyle != NULL)
137 PangoFontDescription *fontdesc = fontstyle->font_desc;
139 if (fontdesc != NULL)
140 gtk_widget_modify_font (widget, fontdesc);
145 /* Compilation workaround for gcc > 3.3 + -pedantic again */
149 g_signal_handlers_unblock_matched (G_OBJECT (widget), G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC,
150 g_signal_lookup ("style_set", G_TYPE_FROM_INSTANCE (widget)),
152 (gpointer) hildon_change_style_recursive_from_ld,
157 * hildon_gtk_widget_set_logical_font:
158 * @widget : A @GtkWidget to assign this logical font for.
159 * @logicalfontname : A gchar* with the logical font name to assign to the widget with an "osso-" -prefix.
161 * This function assigns a defined logical font to the @widget and all its child widgets.
162 * It also connects to the "style_set" signal which will retrieve & assign the new font for the given logical name each time the theme is changed.
163 * The returned signal id can be used to disconnect the signal.
165 * Return value : The signal id that is triggered every time theme is changed. 0 if font set failed.
167 gulong hildon_gtk_widget_set_logical_font (GtkWidget *widget, gchar *logicalfontname)
169 HildonLogicalData *ld;
172 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
173 g_return_val_if_fail (logicalfontname != NULL, 0);
175 ld = g_malloc (sizeof (HildonLogicalData));
179 ld->logicalcolorstring = NULL;
180 ld->logicalfontstring = logicalfontname; /* FIXME: g_strdup() */
182 /* Change the font now */
183 hildon_change_style_recursive_from_ld (widget, NULL, ld);
185 /* Connect to "style_set" so that the font gets changed whenever theme
186 changes. FIXME: if this function is called multiple times, the old signal
187 handler should be disconnected */
188 signum = g_signal_connect_data (G_OBJECT (widget), "style_set", G_CALLBACK (hildon_change_style_recursive_from_ld), ld, (GClosureNotify) g_free, 0);
194 * hildon_gtk_widget_set_logical_color:
195 * @widget : A @GtkWidget to assign this logical font for.
196 * @rcflags : @GtkRcFlags enumeration defining whether to assign to FG, BG, TEXT or BASE style.
197 * @state : @GtkStateType indicating to which state to assign the logical color
198 * @logicalcolorname : A gchar* with the logical font name to assign to the widget.
200 * This function assigns a defined logical color to the @widget and all it's child widgets.
201 * It also connects to the "style_set" signal which will retrieve & assign the new color for the given logical name each time the theme is changed.
202 * The returned signal id can be used to disconnect the signal.
204 * Example : If the style you want to modify is bg[NORMAL] then set rcflags to GTK_RC_BG and state to GTK_STATE_NORMAL.
206 * Return value : The signal id that is triggered every time theme is changed. 0 if color set failed.
208 gulong hildon_gtk_widget_set_logical_color (GtkWidget *widget, GtkRcFlags rcflags,
209 GtkStateType state, gchar *logicalcolorname)
211 HildonLogicalData *ld;
214 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
215 g_return_val_if_fail (logicalcolorname != NULL, 0);
217 ld = g_malloc (sizeof (HildonLogicalData));
219 ld->rcflags = rcflags;
221 ld->logicalcolorstring = logicalcolorname; /* FIXME: g_strdup() */
222 ld->logicalfontstring = NULL;
224 /* Change the colors now */
225 hildon_change_style_recursive_from_ld (widget, NULL, ld);
227 /* Connect to "style_set" so that the colors gets changed whenever theme
228 changes. FIXME: if this function is called multiple times, the old signal
229 handler should be disconnected */
230 signum = g_signal_connect_data (G_OBJECT (widget), "style_set", G_CALLBACK (hildon_change_style_recursive_from_ld), ld, (GClosureNotify) g_free, 0);