home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
piemnsrc.sit
/
PiePopupXCMD.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-09-14
|
4KB
|
181 lines
/*
* PiePopupXCMD.c
*
* XCMD interface for pie popup menus.
*
*/
#include <MacTypes.h>
#include <MenuMgr.h>
#include <QuickDraw.h>
#include <SetUpA4.h>
#include "HyperXCmd.h"
/*
* Local function prototypes.
*/
pascal void main(XCmdBlockPtr);
int GetLocOfCardWindow(XCmdBlockPtr, Point *);
Handle CopyStrToHand(char *);
long HandleToNum(XCmdBlockPtr, Handle);
void HandleToPstr(Str255, Handle);
char *ToCstr(char *);
char *ToPstr(char *);
#define ERRORFLAG (short) -1
#define USAGE "Usage: put PiePopup(\"Semicolon;separated;menu;list\") into container"
pascal void
main(paramPtr)
XCmdBlockPtr paramPtr;
{
Str255 menuList; /* parsed list of menu items */
int num_menu_items; /* number of menu items to display */
char tempStr[32]; /* scratch area for num to string conversions */
int selection; /* the choice the user made from the popup */
Point cardWindowLoc; /* used to align popup on monitors > 9 inches */
/* LightSpeed C allows global variables to be referenced from A4 */
RememberA0();
SetUpA4();
/* Make sure we were called with only one argument */
if (paramPtr->paramCount != 1) {
paramPtr->returnValue = (Handle) CopyStrToHand(USAGE);
return;
}
/* We need to bias the origin of the popup by the HyperCard's window location */
if ((GetLocOfCardWindow(paramPtr, &cardWindowLoc)) == ERRORFLAG) {
return;
}
/* Buffer the menu list. */
strcpy(menuList, *paramPtr->params[0]);
/*
* Strip the features that are supported by the Mac's menu manager but we ignore.
* These include: line separators, check marks, icons, etc.
*/
num_menu_items = ParseMenuList(menuList);
/* Put up the pie popup menu */
selection = DrawPieMenu(cardWindowLoc, menuList, num_menu_items, 0, (int) geneva, 9);
/* Return the menu selection to HyperCard */
NumToStr(paramPtr, (long) selection, (unsigned char *) tempStr);
paramPtr->returnValue = (Handle) CopyStrToHand(ToCstr((char *) tempStr));
/* We're done, recover original A4 and return */
RestoreA4();
return;
}
/********************************************************************************/
/* The following routines are from the book: XCMD's for HyperCard */
/* by: Gary Bond */
/* ISBN: 0-943518-85-7 */
/********************************************************************************/
int
GetLocOfCardWindow(paramPtr, loc)
XCmdBlockPtr paramPtr;
Point *loc;
{
Handle hndl;
char str[256];
strcpy(str, "item 1 of rect of card window");
hndl = EvalExpr(paramPtr, (StringPtr) CtoPstr(str));
if (paramPtr->result != noErr) {
SysBeep(5);
paramPtr->returnValue = (Handle) CopyStrToHand("Can't get rect of card window");
return((int) ERRORFLAG);
}
if (paramPtr->result == noErr) {
loc->h = HandleToNum(paramPtr, hndl);
DisposHandle(hndl);
strcpy(str, "item 2 of rect of card window");
hndl = EvalExpr(paramPtr, (StringPtr) CtoPstr(str));
if (paramPtr->result == noErr) {
loc->v = HandleToNum(paramPtr, hndl);
DisposHandle(hndl);
return(noErr);
}
}
paramPtr->returnValue = (Handle) CopyStrToHand("Can't get rect of card window");
return ((int) ERRORFLAG);
}
Handle
CopyStrToHand(str)
char *str;
{
Handle newHndl;
newHndl = (Handle) NewHandle((long) strlen(str) + 1);
strcpy((char *) (*newHndl) , str);
return(newHndl);
}
long
HandleToNum(paramPtr, hndl)
XCmdBlockPtr paramPtr;
Handle hndl;
{
char str[32];
long num;
strcpy(str, *hndl);
num = StrToLong(paramPtr, (unsigned char *) ToPstr(str));
return(num);
}
char *
ToCstr(str)
char *str;
{
unsigned char length,i;
length = str[0];
for (i = 0; i < length; ++i)
str[i] = str[i+1];
str[length] = 0;
return(str);
}
char *
ToPstr(str)
char *str;
{
unsigned char length, i;
for (i = 0, length = 0; str[i] != 0; ++i)
++length;
while (i--)
str[i+1] = str[i];
str[0] = length;
return(str);
}