application/main.c

Mon, 12 Feb 2024 22:11:33 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 12 Feb 2024 22:11:33 +0100
branch
newapi
changeset 257
a334f9ebc5d0
parent 255
ebdce2bb62be
child 259
8cce275d2847
permissions
-rw-r--r--

update button, togglebutton and checkbox to the new API (GTK)

0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
144
29d98cff4f56 UiInteger uses int64 now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
4 * Copyright 2017 Olaf Wintermann. All rights reserved.
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1f419bd32da1 added files
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
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <ui/ui.h>
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
33 #include <cx/buffer.h>
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
34 #include <cx/utils.h>
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
36 typedef struct {
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
37 UiString *str1;
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
38 UiString *str2;
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
39 } MyDocument;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
40
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
41 MyDocument *doc1;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
42 MyDocument *doc2;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
43
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
44
162
18892c0a9adc ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 158
diff changeset
45 void action_menu(UiEvent *event, void *userdata) {
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
46
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
47 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
48
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
49 void action_button(UiEvent *event, void *userdata) {
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
50
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
51 }
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
52
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
53 void action_switch(UiEvent *event, void *userdata) {
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
54
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
55 }
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
56
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
57
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
58 MyDocument* create_doc(void) {
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
59 MyDocument *doc = ui_document_new(sizeof(MyDocument));
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
60 UiContext *docctx = ui_document_context(doc);
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
61 doc->str1 = ui_string_new(docctx, "str1");
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
62 doc->str1 = ui_string_new(docctx, "str2");
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
63 return doc;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
64 }
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
65
133
6dd780cbc8c6 using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
66 void application_startup(UiEvent *event, void *data) {
136
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
67
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
68 UiObject *obj = ui_window("Test", NULL);
137
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
69
257
a334f9ebc5d0 update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
70 ui_button(obj, .label = "Test Button");
a334f9ebc5d0 update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
71 ui_togglebutton(obj, .label = "Toggle");
a334f9ebc5d0 update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
72 ui_checkbox(obj, .label = "Checkbox");
136
1df2fb3d079c adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
73
133
6dd780cbc8c6 using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
74 ui_show(obj);
95
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
75 }
111
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
76
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
77 int main(int argc, char** argv) {
88
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
78 ui_init("app1", argc, argv);
133
6dd780cbc8c6 using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
79 ui_onstartup(application_startup, NULL);
88
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
80
133
6dd780cbc8c6 using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
81 // menu
255
ebdce2bb62be minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
82 ui_menu("File") {
ebdce2bb62be minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
83 ui_menuitem(.label = "Test");
ebdce2bb62be minimal working menubar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
84 }
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
85
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 139
diff changeset
86
89
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
87
88
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
88 ui_main();
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
89
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 return (EXIT_SUCCESS);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 }

mercurial