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
21 * Hildon provides some functions to extend the functionality of
22 * existing Gtk widgets. This also includes convenience functions to
23 * easily perform frequent tasks.
26 #include "hildon-gtk.h"
28 #define HILDON_HEIGHT_FINGER 70
30 #define HILDON_HEIGHT_THUMB 105
32 #define HILDON_WIDTH_FULLSCREEN \
33 (gdk_screen_get_width (gdk_screen_get_default ()))
35 #define HILDON_WIDTH_HALFSCREEN \
36 (HILDON_WIDTH_FULLSCREEN / 2)
39 * hildon_gtk_widget_set_theme_size
40 * @widget: A #GtkWidget
41 * @size: Flags indicating the size of the widget
43 * This function sets the requested size of a widget.
46 hildon_gtk_widget_set_theme_size (GtkWidget *widget,
51 const gchar *widget_name = NULL;
53 g_return_if_fail (GTK_IS_WIDGET (widget));
55 /* Requested height */
56 if (size & HILDON_SIZE_FINGER_HEIGHT) {
57 height = HILDON_HEIGHT_FINGER;
58 widget_name = "hildon-finger-widget";
59 } else if (size & HILDON_SIZE_THUMB_HEIGHT) {
60 height = HILDON_HEIGHT_THUMB;
61 widget_name = "hildon-thumb-widget";
65 if (size & HILDON_SIZE_HALFSCREEN_WIDTH) {
66 width = HILDON_WIDTH_HALFSCREEN;
67 } else if (size & HILDON_SIZE_FULLSCREEN_WIDTH) {
68 width = HILDON_WIDTH_FULLSCREEN;
71 gtk_widget_set_size_request (widget, width, height);
74 gtk_widget_set_name (widget, widget_name);
78 * hildon_gtk_button_new:
79 * @size: Flags indicating the size of the new button
81 * This is a convenience function to create a #GtkButton setting its
82 * size to one of the pre-defined Hildon sizes.
84 * Return value: A newly created #GtkButton widget.
87 hildon_gtk_button_new (HildonSizeType size)
89 GtkWidget *button = gtk_button_new ();
90 hildon_gtk_widget_set_theme_size (button, size);
95 * hildon_gtk_toggle_button_new:
96 * @size: Flags indicating the size of the new button
98 * This is a convenience function to create a #GtkToggleButton setting
99 * its size to one of the pre-defined Hildon sizes.
101 * Return value: A newly created #GtkToggleButton widget.
104 hildon_gtk_toggle_button_new (HildonSizeType size)
106 GtkWidget *button = gtk_toggle_button_new ();
107 hildon_gtk_widget_set_theme_size (button, size);
112 * hildon_gtk_check_button_new:
113 * @size: Flags indicating the size of the new button
115 * This is a convenience function to create a #GtkCheckButton setting
116 * its size to one of the pre-defined Hildon sizes.
118 * Return value: A newly created #GtkCheckButton widget.
121 hildon_gtk_check_button_new (HildonSizeType size)
123 GtkWidget *button = gtk_check_button_new ();
124 hildon_gtk_widget_set_theme_size (button, size);
129 * hildon_gtk_radio_button_new:
130 * @size: Flags indicating the size of the new button
131 * @group: An existing radio button group, or %NULL if you are
132 * creating a new group
134 * This is a convenience function to create a #GtkRadioButton setting
135 * its size to one of the pre-defined Hildon sizes.
137 * Return value: A newly created #GtkRadioButton widget.
140 hildon_gtk_radio_button_new (HildonSizeType size,
143 GtkWidget *button = gtk_radio_button_new (group);
144 hildon_gtk_widget_set_theme_size (button, size);
149 * hildon_gtk_radio_button_new_from_widget:
150 * @size: Flags indicating the size of the new button
151 * @radio_group_member: widget to get radio group from or %NULL
153 * This is a convenience function to create a #GtkRadioButton setting
154 * its size to one of the pre-defined Hildon sizes.
156 * Return value: A newly created #GtkRadioButton widget.
159 hildon_gtk_radio_button_new_from_widget (HildonSizeType size,
160 GtkRadioButton *radio_group_member)
162 GtkWidget *button = gtk_radio_button_new_from_widget (radio_group_member);
163 hildon_gtk_widget_set_theme_size (button, size);
168 * hildon_gtk_tree_view_new:
169 * @mode: the Hildon UI mode
171 * Creates a new #GtkTreeView widget with the Hildon UI mode set to
174 * Return value: A newly created #GtkTreeView widget.
177 hildon_gtk_tree_view_new (HildonUIMode mode)
179 return g_object_new (GTK_TYPE_TREE_VIEW, "hildon-ui-mode", mode, NULL);
183 * hildon_gtk_tree_view_new_with_model:
184 * @mode: the Hildon UI mode
187 * Creates a new #GtkTreeView widget with the Hildon UI mode set to
188 * @mode and the model initialized to @model.
190 * Return value: A newly created #GtkTreeView widget.
193 hildon_gtk_tree_view_new_with_model (HildonUIMode mode,
196 return g_object_new (GTK_TYPE_TREE_VIEW, "hildon-ui-mode", mode, "model", model, NULL);
200 * hildon_gtk_icon_view_new:
201 * @mode: the Hildon UI mode
203 * Creates a new #GtkIconView widget with the Hildon UI mode set to
206 * Return value: A newly created #GtkIconView widget
209 hildon_gtk_icon_view_new (HildonUIMode mode)
211 return g_object_new (GTK_TYPE_ICON_VIEW, "hildon-ui-mode", mode, NULL);
215 * hildon_gtk_icon_view_new_with_model:
216 * @mode: the Hildon UI mode
219 * Creates a new #GtkIconView widget with the Hildon UI mode set to
220 * @mode and the model intitialized to @model.
222 * Return value: A newly created #GtkIconView widget.
225 hildon_gtk_icon_view_new_with_model (HildonUIMode mode,
228 return g_object_new (GTK_TYPE_ICON_VIEW, "hildon-ui-mode", mode, "model", model, NULL);