rechattr.cpp

Go to the documentation of this file.
00001 // $Id: rechattr.cpp 1698 2006-08-13 19:47:04Z 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 #include "camtypes.h"                          
00100 #include "rechattr.h"   // Record handling classes for attributes
00101 #include "qualattr.h"
00102 #include "webattr.h"
00103 #include "userattr.h"
00104 
00105 
00106 //#include "hotlink.h"      //For USERATTRKEY_WEBADDRESS
00107 
00108 #include "cxftags.h"
00109 //#include "cxfrec.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 
00111 DECLARE_SOURCE("$Revision: 1698 $");
00112 
00113 CC_IMPLEMENT_DYNAMIC(GeneralAttrRecordHandler, CamelotRecordHandler)
00114 
00115 // Declare smart memory handling in Debug builds
00116 // Give this file in memory dumps
00117 #define new CAM_DEBUG_NEW
00118     
00119 
00120 //---------------------------------------------------------------------------------------
00121 //---------------------------------------------------------------------------------------
00122 //---------------------------------------------------------------------------------------
00123 
00124 /********************************************************************************************
00125 
00126 >   virtual UINT32* GeneralAttrRecordHandler::GetTagList()
00127 
00128     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00129     Created:    25/7/96
00130     Inputs:     -
00131     Returns:    Ptr to a list of tag values, terminated by CXFRH_TAG_LIST_END
00132     Purpose:    Provides the record handler system with a list of records handled by this
00133                 handler
00134     SeeAlso:    -
00135 
00136 ********************************************************************************************/
00137 
00138 UINT32* GeneralAttrRecordHandler::GetTagList()
00139 {
00140     static UINT32 TagList[] = { TAG_QUALITY,
00141                                 TAG_USERVALUE,
00142                                 TAG_WEBADDRESS,
00143                                 TAG_WEBADDRESS_BOUNDINGBOX,
00144                                 CXFRH_TAG_LIST_END};
00145 
00146     return (UINT32*)&TagList;
00147 }
00148 
00149 /********************************************************************************************
00150 
00151 >   virtual BOOL GeneralAttrRecordHandler::HandleRecord(CXaraFileRecord* pCXaraFileRecord)
00152 
00153     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00154     Created:    25/7/96
00155     Inputs:     pCXaraFileRecord = ptr to record to handle
00156     Returns:    TRUE if handled successfuly
00157                 FALSE otherwise
00158     Purpose:    Handles the given record.
00159     SeeAlso:    -
00160 
00161 ********************************************************************************************/
00162 
00163 BOOL GeneralAttrRecordHandler::HandleRecord(CXaraFileRecord* pCXaraFileRecord)
00164 {
00165     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00166 
00167     BOOL ok = TRUE;
00168 
00169     switch (pCXaraFileRecord->GetTag())
00170     {
00171         case TAG_QUALITY:
00172             ok = HandleQualityRecord(pCXaraFileRecord);
00173             break;
00174 
00175         case TAG_USERVALUE:
00176             ok = HandleUserValueRecord(pCXaraFileRecord);
00177             break;
00178 
00179         case TAG_WEBADDRESS:
00180             ok = HandleWebAddressRecord(pCXaraFileRecord);
00181             break;
00182 
00183         case TAG_WEBADDRESS_BOUNDINGBOX:
00184             ok = HandleWebAddressBoundingBoxRecord(pCXaraFileRecord);
00185             break;
00186 
00187         default:
00188             ok = FALSE;
00189             ERROR3_PF(("I don't handle records with the tag (%d)\n",pCXaraFileRecord->GetTag()));
00190             break;
00191     }
00192 
00193     return ok;
00194 }
00195 
00196 
00197 /********************************************************************************************
00198 
00199 >   BOOL GeneralAttrRecordHandler::HandleQualityRecord(CXaraFileRecord* pCXaraFileRecord)
00200 
00201     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00202     Created:    25/7/96
00203     Inputs:     pCXaraFileRecord = ptr to record to handle
00204     Returns:    TRUE if handled successfuly
00205                 FALSE otherwise
00206     Purpose:    Handles the given record.
00207                 The record has to be a quality record (and I don't mean a record of high grade)
00208     SeeAlso:    -
00209 
00210 ********************************************************************************************/
00211 
00212 BOOL GeneralAttrRecordHandler::HandleQualityRecord(CXaraFileRecord* pCXaraFileRecord)
00213 {
00214     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00215     ERROR2IF(pCXaraFileRecord->GetTag() != TAG_QUALITY,FALSE,"I don't handle this tag type");
00216 
00217     INT32 Quality = 0;
00218     BOOL ok = pCXaraFileRecord->ReadINT32(&Quality);
00219 
00220     if (ok)
00221     {
00222         AttrQuality* pQual = new AttrQuality;
00223         if (pQual != NULL)
00224         {
00225             pQual->Value.QualityValue.SetQuality(Quality);
00226             ok = InsertNode(pQual);
00227         }
00228         else
00229             ok = FALSE;
00230     }
00231 
00232     return ok;
00233 }
00234 
00235 /********************************************************************************************
00236 
00237 >   BOOL GeneralAttrRecordHandler::HandleUserValueRecord(CXaraFileRecord* pCXaraFileRecord)
00238 
00239     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00240     Created:    22/8/96 - amended by Graham 23/3/97 to use the new Web Address record
00241     Inputs:     pCXaraFileRecord = ptr to record to handle
00242     Returns:    TRUE if handled successfuly
00243                 FALSE otherwise
00244     Purpose:    Handles the given record.
00245                 The record has to be a UserAttribute (ValueAttribute) record
00246     SeeAlso:    -
00247 
00248 ********************************************************************************************/
00249 
00250 BOOL GeneralAttrRecordHandler::HandleUserValueRecord(CXaraFileRecord* pCXaraFileRecord)
00251 {
00252     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00253     ERROR2IF(pCXaraFileRecord->GetTag() != TAG_USERVALUE,FALSE,"I don't handle this tag type");
00254 
00255     String_256 Key;
00256     String_256 Value;
00257     BOOL ok = TRUE;
00258     if (ok) ok = pCXaraFileRecord->ReadUnicode((LPTSTR)Key, 256);
00259     if (ok) ok = pCXaraFileRecord->ReadUnicode((LPTSTR)Value, 256);
00260 
00261     if (ok)
00262     {
00263         //We need to test the Key, to see if this is an old-style Web Address
00264         String_256 strKey=Key;
00265         String_256 strWebAddressKey(_R(IDS_USERATTRKEY_WEBADDRESS));
00266 
00267         //If this is an old-style Web Address
00268         if (strKey==strWebAddressKey)
00269         {
00270             //Then put it in the node tree
00271             AttrWebAddress* pAttrWebAddress = new AttrWebAddress((TCHAR*)Value);
00272         
00273             if (pAttrWebAddress)
00274                 ok = InsertNode(pAttrWebAddress);
00275             else
00276                 ok = FALSE;
00277         }
00278         else
00279         {
00280             // We wrote out the INT32 key, so Key is actually that
00281             AttrUser* const pNewAttr = new AttrUser(Key, Value);
00282         
00283             if (pNewAttr != NULL)
00284             {
00285                 ok = InsertNode(pNewAttr);
00286             }
00287             else
00288             {
00289                 ok = FALSE;
00290             }
00291         }
00292 
00293     }
00294 
00295     return ok;
00296 }
00297 
00298 /********************************************************************************************
00299 
00300 >   BOOL GeneralAttrRecordHandler::HandleWebAddressRecord(CXaraFileRecord* pCXaraFileRecord)
00301 
00302     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00303     Created:    25/3/97
00304     Inputs:     pCXaraFileRecord = ptr to record to handle
00305     Returns:    TRUE if handled successfuly
00306                 FALSE otherwise
00307     Purpose:    Handles the given record.
00308                 The record has to be a WebAddress record
00309     SeeAlso:    -
00310 
00311 ********************************************************************************************/
00312 
00313 BOOL GeneralAttrRecordHandler::HandleWebAddressRecord(CXaraFileRecord* pCXaraFileRecord)
00314 {
00315     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00316     ERROR2IF(pCXaraFileRecord->GetTag() != TAG_WEBADDRESS,FALSE,"I don't handle this tag type");
00317 
00318     //First let's get the size of the record
00319     UINT32 ulSize=pCXaraFileRecord->GetSize();
00320 
00321     //And allocate two buffers of that size to put the URL and Frame strings in
00322     TCHAR* pcURL=new TCHAR[ulSize];
00323     TCHAR* pcFrame=new TCHAR[ulSize];
00324     BOOL ok = TRUE;
00325 
00326     //Read in the strings
00327     if (ok) ok = pCXaraFileRecord->ReadUnicode(pcURL, ulSize);
00328     if (ok) ok = pCXaraFileRecord->ReadUnicode(pcFrame, ulSize);
00329 
00330     //And create a new Web Address attribute out of them
00331     if (ok)
00332     {
00333         AttrWebAddress* pAttrWebAddress = new AttrWebAddress(pcURL, FALSE, pcFrame);
00334         
00335         if (pAttrWebAddress)
00336             ok = InsertNode(pAttrWebAddress);
00337         else
00338             ok = FALSE;
00339     }
00340 
00341     delete pcURL;
00342     delete pcFrame;
00343 
00344     return ok;
00345 }
00346 
00347 /********************************************************************************************
00348 
00349 >   BOOL GeneralAttrRecordHandler::HandleWebAddressBoundingBoxRecord(CXaraFileRecord* pCXaraFileRecord)
00350 
00351     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00352     Created:    25/3/97
00353     Inputs:     pCXaraFileRecord = ptr to record to handle
00354     Returns:    TRUE if handled successfuly
00355                 FALSE otherwise
00356     Purpose:    Handles the given record.
00357                 The record has to be a WebAddressBoundingBox record
00358     SeeAlso:    -
00359 
00360 ********************************************************************************************/
00361 
00362 BOOL GeneralAttrRecordHandler::HandleWebAddressBoundingBoxRecord(CXaraFileRecord* pCXaraFileRecord)
00363 {
00364     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00365     ERROR2IF(pCXaraFileRecord->GetTag() != TAG_WEBADDRESS_BOUNDINGBOX,FALSE,"I don't handle this tag type");
00366 
00367     //There will be two coordinates at the start of the file, which will describe the 
00368     //bounding box of the clickable area of this attribute
00369 
00370     //We don't need these: the bounding box of the clickable area of this attribute
00371     //is the bounding box of the this attribute's parent node. So we throw them away.
00372     DocCoord dcThrowAway;
00373     pCXaraFileRecord->ReadCoordInterleaved(&dcThrowAway);
00374     pCXaraFileRecord->ReadCoordInterleaved(&dcThrowAway);
00375         
00376     //Now get the size of the record
00377     UINT32 ulSize=pCXaraFileRecord->GetSize();
00378 
00379     //And allocate two buffers of that size to put the URL and Frame strings in
00380     TCHAR* pcURL=new TCHAR[ulSize];
00381     TCHAR* pcFrame=new TCHAR[ulSize];
00382     BOOL ok = TRUE;
00383 
00384     //Read in the strings
00385     if (ok) ok = pCXaraFileRecord->ReadUnicode(pcURL, ulSize);
00386     if (ok) ok = pCXaraFileRecord->ReadUnicode(pcFrame, ulSize);
00387 
00388     //And create a new Web Address attribute out of them
00389     if (ok)
00390     {
00391         AttrWebAddress* pAttrWebAddress = new AttrWebAddress(pcURL, TRUE, pcFrame);
00392         
00393         if (pAttrWebAddress)
00394             ok = InsertNode(pAttrWebAddress);
00395         else
00396             ok = FALSE;
00397     }
00398 
00399     delete pcURL;
00400     delete pcFrame;
00401 
00402     return ok;
00403 }
00404 
00405 
00406 
00407 /********************************************************************************************
00408 
00409 >   virtual void GeneralAttrRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord,StringBase* pStr)
00410 
00411     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00412     Created:    25/7/96
00413     Inputs:     pRecord = ptr to a record
00414                 pStr = ptr to string to update
00415     Returns:    -
00416     Purpose:    This provides descriptions for the misc attr records.
00417     Errors:     -
00418     SeeAlso:    -
00419 
00420 ********************************************************************************************/
00421 
00422 #ifdef XAR_TREE_DIALOG
00423 void GeneralAttrRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord,StringBase* pStr)
00424 {
00425     if (pStr == NULL || pRecord == NULL)
00426         return;
00427 
00428     TCHAR s[256];
00429 
00430     //   Call base class first
00431     CamelotRecordHandler::GetRecordDescriptionText(pRecord,pStr);
00432 
00433     switch (pRecord->GetTag())
00434     {
00435         case TAG_QUALITY:
00436         {
00437             INT32 Quality = 0;
00438             pRecord->ReadINT32(&Quality);
00439 
00440             camSprintf(s,_T("Quality = %d\r\n"),Quality);
00441             (*pStr) += s;
00442         }
00443         break;
00444 
00445         case TAG_USERVALUE:
00446         {
00447             TCHAR Key[256];
00448             TCHAR Value[256];
00449             pRecord->ReadUnicode(Key, 256);
00450             pRecord->ReadUnicode(Value, 256);
00451 
00452             camSprintf(s,_T("Key   = %s\r\n"),Key);
00453             (*pStr) += s;
00454             camSprintf(s,_T("Value = %s\r\n"),Value);
00455             (*pStr) += s;
00456         }
00457         break;
00458 
00459         case TAG_WEBADDRESS:
00460         {
00461             TCHAR URL[256];
00462             TCHAR Frame[256];
00463             pRecord->ReadUnicode(URL, 256);
00464             pRecord->ReadUnicode(Frame, 256);
00465 
00466             camSprintf(s,_T("URL   = %s\r\n"),URL);
00467             (*pStr) += s;
00468             camSprintf(s,_T("Frame = %s\r\n"),Frame);
00469             (*pStr) += s;
00470         }
00471         break;
00472 
00473         case TAG_WEBADDRESS_BOUNDINGBOX:
00474         {
00475             TCHAR URL[256];
00476             TCHAR Frame[256];
00477             DocCoord dcThrowAway;
00478             pRecord->ReadCoordInterleaved(&dcThrowAway);
00479             pRecord->ReadCoordInterleaved(&dcThrowAway);
00480 
00481             pRecord->ReadUnicode(URL, 256);
00482             pRecord->ReadUnicode(Frame, 256);
00483 
00484             camSprintf(s,_T("URL   = %s\r\n"),URL);
00485             (*pStr) += s;
00486             camSprintf(s,_T("Frame = %s\r\n"),Frame);
00487             (*pStr) += s;
00488         }
00489         break;
00490     }
00491 }
00492 #endif

Generated on Sat Nov 10 03:46:40 2007 for Camelot by  doxygen 1.4.4