webattr.cpp

Go to the documentation of this file.
00001 // $Id: webattr.cpp 1361 2006-06-25 16:43:38Z 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 "webattr.h"
00104 //#include "hotlink.h"
00105 //#include "mario.h"        //For _R(IDE_NOMORE_MEMORY)
00106 //#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "fixed16.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 #include "blendatt.h"
00110 //#include "ink.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "camfiltr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 #include "cxftags.h"
00113 #include "rechattr.h"   // Record handling classes for attributes
00114 //#include "cxfrec.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 //#include "resimmap.h" //_R(IDS_TAG_WEBADDRESS)
00116 DECLARE_SOURCE("$Revision: 1361 $");
00117 
00118 CC_IMPLEMENT_DYNCREATE(AttrWebAddress, NodeAttribute)
00119 CC_IMPLEMENT_DYNCREATE(WebAddressAttribute, AttributeValue)
00120 
00121 // Declare smart memory handling in Debug builds
00122 // Give this file in memory dumps
00123 #define new CAM_DEBUG_NEW
00124     
00125 /****************************************************************************************
00126 
00127   AttrWebAddress member functions
00128 
00129   ***************************************************************************************/
00130     
00131 /***********************************
00132 
00133   Constructors
00134                                  
00135   **********************************/
00136     
00137 /********************************************************************************************
00138 
00139 >   AttrWebAddress::AttrWebAddress()
00140 
00141     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00142     Created:    27/3/97
00143     Inputs:     -
00144     Outputs:    -
00145     Returns:    -
00146     Purpose:    Default constructor
00147     Errors:     -
00148     SeeAlso:    -
00149 
00150 ********************************************************************************************/
00151 
00152 AttrWebAddress::AttrWebAddress()
00153 {
00154     Value=WebAddressAttribute();
00155 }
00156 
00157     
00158 /********************************************************************************************
00159 
00160 >   AttrWebAddress::AttrWebAddress (Node* ContextNode,  
00161                     AttachNodeDirection Direction,  
00162                     BOOL Locked, 
00163                     BOOL Mangled,  
00164                     BOOL Marked, 
00165                     BOOL Selected    
00166             ): NodeAttribute(ContextNode, Direction, Locked, Mangled, Marked, Selected, TRUE)  
00167 
00168     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00169     Created:    27/3/97
00170     Inputs:     See NodeAttribute for a description
00171     Outputs:    -
00172     Returns:    -
00173     Purpose:    Constructs a Web Address Attribute at a specific place in the tree
00174     Errors:     -
00175     SeeAlso:    -
00176 
00177 ********************************************************************************************/
00178 
00179 AttrWebAddress::AttrWebAddress(Node* ContextNode,  
00180                     AttachNodeDirection Direction,  
00181                     BOOL Locked, 
00182                     BOOL Mangled,  
00183                     BOOL Marked, 
00184                     BOOL Selected    
00185             ): NodeAttribute(ContextNode, Direction, Locked, Mangled, Marked, Selected)  
00186 {   
00187     Value=WebAddressAttribute();
00188 } 
00189 
00190 /********************************************************************************************
00191 
00192 >   AttrWebAddress::AttrWebAddress(WebAddress url, BOOL fBounding=FALSE, TCHAR* pcFrame=NULL)
00193 
00194     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00195     Created:    27/3/97
00196     Inputs:     -
00197     Outputs:    -
00198     Returns:    -
00199     Purpose:    Specific constructor for an AttrWebAddress
00200     Errors:     -
00201     SeeAlso:    -
00202 
00203 ********************************************************************************************/
00204 
00205 AttrWebAddress::AttrWebAddress(WebAddress url, BOOL fBounding, TCHAR* pcFrame)
00206 {
00207     //Construct our Value member variable using the WebAddressAttribute constructor
00208     Value=WebAddressAttribute(url, fBounding, pcFrame);
00209 }
00210 
00211 /********************************************************************************************
00212 
00213 >   AttrWebAddress::AttrWebAddress(TCHAR* pcURL, BOOL fBounding=FALSE, TCHAR* pcFrame=NULL)
00214 
00215     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00216     Created:    27/3/97
00217     Inputs:     -
00218     Outputs:    -
00219     Returns:    -
00220     Purpose:    Specific constructor for an AttrWebAddress
00221     Errors:     -
00222     SeeAlso:    -
00223 
00224 ********************************************************************************************/
00225 
00226 AttrWebAddress::AttrWebAddress(TCHAR* pcURL, BOOL fBounding, TCHAR* pcFrame)
00227 {
00228     //Construct our Value member variable using the WebAddressAttribute constructor
00229     Value=WebAddressAttribute(pcURL, fBounding, pcFrame);
00230 }
00231 
00232 
00233 /*********************************
00234 
00235   Overloaded operators
00236 
00237   *******************************/
00238 
00239 /********************************************************************************************
00240 
00241 >   INT32 AttrWebAddress::operator==(const NodeAttribute& naCompare)
00242 
00243     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00244     Created:    27/3/97
00245     Inputs:     naCompare       The NodeAttribute against which to compare this one
00246     Outputs:    -
00247     Returns:    TRUE if naCompare is identical to this attribute
00248                 FALSE if naCompare is not an AttrWebAddress or if the value
00249                         stored in naCompare is different from the one stored
00250                         in this attribute
00251     Purpose:    A virtual comparison operator.
00252 
00253                 It checks that:
00254                 a. naCompare and this attribute are the same class
00255                 b. naCompare and this attribute hold identical Value member variables
00256                                                                                       
00257     Errors:     -
00258                  
00259     SeeAlso:    NodeAttribute::operator==; WebAddressAttribute::IsDifferent()
00260 
00261 ********************************************************************************************/
00262 
00263 INT32 AttrWebAddress::operator==(const NodeAttribute& naCompare)
00264 {
00265     //If naCompare is not an AttrWebAddress, return FALSE
00266     if (!naCompare.IsKindOf(CC_RUNTIME_CLASS(AttrWebAddress)))
00267         return FALSE;
00268 
00269     //Otherwise, cast naCompare into an AttrWebAddress pointer
00270     AttrWebAddress* pwaAttr = (AttrWebAddress*) &naCompare;
00271              
00272     //And check whether the member variables are the same
00273     BOOL fAreDifferent=Value.IsDifferent((AttributeValue*) &(pwaAttr->Value));
00274 
00275     //And return accordingly
00276     return (!fAreDifferent); 
00277 } 
00278 
00279 /*********************************
00280 
00281   Operations
00282 
00283   *******************************/
00284 
00285 /********************************************************************************************
00286 
00287 >   void AttrWebAddress::Render( RenderRegion* pRender)
00288 
00289     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00290     Created:    27/3/97
00291     Inputs:     pRender     The region into which to render this attribute
00292     Outputs:    -
00293     Returns:    -
00294     Purpose:    Set this attribute as current in the render region
00295     Errors:     -
00296     SeeAlso:    -
00297 
00298 ********************************************************************************************/
00299 
00300 void AttrWebAddress::Render( RenderRegion* pRender)
00301 {
00302     //Check the render region pointer
00303     if (pRender==NULL)
00304         ERROR2RAW("AttrWebAddress::Render - pRender is NULL");
00305 
00306     //Set the clickable rectangle of our WebAddressAttribute
00307     Value.SetClickableRectangleInRendering(GetClickableRectangle());
00308 
00309     //Then set our WebAddressAttribute member variable into that render region
00310     pRender->SetWebAddress(&Value, FALSE);
00311 }
00312 
00313 /********************************************************************************************
00314 
00315 >   virtual BOOL AttrWebAddress::Blend(BlendAttrParam* pBlendParam)
00316 
00317     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> from MarkN
00318     Created:    27/3/97
00319     Inputs:     pBlendParam = ptr to blend attribute param object holding all info needed
00320     Outputs:    -
00321     Returns:    TRUE if successful, FALSE otherwise
00322     Purpose:    Blends one Web Address attribute with another.
00323                 
00324     SeeAlso:    WebAddressAttribute::Blend
00325 
00326 ********************************************************************************************/
00327 
00328 BOOL AttrWebAddress::Blend(BlendAttrParam* pBlendParam)
00329 {
00330     //Check our parameter
00331     ERROR2IF(pBlendParam == NULL, FALSE, "AttrWebAddress::Blend - NULL parameter");
00332     
00333     //Try and blend our WebAddressAttribute member variable
00334     if (Value.Blend(pBlendParam))
00335     {
00336         // Get the blended attr val. After this call, the ptr is our reponsibility
00337         // so we have to delete it if it's no longer needed
00338         AttributeValue* pBlendedAttrVal = pBlendParam->GetBlendedAttrVal();
00339 
00340         if (pBlendedAttrVal != NULL)
00341         {
00342             // We have a blended attr val, so ask it to make a NodeAttribute out of itself
00343             // and set the pBlendParam's blended NodeAttribute ptr to it
00344             NodeAttribute* pBlendedAttr = pBlendedAttrVal->MakeNode();
00345             pBlendParam->SetBlendedAttr(pBlendedAttr);
00346 
00347             if (pBlendedAttr != NULL)
00348             {
00349                 // We were able to make a blended NodeAttribute
00350                 // so delete the blended attr val, and return TRUE
00351                 delete pBlendedAttrVal;
00352                 return TRUE;
00353             }
00354             else
00355             {
00356                 // Couldn't make a blended NodeAttribute, so give the blended attr val back
00357                 // and return FALSE
00358                 pBlendParam->SetBlendedAttrVal(pBlendedAttrVal);
00359                 return FALSE;
00360             }
00361         }
00362     }
00363         
00364     return FALSE;
00365 }
00366 
00367 /********************************************************************************************
00368 
00369   > virtual BOOL AttrWebAddress::WritePreChildrenWeb(BaseCamelotFilter* pFilter)
00370 
00371     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00372     Created:    27/3/97
00373     Inputs:     pFilter - ptr to the filter
00374     Returns:    TRUE if record is written, FALSE if not
00375     Purpose:    Writes this AttrWebAddress out to the filter.
00376 
00377     SeeAlso:    AttrWebAddress::WriteString
00378 
00379 ********************************************************************************************/
00380 
00381 BOOL AttrWebAddress::WritePreChildrenWeb(BaseCamelotFilter* pFilter)
00382 {
00383 #ifdef DO_EXPORT
00384     //Check our incoming parameter
00385     ERROR2IF(pFilter == NULL,FALSE,"AttrWebAddress::WritePreChildrenWeb - NULL parameter");
00386 
00387     //Set up some variables.
00388     //This pointer points to the record we are currently writing
00389     CamelotFileRecord* pRecord=NULL;
00390 
00391     // Add a description of the TAG_MOULD_BOUNDS record, for older importers that don't understand this record
00392     pFilter->AddTagDescription(TAG_WEBADDRESS,_R(IDS_TAG_WEBADDRESS));
00393 
00394     //And this lets us know whether there's been an error
00395     BOOL ok=TRUE;
00396 
00397     //Now, is the clickable area of this attribute the bounding box?
00398     if (Value.m_fBounding)
00399     {
00400         //Yes it is.
00401         //So create a "bounding box" record
00402         pRecord=new CamelotFileRecord(pFilter,TAG_WEBADDRESS_BOUNDINGBOX,TAG_WEBADDRESS_SIZE);
00403 
00404         //Check it's been created OK
00405         ok=(pRecord!=NULL);
00406 
00407         //Initialise it
00408         if (ok)
00409             pRecord->Init();
00410 
00411         //We also want to write out the start of the record, which is the clickable
00412         //rectangle of this record
00413 
00414         //So get the clickable rectangle
00415         DocRect rectBounding=GetClickableRectangle();
00416 
00417         //And write it out
00418         pRecord->WriteCoordInterleaved(rectBounding.lo);
00419         pRecord->WriteCoordInterleaved(rectBounding.hi);
00420     }
00421     else
00422     {
00423         //No, the clickable area of this attribute is the object shape
00424         //So create a normal Web Address record
00425         pRecord=new CamelotFileRecord(pFilter,TAG_WEBADDRESS,TAG_WEBADDRESS_SIZE);
00426 
00427         //And check it's been created OK
00428         ok=(pRecord!=NULL);
00429 
00430         //Initialise it
00431         if (ok)
00432             pRecord->Init();
00433     }
00434 
00435     //The rest of the data we need to write out is common to both types of record.
00436     //We need to write out the URL and Frame strings, in that order.
00437 
00438     
00439     //So write out the URL string
00440     String_256 strToWrite=Value.m_url.GetWebAddress();
00441 
00442     if (ok)
00443         ok=WriteString(pRecord, strToWrite);
00444 
00445     //And the Frame string
00446 
00447     //We do this using our toolkit function WriteString. This function
00448     //will write out a NULL character if the character pointer we pass it
00449     //is NULL
00450     if (ok)
00451         ok=WriteString(pRecord, Value.m_pcFrame);
00452 
00453     //And write out our record
00454     if (ok) 
00455         ok = pFilter->Write(pRecord);
00456 
00457     //And delete it
00458     delete pRecord;
00459 
00460     return ok;
00461 #else
00462     return FALSE;
00463 #endif
00464 }
00465 
00466 /********************************************************************************************
00467 
00468   > virtual BOOL AttrWebAddress::WritePreChildrenNative(BaseCamelotFilter* pFilter)
00469 
00470     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00471     Created:    27/3/97
00472     Inputs:     pFilter - ptr to the filter
00473     Returns:    TRUE if record is written, FALSE if not
00474     Purpose:    Writes this AttrWebAddress out to the filter.
00475 
00476                 Native records are written out in exactly the same way as Web
00477                 records are. So we simply call WritePreChildrenWeb()
00478 
00479     SeeAlso:    AttrWebAddress::WritePreChildrenWeb()
00480 
00481 ********************************************************************************************/
00482 BOOL AttrWebAddress::WritePreChildrenNative(BaseCamelotFilter* pFilter)
00483 {
00484 #ifdef DO_EXPORT
00485     return WritePreChildrenWeb(pFilter);
00486 #else
00487     return FALSE;
00488 #endif
00489 }
00490 
00491 /***********************************************************************************************
00492 > Node* AttrWebAddress::SimpleCopy() 
00493 
00494     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> from Will
00495     Created:    27/3/97
00496     Inputs:     - 
00497     Outputs:    -
00498     Returns:    A copy of the node, or NULL if memory runs out 
00499          
00500     Purpose:    This method returns a shallow copy of the node with all Node pointers NULL. 
00501                 The function is virtual, and must be defined for all derived classes.  
00502 
00503     Errors:     If memory runs out when trying to copy, then ERROR is called with an out of memory
00504                 error and the function returns NULL. 
00505     
00506     Scope:      protected       
00507 ***********************************************************************************************/
00508      
00509 Node* AttrWebAddress::SimpleCopy()
00510 {
00511     AttrWebAddress* NodeCopy = new AttrWebAddress();
00512     ERRORIF(NodeCopy == NULL, _R(IDE_NOMORE_MEMORY), NULL); 
00513     CopyNodeContents(NodeCopy);
00514     return NodeCopy;
00515 } 
00516 
00517 
00518 
00519 /***********************************************************************************************
00520 > ` void AttrWebAddress::CopyNodeContents( AttrWebAddress* NodeCopy)
00521 
00522     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> from Simon
00523     Created:    28/4/93
00524     
00525     Inputs:           
00526     Outputs:    A copy of this node
00527     Returns:    -
00528          
00529     Purpose:    This method copies the node's contents to the node pointed to by NodeCopy.
00530               
00531     Errors:     An assertion failure will occur if NodeCopy is NULL
00532     
00533     Scope:      protected
00534                                      
00535 ***********************************************************************************************/
00536 
00537 void AttrWebAddress::CopyNodeContents( AttrWebAddress* NodeCopy)
00538 {
00539     NodeAttribute::CopyNodeContents( NodeCopy );
00540     
00541     NodeCopy->Value=Value;
00542 } 
00543 
00544 
00545 
00546 /***********************************************************************************************
00547 >   void AttrWebAddress::PolyCopyNodeContents(NodeRenderable* pNodeCopy)
00548 
00549     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00550     Created:    18/12/2003
00551     Outputs:    -
00552     Purpose:    Polymorphically copies the contents of this node to another
00553     Errors:     An assertion failure will occur if NodeCopy is NULL
00554     Scope:      protected
00555                                      
00556 ***********************************************************************************************/
00557 
00558 void AttrWebAddress::PolyCopyNodeContents(NodeRenderable* pNodeCopy)
00559 {
00560     ENSURE(pNodeCopy, "Trying to copy a node's contents into a NULL node");
00561     ENSURE(IS_A(pNodeCopy, AttrWebAddress), "PolyCopyNodeContents given wrong dest node type");
00562 
00563     if (IS_A(pNodeCopy, AttrWebAddress))
00564         CopyNodeContents((AttrWebAddress*)pNodeCopy);
00565 }
00566 
00567 
00568 
00569 /***********************************************************************************************
00570 > ` DocRect AttrWebAddress::GetClickableRectangle()
00571 
00572     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00573     Created:    27/3/97
00574     
00575     Inputs:     -
00576     Outputs:    -
00577     Returns:    The clickable rectangle of this Web Address attribute
00578          
00579     Purpose:    This function calls GetImagemapClickableRectangle() on this
00580                 node's parent.
00581 
00582                 If the parent node is a text character, the rectangle returned
00583                 will be the bounding box of that text character and all
00584                 adjacent text characters with the same Web Address attribute.
00585 
00586                 Otherwise, the rectangle returned will be the bounding box
00587                 of the parent node.
00588               
00589     Errors:     -
00590     SeeAlso:    NodeRenderableBounded::GetImagemapClickableRectangle(); 
00591                 AbstractTextChar::GetImagemapClickableRectangle()
00592     
00593     Scope:      protected
00594                                      
00595 ***********************************************************************************************/
00596 
00597 DocRect AttrWebAddress::GetClickableRectangle()
00598 {
00599     //Get our parent
00600     Node* pNode=FindParent();
00601 
00602     
00603     //If it's not an object, return a NULL value
00604     if (pNode==NULL)
00605         return DocRect(0,0,0,0);
00606     
00607     if (!pNode->IsAnObject())
00608         return DocRect(0,0,0,0);
00609 
00610     //Otherwise, return the bounding box of that object
00611     return (((NodeRenderableBounded*)pNode)->GetImagemapClickableRectangle());
00612                                                                                 
00613 } 
00614 
00615 /********************************************************************************************
00616 
00617 >   BOOL AttrWebAddress::WriteString(CamelotFileRecord* pcfrRecord, TCHAR* pcWrite)
00618 
00619     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00620     Created:    27/3/97
00621     Inputs:     pcWrite     Pointer to a string to write out to the record
00622     Outputs:    pcfrRecord  The record to write out to
00623     Returns:    -
00624     Purpose:    Writes pcWrite out to the file.
00625 
00626                 If pcWrite is NULL, a NULL character will be written out instead.
00627 
00628     SeeAlso:    -
00629 
00630 ********************************************************************************************/
00631 
00632 BOOL AttrWebAddress::WriteString(CamelotFileRecord* pcfrRecord, TCHAR* pcWrite)
00633 {
00634     //Does pcWrite point to a string?
00635     if (pcWrite)
00636     {
00637         //Yes. So write out that string.
00638         return pcfrRecord->WriteUnicode(pcWrite);
00639     }
00640     else
00641     {
00642         //No. So write out a NULL character
00643         TCHAR cNull='\0';
00644 
00645         return pcfrRecord->WriteUnicode(&cNull);
00646     }
00647 }
00648 
00649 
00650 #ifdef _DEBUG
00651 /***********************************************************************************************
00652 
00653 >   void AttrWebAddress::ShowDebugTreeDetails() const
00654 
00655     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00656     Created:    21/6/93
00657     Purpose:    Displays debugging info of the tree
00658 
00659 ***********************************************************************************************/
00660 
00661 void AttrWebAddress::ShowDebugTreeDetails() const
00662 {
00663     // Display a bit of debugging info
00664     NodeAttribute::ShowDebugTreeDetails();  
00665 }
00666 #endif
00667 
00668 
00669 void AttrWebAddress::GetDebugDetails(StringBase* Str)
00670 {
00671 #ifdef _DEBUG
00672     NodeAttribute::GetDebugDetails( Str );
00673 
00674     (*Str) += _T("URL=");
00675     (*Str) += Value.m_url.GetWebAddress();
00676     (*Str) += _T("\r\n");
00677 
00678     (*Str) += _T("Frame=");
00679     (*Str) += Value.m_pcFrame;
00680     (*Str) += _T("\r\n");
00681     
00682     if (Value.m_fBounding)
00683         (*Str) += _T("Clickable area is RECTANGLE\r\n");
00684     else
00685         (*Str) += _T("Clickable area is OBJECT SHAPE\r\n");
00686     
00687 #endif
00688 }
00689 
00690 /****************************************************************************************
00691 
00692   AttrWebAddress member functions
00693 
00694   ***************************************************************************************/
00695     
00696 /***********************************
00697 
00698   Constructors and initialiser
00699                                  
00700   **********************************/
00701 
00702 
00703 /********************************************************************************************
00704 
00705 >   WebAddressAttribute::WebAddressAttribute()
00706 
00707     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00708     Created:    27/3/97
00709     Inputs:     -
00710     Outputs:    -
00711     Returns:    -
00712     Purpose:    Default constructor
00713     Errors:     -
00714     SeeAlso:    -
00715 
00716 ********************************************************************************************/
00717 
00718 WebAddressAttribute::WebAddressAttribute()
00719 {
00720     //Set the URL to a default
00721     m_url=WebAddress();
00722 
00723     //Put "_self" into the Frame member variable
00724     String_256 strSelf(_R(IDS_WEBADDRESS_SHORT_SELF));
00725 
00726     m_pcFrame=NULL;
00727 
00728     CopyString(&m_pcFrame, strSelf);
00729 
00730     //Set the bounding flag to FALSE
00731     m_fBounding=FALSE;
00732 }
00733 
00734 /********************************************************************************************
00735 
00736 >   WebAddressAttribute::WebAddressAttribute(WebAddress url, BOOL fBounding=FALSE, TCHAR* pcFrame=NULL)
00737 
00738     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00739     Created:    27/3/97
00740     Inputs:     New values for member variables
00741     Outputs:    -
00742     Returns:    -
00743     Purpose:    Specific constructor for a Web Address attribute
00744     Errors:     -
00745     SeeAlso:    -
00746 
00747 ********************************************************************************************/
00748 
00749 WebAddressAttribute::WebAddressAttribute(WebAddress url, BOOL fBounding, TCHAR* pcFrame)
00750 {
00751     //First set our member variable string pointer to NULL, 
00752     //so that CopyString doesn't try to delete it
00753     m_pcFrame=NULL;
00754     
00755     //Then copy everything into our member variables
00756     m_url=url;
00757     CopyString(&m_pcFrame, pcFrame);
00758     m_fBounding=fBounding;
00759 
00760     //And set the clickable in rendering rectangle to a zero value
00761     //(See header file for a description of this variable)
00762     m_rectClickableInRendering=DocRect(0,0,0,0);
00763 }
00764 
00765 /********************************************************************************************
00766 
00767 >   WebAddressAttribute::WebAddressAttribute(WebAddress url, BOOL fBounding=FALSE, TCHAR* pcFrame=NULL)
00768 
00769     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00770     Created:    27/3/97
00771     Inputs:     New values for member variables
00772     Outputs:    -
00773     Returns:    -
00774     Purpose:    Specific constructor for a Web Address attribute
00775     Errors:     -
00776     SeeAlso:    -
00777 
00778 ********************************************************************************************/
00779 
00780 WebAddressAttribute::WebAddressAttribute(TCHAR* pcURL, BOOL fBounding, TCHAR* pcFrame)
00781 {
00782     //Simply put pcURL into a string
00783     String_256 strURL=pcURL;
00784 
00785     //Put that into a Web Address
00786     WebAddress urlURL(strURL);
00787 
00788     m_pcFrame=NULL;
00789 
00790     //And make our attribute as normal
00791     *this=WebAddressAttribute(urlURL, fBounding, pcFrame);
00792 }
00793 
00794 
00795 /********************************************************************************************
00796 
00797 >   BOOL WebAddressAttribute::Init()
00798 
00799     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00800     Created:    27/3/97
00801     Inputs:     -
00802     Outputs:    -
00803     Returns:    -
00804     Purpose:    Registers the default WebAddressAttribute
00805     Errors:     -
00806     SeeAlso:    -
00807 
00808 ********************************************************************************************/
00809 
00810 BOOL WebAddressAttribute::Init()
00811 {
00812     WebAddressAttribute *pAttr = new WebAddressAttribute();
00813     
00814     if (pAttr == NULL)
00815         return FALSE;
00816 
00817     UINT32 ID = AttributeManager::RegisterDefaultAttribute(CC_RUNTIME_CLASS(NodeRenderableInk), 
00818                                                          pAttr);
00819     if (ID == ATTR_BAD_ID)
00820         return FALSE;
00821 
00822     ENSURE(ID == ATTR_WEBADDRESS, "Incorrect ID for Web Address attribute!");
00823     return TRUE;
00824 }
00825 
00826 
00827 /******************************************************
00828 
00829   Copy constructor, destructor and assignment operator
00830 
00831   *****************************************************/
00832 /********************************************************************************************
00833 
00834 >   WebAddressAttribute::WebAddressAttribute(const WebAddressAttribute& waaCopy)
00835 
00836     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00837     Created:    27/3/97
00838     Inputs:     WebAddressAttribute to copy
00839     Outputs:    -
00840     Returns:    *this
00841     Purpose:    Copy constructor
00842     Errors:     -
00843     SeeAlso:    -
00844 
00845 ********************************************************************************************/
00846 
00847 WebAddressAttribute::WebAddressAttribute(const WebAddressAttribute& waaCopy)
00848 {
00849     //Set our member variables to NULL
00850     m_pcFrame=NULL;
00851 
00852     m_rectClickableInRendering=DocRect(0,0,0,0);
00853 
00854     //Simply use the assigment operator
00855     *this=waaCopy;
00856                            
00857 }
00858 
00859 /********************************************************************************************
00860 
00861 >   WebAddressAttribute::~WebAddressAttribute()
00862 
00863     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00864     Created:    27/3/97
00865     Inputs:     -
00866     Outputs:    -
00867     Returns:    -
00868     Purpose:    Destructor
00869     Errors:     -                          
00870     SeeAlso:    -
00871 
00872 ********************************************************************************************/
00873 
00874 WebAddressAttribute::~WebAddressAttribute()
00875 {
00876     if (m_pcFrame)
00877         free(m_pcFrame);
00878 }
00879 
00880 /********************************************************************************************
00881 
00882 >   WebAddressAttribute& operator= (const WebAddressAttribute& waaOther)                    
00883 
00884     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00885     Created:    27/3/97
00886     Inputs:     waaOther    Attribute to copy
00887     Outputs:    -
00888     Returns:    -
00889     Purpose:    Assignment operator
00890     Errors:     -
00891     SeeAlso:    -
00892 
00893 ********************************************************************************************/
00894 
00895 WebAddressAttribute& WebAddressAttribute::operator= (const WebAddressAttribute& waaOther)                   
00896 {
00897     //Copy everything into our member variables
00898     m_url=waaOther.m_url;
00899     CopyString(&m_pcFrame, waaOther.m_pcFrame);
00900     m_rectClickableInRendering=waaOther.m_rectClickableInRendering;
00901     m_fBounding=waaOther.m_fBounding;
00902 
00903     return *this;
00904 }
00905 
00906 /**********************************
00907 
00908   Operations
00909 
00910   **********************************/
00911 
00912 /********************************************************************************************
00913 
00914 >   void WebAddressAttribute::Render(RenderRegion *pRegion, BOOL Temp)
00915 
00916     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00917     Created:    23/3/97
00918     Inputs:     pRegion - the render region to render this attribute into.
00919     Purpose:    Sets this Web Address attribute as current within the render
00920                 region.
00921 
00922                 Note that nothing is actually seen on screen as a result
00923                 of rendering the Web Address Attribute.
00924 
00925 ********************************************************************************************/
00926 
00927 void WebAddressAttribute::Render(RenderRegion *pRegion, BOOL Temp)
00928 {
00929     pRegion->SetWebAddress(this, Temp);
00930 }
00931 
00932 /********************************************************************************************
00933 
00934 >   void WebAddressAttribute::Restore(RenderRegion *pRegion, BOOL Temp)
00935 
00936     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00937     Created:    23/3/97
00938     Inputs:     pRegion - the render region to render this attribute into.
00939     Purpose:    Restores this Web Address attribute into the region
00940 
00941 ********************************************************************************************/
00942 
00943 void WebAddressAttribute::Restore(RenderRegion *pRegion, BOOL Temp)
00944 {
00945     pRegion->RestoreWebAddress(this, Temp);
00946 }
00947 
00948 /********************************************************************************************
00949 
00950 >   void WebAddressAttribute::SimpleCopy(AttributeValue *pValue)
00951 
00952     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00953     Created:    27/3/97
00954     Inputs:     pValue - pointer to the value to copy
00955     Purpose:    Assignment operator
00956     SeeAlso:    WebAddressAttribute::operator=
00957 
00958 ********************************************************************************************/
00959 
00960 void WebAddressAttribute::SimpleCopy(AttributeValue *pValue)
00961 {
00962     //Check parameter
00963     if (pValue==NULL)
00964     {
00965         ERROR2RAW("WebAddressAttribute::SimpleCopy - NULL parameter");
00966         return;
00967     }
00968 
00969 
00970 
00971     //If pValue is a Web Address
00972     if (pValue->IsKindOf(CC_RUNTIME_CLASS(WebAddressAttribute)))
00973     {
00974         //Copy it into this attribute
00975         *this=*((WebAddressAttribute*) pValue);
00976     }
00977     else
00978         //Make this attribute blank
00979         *this=WebAddressAttribute();
00980 }
00981 
00982 /********************************************************************************************
00983 
00984 >   NodeAttribute* WebAddressAttribute::MakeNode()
00985 
00986     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> from Tim
00987     Created:    27/3/97
00988     Returns:    Pointer to the new node, or NULL if out of memory.
00989     Purpose:    Make a AttrWebAddress node from this line width attribute.
00990     Errors:     Out of memory
00991     SeeAlso:    AttributeValue::MakeNode
00992 
00993 ********************************************************************************************/
00994 
00995 NodeAttribute *WebAddressAttribute::MakeNode()
00996 {
00997     // Create new attribute node
00998     AttrWebAddress *pAttr = new AttrWebAddress();
00999 
01000     // Copy attribute value into the new node
01001     pAttr->Value=*this;
01002 
01003     // Return the new node
01004     return pAttr;
01005 }
01006 
01007 /********************************************************************************************
01008 
01009 >   BOOL WebAddressAttribute::IsDifferent(AttributeValue *pAttr)
01010 
01011     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
01012     Created:    27/3/97
01013     Purpose:    Determines whether the two attributes are different
01014 
01015                 If the two attributes are of different types, FALSE is returned.
01016 
01017     Errors:     -
01018     SeeAlso:    AttributeValue::IsDifferent
01019 
01020 ********************************************************************************************/
01021 
01022 BOOL WebAddressAttribute::IsDifferent(AttributeValue *pAttr)
01023 {
01024     //Check parameter
01025     ERROR2IF(pAttr==NULL, FALSE, "WebAddressAttribute::IsDifferent - NULL parameter");
01026 
01027     //If pAttr doesn't point to a WebAddressAttribute, return FALSE
01028     if (!pAttr->IsKindOf(CC_RUNTIME_CLASS(WebAddressAttribute)))
01029         return FALSE;
01030 
01031     //Cast pAttr into a WebAddressAttribute*
01032     WebAddressAttribute* pwaaThis=(WebAddressAttribute*) pAttr;
01033 
01034     //And now check whether each of the member strings are different
01035     BOOL fSameURL=(m_url==pwaaThis->m_url);
01036     BOOL fSameFrame=AreStringsEqual(m_pcFrame, pwaaThis->m_pcFrame);
01037     BOOL fSameArea=(m_fBounding==pwaaThis->m_fBounding);
01038         
01039     //If any of them were different, return TRUE
01040     return (!fSameURL || !fSameFrame || !fSameArea);
01041 }
01042 
01043 /********************************************************************************************
01044 
01045 >   BOOL WebAddressAttribute::Blend(BlendAttrParam *pBlendParam)
01046 
01047     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> from Markn
01048     Created:    27/3/97
01049     Inputs:     pBlendParam = ptr to param holding all data needed for the attr val to blend
01050     Outputs:    if TRUE  returned, pBlendParam->GetBlendedAttrVal() will get ptr to the blended attr val
01051                 if FALSE returned, pBlendParam->GetBlendedAttrVal() will return NULL
01052     Returns:    TRUE if successful, FALSE otherwaie
01053     Purpose:    Blends this attr val with the attr val held in pBlendParam
01054     SeeAlso:    -
01055 
01056 ********************************************************************************************/
01057 
01058 BOOL WebAddressAttribute::Blend(BlendAttrParam *pBlendParam)
01059 {
01060     // Check entry param
01061     ERROR3IF(pBlendParam == NULL,"NULL entry param");
01062     if (pBlendParam == NULL) return FALSE;
01063 
01064     WebAddressAttribute* pOtherWebAttr = (WebAddressAttribute*) pBlendParam->GetOtherAttrVal();
01065     
01066     // Check that the other line attr val is not NULL, and is a WebAddressAttribute
01067     ERROR3IF(pOtherWebAttr == NULL,"NULL other attr val");
01068     ERROR3IF(!IS_A(pOtherWebAttr,WebAddressAttribute),"other attr val not a Web Address attr");
01069     if (pOtherWebAttr == NULL || !IS_A(pOtherWebAttr,WebAddressAttribute)) return FALSE;
01070 
01071     // If both attributes do not have a URL then we must return FALSE. 
01072     // Bug fix - Ranbirr 17/03/98
01073     if(!this->HasURL() && !pOtherWebAttr->HasURL())
01074         return FALSE;
01075 
01076     // Get a new WebAddressAttribute to hold the blended version, (return FALSE if this fails)
01077     WebAddressAttribute* pBlendedWebAttr = new WebAddressAttribute;
01078     if (pBlendedWebAttr == NULL) return FALSE;
01079 
01080     //If the blend ratio is less than 0.5, we use this WebAddressAttribute.
01081     //Otherwise, we use the other WebAddressAttribute
01082     double dRatio=pBlendParam->GetBlendRatio();
01083 
01084     if (dRatio<0.5)
01085         *pBlendedWebAttr=*this;
01086     else
01087         *pBlendedWebAttr=*pOtherWebAttr;
01088 
01089     // Store the ptr to the new blended line width attr val
01090     pBlendParam->SetBlendedAttrVal(pBlendedWebAttr);
01091 
01092     return TRUE;
01093 }
01094 
01095 /**********************************
01096 
01097   Toolkit functions
01098 
01099   **********************************/
01100 
01101 
01102 /********************************************************************************************
01103 
01104 void WebAddressAttribute::CopyString(TCHAR** ppcCopyTo, const TCHAR* pcCopyFrom)
01105 
01106     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
01107     Created:    27/3/97
01108     Inputs:     ppcCopyTo   Pointer to a string pointer to copy the string to
01109                 pcCopyFrom  String pointer to copy from
01110     Outputs:    ppcCopyTo
01111     Returns:    -
01112     Purpose:    IF pcCopyFrom is NULL
01113                     then the string pointer that ppcCopyTo is set to NULL
01114 
01115                 ELSE IF pcCopyFrom points to a string
01116                     then that string is copied into the string pointer that
01117                     pcCopyTo pointer to
01118 
01119                 This function will handle pcCopyFrom or *ppcCopyTo being NULL,
01120                 but ppcCopyTo must be valid. It's obvious if you think about it.
01121 
01122     SeeAlso:    -
01123 
01124 ********************************************************************************************/
01125 
01126 void WebAddressAttribute::CopyString(TCHAR** ppcCopyTo, const TCHAR* pcCopyFrom)
01127 {
01128     //We need to check that ppcCopyTo is valid
01129     if (ppcCopyTo==NULL)
01130     {
01131         ERROR2RAW("WebAddress::CopyString passed NULL parameter");
01132         return;
01133     }
01134 
01135     //Now, if *ppcCopyTo points to a string, we delete it now
01136     if (*ppcCopyTo)
01137     {
01138         free (*ppcCopyTo);
01139         *ppcCopyTo=NULL;    
01140     }
01141         
01142     //Does pcCopyFrom point to a string?
01143     if (pcCopyFrom)
01144     {
01145         //Yes (we assume it does if it's not NULL)
01146         //So copy that string into *ppcCopyTo
01147         (*ppcCopyTo) = camStrdup( pcCopyFrom );
01148     }
01149 
01150     //If pcCopyFrom is NULL, then ppcCopyTo is NULL, which is correct
01151     //So return
01152 }
01153 
01154 /********************************************************************************************
01155 
01156 BOOL WebAddressAttribute::AreStringsEqual(TCHAR* pcFirst, TCHAR* pcSecond)
01157 
01158     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
01159     Created:    27/3/97
01160     Inputs:     pcFirst, pcSecond - the two strings to compare
01161     Outputs:    ppcCopyTo
01162     Returns:    TRUE IF pcFirst, pcSecond are both NULL
01163                      OR if they point to identical strings
01164                 FALSE otherwise
01165     Purpose:    To compare two string pointers
01166 b               
01167                 Note that this function handles its input parameters being NULL
01168     SeeAlso:    -
01169 
01170 ********************************************************************************************/
01171 
01172 BOOL WebAddressAttribute::AreStringsEqual(TCHAR* pcFirst, TCHAR* pcSecond)
01173 {
01174     //If either of our incoming string pointers is NULL
01175     if (pcFirst==NULL || pcSecond==NULL)
01176         //Then return TRUE if they are both NULL and FALSE otherwise
01177         return (pcFirst==pcSecond);
01178 
01179     //Otherwise, return the result of comparing the two strings
01180     return (camStrcmp(pcFirst, pcSecond)==0);
01181 }
01182 
01183 
01184 
01185 
01186 
01187                                           

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