DocUnitList Class Reference

Encapsulates units within Camelot. All units (i.e. default and user-defined ones) are an instance of this class. Each document has its own list of units controlled by an instance of DocUnitList within the Document class. Therefore you should get hold of the DocUnitList within the current doc when you want to add/delete/edit/find a unit. More...

#include <units.h>

Inheritance diagram for DocUnitList:

List CCObject SimpleCCObject List of all members.

Public Member Functions

 DocUnitList ()
 Default constructor for a document unit list. Initialises the object.
 ~DocUnitList ()
 Default destructor for a document unit list. Deletes all units in the list.
UnitFindUnit (UnitType ThisUnit)
 Find a unit using its type.
UnitFindUnit (INT32 Index)
 Find a unit by index.
UnitType FindUnitType (const StringBase &Str)
UnitType FindUnitTypeFromToken (const StringBase &Str)
INT32 FindUnitIndex (UnitType ThisUnit)
UnitFindUserUnit (INT32 Index)
UnitFindFirstUserUnit ()
UnitFindNextUserUnit (Unit *pThisUnit)
void UnitHasChanged (UnitType ChangedUnitType)
 This informs the class that the definition of a unit has changed. It ensures that all units that are descendents of the changed unit are recalculated.
BOOL MakeNewUnit (Unit **ppUnit, BOOL Initialise=TRUE)
 Defines all the default units and places them on the list.
BOOL MakeDefaultUnits ()
 This creates the default units for a document. It tries to find the default units via three sources (highest priority first): Disk (Not implemented yet) Bound-in resource (defined in winoil.ini) Hard-wired defaults.
INT32 GetNumUnits ()
 Returns the num units in the list.
UnitReason DeleteUnit (UnitType ThisUnitType)
 Lets you delete a unit from the list.
BOOL HasDescendents (UnitType ThisUnitType)
 Finds out is there are other units that are decendents of this unit, i.e. other units that are based on this unit either directly or indirectly e.g. A->B->C (B is based on A, C is based on B). Both A nd B have decendents. C does not.
BOOL IsDescendent (Unit *pThisUnit, UnitType NewBaseUnitType)
 Checks to see if this unit is a descendent of NewUnitType E.g. A->B->C (B is based on A, and C is based on B) Both B and C are descendents of A.
void RecalcUnit (Unit *pThisUnit)
 Recalculates the number of millipoints in this unit by multiplying the ratio between this and the base unit, with the num millipoints in the base unit. E.g. Recalc Metres : Num Millipoints in metre = Num MP in centimetre * 100; IMPORTANT: This can only recalculate units that are based on another unit. If the unit is not based on another unit (i.e. its base type is NOTYPE) then nothing happens.
BOOL RecalcUnit (Unit *pThisUnit, UnitType ChangedUnitType)
 This recalcs the unit's definition (i.e. the num millipoints that make it up) if it is a descendent of ChangedUnitType.
BOOL SetBaseUnitType (Unit *pThisUnit, UnitType NewBaseUnitType)
 Lets you set that base unit type, dude!
UnitType GetScaleUnits ()
 For getting hold of those pesky scale units.
void SetScaleUnits (UnitType NewUnits)
 Sets the scale units of the object directly.
UnitType GetPageUnits ()
 For getting hold of those pesky page units.
void SetPageUnits (UnitType NewUnits)
 Sets the page units of the object directly.
UnitType GetFontUnits ()
 For getting hold of those pesky font units.
void SetFontUnits (UnitType NewUnits)
 Sets the font units of the object directly.
String_32 GetToken (UnitType)
 Easy way of getting a unit token string. IMPORTANT: This is a general function that can cope with special UnitType values like AUTOMATIC and NOTYPE, i.e. types that don't correspond to an actual instance of Unit.
String_32 GetSpecifier (UnitType)
 Easy way of getting a unit specifier string. If bad UnitType and hence no unit found, returns a blank string.

Static Public Member Functions

static BOOL Init ()
 Initialises the DocUnitList class MUST BE CALLED BEFORE ANY OTHER FUNCTION IN THIS CLASS.
static BOOL Deinit ()
 Deinitialises the doc unit list class.
static DocUnitListGetCurrentDocUnitList ()
 Lets you set that base unit type, dude!

Private Member Functions

BOOL MakeFactoryDefaultUnits ()
 Defines all the default units for a document and places them on the list. Called early on in the document initialisation routines. NOTE: Added some ERROR2 checks so that problems in the default units can be trapped early on rather than a lot later. Should not normally go off unless some of the error checking has problems.
void OutputTrace (char *err, const TCHAR *TokenBuf)
 Helper funtion for the token-reading functions.
