home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////////
- //
- // This file is Copyright 1992,1993 by Warwick W. Allison.
- // This file is part of the gem++ library.
- // You are free to copy and modify these sources, provided you acknowledge
- // the origin by retaining this notice, and adhere to the conditions
- // described in the file COPYING.LIB.
- //
- /////////////////////////////////////////////////////////////////////////////
-
- #include "gemo.h"
- #include "gemf.h"
- #include <aesbind.h>
- #include <string.h>
-
- // Apparently, this DAMNED USEFUL struct is for __TCC_COMPAT__ only!
- typedef struct {
- unsigned short character : 8;
- signed short framesize : 8;
- unsigned short framecol : 4;
- unsigned short textcol : 4;
- unsigned short textmode : 1;
- unsigned short fillpattern : 3;
- unsigned short interiorcol : 4;
- } bfobspec;
-
- GEMobject::GEMobject(GEMform& F, int RSCindex) :
- form(F),
- myindex(RSCindex)
- {
- if (me().Indirect()) {
- // It's already attached to a GEMobject
- original_ob_spec=((GEMobject*)me().ObjectSpecific())->original_ob_spec;
- } else {
- original_ob_spec=me().ObjectSpecific();
- me().ObjectSpecific((unsigned long)this);
- me().Indirect(TRUE);
- }
- }
-
- GEMobject::~GEMobject()
- {
- if (me().ObjectSpecific()==(unsigned long) this) {
- // Must have been a newly attached GEMobject
- me().ObjectSpecific(original_ob_spec);
- me().Indirect(FALSE);
- }
- }
-
- void GEMobject::Redraw()
- {
- form.RedrawObject(myindex);
- }
-
- void GEMobject::RedrawParent()
- {
- form.RedrawObject(form.Parent(myindex));
- }
-
- GEMfeedback GEMobject::Touch(int x, int y, const GEMevent&)
- {
- return IgnoredClick;
- }
-
- bool GEMobject::ContainsPoint(int x, int y) const
- {
- int X,Y;
-
- objc_offset(&form[0],myindex,&X,&Y);
- return (x>=X && y>=Y && x<X+me().Width() && y<Y+me().Height());
- }
-
- char* GEMobject::ImageBitmap(bool Mask=FALSE) const
- {
- switch (Type()) {
- case G_IMAGE:
- return ((BITBLK*)ObjectSpecific())->bi_pdata;
- break; case G_ICON:
- if (Mask)
- return (char*)((ICONBLK*)ObjectSpecific())->ib_pmask;
- else
- return (char*)((ICONBLK*)ObjectSpecific())->ib_pdata;
- break; default:
- return 0;
- }
- return 0;
- }
-
- short GEMobject::ImageWidth() const
- {
- switch (Type()) {
- case G_IMAGE:
- return ((BITBLK*)ObjectSpecific())->bi_wb*8;
- break; case G_ICON:
- return ((ICONBLK*)ObjectSpecific())->ib_wicon;
- break; default:
- return 0;
- }
- return 0;
- }
-
- short GEMobject::ImageHeight() const
- {
- switch (Type()) {
- case G_IMAGE:
- return ((BITBLK*)ObjectSpecific())->bi_hl;
- break; case G_ICON:
- return ((ICONBLK*)ObjectSpecific())->ib_hicon;
- break; default:
- return 0;
- }
- return 0;
- }
-
- void GEMobject::SetImageBitmap(char* d, short w, short h, bool Mask=FALSE)
- {
- switch (Type()) {
- case G_IMAGE:
- ((BITBLK*)ObjectSpecific())->bi_pdata=d;
- ((BITBLK*)ObjectSpecific())->bi_wb=w/8;
- ((BITBLK*)ObjectSpecific())->bi_hl=h;
- break; case G_ICON:
- if (Mask)
- ((ICONBLK*)ObjectSpecific())->ib_pmask=(short*)d;
- else
- ((ICONBLK*)ObjectSpecific())->ib_pdata=(short*)d;
- ((ICONBLK*)ObjectSpecific())->ib_wicon=w;
- ((ICONBLK*)ObjectSpecific())->ib_hicon=h;
- }
- }
-
- char* GEMobject::Text() const
- {
- switch (Type()) {
- case G_ICON:
- return ((ICONBLK*)ObjectSpecific())->ib_ptext;
- break;
- case G_BOXTEXT:
- case G_TEXT:
- case G_FTEXT:
- case G_FBOXTEXT:
- return ((TEDINFO*)ObjectSpecific())->te_ptext;
- break;
- case G_BOXCHAR: // First byte is char. This usage is dubious.
- case G_STRING:
- case G_BUTTON:
- return (char*)ObjectSpecific();
- break;
- default:
- return "";
- }
- }
-
- void GEMobject::SetText(char* t)
- {
- switch (Type()) {
- case G_ICON:
- ((ICONBLK*)ObjectSpecific())->ib_ptext=t;
- break;
- case G_BOXTEXT:
- case G_TEXT:
- case G_FTEXT:
- case G_FBOXTEXT:
- ((TEDINFO*)ObjectSpecific())->te_ptext=t;
- break;
- case G_STRING:
- case G_BUTTON:
- ObjectSpecific((int)t);
- break;
- case G_BOXCHAR:
- ((bfobspec*)ObjectSpecific())->character=*t;
- }
- }
-
- void GEMobject::Detach()
- {
- objc_delete(&form[0],myindex);
- }
-
- void GEMobject::Attach(GEMobject& o)
- {
- objc_add(&form[0],myindex,o.myindex);
- }
-
- void GEMobject::Attach(int RSCindex)
- {
- objc_add(&form[0],myindex,RSCindex);
- }
-
- void GEMobject::GetAbsoluteXY(int& x, int& y) const
- {
- objc_offset(&form[0],myindex,&x,&y);
- }
-
- // RSCindex-based
- int GEMobject::NumberOfChildren() const
- {
- int c=FirstChild();
- for (int n=0; c>=0; n++) c=NextChild(c);
- return n;
- }
-
- int GEMobject::FirstChild() const
- {
- return (me().Head() == myindex) ? -1 : me().Head();
- }
-
- int GEMobject::NextChild(int after) const
- {
- int c=form[after].Next();
- return (c == myindex) ? -1 : c;
- }
-
- // GEMobject-based
- int GEMobject::NumberOfComponents() const
- {
- int c=FirstChild();
- for (int n=0; c>=0; c=NextChild(c)) if (form[c].Cook()) n++;
- return n;
- }
-
- GEMobject* GEMobject::FirstComponent() const
- {
- GEMobject* o=0;
- for (int c=FirstChild(); c>=0 && !(o=form[c].Cook()); c=NextChild(c))
- ;
- return o;
- }
-
- GEMobject* GEMobject::NextComponent(const GEMobject* oo) const
- {
- GEMobject* o=0;
- for (int c=FirstChild(); c>=0 && !(o=form[c].Cook()) && o!=oo; c=NextChild(c))
- ;
- if (c>=0) c=NextChild(c);
- for (; c>=0 && !(o=form[c].Cook()); c=NextChild(c))
- ;
- return o;
- }
-
-
- GEMrawobject* GEMobject::Child(int c) const
- {
- return &form[c];
- }
-
- int GEMobject::Type() const
- {
- return me().Type();
- }
-
- void GEMobject::Type(int t)
- {
- me().Type(t);
- }
-
- int GEMobject::ObjectSpecific() const
- {
- return original_ob_spec;
- }
-
- void GEMobject::ObjectSpecific(int s)
- {
- original_ob_spec=s;
- }
-
- void GEMobject::Font(int font)
- {
- switch (Type()) {
- case G_BOXTEXT:
- case G_TEXT:
- case G_FTEXT:
- case G_FBOXTEXT:
- ((TEDINFO*)ObjectSpecific())->te_font=font;
- }
- }
-
- int GEMobject::Font() const
- {
- switch (Type()) {
- case G_BOXTEXT:
- case G_TEXT:
- case G_FTEXT:
- case G_FBOXTEXT:
- return ((TEDINFO*)ObjectSpecific())->te_font;
- break; default:
- return IBM;
- }
- }
-
- int GEMobject::FillPattern() const
- {
- switch (Type()) {
- case G_BOXCHAR:
- case G_BOX:
- case G_IBOX:
- return ((bfobspec*)ObjectSpecific())->fillpattern;
- break; default:
- return 0;
- }
- }
-
-