Category : C Source Code
Archive   : PUBWIW_C.ZIP
Filename : CONTROL.C
Output of file : CONTROL.C contained in archive : PUBWIW_C.ZIP
#include
#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;
COUNT ControlEvent(X,Y,wnp)
COORD X,Y;
WindowPtr wnp;
{
metaPort savePort;
point pt;
ControlPtr cPtr;
if (wnp->controls == (ControlPtr)0)
return(IN_NOTHING);
GetPort(&savePort);
SetPort(&(wnp->port));
pt.X = X;
pt.Y = Y;
Gbl2LclPt(&pt);
cPtr = (ControlPtr)(wnp->controls);
while (cPtr != (ControlPtr) 0)
{
if ( PtInRect(&pt,&(cPtr->bounds)) == True )
{
(* (cPtr->handler))( cPtr->defn, &pt);
if ( cPtr->action != NULL)
{
(* (cPtr->action))( cPtr->data);
}
SetPort(savePort);
return(True);
}
cPtr = cPtr->next;
}
SetPort(savePort);
return(False);
}
void InsertControl(cp, wnp)
ControlPtr cp;
WindowPtr wnp;
{
ControlPtr newPtr;
if (wnp->controls == (ControlPtr)0)
{
wnp->controls = cp;
cp->next = (ControlPtr)0;
return;
}
newPtr = (ControlPtr)wnp->controls;
while (newPtr->next != (ControlPtr) 0)
{
newPtr = newPtr->next;
}
newPtr->next = cp;
cp->next = (ControlPtr) 0;
}
void _drawRadio(rb)
RadioButton *rb;
{
penState ps;
GetPenState(&ps);
PenMode(Invert);
PenSize(1,1);
FrameOval(&(rb->inner));
FrameOval(&(rb->outer));
if (rb->value == True)
InvertOval(&(rb->inner));
MoveTo(rb->outer.Xmax + 4, rb->outer.Ymax-2);
PenColor(_titlePen);
BackColor(_titleBack);
PenMode(Replace);
DrawString(rb->title);
SetPenState(&ps);
}
void _drawCheck(cb)
CheckBox *cb;
{
penState ps;
GetPenState(&ps);
PenSize(1,1);
PenMode(Invert);
FrameRect(&(cb->box));
if (cb->value == True)
{
MoveTo(cb->box.Xmin, cb->box.Ymin);
LineTo(cb->box.Xmax, cb->box.Ymax);
MoveTo(cb->box.Xmax, cb->box.Ymin);
LineTo(cb->box.Xmin, cb->box.Ymax);
}
MoveTo(cb->box.Xmax + 4, cb->box.Ymax - 2);
PenMode(Replace);
PenColor(_titlePen);
BackColor(_titleBack);
DrawString(cb->title);
SetPenState(&ps);
}
void _drawButton(bt)
Button *bt;
{
penState ps;
GetPenState(&ps);
if (bt->defalt == True)
{
TextFace(cBold);
PenSize(3,3);
}
else
{
TextFace(cNormal);
PenSize(1,1);
}
PenMode(Invert);
FrameRoundRect(&(bt->box),bt->Xdia,bt->Ydia);
PenSize(1,1);
MoveTo
(
bt->box.Xmin + fntWidth,
bt->box.Ymax - (((bt->box.Ymax - bt->box.Ymin) - fntHeight/2) / 2)
);
PenMode(Replace);
PenColor(_titlePen);
BackColor(_titleBack);
DrawString(bt->title);
TextFace(cNormal);
SetPenState(&ps);
}
void DrawControl(cp)
ControlPtr cp;
{
metaPort *savePort;
penState ps;
GetPort(&savePort);
SetPort(&(cp->owner->port));
GetPenState(&ps);
if (cp->visible == False)
return;
switch(cp->type)
{
case C_RADIO:
_drawRadio(cp->defn.rb);
break;
case C_CHECK:
_drawCheck(cp->defn.cb);
break;
case C_BUTTON:
_drawButton(cp->defn.bt);
break;
#if 0
case C_SCROLL:
_drawScroll(cp->defn.sb);
break;
#endif
}
SetPenState(&ps);
SetPort(savePort);
}
ControlPtr NewRadio(wnp, bounds, title, action, data)
WindowPtr wnp;
rect *bounds;
TEXT *title;
COUNT (* action)();
UBYTE *data;
{
extern COUNT RadioAction();
ControlPtr temp;
RadioButton *rb;
if ( (temp = (ControlPtr)malloc(sizeof(Control))) == (ControlPtr)0 )
{
error("Unable to Allocate Control");
ExitToShell();
}
DupRect(bounds, &(temp->bounds));
temp->type = C_RADIO;
temp->owner = wnp;
temp->next = (ControlPtr)0;
if (action != (UBYTE *)0)
temp->action = action;
else
temp->action = (UBYTE *)0;
temp->handler = RadioAction;
temp->data = data;
temp->visible = True;
temp->enabled = True;
temp->defn.rb->value = False;
if ( (rb =
(RadioButton *)malloc(sizeof(RadioButton))) == (RadioButton *)0 )
{
error("Unable to Allocate Control");
ExitToShell();
}
DupRect(bounds,&(rb->outer));
rb->outer.Xmin += 2;
rb->outer.Xmax = rb->outer.Xmin + (rb->outer.Ymax - rb->outer.Ymin) + 3;
rb->outer.Ymin += 1;
rb->outer.Ymax -= 1;
DupRect(&(rb->outer),&(rb->inner));
InsetRect(&(rb->inner),3,2);
temp->defn.rb = rb;
if ( (temp->defn.rb->title = (TEXT *)malloc(strlen(title)+1)) == (TEXT *)0 )
{
error("Unable to Allocate Control");
ExitToShell();
}
strcpy(temp->defn.rb->title,title);
InsertControl(temp,wnp);
return(temp);
}
COUNT RadioAction(rb, pt)
RadioButton *rb;
point *pt;
{
HideCursor();
PenMode(Invert);
InvertOval(&(rb->inner));
ShowCursor();
if ( rb->value == True )
rb->value = False;
else
rb->value = True;
}
COUNT ButtonAction(bt, pt)
Button *bt;
point *pt;
{
HideCursor();
InvertRoundRect(&(bt->box),bt->Xdia, bt->Ydia);
wait();
wait();
InvertRoundRect(&(bt->box),bt->Xdia, bt->Ydia);
ShowCursor();
}
COUNT CBAction(cb, pt)
CheckBox *cb;
point *pt;
{
HideCursor();
PenMode(Invert);
MoveTo(cb->box.Xmin, cb->box.Ymin);
LineTo(cb->box.Xmax, cb->box.Ymax);
MoveTo(cb->box.Xmax, cb->box.Ymin);
LineTo(cb->box.Xmin, cb->box.Ymax);
ShowCursor();
if ( cb->value == True )
cb->value = False;
else
cb->value = True;
}
ControlPtr NewCheckBox(wnp, bounds, title, action, data)
WindowPtr wnp;
rect *bounds;
TEXT *title;
COUNT (* action)();
UBYTE *data;
{
extern COUNT CBAction();
ControlPtr temp;
CheckBox *cb;
if ( (temp = (ControlPtr)malloc(sizeof(Control))) == (ControlPtr)0 )
{
error("Unable to Allocate Control");
ExitToShell();
}
DupRect(bounds, &(temp->bounds));
temp->type = C_CHECK;
temp->owner = wnp;
temp->next = (ControlPtr)0;
if (action != (UBYTE *)0)
temp->action = action;
else
temp->action = (UBYTE *)0;
temp->handler = CBAction;
temp->data = data;
temp->visible = True;
temp->enabled = True;
temp->defn.cb->value = False;
if ( (cb =
(CheckBox *)malloc(sizeof(CheckBox))) == (CheckBox *)0 )
{
error("Unable to Allocate Control");
ExitToShell();
}
DupRect(bounds,&(cb->box));
cb->box.Xmin += 2;
cb->box.Xmax = cb->box.Xmin + (cb->box.Ymax - cb->box.Ymin) + 1;
cb->box.Ymin += 1;
cb->box.Ymax -= 1;
temp->defn.cb = cb;
if ( (temp->defn.cb->title = (TEXT *)malloc(strlen(title)+1)) == (TEXT *)0 )
{
error("Unable to Allocate Control");
ExitToShell();
}
strcpy(temp->defn.cb->title,title);
InsertControl(temp,wnp);
return(temp);
}
void DisposControl(cp)
ControlPtr cp;
{
if (cp == (ControlPtr)0)
{
error("NULL Control Pointer in DisposControl");
return;
}
free(cp->defn);
free(cp);
}
ControlPtr NewButton(wnp, bounds, title, action, data, defalt)
WindowPtr wnp;
rect *bounds;
TEXT *title;
COUNT (* action)(), defalt;
UBYTE *data;
{
extern COUNT ButtonAction();
point pt;
ControlPtr temp;
Button *bt;
COUNT height, width;
if ( (temp = (ControlPtr)malloc(sizeof(Control))) == (ControlPtr)0 )
{
error("Unable to Allocate Control");
ExitToShell();
}
DupRect(bounds, &(temp->bounds));
temp->type = C_BUTTON;
temp->owner = wnp;
temp->next = (ControlPtr)0;
if (action != (UBYTE *)0)
temp->action = action;
else
temp->action = (UBYTE *)0;
temp->handler = ButtonAction;
temp->data = data;
temp->visible = True;
temp->enabled = True;
if ( (bt = (Button *)malloc(sizeof(Button))) == (Button *)0 )
{
error("Unable to Allocate Control");
ExitToShell();
}
pt.X = bounds->Xmin + ((bounds->Xmax - bounds->Xmin) / 2);
pt.Y = bounds->Ymin + ((bounds->Ymax - bounds->Ymin) / 2);
width = StringWidth(title) + (fntWidth * 2);
height = (fntHeight * 2) + 1;
CenterRect(&pt, width, height, &(bt->box));
bt->Xdia = (bt->box.Xmax - bt->box.Xmin) / 3;
bt->Ydia = (bt->box.Ymax - bt->box.Ymin) / 2;
DupRect(&(bt->box), &(temp->bounds));
if (defalt == True)
bt->defalt = True;
else
bt->defalt = False;
temp->defn.bt = bt;
if ( (temp->defn.bt->title = (TEXT *)malloc(strlen(title)+1)) == (TEXT *)0 )
{
error("Unable to Allocate Control");
ExitToShell();
}
strcpy(temp->defn.bt->title,title);
InsertControl(temp,wnp);
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/