1 /* GSequencer - Advanced GTK Sequencer
2 * Copyright (C) 2005-2020 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/X/editor/ags_scrolled_automation_edit_box.h>
21
22 #include <ags/X/ags_ui_provider.h>
23
24 void ags_scrolled_automation_edit_box_class_init(AgsScrolledAutomationEditBoxClass *scrolled_automation_edit_box);
25 void ags_scrolled_automation_edit_box_init(AgsScrolledAutomationEditBox *scrolled_automation_edit_box);
26 void ags_scrolled_automation_edit_box_set_property(GObject *gobject,
27 guint prop_id,
28 const GValue *value,
29 GParamSpec *param_spec);
30 void ags_scrolled_automation_edit_box_get_property(GObject *gobject,
31 guint prop_id,
32 GValue *value,
33 GParamSpec *param_spec);
34 void ags_scrolled_automation_edit_box_finalize(GObject *gobject);
35
36 void ags_scrolled_automation_edit_box_size_allocate(GtkWidget *widget,
37 GtkAllocation *allocation);
38 void ags_scrolled_automation_edit_box_get_preferred_width(GtkWidget *widget,
39 gint *minimum_width,
40 gint *natural_width);
41 void ags_scrolled_automation_edit_box_get_preferred_height(GtkWidget *widget,
42 gint *minimum_height,
43 gint *natural_height);
44
45 /**
46 * SECTION:ags_scrolled_automation_edit_box
47 * @short_description: scrolled automation_edit box widget
48 * @title: AgsScrolledAutomationEditBox
49 * @section_id:
50 * @include: ags/widget/ags_scrolled_automation_edit_box.h
51 *
52 * The #AgsScrolledAutomationEditBox lets you to have a scrolled automation_edit box widget.
53 */
54
55 enum{
56 PROP_0,
57 PROP_MARGIN_TOP,
58 PROP_MARGIN_BOTTOM,
59 PROP_MARGIN_LEFT,
60 PROP_MARGIN_RIGHT,
61 };
62
63 static gpointer ags_scrolled_automation_edit_box_parent_class = NULL;
64
65 GType
ags_scrolled_automation_edit_box_get_type(void)66 ags_scrolled_automation_edit_box_get_type(void)
67 {
68 static volatile gsize g_define_type_id__volatile = 0;
69
70 if(g_once_init_enter (&g_define_type_id__volatile)){
71 GType ags_type_scrolled_automation_edit_box = 0;
72
73 static const GTypeInfo ags_scrolled_automation_edit_box_info = {
74 sizeof (AgsScrolledAutomationEditBoxClass),
75 NULL, /* base_init */
76 NULL, /* base_finalize */
77 (GClassInitFunc) ags_scrolled_automation_edit_box_class_init,
78 NULL, /* class_finalize */
79 NULL, /* class_data */
80 sizeof (AgsScrolledAutomationEditBox),
81 0, /* n_preallocs */
82 (GInstanceInitFunc) ags_scrolled_automation_edit_box_init,
83 };
84
85 ags_type_scrolled_automation_edit_box = g_type_register_static(GTK_TYPE_BIN,
86 "AgsScrolledAutomationEditBox", &ags_scrolled_automation_edit_box_info,
87 0);
88
89 g_once_init_leave(&g_define_type_id__volatile, ags_type_scrolled_automation_edit_box);
90 }
91
92 return g_define_type_id__volatile;
93 }
94
95 void
ags_scrolled_automation_edit_box_class_init(AgsScrolledAutomationEditBoxClass * scrolled_automation_edit_box)96 ags_scrolled_automation_edit_box_class_init(AgsScrolledAutomationEditBoxClass *scrolled_automation_edit_box)
97 {
98 GObjectClass *gobject;
99 GtkWidgetClass *widget;
100
101 GParamSpec *param_spec;
102
103 ags_scrolled_automation_edit_box_parent_class = g_type_class_peek_parent(scrolled_automation_edit_box);
104
105 /* GObjectClass */
106 gobject = (GObjectClass *) scrolled_automation_edit_box;
107
108 gobject->set_property = ags_scrolled_automation_edit_box_set_property;
109 gobject->get_property = ags_scrolled_automation_edit_box_get_property;
110
111 gobject->finalize = ags_scrolled_automation_edit_box_finalize;
112
113 /* properties */
114 /**
115 * AgsScrolledAutomationEditBox:margin-top:
116 *
117 * The margin top.
118 *
119 * Since: 3.0.0
120 */
121 param_spec = g_param_spec_uint("margin-top",
122 "margin top",
123 "The margin top",
124 0,
125 G_MAXUINT32,
126 0,
127 G_PARAM_READABLE | G_PARAM_WRITABLE);
128 g_object_class_install_property(gobject,
129 PROP_MARGIN_TOP,
130 param_spec);
131
132 /**
133 * AgsScrolledAutomationEditBox:margin-bottom:
134 *
135 * The margin bottom.
136 *
137 * Since: 3.0.0
138 */
139 param_spec = g_param_spec_uint("margin-bottom",
140 "margin bottom",
141 "The margin bottom",
142 0,
143 G_MAXUINT32,
144 0,
145 G_PARAM_READABLE | G_PARAM_WRITABLE);
146 g_object_class_install_property(gobject,
147 PROP_MARGIN_BOTTOM,
148 param_spec);
149
150 /**
151 * AgsScrolledAutomationEditBox:margin-left:
152 *
153 * The margin left.
154 *
155 * Since: 3.0.0
156 */
157 param_spec = g_param_spec_uint("margin-left",
158 "margin left",
159 "The margin left",
160 0,
161 G_MAXUINT32,
162 0,
163 G_PARAM_READABLE | G_PARAM_WRITABLE);
164 g_object_class_install_property(gobject,
165 PROP_MARGIN_LEFT,
166 param_spec);
167
168 /**
169 * AgsScrolledAutomationEditBox:margin-right:
170 *
171 * The margin right.
172 *
173 * Since: 3.0.0
174 */
175 param_spec = g_param_spec_uint("margin-right",
176 "margin right",
177 "The margin right",
178 0,
179 G_MAXUINT32,
180 0,
181 G_PARAM_READABLE | G_PARAM_WRITABLE);
182 g_object_class_install_property(gobject,
183 PROP_MARGIN_RIGHT,
184 param_spec);
185
186 /* GtkWidgetClass */
187 widget = (GtkWidgetClass *) scrolled_automation_edit_box;
188
189 // widget->size_allocate = ags_scrolled_automation_edit_box_size_allocate;
190 // widget->get_preferred_width = ags_scrolled_automation_edit_box_get_preferred_width;
191 // widget->get_preferred_height = ags_scrolled_automation_edit_box_get_preferred_height;
192 }
193
194 void
ags_scrolled_automation_edit_box_init(AgsScrolledAutomationEditBox * scrolled_automation_edit_box)195 ags_scrolled_automation_edit_box_init(AgsScrolledAutomationEditBox *scrolled_automation_edit_box)
196 {
197 scrolled_automation_edit_box->margin_top = 0;
198 scrolled_automation_edit_box->margin_bottom = 0;
199 scrolled_automation_edit_box->margin_left = 0;
200 scrolled_automation_edit_box->margin_right = 0;
201
202 /* viewport */
203 scrolled_automation_edit_box->viewport = (GtkViewport *) gtk_viewport_new(NULL,
204 NULL);
205 g_object_set(scrolled_automation_edit_box->viewport,
206 "shadow-type", GTK_SHADOW_NONE,
207 NULL);
208 gtk_widget_set_vexpand(scrolled_automation_edit_box->viewport, TRUE);
209 gtk_widget_set_hexpand(scrolled_automation_edit_box->viewport, TRUE);
210 gtk_container_add((GtkContainer *) scrolled_automation_edit_box,
211 (GtkWidget *) scrolled_automation_edit_box->viewport);
212
213 /* automation_edit box */
214 scrolled_automation_edit_box->automation_edit_box = NULL;
215
216 #if 0
217 scrolled_automation_edit_box->automation_edit_box = ags_vautomation_edit_box_new();
218 gtk_container_add(scrolled_automation_edit_box->viewport,
219 scrolled_automation_edit_box->automation_edit_box);
220 #endif
221 }
222
223 void
ags_scrolled_automation_edit_box_set_property(GObject * gobject,guint prop_id,const GValue * value,GParamSpec * param_spec)224 ags_scrolled_automation_edit_box_set_property(GObject *gobject,
225 guint prop_id,
226 const GValue *value,
227 GParamSpec *param_spec)
228 {
229 AgsScrolledAutomationEditBox *scrolled_automation_edit_box;
230
231 scrolled_automation_edit_box = AGS_SCROLLED_AUTOMATION_EDIT_BOX(gobject);
232
233 switch(prop_id){
234 case PROP_MARGIN_TOP:
235 {
236 scrolled_automation_edit_box->margin_top = g_value_get_uint(value);
237 }
238 break;
239 case PROP_MARGIN_BOTTOM:
240 {
241 scrolled_automation_edit_box->margin_bottom = g_value_get_uint(value);
242 }
243 break;
244 case PROP_MARGIN_LEFT:
245 {
246 scrolled_automation_edit_box->margin_left = g_value_get_uint(value);
247 }
248 break;
249 case PROP_MARGIN_RIGHT:
250 {
251 scrolled_automation_edit_box->margin_right = g_value_get_uint(value);
252 }
253 break;
254 default:
255 G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
256 break;
257 }
258 }
259
260 void
ags_scrolled_automation_edit_box_get_property(GObject * gobject,guint prop_id,GValue * value,GParamSpec * param_spec)261 ags_scrolled_automation_edit_box_get_property(GObject *gobject,
262 guint prop_id,
263 GValue *value,
264 GParamSpec *param_spec)
265 {
266 AgsScrolledAutomationEditBox *scrolled_automation_edit_box;
267
268 scrolled_automation_edit_box = AGS_SCROLLED_AUTOMATION_EDIT_BOX(gobject);
269
270 switch(prop_id){
271 case PROP_MARGIN_TOP:
272 {
273 g_value_set_uint(value,
274 scrolled_automation_edit_box->margin_top);
275 }
276 break;
277 case PROP_MARGIN_BOTTOM:
278 {
279 g_value_set_uint(value,
280 scrolled_automation_edit_box->margin_bottom);
281 }
282 break;
283 case PROP_MARGIN_LEFT:
284 {
285 g_value_set_uint(value,
286 scrolled_automation_edit_box->margin_left);
287 }
288 break;
289 case PROP_MARGIN_RIGHT:
290 {
291 g_value_set_uint(value,
292 scrolled_automation_edit_box->margin_right);
293 }
294 break;
295 default:
296 G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
297 break;
298 }
299 }
300
301 void
ags_scrolled_automation_edit_box_finalize(GObject * gobject)302 ags_scrolled_automation_edit_box_finalize(GObject *gobject)
303 {
304 /* call parent */
305 G_OBJECT_CLASS(ags_scrolled_automation_edit_box_parent_class)->finalize(gobject);
306 }
307
308 void
ags_scrolled_automation_edit_box_size_allocate(GtkWidget * widget,GtkAllocation * allocation)309 ags_scrolled_automation_edit_box_size_allocate(GtkWidget *widget,
310 GtkAllocation *allocation)
311 {
312 AgsScrolledAutomationEditBox *scrolled_automation_edit_box;
313
314 AgsApplicationContext *application_context;
315
316 GtkAllocation child_allocation;
317 GtkRequisition child_requisition;
318
319 gdouble gui_scale_factor;
320
321 scrolled_automation_edit_box = AGS_SCROLLED_AUTOMATION_EDIT_BOX(widget);
322
323 application_context = ags_application_context_get_instance();
324
325 GTK_WIDGET_CLASS(ags_scrolled_automation_edit_box_parent_class)->size_allocate(widget,
326 allocation);
327
328 /* scale factor */
329 gui_scale_factor = ags_ui_provider_get_gui_scale_factor(AGS_UI_PROVIDER(application_context));
330
331 allocation->height = (gint) (gui_scale_factor * AGS_SCALE_DEFAULT_SCALE_HEIGHT);
332
333 /* viewport allocation */
334 gtk_widget_get_child_requisition((GtkWidget *) scrolled_automation_edit_box->viewport,
335 &child_requisition);
336
337 child_allocation.x = allocation->x;
338 child_allocation.y = allocation->y;
339
340 child_allocation.width = allocation->width;
341 child_allocation.height = allocation->height;
342
343 gtk_widget_size_allocate((GtkWidget *) scrolled_automation_edit_box->viewport,
344 &child_allocation);
345
346 /* box */
347 gtk_widget_get_child_requisition((GtkWidget *) scrolled_automation_edit_box->automation_edit_box,
348 &child_requisition);
349
350 child_allocation.x = 0;
351 child_allocation.y = 0;
352
353 child_allocation.width = allocation->width;
354 child_allocation.height = child_requisition.height;
355
356 gtk_widget_size_allocate((GtkWidget *) scrolled_automation_edit_box->automation_edit_box,
357 &child_allocation);
358 }
359
360 void
ags_scrolled_automation_edit_box_get_preferred_width(GtkWidget * widget,gint * minimal_width,gint * natural_width)361 ags_scrolled_automation_edit_box_get_preferred_width(GtkWidget *widget,
362 gint *minimal_width,
363 gint *natural_width)
364 {
365 minimal_width =
366 natural_width = NULL;
367 }
368
369 void
ags_scrolled_automation_edit_box_get_preferred_height(GtkWidget * widget,gint * minimal_height,gint * natural_height)370 ags_scrolled_automation_edit_box_get_preferred_height(GtkWidget *widget,
371 gint *minimal_height,
372 gint *natural_height)
373 {
374 minimal_height =
375 natural_height = NULL;
376 }
377
378 /**
379 * ags_scrolled_automation_edit_box_new:
380 *
381 * Create a new #AgsScrolledAutomationEditBox.
382 *
383 * Returns: a new #AgsScrolledAutomationEditBox
384 *
385 * Since: 3.0.0
386 */
387 AgsScrolledAutomationEditBox*
ags_scrolled_automation_edit_box_new()388 ags_scrolled_automation_edit_box_new()
389 {
390 AgsScrolledAutomationEditBox *scrolled_automation_edit_box;
391
392 scrolled_automation_edit_box = (AgsScrolledAutomationEditBox *) g_object_new(AGS_TYPE_SCROLLED_AUTOMATION_EDIT_BOX,
393 NULL);
394
395 return(scrolled_automation_edit_box);
396 }
397