UnitListComponent Class Reference

Provide a component that allows us to save out the units for this document using the serialisation facilities of the DocComponent base class. More...

#include <unitcomp.h>

Inheritance diagram for UnitListComponent:

DocComponent ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 UnitListComponent ()
 Construct a unit list component.
virtual ~UnitListComponent ()
 Clean up a unit list component's data structures.
virtual BOOL StartImport (BaseCamelotFilter *pFilter)
 Inform the unit list document component that a Native or Web import is about to start.
virtual BOOL EndImport (BaseCamelotFilter *pFilter, BOOL Success)
 Inform the unit list document component that a Native or Web import has just finished.
virtual BOOL StartExport (BaseCamelotFilter *pFilter)
 Inform the unit list document component that a Web or Native export is about to start.
virtual BOOL EndExport (BaseCamelotFilter *pFilter, BOOL Success)
 Inform the unit list document component that a Web or Native export has just finished.
BOOL ImportDefaultDisplayUnits (CXaraFileRecord *pCXaraFileRecord, Document *pDoc)
 Import the default display units from the current record in the native/web file currently being loaded.
BOOL ImportUserUnitDefinition (CXaraFileRecord *pCXaraFileRecord, Document *pDoc, INT32 Tag)
 Import the user unit definition from the current record in the native/web file currently being loaded and add it to the document.
UnitGetReadUnitReference (INT32 UnitRef)
 Try and convert a unit reference i.e. record number into a default or built in document unit or a previously imported user defined unit which should now be a user unit in the document. The public way of importing units and thier references for the new native/web filters.
INT32 GetWriteUnitReference (Unit *pUnit, BaseCamelotFilter *pFilter)
 Return the unit reference to the caller, who will then use it to write the unit in the record that they are preparing to save to a Web or Native file. In the process of getting the unit reference, the user unit definition record for the unit reference will be generated and saved to the file if this is required. This is only required if the unit has been defined by the user as all others are assumed. NOTE: As this does save information into the record stream, it *MUST* be called before the caller has called StartRecord() as otherwise the records will become intertwined!
INT32 GetWriteUnitReference (UnitType type, BaseCamelotFilter *pFilter)
 Return the unit reference to the caller, who will then use it to write the unit in the record that they are preparing to save to a Web or Native file. In the process of getting the unit reference, the user unit definition record for the unit reference will be generated and saved to the file if this is required. This is only required if the unit has been defined by the user as all others are assumed. NOTE: As this does save information into the record stream, it *MUST* be called before the caller has called StartRecord() as otherwise the records will become intertwined!

Private Member Functions

UnitType GetUnitType (INT32 ExportUnitType)
 Convert the built in unit types as defined in the file format into the ones used internally by Camelot.
BOOL ExportUserUnits (BaseCamelotFilter *pFilter)
 Export any user defined units into the native/web file currently being saved.
INT32 ExportUnitDefinition (BaseCamelotFilter *pFilter, Unit *pUnit)
 Export the definition for the specified unit into the native/web file currently being saved.
BOOL ExportDefaultDisplayUnits (BaseCamelotFilter *pFilter)
 Export the default display units into the native/web file currently being saved.
INT32 GetExportUnitType (UnitType type)
 Convert the built in unit types used internally by Camelot into the ones defined in the native/web file format.

Private Attributes

DocUnitListpDocUnitList
DocumentpDocument
CMapPtrToLongpExpUserUnitMap
CMapLongToPtrpImpUserUnitMap
BaseCamelotFilterpCamFilter
BOOL WarnedBefore

Detailed Description

Provide a component that allows us to save out the units for this document using the serialisation facilities of the DocComponent base class.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/07/96
See also:
DocComponent

Definition at line 142 of file unitcomp.h.


Constructor & Destructor Documentation

UnitListComponent::UnitListComponent  ) 
 

Construct a unit list component.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/07/96

Definition at line 214 of file unitcomp.cpp.

00215 {
00216     pDocUnitList = NULL;
00217     pDocument = NULL;
00218 
00219     // No hash tables yet
00220     pImpUserUnitMap = NULL;
00221     pExpUserUnitMap = NULL;
00222 
00223     // Our link to the BaseCamelotFilter
00224     pCamFilter = NULL;
00225     // Set our variable so that we warn about a possible replacement only once
00226     WarnedBefore = FALSE;
00227 }

UnitListComponent::~UnitListComponent  )  [virtual]
 

Clean up a unit list component's data structures.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/07/96
See also:
UnitListComponent

Definition at line 240 of file unitcomp.cpp.

00241 {
00242     // Trash the hash tables, if present
00243     if (pImpUserUnitMap)
00244     {
00245         delete pImpUserUnitMap;
00246         pImpUserUnitMap = NULL;
00247     }
00248 
00249     if (pExpUserUnitMap)
00250     {
00251         delete pExpUserUnitMap;
00252         pExpUserUnitMap = NULL;
00253     }
00254 }


