home *** CD-ROM | disk | FTP | other *** search
- # include "TransSkel.h"
-
- # include "MakeWrite.h"
-
-
-
- typedef enum /* File menu item numbers */
- {
- newMap = 1,
- openMap,
- appendMap,
- saveMap,
- saveMapAs,
- close,
- /* --- */
- makeWrite = 8,
- /* --- */
- quit = 10
- };
-
-
- typedef enum /* Edit menu item numbers */
- {
- undo = 1,
- /* --- */
- cut = 3,
- copy,
- paste,
- clear,
- /* --- */
- new = 8,
- duplicate,
- /* --- */
- sort = 11,
- squish
- };
-
-
- typedef enum /* Special menu items */
- {
- stdFontList = 1,
- systemFontList,
- /* --- */
- pgraphStyle = 4,
- /* --- */
- conflicts = 6,
- /* --- */
- getInfo = 8,
- /* --- */
- debugOption = 10
- };
-
-
- static MenuHandle fileMenu;
- static MenuHandle editMenu;
- static MenuHandle specialMenu;
-
- static MapSpec clipMSpec; /* clipboard specification */
-
-
- /*
- * 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 (MenuHandle m, StringPtr s)
- {
- short i;
- short 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.
- *
- * This routine is stupid about setting cut&paste types of items.
- */
-
- void
- FixMenus (void)
- {
- WindowPtr frontWind;
- short theKind;
- short nLines;
- short 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 = "\p11111100101";
- oStr = "\p11101010101";
- CopyString ("\p1101111011011", eStr); /* points to eString */
-
- if (undoOp == noUndo)
- eStr[undo + 1] = '0';
-
- if (curLine == noLine)
- {
- cpMarker = false; /* no line - *can't* apply to marker */
- eStr[cut + 1] = '0';
- eStr[copy + 1] = '0';
- eStr[clear + 1] = '0';
- eStr[duplicate + 1] = '0';
- if (havePasteMSpec == false)
- eStr[paste + 1] = '0';
- }
- else if (cpMarker == false) /* line but c/p applies to map */
- {
- if (havePasteMSpec == false)
- eStr[paste + 1] = '0';
- }
-
- if (nLines < 2)
- {
- eStr[sort + 1] = '0';
- eStr[squish + 1] = '0';
- }
- else if (nLines >= mapList->maxLines)
- {
- if (cpMarker == false && curLine == noLine)
- eStr[paste + 1] = '0';
- eStr[new + 1] = '0';
- eStr[duplicate + 1] = '0';
- }
-
- /*
- * now figure out how to set the cut/paste indicators. They're
- * blank if there's no current line and can't paste. Else set
- * according to the current state of indicator flag.
- */
-
- if (curLine == noLine && eStr[paste+1] == '0')
- BlankCPCtrls ();
- else
- SetCPMarker (cpMarker);
- }
- else
- {
- /*
- * Settings for File and Special menus are same for DA's and display
- * windows
- */
- fStr = "\p10000010001";
- oStr = "\p10001000101";
-
- if (theKind < 0) /* DA in front */
- eStr = "\p1101111000000";
- else /* some display window in front */
- eStr = "\p0";
-
- BlankCPCtrls ();
- }
-
- drawBar = SetMenuStatus (fileMenu, fStr);
- drawBar |= SetMenuStatus (editMenu, eStr);
- drawBar |= SetMenuStatus (specialMenu, oStr);
-
- if (drawBar)
- DrawMenuBar ();
- }
-
-
- /*
- * Handle "About MakeWrite..." selection from Apple menu.
- */
-
- static pascal void
- DoAbout (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;
-
- case makeWrite:
- TextToWrite ();
- break;
-
- case quit:
- if (DiscardChanges ())
- SkelStopEventLoop ();
- break;
- }
- FixMenus ();
- }
-
-
- static void
- DoUndo (void)
- {
- MapSpec tempSpec;
- StringHandle hStr;
- Str255 tempStr;
- short selStart, selEnd;
- Boolean tmpCPMarker;
-
- tmpCPMarker = cpMarker;
- cpMarker = undoCPMarker;
- undoCPMarker = tmpCPMarker;
-
- InitMSpec (&tempSpec);
- switch (undoOp)
- {
-
- case undoInsert:
- undoOp = undoDelete;
- CopyMSpec (&mapSpec[undoPos], &undoMSpec);
- DeleteMapping (undoPos);
- break;
-
- case undoDelete:
- undoOp = undoInsert;
- InsertMapping (&undoMSpec, undoPos);
- break;
-
- case undoPaste:
- CopyMSpec (&mapSpec[undoPos], &tempSpec);
- PasteMapping (&undoMSpec, undoPos);
- CopyMSpec (&tempSpec, &undoMSpec);
- break;
-
- case undoFieldChg:
- SetMapFieldValue (undoFieldType, undoVal);
- break;
-
- case undoTyping:
- case undoMarkerOp:
- undoOp = undoMarkerOp;
- CopyMSpec (&mapSpec[undoPos], &tempSpec);
- CopyMSpec (&undoMSpec, &mapSpec[undoPos]);
- CopyMSpec (&tempSpec, &undoMSpec);
-
- hStr = mapSpec[undoPos].mark;
- HLock ((Handle) hStr);
- PasteField (mapList, undoPos, markField, *hStr);
- HUnlock ((Handle) hStr);
- SetSelectors (undoPos);
- break;
-
- }
- TermMSpec (&tempSpec);
- }
-
-
- /*
- * Process selection from Edit menu
- */
-
- static pascal void
- DoEditMenu (short item)
- {
- short curLine;
-
- if (SystemEdit (item - 1))
- return;
-
- if (EditMarker (item))
- return; /* it was a marker edit operation */
-
- curLine = mapList->curLine;
- switch (item)
- {
-
- case undo:
- DoUndo ();
- break;
-
- case cut:
- undoCPMarker = cpMarker;
- CopyMSpec (&mapSpec[curLine], &clipMSpec);
- CopyMSpec (&clipMSpec, &undoMSpec);
- undoOp = undoDelete;
- undoPos = curLine;
- havePasteMSpec = true;
- DeleteMapping (curLine);
- break;
-
- case copy:
- CopyMSpec (&mapSpec[curLine], &clipMSpec);
- havePasteMSpec = true;
- break;
-
- case paste:
- undoCPMarker = cpMarker;
- if (curLine != noLine)
- {
- CopyMSpec (&mapSpec[curLine], &undoMSpec);
- 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:
- undoCPMarker = cpMarker;
- CopyMSpec (&mapSpec[curLine], &undoMSpec);
- undoOp = undoDelete;
- undoPos = curLine;
- DeleteMapping (curLine);
- break;
-
- case new:
- undoCPMarker = cpMarker;
- NewMapping ();
- /*SetCPMarker (true);*/
- undoOp = undoInsert;
- break;
-
- case duplicate:
- undoCPMarker = cpMarker;
- DupMapping (curLine); /* changes mapList->curLine */
- SetCPMarker (true);
- 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;
-
- }
-
- if (item != copy)
- mapModified = true;
- FixMenus ();
- }
-
-
- static pascal void
- DoSpecialMenu (short item)
- {
- switch (item)
- {
-
- case stdFontList:
- StrFonts (true);
- SetSelectors (mapList->curLine);
- break;
-
- case systemFontList:
- ResourceFonts (true);
- SetSelectors (mapList->curLine);
- break;
-
- case pgraphStyle:
- DoParaDialog ();
- break;
-
- case conflicts:
- FindConflicts ();
- break;
-
- case getInfo:
- HelpWindow ();
- break;
-
- # ifdef debug
- case debugOption:
- debugOut = !debugOut;
- CheckItem (specialMenu, debugOption, debugOut);
- break;
- # endif
-
- }
- FixMenus ();
- }
-
-
- /*
- * Menu initialization.
- */
-
- void
- SetupMenus (void)
- {
- SkelApple ("\pAbout MakeWrite\311", DoAbout); /* \311 = ellipsis */
-
- fileMenu = GetMenu (fileMenuNum);
- SkelMenu (fileMenu, DoFileMenu, nil, false, false);
-
- editMenu = GetMenu (editMenuNum);
- SkelMenu (editMenu, DoEditMenu, nil, false, false);
-
- specialMenu = GetMenu (specialMenuNum);
- # ifdef debug
- AppendMenu (specialMenu, "\p(-;Debug Output");
- # endif
- SkelMenu (specialMenu, DoSpecialMenu, nil, false, false);
- DrawMenuBar ();
-
- InitMSpec (&undoMSpec);
- InitMSpec (&clipMSpec);
- }
-