Sun, 29 Sep 2024 18:51:03 +0200
use GtkFileDialog on newer gtk4 versions
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> |
28
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
30 | #include <stdlib.h> |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
31 | #include <string.h> |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #import "window.h" |
10
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
34 | #import "menu.h" |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #import "toolbar.h" |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #import "container.h" |
157 | 37 | #import <ucx/mempool.h> |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #import "../common/context.h" |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | static int window_default_width = 600; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | static int window_default_height = 500; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | @implementation UiCocoaWindow |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
14
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
45 | - (UiCocoaWindow*) init: (NSRect)frame object: (UiObject*)obj { |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
46 | self = [self initWithContentRect:frame |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
47 | styleMask:NSTitledWindowMask | |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
48 | NSResizableWindowMask | |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
49 | NSClosableWindowMask | |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
50 | NSMiniaturizableWindowMask |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
51 | backing:NSBackingStoreBuffered |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
52 | defer:false]; |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
53 | |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
54 | uiobj = obj; |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
55 | UcxAllocator *allocator = uiobj->ctx->mempool->allocator; |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
56 | menus = ucx_map_new_a(allocator, 8); |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
57 | items = ucx_map_new_a(allocator, 64); |
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 | return self; |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
60 | } |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
61 | |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | - (UiObject*) object { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | return uiobj; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | } |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | - (void) setObject:(UiObject*)obj { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | uiobj = obj; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | } |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | |
10
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
70 | - (void) setMenuItems:(UcxList*)menuItems { |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
71 | 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
|
72 | |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
73 | UCX_FOREACH(elm, menuItems) { |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
74 | UiStateItem *item = elm->data; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
75 | 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
|
76 | |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
77 | // 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
|
78 | 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
|
79 | windowItem->item = item->item; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
80 | windowItem->state = 0; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
81 | if(item->var) { |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
82 | // bind value |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
83 | 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
|
84 | if(var) { |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
85 | UiInteger *value = var->value; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
86 | value->obj = windowItem; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
87 | 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
|
88 | 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
|
89 | value = 0; |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
90 | } else { |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
91 | // TODO: error |
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 | } |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
94 | |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
95 | // add item |
14
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
96 | UiAbstractMenuItem *abstractItem = malloc(sizeof(UiAbstractMenuItem)); |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
97 | abstractItem->update = ui_update_item; |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
98 | 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
|
99 | 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
|
100 | 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
|
101 | 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
|
102 | |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
103 | 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
|
104 | } |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
105 | } |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
106 | |
14
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
107 | - (void) setMenuItemLists:(UcxList*)itemLists { |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
108 | UcxAllocator *allocator = uiobj->ctx->mempool->allocator; |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
109 | |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
110 | UCX_FOREACH(elm, itemLists) { |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
111 | UiMenuItemList *list = elm->data; |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
112 | |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
113 | UiAbstractMenuItem *abstractItem = malloc(sizeof(UiAbstractMenuItem)); |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
114 | abstractItem->update = ui_update_item_list; |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
115 | abstractItem->item_data = list; |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
116 | |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
117 | 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
|
118 | 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
|
119 | 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
|
120 | |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
121 | } |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
122 | } |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
123 | |
10
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
124 | - (UiMenuItem*) getMenuItem:(NSMenuItem*)item { |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
125 | 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
|
126 | } |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
127 | |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
128 | - (void) updateMenu:(NSMenu*)menu { |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
129 | 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
|
130 | UCX_FOREACH(elm, itemList) { |
14
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
131 | UiAbstractMenuItem *item = elm->data; |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
132 | 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
|
133 | } |
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
134 | |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
135 | // update group items |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
136 | // TODO: use only one loop for all items |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
137 | int ngroups = 0; |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
138 | int *groups = ui_active_groups(uiobj->ctx, &ngroups); |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
139 | |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
140 | NSArray *groupItems = [menu itemArray]; |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
141 | int count = [groupItems count]; |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
142 | for(int i=0;i<count;i++) { |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
143 | id item = [groupItems objectAtIndex:i]; |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
144 | if([item class] == [UiGroupMenuItem class]) { |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
145 | [item checkGroups: groups count:ngroups]; |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
146 | } |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
147 | } |
23
decc6bf584aa
textarea automatically sets selection group (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
148 | free(groups); |
10
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
149 | } |
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
150 | |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | @end |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | /* ------------------------------ public API ------------------------------ */ |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | UiObject* ui_window(char *title, void *window_data) { |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | UcxMempool *mp = ucx_mempool_new(256); |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | UiObject *obj = ucx_mempool_calloc(mp, 1, sizeof(UiObject)); |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | obj->ctx = uic_context(obj, mp); |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | // create native window |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | NSRect frame = NSMakeRect( |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | 300, |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | 200, |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | window_default_width, |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | window_default_height); |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | |
14
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
168 | /* |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | UiCocoaWindow *window = [[UiCocoaWindow alloc] initWithContentRect:frame |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | styleMask:NSTitledWindowMask | NSResizableWindowMask | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | NSClosableWindowMask | NSMiniaturizableWindowMask |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | backing:NSBackingStoreBuffered |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | defer:false]; |
14
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
174 | */ |
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
175 | UiCocoaWindow *window = [[UiCocoaWindow alloc] init:frame object:obj]; |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | NSString *titleStr = [[NSString alloc] initWithUTF8String:title]; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | [window setTitle:titleStr]; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | |
10
6f263196f916
added Cocoa implementation for menu check items (with bugs)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
180 | 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
|
181 | [window setMenuItems: [menuDelegate items]]; |
14
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
182 | [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
|
183 | |
25
78ae3efe463f
added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
184 | NSToolbar *toolbar = ui_create_toolbar(obj); |
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | [window setToolbar: toolbar]; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | obj->widget = (NSView*)window; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | obj->window = window_data; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | obj->container = ui_window_container(obj, window); |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | return obj; |
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | } |
28
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
194 | |
47
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
195 | void ui_close(UiObject *obj) { |
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
196 | // TODO |
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
197 | } |
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
198 | |
28
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
199 | char* ui_openfiledialog(UiObject *obj) { |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
200 | NSOpenPanel* op = [NSOpenPanel openPanel]; |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
201 | if ([op runModal] == NSOKButton) { |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
202 | NSArray *urls = [op URLs]; |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
203 | NSURL *url = [urls objectAtIndex:0]; |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
204 | |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
205 | const char *str = [[url path] UTF8String]; |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
206 | return (char*)strdup(str); |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
207 | } |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
208 | return NULL; |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
209 | } |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
210 | |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
211 | char* ui_savefiledialog(UiObject *obj) { |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
212 | NSSavePanel* sp = [NSSavePanel savePanel]; |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
213 | if ([sp runModal] == NSOKButton) { |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
214 | NSURL *url = [sp URL]; |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
215 | |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
216 | const char *str = [[url path] UTF8String]; |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
217 | return (char*)strdup(str); |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
218 | } |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
219 | return NULL; |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
220 | } |