LineComponent Class Reference

A document component for handling Line definitions. More...

#include <linecomp.h>

Inheritance diagram for LineComponent:

DocComponent ListItem CCObject SimpleCCObject BrushComponent List of all members.

Public Member Functions

 LineComponent ()
 Constructor.
virtual ~LineComponent ()
 Destructor.
virtual LineHandle AddNewItem (LineDefinition *pLine, BOOL AskName=FALSE)
 Adds the given Line to the global Line list.
virtual LineDefinitionFindDefinition (UINT32 Handle, BOOL Dummy=FALSE)
UINT32 GetNumberOfLines ()
virtual BOOL StartImport (BaseCamelotFilter *pFilter)
 Called before we start to import a file.
virtual BOOL EndImport (BaseCamelotFilter *pFilter, BOOL Success)
 Called on completion of an import.
virtual BOOL StartExport (BaseCamelotFilter *pFilter)=0
 Inform the document component that a WEb or Native export is about to start.
virtual BOOL EndExport (BaseCamelotFilter *pFilter, BOOL Success)
 Called on completion of file export.
BOOL EndImportLine (CamelotRecordHandler *pHandler)
LineHandle FindImportedLine (UINT32 ImportedHandle)
 To match up a handle from the currently importing file to the real internal LineHandle of the imported LineDefinition.
virtual BOOL ExportLine (BaseCamelotFilter *pFilter, LineHandle Handle)=0
virtual BOOL NameIsUnique (const String_32 &NameString)
 To find out if someone has already gotten this name.
virtual String_32 GetUniqueName (String_32 *pName=NULL)=0

Static Public Member Functions

static void DeleteList (void)
static BOOL StartImportLine (CamelotRecordHandler *pHandler, CXaraFileRecord *pRecord)
 To import a vector Line definition.

Protected Member Functions

virtual BOOL ExpandArray (void)=0

Static Protected Member Functions

static void DeleteLineList (void)
 Static deinitialisation function, called on shutdown. Clears out the global Line list. Must be called when all users of the Line system (documents) have already been deleted.

Static Protected Attributes

static LineDefinition ** m_pLineArray = NULL
static UINT32 m_CurrentSize = 0
static UINT32 m_Used = 0
static UINT32 m_ImportHandle = 0
static UINT32 m_ImportFlags = 0
static UINT32 m_ImportData1 = 0
static UINT32 m_ImportData2 = 0
static InsertTreeContextm_pImportPreviousContext = NULL
static Nodem_pImportNewLine = NULL
static String_32 m_ImportedName

Detailed Description

A document component for handling Line definitions.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/2/97
LineComponents share a global cache of available Line types. Individual instances serve as managers for the list, mainly providing import/export facilities for Line definitions.

See also:
DocComponent

Definition at line 161 of file linecomp.h.


Constructor & Destructor Documentation

LineComponent::LineComponent  ) 
 

Constructor.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99

Definition at line 137 of file linecomp.cpp.

00138 {
00139     
00140 }

LineComponent::~LineComponent  )  [virtual]
 

Destructor.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99

Definition at line 155 of file linecomp.cpp.

00156 {
00157     if (m_pImportPreviousContext != NULL)
00158         delete m_pImportPreviousContext;
00159     if (m_pImportNewLine != NULL)
00160         delete m_pImportNewLine;
00161 }


Member Function Documentation

LineHandle LineComponent::AddNewItem LineDefinition pItem,
BOOL  AskName = FALSE
[virtual]
 

Adds the given Line to the global Line list.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99
Parameters:
pLine - (may not be NULL) A Line definition to add, which now [INPUTS] belongs to the LineComponent, so you mustn't delete it!
Returns:
A handle which uniquely identifies the new Line, or LineHandle_NoLine if we ran out of memory for storing Lines
Notes: IMPORTANT! The Line definition you pass in belongs to the LineComponent, and will be deleted when finished with.

YOU MUST NOT use the pLine pointer after this call! If the call fails, or if the Line is merged with an existing one, the object you passed in will be IMMEDIATELY DELETED! If you wish to use the Line after Adding it, you must call FindLine with the returned Line handle!

Technical: Lines are recorded in an array of LineDefinition pointers. The LineHandle is just an index into this array, for fast lookup. When deleted, the array-entry is set NULL and never re-used, so that any handles floating around can be safely used (much better than getting IndexedColour deleted when in use errors, eh? ;-). New entries are thus always appended to the list.

Reimplemented in BrushComponent.

Definition at line 231 of file linecomp.cpp.

