# HG changeset patch # User Olaf Wintermann # Date 1395775509 -3600 # Node ID 431dde3c5fbe53614e4324be3e6542866427cff9 # Parent 05a18c56d9ca63ab50d717a59f9c829fb12a8d4b added Cocoa implementation diff -r 05a18c56d9ca -r 431dde3c5fbe application/main.c --- 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; diff -r 05a18c56d9ca -r 431dde3c5fbe make/cocoa_config.sh --- 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__ - - - - - - diff -r 05a18c56d9ca -r 431dde3c5fbe make/configure_cocoa.sh --- /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__ + + + + + + diff -r 05a18c56d9ca -r 431dde3c5fbe make/package_osx.sh --- 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/ diff -r 05a18c56d9ca -r 431dde3c5fbe resource/.DS_Store Binary file resource/.DS_Store has changed diff -r 05a18c56d9ca -r 431dde3c5fbe resource/template.app/Contents/Info.plist --- /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 @@ + + + + + BuildMachineOSBuild + 10K549 + CFBundleDevelopmentRegion + de_DE + CFBundleExecutable + mk12 + CFBundleIdentifier + com.yourcompany.Mk12 + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Test11 + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + DTCompiler + + DTPlatformBuild + 10M2518 + DTPlatformVersion + PG + DTSDKBuild + 10M2518 + DTSDKName + macosx10.6 + DTXcode + 0400 + DTXcodeBuild + 10M2518 + LSMinimumSystemVersion + 10.6 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff -r 05a18c56d9ca -r 431dde3c5fbe resource/template.app/Contents/PkgInfo --- /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 diff -r 05a18c56d9ca -r 431dde3c5fbe resource/template.app/Contents/Resources/English.lproj/InfoPlist.strings Binary file resource/template.app/Contents/Resources/English.lproj/InfoPlist.strings has changed diff -r 05a18c56d9ca -r 431dde3c5fbe resource/template.app/Contents/Resources/English.lproj/MainMenu.nib Binary file resource/template.app/Contents/Resources/English.lproj/MainMenu.nib has changed diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/Makefile --- /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) $< diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/container.h --- /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); diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/container.m --- /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 +#import + +#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]; +} diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/menu.h --- /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" + + diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/menu.m --- /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 +#import +#import + +#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() { + +} + + diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/objs.mk --- /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) diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/text.h --- /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); diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/text.m --- /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 +#import +#import + +#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]; +} diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/toolbar.h --- /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 { + 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 { + NSMutableArray *allowedItems; + NSMutableArray *defaultItems; + NSMutableDictionary *items; +} + +- (UiToolbarDelegate*) init; + +- (void) addDefault:(NSString*)identifier; + +- (void) addItem: (NSString*) identifier + item: (NSObject*) item; + +@end + + +void ui_toolbar_init(); +NSToolbar* ui_create_toolbar(); diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/toolbar.m --- /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 +#import +#import + +#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*) 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; +} + diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/toolkit.h --- /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 diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/toolkit.m --- /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 +#import +#import +#import +#import + +#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 diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/window.h --- /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 +#import "../ui/window.h" + + +@interface UiCocoaWindow : NSWindow { + UiObject *uiobj; +} + +- (UiObject*) object; +- (void) setObject:(UiObject*)obj; + +@end diff -r 05a18c56d9ca -r 431dde3c5fbe ui/cocoa/window.m --- /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 + +#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; +} diff -r 05a18c56d9ca -r 431dde3c5fbe ui/common/document.h --- 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 */ diff -r 05a18c56d9ca -r 431dde3c5fbe ui/ui/stock.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"