TemplateAttribute Class Reference

This represents a TemplateOp/Argument/user-changable from the template file attribute. It will probably be superceded, but for now it's derived from AttrUser with a value of the form <InternalName>[/][;<Question>] Bring on the plug-in attributes I say. More...

#include <tmpltatr.h>

Inheritance diagram for TemplateAttribute:

AttrUser NodeAttribute NodeRenderable Node CCObject SimpleCCObject StyleReferenceAttribute List of all members.

Public Member Functions

 TemplateAttribute (const StringBase &ArgumentName=NullString, const StringBase &Question=NullString, const StringBase &Param=NullString)
 Default constructor for TemplateAttribute.
virtual NodeSimpleCopy ()
 See base class for details.
void CopyNodeContents (TemplateAttribute *pAttr)
 See base class for details.
virtual void PolyCopyNodeContents (NodeRenderable *pNodeCopy)
 Polymorphically copies the contents of this node to another.
virtual UINT32 GetAttrNameID ()
 Provides an attribute name for undo, etc.
virtual BOOL IsAnObjectName () const
virtual BOOL WritePreChildrenWeb (BaseCamelotFilter *pFilter)
 Writes the TemplateAttribute to the filter.
virtual AttributeIdentifier GetAttributeClassID () const
 Generates an AttributeIdentifier for this Attribute. Since the RuntimeClass is inadequate for dynamically generated Atrributes (read Nodes), we need to provide an ID that can be created dynamically too. This is what an AttributeIdentifier is supposed to be. In the case of a TemplateAttribute it returns a pointer to a template handler.
virtual VisibleAttributeCreateVisibleAttribute () const
 Creates a template attribute the user can play with. This is all wrong (arrggghh).
String_256 GetQuestion () const
 Retrieves the Question of this TemplateAttribute.
String_256 GetInternalName () const
 Retrieves the Internal Name of the WizOp associated with this TemplateAttribute.
String_256 GetParam () const
 Retrieves the Parameter that is given to the WizOp when it is invoked.
StringBaseGetUserName () const
BOOL SetWizOpNameAndParam (const StringBase &Name, const StringBase &Param)
 Sets the Key fields in UserAttribute from the WizOp name and Param.

Protected Attributes

BOOL m_fIsAnObjectName

Static Protected Attributes

static const TCHAR s_ParamDelimiter = TEXT('/')
static const String_8 s_TemplateKey = _T("WizOp")

Detailed Description

This represents a TemplateOp/Argument/user-changable from the template file attribute. It will probably be superceded, but for now it's derived from AttrUser with a value of the form <InternalName>[/][;<Question>] Bring on the plug-in attributes I say.

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

Definition at line 124 of file tmpltatr.h.


Constructor & Destructor Documentation

TemplateAttribute::TemplateAttribute const StringBase InternalName = NullString,
const StringBase Question = NullString,
const StringBase Param = NullString
 

Default constructor for TemplateAttribute.

Parameters:
InternalName [INPUTS] Question Param
Notes: Currently forms a UserAttribute with a LongKey of WizOp/Param

Definition at line 179 of file tmpltatr.cpp.

00182 {
00183     // Copy as much of the question as we can.
00184     SetWizOpNameAndParam(InternalName, Param);
00185 
00186     // Cache this test for faster Attribute gallery scans.
00187     m_fIsAnObjectName = (GetInternalName() == TA_NAME);
00188 
00189     if (Question.Length() > 0)
00190     {
00191         String_256 NewValue;
00192         INT32 LengthToCopy = (NewValue.MaxLength() < Question.Length())
00193                                 ? TRACE( _T("TemplateAttribute::TemplateAttribute: Q truncated\n")),
00194                                   NewValue.MaxLength()
00195                                 : Question.Length();
00196         if (LengthToCopy > 0)
00197         {
00198             String_256 TruncatedQuestion;
00199             Question.Left(&TruncatedQuestion, LengthToCopy);
00200 
00201             if (!Value.Value.Alloc(TruncatedQuestion.Length()))
00202             {
00203                 ERROR1RAW(_R(IDE_NOMORE_MEMORY));
00204                 return;
00205             }
00206 
00207             Value.Value = TruncatedQuestion;
00208         }
00209     }
00210 }


