Styles Class Reference

This DocComponent is an abstract class for styles. I put it in 'cos someone's bound to come along and want the functionality of the derived class WizOpStyleComponent. More...

#include <styles.h>

Inheritance diagram for Styles:

DocComponent ListItem CCObject SimpleCCObject WizOpStyles List of all members.

Public Member Functions

virtual BOOL Init ()
 Default constructor would fail, so use an Init() if you don't want a lot of ERROR2's.
virtual StyleAddStyle (const Style &NewStyle)
 Adds the given style to this Styles collection, ensuring that there's only one with the style's name.
virtual BOOL MergeStyles (Styles &OtherStyles)
 Removes the styles in the given styles container and adds them to this one. Duplicates are ignored, so be careful.
virtual StyleIterator Begin () const
 Allows access to individual members of the Styles collection.
virtual const StyleIteratorEnd () const
 Allows access to individual members of the Styles collection.
virtual StyleFindStyleFromName (const StringBase &StyleName) const
 Adds the given style to this Styles collection, ensuring that there's only one with the style's name.
virtual BOOL StartComponentCopy ()
 This function gets called to prepare for an inter-document styles copy.
virtual BOOL EndComponentCopy ()
 Will commit all changes made by doing the component copy, returning TRUE. Any new colours will be inserted as instructed by the InsertBefore parameter. If some colours will not be insterted because they were merged, then a report to this effect can be given if desired.
virtual void AbortComponentCopy ()
 Will abort all changes made for component copies. This means that things such as the colours referenced by the nodes you have just copied do not exist, so you must clean up to the state the document was in before you strated copying.
virtual StyleCopyComponentData (const Style &NewStyle)
 In between StartComponentCopy() & EndComponentCopy() this function is called by StyleReferenceAttribute::CopyComponentData() to ensure that styles are merged between documents.
virtual ~Styles ()
 Clean up a colour list component's data structures - deletes the colour list.

Protected Member Functions

 Styles ()
 Default constructor would fail, so use an Init() if you don't want a lot of ERROR2's.
 Styles (const Styles &OtherStyles)
 Warns us that we've done a destructor but we haven't done either of these.
Stylesoperator= (const Styles &)
BOOL GenerateUniqueName (const StringBase &Prefix, StringBase *pResult)
 Scans the styles to determine if the suggested name is unique within this collection. If it is not, the name is altered (currently by removing the last 14 characters and appending a decimal number) to provide a unique name, which is returned in the supplied string.
BOOL NameExists (const StringBase &Name) const
 Tells us if the given name exists in this Styles collection or the Styles we're adding (cos we only want to eliminate duplicates when we're adding styles see).
void SendStylesChangeMessage ()
StyleContainerGetContainer () const
 The actual styles are held in an internal container. This member provides access to them.
StylesGetStylesToAdd () const
 During a component copy (or import) we have some styles to add at the end (although they maybe empty). This function provides access to them.

Protected Attributes

StylesExporterm_pCurrentExporter

Private Attributes

StyleContainerm_pStyleContainer
Stylesm_pStylesToAdd

Detailed Description

This DocComponent is an abstract class for styles. I put it in 'cos someone's bound to come along and want the functionality of the derived class WizOpStyleComponent.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/07/96
See also:
StyleComponentClass

Definition at line 186 of file styles.h.


Constructor & Destructor Documentation

Styles::~Styles  )  [virtual]
 

Clean up a colour list component's data structures - deletes the colour list.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Returns:
Errors: ENSURE if IndexedColour copying stuff has not been cleaned up (this will occur if End/AbortComponentCopy is not called after a component copy)
See also:
WizOpStyles

Definition at line 487 of file styles.cpp.

00488 {
00489     if (m_pCurrentExporter)
00490     {
00491         // This should have been deleted in EndExport()
00492         TRACE( _T("Styles::~Styles() - m_pCurrentExporter not gone"));
00493         delete m_pCurrentExporter;
00494         m_pCurrentExporter = NULL;
00495     }
00496 
00497     delete m_pStyleContainer;
00498     m_pStyleContainer = NULL;
00499 }

Styles::Styles  )  [protected]
 

Default constructor would fail, so use an Init() if you don't want a lot of ERROR2's.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97

Definition at line 447 of file styles.cpp.

00448 {
00449     m_pStyleContainer   = NULL;     // we'll fill this in in init()
00450     m_pCurrentExporter  = NULL;     // we create an exporter when we need one
00451     m_pStylesToAdd      = NULL;     // this is used during a Component Copy
00452 }

Styles::Styles const Styles OtherStyles  )  [protected]
 

Warns us that we've done a destructor but we haven't done either of these.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97

