home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
luschsrc.sit
/
context.c
< prev
next >
Wrap
Text File
|
1990-05-23
|
5KB
|
205 lines
/********************************************************************************
* context.c
*
* Context Management Package
*
* Written by Paco Xander Nathan
* ⌐1990, Motorola Inc. Public domain source code.
********************************************************************************/
#include "applic.h"
#include "window.h"
#include "dialog.h"
#include "context.h"
#include "edit.h"
#include "document.h"
#include "ascii.h"
#include "about.h"
#include "noise.h"
#include "help.h"
#include "test.h"
#include "gnosis.h"
/* External Data Structures
*/
MenuHandle
menu[MAXMENU];
/* Enable/Disable a menu item... should have been in the MenuMgr Toolbox
*/
void
ContMenuItem (theMenu, theItem, flag)
register MenuHandle theMenu;
register short theItem;
register short flag;
{
if (flag)
EnableItem(theMenu, theItem);
else
DisableItem(theMenu, theItem);
}
/* Enable and disable menus based on the current state of the application. This is
* called just before MenuSelect() or MenuKey(), so it can set up everything for the
* Menu Manager. Since these are the times when the user can select menu items,
* you only need to enable/disable items then.
*/
void
ContAdjMenu ()
{
register Boolean closeFlag, viewFlag;
/* Adjust the file menu options
*/
closeFlag = ((WindowPeek) wPtrGnos)->visible;
viewFlag = ((WindowPeek) dPtrAnal)->visible;
ContMenuItem(menu[fileM], fmNew, !closeFlag);
ContMenuItem(menu[fileM], fmOpen, !closeFlag);
ContMenuItem(menu[fileM], fmClose, closeFlag);
ContMenuItem(menu[fileM], fmSave, !testUser && closeFlag);
ContMenuItem(menu[fileM], fmSaveAs, !testUser && closeFlag);
ContMenuItem(menu[fileM], fmRevert, closeFlag);
ContMenuItem(menu[fileM], fmPrint, viewFlag);
/* Adjust the test menu options
*/
SetItemMark(menu[testM], testUserMode, testUser ? asciiCheckMark : asciiNoMark);
ContMenuItem(menu[testM], testUserMode, testUser);
SetItemMark(menu[testM], testBorderless, testBCraig ? asciiNoMark : asciiCheckMark);
SetItemMark(menu[testM], testInColor, testJDavis ? asciiNoMark : asciiCheckMark);
ContMenuItem(menu[testM], testInColor, laMachine.hasColor);
/* Adjust the prognosis menu options
*/
ContMenuItem(menu[gnosM], gnosNew, !testUser && closeFlag);
ContMenuItem(menu[gnosM], gnosDelete, !testUser && gnosList.open);
ContMenuItem(menu[gnosM], gnosAnalyze, viewFlag);
ContMenuItem(menu[gnosM], gnosLearn, !testUser && closeFlag && viewFlag);
ContMenuItem(menu[gnosM], gnosRecall, closeFlag && viewFlag);
}
/* Change the cursor's shape, depending on its position. This also calculates
* a region that includes the cursor for WaitNextEvent()
*/
void
ContAdjCurs (thePoint, theRgn)
register Point thePoint;
register RgnHandle theRgn;
{
register WindowPtr theWindow = FrontWindow();
register InfoPtr infoPtr = (InfoPtr) GetWRefCon(theWindow);
register RgnHandle arrowRgn;
register RgnHandle iBeamRgn;
Rect iBeamRect;
GrafPtr savePort;
GetPort(&savePort);
SetPort(theWindow);
if (!laMachine.inBackground && !WindIsDA(theWindow)) {
/* calculate regions for different cursor shapes, start arrowRgn wide-open
*/
arrowRgn = NewRgn();
iBeamRgn = NewRgn();
SetRectRgn(arrowRgn, -32768, -32768, 32767, 32767);
/* calculate iBeamRgn
*/
if (WindIsApp(theWindow) && (infoPtr->kind == wkText)) {
iBeamRect = (*(infoPtr->item.text.teHdl))->viewRect;
LocalToGlobal(&TopLeft(iBeamRect));
LocalToGlobal(&BotRight(iBeamRect));
RectRgn(iBeamRgn, &iBeamRect);
}
/* subtract other regions from arrowRgn
*/
DiffRgn(arrowRgn, iBeamRgn, arrowRgn);
/* change the cursor and the region parameter
*/
if (PtInRgn(thePoint, iBeamRgn)) {
SetCursor(*GetCursor(iBeamCursor));
CopyRgn(iBeamRgn, theRgn);
}
else {
SetCursor(&arrow);
CopyRgn(arrowRgn, theRgn);
}
/* get rid of local regions
*/
DisposeRgn(arrowRgn);
DisposeRgn(iBeamRgn);
}
SetPort(savePort);
}
/* Route the various menu and keyboard commands to the appropriate modules
*/
short
ContDispatch (theResult)
register long theResult;
{
register WindowPtr theWindow = FrontWindow();
register short theItem = LoWord(theResult);
Str255 itemName;
GrafPtr savePort;
switch(HiWord(theResult)) {
case appleM + RSRCBASE:
switch (theItem) {
case appleAbout:
NoisePlay(noisePaco);
AboutAppl();
break;
case appleHelp:
HelpAppl();
break;
default:
GetItem(menu[appleM], theItem, &itemName);
GetPort(&savePort);
OpenDeskAcc(&itemName);
SetPort(savePort);
break;
}
break;
case fileM + RSRCBASE:
DocMenu(theItem);
break;
case editM + RSRCBASE:
if (!SystemEdit(theItem - 1))
EditMenu(theItem);
break;
case testM + RSRCBASE:
TestMenu(theItem);
break;
case gnosM + RSRCBASE:
GnosMenu(theItem);
break;
default:
break;
}
HiliteMenu(FALSE);
return TRUE;
}