diff -r 3335268a8073 -r f190d03dce0f ui/cocoa/toolbar.m --- a/ui/cocoa/toolbar.m Wed Jul 13 15:14:09 2016 +0200 +++ b/ui/cocoa/toolbar.m Wed Jul 13 15:35:59 2016 +0200 @@ -122,6 +122,83 @@ @end +/* --------------------- UiToolbarItem --------------------- */ + +@implementation UiToolbarItem + +- (UiToolbarItem*) initWithIdentifier:(char*)identifier + label:(char*)lbl + callback:(ui_callback)f + userdata:(void*)data +{ + name = identifier; + label = lbl; + callback = f; + userdata = data; + groups = NULL; + isToggleButton = NO; + return self; +} + +- (void) setIsToggleButton:(BOOL)t { + isToggleButton = t; +} + +- (void) addGroup:(int)group { + groups = ucx_list_append(groups, (void*)(intptr_t)group); +} + + +- (NSToolbarItem *) createItem:(NSToolbar*)toolbar + identifier:(NSString*)identifier + object:(UiObject*)obj +{ + NSToolbarItem *item = [[[NSToolbarItem alloc] initWithItemIdentifier: + identifier] autorelease]; + //[item setLabel:[s label]]; + //[item setPaletteLabel:[s label]]; + NSString *l = [[NSString alloc]initWithUTF8String:label]; + [item setLabel:l]; + [item setPaletteLabel:@"Operation"]; + + // create button ... + NSRect frame = NSMakeRect(0, 0, 40, 22); + //NSSearchField *sf = [[NSSearchField alloc]initWithFrame:frame]; + NSButton *button = [[NSButton alloc]initWithFrame:frame]; + //[button setImage:[s buttonImage]]; + //[button setImage:[NSImage imageNamed: NSImageNameAddTemplate]]; + + // TODO: image + [button setImage:[NSImage imageNamed: NSImageNameRemoveTemplate]]; + + [button setBezelStyle: NSTexturedRoundedBezelStyle]; + + // event + EventWrapper *event = [[EventWrapper alloc] + initWithData:userdata callback:callback]; + if(isToggleButton) { + [button setButtonType: NSPushOnPushOffButton]; + [button setAction:@selector(handleToggleEvent:)]; + } else { + [button setAction:@selector(handleEvent:)]; + } + [button setTarget:event]; + + if(groups) { + uic_add_group_widget(obj->ctx, item, groups); + } + + [item setView:button]; + return item; +} + +- (UcxList*) groups { + return groups; +} + +@end + + /* --------------------- UiToolbarDelegate --------------------- */ @implementation UiToolbarDelegate @@ -215,6 +292,17 @@ toolbar_delegate = [[UiToolbarDelegate alloc]init]; } +void ui_toolitem(char *name, char *label, ui_callback f, void *udata) { + UiToolbarItem *item = [[UiToolbarItem alloc] + initWithIdentifier: name + label: label + callback: f + userdata: udata]; + + NSString *identifier = [[NSString alloc]initWithUTF8String:name]; + [toolbar_delegate addItem: identifier item: item]; +} + void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *udata) { ui_toolitem_stgr(name, stockid, f, udata, -1); }