2 Copyright (C) 2000-2004 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 #include "UIxTabView.h"
30 extern NSString *UIxTabView_HEAD;
31 extern NSString *UIxTabView_BODY;
32 extern NSString *UIxTabView_KEYS;
33 extern NSString *UIxTabView_SCRIPT;
34 extern NSString *UIxTabView_ACTIVEKEY;
35 extern NSString *UIxTabView_COLLECT;
37 @implementation UIxTabItem
39 static Class StrClass = Nil;
42 return [super version] + 0;
45 StrClass = [NSString class];
48 static NSString *retStrForInt(int i) {
60 case 10: return @"10";
61 // TODO: find useful count!
63 return [[StrClass alloc] initWithFormat:@"%i", i];
67 - (id)initWithName:(NSString *)_name
68 associations:(NSDictionary *)_config
69 template:(WOElement *)_subs
71 if ((self = [super initWithName:_name associations:_config template:_subs])) {
72 self->key = WOExtGetProperty(_config, @"key");
73 self->label = WOExtGetProperty(_config, @"label");
75 self->isScript = WOExtGetProperty(_config, @"isScript");
76 self->href = WOExtGetProperty(_config, @"href");
78 self->icon = WOExtGetProperty(_config, @"icon");
79 self->action = WOExtGetProperty(_config, @"action");
81 self->tabStyle = WOExtGetProperty(_config, @"tabStyle");
82 self->selectedTabStyle = WOExtGetProperty(_config, @"selectedTabStyle");
84 self->tabIcon = WOExtGetProperty(_config, @"tabIcon");
85 self->leftTabIcon = WOExtGetProperty(_config, @"leftTabIcon");
86 self->selectedTabIcon = WOExtGetProperty(_config, @"selectedTabIcon");
88 self->asBackground = WOExtGetProperty(_config, @"asBackground");
89 self->width = WOExtGetProperty(_config, @"width");
90 self->height = WOExtGetProperty(_config, @"height");
91 self->activeBgColor = WOExtGetProperty(_config, @"activeBgColor");
92 self->inactiveBgColor = WOExtGetProperty(_config, @"inactiveBgColor");
94 self->template = [_subs retain];
101 [self->label release];
103 [self->href release];
105 [self->action release];
107 [self->isScript release];
108 [self->template release];
110 [self->tabStyle release];
111 [self->selectedTabStyle release];
113 [self->icon release];
114 [self->leftTabIcon release];
115 [self->selectedTabIcon release];
116 [self->tabIcon release];
118 [self->asBackground release];
119 [self->width release];
120 [self->height release];
122 [self->activeBgColor release];
123 [self->inactiveBgColor release];
130 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
131 NSString *activeTabKey;
135 if ([_ctx objectForKey:UIxTabView_HEAD]) {
137 [[_ctx component] debugWithFormat:
138 @"UIxTabItem: head takes (no) values, eid='%@'",
143 if ((activeTabKey = [_ctx objectForKey:UIxTabView_BODY]) == nil) {
144 [[_ctx component] debugWithFormat:@"UIxTabItem: invalid state"];
145 [self->template takeValuesFromRequest:_rq inContext:_ctx];
149 myTabKey = [self->key stringValueInComponent:[_ctx component]];
150 doCheck = [self->isScript boolValueInComponent:[_ctx component]];
152 if ([activeTabKey isEqualToString:myTabKey] || doCheck) {
153 #if ADD_OWN_ELEMENTIDS
154 [_ctx appendElementIDComponent:activeTabKey];
158 [[_ctx component] debugWithFormat:
159 @"UIxTabItem: body takes values, eid='%@'",
163 [self->template takeValuesFromRequest:_rq inContext:_ctx];
164 #if ADD_OWN_ELEMENTIDS
165 [_ctx deleteLastElementIDComponent];
170 [[_ctx component] debugWithFormat:
171 @"UIxTabItem: body takes no values, eid='%@'",
177 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
180 NSString *activeTabKey;
182 if ((tmp = [_ctx objectForKey:UIxTabView_HEAD])) {
183 /* click on tab icon */
186 tabkey = [_ctx currentElementID];
187 [_ctx consumeElementID];
188 [_ctx appendElementIDComponent:tabkey];
190 if ([tmp isValueSettable])
191 [tmp setValue:tabkey inComponent:[_ctx component]];
194 result = [self->action valueInComponent:[_ctx component]];
197 [_ctx deleteLastElementIDComponent];
199 else if ((activeTabKey = [_ctx objectForKey:UIxTabView_BODY])) {
200 /* clicked somewhere in the (active) body */
201 result = [self->template invokeActionForRequest:_req inContext:_ctx];
204 [[_ctx component] logWithFormat:@"UIxTabItem: invalid invoke state"];
205 result = [self->template invokeActionForRequest:_req inContext:_ctx];
211 /* info collection */
213 - (void)_collectInContext:(WOContext *)_ctx key:(NSString *)k {
215 NSMutableArray *keys;
216 UIxTabItemInfo *info;
219 cmp = [_ctx component];
220 keys = [_ctx objectForKey:UIxTabView_KEYS];
222 keys = [[[NSMutableArray alloc] init] autorelease];
223 [_ctx setObject:keys forKey:UIxTabView_KEYS];
228 /* auto-assign a key */
229 k = retStrForInt([keys count]);
233 [_ctx appendElementIDComponent:k];
235 info = [[UIxTabItemInfo alloc] init];
236 info->key = [k copy];
237 info->label = [[self->label stringValueInComponent:cmp] copy];
238 info->icon = [[self->icon stringValueInComponent:cmp] copy];
240 info->uri = [[_ctx componentActionURL] copy];
242 info->uri = [[self->href stringValueInComponent:cmp] copy];
244 info->isScript = [self->isScript boolValueInComponent:cmp];
245 info->tabIcon = [[self->tabIcon stringValueInComponent:cmp] copy];
246 info->leftIcon = [[self->leftTabIcon stringValueInComponent:cmp] copy];
247 info->selIcon = [[self->selectedTabIcon stringValueInComponent:cmp]
249 info->tabStyle = [[self->tabStyle stringValueInComponent:cmp] copy];
250 info->selectedTabStyle = [[self->selectedTabStyle stringValueInComponent:cmp]
253 if (self->asBackground == nil)
254 info->asBackground = 0;
257 = ([self->asBackground boolValueInComponent:cmp]) ? 1 : -1;
259 info->width = [[self->width stringValueInComponent:cmp] copy];
260 info->height = [[self->height stringValueInComponent:cmp] copy];
261 info->activeBg = [[self->activeBgColor stringValueInComponent:cmp]
263 info->inactiveBg = [[self->inactiveBgColor stringValueInComponent:cmp]
266 if (info->leftIcon == nil) info->leftIcon = [info->tabIcon copy];
268 [keys addObject:info];
272 [_ctx deleteLastElementIDComponent];
275 /* header generation */
277 - (void)_appendHeadToResponse:(WOResponse *)_response
278 inContext:(WOContext *)_ctx
279 activeKey:(NSString *)activeKey
282 /* head is currently generated in UIxTabView */
284 // note: some associations can be inherited by UIxTabView !
291 doImages = ![[[_ctx request] clientCapabilities] isTextModeBrowser];
292 comp = [_ctx component];
294 doBgIcon = self->asBackground && doImages
295 ? [self->asBackground boolValueInComponent:comp] ? YES : NO
298 if ((label = [self->label stringValueInComponent:comp]) == nil)
303 NSString *imgName = nil;
306 imgUri = WEUriOfResource(imgName, _ctx);
307 if ([imgUri length] < 1)
315 /* body generation */
317 - (void)_appendBodyToResponse:(WOResponse *)_response
318 inContext:(WOContext *)_ctx
319 activeKey:(NSString *)tmp
326 doScript = [[_ctx objectForKey:UIxTabView_SCRIPT] boolValue];
327 isScript_ = [self->isScript boolValueInComponent:[_ctx component]];
328 isActive = [tmp isEqualToString:k];
330 if (doScript && (isActive || isScript_)) {
331 [_response appendContentString:@"<div id=\""];
332 [_response appendContentString:k];
333 [_response appendContentString:@"TabLayer\" style=\"display: none;\">\n"];
336 if (isActive || (doScript && isScript_)) {
337 /* content is active or used as layer*/
338 #if ADD_OWN_ELEMENTIDS
339 [_ctx appendElementIDComponent:k];
342 NSLog(@"TAB: %@", k);
345 [self->template appendToResponse:_response inContext:_ctx];
347 #if ADD_OWN_ELEMENTIDS
348 [_ctx deleteLastElementIDComponent];
352 if (doScript && (isActive || isScript_)) {
354 [_response appendContentString:@"</div>"];
356 jsout = [NSString alloc];
357 jsout = [jsout initWithFormat:
358 @"<script language=\"JavaScript\">\n<!--\n"
359 @"%@Tab[\"Div\"] = %@TabLayer;\n",
362 [_response appendContentString:jsout];
366 jsout = [NSString alloc];
367 jsout = [jsout initWithFormat:
368 @"if (%@Tab[\"Div\"].style==null) {"
369 @"alert('missing style in div for tab %@');}",
372 [_response appendContentString:jsout];
377 [_response appendContentString:@"showTab("];
378 [_response appendContentString:k];
379 [_response appendContentString:@"Tab);\n"];
381 [_response appendContentString:@"//-->\n</script>"];
385 /* master generation method */
387 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
392 doForm = [_ctx isInForm];
393 k = [self->key stringValueInComponent:[_ctx component]];
395 if ((tmp = [_ctx objectForKey:UIxTabView_HEAD])) {
396 if ([tmp isEqual:UIxTabView_COLLECT]) {
397 [self _collectInContext:_ctx key:k];
400 [self _appendHeadToResponse:_response inContext:_ctx
401 activeKey:tmp key:k];
404 else if ((tmp = [_ctx objectForKey:UIxTabView_BODY])) {
405 [self _appendBodyToResponse:_response inContext:_ctx
406 activeKey:tmp key:k];
409 [self warnWithFormat:@"(%s): invalid UIxTabItem state !!!",
410 __PRETTY_FUNCTION__];
411 [_response appendContentString:@"[invalid state]"];
415 @end /* UIxTabItem */
417 @implementation UIxTabItemInfo
421 [self->icon release];
422 [self->label release];
424 [self->tabStyle release];
425 [self->selectedTabStyle release];
426 [self->tabIcon release];
427 [self->selIcon release];
428 [self->leftIcon release];
429 [self->width release];
430 [self->height release];
431 [self->activeBg release];
432 [self->inactiveBg release];
442 - (NSString *)label {
452 return self->isScript;
455 - (int)asBackground {
456 return self->asBackground;
459 - (NSString *)width {
463 - (NSString *)height {
467 - (NSString *)activeBg {
468 return self->activeBg;
471 - (NSString *)inactiveBg {
472 return self->inactiveBg;
475 @end /* UIxTabItemInfo */