application/main.c

Sat, 23 Jan 2016 20:47:07 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 23 Jan 2016 20:47:07 +0100
changeset 106
a4f4123ca12a
parent 104
3efe0210e27e
child 107
9aff1dc3990d
permissions
-rw-r--r--

added simple window and open/save file dialogs for Qt

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 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2012 Olaf Wintermann. All rights reserved.
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>
28
794a5c91c479 added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
33 #include <ucx/buffer.h>
794a5c91c479 added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
34 #include <ucx/utils.h>
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
82
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
36 void action_menu(UiEvent *event, void *data) {
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
37 printf("action_menu test: {%s}\n", data);
88
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
38 printf("text: {%s}\n", ui_gettext(event->obj, "text"));
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
39 fflush(stdout);
106
a4f4123ca12a added simple window and open/save file dialogs for Qt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
40
a4f4123ca12a added simple window and open/save file dialogs for Qt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
41 char *file = ui_openfiledialog(event->obj);
a4f4123ca12a added simple window and open/save file dialogs for Qt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
42 printf("file: %s\n", file);
a4f4123ca12a added simple window and open/save file dialogs for Qt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
43 fflush(stdout);
a4f4123ca12a added simple window and open/save file dialogs for Qt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
44 free(file);
88
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
45 }
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
46
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
47 void action_button(UiEvent *event, void *data) {
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
48 printf("button clicked\n");
82
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
49 fflush(stdout);
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
50 }
103
6a6718269c22 added drawing area (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
51
95
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
52 void draw(UiEvent *event, UiGraphics *g, void *data) {
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
53 /*
95
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
54 int width = g->width;
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
55 int height = g->height;
103
6a6718269c22 added drawing area (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
56 printf("rec[%d,%d]\n", width, height);
6a6718269c22 added drawing area (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
57
95
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
58 ui_graphics_color(g, 64, 64, 64);
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
59 ui_draw_rect(g, 0, 0, width, height, TRUE);
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
60
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
61 UiTextLayout *text = ui_text(g);
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
62 ui_text_setfont(text, "Monospace", 12);
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
63 ui_text_setstring(text, "Hello World");
97
1a786201465f implemented text layout functions (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
64 int w, h;
1a786201465f implemented text layout functions (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
65 ui_text_getsize(text, &w, &h);
99
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
66 //printf("ext[%d,%d]\n", w, h);
95
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
67
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
68 ui_graphics_color(g, 255, 255, 255);
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
69 ui_draw_text(g, 50, 50, text);
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
70
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
71 ui_text_free(text);
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
72 */
95
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
73 }
29f5cd5f5367 added drawing area (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
74
98
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
75 void click(UiEvent *event, void *data) {
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
76 UiMouseEvent *me = event->eventdata;
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
77 printf("click[%d](%d,%d)\n", me->type, me->x, me->y);
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
78 }
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
79
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
80 int main(int argc, char** argv) {
88
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
81 ui_init("app1", argc, argv);
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
82
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
83 ui_menu("File");
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
84 ui_menuitem("Hello", action_menu, "hello");
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
85 ui_submenu("Submenu1");
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
86 ui_submenu("Submenu2");
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
87 ui_menuitem("item2", NULL, NULL);
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
88 ui_submenu_end();
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
89 ui_menuitem("item3", NULL, NULL);
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
90 ui_submenu_end();
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
91 ui_menuitem("item4", NULL, NULL);
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
92
89
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
93 ui_toolitem("button1", "Test", action_button, NULL);
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
94 ui_toolitem("button2", "OK", action_button, NULL);
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
95 ui_toolbar_add_default("button1");
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
96 ui_toolbar_add_default("button2");
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
97
88
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
98 UiObject *obj = ui_window("Test", NULL);
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
99 //UIWIDGET w = ui_drawingarea(obj, draw, NULL);
99
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
100 //ui_mouse_handler(obj, w, click, NULL);
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
101
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
102 ///*
102
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
103 ui_grid_sp(obj, 8, 4, 4);
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
104
99
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
105 ui_button(obj, "OK", NULL, NULL);
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
106 ui_layout_hexpand(obj, TRUE);
99
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
107 ui_button(obj, "Google", NULL, NULL);
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
108 ui_textfield(obj, NULL);
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
109 ui_newline(obj);
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
110
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
111 ui_vbox(obj);
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
112 ui_button(obj, "txt", NULL, NULL);
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
113 ui_textfield(obj, NULL);
99
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
114 ui_end(obj);
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
115 ui_layout_hexpand(obj, TRUE);
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
116 ui_layout_vexpand(obj, TRUE);
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
117 ui_textarea(obj, NULL);
101
1c943d43fa81 implemented grid container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
118 ui_button(obj, "BTN1", NULL, NULL);
99
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
119
ea1a2d5de765 improved grid container (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
120 ui_end(obj);
104
3efe0210e27e added grid spacing (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
121 //*/
94
d51e334c1439 added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
122
88
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
123 ui_show(obj);
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
124 ui_main();
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
125
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 return (EXIT_SUCCESS);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 }

mercurial