Fix erroneous gtk-doc comment blocks.
[hildon] / hildon-widgets / hildon-vvolumebar.c
1 /*
2  * This file is part of hildon-libs
3  *
4  * Copyright (C) 2005 Nokia Corporation.
5  *
6  * Contact: Luc Pionchon <luc.pionchon@nokia.com>
7  *
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.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  *
23  */
24
25 /*
26  * @file hildon-vvolumebar.c
27  *
28  * This file contains the implementation of HildonVVolumebar.
29  * This widget is a subclass of HildonVolumebar and implements
30  * horizontal version of Volumebar.
31  */
32
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif
36
37 #include <gtk/gtk.h>
38 #include "hildon-vvolumebar.h"
39 #include "hildon-volumebar.h"
40 #include "hildon-volumebar-range.h"
41 #include "hildon-volumebar-private.h"
42
43 /* Volume bar */
44 #define DEFAULT_BAR_WIDTH               58
45 #define MINIMUM_BAR_HEIGHT             165
46 /* Toggle button */
47 #define DEFAULT_VERTICAL_TBUTTON_WIDTH  26
48 #define DEFAULT_VERTICAL_TBUTTON_HEIGHT 26
49 #define DEFAULT_ENDING_SIZE             20
50 /* Gap to leave for mute button */
51 #define HORIZONTAL_MUTE_GAP             16
52 #define VERTICAL_MUTE_GAP                6
53
54 static HildonVolumebarClass *parent_class;
55 static void vvolumebar_class_init(HildonVVolumebarClass * klass);
56 static void vvolumebar_init(HildonVVolumebar * vvolumebar);
57 static void hildon_vvolumebar_mute(GtkWidget * widget,
58                                    HildonVVolumebar * self);
59 static gboolean hildon_vvolumebar_expose(GtkWidget * widget,
60                                          GdkEventExpose * event);
61 static void hildon_vvolumebar_size_request(GtkWidget * widget,
62                                            GtkRequisition * requisition);
63 static void hildon_vvolumebar_size_allocate(GtkWidget * widget,
64                                             GtkAllocation * allocation);
65
66 GType hildon_vvolumebar_get_type(void)
67 {
68     static GType type = 0;
69
70     if (!type) {
71         static const GTypeInfo info = {
72             sizeof(HildonVVolumebarClass),
73             NULL,       /* base_init */
74             NULL,       /* base_finalize */
75             (GClassInitFunc) vvolumebar_class_init,     /* class_init */
76             NULL,       /* class_finalize */
77             NULL,       /* class_data */
78             sizeof(HildonVVolumebar),
79             0,
80             (GInstanceInitFunc) vvolumebar_init,
81         };
82         type =
83             g_type_register_static(HILDON_TYPE_VOLUMEBAR,
84                                    "HildonVVolumebar", &info, 0);
85     }
86     return type;
87 }
88
89 static void vvolumebar_class_init(HildonVVolumebarClass * klass)
90 {
91     GtkWidgetClass *volumebar_class = GTK_WIDGET_CLASS(klass);
92
93     parent_class = g_type_class_peek_parent(klass);
94
95     volumebar_class->size_request = hildon_vvolumebar_size_request;
96     volumebar_class->size_allocate = hildon_vvolumebar_size_allocate;
97     volumebar_class->expose_event = hildon_vvolumebar_expose;
98 }
99
100 static void vvolumebar_init(HildonVVolumebar * vvolumebar)
101 {
102     HildonVolumebar *v_ptr = HILDON_VOLUMEBAR(vvolumebar);
103     HildonVolumebarPrivate *priv;
104
105     priv = HILDON_VOLUMEBAR_GET_PRIVATE(vvolumebar);
106
107     priv->ownorientation = GTK_ORIENTATION_VERTICAL;
108     priv->orientation = GTK_ORIENTATION_VERTICAL;
109
110     priv->volumebar =
111         HILDON_VOLUMEBAR_RANGE(hildon_volumebar_range_new
112                                (GTK_ORIENTATION_VERTICAL));
113
114     GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(vvolumebar), GTK_CAN_FOCUS);
115
116     gtk_widget_set_parent(GTK_WIDGET(priv->tbutton), GTK_WIDGET(v_ptr));
117     gtk_widget_set_parent(GTK_WIDGET(priv->volumebar), GTK_WIDGET(v_ptr));
118
119     gtk_scale_set_draw_value(GTK_SCALE(priv->volumebar), FALSE);
120
121     /* Signals */
122     g_signal_connect_swapped(G_OBJECT(priv->volumebar), "value-changed",
123                              G_CALLBACK(hildon_volumebar_level_change),
124                              vvolumebar);
125     g_signal_connect(G_OBJECT(priv->tbutton), "toggled",
126                      G_CALLBACK(hildon_vvolumebar_mute), vvolumebar);
127
128     gtk_widget_show(GTK_WIDGET(priv->volumebar));
129 }
130
131 /**
132  * hildon_vvolumebar_new:
133  *
134  * Creates a new #HildonVVolumebar widget.
135  *
136  * Returns: a new #HildonVVolumebar.
137  */
138 GtkWidget *hildon_vvolumebar_new()
139 {
140     return GTK_WIDGET(g_object_new(HILDON_TYPE_VVOLUMEBAR, NULL));
141 }
142
143 static gboolean hildon_vvolumebar_expose(GtkWidget * widget,
144                                          GdkEventExpose * event)
145 {
146     HildonVolumebarPrivate *priv;
147     priv = HILDON_VOLUMEBAR_GET_PRIVATE(HILDON_VOLUMEBAR(widget));
148     
149     if (GTK_WIDGET_DRAWABLE(widget)) {
150         /* Paint background */
151         gtk_paint_box(widget->style, widget->window,
152                       GTK_WIDGET_STATE(priv->volumebar), GTK_SHADOW_OUT,
153                       NULL, widget, "background",
154                       widget->allocation.x,
155                       widget->allocation.y,
156                       widget->allocation.width,
157                       widget->allocation.height);
158
159         /* The contents of the widget can paint themselves */
160         (*GTK_WIDGET_CLASS(parent_class)->expose_event) (widget, event);
161     }
162
163     return FALSE;
164 }
165
166 static void
167 hildon_vvolumebar_size_request(GtkWidget * widget,
168                                GtkRequisition * requisition)
169 {
170     requisition->height = MINIMUM_BAR_HEIGHT;
171     requisition->width = DEFAULT_BAR_WIDTH;
172 }
173
174 static void
175 hildon_vvolumebar_size_allocate(GtkWidget * widget,
176                                 GtkAllocation * allocation)
177 {
178     HildonVolumebar *vbar;
179     HildonVolumebarPrivate *priv;
180
181     GtkAllocation range_allocation, button_allocation;
182
183     vbar = HILDON_VOLUMEBAR(widget);
184     priv = HILDON_VOLUMEBAR_GET_PRIVATE(vbar);
185
186     /* Center the widget horizontally */
187     if (allocation->width > DEFAULT_BAR_WIDTH) {
188         allocation->x +=
189           (allocation->width - DEFAULT_BAR_WIDTH) / 2;
190         allocation->width = DEFAULT_BAR_WIDTH;
191     }
192
193     widget->allocation = *allocation;
194
195     if (priv->volumebar && GTK_WIDGET_VISIBLE(priv->volumebar)) {
196         /* Allocate space for the slider */
197         range_allocation.x = allocation->x;
198         range_allocation.y = allocation->y + DEFAULT_ENDING_SIZE;
199
200         range_allocation.width = DEFAULT_BAR_WIDTH;
201         
202         if (priv->tbutton && GTK_WIDGET_VISIBLE(priv->tbutton))
203         {
204             /* Leave room for the mute button */
205             range_allocation.height = MAX(0,
206                                           allocation->height
207                                           - 2 * DEFAULT_ENDING_SIZE
208                                           - DEFAULT_VERTICAL_TBUTTON_HEIGHT
209                                           - VERTICAL_MUTE_GAP);
210         }
211         
212         else
213         {
214             range_allocation.height = MAX(0,
215                                           allocation->height
216                                           - 2 * DEFAULT_ENDING_SIZE);
217         }
218         
219         gtk_widget_size_allocate(GTK_WIDGET(priv->volumebar),
220                                  &range_allocation);
221     }
222     
223     if (priv->tbutton && GTK_WIDGET_VISIBLE(priv->tbutton)) {
224         /* Allocate space for the mute button */
225         button_allocation.x = allocation->x + HORIZONTAL_MUTE_GAP;
226         button_allocation.y = allocation->y + allocation->height -
227                               VERTICAL_MUTE_GAP - 2 * DEFAULT_ENDING_SIZE;
228         button_allocation.width = DEFAULT_VERTICAL_TBUTTON_WIDTH;
229         button_allocation.height = DEFAULT_VERTICAL_TBUTTON_HEIGHT;
230         gtk_widget_size_allocate(GTK_WIDGET(priv->tbutton),
231                                  &button_allocation);
232     }
233 }
234
235 static void
236 hildon_vvolumebar_mute(GtkWidget * widget, HildonVVolumebar * self)
237 {
238     g_signal_emit_by_name(GTK_WIDGET(self), "mute_toggled");
239 }