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
23 #include "UIxTabView.h"
31 extern NSString *UIxTabView_HEAD;
32 extern NSString *UIxTabView_BODY;
33 extern NSString *UIxTabView_KEYS;
34 extern NSString *UIxTabView_SCRIPT;
35 extern NSString *UIxTabView_ACTIVEKEY;
36 extern NSString *UIxTabView_COLLECT;
38 @implementation UIxTabItem
40 static Class StrClass = Nil;
43 return [super version] + 0;
46 StrClass = [NSString class];
49 static NSString *retStrForInt(int i) {
61 case 10: return @"10";
62 // TODO: find useful count!
64 return [[StrClass alloc] initWithFormat:@"%i", i];
68 - (id)initWithName:(NSString *)_name
69 associations:(NSDictionary *)_config
70 template:(WOElement *)_subs
72 if ((self = [super initWithName:_name associations:_config template:_subs])) {
73 self->key = WOExtGetProperty(_config, @"key");
74 self->label = WOExtGetProperty(_config, @"label");
76 self->isScript = WOExtGetProperty(_config, @"isScript");
77 self->href = WOExtGetProperty(_config, @"href");
79 self->icon = WOExtGetProperty(_config, @"icon");
80 self->action = WOExtGetProperty(_config, @"action");
82 self->tabStyle = WOExtGetProperty(_config, @"tabStyle");
83 self->selectedTabStyle = WOExtGetProperty(_config, @"selectedTabStyle");
85 self->tabIcon = WOExtGetProperty(_config, @"tabIcon");
86 self->leftTabIcon = WOExtGetProperty(_config, @"leftTabIcon");
87 self->selectedTabIcon = WOExtGetProperty(_config, @"selectedTabIcon");
89 self->asBackground = WOExtGetProperty(_config, @"asBackground");
90 self->width = WOExtGetProperty(_config, @"width");
91 self->height = WOExtGetProperty(_config, @"height");
92 self->activeBgColor = WOExtGetProperty(_config, @"activeBgColor");
93 self->inactiveBgColor = WOExtGetProperty(_config, @"inactiveBgColor");
95 self->template = [_subs retain];
102 [self->label release];
104 [self->href release];
106 [self->action release];
108 [self->isScript release];
109 [self->template release];
111 [self->tabStyle release];
112 [self->selectedTabStyle release];
114 [self->icon release];
115 [self->leftTabIcon release];
116 [self->selectedTabIcon release];
117 [self->tabIcon release];
119 [self->asBackground release];
120 [self->width release];
121 [self->height release];
123 [self->activeBgColor release];
124 [self->inactiveBgColor release];
131 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
132 NSString *activeTabKey;
136 if ([_ctx objectForKey:UIxTabView_HEAD]) {
138 [[_ctx component] debugWithFormat:
139 @"UIxTabItem: head takes (no) values, eid='%@'",
144 if ((activeTabKey = [_ctx objectForKey:UIxTabView_BODY]) == nil) {
145 [[_ctx component] debugWithFormat:@"UIxTabItem: invalid state"];
146 [self->template takeValuesFromRequest:_rq inContext:_ctx];
150 myTabKey = [self->key stringValueInComponent:[_ctx component]];
151 doCheck = [self->isScript boolValueInComponent:[_ctx component]];
153 if ([activeTabKey isEqualToString:myTabKey] || doCheck) {
154 #if ADD_OWN_ELEMENTIDS
155 [_ctx appendElementIDComponent:activeTabKey];
159 [[_ctx component] debugWithFormat:
160 @"UIxTabItem: body takes values, eid='%@'",
164 [self->template takeValuesFromRequest:_rq inContext:_ctx];
165 #if ADD_OWN_ELEMENTIDS
166 [_ctx deleteLastElementIDComponent];
171 [[_ctx component] debugWithFormat:
172 @"UIxTabItem: body takes no values, eid='%@'",
178 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
181 NSString *activeTabKey;
183 if ((tmp = [_ctx objectForKey:UIxTabView_HEAD])) {
184 /* click on tab icon */
187 tabkey = [_ctx currentElementID];
188 [_ctx consumeElementID];
189 [_ctx appendElementIDComponent:tabkey];
191 if ([tmp isValueSettable])
192 [tmp setValue:tabkey inComponent:[_ctx component]];
195 result = [self->action valueInComponent:[_ctx component]];
198 [_ctx deleteLastElementIDComponent];
200 else if ((activeTabKey = [_ctx objectForKey:UIxTabView_BODY])) {
201 /* clicked somewhere in the (active) body */
202 result = [self->template invokeActionForRequest:_req inContext:_ctx];
205 [[_ctx component] logWithFormat:@"UIxTabItem: invalid invoke state"];
206 result = [self->template invokeActionForRequest:_req inContext:_ctx];
212 /* info collection */
214 - (void)_collectInContext:(WOContext *)_ctx key:(NSString *)k {
216 NSMutableArray *keys;
217 UIxTabItemInfo *info;
220 cmp = [_ctx component];
221 keys = [_ctx objectForKey:UIxTabView_KEYS];
223 keys = [[[NSMutableArray alloc] init] autorelease];
224 [_ctx setObject:keys forKey:UIxTabView_KEYS];
229 /* auto-assign a key */
230 k = retStrForInt([keys count]);
234 [_ctx appendElementIDComponent:k];
236 info = [[UIxTabItemInfo alloc] init];
237 info->key = [k copy];
238 info->label = [[self->label stringValueInComponent:cmp] copy];
239 info->icon = [[self->icon stringValueInComponent:cmp] copy];
241 info->uri = [[_ctx componentActionURL] copy];
243 info->uri = [[self->href stringValueInComponent:cmp] copy];
245 info->isScript = [self->isScript boolValueInComponent:cmp];
246 info->tabIcon = [[self->tabIcon stringValueInComponent:cmp] copy];
247 info->leftIcon = [[self->leftTabIcon stringValueInComponent:cmp] copy];
248 info->selIcon = [[self->selectedTabIcon stringValueInComponent:cmp]
250 info->tabStyle = [[self->tabStyle stringValueInComponent:cmp] copy];
251 info->selectedTabStyle = [[self->selectedTabStyle stringValueInComponent:cmp]
254 if (self->asBackground == nil)
255 info->asBackground = 0;
258 = ([self->asBackground boolValueInComponent:cmp]) ? 1 : -1;
260 info->width = [[self->width stringValueInComponent:cmp] copy];
261 info->height = [[self->height stringValueInComponent:cmp] copy];
262 info->activeBg = [[self->activeBgColor stringValueInComponent:cmp]
264 info->inactiveBg = [[self->inactiveBgColor stringValueInComponent:cmp]
267 if (info->leftIcon == nil) info->leftIcon = [info->tabIcon copy];
269 [keys addObject:info];
273 [_ctx deleteLastElementIDComponent];
276 /* header generation */
278 - (void)_appendHeadToResponse:(WOResponse *)_response
279 inContext:(WOContext *)_ctx
280 activeKey:(NSString *)activeKey
283 /* head is currently generated in UIxTabView */
285 // note: some associations can be inherited by UIxTabView !
292 doImages = ![[[_ctx request] clientCapabilities] isTextModeBrowser];
293 comp = [_ctx component];
295 doBgIcon = self->asBackground && doImages
296 ? [self->asBackground boolValueInComponent:comp] ? YES : NO
299 if ((label = [self->label stringValueInComponent:comp]) == nil)
304 NSString *imgName = nil;
307 imgUri = WEUriOfResource(imgName, _ctx);
308 if ([imgUri length] < 1)
316 /* body generation */
318 - (void)_appendBodyToResponse:(WOResponse *)_response
319 inContext:(WOContext *)_ctx
320 activeKey:(NSString *)tmp
327 doScript = [[_ctx objectForKey:UIxTabView_SCRIPT] boolValue];
328 isScript_ = [self->isScript boolValueInComponent:[_ctx component]];
329 isActive = [tmp isEqualToString:k];
331 if (doScript && (isActive || isScript_)) {
332 [_response appendContentString:@"<div id=\""];
333 [_response appendContentString:k];
334 [_response appendContentString:@"TabLayer\" style=\"display: none;\">\n"];
337 if (isActive || (doScript && isScript_)) {
338 /* content is active or used as layer*/
339 #if ADD_OWN_ELEMENTIDS
340 [_ctx appendElementIDComponent:k];
343 NSLog(@"TAB: %@", k);
346 [self->template appendToResponse:_response inContext:_ctx];
348 #if ADD_OWN_ELEMENTIDS
349 [_ctx deleteLastElementIDComponent];
353 if (doScript && (isActive || isScript_)) {
355 [_response appendContentString:@"</div>"];
357 jsout = [NSString alloc];
358 jsout = [jsout initWithFormat:
359 @"<script language=\"JavaScript\">\n<!--\n"
360 @"%@Tab[\"Div\"] = %@TabLayer;\n",
363 [_response appendContentString:jsout];
367 jsout = [NSString alloc];
368 jsout = [jsout initWithFormat:
369 @"if (%@Tab[\"Div\"].style==null) {"
370 @"alert('missing style in div for tab %@');}",
373 [_response appendContentString:jsout];
378 [_response appendContentString:@"showTab("];
379 [_response appendContentString:k];
380 [_response appendContentString:@"Tab);\n"];
382 [_response appendContentString:@"//-->\n</script>"];
386 /* master generation method */
388 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
393 doForm = [_ctx isInForm];
394 k = [self->key stringValueInComponent:[_ctx component]];
396 if ((tmp = [_ctx objectForKey:UIxTabView_HEAD])) {
397 if ([tmp isEqual:UIxTabView_COLLECT]) {
398 [self _collectInContext:_ctx key:k];
401 [self _appendHeadToResponse:_response inContext:_ctx
402 activeKey:tmp key:k];
405 else if ((tmp = [_ctx objectForKey:UIxTabView_BODY])) {
406 [self _appendBodyToResponse:_response inContext:_ctx
407 activeKey:tmp key:k];
410 NSLog(@"WARNING(%s): invalid UIxTabItem state !!!", __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 */