home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
luschsrc.sit
/
dialog.c
< prev
next >
Wrap
Text File
|
1990-05-23
|
4KB
|
231 lines
/********************************************************************************
* dialog.c
*
* Dialog Management Package
*
* Written by Paco Xander Nathan
* ⌐1990, Motorola Inc. Public domain source code.
********************************************************************************/
#include "applic.h"
#include "window.h"
#include "dialog.h"
#include "ascii.h"
#include "about.h"
#include "test.h"
#include "error.h"
/* External Data Structures
*/
DialogPtr
dPtrAbout = NULL,
dPtrAnal = NULL;
/* Local Function Prototypes
*/
#ifdef PROTOTYPES
#endif
/* Generate a random number between zero and the given ceiling number
*/
short
DlogRandom (ceiling)
register short ceiling;
{
register short result;
if ((result = Random()) < 0)
result = -result;
if (ceiling)
result %= ceiling;
return result;
}
/* Set the coordinates for centering SFGet/Put and other standard alerts
*/
void
DlogOrigin (alertID, thePoint)
register short alertID;
register Point *thePoint;
{
;
}
/* Filter alert and modal dialog events to keep the background events processed
* and outline the default button in a special way
*/
pascal Boolean
DlogModalEvent (theDialog, theEvent, itemNum)
register DialogPtr theDialog;
register EventRecord *theEvent;
register short *itemNum;
{
register Boolean filtered = FALSE;
register char theChar;
Rect bounds;
short kind;
long finalTick;
Handle theItem;
/* Now take care of the important, boring stuff...
*/
if (theEvent->what == keyDown) {
theChar = (char) BitAnd(theEvent->message, charCodeMask);
if ((theChar == asciiReturn) || (theChar == asciiEnter)) {
GetDItem(theDialog, 1, &kind, &theItem, &bounds);
HiliteControl((ControlHandle) theItem, 1);
Delay(3, &finalTick);
*itemNum = 1;
filtered = TRUE;
}
}
return filtered;
}
/* Create the specified dialog and center it
*/
pascal DialogPtr
DlogOpenModal (dialogID)
register short dialogID;
{
register DialogPtr theDialog = NULL;
/* Create and error check the new modal dialog
*/
if (theDialog = GetNewDialog(dialogID, NULL, -1L)) {
/* Center and display
*/
WindCenter(theDialog);
WindZapPort(theDialog, TRUE);
BringToFront(theDialog);
/* Make sure we have an arrow cursor before returning
*/
InitCursor();
}
return theDialog;
}
/* Dispose the specified modal dialog
*/
void
DlogCloseModal (theDialog, trips)
register DialogPtr theDialog;
register Boolean trips;
{
if (theDialog) {
if (trips)
WindZapPort(theDialog, FALSE);
DisposDialog(theDialog);
}
}
/* Short cut to set a control item value in an active dialog list
*/
void
DlogSetItem (theDialog, itemNum, value)
register DialogPtr theDialog;
register short itemNum;
register short value;
{
short kind;
Handle theItem;
Rect bounds;
GetDItem(theDialog, itemNum, &kind, &theItem, &bounds);
SetCtlValue((ControlHandle) theItem, value);
}
/* Modeless dialog event handler
*/
void
DlogModelessEvent (theEvent)
register EventRecord *theEvent;
{
DialogPtr theDialog;
short dialogID, itemNum, kind;
Handle theItem;
Rect bounds;
if (DialogSelect(theEvent, &theDialog, &itemNum)) {
if (theDialog == dPtrAbout)
AboutEvent(itemNum);
}
}
/* Create a modeless dialog window; dialog window template should have proc type 4
* and needs to have a goAwayBox
*/
pascal DialogPtr
DlogWindow (dlogID)
register short dlogID;
{
register DialogPtr theDialog;
register InfoPtr infoPtr;
GrafPtr savePort;
/* Create the dialog
*/
if (theDialog = GetNewDialog(dlogID, NULL, -1L)) {
GetPort(&savePort);
SetPort(theDialog);
WindCenter(theDialog);
WindZapPort(theDialog, TRUE);
/* Create the window info record
*/
if (infoPtr = (InfoPtr) ErrNewPtr(sizeof(InfoRecord))) {
infoPtr->kind = wkDlog;
infoPtr->active = infoPtr->dirty = FALSE;
infoPtr->named = TRUE;
infoPtr->item.dlog = theDialog;
SetWRefCon(theDialog, (long) infoPtr);
}
else {
DisposDialog(theDialog);
theDialog = NULL;
}
SetPort(savePort);
}
return theDialog;
}
/* Dispose a modeless dialog window
*/
void
DlogDispose (theWindow)
register WindowPtr theWindow;
{
register InfoPtr infoPtr = (InfoPtr) GetWRefCon(theWindow);
register DialogPtr theDialog = infoPtr->item.dlog;
if (theDialog == dPtrAbout)
dPtrAbout = NULL;
else if (theDialog == dPtrAnal)
dPtrAnal = NULL;
DisposPtr(infoPtr);
DisposDialog(theDialog);
}