Wed, 09 Dec 2020 11:32:01 +0100
add existing toolkit source
0
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2012 Olaf Wintermann. All rights reserved. |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #import <stdio.h> |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #import <stdlib.h> |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #import <sys/stat.h> |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #import <sys/types.h> |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #import <errno.h> |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #import "../common/context.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #import "../common/document.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #import "../common/properties.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #import "toolkit.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #import "window.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #import "menu.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #import "toolbar.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | #import "stock.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | NSAutoreleasePool *pool; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | static char *application_name; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | static ui_callback appclose_fnc; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | static void *appclose_udata; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | static ui_callback openfile_fnc; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | static void *openfile_udata; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | void ui_init(char *appname, int argc, char **argv) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | pool = [[NSAutoreleasePool alloc] init]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | [NSApplication sharedApplication]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | [NSBundle loadNibNamed:@"MainMenu" owner:NSApp]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | UiApplicationDelegate *delegate = [[UiApplicationDelegate alloc]init]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | [NSApp setDelegate: delegate]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | uic_docmgr_init(); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | ui_menu_init(); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | ui_toolbar_init(); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | ui_stock_init(); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | uic_load_app_properties(); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | char* ui_appname() { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | return application_name; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | void ui_exitfunc(ui_callback f, void *userdata) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | appclose_fnc = f; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | appclose_udata = userdata; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | void ui_openfilefunc(ui_callback f, void *userdata) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | openfile_fnc = f; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | openfile_udata = userdata; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | void ui_show(UiObject *obj) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | uic_check_group_widgets(obj->ctx); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | if([obj->widget class] == [UiCocoaWindow class]) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | UiCocoaWindow *window = (UiCocoaWindow*)obj->widget; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | [window makeKeyAndOrderFront:nil]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | } else { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | printf("Error: ui_show: Object is not a Window!\n"); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | void ui_set_show_all(UIWIDGET widget, int value) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | // TODO |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | void ui_set_visible(UIWIDGET widget, int visible) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | // TODO |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | void ui_set_enabled(UIWIDGET widget, int enabled) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | [(id)widget setEnabled: enabled]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | UiThread *thread = [[UiThread alloc]initWithObject:obj]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | [thread setJobFunction:tf]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | [thread setJobData:td]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | [thread setFinishCallback:f]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | [thread setFinishData:fd]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | [thread start]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | void ui_main() { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | [NSApp run]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | [pool release]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | void ui_clipboard_set(char *str) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | NSString *string = [[NSString alloc] initWithUTF8String:str]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | NSPasteboard * pasteBoard = [NSPasteboard generalPasteboard]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | [pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | [pasteBoard setString:string forType:NSStringPboardType]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | char* ui_clipboard_get() { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | NSPasteboard * pasteBoard = [NSPasteboard generalPasteboard]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | NSArray *classes = [[NSArray alloc] initWithObjects:[NSString class], nil]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | NSDictionary *options = [NSDictionary dictionary]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | NSArray *data = [pasteBoard readObjectsForClasses:classes options:options]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | if(data != nil) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | NSString *str = [data componentsJoinedByString: @""]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | // copy C string |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | size_t length = [str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | const char *cstr = [str UTF8String]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | char *value = malloc(length + 1); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | memcpy(value, cstr, length); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | value[length] = '\0'; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | return value; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | } else { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | return NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | @implementation UiApplicationDelegate |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | - (void)applicationWillTerminate:(NSNotification*)notification { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | printf("terminate\n"); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | - (BOOL)applicationShouldHandleReopen:(NSApplication *)app hasVisibleWindows:(BOOL)visible; { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | if(!visible) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | printf("reopen\n"); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | return NO; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | - (BOOL)application:(NSApplication*)application openFile:(NSString*)filename { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | if(openfile_fnc) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | UiEvent event; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | event.obj = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | event.document = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | event.window = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | event.eventdata = (void*)[filename UTF8String]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | event.intval = 0; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | openfile_fnc(&event, openfile_udata); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | return NO; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | @end |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | @implementation EventWrapper |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | - (EventWrapper*) initWithData: (void*)d callback:(ui_callback) f { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | data = d; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | callback = f; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | value = 0; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | return self; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | - (void*) data { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | return data; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | - (void) setData:(void*)d { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | data = d; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | - (ui_callback) callback { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | return callback; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | - (void) setCallback: (ui_callback)f { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | callback = f; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | - (int) intval { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | return value; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | - (void) setIntval:(int)i { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | value = i; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | - (BOOL)handleEvent:(id)sender { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | NSWindow *activeWindow = [NSApp keyWindow]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | UiEvent event; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | event.eventdata = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | if([activeWindow class] == [UiCocoaWindow class]) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | event.obj = [(UiCocoaWindow*)activeWindow object]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | event.window = event.obj->window; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | event.document = event.obj->ctx->document; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | event.intval = value; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | if(callback) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | callback(&event, data); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | return true; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | - (BOOL)handleStateEvent:(id)sender { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | NSWindow *activeWindow = [NSApp keyWindow]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | int state = [sender state] ? NSOffState : NSOnState; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | UiEvent event; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | event.intval = state; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | event.eventdata = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | if([activeWindow class] == [UiCocoaWindow class]) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | event.obj = [(UiCocoaWindow*)activeWindow object]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | event.window = event.obj->window; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | event.document = event.obj->ctx->document; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | // if the sender is a menu item, we have to save the state for this |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | // window |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | UiMenuItem *wmi = [(UiCocoaWindow*)activeWindow getMenuItem: sender]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | if(wmi) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | // update state in window data |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | wmi->state = state; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | } else { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | event.window = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | event.document = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | if(callback) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | callback(&event, data); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | [sender setState: state]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | return true; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | - (BOOL)handleToggleEvent:(id)sender { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | NSWindow *activeWindow = [NSApp keyWindow]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | UiEvent event; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | event.intval = [sender state]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | event.eventdata = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | if([activeWindow class] == [UiCocoaWindow class]) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | event.obj = [(UiCocoaWindow*)activeWindow object]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | event.window = event.obj->window; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | event.document = event.obj->ctx->document; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | } else { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | event.window = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | event.document = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | if(callback) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | callback(&event, data); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | return true; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | @end |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | @implementation UiThread |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | - (id) initWithObject:(UiObject*)object { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | obj = object; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | job_func = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | job_data = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | finish_callback = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | finish_data = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | return self; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | - (void) setJobFunction:(ui_threadfunc)func { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304 | job_func = func; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | - (void) setJobData:(void*)data { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | job_data = data; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311 | - (void) setFinishCallback:(ui_callback)callback { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
312 | finish_callback = callback; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
315 | - (void) setFinishData:(void*)data { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316 | finish_data = data; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
317 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | - (void) start { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320 | [NSThread detachNewThreadSelector:@selector(runJob:) |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321 | toTarget:self |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | withObject:nil]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325 | - (void) runJob:(id)n { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
326 | int result = job_func(job_data); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327 | if(!result) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328 | [self performSelectorOnMainThread:@selector(finish:) |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329 | withObject:nil |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330 | waitUntilDone:NO]; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
334 | - (void) finish:(id)n { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335 | UiEvent event; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | event.obj = obj; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337 | event.window = obj->window; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | event.document = obj->ctx->document; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339 | event.eventdata = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | event.intval = 0; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | finish_callback(&event, finish_data); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344 | @end |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 |