Member Function Documentation

BOOL UnitListComponent::EndExport BaseCamelotFilter pFilter,
BOOL  Success
[virtual]
 

Inform the unit list document component that a Web or Native export has just finished.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/6/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS] Success - True if everything went swimmingly, False if just a clean up is required.
Returns:
TRUE if the export happened correctly FALSE if not (e.g. out of memory)
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 719 of file unitcomp.cpp.

00720 {
00721 #ifdef DO_EXPORT
00722 
00723     BOOL ok = TRUE;
00724 
00725     // Only export if we everything went ok up to now and we are not in a clean
00726     // up operation and we are doing a native file
00727     if (Success && !pFilter->IsWebFilter())
00728     {
00729         // Export any user defined units
00730         if (ok) ok = ExportUserUnits(pFilter);
00731 
00732         // Now export the default display units that the user has set
00733         if (ok) ok = ExportDefaultDisplayUnits(pFilter);
00734     }
00735 
00736     // Clean up the hash table
00737     if (pExpUserUnitMap)
00738     {
00739         delete pExpUserUnitMap;
00740         pExpUserUnitMap = NULL;
00741     }
00742 
00743     return ok;
00744 #else
00745     return TRUE;
00746 #endif
00747 }

BOOL UnitListComponent::EndImport BaseCamelotFilter pFilter,
BOOL  Success
[virtual]
 

Inform the unit list document component that a Native or Web import has just finished.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/07/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS] Success - TRUE => The import was successful; FALSE => The import failed - abandon any changes.
Returns:
TRUE if the component was able to end the importing; FALSE if not (e.g. out of memory)
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 333 of file unitcomp.cpp.

00334 {
00335 TRACEUSER( "Neville", _T("UnitListComponent::EndImport\n"));
00336     if (pFilter == NULL)
00337     {
00338         ERROR3("UnitListComponent::EndImport filter is null!");
00339         return TRUE;
00340     }
00341 
00342     // Trash the import hash table, if present
00343     if (pImpUserUnitMap)
00344     {
00345         delete pImpUserUnitMap;
00346         pImpUserUnitMap = NULL;
00347     }
00348 
00349     // Null our link to the BaseCamelotFilter
00350     pCamFilter = NULL;
00351     // Set our variable so that we warn about a possible replacement only once
00352     WarnedBefore = FALSE;
00353 
00354     return TRUE;
00355 }

BOOL UnitListComponent::ExportDefaultDisplayUnits BaseCamelotFilter pFilter  )  [private]
 

Export the default display units into the native/web file currently being saved.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/07/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS]
Returns:
TRUE if the export happened correctly FALSE if not (e.g. out of memory)

Definition at line 1039 of file unitcomp.cpp.

01040 {
01041 #ifdef DO_EXPORT
01042     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitListComponent::ExportDisplayDefaultUnits called with no doc unit list pointer");
01043 
01044     // Get the current default settings
01045     UnitType PageUnits   = pDocUnitList->GetPageUnits();    // The units used to display page measurements
01046     //UnitType ScaledUnits = pDocUnitList->GetScaleUnits(); // The units to display scaled measurements
01047     UnitType FontUnits   = pDocUnitList->GetFontUnits();    // The units to display font measurements
01048 
01049     // Convert these into the export unit types
01050     //INT32 ExportPageUnits = GetExportUnitType(PageUnits);
01051     //INT32 ExportFontUnits = GetExportUnitType(FontUnits);
01052     INT32 ExportPageUnits = GetWriteUnitReference(PageUnits, pFilter);
01053     ERROR2IF(ExportPageUnits == 0,FALSE,"UnitListComponent::ExportDisplayDefaultUnits bad page units reference!");
01054     INT32 ExportFontUnits = GetWriteUnitReference(FontUnits, pFilter);
01055     ERROR2IF(ExportFontUnits == 0,FALSE,"UnitListComponent::ExportDisplayDefaultUnits bad font units reference!");
01056 
01057     BOOL ok = TRUE;
01058 
01059     if (ExportPageUnits !=0 && ExportFontUnits != 0)
01060     {
01061             CXaraFileRecord Rec(TAG_DEFINE_DEFAULTUNITS, TAG_DEFINE_DEFAULTUNITS_SIZE);
01062             ok = Rec.Init();
01063 
01064             if (ok) ok = Rec.WriteINT32(ExportPageUnits);
01065             if (ok) ok = Rec.WriteINT32(ExportFontUnits);
01066 
01067             // Finally, write the record out to file
01068             // In the process get the record number that this was written out as
01069             INT32 RecordNumber = 0L;
01070             if (ok) RecordNumber = pFilter->Write(&Rec);    // Get the document comment
01071 
01072             // If we have had a problem at any of the stages then return that to the caller
01073             if (RecordNumber <= 0)
01074                 ok = FALSE;
01075     }
01076     else
01077         ERROR3("Bad conversion of default font or page units");
01078 
01079     return ok;
01080 #else
01081     return TRUE;
01082 #endif
01083 }

