GSWeb: Class GSWPopUpButton
Copyright (C) 1999-2002 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.
**/
static char rcsId[] = "$Id$";
#include
//====================================================================
@implementation GSWPopUpButton
//--------------------------------------------------------------------
-(id)initWithName:(NSString*)aName
associations:(NSDictionary*)associations
contentElements:(NSArray*)elements
{
//OK
NSMutableDictionary* tmpAssociations=nil;
LOGObjectFnStartC("GSWPopUpButton");
NSDebugMLLog(@"gswdync",@"aName=%@ associations:%@ _elements=%@",
aName,associations,elements);
tmpAssociations=[NSMutableDictionary dictionaryWithDictionary:associations];
[tmpAssociations removeObjectForKey:list__Key];
[tmpAssociations removeObjectForKey:item__Key];
if (!WOStrictFlag)
{
[tmpAssociations removeObjectForKey:count__Key];
[tmpAssociations removeObjectForKey:index__Key];
};
[tmpAssociations removeObjectForKey:displayString__Key];
[tmpAssociations removeObjectForKey:selection__Key];
if (!WOStrictFlag)
[tmpAssociations removeObjectForKey:selectionValue__Key];
[tmpAssociations removeObjectForKey:selectedValue__Key];
[tmpAssociations removeObjectForKey:noSelectionString__Key];
[tmpAssociations removeObjectForKey:escapeHTML__Key];
if ((self=[super initWithName:aName
associations:tmpAssociations
contentElements:nil]))
{
_list=[[associations objectForKey:list__Key
withDefaultObject:[_list autorelease]] retain];
_item=[[associations objectForKey:item__Key
withDefaultObject:[_item autorelease]] retain];
_displayString=[[associations objectForKey:displayString__Key
withDefaultObject:[_displayString autorelease]] retain];
_selection=[[associations objectForKey:selection__Key
withDefaultObject:[_selection autorelease]] retain];
if (_selection && ![_selection isValueSettable])
{
ExceptionRaise0(@"GSWPopUpButton",@"'selection' parameter must be settable");
};
if (!WOStrictFlag)
{
_selectionValue=[[associations objectForKey:selectionValue__Key
withDefaultObject:[_selectionValue autorelease]] retain];
if (_selectionValue && ![_selectionValue isValueSettable])
{
ExceptionRaise0(@"GSWPopUpButton",@"'selectionValue' parameter must be settable");
};
};
_selectedValue=[[associations objectForKey:selectedValue__Key
withDefaultObject:[_selectedValue autorelease]] retain];
_noSelectionString=[[associations objectForKey:noSelectionString__Key
withDefaultObject:[_noSelectionString autorelease]] retain];
_escapeHTML=[[associations objectForKey:escapeHTML__Key
withDefaultObject:[_escapeHTML autorelease]] retain];
if (!WOStrictFlag)
{
_count=[[associations objectForKey:count__Key
withDefaultObject:[_count autorelease]] retain];
NSDebugMLLog(@"gswdync",@"count=%@",_count);
_index=[[associations objectForKey:index__Key
withDefaultObject:[_index autorelease]] retain];
NSDebugMLLog(@"gswdync",@"index=%@",_index);
if (_index && ![_index isValueSettable])
{
ExceptionRaise0(@"GSWPopUpButton",@"'index' parameter must be settable");
};
};
};
LOGObjectFnStopC("GSWPopUpButton");
return self;
};
//--------------------------------------------------------------------
-(void)dealloc
{
DESTROY(_list);
DESTROY(_item);
DESTROY(_displayString);
DESTROY(_selection);
DESTROY(_selectionValue);//GSWeb Only
DESTROY(_selectedValue);
DESTROY(_noSelectionString);
DESTROY(_escapeHTML);
DESTROY(_count);//GSWeb Only
DESTROY(_index);//GSWeb Only
[super dealloc];
};
//--------------------------------------------------------------------
-(NSString*)elementName
{
return @"SELECT";
};
//--------------------------------------------------------------------
-(NSString*)description
{
return [NSString stringWithFormat:@"<%s %p>",
object_get_class_name(self),
(void*)self];
};
//====================================================================
@implementation GSWPopUpButton (GSWPopUpButtonA)
//#define ENABLE_OPTGROUP
//--------------------------------------------------------------------
-(void)appendToResponse:(GSWResponse*)response
inContext:(GSWContext*)context
{
//OK
GSWRequest* request=nil;
BOOL isFromClientComponent=NO;
GSWComponent* component=nil;
NSArray* listValue=nil;
id selectionValue=nil;
id selectedValueValue=nil;
id valueValue=nil;
id itemValue=nil;
id displayStringValue=nil;
BOOL escapeHTMLBoolValue=YES;
id escapeHTMLValue=nil;
int i=0;
BOOL inOptGroup=NO;
#ifndef ENABLE_OPTGROUP
BOOL optGroupLabel=NO;
#endif
int countValue=0;
LOGObjectFnStartC("GSWPopUpButton");
GSWStartElement(context);
GSWSaveAppendToResponseElementID(context);
[self resetAutoValue];
_autoValue = NO;
request=[context request];
isFromClientComponent=[request isFromClientComponent];
component=[context component];
[super appendToResponse:response
inContext:context];
NSDebugMLLog(@"gswdync",@"_list=%@",_list);
if (_list)
{
listValue=[_list valueInComponent:component];
NSDebugMLLog(@"gswdync",@"listValue=%@",listValue);
NSAssert3(!listValue || [listValue respondsToSelector:@selector(count)],
@"The list (%@) (%@ of class:%@) doesn't respond to 'count'",
_list,
listValue,
[listValue class]);
countValue=[listValue count];
};
NSDebugMLLog(@"gswdync",@"_count=%@",_count);
if (_count)
{
id tmpCountValue=[_count valueInComponent:component];
int tmpCount=0;
NSAssert3(!tmpCountValue || [tmpCountValue respondsToSelector:@selector(intValue)],
@"The 'count' (%@) value %@ (of class:%@) doesn't respond to 'intValue'",
_count,
tmpCountValue,
[tmpCountValue class]);
tmpCount=[tmpCountValue intValue];
NSDebugMLog(@"tmpCount=%d",tmpCount);
if (_list)
countValue=min(tmpCount,countValue);
else
countValue=tmpCount;
}
selectionValue=[_selection valueInComponent:component];
NSDebugMLLog(@"gswdync",@"selection=%@",_selection);
NSDebugMLLog(@"gswdync",@"selectionValue=%@",selectionValue);
selectedValueValue=[_selectedValue valueInComponent:component];
NSDebugMLLog(@"gswdync",@"selectedValue=%@",_selectedValue);
NSDebugMLLog(@"gswdync",@"selectedValueValue=%@",selectedValueValue);
if (_escapeHTML)
{
escapeHTMLValue=[_escapeHTML valueInComponent:component];
escapeHTMLBoolValue=boolValueFor(escapeHTMLValue);
};
if (_noSelectionString)
{
id noSelectionStringValue=nil;
[response _appendContentAsciiString:@"\n"];
};
NSDebugMLLog(@"gswdync",@"countValue=%d",countValue);
for(i=0;i'];
};
displayStringValue=nil;
if (_displayString)
{
NSDebugMLLog(@"gswdync",@"displayString=%@",_displayString);
displayStringValue=[_displayString valueInComponent:component];
NSDebugMLLog(@"gswdync",@"displayStringValue=%@",displayStringValue);
}
else
{
displayStringValue = itemValue;
}
if (displayStringValue)
{
if (!valueValue)
{
if (inOptGroup)
{
NSDebugMLLog0(@"gswdync",@"Adding /OPTGROUP");
#ifdef ENABLE_OPTGROUP
[response _appendContentAsciiString:@"\n"];
#endif
inOptGroup=NO;
};
NSDebugMLLog0(@"gswdync",@"Adding OPTGROUP");
#ifdef ENABLE_OPTGROUP
[response _appendContentAsciiString:@"\n