1 /* GSequencer - Advanced GTK Sequencer
2  * Copyright (C) 2005-2019 Joël Krähemann
3  *
4  * This file is part of GSequencer.
5  *
6  * GSequencer is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSequencer is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSequencer.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <ags/widget/ags_scale_box.h>
21 #include <ags/widget/ags_scale.h>
22 
23 void ags_scale_box_class_init(AgsScaleBoxClass *scale_box);
24 void ags_scale_box_init(AgsScaleBox *scale_box);
25 void ags_scale_box_set_property(GObject *gobject,
26 				guint prop_id,
27 				const GValue *value,
28 				GParamSpec *param_spec);
29 void ags_scale_box_get_property(GObject *gobject,
30 				guint prop_id,
31 				GValue *value,
32 				GParamSpec *param_spec);
33 void ags_scale_box_finalize(GObject *gobject);
34 
35 GType ags_scale_box_child_type(GtkContainer *container);
36 
37 /**
38  * SECTION:ags_scale_box
39  * @short_description: abstract box widget
40  * @title: AgsScaleBox
41  * @section_id:
42  * @include: ags/widget/ags_scale_box.h
43  *
44  * The #AgsScaleBox is an abstract box widget containing #AgsScale.
45  */
46 
47 enum{
48   PROP_0,
49   PROP_FIXED_SCALE_WIDTH,
50   PROP_FIXED_SCALE_HEIGHT,
51 };
52 
53 static gpointer ags_scale_box_parent_class = NULL;
54 
55 GType
ags_scale_box_get_type(void)56 ags_scale_box_get_type(void)
57 {
58   static volatile gsize g_define_type_id__volatile = 0;
59 
60   if(g_once_init_enter (&g_define_type_id__volatile)){
61     GType ags_type_scale_box = 0;
62 
63     static const GTypeInfo ags_scale_box_info = {
64       sizeof (AgsScaleBoxClass),
65       NULL, /* base_init */
66       NULL, /* base_finalize */
67       (GClassInitFunc) ags_scale_box_class_init,
68       NULL, /* class_finalize */
69       NULL, /* class_data */
70       sizeof (AgsScaleBox),
71       0,    /* n_preallocs */
72       (GInstanceInitFunc) ags_scale_box_init,
73     };
74 
75     ags_type_scale_box = g_type_register_static(GTK_TYPE_BOX,
76 						"AgsScaleBox", &ags_scale_box_info,
77 						0);
78 
79     g_once_init_leave(&g_define_type_id__volatile, ags_type_scale_box);
80   }
81 
82   return g_define_type_id__volatile;
83 }
84 
85 void
ags_scale_box_class_init(AgsScaleBoxClass * scale_box)86 ags_scale_box_class_init(AgsScaleBoxClass *scale_box)
87 {
88   GObjectClass *gobject;
89   GtkWidgetClass *widget;
90   GtkContainerClass *container;
91 
92   GParamSpec *param_spec;
93 
94   ags_scale_box_parent_class = g_type_class_peek_parent(scale_box);
95 
96   /* GObjectClass */
97   gobject = (GObjectClass *) scale_box;
98 
99   gobject->set_property = ags_scale_box_set_property;
100   gobject->get_property = ags_scale_box_get_property;
101 
102   gobject->finalize = ags_scale_box_finalize;
103 
104   /* properties */
105   /**
106    * AgsScaleBox:fixed-scale-width:
107    *
108    * The fixed width of a scale.
109    *
110    * Since: 3.0.0
111    */
112   param_spec = g_param_spec_uint("fixed-scale-width",
113 				 "fixed scale width",
114 				 "The fixed width of a scale",
115 				 0,
116 				 G_MAXUINT,
117 				 AGS_SCALE_BOX_DEFAULT_FIXED_SCALE_WIDTH,
118 				 G_PARAM_READABLE | G_PARAM_WRITABLE);
119   g_object_class_install_property(gobject,
120 				  PROP_FIXED_SCALE_WIDTH,
121 				  param_spec);
122 
123   /**
124    * AgsScaleBox:fixed-scale-height:
125    *
126    * The fixed height of a scale.
127    *
128    * Since: 3.0.0
129    */
130   param_spec = g_param_spec_uint("fixed-scale-height",
131 				 "fixed scale height",
132 				 "The fixed height of a scale",
133 				 0,
134 				 G_MAXUINT,
135 				 AGS_SCALE_BOX_DEFAULT_FIXED_SCALE_HEIGHT,
136 				 G_PARAM_READABLE | G_PARAM_WRITABLE);
137   g_object_class_install_property(gobject,
138 				  PROP_FIXED_SCALE_HEIGHT,
139 				  param_spec);
140 
141   /* GtkWidgetClass */
142   widget = (GtkWidgetClass *) scale_box;
143 
144   /* GtkContainerClass */
145   container = (GtkWidgetClass *) scale_box;
146 
147   container->child_type = ags_scale_box_child_type;
148 }
149 
150 void
ags_scale_box_init(AgsScaleBox * scale_box)151 ags_scale_box_init(AgsScaleBox *scale_box)
152 {
153   g_object_set(scale_box,
154 	       "homogeneous", FALSE,
155 	       "spacing", 0,
156 	       NULL);
157 
158   scale_box->flags = 0;
159 
160   scale_box->fixed_scale_width = AGS_SCALE_BOX_DEFAULT_FIXED_SCALE_WIDTH;
161   scale_box->fixed_scale_height = AGS_SCALE_BOX_DEFAULT_FIXED_SCALE_HEIGHT;
162 }
163 
164 void
ags_scale_box_set_property(GObject * gobject,guint prop_id,const GValue * value,GParamSpec * param_spec)165 ags_scale_box_set_property(GObject *gobject,
166 			   guint prop_id,
167 			   const GValue *value,
168 			   GParamSpec *param_spec)
169 {
170   AgsScaleBox *scale_box;
171 
172   scale_box = AGS_SCALE_BOX(gobject);
173 
174   switch(prop_id){
175   case PROP_FIXED_SCALE_WIDTH:
176     {
177       scale_box->fixed_scale_width = g_value_get_uint(value);
178     }
179     break;
180   case PROP_FIXED_SCALE_HEIGHT:
181     {
182       scale_box->fixed_scale_height = g_value_get_uint(value);
183     }
184     break;
185   default:
186     G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
187     break;
188   }
189 }
190 
191 void
ags_scale_box_get_property(GObject * gobject,guint prop_id,GValue * value,GParamSpec * param_spec)192 ags_scale_box_get_property(GObject *gobject,
193 			   guint prop_id,
194 			   GValue *value,
195 			   GParamSpec *param_spec)
196 {
197   AgsScaleBox *scale_box;
198 
199   scale_box = AGS_SCALE_BOX(gobject);
200 
201   switch(prop_id){
202   case PROP_FIXED_SCALE_WIDTH:
203     {
204       g_value_set_uint(value,
205 		       scale_box->fixed_scale_width);
206     }
207     break;
208   case PROP_FIXED_SCALE_HEIGHT:
209     {
210       g_value_set_uint(value,
211 		       scale_box->fixed_scale_height);
212     }
213     break;
214   default:
215     G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
216     break;
217   }
218 }
219 
220 void
ags_scale_box_finalize(GObject * gobject)221 ags_scale_box_finalize(GObject *gobject)
222 {
223   /* call parent */
224   G_OBJECT_CLASS(ags_scale_box_parent_class)->finalize(gobject);
225 }
226 
227 GType
ags_scale_box_child_type(GtkContainer * container)228 ags_scale_box_child_type(GtkContainer *container)
229 {
230   return(AGS_TYPE_SCALE);
231 }
232 
233 /**
234  * ags_scale_box_new:
235  *
236  * Create a new instance of #AgsScaleBox.
237  *
238  * Returns: the new #AgsScaleBox instance
239  *
240  * Since: 3.0.0
241  */
242 AgsScaleBox*
ags_scale_box_new()243 ags_scale_box_new()
244 {
245   AgsScaleBox *scale_box;
246 
247   scale_box = (AgsScaleBox *) g_object_new(AGS_TYPE_SCALE_BOX,
248 					   NULL);
249 
250   return(scale_box);
251 }
252