INT32 UnitListComponent::ExportUnitDefinition BaseCamelotFilter pFilter,
Unit pUnit
[private]
 

Export the definition for the specified unit into the native/web file currently being saved.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/07/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS] pUnit - the unit definition to be exported
Returns:
The record number of the unit if the export happened correctly or if the unit definition has already happened. 0 if not (e.g. out of memory)

Definition at line 926 of file unitcomp.cpp.

00927 {
00928 #ifdef DO_EXPORT
00929     ERROR2IF(pFilter == NULL,0L,"UnitListComponent::ExportUnitDefinition null pFilter");
00930     ERROR2IF(pUnit == NULL,0L,"UnitListComponent::ExportUnitDefinition null pUnit");
00931     ERROR2IF(pDocUnitList == NULL,0L,"UnitListComponent::ExportUnitDefinition called with no doc unit list pointer");
00932 
00933     ERROR2IF(pUnit->IsDefault(),0L,"UnitListComponent::ExportUnitDefinition trying to save default unit definition");
00934 
00935     INT32 RecordNumber = 0L;
00936 
00937     // See if we have saved the unit definition out by checking our table
00938     // If so then do nothing
00939     CMapPtrToLong::iterator it = pExpUserUnitMap->find(pUnit);
00940     if (it!=pExpUserUnitMap->end())
00941         return it->second;
00942 
00943     // Export the definition for this unit
00944     // First get all the details
00945 //  UnitType type = pUnit->GetUnitType();
00946     
00947     // Set up the prefix/suffix state for this user's unit.
00948     BOOL Prefix = pUnit->IsPrefix();
00949     INT32 Tag = 0L;
00950     INT32 Size = 0L;
00951     if (Prefix)
00952     {
00953         Tag = TAG_DEFINE_PREFIXUSERUNIT;
00954         Size = TAG_DEFINE_PREFIXUSERUNIT_SIZE;
00955     }
00956     else
00957     {
00958         Tag = TAG_DEFINE_SUFFIXUSERUNIT;
00959         Size = TAG_DEFINE_SUFFIXUSERUNIT_SIZE;
00960     }
00961 
00962     // The main full name of the unit
00963     String_32 Name = pUnit->GetToken();
00964     // And the abbreviation
00965     String_32 Abbrev = pUnit->GetSpecifier();
00966 
00967     // If there are string names, then add it to this size
00968     // REMEMBER: We save out unicode strings and so we need to double the length of the returned string length
00969     Size += (Name.Length() + 1) * SIZEOF_XAR_UTF16;
00970     Size += (Abbrev.Length() + 1) * SIZEOF_XAR_UTF16;
00971 
00972     BOOL ok = TRUE;
00973     CXaraFileRecord Rec(Tag, Size);
00974     ok = Rec.Init();
00975 
00976     // Write out the name and abbreviation for this unit
00977     if (ok) ok = Rec.WriteUnicode(Name);
00978     if (ok) ok = Rec.WriteUnicode(Abbrev);
00979 
00980     // The size of this unit, 0 if based on
00981     double UnitSize = pUnit->GetMillipoints();
00982     if (ok) ok = Rec.WriteDOUBLE(UnitSize);
00983 
00984     // What unit this is based on
00985     UnitType BaseUnit = pUnit->GetBaseUnitType();
00986     //INT32 ExportBaseUnit = GetExportUnitType(BaseUnit);
00987     INT32 ExportBaseUnit = GetWriteUnitReference(BaseUnit, pFilter);
00988     ERROR2IF(ExportBaseUnit == 0,FALSE,"bad base units reference!");
00989     if (ok) ok = Rec.WriteINT32(ExportBaseUnit);
00990 
00991     // Write out the multipliers for this unit
00992     double BaseNumerator = 0.0;
00993     double BaseDenominator = 0.0;
00994     BaseNumerator = pUnit->GetBaseNumerator();
00995     BaseDenominator = pUnit->GetBaseDenominator();
00996     if (ok) ok = Rec.WriteDOUBLE(BaseNumerator);
00997     if (ok) ok = Rec.WriteDOUBLE(BaseDenominator);
00998 
00999     // Finally, write the record out to file
01000     // In the process get the record number that this was written out as
01001     if (ok) RecordNumber = pFilter->Write(&Rec);    // Get the document comment
01002 
01003     // Add the unit to the user units map so we can remember the references of the
01004     // exported units and hence whether we have exported this before
01005     // Reference for this unit is the record number
01006 TRACEUSER( "Neville", _T("Exported user unit reference %d\n"), RecordNumber);
01007     try
01008     {
01009         (*pExpUserUnitMap)[pUnit] = RecordNumber;
01010     }
01011     catch (std::bad_alloc&)
01012     {
01013         ERROR1(FALSE, _R(IDS_OUT_OF_MEMORY));
01014     }
01015     catch (...)
01016     {
01017         ERROR1(FALSE, _R(IDS_UNKNOWN_ERROR));
01018     }
01019 
01020     return RecordNumber;
01021 #else
01022     return 0L;
01023 #endif
01024 }

