1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #include "demo_states.h"
30
31 #include <inttypes.h>
32
33 static void *doc1;
34 static void *doc2;
35
36 static void doc1_attachment(UiEvent *event,
void *userdata) {
37 if(event->intval) {
38 printf(
"attach document 1\n");
39 ui_attach_document(event->obj->ctx, doc1);
40 }
else {
41 printf(
"detach document 1\n");
42 ui_detach_document(event->obj->ctx, doc1);
43 }
44 }
45
46 static void doc2_attachment(UiEvent *event,
void *userdata) {
47 UiContext *ctx = ui_document_context(doc1);
48 if(event->intval) {
49 printf(
"attach document 2 to document 1\n");
50 ui_attach_document(ctx, doc2);
51 }
else {
52 printf(
"detach document 2 from document 1\n");
53 ui_detach_document(ctx, doc2);
54 }
55 }
56
57 static void doc_enable_state1(UiEvent *event,
void *doc) {
58 UiContext *ctx = ui_document_context(doc);
59 if(event->intval) {
60 ui_set_state(ctx,
1);
61 }
else {
62 ui_unset_state(ctx,
1);
63 }
64 }
65
66 static void doc_enable_state2(UiEvent *event,
void *doc) {
67 UiContext *ctx = ui_document_context(doc);
68 if(event->intval) {
69 ui_set_state(ctx,
2);
70 }
else {
71 ui_unset_state(ctx,
2);
72 }
73 }
74
75 static void doc_enable_state3(UiEvent *event,
void *doc) {
76 UiContext *ctx = ui_document_context(doc);
77 if(event->intval) {
78 ui_set_state(ctx,
3);
79 }
else {
80 ui_unset_state(ctx,
3);
81 }
82 }
83
84 static void doc_enable_state4(UiEvent *event,
void *doc) {
85 UiContext *ctx = ui_document_context(doc);
86 if(event->intval) {
87 ui_set_state(ctx,
4);
88 }
else {
89 ui_unset_state(ctx,
4);
90 }
91 }
92
93 static void doc_suppress_state1(UiEvent *event,
void *doc) {
94 UiContext *ctx = ui_document_context(doc);
95 if(event->intval) {
96 ui_suppress_state(ctx,
1);
97 }
else {
98 ui_unsuppress_state(ctx,
1);
99 }
100 }
101
102 static void doc_suppress_state2(UiEvent *event,
void *doc) {
103 UiContext *ctx = ui_document_context(doc);
104 if(event->intval) {
105 ui_suppress_state(ctx,
2);
106 }
else {
107 ui_unsuppress_state(ctx,
2);
108 }
109 }
110
111 static void doc_suppress_state3(UiEvent *event,
void *doc) {
112 UiContext *ctx = ui_document_context(doc);
113 if(event->intval) {
114 ui_suppress_state(ctx,
3);
115 }
else {
116 ui_unsuppress_state(ctx,
3);
117 }
118 }
119
120 static void doc_suppress_state4(UiEvent *event,
void *doc) {
121 UiContext *ctx = ui_document_context(doc);
122 if(event->intval) {
123 ui_suppress_state(ctx,
4);
124 }
else {
125 ui_unsuppress_state(ctx,
4);
126 }
127 }
128
129 static void application_startup(UiEvent *event,
void *userdata) {
130 UiObject *obj = ui_window(
"States Demo");
131
132 doc1 = ui_document_new(
8);
133 doc2 = ui_document_new(
8);
134
135 ui_hbox(obj, .margin =
10, .spacing =
8) {
136 ui_button(obj, .label =
"State 1", .states =
UI_STATES(
1));
137 ui_button(obj, .label =
"State 2", .states =
UI_STATES(
2));
138 ui_button(obj, .label =
"State 3", .states =
UI_STATES(
3));
139 ui_button(obj, .label =
"State 4", .states =
UI_STATES(
4));
140 ui_button(obj, .label =
"State 1,2", .states =
UI_STATES(
1,
2));
141 ui_button(obj, .label =
"State 1,2,3", .states =
UI_STATES(
1,
2,
3));
142 ui_button(obj, .label =
"State 1,2,3,4", .states =
UI_STATES(
1,
2,
3,
4));
143 }
144
145 ui_frame(obj, .label =
"Window", .fill =
TRUE, .margin =
10, .subcontainer =
UI_CONTAINER_VBOX) {
146 ui_hbox(obj, .margin =
10, .spacing =
8) {
147 ui_togglebutton(obj, .label =
"Enable 1", .enable_state =
1);
148 ui_togglebutton(obj, .label =
"Enable 2", .enable_state =
2);
149 ui_togglebutton(obj, .label =
"Enable 3", .enable_state =
3);
150 ui_togglebutton(obj, .label =
"Enable 4", .enable_state =
4);
151 }
152
153 ui_frame(obj, .label =
"Doc 1", .fill =
TRUE, .margin =
10, .padding =
10, .spacing =
10, .subcontainer =
UI_CONTAINER_VBOX) {
154 ui_togglebutton(obj, .label =
"Attach", .onchange = doc1_attachment);
155
156 ui_grid(obj, .margin =
10, .columnspacing =
8, .rowspacing =
8, .def_hfill =
TRUE) {
157 ui_togglebutton(obj, .label =
"Enable 1", .onchange = doc_enable_state1, .onchangedata = doc1);
158 ui_togglebutton(obj, .label =
"Enable 2", .onchange = doc_enable_state2, .onchangedata = doc1);
159 ui_togglebutton(obj, .label =
"Enable 3", .onchange = doc_enable_state3, .onchangedata = doc1);
160 ui_togglebutton(obj, .label =
"Enable 4", .onchange = doc_enable_state4, .onchangedata = doc1);
161
162 ui_newline(obj);
163
164 ui_togglebutton(obj, .label =
"Suppress 1", .onchange = doc_suppress_state1, .onchangedata = doc1);
165 ui_togglebutton(obj, .label =
"Suppress 2", .onchange = doc_suppress_state2, .onchangedata = doc1);
166 ui_togglebutton(obj, .label =
"Suppress 3", .onchange = doc_suppress_state3, .onchangedata = doc1);
167 ui_togglebutton(obj, .label =
"Suppress 4", .onchange = doc_suppress_state4, .onchangedata = doc1);
168 }
169
170 ui_frame(obj, .label =
"Doc 2", .fill =
TRUE, .margin =
10, .padding =
10, .spacing =
10, .subcontainer =
UI_CONTAINER_VBOX) {
171 ui_togglebutton(obj, .label =
"Attach", .onchange = doc2_attachment);
172
173 ui_grid(obj, .margin =
10, .columnspacing =
8, .rowspacing =
8, .def_hfill =
TRUE) {
174 ui_togglebutton(obj, .label =
"Enable 1", .onchange = doc_enable_state1, .onchangedata = doc2);
175 ui_togglebutton(obj, .label =
"Enable 2", .onchange = doc_enable_state2, .onchangedata = doc2);
176 ui_togglebutton(obj, .label =
"Enable 3", .onchange = doc_enable_state3, .onchangedata = doc2);
177 ui_togglebutton(obj, .label =
"Enable 4", .onchange = doc_enable_state4, .onchangedata = doc2);
178
179 ui_newline(obj);
180
181 ui_togglebutton(obj, .label =
"Suppress 1", .onchange = doc_suppress_state1, .onchangedata = doc2);
182 ui_togglebutton(obj, .label =
"Suppress 2", .onchange = doc_suppress_state2, .onchangedata = doc2);
183 ui_togglebutton(obj, .label =
"Suppress 3", .onchange = doc_suppress_state3, .onchangedata = doc2);
184 ui_togglebutton(obj, .label =
"Suppress 4", .onchange = doc_suppress_state4, .onchangedata = doc2);
185 }
186 }
187 }
188 }
189
190 ui_show(obj);
191 }
192
193
194 #ifndef UI_WIN32
195
196 int main(
int argc,
char **argv) {
197 ui_init(
NULL, argc, argv);
198 ui_onstartup(application_startup,
NULL);
199 ui_main();
200 return 0;
201 }
202
203 #else
204
205 int WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd) {
206
207
208
209 return 0;
210 }
211
212 #endif
213