home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / progtool / c / gcc / gempp19.zoo / gem++19 / src / gemo.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-29  |  3.3 KB  |  179 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. #include <limits.h>
  16.  
  17.  
  18. GEMobject::GEMobject(GEMform& F, int RSCindex) :
  19.     form(F),
  20.     myindex(RSCindex)
  21. {
  22.     if (me().Indirect()) {
  23.         // It's already attached to a GEMobject
  24.         original_ob_spec=me().Cook()->original_ob_spec;
  25.     } else {
  26.         original_ob_spec=me().ObjectSpecific();
  27.         me().ObjectSpecific((unsigned long)this);
  28.         me().Indirect(TRUE);
  29.     }
  30. }
  31.  
  32. GEMobject::~GEMobject()
  33. {
  34.     if (me().Cook() == this) {
  35.         // Must have been a newly attached GEMobject
  36.         me().Indirect(FALSE);
  37.         me().ObjectSpecific(original_ob_spec);
  38.     }
  39. }
  40.  
  41. void GEMobject::Resize(short w, short h)
  42. {
  43.     SetWidth(w);
  44.     SetHeight(h);
  45. }
  46.  
  47. void GEMobject::SetWidth(short w)
  48. {
  49.     me().Resize(w,Height());
  50. }
  51.  
  52. void GEMobject::SetHeight(short h)
  53. {
  54.     me().Resize(Width(),h);
  55. }
  56.  
  57. void GEMobject::Redraw()
  58. {
  59.     int border=BorderWidth();
  60.     if (border>0)
  61.         form.RedrawObject(myindex,-border,-border,Width()+2*border,Height()+2*border);
  62.     else
  63.         form.RedrawObject(myindex);
  64. }
  65.  
  66. void GEMobject::RedrawParent()
  67. {
  68.     form.RedrawObject(form.Parent(myindex));
  69. }
  70.  
  71. GEMfeedback GEMobject::Touch(int x, int y, const GEMevent&)
  72. {
  73.     return IgnoredClick;
  74. }
  75.  
  76. bool GEMobject::ContainsPoint(int x, int y) const
  77. {
  78.     int X,Y;
  79.  
  80.     objc_offset(&form[0],myindex,&X,&Y);
  81.     return (x>=X && y>=Y && x<X+me().Width() && y<Y+me().Height());
  82. }
  83.  
  84. void GEMobject::Detach()
  85. {
  86.     objc_delete(&form[0],myindex);
  87. }
  88.  
  89. void GEMobject::Attach(GEMobject& o)
  90. {
  91.     objc_add(&form[0],myindex,o.myindex);
  92. }
  93.  
  94. void GEMobject::Attach(int RSCindex)
  95. {
  96.     objc_add(&form[0],myindex,RSCindex);
  97. }
  98.  
  99. void GEMobject::GetAbsoluteXY(int& x, int& y) const
  100. {
  101.     objc_offset(&form[0],myindex,&x,&y);
  102. }
  103.  
  104. // RSCindex-based
  105. int GEMobject::NumberOfChildren() const
  106. {
  107.     int c=FirstChild();
  108.     for (int n=0; c>=0; n++) c=NextChild(c);
  109.     return n;
  110. }
  111.  
  112. int GEMobject::FirstChild() const
  113. {
  114.     return (me().Head() == myindex) ? -1 : me().Head();
  115. }
  116.  
  117. int GEMobject::NextChild(int after) const
  118. {
  119.     int c=form[after].Next();
  120.     return (c == myindex) ? -1 : c;
  121. }
  122.  
  123. // GEMobject-based
  124. int GEMobject::NumberOfComponents() const
  125. {
  126.     int c=FirstChild();
  127.     for (int n=0; c>=0; c=NextChild(c)) if (form[c].Cook()) n++;
  128.     return n;
  129. }
  130.  
  131. GEMobject* GEMobject::FirstComponent() const
  132. {
  133.     GEMobject* o=0;
  134.     for (int c=FirstChild(); c>=0 && !(o=form[c].Cook()); c=NextChild(c))
  135.         ;
  136.     return o;
  137. }
  138.  
  139. GEMobject* GEMobject::NextComponent(const GEMobject* oo) const
  140. {
  141.     GEMobject* o=0;
  142.     for (int c=FirstChild(); c>=0 && !(o=form[c].Cook()) && o!=oo; c=NextChild(c))
  143.         ;
  144.     if (c>=0) c=NextChild(c);
  145.     for (; c>=0 && !(o=form[c].Cook()); c=NextChild(c))
  146.         ;
  147.     return o;
  148. }
  149.  
  150.  
  151. GEMrawobject* GEMobject::Child(int c) const
  152. {
  153.     return &form[c];
  154. }
  155.  
  156. int GEMobject::Type() const
  157. {
  158.     return me().Type();
  159. }
  160.  
  161. void GEMobject::Type(int t)
  162. {
  163.     me().Type(t);
  164. }
  165.  
  166. int GEMobject::ObjectSpecific() const
  167. {
  168.     return original_ob_spec;
  169. }
  170.  
  171. void GEMobject::ObjectSpecific(int s)
  172. {
  173.     original_ob_spec=s;
  174. }
  175.  
  176. #define CLASS GEMobject
  177. #include "gemo_m.cc"
  178. #undef CLASS
  179.