BOOL UnitListComponent::ExportUserUnits BaseCamelotFilter pFilter  )  [private]
 

Export any user defined units into the native/web file currently being saved.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/07/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS]
Returns:
TRUE if the export happened correctly FALSE if not (e.g. out of memory)

Definition at line 883 of file unitcomp.cpp.

00884 {
00885 #ifdef DO_EXPORT
00886     ERROR2IF(pFilter == NULL,FALSE,"UnitListComponent::ExportUserUnits null pFilter");
00887     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitListComponent::ExportUserUnits called with no doc unit list pointer");
00888 
00889     // Export any user defined units
00890     Unit* pUnit = NULL;
00891     BOOL ok = TRUE;
00892     INT32 RecNum = 0;
00893 
00894     pUnit = pDocUnitList->FindFirstUserUnit();
00895     while (pUnit != NULL)
00896     {
00897         RecNum = ExportUnitDefinition(pFilter, pUnit);
00898         if (RecNum == 0)
00899             break;
00900 
00901         pUnit = pDocUnitList->FindNextUserUnit(pUnit);
00902     }
00903 
00904     return ok;
00905 #else
00906     return TRUE;
00907 #endif
00908 }

INT32 UnitListComponent::GetExportUnitType UnitType  type  )  [private]
 

Convert the built in unit types used internally by Camelot into the ones defined in the native/web file format.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/07/96
Parameters:
type - the unit type used internally by Camelot [INPUTS]
Returns:
The default export unit type as used in the native/web file format

Definition at line 1098 of file unitcomp.cpp.

01099 {
01100 #ifdef DO_EXPORT
01101     INT32 DefUnitType = 0;
01102     switch (type)
01103     {
01104         case MILLIMETRES:   DefUnitType = REF_DEFAULTUNIT_MILLIMETRES;  break;
01105         case CENTIMETRES:   DefUnitType = REF_DEFAULTUNIT_CENTIMETRES;  break;
01106         case METRES:        DefUnitType = REF_DEFAULTUNIT_METRES;       break;
01107         case KILOMETRES:    DefUnitType = REF_DEFAULTUNIT_KILOMETRES;   break;
01108         case MILLIPOINTS:   DefUnitType = REF_DEFAULTUNIT_MILLIPOINTS;  break;
01109         case COMP_POINTS:   DefUnitType = REF_DEFAULTUNIT_COMP_POINTS;  break;
01110         case PICAS:         DefUnitType = REF_DEFAULTUNIT_PICAS;        break;
01111         case INCHES:        DefUnitType = REF_DEFAULTUNIT_INCHES;       break;
01112         case FEET:          DefUnitType = REF_DEFAULTUNIT_FEET;         break;
01113         case YARDS:         DefUnitType = REF_DEFAULTUNIT_YARDS;        break;
01114         case MILES:         DefUnitType = REF_DEFAULTUNIT_MILES;        break;
01115         case PIXELS:        DefUnitType = REF_DEFAULTUNIT_PIXELS;       break;
01116 
01117         case NOTYPE:        DefUnitType = REF_DEFAULTUNIT_NOTYPE;       break;
01118 
01119         case AUTOMATIC:     
01120         case NUM_DEFAULT_UNIT_TYPES:
01121                             ERROR3("This shouldn't happen!");
01122                             DefUnitType = 0; break;
01123     }
01124 
01125     return DefUnitType; 
01126 #else
01127     return 0L; 
01128 #endif
01129 }

Unit * UnitListComponent::GetReadUnitReference INT32  UnitRef  ) 
 

Try and convert a unit reference i.e. record number into a default or built in document unit or a previously imported user defined unit which should now be a user unit in the document. The public way of importing units and thier references for the new native/web filters.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/7/96
Parameters:
UnitRef - The unit reference or record number that the record handler has loaded [INPUTS] from the record.
- [OUTPUTS]
Returns:
pUnit - A pointer to return the required document unit
See also:
-

Definition at line 375 of file unitcomp.cpp.

