UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2024 Olaf Wintermann. All rights reserved. 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 #import "toolkit.h" 30 31 #include "../common/document.h" 32 #include "../common/properties.h" 33 #include "../common/menu.h" 34 #include "../common/toolbar.h" 35 #include "../common/threadpool.h" 36 37 #import "AppDelegate.h" 38 39 static const char *application_name; 40 41 static int app_argc; 42 static const char **app_argv; 43 44 static ui_callback startup_func; 45 static void *startup_data; 46 static ui_callback open_func; 47 void *open_data; 48 static ui_callback exit_func; 49 void *exit_data; 50 51 /* ------------------- App Init / Event Loop functions ------------------- */ 52 53 void ui_init(const char *appname, int argc, char **argv) { 54 application_name = appname; 55 app_argc = argc; 56 app_argv = (const char**)argv; 57 58 uic_init_global_context(); 59 60 uic_docmgr_init(); 61 uic_menu_init(); 62 uic_toolbar_init(); 63 64 uic_load_app_properties(); 65 66 [NSApplication sharedApplication]; 67 //[NSBundle loadNibNamed:@"MainMenu" owner:NSApp ]; 68 //[[NSBundle mainBundle] loadNibNamed:@"MainMenu" owner:NSApp topLevelObjects:&topLevelObjects]; 69 } 70 71 const char* ui_appname() { 72 return application_name; 73 } 74 75 void ui_onstartup(ui_callback f, void *userdata) { 76 startup_func = f; 77 startup_data = userdata; 78 } 79 80 void ui_onopen(ui_callback f, void *userdata) { 81 open_func = f; 82 open_data = userdata; 83 } 84 85 void ui_onexit(ui_callback f, void *userdata) { 86 exit_func = f; 87 exit_data = userdata; 88 } 89 90 void ui_cocoa_onstartup(void) { 91 UiEvent e; 92 e.obj = NULL; 93 e.window = NULL; 94 e.document = NULL; 95 e.eventdata = NULL; 96 e.intval = 0; 97 if(startup_func) { 98 startup_func(&e, startup_data); 99 } 100 } 101 102 void ui_cocoa_onopen(const char *file) { 103 UiEvent e; 104 e.obj = NULL; 105 e.window = NULL; 106 e.document = NULL; 107 e.eventdata = NULL; 108 e.intval = 0; 109 if(open_func) { 110 open_func(&e, open_data); 111 } 112 } 113 114 void ui_cocoa_onexit(void) { 115 UiEvent e; 116 e.obj = NULL; 117 e.window = NULL; 118 e.document = NULL; 119 e.eventdata = NULL; 120 e.intval = 0; 121 if(exit_func) { 122 exit_func(&e, exit_data); 123 } 124 } 125 126 void ui_main(void) { 127 NSApplicationMain(app_argc, app_argv); 128 } 129 130 /* ------------------- Window Visibility functions ------------------- */ 131 132 void ui_show(UiObject *obj) { 133 if(obj->wobj) { 134 NSWindow *window = (__bridge NSWindow*)obj->wobj; 135 [window makeKeyAndOrderFront:nil]; 136 } 137 } 138 139 void ui_close(UiObject *obj) { 140 141 } 142 143 /* ------------------- Job Control / Threadpool functions ------------------- */ 144 145 void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd) { 146 147 } 148 149 void ui_call_mainthread(ui_threadfunc tf, void* td) { 150 151 } 152