home *** CD-ROM | disk | FTP | other *** search
- # include "MakeWrite.h"
-
-
- /*
- * Check whether a MapSpec already exists in the map
- */
-
- Boolean
- StatMSpec (MapSpec *mSpec)
- {
- short i;
-
- for (i = 0; i < mapList->nLines; ++i)
- {
- if (CompareMSpec (mSpec, &mapSpec[i]) == 0)
- return (true);
- }
- return (false);
- }
-
-
- /*
- * Insert the text of all the fields for the given map list line.
- *
- * This routines relies implicitly on the ordering of fields
- * within a map line.
- */
-
- static void
- SetMapFields (LineHandle hLine, MapStr *mStr)
- {
- FieldHandle hField;
-
- hField = hLine;
- SetFieldStr (hField, mStr->markStr);
- hField = NextField (hField);
- SetFieldStr (hField, mStr->fontStr);
- hField = NextField (hField);
- SetFieldStr (hField, mStr->sizeStr);
- hField = NextField (hField);
- SetFieldStr (hField, mStr->styleStr);
- }
-
-
- /*
- * Select a mapping
- */
-
- void
- SelectMapping (short lineNo)
- {
- SelectLine (mapList, lineNo);
- if (lineNo != noLine)
- ScrollToLine (mapList, lineNo);
- SetSelectors (lineNo);
- }
-
-
- /*
- * Insert a new mapping, making it mapping n. This takes care
- * of both the specification array, and the list of text representations
- * of the mappings.
- *
- * Note that there's no explicit count of mappings. Use the count
- * in the LineList corresponding to the mapping array is used.
- */
-
- Boolean
- InsertMapping (MapSpec *mSpec, short n)
- {
- MapStr mStr;
- LineHandle hLine;
- short i, nLines;
- Str255 s;
-
- if (mapList->nLines < mapList->maxLines)
- {
- /*
- * Convert mapping specification into string form and put the strings
- * into a new line to be inserted into the line list.
- *
- * Then make room for the new mapping in spec array and insert it.
- */
-
- nLines = mapList->nLines; /* save; InsertLine changes it */
- MSpecToMStr (mSpec, &mStr); /* convert specs to strings */
- hLine = NewLine (mapList->nFields);
- SetMapFields (hLine, &mStr);
- if (InsertLine (mapList, hLine, n) == false)
- {
- /*DisposeLine (hLine);*/ /* THIS IS WRONG */
- }
- else
- {
- /*
- * Move specs around to make room, then add the new one
- * in the empty slot.
- */
- for (i = nLines; i > n; --i)
- {
- CopyMSpec (&mapSpec[i-1], &mapSpec[i]);
- }
- CopyMSpec (mSpec, &mapSpec[n]);
- /*mapSpec[n].selStart = 0;
- mapSpec[n].selEnd = 32767;*/
- SelectMapping (n);
- /*SetCPMarker (true);*/
- return (true);
- }
- }
- NumToString ((long) mapList->maxLines, s);
- Message3 ("\pMap is full (", s, "\p lines). Can't add anything to it.");
- return (false);
- }
-
-
- /*
- * Add a new, blank, mapping to the end of the list.
- * This should be different - the handle should be copied in InsertMapping.
- */
-
- void
- NewMapping (void)
- {
- MapSpec mSpec;
-
- InitMSpec (&mSpec);
- ClearMSpec (&mSpec);
- (void) InsertMapping (&mSpec, mapList->nLines);
- TermMSpec (&mSpec);
- }
-
-
- /*
- * Duplicate the currently selected mapping and add right after the
- * selection.
- */
-
- void
- DupMapping (short n)
- {
- (void) InsertMapping (&mapSpec[n], n+1);
- }
-
-
- /*
- * Replace the currently selected mapping with the given one.
- * (It's assumed that there *is* one selected.)
- */
-
- void
- PasteMapping (MapSpec *mSpec, short n)
- {
- MapStr mStr;
- short curLine;
-
- curLine = mapList->curLine;
- CopyMSpec (mSpec, &mapSpec[curLine]);
- MSpecToMStr (mSpec, &mStr);
- SetMapFields (ListLine (mapList, curLine), &mStr);
- DrawLine (mapList, curLine);
- SetSelectors (curLine); /* set selection controls */
- }
-
-
- /*
- * Clobber the n-th mapping.
- */
-
- void
- DeleteMapping (short n)
- {
- short i;
-
- for (i = n; i < mapList->nLines; ++i)
- {
- CopyMSpec (&mapSpec[i+1], &mapSpec[i]); /* copy specs */
- }
- DeleteLine (mapList, n);
- SelectMapping (noLine);
- ScrollToLine (mapList, n);
- }
-
-
- /*
- * Clobber entire map.
- */
-
- void
- ClobberMap (void)
- {
- SelectMapping (noLine);
- ResetList (mapList);
- InitParaStyle ();
- }
-
-
-
- /*
- * Sort the map specifications on the input format values. Make
- * sure to keep track of the current spec and redraw the text
- * and controls properly when done.
- */
-
- void
- SortMap (void)
- {
- short i, j, curLine;
- LineHandle tmpLine;
- MapSpec tmpSpec;
-
- InitMSpec (&tmpSpec);
- curLine = mapList->curLine;
- for (i = 0; i < mapList->nLines - 1; ++i)
- {
- for (j = i; j < mapList->nLines; ++j)
- {
- if (CompareMSpec (&mapSpec[i], &mapSpec[j]) > 0)
- {
- CopyMSpec (&mapSpec[i], &tmpSpec);
- CopyMSpec (&mapSpec[j], &mapSpec[i]);
- CopyMSpec (&tmpSpec, &mapSpec[j]);
- tmpLine = ListLine (mapList, i);
- ListLine (mapList, i) = ListLine (mapList, j);
- ListLine (mapList, j) = tmpLine;
- if (curLine == i)
- curLine = j;
- else if (curLine == j)
- curLine = i;
- }
- }
- }
- DrawListText (mapList);
- SelectMapping (curLine);
- TermMSpec (&tmpSpec);
- }
-
-
- /*
- * Eliminate duplicates in the map. The loops must explicitly
- * test mapList->nLines, not a variable set equal to that before
- * the loops, since DeleteMapping causes mapList->nLines to change.
- */
-
- void
- SquishMap (void)
- {
- short i, j;
-
- for (i = 0; i < mapList->nLines; ++i)
- {
- j = i + 1;
- while (j < mapList->nLines)
- {
- if (CompareMSpec (&mapSpec[i], &mapSpec[j]) == 0)
- DeleteMapping (j);
- else
- ++j;
- }
- }
- }
-