00376 {
00377     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitListComponent::GetReadUnitReference called with no doc unit list pointer");
00378 
00379 TRACEUSER( "Neville", _T("GetReadUnitReference for ref %d\n"), UnitRef);
00380     // First check to see if the unit refers to any of the built in units.
00381     // These will have negative record numbers
00382     Unit               *pUnit = NULL;
00383     if (UnitRef <= 0)
00384     {
00385         UnitType type = GetUnitType(UnitRef);
00386 
00387         // If we succesfully converted the unit into a type then find the unit
00388         if (type != NOTYPE)
00389         {
00390             // Find this unit type in the current document list
00391             pUnit = pDocUnitList->FindUnit(type);
00392         }
00393         else
00394             ERROR2(NULL,"BitmapListComponent::GetReadBitmapReference negative UnitRef is unknown");
00395     }
00396     else
00397     {
00398         // Try and find the specified record number in our loaded user unit list
00399         CMapLongToPtr::const_iterator iter = pImpUserUnitMap->find( UnitRef );
00400         /*BOOL          ok =*/ pImpUserUnitMap->end();/* != iter;*/
00401         pUnit = (Unit *)iter->second;
00402         // if ok then pUnit will be the pointer to the required unit
00403         // so return this.
00404         // if not ok then pUnit will still be null.
00405                 
00406         // If not found then this is a problem as a bitmap must have been defined before its being
00407         // referenced 
00408         if (pUnit == NULL)
00409         {
00410             // If we have a pFilter then ask the default warning handle to append our message
00411             if (pCamFilter)
00412             {
00413                 if (!WarnedBefore)
00414                 {
00415                     pCamFilter->AppendWarning(_R(IDS_NATIVE_UNITSWARNING));
00416                     WarnedBefore = TRUE;
00417                 }
00418 
00419                 // Now use a default unit instead, we will use the default page display units
00420                 UnitType PageUnits = pDocUnitList->GetPageUnits();  // The units used to display page measurements
00421                 pUnit = pDocUnitList->FindUnit(PageUnits);  
00422             }
00423             else
00424                 ERROR2IF(pUnit == NULL,NULL,"BitmapListComponent::GetReadUnitReference UnitRef cannot be found");
00425         }
00426     }
00427 
00428     return pUnit;
00429 }

UnitType UnitListComponent::GetUnitType INT32  ExportUnitType  )  [private]
 

Convert the built in unit types as defined in the file format into the ones used internally by Camelot.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/07/96
Parameters:
ExportUnitType - the unit specified as a default export unit [INPUTS]
Returns:
The UnitType in the internal format used by Camelot

Definition at line 613 of file unitcomp.cpp.

00614 {
00615     UnitType Type = NOTYPE;
00616     switch (ExportUnitType)
00617     {
00618         case REF_DEFAULTUNIT_MILLIMETRES:   Type = MILLIMETRES; break;
00619         case REF_DEFAULTUNIT_CENTIMETRES:   Type = CENTIMETRES; break;
00620         case REF_DEFAULTUNIT_METRES:        Type = METRES;      break;
00621         case REF_DEFAULTUNIT_KILOMETRES:    Type = KILOMETRES;  break;
00622         case REF_DEFAULTUNIT_MILLIPOINTS:   Type = MILLIPOINTS; break;
00623         case REF_DEFAULTUNIT_COMP_POINTS:   Type = COMP_POINTS; break;
00624         case REF_DEFAULTUNIT_PICAS:         Type = PICAS;       break;
00625         case REF_DEFAULTUNIT_INCHES:        Type = INCHES;      break;
00626         case REF_DEFAULTUNIT_FEET:          Type = FEET;        break;
00627         case REF_DEFAULTUNIT_YARDS:         Type = YARDS;       break;
00628         case REF_DEFAULTUNIT_MILES:         Type = MILES;       break;
00629         case REF_DEFAULTUNIT_PIXELS:        Type = PIXELS;      break;
00630         
00631         case REF_DEFAULTUNIT_NOTYPE:        Type = NOTYPE;      break;  
00632     }
00633     
00634     return Type; 
00635 }

INT32 UnitListComponent::GetWriteUnitReference UnitType  type,
BaseCamelotFilter pFilter
 

Return the unit reference to the caller, who will then use it to write the unit in the record that they are preparing to save to a Web or Native file. In the process of getting the unit reference, the user unit definition record for the unit reference will be generated and saved to the file if this is required. This is only required if the unit has been defined by the user as all others are assumed. NOTE: As this does save information into the record stream, it *MUST* be called before the caller has called StartRecord() as otherwise the records will become intertwined!

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/7/96
Parameters:
UnitType - The unit type to save [INPUTS] pFilter - The filter to use for saving
- [OUTPUTS]
Returns:
The unit reference for the unit ready for writing in a record. This will be zero if a problem has occurred. May return -1 if it does not need to save anything i.e if the colour is not in use and not named.
See also:
DocComponent

Definition at line 834 of file unitcomp.cpp.

