2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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 <NGObjDOM/ODR_bind_tabview.h>
25 #include <NGObjWeb/WEClientCapabilities.h>
27 #include <WEExtensions/WEClientCapabilities.h>
31 <var:tabview selection="selection"
33 inactivecolor="inactivecolor"
34 activecolor="activecolor"
35 bgiconleft="inactivebgiconleft"
36 bgicon="inactivebgicon"
37 activebgicon="activebgicon">
39 <tab const:title="tab 1" const:key="tab1">
43 <tab const:title="tab 2" const:key="tab2">
71 @implementation ODR_bind_tabview
73 #if !LIB_FOUNDATION_BOEHM_GC
75 RELEASE(self->activeKey);
80 - (void)_setActiveKey:(NSString *)_activeKey {
81 ASSIGN(self->activeKey, _activeKey);
84 - (void)setActiveKey:(id)_node inContext:(WOContext *)_ctx {
89 [self _setActiveKey:[self stringFor:@"selection" node:_node ctx:_ctx]];
90 keys = [[NSMutableArray allocWithZone:[self zone]] initWithCapacity:8];
91 tabNodes = ODRLookupQueryPath(_node, @"-tab");
92 cnt = [tabNodes count];
94 for (i=0; i < cnt; i++) {
98 tab = [tabNodes objectAtIndex:i];
99 key = [self stringFor:@"key" node:tab ctx:_ctx];
101 key = [NSString stringWithFormat:@"%d", i];
102 [self forceSetString:key for:@"key" node:tab ctx:_ctx];
104 [keys addObject:key];
106 /* selection is not available in keys */
107 if (![keys containsObject:self->activeKey])
108 [self _setActiveKey:nil];
110 /* no or invalid selection, use first key */
111 if ((self->activeKey == nil) && ([keys count] > 0))
112 [self _setActiveKey:[[keys objectAtIndex:0] stringValue]];
114 [self forceSetString:self->activeKey for:@"selection" node:_node ctx:_ctx];
121 - (void)takeValuesForNode:(id)_node
122 fromRequest:(WORequest *)_request
123 inContext:(WOContext *)_ctx
128 /* set ODR_bind_tabview_ACTIVEKEY */
129 [self setActiveKey:_node inContext:_ctx];
131 tabs = ODRLookupQueryPath(_node, @"-tab");
134 [_ctx appendElementIDComponent:@"b"];
135 [_ctx appendElementIDComponent:self->activeKey];
137 for (i = 0; i < cnt; i++) {
141 tab = [tabs objectAtIndex:i];
142 key = [self stringFor:@"key" node:tab ctx:_ctx];
144 if ([key isEqualToString:self->activeKey]) {
145 [super takeValuesForNode:tab fromRequest:_request inContext:_ctx];
149 [_ctx deleteLastElementIDComponent]; // activeKey
150 [_ctx deleteLastElementIDComponent]; /* 'b' */
153 - (id)invokeActionForNode:(id)_node
154 fromRequest:(WORequest *)_request
155 inContext:(WOContext *)_ctx
160 if ((section = [_ctx currentElementID])) {
162 if ([section isEqualToString:@"h"]) {
164 [_ctx consumeElementID];
166 [self forceSetString:[_ctx currentElementID]
173 else if ([section isEqualToString:@"b"]) {
178 selection = [self stringFor:@"selection" node:_node ctx:_ctx];
179 tabs = ODRLookupQueryPath(_node, @"-tab");
182 [_ctx consumeElementID];
183 [_ctx appendElementIDComponent:section];
185 for (i = 0; i < cnt; i++) {
189 tab = [tabs objectAtIndex:i];
190 key = [self stringFor:@"key" node:tab ctx:_ctx];
192 if ([key isEqualToString:selection]) {
193 [_ctx appendElementIDComponent:key];
194 [_ctx consumeElementID];
195 result = [super invokeActionForNode:tab
198 [_ctx deleteLastElementIDComponent];
202 [_ctx deleteLastElementIDComponent];
208 - (void)appendTab:(id)_tab
210 response:(WOResponse *)_response
211 ctx:(WOContext *)_ctx
215 NSString *title = nil;
216 NSString *bgcolor = nil;
217 NSString *width = nil;
218 NSString *height = nil;
219 NSString *bgIcon = nil;
221 NSString *tC, *tF, *tS; // text font attrtibutes
225 key = [self stringFor:@"key" node:_tab ctx:_ctx];
226 title = [self stringFor:@"title" node:_tab ctx:_ctx];
227 isActive = [key isEqualToString:self->activeKey];
229 width = [self stringFor:@"width" node:_node ctx:_ctx];
230 height = [self stringFor:@"height" node:_node ctx:_ctx];
232 ? [self stringFor:@"activebgicon" node:_node ctx:_ctx]
233 : ((_isLeft) ? [self stringFor:@"bgiconleft" node:_node ctx:_ctx]
234 : [self stringFor:@"bgicon" node:_node ctx:_ctx]);
235 bgIcon = ODRUriOfResource(bgIcon, _ctx);
238 ? [self stringFor:@"activecolor" node:_node ctx:_ctx]
239 : [self stringFor:@"inactivecolor" node:_node ctx:_ctx];
241 title = (title) ? title : key;
243 [_ctx appendElementIDComponent:key]; // append tab-key
246 [_response appendContentString:@"<td align=\"center\" valign=\"bottom\""];
248 [_response appendContentString:@" bgcolor=\""];
249 [_response appendContentString:bgcolor];
250 [_response appendContentCharacter:'"'];
253 [_response appendContentString:@" width=\""];
254 [_response appendContentString:width];
255 [_response appendContentCharacter:'"'];
258 [_response appendContentString:@" height=\""];
259 [_response appendContentString:height];
260 [_response appendContentCharacter:'"'];
263 [_response appendContentString:@" background=\""];
264 [_response appendContentString:bgIcon];
265 [_response appendContentCharacter:'"'];
267 [_response appendContentCharacter:'>'];
269 [_response appendContentString:@"<a href='"];
270 [_response appendContentHTMLAttributeValue:[_ctx componentActionURL]];
271 [_response appendContentString:@"' style=\"text-decoration: none;\">"];
273 tC = [self stringFor:@"fontcolor" node:_node ctx:_ctx];
274 tF = [self stringFor:@"fontface" node:_node ctx:_ctx];
275 tS = [self stringFor:@"fontsize" node:_node ctx:_ctx];
277 hasFont = (tC || tF || tS) ? YES : NO;
280 ODRAppendFont(_response, tC, tF, tS); // <font...>
283 [_response appendContentString:@"<b>"];
285 if (!(bgIcon || bgcolor))
286 [_response appendContentString:@"["];
288 [_response appendContentString:title];
290 if (!(bgIcon || bgcolor))
291 [_response appendContentString:@"]"];
294 [_response appendContentString:@"</b>"];
297 [_response appendContentString:@"</font"];
299 [_response appendContentString:@"</a>"];
301 [_response appendContentString:@"</td>"];
303 [_ctx deleteLastElementIDComponent]; // delete tab-key
306 - (void)appendHeaderFootRow:(id)_node
307 toResponse:(WOResponse *)_response
308 inContext:(WOContext *)_ctx
309 isLeftActive:(BOOL)_isLeftActive
311 NSString *bgcolor = nil;
313 /* header foot row */
314 bgcolor = [self stringFor:@"bgcolor" node:_node ctx:_ctx];
316 [_response appendContentString:@"<tr"];
318 [_response appendContentString:@" bgcolor=\""];
319 [_response appendContentHTMLAttributeValue:bgcolor];
320 [_response appendContentString:@"\""];
322 [_response appendContentString:@">"];
325 [_response appendContentString:@"<td align=\"left\" width=\"10\">"];
328 [_response appendContentString:@" "];
330 if (!_isLeftActive) {
333 uri = [self stringFor:@"leftcornericon" node:_node ctx:_ctx];
334 if ((uri = ODRUriOfResource(uri, _ctx))) {
335 [_response appendContentString:@"<img border=\"0\" alt=\"\" src=\""];
336 [_response appendContentString:uri];
337 [_response appendContentString:@"\" />"];
340 [_response appendContentString:@" "];
342 [_response appendContentString:@"</td>"];
345 [_response appendContentString:@"<td align=\"right\">"];
349 uri = [self stringFor:@"rightcornericon" node:_node ctx:_ctx];
350 if ((uri = ODRUriOfResource(uri, _ctx))) {
351 [_response appendContentString:@"<img border=\"0\" alt=\"\" src=\""];
352 [_response appendContentString:uri];
353 [_response appendContentString:@"\" />"];
356 [_response appendContentString:@" "];
358 [_response appendContentString:@"</td>"];
360 [_response appendContentString:@"</tr>"];
363 - (void)appendTabs:(id)_node
364 toResponse:(WOResponse *)_response
365 inContext:(WOContext *)_ctx
369 BOOL isLeftActive = NO, isFirst;
372 [_ctx appendElementIDComponent:@"h"];
374 tabNodes = ODRLookupQueryPath(_node, @"-tab");
375 selection = self->activeKey;
377 /* generate header row */
379 [_response appendContentString:@"<tr>"];
380 [_response appendContentString:
382 @"<table border='0' cellpadding='0' "
383 @"cellspacing='0'><tr>"];
385 for (i = 0, isFirst = YES, count = [tabNodes count]; i < count; i++) {
389 tab = [tabNodes objectAtIndex:i];
391 if ([self boolFor:@"disabled" node:tab ctx:_ctx])
394 key = [self stringFor:@"key" node:tab ctx:_ctx];
395 if (isFirst && [key isEqualToString:selection])
398 [self appendTab:tab node:_node response:_response ctx:_ctx left:isFirst];
401 [_response appendContentString:@"</tr></table></td></tr>"];
403 [_ctx deleteLastElementIDComponent];
405 [self appendHeaderFootRow:_node
408 isLeftActive:isLeftActive];
411 - (void)appendNode:(id)_node
412 toResponse:(WOResponse *)_response
413 inContext:(WOContext *)_ctx
417 [self setActiveKey:_node inContext:_ctx];
419 /* start appending */
420 [_response appendContentString:
421 @"<table border='0' width='100%'"
422 @" cellpadding='0' cellspacing='0'>"];
426 [self appendTabs:_node toResponse:_response inContext:_ctx];
428 bgcolor = [self stringFor:@"bgcolor" node:_node ctx:_ctx];
430 /* append body row */
432 [_response appendContentString:@"<tr><td colspan='2'"];
434 [_response appendContentString:@" bgcolor=\""];
435 [_response appendContentHTMLAttributeValue:bgcolor];
436 [_response appendContentString:@"\""];
438 [_response appendContentString:@">"];
440 if (/*indentContent*/ YES) {
441 /* start padding table */
442 [_response appendContentString:
443 @"<table border='0' width='100%'"
444 @" cellpadding='10' cellspacing='0'>"];
445 [_response appendContentString:@"<tr><td>"];
448 [_ctx appendElementIDComponent:@"b"];
450 /* generate currently active body */
455 tabs = ODRLookupQueryPath(_node, @"-tab");
458 [_ctx appendElementIDComponent:self->activeKey];
459 for (i=0; i<cnt; i++) {
463 tab = [tabs objectAtIndex:i];
464 key = [self stringFor:@"key" node:tab ctx:_ctx];
465 if ([key isEqualToString:self->activeKey]) {
466 [super appendNode:tab toResponse:_response inContext:_ctx];
470 [_ctx deleteLastElementIDComponent];
473 [_ctx deleteLastElementIDComponent];
475 if (/*indentContent*/ YES)
476 /* close padding table */
477 [_response appendContentString:@"</td></tr></table>"];
479 [_response appendContentString:@"</td></tr>"];
482 [_response appendContentString:@"</table>"];
485 @end /* ODR_bind_tabview */