ui/cocoa/toolkit.m

changeset 29
c96169444d88
parent 26
a137277f9173
child 31
34df61c6ec3c
equal deleted inserted replaced
28:794a5c91c479 29:c96169444d88
43 43
44 NSAutoreleasePool *pool; 44 NSAutoreleasePool *pool;
45 45
46 static char *application_name; 46 static char *application_name;
47 47
48 static ui_callback appclose_fnc; 48 static ui_callback appclose_fnc;
49 static void *appclose_udata; 49 static void *appclose_udata;
50
51 static ui_callback openfile_fnc;
52 static void *openfile_udata;
50 53
51 void ui_init(char *appname, int argc, char **argv) { 54 void ui_init(char *appname, int argc, char **argv) {
52 pool = [[NSAutoreleasePool alloc] init]; 55 pool = [[NSAutoreleasePool alloc] init];
53 [NSApplication sharedApplication]; 56 [NSApplication sharedApplication];
54 [NSBundle loadNibNamed:@"MainMenu" owner:NSApp]; 57 [NSBundle loadNibNamed:@"MainMenu" owner:NSApp];
55 58
59 UiApplicationDelegate *delegate = [[UiApplicationDelegate alloc]init];
60 [NSApp setDelegate: delegate];
61
56 62
57 uic_docmgr_init(); 63 uic_docmgr_init();
58 ui_menu_init(); 64 ui_menu_init();
59 ui_toolbar_init(); 65 ui_toolbar_init();
60 ui_stock_init(); 66 ui_stock_init();
62 uic_load_app_properties(); 68 uic_load_app_properties();
63 } 69 }
64 70
65 char* ui_appname() { 71 char* ui_appname() {
66 return application_name; 72 return application_name;
73 }
74
75 void ui_exitfunc(ui_callback f, void *userdata) {
76 appclose_fnc = f;
77 appclose_udata = userdata;
78 }
79
80 void ui_openfilefunc(ui_callback f, void *userdata) {
81 openfile_fnc = f;
82 openfile_udata = userdata;
67 } 83 }
68 84
69 void ui_show(UiObject *obj) { 85 void ui_show(UiObject *obj) {
70 uic_check_group_widgets(obj->ctx); 86 uic_check_group_widgets(obj->ctx);
71 if([obj->widget class] == [UiCocoaWindow class]) { 87 if([obj->widget class] == [UiCocoaWindow class]) {
113 } else { 129 } else {
114 return NULL; 130 return NULL;
115 } 131 }
116 } 132 }
117 133
134
135 @implementation UiApplicationDelegate
136
137 - (void)applicationWillTerminate:(NSNotification*)notification {
138 printf("terminate\n");
139 }
140
141 - (BOOL)applicationShouldHandleReopen:(NSApplication *)app hasVisibleWindows:(BOOL)visible; {
142 if(!visible) {
143 printf("reopen\n");
144 }
145 return NO;
146 }
147
148 - (BOOL)application:(NSApplication*)application openFile:(NSString*)filename {
149 if(openfile_fnc) {
150 UiEvent event;
151 event.obj = NULL;
152 event.document = NULL;
153 event.window = NULL;
154 event.eventdata = (void*)[filename UTF8String];
155 event.intval = 0;
156 openfile_fnc(&event, openfile_udata);
157 }
158
159 return NO;
160 }
161
162 @end
163
164
118 @implementation EventWrapper 165 @implementation EventWrapper
119 166
120 - (EventWrapper*) initWithData: (void*)d callback:(ui_callback) f { 167 - (EventWrapper*) initWithData: (void*)d callback:(ui_callback) f {
121 data = d; 168 data = d;
122 callback = f; 169 callback = f;

mercurial