Category : Recently Uploaded Files
Archive   : DOSUIT07.ZIP
Filename : VOBJECT.CPP

 
Output of file : VOBJECT.CPP contained in archive : DOSUIT07.ZIP
#ifdef ALL
#define VOBJECTA
#define VOBJECTB
#define VOBJECTC
#define VOBJECTD
#define VOBJECTE
#define VOBJECTF
#define VOBJECTG
#define VOBJECTH
#define VOBJECTI
#define VOBJECTJ
#define VOBJECTK
#define VOBJECTL
#define VOBJECTM
#define VOBJECTN
#endif
#ifndef VOBJECTA
#define LIBRARY_MODULE
#endif

/*
* Basic user interface object.
*/

#ifndef NDEBUG
#include
#endif
#include
#include "vobject.hpp"
#include "applic.hpp"
#include "event.hpp"
#ifndef NINSPECT
#include "inspect.hpp"
#endif

#ifdef VOBJECTA

FILE *VObject::debug = 0;

// destructor & virtual methods

const VObject *EndList = 0;

void VObject::build()
{
sflags = SFalloff;
cflags = CFdirty; // force draw when added to a window
container = 0;
window = 0;
#ifndef NDEBUG
if(debug)
fprintf(debug,"Construct %s\n",debuginfo());
#endif
}

static const char stateletters[17] = "DFHSSATM";
static const char controlletters[17] = "FSPDCPA";

void VObject::setcFlag(ControlFlag f)
{
ControlFlag oldflags = cflags;

if(testFlag(SFshowfocus) && (f & CFfocus) && !testcFlag(CFfocus))
{
setFlag(SFfocus); // if setting focus, change color
f = (ControlFlag) (f | CFdirty); // and mark dirty too
}
cflags = (ControlFlag) (cflags | f);
oldflags = (ControlFlag) (oldflags ^ cflags);
#ifndef NDEBUG
if(debug && oldflags)
{
fprintf(debug,"%s->setcFlag(%s) ",debuginfo(),transbits(f,controlletters));
fprintf(debug,"changed(%s) ",transbits(oldflags,controlletters));
fprintf(debug,"now(%s)\n",transbits(cflags,controlletters));
}
#endif
if(oldflags && container)
container->contentsSet(this,oldflags);
}

void VObject::clearcFlag(ControlFlag f)
{
ControlFlag oldflags = cflags;

cflags = (ControlFlag) (cflags & ~f);
oldflags = (ControlFlag) (oldflags ^ cflags);
#ifndef NDEBUG
if(debug && oldflags)
{
fprintf(debug,"%s->clearcFlag(%s) ",debuginfo(),transbits(oldflags,controlletters));
fprintf(debug,"now(%s)\n",transbits(cflags,controlletters));
}
#endif
if(oldflags && container)
container->contentsCleared(this,oldflags);
if(testFlag(SFshowfocus) && (oldflags & CFfocus))
{
clearFlag(SFfocus); // if clearing focus, change color
dirty(); // and mark dirty
}
}

VObject::~VObject()
{
if(container)
container->contentsDeleted(this);
#ifndef NDEBUG
if(debug)
fprintf(debug,"Delete %s@%p\n",name(),this);
#endif
}

void VObject::dirty(const Rectangle &r)
{
if(testcFlag(CFdirty) || !this->intersects(r))
return;
if(!testcFlag(CFpartdirty))
{
dirtyArea = r;
dirtyArea &= *this; // ensure dirtyArea no bigger than Object
setcFlag(CFpartdirty);
}
else
{
Rectangle d(r);
d &= *this;
dirtyArea |= d;
}
}

void VObject::contentsSet(VObject* o,ControlFlag f)
{
ControlFlag s = CFNone;

if(f & (CFsize | CFposition))
dirty(*o);
else if(f & (CFdirty | CFcontentsdirty | CFpartdirty))
s = (ControlFlag) (s | CFcontentsdirty);
s = (ControlFlag) (s | (f & CFfocus));
if(!testcFlag(CFactive))
s = (ControlFlag) (s | (f & CFactive));
if(s)
setcFlag(s);
}

