Fri, 16 May 2014 19:20:17 +0200
optimized selection callback (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 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #import "../common/document.h" |
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
36 | #import "../common/properties.h" |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #import "toolkit.h" |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #import "window.h" |
10
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
40 | #import "menu.h" |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #import "toolbar.h" |
14
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
42 | #import "stock.h" |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | NSAutoreleasePool *pool; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | static char *application_name; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
48 | static ui_callback appclose_fnc; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
49 | static void *appclose_udata; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
50 | |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
51 | static ui_callback openfile_fnc; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
52 | static void *openfile_udata; |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | void ui_init(char *appname, int argc, char **argv) { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | pool = [[NSAutoreleasePool alloc] init]; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | [NSApplication sharedApplication]; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | [NSBundle loadNibNamed:@"MainMenu" owner:NSApp]; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | |
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
59 | UiApplicationDelegate *delegate = [[UiApplicationDelegate alloc]init]; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
60 | [NSApp setDelegate: delegate]; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
61 | |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | uic_docmgr_init(); |
10
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
64 | ui_menu_init(); |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | ui_toolbar_init(); |
14
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
66 | ui_stock_init(); |
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
67 | |
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
68 | uic_load_app_properties(); |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | } |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | |
25
78ae3efe463f
added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
71 | char* ui_appname() { |
78ae3efe463f
added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
72 | return application_name; |
78ae3efe463f
added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
73 | } |
78ae3efe463f
added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
74 | |
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
75 | 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
|
76 | appclose_fnc = f; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
77 | appclose_udata = userdata; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
78 | } |
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 | 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
|
81 | openfile_fnc = f; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
82 | openfile_udata = userdata; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
83 | } |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
84 | |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | void ui_show(UiObject *obj) { |
25
78ae3efe463f
added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
86 | uic_check_group_widgets(obj->ctx); |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | if([obj->widget class] == [UiCocoaWindow class]) { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | UiCocoaWindow *window = (UiCocoaWindow*)obj->widget; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | [window makeKeyAndOrderFront:nil]; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | } else { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | printf("Error: ui_show: Object is not a Window!\n"); |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | } |
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 | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
95 | 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
|
96 | [(id)widget setEnabled: enabled]; |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
97 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
98 | |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | void ui_main() { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | [NSApp run]; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | [pool release]; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | } |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | |
26
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
105 | void ui_clipboard_set(char *str) { |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
106 | NSString *string = [[NSString alloc] initWithUTF8String:str]; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
107 | NSPasteboard * pasteBoard = [NSPasteboard generalPasteboard]; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
108 | [pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
109 | [pasteBoard setString:string forType:NSStringPboardType]; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
110 | } |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
111 | |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
112 | char* ui_clipboard_get() { |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
113 | NSPasteboard * pasteBoard = [NSPasteboard generalPasteboard]; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
114 | NSArray *classes = [[NSArray alloc] initWithObjects:[NSString class], nil]; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
115 | NSDictionary *options = [NSDictionary dictionary]; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
116 | NSArray *data = [pasteBoard readObjectsForClasses:classes options:options]; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
117 | |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
118 | if(data != nil) { |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
119 | NSString *str = [data componentsJoinedByString: @""]; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
120 | |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
121 | // copy C string |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
122 | size_t length = [str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
123 | const char *cstr = [str UTF8String]; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
124 | char *value = malloc(length + 1); |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
125 | memcpy(value, cstr, length); |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
126 | value[length] = '\0'; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
127 | |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
128 | return value; |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
129 | } else { |
a137277f9173
added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
130 | return NULL; |
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 | } |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | |
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
134 | |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
135 | @implementation UiApplicationDelegate |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
136 | |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
137 | - (void)applicationWillTerminate:(NSNotification*)notification { |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
138 | printf("terminate\n"); |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
139 | } |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
140 | |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
141 | - (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
|
142 | if(!visible) { |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
143 | printf("reopen\n"); |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
144 | } |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
145 | return NO; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
146 | } |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
147 | |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
148 | - (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
|
149 | if(openfile_fnc) { |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
150 | UiEvent event; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
151 | event.obj = NULL; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
152 | event.document = NULL; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
153 | event.window = NULL; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
154 | event.eventdata = (void*)[filename UTF8String]; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
155 | event.intval = 0; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
156 | openfile_fnc(&event, openfile_udata); |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
157 | } |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
158 | |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
159 | return NO; |
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 | |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
162 | @end |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
163 | |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
164 | |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | @implementation EventWrapper |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | - (EventWrapper*) initWithData: (void*)d callback:(ui_callback) f { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | data = d; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | callback = f; |
15
7a36f91c22f7
fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
170 | value = 0; |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | return self; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | } |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | - (void*) data { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | return data; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | } |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | - (void) setData:(void*)d { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | data = d; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | } |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | - (ui_callback) callback { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | return callback; |
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 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | - (void) setCallback: (ui_callback)f { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | callback = f; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | } |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | |
15
7a36f91c22f7
fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
192 | - (int) intval { |
7a36f91c22f7
fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
193 | return value; |
7a36f91c22f7
fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
194 | } |
7a36f91c22f7
fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
195 | |
7a36f91c22f7
fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
196 | - (void) setIntval:(int)i { |
7a36f91c22f7
fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
197 | value = i; |
7a36f91c22f7
fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
198 | } |
7a36f91c22f7
fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
199 | |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | - (BOOL)handleEvent:(id)sender { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | NSWindow *activeWindow = [NSApp keyWindow]; |
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 | UiEvent event; |
31
34df61c6ec3c
fixed cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
205 | event.eventdata = NULL; |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | if([activeWindow class] == [UiCocoaWindow class]) { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | event.obj = [(UiCocoaWindow*)activeWindow object]; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | event.window = event.obj->window; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | event.document = event.obj->document; |
15
7a36f91c22f7
fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
210 | event.intval = value; |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | } |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | if(callback) { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | callback(&event, data); |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | } |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | return true; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | } |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | |
10
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
219 | - (BOOL)handleStateEvent:(id)sender { |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
220 | NSWindow *activeWindow = [NSApp keyWindow]; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
221 | NSMenuItem *item = (NSMenuItem*)sender; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
222 | int state = [item state] ? NSOffState : NSOnState; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
223 | |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
224 | UiEvent event; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
225 | event.intval = state; |
31
34df61c6ec3c
fixed cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
226 | event.eventdata = NULL; |
10
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
227 | 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
|
228 | 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
|
229 | event.window = event.obj->window; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
230 | event.document = event.obj->document; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
231 | // update state in window data |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
232 | UiMenuItem *wmi = [(UiCocoaWindow*)activeWindow getMenuItem: sender]; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
233 | wmi->state = state; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
234 | } else { |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
235 | event.window = NULL; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
236 | event.document = NULL; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
237 | } |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
238 | if(callback) { |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
239 | callback(&event, data); |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
240 | } |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
241 | [item setState: state]; |
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 | return true; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
244 | } |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
245 | |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | @end |
10
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
247 | |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
248 |