00232 {
00233     // ****!!!!TODO - if we're multi-threadig, this probably needs to be a critical section
00234     // because the list is global
00235 
00236     ERROR3IF(pItem == NULL, "Illegal NULL param");
00237 
00238     // --- First, check if we can merge the given Line with one already in the list
00239     for (UINT32 i = 0; i < m_Used; i++)
00240     {
00241         if (m_pLineArray[i] != NULL && !pItem->IsDifferent(m_pLineArray[i]))
00242         {
00243             // The Line is the same as one we already have in our Line list, so we
00244             // delete the copy that was passed in, and return the existing ones handle
00245             // We copy the import handle value over, though, so that we don't "lose"
00246             // merged Lines during import!
00247             m_pLineArray[i]->SetIOStore(pItem->ReadIOStore());
00248             delete pItem;
00249             return((LineHandle) i);
00250         }
00251     }
00252 
00253     // --- Next, check if we have enough room in our Line array to add a new entry to the end
00254     if (m_Used >= m_CurrentSize)
00255     {
00256         if (!ExpandArray())
00257         {
00258             delete pItem;
00259             return(LineHandle_NoLine);
00260         }
00261     }
00262 
00263     // --- OK, we have a totally new Line, so add it to the end of the list
00264     LineHandle NewHandle = (LineHandle) m_Used;
00265     m_pLineArray[m_Used] = pItem;
00266     m_Used++;
00267 
00268 
00269     // --- And return the new handle
00270     return(NewHandle);
00271 }

void LineComponent::DeleteLineList void   )  [static, protected]
 

Static deinitialisation function, called on shutdown. Clears out the global Line list. Must be called when all users of the Line system (documents) have already been deleted.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99

Definition at line 178 of file linecomp.cpp.

00179 {
00180     if (m_pLineArray != NULL)
00181     {
00182         for (UINT32 i = 0; i < m_Used; i++)
00183         {
00184             if (m_pLineArray[i] != NULL)
00185                 delete m_pLineArray[i];
00186 
00187             m_pLineArray[i] = NULL;
00188         }
00189 
00190         CCFree(m_pLineArray);
00191         m_pLineArray = NULL;
00192     }
00193 }

static void LineComponent::DeleteList void   )  [inline, static]
 

Definition at line 170 of file linecomp.h.

00170 { DeleteLineList();}    

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

Called on completion of file export.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99
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 component was able to end the exporting; FALSE if not (e.g. out of memory)

Reimplemented from DocComponent.

Definition at line 388 of file linecomp.cpp.

00389 {
00390     BOOL ok = TRUE;
00391     TRACEUSER( "Diccon", _T("End Export Brush\n"));
00392 #if !defined(EXCLUDE_FROM_RALPH)
00393     if (pFilter == NULL)
00394     {
00395         ERROR3("LineComponent::EndExport filter is null!");
00396         return(ok);
00397     }
00398 
00399     if (!Success)       // If we failed to export, then return immediately
00400         return(ok);
00401 
00402 #endif
00403     return(ok);
00404 }

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

Called on completion of an import.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99
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)

Reimplemented from DocComponent.

Definition at line 366 of file linecomp.cpp.

00367 {
00368     return TRUE;
00369 }

BOOL LineComponent::EndImportLine CamelotRecordHandler pHandler  )  [inline]
 

Definition at line 201 of file linecomp.h.

00201 {return TRUE;}

virtual BOOL LineComponent::ExpandArray void   )  [protected, pure virtual]
 

Implemented in BrushComponent.

virtual BOOL LineComponent::ExportLine BaseCamelotFilter pFilter,
LineHandle  Handle
[pure virtual]
 

Implemented in BrushComponent.

virtual LineDefinition* LineComponent::FindDefinition UINT32  Handle,
BOOL  Dummy = FALSE
[virtual]
 

LineHandle LineComponent::FindImportedLine UINT32  ImportedHandle  ) 
 

To match up a handle from the currently importing file to the real internal LineHandle of the imported LineDefinition.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99
Parameters:
Importedhandle - The handle which is used in the file being imported [INPUTS] to reference the Line.
Returns:
The LineHandle of the loaded Line, or LineHandle_NoLine if the Line could not be found.

Definition at line 488 of file linecomp.cpp.

00489 {
00490     ImportedHandle &= 0x00ffffff;   // Only the bottom 24 bits are relevant
00491     for (UINT32 Index = 0; Index < m_Used; Index++)
00492     {
00493         if (m_pLineArray[Index] != NULL && m_pLineArray[Index]->ReadIOStore() == ImportedHandle)
00494             return((LineHandle)Index);
00495     }
00496 
00497     return(LineHandle_NoLine);
00498 }

UINT32 LineComponent::GetNumberOfLines  )  [inline]
 

Definition at line 182 of file linecomp.h.

00182 { return m_Used;}

virtual String_32 LineComponent::GetUniqueName String_32 pName = NULL  )  [pure virtual]
 

Implemented in BrushComponent.

BOOL LineComponent::NameIsUnique const String_32 NameString  )  [virtual]
 

To find out if someone has already gotten this name.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/7/2000
Parameters:
NameString - the string to test [INPUTS]
Returns:
TRUE if none of the definitions in the component have this string as their name, FALSE if one of them does

Reimplemented in BrushComponent.

Definition at line 516 of file linecomp.cpp.

