/* 
Copyright (c) 1991-2000 UserLand Software, Inc. 

Permission is hereby granted, free of charge, to any person obtaining a 
copy of this software and associated documentation files (the 
"Software"), to deal in the Software without restriction, including 
without limitation the rights to use, copy, modify, merge, publish, 
distribute, sublicense, and/or sell copies of the Software, and to 
permit persons to whom the Software is furnished to do so, subject to the 
following conditions: 

The above copyright notice and this permission notice shall be 
included in all copies or substantial portions of the Software. 

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
*/ 


#include <Components.h>
#include "iowacore.h"
#ifndef iowaRuntime
	#include "iowaobject.h"
	#include "iowaicons.h"
#endif
#include <appletfont.h>
#include <appletresource.h>



typedef struct tycomponentrecord {
	
	ComponentInstance component;
	
	long objectTypeID;
	} tycomponentrecord, **hdlcomponentrecord;
	
	
static tycomponentrecord **componentarray = nil; /*dynamic array of components*/


static short countcomponents (void) {
	
	if (componentarray == nil)
		return (0);
		
	return ((short) (GetHandleSize ((Handle) componentarray) / longsizeof (tycomponentrecord)));
	} /*countcomponents*/
	
	
static boolean addcomponent (ComponentInstance component, long objectTypeID) {

	tycomponentrecord rec;
	short ct;
	
	rec.component = component;
	
	rec.objectTypeID = objectTypeID;
	
	if (componentarray == nil)
		return (newfilledhandle (&rec, longsizeof (tycomponentrecord), (Handle *) &componentarray));
	
	ct = countcomponents ();
	
	SetHandleSize ((Handle) componentarray, (ct + 1) * longsizeof (tycomponentrecord));

	if (MemError () != noErr)
		return (false);
	
	(*componentarray) [ct] = rec;
	
	return (true);
	} /*addcomponent*/
	
	
static ComponentInstance findcomponent (long objectTypeID) {
	
	short ct, i;
	tycomponentrecord rec;
	
	ct = countcomponents ();
	
	for (i = 0; i < ct; i++) {
		
		rec = (*componentarray) [i];
		
		if (rec.objectTypeID == objectTypeID) 			
			return (rec.component);
		} /*for*/
	
	return (0); /*not found*/
	} /*findcomponent*/
	