Definition at line 513 of file styles.cpp.

00514 {
00515     TRACE( _T("Styles - Copy constructor not implemented"));
00516 }


Member Function Documentation

void Styles::AbortComponentCopy  )  [virtual]
 

Will abort all changes made for component copies. This means that things such as the colours referenced by the nodes you have just copied do not exist, so you must clean up to the state the document was in before you strated copying.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Notes: May be called even if StartComponentCopy has not been called. May be called multiple times

See also:
WizOpStyles::EndComponentCopy; WizOpStyles::AbortComponentCopy; WizOpStyles::CopyColourAcross

Reimplemented from DocComponent.

Definition at line 858 of file styles.cpp.

00859 {
00860     delete m_pStylesToAdd;
00861     m_pStylesToAdd = NULL;
00862 }

Style * Styles::AddStyle const Style NewStyle  )  [virtual]
 

Adds the given style to this Styles collection, ensuring that there's only one with the style's name.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Parameters:
NewStyle - the style to add [INPUTS]
Returns:
A pointer to the style contained in this collection or NULL if it didn't work.

Definition at line 567 of file styles.cpp.

00568 {
00569     ENSURE_NOT_NULL(m_pStyleContainer);
00570 
00571     // Look for an existing one which we could return
00572     Style* pStyleToUse = FindStyleFromName(NewStyle.GetName());
00573     if (pStyleToUse == NULL)
00574     {
00575         // didn't find one so create a spanking new version
00576         Style* pNewStyleCopy = NewStyle.CreateCopy(NewStyle.GetName());
00577         if (pNewStyleCopy != NULL)
00578         {
00579             if (!GetContainer().AddStyle(*pNewStyleCopy))
00580             {
00581                 delete pNewStyleCopy;
00582                 pNewStyleCopy = NULL;
00583             }
00584         }
00585         pStyleToUse = pNewStyleCopy;
00586     }
00587 
00588     return pStyleToUse;
00589 }

StyleIterator Styles::Begin  )  const [virtual]
 

Allows access to individual members of the Styles collection.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Returns:
An iterator which will run through to the End() of the styles collection.

Definition at line 603 of file styles.cpp.

00604 {
00605     if (m_pStyleContainer != NULL)
00606     {
00607         return StyleIterator(*m_pStyleContainer, (StyleContainerItem*)(GetContainer().GetHead()));
00608     }
00609     else
00610     {
00611         StyleContainer  Container;
00612         return StyleIterator( Container, NULL );
00613     }
00614 }

Style * Styles::CopyComponentData const Style StyleToCopy  )  [virtual]
 

In between StartComponentCopy() & EndComponentCopy() this function is called by StyleReferenceAttribute::CopyComponentData() to ensure that styles are merged between documents.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Parameters:
The style that should be used by any reference. [INPUTS]
Returns:
The style that should be used by any reference.

Definition at line 759 of file styles.cpp.

00760 {
00761     // it would be helpful if one of these were set up in StartComponentCopy()
00762     ENSURE_NOT_NULL(m_pStylesToAdd);
00763 
00764     Style* pStyleToUse = NULL;      // return this
00765 
00766     // If we've already got a style of the same name 
00767     //  If the style definitions are the same then use the existing one
00768     //  If they're different, rename the style, and add it to the list to add at the end
00769 
00770     Style* pStyleToAdd = NULL;  // if any
00771     Style* const pExistingStyle = FindStyleFromName(StyleToCopy.GetName());
00772     if (pExistingStyle != NULL)
00773     {
00774         if (StyleToCopy == *pExistingStyle)
00775         {
00776             pStyleToUse = pExistingStyle;
00777         }
00778         else    // conflicting style names so create a new one
00779         {
00780             String_64 NewStyleName = StyleToCopy.GetName();
00781             GenerateUniqueName(NewStyleName, &NewStyleName);
00782             pStyleToAdd = StyleToCopy.CreateCopy(NewStyleName);
00783         }
00784     }
00785     else
00786     {
00787         // there was no existing style so add the style to the list of styles to add at the end
00788         pStyleToAdd = StyleToCopy.CreateCopy(StyleToCopy.GetName());
00789     }
00790 
00791     // We may need to add a new style to the list to merge at the end
00792     if (pStyleToAdd != NULL)
00793     {
00794         pStyleToUse = GetStylesToAdd().AddStyle(*pStyleToAdd);
00795         // AddStyle copies the one we give it, so delete it
00796         delete pStyleToAdd;
00797     }
00798 
00799     return pStyleToUse;
00800 }

const StyleIterator & Styles::End  )  const [virtual]
 

Allows access to individual members of the Styles collection.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Returns:
A reference to a constant iterator which marks the end of the collection

