ui/motif/container.c

Thu, 12 Dec 2024 20:01:43 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 12 Dec 2024 20:01:43 +0100
changeset 100
d2bd73d28ff1
parent 29
3fc287f06305
permissions
-rw-r--r--

update toolkit

0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
4 * Copyright 2024 Olaf Wintermann. All rights reserved.
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <inttypes.h>
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "container.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "../common/context.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "../common/object.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
37 #include "Grid.h"
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
39 /* ---------------------------- Box Container ---------------------------- */
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
41 static UIWIDGET box_create(UiObject *obj, UiContainerArgs args, UiBoxOrientation orientation) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
42 UiContainerPrivate *ctn = ui_obj_container(obj);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
43 UI_APPLY_LAYOUT(ctn->layout, args);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
45 Arg xargs[16];
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
46 int n = 0;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
48 if(orientation == UI_BOX_VERTICAL) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
49 //XtSetArg(xargs[n], gridRowSpacing, args.spacing); n++;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 } else {
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
51 //XtSetArg(xargs[n], gridColumnSpacing, args.spacing); n++;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
54 Widget parent = ctn->prepare(ctn, xargs, &n);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
55 Widget grid = XtCreateManagedWidget(args.name ? args.name : "boxcontainer", gridClass, parent, xargs, n);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
56 ctn->add(ctn, grid);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
58 UiContainerX *container = ui_box_container(obj, grid, orientation);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
59 uic_object_push_container(obj, container);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 return grid;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
64 // public
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
65 UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
66 return box_create(obj, args, UI_BOX_VERTICAL);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
67 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
68
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
69 // public
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
70 UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
71 return box_create(obj, args, UI_BOX_HORIZONTAL);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
74 UiContainerX* ui_box_container(UiObject *obj, Widget grid, UiBoxOrientation orientation) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
75 UiBoxContainer *ctn = ui_malloc(obj->ctx, sizeof(UiBoxContainer));
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
76 memset(ctn, 0, sizeof(UiBoxContainer));
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
77 ctn->container.prepare = orientation == UI_BOX_VERTICAL ? ui_vbox_prepare : ui_hbox_prepare;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
78 ctn->container.add = ui_box_container_add;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
79 ctn->container.widget = grid;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
80 ctn->n = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
81 return (UiContainerX*)ctn;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
84 static Widget ui_box_container_prepare(UiBoxContainer *box, Arg *args, int *n) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
85 int a = *n;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
86 box->n++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
87 return box->container.widget;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
90 Widget ui_vbox_prepare(UiContainerPrivate *ctn, Arg *args, int *n) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
91 UiBoxContainer *box = (UiBoxContainer*)ctn;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
92 int a = *n;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
93 XtSetArg(args[a], gridRow, box->n); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
94 if(box->container.layout.fill == UI_ON) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
95 XtSetArg(args[a], gridVExpand, TRUE); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
96 XtSetArg(args[a], gridVFill, TRUE); a++;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 }
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
98 XtSetArg(args[a], gridHExpand, TRUE); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
99 XtSetArg(args[a], gridHFill, TRUE); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
100 *n = a;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
101 return ui_box_container_prepare(box, args, n);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
104 Widget ui_hbox_prepare(UiContainerPrivate *ctn, Arg *args, int *n) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
105 UiBoxContainer *box = (UiBoxContainer*)ctn;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
106 int a = *n;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
107 XtSetArg(args[a], gridColumn, box->n); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
108 if(box->container.layout.fill == UI_ON) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
109 XtSetArg(args[a], gridHExpand, TRUE); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
110 XtSetArg(args[a], gridHFill, TRUE); a++;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 }
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
112 XtSetArg(args[a], gridVExpand, TRUE); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
113 XtSetArg(args[a], gridVFill, TRUE); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
114 *n = a;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
115 return ui_box_container_prepare(box, args, n);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
118 void ui_box_container_add(UiContainerPrivate *ctn, Widget widget) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
119 ui_reset_layout(ctn->layout);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
123
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
124 /* ---------------------------- Grid Container ---------------------------- */
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
125
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
126 // public
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
127 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
128 Arg xargs[16];
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 int n = 0;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
131 XtSetArg(xargs[n], XmNbackground, 0); n++;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
133 UiContainerPrivate *ctn = ui_obj_container(obj);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
134 UI_APPLY_LAYOUT(ctn->layout, args);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
136 Widget parent = ctn->prepare(ctn, xargs, &n);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
137 Widget grid = XtCreateManagedWidget(args.name ? args.name : "gridcontainer", gridClass, parent, xargs, n);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
138 ctn->add(ctn, grid);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
140 UiContainerX *container = ui_grid_container(obj, grid);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
141 uic_object_push_container(obj, container);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
143 return grid;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
146 UiContainerX* ui_grid_container(UiObject *obj, Widget grid) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
147 UiGridContainer *ctn = ui_malloc(obj->ctx, sizeof(UiGridContainer));
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
148 memset(ctn, 0, sizeof(UiBoxContainer));
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
149 ctn->container.prepare = ui_grid_container_prepare;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
150 ctn->container.add = ui_grid_container_add;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
151 ctn->container.widget = grid;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
152 ctn->x = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
153 ctn->y = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
154 return (UiContainerX*)ctn;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
155 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
156
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
157 Widget ui_grid_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
158 UiGridContainer *grid = (UiGridContainer*)ctn;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
159 if(ctn->layout.newline) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
160 grid->y++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
161 grid->x = 0;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
164 int a = *n;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
165 XtSetArg(args[a], gridColumn, grid->x); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
166 XtSetArg(args[a], gridRow, grid->y); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
167 if(ctn->layout.colspan > 0) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
168 XtSetArg(args[a], gridColspan, ctn->layout.colspan); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
169 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
170 if(ctn->layout.rowspan > 0) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
171 XtSetArg(args[a], gridRowspan, ctn->layout.rowspan); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
172 }
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
174 if(grid->container.layout.fill == UI_ON) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
175 grid->container.layout.hfill = TRUE;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
176 grid->container.layout.vfill = TRUE;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
177 grid->container.layout.hexpand = TRUE;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
178 grid->container.layout.vexpand = TRUE;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
181 if(grid->container.layout.hfill) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
182 XtSetArg(args[a], gridHFill, TRUE); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
183 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
184 if(grid->container.layout.vfill) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
185 XtSetArg(args[a], gridVFill, TRUE); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
186 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
187 if(grid->container.layout.hexpand) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
188 XtSetArg(args[a], gridHExpand, TRUE); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
189 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
190 if(grid->container.layout.vexpand) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
191 XtSetArg(args[a], gridVExpand, TRUE); a++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
192 }
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
194 *n = a;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
195 return ctn->widget;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
198 void ui_grid_container_add(UiContainerPrivate *ctn, Widget widget) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
199 UiGridContainer *grid = (UiGridContainer*)ctn;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
200 grid->x++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
201 ui_reset_layout(ctn->layout);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
204
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
205 /* -------------------- Container Helper Functions -------------------- */
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
206
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
207 void ui_container_begin_close(UiObject *obj) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
208 UiContainerPrivate *ct = ui_obj_container(obj);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
209 ct->container.close = 1;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
212 int ui_container_finish(UiObject *obj) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
213 UiContainerPrivate *ct = ui_obj_container(obj);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
214 if(ct->container.close) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
215 ui_end_new(obj);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
216 return 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
217 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
218 return 1;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
219 }
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 /*
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 * -------------------- Layout Functions --------------------
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 * functions for setting layout attributes for the current container
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 */
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 void ui_newline(UiObject *obj) {
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
230 UiContainerPrivate *ct = ui_obj_container(obj);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 ct->layout.newline = TRUE;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 }

mercurial