2 * This file is a part of hildon
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * Contact: Karl Lattimer <karl.lattimer@nokia.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser Public License as published by
10 * the Free Software Foundation; version 2 of the license.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser Public License for more details.
20 * SECTION:hildon-toggle-button
21 * @short_description: Widget representing a toggle button in the Hildon framework.
23 * The #HildonToggleButton is a GTK widget which represents a toggle
24 * button. It is derived from the GtkToggleButton widget and provides
25 * additional commodities specific to the Hildon framework.
27 * The height of a #HildonToggleButton can be set to either "finger" height
28 * or "thumb" height. It can also be configured to use halfscreen or
29 * fullscreen width. Alternatively, either dimension can be set to
30 * "auto" so it behaves like a standard GtkToggleButton.
33 #include "hildon-toggle-button.h"
34 #include "hildon-enum-types.h"
36 #define FINGER_BUTTON_HEIGHT 70
37 #define THUMB_BUTTON_HEIGHT 105
38 #define HALFSCREEN_BUTTON_WIDTH 400
39 #define FULLSCREEN_BUTTON_WIDTH 800
41 G_DEFINE_TYPE (HildonToggleButton, hildon_toggle_button, GTK_TYPE_TOGGLE_BUTTON);
44 PROP_ARRANGEMENT_FLAGS
48 hildon_toggle_button_set_arrangement (HildonToggleButton *button,
49 HildonToggleButtonFlags flags);
52 hildon_toggle_button_set_property (GObject *object,
57 HildonToggleButton *button = HILDON_TOGGLE_BUTTON (object);
61 case PROP_ARRANGEMENT_FLAGS:
62 hildon_toggle_button_set_arrangement (button, g_value_get_flags (value));
65 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
71 hildon_toggle_button_class_init (HildonToggleButtonClass *klass)
73 GObjectClass *gobject_class = (GObjectClass *)klass;
75 gobject_class->set_property = hildon_toggle_button_set_property;
77 g_object_class_install_property (
79 PROP_ARRANGEMENT_FLAGS,
83 "How the button contents must be arranged",
84 HILDON_TYPE_TOGGLE_BUTTON_FLAGS,
85 HILDON_TOGGLE_BUTTON_AUTO_WIDTH | HILDON_TOGGLE_BUTTON_AUTO_HEIGHT,
86 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
90 hildon_toggle_button_init (HildonToggleButton *self)
95 * hildon_toggle_button_new:
96 * @flags: flags to set the size of the button
98 * Creates a new #HildonToggleButton. To add a child widget use gtk_container_add().
100 * Returns: a new #HildonToggleButton
103 hildon_toggle_button_new (HildonToggleButtonFlags flags)
107 button = g_object_new (HILDON_TYPE_TOGGLE_BUTTON,
108 "arrangement-flags", flags,
114 * hildon_toggle_button_new_with_label:
115 * @flags: flags to set the size of the button
116 * @label: a text to set in the button label
118 * Creates a new #HildonToggleButton with a text label.
120 * Returns: a new #HildonToggleButton
123 hildon_toggle_button_new_with_label (HildonToggleButtonFlags flags,
128 button = g_object_new (HILDON_TYPE_TOGGLE_BUTTON,
129 "arrangement-flags", flags,
136 hildon_toggle_button_set_arrangement (HildonToggleButton *button,
137 HildonToggleButtonFlags flags)
141 const char *widget_name = NULL;
143 /* Requested height */
144 if (flags & HILDON_TOGGLE_BUTTON_FINGER_HEIGHT) {
145 height = FINGER_BUTTON_HEIGHT;
146 widget_name = "hildon-finger-button";
147 } else if (flags & HILDON_TOGGLE_BUTTON_THUMB_HEIGHT) {
148 height = THUMB_BUTTON_HEIGHT;
149 widget_name = "hildon-thumb-button";
153 gtk_widget_set_name (GTK_WIDGET (button), widget_name);
156 /* Requested width */
157 if (flags & HILDON_TOGGLE_BUTTON_HALFSCREEN_WIDTH) {
158 width = HALFSCREEN_BUTTON_WIDTH;
159 } else if (flags & HILDON_TOGGLE_BUTTON_FULLSCREEN_WIDTH) {
160 width = FULLSCREEN_BUTTON_WIDTH;
163 g_object_set (button,
164 "width-request", width,
165 "height-request", height,