1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
/*
Copyright (C) 2000-2005 SKYRIX Software AG
This file is part of SOPE.
SOPE is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#include "WOInput.h"
@interface WOImageButton : WOInput
{
// WODynamicElement: extraAttributes
// WODynamicElement: otherTagString
// WOInput: name
// WOInput: value
// WOInput: disabled
@protected
WOAssociation *filename; // image path relative to WebServerResources
WOAssociation *framework;
WOAssociation *src; // absolute URL
WOAssociation *action;
WOAssociation *pageName;
WOAssociation *x;
WOAssociation *y;
// new in WO4:
WOAssociation *queryDictionary;
NSDictionary *queryParameters; // associations beginning with ?
WOAssociation *actionClass;
WOAssociation *directActionName;
BOOL sidInUrl;
// non-WO
WOAssociation *disabledFilename; // image path to icon for 'disabled' state
}
@end /* WOImageButton */
#include <NGObjWeb/WOApplication.h>
#include <NGObjWeb/WOResourceManager.h>
#include "decommon.h"
@implementation WOImageButton
- (id)initWithName:(NSString *)_name
associations:(NSDictionary *)_config
template:(WOElement *)_t
{
if ((self = [super initWithName:_name associations:_config template:_t])) {
WOAssociation *sidInUrlAssoc;
sidInUrlAssoc = OWGetProperty(_config, @"?wosid");
self->action = OWGetProperty(_config, @"action");
self->filename = OWGetProperty(_config, @"filename");
self->framework = OWGetProperty(_config, @"framework");
self->pageName = OWGetProperty(_config, @"pageName");
self->x = OWGetProperty(_config, @"x");
self->y = OWGetProperty(_config, @"y");
self->queryDictionary = OWGetProperty(_config, @"queryDictionary");
self->queryParameters = OWExtractQueryParameters(_config);
self->actionClass = OWGetProperty(_config, @"actionClass");
self->directActionName = OWGetProperty(_config, @"directActionName");
self->disabledFilename = OWGetProperty(_config, @"disabledFilename");
self->sidInUrl = (sidInUrlAssoc)
? [sidInUrlAssoc boolValueInComponent:nil]
: YES;
}
return self;
}
- (void)dealloc {
[self->actionClass release];
[self->directActionName release];
[self->queryDictionary release];
[self->queryParameters release];
[self->action release];
[self->disabledFilename release];
[self->framework release];
[self->filename release];
[self->src release];
[self->pageName release];
[self->x release];
[self->y release];
[super dealloc];
}
/* handling requests */
- (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
WOComponent *sComponent = [_ctx component];
NSString *baseId = nil;
id xVal = nil;
id yVal = nil;
//NSLog(@"%s: take values ...", __PRETTY_FUNCTION__);
if (self->disabled != nil) {
if ([self->disabled boolValueInComponent:sComponent])
return;
}
baseId = OWFormElementName(self, _ctx);
xVal = [_rq formValueForKey:[baseId stringByAppendingString:@".x"]];
yVal = [_rq formValueForKey:[baseId stringByAppendingString:@".y"]];
if (xVal) {
if ([self->x isValueSettable]) {
[self->x setUnsignedIntValue:[xVal unsignedIntValue]
inComponent:sComponent];
}
}
if (yVal) {
if ([self->y isValueSettable]) {
[self->y setUnsignedIntValue:[yVal unsignedIntValue]
inComponent:sComponent];
}
}
if (((xVal != nil) || (yVal != nil)) &&
((self->action != nil) || (self->pageName != nil))) {
/* should perform action */
[_ctx addActiveFormElement:self];
}
}
- (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
if (self->disabled != nil) {
if ([self->disabled boolValueInComponent:[_ctx component]])
return nil;
}
/* check whether this is the active form element (determined above) */
if (![[_ctx elementID] isEqualToString:[_ctx senderID]]) {
NSLog(@"WOImageButton is not active (%@ vs %@) !",
[_ctx elementID], [_ctx senderID]);
return nil;
}
if (self->action)
return [self executeAction:self->action inContext:_ctx];
if (self->pageName) {
NSString *pname = nil;
WOComponent *page = nil;
pname = [self->pageName stringValueInComponent:[_ctx component]];
page = [[_ctx application] pageWithName:pname inContext:_ctx];
if (page == nil) {
[[_ctx session] logWithFormat:
@"%@[0x%p]: did not find page with name %@ !",
NSStringFromClass([self class]), self, pname];
}
NSLog(@"%@: showing page %@", self, page);
return page;
}
return nil;
}
/* generating response */
- (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
WOComponent *sComponent;
NSString *uUri = nil;
NSString *uFi = nil;
BOOL isDisabled;
if ([_ctx isRenderingDisabled]) return;
sComponent = [_ctx component];
uUri = [self->src stringValueInComponent:sComponent];
if ((isDisabled = [self->disabled boolValueInComponent:sComponent])) {
uFi = [self->disabledFilename stringValueInComponent:sComponent];
if (uFi == nil)
uFi = [self->filename stringValueInComponent:sComponent];
}
else
uFi = [self->filename stringValueInComponent:sComponent];
if (isDisabled) {
WOResponse_AddCString(_response, "<img");
}
else {
WOResponse_AddCString(_response, "<input type=\"image\" name=\"");
[_response appendContentHTMLAttributeValue:OWFormElementName(self, _ctx)];
WOResponse_AddChar(_response, '"');
}
WOResponse_AddCString(_response, " src=\"");
if (uFi != nil) {
WOResourceManager *rm;
NSArray *langs;
NSString *frameworkName;
if ((rm = [[_ctx component] resourceManager]) == nil)
rm = [[_ctx application] resourceManager];
langs = [_ctx resourceLookupLanguages];
/* If 'framework' binding is not set, use parent component's framework */
if (self->framework){
frameworkName = [self->framework stringValueInComponent:sComponent];
if (frameworkName != nil && [frameworkName isEqualToString:@"app"])
frameworkName = nil;
}
else
frameworkName = [sComponent frameworkName];
uFi = [rm urlForResourceNamed:uFi
inFramework:frameworkName
languages:langs
request:[_ctx request]];
if (uFi == nil) {
NSLog(@"%@: did not find resource '%@'", sComponent,
[self->filename stringValueInComponent:sComponent]);
uFi = uUri;
}
[_response appendContentHTMLAttributeValue:uFi];
}
else
[_response appendContentHTMLAttributeValue:uUri];
WOResponse_AddChar(_response, '"');
[self appendExtraAttributesToResponse:_response inContext:_ctx];
if (self->otherTagString != nil) {
NSString *s;
s = [self->otherTagString stringValueInComponent:sComponent];
WOResponse_AddChar(_response, ' ');
WOResponse_AddString(_response, s);
}
WOResponse_AddEmptyCloseParens(_response, _ctx);
}
/* description */
- (NSString *)associationDescription {
NSMutableString *str;
str = [NSMutableString stringWithCapacity:128];
[str appendString:[super associationDescription]];
if (self->action) [str appendFormat:@" action=%@", self->action];
if (self->pageName) [str appendFormat:@" page=%@", self->pageName];
if (self->filename) [str appendFormat:@" file=%@", self->filename];
if (self->src) [str appendFormat:@" src=%@", self->src];
if (self->x) [str appendFormat:@" x=%@", self->x];
if (self->y) [str appendFormat:@" y=%@", self->y];
if (self->actionClass)
[str appendFormat:@" actionClass=%@", self->actionClass];
if (self->directActionName)
[str appendFormat:@" directAction=%@", self->directActionName];
return str;
}
@end /* WOImageButton */
|