Category : C Source Code
Archive   : PUBWIW_C.ZIP
Filename : SCROLL.C
Output of file : SCROLL.C contained in archive : PUBWIW_C.ZIP
#include
#include
#include "GRconst.h"
#include "GRports.h" /* MetaWINDOW header files */
#include "GRextrn.h"
#include "window.h"
#include "control.h"
extern COUNT _titlePen, _titleBack, _threshold,
fntWidth, fntHeight,
_VDelta, _HDelta, _VPageDelta, _HPageDelta;
void _drawVScroll(sb)
ScrollBar *sb;
{
penState ps;
GetPenState(&ps);
PenSize(1,1);
FillRect(&(sb->shaft),4);
PenMode(Invert);
FrameRect(&(sb->shaft));
FillRect(&(sb->thumb), 1);
FrameRect(&(sb->thumb));
FillRect(&(sb->downArrow->pHdr.polyRect),1);
FillRect(&(sb->upArrow->pHdr.polyRect),1);
FramePoly(1,&(sb->downArrow->pHdr), sb->downArrow->pnts);
FramePoly(1,&(sb->upArrow->pHdr), sb->upArrow->pnts);
FrameRect(&(sb->downArrow->pHdr.polyRect));
FrameRect(&(sb->upArrow->pHdr.polyRect));
SetPenState(&ps);
}
void _hiliteVScroll(sb, state)
ScrollBar *sb;
COUNT state;
{
penState ps;
GetPenState(&ps);
PenSize(1,1);
PenMode(Replace);
if (state == False)
{
FillRect(&(sb->shaft),1);
}
else
{
FillRect(&(sb->shaft),4);
FillRect(&(sb->thumb), 1);
PenMode(Invert);
FrameRect(&(sb->thumb));
}
PenMode(Invert);
FrameRect(&(sb->shaft));
SetPenState(&ps);
}
/*--------------------------------------------------------------------------*/
BOOL _dragThumb(br, rp, pt)
rect *br;
rect *rp;
point *pt;
{
rect oldR;
point pnt;
COORD x,y;
COUNT button, Xdelta, Ydelta;
penState ps;
GetPenState(&ps);
DupRect(rp,&oldR);
x = rp->Xmin+1;
y = rp->Ymin+1;
pnt.X = x;
PenSize(3,3);
EventQueue(False);
HideCursor();
ReadMouse(&x,&y,&button);
PenMode(Invert);
FrameRect(&oldR);
while (button & LeftButton)
{
ReadMouse(&x,&y,&button);
if (button < 0)
continue;
pnt.Y = y;
/* Gbl2LclPt(&pnt); */
if ( PtInRect(&pnt,br) == False)
continue;
Xdelta = 0;
Ydelta = y - oldR.Ymin;
if ( (iabs(Ydelta) > _threshold))
{
FrameRect(&oldR);
OffsetRect(&oldR,Xdelta,Ydelta);
FrameRect(&oldR);
}
}
FrameRect(&oldR);
EventQueue(True);
PenSize(1,1);
SetPenState(&ps);
ShowCursor();
pt->X = x;
pt->Y = y;
}
COUNT VScrollAction(sb, pt)
ScrollBar *sb;
point *pt;
{
penState ps;
point pnt;
COUNT delta;
COORD saveY;
HideCursor();
GetPenState(&ps);
if ( PtInRect(pt,&(sb->downArrow->pHdr.polyRect)) == True )
{
InvertPoly(1,&(sb->downArrow->pHdr), sb->downArrow->pnts);
wait();
wait();
InvertPoly(1,&(sb->downArrow->pHdr), sb->downArrow->pnts);
if ( (sb->thumb.Ymin - _VDelta) <= sb->shaft.Ymin )
{
if (sb->shaft.Ymin >= sb->thumb.Ymin)
delta = 0;
else
delta = sb->thumb.Ymin - sb->shaft.Ymin;
}
else
delta = _VDelta;
FillRect(&(sb->thumb),4);
OffsetRect(&(sb->thumb),0,-delta);
FillRect(&(sb->thumb),1);
PenMode(Invert);
FrameRect(&(sb->thumb));
}
else
if ( PtInRect(pt,&(sb->upArrow->pHdr.polyRect)) == True )
{
InvertPoly(1,&(sb->upArrow->pHdr), sb->upArrow->pnts);
wait();
wait();
InvertPoly(1,&(sb->upArrow->pHdr), sb->upArrow->pnts);
if ( (sb->thumb.Ymax + _VDelta) >= sb->shaft.Ymax )
{
if (sb->thumb.Ymax >= sb->shaft.Ymax)
delta = 0;
else
delta = sb->shaft.Ymax - sb->thumb.Ymax;
}
else
delta = _VDelta;
FillRect(&(sb->thumb),4);
OffsetRect(&(sb->thumb),0,delta);
FillRect(&(sb->thumb),1);
PenMode(Invert);
FrameRect(&(sb->thumb));
}
else
if ( PtInRect(pt,&(sb->thumb)) == True )
{
saveY = sb->shaft.Ymax;
sb->shaft.Ymax = sb->upArrow->pHdr.polyRect.Ymin - 20;
_dragThumb(&(sb->shaft),&(sb->thumb),&pnt);
sb->shaft.Ymax = saveY;
delta = (pnt.Y - sb->thumb.Ymin);
if ( (sb->thumb.Ymin + delta) < sb->shaft.Ymin )
{
delta = sb->shaft.Ymin - sb->thumb.Ymin;
}
if ( (sb->thumb.Ymax + delta) > sb->shaft.Ymax )
{
delta = sb->shaft.Ymax - sb->thumb.Ymax;
}
FillRect(&(sb->thumb),4);
OffsetRect(&(sb->thumb),0, delta);
FillRect(&(sb->thumb),1);
PenMode(Invert);
FrameRect(&(sb->thumb));
}
else
{
/* Move Thumb Up */
if (pt->Y < sb->thumb.Ymin)
{
if ( (sb->thumb.Ymin - _VPageDelta) <= sb->shaft.Ymin )
{
if (sb->shaft.Ymin >= sb->thumb.Ymin)
delta = 0;
else
delta = sb->shaft.Ymin - sb->thumb.Ymin;
}
else
delta = -_VPageDelta;
}
/* Move Thumb Down */
if (pt->Y > sb->thumb.Ymax)
{
if ( (sb->thumb.Ymax + _VPageDelta) >= sb->shaft.Ymax )
{
if (sb->thumb.Ymax >= sb->shaft.Ymax)
delta = 0;
else
delta = sb->shaft.Ymax - sb->thumb.Ymax;
}
else
delta = _VPageDelta;
}
FillRect(&(sb->thumb),4);
OffsetRect(&(sb->thumb),0, delta);
FillRect(&(sb->thumb),1);
PenMode(Invert);
FrameRect(&(sb->thumb));
}
SetPenState(&ps);
ShowCursor();
}
SBArrow *_downArrow(sbPt)
point *sbPt;
{
SBArrow *temp;
static COUNT base = 4;
COUNT pPtr;
COORD x,y;
if ( (temp = (SBArrow *)malloc(sizeof(SBArrow))) == (SBArrow *)0 )
{
error("Allocation Error in _downArrow");
return ( (SBArrow *)0 );
}
x = sbPt->X;
y = sbPt->Y;
pPtr = 0;
temp->base = base;
temp->pnts[pPtr].X = x;
temp->pnts[pPtr++].Y = y;
temp->pnts[pPtr].X = x + (base * 2);
temp->pnts[pPtr++].Y = y + (base * 2);
temp->pnts[pPtr].X = x + base;
temp->pnts[pPtr++].Y = y + (base * 2);
temp->pnts[pPtr].X = x + base;
temp->pnts[pPtr++].Y = y + (base * 3);
temp->pnts[pPtr].X = x - base;
temp->pnts[pPtr++].Y = y + (base * 3);
temp->pnts[pPtr].X = x - base;
temp->pnts[pPtr++].Y = y + (base * 2);
temp->pnts[pPtr].X = x - (base * 2);
temp->pnts[pPtr++].Y = y + (base * 2);
temp->pnts[pPtr].X = x;
temp->pnts[pPtr++].Y = y;
temp->pHdr.polyBgn = 0;
temp->pHdr.polyEnd = 7;
temp->pHdr.polyRect.Xmin = x - ((base * 2) + 2);
temp->pHdr.polyRect.Xmax = x + ((base * 2) + 2);
temp->pHdr.polyRect.Ymin = y - 2;
temp->pHdr.polyRect.Ymax = y + ((base * 3) + 2);
return(temp);
}
SBArrow *_upArrow(sbPt)
point *sbPt;
{
SBArrow *temp;
static COUNT base = 4;
COUNT pPtr;
COORD x,y;
if ( (temp = (SBArrow *)malloc(sizeof(SBArrow))) == (SBArrow *)0 )
{
error("Allocation Error in _downArrow");
return ( (SBArrow *)0 );
}
x = sbPt->X;
y = sbPt->Y;
pPtr = 0;
temp->base = base;
temp->pnts[pPtr].X = x;
temp->pnts[pPtr++].Y = y;
temp->pnts[pPtr].X = x + (base * 2);
temp->pnts[pPtr++].Y = y - (base * 2);
temp->pnts[pPtr].X = x + base;
temp->pnts[pPtr++].Y = y - (base * 2);
temp->pnts[pPtr].X = x + base;
temp->pnts[pPtr++].Y = y - (base * 3);
temp->pnts[pPtr].X = x - base;
temp->pnts[pPtr++].Y = y - (base * 3);
temp->pnts[pPtr].X = x - base;
temp->pnts[pPtr++].Y = y - (base * 2);
temp->pnts[pPtr].X = x - (base * 2);
temp->pnts[pPtr++].Y = y - (base * 2);
temp->pnts[pPtr].X = x;
temp->pnts[pPtr++].Y = y;
temp->pHdr.polyBgn = 0;
temp->pHdr.polyEnd = 7;
temp->pHdr.polyRect.Xmin = x - ((base * 2) + 2);
temp->pHdr.polyRect.Xmax = x + ((base * 2) + 2);
temp->pHdr.polyRect.Ymin = y - ((base * 3) + 2);
temp->pHdr.polyRect.Ymax = y + 2;
return(temp);
}
ControlPtr NewVScroll(wnp, bounds, action, data, defalt, min, max)
WindowPtr wnp;
rect *bounds;
COUNT (* action)();
UBYTE *data;
COUNT defalt, min, max;
{
extern COUNT ScrollAction();
point pt;
ControlPtr temp;
ScrollBar *sb;
if ( (temp = (ControlPtr)malloc(sizeof(Control))) == (ControlPtr)0 )
{
error("Unable to Allocate Control");
ExitToShell();
}
DupRect(bounds, &(temp->bounds));
temp->type = C_SCROLL;
temp->owner = wnp;
temp->next = (ControlPtr)0;
if (action != (UBYTE *)0)
temp->action = action;
else
temp->action = (UBYTE *)0;
temp->handler = VScrollAction;
temp->data = data;
temp->visible = True;
temp->enabled = True;
if ( (sb = (ScrollBar *)malloc(sizeof(ScrollBar))) == (ScrollBar *)0 )
{
error("Unable to Allocate Control");
ExitToShell();
}
pt.X = bounds->Xmin + (bounds->Xmax - bounds->Xmin) / 2;
pt.Y = wnp->content.Ymin + 2;
if ( (sb->downArrow = _downArrow(&pt)) == (SBArrow *)0 )
{
error("Unable to Allocate Arrow");
ExitToShell();
}
pt.X = bounds->Xmin + (bounds->Xmax - bounds->Xmin) / 2;
if ( wnp->growBox != (rect *)0 )
pt.Y = wnp->growBox->Ymin - 2;
else
pt.Y = wnp->content.Ymax - 2;
if ( (sb->upArrow = _upArrow(&pt)) == (SBArrow *)0 )
{
error("Unable to Allocate Arrow");
ExitToShell();
}
DupRect(bounds, &(sb->shaft));
sb->shaft.Ymin = sb->downArrow->pHdr.polyRect.Ymax + 2;
sb->shaft.Ymax = sb->upArrow->pHdr.polyRect.Ymin - 2;
DupRect(&(sb->shaft), &(sb->thumb));
sb->thumb.Ymax = sb->thumb.Ymin + (bounds->Xmax - bounds->Xmin);
sb->minVal = min;
sb->maxVal = max;
sb->currVal = defalt;
temp->defn.sb = sb;
wnp->VScroll = temp;
return(temp);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
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/