BOOL ReadLong (CCLexFile &file, void *pLong, char *err)
 Reads a INT32 value from file and puts it in pLong. If it fails, err is passed to OutputTrace() and FALSE is returned.
BOOL ReadDouble (CCLexFile &file, double *pDouble, char *err)
 Reads a double value from file and puts it in pDouble. If it fails, err is passed to OutputTrace() and FALSE is returned.
BOOL ReadString (CCLexFile &file, StringBase *pStr, char *err)
 Reads a string from file and puts it in pStr. If it fails, err is passed to OutputTrace() and FALSE is returned.
BOOL ReadUnitsFromFile (CCLexFile &file)
 Reads the unit definitions from the given file.
BOOL ReadUnitsFromDisk ()
 Reads the unit definitions from disk (i.e. writable media).
BOOL ReadUnitsFromRes ()
 Reads the unit definitions from the bound in resource.

Static Private Member Functions

static BOOL CheckUnitTypesValid ()
 This checks to see if the UnitType enum and the defines that specify unit IDs match up.

Private Attributes

INT32 NumUnits
INT32 NextUnitNum
INT32 NextUnitType
BOOL DefaultsMade
UnitType ScaleUnits
UnitType PageUnits
UnitType FontUnits
UnitType LastEditedUnit

Detailed Description

Encapsulates units within Camelot. All units (i.e. default and user-defined ones) are an instance of this class. Each document has its own list of units controlled by an instance of DocUnitList within the Document class. Therefore you should get hold of the DocUnitList within the current doc when you want to add/delete/edit/find a unit.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
See also:
DocUnitList,Document

Definition at line 253 of file units.h.


Constructor & Destructor Documentation

DocUnitList::DocUnitList  ) 
 

Default constructor for a document unit list. Initialises the object.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 702 of file units.cpp.

00703 {
00704     NumUnits = 0;
00705     NextUnitNum = 0;
00706     NextUnitType = NUM_DEFAULT_UNIT_TYPES;
00707     DefaultsMade = FALSE;
00708     LastEditedUnit = NOTYPE;
00709 
00710     SetScaleUnits(AUTOMATIC);
00711     SetPageUnits(CENTIMETRES);
00712     SetFontUnits(COMP_POINTS);
00713 }

DocUnitList::~DocUnitList  ) 
 

Default destructor for a document unit list. Deletes all units in the list.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 729 of file units.cpp.

00730 {
00731 /*  Unit* pUnit = (Unit*)this->GetHead();
00732     Unit* pOldUnit;
00733 
00734     while (pUnit != NULL)
00735     {
00736         pOldUnit = pUnit;
00737         pUnit = (Unit*)this->GetNext(pOldUnit);
00738         this->RemoveItem(pOldUnit);
00739         delete pOldUnit;
00740     }
00741 */
00742     ListItem* pItem;
00743 
00744     while ((pItem = this->RemoveHead()) != NULL)
00745         delete pItem;
00746 }


Member Function Documentation

BOOL DocUnitList::CheckUnitTypesValid  )  [static, private]
 

This checks to see if the UnitType enum and the defines that specify unit IDs match up.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/11/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if valid, FALSE if not
UnitType was originally defined as an enum so that it could by used like a normal type.

Later on, internationalisation came along requiring the ability to define the default set of units via an .ini file. This required unit types to be specified using defines so that C preprocessing could be used to make the creation of the built-in .ini file easy to read.

This conflict meant that it could be possible for these values to get out of step. This function goes some way to ensure that they don't.

Definition at line 666 of file units.cpp.

00667 {
00668     BOOL ok = TRUE;
00669 
00670     if (ok) ok = (MILLIMETRES   == UNIT_MILLIMETRES);
00671     if (ok) ok = (CENTIMETRES   == UNIT_CENTIMETRES);
00672     if (ok) ok = (METRES        == UNIT_METRES);
00673     if (ok) ok = (INCHES        == UNIT_INCHES);
00674     if (ok) ok = (FEET          == UNIT_FEET);
00675     if (ok) ok = (YARDS         == UNIT_YARDS);
00676     if (ok) ok = (COMP_POINTS   == UNIT_COMP_POINTS);
00677     if (ok) ok = (PICAS         == UNIT_PICAS);
00678     if (ok) ok = (MILLIPOINTS   == UNIT_MILLIPOINTS);
00679     if (ok) ok = (MILES         == UNIT_MILES);
00680     if (ok) ok = (KILOMETRES    == UNIT_KILOMETRES);
00681     if (ok) ok = (PIXELS        == UNIT_PIXELS);
00682 
00683     ERROR2IF(!ok,FALSE,"One or more enum UnitType values are different to the #define UNIT_ values");
00684 
00685     return (ok);
00686 }

BOOL DocUnitList::Deinit void   )  [static]
 

