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];
161 - (id)toolbarConfig {
164 if (toolbarConfig != nil)
165 return [toolbarConfig isNotNull] ? toolbarConfig : nil;
170 tb = [[self clientObject] lookupName:@"toolbar" inContext:[self context]
173 if ([tb isKindOfClass:[NSException class]]) {
174 [self errorWithFormat:
175 @"not toolbar configuration found on SoObject: %@ (%@)",
176 [self clientObject], [[self clientObject] soClass]];
177 toolbarConfig = [[NSNull null] retain];
181 if ([tb isKindOfClass:[NSString class]])
182 tb = [self loadToolbarConfigFromResourceNamed:tb];
184 toolbarConfig = [tb retain];
185 return toolbarConfig;
190 - (NSString *) buttonLabel
194 key = [[self buttonInfo] valueForKey: @"label"];
196 return [self labelForKey: key];
203 image = [buttonInfo objectForKey: @"image"];
204 if (image && [image length] > 0)
205 image = [self urlForResourceFilename: image];
210 /* enable/disable buttons */
212 - (BOOL)isButtonEnabled {
213 // TODO: replace 'enabled' with WOAssociation when this gets a dynamic
217 if ((onOffKey = [[self buttonInfo] valueForKey:@"enabled"]) == nil)
220 return [[[[self context] page] valueForKeyPath:onOffKey] boolValue];
223 - (BOOL) isLastGroup {
224 return ([toolbarConfig indexOfObject: toolbarGroup]
225 == ([toolbarConfig count] - 1));
231 unsigned int count, max, amount;
233 tbConfig = [self toolbarConfig];
236 max = [tbConfig count];
237 for (count = 0; count < max; count++)
238 amount += [[tbConfig objectAtIndex: count] count];
243 - (void) setToolbar: (NSString *) newToolbar
245 ASSIGN(toolbar, newToolbar);
248 - (NSString *) toolbar
253 @end /* UIxToolbar */