void VObject::contentsCleared(VObject*,ControlFlag)
{
}

void VObject::contentsDeleted(VObject*)
{
}

void VObject::setwindow(Window *w)
{
if(w != window && testFlag(SFactfocus))
{
if(window)
window->clearactive(this);
if(w)
w->setactive(this);
}
window = w;
}

void VObject::move(coord x,coord y)
{
if(!x && !y)
return;
Rectangle::move(x,y);
setcFlag((ControlFlag) (CFdirty|CFposition));
}

void VObject::setwidth(const coord w)
{
if(w == width())

return;
Rectangle::setwidth(w);
setcFlag((ControlFlag) (CFdirty|CFsize));
}

void VObject::setheight(const coord h)
{
if(h == height())
return;
Rectangle::setheight(h);
setcFlag((ControlFlag) (CFdirty|CFsize));
}

void VObject::align(AlignFlag a,const Rectangle& r)
{
Point p, s;

switch(a & AFHoriz)
{
case AFHleft:
p.x = r.left();
s.x = width();
break;
case AFHright:
p.x = r.right() - width() + 1;
s.x = width();
break;
case AFHcenter:
p.x = r.left() + (r.width() - width()) / 2;
s.x = width();
break;
case AFHexpand:
p.x = r.left();
s.x = r.width();
break;
}
switch(a & AFVert)
{
case AFVtop:
p.y = r.top();
s.y = height();
break;
case AFVbottom:
p.y = r.bottom() - height() + 1;
s.y = height();
break;
case AFVcenter:
p.y = r.top() + (r.height() - height()) / 2;
s.y = height();
break;
case AFVexpand:
p.y = r.top();
s.y = r.height();
break;
}
position(p);
setsize(s);
}

void VObject::update()
{
if(testcFlag(CFdirty))
draw();
else if(testcFlag(CFpartdirty))
{
paint(dirtyArea);
clean();
}
}

coord VObject::minwidth() const
{
return 1;
}

coord VObject::minheight() const
{
return 1;
}

coord VObject::maxwidth() const
{
return minwidth();
}

coord VObject::maxheight() const
{
return minheight();
}

void VObject::paint(Rectangle r)
{
r &= *this;
ASSERT(window);
window->fillrect(r,getcolor(),' ');
}

int VObject::setfocus(int tabstop)
{
if(!testcFlag(CFactive))
return 0;
if(!tabstop && testFlag(SFtabstop))
return 0;
#ifndef NDEBUG
if(debug)
fprintf(debug,"%s->setfocus\n",debuginfo());
#endif
Application::focusto(this);
setcFlag(CFfocus);
return 1;
}

void VObject::resetfocus()
{
#ifndef NDEBUG
if(debug)
fprintf(debug,"%s->resetfocus\n",debuginfo());
#endif
clearcFlag(CFfocus);
}

void VObject::clearfocus(VObject *)
{
#ifndef NDEBUG
if(debug)
fprintf(debug,"%s->clearfocus\n",debuginfo());
#endif
if(testcFlag(CFfocus))
clearcFlag(CFfocus);
if(container)
container->clearfocus(this);
if(Application::kbdfocus() == this)
Application::focusto(0);
}

int VObject::incfocus(int,int)
{
return 0;
}

int VObject::nextTabstop(int,int)
{
if(testFlag(SFtabstop) && !testcFlag(CFfocus))
return setfocus();
return 0;
}

VObject *VObject::containingObject(const Point &p)
{
return this->encloses(p) ? this : 0;
}

