00001 // $Id: tmpltatr.cpp 1688 2006-08-10 12:05:20Z gerry $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 00099 /* 00100 */ 00101 00102 #include "camtypes.h" 00103 00104 //#include "attrval.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00105 //#include "nodeattr.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 #include "userattr.h" 00107 //#include "cxfrech.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00108 #include "tmpltatr.h" 00109 00110 #include "gadget.h" 00111 #include "uielem.h" 00112 #include "visiattr.h" // the visible bits 00113 00114 //#include "tmpltdlg.h" // for slight bodginess 00115 00116 //#include "camfiltr.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00117 #include "cxftags.h" 00118 //#include "cxfdefs.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00119 //#include "cxfrec.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00120 00121 #include "tmpltarg.h" // WizOp 00122 00123 //#include "mario.h" // for _R(IDE_NOMORE_MEMORY) 00124 #include "styles.h" 00125 //#include "tim.h" // for _R(IDE_FILE_WRITE_ERROR) 00126 //#include "tmpltres.h" // for _R(IDE_FILE_WRITE_ERROR) 00127 00128 #include "ngsentry.h" 00129 00130 #ifdef _DEBUG 00131 //#include "convert.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00132 #endif 00133 00134 DECLARE_SOURCE("$Revision: 1688 $"); 00135 00136 CC_IMPLEMENT_DYNAMIC(TemplateAttribute, AttrUser) 00137 CC_IMPLEMENT_MEMDUMP(VisibleTemplateAttribute, VisibleUserAttribute) 00138 CC_IMPLEMENT_DYNAMIC(TemplateAttrRecordHandler, CamelotRecordHandler) 00139 00140 CC_IMPLEMENT_MEMDUMP(StyleReferenceAttribute, TemplateAttribute) 00141 CC_IMPLEMENT_MEMDUMP(VisibleStyleReference, VisibleAttribute) 00142 CC_IMPLEMENT_DYNAMIC(WizOpStyleRefRecordHandler, CamelotRecordHandler) 00143 00144 00145 // Give this file in memory dumps 00146 // Declare smart memory handling in Debug builds 00147 #define new CAM_DEBUG_NEW 00148 00149 00150 00151 const String_8 NullString = TEXT(""); 00152 00153 const String_8 TemplateAttribute::s_TemplateKey = _T("WizOp"); 00154 const TCHAR TemplateAttribute::s_ParamDelimiter = TEXT('/'); 00155 00156 //const String_8 NameAttribute::NameKey = "Name"; 00157 00158 #define ENSURE_KIND(pInstance, Class) ERROR3IF(!pInstance->IS_KIND_OF(Class), #pInstance" is not kind of "#Class); 00159 00160 00161 /******************************************************************************************** 00162 00163 > TemplateAttribute::TemplateAttribute( const StringBase& InternalName, 00164 const StringBase& Question, 00165 const StringBase& Param) 00166 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00167 Created: 27/06/97 00168 00169 Purpose: Default constructor for TemplateAttribute 00170 00171 Inputs: InternalName 00172 Question 00173 Param 00174 00175 Notes: Currently forms a UserAttribute with a LongKey of 00176 WizOp\InternalName/Param 00177 00178 ********************************************************************************************/ 00179 TemplateAttribute::TemplateAttribute( const StringBase& InternalName, 00180 const StringBase& Question, 00181 const StringBase& Param) 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 } 00211 00212 00213 /******************************************************************************************** 00214 00215 > BOOL TemplateAttribute::SetWizOpNameAndParam( const StringBase& Name, 00216 const StringBase& Param) 00217 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00218 Created: 27/06/97 00219 00220 Purpose: Sets the Key fields in UserAttribute from the WizOp name and Param. 00221 00222 Inputs: InternalName 00223 Param 00224 00225 Notes: Currently forms a UserAttribute with a LongKey of 00226 WizOp\InternalName/Param 00227 00228 ********************************************************************************************/ 00229 BOOL TemplateAttribute::SetWizOpNameAndParam( const StringBase& InternalName, 00230 const StringBase& Param) 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 } 00289 00290 /*********************************************************************************************** 00291 00292 > Node* TemplateAttribute::SimpleCopy() 00293 00294 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00295 Created: 27/06/97 00296 00297 Purpose: See base class for details. 00298 00299 ***********************************************************************************************/ 00300 Node* TemplateAttribute::SimpleCopy() 00301 { 00302 TemplateAttribute* pNodeCopy = new TemplateAttribute(); 00303 ERRORIF(pNodeCopy == 0, _R(IDE_NOMORE_MEMORY), 0); 00304 CopyNodeContents(pNodeCopy); 00305 return pNodeCopy; 00306 } 00307 00308 00309 00310 /*********************************************************************************************** 00311 > void TemplateAttribute::CopyNodeContents(TemplateAttribute* pAttr) 00312 00313 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> 00314 Created: 27/08/99 00315 Purpose: See base class for details. 00316 ***********************************************************************************************/ 00317 00318 void TemplateAttribute::CopyNodeContents(TemplateAttribute* pAttr) 00319 { 00320 AttrUser::CopyNodeContents(pAttr); 00321 pAttr->m_fIsAnObjectName = m_fIsAnObjectName; 00322 } 00323 00324 00325 00326 /*********************************************************************************************** 00327 > void TemplateAttribute::PolyCopyNodeContents(NodeRenderable* pNodeCopy) 00328 00329 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00330 Created: 18/12/2003 00331 Outputs: - 00332 Purpose: Polymorphically copies the contents of this node to another 00333 Errors: An assertion failure will occur if NodeCopy is NULL 00334 Scope: protected 00335 00336 ***********************************************************************************************/ 00337 00338 void TemplateAttribute::PolyCopyNodeContents(NodeRenderable* pNodeCopy) 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 } 00346 00347 00348 00349 /******************************************************************************************** 00350 00351 > virtual UINT32 TemplateAttribute::GetAttrNameID() 00352 00353 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00354 Created: 27/06/97 00355 00356 Purpose: Provides an attribute name for undo, etc. 00357 00358 Returns: A resource id for "Wizard Property" 00359 00360 ********************************************************************************************/ 00361 UINT32 TemplateAttribute::GetAttrNameID() 00362 { 00363 return _R(IDS_WIZOP); 00364 } 00365 00366 00367 00368 /******************************************************************************************** 00369 > virtual BOOL TemplateAttribute::IsAnObjectName() const 00370 00371 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> 00372 Created: 26/09/99 00373 Returns: TRUE if this attribute has an 'ObjectName' key, FALSE if not. 00374 ********************************************************************************************/ 00375 00376 BOOL TemplateAttribute::IsAnObjectName() const 00377 { 00378 return m_fIsAnObjectName; 00379 } 00380 00381 00382 00383 /******************************************************************************************** 00384 00385 > virtual BOOL TemplateAttribute::WritePreChildrenWeb(BaseCamelotFilter* pFilter) 00386 00387 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00388 Created: 27/06/97 00389 00390 Purpose: Writes the TemplateAttribute to the filter 00391 00392 Inputs: pFilter = ptr to the filter 00393 Returns: TRUE if record is written, FALSE if not 00394 00395 ********************************************************************************************/ 00396 BOOL TemplateAttribute::WritePreChildrenWeb(BaseCamelotFilter* pFilter) 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 } 00445 00446 00447 /******************************************************************************************** 00448 00449 > virtual AttributeIdentifier TemplateAttribute::GetAttributeClassID() const 00450 00451 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00452 Created: 09/06/97 00453 00454 Purpose: Generates an AttributeIdentifier for this Attribute. 00455 Since the RuntimeClass is inadequate for dynamically generated Atrributes 00456 (read Nodes), we need to provide an ID that can be created dynamically too. 00457 This is what an AttributeIdentifier is supposed to be. 00458 In the case of a TemplateAttribute it returns a pointer to a template 00459 handler. 00460 00461 ********************************************************************************************/ 00462 AttributeIdentifier TemplateAttribute::GetAttributeClassID() const 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 } 00479 00480 00481 /******************************************************************************************** 00482 00483 > VisibleAttribute* TemplateAttribute::CreateVisibleAttribute() const 00484 00485 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00486 Created: 09/06/97 00487 00488 Purpose: Creates a template attribute the user can play with. This is all wrong 00489 (arrggghh) 00490 00491 Returns: A pointer to the UI equivalent of this attribute 00492 00493 ********************************************************************************************/ 00494 VisibleAttribute* TemplateAttribute::CreateVisibleAttribute() const 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 } 00507 00508 00509 00510 /******************************************************************************************** 00511 00512 > String_256 TemplateAttribute::GetInternalName() const 00513 00514 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00515 Created: 09/06/97 00516 00517 Purpose: Retrieves the Internal Name of the WizOp associated with this 00518 TemplateAttribute. 00519 00520 ********************************************************************************************/ 00521 String_256 TemplateAttribute::GetInternalName() const 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 } 00550 00551 00552 00553 /******************************************************************************************** 00554 00555 > String_256 TemplateAttribute::GetParam() const 00556 00557 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00558 Created: 09/06/97 00559 00560 Purpose: Retrieves the Parameter that is given to the WizOp when it is invoked. 00561 00562 ********************************************************************************************/ 00563 String_256 TemplateAttribute::GetParam() const 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 } 00586 00587 00588 /******************************************************************************************** 00589 00590 > String_256 TemplateAttribute::GetQuestion() const 00591 00592 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00593 Created: 09/06/97 00594 00595 Purpose: Retrieves the Question of this TemplateAttribute 00596 00597 ********************************************************************************************/ 00598 String_256 TemplateAttribute::GetQuestion() const 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 } 00610 00611 00612 //--------------------------------------------------------------------------------------- 00613 //--------------------------------------------------------------------------------------- 00614 //--------------------------------------------------------------------------------------- 00615 00616 /******************************************************************************************** 00617 00618 > virtual UINT32* TemplateAttrRecordHandler::GetTagList() 00619 00620 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00621 Created: 27/06/97 00622 00623 Purpose: Provides the record handler system with a list of records handled by this 00624 handler 00625 00626 Returns: Ptr to a list of tag values, terminated by CXFRH_TAG_LIST_END 00627 00628 Notes: Don't ever extend this. Derive a class from it. See GeneralAttrRecordHandler 00629 for how not to do it. 00630 00631 ********************************************************************************************/ 00632 UINT32* TemplateAttrRecordHandler::GetTagList() 00633 { 00634 static const UINT32 TagList[] = { TAG_WIZOP, CXFRH_TAG_LIST_END}; 00635 00636 return (UINT32*)&TagList; 00637 } 00638 00639 /******************************************************************************************** 00640 00641 > virtual BOOL TemplateAttrRecordHandler::HandleRecord(CXaraFileRecord* pCXaraFileRecord) 00642 00643 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00644 Created: 27/06/97 00645 00646 Purpose: Handles the given TAG_WIZOP record. 00647 00648 Inputs: pCXaraFileRecord = ptr to record to handle 00649 00650 Returns: TRUE if handled successfuly 00651 FALSE otherwise 00652 00653 Errors: If pCXaraFileRecord isn't a TAG_WIZOP record 00654 00655 ********************************************************************************************/ 00656 BOOL TemplateAttrRecordHandler::HandleRecord(CXaraFileRecord* pRecord) 00657 { 00658 ERROR2IF(pRecord == NULL,FALSE,"pCXaraFileRecord is NULL"); 00659 ERROR2IF(pRecord->GetTag() != TAG_WIZOP, FALSE, "I don't handle this tag type"); 00660 00661 String_64 OpName; 00662 String_256 Question; 00663 String_256 Param; 00664 String_256 PatchSpace; 00665 00666 BOOL ok = pRecord->ReadUnicode(OpName, 64); 00667 00668 if (ok) 00669 { 00670 ok = pRecord->ReadUnicode(Question, 256); 00671 } 00672 00673 if (ok) 00674 { 00675 ok = pRecord->ReadUnicode(Param, 256); 00676 } 00677 00678 if (ok) 00679 { 00680 ok = pRecord->ReadUnicode(PatchSpace, 256); 00681 } 00682 00683 BaseCamelotFilter* pFilter = GetBaseCamelotFilter(); 00684 if (ok) 00685 { 00686 NodeSetSentinel * pNodeSetSentinel = pFilter->GetDocument()->GetSetSentinel(); 00687 00688 if (pNodeSetSentinel) 00689 { 00690 Node * pContextNode = pFilter->GetInsertContextNode(); 00691 00692 // dont add the attrib if it is a duplicate and it is in the sentinel 00693 if ((pNodeSetSentinel != pContextNode->FindParent() && 00694 pNodeSetSentinel != pContextNode ) || 00695 SliceHelper::LookupNameGalleryItem(Param) == NULL) 00696 { 00697 // We managed to read it all OK so add a new TemplateAttribute to the tree 00698 TemplateAttribute* pNewAttribute = new TemplateAttribute(OpName, Question, Param); 00699 ok = (pNewAttribute != 0) && InsertNode(pNewAttribute); 00700 00701 // JCF: Web files don't include records for the NodeSetSentinel or its child 00702 // ObjectName attributes, so make sure that a copy of the TemplateAttribute 00703 // is inserted as a child of the sentinel as well, if there isn't one already 00704 // in place. 00705 if (ok && pNewAttribute->IsAnObjectName()) 00706 { 00707 // Register/insert the imported ObjectName with the doc's NodeSetSentinel. 00708 ok = pNodeSetSentinel->OnLoadName(pFilter, pNewAttribute); 00709 } 00710 } 00711 } 00712 } 00713 00714 if (!ok) 00715 { 00716 ENSURE_NOT_NULL(pFilter); 00717 pFilter->GotError(_R(IDE_FILE_READ_ERROR)); 00718 } 00719 00720 return ok; 00721 } 00722 00723 00724 /******************************************************************************************** 00725 00726 > virtual void TemplateAttrRecordHandler::GetRecordDescriptionText( 00727 CXaraFileRecord* pRecord, StringBase* pStr) 00728 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00729 Created: 27/06/97 00730 00731 Purpose: Debug function that provides descriptions for TemplateAttribute (WizOp) records. 00732 00733 Inputs: pRecord = ptr to a record 00734 pStr = ptr to string to update 00735 00736 ********************************************************************************************/ 00737 #ifdef XAR_TREE_DIALOG 00738 void TemplateAttrRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord,StringBase* pStr) 00739 { 00740 if (pStr == NULL || pRecord == NULL) 00741 { 00742 TRACE( _T("TemplateAttrRecordHandler::GetRecordDescriptionText - NULL Args\n")); 00743 return; 00744 } 00745 if (pRecord->GetTag() != TAG_WIZOP) 00746 { 00747 TRACE( _T("TemplateAttrRecordHandler::GetRecordDescriptionText - Incorrect record\n")); 00748 return; 00749 } 00750 00751 // Call base class first 00752 CamelotRecordHandler::GetRecordDescriptionText(pRecord, pStr); 00753 00754 TCHAR OpName[64] = {0}; 00755 TCHAR Question[256] = {0}; 00756 TCHAR Param[256] = {0}; 00757 TCHAR Patch[256] = {0}; 00758 00759 BOOL ok = pRecord->ReadUnicode(OpName, 64); 00760 00761 if (ok) 00762 { 00763 *pStr += TEXT("OpName = "); 00764 *pStr += OpName; 00765 00766 ok = pRecord->ReadUnicode(Question, 256); 00767 } 00768 00769 if (ok) 00770 { 00771 *pStr += TEXT("\r\nQuestion = "); 00772 *pStr += Question; 00773 00774 ok = pRecord->ReadUnicode(Param, 256); 00775 } 00776 00777 if (ok) 00778 { 00779 *pStr += TEXT("\r\nParam = "); 00780 *pStr += Param; 00781 00782 ok = pRecord->ReadUnicode(Patch, 256); 00783 } 00784 00785 if (ok) 00786 { 00787 *pStr += TEXT("\r\nPatch = "); 00788 *pStr += Patch; 00789 } 00790 } 00791 00792 00793 /******************************************************************************************** 00794 00795 > virtual void TemplateAttrRecordHandler::GetTagText(UINT32 Tag,String_256& Str) 00796 00797 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00798 Created: 27/06/97 00799 00800 Purpose: A debug function that gives the tag description. 00801 00802 Inputs: Tag = the tag value 00803 Outputs: Str = place to put textual description of the tag 00804 00805 ********************************************************************************************/ 00806 void TemplateAttrRecordHandler::GetTagText(UINT32 Tag,String_256& Str) 00807 { 00808 Str = TEXT("TAG_WIZOP"); 00809 } 00810 #endif // _DEBUG 00811 00812 00813 00814 00815 00816 00817 00818 00819 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00820 // V I S I B L E T E M P L A T E A T T R I B U T E 00821 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00822 00823 00824 00825 00826 00827 00828 00829 /******************************************************************************************** 00830 00831 > VisibleTemplateAttribute::VisibleTemplateAttribute( const WizOp& Handler, 00832 const StringBase& Question, 00833 const StringBase& Param) 00834 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00835 Created: 27/06/97 00836 00837 Purpose: Constructor to ensure the data members are set up correctly. 00838 00839 Inputs: Handler: The WizOp that makes this VisibleTemplateAttribute changeable. 00840 Question: The question to ask when changing the attribute 00841 Param: Any parameter the WizOp may have. 00842 00843 ********************************************************************************************/ 00844 VisibleTemplateAttribute::VisibleTemplateAttribute( const WizOp& Handler, 00845 const StringBase& Question, 00846 const StringBase& Param) : 00847 VisibleUserAttribute(NullString, NullString), 00848 m_Handler(Handler) 00849 { 00850 // do something here so it can create its text 00851 00852 SetLongKey(Param); 00853 SetValue(Question); 00854 } 00855 00856 00857 /******************************************************************************************** 00858 00859 > StringBase& VisibleTemplateAttribute::GetText(StringBase& Description) const; 00860 00861 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00862 Created: 09/06/97 00863 00864 Purpose: Gives the user something to chew on in the "Used Properties" list of the 00865 Wizard Properties dialog. 00866 00867 Returns: A string 00868 00869 ********************************************************************************************/ 00870 StringBase& VisibleTemplateAttribute::GetText(StringBase& Description) const 00871 { 00872 Description = m_Handler.GetUserName(); 00873 return Description; 00874 } 00875 00876 00877 /******************************************************************************************** 00878 00879 > virtual BOOL VisibleTemplateAttribute::Display(DialogOp& Dialog) 00880 00881 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00882 Created: 09/06/97 00883 00884 Purpose: Lets the user see the contents of this VisibleTemplateAttribute on the given 00885 dialog. 00886 Overrides the base class to provide a param hint 00887 00888 See Also: VisibleUserAttribute::Display() 00889 00890 00891 ********************************************************************************************/ 00892 BOOL VisibleTemplateAttribute::Display(DialogOp& Dialog) 00893 { 00894 SetParamHint( GetWizOp().GetParamHint() ); 00895 // bodgy bit this... 00896 BOOL fOk = GetParamHint().Display( Dialog ); 00897 00898 if( fOk ) 00899 { 00900 fOk = VisibleUserAttribute::Display(Dialog); 00901 } 00902 00903 return fOk; 00904 } 00905 00906 00907 /******************************************************************************************** 00908 00909 > virtual BOOL VisibleTemplateAttribute::Interact(DialogOp& Dialog) 00910 00911 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00912 Created: 09/06/97 00913 00914 Purpose: This allows the user to change this VisibleTemplateAttribute 00915 00916 00917 ********************************************************************************************/ 00918 BOOL VisibleTemplateAttribute::Interact(DialogOp& Dialog) 00919 { 00920 PORTNOTETRACE("other","TemplateAttribute::Interact - do nothing"); 00921 #ifndef EXCLUDE_FROM_XARALX 00922 ERROR3IF(!((&Dialog)->IS_KIND_OF(TemplateDialog)), "Dialog isn't kind of TemplateDialog"); 00923 00924 TemplateDialog& BetterBeThisDialog = (TemplateDialog&)Dialog; 00925 00926 // if there's a parameter hint, then let them edit the parameter 00927 // we'll blam 'em with an error message if they give us a duplicate 00928 if (IsNew() && !GetWizOp().GetParamHint().IsEmpty()) 00929 { 00930 BetterBeThisDialog.GetParamHintControl().Enable(); 00931 BetterBeThisDialog.GetKeyControl().Enable(); 00932 } 00933 00934 // always let them change the question 00935 BetterBeThisDialog.GetValueControl().Enable(); 00936 #endif 00937 return TRUE; 00938 } 00939 00940 00941 /******************************************************************************************** 00942 00943 > virtual void VisibleTemplateAttribute::Hide() 00944 00945 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00946 Created: 09/06/97 00947 00948 Purpose: Hides this VisibleTemplateAttribute from the user. 00949 Overrides the base class to hide the param hint 00950 00951 See Also: VisibleUserAttribute::Hide() 00952 00953 ********************************************************************************************/ 00954 void VisibleTemplateAttribute::Hide() 00955 { 00956 GetParamHint().Hide(); 00957 00958 VisibleUserAttribute::Hide(); 00959 } 00960 00961 00962 /******************************************************************************************** 00963 00964 > virtual NodeAttribute* VisibleTemplateAttribute::CreateNewAttribute() 00965 00966 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00967 Created: 09/06/97 00968 00969 Purpose: Creates a new used property. 00970 00971 Returns: A new AttrUser 00972 00973 ********************************************************************************************/ 00974 NodeAttribute* VisibleTemplateAttribute::CreateNewAttribute() 00975 { 00976 return new TemplateAttribute( m_Handler.GetInternalName(), GetValue(), GetLongKey() ); 00977 } 00978 00979 00980 00981 const WizOp& VisibleTemplateAttribute::GetWizOp() 00982 { 00983 return m_Handler; 00984 } 00985 00986 00987 void VisibleTemplateAttribute::SetParamHint(const StringBase& HintToShow) 00988 { 00989 m_ParamHint = HintToShow; 00990 } 00991 00992 00993 VisibleLabel& VisibleTemplateAttribute::GetParamHint() 00994 { 00995 return m_ParamHint; 00996 } 00997 00998 00999 01000 01001 01002 01003 01004 01005 01006 01007 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 01008 // S T Y L E R E F E R E N C E A T T R I B U T E 01009 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 01010 01011 01012 01013 01014 01015 01016 01017 /******************************************************************************************** 01018 01019 > StyleReferenceAttribute::StyleReferenceAttribute(const WizOpStyle& Style) 01020 01021 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01022 Created: 27/06/97 01023 01024 Purpose: Constructor ensures this attribute actually references a style 01025 01026 ********************************************************************************************/ 01027 StyleReferenceAttribute::StyleReferenceAttribute(const WizOpStyle& Style) 01028 { 01029 SetWizOpNameAndParam( Style.GetWizOp().GetInternalName(), Style.GetParam() ); 01030 SetStyle( Style ); 01031 } 01032 01033 01034 /******************************************************************************************** 01035 01036 > Node* StyleReferenceAttribute::SimpleCopy() 01037 01038 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01039 Created: 27/06/97 01040 01041 Purpose: Creates a new copy of this StyleReferenceAttribute 01042 01043 Returns: A new Node 01044 01045 ********************************************************************************************/ 01046 Node* StyleReferenceAttribute::SimpleCopy() 01047 { 01048 ENSURE_NOT_NULL(Value.m_pStyle); 01049 ENSURE_KIND(Value.m_pStyle, WizOpStyle); 01050 01051 WizOpStyle& TrueStyle = (WizOpStyle&)*Value.m_pStyle; 01052 StyleReferenceAttribute* pNodeCopy = new StyleReferenceAttribute(TrueStyle); 01053 01054 ERRORIF(pNodeCopy == NULL, _R(IDE_NOMORE_MEMORY), NULL); 01055 01056 CopyNodeContents(pNodeCopy); 01057 01058 return pNodeCopy; 01059 } 01060 01061 01062 /******************************************************************************************** 01063 01064 > virtual UINT32 StyleReferenceAttribute::GetAttrNameID() 01065 01066 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01067 Created: 27/06/97 01068 01069 Purpose: Provides an attribute name for undo, etc. 01070 01071 Returns: A resource id for "Wizard Style Reference" 01072 01073 ********************************************************************************************/ 01074 UINT32 StyleReferenceAttribute::GetAttrNameID() 01075 { 01076 return _R(IDS_WIZOP_STYLEREF); 01077 } 01078 01079 01080 /******************************************************************************************** 01081 01082 > virtual BOOL StyleReferenceAttribute::CopyComponentData(BaseDocument* pSrcDoc, 01083 BaseDocument* pTargetDoc) 01084 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01085 Created: 09/06/97 01086 01087 Purpose: Ensures that the style to which this refers is in the target document. 01088 01089 Inputs: pSrcDoc: The document from where this node was copied 01090 pTargetDoc: The document where this node lives 01091 01092 Returns: FALSE if unable to copy data 01093 01094 SeeAlso: NodeAttribute::CopyComponentData 01095 01096 ********************************************************************************************/ 01097 BOOL StyleReferenceAttribute::CopyComponentData(BaseDocument* pSourceDoc, 01098 BaseDocument* pTargetDoc) 01099 { 01100 ENSURE_NOT_NULL(Value.m_pStyle); 01101 01102 ENSURE_NOT_NULL(pSourceDoc); 01103 ENSURE_NOT_NULL(pTargetDoc); 01104 01105 // Ask the base class to copy its data 01106 BOOL Ok = TemplateAttribute::CopyComponentData(pSourceDoc, pTargetDoc); 01107 01108 // Get the style in our document 01109 WizOpStyles* pTargetStyles = NULL; 01110 01111 if (Ok) 01112 { 01113 pTargetStyles = GetStylesForDoc(*pTargetDoc); 01114 01115 Ok = (pTargetStyles != NULL); 01116 } 01117 01118 if (Ok) 01119 { 01120 // Attempt to add the style that was in the old (source) document and to which this 01121 // StyleReferenceAttribute currently refers, to the new (target) document 01122 01123 // If the new document already has a style of the same name, but different 01124 // characteristics it will return a style with a different name, which we will need 01125 // to use as our reference. 01126 ENSURE_KIND(Value.m_pStyle, WizOpStyle); 01127 const WizOpStyle& SourceStyle = (WizOpStyle&)*Value.m_pStyle; 01128 01129 WizOpStyle* const pTargetStyle = (WizOpStyle*)pTargetStyles->CopyComponentData(SourceStyle); 01130 if (pTargetStyle != NULL) 01131 { 01132 SetStyle(*pTargetStyle); 01133 } 01134 else 01135 { 01136 Ok = FALSE; 01137 } 01138 } 01139 01140 return Ok; 01141 } 01142 01143 01144 01145 /******************************************************************************************** 01146 01147 > virtual BOOL StyleReferenceAttribute::WritePreChildrenWeb(BaseCamelotFilter* pFilter) 01148 01149 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01150 Created: 09/06/97 01151 01152 Purpose: Writes this StyleReferenceAttribute via the given filter. 01153 01154 Inputs: pFilter: The filter to use 01155 01156 Returns: FALSE if it failed 01157 01158 Notes: this StyleReferenceAttribute attempts to write the referenced style out 01159 first. 01160 01161 ********************************************************************************************/ 01162 BOOL StyleReferenceAttribute::WritePreChildrenWeb(BaseCamelotFilter* pFilter) 01163 { 01164 #ifdef DO_EXPORT 01165 ENSURE_NOT_NULL(Value.m_pStyle); 01166 01167 ERROR2IF(pFilter == NULL,FALSE,"NULL filter param"); 01168 01169 // Must write out the style first 01170 ENSURE_KIND(Value.m_pStyle, WizOpStyle); 01171 const WizOpStyle& ActualStyle = (WizOpStyle&)*Value.m_pStyle; 01172 01173 WizOpStyles* const pStyles = GetStylesForFilter(*pFilter); 01174 BOOL Ok = (pStyles != NULL); 01175 01176 XFileRef RecordRef = 0; 01177 if (Ok) 01178 { 01179 RecordRef = pStyles->GetRecordRefForStyle(ActualStyle); 01180 01181 // Is the style reference ok? 01182 Ok = (RecordRef != 0); 01183 } 01184 01185 if (Ok) 01186 { 01187 // Add a description of the TAG_WIZOP_STYLEREF record for older importers 01188 pFilter->AddTagDescription(TAG_WIZOP_STYLEREF, _R(IDS_TAG_WIZOP_STYLEREF)); 01189 } 01190 01191 if (Ok) 01192 { 01193 CamelotFileRecord Rec(pFilter, TAG_WIZOP_STYLEREF, TAG_WIZOP_STYLEREF_SIZE); 01194 01195 if (Ok) Ok = Rec.Init(); 01196 if (Ok) Ok = Rec.WriteReference(RecordRef); 01197 if (Ok) Ok = pFilter->Write(&Rec); 01198 } 01199 01200 if (!Ok) 01201 pFilter->GotError(_R(IDE_FILE_WRITE_ERROR)); 01202 01203 return Ok; 01204 #else 01205 return FALSE; 01206 #endif 01207 } 01208 01209 01210 /******************************************************************************************** 01211 01212 > virtual VisibleAttribute* StyleReferenceAttribute::CreateVisibleAttribute() const 01213 01214 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01215 Created: 09/06/97 01216 01217 Purpose: Creates the user with something to look at in the Wizard Properties dialog 01218 01219 Returns: A pointer to a new VisibleStyleReference (or NULL if not) 01220 01221 ********************************************************************************************/ 01222 VisibleAttribute* StyleReferenceAttribute::CreateVisibleAttribute() const 01223 { 01224 ENSURE_NOT_NULL(Value.m_pStyle); 01225 ENSURE_KIND(Value.m_pStyle, WizOpStyle); 01226 const WizOpStyle& ActualStyle = (WizOpStyle&)*Value.m_pStyle; 01227 01228 return new VisibleStyleReference(ActualStyle); 01229 } 01230 01231 01232 /******************************************************************************************** 01233 01234 > BOOL StyleReferenceAttribute::SetStyle(const Style& StyleToReference) 01235 01236 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01237 Created: 09/06/97 01238 01239 Purpose: When the component copy does it's stuff it sometimes needs to change the 01240 reference. This member is for that purpose. 01241 01242 Inputs: StyleToReference The Style to which this StyleReferenceAttribute refers 01243 Returns: TRUE 01244 01245 ********************************************************************************************/ 01246 BOOL StyleReferenceAttribute::SetStyle(const Style& StyleToReference) 01247 { 01248 Value.m_pStyle = &StyleToReference; 01249 return TRUE; 01250 } 01251 01252 01253 /******************************************************************************************** 01254 01255 > const StringBase& StyleReferenceAttribute::GetStyleName() const 01256 01257 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01258 Created: 09/06/97 01259 01260 Purpose: Support function to get the name of the referred style. 01261 01262 Returns: A string for the referred style's name. 01263 01264 ********************************************************************************************/ 01265 const StringBase& StyleReferenceAttribute::GetStyleName() const 01266 { 01267 STRING_ENSURE_NOT_NULL(Value.m_pStyle); 01268 return Value.m_pStyle->GetName(); 01269 } 01270 01271 01272 /******************************************************************************************** 01273 01274 > WizOpStyles* StyleReferenceAttribute::GetStylesForFilter(BaseCamelotFilter& Filter) const 01275 01276 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01277 Created: 09/06/97 01278 01279 Purpose: Support function to get the styles for the exporting document 01280 01281 Returns: Some WizOpStyles (or NULL) 01282 01283 ********************************************************************************************/ 01284 WizOpStyles* StyleReferenceAttribute::GetStylesForFilter(BaseCamelotFilter& Filter) const 01285 { 01286 WizOpStyles* pStyles = NULL; 01287 01288 BaseDocument* const pDoc = Filter.GetDocument(); 01289 if (pDoc != NULL) 01290 { 01291 pStyles = GetStylesForDoc(*pDoc); 01292 } 01293 01294 return pStyles; 01295 } 01296 01297 01298 /******************************************************************************************** 01299 01300 > WizOpStyles* StyleReferenceAttribute::GetStylesForFilter(BaseCamelotFilter& Filter) const 01301 01302 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01303 Created: 09/06/97 01304 01305 Purpose: Support function to get the styles for the given document 01306 01307 Returns: Some WizOpStyles (or NULL) 01308 01309 ********************************************************************************************/ 01310 WizOpStyles* StyleReferenceAttribute::GetStylesForDoc(BaseDocument& Doc) const 01311 { 01312 return (WizOpStyles*)Doc.GetDocComponent( CC_RUNTIME_CLASS(WizOpStyles) ); 01313 } 01314 01315 01316 01317 //--------------------------------------------------------------------------------------- 01318 //--------------------------------------------------------------------------------------- 01319 //--------------------------------------------------------------------------------------- 01320 01321 01322 01323 /******************************************************************************************** 01324 01325 > virtual UINT32* WizOpStyleRefRecordHandler::GetTagList() 01326 01327 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01328 Created: 27/06/97 01329 01330 Purpose: Provides the record handler system with a list of records handled by this 01331 handler 01332 01333 Returns: Ptr to a list of tag values, terminated by CXFRH_TAG_LIST_END 01334 01335 Notes: Don't ever extend this. Derive a class from it. See GeneralAttrRecordHandler 01336 for how not to do it. 01337 01338 ********************************************************************************************/ 01339 UINT32* WizOpStyleRefRecordHandler::GetTagList() 01340 { 01341 static const UINT32 TagList[] = { TAG_WIZOP_STYLEREF, CXFRH_TAG_LIST_END}; 01342 01343 return (UINT32*)&TagList; 01344 } 01345 01346 01347 /******************************************************************************************** 01348 01349 > virtual BOOL WizOpStyleRefRecordHandler::Init(BaseCamelotFilter* pFilter) 01350 01351 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01352 Created: 10/07/97 01353 01354 Purpose: Initialises the WizOpStyleRecordHandler 01355 01356 Returns: TRUE if ok 01357 FALSE otherwise 01358 01359 ********************************************************************************************/ 01360 BOOL WizOpStyleRefRecordHandler::Init(BaseCamelotFilter* pFilter) 01361 { 01362 BOOL Ok = TRUE; 01363 01364 Ok = CamelotRecordHandler::Init(pFilter); 01365 01366 Document* const pDoc = GetDocument(); 01367 Ok = (pDoc != NULL); 01368 01369 if (Ok) 01370 { 01371 m_pStyleComponent = (WizOpStyles*)pDoc->GetDocComponent( CC_RUNTIME_CLASS(WizOpStyles) ); 01372 Ok = (m_pStyleComponent != NULL); 01373 } 01374 01375 return Ok; 01376 } 01377 01378 01379 /******************************************************************************************** 01380 01381 > virtual BOOL WizOpStyleRefRecordHandler::HandleRecord(CXaraFileRecord* pRecord) 01382 01383 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01384 Created: 27/06/97 01385 01386 Purpose: Handles the given TAG_WIZOP record. 01387 01388 Inputs: pCXaraFileRecord = ptr to record to handle 01389 01390 Returns: TRUE if handled successfuly 01391 FALSE otherwise 01392 01393 Errors: If pCXaraFileRecord isn't a TAG_WIZOP record 01394 01395 ********************************************************************************************/ 01396 BOOL WizOpStyleRefRecordHandler::HandleRecord(CXaraFileRecord* pRecord) 01397 { 01398 ERROR2IF(pRecord == NULL,FALSE,"pCXaraFileRecord is NULL"); 01399 ERROR2IF(pRecord->GetTag() != TAG_WIZOP_STYLEREF, FALSE, "I don't handle this tag type"); 01400 01401 XFileRef StyleRecordRef; 01402 01403 BOOL Ok = pRecord->ReadINT32(&StyleRecordRef); 01404 if (Ok) 01405 { 01406 WizOpStyle* const pStyle = GetImportedStyles().FindStyleFromRecordReference(StyleRecordRef); 01407 if (pStyle != NULL) 01408 { 01409 // We managed to read it all OK so add a new StyleRefAttribute to the tree 01410 StyleReferenceAttribute* const pNewAttribute = new StyleReferenceAttribute(*pStyle); 01411 01412 if (pNewAttribute != NULL) 01413 { 01414 Ok = InsertNode(pNewAttribute); 01415 } 01416 else 01417 { 01418 Ok = FALSE; 01419 } 01420 } 01421 else 01422 { 01423 BaseCamelotFilter* const pFilter = GetBaseCamelotFilter(); 01424 ENSURE_NOT_NULL(pFilter); 01425 pFilter->AppendWarning(_R(IDS_STYLE_NOT_FOUND)); 01426 } 01427 } 01428 01429 return Ok; 01430 } 01431 01432 01433 /******************************************************************************************** 01434 01435 > WizOpStyles& WizOpStyleRefRecordHandler::GetImportedStyles() const 01436 01437 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01438 Created: 27/06/97 01439 01440 Purpose: Data access 01441 01442 Errors: Will ERROR2 if the Init function failed 01443 01444 ********************************************************************************************/ 01445 WizOpStyles& WizOpStyleRefRecordHandler::GetImportedStyles() const 01446 { 01447 // This static dummy object is used for returning in the ERROR2 case 01448 // The original used to return a ptr to a local variable, which is a tad dangerous. 01449 // This solution is not ideal, because there's a permanent instance of an object 01450 // that will probably never be used. 01451 static WizOpStyles Dummy; 01452 01453 ERROR2IF(m_pStyleComponent == NULL, Dummy, "NULL Member"); 01454 01455 return *m_pStyleComponent; 01456 } 01457 01458 /******************************************************************************************** 01459 01460 > virtual void WizOpStyleRefRecordHandler::GetRecordDescriptionText( 01461 CXaraFileRecord* pRecord, StringBase* pStr) 01462 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01463 Created: 27/06/97 01464 01465 Purpose: Debug function that provides descriptions for TemplateAttribute (WizOp) records. 01466 01467 Inputs: pRecord = ptr to a record 01468 pStr = ptr to string to update 01469 01470 ********************************************************************************************/ 01471 #ifdef XAR_TREE_DIALOG 01472 void WizOpStyleRefRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord,StringBase* pStr) 01473 { 01474 if (pStr == NULL || pRecord == NULL) 01475 { 01476 TRACE( _T("TemplateAttrRecordHandler::GetRecordDescriptionText - NULL Args\n")); 01477 return; 01478 } 01479 if (pRecord->GetTag() != TAG_WIZOP_STYLEREF) 01480 { 01481 TRACE( _T("TemplateAttrRecordHandler::GetRecordDescriptionText - Incorrect record\n")); 01482 return; 01483 } 01484 01485 // Call base class first 01486 CamelotRecordHandler::GetRecordDescriptionText(pRecord, pStr); 01487 01488 XFileRef StyleRecordRef; 01489 01490 BOOL Ok = pRecord->ReadINT32(&StyleRecordRef); 01491 01492 // WizOpStyle* pStyle = NULL; 01493 01494 if (Ok) 01495 { 01496 *pStr += TEXT("Record Reference = "); 01497 01498 String_16 RecordRefString; 01499 Ok = Convert::LongToString(StyleRecordRef, &RecordRefString); 01500 if (Ok) 01501 { 01502 *pStr += RecordRefString; 01503 } 01504 01505 } 01506 } 01507 01508 01509 /******************************************************************************************** 01510 01511 > virtual void WizOpStyleRefRecordHandler::GetTagText(UINT32 Tag,String_256& Str) 01512 01513 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01514 Created: 27/06/97 01515 01516 Purpose: A debug function that gives the tag description. 01517 01518 Inputs: Tag = the tag value 01519 Outputs: Str = place to put textual description of the tag 01520 01521 ********************************************************************************************/ 01522 void WizOpStyleRefRecordHandler::GetTagText(UINT32 Tag,String_256& Str) 01523 { 01524 Str = TEXT("TAG_WIZOP_STYLEREF"); 01525 } 01526 #endif // _DEBUG 01527 01528 01529 01530 01531 01532 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 01533 // V I S I B L E S T Y L E R E F E R E N C E 01534 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 01535 01536 01537 01538 01539 01540 01541 01542 /******************************************************************************************** 01543 01544 > VisibleStyleReference::VisibleStyleReference(const WizOpStyle& Style) 01545 01546 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01547 Created: 27/06/97 01548 01549 Purpose: Sets up a VisibleStyleReference so it actually references a 01550 style and so we can play with it. 01551 01552 Inputs: Style: The style that you want to show the user. 01553 01554 ********************************************************************************************/ 01555 VisibleStyleReference::VisibleStyleReference(const WizOpStyle& Style) : 01556 m_Style(Style) 01557 { 01558 m_Question = m_Style.GetQuestion(); 01559 } 01560 01561 01562 /******************************************************************************************** 01563 01564 > StringBase& VisibleStyleReference::GetText(StringBase& Description) const 01565 01566 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01567 Created: 27/06/97 01568 01569 Purpose: Gives the VisibleListItem its text to display 01570 01571 Outputs: Description Where the text should go 01572 Returns: A reference to the given StringBase 01573 01574 ********************************************************************************************/ 01575 StringBase& VisibleStyleReference::GetText(StringBase& Description) const 01576 { 01577 return (Description = m_Style.GetName()); 01578 } 01579 01580 01581 01582 /******************************************************************************************** 01583 01584 > virtual BOOL VisibleStyleReference::Display(DialogOp& Dialog) 01585 01586 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01587 Created: 09/06/97 01588 01589 Purpose: This displays the StyleReference to the user. 01590 01591 Notes: This function takes a DialopOp as its argument to determine where to 01592 put this object. Since this requires an internal knowledge of the DialogOp 01593 at the moment it is cast to a TemplateDialog which has the fields all ready. 01594 This is likely to change in the future. 01595 01596 ********************************************************************************************/ 01597 BOOL VisibleStyleReference::Display(DialogOp& Dialog) 01598 { 01599 BOOL Ok = TRUE; 01600 01601 PORTNOTETRACE("other","TemplateAttribute::Display - do nothing"); 01602 #ifndef EXCLUDE_FROM_XARALX 01603 ERROR3IF(!((&Dialog)->IS_KIND_OF(TemplateDialog)), "Dialog isn't kind of TemplateDialog"); 01604 01605 TemplateDialog& BetterBeThisDialog = (TemplateDialog&)Dialog; 01606 01607 Ok = m_Question.Display(BetterBeThisDialog.GetValueControl()); 01608 01609 if (Ok) 01610 { 01611 SetParamHintString(GetStyle().GetWizOp().GetParamHint()); 01612 // bodgy bit this... 01613 Ok = GetParamHintLabel().Display(Dialog); 01614 } 01615 01616 if (Ok) 01617 { 01618 SetParamText(GetStyle().GetParam()); 01619 // bodgy bit this... 01620 Ok = GetParamText().Display(BetterBeThisDialog.GetKeyControl()); 01621 } 01622 #endif 01623 return Ok; 01624 } 01625 01626 01627 /******************************************************************************************** 01628 01629 > virtual BOOL VisibleStyleReference::Interact(DialogOp& Dialog) 01630 01631 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01632 Created: 09/06/97 01633 01634 Purpose: This allows the user to change this VisibleStyleReference. 01635 Except it does nothing. 01636 01637 01638 ********************************************************************************************/ 01639 BOOL VisibleStyleReference::Interact(DialogOp& Dialog) 01640 { 01641 return TRUE; 01642 } 01643 01644 01645 /******************************************************************************************** 01646 01647 > virtual void VisibleStyleReference::Hide() 01648 01649 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01650 Created: 09/06/97 01651 01652 Purpose: Hides any interaction with the user 01653 01654 ********************************************************************************************/ 01655 void VisibleStyleReference::Hide() 01656 { 01657 m_Question.Hide(); 01658 GetParamHintLabel().Hide(); 01659 GetParamText().Hide(); 01660 } 01661 01662 01663 /******************************************************************************************** 01664 01665 > virtual NodeAttribute* VisibleStyleReference::CreateNewAttribute() 01666 01667 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01668 Created: 27/06/97 01669 01670 Purpose: Creates a new StyleReferenceAttribute that this VisibleStyleReference 01671 represents to put in the tree. 01672 01673 Returns: A pointer to the new StyleReferenceAttribute (or NULL) 01674 01675 ********************************************************************************************/ 01676 NodeAttribute* VisibleStyleReference::CreateNewAttribute() 01677 { 01678 return new StyleReferenceAttribute(m_Style); 01679 } 01680 01681 01682 01683 01684 void VisibleStyleReference::SetParamHintString(const StringBase& HintToShow) 01685 { 01686 m_ParamHintLabel = HintToShow; 01687 } 01688 01689 01690 const WizOpStyle& VisibleStyleReference::GetStyle() 01691 { 01692 return m_Style; 01693 } 01694 01695 01696 01697 VisibleLabel& VisibleStyleReference::GetParamHintLabel() 01698 { 01699 return m_ParamHintLabel; 01700 } 01701 01702 01703 01704 EditableText& VisibleStyleReference::GetParamText() 01705 { 01706 return m_Param; 01707 } 01708 01709 01710 01711 void VisibleStyleReference::SetParamText(const StringBase& ParamToShow) 01712 { 01713 m_Param = ParamToShow; 01714 }