Member Function Documentation

void TemplateAttribute::CopyNodeContents TemplateAttribute pAttr  ) 
 

See base class for details.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/08/99

Definition at line 318 of file tmpltatr.cpp.

00319 {
00320     AttrUser::CopyNodeContents(pAttr);
00321     pAttr->m_fIsAnObjectName = m_fIsAnObjectName;
00322 }

VisibleAttribute * TemplateAttribute::CreateVisibleAttribute  )  const [virtual]
 

Creates a template attribute the user can play with. This is all wrong (arrggghh).

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/06/97
Returns:
A pointer to the UI equivalent of this attribute

Reimplemented from AttrUser.

Reimplemented in StyleReferenceAttribute.

Definition at line 494 of file tmpltatr.cpp.

00495 {
00496     VisibleAttribute* pVisibleAttribute = NULL; // return this
00497 
00498     WizOp* pHandler = GetWizOps().FindWizOpFromInternalName(GetInternalName());
00499 
00500     if (pHandler != NULL)
00501     {
00502         pVisibleAttribute = new VisibleTemplateAttribute(*pHandler, GetQuestion(), GetParam());
00503     }
00504 
00505     return pVisibleAttribute;
00506 }

AttributeIdentifier TemplateAttribute::GetAttributeClassID  )  const [virtual]
 

Generates an AttributeIdentifier for this Attribute. Since the RuntimeClass is inadequate for dynamically generated Atrributes (read Nodes), we need to provide an ID that can be created dynamically too. This is what an AttributeIdentifier is supposed to be. In the case of a TemplateAttribute it returns a pointer to a template handler.

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

Reimplemented from AttrUser.

Definition at line 462 of file tmpltatr.cpp.

00463 {
00464 #ifdef _DEBUG
00465     String_128          ConstructedKey( s_TemplateKey );
00466     ConstructedKey += s_KeyDelimiter;
00467     ConstructedKey += GetInternalName();
00468     if (!GetParam().IsEmpty())
00469     {
00470         ConstructedKey += s_ParamDelimiter;
00471         ConstructedKey += GetParam();
00472     }
00473     ERROR3IF(ConstructedKey != Value.LongKey,
00474                 "TemplateAttribute::GetAttributeClassID: ConstructedKey != LongKey");
00475 #endif
00476 
00477     return Value.LongKey;
00478 }

UINT32 TemplateAttribute::GetAttrNameID void   )  [virtual]
 

Provides an attribute name for undo, etc.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/06/97
Returns:
A resource id for "Wizard Property"

Reimplemented from AttrUser.

Reimplemented in StyleReferenceAttribute.

Definition at line 361 of file tmpltatr.cpp.

00362 {
00363     return _R(IDS_WIZOP);
00364 }

String_256 TemplateAttribute::GetInternalName  )  const
 

Retrieves the Internal Name of the WizOp associated with this TemplateAttribute.

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

Definition at line 521 of file tmpltatr.cpp.

00522 {
00523     String_256 Name;        // return this
00524     const StringBase& SourceString = Value.LongKey;
00525 
00526     // Find the bit after the WizOp key
00527     INT32 StartDelimiterPosition = SourceString.FindNextChar(s_KeyDelimiter);
00528 
00529     // Look for a parameter following
00530     INT32 EndDelimiterPosition = SourceString.FindNextChar(s_ParamDelimiter);
00531     if (EndDelimiterPosition < 0)
00532     {
00533         // there wasn't a parameter following so the delimiter is beyond the end of 
00534         // the string
00535         EndDelimiterPosition = SourceString.Length();
00536     }
00537 
00538     UINT32 LengthToCopy = EndDelimiterPosition - StartDelimiterPosition - 1;
00539     if (LengthToCopy > 0)
00540     {
00541         SourceString.Mid(&Name, StartDelimiterPosition + 1, LengthToCopy);
00542     }
00543     else
00544     {
00545         TRACE( _T("TemplateAttribute::GetInternalName - no name\n"));
00546     }
00547 
00548     return Name;
00549 }

String_256 TemplateAttribute::GetParam  )  const
 

