ui/cocoa/toolkit.m

changeset 963
90b349cdd47f
parent 870
e167cf006213
equal deleted inserted replaced
962:7016bcb8d38b 963:90b349cdd47f
31 #include "../common/document.h" 31 #include "../common/document.h"
32 #include "../common/properties.h" 32 #include "../common/properties.h"
33 #include "../common/menu.h" 33 #include "../common/menu.h"
34 #include "../common/toolbar.h" 34 #include "../common/toolbar.h"
35 #include "../common/threadpool.h" 35 #include "../common/threadpool.h"
36 #include "../common/app.h"
36 37
37 #import "image.h" 38 #import "image.h"
38 #import "menu.h" 39 #import "menu.h"
39 #import "Toolbar.h" 40 #import "Toolbar.h"
40 #import "UiThread.h" 41 #import "UiThread.h"
43 44
44 static const char *application_name; 45 static const char *application_name;
45 46
46 static int app_argc; 47 static int app_argc;
47 static const char **app_argv; 48 static const char **app_argv;
48
49 static ui_callback startup_func;
50 static void *startup_data;
51 static ui_callback open_func;
52 static void *open_data;
53 static ui_callback exit_func;
54 static void *exit_data;
55 49
56 static UiBool exit_on_shutdown; 50 static UiBool exit_on_shutdown;
57 51
58 /* ------------------- App Init / Event Loop functions ------------------- */ 52 /* ------------------- App Init / Event Loop functions ------------------- */
59 53
83 77
84 const char* ui_appname() { 78 const char* ui_appname() {
85 return application_name; 79 return application_name;
86 } 80 }
87 81
88 void ui_onstartup(ui_callback f, void *userdata) {
89 startup_func = f;
90 startup_data = userdata;
91 }
92
93 void ui_onopen(ui_callback f, void *userdata) {
94 open_func = f;
95 open_data = userdata;
96 }
97
98 void ui_onexit(ui_callback f, void *userdata) {
99 exit_func = f;
100 exit_data = userdata;
101 }
102
103 void ui_app_exit_on_shutdown(UiBool exitapp) { 82 void ui_app_exit_on_shutdown(UiBool exitapp) {
104 exit_on_shutdown = exitapp; 83 exit_on_shutdown = exitapp;
105 } 84 }
106 85
107 void ui_cocoa_onstartup(void) { 86 void ui_cocoa_onstartup(void) {
109 e.obj = NULL; 88 e.obj = NULL;
110 e.window = NULL; 89 e.window = NULL;
111 e.document = NULL; 90 e.document = NULL;
112 e.eventdata = NULL; 91 e.eventdata = NULL;
113 e.intval = 0; 92 e.intval = 0;
114 if(startup_func) { 93 uic_application_startup(&e);
115 startup_func(&e, startup_data);
116 }
117 } 94 }
118 95
119 void ui_cocoa_onopen(const char *file) { 96 void ui_cocoa_onopen(const char *file) {
120 UiEvent e; 97 UiEvent e;
121 e.obj = NULL; 98 e.obj = NULL;
122 e.window = NULL; 99 e.window = NULL;
123 e.document = NULL; 100 e.document = NULL;
124 e.eventdata = NULL; 101 e.eventdata = NULL;
125 e.intval = 0; 102 e.intval = 0;
126 if(open_func) { 103 uic_application_open(&e);
127 open_func(&e, open_data);
128 }
129 } 104 }
130 105
131 void ui_cocoa_onexit(void) { 106 void ui_cocoa_onexit(void) {
132 UiEvent e; 107 UiEvent e;
133 e.obj = NULL; 108 e.obj = NULL;
134 e.window = NULL; 109 e.window = NULL;
135 e.document = NULL; 110 e.document = NULL;
136 e.eventdata = NULL; 111 e.eventdata = NULL;
137 e.intval = 0; 112 e.intval = 0;
138 if(exit_func) { 113 uic_application_exit(&e);
139 exit_func(&e, exit_data);
140 }
141 } 114 }
142 115
143 void ui_main(void) { 116 void ui_main(void) {
144 NSApplicationMain(app_argc, app_argv); 117 NSApplicationMain(app_argc, app_argv);
145 if(exit_on_shutdown) { 118 if(exit_on_shutdown) {

mercurial