home *** CD-ROM | disk | FTP | other *** search
- #include "..\WINDOW\WINDOW.HPP"
- #include <mem.h>
-
- // ------------------------------------------------------------------
- // File: VISIBLE.CPP
- // Path: ...\REHACK\WINDOW\VISIBLE.CPP
- // Version: 0.01
- // Author: Pat Reilly
- // CIS Id: 71333,2764
- // Created On: 6/28/93
- // Modified On:
- // Description: Visible class for REHACK. See WINDOW.TXT for
- // more details.
- // Tabs: 4
- // ------------------------------------------------------------------
-
- Visible::Visible(const Rect& aBounds) :
- bounds(aBounds), owner(0), flags(0UL), next(0)
- {
- // start with the object able to accept the focus and visible.
- flags |= vfFocusable|vfVisible;
- eventMask = ~Broadcast;
- }
-
- Visible::~Visible()
- {
- // remove it from its owner if necessary.
- if(owner != 0)
- owner->remove(this);
- }
-
- void Visible::get(Event& event)
- {
- // use the top window's get().
- if(owner != 0)
- owner->get(event);
- else
- event.clear();
- }
-
- void Visible::handle(Event& event)
- {
- // If user clicks on this object, focus it if its focusable.
- if((event.type & PosDeviceBtnDown) &&
- (event.posDevice.buttons & LeftBtn) && !event.posDevice.dblClicked)
- {
- bool amFocused = getFlag(vfFocused);
- grabFocus();
- if(getFlag(vfFocused) != amFocused && !getFlag(vfPassFirstClick))
- event.clear();
- }
- }
-
- Rect Visible::getLocalBounds() const
- {
- Rect r = bounds;
- r -= bounds.topLeft;
- return r;
- }
-
- Rect Visible::getOwnerBounds() const
- {
- return bounds;
- }
-
- Point Visible::makePointLocal(const Point& point) const
- {
- Point pt = point;
- Visible* o = (Visible*) this;
- while(o != 0)
- {
- pt -= o->bounds.topLeft;
- o = o->owner;
- }
- return pt;
- }
-
- Point Visible::makePointGlobal(const Point& point) const
- {
- Point pt = point;
- Visible* o = (Visible*) this;
- while(o != 0)
- {
- pt += o->bounds.topLeft;
- o = o->owner;
- }
- return pt;
- }
-
- void Visible::setFlag(dword flag, bool enable)
- {
- // Only modify the flag(s).
- if(getFlag(flag) != enable)
- {
- if(enable)
- flags |= flag;
- else
- flags &= ~flag;
- // If we changed *this' visibility, call owner to paint.
- }
- }
-
- bool Visible::getFlag(dword flag) const
- {
- return bool((flags & flag) == flag);
- }
-
- bool Visible::grabFocus()
- {
- // Have the owning VisGroup move the focus.
- return owner->moveFocusTo(this);
- }
-
- bool Visible::canLoseFocus()
- {
- // By default, any object can lose the focus. Override this function
- // if validation is required.
- return true;
- }
-
- Visible* Visible::nextObject() const
- {
- return (owner != 0) ? next : 0;
- }
-
- // Static function used by prevObject().
- static bool hasNextOf(Visible* obj, void* ptr)
- {
- return bool(obj->nextObject() == ptr);
- }
-
- Visible* Visible::prevObject() const
- {
- Visible* obj;
-
- if(owner != 0 && (obj = owner->firstObjectThat(hasNextOf, (void*)this)) != 0)
- return obj;
- else
- return 0;
- }
-
- word Visible::run()
- {
- // By default, objects can't run (be made modal) - override and include
- // an event loop if it should (VisGroup does this).
- return IdCancel;
- }
-
- void Visible::stopRunning(word id)
- {
- // Have the first modal object in the hierarchy stop running.
- if(getFlag(vfModal))
- modalReturnValue = id;
- else if(owner != 0)
- owner->stopRunning(id);
- }
-
-