home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / window / visible.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-29  |  3.2 KB  |  158 lines

  1. #include "..\WINDOW\WINDOW.HPP"
  2. #include <mem.h>
  3.  
  4. // ------------------------------------------------------------------
  5. // File:        VISIBLE.CPP
  6. // Path:        ...\REHACK\WINDOW\VISIBLE.CPP
  7. // Version:        0.01
  8. // Author:        Pat Reilly
  9. // CIS Id:        71333,2764
  10. // Created On:    6/28/93
  11. // Modified On:
  12. // Description:    Visible class for REHACK. See WINDOW.TXT for
  13. //                more details.
  14. // Tabs:        4
  15. // ------------------------------------------------------------------
  16.  
  17. Visible::Visible(const Rect& aBounds) :
  18.     bounds(aBounds), owner(0), flags(0UL), next(0)
  19. {
  20.     // start with the object able to accept the focus and visible.
  21.     flags |= vfFocusable|vfVisible;
  22.     eventMask = ~Broadcast;
  23. }
  24.  
  25. Visible::~Visible()
  26. {
  27.     // remove it from its owner if necessary.
  28.     if(owner != 0)
  29.         owner->remove(this);
  30. }
  31.  
  32. void Visible::get(Event& event)
  33. {
  34.     // use the top window's get().
  35.     if(owner != 0)
  36.         owner->get(event);
  37.     else
  38.         event.clear();
  39. }
  40.  
  41. void Visible::handle(Event& event)
  42. {
  43.     // If user clicks on this object, focus it if its focusable.
  44.     if((event.type & PosDeviceBtnDown) &&
  45.        (event.posDevice.buttons & LeftBtn) && !event.posDevice.dblClicked)
  46.         {
  47.         bool amFocused = getFlag(vfFocused);
  48.         grabFocus();
  49.         if(getFlag(vfFocused) != amFocused && !getFlag(vfPassFirstClick))
  50.             event.clear();
  51.         }
  52. }
  53.  
  54. Rect Visible::getLocalBounds() const
  55. {
  56.     Rect r = bounds;
  57.     r -= bounds.topLeft;
  58.     return r;
  59. }
  60.  
  61. Rect Visible::getOwnerBounds() const
  62. {
  63.     return bounds;
  64. }
  65.  
  66. Point Visible::makePointLocal(const Point& point) const
  67. {
  68.     Point pt = point;
  69.     Visible* o = (Visible*) this;
  70.     while(o != 0)
  71.         {
  72.         pt -= o->bounds.topLeft;
  73.         o = o->owner;
  74.         }
  75.     return pt;
  76. }
  77.  
  78. Point Visible::makePointGlobal(const Point& point) const
  79. {
  80.     Point pt = point;
  81.     Visible* o = (Visible*) this;
  82.     while(o != 0)
  83.         {
  84.         pt += o->bounds.topLeft;
  85.         o = o->owner;
  86.         }
  87.     return pt;
  88. }
  89.  
  90. void Visible::setFlag(dword flag, bool enable)
  91. {
  92.     // Only modify the flag(s).
  93.     if(getFlag(flag) != enable)
  94.         {
  95.         if(enable)
  96.             flags |= flag;
  97.         else
  98.             flags &= ~flag;
  99.         // If we changed *this' visibility, call owner to paint.
  100.         }
  101. }
  102.  
  103. bool Visible::getFlag(dword flag) const
  104. {
  105.     return bool((flags & flag) == flag);
  106. }
  107.  
  108. bool Visible::grabFocus()
  109. {
  110.     // Have the owning VisGroup move the focus.
  111.     return owner->moveFocusTo(this);
  112. }
  113.  
  114. bool Visible::canLoseFocus()
  115. {
  116.     // By default, any object can lose the focus. Override this function
  117.     //    if validation is required.
  118.     return true;
  119. }
  120.  
  121. Visible* Visible::nextObject() const
  122. {
  123.     return (owner != 0) ? next : 0;
  124. }
  125.  
  126. // Static function used by prevObject().
  127. static bool hasNextOf(Visible* obj, void* ptr)
  128. {
  129.     return bool(obj->nextObject() == ptr);
  130. }
  131.  
  132. Visible* Visible::prevObject() const
  133. {
  134.     Visible* obj;
  135.  
  136.     if(owner != 0 && (obj = owner->firstObjectThat(hasNextOf, (void*)this)) != 0)
  137.         return obj;
  138.     else
  139.         return 0;
  140. }
  141.  
  142. word Visible::run()
  143. {
  144.     // By default, objects can't run (be made modal) - override and include
  145.     //    an event loop if it should (VisGroup does this).
  146.     return IdCancel;
  147. }
  148.  
  149. void Visible::stopRunning(word id)
  150. {
  151.     // Have the first modal object in the hierarchy stop running.
  152.     if(getFlag(vfModal))
  153.         modalReturnValue = id;
  154.     else if(owner != 0)
  155.         owner->stopRunning(id);
  156. }
  157.  
  158.