ui/cocoa/toolbar.m

Fri, 04 Apr 2014 17:45:36 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 04 Apr 2014 17:45:36 +0200
changeset 24
06bceda81a03
parent 23
decc6bf584aa
child 25
78ae3efe463f
permissions
-rw-r--r--

added application properties

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>
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 "toolbar.h"
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
34 #import "stock.h"
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 static UiToolbarDelegate* toolbar_delegate;
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 /* --------------------- UiToolbarStockItem --------------------- */
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 UiToolbarStockItem
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 - (UiToolbarStockItem*) initWithIdentifier:(char*)identifier
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 stockID:(char*)sid
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 callback:(ui_callback)f
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 userdata:(void*)data
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 name = identifier;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 stockid = sid;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 callback = f;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 userdata = data;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 return self;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 - (NSToolbarItem *) createItem:(NSToolbar*)toolbar
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 identifier:(NSString*)identifier
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 UiStockItem *s = ui_get_stock_item(stockid);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 if(s == nil) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 printf("cannot find stock item\n");
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 return nil;
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
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 NSToolbarItem *item = [[[NSToolbarItem alloc] initWithItemIdentifier:
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 identifier] autorelease];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 //[item setLabel:[s label]];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 //[item setPaletteLabel:[s label]];
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
69 [item setLabel:s->label];
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 [item setPaletteLabel:@"Operation"];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 // create button ...
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 NSRect frame = NSMakeRect(0, 0, 40, 22);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 //NSSearchField *sf = [[NSSearchField alloc]initWithFrame:frame];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 NSButton *button = [[NSButton alloc]initWithFrame:frame];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 //[button setImage:[s buttonImage]];
14
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
77 //[button setImage:[NSImage imageNamed: NSImageNameAddTemplate]];
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
78 if(s->image) {
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
79 [button setImage:s->image];
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
80 } else {
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
81 [button setImage:[NSImage imageNamed: NSImageNameRemoveTemplate]];
e2fd132ab781 added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
82 }
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 [button setBezelStyle: NSTexturedRoundedBezelStyle];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 [item setView:button];
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 // event
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 EventWrapper *event = [[EventWrapper alloc]
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 initWithData:userdata callback:callback];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 [button setAction:@selector(handleEvent:)];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 [button setTarget:event];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 return item;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 @end
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 /* --------------------- UiToolbarDelegate --------------------- */
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 @implementation UiToolbarDelegate
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 - (UiToolbarDelegate*) init {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 allowedItems = [[NSMutableArray alloc]initWithCapacity: 16];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 defaultItems = [[NSMutableArray alloc]initWithCapacity: 16];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 items = [[NSMutableDictionary alloc] init];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 return self;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 - (void) addDefault:(NSString*)identifier {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 [defaultItems addObject: identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 - (void) addItem: (NSString*) identifier
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 item: (NSObject<UiToolItem>*) item
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 [allowedItems addObject: identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 [items setObject: item forKey:identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 /*
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 - (void) addStockItem:(char*)name
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 stockID:(char*)sid
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 callback:(ui_callback)f
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 data:(void*)userdata
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 UiToolbarStockItem *item = [[UiToolbarStockItem alloc]initWithData:name
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 stockID:sid callback:f data:userdata];
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 NSString *s = [[NSString alloc]initWithUTF8String:name];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 [allowedItems addObject: s];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 [items setObject: item forKey:s];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 */
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 // implementation of NSToolbarDelegate methods
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 NSMutableArray *i = [[NSMutableArray alloc]
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 initWithCapacity:[allowedItems count] + 3];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 [i addObject: NSToolbarFlexibleSpaceItemIdentifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 [i addObject: NSToolbarSpaceItemIdentifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 [i addObject: NSToolbarSeparatorItemIdentifier];
23
decc6bf584aa textarea automatically sets selection group (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
142 for(id item in allowedItems) {
decc6bf584aa textarea automatically sets selection group (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
143 [i addObject: item];
decc6bf584aa textarea automatically sets selection group (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
144 }
7
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 return i;
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
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 return defaultItems;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152
23
decc6bf584aa textarea automatically sets selection group (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
153 - (NSToolbarItem *) toolbar:(NSToolbar*)toolbar
7
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 itemForItemIdentifier:(NSString*)identifier
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 willBeInsertedIntoToolbar:(BOOL)flag
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 Protocol *item = @protocol(UiToolItem);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 item = [items objectForKey: identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 return [item createItem:toolbar identifier:identifier];
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 @end
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 /* --------------------- functions --------------------- */
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 void ui_toolbar_init() {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 toolbar_delegate = [[UiToolbarDelegate alloc]init];
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
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *udata) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 UiToolbarStockItem *item = [[UiToolbarStockItem alloc]
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 initWithIdentifier: name
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 stockID: stockid
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 callback: f
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 userdata: udata];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 NSString *identifier = [[NSString alloc]initWithUTF8String:name];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 [toolbar_delegate addItem: identifier item: item];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 void ui_toolbar_add_default(char *name) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 NSString *identifier = [[NSString alloc]initWithUTF8String:name];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 [toolbar_delegate addDefault: identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 NSToolbar* ui_create_toolbar() {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 NSToolbar *toolbar = [[NSToolbar alloc]initWithIdentifier: @"MainToolbar"];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 [toolbar setDelegate: toolbar_delegate];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 [toolbar setAllowsUserCustomization: true];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 return toolbar;
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

mercurial