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 WERichString : WODynamicElement
27 WOAssociation *isBold;
28 WOAssociation *isItalic;
29 WOAssociation *isUnderlined;
30 WOAssociation *isSmall;
34 WOAssociation *insertBR;
36 WOAssociation *condition;
37 WOAssociation *negate;
39 WOAssociation *formatter;
48 #include <NGObjWeb/NGObjWeb.h>
51 @implementation WERichString
53 - (id)initWithName:(NSString *)_name
54 associations:(NSDictionary *)_config
55 template:(WOElement *)_t
57 if ((self = [super initWithName:_name associations:_config template:_t])) {
58 self->value = OWGetProperty(_config, @"value");
60 self->isBold = OWGetProperty(_config, @"isBold");
61 self->isItalic = OWGetProperty(_config, @"isItalic");
62 self->isUnderlined = OWGetProperty(_config, @"isUnderlined");
63 self->isSmall = OWGetProperty(_config, @"isSmall");
64 self->color = OWGetProperty(_config, @"color");
65 self->face = OWGetProperty(_config, @"face");
66 self->size = OWGetProperty(_config, @"size");
67 self->insertBR = OWGetProperty(_config, @"insertBR");
69 self->condition = OWGetProperty(_config, @"condition");
70 self->negate = OWGetProperty(_config, @"negate");
72 self->formatter = OWGetProperty(_config, @"formatter");
74 ASSIGN(self->template, _t);
81 RELEASE(self->isBold);
82 RELEASE(self->isItalic);
83 RELEASE(self->isUnderlined);
84 RELEASE(self->isSmall);
88 RELEASE(self->insertBR);
89 RELEASE(self->formatter);
91 RELEASE(self->condition);
92 RELEASE(self->negate);
94 RELEASE(self->template);
99 static inline BOOL _doShow(WERichString *self, WOContext *_ctx) {
103 if (self->condition != nil) {
104 doShow = [self->condition boolValueInComponent:[_ctx component]];
105 doNegate = [self->negate boolValueInComponent:[_ctx component]];
108 return (doNegate) ? !doShow : doShow;
111 - (void)takeValuesFromRequest:(WORequest *)_request
112 inContext:(WOContext *)_ctx
114 if (_doShow(self, _ctx)) {
115 [_ctx appendElementIDComponent:@"1"];
116 [self->template takeValuesFromRequest:_request inContext:_ctx];
117 [_ctx deleteLastElementIDComponent];
121 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
124 state = [[_ctx currentElementID] stringValue];
127 [_ctx consumeElementID]; // consume state-id (on or off)
129 if ([state isEqualToString:@"1"]) {
132 [_ctx appendElementIDComponent:state];
133 result = [self->template invokeActionForRequest:_request inContext:_ctx];
134 [_ctx deleteLastElementIDComponent];
142 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
143 WOComponent *comp = nil;
146 BOOL doUnderlined = NO;
148 NSString *color_ = nil;
149 NSString *face_ = nil;
150 NSString *size_ = nil;
151 NSFormatter *fmt = nil;
155 if (!_doShow(self, _ctx)) return;
157 comp = [_ctx component];
159 doBold = [self->isBold boolValueInComponent:comp];
160 doItalic = [self->isItalic boolValueInComponent:comp];
161 doUnderlined = [self->isUnderlined boolValueInComponent:comp];
162 doSmall = [self->isSmall boolValueInComponent:comp];
163 face_ = [self->face stringValueInComponent:comp];
164 color_ = [self->color stringValueInComponent:comp];
165 size_ = [self->size stringValueInComponent:comp];
166 v = [self->value valueInComponent:comp];
167 fmt = [self->formatter valueInComponent:comp];
170 [_response appendContentString:@"<small>"];
172 [_response appendContentString:@"<b>"];
174 [_response appendContentString:@"<i>"];
176 [_response appendContentString:@"<u>"];
178 [_response appendContentString:@"<font"];
180 [_response appendContentString:@" color='"];
181 [_response appendContentHTMLString:color_];
182 [_response appendContentCharacter:'\''];
185 [_response appendContentString:@" face='"];
186 [_response appendContentHTMLString:face_];
187 [_response appendContentCharacter:'\''];
190 [_response appendContentString:@" size='"];
191 [_response appendContentHTMLString:size_];
192 [_response appendContentCharacter:'\''];
194 [_response appendContentCharacter:'>'];
196 [_ctx appendElementIDComponent:@"1"];
197 [self->template appendToResponse:_response inContext:_ctx];
198 [_ctx deleteLastElementIDComponent];
201 ? [fmt stringForObjectValue:v]
204 if (v && [self->insertBR boolValueInComponent:comp]) {
208 lines = [v componentsSeparatedByString:@"\n"];
209 count = [lines count];
210 for (i = 0; i < count; i++) {
211 NSString *line = [lines objectAtIndex:i];
213 if (i != 0) [_response appendContentString:@"<br />"];
215 [_response appendContentHTMLString:line];
219 [_response appendContentHTMLString:v];
221 [_response appendContentString:@"</font>"];
223 [_response appendContentString:@"</u>"];
225 [_response appendContentString:@"</i>"];
227 [_response appendContentString:@"</b>"];
229 [_response appendContentString:@"</small>"];