ui/cocoa/toolbar.m

changeset 129
5babf09f5f19
parent 128
c284c15509a8
equal deleted inserted replaced
128:c284c15509a8 129:5babf09f5f19
120 } 120 }
121 121
122 @end 122 @end
123 123
124 124
125 /* --------------------- UiToolbarItem --------------------- */
126
127 @implementation UiToolbarItem
128
129 - (UiToolbarItem*) initWithIdentifier:(char*)identifier
130 label:(char*)lbl
131 callback:(ui_callback)f
132 userdata:(void*)data
133 {
134 name = identifier;
135 label = lbl;
136 callback = f;
137 userdata = data;
138 groups = NULL;
139 isToggleButton = NO;
140 return self;
141 }
142
143 - (void) setIsToggleButton:(BOOL)t {
144 isToggleButton = t;
145 }
146
147 - (void) addGroup:(int)group {
148 groups = ucx_list_append(groups, (void*)(intptr_t)group);
149 }
150
151
152 - (NSToolbarItem *) createItem:(NSToolbar*)toolbar
153 identifier:(NSString*)identifier
154 object:(UiObject*)obj
155 {
156 NSToolbarItem *item = [[[NSToolbarItem alloc] initWithItemIdentifier:
157 identifier] autorelease];
158 //[item setLabel:[s label]];
159 //[item setPaletteLabel:[s label]];
160 NSString *l = [[NSString alloc]initWithUTF8String:label];
161 [item setLabel:l];
162 [item setPaletteLabel:@"Operation"];
163
164 // create button ...
165 NSRect frame = NSMakeRect(0, 0, 40, 22);
166 //NSSearchField *sf = [[NSSearchField alloc]initWithFrame:frame];
167 NSButton *button = [[NSButton alloc]initWithFrame:frame];
168 //[button setImage:[s buttonImage]];
169 //[button setImage:[NSImage imageNamed: NSImageNameAddTemplate]];
170
171 // TODO: image
172 [button setImage:[NSImage imageNamed: NSImageNameRemoveTemplate]];
173
174 [button setBezelStyle: NSTexturedRoundedBezelStyle];
175
176 // event
177 EventWrapper *event = [[EventWrapper alloc]
178 initWithData:userdata callback:callback];
179 if(isToggleButton) {
180 [button setButtonType: NSPushOnPushOffButton];
181 [button setAction:@selector(handleToggleEvent:)];
182 } else {
183 [button setAction:@selector(handleEvent:)];
184 }
185 [button setTarget:event];
186
187 if(groups) {
188 uic_add_group_widget(obj->ctx, item, groups);
189 }
190
191 [item setView:button];
192 return item;
193 }
194
195 - (UcxList*) groups {
196 return groups;
197 }
198
199 @end
200
201
125 /* --------------------- UiToolbarDelegate --------------------- */ 202 /* --------------------- UiToolbarDelegate --------------------- */
126 203
127 @implementation UiToolbarDelegate 204 @implementation UiToolbarDelegate
128 205
129 - (UiToolbarDelegate*) init { 206 - (UiToolbarDelegate*) init {
213 290
214 void ui_toolbar_init() { 291 void ui_toolbar_init() {
215 toolbar_delegate = [[UiToolbarDelegate alloc]init]; 292 toolbar_delegate = [[UiToolbarDelegate alloc]init];
216 } 293 }
217 294
295 void ui_toolitem(char *name, char *label, ui_callback f, void *udata) {
296 UiToolbarItem *item = [[UiToolbarItem alloc]
297 initWithIdentifier: name
298 label: label
299 callback: f
300 userdata: udata];
301
302 NSString *identifier = [[NSString alloc]initWithUTF8String:name];
303 [toolbar_delegate addItem: identifier item: item];
304 }
305
218 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *udata) { 306 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *udata) {
219 ui_toolitem_stgr(name, stockid, f, udata, -1); 307 ui_toolitem_stgr(name, stockid, f, udata, -1);
220 } 308 }
221 309
222 void ui_toolitem_stgr(char *name, char *stockid, ui_callback f, void *udata, ...) { 310 void ui_toolitem_stgr(char *name, char *stockid, ui_callback f, void *udata, ...) {

mercurial