Deinitialises the doc unit list class.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if deinitialised OK

Definition at line 780 of file units.cpp.

00781 {
00782     return TRUE;
00783 }

UnitReason DocUnitList::DeleteUnit UnitType  ThisUnitType  ) 
 

Lets you delete a unit from the list.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/7/94
Parameters:
ThisUnitType = the type of the unit to delete [INPUTS]
- [OUTPUTS]
Returns:
UNITREASON_OK - The unit has been deleted UNITREASON_HASDESCENDENTS - Other units are based on this unit e.g. cm is based on mm UNITREASON_BEINGUSED - This unit type is being used in the document e.g. page units may use this unit

Errors: Can only be called once per instance. Errors if called again.

Definition at line 865 of file units.cpp.

00866 {
00867     if (HasDescendents(ThisUnitType))
00868         return UNITREASON_HASDESCENDENTS;
00869 
00870     if (PageUnits  == ThisUnitType ||
00871         ScaleUnits == ThisUnitType ||
00872         FontUnits  == ThisUnitType)
00873         return UNITREASON_BEINGUSED;
00874 
00875     // Tell everybody that the unit is about to be deleted)
00876     BROADCAST_TO_ALL(UnitMsg(this,ThisUnitType,UnitMsg::BEFOREDELETE));
00877 
00878     this->RemoveItem(FindUnit(ThisUnitType));
00879     NumUnits--;
00880 
00881     // Tell everybody that the unit is about to be deleted)
00882     BROADCAST_TO_ALL(UnitMsg(this,NOTYPE,UnitMsg::AFTERDELETE));
00883 
00884     return UNITREASON_OK;
00885 }

Unit * DocUnitList::FindFirstUserUnit  ) 
 

Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> Created: 5/7/94 Inputs: - Outputs: - Returns: Ptr to the first user (or non-default) unit in the list NULL is returned if all the units are default ones, or the list is empty Purpose: Lets you get hold of that elusive first user-defined unit. All units are either default or user-defined units.

Definition at line 1112 of file units.cpp.

01113 {
01114     // Get a pointer to the first unit in the list
01115     Unit* pUnit = (Unit*) this->GetHead();
01116 
01117     while (pUnit != NULL)
01118     {
01119         if (!pUnit->IsDefault())
01120             return pUnit;
01121 
01122         pUnit = (Unit*) this->GetNext(pUnit);
01123     }
01124 
01125     return (pUnit);
01126 }

Unit * DocUnitList::FindNextUserUnit Unit pUnit  ) 
 

Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> Created: 5/7/94 Inputs: pUnit = ptr to a unit in the list Outputs: - Returns: Ptr to the first user (or non-default) unit in the list NULL is returned if all the units are default ones, or the list is empty Purpose: Lets you get hold of that elusive first user-defined unit. All units are either default or user-defined units.

Definition at line 1144 of file units.cpp.

01145 {
01146     pUnit = (Unit*) this->GetNext(pUnit);
01147 
01148     while (pUnit != NULL)
01149     {
01150         if (!pUnit->IsDefault())
01151             return pUnit;
01152 
01153         pUnit = (Unit*) this->GetNext(pUnit);
01154     }
01155 
01156     return (pUnit);
01157 }

Unit * DocUnitList::FindUnit INT32  Index  ) 
 

Find a unit by index.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/5/94
Parameters:
Index = indexes directly into the unit list (0 = first unit in list) [INPUTS]
- [OUTPUTS]
Returns:
Ptr to the unit. NULL is returned if not found.

Definition at line 950 of file units.cpp.

00951 {
00952     ERROR3IF(Index < 0,"DocUnitList::FindUnit A negative index? Now there's a novelty");
00953     ERROR3IF(Index >= NumUnits,"DocUnitList::FindUnit Index is greater than num units in system");
00954     if (Index < 0 || Index >= NumUnits)
00955         return NULL;    // Problem, so return quickly
00956 
00957     Unit* pUnit = (Unit*) this->GetHead();
00958 
00959     while ((pUnit != NULL) && (Index > 0))
00960     {
00961         pUnit = (Unit*) this->GetNext(pUnit);
00962         Index--;
00963     }
00964 
00965     ERROR3IF(pUnit == NULL,"DocUnitList::FindUnit Can't find the unit");
00966 
00967     return pUnit;
00968 }

Unit * DocUnitList::FindUnit UnitType  ThisUnit  ) 
 

Find a unit using its type.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
ThisUnit = the unit type of the unit we want [INPUTS]
- [OUTPUTS]
Returns:
Ptr to the unit. NULL is returned if not found.

Definition at line 919 of file units.cpp.

