ui/cocoa/window.m

Wed, 02 Apr 2014 09:59:38 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 02 Apr 2014 09:59:38 +0200
changeset 18
06be29a56f8b
parent 14
e2fd132ab781
child 20
2dda1ad6dc7a
permissions
-rw-r--r--

added menu accelerators

7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2012 Olaf Wintermann. All rights reserved.
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #import "window.h"
10
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
32 #import "menu.h"
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #import "toolbar.h"
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #import "container.h"
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #import "../../ucx/mempool.h"
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #import "../common/context.h"
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 static int window_default_width = 600;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 static int window_default_height = 500;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 @implementation UiCocoaWindow
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
43 - (UiCocoaWindow*) init: (NSRect)frame object: (UiObject*)obj {
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
44 self = [self initWithContentRect:frame
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
45 styleMask:NSTitledWindowMask |
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
46 NSResizableWindowMask |
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
47 NSClosableWindowMask |
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
48 NSMiniaturizableWindowMask
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
49 backing:NSBackingStoreBuffered
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
50 defer:false];
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
51
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
52 uiobj = obj;
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
53 UcxAllocator *allocator = uiobj->ctx->mempool->allocator;
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
54 menus = ucx_map_new_a(allocator, 8);
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
55 items = ucx_map_new_a(allocator, 64);
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
56
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
57 return self;
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
58 }
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
59
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 - (UiObject*) object {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 return uiobj;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 - (void) setObject:(UiObject*)obj {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 uiobj = obj;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
10
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
68 - (void) setMenuItems:(UcxList*)menuItems {
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
69 UcxAllocator *allocator = uiobj->ctx->mempool->allocator;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
70
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
71 UCX_FOREACH(elm, menuItems) {
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
72 UiStateItem *item = elm->data;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
73 NSMenu *menu = [item->item menu];
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
74
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
75 // create UiMenuItem which represents an NSMenuItem for a Window
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
76 UiMenuItem *windowItem = ucx_mempool_malloc(uiobj->ctx->mempool, sizeof(UiMenuItem));
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
77 windowItem->item = item->item;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
78 windowItem->state = 0;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
79 if(item->var) {
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
80 // bind value
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
81 UiVar *var = uic_connect_var(uiobj->ctx, item->var, UI_VAR_INTEGER);
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
82 if(var) {
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
83 UiInteger *value = var->value;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
84 value->obj = windowItem;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
85 value->get = ui_menuitem_get;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
86 value->set = ui_menuitem_set;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
87 value = 0;
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
88 } else {
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
89 // TODO: error
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
90 }
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
91 }
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
92
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
93 // add item
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
94 UiAbstractMenuItem *abstractItem = malloc(sizeof(UiAbstractMenuItem));
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
95 abstractItem->update = ui_update_item;
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
96 abstractItem->item_data = windowItem;
10
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
97 UcxList *itemList = ucx_map_get(menus, ucx_key(&menu, sizeof(void*)));
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
98 itemList = ucx_list_append_a(allocator, itemList, abstractItem);
10
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
99 ucx_map_put(menus, ucx_key(&menu, sizeof(void*)), itemList);
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
100
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
101 ucx_map_put(items, ucx_key(&windowItem->item, sizeof(void*)), windowItem);
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
102 }
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
103 }
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
104
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
105 - (void) setMenuItemLists:(UcxList*)itemLists {
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
106 UcxAllocator *allocator = uiobj->ctx->mempool->allocator;
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
107
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
108 UCX_FOREACH(elm, itemLists) {
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
109 UiMenuItemList *list = elm->data;
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
110
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
111 UiAbstractMenuItem *abstractItem = malloc(sizeof(UiAbstractMenuItem));
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
112 abstractItem->update = ui_update_item_list;
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
113 abstractItem->item_data = list;
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
114
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
115 UcxList *itemList = ucx_map_get(menus, ucx_key(&list->menu, sizeof(void*)));
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
116 itemList = ucx_list_append_a(allocator, itemList, abstractItem);
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
117 ucx_map_put(menus, ucx_key(&list->menu, sizeof(void*)), itemList);
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
118
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
119 }
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
120 }
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
121
10
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
122 - (UiMenuItem*) getMenuItem:(NSMenuItem*)item {
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
123 return ucx_map_get(items, ucx_key(&item, sizeof(void*)));
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
124 }
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
125
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
126 - (void) updateMenu:(NSMenu*)menu {
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
127 UcxList *itemList = ucx_map_get(menus, ucx_key(&menu, sizeof(void*)));
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
128 UCX_FOREACH(elm, itemList) {
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
129 UiAbstractMenuItem *item = elm->data;
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
130 item->update(self, item->item_data);
10
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
131 }
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
132 }
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
133
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 @end
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 /* ------------------------------ public API ------------------------------ */
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 UiObject* ui_window(char *title, void *window_data) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 UcxMempool *mp = ucx_mempool_new(256);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 UiObject *obj = ucx_mempool_calloc(mp, 1, sizeof(UiObject));
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 obj->ctx = uic_context(obj, mp);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 // create native window
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 NSRect frame = NSMakeRect(
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 300,
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 200,
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 window_default_width,
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 window_default_height);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
151 /*
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 UiCocoaWindow *window = [[UiCocoaWindow alloc] initWithContentRect:frame
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 styleMask:NSTitledWindowMask | NSResizableWindowMask |
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 NSClosableWindowMask | NSMiniaturizableWindowMask
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 backing:NSBackingStoreBuffered
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 defer:false];
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
157 */
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
158 UiCocoaWindow *window = [[UiCocoaWindow alloc] init:frame object:obj];
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 NSString *titleStr = [[NSString alloc] initWithUTF8String:title];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 [window setTitle:titleStr];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162
10
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
163 UiMenuDelegate *menuDelegate = ui_menu_delegate();
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
164 [window setMenuItems: [menuDelegate items]];
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
165 [window setMenuItemLists: [menuDelegate lists]];
10
6f263196f916 added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
166
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 NSToolbar *toolbar = ui_create_toolbar();
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 [window setToolbar: toolbar];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 obj->widget = (NSView*)window;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 obj->window = window_data;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 obj->document = NULL;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 obj->container = ui_window_container(obj, window);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 return obj;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 }

mercurial