00517 {
00518     ERROR3IF(NameString.IsEmpty(), "Empty string in LineComponent::NameIsUnique");
00519     
00520     BOOL Unique = TRUE;
00521     UINT32 Counter = 0;
00522     String_32* pDefName = NULL;
00523     LineDefinition* pDef = NULL;
00524     while (Counter < m_Used)
00525     {
00526         pDef = FindDefinition(Counter);
00527         if (pDef == NULL)
00528         {
00529             ERROR3("null brush definition in LineComponent::NameIsUnique");
00530             break;
00531         }
00532         pDefName = pDef->GetLineName();
00533         if( pDefName != NULL )
00534         {
00535             if (NameString == *pDefName)
00536             {
00537                 Unique = FALSE;
00538                 break;
00539             }
00540         }
00541         Counter++;
00542     }
00543     return Unique;
00544 
00545 }

virtual BOOL LineComponent::StartExport BaseCamelotFilter pFilter  )  [pure virtual]
 

Inform the document component that a WEb or Native export is about to start.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/5/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.

Implemented in BrushComponent.

BOOL LineComponent::StartImport BaseCamelotFilter pFilter  )  [virtual]
 

Called before we start to import a file.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99
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 324 of file linecomp.cpp.

00325 {
00326     if (pFilter == NULL)
00327     {
00328         ERROR3("LineComponent::StartImport filter is null!");
00329         return(TRUE);
00330     }
00331 
00332     // Set the IOStore in all the Lines to 0xffffffff. During import, this entry is used
00333     // to map imported handles to the real handles they have been assigned.
00334     if (m_pLineArray != NULL)
00335     {
00336         for (UINT32 Index = 0; Index < m_Used; Index++)
00337         {
00338             if (m_pLineArray[Index] != NULL)
00339                 m_pLineArray[Index]->SetIOStore(0xffffffff);
00340         }
00341     }
00342 
00343     return(TRUE);
00344 }

BOOL LineComponent::StartImportLine CamelotRecordHandler pHandler,
CXaraFileRecord pRecord
[static]
 

To import a vector Line definition.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99
Parameters:
pRecord - The TAG_LineDEFINITION record to import [INPUTS]
Returns:
TRUE if Import was successful

Definition at line 423 of file linecomp.cpp.

00424 {
00425     m_ImportHandle = 0xffffffff;
00426     m_ImportFlags  = 0;
00427     m_ImportData1  = 0;
00428     m_ImportData2  = 0;
00429     m_pImportPreviousContext = NULL;
00430     m_pImportNewLine = NULL;
00431 
00432     String_256 TempName;    // Load the name into a nice large safe buffer
00433 
00434     // Import the data from the record
00435     if (!pRecord->ReadUINT32(&m_ImportHandle) || !pRecord->ReadUINT32(&m_ImportFlags) ||
00436         !pRecord->ReadUINT32(&m_ImportData1) || !pRecord->ReadUINT32(&m_ImportData2))
00437     {
00438         return(FALSE);
00439     }
00440 
00441     // If there is a name to be imported, read it as well
00442     if ((m_ImportFlags & 0x200) != 0 && !pRecord->ReadUnicode(&TempName))
00443         return(FALSE);
00444 
00445     // We remember the imported flags and suchlike, which we will use in EndImportLine.
00446     TempName.Left((StringBase *)&m_ImportedName, 31);
00447 
00448     // Create a spread and set up the import system to import the brush into it
00449     // If this fails, then it'll just find somewhere "sensible" to import into
00450     m_pImportNewLine = new Spread;
00451     if (m_pImportNewLine == NULL)
00452         return(FALSE);
00453 
00454     Layer *pLineLayer = new Layer(m_pImportNewLine, FIRSTCHILD, String_256(TEXT("Jason did this")));
00455     if (pLineLayer == NULL)
00456     {
00457         delete m_pImportNewLine;
00458         m_pImportNewLine = NULL;
00459         return(FALSE);
00460     }
00461 
00462     // Now, remember where we were importing into, and point the importer at our brush tree
00463     m_pImportPreviousContext = pHandler->GetInsertContext();
00464     pHandler->SetInsertContextNode(pLineLayer);
00465     return(TRUE);
00466 }


Member Data Documentation

UINT32 LineComponent::m_CurrentSize = 0 [static, protected]
 

Definition at line 220 of file linecomp.h.

UINT32 LineComponent::m_ImportData1 = 0 [static, protected]
 

Definition at line 226 of file linecomp.h.

UINT32 LineComponent::m_ImportData2 = 0 [static, protected]
 

Definition at line 227 of file linecomp.h.

String_32 LineComponent::m_ImportedName [static, protected]
 

Definition at line 230 of file linecomp.h.

UINT32 LineComponent::m_ImportFlags = 0 [static, protected]
 

Definition at line 225 of file linecomp.h.

UINT32 LineComponent::m_ImportHandle = 0 [static, protected]
 

Definition at line 224 of file linecomp.h.

Node * LineComponent::m_pImportNewLine = NULL [static, protected]
 

Definition at line 229 of file linecomp.h.

InsertTreeContext * LineComponent::m_pImportPreviousContext = NULL [static, protected]
 

Definition at line 228 of file linecomp.h.

LineDefinition ** LineComponent::m_pLineArray = NULL [static, protected]
 

Definition at line 219 of file linecomp.h.

UINT32 LineComponent::m_Used = 0 [static, protected]
 

Definition at line 221 of file linecomp.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:55:57 2007 for Camelot by  doxygen 1.4.4