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 <NGObjWeb/WODynamicElement.h>
24 @interface WETableMatrixLabel : WODynamicElement
26 WOAssociation *position; /* top, bottom, left, right, topleft */
27 WOAssociation *elementName;
29 WOAssociation *string;
35 #include <NGObjWeb/NGObjWeb.h>
38 @implementation WETableMatrixLabel
40 static Class StrClass = Nil;
43 static BOOL didInit = NO;
47 StrClass = [NSString class];
50 static NSString *retStrForInt(int i) {
62 case 10: return @"10";
63 // TODO: find useful count!
65 return [[StrClass alloc] initWithFormat:@"%i", i];
69 - (id)initWithName:(NSString *)_name
70 associations:(NSDictionary *)_config
71 template:(WOElement *)_subs
73 if ((self = [super initWithName:_name associations:_config template:_subs])) {
74 self->position = WOExtGetProperty(_config, @"position");
75 if (self->position == nil)
76 self->position = [[WOAssociation associationWithValue:@"top"] retain];
78 self->elementName = WOExtGetProperty(_config, @"elementName");
79 self->span = WOExtGetProperty(_config, @"span");
80 self->string = WOExtGetProperty(_config, @"string");
82 self->template = [_subs retain];
88 [self->string release];
90 [self->elementName release];
91 [self->position release];
92 [self->template release];
96 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
102 pos = [self->position stringValueInComponent:[_ctx component]];
104 if ((tmp = [_ctx valueForKey:@"WETableMatrix_Query"])) {
109 if ((tmp = [_ctx valueForKey:@"WETableMatrix_Mode"]) == nil)
112 if (![tmp isEqualToString:pos])
115 /* check span (some kind of condition) */
117 ispan = [self->span intValueInComponent:[_ctx component]];
118 if (ispan < 1) ispan = 1;
123 idx = [[_ctx objectForKey:@"WETableMatrix_Index"] intValue];
124 if (idx % ispan != 0)
125 /* the label is not active in that column/row */
131 tag = [self->elementName stringValueInComponent:[_ctx component]];
137 [_response appendContentString:@"<"];
138 [_response appendContentString:tag];
140 rspan = [[_ctx objectForKey:@"WETableMatrix_RowSpan"] intValue];
141 cspan = [[_ctx objectForKey:@"WETableMatrix_ColSpan"] intValue];
144 [_response appendContentString:@" rowspan=\""];
145 s = retStrForInt(rspan);
146 [_response appendContentString:s];
148 [_response appendContentString:@"\""];
151 [_response appendContentString:@" colspan=\""];
152 s = retStrForInt(cspan);
153 [_response appendContentString:s];
155 [_response appendContentString:@"\""];
159 if ([tmp isEqualToString:@"bottom"] || [tmp isEqualToString:@"top"]) {
160 [_response appendContentString:@" colspan=\""];
161 NSAssert(cspan <= 1, @"double row-span !!");
164 [_response appendContentString:@" rowspan=\""];
165 NSAssert(rspan <= 1, @"double row-span !!");
167 s = retStrForInt(ispan);
168 [_response appendContentString:s];
170 [_response appendContentString:@"\""];
173 if ([tmp isEqualToString:@"top"]) {
179 count = [[_ctx objectForKey:@"WETableMatrix_Count"] intValue];
180 width = 100.0 / ((double)count / (double)ispan);
182 sprintf(buf, "%.0f", width);
183 s = [[StrClass alloc] initWithCString:buf];
185 [_response appendContentString:@" width=\""];
186 [_response appendContentString:s];
187 [_response appendContentString:@"%\""];
192 [self appendExtraAttributesToResponse:_response inContext:_ctx];
193 [_response appendContentString:@">"];
198 s = [self->string stringValueInComponent:[_ctx component]];
199 [_response appendContentHTMLString:s];
201 [self->template appendToResponse:_response inContext:_ctx];
204 [_response appendContentString:@"</"];
205 [_response appendContentString:tag];
206 [_response appendContentString:@">"];
210 @end /* WETableMatrixLabel */