Definition at line 629 of file styles.cpp.

00630 {
00631     StyleContainer      Container;
00632     static const StyleIterator TheEnd( Container, NULL);
00633 
00634     return TheEnd;
00635 }

BOOL Styles::EndComponentCopy  )  [virtual]
 

Will commit all changes made by doing the component copy, returning TRUE. Any new colours will be inserted as instructed by the InsertBefore parameter. If some colours will not be insterted because they were merged, then a report to this effect can be given if desired.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Returns:
TRUE if it succeeded

Reimplemented from DocComponent.

Definition at line 819 of file styles.cpp.

00820 {
00821     // it would be helpful if one of these were set up in StartComponentCopy()
00822     // Unfortunately Undo'ing a Copy will just call this without a Start...we'll do nothing 
00823     // then
00824     if (m_pStylesToAdd != NULL)
00825     {
00826         MergeStyles(GetStylesToAdd());
00827         delete m_pStylesToAdd;
00828         m_pStylesToAdd = NULL;
00829 
00830         SendStylesChangeMessage();
00831     }
00832 
00833     return TRUE;
00834 }

Style * Styles::FindStyleFromName const StringBase StyleName  )  const [virtual]
 

Adds the given style to this Styles collection, ensuring that there's only one with the style's name.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Parameters:
NewStyle - the style to add [INPUTS]
Returns:
A pointer to the style contained in this collection or NULL if it didn't work.

Definition at line 653 of file styles.cpp.

00654 {
00655     ENSURE_NOT_NULL(m_pStyleContainer);
00656 
00657     Style* pStyleFound = NULL;  // return this
00658 
00659     StyleContainerItem* pCurrentStyle = (StyleContainerItem*)m_pStyleContainer->GetHead();
00660     while (pCurrentStyle != NULL && pStyleFound == NULL)
00661     {
00662         if (pCurrentStyle->GetStyle().GetName() == StyleName)
00663         {
00664             pStyleFound = &(pCurrentStyle->GetStyle());
00665         }
00666         else
00667         {
00668             pCurrentStyle = (StyleContainerItem*)m_pStyleContainer->GetNext(pCurrentStyle);
00669         }
00670     }
00671 
00672     return pStyleFound;
00673 }

BOOL Styles::GenerateUniqueName const StringBase Prefix,
StringBase pResult
[protected]
 

Scans the styles to determine if the suggested name is unique within this collection. If it is not, the name is altered (currently by removing the last 14 characters and appending a decimal number) to provide a unique name, which is returned in the supplied string.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from Jason (From code by Tim))
Date:
11/07/97 (16/12/94 (8/8/94))
Parameters:
pPrefix - Points to the suggested name for this style. [INPUTS]
pResult - is filled in with a unique name [OUTPUTS]
Returns:
TRUE if the pResult contains a different string from that supplied in pPrefix. (pResult will always contain a valid result, but checking this flag may save you the bother of copying the string over)
Notes: This method should only be called when importing or copying styles. Name matching is done using StringBase::IsIdentical, so see that method to determine the rules by which strings are matched

Definition at line 943 of file styles.cpp.

00944 {
00945     ENSURE_NOT_NULL(pResult);
00946 
00947     // Either the List is empty, or this name is unique, so return it (ensuring < 64 chars)
00948     Prefix.Left(pResult, pResult->MaxLength());
00949     if (!NameExists(*pResult))
00950     {
00951         return(FALSE);
00952     }
00953 
00954     Prefix.Left(pResult, pResult->MaxLength() - 14);                    // Copy into NewName, truncating
00955     INT32 PrefixLen = pResult->Length();
00956 
00957     LPTSTR pPrefixEnd = (TCHAR*)(*pResult);
00958     pPrefixEnd += PrefixLen;
00959 
00960     INT32 i = 2;
00961 
00962     do 
00963     {
00964         camSnprintf( pPrefixEnd, 256, _T(" %ld"), i++ );
00965     }
00966     while (NameExists(*pResult));
00967 
00968     return TRUE;
00969 }

StyleContainer & Styles::GetContainer  )  const [protected]
 

The actual styles are held in an internal container. This member provides access to them.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97

Definition at line 537 of file styles.cpp.

00538 {
00539     // This static dummy object is used for returning in the ERROR2 case
00540     // The original used to return a ptr to a local variable, which is a tad dangerous.
00541     // This solution is not ideal, because there's a permanent instance of an object
00542     // that will probably never be used.
00543     static StyleContainer Dummy;
00544 
00545     ERROR2IF(m_pStyleContainer == NULL, Dummy, "NULL Member");
00546 
00547     return *m_pStyleContainer;
00548 }

