application/main.c

changeset 2
eeb50c534497
parent 1
eb5269000bc8
child 3
c1a75454b444
equal deleted inserted replaced
1:eb5269000bc8 2:eeb50c534497
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 31
32 #include <ui/ui.h> 32 #include <ui/ui.h>
33 33
34 typedef struct TestDocument {
35 UiInteger check1;
36 } TestDocument;
37
38 typedef struct TestWindowData {
39 TestDocument *doc1;
40 TestDocument *doc2;
41 } TestWindowData;
42
34 UiInteger check1; 43 UiInteger check1;
35 44
36 void action_new(UiEvent *event, void *data) { 45 void action_new(UiEvent *event, void *data) {
37 UiObject *window = ui_window("Mod1", NULL); 46 UiObject *window = ui_window("Mod1", NULL);
38 //ui_window_addint(window, "check1"); 47 //ui_window_addint(window, "check1");
39 ui_show(window); 48 ui_show(window);
40 } 49 }
41 50
42 void action_open(UiEvent *event, void *data) { 51 void action_open(UiEvent *event, void *data) {
43 printf("check1: %s\n", ui_window_getint(event->obj, "check1") ? "true" : "false"); 52 //printf("check1: %s\n", ui_getint(event->obj, "check1") ? "true" : "false");
53 TestDocument *doc = event->document;
54 printf("check1: %s\n", ui_getval(doc->check1) ? "true" : "false");
44 } 55 }
45 56
46 void action_close(UiEvent *event, void *data) { 57 void action_close(UiEvent *event, void *data) {
47 exit(0); 58 exit(0);
59 }
60
61 void action_doc1(UiEvent *event, void *data) {
62 TestWindowData *wdata = event->window;
63 if(event->obj->document != wdata->doc1) {
64 ui_set_document(event->obj, wdata->doc1);
65 }
66 }
67
68 void action_doc2(UiEvent *event, void *data) {
69 TestWindowData *wdata = event->window;
70 if(event->obj->document != wdata->doc2) {
71 ui_set_document(event->obj, wdata->doc2);
72 }
48 } 73 }
49 74
50 int main(int argc, char** argv) { 75 int main(int argc, char** argv) {
51 ui_init("app1", argc, argv); 76 ui_init("app1", argc, argv);
52 77
53 ui_menu("File"); 78 ui_menu("File");
54 ui_menuitem("New", action_new, NULL); 79 ui_menuitem("New", action_new, NULL);
55 ui_menuitem("Open", action_open, NULL); 80 ui_menuitem("Open", action_open, NULL);
56 ui_menuseparator(); 81 ui_menuseparator();
82 ui_menuitem("Dokument 1", action_doc1, NULL);
83 ui_menuitem("Dokument 2", action_doc2, NULL);
84 ui_menuseparator();
57 ui_checkitem_nv("Check", "check1"); 85 ui_checkitem_nv("Check", "check1");
58 ui_menuitem("Close", action_close, NULL); 86 ui_menuitem("Close", action_close, NULL);
59 87
60 UiObject *window = ui_window("Mod0", NULL); 88 UiObject *window = ui_window("Mod0", NULL);
89 TestWindowData *wdata = malloc(sizeof(TestWindowData));
90 window->window = wdata;
61 91
92 TestDocument *doc1 = ui_document_new(sizeof(TestDocument));
93 TestDocument *doc2 = ui_document_new(sizeof(TestDocument));
94 ui_document_regint(doc1, "check1", &doc1->check1);
95 ui_document_regint(doc2, "check1", &doc2->check1);
96 wdata->doc1 = doc1;
97 wdata->doc2 = doc2;
62 98
99 ui_set_document(window, doc1);
63 100
64 //ui_window_addint(window, "check1"); 101 //ui_window_addint(window, "check1");
65 ui_show(window); 102 ui_show(window);
66 ui_main(); 103 ui_main();
67 104

mercurial