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 "WETabView.h"
31 extern NSString *WETabView_HEAD;
32 extern NSString *WETabView_BODY;
33 extern NSString *WETabView_KEYS;
34 extern NSString *WETabView_SCRIPT;
35 extern NSString *WETabView_ACTIVEKEY;
36 extern NSString *WETabView_COLLECT;
38 @implementation WETabItem
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->icon = WOExtGetProperty(_config, @"icon");
75 self->label = WOExtGetProperty(_config, @"label");
76 self->action = WOExtGetProperty(_config, @"action");
77 self->isScript = WOExtGetProperty(_config, @"isScript");
79 self->tabIcon = WOExtGetProperty(_config, @"tabIcon");
80 self->leftTabIcon = WOExtGetProperty(_config, @"leftTabIcon");
81 self->selectedTabIcon = WOExtGetProperty(_config, @"selectedTabIcon");
83 self->asBackground = WOExtGetProperty(_config, @"asBackground");
84 self->width = WOExtGetProperty(_config, @"width");
85 self->height = WOExtGetProperty(_config, @"height");
86 self->activeBgColor = WOExtGetProperty(_config, @"activeBgColor");
87 self->inactiveBgColor = WOExtGetProperty(_config, @"inactiveBgColor");
89 self->template = [_subs retain];
95 [self->action release];
96 [self->label release];
99 [self->isScript release];
100 [self->template release];
102 [self->leftTabIcon release];
103 [self->selectedTabIcon release];
104 [self->tabIcon release];
106 [self->asBackground release];
107 [self->width release];
108 [self->height release];
110 [self->activeBgColor release];
111 [self->inactiveBgColor release];
118 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
119 NSString *activeTabKey;
123 if ([_ctx objectForKey:WETabView_HEAD]) {
125 [[_ctx component] debugWithFormat:
126 @"WETabItem: head takes (no) values, eid='%@'",
131 if ((activeTabKey = [_ctx objectForKey:WETabView_BODY]) == nil) {
132 [[_ctx component] debugWithFormat:@"WETabItem: invalid state"];
133 [self->template takeValuesFromRequest:_rq inContext:_ctx];
137 myTabKey = [self->key stringValueInComponent:[_ctx component]];
138 doCheck = [self->isScript boolValueInComponent:[_ctx component]];
140 if ([activeTabKey isEqualToString:myTabKey] || doCheck) {
141 #if ADD_OWN_ELEMENTIDS
142 [_ctx appendElementIDComponent:activeTabKey];
146 [[_ctx component] debugWithFormat:
147 @"WETabItem: body takes values, eid='%@'",
151 [self->template takeValuesFromRequest:_rq inContext:_ctx];
152 #if ADD_OWN_ELEMENTIDS
153 [_ctx deleteLastElementIDComponent];
158 [[_ctx component] debugWithFormat:
159 @"WETabItem: body takes no values, eid='%@'",
165 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
168 NSString *activeTabKey;
170 if ((tmp = [_ctx objectForKey:WETabView_HEAD])) {
171 /* click on tab icon */
174 tabkey = [_ctx currentElementID];
175 [_ctx consumeElementID];
176 [_ctx appendElementIDComponent:tabkey];
178 if ([tmp isValueSettable])
179 [tmp setValue:tabkey inComponent:[_ctx component]];
181 result = [self->action valueInComponent:[_ctx component]];
183 [_ctx deleteLastElementIDComponent];
185 else if ((activeTabKey = [_ctx objectForKey:WETabView_BODY])) {
186 /* clicked somewhere in the (active) body */
187 result = [self->template invokeActionForRequest:_req inContext:_ctx];
190 [[_ctx component] logWithFormat:@"WETabItem: invalid invoke state"];
191 result = [self->template invokeActionForRequest:_req inContext:_ctx];
197 /* info collection */
199 - (void)_collectInContext:(WOContext *)_ctx key:(NSString *)k {
201 NSMutableArray *keys;
205 cmp = [_ctx component];
206 keys = [_ctx objectForKey:WETabView_KEYS];
208 keys = [[[NSMutableArray alloc] init] autorelease];
209 [_ctx setObject:keys forKey:WETabView_KEYS];
214 /* auto-assign a key */
215 k = retStrForInt([keys count]);
219 [_ctx appendElementIDComponent:k];
221 info = [[WETabItemInfo alloc] init];
222 info->key = [k copy];
223 info->label = [[self->label stringValueInComponent:cmp] copy];
224 info->icon = [[self->icon stringValueInComponent:cmp] copy];
225 info->uri = [[_ctx componentActionURL] copy];
226 info->isScript = [self->isScript boolValueInComponent:cmp];
227 info->tabIcon = [[self->tabIcon stringValueInComponent:cmp] copy];
228 info->leftIcon = [[self->leftTabIcon stringValueInComponent:cmp] copy];
229 info->selIcon = [[self->selectedTabIcon stringValueInComponent:cmp]
231 if (self->asBackground == nil)
232 info->asBackground = 0;
235 = ([self->asBackground boolValueInComponent:cmp]) ? 1 : -1;
237 info->width = [[self->width stringValueInComponent:cmp] copy];
238 info->height = [[self->height stringValueInComponent:cmp] copy];
239 info->activeBg = [[self->activeBgColor stringValueInComponent:cmp]
241 info->inactiveBg = [[self->inactiveBgColor stringValueInComponent:cmp]
244 if (info->leftIcon == nil) info->leftIcon = [info->tabIcon copy];
246 [keys addObject:info];
250 [_ctx deleteLastElementIDComponent];
253 /* header generation */
255 - (void)_appendHeadToResponse:(WOResponse *)_response
256 inContext:(WOContext *)_ctx
257 activeKey:(NSString *)activeKey
260 /* head is currently generated in WETabView */
262 // note: some associations can be inherited by WETabView !
269 doImages = ![[[_ctx request] clientCapabilities] isTextModeBrowser];
270 comp = [_ctx component];
272 doBgIcon = self->asBackground && doImages
273 ? [self->asBackground boolValueInComponent:comp] ? YES : NO
276 if ((label = [self->label stringValueInComponent:comp]) == nil)
281 NSString *imgName = nil;
284 imgUri = WEUriOfResource(imgName, _ctx);
285 if ([imgUri length] < 1)
293 /* body generation */
295 - (void)_appendBodyToResponse:(WOResponse *)_response
296 inContext:(WOContext *)_ctx
297 activeKey:(NSString *)tmp
304 doScript = [[_ctx objectForKey:WETabView_SCRIPT] boolValue];
305 isScript_ = [self->isScript boolValueInComponent:[_ctx component]];
306 isActive = [tmp isEqualToString:k];
308 if (doScript && (isActive || isScript_)) {
309 [_response appendContentString:@"<div id=\""];
310 [_response appendContentString:k];
311 [_response appendContentString:@"TabLayer\" style=\"display: none;\">\n"];
314 if (isActive || (doScript && isScript_)) {
315 /* content is active or used as layer*/
316 #if ADD_OWN_ELEMENTIDS
317 [_ctx appendElementIDComponent:k];
320 NSLog(@"TAB: %@", k);
323 [self->template appendToResponse:_response inContext:_ctx];
325 #if ADD_OWN_ELEMENTIDS
326 [_ctx deleteLastElementIDComponent];
330 if (doScript && (isActive || isScript_)) {
332 [_response appendContentString:@"</div>"];
334 jsout = [NSString alloc];
335 jsout = [jsout initWithFormat:
336 @"<script language=\"JavaScript\">\n<!--\n"
337 @"%@Tab[\"Div\"] = %@TabLayer;\n",
340 [_response appendContentString:jsout];
344 jsout = [NSString alloc];
345 jsout = [jsout initWithFormat:
346 @"if (%@Tab[\"Div\"].style==null) {"
347 @"alert('missing style in div for tab %@');}",
350 [_response appendContentString:jsout];
355 [_response appendContentString:@"showTab("];
356 [_response appendContentString:k];
357 [_response appendContentString:@"Tab);\n"];
359 [_response appendContentString:@"//-->\n</script>"];
363 /* master generation method */
365 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
370 doForm = [_ctx isInForm];
371 k = [self->key stringValueInComponent:[_ctx component]];
373 if ((tmp = [_ctx objectForKey:WETabView_HEAD])) {
374 if ([tmp isEqual:WETabView_COLLECT]) {
375 [self _collectInContext:_ctx key:k];
378 [self _appendHeadToResponse:_response inContext:_ctx
379 activeKey:tmp key:k];
382 else if ((tmp = [_ctx objectForKey:WETabView_BODY])) {
383 [self _appendBodyToResponse:_response inContext:_ctx
384 activeKey:tmp key:k];
387 NSLog(@"WARNING(%s): invalid WETabItem state !!!", __PRETTY_FUNCTION__);
388 [_response appendContentString:@"[invalid state]"];
394 @implementation WETabItemInfo
398 [self->icon release];
399 [self->label release];
401 [self->tabIcon release];
402 [self->selIcon release];
403 [self->leftIcon release];
404 [self->width release];
405 [self->height release];
406 [self->activeBg release];
407 [self->inactiveBg release];
417 - (NSString *)label {
427 return self->isScript;
430 - (int)asBackground {
431 return self->asBackground;
434 - (NSString *)width {
438 - (NSString *)height {
442 - (NSString *)activeBg {
443 return self->activeBg;
446 - (NSString *)inactiveBg {
447 return self->inactiveBg;
450 @end /* WETabItemInfo */