ui/cocoa/toolkit.m

changeset 7
431dde3c5fbe
child 10
6f263196f916
equal deleted inserted replaced
6:05a18c56d9ca 7:431dde3c5fbe
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2012 Olaf Wintermann. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #import <stdio.h>
30 #import <stdlib.h>
31 #import <sys/stat.h>
32 #import <sys/types.h>
33 #import <errno.h>
34
35 #import "../common/document.h"
36
37 #import "toolkit.h"
38 #import "window.h"
39 #import "toolbar.h"
40
41
42 NSAutoreleasePool *pool;
43
44 static char *application_name;
45
46 static ui_callback appclose_fnc;
47 static void *appclose_udata;
48
49 void ui_init(char *appname, int argc, char **argv) {
50 pool = [[NSAutoreleasePool alloc] init];
51 [NSApplication sharedApplication];
52 [NSBundle loadNibNamed:@"MainMenu" owner:NSApp];
53
54
55 uic_docmgr_init();
56 ui_toolbar_init();
57 // load item stock
58 // ui_init_stock();
59 }
60
61 void ui_show(UiObject *obj) {
62 if([obj->widget class] == [UiCocoaWindow class]) {
63 UiCocoaWindow *window = (UiCocoaWindow*)obj->widget;
64 [window makeKeyAndOrderFront:nil];
65 } else {
66 printf("Error: ui_show: Object is not a Window!\n");
67 }
68 }
69
70 void ui_main() {
71 [NSApp run];
72 [pool release];
73 }
74
75
76
77 @implementation EventWrapper
78
79 - (EventWrapper*) initWithData: (void*)d callback:(ui_callback) f {
80 data = d;
81 callback = f;
82 return self;
83 }
84
85
86 - (void*) data {
87 return data;
88 }
89
90 - (void) setData:(void*)d {
91 data = d;
92 }
93
94
95 - (ui_callback) callback {
96 return callback;
97 }
98
99 - (void) setCallback: (ui_callback)f {
100 callback = f;
101 }
102
103
104 - (BOOL)handleEvent:(id)sender {
105 NSWindow *activeWindow = [NSApp keyWindow];
106
107 UiEvent event;
108 if([activeWindow class] == [UiCocoaWindow class]) {
109 event.obj = [(UiCocoaWindow*)activeWindow object];
110 event.window = event.obj->window;
111 event.document = event.obj->document;
112 event.intval = 0;
113 }
114 if(callback) {
115 callback(&event, data);
116 }
117
118 return true;
119 }
120
121 @end

mercurial