00920 {
00921     Unit* pUnit = (Unit*) this->GetHead();
00922 
00923     while (pUnit != NULL)
00924     {
00925         if (pUnit->GetUnitType() == ThisUnit)
00926             return pUnit;
00927 
00928         pUnit = (Unit*) this->GetNext(pUnit);
00929     }
00930 
00931     ERROR3IF(pUnit == NULL,"Can't find the unit");
00932 
00933     return NULL;
00934 }

INT32 DocUnitList::FindUnitIndex UnitType  ThisUnit  ) 
 

Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> Created: 5/7/94 Inputs: ThisUnit = Type of unit you want Returns: The position of this unit in the list of units. Purpose: Get the position of the unit in the list of units. Used mainly in conjunction with drop-down lists of units

Definition at line 1079 of file units.cpp.

01080 {
01081     Unit* pUnit = (Unit*) this->GetHead();
01082     INT32 Index = 0;
01083 
01084     while ((pUnit != NULL) && (pUnit->GetUnitType() != ThisUnit))
01085     {
01086         pUnit = (Unit*) this->GetNext(pUnit);
01087         Index++;
01088     }
01089 
01090     ERROR3IF(pUnit == NULL,"Can't find the unit");
01091     if (pUnit == NULL) Index = 0;   // Safe for retail builds
01092 
01093     return Index;
01094 }

UnitType DocUnitList::FindUnitType const StringBase Str  ) 
 

Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> Created: 5/7/94 Inputs: Str = string specifying a unit specifier Returns: The type of unit represented by the string passed in Purpose: Identifies the unit by the unit specifier string E.g. 'cm', 'km','mi', 'bananas', etc If the unit is not recognised, NOTYPE is returned SeeAlso: DocUnitList::FindUnitTypeFromToken;

Definition at line 985 of file units.cpp.

00986 {
00987     String_32 Specifier;
00988     String_32 SearchStr;
00989     INT32 len = min(32,Str.Length());
00990     const TCHAR* p1 = (const TCHAR *) Str;
00991     TCHAR* p2 = (TCHAR *) SearchStr;
00992 
00993     // Copy param Str into SearchStr
00994     INT32 i;
00995     for (i=0;i<len;i++)
00996         p2[i] = p1[i];
00997 
00998     p2[i] = 0;              // Terminate
00999     SearchStr.toLower();    // and convert to lower case
01000 
01001     Unit* pUnit = (Unit*) this->GetHead();
01002 
01003     while (pUnit != NULL)
01004     {
01005         Specifier = pUnit->GetSpecifier();
01006         Specifier.toLower();
01007 
01008         if (Specifier == SearchStr)
01009             return (pUnit->GetUnitType());
01010 
01011         pUnit = (Unit*) this->GetNext(pUnit);
01012     }
01013 
01014     return NOTYPE;
01015 }

UnitType DocUnitList::FindUnitTypeFromToken const StringBase Str  ) 
 

Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> Created: 1/9/95 Inputs: Str = string specifying a unit token Returns: The type of unit represented by the string passed in Purpose: Identifies the unit by the unit token string E.g. 'cm', 'km','mi', 'bananas', etc If the unit is not recognised, NOTYPE is returned SeeAlso: DocUnitList::FindUnitType;

Definition at line 1033 of file units.cpp.

01034 {
01035     String_32 Token;
01036     String_32 SearchStr;
01037     INT32 len = min(32,Str.Length());
01038     const TCHAR* p1 = Str;
01039     TCHAR* p2 = SearchStr;
01040 
01041     // Copy param Str into SearchStr
01042     INT32 i;
01043     for (i=0;i<len;i++)
01044         p2[i] = p1[i];
01045 
01046     p2[i] = 0;              // Terminate
01047     SearchStr.toLower();    // and convert to lower case
01048 
01049     Unit* pUnit = (Unit*) this->GetHead();
01050 
01051     while (pUnit != NULL)
01052     {
01053         Token = pUnit->GetToken();
01054         Token.toLower();
01055 
01056         if (Token == SearchStr)
01057             return (pUnit->GetUnitType());
01058 
01059         pUnit = (Unit*) this->GetNext(pUnit);
01060     }
01061 
01062     return NOTYPE;
01063 }

Unit * DocUnitList::FindUserUnit INT32  Index  ) 
 

Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> Created: 7/7/94 Inputs: Index = the index into the list of user-defined units Outputs: - Returns: Ptr to the Index-th user (or non-default) unit in the list NULL is returned if there isn't an Index-th user unit Purpose: Lets you get hold of that elusive Index-th user-defined unit. SeeAlso: FindFirstUserUnit,FindNextUserUnit

Definition at line 1175 of file units.cpp.

01176 {
01177     if (Index < 0) return NULL;
01178 
01179     Unit* pUnit = FindFirstUserUnit();
01180 
01181     while (pUnit != NULL && Index > 0)
01182     {
01183         pUnit = FindNextUserUnit(pUnit);
01184         Index--;
01185     }
01186 
01187     return (pUnit);
01188 }