Retrieves the Parameter that is given to the WizOp when it is invoked.

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

Definition at line 563 of file tmpltatr.cpp.

00564 {
00565     String_256 Param;       // return this
00566     const StringBase& SourceString = Value.LongKey;
00567 
00568     // find the start of the parameter string
00569     INT32 StartDelimiter = SourceString.FindNextChar(s_ParamDelimiter);
00570     if (StartDelimiter > 0)     
00571     {
00572         // We've found the start, the rest of the key is the parameter
00573         UINT32 LengthToCopy = SourceString.Length() - StartDelimiter - 1;
00574         if (LengthToCopy > 0)
00575         {
00576             SourceString.Mid(&Param, StartDelimiter + 1, LengthToCopy);
00577         }
00578         else
00579         {
00580             TRACE( _T("TemplateAttribute::GetParam - empty param\n"));
00581         }
00582     }
00583 
00584     return Param;
00585 }

String_256 TemplateAttribute::GetQuestion  )  const
 

Retrieves the Question of this TemplateAttribute.

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

Definition at line 598 of file tmpltatr.cpp.

00599 {
00600     String_256 Question;
00601     const StringBase& SourceString = Value.Value;
00602 
00603     UINT32 LengthToCopy = SourceString.Length() > Question.MaxLength() ? 
00604                                 Question.MaxLength() : 
00605                                 SourceString.Length();
00606 
00607     SourceString.Left(&Question, LengthToCopy);
00608     return Question;
00609 }

StringBase& TemplateAttribute::GetUserName  )  const
 

BOOL TemplateAttribute::IsAnObjectName  )  const [virtual]
 

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/09/99
Returns:
TRUE if this attribute has an 'ObjectName' key, FALSE if not.

Reimplemented from Node.

Definition at line 376 of file tmpltatr.cpp.

00377 {
00378     return m_fIsAnObjectName;
00379 }

void TemplateAttribute::PolyCopyNodeContents NodeRenderable pNodeCopy  )  [virtual]
 

Polymorphically copies the contents of this node to another.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/12/2003
Parameters:
- [OUTPUTS]
Returns:
Errors: An assertion failure will occur if NodeCopy is NULL Scope: protected

Reimplemented from AttrUser.

Definition at line 338 of file tmpltatr.cpp.

00339 {
00340     ENSURE(pNodeCopy, "Trying to copy a node's contents into a NULL node");
00341     ENSURE(IS_A(pNodeCopy, TemplateAttribute), "PolyCopyNodeContents given wrong dest node type");
00342 
00343     if (IS_A(pNodeCopy, TemplateAttribute))
00344         CopyNodeContents((TemplateAttribute*)pNodeCopy);
00345 }

BOOL TemplateAttribute::SetWizOpNameAndParam const StringBase InternalName,
const StringBase Param
 

Sets the Key fields in UserAttribute from the WizOp name and Param.

Parameters:
InternalName [INPUTS] Param
Notes: Currently forms a UserAttribute with a LongKey of WizOp/Param

Definition at line 229 of file tmpltatr.cpp.

