Thu, 01 Feb 2024 19:45:17 +0100
implement table dnd drop
0 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
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 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
31 | ||
32 | #include <ui/ui.h> | |
174 | 33 | #include <cx/buffer.h> |
34 | #include <cx/utils.h> | |
0 | 35 | |
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
36 | typedef struct { |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
37 | UiText *text; |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
38 | } MyDocument; |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
39 | |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
40 | MyDocument *doc1; |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
41 | MyDocument *doc2; |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
42 | |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
43 | |
162 | 44 | void action_menu(UiEvent *event, void *userdata) { |
164
1d912f78fd1d
fix some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
45 | printf("action_menu: %s\n", (char*)userdata); |
145
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
46 | } |
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
47 | |
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
48 | 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
|
49 | printf("button test\n"); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
50 | MyDocument *doc = event->document; |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
51 | if(!doc) { |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
52 | printf("no document\n"); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
53 | return; |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
54 | } |
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 | char *text = doc->text->get(doc->text); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
57 | printf("text: {\n%s\n}\n", text); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
58 | } |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
59 | |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
60 | void action_switch(UiEvent *event, void *userdata) { |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
61 | if(event->document == doc1) { |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
62 | ui_set_document(event->obj, doc2); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
63 | } else { |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
64 | ui_set_document(event->obj, doc1); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
65 | } |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
66 | } |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
67 | |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
68 | |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
69 | MyDocument* create_doc(void) { |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
70 | 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
|
71 | UiContext *docctx = ui_document_context(doc); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
72 | doc->text = ui_text_new(docctx, "text"); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
73 | return doc; |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
74 | } |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
75 | |
133
6dd780cbc8c6
using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
127
diff
changeset
|
76 | void application_startup(UiEvent *event, void *data) { |
136
1df2fb3d079c
adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
77 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
78 | UiObject *obj = ui_window("Test", NULL); |
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
79 | ui_textarea_nv(obj, "text"); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
80 | ui_button(obj, "Test", action_button, NULL); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
81 | ui_button(obj, "Switch Document", action_switch, NULL); |
137
c9b8b9e0cfe8
adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
82 | |
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
83 | doc1 = create_doc(); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
84 | doc2 = create_doc(); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
85 | |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
162
diff
changeset
|
86 | ui_attach_document(obj->ctx, doc1); |
136
1df2fb3d079c
adds gridwidth layout option (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
87 | |
133
6dd780cbc8c6
using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
127
diff
changeset
|
88 | ui_show(obj); |
95
29f5cd5f5367
added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
89 | } |
111
40dbf1a7526a
added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
90 | |
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
91 | int main(int argc, char** argv) { |
88
04c81be1c5a0
added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
92 | ui_init("app1", argc, argv); |
133
6dd780cbc8c6
using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
127
diff
changeset
|
93 | ui_onstartup(application_startup, NULL); |
88
04c81be1c5a0
added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
94 | |
133
6dd780cbc8c6
using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
127
diff
changeset
|
95 | // menu |
164
1d912f78fd1d
fix some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
96 | ui_menu("_File"); |
1d912f78fd1d
fix some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
97 | ui_menuitem("_Hello", action_menu, NULL); |
88
04c81be1c5a0
added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
98 | ui_submenu("Submenu1"); |
04c81be1c5a0
added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
99 | ui_submenu("Submenu2"); |
133
6dd780cbc8c6
using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
127
diff
changeset
|
100 | ui_menuitem("item2", action_menu, NULL); |
6dd780cbc8c6
using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
127
diff
changeset
|
101 | ui_submenu_end(); |
6dd780cbc8c6
using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
127
diff
changeset
|
102 | ui_menuitem("item3", action_menu, NULL); |
88
04c81be1c5a0
added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
103 | ui_submenu_end(); |
133
6dd780cbc8c6
using GtkApplication now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
127
diff
changeset
|
104 | ui_menuitem("item4", action_menu, NULL); |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
139
diff
changeset
|
105 | |
89
9a7e4a335b2b
added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
106 | |
88
04c81be1c5a0
added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
107 | ui_main(); |
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
108 | |
0 | 109 | return (EXIT_SUCCESS); |
110 | } |