2 * This file is a part of hildon
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser Public License as published by
8 * the Free Software Foundation; version 2 of the license.
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
13 * GNU Lesser Public License for more details.
19 * @short_description: Additional functions for Gtk widgets
20 * @see_also: #HildonButton, #HildonCheckButton
22 * Hildon provides some functions to extend the functionality of
23 * existing Gtk widgets. This also includes convenience functions to
24 * easily perform frequent tasks.
27 #include <X11/Xatom.h>
30 #include "hildon-gtk.h"
33 image_visible_changed_cb (GtkWidget *image,
37 if (!GTK_WIDGET_VISIBLE (image))
38 gtk_widget_show (image);
42 parent_changed_cb (GtkWidget *image,
46 /* If the parent has really changed, remove the old signal handlers */
47 if (image->parent != oldparent) {
48 g_signal_handlers_disconnect_by_func (image, parent_changed_cb, oldparent);
49 g_signal_handlers_disconnect_by_func (image, image_visible_changed_cb, NULL);
54 image_changed_cb (GtkButton *button,
58 GtkWidget *image = gtk_button_get_image (button);
60 g_return_if_fail (image == NULL || GTK_IS_WIDGET (image));
63 /* If the button has a new image, show it */
64 gtk_widget_show (image);
65 /* Show the image no matter the value of gtk-button-images */
66 g_signal_connect (image, "notify::visible", G_CALLBACK (image_visible_changed_cb), NULL);
67 /* If the image is removed from the button, disconnect these handlers */
68 g_signal_connect (image, "notify::parent", G_CALLBACK (parent_changed_cb), image->parent);
73 button_common_init (GtkWidget *button,
76 /* Set requested size */
77 hildon_gtk_widget_set_theme_size (button, size);
79 /* Set focus-on-click to FALSE by default */
80 gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
82 /* Make sure that all images in this button are always shown */
83 g_signal_connect (button, "notify::image", G_CALLBACK (image_changed_cb), NULL);
87 * hildon_gtk_menu_new:
89 * This is a convenience function to create a #GtkMenu setting its
90 * widget name to allow Hildon specific styling.
92 * Return value: A newly created #GtkMenu widget.
97 hildon_gtk_menu_new (void)
99 GtkWidget *menu = gtk_menu_new ();
100 gtk_widget_set_name (menu, "hildon-context-sensitive-menu");
105 * hildon_gtk_button_new:
106 * @size: Flags indicating the size of the new button
108 * This is a convenience function to create a #GtkButton setting its
109 * size to one of the pre-defined Hildon sizes.
111 * Buttons created with this function also override the
112 * "gtk-button-images" setting. Images set using
113 * gtk_button_set_image() are always shown.
115 * Buttons created using this function have #GtkButton:focus-on-click
116 * set to %FALSE by default.
118 * Return value: A newly created #GtkButton widget.
123 hildon_gtk_button_new (HildonSizeType size)
125 GtkWidget *button = gtk_button_new ();
126 button_common_init (button, size);
131 * hildon_gtk_toggle_button_new:
132 * @size: Flags indicating the size of the new button
134 * This is a convenience function to create a #GtkToggleButton setting
135 * its size to one of the pre-defined Hildon sizes.
137 * Buttons created with this function also override the
138 * "gtk-button-images" setting. Images set using
139 * gtk_button_set_image() are always shown.
141 * Buttons created using this function have #GtkButton:focus-on-click
142 * set to %FALSE by default.
144 * Return value: A newly created #GtkToggleButton widget.
149 hildon_gtk_toggle_button_new (HildonSizeType size)
151 GtkWidget *button = gtk_toggle_button_new ();
152 button_common_init (button, size);
157 * hildon_gtk_radio_button_new:
158 * @size: Flags indicating the size of the new button
159 * @group: An existing radio button group, or %NULL if you are
160 * creating a new group
162 * This is a convenience function to create a #GtkRadioButton setting
163 * its size to one of the pre-defined Hildon sizes.
165 * Buttons created with this function also override the
166 * "gtk-button-images" setting. Images set using
167 * gtk_button_set_image() are always shown.
169 * Buttons created using this function have #GtkButton:focus-on-click
170 * set to %FALSE by default.
172 * Return value: A newly created #GtkRadioButton widget.
177 hildon_gtk_radio_button_new (HildonSizeType size,
180 GtkWidget *button = gtk_radio_button_new (group);
181 button_common_init (button, size);
186 * hildon_gtk_radio_button_new_from_widget:
187 * @size: Flags indicating the size of the new button
188 * @radio_group_member: widget to get radio group from or %NULL
190 * This is a convenience function to create a #GtkRadioButton setting
191 * its size to one of the pre-defined Hildon sizes.
193 * Buttons created with this function also override the
194 * "gtk-button-images" setting. Images set using
195 * gtk_button_set_image() are always shown.
197 * Buttons created using this function have #GtkButton:focus-on-click
198 * set to %FALSE by default.
200 * Return value: A newly created #GtkRadioButton widget.
205 hildon_gtk_radio_button_new_from_widget (HildonSizeType size,
206 GtkRadioButton *radio_group_member)
208 GtkWidget *button = gtk_radio_button_new_from_widget (radio_group_member);
209 button_common_init (button, size);
215 * hildon_gtk_tree_view_new:
216 * @mode: the Hildon UI mode
218 * Creates a new #GtkTreeView widget with the Hildon UI mode set to
221 * Return value: A newly created #GtkTreeView widget.
226 hildon_gtk_tree_view_new (HildonUIMode mode)
228 return g_object_new (GTK_TYPE_TREE_VIEW, "hildon-ui-mode", mode,
229 "enable-search", FALSE, NULL);
233 * hildon_gtk_tree_view_new_with_model:
234 * @mode: the Hildon UI mode
237 * Creates a new #GtkTreeView widget with the Hildon UI mode set to
238 * @mode and the model initialized to @model.
240 * Return value: A newly created #GtkTreeView widget.
245 hildon_gtk_tree_view_new_with_model (HildonUIMode mode,
248 return g_object_new (GTK_TYPE_TREE_VIEW, "hildon-ui-mode", mode, "model", model, NULL);
252 * hildon_gtk_tree_view_set_ui_mode:
253 * @treeview: A #GtkTreeView
254 * @mode: The new #HildonUIMode
256 * Sets the UI mode of @treeview to @mode.
261 hildon_gtk_tree_view_set_ui_mode (GtkTreeView *treeview,
264 g_return_if_fail (GTK_IS_TREE_VIEW (treeview));
265 g_object_set (treeview, "hildon-ui-mode", mode, NULL);
269 * hildon_gtk_icon_view_new:
270 * @mode: the Hildon UI mode
272 * Creates a new #GtkIconView widget with the Hildon UI mode set to
275 * Return value: A newly created #GtkIconView widget
280 hildon_gtk_icon_view_new (HildonUIMode mode)
282 return g_object_new (GTK_TYPE_ICON_VIEW, "hildon-ui-mode", mode, NULL);
286 * hildon_gtk_icon_view_new_with_model:
287 * @mode: the Hildon UI mode
290 * Creates a new #GtkIconView widget with the Hildon UI mode set to
291 * @mode and the model intitialized to @model.
293 * Return value: A newly created #GtkIconView widget.
298 hildon_gtk_icon_view_new_with_model (HildonUIMode mode,
301 return g_object_new (GTK_TYPE_ICON_VIEW, "hildon-ui-mode", mode, "model", model, NULL);
305 * hildon_gtk_icon_view_set_ui_mode:
306 * @iconview: A #GtkIconView
307 * @mode: The new #HildonUIMode
309 * Sets the UI mode of @iconview to @mode.
314 hildon_gtk_icon_view_set_ui_mode (GtkIconView *iconview,
317 g_return_if_fail (GTK_IS_ICON_VIEW (iconview));
318 g_object_set (iconview, "hildon-ui-mode", mode, NULL);
320 #endif /* MAEMO_GTK */
323 set_clear_window_flag (GtkWindow *window,
324 const gchar *atomname,
330 g_return_if_fail (GTK_IS_WINDOW (window));
331 g_return_if_fail (GTK_WIDGET_REALIZED (window));
333 gdkwin = GTK_WIDGET (window)->window;
334 atom = gdk_atom_intern (atomname, FALSE);
338 gdk_property_change (gdkwin, atom, gdk_x11_xatom_to_atom (XA_INTEGER),
339 32, GDK_PROP_MODE_REPLACE, (const guchar *) &set, 1);
341 gdk_property_delete (gdkwin, atom);
346 * hildon_gtk_window_set_progress_indicator:
347 * @window: a #GtkWindow.
348 * @state: The state we want to set: 1 -> show progress indicator, 0
349 * -> hide progress indicator.
351 * This functions tells the window manager to show/hide a progress
352 * indicator in the window title. It applies to #HildonDialog and
353 * #HildonWindow (including subclasses).
355 * Note that @window must be realized for this to work.
360 hildon_gtk_window_set_progress_indicator (GtkWindow *window,
363 set_clear_window_flag (window, "_HILDON_WM_WINDOW_PROGRESS_INDICATOR", state);
367 * hildon_gtk_hscale_new:
369 * Creates a new horizontal scale widget that lets the user select
370 * a value. The value is technically a double between 0.0 and 1.0.
371 * See gtk_adjustment_configure() for reconfiguring the adjustment.
373 * The scale is hildonized, which means that a click or tap immediately
374 * jumps to the desired position, see gtk_range_set_jump_to_position().
375 * Further more the value is not displayed, see gtk_scale_set_draw_value().
377 * Returns: a new hildonized #GtkHScale
382 hildon_gtk_hscale_new (void)
384 GtkWidget *scale = gtk_hscale_new_with_range (0.0, 1.0, 0.1);
388 "jump-to-position", TRUE,
396 * hildon_gtk_vscale_new:
398 * Creates a new vertical scale widget that lets the user select
399 * a value. The value is technically a double between 0.0 and 1.0.
400 * See gtk_adjustment_configure() for reconfiguring the adjustment.
402 * The scale is hildonized, which means that a click or tap immediately
403 * jumps to the desired position, see gtk_range_set_jump_to_position().
404 * Further more the value is not displayed, see gtk_scale_set_draw_value().
406 * Returns: a new hildonized #GtkVScale
411 hildon_gtk_vscale_new (void)
413 GtkWidget *scale = gtk_vscale_new_with_range (0.0, 1.0, 0.1);
417 "jump-to-position", TRUE,