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 "gemrawo.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;
-
- GEMrawobject::GEMrawobject(const GEMrawobject& copy)
- {
- memcpy(this,©,sizeof(GEMrawobject));
-
- int copylevel=ExtType()&3;
-
- if (Editable()) copylevel^=2;
-
- unsigned long& spec=Indirect() ? *((unsigned long*)ob_spec) : ob_spec;
-
- if (copylevel) {
- switch (Type()) {
- case G_TEXT: case G_BOXTEXT: case G_FTEXT: case G_FBOXTEXT: {
- TEDINFO* cp=(TEDINFO*)spec;
- TEDINFO* te=new TEDINFO;
- *te=*cp;
-
- if (copylevel&2) {
- te->te_ptext=strdup(cp->te_ptext);
- }
-
- if (copylevel&1) {
- te->te_ptmplt=strdup(cp->te_ptmplt);
- te->te_pvalid=strdup(cp->te_pvalid);
- }
-
- spec=(unsigned long)te;
- } break; case G_IMAGE: {
- BITBLK* cp=(BITBLK*)spec;
- BITBLK* bi=new BITBLK;
- *bi=*cp;
- bi->bi_pdata=new char[cp->bi_wb*cp->bi_hl];
- memcpy(bi->bi_pdata,cp->bi_pdata,cp->bi_wb*cp->bi_hl);
- spec=(unsigned long)bi;
- } break; case G_BUTTON: case G_STRING: case G_TITLE: {
- spec=(unsigned long)strdup((char*)spec);
- } break; case G_ICON: {
- ICONBLK* cp=(ICONBLK*)spec;
- ICONBLK* ib=new ICONBLK;
- *ib=*cp;
-
- if (copylevel&1) {
- int dlen=cp->ib_wicon*cp->ib_hicon/16;
- ib->ib_pdata=new short[dlen];
- ib->ib_pmask=new short[dlen];
- memcpy(ib->ib_pdata,cp->ib_pdata,dlen*sizeof(short));
- memcpy(ib->ib_pmask,cp->ib_pmask,dlen*sizeof(short));
- }
-
- if (copylevel&2) {
- ib->ib_ptext=strdup(cp->ib_ptext);
- }
-
- spec=(unsigned long)ib;
- } break; case G_USERDEF: // Hmm...
- ;
- }
- }
- }
-
- char* GEMrawobject::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 GEMrawobject::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 GEMrawobject::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 GEMrawobject::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* GEMrawobject::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 GEMrawobject::Font(int font)
- {
- switch (Type()) {
- case G_BOXTEXT:
- case G_TEXT:
- case G_FTEXT:
- case G_FBOXTEXT:
- ((TEDINFO*)ObjectSpecific())->te_font=font;
- }
- }
-
- int GEMrawobject::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;
- }
- }
-
- void GEMrawobject::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;
- }
- }
-
- int GEMrawobject::FillPattern() const
- {
- switch (Type()) {
- case G_BOXCHAR:
- case G_BOX:
- case G_IBOX:
- return ((bfobspec*)ObjectSpecific())->fillpattern;
- break; default:
- return 0;
- }
- }
-
- GEMobject* GEMrawobject::Cook()
- {
- return Indirect() ? (GEMobject*)ObjectSpecific() : 0;
- }
-