home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
macify13.shr
/
macify.hqx
/
Source
/
P
/
Main_Macify.c
next >
Wrap
Text File
|
1991-03-15
|
17KB
|
446 lines
/* Main_Macify */
/* Program name: Main_Macify.c */
/* Function: This is the main module for this program. */
/* History: 3/15/91 Original by Prototyper 3.0 */
#include <stdio.h> /* Standard I/O functions */
#include "PCommonMacify.h" /* Common */
#include "Common_Macify.h" /* Common */
#include "PUtils_Macify.h" /* General Utilities */
#include "Utils_Macify.h" /* General Utilities */
#include "InitExitMacify.h" /* Init, Exit handlers */
#include "EventsMacify.h" /* Extra event handlers */
#include "PD_About_Dialog.h" /* Modal Dialog */
#include "PIMenu_Macify.h" /* Init menus */
#include "PDoMenuMacify.h" /* Handle menus */
Boolean DoIt; /* Flag saying an event is ready */
short code; /* Determine event type */
WindowPtr whichWindow; /* See which window for event */
long mResult; /* Menu list and item selected values */
short theMenu,theItem; /* Menu list and item selected */
/* Prototypes */
/* See if WaitNextEvent is available */
static Boolean WNEIsImplemented(void);
/* Check for user events */
static void Handle_User_Event(void);
/* Handle key strokes */
static void DoKeyEvent(void);
/* Handle a diskette inserted */
static void DoDiskEvent(void);
/* Handle a window being resized */
static void DoGrow(WindowPtr whichWindow);
/* Handle a window being dragged */
static void DoDrag(WindowPtr whichWindow);
/* Handle a window goaway box */
static void DoGoAway(WindowPtr whichWindow);
/* Handle a hit in the window */
static void DoInContent(WindowPtr whichWindow);
/* Handle an update to the window */
static void DoUpdate(void);
/* Handle an activate of the window */
static void DoActivate(void);
/* MAIN entry point */
void main(void);
/* ======================================================= */
/* Routine: WNEIsImplemented */
/* Purpose: See if the MultiFinder trap, WaitNextEvent, is available */
Boolean WNEIsImplemented() /* See if WaitNextEvent is available */
{
#define WNETrapNumber 0xA860 /* The expected trap number */
SysEnvRec theWorld; /* Environment record */
OSErr discardError; /* Error code returned */
Boolean theWNEIsImplemented; /* Value to return */
HasColorQD = FALSE; /* Init to no color QuickDraw */
HasFPU = FALSE; /* Init to no floating point chip */
InTheForeground = TRUE; /* Init to a foreground app */
discardError = SysEnvirons(1, &theWorld); /* Check how old this system is */
if (theWorld.machineType < 0) /* Negative means really old */
theWNEIsImplemented = FALSE; /* Really old ROMs, no WNE possible */
else
{
theWNEIsImplemented = TrapAvailable(WNETrapNumber, ToolTrap);/* See if trap is there */
HasColorQD = theWorld.hasColorQD; /* Flag for Color QuickDraw being available */
HasFPU = theWorld.hasFPU; /* Flag for Floating Point Math Chip being available */
}
return(theWNEIsImplemented);
}
/* ======================================================= */
/* Routine: Handle_User_Event */
/* Purpose: Check for user events */
void Handle_User_Event() /* Check for user events */
{
UserEventRec TheUserEvent; /* The user event */
GetUserEvent(&TheUserEvent); /* Check for any user events */
if (TheUserEvent.ID != UserEvent_None) /* Only do if we have any */
{
switch (TheUserEvent.ID) /* Key off the Event ID */
{
case UserEvent_Open_Window: /* Open a Window or Modeless dialog */
switch (TheUserEvent.ID2) /* Do the appropiate window */
{
case Res_D_About_Dialog:
PD_About_Dialog(); /* Open this modal dialog */
break;
default: /* Handle others */
break;
} /* End of the switch */
break;
case UserEvent_Close_Window: /* Close a Window or Modeless dialog */
break;
default: /* Not standard, must be program specific */
Handle_UserEvent(&TheUserEvent); /* Let program specific handle it */
break;
} /* End of switch */
} /* End of handling a user event */
}
/* ======================================================= */
/* Routine: DoKeyEvent */
/* Purpose: Handle a key pressed */
void DoKeyEvent() /* Handle key presses */
{
short charCode; /* Key code */
char ch; /* Key pressed in Ascii */
long mResult; /* Menu list and item, if a command key */
short theMenu,theItem; /* Menu list and item, if command key */
if (HandleKey(&myEvent)) /* Allow for special key handling */
{
charCode = myEvent.message & charCodeMask; /* Get the character */
ch = (char)charCode; /* Change it to ASCII */
if ((myEvent.modifiers / cmdKey) & 1) /* See if Command key is down */
{
mResult = MenuKey(ch); /* See if a menu selection */
theMenu = HiWord(mResult); /* Get the menu list number */
theItem = LoWord(mResult); /* Get the menu item number */
if (theMenu != 0) /* See if a list was selected */
Handle_My_Menu(theMenu, theItem); /* Do the menu selection */
if (((ch == 'x') || (ch == 'X')) && (theInput != NIL)) /* See if a standard Cut */
TECut(theInput); /* Handle a Cut in a TE area */
if (((ch == 'c') || (ch == 'C')) && (theInput != NIL)) /* See if a standard Copy */
TECopy(theInput); /* Handle a Copy in a TE area */
if (((ch == 'v') || (ch == 'V')) && (theInput != NIL)) /* See if a standard Paste */
TEPaste(theInput); /* Handle a Paste in a TE area */
} /* End of Command key special condition */
else if (theInput != NIL)
TEKey(ch,theInput); /* Place the normal key stroke */
} /* End of Standard keystroke handling */
}
/* ======================================================= */
/* Routine: DoDiskEvent */
/* Purpose: Handle a diskette inserted */
void DoDiskEvent() /* Handle disk inserted */
{
short theError; /* Error returned from mount */
if (HandleDisk(&myEvent)) /* Allow for special disk inserted handling */
{
if (HiWord(myEvent.message) != noErr) /* See if a diskette mount error */
{ /* due to unformatted diskette inserted */
myEvent.where.h = ((screenBits.bounds.right - screenBits.bounds.left) / 2) - (304 / 2);/* Center horz */
myEvent.where.v = ((screenBits.bounds.bottom - screenBits.bounds.top) / 3) - (104 / 2);/* Top 3ed vertically */
InitCursor(); /* Make sure it has an arrow cursor */
theError = DIBadMount(myEvent.where, myEvent.message);/* Let the OS handle the diskette */
}
} /* End of Standard disk inserted handling */
}
/* ======================================================= */
/* Routine: DoGrow */
/* Purpose: Handle a window resize */
void DoGrow(whichWindow) /* Handle a window being resized */
WindowPtr whichWindow;
{
Rect OldRect; /* Window rect before the grow */
Point myPt; /* Point for tracking grow box */
Rect GrowRect; /* Set the grow bounds */
long mResult; /* Result from the grow */
if (whichWindow != NIL) /* See if we have a legal window */
{
SetPort(whichWindow); /* Get ready to draw in this window */
myPt = myEvent.where; /* Get mouse position */
GlobalToLocal(&myPt); /* Make it relative */
OldRect = whichWindow->portRect; /* Save the rect before resizing */
SetRect(&GrowRect, 4, 4, (screenBits.bounds.right - screenBits.bounds.left)-4, (screenBits.bounds.bottom - screenBits.bounds.top) - 4);/* l,t,r,b */
mResult = GrowWindow(whichWindow, myEvent.where, &GrowRect);/* Grow it */
SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE);/* Resize to result */
SetPort(whichWindow); /* Get ready to draw in this window */
myPt.h = whichWindow->portRect.right - whichWindow->portRect.left; /* Local right edge */
myPt.v = whichWindow->portRect.bottom - whichWindow->portRect.top; /* Local bottom edge */
SetRect(&GrowRect, 0, myPt.v - 15, myPt.h + 15, myPt.v + 15); /* Position for horz scrollbar area */
EraseRect(&GrowRect); /* Erase old area */
InvalRect(&GrowRect); /* Flag us to update it */
SetRect(&GrowRect, myPt.h - 15, 0, myPt.h + 15, myPt.v + 15); /* Position for vert scrollbar area */
EraseRect(&GrowRect); /* Erase old area */
InvalRect(&GrowRect); /* Flag us to update it */
DrawGrowIcon(whichWindow); /* Draw the grow Icon again */
} /* End of (WhichWindow <> nil) */
}
/* ======================================================= */
/* Routine: DoDrag */
/* Purpose: Drag a window around */
void DoDrag( whichWindow) /* Handle a window being dragged */
WindowPtr whichWindow;
{
Rect OldRect; /* Window rect before the drag */
Rect tempRect; /* temporary rect */
OldRect = whichWindow->portRect; /* Save the rect before resizing */
tempRect = screenBits.bounds; /* Get screen area, l,t,r,b, drag area */
SetRect(&tempRect,tempRect.left+4,tempRect.top+4,tempRect.right-4,tempRect.bottom - 4);
DragWindow(whichWindow, myEvent.where, &tempRect); /* Drag the window */
}
/* ======================================================= */
/* Routine: DoGoAway */
/* Purpose: Close a window */
void DoGoAway( whichWindow) /* Handle a window goaway box */
WindowPtr whichWindow;
{
Rect OldRect; /* Window rect before the drag */
Rect tempRect; /* temporary rect */
if (TrackGoAway(whichWindow,myEvent.where) == TRUE) /* See if mouse released in GoAway box */
{ /* Handle the GoAway */
} /* End of TrackGoAway */
}
/* ======================================================= */
/* Routine: DoInContent */
/* Purpose: Pressed in the content area */
void DoInContent( whichWindow) /* Handle a hit in the window */
WindowPtr whichWindow;
{
if (whichWindow != FrontWindow()) /* See if already selected or not, in front if selected */
SelectWindow(whichWindow); /* Select this window to make it active */
else /* If already in front the already selected */
{ /* Handle the press in the content */
SetPort(whichWindow); /* Get ready to draw in this window */
} /* End of else */
}
/* ======================================================= */
/* Routine: DoUpdate */
/* Purpose: Got an update event */
void DoUpdate() /* Handle an update to the window */
{
WindowPtr whichWindow; /* See which window for event */
whichWindow = (WindowPtr)myEvent.message; /* Get the window the update is for */
BeginUpdate(whichWindow); /* Set the clipping to the update area */
EndUpdate(whichWindow); /* Return to normal clipping area */
}
/* ======================================================= */
/* Routine: DoActivate */
/* Purpose: Got an activate or deactivate event */
void DoActivate() /* Handle an activate of the window */
{
Boolean Do_An_Activate; /* Flag to pass */
WindowPtr whichWindow; /* See which window for event */
whichWindow = (WindowPtr)myEvent.message; /* Get the window the update is for */
Do_An_Activate = ((myEvent.modifiers & 0x0001) != 0); /* Make sure it is Activate and not DeActivate */
}
/* ======================================================= */
void main() /* Start of main body */
{
MoreMasters(); /* This reserves space for more handles */
MaxApplZone(); /* Give us room for memory allocation */
InitGraf(&thePort); /* Quickdraw Init */
InitFonts(); /* Font manager init */
InitWindows(); /* Window manager init */
InitMenus(); /* Menu manager init */
TEInit(); /* Text edit init */
InitDialogs(NIL); /* Dialog manager */
FlushEvents ( everyEvent , 0 ); /* Clear out all events */
InitCursor(); /* Make an arrow cursor */
doneFlag = FALSE; /* Do not exit program yet */
Init_My_Menus(); /* Initialize menu bar */
theInput = NIL; /* Init to no text edit selection active */
SleepValue = 40; /* Set sleep value */
WNE = WNEIsImplemented(); /* See if WaitNextEvent is available */
UserEventList = NIL; /* No user events yet */
ApplInit_Macify(); /* Handle extra program initialization */
I_PD_About_Dialog(); /* Initialize the modal dialog globals */
do /* Start of main event loop */
{
ApplLoop_Macify(); /* Let into main loop */
Handle_User_Event(); /* Check for user events */
if (theInput != NIL) /* See if a TE is active */
TEIdle(theInput); /* Blink the cursor if everything is ok */
if (WNE == TRUE) /* See if do the MultiFinder way */
DoIt = WaitNextEvent(everyEvent, &myEvent, SleepValue, NIL);/* Wait for an event */
else
{
SystemTask(); /* For support of desk accessories */
DoIt = GetNextEvent(everyEvent, &myEvent); /* See if an event is ready */
}
ApplEvent_Macify(&DoIt,&myEvent); /* Let us at the event first */
if (DoIt == TRUE) /* If event then... */
{ /* Start handling the event */
switch (myEvent.what) /* Decide type of event */
{
case mouseDown : /* Mouse button pressed */
code = FindWindow(myEvent.where, &whichWindow);/* Get which window the event happened in */
switch (code) /* Decide type of event again */
{
case inMenuBar : /* In the menubar */
mResult = MenuSelect(myEvent.where); /* Do menu selection */
theMenu = HiWord(mResult); /* Get the menu list number */
theItem = LoWord(mResult); /* Get the menu list item number */
Handle_My_Menu( theMenu, theItem); /* Handle the menu */
break; /* End of inMenuBar */
case inDrag : /* In window drag area */
DoDrag(whichWindow); /* Go drag the window */
break; /* End of InDrag */
case inGrow : /* In window grow area */
DoGrow(whichWindow); /* Handle the growing */
break; /* End of inGrow */
case inGoAway : /* In window goaway area */
DoGoAway(whichWindow); /* Handle the goaway button */
break; /* End of inGoAway */
case inContent : /* In window contents */
DoInContent(whichWindow); /* Handle the hit inside a window */
break; /* End of inContent */
case inSysWindow : /* See if a DA selectio */
SystemClick(&myEvent, whichWindow); /* Let other programs in */
break; /* End of inSysWindow */
default: /* Handle others */
break; /* End of otherwise */
} /* End of code case */
break; /* End of MouseDown */
case keyDown: /* Handle key inputs */
case autoKey: /* and auto repeats */
DoKeyEvent(); /* Get the key and handle it */
break; /* End of otherwise */
case updateEvt : /* Update event for a window */
DoUpdate(); /* Handle the update */
break; /* End of otherwise */
case diskEvt : /* Disk inserted event */
DoDiskEvent(); /* Handle a disk event */
break; /* End of otherwise */
case activateEvt : /* Window activated event */
DoActivate(); /* Handle the activation */
break; /* End of otherwise */
default: /* Used for debugging, to see what other events are coming in */
break; /* End of otherwise */
} /* End of case */
} /* end of GetNextEvent */
} /* end of while */
while (doneFlag == FALSE); /* End of the event loop */
ApplExit_Macify(); /* Handle extra program termination code */
} /* end of main */