Styles & Styles::GetStylesToAdd  )  const [protected]
 

During a component copy (or import) we have some styles to add at the end (although they maybe empty). This function provides access to them.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Returns:
Errors: If you call this at the wrong time an ERROR2 will result.

Definition at line 879 of file styles.cpp.

00880 {
00881     // This static dummy object is used for returning in the ERROR2 case
00882     // The original used to return a ptr to a local variable, which is a tad dangerous.
00883     // This solution is not ideal, because there's a permanent instance of an object
00884     // that will probably never be used.
00885     static Styles Dummy;
00886 
00887     ERROR2IF(m_pStylesToAdd == NULL, Dummy, "NULL Member");
00888 
00889     return *m_pStylesToAdd;
00890 }

BOOL Styles::Init void   )  [virtual]
 

Default constructor would fail, so use an Init() if you don't want a lot of ERROR2's.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97

Reimplemented from SimpleCCObject.

Definition at line 466 of file styles.cpp.

00467 {
00468     m_pStyleContainer = new StyleContainer;
00469 
00470     return (m_pStyleContainer != NULL);
00471 }

BOOL Styles::MergeStyles Styles OtherStyles  )  [virtual]
 

Removes the styles in the given styles container and adds them to this one. Duplicates are ignored, so be careful.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Parameters:
OtherStyles - the styles to merge [INPUTS]
Returns:
TRUE if it worked

Definition at line 690 of file styles.cpp.

00691 {
00692     BOOL Ok = TRUE;
00693 
00694     StyleContainer& OtherContainer = OtherStyles.GetContainer();
00695     StyleContainer& ThisContainer = GetContainer();
00696 
00697     ListItem* pLink = OtherContainer.RemoveHead();
00698     while (pLink != NULL && Ok)
00699     {
00700         ThisContainer.AddTail(pLink);
00701 
00702         pLink = OtherContainer.RemoveHead();
00703     }
00704 
00705     return Ok;
00706 }

BOOL Styles::NameExists const StringBase Name  )  const [protected]
 

Tells us if the given name exists in this Styles collection or the Styles we're adding (cos we only want to eliminate duplicates when we're adding styles see).

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Parameters:
Name,: the name of the style we want to add [INPUTS]
Returns:
TRUE if there's a style in here with that Name, FALSE if not
Notes: Used by GenerateUniqueName() during ComponentCopy

Definition at line 910 of file styles.cpp.

00911 {
00912     return (FindStyleFromName(Name) != NULL || 
00913             GetStylesToAdd().FindStyleFromName(Name) != NULL);
00914 }

Styles & Styles::operator= const Styles  )  [protected]
 

Definition at line 518 of file styles.cpp.

00519 {
00520     TRACE( _T("Styles - Assignment operator not implemented"));
00521 
00522     return *this;
00523 }

void Styles::SendStylesChangeMessage  )  [protected]
 

Definition at line 973 of file styles.cpp.

00974 {
00975     PORTNOTETRACE("other","Styles::SendStylesChangeMessage - do nothing - using TemplateDialog");
00976 #ifndef EXCLUDE_FROM_XARALX
00977     if (MessageHandler::MessageHandlerExists(CC_RUNTIME_CLASS(TemplateDialog)))
00978     {
00979         BROADCAST_TO_CLASS(StylesMessage(*this), DialogOp);
00980     }
00981 #endif
00982 }

BOOL Styles::StartComponentCopy  )  [virtual]
 

This function gets called to prepare for an inter-document styles copy.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/07/97
Returns:
TRUE if it succeeded. FALSE if the copy must be aborted
See also:
WizOpStyles::EndComponentCopy; WizOpStyles::AbortComponentCopy; WizOpStyles::CopyComponentData

Reimplemented from DocComponent.

Definition at line 725 of file styles.cpp.

00726 {
00727     ERROR2IF(m_pStylesToAdd != NULL, FALSE, "Styles::StartComponentCopy() - Copy already in progress?\n");
00728 
00729     BOOL Ok = TRUE;
00730     
00731     m_pStylesToAdd = new Styles();
00732     Ok = (m_pStylesToAdd != NULL);
00733 
00734     if (Ok)
00735     {
00736         m_pStylesToAdd->Init();
00737     }
00738 
00739     return Ok;
00740 }


Member Data Documentation

StylesExporter* Styles::m_pCurrentExporter [protected]
 

Definition at line 223 of file styles.h.

StyleContainer* Styles::m_pStyleContainer [private]
 

Definition at line 225 of file styles.h.

Styles* Styles::m_pStylesToAdd [private]
 

Definition at line 228 of file styles.h.


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