added Cocoa implementation

Tue, 25 Mar 2014 20:25:09 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 25 Mar 2014 20:25:09 +0100
changeset 7
431dde3c5fbe
parent 6
05a18c56d9ca
child 8
84a541c6e093

added Cocoa implementation

application/main.c file | annotate | diff | comparison | revisions
make/cocoa_config.sh file | annotate | diff | comparison | revisions
make/configure_cocoa.sh file | annotate | diff | comparison | revisions
make/package_osx.sh file | annotate | diff | comparison | revisions
resource/.DS_Store file | annotate | diff | comparison | revisions
resource/template.app/Contents/Info.plist file | annotate | diff | comparison | revisions
resource/template.app/Contents/PkgInfo file | annotate | diff | comparison | revisions
resource/template.app/Contents/Resources/English.lproj/InfoPlist.strings file | annotate | diff | comparison | revisions
resource/template.app/Contents/Resources/English.lproj/MainMenu.nib file | annotate | diff | comparison | revisions
ui/cocoa/Makefile file | annotate | diff | comparison | revisions
ui/cocoa/container.h file | annotate | diff | comparison | revisions
ui/cocoa/container.m file | annotate | diff | comparison | revisions
ui/cocoa/menu.h file | annotate | diff | comparison | revisions
ui/cocoa/menu.m file | annotate | diff | comparison | revisions
ui/cocoa/objs.mk file | annotate | diff | comparison | revisions
ui/cocoa/text.h file | annotate | diff | comparison | revisions
ui/cocoa/text.m file | annotate | diff | comparison | revisions
ui/cocoa/toolbar.h file | annotate | diff | comparison | revisions
ui/cocoa/toolbar.m file | annotate | diff | comparison | revisions
ui/cocoa/toolkit.h file | annotate | diff | comparison | revisions
ui/cocoa/toolkit.m file | annotate | diff | comparison | revisions
ui/cocoa/window.h file | annotate | diff | comparison | revisions
ui/cocoa/window.m file | annotate | diff | comparison | revisions
ui/common/document.h file | annotate | diff | comparison | revisions
ui/ui/stock.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Mon Mar 24 11:21:59 2014 +0100
+++ b/application/main.c	Tue Mar 25 20:25:09 2014 +0100
@@ -82,7 +82,7 @@
 void action_undo(UiEvent *event, void *data) {
     printf("undo\n");
     TestWindowData *wd = event->window;
-    ui_text_undo(&wd->text);
+    //ui_text_undo(&wd->text);
 }
 
 void action_redo(UiEvent *event, void *data) {
@@ -93,6 +93,7 @@
 int main(int argc, char** argv) {
     ui_init("app1", argc, argv);
     
+    
     ui_menu("File");
     ui_menuitem("New", action_new, NULL);
     ui_menuitem("Open", action_open, NULL);
@@ -100,9 +101,11 @@
     ui_menuitem("Dokument 1", action_doc1, NULL);
     ui_menuitem("Dokument 2", action_doc2, NULL);
     ui_menuseparator();
-    ui_checkitem_nv("Check", "check1");
+    //ui_checkitem_nv("Check", "check1");
     ui_menuitem("Close", action_close, NULL);
     
+    
+    
     ui_toolitem_st("new", UI_STOCK_NEW, action_new, NULL);
     ui_toolitem_st("open", UI_STOCK_OPEN, action_open, NULL);
     ui_toolitem_st("save", UI_STOCK_SAVE, action_save, NULL);
@@ -118,6 +121,7 @@
     ui_toolbar_add_default("redo");
     
     
+    printf("create window\n");
     UiObject *window = ui_window("Mod0", NULL);
     TestWindowData *wdata = malloc(sizeof(TestWindowData));
     window->window = wdata;
--- a/make/cocoa_config.sh	Mon Mar 24 11:21:59 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-#
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
-#
-# Copyright 2011 Olaf Wintermann. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-#   1. Redistributions of source code must retain the above copyright notice,
-#      this list of conditions and the following disclaimer.
-#
-#   2. Redistributions in binary form must reproduce the above copyright
-#      notice, this list of conditions and the following disclaimer in the
-#      documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-
-TK_CFLAGS="-DUI_COCOA"
-TK_LDFLAGS="-lobjc -framework Cocoa"
-
-cat >> config.mk << __EOF__
-
-# toolkit configuration
-CFLAGS += $TK_CFLAGS
-
-LDFLAGS += $TK_LDFLAGS
-
-TOOLKIT = cocoa
-
-__EOF__
-
-
-
-
- 
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/configure_cocoa.sh	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,47 @@
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+#
+# Copyright 2011 Olaf Wintermann. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#   1. Redistributions of source code must retain the above copyright notice,
+#      this list of conditions and the following disclaimer.
+#
+#   2. Redistributions in binary form must reproduce the above copyright
+#      notice, this list of conditions and the following disclaimer in the
+#      documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+TK_CFLAGS="-DUI_COCOA `xml2-config --cflags`"
+TK_LDFLAGS="-lobjc -framework Cocoa `xml2-config --libs`"
+
+cat >> config.mk << __EOF__
+
+# toolkit configuration
+CFLAGS += $TK_CFLAGS
+
+LDFLAGS += $TK_LDFLAGS
+
+TOOLKIT = cocoa
+
+__EOF__
+
+
+
+
+ 
+
--- a/make/package_osx.sh	Mon Mar 24 11:21:59 2014 +0100
+++ b/make/package_osx.sh	Tue Mar 25 20:25:09 2014 +0100
@@ -3,5 +3,6 @@
 # create .app
 cp -R resource/template.app build/mk12.app
 
-cp build/mk12 build/mk12.app/Contents/MacOS/
+mkdir -p build/mk12.app/Contents/MacOS/
+cp build/bin/mk12 build/mk12.app/Contents/MacOS/
 
Binary file resource/.DS_Store has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resource/template.app/Contents/Info.plist	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>BuildMachineOSBuild</key>
+	<string>10K549</string>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>de_DE</string>
+	<key>CFBundleExecutable</key>
+	<string>mk12</string>
+	<key>CFBundleIdentifier</key>
+	<string>com.yourcompany.Mk12</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleName</key>
+	<string>Test11</string>
+	<key>CFBundlePackageType</key>
+	<string>APPL</string>
+	<key>CFBundleShortVersionString</key>
+	<string>1.0</string>
+	<key>CFBundleSignature</key>
+	<string>????</string>
+	<key>CFBundleVersion</key>
+	<string>1</string>
+	<key>DTCompiler</key>
+	<string></string>
+	<key>DTPlatformBuild</key>
+	<string>10M2518</string>
+	<key>DTPlatformVersion</key>
+	<string>PG</string>
+	<key>DTSDKBuild</key>
+	<string>10M2518</string>
+	<key>DTSDKName</key>
+	<string>macosx10.6</string>
+	<key>DTXcode</key>
+	<string>0400</string>
+	<key>DTXcodeBuild</key>
+	<string>10M2518</string>
+	<key>LSMinimumSystemVersion</key>
+	<string>10.6</string>
+	<key>NSMainNibFile</key>
+	<string>MainMenu</string>
+	<key>NSPrincipalClass</key>
+	<string>NSApplication</string>
+</dict>
+</plist>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resource/template.app/Contents/PkgInfo	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,1 @@
+APPL????
\ No newline at end of file
Binary file resource/template.app/Contents/Resources/English.lproj/InfoPlist.strings has changed
Binary file resource/template.app/Contents/Resources/English.lproj/MainMenu.nib has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/Makefile	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,30 @@
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+#
+# Copyright 2012 Olaf Wintermann. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#   1. Redistributions of source code must retain the above copyright notice,
+#      this list of conditions and the following disclaimer.
+#
+#   2. Redistributions in binary form must reproduce the above copyright
+#      notice, this list of conditions and the following disclaimer in the
+#      documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+$(COCOA_OBJPRE)%.o: cocoa/%.m
+	$(CC) -o $@ -c $(CFLAGS) $<
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/container.h	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,42 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2014 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "../ui/toolkit.h"
+#import "toolkit.h"
+
+typedef void(*ui_container_add_f)(UiContainer*, NSView*);
+
+struct UiContainer {
+    NSView* widget;
+    void   (*add)(UiContainer*, NSView*);
+    NSRect (*getframe)(UiContainer*);
+};
+
+UiContainer* ui_window_container(UiObject *obj, NSWindow *window);
+void   ui_window_container_add(UiContainer *ct, NSView *view);
+NSRect ui_window_container_getframe(UiContainer *ct);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/container.m	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,52 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2014 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <stdio.h>
+#import <stdlib.h>
+
+#import "container.h"
+
+
+UiContainer* ui_window_container(UiObject *obj, NSWindow *window) {
+    UiContainer *ct = ucx_mempool_malloc(
+                                         obj->ctx->mempool,
+                                         sizeof(UiContainer));
+    ct->widget = (NSView*)window;
+    ct->add = ui_window_container_add;
+    ct->getframe = ui_window_container_getframe;
+    return ct;
+}
+
+void ui_window_container_add(UiContainer *ct, NSView *view) {
+    NSWindow *window = (NSWindow*)ct->widget;
+    [window setContentView:view];
+}
+
+NSRect ui_window_container_getframe(UiContainer *ct) {
+    [ct->widget frame];
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/menu.h	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,32 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2014 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "../ui/menu.h"
+#import "toolkit.h"
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/menu.m	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,70 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2014 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <stdio.h>
+#import <stdlib.h>
+#import <string.h>
+
+#import "menu.h"
+
+
+static NSMenu *currentMenu = NULL;
+
+void ui_menu(char *title) {
+    NSString *str = [[NSString alloc] initWithUTF8String:title];
+    
+    NSMenu *menu = [[NSMenu alloc] initWithTitle: str];
+    NSMenuItem *menuItem = [[NSApp mainMenu] addItemWithTitle:str
+                                                       action:nil keyEquivalent:@""];
+    
+    [[NSApp mainMenu] setSubmenu:menu forItem:menuItem];
+    currentMenu = menu;
+}
+
+void ui_menuitem(char *label, ui_callback f, void *data) {
+    EventWrapper *event = [[EventWrapper alloc]initWithData:data callback:f];
+    NSString *str = [[NSString alloc] initWithUTF8String:label];
+    
+    NSMenuItem *item = [currentMenu addItemWithTitle:str
+                                              action:@selector(handleEvent:) keyEquivalent:@""];
+    [item setTarget:event];
+}
+
+void ui_checkitem(char *label, ui_callback f, void *userdata) {
+    
+}
+
+void ui_checkitem_nv(char *label, char *vname) {
+    
+}
+
+void ui_menuseparator() {
+    
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/objs.mk	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,41 @@
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+#
+# Copyright 2012 Olaf Wintermann. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#   1. Redistributions of source code must retain the above copyright notice,
+#      this list of conditions and the following disclaimer.
+#
+#   2. Redistributions in binary form must reproduce the above copyright
+#      notice, this list of conditions and the following disclaimer in the
+#      documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+COCOA_SRC_DIR = ui/cocoa/
+COCOA_OBJPRE = $(OBJ_DIR)/$(COCOA_SRC_DIR)
+
+COCOAOBJ = toolkit.o
+COCOAOBJ += window.o
+COCOAOBJ += menu.o
+COCOAOBJ += toolbar.o
+COCOAOBJ += container.o
+COCOAOBJ += text.o
+
+
+TOOLKITOBJS = $(COCOAOBJ:%=$(COCOA_OBJPRE)%)
+TOOLKITSOURCE = $(COCOAOBJ:%.o=cocoa/%.m)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/text.h	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,33 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2014 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "../ui/text.h"
+#import "toolkit.h"
+
+char* ui_textarea_get(UiText *text);
+void ui_textarea_set(UiText *text, char *str);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/text.m	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,78 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2014 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <stdio.h>
+#import <stdlib.h>
+#import <string.h>
+
+#import "text.h"
+#import "container.h"
+
+UIWIDGET ui_textarea(UiObject *obj, UiText *value) {
+    UiContainer *ct = uic_get_current_container(obj);
+    
+    NSRect frame = ct->getframe(ct);
+    
+    NSScrollView *scrollview = [[NSScrollView alloc] initWithFrame:frame];
+    [scrollview setHasVerticalScroller:YES];
+    //[scrollvew setHasHorizontalScroller:YES];
+    [scrollview setBorderType:NSNoBorder];
+    //[scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
+    
+    //frame.size.width = frame.size.width - 15;
+    NSTextView *textview = [[NSTextView alloc]initWithFrame:frame];
+    [textview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
+    
+    [scrollview setDocumentView:textview];
+    
+    ct->add(ct, scrollview);
+    
+    // bind value
+    if(value) {
+        value->get = ui_textarea_get;
+        value->set = ui_textarea_set;
+        value->value = NULL;
+        value->obj = textview;
+        
+    }
+    
+    return textview;
+}
+
+char* ui_textarea_get(UiText *text) {
+    NSTextView *textview = (NSTextView*)text->obj;
+    NSString *str = [[textview textStorage]string];
+    return (char*)[str UTF8String];
+}
+
+void ui_textarea_set(UiText *text, char *str) {
+    NSTextView *textview = (NSTextView*)text->obj;
+    NSString *s = [[NSString alloc]initWithUTF8String:str];
+    NSAttributedString *as = [[NSAttributedString alloc]initWithString:s];
+    [[textview textStorage] setAttributedString:as];
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/toolbar.h	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,79 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2014 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "../ui/toolbar.h"
+#import "toolkit.h"
+
+
+@protocol UiToolItem
+- (NSToolbarItem *) createItem:(NSToolbar*)toolbar
+                    identifier:(NSString*)identifier;
+@end
+
+
+/*
+ * UiToolbarStockItem
+ *
+ * creates a toolbar item from stock description
+ */
+@interface UiToolbarStockItem : NSObject <UiToolItem> {
+    char          *name;
+    char          *stockid;
+    ui_callback   callback;
+    void          *userdata;
+}
+
+- (UiToolbarStockItem*) initWithIdentifier:(char*)identifier
+                             stockID:(char*)sid
+                            callback:(ui_callback)f
+                            userdata:(void*)data;
+
+@end
+
+
+/*
+ * UiToolbarDelegate
+ */
+@interface UiToolbarDelegate : NSObject <NSToolbarDelegate> {
+    NSMutableArray      *allowedItems;
+    NSMutableArray      *defaultItems;
+    NSMutableDictionary *items;
+}
+
+- (UiToolbarDelegate*) init;
+
+- (void) addDefault:(NSString*)identifier;
+
+- (void) addItem: (NSString*) identifier
+            item: (NSObject<UiToolItem>*) item;
+
+@end
+
+
+void ui_toolbar_init();
+NSToolbar* ui_create_toolbar();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/toolbar.m	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,188 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2014 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <stdio.h>
+#import <stdlib.h>
+#import <string.h>
+
+#import "toolbar.h"
+
+
+static UiToolbarDelegate* toolbar_delegate;
+
+/* ---------------------      UiToolbarStockItem     --------------------- */
+
+@implementation UiToolbarStockItem
+
+- (UiToolbarStockItem*) initWithIdentifier:(char*)identifier
+                                   stockID:(char*)sid
+                                  callback:(ui_callback)f
+                                  userdata:(void*)data
+{
+    name = identifier;
+    stockid = sid;
+    callback = f;
+    userdata = data;
+    return self;
+}
+
+
+- (NSToolbarItem *) createItem:(NSToolbar*)toolbar
+                    identifier:(NSString*)identifier
+{
+    /*
+    UiStockItem *s = ui_get_stock_item(stockid);
+    if(s == nil) {
+        printf("cannot find stock item\n");
+        return nil;
+    }
+    if([s buttonImage] == nil && [s itemImage] == nil) {
+        return nil;
+    }
+    */
+    
+    NSToolbarItem *item = [[[NSToolbarItem alloc] initWithItemIdentifier:
+                            identifier] autorelease];
+    //[item setLabel:[s label]];
+    //[item setPaletteLabel:[s label]];
+    [item setLabel:@"Add"];
+    [item setPaletteLabel:@"Operation"];
+    
+    // create button ...
+    NSRect frame = NSMakeRect(0, 0, 40, 22);
+    //NSSearchField *sf = [[NSSearchField alloc]initWithFrame:frame];
+    NSButton *button = [[NSButton alloc]initWithFrame:frame];
+    //[button setImage:[s buttonImage]];
+    [button setImage:[NSImage imageNamed: NSImageNameAddTemplate]];
+    [button setBezelStyle: NSTexturedRoundedBezelStyle];
+    [item setView:button];
+    
+    // event
+    EventWrapper *event = [[EventWrapper alloc]
+                           initWithData:userdata callback:callback];
+    [button setAction:@selector(handleEvent:)];
+    [button setTarget:event];
+    
+    return item;
+}
+
+@end
+
+
+/* ---------------------      UiToolbarDelegate      --------------------- */
+
+@implementation UiToolbarDelegate
+
+- (UiToolbarDelegate*) init {
+    allowedItems = [[NSMutableArray alloc]initWithCapacity: 16];
+    defaultItems = [[NSMutableArray alloc]initWithCapacity: 16];
+    items = [[NSMutableDictionary alloc] init];
+    return self;
+}
+
+- (void) addDefault:(NSString*)identifier {
+    [defaultItems addObject: identifier];
+}
+
+- (void) addItem: (NSString*) identifier
+            item: (NSObject<UiToolItem>*) item
+{
+    [allowedItems addObject: identifier];
+    [items setObject: item forKey:identifier];
+}
+
+/*
+- (void) addStockItem:(char*)name
+              stockID:(char*)sid
+             callback:(ui_callback)f
+                 data:(void*)userdata
+{
+    UiToolbarStockItem *item = [[UiToolbarStockItem alloc]initWithData:name
+                                                               stockID:sid callback:f data:userdata];
+    
+    NSString *s = [[NSString alloc]initWithUTF8String:name];
+    [allowedItems addObject: s];
+    [items setObject: item forKey:s];
+}
+*/
+
+// implementation of NSToolbarDelegate methods
+- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
+    NSMutableArray *i = [[NSMutableArray alloc]
+                         initWithCapacity:[allowedItems count] + 3];
+    [i addObject: NSToolbarFlexibleSpaceItemIdentifier];
+    [i addObject: NSToolbarSpaceItemIdentifier];
+    [i addObject: NSToolbarSeparatorItemIdentifier];
+    
+    return i;
+}
+
+- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
+    return defaultItems;
+}
+
+- (NSToolbarItem *)    toolbar:(NSToolbar*)toolbar
+         itemForItemIdentifier:(NSString*)identifier
+     willBeInsertedIntoToolbar:(BOOL)flag
+{
+    Protocol *item = @protocol(UiToolItem);
+    item = [items objectForKey: identifier];
+    return [item createItem:toolbar identifier:identifier];
+}
+
+@end
+
+
+/* ---------------------          functions          --------------------- */
+
+void ui_toolbar_init() {
+    toolbar_delegate = [[UiToolbarDelegate alloc]init];
+}
+
+void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *udata) {
+    UiToolbarStockItem *item = [[UiToolbarStockItem alloc]
+                                initWithIdentifier: name
+                                           stockID: stockid
+                                          callback: f
+                                          userdata: udata];
+    NSString *identifier = [[NSString alloc]initWithUTF8String:name];
+    [toolbar_delegate addItem: identifier item: item];
+}
+
+void ui_toolbar_add_default(char *name) {
+    NSString *identifier = [[NSString alloc]initWithUTF8String:name];
+    [toolbar_delegate addDefault: identifier];
+}
+
+NSToolbar* ui_create_toolbar() {
+    NSToolbar *toolbar = [[NSToolbar alloc]initWithIdentifier: @"MainToolbar"];
+    [toolbar setDelegate: toolbar_delegate];
+    [toolbar setAllowsUserCustomization: true];
+    return toolbar;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/toolkit.h	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,49 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2014 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "../ui/toolkit.h"
+#include "../common/context.h"
+#include "../common/object.h"
+
+@interface EventWrapper : NSObject {
+    void         *data;
+    ui_callback  callback;
+}
+
+- (EventWrapper*) initWithData: (void*)data callback:(ui_callback) f;
+
+- (void*) data;
+- (void) setData:(void*)d;
+
+- (ui_callback) callback;
+- (void) setCallback: (ui_callback)f;
+
+- (BOOL)handleEvent:(id)sender;
+
+@end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/toolkit.m	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,121 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2012 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <stdio.h>
+#import <stdlib.h>
+#import <sys/stat.h>
+#import <sys/types.h>
+#import <errno.h>
+
+#import "../common/document.h"
+
+#import "toolkit.h"
+#import "window.h"
+#import "toolbar.h"
+
+
+NSAutoreleasePool *pool;
+
+static char *application_name;
+
+static ui_callback appclose_fnc;
+static void *appclose_udata;
+
+void ui_init(char *appname, int argc, char **argv) {
+    pool = [[NSAutoreleasePool alloc] init];
+    [NSApplication sharedApplication];
+    [NSBundle loadNibNamed:@"MainMenu" owner:NSApp];
+    
+    
+    uic_docmgr_init();
+    ui_toolbar_init();
+    // load item stock
+    // ui_init_stock();
+}
+
+void ui_show(UiObject *obj) {
+    if([obj->widget class] == [UiCocoaWindow class]) {
+        UiCocoaWindow *window = (UiCocoaWindow*)obj->widget;
+        [window makeKeyAndOrderFront:nil];
+    } else {
+        printf("Error: ui_show: Object is not a Window!\n");
+    }
+}
+
+void ui_main() {
+    [NSApp run];
+    [pool release];
+}
+
+
+
+@implementation EventWrapper
+
+- (EventWrapper*) initWithData: (void*)d callback:(ui_callback) f {
+    data = d;
+    callback = f;
+    return self;
+}
+
+
+- (void*) data {
+    return data;
+}
+
+- (void) setData:(void*)d {
+    data = d;
+}
+
+
+- (ui_callback) callback {
+    return callback;
+}
+
+- (void) setCallback: (ui_callback)f {
+    callback = f;
+}
+
+
+- (BOOL)handleEvent:(id)sender {
+    NSWindow *activeWindow = [NSApp keyWindow];
+    
+    UiEvent event;
+    if([activeWindow class] == [UiCocoaWindow class]) {
+        event.obj = [(UiCocoaWindow*)activeWindow object];
+        event.window = event.obj->window;
+        event.document = event.obj->document;
+        event.intval = 0;
+    }
+    if(callback) {
+        callback(&event, data);
+    }
+    
+    return true;
+}
+
+@end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/window.h	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,40 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2012 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import "../ui/window.h"
+
+
+@interface UiCocoaWindow : NSWindow {
+    UiObject *uiobj;
+}
+
+- (UiObject*) object;
+- (void)  setObject:(UiObject*)obj;
+
+@end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/window.m	Tue Mar 25 20:25:09 2014 +0100
@@ -0,0 +1,87 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2012 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#import "window.h"
+#import "toolbar.h"
+#import "container.h"
+#import "../../ucx/mempool.h"
+#import "../common/context.h"
+
+static int window_default_width = 600;
+static int window_default_height = 500;
+
+@implementation UiCocoaWindow
+
+- (UiObject*) object {
+    return uiobj;
+}
+
+- (void)  setObject:(UiObject*)obj {
+    uiobj = obj;
+}
+
+@end
+
+
+/* ------------------------------ public API ------------------------------ */
+
+UiObject* ui_window(char *title, void *window_data) {
+    UcxMempool *mp = ucx_mempool_new(256);
+    UiObject *obj = ucx_mempool_calloc(mp, 1, sizeof(UiObject));
+    obj->ctx = uic_context(obj, mp);
+    
+    // create native window
+    NSRect frame = NSMakeRect(
+                              300,
+                              200,
+                              window_default_width,
+                              window_default_height);
+    
+    UiCocoaWindow *window = [[UiCocoaWindow alloc] initWithContentRect:frame
+                                styleMask:NSTitledWindowMask | NSResizableWindowMask |
+                                NSClosableWindowMask | NSMiniaturizableWindowMask
+                                backing:NSBackingStoreBuffered
+                                defer:false];
+    
+    [window setObject: obj];
+    NSString *titleStr = [[NSString alloc] initWithUTF8String:title];
+    [window setTitle:titleStr];
+    
+    NSToolbar *toolbar = ui_create_toolbar();
+    [window setToolbar: toolbar];
+    
+    obj->widget = (NSView*)window;
+    obj->window = window_data;
+    obj->document = NULL;
+    obj->container = ui_window_container(obj, window);
+    
+    
+    return obj;
+}
--- a/ui/common/document.h	Mon Mar 24 11:21:59 2014 +0100
+++ b/ui/common/document.h	Tue Mar 25 20:25:09 2014 +0100
@@ -26,8 +26,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef DOCUMENT_H
-#define	DOCUMENT_H
+#ifndef UIC_DOCUMENT_H
+#define	UIC_DOCUMENT_H
 
 #include "../ui/toolkit.h"
 #include "context.h"
@@ -70,5 +70,5 @@
 }
 #endif
 
-#endif	/* DOCUMENT_H */
+#endif	/* UIC_DOCUMENT_H */
 
--- a/ui/ui/stock.h	Mon Mar 24 11:21:59 2014 +0100
+++ b/ui/ui/stock.h	Tue Mar 25 20:25:09 2014 +0100
@@ -36,7 +36,7 @@
 #endif
 
 // motif stock ids
-#ifdef UI_MOTIF
+#if UI_MOTIF || UI_COCOA
     
 #define UI_STOCK_NEW                    "uiNew"
 #define UI_STOCK_OPEN                   "uiOpen"

mercurial