00231 {
00232     BOOL NotTruncated = TRUE;       // return this
00233     String_128 NewLongKey(s_TemplateKey);
00234 
00235     if (InternalName.Length() > 0)
00236     {
00237         // Don't forget the delimiter
00238         INT32 SpaceFree = NewLongKey.MaxLength() - NewLongKey.Length() - 1;
00239 
00240         if (SpaceFree > 0)
00241         {
00242             NewLongKey += s_KeyDelimiter;
00243         }
00244 
00245         if (SpaceFree > 1)
00246         {
00247             String_128 TruncatedName;
00248             INT32 LengthToCopy = (SpaceFree < InternalName.Length()) ? SpaceFree : InternalName.Length();
00249             InternalName.Left(&TruncatedName, LengthToCopy);
00250             NewLongKey += TruncatedName;
00251         }
00252         else
00253         {
00254             NotTruncated = FALSE;
00255         }
00256     }
00257 
00258     if (Param.Length() > 0)
00259     {
00260         // Don't forget the delimiter
00261         INT32 SpaceFree = NewLongKey.MaxLength() - NewLongKey.Length() - 1;
00262 
00263         if (SpaceFree > 0)
00264         {
00265             NewLongKey += s_ParamDelimiter;
00266         }
00267 
00268         if (SpaceFree > 1)
00269         {
00270             String_256 TruncatedParam;
00271             INT32 LengthToCopy = (SpaceFree < Param.Length()) ? SpaceFree : Param.Length();
00272             Param.Left(&TruncatedParam, LengthToCopy);
00273             NewLongKey += TruncatedParam;
00274         }
00275         else
00276         {
00277             NotTruncated = FALSE;
00278         }
00279     }
00280 
00281     ERRORIF(!Value.Key.Alloc(s_TemplateKey.Length()), _R(IDE_NOMORE_MEMORY), FALSE);
00282     Value.Key = s_TemplateKey;
00283 
00284     ERRORIF(!Value.LongKey.Alloc(NewLongKey.Length()), _R(IDE_NOMORE_MEMORY), FALSE);
00285     Value.LongKey = NewLongKey;
00286 
00287     return NotTruncated;
00288 }

Node * TemplateAttribute::SimpleCopy void   )  [virtual]
 

See base class for details.

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

Reimplemented from AttrUser.

Reimplemented in StyleReferenceAttribute.

Definition at line 300 of file tmpltatr.cpp.

00301 {
00302     TemplateAttribute* pNodeCopy = new TemplateAttribute();
00303     ERRORIF(pNodeCopy == 0, _R(IDE_NOMORE_MEMORY), 0); 
00304     CopyNodeContents(pNodeCopy);
00305     return pNodeCopy;
00306 } 

BOOL TemplateAttribute::WritePreChildrenWeb BaseCamelotFilter pFilter  )  [virtual]
 

Writes the TemplateAttribute to the filter.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/06/97
Parameters:
pFilter = ptr to the filter [INPUTS]
Returns:
TRUE if record is written, FALSE if not

Reimplemented from AttrUser.

Reimplemented in StyleReferenceAttribute.

Definition at line 396 of file tmpltatr.cpp.

00397 {
00398 #ifdef DO_EXPORT
00399     ERROR2IF(pFilter == NULL,FALSE,"NULL filter param");
00400 
00401     // Add a description of the TAG_WIZOP record for older importers
00402     pFilter->AddTagDescription(TAG_WIZOP, _R(IDS_TAG_WIZOP));
00403 
00404     CamelotFileRecord Rec(pFilter, TAG_WIZOP, CXF_UNKNOWN_SIZE);
00405 
00406     BOOL ok = Rec.Init();
00407 
00408     if (ok)
00409     {
00410         String_64 InternalName = GetInternalName();
00411         ok = Rec.WriteUnicode((TCHAR*)InternalName);
00412     }
00413     if (ok)
00414     {
00415         String_256 Question = GetQuestion();
00416         ok = Rec.WriteUnicode((TCHAR*)Question);
00417     }
00418     if (ok)
00419     {
00420         String_64 Param = GetParam();
00421         ok = Rec.WriteUnicode((TCHAR*)Param);
00422     }
00423     if (ok)
00424     {
00425         // Write out some patch space
00426         String_8 NonConstNullString = NullString;
00427         ok = Rec.WriteUnicode((TCHAR*)NonConstNullString);
00428     }
00429 
00430     if (ok)
00431     {
00432         ok = pFilter->Write(&Rec);
00433     }
00434 
00435     if (!ok)
00436     {
00437         pFilter->GotError(_R(IDE_FILE_WRITE_ERROR));
00438     }
00439 
00440     return ok;
00441 #else
00442     return FALSE;
00443 #endif
00444 }


Member Data Documentation

BOOL TemplateAttribute::m_fIsAnObjectName [protected]
 

Definition at line 153 of file tmpltatr.h.

const TCHAR TemplateAttribute::s_ParamDelimiter = TEXT('/') [static, protected]
 

Definition at line 154 of file tmpltatr.h.

const String_8 TemplateAttribute::s_TemplateKey = _T("WizOp") [static, protected]
 

Definition at line 155 of file tmpltatr.h.


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