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