Category : C Source Code
Archive   : PUBWIW_C.ZIP
Filename : MENU.C

 
Output of file : MENU.C contained in archive : PUBWIW_C.ZIP
#include
#include
#include


#include "GRconst.h"
#include "GRports.h" /* MetaWINDOW header files */
#include "GRextrn.h"

#include "menu.h"
#include "window.h"

#define GRwait 0 /* disable GRquery wait */

#define SwRight 1
#define SwLeft 4

#define MAX_MENU 13

extern COUNT GrafixCard,CommPort; /* Device Dependant Info */

extern COUNT fntWidth, fntHeight; /* System Font Dimensions */


extern COUNT ExitToShell(), _sysBack;

LOCAL UWORD _menuPen = 0, _disabPen = 7, _menuBack=0x0F;

extern metaPort *thePort;

extern WindowPtr _TopWindow, /* Pointer to Front or Top Window */
_LastWindow; /* Pointer to Last or Bottom Window */



extern rect scrnRect; /* Screen Rectangle - full screen */


rect _menuRect; /* Menu Rectangle - first line of screen Rect */
PDMenu _menuBar[MAX_MENU]; /* Array of PullDown Menu Items */
COUNT _menuCnt = 0; /* Number of PullDown Menu Items */

mapArray def_map = {0,4,0,0,2,0,0,0}; /* Cursor display map - mouse driver */
mapArray cross_map = {2,2,2,2,2,2,2,2};
mapArray hand_map = {4,4,4,4,4,4,4,4};

/*---------------------------------------------*
* Low Level Initialization of User Interface *
*---------------------------------------------*/
void _init()
{

InitGrafix(-GrafixCard);

SetDisplay(GrafPg0);

GetPort(&thePort); /* Get Default Port Info */

if ( thePort->txFont != (char *)0 )
{
fntHeight = thePort->txFont->chHeight;
if ( (fntHeight < 5) || (fntHeight > 21) )
fntHeight = 14;

fntWidth = thePort->txFont->chWidth;
if ( (fntWidth < 5) || (fntWidth > 21) )
fntWidth = 9;
}

ScreenRect(&scrnRect);

InitMouse(CommPort);

PenNormal();

/* Define cursor mapping */
CursorMap(&def_map);

ShowCursor();

}



void DrawMenuBar()
{
COUNT i;
penState ps;
metaPort savePort;

GetPenState(&ps);

GetPort(&savePort);

SetPort(thePort);

PenMode(Replace);

PenColor(_menuBack);

ProtectRect(&_menuRect);

PaintRect(&_menuRect);

PenMode(Invert);

FrameRect(&_menuRect);

PenMode(Replace);

PenColor(_menuPen);

BackColor(_menuBack);

for(i=0; i<_menuCnt; i++)
{
MoveTo(_menuBar[i].bbox.Xmin+2, _menuBar[i].bbox.Ymax-3);
DrawString(_menuBar[i].name);
}

ProtectOff();

SetPenState(&ps);

SetPort(savePort);
}


void MenuColor(pen,back)
COUNT pen,back;
{
_menuPen = pen;
_menuBack = back;
}


void InitMenus()
{
extern rect deskTop;

DupRect(&scrnRect,&_menuRect);

_menuRect.Ymax = fntHeight + 4;

deskTop.Ymin = _menuRect.Ymax + 2;

DrawMenuBar();
}


BOOL MenuEvent(X,Y)
COORD X,Y;
{
metaPort *savePort;
point mousePnt;
COUNT i, ret_val;

mousePnt.X = X;
mousePnt.Y = Y;

GetPort(&savePort);

SetPort(thePort);

if (PtInRect(&mousePnt,&_menuRect) == False)
{
SetPort(savePort);
return(False);
}

for(i=0; i<_menuCnt; i++)
{
if (PtInRect(&mousePnt,&(_menuBar[i].bbox)) == True)
{
HideCursor();
InvertRect(&(_menuBar[i].bbox));

ret_val = PopUpMenu
(
_menuBar[i].items,
_menuBar[i].bbox.Xmin,
_menuBar[i].bbox.Ymax+2
);

InvertRect(&(_menuBar[i].bbox));
ShowCursor();
SetPort(savePort);
return(ret_val);
}
}

SetPort(savePort);

return(False);
}



COUNT ExitToShell()
{
ClearText();
SetDisplay(TextPg0);
StopMouse();
StopEvent();
exit(0);
}



AppendMenu(name,keyCode,items)
TEXT *name;
UWORD keyCode;
MenuItem *items;
{
COORD Xoffset;

if (_menuCnt == 0 )
_menuBar[_menuCnt].bbox.Xmin = fntWidth + 6;
else
_menuBar[_menuCnt].bbox.Xmin = _menuBar[_menuCnt-1].bbox.Xmax +
fntWidth + 6;

_menuBar[_menuCnt].bbox.Xmax = _menuBar[_menuCnt].bbox.Xmin +
StringWidth(name)+2;
_menuBar[_menuCnt].bbox.Ymin = _menuRect.Ymin+2;
_menuBar[_menuCnt].bbox.Ymax = _menuRect.Ymax-2;

if ( (_menuBar[_menuCnt].name = (TEXT *)malloc(strlen(name)+1)) == 0L )
{
error("Allocation Error in AppendMenu");
exit(1);
}
strcpy(_menuBar[_menuCnt].name,name);

_menuBar[_menuCnt].keyCode = keyCode;

_menuBar[_menuCnt].items = items;

_menuCnt++;
}

