2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <Foundation/NSKeyValueCoding.h>
23 #import <NGExtensions/NGExtensions.h>
24 #import <NGObjWeb/NGObjWeb.h>
25 #import <NGObjWeb/SoObjects.h>
27 #import <SOGoUI/UIxComponent.h>
29 #import <NGObjWeb/SoComponent.h>
31 @class NSArray, NSDictionary;
33 @interface UIxToolbar : UIxComponent
35 NSArray *toolbarConfig;
36 NSArray *toolbarGroup;
38 NSDictionary *buttonInfo;
41 - (void) setToolbar: (NSString *) newToolbar;
42 - (NSString *) toolbar;
46 @implementation UIxToolbar
50 if ((self = [super init]))
59 [toolbarGroup release];
60 [toolbarConfig release];
70 [toolbarGroup release]; toolbarGroup = nil;
71 [toolbarConfig release]; toolbarConfig = nil;
72 [buttonInfo release]; buttonInfo = nil;
78 - (void)setToolbarGroup:(id)_group {
79 ASSIGN(toolbarGroup, _group);
86 - (void)setButtonInfo:(id)_info {
87 ASSIGN(buttonInfo, _info);
96 - (WOResourceManager *)pageResourceManager {
97 WOResourceManager *rm;
99 if ((rm = [[[self context] page] resourceManager]) != nil)
102 return [[self application] resourceManager];
105 - (id) pathToResourceNamed: (NSString *) name
107 WOResourceManager *rm;
111 r = [name rangeOfString: @"/"];
114 fw = [name substringToIndex: r.location];
115 rn = [name substringFromIndex: (r.location + r.length)];
123 rm = [self pageResourceManager];
125 return [rm pathForResourceNamed: rn inFramework: fw
126 languages: [[self context] resourceLookupLanguages]];
129 - (id)loadToolbarConfigFromResourceNamed:(NSString *)_name {
131 Note: we cannot cache by name because we don't know how the resource
132 manager will look up the name.
133 Both, the clientObject and the page might be different.
135 Of course the resourcemanager will cache the resource path and we
136 cache the parsed content for a given path;
138 static NSMutableDictionary *pathToConfig = nil;
142 path = [self pathToResourceNamed: _name];
144 [self errorWithFormat:@"Did not find toolbar resource: %@", _name];
148 if ((tb = [pathToConfig objectForKey:path]) != nil)
149 return [tb isNotNull] ? tb : nil;
151 if ((tb = [NSArray arrayWithContentsOfFile:path]) == nil)
152 [self errorWithFormat:@"Could not load toolbar resource: %@", _name];
154 if (pathToConfig == nil)
155 pathToConfig = [[NSMutableDictionary alloc] initWithCapacity:32];
156 [pathToConfig setObject:(tb ? tb : (id)[NSNull null]) forKey:path];
165 if (toolbarConfig != nil)
166 return [toolbarConfig isNotNull] ? toolbarConfig : nil;
171 tb = [[self clientObject] lookupName: @"toolbar" inContext:[self context]
174 if ([tb isKindOfClass:[NSException class]]) {
175 [self errorWithFormat:
176 @"not toolbar configuration found on SoObject: %@ (%@)",
177 [self clientObject], [[self clientObject] soClass]];
178 toolbarConfig = [[NSNull null] retain];
182 if ([tb isKindOfClass: [NSString class]])
184 if ([tb isEqualToString: @"none"])
187 tb = [self loadToolbarConfigFromResourceNamed:tb];
190 toolbarConfig = [tb retain];
192 return toolbarConfig;
197 - (NSString *) buttonLabel
201 key = [[self buttonInfo] valueForKey: @"label"];
203 return [self labelForKey: key];
210 image = [buttonInfo objectForKey: @"image"];
211 if (image && [image length] > 0)
212 image = [self urlForResourceFilename: image];
217 - (NSString *) buttonTooltip
221 key = [[self buttonInfo] valueForKey: @"tooltip"];
223 return [self labelForKey: key];
226 /* enable/disable buttons */
228 - (BOOL)isButtonEnabled {
229 // TODO: replace 'enabled' with WOAssociation when this gets a dynamic
233 if ((onOffKey = [[self buttonInfo] valueForKey:@"enabled"]) == nil)
236 return [[[[self context] page] valueForKeyPath:onOffKey] boolValue];
239 - (BOOL) isLastGroup {
240 return ([toolbarConfig indexOfObject: toolbarGroup]
241 == ([toolbarConfig count] - 1));
247 unsigned int count, max, amount;
249 tbConfig = [self toolbarConfig];
252 max = [tbConfig count];
253 for (count = 0; count < max; count++)
254 amount += [[tbConfig objectAtIndex: count] count];
261 return [[[self buttonInfo] valueForKey:@"hasMenu"] boolValue];
264 - (void) setToolbar: (NSString *) newToolbar
266 ASSIGN(toolbar, newToolbar);
269 - (NSString *) toolbar
274 @end /* UIxToolbar */