#define MYLIB_BOOPSI
#define MYLIB_GRAPHICS
#define ROM_VERSION 39

#ifndef INTUITION_IMAGECLASS_H
#include <intuition/imageclass.h>
#endif

#ifndef INTUITION_GADGETCLASS_H
#include <intuition/gadgetclass.h>
#endif

#ifndef INTUITION_SGHOOKS_H
#include <intuition/sghooks.h>
#endif

#include "MyLib.h"
#include "BOOPSILib.h"

#include "StaticSavedsAsmA0A1A2.h"

/****** String/--background-- ********************************************
*
*	This class implements the string gadget type for BOOPSILib.
*
*	Parent class: strgclass
*
*************************************************************************/

struct InstanceData
{
  struct BOOPSILibS_LayoutInfo LayoutInfo;
  char ControlChar;
};

/************************************************************************/

struct IClass *BOOPSILibC_String;

/************************************************************************/

METHOD(OM_NEW,struct opSet *)

{
  TheObject=DoSuperNew(TheClass, TheObject,
		       GA_TabCycle, TRUE,
		       GA_RelVerify, TRUE,
		       TAG_MORE, Message->ops_AttrList);
  if (TheObject!=NULL)
    {
      struct InstanceData *InstanceData;

      InstanceData=INSTANCEDATA;
      InstanceData->LayoutInfo.Weight=(WORD)GetTagData(BOOPSILibA_Weight,100,Message->ops_AttrList);
      InstanceData->ControlChar=(char)GetTagData(BOOPSILibA_ControlChar,'\0',Message->ops_AttrList);
    }
  return (ULONG)TheObject;
}

/************************************************************************/

METHOD(BOOPSILibM_Init,const struct BOOPSILibP_Init *)

{
  struct InstanceData *InstanceData;
  struct TextExtent TextExtent;

  DoMethod(Message->Root,BOOPSILibM_Root_AddGadget,(struct Gadget *)TheObject);
  InstanceData=INSTANCEDATA;
  if (InstanceData->ControlChar!='\0')
    {
      DoMethod(Message->Root,BOOPSILibM_Root_RequestKey,TheObject,InstanceData->ControlChar);
    }
  SetAttrs(TheObject,STRINGA_Font,Message->Font,TAG_DONE);
  FontExtent(Message->Font,&TextExtent);
  InstanceData->LayoutInfo.Width.Max=(((struct StringInfo *)((struct ExtGadget *)TheObject)->SpecialInfo)->MaxChars-1)*TextExtent.te_Width;
  InstanceData->LayoutInfo.Width.Min=TextExtent.te_Width;
  InstanceData->LayoutInfo.Height.Min=TextExtent.te_Height;
  InstanceData->LayoutInfo.Height.Max=TextExtent.te_Height;
  return (ULONG)&InstanceData->LayoutInfo;
}

/************************************************************************/

METHOD(BOOPSILibM_Layout,const struct BOOPSILibP_Layout *)

{
  const struct InstanceData *InstanceData;

  InstanceData=INSTANCEDATA;
  return SetAttrs(TheObject,
		  GA_Left, Message->Position.Left,
		  GA_Top, Message->Position.Top,
		  GA_Width, Message->Position.Width,
		  GA_Height, Message->Position.Height,
		  TAG_DONE);
}

/************************************************************************/

METHOD(OM_GET,struct opGet *)

{
  switch (Message->opg_AttrID)
    {
    case BOOPSILibA_LayoutInfo:
      *Message->opg_Storage=(ULONG)&INSTANCEDATA->LayoutInfo;
      return TRUE;
    }
  return SUPER_METHOD;
}

/************************************************************************/

METHOD(OM_SET,struct opSet *)

{
  struct TagItem *Tags;
  const struct TagItem *Tag;

  Tags=Message->ops_AttrList;
  while ((Tag=NextTagItem(&Tags))!=NULL)
    {
      switch (Tag->ti_Tag)
	{
	case BOOPSILibA_Frame:
	  SetAttrs(TheObject,GA_Image,Tag->ti_Data,TAG_DONE);
	  break;
	}
    }
  return SUPER_METHOD;
}

/************************************************************************/

METHOD(BOOPSILibM_ControlChar,const struct BOOPSILibP_ControlChar *)

{
  if (!(Message->Code&IECODE_UP_PREFIX))
    {
      ActivateGadget((struct Gadget *)TheObject,Message->GadgetInfo->gi_Window,NULL);
    }
  return 0;
}

/************************************************************************/

STATIC_SAVEDS_ASM_A0A1A2(ULONG,Dispatcher,struct IClass *,TheClass,Msg,Message,Object *,TheObject)

{
  switch(Message->MethodID)
    {
      METHOD_DISP(OM_NEW,struct opSet *);
      METHOD_DISP(OM_GET,struct opGet *);
      METHOD_DISP(OM_SET,struct opSet *);
      METHOD_DISP(BOOPSILibM_Init,struct BOOPSILibP_Init *);
      METHOD_DISP(BOOPSILibM_Layout,struct BOOPSILibP_Layout *);
      METHOD_DISP(BOOPSILibM_ControlChar,struct BOOPSILibP_ControlChar *);
    }
  return SUPER_METHOD;
}

/************************************************************************/

struct IClass *CreateBOOPSILibC_String(void)

{
  if ((BOOPSILibC_String=MakeClass(NULL,BOOPSI_strgclass,NULL,sizeof(struct InstanceData),0))!=NULL)
    {
      BOOPSILibC_String->cl_Dispatcher.h_Entry=Dispatcher;
    }
  return BOOPSILibC_String;
}
