ui/cocoa/toolkit.m

Sun, 06 Apr 2014 13:21:37 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 06 Apr 2014 13:21:37 +0200
changeset 28
794a5c91c479
parent 26
a137277f9173
child 29
c96169444d88
permissions
-rw-r--r--

added open/save dialogs

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
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 static ui_callback appclose_fnc;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 static void *appclose_udata;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 void ui_init(char *appname, int argc, char **argv) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 pool = [[NSAutoreleasePool alloc] init];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 [NSApplication sharedApplication];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 [NSBundle loadNibNamed:@"MainMenu" owner:NSApp];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 uic_docmgr_init();
10
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
58 ui_menu_init();
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 ui_toolbar_init();
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
60 ui_stock_init();
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
61
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
62 uic_load_app_properties();
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
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
65 char* ui_appname() {
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
66 return application_name;
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
67 }
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
68
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 void ui_show(UiObject *obj) {
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
70 uic_check_group_widgets(obj->ctx);
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 if([obj->widget class] == [UiCocoaWindow class]) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 UiCocoaWindow *window = (UiCocoaWindow*)obj->widget;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 [window makeKeyAndOrderFront:nil];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 } else {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 printf("Error: ui_show: Object is not a Window!\n");
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
79 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
80 [(id)widget setEnabled: enabled];
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
81 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
82
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 void ui_main() {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 [NSApp run];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 [pool release];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
26
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
89 void ui_clipboard_set(char *str) {
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
90 NSString *string = [[NSString alloc] initWithUTF8String:str];
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
91 NSPasteboard * pasteBoard = [NSPasteboard generalPasteboard];
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
92 [pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
93 [pasteBoard setString:string forType:NSStringPboardType];
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
94 }
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
95
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
96 char* ui_clipboard_get() {
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
97 NSPasteboard * pasteBoard = [NSPasteboard generalPasteboard];
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
98 NSArray *classes = [[NSArray alloc] initWithObjects:[NSString class], nil];
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
99 NSDictionary *options = [NSDictionary dictionary];
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
100 NSArray *data = [pasteBoard readObjectsForClasses:classes options:options];
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
101
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
102 if(data != nil) {
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
103 NSString *str = [data componentsJoinedByString: @""];
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
104
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
105 // copy C string
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
106 size_t length = [str lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
107 const char *cstr = [str UTF8String];
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
108 char *value = malloc(length + 1);
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
109 memcpy(value, cstr, length);
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
110 value[length] = '\0';
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 return value;
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
113 } else {
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
114 return NULL;
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
115 }
a137277f9173 added copy & paste (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
116 }
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 @implementation EventWrapper
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 - (EventWrapper*) initWithData: (void*)d callback:(ui_callback) f {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 data = d;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 callback = f;
15
7a36f91c22f7 fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
123 value = 0;
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 return self;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 - (void*) data {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 return data;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 - (void) setData:(void*)d {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 data = d;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 - (ui_callback) callback {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 return callback;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 - (void) setCallback: (ui_callback)f {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 callback = f;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
15
7a36f91c22f7 fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
145 - (int) intval {
7a36f91c22f7 fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
146 return value;
7a36f91c22f7 fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
147 }
7a36f91c22f7 fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
148
7a36f91c22f7 fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
149 - (void) setIntval:(int)i {
7a36f91c22f7 fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
150 value = i;
7a36f91c22f7 fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
151 }
7a36f91c22f7 fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
152
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 - (BOOL)handleEvent:(id)sender {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 NSWindow *activeWindow = [NSApp keyWindow];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 UiEvent event;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 if([activeWindow class] == [UiCocoaWindow class]) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 event.obj = [(UiCocoaWindow*)activeWindow object];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 event.window = event.obj->window;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 event.document = event.obj->document;
15
7a36f91c22f7 fixed menu update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
162 event.intval = value;
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 if(callback) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 callback(&event, data);
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
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 return true;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170
10
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
171 - (BOOL)handleStateEvent:(id)sender {
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
172 NSWindow *activeWindow = [NSApp keyWindow];
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
173 NSMenuItem *item = (NSMenuItem*)sender;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
174 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
175
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
176 UiEvent event;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
177 event.intval = state;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
178 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
179 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
180 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
181 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
182 // 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
183 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
184 wmi->state = state;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
185 } else {
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
186 event.window = NULL;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
187 event.document = NULL;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
188 }
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
189 if(callback) {
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
190 callback(&event, data);
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
191 }
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
192 [item setState: state];
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
193
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
194 return true;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
195 }
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
196
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 @end
10
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
198
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
199

mercurial