#if GENERATINGCFM

	enum {
		uppCallComponentProcInfo = kPascalStackBased
				| RESULT_SIZE(kFourByteCode)
				| STACK_ROUTINE_PARAMETER(1, kFourByteCode)
	};
	
	#pragma options align=mac68k
	
	static pascal ComponentResult getconfigGlue (ComponentInstance comp, tyconfigrecord *config) {
		
		#define	getconfigGlueParamSize	(sizeof (config))
		
		struct getconfigGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			tyconfigrecord *config;
			ComponentInstance comp;
		};
		
		struct getconfigGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = getconfigGlueParamSize;
		pb.componentWhat = IOAgetconfigcommand;
		pb.config = config;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*getconfigGlue*/
	
	
	static pascal ComponentResult drawobjectGlue (ComponentInstance comp, hdlobject h) {
		
		#define	drawobjectGlueParamSize	(sizeof (h))
		
		struct drawobjectGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct drawobjectGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = drawobjectGlueParamSize;
		pb.componentWhat = IOAdrawobjectcommand;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*drawobjecttGlue*/
	
	
	static pascal ComponentResult initobjectGlue (ComponentInstance comp, tyobject *obj) {
		
		#define	initobjectGlueParamSize	(sizeof (obj))
		
		struct initobjectGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			tyobject *obj;
			ComponentInstance comp;
		};
		
		struct initobjectGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = initobjectGlueParamSize;
		pb.componentWhat = IOAinitobjectcommand;
		pb.obj = obj;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*initobjectGlue*/
	
	
	static pascal ComponentResult debugGlue (ComponentInstance comp, hdlobject h, ptrstring errorstring) {
		
		#define	debugGlueParamSize	(sizeof (h) + sizeof (errorstring))
		
		struct debugGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			ptrstring errorstring;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct debugGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = debugGlueParamSize;
		pb.componentWhat = IOAdebugobjectcommand;
		pb.errorstring = errorstring;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*debugGlue*/
	
	
	static pascal ComponentResult clickGlue (ComponentInstance comp, hdlobject listhead, hdlobject h, Point pt, boolean flshiftkey, boolean fl2click) {
		
		#define	clickGlueParamSize	(sizeof (listhead) + sizeof (h) + sizeof (pt) + sizeof (flshiftkey) + sizeof (fl2click))
		
		struct clickGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			boolean fl2click;
			boolean flshiftkey;
			Point pt;
			hdlobject h;
			hdlobject listhead;
			ComponentInstance comp;
		};
		
		struct clickGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = clickGlueParamSize;
		pb.componentWhat = IOAclickcommand;
		pb.fl2click = fl2click;
		pb.flshiftkey = flshiftkey;
		pb.pt = pt;
		pb.h = h;
		pb.listhead = listhead;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*clickGlue*/
	
	
	static pascal ComponentResult cleanGlue (ComponentInstance comp, hdlobject h, short height, short width, Rect *r) {
		
		#define	cleanGlueParamSize	(sizeof (h) + sizeof (height) + sizeof (width) + sizeof (r))
		
		struct cleanGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			Rect *r;
			short width;
			short height;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct cleanGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = cleanGlueParamSize;
		pb.componentWhat = IOAcleanupcommand;
		pb.r = r;
		pb.width = width;
		pb.height = height;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*cleanGlue*/
	
	
	static pascal ComponentResult recalcGlue (ComponentInstance comp, hdlobject h, boolean flmajorrecalc) {
		
		#define	recalcGlueParamSize	(sizeof (h) + sizeof (flmajorrecalc))
		
		struct recalcGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			boolean flmajorrecalc;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct recalcGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = recalcGlueParamSize;
		pb.componentWhat = IOArecalccommand;
		pb.flmajorrecalc = flmajorrecalc;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*recalcGlue*/
	
	
	static pascal ComponentResult editGlue (ComponentInstance comp, hdlobject h, boolean flgoin) {
		
		#define	editGlueParamSize	(sizeof (h) + sizeof (flgoin))
		
		struct editGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			boolean flgoin;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct editGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = editGlueParamSize;
		pb.componentWhat = IOAeditobjectcommand;
		pb.flgoin = flgoin;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*editGlue*/
	
	
	static pascal ComponentResult keyGlue (ComponentInstance comp, hdlobject h, short ch) {
		
		#define	keyGlueParamSize	(sizeof (h) + sizeof (ch))
		
		struct keyGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			short ch;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct keyGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = keyGlueParamSize;
		pb.componentWhat = IOAkeystrokecommand;
		pb.ch = ch;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*keyGlue*/
	
	
	static pascal ComponentResult idleGlue (ComponentInstance comp, hdlobject h) {
		
		#define	idleGlueParamSize	(sizeof (h))
		
		struct idleGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct idleGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = idleGlueParamSize;
		pb.componentWhat = IOAidlecommand;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*idleGlue*/
	
	
	static pascal ComponentResult getvalueGlue (ComponentInstance comp, hdlobject h, Handle *r) {
		
		#define	getvalueGlueParamSize	(sizeof (h) + sizeof (r))
		
		struct getvalueGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			Handle *r;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct getvalueGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = getvalueGlueParamSize;
		pb.componentWhat = IOAgetvaluecommand;
		pb.r = r;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*getvalueGlue*/
	
	
	static pascal ComponentResult setvalueGlue (ComponentInstance comp, hdlobject h, Handle hvalue) {
		
		#define	setvalueGlueParamSize	(sizeof (h) + sizeof (hvalue))
		
		struct setvalueGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			Handle hvalue;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct setvalueGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = setvalueGlueParamSize;
		pb.componentWhat = IOAsetvaluecommand;
		pb.hvalue = hvalue;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*setvalueGlue*/
	
	
	static pascal ComponentResult setcursorGlue (ComponentInstance comp, hdlobject h, Point pt) {
		
		#define	setcursorGlueParamSize	(sizeof (h) + sizeof (pt))
		
		struct setcursorGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			Point pt;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct setcursorGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = setcursorGlueParamSize;
		pb.componentWhat = IOAsetcursorcommand;
		pb.pt = pt;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*setcursorGlue*/
	
	
	static pascal ComponentResult unpackdataGlue (ComponentInstance comp, hdlobject h) {
		
		#define	unpackdataGlueParamSize	(sizeof (h))
		
		struct unpackdataGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct unpackdataGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = unpackdataGlueParamSize;
		pb.componentWhat = IOAunpackdatacommand;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*unpackdataGlue*/
	
	
	static pascal ComponentResult getattributesGlue (ComponentInstance comp, hdlobject h, AppleEvent *event) {
		
		#define	getattributesGlueParamSize	(sizeof (h) + sizeof (event))
		
		struct getattributesGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			AppleEvent *event;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct getattributesGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = getattributesGlueParamSize;
		pb.componentWhat = IOAgetattributescommand;
		pb.event = event;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*getattributesGlue*/
	
	
	static pascal ComponentResult setattributesGlue (ComponentInstance comp, hdlobject h, AppleEvent *event) {
		
		#define	setattributesGlueParamSize	(sizeof (h) + sizeof (event))
		
		struct setattributesGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			AppleEvent *event;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct setattributesGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = setattributesGlueParamSize;
		pb.componentWhat = IOAsetattributescommand;
		pb.event = event;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*setattributesGlue*/
	
	
	static pascal ComponentResult geticonGlue (ComponentInstance comp, Handle *h) {
		
		#define	geticonGlueParamSize	(sizeof (h))
		
		struct geticonGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			Handle *h;
			ComponentInstance comp;
		};
		
		struct geticonGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = geticonGlueParamSize;
		pb.componentWhat = IOAgeticoncommand;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*geticonGlue*/
	
	
	static pascal ComponentResult getcardGlue (ComponentInstance comp, Handle *hcard) {
		
		#define	getcardGlueParamSize	(sizeof (hcard))
		
		struct getcardGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			Handle *hcard;
			ComponentInstance comp;
		};
		
		struct getcardGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = getcardGlueParamSize;
		pb.componentWhat = IOAgetcardcommand;
		pb.hcard = hcard;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*getcardGlue*/
	
	
	static pascal ComponentResult packdataGlue (ComponentInstance comp, hdlobject h, Handle *hpackeddata) {
		
		#define	packdataGlueParamSize	(sizeof (h) + sizeof (hpackeddata))
		
		struct packdataGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			Handle *hpackeddata;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct packdataGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = packdataGlueParamSize;
		pb.componentWhat = IOApackdatacommand;
		pb.hpackeddata = hpackeddata;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*packdataGlue*/
	
	
	static pascal ComponentResult disposedataGlue (ComponentInstance comp, hdlobject h) {
		
		#define	disposedataGlueParamSize	(sizeof (h))
		
		struct disposedataGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct disposedataGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = disposedataGlueParamSize;
		pb.componentWhat = IOAdisposedatacommand;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*disposedataGlue*/
	
	
	static pascal ComponentResult canreplicateGlue (ComponentInstance comp, hdlobject h) {
		
		#define	canreplicateGlueParamSize	(sizeof (h))
		
		struct canreplicateGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct canreplicateGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = canreplicateGlueParamSize;
		pb.componentWhat = IOAcanreplicatcommand;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*canreplicateGlue*/
	
	
	static pascal ComponentResult catchreturnGlue (ComponentInstance comp, hdlobject h) {
		
		#define	catchreturnGlueParamSize	(sizeof (h))
		
		struct catchreturnGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct catchreturnGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = catchreturnGlueParamSize;
		pb.componentWhat = IOAcatchreturncommand;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*catchreturnGlue*/
	
	
	static pascal ComponentResult getinvalrectGlue (ComponentInstance comp, hdlobject h, Rect *r) {
		
		#define	getinvalrectGlueParamSize	(sizeof (h) + sizeof (r))
		
		struct getinvalrectGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			Rect *r;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct getinvalrectGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = getinvalrectGlueParamSize;
		pb.componentWhat = IOAgetobjectinvalrectcommand;
		pb.r = r;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*getinvalrectGlue*/
	
	
	static pascal ComponentResult geteditrectGlue (ComponentInstance comp, hdlobject h, Rect *r) {
		
		#define	geteditrectGlueParamSize	(sizeof (h) + sizeof (r))
		
		struct geteditrectGlueGluePB {
			unsigned char componentFlags;
			unsigned char componentParamSize;
			short componentWhat;
			Rect *r;
			hdlobject h;
			ComponentInstance comp;
		};
		
		struct geteditrectGlueGluePB pb;
		
		pb.componentFlags = 0;
		pb.componentParamSize = geteditrectGlueParamSize;
		pb.componentWhat = IOAgetobjecteditrectcommand;
		pb.r = r;
		pb.h = h;
		pb.comp = comp;
		
		return CallUniversalProc(CallComponentUPP, uppCallComponentProcInfo, &pb);
		} /*geteditrectGlue*/

	#pragma options align=reset

#else	// not CFM

	static pascal ComponentResult getconfigGlue (ComponentInstance comp, tyconfigrecord *config)
		
		ComponentCallNow (IOAgetconfigcommand, longsizeof (tyconfigrecord *)); 
		/*getconfigGlue*/
	
	
	static pascal ComponentResult drawobjectGlue (ComponentInstance comp, hdlobject h) 
		
		ComponentCallNow (IOAdrawobjectcommand, longsizeof (hdlobject)); 
		/*drawobjecttGlue*/
	
	
	static pascal ComponentResult initobjectGlue (ComponentInstance comp, tyobject *obj) 
		
		ComponentCallNow (IOAinitobjectcommand, longsizeof (tyobject *)); 
		/*initobjectGlue*/
	
	
	static pascal ComponentResult debugGlue (ComponentInstance comp, hdlobject h, bigstring errorstring) 
		
		ComponentCallNow (IOAdebugobjectcommand, longsizeof (hdlobject) + longsizeof (char *)); 
		/*debugGlue*/
	
	
	static pascal ComponentResult clickGlue (ComponentInstance comp, hdlobject listhead, hdlobject h, Point pt, boolean flshiftkey, boolean fl2click) 
		
		ComponentCallNow (IOAclickcommand, (2 * longsizeof (hdlobject)) + longsizeof (Point) + longsizeof (boolean) + longsizeof (boolean)); 
		/*clickGlue*/
	
	
	static pascal ComponentResult cleanGlue (ComponentInstance comp, hdlobject h, short height, short width, Rect *r) 
		
		ComponentCallNow (IOAcleanupcommand, longsizeof (hdlobject) + longsizeof (short) + longsizeof (short) + longsizeof (Rect *)); 
		/*cleanGlue*/
	
	
	static pascal ComponentResult recalcGlue (ComponentInstance comp, hdlobject h, boolean flmajorrecalc) 
		
		ComponentCallNow (IOArecalccommand, longsizeof (hdlobject) + longsizeof (boolean)); 
		/*recalcGlue*/
	
	
	static pascal ComponentResult editGlue (ComponentInstance comp, hdlobject h, boolean flgoin) 
		
		ComponentCallNow (IOAeditobjectcommand, longsizeof (hdlobject) + longsizeof (boolean)); 
		/*editGlue*/
	
	
	static pascal ComponentResult keyGlue (ComponentInstance comp, hdlobject h, short ch) 
		
		/*
		1/20/93 DW: last param used to be a char, but this was causing the size computed
		below to be an odd number. by changing it to a short, we keep things clean and
		working.
		*/
		
		ComponentCallNow (IOAkeystrokecommand, longsizeof (hdlobject) + longsizeof (short)); 
		/*keyGlue*/
	
	
	static pascal ComponentResult idleGlue (ComponentInstance comp, hdlobject h) 
		
		ComponentCallNow (IOAidlecommand, longsizeof (hdlobject)); 
		/*idleGlue*/
	
	
	static pascal ComponentResult getvalueGlue (ComponentInstance comp, hdlobject h, Handle *r) 
		
		ComponentCallNow (IOAgetvaluecommand, longsizeof (hdlobject) + longsizeof (Handle *)); 
		/*getvalueGlue*/
	
	
	static pascal ComponentResult setvalueGlue (ComponentInstance comp, hdlobject h, Handle hvalue) 
		
		ComponentCallNow (IOAsetvaluecommand, longsizeof (hdlobject) + longsizeof (Handle)); 
		/*setvalueGlue*/
	
	
	static pascal ComponentResult setcursorGlue (ComponentInstance comp, hdlobject h, Point pt) 
		
		ComponentCallNow (IOAsetcursorcommand, longsizeof (hdlobject) + longsizeof (Point)); 
		/*setcursorGlue*/
	
	
	static pascal ComponentResult unpackdataGlue (ComponentInstance comp, hdlobject h) 
		
		ComponentCallNow (IOAunpackdatacommand, longsizeof (hdlobject)); 
		/*unpackdataGlue*/
	
	
	static pascal ComponentResult getattributesGlue (ComponentInstance comp, hdlobject h, AppleEvent *event) 
		
		ComponentCallNow (IOAgetattributescommand, longsizeof (hdlobject) + longsizeof (AppleEvent *)); 
		/*getattributesGlue*/
	
	
	static pascal ComponentResult setattributesGlue (ComponentInstance comp, hdlobject h, AppleEvent *event) 
		
		ComponentCallNow (IOAsetattributescommand, longsizeof (hdlobject) + longsizeof (AppleEvent *)); 
		/*setattributesGlue*/
	
	
	static pascal ComponentResult geticonGlue (ComponentInstance comp, Handle *h) 
		
		ComponentCallNow (IOAgeticoncommand, longsizeof (Handle *)); 
		/*geticonGlue*/
	
	
	static pascal ComponentResult getcardGlue (ComponentInstance comp, Handle *hcard) 
		
		ComponentCallNow (IOAgetcardcommand, longsizeof (Handle *)); 
		/*getcardGlue*/
	
	
	static pascal ComponentResult packdataGlue (ComponentInstance comp, hdlobject h, Handle *hpackeddata) 
		
		ComponentCallNow (IOApackdatacommand, longsizeof (hdlobject) + longsizeof (Handle *)); 
		/*packdataGlue*/
	
	
	static pascal ComponentResult disposedataGlue (ComponentInstance comp, hdlobject h) 
		
		ComponentCallNow (IOAdisposedatacommand, longsizeof (hdlobject)); 
		/*disposedataGlue*/
	
	
	static pascal ComponentResult canreplicateGlue (ComponentInstance comp, hdlobject h) 
		
		ComponentCallNow (IOAcanreplicatcommand, longsizeof (hdlobject)); 
		/*canreplicateGlue*/
	
	
	static pascal ComponentResult catchreturnGlue (ComponentInstance comp, hdlobject h) 
		
		ComponentCallNow (IOAcatchreturncommand, longsizeof (hdlobject)); 
		/*catchreturnGlue*/
	
	
	static pascal ComponentResult getinvalrectGlue (ComponentInstance comp, hdlobject h, Rect *r) 
		
		ComponentCallNow (IOAgetobjectinvalrectcommand, longsizeof (hdlobject) + longsizeof (Rect *)); 
		/*getinvalrectGlue*/
	
	
	static pascal ComponentResult geteditrectGlue (ComponentInstance comp, hdlobject h, Rect *r) 
		
		ComponentCallNow (IOAgetobjecteditrectcommand, longsizeof (hdlobject) + longsizeof (Rect *)); 
		/*geteditrectGlue*/

#endif

boolean callinitobject (tyobject *obj) {
	
	(*obj).owningcard = iowadata; /*make card record available to the object handler*/
	
	(**iowadata).fontinfo = globalfontinfo;
	
	return (initobjectGlue (findcomponent ((*obj).objecttype), obj));
	} /*callinitobject*/
	
	
static boolean pregluecall (hdlobject h, ComponentInstance *comp) {
	
	/*
	set up the object record so the callback can find information
	that many of them need. 
	
	1/23/93 DW: beef it up to get the component id from the array and
	return false if it's 0.
	
	2/16/93 dmb: check iowadata for nil -- defensive driving
	*/
	
	(**h).owningcard = iowadata; /*make card record available to the object handler*/
	
	if (iowadata == nil)
		return (false);
	
	(**iowadata).fontinfo = globalfontinfo;
	
	*comp = findcomponent ((**h).objecttype);
	
	return (*comp != 0);
	} /*pregluecall*/
	
	
boolean calldrawobject (hdlobject h) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp)) {
		
		Rect r = (**h).objectrect;
		
		FillRect (&r, (ConstPatternParam) &quickdrawglobal (gray));
		
		FrameRect (&r);
		
		return (false);
		}
	
	return (drawobjectGlue (comp, h));
	} /*calldrawobject*/
	
	
boolean callclick (hdlobject listhead, hdlobject h, Point pt, boolean flshiftkey, boolean fl2click) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (clickGlue (comp, listhead, h, pt, flshiftkey, fl2click));
	} /*callclick*/
	
	
boolean callcleanobject (hdlobject h, short height, short width, Rect *r) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (cleanGlue (comp, h, height, width, r));
	} /*callcleanobject*/
	
	
boolean callrecalcobject (hdlobject h, boolean flmajorrecalc) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (recalcGlue (comp, h, flmajorrecalc));
	} /*callrecalcobject*/
	
	
boolean calleditobject (hdlobject h, boolean flgoin) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (editGlue (comp, h, flgoin));
	} /*calleditobject*/


boolean callkeyobject (hdlobject h, char ch) {
	
	ComponentInstance comp;
	
	if (h == nil)
		return (true);
		
	if (!pregluecall (h, &comp))
		return (true);
	
	return (keyGlue (comp, h, (short) ch));
	} /*callkeyobject*/
	
	
boolean callidleobject (hdlobject h) {
	
	ComponentInstance comp;
	
	if (h == nil)
		return (true);
		
	if (!pregluecall (h, &comp))
		return (true);
	
	return (idleGlue (comp, h));
	} /*callidleobject*/
	
	
boolean callcanreplicate (hdlobject h) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (canreplicateGlue (comp, h));
	} /*callcanreplicate*/
	
	
boolean callcatchreturn (hdlobject h) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (catchreturnGlue (comp, h));
	} /*callcatchreturn*/
	
	
boolean callgetinvalrect (hdlobject h, Rect *r) {
	
	ComponentInstance comp;
	
	getobjectrect (h, r); /*allow for groups*/
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (getinvalrectGlue (comp, h, r));
	} /*callinvalobject*/
	
	
boolean callgeteditrect (hdlobject h, Rect *r) {
	
	ComponentInstance comp;
	
	*r = (**h).objectrect; /*geteditrect has special case for groups*/
	
	if (!pregluecall (h, &comp))
		return (false);
	
	getobjectrect (h, r); 
		
	return (geteditrectGlue (comp, h, r));
	} /*callgeteditrect*/
	
	
boolean callgetvalue (hdlobject h, Handle *hvalue) {
	
	ComponentInstance comp;
	
	*hvalue = nil;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (getvalueGlue (comp, h, hvalue));
	} /*callgetvalue*/
	
	
boolean callsetvalue (hdlobject h, Handle hvalue) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (setvalueGlue (comp, h, hvalue));
	} /*callsetvalue*/
	
	
boolean callsetcursor (hdlobject h, Point pt) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (setcursorGlue (comp, h, pt));
	} /*callsetcursor*/
	
	
boolean calldisposedata (hdlobject h) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (disposedataGlue (comp, h));
	} /*calldisposedata*/
	

boolean callgetattributes (hdlobject h, AppleEvent *event) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (getattributesGlue (comp, h, event));
	} /*callgetattributes*/
	
	
boolean callsetattributes (hdlobject h, AppleEvent *event) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (setattributesGlue (comp, h, event));
	} /*callsetattributes*/
	
	
boolean callgetcard (hdlobject h, Handle *hcard) {
	
	ComponentInstance comp;
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (getcardGlue (comp, hcard));
	} /*callgetcard*/
	

boolean callpackdata (hdlobject h, Handle *hpackeddata) {
	
	switch ((**h).objecttype) {
	
		case grouptype: case clonetype:
			return (true);
			
		default: {
			ComponentInstance comp;
	
			if (!pregluecall (h, &comp))
				return (false);
	
			return (packdataGlue (comp, h, hpackeddata));
			}
		} /*switch*/
	} /*callpackdata*/
	
	
boolean callunpackdata (hdlobject h) {
	
	switch ((**h).objecttype) {
	
		case grouptype: case clonetype:
			return (true);
			
		default: {
			ComponentInstance comp;
	
			if (!pregluecall (h, &comp))
				return (false);
			
			return (unpackdataGlue (comp, h));
			}
		} /*switch*/
	} /*callunpackdata*/
	
	
boolean calldebug (hdlobject h, Str255 errorstring) {
	
	ComponentInstance comp;
	
	setstringlength (errorstring, 0);
	
	if (!pregluecall (h, &comp))
		return (false);
	
	return (debugGlue (comp, h, errorstring));
	} /*calldebug*/
	
	
static boolean getconfigrecord (hdlobject h, tyconfigrecord *config) {
	
	ComponentInstance comp;
	
	clearbytes (config, longsizeof (tyconfigrecord));
	
	comp = findcomponent ((**h).objecttype);
	
	if (comp == 0)
		return (false);
		
	return (getconfigGlue (comp, config));
	} /*getconfigrecord*/
	
	
boolean callgetobjectname (hdlobject h, Str255 objectname) {

	switch ((**h).objecttype) {
	
		case grouptype:
			copystring ("\pGroup", objectname);
			
			break;
			
		case clonetype:
			copystring ("\pClone", objectname);
			
			break;
			
		default: {
			tyconfigrecord config;
			
			getconfigrecord (h, &config);
			
			copystring (config.objectTypeName, objectname);
			
			break;
			}
		} /*switch*/
	
	return (true);
	} /*callgetobjectname*/


boolean callgetobjectflagname (hdlobject h, Str255 objectflagname) {

	tyconfigrecord config;
	
	getconfigrecord (h, &config);
	
	copystring (config.objectFlagName, objectflagname);
	
	return (true);
	} /*callgetobjectflagname*/


boolean callframewhenediting (hdlobject h) {

	tyconfigrecord config;
	
	getconfigrecord (h, &config);
	
	return (config.frameWhenEditing);
	} /*callframewhenediting*/


boolean callcaneditvalue (hdlobject h) {

	tyconfigrecord config;
	
	getconfigrecord (h, &config);
	
	return (config.canEditValue);
	} /*callcaneditvalue*/


boolean calltoggleflagwhenhit (hdlobject h) {

	tyconfigrecord config;
	
	getconfigrecord (h, &config);
	
	return (config.toggleFlagWhenHit);
	} /*calltoggleflagwhenhit*/


boolean callmutallyexclusive (hdlobject h) {

	tyconfigrecord config;
	
	getconfigrecord (h, &config);
	
	return (config.mutuallyExclusive);
	} /*callmutallyexclusive*/


boolean callspeaksforgroup (hdlobject h) {

	tyconfigrecord config;
	
	getconfigrecord (h, &config);
	
	return (config.speaksForGroup);
	} /*callspeaksforgroup*/


boolean callhandlesmousetrack (hdlobject h) {

	tyconfigrecord config;
	
	getconfigrecord (h, &config);
	
	return (config.handlesMouseTrack);
	} /*callhandlesmousetrack*/


boolean calleditableinrunmode (hdlobject h) {

	tyconfigrecord config;
	
	getconfigrecord (h, &config); 
	
	return (config.editableInRunMode);
	} /*calleditableinrunmode*/


boolean callfontaware (hdlobject h) {
	
	switch ((**h).objecttype) {
		
		case clonetype:
			return (true); /*allow centering using the Justify menu*/
	
		default: {
			tyconfigrecord config;
	
			getconfigrecord (h, &config);
	
			return (config.isFontAware);
			}
		} /*switch*/
	} /*callfontaware*/


boolean callalwaysidle (hdlobject h) {

	tyconfigrecord config;
	
	getconfigrecord (h, &config);
	
	return (config.alwaysIdle);
	} /*callalwaysidle*/
	

boolean callhasspecialcard (hdlobject h) {

	tyconfigrecord config;
	
	getconfigrecord (h, &config);
	
	return (config.hasSpecialCard);
	} /*callhasspecialcard*/
	

boolean callcantdrawinbitmap (hdlobject h) {

	tyconfigrecord config;
	
	getconfigrecord (h, &config);
	
	return (config.cantDrawInBitmap);
	} /*callcantdrawinbitmap*/
	

boolean initIOAcomponents (Handle *harray) {
	
	/*
	2/27/93 DW: return a handle to the component array so that Iowa Runtime
	can save this between calls to run a card.
	*/
	
	ComponentDescription desc;
	Component comp, prevcomponent;
	ComponentInstance instance;
	tyconfigrecord config;
	long ct, i;
	
	clearbytes (&desc, longsizeof (desc));
	
	desc.componentType = 'IOAb';
	
	ct = CountComponents (&desc);
	
	prevcomponent = nil; /*start with the first one*/
	
	for (i = 0; i < ct; i++) {
		
		comp = FindNextComponent (prevcomponent, &desc);
		
		instance = OpenComponent (comp);
		
		getconfigGlue (instance, &config);
		
		addcomponent (instance, config.objectTypeID);
		
		#ifndef iowaRuntime
			{
			Handle hsmallicon;
			
			geticonGlue (instance, &hsmallicon);
			
			addtoiconarray (hsmallicon, config.objectTypeID);
			}
		#endif
		
		prevcomponent = comp;
		} /*for*/
	
	#ifndef iowaRuntime
	
		converticonarray ();
	
	#endif
	
	*harray = (Handle) componentarray;
	
	return (true);
	} /*initIOAcomponents*/
	

void restorecomponentarray (Handle harray) {
	
	componentarray = (hdlcomponentrecord) harray;
	} /*restorecomponentarray*/
	

boolean closeIOAcomponents (void) {
	
	short ct, i;
	
	ct = countcomponents ();
	
	for (i = 0; i < ct; i++) 
		CloseComponent ((*componentarray) [i].component);
		
	disposehandle ((Handle) componentarray);
	
	componentarray = nil;
	
	return (true);
	} /*closeIOAcomponents*/