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 <NGObjWeb/WODynamicElement.h>
25 @interface WETableMatrixLabel : WODynamicElement
27 WOAssociation *position; /* top, bottom, left, right, topleft */
28 WOAssociation *elementName;
30 WOAssociation *string;
36 #include <NGObjWeb/NGObjWeb.h>
39 @implementation WETableMatrixLabel
41 static Class StrClass = Nil;
44 static BOOL didInit = NO;
48 StrClass = [NSString class];
51 static NSString *retStrForInt(int i) {
63 case 10: return @"10";
64 // TODO: find useful count!
66 return [[StrClass alloc] initWithFormat:@"%i", i];
70 - (id)initWithName:(NSString *)_name
71 associations:(NSDictionary *)_config
72 template:(WOElement *)_subs
74 if ((self = [super initWithName:_name associations:_config template:_subs])) {
75 self->position = WOExtGetProperty(_config, @"position");
76 if (self->position == nil)
77 self->position = [[WOAssociation associationWithValue:@"top"] retain];
79 self->elementName = WOExtGetProperty(_config, @"elementName");
80 self->span = WOExtGetProperty(_config, @"span");
81 self->string = WOExtGetProperty(_config, @"string");
83 self->template = [_subs retain];
89 [self->string release];
91 [self->elementName release];
92 [self->position release];
93 [self->template release];
97 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
103 pos = [self->position stringValueInComponent:[_ctx component]];
105 if ((tmp = [_ctx valueForKey:@"WETableMatrix_Query"])) {
110 if ((tmp = [_ctx valueForKey:@"WETableMatrix_Mode"]) == nil)
113 if (![tmp isEqualToString:pos])
116 /* check span (some kind of condition) */
118 ispan = [self->span intValueInComponent:[_ctx component]];
119 if (ispan < 1) ispan = 1;
124 idx = [[_ctx objectForKey:@"WETableMatrix_Index"] intValue];
125 if (idx % ispan != 0)
126 /* the label is not active in that column/row */
132 tag = [self->elementName stringValueInComponent:[_ctx component]];
138 [_response appendContentString:@"<"];
139 [_response appendContentString:tag];
141 rspan = [[_ctx objectForKey:@"WETableMatrix_RowSpan"] intValue];
142 cspan = [[_ctx objectForKey:@"WETableMatrix_ColSpan"] intValue];
145 [_response appendContentString:@" rowspan=\""];
146 s = retStrForInt(rspan);
147 [_response appendContentString:s];
149 [_response appendContentString:@"\""];
152 [_response appendContentString:@" colspan=\""];
153 s = retStrForInt(cspan);
154 [_response appendContentString:s];
156 [_response appendContentString:@"\""];
160 if ([tmp isEqualToString:@"bottom"] || [tmp isEqualToString:@"top"]) {
161 [_response appendContentString:@" colspan=\""];
162 NSAssert(cspan <= 1, @"double row-span !!");
165 [_response appendContentString:@" rowspan=\""];
166 NSAssert(rspan <= 1, @"double row-span !!");
168 s = retStrForInt(ispan);
169 [_response appendContentString:s];
171 [_response appendContentString:@"\""];
174 if ([tmp isEqualToString:@"top"]) {
180 count = [[_ctx objectForKey:@"WETableMatrix_Count"] intValue];
181 width = 100.0 / ((double)count / (double)ispan);
183 sprintf(buf, "%.0f", width);
184 s = [[StrClass alloc] initWithCString:buf];
186 [_response appendContentString:@" width=\""];
187 [_response appendContentString:s];
188 [_response appendContentString:@"%\""];
193 [self appendExtraAttributesToResponse:_response inContext:_ctx];
194 [_response appendContentString:@">"];
199 s = [self->string stringValueInComponent:[_ctx component]];
200 [_response appendContentHTMLString:s];
202 [self->template appendToResponse:_response inContext:_ctx];
205 [_response appendContentString:@"</"];
206 [_response appendContentString:tag];
207 [_response appendContentString:@">"];
211 @end /* WETableMatrixLabel */