wait()
{
int i;

for(i=0; i<12000; i++)
;
}


COUNT PopUpMenu(ITEMS,mouseX,mouseY)
MenuItem *ITEMS;
int mouseX,mouseY;
{
metaPort *savePort;
penState thisState;
image *saveImage;
long imageBytes;
rect menuRect, thisRect;
int widMax;
int itemCnt, thisWid, thisItem, delta;
int i, x, y, oldY, button, done;

TrackCursor(False);

EventQueue(False);

GetPenState(&thisState);

GetPort(&savePort);

widMax = 0;

itemCnt = 0;

/* Compute Number of Menu Items and Maximum Width */
while (ITEMS[itemCnt].type != M_LAST)
{
if ( (thisWid = strlen(ITEMS[itemCnt].title)) > widMax)
widMax = thisWid;
itemCnt++;
}

if ( mouseX < (scrnRect.Xmin + 6) )
mouseX = scrnRect.Xmin + 6;

if ( mouseY < (scrnRect.Ymin + 10) )
mouseY = scrnRect.Ymin + 10;

if ( (mouseX + ((++widMax*fntWidth) + 4)) > scrnRect.Xmax )
mouseX = scrnRect.Xmax - ((widMax*fntWidth) + 8);

if ( (mouseY + itemCnt*fntHeight + 6) > scrnRect.Ymax )
mouseY = scrnRect.Ymax - ((itemCnt*fntHeight) + 6);

menuRect.Xmin = mouseX;
menuRect.Ymin = mouseY;
menuRect.Xmax = mouseX + (widMax * fntWidth) + 4;
menuRect.Ymax = mouseY + (itemCnt * fntHeight) + 4;

ProtectRect(&menuRect);

imageBytes = ImageSize(&menuRect);
saveImage = (image *)malloc( (unsigned int) imageBytes );
ReadImage(&menuRect,saveImage);

PenColor(_menuPen);

BackColor(_menuBack);

EraseRect(&(menuRect));

PenMode(Replace);

FrameRect(&(menuRect));

HideCursor();

for (i=0; i {
MoveTo(menuRect.Xmin+10, menuRect.Ymin + (i*fntHeight) + fntHeight);
if (ITEMS[i].enabled == True)
PenColor(_menuPen);
else
PenColor(_disabPen);
DrawString(ITEMS[i].title);
}

PenMode(Invert);

thisItem = 1;

oldY = menuRect.Ymin;

thisRect.Xmin = menuRect.Xmin+3;
thisRect.Xmax = menuRect.Xmax-3;
thisRect.Ymin = menuRect.Ymin+3;
thisRect.Ymax = menuRect.Ymin+16;

InvertRect(&thisRect);


while (1)
{
button = 0;

ReadMouse(&x,&y,&button);

if (button == SwLeft)
{
PenMode(Replace);

WriteImage(&menuRect, saveImage);

free(saveImage);

SetPenState(&thisState);

MoveCursor(mouseX,mouseY);

ShowCursor();

TrackCursor(True);

EventQueue(True);

ProtectOff();

SetPort(savePort);

return(M_LAST);
}

if (button == SwRight)
{
if (ITEMS[thisItem-1].PFI != M_NULL)
{
(*(ITEMS[thisItem-1].PFI))();
}

if (ITEMS[thisItem-1].subMenu == (MenuItem *)0)
{
InvertRect(&thisRect);
wait();
InvertRect(&thisRect);
wait();
InvertRect(&thisRect);
wait();
InvertRect(&thisRect);
wait();

InvertRect(&thisRect);

SetPenState(&thisState);

MoveCursor(mouseX,mouseY);

ShowCursor();

TrackCursor(True);

EventQueue(True);

PenMode(Replace);

WriteImage(&menuRect, saveImage);

free(saveImage);

ProtectOff();

SetPort(savePort);

return(thisItem);
}
else
{
PopUpMenu
(
ITEMS[thisItem-1].subMenu,
thisRect.Xmax+6,
thisRect.Ymin
);
}

}

delta = oldY - y;

if ( iabs(delta) > 12)
{
oldY = y;
}
else
continue;

if (delta > 0)
{
if (--thisItem < 1)
{
thisItem = 1;
}
else
{

InvertRect(&thisRect);
thisRect.Ymin -= fntHeight;
thisRect.Ymax -= fntHeight;
InvertRect(&thisRect);

}
}
else
{
if (++thisItem > itemCnt)
{
thisItem = itemCnt;
}
else
{
InvertRect(&thisRect);
thisRect.Ymin += fntHeight;
thisRect.Ymax += fntHeight;
InvertRect(&thisRect);
}
}



} /* while (1) */

}





  3 Responses to “Category : C Source Code
Archive   : PUBWIW_C.ZIP
Filename : MENU.C

  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/