00835 {
00836 #ifdef DO_EXPORT
00837     ERROR2IF(pFilter == NULL,0L,"UnitListComponent::GetWriteUnitReference null pFilter");
00838     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitListComponent::GetWriteUnitReference called with no doc unit list pointer");
00839 
00840     INT32 RecordNumber = 0L;
00841 
00842     // Get a pointer to the unit
00843     Unit* pUnit = NULL;
00844     pUnit = pDocUnitList->FindUnit(type);   
00845 
00846     // Is the unit a user defined unit or one of the defaults?
00847     if (pUnit->IsDefault())
00848     {
00849         // Its a default unit so convert the type into the default reference
00850         RecordNumber = GetExportUnitType(type);
00851     }
00852     else
00853     {
00854         // See if we have saved the unit definition out by checking our has table
00855         // Try and find the specified record number in our loaded user unit list
00856         if (pExpUserUnitMap->find(pUnit)==pExpUserUnitMap->end())
00857         {
00858             // We have not seen this unit before so save out the definition
00859             /*BOOL ok =*/ ExportUnitDefinition(pFilter, pUnit);
00860         }
00861     }
00862 
00863     return RecordNumber;
00864 #else
00865     return 0;
00866 #endif
00867 }

INT32 UnitListComponent::GetWriteUnitReference Unit pUnit,
BaseCamelotFilter pFilter
 

Return the unit reference to the caller, who will then use it to write the unit in the record that they are preparing to save to a Web or Native file. In the process of getting the unit reference, the user unit definition record for the unit reference will be generated and saved to the file if this is required. This is only required if the unit has been defined by the user as all others are assumed. NOTE: As this does save information into the record stream, it *MUST* be called before the caller has called StartRecord() as otherwise the records will become intertwined!

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/7/96
Parameters:
pUnit - The unit to save [INPUTS] pFilter - The filter to use for saving
- [OUTPUTS]
Returns:
The unit reference for the unit ready for writing in a record. This will be zero if a problem has occurred. May return -1 if it does not need to save anything i.e if the colour is not in use and not named.
See also:
DocComponent

Definition at line 776 of file unitcomp.cpp.

00777 {
00778 #ifdef DO_EXPORT
00779     ERROR2IF(pUnit == NULL,0L,"UnitListComponent::GetWriteUnitReference null pUnit");
00780     ERROR2IF(pFilter == NULL,0L,"UnitListComponent::GetWriteUnitReference null pFilter");
00781 
00782     INT32 RecordNumber = 0L;
00783 
00784     // Is the unit a user defined unit or one of the defaults?
00785     if (pUnit->IsDefault())
00786     {
00787         UnitType type = pUnit->GetUnitType();
00788         // Its a default unit so convert the type into the default reference
00789         RecordNumber = GetExportUnitType(type);
00790     }
00791     else
00792     {
00793         // See if we have saved the unit definition out by checking our has table
00794         // Try and find the specified record number in our loaded user unit list
00795         if (pExpUserUnitMap->find(pUnit)==pExpUserUnitMap->end())
00796         {
00797             // We have not seen this unit before so save out the definition
00798             /*BOOL ok =*/ ExportUnitDefinition(pFilter, pUnit);
00799         }
00800     }
00801 
00802     return RecordNumber;
00803 #else
00804     return 0;
00805 #endif
00806 }

BOOL UnitListComponent::ImportDefaultDisplayUnits CXaraFileRecord pCXaraFileRecord,
Document pDoc
 

Import the default display units from the current record in the native/web file currently being loaded.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/07/96
Parameters:
pCXaraFileRecord = ptr to record to handle [INPUTS] pDoc = document to apply the information to
Returns:
TRUE if the export happened correctly FALSE if not (e.g. out of memory)

Definition at line 556 of file unitcomp.cpp.

00557 {
00558     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"UnitListComponent::ImportDefaultUnits called with no pCXaraFileRecord pointer");
00559     ERROR2IF(pDoc == NULL,FALSE,"UnitListComponent::ImportDefaultUnits called with no doc pointer");
00560 
00561     // Read in the export unit types
00562     INT32 ExportPageUnits = 0L;
00563     INT32 ExportFontUnits = 0L;
00564 
00565     // Read the desired units from the record
00566     pCXaraFileRecord->ReadINT32(&ExportPageUnits);
00567     pCXaraFileRecord->ReadINT32(&ExportFontUnits);
00568 
00569     // Convert these read in references to their correct unit types
00570     // First the page units
00571     UnitType PageUnits = NOTYPE;
00572     Unit* pPageUnits = GetReadUnitReference(ExportPageUnits);
00573     if (pPageUnits != NULL)
00574         PageUnits = pPageUnits->GetUnitType();
00575     else
00576         ERROR3("The default page units have a bad unit on which it is based");
00577 
00578     // Now the font units
00579     UnitType FontUnits = NOTYPE;
00580     Unit* pFontUnits = GetReadUnitReference(ExportFontUnits);
00581     if (pFontUnits != NULL)
00582         FontUnits = pFontUnits->GetUnitType();
00583     else
00584         ERROR3("The default font units have a bad unit on which it is based");
00585 
00586     DocUnitList* pDocUnitList = pDoc->GetDocUnitList();
00587     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitListComponent::ImportDefaultUnits called with no doc unit list pointer");
00588 
00589     // Set the new default settings
00590     // The units used to display page measurements
00591     if (PageUnits != NOTYPE)
00592         pDocUnitList->SetPageUnits(PageUnits);  
00593     // The units to display font measurements
00594     if (FontUnits != NOTYPE)
00595         pDocUnitList->SetFontUnits(FontUnits);
00596 
00597     return TRUE;
00598 }

