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
24 @interface WOImageButton : WOInput
26 // WODynamicElement: extraAttributes
27 // WODynamicElement: otherTagString
32 WOAssociation *filename; // image path relative to WebServerResources
33 WOAssociation *framework;
34 WOAssociation *src; // absolute URL
35 WOAssociation *action;
36 WOAssociation *pageName;
41 WOAssociation *queryDictionary;
42 NSDictionary *queryParameters; // associations beginning with ?
43 WOAssociation *actionClass;
44 WOAssociation *directActionName;
48 WOAssociation *disabledFilename; // image path to icon for 'disabled' state
51 @end /* WOImageButton */
53 #include <NGObjWeb/WOApplication.h>
54 #include <NGObjWeb/WOResourceManager.h>
57 @implementation WOImageButton
63 - (id)initWithName:(NSString *)_name
64 associations:(NSDictionary *)_config
65 template:(WOElement *)_t
67 if ((self = [super initWithName:_name associations:_config template:_t])) {
68 WOAssociation *sidInUrlAssoc;
70 sidInUrlAssoc = OWGetProperty(_config, @"?wosid");
71 self->action = OWGetProperty(_config, @"action");
72 self->filename = OWGetProperty(_config, @"filename");
73 self->framework = OWGetProperty(_config, @"framework");
74 self->pageName = OWGetProperty(_config, @"pageName");
75 self->x = OWGetProperty(_config, @"x");
76 self->y = OWGetProperty(_config, @"y");
78 self->queryDictionary = OWGetProperty(_config, @"queryDictionary");
79 self->queryParameters = OWExtractQueryParameters(_config);
80 self->actionClass = OWGetProperty(_config, @"actionClass");
81 self->directActionName = OWGetProperty(_config, @"directActionName");
83 self->disabledFilename = OWGetProperty(_config, @"disabledFilename");
85 self->sidInUrl = (sidInUrlAssoc)
86 ? [sidInUrlAssoc boolValueInComponent:nil]
93 [self->actionClass release];
94 [self->directActionName release];
95 [self->queryDictionary release];
96 [self->queryParameters release];
97 [self->action release];
98 [self->disabledFilename release];
99 [self->framework release];
100 [self->filename release];
102 [self->pageName release];
108 /* handling requests */
110 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
111 WOComponent *sComponent = [_ctx component];
112 NSString *baseId = nil;
116 //NSLog(@"%s: take values ...", __PRETTY_FUNCTION__);
118 if (self->disabled != nil) {
119 if ([self->disabled boolValueInComponent:sComponent])
123 baseId = OWFormElementName(self, _ctx);
125 xVal = [_rq formValueForKey:[baseId stringByAppendingString:@".x"]];
126 yVal = [_rq formValueForKey:[baseId stringByAppendingString:@".y"]];
129 if ([self->x isValueSettable]) {
130 [self->x setUnsignedIntValue:[xVal unsignedIntValue]
131 inComponent:sComponent];
135 if ([self->y isValueSettable]) {
136 [self->y setUnsignedIntValue:[yVal unsignedIntValue]
137 inComponent:sComponent];
141 if (((xVal != nil) || (yVal != nil)) &&
142 ((self->action != nil) || (self->pageName != nil))) {
143 /* should perform action */
144 [_ctx addActiveFormElement:self];
148 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
149 if (self->disabled != nil) {
150 if ([self->disabled boolValueInComponent:[_ctx component]])
154 /* check whether this is the active form element (determined above) */
155 if (![[_ctx elementID] isEqualToString:[_ctx senderID]]) {
156 NSLog(@"WOImageButton is not active (%@ vs %@) !",
157 [_ctx elementID], [_ctx senderID]);
162 return [self executeAction:self->action inContext:_ctx];
164 if (self->pageName) {
165 NSString *pname = nil;
166 WOComponent *page = nil;
168 pname = [self->pageName stringValueInComponent:[_ctx component]];
169 page = [[_ctx application] pageWithName:pname inContext:_ctx];
172 [[_ctx session] logWithFormat:
173 @"%@[0x%08X]: did not find page with name %@ !",
174 NSStringFromClass([self class]), self, pname];
176 NSLog(@"%@: showing page %@", self, page);
182 /* generating response */
184 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
185 WOComponent *sComponent = [_ctx component];
186 NSString *uUri = nil;
190 uUri = [self->src stringValueInComponent:sComponent];
192 if ((isDisabled = [self->disabled boolValueInComponent:sComponent])) {
193 uFi = [self->disabledFilename stringValueInComponent:sComponent];
195 uFi = [self->filename stringValueInComponent:sComponent];
198 uFi = [self->filename stringValueInComponent:sComponent];
201 WOResponse_AddCString(_response, "<img");
204 WOResponse_AddCString(_response, "<input type=\"image\" name=\"");
205 [_response appendContentHTMLAttributeValue:OWFormElementName(self, _ctx)];
206 WOResponse_AddChar(_response, '"');
209 WOResponse_AddCString(_response, " src=\"");
211 WOResourceManager *rm;
213 NSString *frameworkName;
215 if ((rm = [[_ctx component] resourceManager]) == nil)
216 rm = [[_ctx application] resourceManager];
218 langs = [_ctx resourceLookupLanguages];
220 /* If 'framework' binding is not set, use parent component's framework */
221 if (self->framework){
222 frameworkName = [self->framework stringValueInComponent:sComponent];
223 if (frameworkName != nil && [frameworkName isEqualToString:@"app"])
227 frameworkName = [sComponent frameworkName];
229 uFi = [rm urlForResourceNamed:uFi
230 inFramework:frameworkName
232 request:[_ctx request]];
234 NSLog(@"%@: did not find resource '%@'", sComponent,
235 [self->filename stringValueInComponent:sComponent]);
238 [_response appendContentHTMLAttributeValue:uFi];
241 [_response appendContentHTMLAttributeValue:uUri];
242 WOResponse_AddChar(_response, '"');
244 [self appendExtraAttributesToResponse:_response inContext:_ctx];
245 if (self->otherTagString != nil) {
248 s = [self->otherTagString stringValueInComponent:sComponent];
249 WOResponse_AddChar(_response, ' ');
250 WOResponse_AddString(_response, s);
252 WOResponse_AddEmptyCloseParens(_response, _ctx);
257 - (NSString *)associationDescription {
258 NSMutableString *str;
260 str = [NSMutableString stringWithCapacity:128];
261 [str appendString:[super associationDescription]];
262 if (self->action) [str appendFormat:@" action=%@", self->action];
263 if (self->pageName) [str appendFormat:@" page=%@", self->pageName];
264 if (self->filename) [str appendFormat:@" file=%@", self->filename];
265 if (self->src) [str appendFormat:@" src=%@", self->src];
266 if (self->x) [str appendFormat:@" x=%@", self->x];
267 if (self->y) [str appendFormat:@" y=%@", self->y];
269 if (self->actionClass)
270 [str appendFormat:@" actionClass=%@", self->actionClass];
271 if (self->directActionName)
272 [str appendFormat:@" directAction=%@", self->directActionName];
277 @end /* WOImageButton */