userattr.cpp

Go to the documentation of this file.
00001 // $Id: userattr.cpp 1282 2006-06-09 09:46:49Z alex $
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 //#include "attrval.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 //#include "nodeattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 #include "userattr.h"
00106 
00107 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "ink.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 #include "blendatt.h"
00110 
00111 //#include "camfiltr.h" // Record handling classes for attributes - in camtypes.h [AUTOMATICALLY REMOVED]
00112 #include "rechattr.h"
00113 //#include "cxfrec.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00114 #include "cxftags.h"
00115 //#include "cxfdefs.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 
00117 //#include "mario.h"        // for _R(IDE_NOMORE_MEMORY)
00118 //#include "hotlink.h"  // for _R(IDS_USERATTRIBUTE_ID)
00119 //#include "tmpltres.h" // for _R(IDS_CUSTOM)
00120 
00121 #include "gadget.h"     // for the UI side
00122 #include "uielem.h"
00123 #include "visiattr.h"
00124 
00125 //#include "dialogop.h" // for slight bodge
00126 //#include "tmpltdlg.h"
00127 
00128 DECLARE_SOURCE("$Revision: 1282 $");
00129 
00130 CC_IMPLEMENT_DYNCREATE(AttrUser, NodeAttribute)
00131 CC_IMPLEMENT_MEMDUMP(VisibleAttribute, UserInterface)
00132 CC_IMPLEMENT_MEMDUMP(VisibleUserAttribute, VisibleAttribute)
00133 
00134 // Give this file in memory dumps
00135 // Declare smart memory handling in Debug builds
00136 #define new CAM_DEBUG_NEW
00137 
00138 #undef ENSURE_NOT_NULL
00139 #define ENSURE_NOT_NULL(Pointer)        ERROR2IF(Pointer == NULL, 0, "NULL Args")
00140 #define ENSURE_KIND(pInstance, Class)   ERROR3IF(!pInstance->IS_KIND_OF(Class), #pInstance" is not kind of "#Class);
00141 
00142 /******************************************************************************************
00143 
00144   FUNCTIONS FOR THE UserATTRIBUTE CLASS (Graham 18/8/96)
00145 
00146 **********************************************************************************************/
00147 UserAttribute::UserAttribute()
00148   : m_pStyle(0)
00149 {
00150     // To ensure default constructed UserAttributes can be copied, alloc the strings.
00151     if (!Key.Alloc(0) || !LongKey.Alloc(0) || !Value.Alloc(0)) return;
00152 }
00153 
00154 
00155 
00156 /********************************************************************************************
00157 >   UserAttribute& UserAttribute::operator=(const UserAttribute& other)
00158 
00159     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00160     Created:    26/9/99
00161     Purpose:    Assignment operator for UserAttributes.
00162     Errors:     _R(IDE_NOMORE_MEMORY)
00163     Notes:      *DOESN'T* COPY THE m_pStyle MEMBER!  What the hell is that doing in this
00164                 class, anyway??
00165     SeeAlso:    UserAttribute::SimpleCopy; AttrUser::CopyNodeContents
00166 ********************************************************************************************/
00167 
00168 UserAttribute& UserAttribute::operator=(const UserAttribute& other)
00169 {
00170     if (Key.Alloc(other.Key.Length()) &&
00171         LongKey.Alloc(other.LongKey.Length()) &&
00172         Value.Alloc(other.Value.Length()))
00173     {       
00174         Key = other.Key;
00175         LongKey = other.LongKey;
00176         Value = other.Value;
00177     }
00178 
00179     return *this;
00180 }
00181 
00182 
00183 
00184 /********************************************************************************************
00185 
00186 >   static BOOL UserAttribute::Init()
00187 
00188     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00189     Created:    14/8/96
00190     Returns:    TRUE - initialised ok; FALSE if not.
00191     Purpose:    There's no need for this function at the moment but I'll leave it in
00192                 in case someone needs it in the future.
00193 
00194                 This function usually registers Default Attributes (see commented out
00195                 code below). There's never a need to register a Default User Attribute.
00196 
00197     Errors:     None
00198     SeeAlso:    AttributeManager
00199 
00200 ********************************************************************************************/
00201 
00202 BOOL UserAttribute::Init()
00203 {
00204     UserAttribute *pAttr = new UserAttribute;
00205     if (pAttr == NULL)
00206         return FALSE;
00207 
00208     UINT32 ID = AttributeManager::RegisterDefaultAttribute(CC_RUNTIME_CLASS(NodeRenderableInk), 
00209                                                          pAttr);
00210     if (ID == ATTR_BAD_ID)
00211         return FALSE;
00212     ENSURE(ID == ATTR_USERATTRIBUTE, "Incorrect ID for attribute!");
00213     return TRUE;
00214 }
00215 
00216 
00217 /********************************************************************************************
00218 
00219 >   void UserAttribute::Render(RenderRegion *pRegion)
00220 
00221     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00222     Created:    14/8/96
00223     Inputs:     pRegion - the render region to render this attribute into.
00224     Purpose:    Rendering a User Attribute does nothing. That's what
00225                 this function does.
00226     SeeAlso:    UserAttribute; RenderStack; AttributeValue; NodeAttribute;
00227                 ValueAttribute::Restore; ValueAttribute::SimpleCopy;
00228                 AttributeValue::Render; AttributeValue::Restore; AttributeValue::SimpleCopy
00229 
00230 ********************************************************************************************/
00231 void UserAttribute::Render(RenderRegion *pRegion, BOOL Temp)
00232 {
00233     //Do nothing
00234 }
00235 
00236 
00237 /********************************************************************************************
00238 
00239 >   void UserAttribute::Restore(RenderRegion *pRegion, BOOL Temp)
00240 
00241     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00242     Created:    03/02/94
00243     Inputs:     pRegion - the render region to restore the attribute into.
00244                 Temp    - TRUE if this is a temporary attribute, FALSE if it is
00245                           permanent (e.g. it's in a document tree).
00246     Purpose:    Again, restoring a User Attribute does nothing
00247     SeeAlso:    UserAttribute; RenderStack; AttributeValue; NodeAttribute;
00248                 ValueAttribute::Render; ValueAttribute::SimpleCopy;
00249                 AttributeValue::Render; AttributeValue::Restore; AttributeValue::SimpleCopy
00250 
00251 ********************************************************************************************/
00252 
00253 void UserAttribute::Restore(RenderRegion *pRegion, BOOL Temp)
00254 {
00255     // Do nothing
00256 }
00257 
00258 /********************************************************************************************
00259 
00260 >   void UserAttribute::SimpleCopy(AttributeValue* pValue)
00261 
00262     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00263     Created:    16/8/96
00264     Inputs:     pValue - pointer to the AttributeValue to copy.
00265     Purpose:    Copies both bits of the data from pValue
00266     SeeAlso:    ValueAttribute; RenderStack; AttributeValue; NodeAttribute;
00267                 ValueAttribute::Render; ValueAttribute::Restore;
00268                 AttributeValue::Render; AttributeValue::Restore; AttributeValue::SimpleCopy
00269 
00270 ********************************************************************************************/
00271 
00272 void UserAttribute::SimpleCopy(AttributeValue* pValue)
00273 {
00274     *this = *((UserAttribute*) pValue);
00275 }
00276 
00277 
00278 /********************************************************************************************
00279 
00280 >   NodeAttribute *UserAttribute::MakeNode()
00281 
00282     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00283     Created:    11/04/94
00284     Returns:    Pointer to the new node, or NULL if out of memory.
00285     Purpose:    Make a AttrUser node from this line width attribute.
00286     Errors:     Out of memory
00287     SeeAlso:    AttributeValue::MakeNode
00288 
00289 ********************************************************************************************/
00290 
00291 NodeAttribute *UserAttribute::MakeNode()
00292 {
00293     // Create new attribute node
00294     AttrUser *pAttr = new AttrUser();
00295 
00296     // Copy attribute value into the new node.
00297     pAttr->Value.SimpleCopy(this);
00298 
00299     // Return the new node
00300     return pAttr;
00301 }
00302 
00303 /********************************************************************************************
00304 
00305 >   BOOL UserAttribute::IsDifferent(AttributeUser *pAttr)
00306 
00307     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> from Tim
00308     Created:    12/04/94
00309     Purpose:    See base class version.
00310     Errors:     The two attributes are not of the same type.
00311     SeeAlso:    AttributeValue::IsDifferent
00312 
00313 ********************************************************************************************/
00314 
00315 BOOL UserAttribute::IsDifferent(AttributeValue *pAttr)
00316 {
00317     ENSURE_NOT_NULL(pAttr);
00318 
00319     ENSURE(GetRuntimeClass() == pAttr->GetRuntimeClass(), 
00320            "Different attribute types in AttributeValue::IsDifferent()");
00321 
00322     ENSURE_KIND(pAttr, UserAttribute);
00323     UserAttribute* const pUserAttrVal = (UserAttribute*)pAttr;
00324 
00325     // LongKey should always start with Key
00326     return pUserAttrVal->LongKey != LongKey || pUserAttrVal->Value != Value;
00327 }
00328 
00329 /********************************************************************************************
00330 
00331 >   BOOL UserAttribute::Blend(BlendAttrParam *pBlendParam)
00332 
00333     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> from Markn
00334     Created:    15/8/96
00335     Inputs:     pBlendParam = ptr to param holding all data needed for the attr val to blend
00336     Outputs:    if TRUE  returned, pBlendParam->GetBlendedAttrVal() will get ptr to the blended attr val
00337                 if FALSE returned, pBlendParam->GetBlendedAttrVal() will return NULL
00338     Returns:    TRUE if successful, FALSE otherwaie
00339     Purpose:    Blends this attr val with the attr val held in pBlendParam
00340     SeeAlso:    -
00341 
00342 ********************************************************************************************/
00343 
00344 BOOL UserAttribute::Blend(BlendAttrParam *pBlendParam)
00345 {
00346     // Check entry param
00347     ERROR3IF(pBlendParam == NULL,"NULL entry param");
00348     if (pBlendParam == NULL) return FALSE;
00349 
00350     // Check that the pointer to the other User attr val is not NULL, and is a UserAttribute
00351     UserAttribute* pOtherUserAttr = (UserAttribute*) pBlendParam->GetOtherAttrVal();
00352     ERROR3IF(pOtherUserAttr == NULL,"NULL other attr val");
00353     ERROR3IF(!IS_A(pOtherUserAttr, UserAttribute),"other attr val not a user attr");
00354     if (pOtherUserAttr == NULL || !IS_A(pOtherUserAttr, UserAttribute)) return FALSE;
00355 
00356     //Graham: Here's the change. If the Keys of the attributes are not the same, we must
00357     //not blend these attributes.
00358     if (Key != pOtherUserAttr->Key && LongKey != pOtherUserAttr->LongKey)
00359     {
00360         return FALSE;
00361     }
00362 
00363     // Get a new UserAttribute to hold the blended version, (return FALSE if this fails)
00364     UserAttribute* pBlendedUserAttr = new UserAttribute;
00365     if (pBlendedUserAttr == NULL) return FALSE;
00366 
00367     //Graham: For blending two User Attributes with the same Key, we simply
00368     //use the first User Attribute for the first half of the blend, and the
00369     //second User Attribute for the second half of the blend.
00370     StringBase* pStr;   
00371     if (pBlendParam->GetBlendRatio() < 0.5)
00372         pStr = &Value;
00373     else
00374         pStr = &(pOtherUserAttr->Value);
00375     
00376     ERRORIF(!pBlendedUserAttr->Value.Alloc(pStr->Length()), _R(IDE_NOMORE_MEMORY), FALSE);
00377     pBlendedUserAttr->Value = *pStr;
00378     
00379     // Store the ptr to the new blended User width attr val
00380     pBlendParam->SetBlendedAttrVal(pBlendedUserAttr);
00381     return TRUE;
00382 }
00383 
00384 
00385 
00386 
00387 
00388 
00389 
00390 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
00391 //                              A  T  T  R  U  S  E  R
00392 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
00393 
00394 
00395 
00396 
00397 
00398 
00399 const TCHAR AttrUser::s_KeyDelimiter = TEXT('\\');
00400 const TCHAR s_KeyDelimiter = TEXT('\\');
00401 
00402 /********************************************************************************************
00403 
00404 >   AttrUser::AttrUser (Node* ContextNode,  
00405                     AttachNodeDirection Direction,  
00406                     BOOL Locked, 
00407                     BOOL Mangled,  
00408                     BOOL Marked, 
00409                     BOOL Selected    
00410             ): NodeAttribute(ContextNode, Direction, Locked, Mangled, Marked, Selected, TRUE)  
00411 
00412     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> (from Will)
00413     Created:    14/8/96
00414     Inputs:     -
00415     Outputs:    -
00416     Returns:    -
00417     Purpose:    Creates a User Attribute
00418     Errors:     -
00419     SeeAlso:    -
00420 
00421 ********************************************************************************************/
00422 
00423 AttrUser::AttrUser(Node* ContextNode,  
00424                     AttachNodeDirection Direction,  
00425                     BOOL Locked, 
00426                     BOOL Mangled,  
00427                     BOOL Marked, 
00428                     BOOL Selected)
00429   : NodeAttribute(ContextNode, Direction, Locked, Mangled, Marked, Selected)  
00430 {
00431     // Empty.
00432 } 
00433 
00434 /********************************************************************************************
00435 
00436 >   AttrUser::AttrUser()
00437 
00438     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00439     Created:    21/8/96
00440 
00441     Purpose:    Default constructor for User Attribute class
00442 
00443 ********************************************************************************************/
00444 
00445 AttrUser::AttrUser()
00446 {
00447 }
00448 
00449 /********************************************************************************************
00450 
00451 >   AttrUser::AttrUser( const StringBase& NewKey, const StringBase& NewSubKey, 
00452                         const StringBase& NewValue)
00453 
00454     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00455     Created:    21/8/96
00456 
00457     Inputs:     
00458     Purpose:    Constructs a User Attribute node given a Key, SubKey and Value
00459 
00460 ********************************************************************************************/
00461 AttrUser::AttrUser( const StringBase& NewKey, const StringBase& NewSubKey, 
00462                     const StringBase& NewValue)
00463 {
00464     if (!Value.Key.Alloc(NewKey.Length())) return;
00465     Value.Key = NewKey;
00466 
00467     INT32 n = NewKey.Length();
00468     if (!NewSubKey.IsEmpty())  n += 1 + NewSubKey.Length();
00469     
00470     if (!Value.LongKey.Alloc(n)) return;
00471     Value.LongKey = NewKey;
00472     if (!NewSubKey.IsEmpty())
00473     {
00474         Value.LongKey += s_KeyDelimiter;
00475         Value.LongKey += NewSubKey;
00476     }
00477 
00478     if (!Value.Value.Alloc(NewValue.Length())) return;
00479     Value.Value = NewValue;
00480 }
00481 
00482 
00483 /********************************************************************************************
00484 
00485 >   AttrUser::AttrUser(const StringBase& NewLongKey)
00486 
00487     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00488     Created:    21/07/97
00489 
00490     Purpose:    Constructs an AttrUser (User attribute node) from a long key
00491 
00492 ********************************************************************************************/
00493 AttrUser::AttrUser(const StringBase& NewLongKey, const StringBase& NewValue)
00494 {
00495     // Find the first bit of the long key
00496     INT32 DelimiterPosition = NewLongKey.FindNextChar(s_KeyDelimiter);
00497     if (DelimiterPosition < 0)
00498     {
00499         // couldn't find the end so the delimiter is beyond the end of the string
00500         DelimiterPosition = NewLongKey.Length();
00501     }
00502 
00503     INT32 ShortKeyLength = DelimiterPosition;
00504     if (ShortKeyLength > 0)
00505     {
00506         // Added by Craig Hamilton 2/8/00.
00507         // This section of code deals with the situation where the length of Value.Key.Length is
00508         // less than ShortKeyLength. This was causing problems with the call to StringBase::Left
00509         // which would fail in this eventuality. To prevent this we just allocate Value.Key more
00510         // space. We did try another method involving the use of a String_256 being passed to 
00511         // StringBase::Left and then asigning Value.Key to the String_256, but this caused a
00512         // Damage: after normal block error in the VC++ debug library.
00513         if(Value.Key.Length() < ShortKeyLength)
00514         {
00515             Value.Key.Alloc(ShortKeyLength);
00516         }
00517         // End Added.
00518 
00519         NewLongKey.Left(&Value.Key, ShortKeyLength);
00520     }
00521     else
00522     {
00523         TRACE( _T("AttrUser::AttrUser - no key\n"));
00524     }
00525 
00526     if (!Value.LongKey.Alloc(NewLongKey.Length())) return;
00527     Value.LongKey   = NewLongKey;
00528 
00529     if (!Value.Value.Alloc(NewValue.Length())) return;
00530     Value.Value     = NewValue;
00531 }
00532 
00533 
00534 /********************************************************************************************
00535 
00536 >   void AttrUser::Render( RenderRegion* pRender)
00537 
00538     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00539     Created:    14/6/96
00540 
00541     Purpose:    We don't need to render a user attribute. So simply do nothing.
00542 
00543 ********************************************************************************************/
00544 
00545 void AttrUser::Render(RenderRegion* pRender)
00546 {
00547     //Don't need to do anything to render a User Attribute.
00548 }
00549 
00550 /********************************************************************************************
00551 
00552 >   void AttrUser::Transform( TransformBase& Trans )
00553 
00554     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00555     Created:    14/8/96
00556     Inputs:     Trans - the transform object to apply to this attribute.
00557     Purpose:    We don't need to transform a User Attribute - so this function does nothing
00558     SeeAlso:    NodeRenderable::Transform
00559 
00560 ********************************************************************************************/
00561 
00562 void AttrUser::Transform( TransformBase& Trans )
00563 {
00564     //Transforming a User Attribute does nothing.
00565 }
00566 
00567 /***********************************************************************************************
00568 > Node* AttrUser::SimpleCopy() 
00569 
00570     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00571     Created:    21/6/93
00572     
00573     Inputs:         - 
00574     Outputs:     
00575     Returns:    A copy of the node, or NULL if memory runs out 
00576          
00577     Purpose:    This method returns a shallow copy of the node with all Node pointers NULL. 
00578                 The function is virtual, and must be defined for all derived classes.  
00579 
00580     Errors:     If memory runs out when trying to copy, then ERROR is called with an out of memory
00581                 error and the function returns NULL. 
00582     
00583     Scope:      protected       
00584 ***********************************************************************************************/
00585      
00586 Node* AttrUser::SimpleCopy()
00587 {
00588     AttrUser* pNodeCopy = new AttrUser;
00589     ERRORIF(pNodeCopy == NULL, _R(IDE_NOMORE_MEMORY), NULL); 
00590     CopyNodeContents(pNodeCopy);
00591     return pNodeCopy;
00592 } 
00593 
00594 /********************************************************************************************
00595 
00596 >   INT32 AttrUser::operator==(const NodeAttribute& Attrib)
00597 
00598     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>, from Simon
00599     Created:    9/2/94
00600     Inputs:     Atrib:  The attribute to compare, which must be an AttrUser 
00601     Outputs:    -
00602     Returns:    -
00603     Purpose:    A virtual comparison operator. See NodeAttribute::operator== for 
00604                 a description of why it's required. 
00605 
00606               Graham says: with this class you actually need to compare two values (the Value and
00607                 and the Key) not just one.
00608  
00609     Errors:     An ENSURE failure will occur if Attrib does not have a AttrUser 
00610                 runtime class.
00611                  
00612     SeeAlso:    NodeAttribute::operator==
00613 
00614 ********************************************************************************************/
00615 
00616 INT32 AttrUser::operator==(const NodeAttribute& Attrib)
00617 {
00618     ENSURE(Attrib.IsKindOf(CC_RUNTIME_CLASS(AttrUser)), 
00619         "Trying to compare two objects with different types"); 
00620 
00621     AttrUser& OtherUserNode = (AttrUser&) Attrib;
00622     return !(Value.IsDifferent(&OtherUserNode.Value));
00623 } 
00624 
00625 
00626 /********************************************************************************************
00627 
00628 >   virtual UINT32 AttrUser::GetAttrNameID(void)  
00629 
00630     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> from Simon
00631     Created:    22/2/94
00632     Inputs:     -
00633     Outputs:    -
00634     Returns:    Attribute description ID
00635     Purpose:    Returns back a string resource ID describing the attribute
00636 
00637     Errors:     -
00638     SeeAlso:    -
00639 
00640 ********************************************************************************************/
00641 
00642 UINT32 AttrUser::GetAttrNameID(void)  
00643 {
00644     return (_R(IDS_USERATTRIBUTE_ID)); 
00645 }               
00646                  
00647 
00648 /***********************************************************************************************
00649 > ` void AttrUser::CopyNodeContents( AttrUser* NodeCopy)
00650 
00651     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> from Simon
00652     Created:    28/4/93
00653     
00654     Inputs:           
00655     Outputs:    A copy of this node
00656     Returns:    -
00657          
00658     Purpose:    This method copies the node's contents to the node pointed to by NodeCopy.
00659               
00660     Errors:     An assertion failure will occur if NodeCopy is NULL
00661     
00662     Scope:      protected
00663                                      
00664 ***********************************************************************************************/
00665 
00666 void AttrUser::CopyNodeContents( AttrUser* NodeCopy)
00667 {
00668     NodeAttribute::CopyNodeContents(NodeCopy);
00669     NodeCopy->Value = Value;
00670 } 
00671 
00672 
00673 
00674 /***********************************************************************************************
00675 >   void AttrUser::PolyCopyNodeContents(NodeRenderable* pNodeCopy)
00676 
00677     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00678     Created:    18/12/2003
00679     Outputs:    -
00680     Purpose:    Polymorphically copies the contents of this node to another
00681     Errors:     An assertion failure will occur if NodeCopy is NULL
00682     Scope:      protected
00683                                      
00684 ***********************************************************************************************/
00685 
00686 void AttrUser::PolyCopyNodeContents(NodeRenderable* pNodeCopy)
00687 {
00688     ENSURE(pNodeCopy, "Trying to copy a node's contents into a NULL node");
00689     ENSURE(IS_A(pNodeCopy, AttrUser), "PolyCopyNodeContents given wrong dest node type");
00690 
00691     if (IS_A(pNodeCopy, AttrUser))
00692         CopyNodeContents((AttrUser*)pNodeCopy);
00693 }
00694 
00695 
00696 
00697 #ifdef _DEBUG
00698 /***********************************************************************************************
00699 
00700 >   void AttrUser::ShowDebugTreeDetails() const
00701 
00702     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00703     Created:    21/6/93
00704     Purpose:    Displays debugging info of the tree
00705 
00706 ***********************************************************************************************/
00707 
00708 void AttrUser::ShowDebugTreeDetails() const
00709 {
00710     // Display a bit of debugging info
00711     // For now, we will just call the base class version
00712     NodeAttribute::ShowDebugTreeDetails();  
00713 }
00714 #endif
00715 
00716 
00717 void AttrUser::GetDebugDetails(StringBase* Str)
00718 {
00719 #ifdef _DEBUG
00720     NodeAttribute::GetDebugDetails( Str );
00721 
00722     *Str += TEXT("\r\nKey = ");
00723     *Str += Value.Key;
00724     *Str += TEXT("\r\nLongKey = ");
00725     *Str += Value.LongKey;
00726     *Str += TEXT("\r\nData= ");
00727     *Str += Value.Value;
00728 #endif
00729 }
00730 
00731 
00732 /********************************************************************************************
00733 
00734 >   virtual UINT32 AttrUser::GetNodeSize() const
00735 
00736     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> from Simon
00737     Created:    6/10/93
00738     Inputs:     -
00739     Outputs:    -
00740     Returns:    The size of the node in bytes
00741     Purpose:    For finding the size of the node 
00742                 
00743     SeeAlso:    Node::GetSubtreeSize
00744 
00745 ********************************************************************************************/
00746 
00747 UINT32 AttrUser::GetNodeSize() const 
00748 {     
00749     return sizeof(*this); 
00750 }  
00751 
00752 
00753 /********************************************************************************************
00754 
00755 >   virtual BOOL AttrUser::ShouldBeOptimized()
00756 
00757     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00758     Created:    24/06/97
00759 
00760     Purpose:    When applying multiple template args / WizOp user attributes we want them to
00761                 remain associated with the object they were applied to rather than migrating
00762                 to groups, otherwise where there was once two questions for two objects in
00763                 a group there would instead be one.
00764                 The default AttrUser should always be optimized out.
00765                 
00766     Returns:    TRUE if the attribute should be optimized, normalized, etc.
00767                 FALSE otherwise
00768 
00769     See Also:   NodeRenderableInk::NormaliseAttributes()
00770                 NodeRenderableInk::FindCommonAttributesToFactorOut()
00771                 NodeRenderableInk::MakeAttributeComplete()
00772 
00773 ********************************************************************************************/
00774 BOOL AttrUser::ShouldBeOptimized()
00775 {
00776     return Value.Key.IsEmpty() && Value.LongKey.IsEmpty() && Value.Value.IsEmpty();
00777 }  
00778 
00779 
00780 /********************************************************************************************
00781 
00782 >   virtual BOOL AttrUser::Blend(BlendAttrParam* pBlendParam)
00783 
00784     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> from MarkN
00785     Created:    14/8/96
00786     Inputs:     pBlendParam = ptr to blend attribute param object holding all info needed
00787     Outputs:    -
00788     Returns:    TRUE if successful, FALSE otherwise
00789     Purpose:    Blends one User attribute with another.
00790                 
00791     SeeAlso:    -
00792 
00793 ********************************************************************************************/
00794 
00795 BOOL AttrUser::Blend(BlendAttrParam* pBlendParam)
00796 {
00797     // Get the User member to blend to the User member of the other NodeAttribute.
00798     // If it succeeds, ask the blended Value to make a NodeAttribute out of itself.
00799     ERROR3IF(pBlendParam == NULL,"NULL entry param");
00800     if (Value.Blend(pBlendParam))
00801     {
00802         // Get the blended attr val. After this call, the ptr is our reponsibility
00803         // so we have to delete it if it's no longer needed
00804         AttributeValue* pBlendedAttrVal = pBlendParam->GetBlendedAttrVal();
00805         if (pBlendedAttrVal != NULL)
00806         {
00807             // We have a blended attr val, so ask it to make a NodeAttribute out of itself
00808             // and set the pBlendParam's blended NodeAttribute ptr to it
00809             NodeAttribute* pBlendedAttr = pBlendedAttrVal->MakeNode();
00810             pBlendParam->SetBlendedAttr(pBlendedAttr);
00811 
00812             if (pBlendedAttr != NULL)
00813             {
00814                 // We were able to make a blended NodeAttribute
00815                 // so delete the blended attr val, and return TRUE
00816                 delete pBlendedAttrVal;
00817                 return TRUE;
00818             }
00819             else
00820             {
00821                 // Couldn't make a blended NodeAttribute, so give the blended attr val back
00822                 // and return FALSE
00823                 pBlendParam->SetBlendedAttrVal(pBlendedAttrVal);
00824             }
00825         }
00826     }
00827     
00828     return FALSE;
00829 }
00830 
00831 
00832 
00833 /********************************************************************************************
00834 
00835   > virtual BOOL AttrUser::WritePreChildrenWeb(BaseCamelotFilter* pFilter)
00836 
00837     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00838     Created:    30/5/96
00839     Inputs:     pFilter = ptr to the filter
00840     Returns:    TRUE if record is written, FALSE if not
00841     Purpose:    Writes the line width record to the filter
00842     SeeAlso:    -
00843 
00844 ********************************************************************************************/
00845 
00846 BOOL AttrUser::WritePreChildrenWeb(BaseCamelotFilter* pFilter)
00847 {
00848 #ifdef DO_EXPORT
00849     ERROR2IF(pFilter == NULL,FALSE,"NULL filter param");
00850 
00851     BOOL ok = TRUE;
00852 
00853     CamelotFileRecord Rec(pFilter,TAG_USERVALUE,TAG_USERVALUEATTRSIZE);
00854 
00855     ok = Rec.Init();
00856 
00857     if (ok) ok = Rec.WriteUnicode((TCHAR*)Value.LongKey);
00858     if (ok) ok = Rec.WriteUnicode((TCHAR*)Value.Value);
00859 
00860     if (ok) ok = pFilter->Write(&Rec);
00861 
00862     return ok;
00863 #else
00864     return FALSE;
00865 #endif
00866 }
00867 
00868 //--------------------------------------------------------------
00869 // See AttrUser::WritePreChildrenWeb(BaseCamelotFilter* pFilter)
00870 //
00871 BOOL AttrUser::WritePreChildrenNative(BaseCamelotFilter* pFilter)
00872 {
00873 #ifdef DO_EXPORT
00874     return WritePreChildrenWeb(pFilter);
00875 #else
00876     return FALSE;
00877 #endif
00878 }
00879 
00880 /********************************************************************************************
00881 
00882 >   BOOL AttrUser::ShouldBecomeCurrent()
00883 
00884     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00885     Created:    14/6/96
00886     Returns:    TRUE if this attribute should become current.
00887 
00888                 FALSE if the user must deliberately apply this attribute to an object
00889                 every time he wants to use it.
00890 
00891     Purpose:    The attribute manager calls this function before making an attribute current.
00892 
00893                 There are some attributes - like this URL Hot Link attribute I'm about
00894                 to put in - that the user probably won't want to become current.
00895                 For example, if a user puts a HotLink on an object and happens to have
00896                 the Give Other Objects Most Recent Attributes option on, all his new objects are
00897                 going to have HotLinks. That's not good.
00898 
00899                 So those attributes will override this function and return FALSE.
00900 
00901 ********************************************************************************************/
00902 BOOL AttrUser::ShouldBecomeCurrent()
00903 { 
00904     //No, don't pass this attribute on
00905     return FALSE; 
00906 }
00907 
00908 
00909 /********************************************************************************************
00910 
00911 >   StringBase& AttrUser::GetWebAddress()
00912 
00913     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00914     Created:    14/6/96
00915 
00916     Returns:    The URL of the Hot Link
00917 
00918     Purpose:    This is only used for Web Address User Attributes.
00919             
00920 ********************************************************************************************/
00921 StringBase& AttrUser::GetWebAddress()
00922 { 
00923     return Value.Value;
00924 }
00925 
00926 
00927 /********************************************************************************************
00928 
00929 >   virtual AttributeIdentifier AttrUser::GetAttributeClassID() const
00930 
00931     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00932     Created:    09/06/97
00933     
00934     Purpose:    Generates an AttributeIdentifier for this Attribute.
00935                 Since the RuntimeClass is inadequate for dynamically generated Atrributes
00936                 (read Nodes), we need to provide an ID that can be created dynamically too.
00937                 This is what an AttributeIdentifier is supposed to be.
00938                 In the case of an AttrUser it returns a pointer to a template
00939                 handler.
00940 
00941 ********************************************************************************************/
00942 AttributeIdentifier AttrUser::GetAttributeClassID() const
00943 {
00944     return Value.LongKey;
00945 }
00946 
00947 
00948 /********************************************************************************************
00949 
00950 >   VisibleAttribute* AttrUser::CreateVisibleAttribute() const
00951 
00952     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00953     Created:    09/06/97
00954     
00955     Purpose:    Creates a VisibleAttribute representing this AttrUser that the user can edit.
00956                 (this is all horribly wrong).
00957 
00958     Returns:    A new VIsibleAttribute
00959 
00960 ********************************************************************************************/
00961 VisibleAttribute* AttrUser::CreateVisibleAttribute() const
00962 {
00963     VisibleAttribute* pVisibleAttribute = NULL; // return this
00964 
00965     PORTNOTETRACE("other","AttrUser::CreateVisibleAttribute - do nothing");
00966 #ifndef EXCLUDE_FROM_XARALX
00967     pVisibleAttribute = new VisibleUserAttribute(Value.LongKey, Value.Value);
00968 #endif
00969     return pVisibleAttribute;
00970 }
00971 
00972 
00973 
00974 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
00975 //              V  I  S  I  B  L  E  U  S  E  R  A  T  T  R  I  B  U  T  E
00976 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
00977 
00978 
00979 
00980 
00981 
00982 
00983 /********************************************************************************************
00984 
00985 >   VisibleUserAttribute::VisibleUserAttribute(const StringBase& Key, const StringBase& Value)
00986 
00987     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00988     Created:    09/06/97
00989     
00990     Purpose:    Represents an AttrUser that the user can edit
00991                 (this is all horribly wrong).
00992 
00993 ********************************************************************************************/
00994 
00995 VisibleUserAttribute::VisibleUserAttribute(const StringBase& Key, const StringBase& Value) :
00996     m_LongKey(Key),
00997     m_Value(Value)
00998 {
00999 }
01000 
01001 
01002 
01003 void VisibleUserAttribute::SetLongKey(const StringBase& NewKey)
01004 {
01005     m_LongKey = NewKey;
01006 }
01007 
01008 
01009 const StringBase& VisibleUserAttribute::GetKey()
01010 {
01011     const StringBase& SourceString = (const StringBase&)m_LongKey;
01012 
01013     // Find the first bit of the long key
01014     INT32 EndDelimiterPosition = SourceString.FindNextChar(s_KeyDelimiter);
01015 
01016     if (EndDelimiterPosition < 0)
01017     {
01018         // couldn't find the end so the delimiter is beyond the end of the string
01019         EndDelimiterPosition = SourceString.Length();
01020     }
01021 
01022     const UINT32 LengthToCopy = EndDelimiterPosition;
01023     if (LengthToCopy > 0)
01024     {
01025         SourceString.Left(&m_Key, LengthToCopy);
01026     }
01027     else
01028     {
01029         TRACE( _T("VisibleUserAttribute::GetKey - no key\n"));
01030     }
01031 
01032     return m_Key;
01033 }
01034 
01035 const StringBase& VisibleUserAttribute::GetLongKey()
01036 {
01037     return m_LongKey;
01038 }
01039 
01040 const StringBase& VisibleUserAttribute::GetValue()
01041 {
01042     return m_Value;
01043 }
01044 
01045 /********************************************************************************************
01046 
01047 >   virtual NodeAttribute* VisibleUserAttribute::CreateNewAttribute()
01048 
01049     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01050     Created:    09/06/97
01051     
01052     Purpose:    Creates a new NodeAttribute from what the user entered.
01053                 (this is all horribly wrong).
01054 
01055 ********************************************************************************************/
01056 NodeAttribute* VisibleUserAttribute::CreateNewAttribute()
01057 {
01058     return new AttrUser(GetLongKey(), GetValue());
01059 }
01060 
01061 
01062 /********************************************************************************************
01063 
01064 >   virtual StringBase& GetText(StringBase& Description) const
01065 
01066     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01067     Created:    09/06/97
01068     
01069     Purpose:    
01070     
01071     Returns:    Some user visible text describing this VisibleUserAttribute
01072 
01073 ********************************************************************************************/
01074 StringBase& VisibleUserAttribute::GetText(StringBase& Description) const
01075 {
01076     PORTNOTETRACE("other","VisibleUserAttribute::GetText - do nothing");
01077 #ifndef EXCLUDE_FROM_XARALX
01078     String_32 TruncatedKey((const StringBase&)m_LongKey);
01079     Description.MakeMsg(_R(IDS_APPLIED_CUSTOM), TruncatedKey);
01080 #endif
01081     return Description; 
01082 }
01083 
01084 
01085 /********************************************************************************************
01086 
01087 >   BOOL VisibleUserAttribute::Display(DialogOp& Dialog)
01088 
01089     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01090     Created:    09/06/97
01091     
01092     Purpose:    This allows the user to change this VisibleUserAttribute
01093     
01094     Notes:      This function takes a DialopOp as its argument to determine where to
01095                 put this object. Since this requires an internal knowledge of the DialogOp
01096                 at the moment it is cast to a TemplateDialog which has the fields all ready.
01097                 This is likely to change in the future.
01098 
01099 ********************************************************************************************/
01100 BOOL VisibleUserAttribute::Display(DialogOp& Dialog)
01101 {
01102     PORTNOTETRACE("other","VisibleUserAttribute::Display - do nothing");
01103 #ifndef EXCLUDE_FROM_XARALX
01104     ERROR3IF(!((&Dialog)->IS_KIND_OF(TemplateDialog)), "Dialog isn't kind of TemplateDialog");
01105 
01106     TemplateDialog& BetterBeThisDialog = (TemplateDialog&)Dialog;
01107     BOOL Success = TRUE;
01108 
01109     Success = m_LongKey.Display(BetterBeThisDialog.GetKeyControl());
01110     if (Success)
01111     {
01112         Success = m_Value.Display(BetterBeThisDialog.GetValueControl());
01113     }
01114 
01115     return Success;
01116 #else
01117     return FALSE;
01118 #endif
01119 }
01120 
01121 
01122 /********************************************************************************************
01123 
01124 >   BOOL VisibleUserAttribute::Interact(DialogOp& Dialog)
01125 
01126     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01127     Created:    09/06/97
01128     
01129     Purpose:    This allows the user to change this VisibleUserAttribute
01130     
01131     Notes:      This function takes a DialopOp as its argument to determine where to
01132                 put this object. Since this requires an internal knowledge of the DialogOp
01133                 at the moment it is cast to a TemplateDialog which has the fields all ready.
01134                 This is likely to change in the future.
01135 
01136 ********************************************************************************************/
01137 BOOL VisibleUserAttribute::Interact(DialogOp& Dialog)
01138 {
01139     PORTNOTETRACE("other","VisibleUserAttribute::Interact - do nothing");
01140 #ifndef EXCLUDE_FROM_XARALX
01141     if (!((&Dialog)->IS_KIND_OF(TemplateDialog)))
01142     {
01143         ERROR3("Dialog isn't kind of TemplateDialog");
01144         return FALSE;
01145     }
01146 
01147     TemplateDialog& BetterBeThisDialog = (TemplateDialog&)Dialog;
01148     
01149     if (IsNew())
01150     {
01151         BetterBeThisDialog.GetKeyControl().Enable();
01152     }
01153     BetterBeThisDialog.GetValueControl().Enable();
01154 
01155     return TRUE;
01156 #else
01157     return FALSE;
01158 #endif
01159 }
01160 
01161 /********************************************************************************************
01162 
01163 >   void VisibleUserAttribute::Hide()
01164 
01165     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01166     Created:    09/06/97
01167     
01168     Purpose:    Hides this VisibleUserAttribute from the user.
01169     
01170 ********************************************************************************************/
01171 void VisibleUserAttribute::Hide()
01172 {
01173     m_LongKey.Hide();
01174     m_Value.Hide();
01175 }

Generated on Sat Nov 10 03:47:18 2007 for Camelot by  doxygen 1.4.4