2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "WETabView.h"
30 extern NSString *WETabView_HEAD;
31 extern NSString *WETabView_BODY;
32 extern NSString *WETabView_KEYS;
33 extern NSString *WETabView_SCRIPT;
34 extern NSString *WETabView_ACTIVEKEY;
35 extern NSString *WETabView_COLLECT;
37 @implementation WETabItem
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->icon = WOExtGetProperty(_config, @"icon");
74 self->label = WOExtGetProperty(_config, @"label");
75 self->action = WOExtGetProperty(_config, @"action");
76 self->isScript = WOExtGetProperty(_config, @"isScript");
78 self->href = WOExtGetProperty(_config, @"href");
79 self->directActionName = WOExtGetProperty(_config, @"directActionName");
80 self->actionClass = WOExtGetProperty(_config, @"actionClass");
82 self->tabIcon = WOExtGetProperty(_config, @"tabIcon");
83 self->leftTabIcon = WOExtGetProperty(_config, @"leftTabIcon");
84 self->selectedTabIcon = WOExtGetProperty(_config, @"selectedTabIcon");
86 self->asBackground = WOExtGetProperty(_config, @"asBackground");
87 self->width = WOExtGetProperty(_config, @"width");
88 self->height = WOExtGetProperty(_config, @"height");
89 self->activeBgColor = WOExtGetProperty(_config, @"activeBgColor");
90 self->inactiveBgColor = WOExtGetProperty(_config, @"inactiveBgColor");
92 self->template = [_subs retain];
99 [self->directActionName release];
100 [self->actionClass release];
101 [self->action release];
102 [self->label release];
103 [self->icon release];
105 [self->isScript release];
106 [self->template release];
107 [self->leftTabIcon release];
108 [self->selectedTabIcon release];
109 [self->tabIcon release];
110 [self->asBackground release];
111 [self->width release];
112 [self->height release];
113 [self->activeBgColor release];
114 [self->inactiveBgColor release];
120 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
121 NSString *activeTabKey;
125 if ([_ctx objectForKey:WETabView_HEAD]) {
127 [[_ctx component] debugWithFormat:
128 @"WETabItem: head takes (no) values, eid='%@'",
133 if ((activeTabKey = [_ctx objectForKey:WETabView_BODY]) == nil) {
134 [[_ctx component] debugWithFormat:@"WETabItem: invalid state"];
135 [self->template takeValuesFromRequest:_rq inContext:_ctx];
139 myTabKey = [self->key stringValueInComponent:[_ctx component]];
140 doCheck = [self->isScript boolValueInComponent:[_ctx component]];
142 if ([activeTabKey isEqualToString:myTabKey] || doCheck) {
143 #if ADD_OWN_ELEMENTIDS
144 [_ctx appendElementIDComponent:activeTabKey];
148 [[_ctx component] debugWithFormat:
149 @"WETabItem: body takes values, eid='%@'",
153 [self->template takeValuesFromRequest:_rq inContext:_ctx];
154 #if ADD_OWN_ELEMENTIDS
155 [_ctx deleteLastElementIDComponent];
160 [[_ctx component] debugWithFormat:
161 @"WETabItem: body takes no values, eid='%@'",
167 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
170 NSString *activeTabKey;
172 if ((tmp = [_ctx objectForKey:WETabView_HEAD])) {
173 /* click on tab icon */
176 tabkey = [_ctx currentElementID];
177 [_ctx consumeElementID];
178 [_ctx appendElementIDComponent:tabkey];
180 if ([tmp isValueSettable])
181 [tmp setValue:tabkey inComponent:[_ctx component]];
183 result = [self->action valueInComponent:[_ctx component]];
185 [_ctx deleteLastElementIDComponent];
187 else if ((activeTabKey = [_ctx objectForKey:WETabView_BODY])) {
188 /* clicked somewhere in the (active) body */
189 result = [self->template invokeActionForRequest:_req inContext:_ctx];
192 [[_ctx component] logWithFormat:@"WETabItem: invalid invoke state"];
193 result = [self->template invokeActionForRequest:_req inContext:_ctx];
201 - (NSString *)urlForTabItemInContext:(WOContext *)_ctx {
202 if (self->href != nil)
203 return [self->href stringValueInComponent:[_ctx component]];
205 if (self->directActionName != nil || self->actionClass != nil) {
206 NSDictionary *qd = nil;
207 NSString *daClass = nil;
208 NSString *daName = nil;
210 daClass = [self->actionClass stringValueInComponent:[_ctx component]];
211 daName = [self->directActionName stringValueInComponent:[_ctx component]];
213 if (daClass != nil) {
215 if (![daClass isEqualToString:@"DirectAction"])
216 daName = [NSString stringWithFormat:@"%@/%@", daClass, daName];
222 return [_ctx directActionURLForActionNamed:daName queryDictionary:qd];
225 return [_ctx componentActionURL];
228 /* info collection */
230 - (void)_collectInContext:(WOContext *)_ctx key:(NSString *)k {
232 NSMutableArray *keys;
236 cmp = [_ctx component];
237 keys = [_ctx objectForKey:WETabView_KEYS];
239 keys = [[[NSMutableArray alloc] init] autorelease];
240 [_ctx setObject:keys forKey:WETabView_KEYS];
245 /* auto-assign a key */
246 k = retStrForInt([keys count]);
250 [_ctx appendElementIDComponent:k];
252 info = [[WETabItemInfo alloc] init];
253 info->key = [k copy];
254 info->uri = [[self urlForTabItemInContext:_ctx] copy];
255 info->label = [[self->label stringValueInComponent:cmp] copy];
256 info->icon = [[self->icon stringValueInComponent:cmp] copy];
257 info->isScript = [self->isScript boolValueInComponent:cmp];
258 info->tabIcon = [[self->tabIcon stringValueInComponent:cmp] copy];
259 info->leftIcon = [[self->leftTabIcon stringValueInComponent:cmp] copy];
260 info->selIcon = [[self->selectedTabIcon stringValueInComponent:cmp]
262 if (self->asBackground == nil)
263 info->asBackground = 0;
266 = ([self->asBackground boolValueInComponent:cmp]) ? 1 : -1;
268 info->width = [[self->width stringValueInComponent:cmp] copy];
269 info->height = [[self->height stringValueInComponent:cmp] copy];
270 info->activeBg = [[self->activeBgColor stringValueInComponent:cmp]
272 info->inactiveBg = [[self->inactiveBgColor stringValueInComponent:cmp]
275 if (info->leftIcon == nil) info->leftIcon = [info->tabIcon copy];
277 [keys addObject:info];
281 [_ctx deleteLastElementIDComponent];
284 /* header generation */
286 - (void)_appendHeadToResponse:(WOResponse *)_response
287 inContext:(WOContext *)_ctx
288 activeKey:(NSString *)activeKey
291 /* head is currently generated in WETabView */
293 // note: some associations can be inherited by WETabView !
300 doImages = ![[[_ctx request] clientCapabilities] isTextModeBrowser];
301 comp = [_ctx component];
303 doBgIcon = self->asBackground && doImages
304 ? [self->asBackground boolValueInComponent:comp] ? YES : NO
307 if ((label = [self->label stringValueInComponent:comp]) == nil)
312 NSString *imgName = nil;
315 imgUri = WEUriOfResource(imgName, _ctx);
316 if ([imgUri length] < 1)
324 /* body generation */
326 - (void)_appendBodyToResponse:(WOResponse *)_response
327 inContext:(WOContext *)_ctx
328 activeKey:(NSString *)tmp
335 doScript = [[_ctx objectForKey:WETabView_SCRIPT] boolValue];
336 isScript_ = [self->isScript boolValueInComponent:[_ctx component]];
337 isActive = [tmp isEqualToString:k];
339 if (doScript && (isActive || isScript_)) {
340 [_response appendContentString:@"<div id=\""];
341 [_response appendContentString:k];
342 [_response appendContentString:@"TabLayer\" style=\"display: none;\">\n"];
345 if (isActive || (doScript && isScript_)) {
346 /* content is active or used as layer*/
347 #if ADD_OWN_ELEMENTIDS
348 [_ctx appendElementIDComponent:k];
351 NSLog(@"TAB: %@", k);
354 [self->template appendToResponse:_response inContext:_ctx];
356 #if ADD_OWN_ELEMENTIDS
357 [_ctx deleteLastElementIDComponent];
361 if (doScript && (isActive || isScript_)) {
363 [_response appendContentString:@"</div>"];
365 jsout = [NSString alloc];
366 jsout = [jsout initWithFormat:
367 @"<script language=\"JavaScript\">\n<!--\n"
368 @"%@Tab[\"Div\"] = %@TabLayer;\n",
371 [_response appendContentString:jsout];
375 jsout = [NSString alloc];
376 jsout = [jsout initWithFormat:
377 @"if (%@Tab[\"Div\"].style==null) {"
378 @"alert('missing style in div for tab %@');}",
381 [_response appendContentString:jsout];
386 [_response appendContentString:@"showTab("];
387 [_response appendContentString:k];
388 [_response appendContentString:@"Tab);\n"];
390 [_response appendContentString:@"//-->\n</script>"];
394 /* master generation method */
396 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
401 doForm = [_ctx isInForm];
402 k = [self->key stringValueInComponent:[_ctx component]];
404 if ((tmp = [_ctx objectForKey:WETabView_HEAD])) {
405 if ([tmp isEqual:WETabView_COLLECT]) {
406 [self _collectInContext:_ctx key:k];
409 [self _appendHeadToResponse:_response inContext:_ctx
410 activeKey:tmp key:k];
413 else if ((tmp = [_ctx objectForKey:WETabView_BODY])) {
414 [self _appendBodyToResponse:_response inContext:_ctx
415 activeKey:tmp key:k];
418 NSLog(@"WARNING(%s): invalid WETabItem state !!!", __PRETTY_FUNCTION__);
419 [_response appendContentString:@"[invalid state]"];
425 @implementation WETabItemInfo
429 [self->icon release];
430 [self->label release];
432 [self->tabIcon release];
433 [self->selIcon release];
434 [self->leftIcon release];
435 [self->width release];
436 [self->height release];
437 [self->activeBg release];
438 [self->inactiveBg release];
448 - (NSString *)label {
458 return self->isScript;
461 - (int)asBackground {
462 return self->asBackground;
465 - (NSString *)width {
469 - (NSString *)height {
473 - (NSString *)activeBg {
474 return self->activeBg;
477 - (NSString *)inactiveBg {
478 return self->inactiveBg;
481 @end /* WETabItemInfo */