DocUnitList * DocUnitList::GetCurrentDocUnitList  )  [static]
 

Lets you set that base unit type, dude!

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
Ptr to the doc unit list object of the current doc, or NULL if there isn't one

Definition at line 1431 of file units.cpp.

01432 {
01433     // Get the current doc and return if there is not one
01434     Document* pDoc = Document::GetCurrent();
01435     //ERROR3IF(pDoc==NULL, "Can't find the current doc");
01436     if (pDoc==NULL)
01437         return NULL;
01438 
01439     // get the Unit list and return it
01440 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
01441     ERROR3IF(pDoc->GetDocUnitList()==NULL, "Can't find the doc unit list in the current doc");
01442 #endif
01443     return (pDoc->GetDocUnitList());
01444 }

UnitType DocUnitList::GetFontUnits  ) 
 

For getting hold of those pesky font units.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The font units of this object
See also:
-

Definition at line 1555 of file units.cpp.

01556 {
01557     return (FontUnits);
01558 }

INT32 DocUnitList::GetNumUnits  ) 
 

Returns the num units in the list.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The num defined units in the list

Definition at line 900 of file units.cpp.

00901 {
00902     return NumUnits;
00903 }

UnitType DocUnitList::GetPageUnits  ) 
 

For getting hold of those pesky page units.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The page units of this object
See also:
-

Definition at line 1517 of file units.cpp.

01518 {
01519     return (PageUnits);
01520 }

UnitType DocUnitList::GetScaleUnits  ) 
 

For getting hold of those pesky scale units.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The scale units of this object
See also:
-

Definition at line 1479 of file units.cpp.

01480 {
01481     return ScaleUnits;
01482 }

String_32 DocUnitList::GetSpecifier UnitType  ThisUnitType  ) 
 

Easy way of getting a unit specifier string. If bad UnitType and hence no unit found, returns a blank string.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/95
Parameters:
ThisUnitType = type of unit you want specfier of [INPUTS]
- [OUTPUTS]
Returns:
The Specifier for the unit, i.e. the string that describes the unit e.g. "cm"
See also:
DocUnitList::GetToken; Unit::GetToken

Definition at line 1624 of file units.cpp.

01625 {        
01626     String_32 Str = _T("");
01627     
01628     Unit* pUnit = NULL;
01629     pUnit = FindUnit(ThisUnitType);
01630     if (pUnit)
01631         Str = pUnit->GetSpecifier();
01632 
01633     return Str;
01634 }

String_32 DocUnitList::GetToken UnitType  ThisUnitType  ) 
 

Easy way of getting a unit token string. IMPORTANT: This is a general function that can cope with special UnitType values like AUTOMATIC and NOTYPE, i.e. types that don't correspond to an actual instance of Unit.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
ThisUnitType = type of unit you want token of [INPUTS]
- [OUTPUTS]
Returns:
The token for the unit, i.e. the string that describes the unit e.g. "Centimetres"
See also:
DocUnitList::GetSpecifier; Unit::GetSpecifier;

Definition at line 1578 of file units.cpp.

01579 {        
01580     String_32 Str;
01581     
01582     switch (ThisUnitType)
01583     {
01584         case AUTOMATIC :
01585             Str = String_32(_R(IDS_AUTOMATIC));
01586             break;
01587 
01588         case NOTYPE :
01589             Str = String_32(_R(IDS_NOTYPE));
01590             break;
01591 
01592         default :
01593             {
01594                 Unit * pUnit = NULL;
01595                 pUnit = FindUnit(ThisUnitType);
01596                 if (pUnit)
01597                     Str = pUnit->GetToken();
01598                 else
01599                     Str = String_32(_R(IDS_NOTYPE));    
01600             }
01601             
01602             break;
01603     }
01604 
01605     return Str;
01606 }

BOOL DocUnitList::HasDescendents UnitType  ThisUnitType  ) 
 

Finds out is there are other units that are decendents of this unit, i.e. other units that are based on this unit either directly or indirectly e.g. A->B->C (B is based on A, C is based on B). Both A nd B have decendents. C does not.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/7/94
Parameters:
ThisUnitType = The unit type to check for decendents [INPUTS]
- [OUTPUTS]
Returns:
TRUE - This unit is has one or more descendents FALSE - No other unit is based on this unit

Definition at line 1370 of file units.cpp.

01371 {
01372     Unit* pUnit = (Unit*) this->GetHead();
01373 
01374     while (pUnit != NULL)
01375     {
01376         if (pUnit->GetUnitType() != ThisUnitType)
01377         {
01378             if (IsDescendent(pUnit,ThisUnitType))
01379                 return TRUE;
01380         }
01381         pUnit = (Unit*) this->GetNext(pUnit);
01382     }
01383 
01384     return FALSE;
01385 }