int VObject::handle(MouseEvent& e)
{
int r = 0;

if(this->encloses(e.at()))
{
if(!testFlag(SFmousein))
{
setFlag(SFmousein);
r = mouseenter(e);
}
}
else
{
if(testFlag(SFmousein))
{
clearFlag(SFmousein);
r = mouseexit(e);
}
}
if(!r)
r = e.callHandler(this);
#ifndef NDEBUG
if(debug && r)
fprintf(debug,"%s->handle(%s[%d,%d])\n",
debuginfo(),e.name(),e.at().x,e.at().y);
#endif
return r;
}

int VObject::mousemove(MouseEvent&)
{
return 0;
}

int VObject::mouseenter(MouseEvent&)
{
return 0;
}

int VObject::mouseexit(MouseEvent&)
{
return 0;
}

int VObject::leftdown(MouseEvent&)
{
return 0;
}

int VObject::middledown(MouseEvent&)
{
return 0;
}

int VObject::rightdown(MouseEvent&)
{
return 0;
}

int VObject::leftup(MouseEvent&)
{
return 0;
}

int VObject::middleup(MouseEvent&)
{
return 0;
}

int VObject::rightup(MouseEvent&)
{
return 0;
}

int VObject::leftclick(MouseEvent&)
{
return 0;
}

int VObject::middleclick(MouseEvent&)
{
return 0;
}

int VObject::rightclick(MouseEvent&)
{
return 0;
}

int VObject::leftdoubleclick(MouseEvent&)
{
return 0;
}

int VObject::middledoubleclick(MouseEvent&)
{
return 0;
}

int VObject::rightdoubleclick(MouseEvent&)
{
return 0;
}

int VObject::inspectclick(MouseEvent&)
{
#ifndef NINSPECT
new Inspector(this);
#endif
return 1;
}

int VObject::kbdevent(KeyboardEvent& e)
{
if(testFlag(SFtabstop))
switch(e.value())
{
case Kright:
case Kleft:
case Kup:
case Kdown:
return 1; // ignore arrows off tabbed object
}
if(e.value() == KF1)
return help();
return 0;
}

int VObject::dohotkey(KeyboardEvent&)
{
return 0;
}

int VObject::interruptevent(InterruptEvent&)
{
return 0;
}

int VObject::criterr(CriticalErrorEvent&)
{
return 0;
}

int VObject::help()
{
return Application::help(name());
}

#ifdef NINSPECT
char *VObject::inspectinfo(char *buf,const char *s) const
{
return "";
}
#else
static char inspectbuf[2048];

char *VObject::inspectinfo(char *buf,const char *s) const
{

if(!s)
s = "VObject ";
if(!buf)
{
buf = inspectbuf;
*buf = 0;
}
strcat(buf,form("%s'%s'@%p\n",s,name(),this));
Rectangle::inspectinfo(buf,"At ");
strcat(buf,form("\nState:%s\n",transbits(sflags,stateletters)));
strcat(buf,form("Control:%s\n",transbits(cflags,controlletters)));
if(testcFlag(CFpartdirty))
{
dirtyArea.inspectinfo(buf,"Dirty Area ");
strcat(buf,"\n");
}
strcat(buf,form("Container:'%s'@%p\n",
(container) ? container->name() : "NULL",container));
return strcat(buf,form("Window:'%s'@%p\n",
(window) ? window->name() : "NULL",window));
}
#endif

char VObject::debugbuf[2048];

#ifdef NDEBUG
char *VObject::debuginfo(char *buf) const
{
return buf;
}
#else
char *VObject::debuginfo(char *buf) const
{
if(!buf)
{
buf = debugbuf;
*buf = 0;
}
strcat(buf,form("%s@%p",name(),this));
Rectangle::inspectinfo(buf);
return buf;
}
#endif

#ifndef NOPROTECT
#ifdef NDEBUG
void VObject::dump(FILE *f) const
{
if(f)
fprintf(f,"%s@%p\n", this, name());
}
#else
void VObject::dump(FILE *f) const
{
if(f)
fprintf(f,"%s\n", debuginfo());
}
#endif
#endif
#endif /* VOBJECTA */

