ui/cocoa/toolbar.m

Fri, 28 Mar 2014 20:03:49 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 28 Mar 2014 20:03:49 +0100
changeset 11
979c0e0ee853
parent 7
431dde3c5fbe
child 14
e2fd132ab781
permissions
-rw-r--r--

merge

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"
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
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 static UiToolbarDelegate* toolbar_delegate;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 /* --------------------- UiToolbarStockItem --------------------- */
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 @implementation UiToolbarStockItem
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*) initWithIdentifier:(char*)identifier
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 stockID:(char*)sid
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 callback:(ui_callback)f
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 userdata:(void*)data
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 name = identifier;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 stockid = sid;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 callback = f;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 userdata = data;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 return self;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 }
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 - (NSToolbarItem *) createItem:(NSToolbar*)toolbar
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 identifier:(NSString*)identifier
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 {
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 if([s buttonImage] == nil && [s itemImage] == nil) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 return nil;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 */
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 *item = [[[NSToolbarItem alloc] initWithItemIdentifier:
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 identifier] autorelease];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 //[item setLabel:[s label]];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 //[item setPaletteLabel:[s label]];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 [item setLabel:@"Add"];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 [item setPaletteLabel:@"Operation"];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 // create button ...
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 NSRect frame = NSMakeRect(0, 0, 40, 22);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 //NSSearchField *sf = [[NSSearchField alloc]initWithFrame:frame];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 NSButton *button = [[NSButton alloc]initWithFrame:frame];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 //[button setImage:[s buttonImage]];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 [button setImage:[NSImage imageNamed: NSImageNameAddTemplate]];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 [button setBezelStyle: NSTexturedRoundedBezelStyle];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 [item setView:button];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 // event
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 EventWrapper *event = [[EventWrapper alloc]
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 initWithData:userdata callback:callback];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 [button setAction:@selector(handleEvent:)];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 [button setTarget:event];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 return item;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 }
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 @end
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95
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 /* --------------------- UiToolbarDelegate --------------------- */
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 @implementation UiToolbarDelegate
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 - (UiToolbarDelegate*) init {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 allowedItems = [[NSMutableArray alloc]initWithCapacity: 16];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 defaultItems = [[NSMutableArray alloc]initWithCapacity: 16];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 items = [[NSMutableDictionary alloc] init];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 return self;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 }
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 - (void) addDefault:(NSString*)identifier {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 [defaultItems addObject: identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 }
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 - (void) addItem: (NSString*) identifier
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 item: (NSObject<UiToolItem>*) item
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 [allowedItems addObject: identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 [items setObject: item forKey:identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 }
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 - (void) addStockItem:(char*)name
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 stockID:(char*)sid
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 callback:(ui_callback)f
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 data:(void*)userdata
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 UiToolbarStockItem *item = [[UiToolbarStockItem alloc]initWithData:name
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 stockID:sid callback:f data:userdata];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 NSString *s = [[NSString alloc]initWithUTF8String:name];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 [allowedItems addObject: s];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 [items setObject: item forKey:s];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 }
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 // implementation of NSToolbarDelegate methods
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 NSMutableArray *i = [[NSMutableArray alloc]
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 initWithCapacity:[allowedItems count] + 3];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 [i addObject: NSToolbarFlexibleSpaceItemIdentifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 [i addObject: NSToolbarSpaceItemIdentifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 [i addObject: NSToolbarSeparatorItemIdentifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 return i;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 return defaultItems;
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 - (NSToolbarItem *) toolbar:(NSToolbar*)toolbar
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 itemForItemIdentifier:(NSString*)identifier
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 willBeInsertedIntoToolbar:(BOOL)flag
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 Protocol *item = @protocol(UiToolItem);
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 item = [items objectForKey: identifier];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 return [item createItem:toolbar identifier:identifier];
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
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 @end
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 /* --------------------- functions --------------------- */
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 void ui_toolbar_init() {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 toolbar_delegate = [[UiToolbarDelegate alloc]init];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 }
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_toolitem_st(char *name, char *stockid, ui_callback f, void *udata) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 UiToolbarStockItem *item = [[UiToolbarStockItem alloc]
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 initWithIdentifier: name
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 stockID: stockid
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 callback: f
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 userdata: udata];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 NSString *identifier = [[NSString alloc]initWithUTF8String:name];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 [toolbar_delegate addItem: identifier item: item];
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
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 void ui_toolbar_add_default(char *name) {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 NSString *identifier = [[NSString alloc]initWithUTF8String:name];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 [toolbar_delegate addDefault: identifier];
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
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 NSToolbar* ui_create_toolbar() {
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 NSToolbar *toolbar = [[NSToolbar alloc]initWithIdentifier: @"MainToolbar"];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 [toolbar setDelegate: toolbar_delegate];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 [toolbar setAllowsUserCustomization: true];
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 return toolbar;
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 }
431dde3c5fbe added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188

mercurial