BOOL DocUnitList::Init void   )  [static]
 

Initialises the DocUnitList class MUST BE CALLED BEFORE ANY OTHER FUNCTION IN THIS CLASS.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Reimplemented from SimpleCCObject.

Definition at line 762 of file units.cpp.

00763 {
00764     return CheckUnitTypesValid();
00765 }

BOOL DocUnitList::IsDescendent Unit pThisUnit,
UnitType  NewUnitType
 

Checks to see if this unit is a descendent of NewUnitType E.g. A->B->C (B is based on A, and C is based on B) Both B and C are descendents of A.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
pThisUnit = ptr to unit in question [INPUTS] NewUnitType = the unit type to check against accendency
- [OUTPUTS]
Returns:
TRUE - This unit is a descendent of NewUnitType FALSE - Never heard of the unit guv.

Definition at line 1340 of file units.cpp.

01341 {
01342     if (pThisUnit->GetBaseUnitType() == NOTYPE)
01343         return FALSE;   
01344 
01345     if (pThisUnit->GetBaseUnitType() == NewUnitType)
01346         return TRUE;
01347 
01348     Unit* pBaseUnit = FindUnit(pThisUnit->GetBaseUnitType());
01349 
01350     return (IsDescendent(pBaseUnit,NewUnitType));
01351 }

BOOL DocUnitList::MakeDefaultUnits  ) 
 

This creates the default units for a document. It tries to find the default units via three sources (highest priority first): Disk (Not implemented yet) Bound-in resource (defined in winoil.ini) Hard-wired defaults.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/11/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if OK, FALSE otherwise
See also:
-

Definition at line 1692 of file units.cpp.

01693 {
01694     ERROR3IF(DefaultsMade,"MakeDefaultUnits has already been called for this instance of DocUnitList");
01695     if (DefaultsMade) return TRUE;
01696     
01697     // Ensure the list is empty before proceeding
01698     DeleteAll();
01699 
01700     BOOL ok = TRUE;
01701     ok = ReadUnitsFromDisk();
01702 
01703 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
01704     if (!ok) ok = ReadUnitsFromRes();
01705 #endif
01706 
01707     if (!ok) ok = MakeFactoryDefaultUnits();
01708 
01709     DefaultsMade = ok;
01710 
01711     return (ok);
01712 }

BOOL DocUnitList::MakeFactoryDefaultUnits  )  [private]
 

Defines all the default units for a document and places them on the list. Called early on in the document initialisation routines. NOTE: Added some ERROR2 checks so that problems in the default units can be trapped early on rather than a lot later. Should not normally go off unless some of the error checking has problems.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE - successfully added all default units to the doc unit list FALSE - Can't add all the units to the list (lack of memory most likely)
(Markn 23/11/95 - The name of this function has changed so that it is no longer the routine called by the document initialisation code)

Returns:
Errors: Can only be called once per instance. Errors if called again.

Definition at line 2115 of file units.cpp.

