home *** CD-ROM | disk | FTP | other *** search
- # include "TransSkel.h"
-
- # include "FLMaca.h"
- # include "FaceLift.h"
-
-
- typedef enum /* File menu item numbers */
- {
- newMap = 1,
- openMap,
- appendMap,
- saveMap,
- saveMapAs,
- close,
- /* --- */
- reformat = 8,
- reformatAs,
- /* --- */
- quit = 11
- };
-
-
- typedef enum /* Edit menu item numbers */
- {
- undo = 1,
- /* --- */
- cut = 3,
- copy,
- paste,
- clear,
- /* --- */
- new = 8,
- duplicate,
- /* --- */
- sort = 11,
- squish,
- reverse
- };
-
-
- typedef enum /* Options menu items */
- {
- showFormats = 1,
- useFormats,
- addFormats,
- /* --- */
- showBad = 5,
- /* --- */
- stdFontList = 7,
- systemFontList,
- /* --- */
- showFont = 10,
- /* --- */
- getInfo = 12
- };
-
-
- static MenuHandle fileMenu;
- static MenuHandle editMenu;
- static MenuHandle optionsMenu;
-
- static MapSpec clipMSpec; /* clipboard specification */
- static Boolean haveClipSpec = false; /* can't paste until cut/copy */
-
-
- /*
- * Enable or disable menu or menu items, according to the string.
- * First char of string is for entire menu, following chars are
- * for successive items. '0' disables, '1' enables.
- *
- * Return true if the status of the menu itself changed
- * value, i.e., if the menu bar now needs redrawing.
- */
-
- static Boolean
- SetMenuStatus (m, s)
- MenuHandle m;
- StringPtr s;
- {
- int i;
- int menuState;
-
- menuState = ((**m).enableFlags & 1); /* current state of menu */
- for (i = 1; i <= s[0]; ++i)
- {
- if (s[i] == '0')
- DisableItem (m, i - 1);
- else
- EnableItem (m, i - 1);
- }
- return (menuState != ((**m).enableFlags & 1));
- }
-
-
- /*
- * Fix up menus to match window states. There will always be some
- * window.
- *
- * Note the handling of strings. Those that may change need to be
- * CopyString'ed into the string, otherwise the string constant
- * itself will be changed.
- */
-
- void
- FixMenus (void)
- {
- WindowPtr frontWind;
- int theKind;
- int nLines;
- int curLine;
- Boolean drawBar = false;
- Str255 eString;
- StringPtr fStr,
- eStr = eString, /* initial setting, may change */
- oStr;
-
- curLine = mapList->curLine;
- nLines = mapList->nLines;
- frontWind = FrontWindow ();
- theKind = ((WindowPeek) frontWind)->windowKind;
-
- if (frontWind == mapWind)
- {
- fStr = (StringPtr) "\p111111001101";
- oStr = (StringPtr) "\p1111010110101";
- CopyString ("\p11011110110111", eStr); /* points to eString */
-
- if (undoOp == noUndo)
- eStr[undo + 1] = '0';
-
- if (curLine == noLine)
- {
- eStr[cut + 1] = '0';
- eStr[copy + 1] = '0';
- eStr[clear + 1] = '0';
- eStr[duplicate + 1] = '0';
- }
-
- if (haveClipSpec == false)
- eStr[paste + 1] = '0';
-
- if (nLines < 2)
- {
- eStr[sort + 1] = '0';
- eStr[squish + 1] = '0';
- if (nLines == 0)
- eStr[reverse + 1] = '0';
- }
- else if (nLines >= mapList->maxLines)
- {
- if (curLine == noLine)
- eStr[paste + 1] = '0';
- eStr[new + 1] = '0';
- eStr[duplicate + 1] = '0';
- }
- }
- else
- {
- /*
- * Settings for File and Options menus are same for DA's and display
- * windows
- */
- fStr = (StringPtr) "\p100000100001";
- oStr = (StringPtr) "\p1100010000101";
-
- if (theKind < 0) /* DA in front */
- eStr = (StringPtr) "\p11011110000000";
- else /* some display window in front */
- eStr = (StringPtr) "\p0";
- }
-
- drawBar = SetMenuStatus (fileMenu, fStr);
- drawBar |= SetMenuStatus (editMenu, eStr);
- drawBar |= SetMenuStatus (optionsMenu, oStr);
-
- if (drawBar)
- DrawMenuBar ();
-
- }
-
-
- /*
- * Handle "About FaceLift..." selection from Apple menu.
- */
-
- static pascal void
- DoAppleMenu (short item)
- {
- (void) SkelAlert (aboutAlrtNum, SkelDlogFilter (nil, true),
- skelPositionOnParentDevice);
- SkelRmveDlogFilter ();
- }
-
-
- /*
- * Process selection from File menu
- */
-
- static pascal void
- DoFileMenu (short item)
- {
- switch (item)
- {
-
- case newMap:
- if (DiscardChanges ())
- {
- ClobberMap ();
- ClearMapName ();
- undoOp = noUndo;
- mapModified = false;
- }
- break;
-
- case openMap:
- if (DiscardChanges ())
- {
- if (OpenMap ())
- {
- undoOp = noUndo;
- mapModified = false;
- }
- }
- break;
-
- case appendMap:
- if (AddMap ())
- {
- undoOp = noUndo;
- mapModified = true;
- }
- break;
-
- case saveMap:
- if (SaveMap (false))
- mapModified = false;
- break;
-
- case saveMapAs:
- if (SaveMap (true))
- mapModified = false;
- break;
-
- case close:
- SkelClose (FrontWindow ());
- break; /* dispose of it */
-
- case reformat:
- Reformat (true); /* reformat in place */
- break;
-
- case reformatAs:
- Reformat (false); /* reformat to another document */
- break;
-
- case quit:
- if (DiscardChanges ())
- SkelStopEventLoop ();
- break;
- }
- FixMenus ();
- }
-
-
- static void
- DoUndo (void)
- {
- MapSpec tempSpec;
-
- switch (undoOp)
- {
-
- case undoInsert:
- undoOp = undoDelete;
- undoSpec = mapSpec[undoPos];
- DeleteMapping (undoPos);
- break;
-
- case undoDelete:
- undoOp = undoInsert;
- InsertMapping (&undoSpec, undoPos);
- break;
-
- case undoPaste:
- tempSpec = mapSpec[undoPos];
- PasteMapping (&undoSpec, undoPos);
- undoSpec = tempSpec;
- break;
-
- case undoReverse:
- ReverseMap ();
- break;
-
- case undoFieldChg:
- SetMapFieldValue (undoFieldType, undoVal);
- break;
-
- }
- }
-
-
- /*
- * Process selection from Edit menu
- */
-
- static pascal void
- DoEditMenu (short item)
- {
- int curLine;
-
- if (SystemEdit (item - 1))
- return;
-
- curLine = mapList->curLine;
- switch (item)
- {
-
- case undo:
- DoUndo ();
- break;
-
- case cut:
- clipMSpec = mapSpec[curLine];
- undoSpec = clipMSpec;
- undoOp = undoDelete;
- undoPos = curLine;
- haveClipSpec = true;
- DeleteMapping (curLine);
- break;
-
- case copy:
- clipMSpec = mapSpec[curLine];
- haveClipSpec = true;
- break;
-
- case paste:
- if (curLine != noLine)
- {
- undoSpec = mapSpec [curLine];
- undoOp = undoPaste;
- undoPos = curLine;
- PasteMapping (&clipMSpec, curLine);
- }
- else /* no selection; */
- { /* add at end */
- undoOp = undoInsert;
- undoPos = mapList->nLines;
- if (InsertMapping (&clipMSpec, mapList->nLines) == false)
- undoOp = noUndo;
- }
- break;
-
- case clear:
- undoSpec = mapSpec[curLine];
- undoOp = undoDelete;
- undoPos = curLine;
- DeleteMapping (curLine);
- break;
-
- case new:
- NewMapping ();
- undoOp = undoInsert;
- break;
-
- case duplicate:
- DupMapping (curLine); /* changes mapList->curLine */
- undoOp = undoInsert;
- undoPos = mapList->curLine;
- break;
-
- case sort:
- SortMap ();
- undoOp = noUndo; /* can't undo this */
- break;
-
- case squish:
- SquishMap ();
- undoOp = noUndo; /* can't undo this */
- break;
-
- case reverse:
- ReverseMap ();
- undoOp = undoReverse;
- break;
-
- }
-
- if (item != copy)
- mapModified = true;
- FixMenus ();
- }
-
-
- static pascal void
- DoOptionsMenu (short item)
- {
- switch (item)
- {
-
- case showFormats:
- ShowFormats ();
- break;
-
- case useFormats:
- if (DestroyWarn ()
- && AddFormats ("\pUse", true)) /* add formats, clobber map first */
- {
- undoOp = noUndo;
- mapModified = false;
- }
- break;
-
- case addFormats:
- if (AddFormats ("\pAdd", false)) /* add formats, don't clobber map first */
- {
- undoOp = noUndo;
- mapModified = true;
- }
- break;
-
- case showBad:
- showBadFormats = !showBadFormats;
- CheckItem (optionsMenu, showBad, showBadFormats);
- break;
-
- case stdFontList:
- StrFonts (true);
- SetSelectors (mapList->curLine);
- break;
-
- case systemFontList:
- ResourceFonts (true);
- SetSelectors (mapList->curLine);
- break;
-
- case showFont:
- showCurFont = !showCurFont;
- CheckItem (optionsMenu, showFont, showCurFont);
- SetSelectors (mapList->curLine);
- break;
-
- case getInfo:
- HelpWindow ();
- break;
-
- }
- FixMenus ();
- }
-
-
- /*
- * Menu initialization. This must be done *after* the Map window
- * is initialized, because it affects stuff in that window.
- */
-
- void
- SetupMenus (void)
- {
- SkelApple ("\pAbout FaceLift\311", DoAppleMenu); /* \311 = ellipsis */
-
- fileMenu = GetMenu (fileMenuNum);
- (void) SkelMenu (fileMenu, DoFileMenu, nil, false, false);
-
- editMenu = GetMenu (editMenuNum);
- (void) SkelMenu (editMenu, DoEditMenu, nil, false, false);
-
- optionsMenu = GetMenu (optionsMenuNum);
- (void) SkelMenu (optionsMenu, DoOptionsMenu, nil, false, false);
-
- DrawMenuBar ();
-
- showBadFormats = false;
- DoOptionsMenu (showBad);
- showCurFont = false;
- DoOptionsMenu (showFont);
- }
-