ui/cocoa/toolbar.m

Sun, 24 Jan 2016 19:23:49 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 24 Jan 2016 19:23:49 +0100
changeset 112
fdd33964b35f
parent 49
a80ba8741be6
child 126
f190d03dce0f
permissions
-rw-r--r--

added radio buttons (Motif)

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 2014 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 #import <stdio.h>
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #import <stdlib.h>
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #import <string.h>
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
32 #import <inttypes.h>
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
33 #import <stdarg.h>
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #import "toolbar.h"
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
36 #import "window.h"
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
37 #import "stock.h"
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
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 UiToolbarDelegate* toolbar_delegate;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 /* --------------------- UiToolbarStockItem --------------------- */
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 @implementation UiToolbarStockItem
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 - (UiToolbarStockItem*) initWithIdentifier:(char*)identifier
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 stockID:(char*)sid
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 callback:(ui_callback)f
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 userdata:(void*)data
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 name = identifier;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 stockid = sid;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 callback = f;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 userdata = data;
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
55 groups = NULL;
49
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
56 isToggleButton = NO;
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 return self;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
49
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
60 - (void) setIsToggleButton:(BOOL)t {
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
61 isToggleButton = t;
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
62 }
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
63
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
64 - (void) addGroup:(int)group {
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
65 groups = ucx_list_append(groups, (void*)(intptr_t)group);
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
66 }
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
67
7
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 - (NSToolbarItem *) createItem:(NSToolbar*)toolbar
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 identifier:(NSString*)identifier
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
71 object:(UiObject*)obj
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 UiStockItem *s = ui_get_stock_item(stockid);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 if(s == nil) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 printf("cannot find stock item\n");
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 return nil;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 NSToolbarItem *item = [[[NSToolbarItem alloc] initWithItemIdentifier:
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 identifier] autorelease];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 //[item setLabel:[s label]];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 //[item setPaletteLabel:[s label]];
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
83 [item setLabel:s->label];
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 [item setPaletteLabel:@"Operation"];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 // create button ...
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 NSRect frame = NSMakeRect(0, 0, 40, 22);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 //NSSearchField *sf = [[NSSearchField alloc]initWithFrame:frame];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 NSButton *button = [[NSButton alloc]initWithFrame:frame];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 //[button setImage:[s buttonImage]];
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
91 //[button setImage:[NSImage imageNamed: NSImageNameAddTemplate]];
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
92 if(s->image) {
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
93 [button setImage:s->image];
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
94 } else {
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
95 [button setImage:[NSImage imageNamed: NSImageNameRemoveTemplate]];
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
96 }
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 [button setBezelStyle: NSTexturedRoundedBezelStyle];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 // event
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 EventWrapper *event = [[EventWrapper alloc]
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 initWithData:userdata callback:callback];
49
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
102 if(isToggleButton) {
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
103 [button setButtonType: NSPushOnPushOffButton];
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
104 [button setAction:@selector(handleToggleEvent:)];
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
105 } else {
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
106 [button setAction:@selector(handleEvent:)];
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
107 }
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 [button setTarget:event];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
110 if(groups) {
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
111 uic_add_group_widget(obj->ctx, item, groups);
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
112 }
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
113
49
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
114 [item setView:button];
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 return item;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
118 - (UcxList*) groups {
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
119 return groups;
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
120 }
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
121
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 @end
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 /* --------------------- UiToolbarDelegate --------------------- */
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 @implementation UiToolbarDelegate
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 - (UiToolbarDelegate*) init {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 allowedItems = [[NSMutableArray alloc]initWithCapacity: 16];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 defaultItems = [[NSMutableArray alloc]initWithCapacity: 16];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 items = [[NSMutableDictionary alloc] init];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 return self;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 }
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 - (void) addDefault:(NSString*)identifier {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 [defaultItems addObject: identifier];
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
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 - (void) addItem: (NSString*) identifier
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 item: (NSObject<UiToolItem>*) item
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 [allowedItems addObject: identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 [items setObject: item forKey:identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 /*
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 - (void) addStockItem:(char*)name
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 stockID:(char*)sid
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 callback:(ui_callback)f
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 data:(void*)userdata
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 UiToolbarStockItem *item = [[UiToolbarStockItem alloc]initWithData:name
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 stockID:sid callback:f data:userdata];
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 NSString *s = [[NSString alloc]initWithUTF8String:name];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 [allowedItems addObject: s];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 [items setObject: item forKey:s];
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 */
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 // implementation of NSToolbarDelegate methods
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 NSMutableArray *i = [[NSMutableArray alloc]
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 initWithCapacity:[allowedItems count] + 3];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 [i addObject: NSToolbarFlexibleSpaceItemIdentifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 [i addObject: NSToolbarSpaceItemIdentifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 [i addObject: NSToolbarSeparatorItemIdentifier];
23
decc6bf584aa textarea automatically sets selection group (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
169 for(id item in allowedItems) {
decc6bf584aa textarea automatically sets selection group (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
170 [i addObject: item];
decc6bf584aa textarea automatically sets selection group (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
171 }
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 return i;
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 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 return defaultItems;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179
23
decc6bf584aa textarea automatically sets selection group (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
180 - (NSToolbarItem *) toolbar:(NSToolbar*)toolbar
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 itemForItemIdentifier:(NSString*)identifier
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 willBeInsertedIntoToolbar:(BOOL)flag
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 Protocol *item = @protocol(UiToolItem);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 item = [items objectForKey: identifier];
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
186
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
187 // get UiObject from toolbar
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
188 UiObject *obj = [(UiToolbar*)toolbar object];
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
189
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
190 // create new NSToolbarItem
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
191 return [item createItem:toolbar identifier:identifier object:obj];
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
192 }
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
193
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
194 @end
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
195
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
196
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
197 @implementation UiToolbar
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
198
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
199 - (UiToolbar*) initWithObject:(UiObject*)object {
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
200 [self initWithIdentifier: @"MainToolbar"];
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
201 obj = object;
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
202 return self;
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
203 }
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
204
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
205 - (UiObject*) object {
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
206 return obj;
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 @end
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 /* --------------------- functions --------------------- */
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 void ui_toolbar_init() {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 toolbar_delegate = [[UiToolbarDelegate alloc]init];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *udata) {
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
219 ui_toolitem_stgr(name, stockid, f, udata, -1);
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
220 }
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
221
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
222 void ui_toolitem_stgr(char *name, char *stockid, ui_callback f, void *udata, ...) {
49
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
223 va_list ap;
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
224 va_start(ap, udata);
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
225 ui_toolbar_stock_button(name, stockid, NO, f, udata, ap);
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
226 va_end(ap);
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
227 }
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
228
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
229 void ui_toolitem_toggle_st(char *name, char *stockid, ui_callback f, void *udata) {
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
230 ui_toolitem_toggle_stgr(name, stockid, f, udata, -1);
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
231 }
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
232
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
233 void ui_toolitem_toggle_stgr(char *name, char *stockid, ui_callback f, void *udata, ...) {
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
234 va_list ap;
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
235 va_start(ap, udata);
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
236 ui_toolbar_stock_button(name, stockid, YES, f, udata, ap);
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
237 va_end(ap);
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
238 }
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
239
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
240
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
241 void ui_toolbar_stock_button(char *name, char *stockid, BOOL toggle, ui_callback f, void *udata, va_list ap) {
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 UiToolbarStockItem *item = [[UiToolbarStockItem alloc]
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 initWithIdentifier: name
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
244 stockID: stockid
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
245 callback: f
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
246 userdata: udata];
49
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
247 [item setIsToggleButton: toggle];
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 NSString *identifier = [[NSString alloc]initWithUTF8String:name];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 [toolbar_delegate addItem: identifier item: item];
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
250
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
251 // add groups
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
252 int group;
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
253 while((group = va_arg(ap, int)) != -1) {
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
254 [item addGroup: group];
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
255 }
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257
49
a80ba8741be6 added toolbar toggle button (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
258
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 void ui_toolbar_add_default(char *name) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 NSString *identifier = [[NSString alloc]initWithUTF8String:name];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 [toolbar_delegate addDefault: identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
264 NSToolbar* ui_create_toolbar(UiObject *obj) {
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
265 UiToolbar *toolbar = [[UiToolbar alloc] initWithObject:obj];
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 [toolbar setDelegate: toolbar_delegate];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 [toolbar setAllowsUserCustomization: true];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 return toolbar;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270

mercurial