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 * @file hildon-vvolumebar.c
28 * This file contains the implementation of HildonVVolumebar.
29 * This widget is a subclass of HildonVolumebar and implements
30 * horizontal version of Volumebar.
38 #include "hildon-vvolumebar.h"
39 #include "hildon-volumebar.h"
40 #include "hildon-volumebar-range.h"
41 #include "hildon-volumebar-private.h"
43 #define DEFAULT_BAR_WIDTH 58
44 #define MINIMUM_BAR_HEIGHT 165
45 #define DEFAULT_VERTICAL_TBUTTON_WIDTH 26
46 #define DEFAULT_VERTICAL_TBUTTON_HEIGHT 26
47 #define DEFAULT_ENDING_SIZE 20
48 #define HORIZONTAL_MUTE_GAP 16
49 #define VERTICAL_MUTE_GAP 6
51 static HildonVolumebarClass *parent_class;
52 static void vvolumebar_class_init(HildonVVolumebarClass * klass);
53 static void vvolumebar_init(HildonVVolumebar * vvolumebar);
54 static void hildon_vvolumebar_mute(GtkWidget * widget,
55 HildonVVolumebar * self);
56 static gboolean hildon_vvolumebar_expose(GtkWidget * widget,
57 GdkEventExpose * event);
58 static void hildon_vvolumebar_size_request(GtkWidget * widget,
59 GtkRequisition * requisition);
60 static void hildon_vvolumebar_size_allocate(GtkWidget * widget,
61 GtkAllocation * allocation);
63 GType hildon_vvolumebar_get_type(void)
65 static GType type = 0;
68 static const GTypeInfo info = {
69 sizeof(HildonVVolumebarClass),
71 NULL, /* base_finalize */
72 (GClassInitFunc) vvolumebar_class_init, /* class_init */
73 NULL, /* class_finalize */
74 NULL, /* class_data */
75 sizeof(HildonVVolumebar),
77 (GInstanceInitFunc) vvolumebar_init,
80 g_type_register_static(HILDON_TYPE_VOLUMEBAR,
81 "HildonVVolumebar", &info, 0);
86 static void vvolumebar_class_init(HildonVVolumebarClass * klass)
88 GtkWidgetClass *volumebar_class = GTK_WIDGET_CLASS(klass);
90 parent_class = g_type_class_peek_parent(klass);
92 volumebar_class->size_request = hildon_vvolumebar_size_request;
93 volumebar_class->size_allocate = hildon_vvolumebar_size_allocate;
94 volumebar_class->expose_event = hildon_vvolumebar_expose;
97 static void vvolumebar_init(HildonVVolumebar * vvolumebar)
99 HildonVolumebar *v_ptr = HILDON_VOLUMEBAR(vvolumebar);
100 HildonVolumebarPrivate *priv;
102 priv = HILDON_VOLUMEBAR_GET_PRIVATE(vvolumebar);
104 priv->ownorientation = GTK_ORIENTATION_VERTICAL;
105 priv->orientation = GTK_ORIENTATION_VERTICAL;
108 HILDON_VOLUMEBAR_RANGE(hildon_volumebar_range_new
109 (GTK_ORIENTATION_VERTICAL));
111 GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(vvolumebar), GTK_CAN_FOCUS);
113 gtk_widget_set_parent(GTK_WIDGET(priv->tbutton), GTK_WIDGET(v_ptr));
114 gtk_widget_set_parent(GTK_WIDGET(priv->volumebar), GTK_WIDGET(v_ptr));
116 gtk_scale_set_draw_value(GTK_SCALE(priv->volumebar), FALSE);
119 g_signal_connect_swapped(G_OBJECT(priv->volumebar), "value-changed",
120 G_CALLBACK(hildon_volumebar_level_change),
122 g_signal_connect(G_OBJECT(priv->tbutton), "toggled",
123 G_CALLBACK(hildon_vvolumebar_mute), vvolumebar);
126 gtk_widget_show(GTK_WIDGET(priv->volumebar));
130 * hildon_vvolumebar_new:
132 * Creates a new #HildonVVolumebar widget.
134 * Returns: a new #HildonVVolumebar.
136 GtkWidget *hildon_vvolumebar_new()
138 return GTK_WIDGET(g_object_new(HILDON_TYPE_VVOLUMEBAR, NULL));
141 static gboolean hildon_vvolumebar_expose(GtkWidget * widget,
142 GdkEventExpose * event)
144 if (GTK_WIDGET_DRAWABLE(widget)) {
145 gtk_paint_box(widget->style, widget->window,
146 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
147 NULL, widget, "background",
148 widget->allocation.x,
149 widget->allocation.y,
150 widget->allocation.width,
151 widget->allocation.height);
153 (*GTK_WIDGET_CLASS(parent_class)->expose_event) (widget, event);
160 hildon_vvolumebar_size_request(GtkWidget * widget,
161 GtkRequisition * requisition)
163 requisition->height = MINIMUM_BAR_HEIGHT;
164 requisition->width = DEFAULT_BAR_WIDTH;
168 hildon_vvolumebar_size_allocate(GtkWidget * widget,
169 GtkAllocation * allocation)
171 HildonVolumebar *vbar;
172 HildonVolumebarPrivate *priv;
174 GtkAllocation range_allocation, button_allocation;
176 vbar = HILDON_VOLUMEBAR(widget);
177 priv = HILDON_VOLUMEBAR_GET_PRIVATE(vbar);
179 if (allocation->width > DEFAULT_BAR_WIDTH) {
181 (allocation->width - DEFAULT_BAR_WIDTH) / 2;
182 allocation->width = DEFAULT_BAR_WIDTH;
185 widget->allocation = *allocation;
187 if (priv->volumebar && GTK_WIDGET_VISIBLE(priv->volumebar)) {
188 range_allocation.x = allocation->x;
189 range_allocation.y = allocation->y + DEFAULT_ENDING_SIZE;
191 range_allocation.width = DEFAULT_BAR_WIDTH;
193 if (priv->tbutton && GTK_WIDGET_VISIBLE(priv->tbutton))
195 range_allocation.height = MAX(0,
197 - 2 * DEFAULT_ENDING_SIZE
198 - DEFAULT_VERTICAL_TBUTTON_HEIGHT
199 - VERTICAL_MUTE_GAP);
204 range_allocation.height = MAX(0,
206 - 2 * DEFAULT_ENDING_SIZE);
209 gtk_widget_size_allocate(GTK_WIDGET(priv->volumebar),
213 if (priv->tbutton && GTK_WIDGET_VISIBLE(priv->tbutton)) {
214 button_allocation.x = allocation->x + HORIZONTAL_MUTE_GAP;
215 button_allocation.y = allocation->y + allocation->height -
216 VERTICAL_MUTE_GAP - 2 * DEFAULT_ENDING_SIZE;
217 button_allocation.width = DEFAULT_VERTICAL_TBUTTON_WIDTH;
218 button_allocation.height = DEFAULT_VERTICAL_TBUTTON_HEIGHT;
219 gtk_widget_size_allocate(GTK_WIDGET(priv->tbutton),
225 hildon_vvolumebar_mute(GtkWidget * widget, HildonVVolumebar * self)
227 g_signal_emit_by_name(GTK_WIDGET(self), "mute_toggled");