ui/cocoa/toolkit.m

changeset 1148
6ebe1b98f53b
parent 1146
35e098a663a7
child 1174
8b8da1adef7d
equal deleted inserted replaced
1147:30476eaff3ba 1148:6ebe1b98f53b
48 static const char *application_name; 48 static const char *application_name;
49 49
50 static int app_argc; 50 static int app_argc;
51 static const char **app_argv; 51 static const char **app_argv;
52 52
53 static UiBool exit_on_shutdown; 53 static UiBool exit_on_shutdown;
54
55 static char *main_thread_error_msg;
56
57 // This function is only used by language bindings, to improve error messages
58 // for example, when using java bindings, this can provide infos how to fix
59 // this (-XstartOnFirstThread)
60 void ui_set_main_thread_error_msg(const char *msg) {
61 main_thread_error_msg = msg ? strdup(msg) : NULL;
62 }
54 63
55 /* ------------------- App Init / Event Loop functions ------------------- */ 64 /* ------------------- App Init / Event Loop functions ------------------- */
56 65
57 static AppDelegate *app_delegate; 66 static AppDelegate *app_delegate;
58 67
68 static void main_thr_check(const char *func) {
69 if(![NSThread isMainThread]) {
70 fprintf(stderr, "Error: %s must run on the main thread.\n", func);
71 if(main_thread_error_msg) {
72 fprintf(stderr, "%s\n", main_thread_error_msg);
73 }
74 exit(1);
75 }
76 }
77
59 void ui_init(const char *appname, int argc, char **argv) { 78 void ui_init(const char *appname, int argc, char **argv) {
79 main_thr_check("ui_init");
80
60 application_name = appname ? strdup(appname) : NULL; 81 application_name = appname ? strdup(appname) : NULL;
61 app_argc = argc; 82 app_argc = argc;
62 app_argv = (const char**)argv; 83 app_argv = (const char**)argv;
63 84
64 uic_init_global_context(); 85 uic_init_global_context();
122 e.intval = 0; 143 e.intval = 0;
123 uic_application_exit(&e); 144 uic_application_exit(&e);
124 } 145 }
125 146
126 void ui_main(void) { 147 void ui_main(void) {
148 main_thr_check("ui_main");
149
127 NSApplicationMain(app_argc, app_argv); 150 NSApplicationMain(app_argc, app_argv);
128 //[NSApp finishLaunching]; 151 //[NSApp finishLaunching];
129 //[NSApp activateIgnoringOtherApps:YES]; 152 //[NSApp activateIgnoringOtherApps:YES];
130 //[NSApp run]; 153 //[NSApp run];
131 if(exit_on_shutdown) { 154 if(exit_on_shutdown) {

mercurial