#include <units.h>
Inheritance diagram for DocUnitList:
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. | |
Unit * | FindUnit (UnitType ThisUnit) |
Find a unit using its type. | |
Unit * | FindUnit (INT32 Index) |
Find a unit by index. | |
UnitType | FindUnitType (const StringBase &Str) |
UnitType | FindUnitTypeFromToken (const StringBase &Str) |
INT32 | FindUnitIndex (UnitType ThisUnit) |
Unit * | FindUserUnit (INT32 Index) |
Unit * | FindFirstUserUnit () |
Unit * | FindNextUserUnit (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 DocUnitList * | GetCurrentDocUnitList () |
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 |
Definition at line 253 of file units.h.
|
Default constructor for a document unit list. Initialises the object.
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 }
|
|
Default destructor for a document unit list. Deletes all units in the list.
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 }
|
|
This checks to see if the UnitType enum and the defines that specify unit IDs match up.
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 }
|
|
Deinitialises the doc unit list class.
Definition at line 780 of file units.cpp. 00781 { 00782 return TRUE; 00783 }
|
|
Lets you delete a unit from the list.
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 }
|
|
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 }
|
|
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 }
|
|
Find a unit by index.
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 }
|
|
Find a unit using its type.
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 }
|
|
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 }
|
|
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 }
|
|
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 }
|
|
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 }
|
|
Lets you set that base unit type, dude!
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 }
|
|
For getting hold of those pesky font units.
Definition at line 1555 of file units.cpp. 01556 { 01557 return (FontUnits); 01558 }
|
|
Returns the num units in the list.
Definition at line 900 of file units.cpp. 00901 { 00902 return NumUnits; 00903 }
|
|
For getting hold of those pesky page units.
Definition at line 1517 of file units.cpp. 01518 { 01519 return (PageUnits); 01520 }
|
|
For getting hold of those pesky scale units.
Definition at line 1479 of file units.cpp. 01480 { 01481 return ScaleUnits; 01482 }
|
|
Easy way of getting a unit specifier string. If bad UnitType and hence no unit found, returns a blank string.
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 }
|
|
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.
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 }
|
|
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.
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 }
|
|
Initialises the DocUnitList class MUST BE CALLED BEFORE ANY OTHER FUNCTION IN THIS CLASS.
Reimplemented from SimpleCCObject. Definition at line 762 of file units.cpp. 00763 { 00764 return CheckUnitTypesValid(); 00765 }
|
|
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.
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 }
|
|
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.
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 }
|
|
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.
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 }
|
|
Defines all the default units and places them on the list.
Definition at line 802 of file units.cpp. 00803 { 00804 Unit* pUnit = new Unit; 00805 if (pUnit == NULL) return FALSE; 00806 00807 if (Initialise) 00808 { 00809 String_32 num(_R(IDS_UNITS_NEW_UNIT_ABBREV)); 00810 String_32 abbrev(_R(IDS_UNITS_NEW_UNIT_ABBREV)); 00811 00812 INT32 i; 00813 for( i = 0;i<(NextUnitNum / 20) && i<10;i++) 00814 num += abbrev; 00815 00816 ((LPTSTR) num)[i] += ((NextUnitNum++) % 20); 00817 00818 String_32 TokenStr(_R(IDS_UNITS_NEW_UNIT_NAME)); 00819 String_32 SpecifierStr(_R(IDS_UNITS_NEW_UNIT_SPECIFIER)); 00820 TokenStr += num; 00821 SpecifierStr += num; 00822 00823 pUnit->SetUnitType((UnitType) NextUnitType++); 00824 pUnit->SetDefaultState(FALSE); 00825 pUnit->SetPrefixState(FALSE); 00826 pUnit->SetBaseUnitType(MILLIMETRES); 00827 pUnit->SetBaseNumerator(10); 00828 pUnit->SetBaseDenominator(1); 00829 pUnit->SetMillipoints(CM_MP_VAL); 00830 pUnit->SetToken(TokenStr); 00831 pUnit->SetSpecifier(SpecifierStr); 00832 } 00833 00834 this->AddTail(pUnit); 00835 *ppUnit = pUnit; 00836 NumUnits++; 00837 00838 if (Initialise) 00839 { 00840 // Tell everybody that the unit has been created 00841 BROADCAST_TO_ALL(UnitMsg(this,pUnit->GetUnitType(),UnitMsg::NEW)); 00842 } 00843 00844 return TRUE; 00845 }
|
|
Helper funtion for the token-reading functions.
Definition at line 1788 of file units.cpp. 01789 { 01790 #if 0 != wxUSE_UNICODE 01791 size_t cch = camMbstowcs( NULL, err, 0 ) + 1; 01792 wchar_t *pwsz = (wchar_t *)alloca( cch * 2 ); 01793 camMbstowcs( pwsz, err, cch ); 01794 01795 TRACE( pwsz ); 01796 #else 01797 TRACE( err ); 01798 #endif 01799 01800 TRACE( _T(", but got %s\n"), TokenBuf ); 01801 }
|
|
Reads a double value from file and puts it in pDouble. If it fails, err is passed to OutputTrace() and FALSE is returned.
Definition at line 1854 of file units.cpp. 01855 { 01856 ERROR2IF(pDouble == NULL,FALSE,"pDouble == NULL"); 01857 01858 const TCHAR *TokenBuf = file.GetTokenBuf(); 01859 BOOL ok = file.GetSimpleToken(); 01860 if (ok) 01861 ok = ( camSscanf( TokenBuf, _T("%lg"), pDouble ) == 1 ); 01862 01863 if (!ok) 01864 OutputTrace( err, TokenBuf ); 01865 01866 return ok; 01867 }
|
|
Reads a INT32 value from file and puts it in pLong. If it fails, err is passed to OutputTrace() and FALSE is returned.
Definition at line 1822 of file units.cpp. 01823 { 01824 ERROR2IF(pLong == NULL,FALSE,"pLong == NULL"); 01825 01826 const TCHAR *TokenBuf = file.GetTokenBuf(); 01827 BOOL ok = file.GetSimpleToken(); 01828 if (ok) 01829 ok = ( camSscanf( TokenBuf, _T("%li"), pLong ) == 1 ); 01830 01831 if (!ok) 01832 OutputTrace( err, TokenBuf ); 01833 01834 return ok; 01835 }
|
|
Reads a string from file and puts it in pStr. If it fails, err is passed to OutputTrace() and FALSE is returned.
Definition at line 1886 of file units.cpp. 01887 { 01888 ERROR2IF(pStr == NULL,FALSE,"pStr == NULL"); 01889 01890 const TCHAR *TokenBuf = file.GetTokenBuf(); 01891 BOOL ok = file.GetSimpleToken(); 01892 if (ok) 01893 { 01894 pStr->Empty(); 01895 INT32 len = pStr->MaxLength(); 01896 if (len > 0) 01897 { 01898 TCHAR *pBuf = *pStr; 01899 INT32 i; 01900 for ( i = 0; TBYTE(TokenBuf[i]) > TBYTE(' ') && i < len; i++ ) 01901 pBuf[i] = TokenBuf[i]; 01902 01903 pBuf[i] = 0; 01904 } 01905 } 01906 01907 if (!ok) OutputTrace(err,TokenBuf); 01908 01909 return ok; 01910 }
|
|
Reads the unit definitions from disk (i.e. writable media).
Definition at line 1728 of file units.cpp. 01729 { 01730 // Not yet implemented 01731 01732 return FALSE; 01733 }
|
|
Reads the unit definitions from the given file.
Definition at line 1926 of file units.cpp. 01927 { 01928 BOOL finished = FALSE; 01929 BOOL ok;; 01930 01931 // Initialise lexing routines, and aspects of the lexer 01932 ok = file.InitLexer(); 01933 file.SetDelimiters("\r\n"); // Set token delimiting characters 01934 file.SetCommentMarker(';'); // Set comment marker char 01935 file.SetWhitespace(" \t"); // Set whitespace chars 01936 file.SetStringDelimiters("\"\""); // Set string delimiters 01937 01938 UnTokenIndex Token; 01939 const TCHAR *TokenBuf = file.GetTokenBuf(); // Token buffer remains constant until lexer deinitialisation 01940 01941 while (ok && !finished) 01942 { 01943 // Grab a token 01944 ok = file.GetSimpleToken(); 01945 01946 // Look the token up in our table 01947 Token = FindToken( TokenBuf ); 01948 01949 switch (Token) 01950 { 01951 case TOKEN_UNIT: 01952 { 01953 Unit* pUnit; 01954 // Defining a unit. Firstly make a new blank unit to put the definition in 01955 if (MakeNewUnit(&pUnit,FALSE)) 01956 { 01957 // We have a blank unit, now read its definition fields 01958 01959 double NumMillipoints; 01960 String_32 NameStr; 01961 String_32 SpecifierStr; 01962 UnitType TheUnitType,BaseUnitType; 01963 BOOL Prefix; 01964 double BaseNumerator,BaseDenominator; 01965 01966 // Read in all the fields of the unit definition 01967 if (ok) ok = ReadLong( file,&TheUnitType, "Expected the unit's type"); 01968 if (ok) ok = ReadString(file,&NameStr, "Expected the unit's name"); 01969 if (ok) ok = ReadString(file,&SpecifierStr, "Expected the unit's specifier"); 01970 if (ok) ok = ReadDouble(file,&NumMillipoints, "Expected the unit's millipoint value"); 01971 if (ok) ok = ReadLong( file,&Prefix, "Expected the unit's prefix flag"); 01972 if (ok) ok = ReadLong( file,&BaseUnitType, "Expected the unit's base type"); 01973 if (ok) ok = ReadDouble(file,&BaseNumerator, "Expected the unit's base numerator"); 01974 if (ok) ok = ReadDouble(file,&BaseDenominator, "Expected the unit's base denominator"); 01975 01976 if (ok) 01977 { 01978 // If it's based on another unit, get a pointer to the base unit 01979 Unit* pBaseUnit = NULL; 01980 if (BaseUnitType != UNIT_NOTYPE) 01981 pBaseUnit = FindUnit(BaseUnitType); 01982 01983 // If no base unit AND no millipoint value, error 01984 if (pBaseUnit == NULL && NumMillipoints <= 0.0) 01985 { 01986 TRACE( _T("Base unit not found AND the number of millipoints <= 0.0\n")); 01987 TRACE( _T("Either the base unit is not yet defined, or the millipoint value is wrong\n")); 01988 ok= FALSE; 01989 } 01990 else 01991 { 01992 if (pBaseUnit != NULL) 01993 { 01994 // If Millipoint value is based on another, calculate it 01995 // (error if denominator is 0 - we don't want to divide by this value) 01996 if (BaseDenominator != 0.0) 01997 NumMillipoints = (pBaseUnit->GetMillipoints()*BaseNumerator)/BaseDenominator; 01998 else 01999 { 02000 TRACE( _T("Base denominator is 0\n")); 02001 ok = FALSE; 02002 } 02003 } 02004 02005 // If we still have a silly millipoint value, error 02006 if (NumMillipoints <= 0.0) 02007 { 02008 TRACE( _T("The millipoint value is <= 0.0\n")); 02009 ok = FALSE; 02010 } 02011 02012 if (ok) 02013 { 02014 // Apply the read values 02015 pUnit->SetUnitType(TheUnitType); 02016 pUnit->SetDefaultState(TRUE); 02017 pUnit->SetPrefixState(Prefix); 02018 pUnit->SetBaseUnitType(BaseUnitType); 02019 02020 pUnit->SetBaseNumerator(BaseNumerator); 02021 pUnit->SetBaseDenominator(BaseDenominator); 02022 pUnit->SetMillipoints(NumMillipoints); 02023 02024 if (ok) 02025 { 02026 ok = pUnit->SetToken(NameStr); 02027 if (!ok) TRACE( _T("There's a problem with the name string : %s\n"),(TCHAR*)NameStr); 02028 } 02029 02030 if (ok) 02031 { 02032 ok = pUnit->SetSpecifier(SpecifierStr); 02033 if (!ok) TRACE( _T("There's a problem with the specifier string : %s\n"),(TCHAR*)NameStr); 02034 } 02035 } 02036 } 02037 } 02038 } 02039 } 02040 break; 02041 02042 case TOKEN_PAGEUNITS: 02043 { 02044 UnitType TheUnitType; 02045 if (ok) ok = ReadLong(file,&TheUnitType,"Expected the Page unit's type"); 02046 02047 if (ok) 02048 { 02049 ok = (FindUnit(TheUnitType) != NULL); 02050 if (!ok) TRACE( _T("The PageUnit specified cannot be found\n")); 02051 } 02052 02053 if (ok) SetPageUnits(TheUnitType); 02054 } 02055 break; 02056 02057 case TOKEN_FONTUNITS: 02058 { 02059 UnitType TheUnitType; 02060 if (ok) ok = ReadLong(file,&TheUnitType,"Expected the Font unit's type"); 02061 if (ok) 02062 { 02063 ok = (FindUnit(TheUnitType) != NULL); 02064 if (!ok) TRACE( _T("The FontUnit specified cannot be found\n")); 02065 } 02066 if (ok) SetFontUnits(TheUnitType); 02067 } 02068 break; 02069 02070 case TOKEN_UNITSEND: 02071 finished = TRUE; 02072 break; 02073 02074 default: 02075 TRACE( _T("DocUnitList: Unexpected token - %s\n"),TokenBuf); 02076 break; 02077 } 02078 } 02079 02080 if (!ok) 02081 { 02082 TRACE( _T("\nDocUnitList: Offending line - %s\n"),file.GetLineBuf()); 02083 ERROR3("Error reading units. See TRACE output for details"); 02084 } 02085 02086 // We are now finished with the lexer 02087 file.DeinitLexer(); 02088 02089 return (ok); 02090 }
|
|
Reads the unit definitions from the bound in resource.
Definition at line 1749 of file units.cpp. 01750 { 01751 PORTNOTETRACE("other","Removed DocUnitList::ReadUnitsFromRes()"); 01752 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX) 01753 // Remove all previously defined units. We're starting from scratch 01754 DeleteAll(); 01755 01756 CCResTextFile file; // Resource File 01757 01758 BOOL ok = file.open(_R(IDM_DEFAULT_UNITS),_R(IDT_CAM_UNITS)); // Open resource 01759 01760 if (ok) 01761 { 01762 ok = ReadUnitsFromFile(file); 01763 file.close(); 01764 } 01765 01766 return (ok); 01767 #else 01768 return FALSE; 01769 #endif 01770 }
|
|
This recalcs the unit's definition (i.e. the num millipoints that make it up) if it is a descendent of ChangedUnitType.
Definition at line 1259 of file units.cpp. 01260 { 01261 if (pThisUnit->GetBaseUnitType() == NOTYPE) 01262 return FALSE; 01263 01264 if (pThisUnit->GetBaseUnitType() == ChangedUnitType) 01265 { 01266 RecalcUnit(pThisUnit); 01267 return TRUE; 01268 } 01269 01270 Unit* pBaseUnit = FindUnit(pThisUnit->GetBaseUnitType()); 01271 01272 if (RecalcUnit(pBaseUnit,ChangedUnitType)) 01273 { 01274 RecalcUnit(pThisUnit); 01275 return TRUE; 01276 } 01277 01278 return FALSE; 01279 }
|
|
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.
Definition at line 1210 of file units.cpp. 01211 { 01212 if (pThisUnit->GetBaseUnitType() == NOTYPE) return; 01213 01214 Unit* pBaseUnit = FindUnit(pThisUnit->GetBaseUnitType()); 01215 double ratio = pThisUnit->GetBaseNumerator() / pThisUnit->GetBaseDenominator(); 01216 01217 pThisUnit->SetMillipoints(pBaseUnit->GetMillipoints() * ratio); 01218 }
|
|
Lets you set that base unit type, dude!
Definition at line 1401 of file units.cpp. 01402 { 01403 if (pThisUnit->GetUnitType() == NewBaseUnitType) 01404 return FALSE; 01405 01406 if (NewBaseUnitType != NOTYPE) 01407 { 01408 Unit* pNewBaseUnit = FindUnit(NewBaseUnitType); 01409 01410 if (IsDescendent(pNewBaseUnit,pThisUnit->GetUnitType())) 01411 return FALSE; 01412 } 01413 01414 pThisUnit->SetBaseUnitType(NewBaseUnitType); 01415 return TRUE; 01416 }
|
|
Sets the font units of the object directly.
Definition at line 1536 of file units.cpp. 01537 { 01538 FontUnits = NewUnits; 01539 }
|
|
Sets the page units of the object directly.
Definition at line 1498 of file units.cpp. 01499 { 01500 PageUnits = NewUnits; 01501 }
|
|
Sets the scale units of the object directly.
Definition at line 1460 of file units.cpp. 01461 { 01462 ScaleUnits = NewUnits; 01463 }
|
|
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.
Definition at line 1297 of file units.cpp. 01298 { 01299 Unit* pUnit = (Unit*) this->GetHead(); 01300 01301 while (pUnit != NULL) 01302 { 01303 RecalcUnit(pUnit,ChangedUnitType); 01304 pUnit = (Unit*) this->GetNext(pUnit); 01305 } 01306 01307 // Tell everybody that the unit has changed 01308 BROADCAST_TO_ALL(UnitMsg(this,ChangedUnitType,UnitMsg::CHANGED)); 01309 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|