ui/cocoa/toolbar.m

Wed, 09 Dec 2020 11:32:01 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 09 Dec 2020 11:32:01 +0100
changeset 0
804d8803eade
permissions
-rw-r--r--

add existing toolkit source

0
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
804d8803eade add existing toolkit source
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
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #import <stdio.h>
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #import <stdlib.h>
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #import <string.h>
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #import <inttypes.h>
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #import <stdarg.h>
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #import "toolbar.h"
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #import "window.h"
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #import "stock.h"
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 static UiToolbarDelegate* toolbar_delegate;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 /* --------------------- UiToolbarStockItem --------------------- */
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 @implementation UiToolbarStockItem
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 - (UiToolbarStockItem*) initWithIdentifier:(char*)identifier
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 stockID:(char*)sid
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 callback:(ui_callback)f
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 userdata:(void*)data
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 name = identifier;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 stockid = sid;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 callback = f;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 userdata = data;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 groups = NULL;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 isToggleButton = NO;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 return self;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 - (void) setIsToggleButton:(BOOL)t {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 isToggleButton = t;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 - (void) addGroup:(int)group {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 groups = ucx_list_append(groups, (void*)(intptr_t)group);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 - (NSToolbarItem *) createItem:(NSToolbar*)toolbar
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 identifier:(NSString*)identifier
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 object:(UiObject*)obj
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 UiStockItem *s = ui_get_stock_item(stockid);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 if(s == nil) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 printf("cannot find stock item\n");
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 return nil;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 NSToolbarItem *item = [[[NSToolbarItem alloc] initWithItemIdentifier:
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 identifier] autorelease];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 //[item setLabel:[s label]];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 //[item setPaletteLabel:[s label]];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 [item setLabel:s->label];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 [item setPaletteLabel:@"Operation"];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 // create button ...
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 NSRect frame = NSMakeRect(0, 0, 40, 22);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 //NSSearchField *sf = [[NSSearchField alloc]initWithFrame:frame];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 NSButton *button = [[NSButton alloc]initWithFrame:frame];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 //[button setImage:[s buttonImage]];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 //[button setImage:[NSImage imageNamed: NSImageNameAddTemplate]];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 if(s->image) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 [button setImage:s->image];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 } else {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 [button setImage:[NSImage imageNamed: NSImageNameRemoveTemplate]];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 [button setBezelStyle: NSTexturedRoundedBezelStyle];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 // event
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 EventWrapper *event = [[EventWrapper alloc]
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 initWithData:userdata callback:callback];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 if(isToggleButton) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 [button setButtonType: NSPushOnPushOffButton];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 [button setAction:@selector(handleToggleEvent:)];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 } else {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 [button setAction:@selector(handleEvent:)];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 [button setTarget:event];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 if(groups) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 uic_add_group_widget(obj->ctx, item, groups);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 [item setView:button];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 return item;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 - (UcxList*) groups {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 return groups;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 @end
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 /* --------------------- UiToolbarItem --------------------- */
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 @implementation UiToolbarItem
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 - (UiToolbarItem*) initWithIdentifier:(char*)identifier
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 label:(char*)lbl
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 callback:(ui_callback)f
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 userdata:(void*)data
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 name = identifier;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 label = lbl;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 callback = f;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 userdata = data;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 groups = NULL;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 isToggleButton = NO;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 return self;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 - (void) setIsToggleButton:(BOOL)t {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 isToggleButton = t;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 - (void) addGroup:(int)group {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 groups = ucx_list_append(groups, (void*)(intptr_t)group);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 - (NSToolbarItem *) createItem:(NSToolbar*)toolbar
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 identifier:(NSString*)identifier
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 object:(UiObject*)obj
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 NSToolbarItem *item = [[[NSToolbarItem alloc] initWithItemIdentifier:
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 identifier] autorelease];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 //[item setLabel:[s label]];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 //[item setPaletteLabel:[s label]];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 NSString *l = [[NSString alloc]initWithUTF8String:label];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 [item setLabel:l];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 [item setPaletteLabel:@"Operation"];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 // create button ...
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 NSRect frame = NSMakeRect(0, 0, 40, 22);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 //NSSearchField *sf = [[NSSearchField alloc]initWithFrame:frame];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 NSButton *button = [[NSButton alloc]initWithFrame:frame];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 //[button setImage:[s buttonImage]];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 //[button setImage:[NSImage imageNamed: NSImageNameAddTemplate]];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 // TODO: image
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 [button setImage:[NSImage imageNamed: NSImageNameRemoveTemplate]];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 [button setBezelStyle: NSTexturedRoundedBezelStyle];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 // event
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 EventWrapper *event = [[EventWrapper alloc]
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 initWithData:userdata callback:callback];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 if(isToggleButton) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 [button setButtonType: NSPushOnPushOffButton];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 [button setAction:@selector(handleToggleEvent:)];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 } else {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 [button setAction:@selector(handleEvent:)];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 [button setTarget:event];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 if(groups) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 uic_add_group_widget(obj->ctx, item, groups);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 [item setView:button];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 return item;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 - (UcxList*) groups {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 return groups;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 @end
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 /* --------------------- UiToolbarDelegate --------------------- */
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 @implementation UiToolbarDelegate
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 - (UiToolbarDelegate*) init {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 allowedItems = [[NSMutableArray alloc]initWithCapacity: 16];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 defaultItems = [[NSMutableArray alloc]initWithCapacity: 16];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 items = [[NSMutableDictionary alloc] init];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 return self;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 - (void) addDefault:(NSString*)identifier {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 [defaultItems addObject: identifier];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 - (void) addItem: (NSString*) identifier
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 item: (NSObject<UiToolItem>*) item
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 [allowedItems addObject: identifier];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 [items setObject: item forKey:identifier];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 /*
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 - (void) addStockItem:(char*)name
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 stockID:(char*)sid
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 callback:(ui_callback)f
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 data:(void*)userdata
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 UiToolbarStockItem *item = [[UiToolbarStockItem alloc]initWithData:name
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 stockID:sid callback:f data:userdata];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 NSString *s = [[NSString alloc]initWithUTF8String:name];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 [allowedItems addObject: s];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 [items setObject: item forKey:s];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 */
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 // implementation of NSToolbarDelegate methods
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 NSMutableArray *i = [[NSMutableArray alloc]
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 initWithCapacity:[allowedItems count] + 3];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 [i addObject: NSToolbarFlexibleSpaceItemIdentifier];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 [i addObject: NSToolbarSpaceItemIdentifier];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 [i addObject: NSToolbarSeparatorItemIdentifier];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 for(id item in allowedItems) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 [i addObject: item];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 return i;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 return defaultItems;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 - (NSToolbarItem *) toolbar:(NSToolbar*)toolbar
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 itemForItemIdentifier:(NSString*)identifier
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 willBeInsertedIntoToolbar:(BOOL)flag
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 Protocol *item = @protocol(UiToolItem);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 item = [items objectForKey: identifier];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 // get UiObject from toolbar
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 UiObject *obj = [(UiToolbar*)toolbar object];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 // create new NSToolbarItem
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 return [item createItem:toolbar identifier:identifier object:obj];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 @end
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 @implementation UiToolbar
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 - (UiToolbar*) initWithObject:(UiObject*)object {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 [self initWithIdentifier: @"MainToolbar"];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 obj = object;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 return self;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 - (UiObject*) object {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 return obj;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 @end
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 /* --------------------- functions --------------------- */
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 void ui_toolbar_init() {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 toolbar_delegate = [[UiToolbarDelegate alloc]init];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 void ui_toolitem(char *name, char *label, ui_callback f, void *udata) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 UiToolbarItem *item = [[UiToolbarItem alloc]
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 initWithIdentifier: name
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 label: label
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 callback: f
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 userdata: udata];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 NSString *identifier = [[NSString alloc]initWithUTF8String:name];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 [toolbar_delegate addItem: identifier item: item];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *udata) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 ui_toolitem_stgr(name, stockid, f, udata, -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 void ui_toolitem_stgr(char *name, char *stockid, ui_callback f, void *udata, ...) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 va_list ap;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 va_start(ap, udata);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 ui_toolbar_stock_button(name, stockid, NO, f, udata, ap);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 va_end(ap);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 void ui_toolitem_toggle_st(char *name, char *stockid, ui_callback f, void *udata) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 ui_toolitem_toggle_stgr(name, stockid, f, udata, -1);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 void ui_toolitem_toggle_stgr(char *name, char *stockid, ui_callback f, void *udata, ...) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 va_list ap;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 va_start(ap, udata);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 ui_toolbar_stock_button(name, stockid, YES, f, udata, ap);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 va_end(ap);
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 void ui_toolbar_stock_button(char *name, char *stockid, BOOL toggle, ui_callback f, void *udata, va_list ap) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 UiToolbarStockItem *item = [[UiToolbarStockItem alloc]
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 initWithIdentifier: name
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 stockID: stockid
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 callback: f
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 userdata: udata];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 [item setIsToggleButton: toggle];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 NSString *identifier = [[NSString alloc]initWithUTF8String:name];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 [toolbar_delegate addItem: identifier item: item];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 // add groups
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 int group;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 while((group = va_arg(ap, int)) != -1) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 [item addGroup: group];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347 void ui_toolbar_add_default(char *name) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 NSString *identifier = [[NSString alloc]initWithUTF8String:name];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349 [toolbar_delegate addDefault: identifier];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352 NSToolbar* ui_create_toolbar(UiObject *obj) {
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353 UiToolbar *toolbar = [[UiToolbar alloc] initWithObject:obj];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
354 [toolbar setDelegate: toolbar_delegate];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 [toolbar setAllowsUserCustomization: true];
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 return toolbar;
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 }
804d8803eade add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358

mercurial