1 /* Libvisual - The audio visualisation framework.
2 *
3 * Copyright (C) 2004, 2005, 2006 Dennis Smit <ds@nerds-incorporated.org>
4 *
5 * Authors: Dennis Smit <ds@nerds-incorporated.org>
6 *
7 * $Id: lv_ui.c,v 1.59 2006/01/22 13:23:37 synap Exp $
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <errno.h>
28 #include <string.h>
29
30 #include "lv_log.h"
31 #include "lv_ui.h"
32
33 static int box_dtor (VisObject *object);
34 static int table_dtor (VisObject *object);
35 static int table_entry_dtor (VisObject *object);
36 static int frame_dtor (VisObject *object);
37 static int choice_dtor (VisObject *object);
38 static int widget_dtor (VisObject *object);
39
box_dtor(VisObject * object)40 static int box_dtor (VisObject *object)
41 {
42 VisUIBox *box = VISUAL_UI_BOX (object);
43
44 visual_collection_destroy (VISUAL_COLLECTION (&box->childs));
45
46 widget_dtor (object);
47
48 return VISUAL_OK;
49 }
50
table_dtor(VisObject * object)51 static int table_dtor (VisObject *object)
52 {
53 VisUITable *table = VISUAL_UI_TABLE (object);
54
55 visual_collection_destroy (VISUAL_COLLECTION (&table->childs));
56
57 widget_dtor (object);
58
59 return VISUAL_OK;
60 }
61
table_entry_dtor(VisObject * object)62 static int table_entry_dtor (VisObject *object)
63 {
64 VisUITableEntry *tentry = VISUAL_UI_TABLE_ENTRY (object);
65
66 if (tentry->widget != NULL)
67 visual_object_unref (VISUAL_OBJECT (tentry->widget));
68
69 tentry->widget = NULL;
70
71 return VISUAL_OK;
72 }
73
notebook_dtor(VisObject * object)74 static int notebook_dtor (VisObject *object)
75 {
76 VisUINotebook *notebook = VISUAL_UI_NOTEBOOK (object);
77
78 visual_collection_destroy (VISUAL_COLLECTION (¬ebook->labels));
79 visual_collection_destroy (VISUAL_COLLECTION (¬ebook->childs));
80
81 widget_dtor (object);
82
83 return VISUAL_OK;
84 }
85
frame_dtor(VisObject * object)86 static int frame_dtor (VisObject *object)
87 {
88 VisUIContainer *container = VISUAL_UI_CONTAINER (object);
89
90 if (container->child != NULL)
91 visual_object_unref (VISUAL_OBJECT (container->child));
92
93 container->child = NULL;
94
95 widget_dtor (object);
96
97 return VISUAL_OK;
98 }
99
100
choice_dtor(VisObject * object)101 static int choice_dtor (VisObject *object)
102 {
103 visual_ui_choice_free_choices (VISUAL_UI_CHOICE (object));
104
105 widget_dtor (object);
106
107 return VISUAL_OK;
108 }
109
widget_dtor(VisObject * object)110 static int widget_dtor (VisObject *object)
111 {
112 VisUIWidget *widget = VISUAL_UI_WIDGET (object);
113
114 if (widget->tooltip != NULL)
115 visual_mem_free ((char *) widget->tooltip);
116
117 widget->tooltip = NULL;
118
119 return VISUAL_OK;
120 }
121
122 /**
123 * @defgroup VisUI VisUI
124 * @{
125 */
126
127 /**
128 * Creates a new VisUIWidget structure.
129 *
130 * @return A newly allocated VisUIWidget, or NULL on failure.
131 */
visual_ui_widget_new()132 VisUIWidget *visual_ui_widget_new ()
133 {
134 VisUIWidget *widget;
135
136 widget = visual_mem_new0 (VisUIWidget, 1);
137 widget->type = VISUAL_WIDGET_TYPE_NULL;
138
139 /* Do the VisObject initialization */
140 visual_object_initialize (VISUAL_OBJECT (widget), TRUE, widget_dtor);
141
142 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (widget), -1, -1);
143
144 return widget;
145 }
146
147 /**
148 * Sets a request for size to a VisUIWidget, to be used to request a certain dimension.
149 *
150 * @param widget Pointer to the VisUIWidget to which the size request is set.
151 * @param width The width in pixels of the size requested.
152 * @param height The height in pixels of the size requested.
153 *
154 * @return VISUAL_OK on succes, or -VISUAL_ERROR_UI_WIDGET_NULL on failure.
155 */
visual_ui_widget_set_size_request(VisUIWidget * widget,int width,int height)156 int visual_ui_widget_set_size_request (VisUIWidget *widget, int width, int height)
157 {
158 visual_log_return_val_if_fail (widget != NULL, -VISUAL_ERROR_UI_WIDGET_NULL);
159
160 widget->width = width;
161 widget->height = height;
162
163 return VISUAL_OK;
164 }
165
166 /**
167 * Sets a tooltip to a VisUIWidget.
168 *
169 * @param widget Pointer to the VisUIWidget to which the tooltip is set.
170 * @param tooltip A string containing the tooltip text.
171 *
172 * @return VISUAL_OK on succes, or -VISUAL_ERROR_UI_WIDGET_NULL on failure.
173 */
visual_ui_widget_set_tooltip(VisUIWidget * widget,const char * tooltip)174 int visual_ui_widget_set_tooltip (VisUIWidget *widget, const char *tooltip)
175 {
176 visual_log_return_val_if_fail (widget != NULL, -VISUAL_ERROR_UI_WIDGET_NULL);
177
178 if (widget->tooltip != NULL)
179 visual_mem_free ((char *) widget->tooltip);
180
181 widget->tooltip = strdup (tooltip);
182
183 return VISUAL_OK;
184 }
185
186 /**
187 * Retrieves the tooltip that is set to a VisUIWidget.
188 *
189 * @param widget Pointer to the VisUIWidget from which the tooltip is requested.
190 *
191 * @return The tooltip, possibly NULL, NULL on failure.
192 */
visual_ui_widget_get_tooltip(VisUIWidget * widget)193 const char *visual_ui_widget_get_tooltip (VisUIWidget *widget)
194 {
195 visual_log_return_val_if_fail (widget != NULL, NULL);
196
197 return widget->tooltip;
198 }
199
200 /**
201 * Gets the top VisUIWidget from a VisUIWidget, this means that it will retrieve
202 * the widget that is the parent of all underlaying widgets.
203 *
204 * @param widget Pointer to the VisUIWidget of which we want to have the top VisUIWidget.
205 *
206 * @return Pointer to the top VisUIWidget, or NULL on failure.
207 */
visual_ui_widget_get_top(VisUIWidget * widget)208 VisUIWidget *visual_ui_widget_get_top (VisUIWidget *widget)
209 {
210 VisUIWidget *above;
211 VisUIWidget *prev = widget;
212
213 visual_log_return_val_if_fail (widget != NULL, NULL);
214
215 while ((above = visual_ui_widget_get_parent (widget)) != NULL) {
216 prev = widget;
217 }
218
219 return prev;
220 }
221
222 /**
223 * Gets the parent VisUIWidget from a VisUIWidget, this retrieves the parent of the given
224 * widget.
225 *
226 * @param widget Pointer to the VisUIWidget of which the parent is requested.
227 *
228 * @return Pointer to the parent VisUIWidget, or NULL on failure.
229 */
visual_ui_widget_get_parent(VisUIWidget * widget)230 VisUIWidget *visual_ui_widget_get_parent (VisUIWidget *widget)
231 {
232 visual_log_return_val_if_fail (widget != NULL, NULL);
233
234 return widget->parent;
235 }
236
237 /**
238 * Gets the VisUIWidgetType type from a VisUIWidget, this contains what kind of widget the given
239 * VisUIWidget is.
240 *
241 * @param widget Pointer to the VisUIWidget of which the type is requested.
242 *
243 * @return The VisUIWidgetType of the given VisUIWidget.
244 */
visual_ui_widget_get_type(VisUIWidget * widget)245 VisUIWidgetType visual_ui_widget_get_type (VisUIWidget *widget)
246 {
247 visual_log_return_val_if_fail (widget != NULL, VISUAL_WIDGET_TYPE_NULL);
248
249 return widget->type;
250 }
251
252 /**
253 * Adds a VisUIWidget to a VisUIContainer.
254 *
255 * @see visual_ui_box_pack
256 * @see visual_ui_table_attach
257 *
258 * @param container Pointer to the VisUIContainer in which a VisUIWidget is put.
259 * @param widget Pointer to the VisUIWidget that is been put in the VisUIContainer.
260 *
261 * @return VISUAL_OK on succes, or -VISUAL_ERROR_UI_CONTAINER_NULL, -VISUAL_ERROR_UI_WIDGET_NULL on failure.
262 */
visual_ui_container_add(VisUIContainer * container,VisUIWidget * widget)263 int visual_ui_container_add (VisUIContainer *container, VisUIWidget *widget)
264 {
265 visual_log_return_val_if_fail (container != NULL, -VISUAL_ERROR_UI_CONTAINER_NULL);
266 visual_log_return_val_if_fail (widget != NULL, -VISUAL_ERROR_UI_WIDGET_NULL);
267
268 container->child = widget;
269
270 return VISUAL_OK;
271 }
272
273 /**
274 * Gets the child VisUIWidget from a VisUIContainer.
275 *
276 * @param container Pointer to the VisUIContainer of which we want the child VisUIWidget.
277 *
278 * @return The child VisUIWidget, or NULL on failure.
279 */
visual_ui_container_get_child(VisUIContainer * container)280 VisUIWidget *visual_ui_container_get_child (VisUIContainer *container)
281 {
282 visual_log_return_val_if_fail (container != NULL, NULL);
283
284 return container->child;
285 }
286
287 /**
288 * Creates a new VisUIBox, that can be used to pack VisUIWidgets in.
289 *
290 * @param orient Indicates the orientation style of the box, being either
291 * VISUAL_ORIENT_TYPE_HORIZONTAL or VISUAL_ORIENT_TYPE_VERTICAL.
292 *
293 * @return The newly created VisUIBox in the form of a VisUIWidget.
294 */
visual_ui_box_new(VisUIOrientType orient)295 VisUIWidget *visual_ui_box_new (VisUIOrientType orient)
296 {
297 VisUIBox *box;
298
299 box = visual_mem_new0 (VisUIBox, 1);
300
301 /* Do the VisObject initialization */
302 visual_object_initialize (VISUAL_OBJECT (box), TRUE, box_dtor);
303
304 VISUAL_UI_WIDGET (box)->type = VISUAL_WIDGET_TYPE_BOX;
305
306 box->orient = orient;
307
308 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (box), -1, -1);
309
310 visual_collection_set_destroyer (VISUAL_COLLECTION (&box->childs), visual_object_collection_destroyer);
311
312 return VISUAL_UI_WIDGET (box);
313 }
314
315 /**
316 * Packs VisUIWidgets into a VisUIBox, this can be used to pack widgets either vertically or horizontally,
317 * depending on the type of box.
318 *
319 * @param box Pointer to the VisUIBox in which the widget is packed.
320 * @param widget Pointer to the VisUIWidget which is packed in the box.
321 *
322 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_BOX_NULL, -VISUAL_ERROR_UI_WIDGET_NULL or
323 * error values returned by visual_list_add () on failure.
324 */
visual_ui_box_pack(VisUIBox * box,VisUIWidget * widget)325 int visual_ui_box_pack (VisUIBox *box, VisUIWidget *widget)
326 {
327 visual_log_return_val_if_fail (box != NULL, -VISUAL_ERROR_UI_BOX_NULL);
328 visual_log_return_val_if_fail (widget != NULL, -VISUAL_ERROR_UI_WIDGET_NULL);
329
330 return visual_list_add (&box->childs, widget);
331 }
332
333 /**
334 * Retrieve a VisList of VisUIWidget elements, being the childs of the VisUIBox.
335 *
336 * @param box Pointer to the VisUIBox from which the childs are requested.
337 *
338 * @return VisList containing the childs of the VisUIBox or NULL on failure.
339 */
visual_ui_box_get_childs(VisUIBox * box)340 VisList *visual_ui_box_get_childs (VisUIBox *box)
341 {
342 VisUIWidget *next;
343 VisListEntry *le = NULL;
344
345 visual_log_return_val_if_fail (box != NULL, NULL);
346
347 return &box->childs;
348 }
349
350 /**
351 * Get the VisUIOrientType value from a VisUIBox.
352 *
353 * @param box VisUIBox from which the VisUIOrientType is requested.
354 *
355 * @return VisUIOrientType containing the orientation style for this VisUIBox.
356 */
visual_ui_box_get_orient(VisUIBox * box)357 VisUIOrientType visual_ui_box_get_orient (VisUIBox *box)
358 {
359 visual_log_return_val_if_fail (box != NULL, VISUAL_ORIENT_TYPE_NONE);
360
361 return box->orient;
362 }
363
364 /**
365 * Creates a new VisUITable, that can be used to attach VisUIWidgets to cells in the table.
366 *
367 * @param rows The number of rows in the table.
368 * @param cols The number of columns in the table.
369 *
370 * @return The newly created VisUITable in the form of a VisUIWidget.
371 */
visual_ui_table_new(int rows,int cols)372 VisUIWidget *visual_ui_table_new (int rows, int cols)
373 {
374 VisUITable *table;
375
376 table = visual_mem_new0 (VisUITable, 1);
377
378 /* Do the VisObject initialization */
379 visual_object_initialize (VISUAL_OBJECT (table), TRUE, table_dtor);
380
381 VISUAL_UI_WIDGET (table)->type = VISUAL_WIDGET_TYPE_TABLE;
382
383 table->rows = rows;
384 table->cols = cols;
385
386 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (table), -1, -1);
387
388 visual_collection_set_destroyer (VISUAL_COLLECTION (&table->childs), visual_object_collection_destroyer);
389
390 return VISUAL_UI_WIDGET (table);
391 }
392
393 /**
394 * Creates a new VisUITableEntry. You probably never need this function, but it's used internally.
395 *
396 * @param widget Pointer to the VisUIWidget of which a VisUITableEntry is created.
397 * @param row The row this entry will be placed.
398 * @param col The column this entry will be placed.
399 *
400 * @return A newly allocated VisUITableEntry, NULL on failure.
401 */
visual_ui_table_entry_new(VisUIWidget * widget,int row,int col)402 VisUITableEntry *visual_ui_table_entry_new (VisUIWidget *widget, int row, int col)
403 {
404 VisUITableEntry *tentry;
405
406 visual_log_return_val_if_fail (widget != NULL, NULL);
407
408 tentry = visual_mem_new0 (VisUITableEntry, 1);
409
410 /* Do the VisObject initialization */
411 visual_object_initialize (VISUAL_OBJECT (tentry), TRUE, table_entry_dtor);
412
413 tentry->row = row;
414 tentry->col = col;
415
416 tentry->widget = widget;
417
418 return tentry;
419 }
420
421 /**
422 * Attaches a VisUIWidget to a cell within a VisUITable.
423 *
424 * @param table Pointer to the VisUITable to which a VisUiWidget is attached.
425 * @param widget Pointer to the VisUIWidget that is being attached to the VisUITable.
426 * @param row The row number starting at 0.
427 * @param col The column number starting at 0.
428 *
429 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_TABLE_NULL, -VISUAL_ERROR_UI_WIDGET_NULL or
430 * error values returned by visual_list_add () on failure.
431 */
visual_ui_table_attach(VisUITable * table,VisUIWidget * widget,int row,int col)432 int visual_ui_table_attach (VisUITable *table, VisUIWidget *widget, int row, int col)
433 {
434 VisUITableEntry *tentry;
435
436 visual_log_return_val_if_fail (table != NULL, -VISUAL_ERROR_UI_TABLE_NULL);
437 visual_log_return_val_if_fail (widget != NULL, -VISUAL_ERROR_UI_WIDGET_NULL);
438
439 tentry = visual_ui_table_entry_new (widget, row, col);
440
441 return visual_list_add (&table->childs, tentry);
442 }
443
444 /**
445 * Retrieve a VisList containing VisUITableEntry elements, in which the child VisUIWidget and it's place
446 * in the VisUITable is stored.
447 *
448 * @param table Pointer to the VisUITable from which the childs are requested.
449 *
450 * @return VisList containing the childs of the VisUITable, or NULL on failure.
451 */
visual_ui_table_get_childs(VisUITable * table)452 VisList *visual_ui_table_get_childs (VisUITable *table)
453 {
454 visual_log_return_val_if_fail (table != NULL, NULL);
455
456 return &table->childs;
457 }
458
459 /**
460 * Creates a new VisUINotebook, this can is a container which can contain multiple childs under notebook tabs.
461 *
462 * @return The newly created VisUINotebook in the form of a VisUIWidget.
463 */
visual_ui_notebook_new()464 VisUIWidget *visual_ui_notebook_new ()
465 {
466 VisUINotebook *notebook;
467
468 notebook = visual_mem_new0 (VisUINotebook, 1);
469
470 /* Do the VisObject initialization */
471 visual_object_initialize (VISUAL_OBJECT (notebook), TRUE, notebook_dtor);
472
473 VISUAL_UI_WIDGET (notebook)->type = VISUAL_WIDGET_TYPE_NOTEBOOK;
474
475 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (notebook), -1, -1);
476
477 visual_collection_set_destroyer (VISUAL_COLLECTION (¬ebook->labels), visual_object_collection_destroyer);
478 visual_collection_set_destroyer (VISUAL_COLLECTION (¬ebook->childs), visual_object_collection_destroyer);
479
480 return VISUAL_UI_WIDGET (notebook);
481 }
482
483 /**
484 * Adds a VisUIWidget with a text label (Internally stored as a VisUILabel) to the notebook container.
485 *
486 * @param notebook Pointer to the VisUINotebook to which the VisUIWidget is added.
487 * @param widget Pointer to the VisUIWidget that is added to the VisUINotebook.
488 * @param label The label attached to the tab of this notebook entry.
489 *
490 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_NOTEBOOK_NULL, -VISUAL_ERROR_UI_WIDGET_NULL or -VISUAL_ERROR_NULL
491 * on failure.
492 */
visual_ui_notebook_add(VisUINotebook * notebook,VisUIWidget * widget,char * label)493 int visual_ui_notebook_add (VisUINotebook *notebook, VisUIWidget *widget, char *label)
494 {
495 visual_log_return_val_if_fail (notebook != NULL, -VISUAL_ERROR_UI_NOTEBOOK_NULL);
496 visual_log_return_val_if_fail (widget != NULL, -VISUAL_ERROR_UI_WIDGET_NULL);
497 visual_log_return_val_if_fail (label != NULL, -VISUAL_ERROR_NULL);
498
499 visual_list_add (¬ebook->labels, visual_ui_label_new (label, FALSE));
500 visual_list_add (¬ebook->childs, widget);
501
502 return VISUAL_OK;
503 }
504
505 /**
506 * Retrieve a VisList containing VisUIWidget elements, that are the childs for every tab.
507 *
508 * @param notebook Pointer to the VisUINotebook from which the childs are requested.
509 *
510 * @return VisList containing the childs of the VisUINotebook, or NULL on failure.
511 */
visual_ui_notebook_get_childs(VisUINotebook * notebook)512 VisList *visual_ui_notebook_get_childs (VisUINotebook *notebook)
513 {
514 visual_log_return_val_if_fail (notebook != NULL, NULL);
515
516 return ¬ebook->childs;
517 }
518
519 /**
520 * Retrieve a VisList containing VisUILabel elements, that are the child labels for every tab.
521 *
522 * @param notebook Pointer to the VisUINotebook from which the child labels are requested.
523 *
524 * @return VisList containing the child labels of the VisUINotebook, or NULL on failure.
525 */
visual_ui_notebook_get_childlabels(VisUINotebook * notebook)526 VisList *visual_ui_notebook_get_childlabels (VisUINotebook *notebook)
527 {
528 visual_log_return_val_if_fail (notebook != NULL, NULL);
529
530 return ¬ebook->labels;
531 }
532
533 /**
534 * Creates a new VisUIFrame, which can be used to put a frame around a VisUIWidget.
535 *
536 * @param name The name of this frame.
537 *
538 * @return The newly created VisUIFrame in the form of a VisUIWidget.
539 */
visual_ui_frame_new(const char * name)540 VisUIWidget *visual_ui_frame_new (const char *name)
541 {
542 VisUIFrame *frame;
543
544 frame = visual_mem_new0 (VisUIFrame, 1);
545
546 /* Do the VisObject initialization */
547 visual_object_initialize (VISUAL_OBJECT (frame), TRUE, frame_dtor);
548
549 VISUAL_UI_WIDGET (frame)->type = VISUAL_WIDGET_TYPE_FRAME;
550
551 frame->name = name;
552
553 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (frame), -1, -1);
554
555 return VISUAL_UI_WIDGET (frame);
556 }
557
558 /**
559 * Creates a new VisUILabel, which can be used as a one line piece of text in an user interface.
560 *
561 * @param text Text of which the label consists.
562 * @param bold Flag that indicates if a label should be drawn bold or not.
563 *
564 * @return The newly created VisUILabel in the form of a VisUIWidget.
565 */
visual_ui_label_new(const char * text,int bold)566 VisUIWidget *visual_ui_label_new (const char *text, int bold)
567 {
568 VisUILabel *label;
569
570 label = visual_mem_new0 (VisUILabel, 1);
571
572 /* Do the VisObject initialization */
573 visual_object_initialize (VISUAL_OBJECT (label), TRUE, widget_dtor);
574
575 VISUAL_UI_WIDGET (label)->type = VISUAL_WIDGET_TYPE_LABEL;
576
577 label->text = text;
578 label->bold = bold;
579
580 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (label), -1, -1);
581
582 return VISUAL_UI_WIDGET (label);
583 }
584
585 /**
586 * Sets the bold flag for a VisUILabel.
587 *
588 * @param label Pointer to the VisUILabel of which the bold flag is set, or unset.
589 * @param bold Flag that indicates if a label should be drawn bold or not.
590 *
591 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_LABEL_NULL on failure.
592 */
visual_ui_label_set_bold(VisUILabel * label,int bold)593 int visual_ui_label_set_bold (VisUILabel *label, int bold)
594 {
595 visual_log_return_val_if_fail (label != NULL, -VISUAL_ERROR_UI_LABEL_NULL);
596
597 label->bold = bold;
598
599 return VISUAL_OK;
600 }
601
602 /**
603 * Sets the text for a VisUILabel.
604 *
605 * @param label Pointer to the VisUILabel to which text is being set.
606 * @param text The text that is being set to the VisUILabel.
607 *
608 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_LABEL_NULL on failure.
609 */
visual_ui_label_set_text(VisUILabel * label,const char * text)610 int visual_ui_label_set_text (VisUILabel *label, const char *text)
611 {
612 visual_log_return_val_if_fail (label != NULL, -VISUAL_ERROR_UI_LABEL_NULL);
613
614 label->text = text;
615
616 return VISUAL_OK;
617 }
618
619 /**
620 * Retrieve the text from a VisUILabel.
621 *
622 * @param label Pointer to the VisUILabel from which the text is being requested.
623 *
624 * return The text contained in the label, NULL on failure.
625 */
visual_ui_label_get_text(VisUILabel * label)626 const char *visual_ui_label_get_text (VisUILabel *label)
627 {
628 visual_log_return_val_if_fail (label != NULL, NULL);
629
630 return label->text;
631 }
632
633 /**
634 * Creates a new VisUIImage, which can contain an image, loaded from a VisVideo.
635 *
636 * @param video The VisVideo containing the image to be displayed.
637 *
638 * @return The newly created VisUIImage in the form of a VisUIWidget.
639 */
visual_ui_image_new(VisVideo * video)640 VisUIWidget *visual_ui_image_new (VisVideo *video)
641 {
642 VisUIImage *image;
643
644 image = visual_mem_new0 (VisUIImage, 1);
645
646 /* Do the VisObject initialization */
647 visual_object_initialize (VISUAL_OBJECT (image), TRUE, widget_dtor);
648
649 VISUAL_UI_WIDGET (image)->type = VISUAL_WIDGET_TYPE_IMAGE;
650
651 image->image = video;
652
653 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (image), -1, -1);
654
655 return VISUAL_UI_WIDGET (image);
656 }
657
658 /**
659 * Sets a VisVideo to a VisUIImage. The VisVideo contains the content of the image.
660 *
661 * @param image Pointer to the VisUIImage to which the VisVideo is set.
662 * @param video Pointer to the VisVideo that is set to the VisUIImage.
663 *
664 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_IMAGE_NULL on failure.
665 */
visual_ui_image_set_video(VisUIImage * image,VisVideo * video)666 int visual_ui_image_set_video (VisUIImage *image, VisVideo *video)
667 {
668 visual_log_return_val_if_fail (image != NULL, -VISUAL_ERROR_UI_IMAGE_NULL);
669
670 image->image = video;
671
672 return VISUAL_OK;
673 }
674
675 /**
676 * Retrieves the VisVideo from a VisUIImage.
677 *
678 * @param image Pointer to the VisUIImage from which the VisVideo is requested.
679 *
680 * return The VisVideo that is connected to the VisUIImage.
681 */
visual_ui_image_get_video(VisUIImage * image)682 VisVideo *visual_ui_image_get_video (VisUIImage *image)
683 {
684 visual_log_return_val_if_fail (image != NULL, NULL);
685
686 return image->image;
687 }
688
689 /**
690 * Creates a new VisUISeparator, which can function as a separation item between other VisUIWidgets.
691 *
692 * @param orient Indicates the orientation style of the separator, being either
693 * VISUAL_ORIENT_TYPE_HORIZONTAL or VISUAL_ORIENT_TYPE_VERTICAL.
694 *
695 * @return The newly created VisUISeparator in the form of a VisUIWidget.
696 */
visual_ui_separator_new(VisUIOrientType orient)697 VisUIWidget *visual_ui_separator_new (VisUIOrientType orient)
698 {
699 VisUISeparator *separator;
700
701 separator = visual_mem_new0 (VisUISeparator, 1);
702
703 /* Do the VisObject initialization */
704 visual_object_initialize (VISUAL_OBJECT (separator), TRUE, widget_dtor);
705
706 VISUAL_UI_WIDGET (separator)->type = VISUAL_WIDGET_TYPE_SEPARATOR;
707
708 separator->orient = orient;
709
710 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (separator), -1, -1);
711
712 return VISUAL_UI_WIDGET (separator);
713 }
714
715 /**
716 * Get the VisUIOrientType value from a VisUISeparator.
717 *
718 * @param separator VisUISeparator from which the VisUIOrientType is requested.
719 *
720 * @return VisUIOrientType containing the orientation style for this VisUISeparator.
721 */
visual_ui_separator_get_orient(VisUISeparator * separator)722 VisUIOrientType visual_ui_separator_get_orient (VisUISeparator *separator)
723 {
724 visual_log_return_val_if_fail (separator != NULL, VISUAL_ORIENT_TYPE_NONE);
725
726 return separator->orient;
727 }
728
729 /**
730 * Links a VisParamEntry to a VisUIMutator type.
731 *
732 * @param mutator Pointer to the VisUIMutator to which the VisParamEntry is linked.
733 * @param param Pointer to the VisParamEntry that is linked to the VisUIMutator.
734 *
735 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_MUTATOR_NULL or -VISUAL_ERROR_PARAM_NULL on failure.
736 */
visual_ui_mutator_set_param(VisUIMutator * mutator,VisParamEntry * param)737 int visual_ui_mutator_set_param (VisUIMutator *mutator, VisParamEntry *param)
738 {
739 visual_log_return_val_if_fail (mutator != NULL, -VISUAL_ERROR_UI_MUTATOR_NULL);
740 visual_log_return_val_if_fail (param != NULL, -VISUAL_ERROR_PARAM_NULL);
741
742 /* FIXME Check if param is valid with mutator type, if not, give a critical */
743
744 mutator->param = param;
745
746 return VISUAL_OK;
747 }
748
749 /**
750 * Request the VisParamEntry that is linked to a VisUIMutator.
751 *
752 * @param mutator Pointer to the VisUIMutator from which the VisParamEntry is requested.
753 *
754 * return The VisParamEntry that links to the VisUIMutator, or NULL on failure.
755 */
visual_ui_mutator_get_param(VisUIMutator * mutator)756 VisParamEntry *visual_ui_mutator_get_param (VisUIMutator *mutator)
757 {
758 visual_log_return_val_if_fail (mutator != NULL, NULL);
759
760 return mutator->param;
761 }
762
763 /**
764 * Set the properties for a VisUIRange.
765 *
766 * @param range Pointer to the VisUIRange to which the properties are set.
767 * @param min The minimal value.
768 * @param max The maximal value.
769 * @param step The increase/decrease step value.
770 * @param precision The precision in numbers behind the comma.
771 *
772 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_RANGE_NULL on failure.
773 */
visual_ui_range_set_properties(VisUIRange * range,double min,double max,double step,int precision)774 int visual_ui_range_set_properties (VisUIRange *range, double min, double max, double step, int precision)
775 {
776 visual_log_return_val_if_fail (range != NULL, -VISUAL_ERROR_UI_RANGE_NULL);
777
778 range->min = min;
779 range->max = max;
780 range->step = step;
781 range->precision = precision;
782
783 return VISUAL_OK;
784 }
785
786 /**
787 * Sets the maximal value for a VisUIRange.
788 *
789 * @param range Pointer to the VisUIRange to which the maximum value is set.
790 * @param max The maximal value.
791 *
792 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_RANGE_NULL on failure.
793 */
visual_ui_range_set_max(VisUIRange * range,double max)794 int visual_ui_range_set_max (VisUIRange *range, double max)
795 {
796 visual_log_return_val_if_fail (range != NULL, -VISUAL_ERROR_UI_RANGE_NULL);
797
798 range->max = max;
799
800 return VISUAL_OK;
801 }
802
803 /**
804 * Sets the minimal value for a VisUIRange.
805 *
806 * @param range Pointer to the VisUIRange to which the minimal value is set.
807 * @param min The minimal value.
808 *
809 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_RANGE_NULL on failure.
810 */
visual_ui_range_set_min(VisUIRange * range,double min)811 int visual_ui_range_set_min (VisUIRange *range, double min)
812 {
813 visual_log_return_val_if_fail (range != NULL, -VISUAL_ERROR_UI_RANGE_NULL);
814
815 range->min = min;
816
817 return VISUAL_OK;
818 }
819
820 /**
821 * Sets the increase/decrease step size for a VisUIRange.
822 *
823 * @param range Pointer to the VisUIRange to which the step size value is set.
824 * @param step The increase/decrase step value.
825 *
826 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_RANGE_NULL on failure.
827 */
visual_ui_range_set_step(VisUIRange * range,double step)828 int visual_ui_range_set_step (VisUIRange *range, double step)
829 {
830 visual_log_return_val_if_fail (range != NULL, -VISUAL_ERROR_UI_RANGE_NULL);
831
832 range->step = step;
833
834 return VISUAL_OK;
835 }
836
837 /**
838 * Sets the precision for a VisUIRange.
839 *
840 * @param range Pointer to the VisUIRange to which the step size value is set.
841 * @param precision The precision in numbers behind the comma.
842 *
843 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_RANGE_NULL on failure.
844 */
visual_ui_range_set_precision(VisUIRange * range,int precision)845 int visual_ui_range_set_precision (VisUIRange *range, int precision)
846 {
847 visual_log_return_val_if_fail (range != NULL, -VISUAL_ERROR_UI_RANGE_NULL);
848
849 range->precision = precision;
850
851 return VISUAL_OK;
852 }
853
854 /**
855 * Creates a new VisUIEntry, which can be used to enter text.
856 *
857 * @return The newly created VisUIEntry in the form of a VisUIWidget.
858 */
visual_ui_entry_new()859 VisUIWidget *visual_ui_entry_new ()
860 {
861 VisUIEntry *entry;
862
863 entry = visual_mem_new0 (VisUIEntry, 1);
864
865 /* Do the VisObject initialization */
866 visual_object_initialize (VISUAL_OBJECT (entry), TRUE, widget_dtor);
867
868 VISUAL_UI_WIDGET (entry)->type = VISUAL_WIDGET_TYPE_ENTRY;
869
870 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (entry), -1, -1);
871
872 return VISUAL_UI_WIDGET (entry);
873 }
874
875 /**
876 * Sets the maximum length for the text in a VisUIEntry.
877 *
878 * @param entry Pointer to the VisUIEntry to which the maximum text length is set.
879 * @param length The maximum text length for the VisUIEntry.
880 *
881 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_ENTRY_NULL on failure.
882 */
visual_ui_entry_set_length(VisUIEntry * entry,int length)883 int visual_ui_entry_set_length (VisUIEntry *entry, int length)
884 {
885 visual_log_return_val_if_fail (entry != NULL, -VISUAL_ERROR_UI_ENTRY_NULL);
886
887 entry->length = length;
888
889 return VISUAL_OK;
890 }
891
892 /**
893 * Creates a new VisUISlider, which can be used as a VisUIRange type, in the form of a slider.
894 *
895 * @param showvalue Show the value of the slider place.
896 *
897 * @return The newly created VisUISlider in the form of a VisUIWidget.
898 */
visual_ui_slider_new(int showvalue)899 VisUIWidget *visual_ui_slider_new (int showvalue)
900 {
901 VisUISlider *slider;
902
903 slider = visual_mem_new0 (VisUISlider, 1);
904
905 /* Do the VisObject initialization */
906 visual_object_initialize (VISUAL_OBJECT (slider), TRUE, widget_dtor);
907
908 VISUAL_UI_WIDGET (slider)->type = VISUAL_WIDGET_TYPE_SLIDER;
909
910 slider->showvalue = showvalue;
911
912 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (slider), -1, -1);
913
914 return VISUAL_UI_WIDGET (slider);
915 }
916
917 /**
918 * Creates a new VisUINumerici, which can be used as a VisUIRange type, in the form of a numeric spinbutton.
919 *
920 * @return The newly created VisUINumeric in the form of a VisUIWidget.
921 */
visual_ui_numeric_new()922 VisUIWidget *visual_ui_numeric_new ()
923 {
924 VisUINumeric *numeric;
925
926 numeric = visual_mem_new0 (VisUINumeric, 1);
927
928 /* Do the VisObject initialization */
929 visual_object_initialize (VISUAL_OBJECT (numeric), TRUE, widget_dtor);
930
931 VISUAL_UI_WIDGET (numeric)->type = VISUAL_WIDGET_TYPE_NUMERIC;
932
933 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (numeric), -1, -1);
934
935 return VISUAL_UI_WIDGET (numeric);
936 }
937
938 /**
939 * Creates a new VisUIColor, which can be used to select a color.
940 *
941 * @return The newly created VisUIColor in the form of a VisUIWidget.
942 */
visual_ui_color_new()943 VisUIWidget *visual_ui_color_new ()
944 {
945 VisUIColor *color;
946
947 color = visual_mem_new0 (VisUIColor, 1);
948
949 /* Do the VisObject initialization */
950 visual_object_initialize (VISUAL_OBJECT (color), TRUE, widget_dtor);
951
952 VISUAL_UI_WIDGET (color)->type = VISUAL_WIDGET_TYPE_COLOR;
953
954 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (color), -1, -1);
955
956 return VISUAL_UI_WIDGET (color);
957 }
958
959 /**
960 * Creates a new VisUIColorButton, which can be used to select a color button.
961 *
962 * @return The newly created VisUIColorButton in the form of a VisUIWidget.
963 */
visual_ui_colorbutton_new()964 VisUIWidget *visual_ui_colorbutton_new ()
965 {
966 VisUIColorButton *colorbutton;
967
968 colorbutton = visual_mem_new0 (VisUIColorButton, 1);
969
970 /* Do the VisObject initialization */
971 visual_object_initialize (VISUAL_OBJECT (colorbutton), TRUE, widget_dtor);
972
973 VISUAL_UI_WIDGET (colorbutton)->type = VISUAL_WIDGET_TYPE_COLORBUTTON;
974
975 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (colorbutton), -1, -1);
976
977 return VISUAL_UI_WIDGET (colorbutton);
978 }
979
980 /* FIXME finish */
981 /**
982 * Creates a new VisUIColorPalette, which can be used to describe small palettes.
983 *
984 * @return The newly created VisUIColorPalette in the form of a VisUIWidget.
985 */
visual_ui_colorpalette_new()986 VisUIWidget *visual_ui_colorpalette_new ()
987 {
988 VisUIColorPalette *colorpalette;
989
990 colorpalette = visual_mem_new0 (VisUIColorPalette, 1);
991
992 /* Do the VisObject initialization */
993 visual_object_initialize (VISUAL_OBJECT (colorpalette), TRUE, widget_dtor);
994
995 VISUAL_UI_WIDGET (colorpalette)->type = VISUAL_WIDGET_TYPE_COLORPALETTE;
996
997 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (colorpalette), -1, -1);
998
999 return VISUAL_UI_WIDGET (colorpalette);
1000 }
1001
1002 /**
1003 * Creates a new VisUIChoiceEntry, this is an entry in an entry in VisUIChoiceList, that is used
1004 * by the different VisUIChoice inherentence.
1005 *
1006 * @param name The name ofe the choice.
1007 * @param value The VisParamEntry associated with this choice.
1008 *
1009 * @return The newly created VisUIChoiceEntry.
1010 */
visual_ui_choice_entry_new(const char * name,VisParamEntry * value)1011 VisUIChoiceEntry *visual_ui_choice_entry_new (const char *name, VisParamEntry *value)
1012 {
1013 VisUIChoiceEntry *centry;
1014
1015 visual_log_return_val_if_fail (name != NULL, NULL);
1016 visual_log_return_val_if_fail (value != NULL, NULL);
1017
1018 centry = visual_mem_new0 (VisUIChoiceEntry, 1);
1019
1020 /* Do the VisObject initialization */
1021 visual_object_initialize (VISUAL_OBJECT (centry), TRUE, NULL);
1022
1023 centry->name = name;
1024 centry->value = value;
1025
1026 return centry;
1027 }
1028
1029 /**
1030 * Add a VisParamEntry as a choice for a VisUIWidget that inherents from VisUIChoice.
1031 *
1032 * @param choice Pointer to the VisUIChoice widget to which the choice is added.
1033 * @param name The name of this choice.
1034 * @param value Pointer to the VisParamEntry that is associated with this choice.
1035 *
1036 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_CHOICE_NULL, -VISUAL_ERROR_NULL
1037 * or -VISUAL_ERROR_PARAM_NULL on failure.
1038 */
visual_ui_choice_add(VisUIChoice * choice,const char * name,VisParamEntry * value)1039 int visual_ui_choice_add (VisUIChoice *choice, const char *name, VisParamEntry *value)
1040 {
1041 VisUIChoiceEntry *centry;
1042
1043 visual_log_return_val_if_fail (choice != NULL, -VISUAL_ERROR_UI_CHOICE_NULL);
1044 visual_log_return_val_if_fail (name != NULL, -VISUAL_ERROR_NULL);
1045 visual_log_return_val_if_fail (value != NULL, -VISUAL_ERROR_PARAM_NULL);
1046
1047 centry = visual_ui_choice_entry_new (name, value);
1048
1049 choice->choices.count++;
1050
1051 visual_list_add (&choice->choices.choices, centry);
1052
1053 return VISUAL_OK;
1054 }
1055
1056 /**
1057 * Add many choices using a VisParamEntry array.
1058 *
1059 * @see visual_ui_choice_add
1060 *
1061 * @param choice Pointer to the VisUIChoice widget to which the choices are added.
1062 * @param paramchoices Pointer to the array of VisParamEntries that are added to the internal
1063 * VisUIChoiceList of the VisUIChoice widget.
1064 *
1065 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_CHOICE_NULL or -VISUAL_ERROR_PARAM_NULL on failure.
1066 */
visual_ui_choice_add_many(VisUIChoice * choice,VisParamEntry * paramchoices)1067 int visual_ui_choice_add_many (VisUIChoice *choice, VisParamEntry *paramchoices)
1068 {
1069 VisUIChoiceEntry *centry;
1070 int i = 0;
1071
1072 visual_log_return_val_if_fail (choice != NULL, -VISUAL_ERROR_UI_CHOICE_NULL);
1073 visual_log_return_val_if_fail (paramchoices != NULL, -VISUAL_ERROR_PARAM_NULL);
1074
1075 while (paramchoices[i].type != VISUAL_PARAM_ENTRY_TYPE_END) {
1076 visual_ui_choice_add (choice, paramchoices[i].name, ¶mchoices[i]);
1077
1078 i++;
1079 }
1080
1081 return VISUAL_OK;
1082 }
1083
1084 /**
1085 * Frees all the memory used by the VisUIChoiceList and it's entries for the given VisUIChoice.
1086 *
1087 * @param choice Pointer to the VisUIChoice for which the VisUIChoiceList and it's entries
1088 * are being freed.
1089 *
1090 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_CHOICE_NULL on failure.
1091 */
visual_ui_choice_free_choices(VisUIChoice * choice)1092 int visual_ui_choice_free_choices (VisUIChoice *choice)
1093 {
1094 visual_log_return_val_if_fail (choice != NULL, -VISUAL_ERROR_UI_CHOICE_NULL);
1095
1096 visual_collection_set_destroyer (VISUAL_COLLECTION (&choice->choices.choices), visual_object_collection_destroyer);
1097 visual_collection_destroy (VISUAL_COLLECTION (&choice->choices.choices));
1098
1099 return VISUAL_OK;
1100 }
1101
1102 /**
1103 * Sets the active choice for a VisUIChoice widget.
1104 *
1105 * @param choice Pointer to the VisUIChoice widget for which an entry is being activated.
1106 * @param index Index containing which choice needs to be activated, counting starts at 0.
1107 *
1108 * @return VISUAL_OK on succes, -VISUAL_ERROR_UI_CHOICE_NULL, -VISUAL_ERROR_UI_CHOICE_ENTRY_NULL or
1109 * error values returned by visual_ui_mutator_get_param () on failure.
1110 */
visual_ui_choice_set_active(VisUIChoice * choice,int index)1111 int visual_ui_choice_set_active (VisUIChoice *choice, int index)
1112 {
1113 VisUIChoiceEntry *centry;
1114 VisParamEntry *param;
1115 VisParamEntry *newparam;
1116
1117 visual_log_return_val_if_fail (choice != NULL, -VISUAL_ERROR_UI_CHOICE_NULL);
1118
1119 centry = visual_ui_choice_get_choice (choice, index);
1120 visual_log_return_val_if_fail (centry != NULL, -VISUAL_ERROR_UI_CHOICE_ENTRY_NULL);
1121
1122 param = visual_ui_mutator_get_param (VISUAL_UI_MUTATOR (choice));
1123
1124 newparam = (VisParamEntry *) centry->value;
1125
1126 return visual_param_entry_set_from_param (param, newparam);
1127 }
1128
1129 /**
1130 * Retrieves the index of the current active choice.
1131 *
1132 * @param choice Pointer to the VisUIChoice widget from which the active choice is requested.
1133 *
1134 * @return Index of the active choice entry.
1135 */
visual_ui_choice_get_active(VisUIChoice * choice)1136 int visual_ui_choice_get_active (VisUIChoice *choice)
1137 {
1138 VisListEntry *le = NULL;
1139 VisUIChoiceEntry *centry;
1140 VisParamEntry *param;
1141 int i = 0;
1142
1143 visual_log_return_val_if_fail (choice != NULL, -VISUAL_ERROR_UI_CHOICE_NULL);
1144
1145 param = visual_ui_mutator_get_param (VISUAL_UI_MUTATOR (choice));
1146
1147 while ((centry = visual_list_next (&choice->choices.choices, &le)) != NULL) {
1148 VisParamEntry *cparam;
1149
1150 cparam = centry->value;
1151
1152 if (visual_param_entry_compare (param, cparam) == TRUE)
1153 return i;
1154
1155 i++;
1156 }
1157
1158 return -VISUAL_ERROR_UI_CHOICE_NONE_ACTIVE;
1159 }
1160
1161 /**
1162 * Retrieves a VisUIChoiceEntry from a VisUIChoice based on the index.
1163 *
1164 * @param choice Pointer to the VisUIChoice widget from which a VisUIChoiceEntry is requested.
1165 * @param index Index of the requested VisUIChoiceEntry.
1166 *
1167 * @return The VisUIChoiceEntry that is located on the given index, or NULL on failure.
1168 */
visual_ui_choice_get_choice(VisUIChoice * choice,int index)1169 VisUIChoiceEntry *visual_ui_choice_get_choice (VisUIChoice *choice, int index)
1170 {
1171 visual_log_return_val_if_fail (choice != NULL, NULL);
1172
1173 return visual_list_get (&choice->choices.choices, index);
1174 }
1175
1176 /**
1177 * Retrvies the VisUIChoiceList from a VisUIChoice widget.
1178 *
1179 * @param choice Pointer to the VisUIChoice widget from which the VisUIChoiceList is requested.
1180 *
1181 * @return The VisUIChoiceList that is associated to the VisUIChoice.
1182 */
visual_ui_choice_get_choices(VisUIChoice * choice)1183 VisUIChoiceList *visual_ui_choice_get_choices (VisUIChoice *choice)
1184 {
1185 visual_log_return_val_if_fail (choice != NULL, NULL);
1186
1187 return &choice->choices;
1188 }
1189
1190 /**
1191 * Creates a new VisUIPopup. This can be used to show a popup list containing items from which
1192 * can be choosen.
1193 *
1194 * @return The newly created VisUIPopup in the form of a VisUIWidget.
1195 */
visual_ui_popup_new()1196 VisUIWidget *visual_ui_popup_new ()
1197 {
1198 VisUIPopup *popup;
1199
1200 popup = visual_mem_new0 (VisUIPopup, 1);
1201
1202 /* Do the VisObject initialization */
1203 visual_object_initialize (VISUAL_OBJECT (popup), TRUE, choice_dtor);
1204
1205 VISUAL_UI_WIDGET (popup)->type = VISUAL_WIDGET_TYPE_POPUP;
1206
1207 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (popup), -1, -1);
1208
1209 return VISUAL_UI_WIDGET (popup);
1210 }
1211
1212 /**
1213 * Creates a new VisUIList. This can be used to show a list containing items from which
1214 * can be choosen.
1215 *
1216 * @return The newly created VisUIList in the form of a VisUIWidget.
1217 */
visual_ui_list_new()1218 VisUIWidget *visual_ui_list_new ()
1219 {
1220 VisUIList *list;
1221
1222 list = visual_mem_new0 (VisUIList, 1);
1223
1224 /* Do the VisObject initialization */
1225 visual_object_initialize (VISUAL_OBJECT (list), TRUE, choice_dtor);
1226
1227 VISUAL_UI_WIDGET (list)->type = VISUAL_WIDGET_TYPE_LIST;
1228
1229 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (list), -1, -1);
1230
1231 return VISUAL_UI_WIDGET (list);
1232 }
1233
1234 /**
1235 * Creates a new VisUIRadio. This can be used to show a list of radio buttons containing items from which
1236 * can be choosen.
1237 *
1238 * @param orient The orientation of the radio button layout.
1239 *
1240 * @return The newly created VisUIRadio in the form of a VisUIWidget.
1241 */
visual_ui_radio_new(VisUIOrientType orient)1242 VisUIWidget *visual_ui_radio_new (VisUIOrientType orient)
1243 {
1244 VisUIRadio *radio;
1245
1246 radio = visual_mem_new0 (VisUIRadio, 1);
1247
1248 /* Do the VisObject initialization */
1249 visual_object_initialize (VISUAL_OBJECT (radio), TRUE, choice_dtor);
1250
1251 VISUAL_UI_WIDGET (radio)->type = VISUAL_WIDGET_TYPE_RADIO;
1252
1253 radio->orient = orient;
1254
1255 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (radio), -1, -1);
1256
1257 return VISUAL_UI_WIDGET (radio);
1258 }
1259
1260 /**
1261 * Creates a new VisUICheckbox. This can be used to show a checkbox that can be toggled and untoggled.
1262 *
1263 * @param name The text behind the checkbox.
1264 * @param boolcheck Automaticly set a boolean, TRUE and FALSE VisUIChoiceList on the VisUICheckbox.
1265 *
1266 * @return The newly created VisUICheckbox in the form of a VisUIWidget.
1267 */
visual_ui_checkbox_new(const char * name,int boolcheck)1268 VisUIWidget *visual_ui_checkbox_new (const char *name, int boolcheck)
1269 {
1270 VisUICheckbox *checkbox;
1271 static VisParamEntry truefalse[] = {
1272 VISUAL_PARAM_LIST_ENTRY_INTEGER ("false", FALSE),
1273 VISUAL_PARAM_LIST_ENTRY_INTEGER ("true", TRUE),
1274 VISUAL_PARAM_LIST_END
1275 };
1276
1277 checkbox = visual_mem_new0 (VisUICheckbox, 1);
1278
1279 /* Do the VisObject initialization */
1280 visual_object_initialize (VISUAL_OBJECT (checkbox), TRUE, choice_dtor);
1281
1282 VISUAL_UI_WIDGET (checkbox)->type = VISUAL_WIDGET_TYPE_CHECKBOX;
1283
1284 checkbox->name = name;
1285
1286 /* Boolean checkbox, generate a FALSE, TRUE choicelist ourself */
1287 if (boolcheck == TRUE)
1288 visual_ui_choice_add_many (VISUAL_UI_CHOICE (checkbox), truefalse);
1289
1290 visual_ui_widget_set_size_request (VISUAL_UI_WIDGET (checkbox), -1, -1);
1291
1292 return VISUAL_UI_WIDGET (checkbox);
1293 }
1294
1295 /**
1296 * @}
1297 */
1298
1299