BOOL UnitListComponent::ImportUserUnitDefinition CXaraFileRecord pCXaraFileRecord,
Document pDoc,
INT32  Tag
 

Import the user unit definition from the current record in the native/web file currently being loaded and add it to the document.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/07/96
Parameters:
pCXaraFileRecord = ptr to record to handle [INPUTS] pDoc = document to apply the information to Tag = the tag of the record
Returns:
TRUE if the export happened correctly FALSE if not (e.g. out of memory)

Definition at line 449 of file unitcomp.cpp.

00451 {
00452     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"UnitListComponent::ImportUserUnitDefinition called with no pCXaraFileRecord pointer");
00453     ERROR2IF(pDoc == NULL,FALSE,"UnitListComponent::ImportUserUnitDefinition called with no doc pointer");
00454     ERROR2IF(pDocUnitList == NULL,FALSE,"UnitListComponent::ImportUserUnitDefinition called with no doc unit list pointer");
00455 
00456     Unit* pUnit = NULL;
00457 
00458     BOOL ok = TRUE;
00459     ok = pDocUnitList->MakeNewUnit(&pUnit);
00460 
00461     if (ok && pUnit)
00462     {
00463         BOOL Prefix = TRUE;
00464         switch (Tag)
00465         {
00466             case TAG_DEFINE_PREFIXUSERUNIT:
00467                 Prefix = TRUE;
00468                 break;
00469             case TAG_DEFINE_SUFFIXUSERUNIT:
00470                 Prefix = FALSE;
00471                 break;
00472             default:
00473                 ERROR3("Bad tag in ImportUserUnitDefinition");
00474         }
00475         pUnit->SetPrefixState(Prefix);
00476                 
00477         // Read in the main full name of the unit
00478         String_32 Name;
00479         if (ok) ok = pCXaraFileRecord->ReadUnicode(&Name);//Name, Name.MaxLength());
00480         if (ok) ok = pUnit->SetToken(Name);
00481 
00482         // And the abbreviation
00483         String_32 Abbrev;
00484         if (ok) ok = pCXaraFileRecord->ReadUnicode(&Abbrev);//Abbrev, Abbrev.MaxLength());
00485         if (ok) ok = pUnit->SetSpecifier(Abbrev);
00486         
00487         // Read in the size of this unit, 0 means based on
00488         double UnitSize = 0.0;
00489         if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&UnitSize);
00490         if (ok) ok = pUnit->SetMillipoints(UnitSize);
00491 
00492         // Read in the exported base unit type
00493         INT32 ExportBaseUnit = 0L;
00494         if (ok) ok = pCXaraFileRecord->ReadINT32(&ExportBaseUnit);
00495         UnitType BasedOn = NOTYPE;
00496         // Convert this based on unit into the required forms
00497         Unit* pBasedOnUnit = GetReadUnitReference(ExportBaseUnit);
00498         if (pBasedOnUnit != NULL)
00499         {
00500             //BasedOn = GetUnitType(ExportBaseUnit);
00501             BasedOn = pBasedOnUnit->GetUnitType();
00502             if (ok) ok = pUnit->SetBaseUnitType(BasedOn);
00503         }
00504         else
00505         {
00506             ERROR3("UserUnit has a bad unit on which it is based");
00507         }
00508 
00509         // Read in the multipliers for this unit
00510         double BaseNumerator = 0.0;
00511         double BaseDenominator = 0.0;
00512         if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&BaseNumerator);
00513         if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&BaseDenominator);
00514         if (ok) ok = pUnit->SetBaseNumerator(BaseNumerator);
00515         if (ok) ok = pUnit->SetBaseDenominator(BaseDenominator);
00516 
00517 
00518         // Add the unit to the user units map so we can remember the references of the
00519         // imported units
00520         // Reference for this unit is the record number
00521         INT32 RecordNumber = pCXaraFileRecord->GetRecordNumber();
00522 TRACEUSER( "Neville", _T("Imported user unit reference %d\n"), RecordNumber);
00523         (*pImpUserUnitMap)[ RecordNumber ] = pUnit;
00524     }
00525 
00526     // We will ignore any errors as we shouldn't not load a document because there is an
00527     // error in the units definition. We will just warn the user about a problem
00528     // If we have a pFilter then ask the default warning handle to append our message
00529     if (!ok && pCamFilter)
00530     {
00531         if (!WarnedBefore)
00532         {
00533             pCamFilter->AppendWarning(_R(IDS_NATIVE_UNITSWARNING));
00534             WarnedBefore = TRUE;
00535         }
00536     }
00537 
00538     return TRUE;
00539 }

