home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / gempp15b / gemo.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-23  |  5.9 KB  |  303 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is Copyright 1992,1993 by Warwick W. Allison.
  4. //  This file is part of the gem++ library.
  5. //  You are free to copy and modify these sources, provided you acknowledge
  6. //  the origin by retaining this notice, and adhere to the conditions
  7. //  described in the file COPYING.LIB.
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11. #include "gemo.h"
  12. #include "gemf.h"
  13. #include <aesbind.h>
  14. #include <string.h>
  15.  
  16. // Apparently, this DAMNED USEFUL struct is for __TCC_COMPAT__ only!
  17. typedef struct {
  18.     unsigned short character   :  8;
  19.     signed   short framesize   :  8;
  20.     unsigned short framecol    :  4;
  21.     unsigned short textcol     :  4;
  22.     unsigned short textmode    :  1;
  23.     unsigned short fillpattern :  3;
  24.     unsigned short interiorcol :  4;
  25. } bfobspec;
  26.  
  27. GEMobject::GEMobject(GEMform& F, int RSCindex) :
  28.     form(F),
  29.     myindex(RSCindex)
  30. {
  31.     if (me().Indirect()) {
  32.         // It's already attached to a GEMobject
  33.         original_ob_spec=((GEMobject*)me().ObjectSpecific())->original_ob_spec;
  34.     } else {
  35.         original_ob_spec=me().ObjectSpecific();
  36.         me().ObjectSpecific((unsigned long)this);
  37.         me().Indirect(TRUE);
  38.     }
  39. }
  40.  
  41. GEMobject::~GEMobject()
  42. {
  43.     if (me().ObjectSpecific()==(unsigned long) this) {
  44.         // Must have been a newly attached GEMobject
  45.         me().ObjectSpecific(original_ob_spec);
  46.         me().Indirect(FALSE);
  47.     }
  48. }
  49.  
  50. void GEMobject::Redraw()
  51. {
  52.     form.RedrawObject(myindex);
  53. }
  54.  
  55. void GEMobject::RedrawParent()
  56. {
  57.     form.RedrawObject(form.Parent(myindex));
  58. }
  59.  
  60. GEMfeedback GEMobject::Touch(int x, int y, const GEMevent&)
  61. {
  62.     return IgnoredClick;
  63. }
  64.  
  65. bool GEMobject::ContainsPoint(int x, int y) const
  66. {
  67.     int X,Y;
  68.  
  69.     objc_offset(&form[0],myindex,&X,&Y);
  70.     return (x>=X && y>=Y && x<X+me().Width() && y<Y+me().Height());
  71. }
  72.  
  73. char* GEMobject::ImageBitmap(bool Mask=FALSE) const
  74. {
  75.     switch (Type()) {
  76.      case G_IMAGE:
  77.         return ((BITBLK*)ObjectSpecific())->bi_pdata;
  78.     break; case G_ICON:
  79.         if (Mask)
  80.             return (char*)((ICONBLK*)ObjectSpecific())->ib_pmask;
  81.         else
  82.             return (char*)((ICONBLK*)ObjectSpecific())->ib_pdata;
  83.     break; default:
  84.         return 0;
  85.     }
  86.     return 0;
  87. }
  88.  
  89. short GEMobject::ImageWidth() const
  90. {
  91.     switch (Type()) {
  92.      case G_IMAGE:
  93.         return ((BITBLK*)ObjectSpecific())->bi_wb*8;
  94.     break; case G_ICON:
  95.         return ((ICONBLK*)ObjectSpecific())->ib_wicon;
  96.     break; default:
  97.         return 0;
  98.     }
  99.     return 0;
  100. }
  101.  
  102. short GEMobject::ImageHeight() const
  103. {
  104.     switch (Type()) {
  105.      case G_IMAGE:
  106.         return ((BITBLK*)ObjectSpecific())->bi_hl;
  107.     break; case G_ICON:
  108.         return ((ICONBLK*)ObjectSpecific())->ib_hicon;
  109.     break; default:
  110.         return 0;
  111.     }
  112.     return 0;
  113. }
  114.  
  115. void GEMobject::SetImageBitmap(char* d, short w, short h, bool Mask=FALSE)
  116. {
  117.     switch (Type()) {
  118.      case G_IMAGE:
  119.         ((BITBLK*)ObjectSpecific())->bi_pdata=d;
  120.         ((BITBLK*)ObjectSpecific())->bi_wb=w/8;
  121.         ((BITBLK*)ObjectSpecific())->bi_hl=h;
  122.     break; case G_ICON:
  123.         if (Mask)
  124.             ((ICONBLK*)ObjectSpecific())->ib_pmask=(short*)d;
  125.         else
  126.             ((ICONBLK*)ObjectSpecific())->ib_pdata=(short*)d;
  127.         ((ICONBLK*)ObjectSpecific())->ib_wicon=w;
  128.         ((ICONBLK*)ObjectSpecific())->ib_hicon=h;
  129.     }
  130. }
  131.  
  132. char* GEMobject::Text() const
  133. {
  134.     switch (Type()) {
  135.      case G_ICON:
  136.         return ((ICONBLK*)ObjectSpecific())->ib_ptext;
  137.     break;
  138.         case G_BOXTEXT:
  139.         case G_TEXT:
  140.         case G_FTEXT:
  141.         case G_FBOXTEXT:
  142.             return ((TEDINFO*)ObjectSpecific())->te_ptext;
  143.     break;
  144.         case G_BOXCHAR: // First byte is char.  This usage is dubious.
  145.         case G_STRING:
  146.         case G_BUTTON:
  147.             return (char*)ObjectSpecific();
  148.     break;
  149.         default:
  150.             return "";
  151.     }
  152. }
  153.  
  154. void GEMobject::SetText(char* t)
  155. {
  156.     switch (Type()) {
  157.      case G_ICON:
  158.         ((ICONBLK*)ObjectSpecific())->ib_ptext=t;
  159.     break;
  160.         case G_BOXTEXT:
  161.         case G_TEXT:
  162.         case G_FTEXT:
  163.         case G_FBOXTEXT:
  164.             ((TEDINFO*)ObjectSpecific())->te_ptext=t;
  165.     break;
  166.         case G_STRING:
  167.         case G_BUTTON:
  168.             ObjectSpecific((int)t);
  169.     break;
  170.         case G_BOXCHAR:
  171.             ((bfobspec*)ObjectSpecific())->character=*t;
  172.     }
  173. }
  174.  
  175. void GEMobject::Detach()
  176. {
  177.     objc_delete(&form[0],myindex);
  178. }
  179.  
  180. void GEMobject::Attach(GEMobject& o)
  181. {
  182.     objc_add(&form[0],myindex,o.myindex);
  183. }
  184.  
  185. void GEMobject::Attach(int RSCindex)
  186. {
  187.     objc_add(&form[0],myindex,RSCindex);
  188. }
  189.  
  190. void GEMobject::GetAbsoluteXY(int& x, int& y) const
  191. {
  192.     objc_offset(&form[0],myindex,&x,&y);
  193. }
  194.  
  195. // RSCindex-based
  196. int GEMobject::NumberOfChildren() const
  197. {
  198.     int c=FirstChild();
  199.     for (int n=0; c>=0; n++) c=NextChild(c);
  200.     return n;
  201. }
  202.  
  203. int GEMobject::FirstChild() const
  204. {
  205.     return (me().Head() == myindex) ? -1 : me().Head();
  206. }
  207.  
  208. int GEMobject::NextChild(int after) const
  209. {
  210.     int c=form[after].Next();
  211.     return (c == myindex) ? -1 : c;
  212. }
  213.  
  214. // GEMobject-based
  215. int GEMobject::NumberOfComponents() const
  216. {
  217.     int c=FirstChild();
  218.     for (int n=0; c>=0; c=NextChild(c)) if (form[c].Cook()) n++;
  219.     return n;
  220. }
  221.  
  222. GEMobject* GEMobject::FirstComponent() const
  223. {
  224.     GEMobject* o=0;
  225.     for (int c=FirstChild(); c>=0 && !(o=form[c].Cook()); c=NextChild(c))
  226.         ;
  227.     return o;
  228. }
  229.  
  230. GEMobject* GEMobject::NextComponent(const GEMobject* oo) const
  231. {
  232.     GEMobject* o=0;
  233.     for (int c=FirstChild(); c>=0 && !(o=form[c].Cook()) && o!=oo; c=NextChild(c))
  234.         ;
  235.     if (c>=0) c=NextChild(c);
  236.     for (; c>=0 && !(o=form[c].Cook()); c=NextChild(c))
  237.         ;
  238.     return o;
  239. }
  240.  
  241.  
  242. GEMrawobject* GEMobject::Child(int c) const
  243. {
  244.     return &form[c];
  245. }
  246.  
  247. int GEMobject::Type() const
  248. {
  249.     return me().Type();
  250. }
  251.  
  252. void GEMobject::Type(int t)
  253. {
  254.     me().Type(t);
  255. }
  256.  
  257. int GEMobject::ObjectSpecific() const
  258. {
  259.     return original_ob_spec;
  260. }
  261.  
  262. void GEMobject::ObjectSpecific(int s)
  263. {
  264.     original_ob_spec=s;
  265. }
  266.  
  267. void GEMobject::Font(int font)
  268. {
  269.     switch (Type()) {
  270.         case G_BOXTEXT:
  271.         case G_TEXT:
  272.         case G_FTEXT:
  273.         case G_FBOXTEXT:
  274.             ((TEDINFO*)ObjectSpecific())->te_font=font;
  275.     }
  276. }
  277.  
  278. int GEMobject::Font() const
  279. {
  280.     switch (Type()) {
  281.      case G_BOXTEXT:
  282.      case G_TEXT:
  283.      case G_FTEXT:
  284.      case G_FBOXTEXT:
  285.         return ((TEDINFO*)ObjectSpecific())->te_font;
  286.     break; default:
  287.         return IBM;
  288.     }
  289. }
  290.  
  291. int GEMobject::FillPattern() const
  292. {
  293.     switch (Type()) {
  294.      case G_BOXCHAR:
  295.      case G_BOX:
  296.      case G_IBOX:
  297.         return ((bfobspec*)ObjectSpecific())->fillpattern;
  298.     break; default:
  299.         return 0;
  300.     }
  301. }
  302.  
  303.