home *** CD-ROM | disk | FTP | other *** search
- # include "ListEdit.h"
- # include "FLMaca.h"
- # include "FLMapInfo.h"
- # include "FaceLift.h"
-
-
- /*
- * Check two MapSpecs for equality.
- */
-
- Boolean
- EqualMSpec (MapSpec *m1, MapSpec *m2)
- {
- return (CompareCSpec (&m1->inFmt, &m2->inFmt) == 0
- && CompareCSpec (&m1->outFmt, &m2->outFmt) == 0);
- }
-
-
- /*
- * Check whether a MapSpec already exists in the map
- */
-
- Boolean
- StatMSpec (MapSpec *mSpec)
- {
- int i;
-
- for (i = 0; i < mapList->nLines; ++i)
- {
- if (EqualMSpec (mSpec, &mapSpec[i]))
- 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.
- */
-
- void
- SetMapFields (LineHandle hLine, MapStr *mStr)
- {
- FieldHandle hField;
-
- hField = hLine;
- SetFieldStr (hField, mStr->inStr.markStr);
- hField = NextField (hField);
- SetFieldStr (hField, mStr->inStr.fontStr);
- hField = NextField (hField);
- SetFieldStr (hField, mStr->inStr.sizeStr);
- hField = NextField (hField);
- SetFieldStr (hField, mStr->inStr.styleStr);
- hField = NextField (hField);
- SetFieldStr (hField, mStr->outStr.markStr);
- hField = NextField (hField);
- SetFieldStr (hField, mStr->outStr.fontStr);
- hField = NextField (hField);
- SetFieldStr (hField, mStr->outStr.sizeStr);
- hField = NextField (hField);
- SetFieldStr (hField, mStr->outStr.styleStr);
- }
-
-
- /*
- * Select a mapping
- */
-
- void
- SelectMapping (int lineNo)
- {
- SelectLine (mapList, lineNo); /* sets mapList->curLine */
- if (lineNo != noLine)
- ScrollToLine (mapList, lineNo);
- SetSelectors (lineNo);
- }
-
-
- /*
- * Insert a new mapping, making it mapping n. This takes care
- * of both the array of mappings, and the list of text representations
- * of the mappings. It also sets up lots of pointers to various
- * parts of the current mapping.
- *
- * 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, int n)
- {
- MapStr mStr;
- LineHandle hLine;
- int 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;
- 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 (won't have been attached!) */
- }
- else
- {
- for (i = nLines; i > n; --i)
- {
- mapSpec[i] = mapSpec[i-1]; /* move specs to make room */
- }
- mapSpec[n] = *mSpec; /* add new one */
-
- SelectMapping (n);
- 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.
- */
-
- void
- NewMapping (void)
- {
- MapSpec mSpec;
-
- ClearMSpec (&mSpec);
- (void) InsertMapping (&mSpec, mapList->nLines);
- }
-
-
- /*
- * Duplicate the currently selected mapping and add right after the
- * selection.
- */
-
- void
- DupMapping (int 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, int n)
- {
- MapStr mStr;
- int curLine;
-
- curLine = mapList->curLine;
- mapSpec[curLine] = *mSpec;
- MSpecToMStr (mSpec, &mStr);
- SetMapFields (ListLine (mapList, curLine), &mStr);
- DrawLine (mapList, curLine);
- SetSelectors (curLine); /* set selection controls */
- }
-
-
- /*
- * Clobber the n-th mapping.
- */
-
- void
- DeleteMapping (int n)
- {
- int i;
-
- for (i = n; i < mapList->nLines; ++i)
- {
- mapSpec[i] = mapSpec[i+1]; /* copy specs */
- }
- DeleteLine (mapList, n);
- SelectMapping (noLine);
- ScrollToLine (mapList, n);
- }
-
-
- /*
- * Clobber entire map.
- */
-
- void
- ClobberMap (void)
- {
- SelectMapping (noLine);
- ResetList (mapList);
- }
-
-
-
- /*
- * 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)
- {
- int i, j, curLine;
- MapSpec tmpSpec;
- LineHandle tmpLine;
-
- curLine = mapList->curLine;
- for (i = 0; i < mapList->nLines - 1; ++i)
- {
- for (j = i; j < mapList->nLines; ++j)
- {
- if (CompareCSpec (&mapSpec[i].inFmt, &mapSpec[j].inFmt) > 0)
- {
- tmpSpec = mapSpec[i];
- mapSpec[i] = mapSpec[j];
- mapSpec[j] = tmpSpec;
- 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);
- }
-
-
- /*
- * 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)
- {
- int i, j;
-
- for (i = 0; i < mapList->nLines; ++i)
- {
- j = i + 1;
- while (j < mapList->nLines)
- {
- if (EqualMSpec (&mapSpec[i], &mapSpec[j]))
- DeleteMapping (j);
- else
- ++j;
- }
- }
- }
-
-
- /*
- * Reverse input and output sides of map.
- */
-
- void
- ReverseMap (void)
- {
- short i;
- ConvSpec cSpec;
- MapSpec *mSpec;
- MapStr mStr;
-
- for (i = 0; i < mapList->nLines; ++i)
- {
- mSpec = &mapSpec[i];
- cSpec = mSpec->inFmt;
- mSpec->inFmt = mSpec->outFmt;
- mSpec->outFmt = cSpec;
- mSpec->isInput = !mSpec->isInput;
- MSpecToMStr (mSpec, &mStr); /* convert specs to strings */
- SetMapFields (ListLine (mapList, i), &mStr);
- }
- DrawListText (mapList);
- SetSelectors (mapList->curLine);
- }
-