02116 {
02117     // Remove all previously defined units.  We're starting from scratch
02118     DeleteAll();
02119 
02120     Unit* pUnit = NULL;
02121     BOOL ok = TRUE;
02122 
02123     // Default unit - Millimetres
02124     if (MakeNewUnit(&pUnit,FALSE))
02125     {
02126         String_32 TokenStr(_R(IDS_MILLIMETRES));
02127         String_32 SpecifierStr(_R(IDS_MM));
02128 
02129         pUnit->SetDefaultState(TRUE);
02130         pUnit->SetPrefixState(FALSE);
02131         pUnit->SetUnitType(MILLIMETRES);
02132 
02133 
02134         ok =    pUnit->SetToken(TokenStr) &&
02135                 pUnit->SetSpecifier(SpecifierStr) &&
02136                 pUnit->SetBaseUnitType(NOTYPE) &&
02137                 pUnit->SetMillipoints(MM_MP_VAL);
02138              
02139         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad MILLIMETRES");
02140     }
02141     else
02142         return FALSE;
02143 
02144     // Default unit - Centimetres
02145     if (MakeNewUnit(&pUnit,FALSE))
02146     {
02147         String_32 TokenStr(_R(IDS_CENTIMETRES));
02148         String_32 SpecifierStr(_R(IDS_CM));
02149 
02150         pUnit->SetUnitType(CENTIMETRES);
02151         pUnit->SetDefaultState(TRUE);
02152         pUnit->SetPrefixState(FALSE);
02153         pUnit->SetBaseUnitType(MILLIMETRES);
02154 
02155         ok =    pUnit->SetBaseNumerator(10) &&
02156                 pUnit->SetBaseDenominator(1) &&
02157                 pUnit->SetMillipoints(CM_MP_VAL) &&
02158                 pUnit->SetToken(TokenStr) &&
02159                 pUnit->SetSpecifier(SpecifierStr);
02160 
02161         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad CENTIMETRES");
02162     }
02163     else
02164         return FALSE;
02165 
02166     // Default unit - Metres
02167     if (MakeNewUnit(&pUnit,FALSE))
02168     {
02169         String_32 TokenStr(_R(IDS_METRES));
02170         String_32 SpecifierStr(_R(IDS_M));
02171 
02172         pUnit->SetUnitType(METRES);
02173         pUnit->SetDefaultState(TRUE);
02174         pUnit->SetPrefixState(FALSE);
02175         pUnit->SetBaseUnitType(CENTIMETRES);
02176         
02177         ok =    pUnit->SetBaseNumerator(100) &&
02178                 pUnit->SetBaseDenominator(1) &&
02179                 pUnit->SetMillipoints(M_MP_VAL) &&
02180                 pUnit->SetToken(TokenStr) &&
02181                 pUnit->SetSpecifier(SpecifierStr);
02182         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad METRES");
02183     }
02184     else
02185         return FALSE;
02186 
02187     // Default unit - Kilometres
02188     if (MakeNewUnit(&pUnit,FALSE))
02189     {
02190         String_32 TokenStr(_R(IDS_KILOMETRES));
02191         String_32 SpecifierStr(_R(IDS_KM));
02192 
02193         pUnit->SetUnitType(KILOMETRES);
02194         pUnit->SetDefaultState(TRUE);
02195         pUnit->SetPrefixState(FALSE);
02196         pUnit->SetBaseUnitType(METRES);
02197         ok =    pUnit->SetBaseNumerator(1000) &&
02198                 pUnit->SetBaseDenominator(1) &&
02199                 pUnit->SetMillipoints(KM_MP_VAL) &&
02200                 pUnit->SetToken(TokenStr) &&
02201                 pUnit->SetSpecifier(SpecifierStr);
02202         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad KILOMETRES");
02203     }
02204     else
02205         return FALSE;
02206 
02207     // Default unit - Millipoints
02208     if (MakeNewUnit(&pUnit,FALSE))
02209     {
02210         String_32 TokenStr(_R(IDS_MILLIPOINTS));
02211         String_32 SpecifierStr(_R(IDS_MP));
02212 
02213         pUnit->SetUnitType(MILLIPOINTS);
02214         pUnit->SetDefaultState(TRUE);
02215         pUnit->SetPrefixState(FALSE);
02216         pUnit->SetBaseUnitType(NOTYPE);
02217         ok =    pUnit->SetMillipoints(MP_MP_VAL) &&
02218                 pUnit->SetToken(TokenStr) &&
02219                 pUnit->SetSpecifier(SpecifierStr);
02220         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad MILLIPOINTS");
02221     }
02222     else
02223         return FALSE;
02224 
02225     // Default unit - Computer points
02226     if (MakeNewUnit(&pUnit,FALSE))
02227     {
02228         String_32 TokenStr(_R(IDS_COMP_POINTS));
02229         String_32 SpecifierStr(_R(IDS_PT));
02230 
02231         pUnit->SetUnitType(COMP_POINTS);
02232         pUnit->SetDefaultState(TRUE);
02233         pUnit->SetPrefixState(FALSE);
02234         pUnit->SetBaseUnitType(MILLIPOINTS);
02235         ok =    pUnit->SetBaseNumerator(1000) &&
02236                 pUnit->SetBaseDenominator(1) &&
02237                 pUnit->SetMillipoints(PT_MP_VAL) &&
02238                 pUnit->SetToken(TokenStr) &&
02239                 pUnit->SetSpecifier(SpecifierStr);
02240         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad COMP_POINTS");
02241     }
02242     else
02243         return FALSE;
02244 
02245     // Default unit - Picas
02246     if (MakeNewUnit(&pUnit,FALSE))
02247     {
02248         String_32 TokenStr(_R(IDS_PICAS));
02249         String_32 SpecifierStr(_R(IDS_PI));
02250 
02251         pUnit->SetUnitType(PICAS);
02252         pUnit->SetDefaultState(TRUE);
02253         pUnit->SetPrefixState(FALSE);
02254         pUnit->SetBaseUnitType(COMP_POINTS);
02255         ok =    pUnit->SetBaseNumerator(12) &&
02256                 pUnit->SetBaseDenominator(1) &&
02257                 pUnit->SetMillipoints(PI_MP_VAL) &&
02258                 pUnit->SetToken(TokenStr) &&
02259                 pUnit->SetSpecifier(SpecifierStr);
02260         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad PICAS");
02261     }
02262     else
02263         return FALSE;
02264 
02265     // Default unit - Inches
02266     if (MakeNewUnit(&pUnit,FALSE))
02267     {
02268         String_32 TokenStr(_R(IDS_INCHES));
02269         String_32 SpecifierStr(_R(IDS_IN));
02270 
02271         pUnit->SetUnitType(INCHES);
02272         pUnit->SetDefaultState(TRUE);
02273         pUnit->SetPrefixState(FALSE);
02274         pUnit->SetBaseUnitType(PICAS);
02275         ok =    pUnit->SetBaseNumerator(6) &&
02276                 pUnit->SetBaseDenominator(1) &&
02277                 pUnit->SetMillipoints(IN_MP_VAL) &&
02278                 pUnit->SetToken(TokenStr) &&
02279                 pUnit->SetSpecifier(SpecifierStr);
02280         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad INCHES");
02281     }
02282     else
02283         return FALSE;
02284 
02285     // Default unit - Feet
02286     if (MakeNewUnit(&pUnit,FALSE))
02287     {
02288         String_32 TokenStr(_R(IDS_FEET));
02289         String_32 SpecifierStr(_R(IDS_FT));
02290 
02291         pUnit->SetUnitType(FEET);
02292         pUnit->SetDefaultState(TRUE);
02293         pUnit->SetPrefixState(FALSE);
02294         pUnit->SetBaseUnitType(INCHES);
02295         ok =    pUnit->SetBaseNumerator(12) &&
02296                 pUnit->SetBaseDenominator(1) &&
02297                 pUnit->SetMillipoints(FT_MP_VAL) &&
02298                 pUnit->SetToken(TokenStr) &&
02299                 pUnit->SetSpecifier(SpecifierStr);
02300         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad FEET");
02301     }
02302     else
02303         return FALSE;
02304 
02305     // Default unit - Yards
02306     if (MakeNewUnit(&pUnit,FALSE))
02307     {
02308         String_32 TokenStr(_R(IDS_YARDS));
02309         String_32 SpecifierStr(_R(IDS_YD));
02310 
02311         pUnit->SetUnitType(YARDS);
02312         pUnit->SetDefaultState(TRUE);
02313         pUnit->SetPrefixState(FALSE);
02314         pUnit->SetBaseUnitType(FEET);
02315         ok =    pUnit->SetBaseNumerator(3) &&
02316                 pUnit->SetBaseDenominator(1) &&
02317                 pUnit->SetMillipoints(YD_MP_VAL) &&
02318                 pUnit->SetToken(TokenStr) &&
02319                 pUnit->SetSpecifier(SpecifierStr);
02320         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad YARDS");
02321     }
02322     else
02323         return FALSE;
02324 
02325     // Default unit - Miles
02326     if (MakeNewUnit(&pUnit,FALSE))
02327     {
02328         String_32 TokenStr(_R(IDS_MILES));
02329         String_32 SpecifierStr(_R(IDS_MI));
02330 
02331         pUnit->SetUnitType(MILES);
02332         pUnit->SetDefaultState(TRUE);
02333         pUnit->SetPrefixState(FALSE);
02334         pUnit->SetBaseUnitType(YARDS);
02335         ok =    pUnit->SetBaseNumerator(1760) &&
02336                 pUnit->SetBaseDenominator(1) &&
02337                 pUnit->SetMillipoints(MI_MP_VAL) &&
02338                 pUnit->SetToken(TokenStr) &&
02339                 pUnit->SetSpecifier(SpecifierStr);
02340         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad MILES");
02341     }
02342     else
02343         return FALSE;
02344 
02345     // Default unit - Pixels
02346     if (MakeNewUnit(&pUnit,FALSE))
02347     {
02348         String_32 TokenStr(_R(IDS_PIXELS));
02349         String_32 SpecifierStr(_R(IDS_PX));
02350 
02351         pUnit->SetDefaultState(TRUE);
02352         pUnit->SetPrefixState(FALSE);
02353         pUnit->SetUnitType(PIXELS);
02354 
02355 
02356         ok =    pUnit->SetToken(TokenStr) &&
02357                 pUnit->SetSpecifier(SpecifierStr) &&
02358                 pUnit->SetBaseUnitType(NOTYPE) &&
02359                 pUnit->SetMillipoints(PX_MP_VAL);
02360              
02361         ERROR2IF(!ok,FALSE,"DocUnitList::MakeFactoryDefaultUnits bad PIXELS");
02362     }
02363     else
02364         return FALSE;
02365     
02366     return TRUE;
02367 }

BOOL DocUnitList::MakeNewUnit Unit **  ppUnit,