BOOL UnitListComponent::StartExport BaseCamelotFilter pFilter  )  [virtual]
 

Inform the unit list document component that a Web or Native export is about to start.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/6/96
Returns:
TRUE if the component was able to prepare for exporting; FALSE if not (e.g. out of memory)
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to export a file. [INPUTS]
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 652 of file unitcomp.cpp.

00653 {
00654 #ifdef DO_EXPORT
00655     ERROR3IF(pExpUserUnitMap != NULL,"UnitListComponent::StartExport pExpUserUnitMap is non-NULL!");
00656 
00657     if (pFilter)
00658     {
00659         // Get the document we are interested in
00660         pDocument = pFilter->GetDocument();
00661 
00662         // Get the unit list attached to the current document
00663         if (pDocument)
00664             pDocUnitList = pDocument->GetDocUnitList();
00665         ERROR3IF(pDocUnitList == NULL,"UnitListComponent::StartExport No doc unit list attached to this doc yet");
00666 
00667         // Get a hash table for the user units...
00668 /*      TRY
00669         {
00670             pExpUserUnitMap = new CMapPtrToPtr;
00671         }
00672         CATCH (CMemoryException, e)
00673         {
00674             ERROR1(FALSE, _R(IDS_OUT_OF_MEMORY));
00675         }
00676         END_CATCH
00677 */
00678         try
00679         {
00680             pExpUserUnitMap = new CMapPtrToLong;
00681         }
00682         catch (std::bad_alloc&)
00683         {
00684             ERROR1(FALSE, _R(IDS_OUT_OF_MEMORY));
00685         }
00686         catch (...)
00687         {
00688             ERROR1(FALSE, _R(IDS_UNKNOWN_ERROR));
00689         }
00690 
00691     }
00692     else
00693     {
00694         pDocUnitList = NULL;
00695         pDocument = NULL;
00696     }
00697 
00698 #endif
00699     return TRUE;
00700 }

BOOL UnitListComponent::StartImport BaseCamelotFilter pFilter  )  [virtual]
 

Inform the unit list document component that a Native or Web import is about to start.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/07/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS]
Returns:
TRUE if the component was able to prepare for importing; FALSE if not (e.g. out of memory)
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 278 of file unitcomp.cpp.

00279 {
00280 TRACEUSER( "Neville", _T("UnitListComponent::StartImport\n"));
00281     if (pFilter)
00282     {
00283         // Get the document we are interested in
00284         pDocument = pFilter->GetDocument();
00285 
00286         // Get the unit list attached to the current document
00287         if (pDocument)
00288             pDocUnitList = pDocument->GetDocUnitList();
00289         ERROR3IF(pDocUnitList == NULL,"UnitListComponent::StartImport No doc unit list attached to this doc yet");
00290 
00291         // Save this in our link to the BaseCamelotFilter
00292         pCamFilter = pFilter;
00293         // Set our variable so that we warn about a possible replacement only once
00294         WarnedBefore = FALSE;
00295 
00296         // Get a hash table for the user units...
00297         try
00298         {
00299             pImpUserUnitMap = new CMapLongToPtr;
00300         }
00301         catch( CMemoryException )
00302         {
00303             ERROR( _R(IDS_OUT_OF_MEMORY), FALSE );
00304         }
00305     }
00306     else
00307     {
00308         pDocUnitList = NULL;
00309         pDocument = NULL;
00310         ERROR3("UnitListComponent::StartImport filter is null!");
00311     }
00312     
00313     return TRUE;
00314 }


Member Data Documentation

BaseCamelotFilter* UnitListComponent::pCamFilter [private]
 

Definition at line 185 of file unitcomp.h.

Document* UnitListComponent::pDocument [private]
 

Definition at line 178 of file unitcomp.h.

DocUnitList* UnitListComponent::pDocUnitList [private]
 

Definition at line 177 of file unitcomp.h.

CMapPtrToLong* UnitListComponent::pExpUserUnitMap [private]
 

Definition at line 181 of file unitcomp.h.

CMapLongToPtr* UnitListComponent::pImpUserUnitMap [private]
 

Definition at line 182 of file unitcomp.h.

BOOL UnitListComponent::WarnedBefore [private]
 

Definition at line 186 of file unitcomp.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 04:02:40 2007 for Camelot by  doxygen 1.4.4