/** GSWImageButton.m -
GSWeb: Class GSWImageButton
Copyright (C) 1999-2004 Free Software Foundation, Inc.
Written by: Manuel Guesdon
Date: Jan 1999
$Revision$
$Date$
This file is part of the GNUstep Web Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include "config.h"
RCS_ID("$Id$")
#include "GSWeb.h"
//====================================================================
@implementation GSWImageButton
//--------------------------------------------------------------------
-(id)initWithName:(NSString*)aName
associations:(NSDictionary*)associations
contentElements:(NSArray*)elements;
{
//OK
NSMutableDictionary* tmpAssociations=nil;
LOGObjectFnStart();
NSDebugMLLog(@"gswdync",@"aName=%@ associations:%@ elements=%@",
aName,associations,elements);
tmpAssociations=[NSMutableDictionary dictionaryWithDictionary:associations];
[tmpAssociations removeObjectForKey:imageMapFileName__Key];
if (!WOStrictFlag)
{
[tmpAssociations removeObjectForKey:imageMapString__Key];
[tmpAssociations removeObjectForKey:imageMapRegions__Key];
[tmpAssociations removeObjectForKey:cidStore__Key];
[tmpAssociations removeObjectForKey:cidKey__Key];
};
[tmpAssociations removeObjectForKey:action__Key];
[tmpAssociations removeObjectForKey:actionClass__Key];
[tmpAssociations removeObjectForKey:directActionName__Key];
[tmpAssociations removeObjectForKey:x__Key];
[tmpAssociations removeObjectForKey:y__Key];
[tmpAssociations removeObjectForKey:filename__Key];
[tmpAssociations removeObjectForKey:framework__Key];
[tmpAssociations removeObjectForKey:src__Key];
[tmpAssociations removeObjectForKey:data__Key];
[tmpAssociations removeObjectForKey:mimeType__Key];
[tmpAssociations removeObjectForKey:key__Key];
if ((self=[super initWithName:aName
associations:tmpAssociations
contentElements:elements]))
{
int imageMapDefNb=0;
_action = [[associations objectForKey:action__Key
withDefaultObject:[_action autorelease]] retain];
NSDebugMLLog(@"gswdync",@"action=%@",_action);
if ([_action isValueConstant])
{
ExceptionRaise0(@"GSWImageButton",@"'Action' parameter can't be a constant association");
};
_imageMapFileName = [[associations objectForKey:imageMapFileName__Key
withDefaultObject:[_imageMapFileName autorelease]] retain];
if (_imageMapFileName)
imageMapDefNb++;
NSDebugMLLog(@"gswdync",@"imageMapFileName=%@",_imageMapFileName);
if (!WOStrictFlag)
{
_imageMapString = [[associations objectForKey:imageMapString__Key
withDefaultObject:[_imageMapString autorelease]] retain];
if (_imageMapString)
imageMapDefNb++;
_imageMapRegions = [[associations objectForKey:imageMapRegions__Key
withDefaultObject:[_imageMapRegions autorelease]] retain];
if (_imageMapRegions)
imageMapDefNb++;
if (imageMapDefNb>0)
{
ExceptionRaise(@"GSWActiveImage",@"you can't specify %@, %@ and %@",
imageMapFileName__Key,
imageMapString__Key,
imageMapRegions__Key);
};
_cidStore = [[associations objectForKey:cidStore__Key
withDefaultObject:[_cidStore autorelease]] retain];
NSDebugMLLog(@"gswdync",@"cidStore=%@",_cidStore);
_cidKey = [[associations objectForKey:cidKey__Key
withDefaultObject:[_cidKey autorelease]] retain];
NSDebugMLLog(@"gswdync",@"cidKey=%@",_cidKey);
};
_actionClass = [[associations objectForKey:actionClass__Key
withDefaultObject:[_actionClass autorelease]] retain];
NSDebugMLLog(@"gswdync",@"actionClass=%@",_actionClass);
_directActionName = [[associations objectForKey:directActionName__Key
withDefaultObject:[_directActionName autorelease]] retain];
NSDebugMLLog(@"gswdync",@"directActionName=%@",_directActionName);
_xAssoc = [[associations objectForKey:x__Key
withDefaultObject:[_xAssoc autorelease]] retain];
_yAssoc = [[associations objectForKey:y__Key
withDefaultObject:[_yAssoc autorelease]] retain];
_filename = [[associations objectForKey:filename__Key
withDefaultObject:[_filename autorelease]] retain];
_framework = [[associations objectForKey:framework__Key
withDefaultObject:[_framework autorelease]] retain];
_src = [[associations objectForKey:src__Key
withDefaultObject:[_src autorelease]] retain];
NSDebugMLLog(@"gswdync",@"src=%@",_src);
_data = [[associations objectForKey:data__Key
withDefaultObject:[_data autorelease]] retain];
NSDebugMLLog(@"gswdync",@"data=%@",_data);
_mimeType = [[associations objectForKey:mimeType__Key
withDefaultObject:[_mimeType autorelease]] retain];
_key = [[associations objectForKey:key__Key
withDefaultObject:[_key autorelease]] retain];
};
return self;
};
//--------------------------------------------------------------------
-(void)dealloc
{
DESTROY(_imageMapFileName);
DESTROY(_imageMapString);//GSWeb only
DESTROY(_imageMapRegions);//GSWeb Only
DESTROY(_cidStore);//GSWeb only
DESTROY(_cidKey);//GSWeb only
DESTROY(_action);
DESTROY(_actionClass);
DESTROY(_directActionName);
DESTROY(_xAssoc);
DESTROY(_yAssoc);
DESTROY(_filename);
DESTROY(_framework);
DESTROY(_src);
DESTROY(_data);
DESTROY(_mimeType);
DESTROY(_key);
[super dealloc];
};
//--------------------------------------------------------------------
-(NSString*)elementName
{
return nil;//@"ELEMENTCHOSENBYCONTEXT";//TODO
};
//--------------------------------------------------------------------
-(NSString*)description
{
return [NSString stringWithFormat:@"<%s %p>",
object_get_class_name(self),
(void*)self];
};
@end
//====================================================================
@implementation GSWImageButton (GSWImageButtonA)
-(GSWAssociation*)hitTestX:(int)x
y:(int)y
inRegions:(NSArray*)regions
{
GSWAssociation* assoc=nil;
GSWGeometricRegion* region=[GSWGeometricRegion hitTestX:x
y:y
inRegions:regions];
if (region)
assoc=[GSWAssociation associationWithKeyPath:[region userDefinedString]];
else
assoc=_action;
return assoc;
};
@end
//====================================================================
@implementation GSWImageButton (GSWImageButtonB)
//--------------------------------------------------------------------
-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response
inContext:(GSWContext*)context
{
//OK
NSString* urlValue=nil;
NSString* name=nil;
BOOL disabledInContext=NO;
GSWComponent* component=nil;
GSWResourceManager* resourceManager=nil;
GSWURLValuedElementData* dataValue=nil;
NSString* keyValue=nil;
id cidStoreValue=nil;
LOGObjectFnStart();
disabledInContext=[self disabledInContext:context];
[response _appendContentAsciiString:@" type=image"];
name=[self nameInContext:context];
NSDebugMLLog(@"gswdync",@"declarationName=%@ name=%@",
[self declarationName],name);
[response _appendContentAsciiString:@" name=\""];
[response appendContentHTMLAttributeValue:name];
[response appendContentCharacter:'"'];
component=[context component];
cidStoreValue=[_cidStore valueInComponent:component];
NSDebugMLLog(@"gswdync",@"cidStoreValue=%@",cidStoreValue);
resourceManager=[[GSWApplication application]resourceManager];
if (_src)
{
urlValue=[_src valueInComponent:component];
if (cidStoreValue)
{
urlValue=[self addURL:urlValue
forCIDKeyAssociation:_cidKey
CIDStoreAssociation:_cidStore
inContext:context];
NSDebugMLLog(@"gswdync",@"urlValue=%@",urlValue);
};
}
else
{
if (_key)
{
keyValue=[_key valueInComponent:component];
dataValue=[resourceManager _cachedDataForKey:keyValue];
if (cidStoreValue && dataValue)
{
urlValue=[self addURLValuedElementData:dataValue
forCIDKeyAssociation:_cidKey
CIDStoreAssociation:_cidStore
inContext:context];
NSDebugMLLog(@"gswdync",@"urlValue=%@",urlValue);
}
};
if (!dataValue && _data)
{
id tmpDataValue=[_data valueInComponent:component];
id mimeTypeValue=[_mimeType valueInComponent:component];
dataValue=[[[GSWURLValuedElementData alloc] initWithData:tmpDataValue
mimeType:mimeTypeValue
key:keyValue] autorelease];
[resourceManager setURLValuedElementData:dataValue];
if (cidStoreValue && dataValue)
{
urlValue=[self addURLValuedElementData:dataValue
forCIDKeyAssociation:_cidKey
CIDStoreAssociation:_cidStore
inContext:context];
NSDebugMLLog(@"gswdync",@"urlValue=%@",urlValue);
}
}
else if (_filename)
{
id filenameValue=nil;
id frameworkValue=nil;
GSWRequest* request=nil;
NSArray* languages=nil;
NSDebugMLLog(@"gswdync",@"filename=%@",_filename);
filenameValue=[_filename valueInComponent:component];
NSDebugMLLog(@"gswdync",@"filenameValue=%@",filenameValue);
frameworkValue=[self frameworkNameInContext:context];
NSDebugMLLog(@"gswdync",@"frameworkValue=%@",frameworkValue);
request=[context request];
languages=[context languages];
if (cidStoreValue)
{
NSString* path=[resourceManager pathForResourceNamed:filenameValue
inFramework:frameworkValue
languages:languages];
urlValue=[self addPath:path
forCIDKeyAssociation:_cidKey
CIDStoreAssociation:_cidStore
inContext:context];
NSDebugMLLog(@"gswdync",@"urlValue=%@",urlValue);
}
else
{
urlValue=[resourceManager urlForResourceNamed:filenameValue
inFramework:frameworkValue
languages:languages
request:request];
};
};
};
[response _appendContentAsciiString:@" src=\""];
if (_src)
{
[response appendContentString:urlValue];
}
else
{
if (_key || _data)
{
if (cidStoreValue)
[response appendContentString:urlValue];
else
[dataValue appendDataURLToResponse:response
inContext:context];
}
else if (_filename)
{
[response appendContentString:urlValue];
}
else
{
GSWDynamicURLString* componentActionURL=[context componentActionURL];
NSDebugMLLog(@"gswdync",@"componentActionURL=%@",componentActionURL);
[response appendContentString:(NSString*)componentActionURL];
};
};
[response appendContentCharacter:'"'];
LOGObjectFnStop();
};
//--------------------------------------------------------------------
-(id)_imageURLInContext:(GSWContext*)context
{
LOGObjectFnNotImplemented(); //TODOFN
return nil;
};
//--------------------------------------------------------------------
-(void)appendToResponse:(GSWResponse*)response
inContext:(GSWContext*)context
{
//OK
//GSWRequest* request=[context request];
//Unused now BOOL isFromClientComponent=[request isFromClientComponent];
BOOL disabledInContext=[self disabledInContext:context];
GSWSaveAppendToResponseElementID(context);//Debug Only
if (disabledInContext)
{
//TODO
};
[response _appendContentAsciiString:@"