#ifdef VOBJECTB

void VObject::placeInside(const Rectangle &r)
{
if(width() > r.width())
setwidth(r.width());
if(height() > r.height())
setheight(r.height());

Point p;

if(left() < r.left())
p.x = r.left() - left();
else if(right() > r.right())
p.x = r.right() - right(); // negative i.e. move left
else
p.x = 0;
if(top() < r.top())
p.y = r.top() - top();
else if(bottom() > r.bottom())
p.y = r.bottom() - bottom(); // negative i.e. move up
else
p.y = 0;
if(p.x || p.y)
move(p);
}
#endif

#ifdef VOBJECTC
void VObject::setmoufocus(int repeat)
{
Application::mousefocusto(this,repeat);
}

void VObject::resetmoufocus()
{
Application::mousefocusoff(this);
}
#endif

#ifdef VOBJECTD
VObject::VObject(const Rectangle &r,const char *n)
: Rectangle(r), NamedProtected(n)
{
build();
}
#endif

#ifdef VOBJECTE
VObject::VObject(const char *n)
: NamedProtected(n)
{
build();
}
#endif

#ifdef VOBJECTF
VObject::VObject(const coord l,const coord t,const coord r,const coord b,
const char *n)
: Rectangle(l,t,r,b), NamedProtected(n)
{
build();
}
#endif

#ifdef VOBJECTG
VObject::VObject(const coord w,const coord h,const char *n)
: Rectangle(w,h), NamedProtected(n)
{
build();
}
#endif

#ifdef VOBJECTH
void VObject::moveDirtyArea(coord x,coord y)
{
if(testcFlag(CFpartdirty))
{
dirtyArea.move(x,y); // the dirty area is moving
if(!this->intersects(dirtyArea))
clearcFlag(CFpartdirty);
else
dirtyArea &= *this;
}
}
#endif

#ifdef VOBJECTI
Control::Control(const Rectangle &r,const char *n)
: VObject(r,n)
{
recogniseEvents();
}
#endif

#ifdef VOBJECTJ
Control::Control(const char *n)
: VObject(n)
{
recogniseEvents();
}
#endif

#ifdef VOBJECTK
Control::Control(const coord l,const coord t,const coord r,const coord b,
const char *n)
: VObject(l,t,r,b,n)
{
recogniseEvents();
}
#endif

#ifdef VOBJECTL
Control::Control(const coord w,const coord h,const char *n)
: VObject(w,h,n)
{
recogniseEvents();
}
#endif

#ifdef VOBJECTM
const char *transbits(unsigned int flags,const char *letters)
{
const bitsInAnUnsignedInt = 32;
static char buf[bitsInAnUnsignedInt+1];

ASSERT(strlen(letters) <= bitsInAnUnsignedInt);
for(char *p = buf; *letters; flags >>= 1, letters++)
*p++ = (flags & 1) ? *letters : '-';
*p = 0;
return buf;
}
#endif

#ifdef VOBJECTN
#ifdef NDEBUG
void crash(const char *,const char *,unsigned)
{
}
#else
#include

void crash(const char *e,const char *file,unsigned line)
{
fprintf(stderr,"Assertion failure: '%s' on line %u in file '%s'\n",
e,line,file);
if(VObject::debug)
fprintf(VObject::debug,"Assertion failure: '%s' on line %u in file '%s'\n",
e,line,file);
#ifndef NOPROTECT
Protected::dumpall(stderr);
if(VObject::debug)
Protected::dumpclose(VObject::debug);
if(Protected::dumpfile)
{
fprintf(Protected::dumpfile,"Assertion failure: '%s' on line %u in file '%s'\n",
e,line,file);
Protected::dumpclose();
}
#endif
_exit(1);
}

#endif
#endif


  3 Responses to “Category : Recently Uploaded Files
Archive   : DOSUIT07.ZIP
Filename : VOBJECT.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/