rechdoc.cpp

Go to the documentation of this file.
00001 // $Id: rechdoc.cpp 1688 2006-08-10 12:05:20Z gerry $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // Header for the document record handling classes for the v2 file format
00099 
00100 #include "camtypes.h"
00101 #include "rechdoc.h"
00102 
00103 //#include <libintl.h>
00104 
00105 //#include "selop.h"
00106 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 #include "page.h"
00108 #include "layer.h"
00109 #include "grid.h"
00110 #include "chapter.h"
00111 //#include "cxfrec.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 #include "cxftags.h"
00113 //#include "camfiltr.h" // BaseCamelotFilter - in camtypes.h [AUTOMATICALLY REMOVED]
00114 #include "unitcomp.h"   // UnitListComponent
00115 #include "guides.h"     // NodeGuideline
00116 
00117 #include "ngsentry.h"   // NodeSetSentinel & NodeSetProperty
00118 //#include "cxfrech.h"  // TemplateAttribute - in camtypes.h [AUTOMATICALLY REMOVED]
00119 //#include "attrval.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00120 #include "userattr.h"
00121 #include "tmpltatr.h"
00122 #include "nodetxts.h"   // For CC_RUNTIME_CLASS(BaseTextClass)
00123 //#include "fillattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00124 
00125 //#include "will2.h"
00126 //#include "simon.h"        // _R(IDS_LAYER_DESCRS)
00127 //#include "mario.h"        // for _R(IDE_NOMORE_MEMORY)
00128 
00129 // global that is set when a bar property tag is imported to say how many bars there were beforehand
00130 // used by SliceHelper::MeshImportedLayersWithExistingButtonBars()
00131 INT32 g_NoOfBarsBeforeImport;
00132 
00133 DECLARE_SOURCE("$Revision: 1688 $");
00134 
00135 CC_IMPLEMENT_DYNAMIC(DocumentRecordHandler,CamelotRecordHandler)
00136 
00137 // Give this file in memory dumps
00138 // Declare smart memory handling in Debug builds
00139 #define new CAM_DEBUG_NEW
00140 
00141 
00142 /********************************************************************************************
00143 
00144 >   DocumentRecordHandler::DocumentRecordHandler()
00145 
00146     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00147     Created:    31/7/96
00148     Inputs:     -
00149     Returns:    -
00150     Purpose:    Default constructor
00151     SeeAlso:    -
00152 
00153 ********************************************************************************************/
00154 
00155 DocumentRecordHandler::DocumentRecordHandler()
00156 {
00157     InitVars();
00158 }
00159 
00160 /********************************************************************************************
00161 
00162 >   void DocumentRecordHandler::InitVars()
00163 
00164     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00165     Created:    1/8/96
00166     Inputs:     -
00167     Returns:    -
00168     Purpose:    Inits all the member vars to their default settings
00169     SeeAlso:    -
00170 
00171 ********************************************************************************************/
00172 
00173 void DocumentRecordHandler::InitVars()
00174 {
00175 }
00176 
00177 /********************************************************************************************
00178 
00179 >   BOOL DocumentRecordHandler::BeginImport()
00180 
00181     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00182     Created:    31/7/96
00183     Inputs:     -
00184     Returns:    TRUE if ok, FALSE otherwise
00185     Purpose:    Default constructor
00186     SeeAlso:    -
00187 
00188 ********************************************************************************************/
00189 
00190 BOOL DocumentRecordHandler::BeginImport()
00191 {
00192     // Init vars before import
00193     InitVars();
00194 
00195     return TRUE;
00196 }
00197 
00198 
00199 
00200 /********************************************************************************************
00201 >   virtual UINT32* DocumentRecordHandler::GetTagList()
00202 
00203     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00204     Created:    24/6/96
00205     Returns:    Ptr to a list of tag values, terminated by CXFRH_TAG_LIST_END
00206     Purpose:    Provides the record handler system with a list of records handled by this
00207                 handler
00208 ********************************************************************************************/
00209 
00210 UINT32* DocumentRecordHandler::GetTagList()
00211 {
00212     static UINT32 TagList[] = { TAG_SPREAD,
00213                                 TAG_SPREADINFORMATION,
00214                                 TAG_DOCUMENT,
00215                                 TAG_CHAPTER,
00216                                 TAG_LAYER,
00217                                 TAG_LAYERDETAILS,
00218                                 TAG_GUIDELAYERDETAILS,
00219                                 TAG_GUIDELINE,
00220                                 TAG_GRIDRULERSETTINGS,
00221                                 TAG_GRIDRULERORIGIN,
00222                                 TAG_SPREADSCALING_ACTIVE,
00223                                 TAG_SPREADSCALING_INACTIVE,
00224                                 TAG_SPREAD_ANIMPROPS,
00225                                 TAG_LAYER_FRAMEPROPS,
00226                                 TAG_SETSENTINEL,
00227                                 TAG_SETPROPERTY,
00228                                 TAG_BARPROPERTY,
00229                                 TAG_CURRENTATTRIBUTES,
00230                                 TAG_CURRENTATTRIBUTEBOUNDS,
00231                                 TAG_DUPLICATIONOFFSET,
00232                                 CXFRH_TAG_LIST_END
00233                              };
00234     return TagList;
00235 }
00236 
00237 
00238 
00239 /********************************************************************************************
00240 
00241 >   virtual BOOL DocumentRecordHandler::HandleRecord(CXaraFileRecord* pCXaraFileRecord)
00242 
00243     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00244     Created:    24/6/96
00245     Inputs:     pCXaraFileRecord = ptr to record to handle
00246     Returns:    TRUE if handled successfuly
00247                 FALSE otherwise
00248     Purpose:    Handles the given record.
00249     SeeAlso:    -
00250 
00251 ********************************************************************************************/
00252 
00253 BOOL DocumentRecordHandler::HandleRecord(CXaraFileRecord* pCXaraFileRecord)
00254 {
00255     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00256 
00257     BOOL ok = TRUE;
00258 
00259     INT32 Tag = pCXaraFileRecord->GetTag();
00260     switch (Tag)
00261     {
00262         case TAG_DOCUMENT:
00263             ok = HandleDocumentRecord(pCXaraFileRecord);
00264             break;
00265 
00266         case TAG_CHAPTER:
00267             ok = HandleChapterRecord(pCXaraFileRecord);
00268             break;
00269 
00270         case TAG_SPREAD:
00271             ok = HandleSpreadRecord(pCXaraFileRecord);
00272             break;
00273 
00274         case TAG_SPREADINFORMATION:
00275             ok = HandleSpreadInformationRecord(pCXaraFileRecord);
00276             break;
00277         
00278         case TAG_GRIDRULERSETTINGS:
00279             ok = HandleGridAndRulerSettingsRecord(pCXaraFileRecord);
00280             break;
00281         case TAG_GRIDRULERORIGIN:
00282             ok = HandleGridAndRulerOriginRecord(pCXaraFileRecord);
00283             break;
00284 
00285         case TAG_SPREADSCALING_ACTIVE:
00286         case TAG_SPREADSCALING_INACTIVE:
00287             ok = HandleSpreadScalingRecord(pCXaraFileRecord, Tag);
00288             break;
00289 
00290         case TAG_LAYER:
00291             ok = HandleLayerRecord(pCXaraFileRecord);
00292             break;
00293 
00294         case TAG_LAYERDETAILS:
00295         case TAG_GUIDELAYERDETAILS:
00296                 ok = HandleLayerDetailsRecord(pCXaraFileRecord);
00297             break;
00298 
00299         case TAG_GUIDELINE:
00300             ok = HandleGuidelineRecord(pCXaraFileRecord);
00301             break;
00302 
00303         case TAG_SPREAD_ANIMPROPS:
00304             ok = HandleSpreadAnimPropertiesRecord(pCXaraFileRecord);
00305             break;
00306             
00307         case TAG_LAYER_FRAMEPROPS:
00308             ok = HandleFramePropertiesRecord(pCXaraFileRecord);
00309             break;
00310 
00311         case TAG_SETSENTINEL:
00312             ok = HandleSetSentinelRecord(pCXaraFileRecord);
00313             break;
00314 
00315         case TAG_SETPROPERTY:
00316             ok = HandleSetPropertyRecord(pCXaraFileRecord);
00317             break;
00318 
00319         case TAG_BARPROPERTY:
00320             ok = HandleBarPropertyRecord(pCXaraFileRecord);
00321             break;
00322 
00323         case TAG_CURRENTATTRIBUTES:
00324             ok = HandleCurrentAttrsRecord(pCXaraFileRecord);
00325             break;
00326 
00327         case TAG_CURRENTATTRIBUTEBOUNDS:
00328             ok = HandleCurrentAttrsRecord(pCXaraFileRecord);
00329             break;
00330 
00331         case TAG_DUPLICATIONOFFSET:
00332             ok = HandleDuplicationOffsetRecord(pCXaraFileRecord);
00333             break;
00334 
00335         default:
00336             ok = FALSE;
00337             ERROR3_PF(("I don't handle records with the tag (%d)\n",pCXaraFileRecord->GetTag()));
00338             break;
00339     }
00340 
00341     return ok;
00342 }
00343 
00344 
00345 /********************************************************************************************
00346 
00347 >   BOOL DocumentRecordHandler::HandleDocumentRecord(CXaraFileRecord* pCXaraFileRecord)
00348 
00349     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00350     Created:    31/7/96
00351     Inputs:     pCXaraFileRecord = ptr to record to handle
00352     Returns:    TRUE if handled successfuly
00353                 FALSE otherwise
00354     Purpose:    Handles the given record.
00355                 The record has to be a document record
00356     SeeAlso:    -
00357 
00358 ********************************************************************************************/
00359 
00360 BOOL DocumentRecordHandler::HandleDocumentRecord(CXaraFileRecord* pCXaraFileRecord)
00361 {
00362     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00363     ERROR2IF(pCXaraFileRecord->GetTag() != TAG_DOCUMENT,FALSE,"I don't handle this tag type");
00364 
00365     IncDocumentInsertedCount();
00366 
00367     // If this is not the first doc in the file, ignore the rest of the file
00368     if (GetDocumentInsertedCount() > 1)
00369         EndOfFile();
00370 
00371     return TRUE;
00372 }
00373 
00374 /********************************************************************************************
00375 
00376 >   BOOL DocumentRecordHandler::HandleChapterRecord(CXaraFileRecord* pCXaraFileRecord)
00377 
00378     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00379     Created:    1/8/96
00380     Inputs:     pCXaraFileRecord = ptr to record to handle
00381     Returns:    TRUE if handled successfuly
00382                 FALSE otherwise
00383     Purpose:    Handles the given record.
00384                 The record has to be a chapter record
00385     SeeAlso:    -
00386 
00387 ********************************************************************************************/
00388 
00389 BOOL DocumentRecordHandler::HandleChapterRecord(CXaraFileRecord* pCXaraFileRecord)
00390 {
00391     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00392     ERROR2IF(pCXaraFileRecord->GetTag() != TAG_CHAPTER,FALSE,"I don't handle this tag type");
00393 
00394     IncChapterInsertedCount();
00395 
00396     // If this is not the first chapter in the file, ignore the rest of the file
00397     if (GetChapterInsertedCount() > 1)
00398     {
00399         EndOfFile();
00400         return TRUE;
00401     }
00402 
00403     // Ignore this record if we are importing into an existing file
00404     if (IsImporting()) return TRUE;
00405 
00406     Node* pContextNode = GetInsertContextNode();
00407     ERROR2IF(pContextNode == NULL,FALSE, "What? No context node?");
00408     Node* pChapter = pContextNode->FindParent(CC_RUNTIME_CLASS(Chapter));
00409     ERROR2IF(pChapter == NULL,FALSE, "Couldn't find the chapter node");
00410 
00411     return TRUE;
00412 /*
00413     Node* pContextNode = GetInsertContextNode();
00414     ERROR2IF(pContextNode == NULL,FALSE,"What? No context node?");
00415 
00416     Node* pChapter = pContextNode->FindParent(CC_RUNTIME_CLASS(Chapter));
00417     if (pChapter!= NULL)
00418     {
00419         SetInsertContextNode(pChapter);
00420         InsertNextNodeAsSibling();
00421     }
00422 
00423     BOOL ok = FALSE;
00424 
00425     {
00426         Chapter* pNewChapter = new Chapter;
00427         if (pNewChapter != NULL)
00428             ok = InsertNode(pNewChapter);
00429 
00430         SetLastChapterInserted(pNewChapter);
00431         InsertNextNodeAsChild();
00432     }
00433 
00434     if (ok && pChapter != NULL)
00435     {
00436         pChapter->CascadeDelete();
00437         delete pChapter;
00438         pChapter = NULL;
00439     }
00440     return ok;
00441   */
00442 }
00443 
00444 /********************************************************************************************
00445 
00446 >   BOOL DocumentRecordHandler::HandleSpreadRecord(CXaraFileRecord* pCXaraFileRecord)
00447 
00448     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00449     Created:    24/6/96
00450     Inputs:     pCXaraFileRecord = ptr to record to handle
00451     Returns:    TRUE if handled successfuly
00452                 FALSE otherwise
00453     Purpose:    Handles the given record.
00454                 The record has to be a spread record
00455     SeeAlso:    -
00456 
00457 ********************************************************************************************/
00458 
00459 BOOL DocumentRecordHandler::HandleSpreadRecord(CXaraFileRecord* pCXaraFileRecord)
00460 {
00461     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00462     ERROR2IF(pCXaraFileRecord->GetTag() != TAG_SPREAD,FALSE,"I don't handle this tag type");
00463 
00464     IncSpreadInsertedCount();
00465 
00466     // If this is not the first spread in the file, ignore the rest of the file
00467     if (GetSpreadInsertedCount() <= 1)
00468     {
00469         // Mainstream code used between 1994 and 2006
00470         //
00471         // Ignore this record if we are importing into an existing file
00472         if (IsImporting())
00473             return TRUE;
00474 
00475         Node* pContextNode = GetInsertContextNode();
00476         ERROR2IF(pContextNode == NULL, FALSE, "What? No context node?");
00477 
00478         // JCF: bodge insertion context.
00479         if (IS_A(pContextNode, NodeSetSentinel))
00480         {
00481             SetInsertContextNode(0);
00482             pContextNode = GetInsertContextNode();
00483         }
00484 
00485         Spread* pSpread = (Spread*) pContextNode->FindParent(CC_RUNTIME_CLASS(Spread));
00486         ERROR2IF(pSpread == NULL, FALSE, "Can't find the spread");
00487 
00488         SetLastSpreadInserted(pSpread);
00489         SetInsertContextNode(pSpread);
00490         InsertNextNodeAsChild();
00491 
00492         Layer* pLayer = pSpread->FindFirstLayer();
00493         if (pLayer != NULL)
00494         {
00495             SetInsertContextNode(pLayer);
00496             InsertNextNodeAsChild();
00497         }
00498 
00499         return TRUE;
00500     }
00501     else
00502     {
00503         // Multi-spread code written before 1994, resurrected in 2006 by Phil
00504         //
00505         // For some reason the above code assumes that a spread already
00506         // exists and simply "overloads" it.
00507         // Some of the logic below creates grid and page nodes in a similar
00508         // vein. Not sure why...
00509         //
00510         Node* pContextNode = GetInsertContextNode();
00511         ERROR2IF(pContextNode == NULL,FALSE,"What? No context node?");
00512 
00513         // JCF: bodge insertion context.
00514         if (IS_A(pContextNode, NodeSetSentinel))
00515         {
00516             SetInsertContextNode(0);
00517             pContextNode = GetInsertContextNode();
00518         }
00519 
00520         Node* pSpread = pContextNode->FindParent(CC_RUNTIME_CLASS(Spread));
00521         if (pSpread != NULL)
00522         {
00523             SetInsertContextNode(pSpread);
00524             InsertNextNodeAsSibling();
00525         }
00526 
00527         BOOL ok = FALSE;
00528 
00529         {
00530             Spread* pNewSpread = new Spread;
00531             if (pNewSpread != NULL)
00532                 ok = InsertNode(pNewSpread);
00533 
00534             if (ok)
00535             {
00536                 SetLastSpreadInserted(pNewSpread);
00537                 InsertNextNodeAsChild();
00538 
00539                 NodeGrid::MakeDefaultGrid(pNewSpread);
00540 
00541                 Page* pPage = new Page;
00542                 ok = (pPage != NULL);
00543 
00544                 if (ok)
00545                     pPage->AttachNode(pNewSpread,LASTCHILD);
00546 
00547                 SetInsertContextNode(pNewSpread);
00548                 InsertNextNodeAsChild();
00549             }
00550         }
00551 
00552         if (!ok && pSpread != NULL)
00553         {
00554             pSpread->CascadeDelete();
00555             delete pSpread;
00556             pSpread = NULL;
00557         }
00558         return ok;
00559     }
00560 }
00561 
00562 
00563 /********************************************************************************************
00564 
00565 >   BOOL DocumentRecordHandler::HandleSpreadInformationRecord(CXaraFileRecord* pCXaraFileRecord)
00566 
00567     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00568     Created:    8/7/96
00569     Inputs:     pCXaraFileRecord = ptr to record to handle
00570     Returns:    TRUE if handled successfuly
00571                 FALSE otherwise
00572     Purpose:    Handles the spread information record. Decodes the information and then
00573                 applies it.
00574     SeeAlso:    -
00575 
00576 ********************************************************************************************/
00577 
00578 BOOL DocumentRecordHandler::HandleSpreadInformationRecord(CXaraFileRecord* pCXaraFileRecord)
00579 {
00580     // Ignore this record if we are importing into ac existing file
00581     if (IsImporting())
00582         return TRUE;
00583 
00584     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00585 
00586     Spread* pLastSpread = GetLastSpreadInserted();
00587 
00588     // If there isn't a spread to apply the info to, just ignore it
00589     if (pLastSpread == NULL)
00590     {
00591         ERROR3("I don't have a 'last spread' ptr");
00592         return TRUE;
00593     }
00594 
00595     BOOL ok = TRUE;
00596 
00597     // Width, Height of page
00598     MILLIPOINT Width = 0;
00599     MILLIPOINT Height = 0;
00600     if (ok) ok = pCXaraFileRecord->ReadINT32(&Width);
00601     if (ok) ok = pCXaraFileRecord->ReadINT32(&Height);
00602     
00603     // <Margin : MILLIPOINT>    The margin to add around all four sides of the pages in the spread to make up the pasteboard. 
00604     // <Bleed : MILLIPOINT> Bleed margin to add around all pages in this spread. (0 means none)
00605     MILLIPOINT Margin = 0;
00606     MILLIPOINT Bleed = 0;
00607     if (ok) ok = pCXaraFileRecord->ReadINT32(&Margin);
00608     if (ok) ok = pCXaraFileRecord->ReadINT32(&Bleed);
00609 
00610     // <SpreadFlags : BYTE> Flags for the current spread.
00611     // SpreadFlags ::= DoublePageSpread | ShowDropShadow 
00612     // ShowDropShadow flag to say whether we apply a page shadow behind the page
00613     // DoublePageSpread flag to say whether one or two pages are present 
00614     BOOL Dps = TRUE;
00615     BOOL ShowDropShadow = TRUE;
00616     BYTE FlagsWord = 0; 
00617     if (ok) ok = pCXaraFileRecord->ReadBYTE(&FlagsWord);
00618     if (FlagsWord & 1)
00619         Dps = TRUE;
00620     else
00621         Dps = FALSE; 
00622     if (FlagsWord & 2)
00623         ShowDropShadow = TRUE;
00624     else
00625         ShowDropShadow = FALSE; 
00626 
00627     // If everything has been read in ok then go and apply those settings to the current
00628     // spread
00629 //  Document* pDoc = GetDocument();
00630     if (ok && pLastSpread && Width > 0 && Height > 0)
00631     {
00632         // This function also sets the fold linea automatically
00633         /*BOOL Worked =*/ pLastSpread->SetPageSize(Width, Height, Margin, Bleed, Dps, ShowDropShadow);
00634 
00635         if (!IsImporting())
00636         {
00637             // Only change the the import coord origin if are not importing into another document
00638             // When importing into an existing document, the import origin would have already been set
00639             // (e.g. to the drag & drop point)
00640 
00641             // We have altered the coordinates origin by this so we must update it
00642             DocRect PagesRect;
00643             if (pLastSpread->GetPagesRect(&PagesRect))
00644                 SetCoordOrigin(PagesRect.lo);
00645         }
00646     }   
00647 
00648     return ok;
00649 }
00650 
00651 /********************************************************************************************
00652 
00653 >   Layer* DocumentRecordHandler::FindThisLayer(UINT32 n)
00654 
00655     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00656     Created:    6/8/96
00657     Inputs:     n = number of the layer to find (the first layer is layer 1)
00658     Returns:    ptr to layer, or NULL if it couldn't find the nth layer
00659     Purpose:    This hunts for the nth layer in the sibling list of the context node.
00660 
00661                 It is used when loading in a file (as opposed to importing).
00662                 If a layer is read in, and there already exists a layer in the tree that corresponds to
00663                 this layer, this func with find it so it can be used, instead of creating a new one
00664     SeeAlso:    -
00665 
00666 ********************************************************************************************/
00667 
00668 Layer* DocumentRecordHandler::FindThisLayer(UINT32 n)
00669 {
00670     if (n < 1) n = 1;
00671 
00672     Node* pNode = GetInsertContextNode();
00673     if (pNode != NULL)
00674         pNode = pNode->FindParent();
00675     if (pNode != NULL)
00676         pNode = pNode->FindFirstChild();
00677 
00678     while (pNode != NULL)
00679     {
00680         if (pNode->IsLayer())
00681         {
00682             n--;
00683             if (n == 0)
00684                 return (Layer*)pNode;
00685         }
00686 
00687         pNode = pNode->FindNext();
00688     }
00689 
00690     return NULL;
00691 }
00692 
00693 
00694 /********************************************************************************************
00695 
00696 >   BOOL DocumentRecordHandler::HandleLayerRecord(CXaraFileRecord* pCXaraFileRecord)
00697 
00698     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00699     Created:    31/7/96
00700     Inputs:     pCXaraFileRecord = ptr to record to handle
00701     Returns:    TRUE if handled successfuly
00702                 FALSE otherwise
00703     Purpose:    Handles the given record.
00704                 The record has to be a layer record
00705     SeeAlso:    -
00706 
00707 ********************************************************************************************/
00708 
00709 BOOL DocumentRecordHandler::HandleLayerRecord(CXaraFileRecord* pCXaraFileRecord)
00710 {
00711     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00712     ERROR2IF(pCXaraFileRecord->GetTag() != TAG_LAYER,FALSE,"I don't handle this tag type");
00713 
00714     IncLayerInsertedCount();
00715 
00716     BOOL ok = TRUE;
00717 
00718     Layer* pLayer = NULL;
00719     
00720     if (!IsImporting())
00721         pLayer = FindThisLayer(GetLayerInsertedCount());
00722 
00723     if (pLayer == NULL)
00724     {
00725         pLayer = new Layer;
00726 
00727         ok = FALSE;
00728         if (pLayer != NULL)
00729         {
00730             ok = InsertNode(pLayer);
00731 
00732             if (ok)
00733             {
00734                 // Set the layer name to a default
00735                 String_256 LayerName( _("Imported ") );
00736                 String_256 Suffix( _("layer") );
00737                 LayerName += Suffix;
00738                 pLayer->SetLayerID(LayerName);
00739                 pLayer->EnsureUniqueLayerID();
00740             }
00741         }
00742     }
00743 
00744     SetLastLayerInserted(pLayer);
00745     
00746     // If we haven't set it already, then set this as the first imported layer
00747     Layer * pFirstImportedLayer = GetFirstImportedLayer();
00748     if (pFirstImportedLayer == NULL)
00749         SetFirstImportedLayer(pLayer);
00750 
00751     return ok;
00752 }
00753 
00754 /********************************************************************************************
00755 
00756 >   BOOL DocumentRecordHandler::HandleLayerDetailsRecord(CXaraFileRecord* pCXaraFileRecord)
00757 
00758     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00759     Created:    31/7/96
00760     Inputs:     pCXaraFileRecord = ptr to record to handle
00761     Returns:    TRUE if handled successfuly
00762                 FALSE otherwise
00763     Purpose:    Handles the given record.
00764                 The record has to be a layer and guide layer details record
00765     SeeAlso:    -
00766 
00767 ********************************************************************************************/
00768 
00769 BOOL DocumentRecordHandler::HandleLayerDetailsRecord(CXaraFileRecord* pCXaraFileRecord)
00770 {
00771     UINT32 Tag = pCXaraFileRecord->GetTag();
00772 
00773     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00774     ERROR2IF(Tag != TAG_LAYERDETAILS && Tag != TAG_GUIDELAYERDETAILS,FALSE,"I don't handle this tag type");
00775 
00776     Layer* pLastLayer = GetLastLayerInserted();
00777 
00778     // If there isn't a layer to apply the info to, just ignore it
00779     if (pLastLayer == NULL)
00780     {
00781         ERROR3("I don't have a 'last layer' ptr");
00782         return TRUE;
00783     }
00784 
00785     BYTE Flags = 0;
00786     String_256 Name;
00787     INT32 ColRef = 0;
00788     DocColour Col;
00789 
00790     BOOL ok = TRUE;
00791 
00792     if (ok) ok = pCXaraFileRecord->ReadBYTE(&Flags);
00793     if (ok) ok = pCXaraFileRecord->ReadUnicode(&Name);//Name, Name.MaxLength());
00794 
00795     if (ok && Tag == TAG_GUIDELAYERDETAILS)
00796         ok = pCXaraFileRecord->ReadINT32(&ColRef);
00797 
00798 #ifdef WEBSTER
00799     if (ok)
00800     {
00801         // WEBSTER - markn 14/1/97
00802         // If it's a guide layer, make it invisible
00803         // otherwise if the layer is visible, make sure it's editable
00804 
00805         if (Tag == TAG_GUIDELAYERDETAILS)
00806             Flags &= ~TAG_LAYER_FLAG_VISIBLE;   // clear visible flag
00807         else
00808         {
00809             if (Flags & TAG_LAYER_FLAG_VISIBLE)
00810                 Flags &= ~TAG_LAYER_FLAG_LOCKED;    // visible, so clear locked flag
00811 
00812             // Markn 18/7/97
00813             // Fixed a bug whereby Webster would load in locked page background layers and
00814             // unlock them because of the two lines above.
00815             if (Flags & TAG_LAYER_FLAG_PAGEBACKGROUND)
00816                 Flags |= TAG_LAYER_FLAG_LOCKED;     // page background, so make sure it's locked
00817         }
00818     }
00819 #endif  // WEBSTER
00820 
00821     pLastLayer->SetVisible(  (Flags & TAG_LAYER_FLAG_VISIBLE)   != 0);
00822     pLastLayer->SetLocked(   (Flags & TAG_LAYER_FLAG_LOCKED)    != 0);
00823     pLastLayer->SetPrintable((Flags & TAG_LAYER_FLAG_PRINTABLE) != 0);
00824     pLastLayer->SetActive(   (Flags & TAG_LAYER_FLAG_ACTIVE)    != 0);
00825     // new 4/4/97
00826     pLastLayer->SetPageBackground((Flags & TAG_LAYER_FLAG_PAGEBACKGROUND) != 0);
00827 
00828     pLastLayer->SetBackground((Flags & TAG_LAYER_FLAG_BACKGROUND) != 0);
00829 
00830     // handle Guide Layers a little differently:
00831     if(Tag == TAG_GUIDELAYERDETAILS)
00832     {
00833         pLastLayer->SetGuide(TRUE);
00834     }
00835     else
00836     {
00837         pLastLayer->SetGuide(FALSE);
00838     }
00839 
00840     pLastLayer->SetLayerID(Name);
00841 
00842 #if !defined(EXCLUDE_FROM_RALPH)
00843     if (ok && ColRef != 0)
00844     {
00845         ok = GetDocColour(ColRef,&Col);
00846         if (ok)
00847         {
00848             IndexedColour* pIndexedColour = Col.FindParentIndexedColour();
00849             pLastLayer->SetGuideColour(pIndexedColour);
00850             pLastLayer->SetGuide(TRUE);
00851         }
00852     }
00853 #endif
00854 
00855     if (ok)
00856     {
00857         // Do some extra work on the layer, such as ensuring the layer name is unique
00858         // Ensure that if we are importing that the layers are placed in as foreground visible
00859         // and editable layers as otherwise confusion may reign.
00860         
00861         // NOTE: If not importing then Webster must not play with the PageBackground layer and
00862         // its visible and editable status
00863         
00864         if (IsImporting())
00865         {
00866             // Firstly, make sure all imported layers are printable visible editable foreground layers
00867             // but only if they are not guide layers
00868             if (!pLastLayer->IsGuide())
00869             {
00870                 // Disable the blatent lets make all layers visible code. This would mean
00871                 // that hidden layers actually appear. In cases like pills.xar, this is bad!
00872                 //pLastLayer->SetVisible(TRUE);
00873                 pLastLayer->SetLocked(FALSE);
00874                 pLastLayer->SetPrintable(TRUE);
00875             }
00876 
00877             // Ensure that all imported layers are NOT background as otherwise we will have a mixture
00878             //pLastLayer->SetBackground(FALSE);
00879 
00880             // no imported layer is going to be the active layer!
00881             pLastLayer->SetActive(FALSE);
00882 
00883             // If we have improted a page background layer then we need to do some extra work
00884             if (pLastLayer->IsPageBackground())
00885             {
00886                 // If we dont unset this then things may get confusing!
00887                 // Unlocked visible page background layers = trouble
00888                 pLastLayer->SetPageBackground(FALSE);
00889                 // If we set it as a frame layer then it wont get merged with the active layer
00890                 pLastLayer->SetFrame(TRUE);
00891                 // Mark it as hidden and solid so that it is almost as it was as a page background layer
00892                 pLastLayer->SetHiddenFrame(TRUE);
00893                 pLastLayer->SetSolid(TRUE);
00894             }
00895 
00896             // If importing do something a little more intelligent with the name matching
00897             // SJK - as a test try to keep the names the same then merge similar names at 
00898             // the last minute when importing
00899             INT32 ImportWithLayers = 1;
00900             Camelot.GetPrefValue(TEXT("Filters"), TEXT("ImportWithLayers"), &ImportWithLayers);
00901 
00902             if (ImportWithLayers == 0) // ask for unique layer names, all on new layers
00903                 pLastLayer->EnsureUniqueLayerID();
00904             else if (ImportWithLayers == 1) // stick it on the active layer
00905             {
00906                 Spread* pSpread = GetSpread();
00907 
00908                 if (pSpread)
00909                 {
00910                     // name it the same as the active layer
00911                     // and the layers will be meshed together later
00912                     Layer * pActiveLayer = pSpread->FindActiveLayer();
00913                     pLastLayer->SetLayerID(pActiveLayer->GetLayerID());
00914                 }               
00915             }
00916 
00917             String_256 CurName = pLastLayer->GetLayerID();
00918 
00919             // Has the name changed as a result of the above call?
00920             if (ImportWithLayers == 0 && CurName != Name)
00921             {
00922                 // Get a suitable prefix string (in this case "Imported ")
00923                 String_256 Prefix( _("Imported ") );
00924 
00925                 // Does the name already have the prefix string embedded in it?
00926 //              if (cc_lstristr(Name,Prefix) == NULL)
00927                 if (Name.Sub(Prefix) == 0)
00928                 {
00929                     // If not, append the prefix to the original name, and try again
00930                     Prefix += Name;
00931                     pLastLayer->SetLayerID(Prefix);
00932                     pLastLayer->EnsureUniqueLayerID();
00933                 }
00934             }
00935         }
00936         else
00937             pLastLayer->EnsureUniqueLayerID();
00938     }
00939 
00940     return ok;
00941 }
00942 
00943 /********************************************************************************************
00944 
00945 >   BOOL DocumentRecordHandler::HandleGuidelineRecord(CXaraFileRecord* pCXaraFileRecord)
00946 
00947     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00948     Created:    8/8/96
00949     Inputs:     pCXaraFileRecord = ptr to record to handle
00950     Returns:    TRUE if handled successfuly
00951                 FALSE otherwise
00952     Purpose:    Handles the given record.
00953                 The record has to be a guideline record
00954     SeeAlso:    -
00955 
00956 ********************************************************************************************/
00957 
00958 BOOL DocumentRecordHandler::HandleGuidelineRecord(CXaraFileRecord* pCXaraFileRecord)
00959 {
00960 #if !defined(EXCLUDE_FROM_RALPH)
00961     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
00962     ERROR3IF(pCXaraFileRecord->GetTag() != TAG_GUIDELINE,"I don't handle this tag type");
00963 
00964     BYTE Type;
00965     MILLIPOINT Ordinate;
00966 
00967     BOOL ok = pCXaraFileRecord->ReadBYTE(&Type);
00968 
00969     if (ok && Type == GUIDELINE_HORZ)
00970         ok = pCXaraFileRecord->ReadYOrd(&Ordinate);
00971     else
00972         ok = pCXaraFileRecord->ReadXOrd(&Ordinate);
00973 
00974     if (ok)
00975     {
00976         NodeGuideline* pGuide = new NodeGuideline;
00977 
00978         if (pGuide != NULL)
00979         {
00980             pGuide->SetType(GuidelineType(Type));
00981             pGuide->SetOrdinate(Ordinate);
00982             ok = InsertNode(pGuide);
00983         }
00984     }
00985 
00986     return ok;
00987 #else
00988     return TRUE;
00989 #endif
00990 }
00991 
00992 /********************************************************************************************
00993 
00994 >   BOOL DocumentRecordHandler::HandleGridAndRulerSettingsRecord(CXaraFileRecord* pCXaraFileRecord)
00995 
00996     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00997     Created:    8/7/96
00998     Inputs:     pCXaraFileRecord = ptr to record to handle
00999     Returns:    TRUE if handled successfuly
01000                 FALSE otherwise
01001     Purpose:    Handles grid and ruler settings record. Decodes the information and then
01002                 applies it.
01003     SeeAlso:    Document::ImportGridInfo;
01004 
01005 ********************************************************************************************/
01006 
01007 BOOL DocumentRecordHandler::HandleGridAndRulerSettingsRecord(CXaraFileRecord* pCXaraFileRecord)
01008 {
01009 #if !defined(EXCLUDE_FROM_RALPH)
01010     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
01011 
01012     // If we are just importing data from this document into an existing one,
01013     // then don't import this data.
01014     if (IsImporting())
01015         return TRUE;
01016     
01017     BOOL ok = TRUE;
01018 
01019     double   Divisions    = 0.0;
01020     UnitType Type         = NOTYPE;
01021     UINT32    SubDivisions = 0;
01022     GridType TypeOfGrid   = RECTANGULAR;
01023     INT32    UnitsRef     = 0L;
01024     BYTE     TypeOfGridB  = (BYTE)RECTANGULAR;
01025 
01026     if (ok) ok = pCXaraFileRecord->ReadINT32(&UnitsRef);
01027     if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&Divisions);
01028     if (ok) ok = pCXaraFileRecord->ReadUINT32(&SubDivisions);
01029     if (ok) ok = pCXaraFileRecord->ReadBYTE(&TypeOfGridB);
01030     TypeOfGrid = (GridType)TypeOfGridB;
01031 
01032     // Convert the reference into unittype
01033     UnitListComponent * pUnitsComponent = GetUnitDocComponent();
01034     ERROR2IF(pUnitsComponent == NULL,FALSE,"HandleGridAndRulerSettingsRecord No units doc component present");
01035 
01036     Unit* pUnit = pUnitsComponent->GetReadUnitReference(UnitsRef);
01037     if (pUnit)
01038         Type = pUnit->GetUnitType();
01039     else
01040         return FALSE;
01041 
01042     Spread* pSpread = GetSpread();
01043     ERROR2IF(pSpread == NULL,FALSE,"HandleGridAndRulerSettingsRecord No spread");
01044 
01045     NodeGrid* pDefaultGrid = pSpread->FindFirstDefaultGridInSpread();
01046     ERROR2IF(pDefaultGrid == NULL,FALSE,"HandleGridAndRulerSettingsRecord No default grid");
01047     
01048     // remove it as its bound to be wrong
01049     pDefaultGrid->CascadeDelete();
01050     delete pDefaultGrid;                
01051 
01052     // Set all the global variables - What a load of B********
01053     NodeGrid::SetDefaultDivisions(Divisions);
01054     NodeGrid::SetDefaultSubdivisions(SubDivisions);
01055     NodeGrid::SetDefaultUnits(Type);
01056     NodeGrid::SetDefaultGridType(TypeOfGrid);
01057 
01058     // Make a grid
01059     // BODGE - old builds (hence docs) save the grid spacing in divisions and units but don't
01060     // account for unit scaling, so as not to change doc format new docs do the same so we must
01061     // set the grid with scaling turned off - yuk!
01062     // But surely it is best saved unscaled!
01063     BOOL Scale=FALSE;
01064     NodeGrid::MakeDefaultGrid(pSpread, Scale);
01065 
01066     /* DocRect PageRect;
01067     pDefaultGrid = pSpread->FindFirstDefaultGridInSpread();
01068     if (pSpread->GetPagesRect(&PageRect) && pDefaultGrid)
01069     {
01070         pDefaultGrid->SetOrigin(PageRect.lo.x, PageRect.lo.y);
01071     } */
01072 
01073     return ok;
01074 #else
01075     return TRUE;
01076 #endif
01077 }
01078 
01079 /********************************************************************************************
01080 
01081 >   BOOL DocumentRecordHandler::HandleGridAndRulerOriginRecord(CXaraFileRecord* pCXaraFileRecord)
01082 
01083     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01084     Created:    8/7/96
01085     Inputs:     pCXaraFileRecord = ptr to record to handle
01086     Returns:    TRUE if handled successfuly
01087                 FALSE otherwise
01088     Purpose:    Handles the grid and ruler origin record. Decodes the information and then
01089                 applies it.
01090     SeeAlso:    Document::ImportOriginInfo;
01091 
01092 ********************************************************************************************/
01093 
01094 BOOL DocumentRecordHandler::HandleGridAndRulerOriginRecord(CXaraFileRecord* pCXaraFileRecord)
01095 {
01096 #if !defined(EXCLUDE_FROM_RALPH)
01097     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
01098 
01099     // If we are just importing data from this document into an existing one,
01100     // then don't import this data.
01101     if (IsImporting())
01102         return TRUE;
01103     
01104     BOOL ok = TRUE;
01105 
01106     DocCoord Origin(0,0);
01107     if (ok) ok = pCXaraFileRecord->ReadCoord(&Origin);
01108 
01109     Spread* pSpread = GetSpread();
01110     ERROR2IF(pSpread == NULL,FALSE,"HandleGridAndRulerOriginRecord No spread");
01111 
01112     NodeGrid* pDefaultGrid = pSpread->FindFirstDefaultGridInSpread();
01113     ERROR2IF(pDefaultGrid == NULL,FALSE,"HandleGridAndRulerOriginRecord No default grid");
01114 
01115     pDefaultGrid->SetOrigin(Origin.x, Origin.y);    
01116 
01117     return ok;
01118 #else
01119     return TRUE;
01120 #endif
01121 }
01122 
01123 /********************************************************************************************
01124 
01125 >   BOOL DocumentRecordHandler::HandleSpreadScalingRecord(CXaraFileRecord* pCXaraFileRecord,
01126                                                           INT32 Tag)
01127 
01128     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01129     Created:    8/7/96
01130     Inputs:     pCXaraFileRecord = ptr to record to handle
01131                 Tag = tag for this record
01132     Returns:    TRUE if handled successfuly
01133                 FALSE otherwise
01134     Purpose:    Handles the spread scaling records. Decodes the information and then
01135                 applies it.
01136     SeeAlso:    Document::ImportViewInfo;
01137 
01138 ********************************************************************************************/
01139 
01140 BOOL DocumentRecordHandler::HandleSpreadScalingRecord(CXaraFileRecord* pCXaraFileRecord, INT32 Tag)
01141 {
01142 #if !defined(EXCLUDE_FROM_RALPH)
01143     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
01144 
01145     // If we are just importing data from this document into an existing one,
01146     // then don't import this data.
01147     if (IsImporting())
01148         return TRUE;
01149     
01150     BOOL ok = TRUE;
01151 
01152     BOOL Active = FALSE;
01153     if (Tag == TAG_SPREADSCALING_ACTIVE)
01154         Active= TRUE;
01155     
01156     double      DrawingScaleValue   = 1.0;
01157     INT32       DrawingUnits        = 0L;
01158     double      RealScaleValue      = 1.0;
01159     INT32       RealUnits           = 0L;
01160 //  UnitType    DrawingType         = NOTYPE;
01161 //  UnitType    RealType            = NOTYPE;
01162     BOOL        DrawingPrefix       = FALSE;
01163     BOOL        RealPrefix          = FALSE;
01164     String_32   DrawingAbbr;
01165     String_32   RealAbbr;
01166 
01167     if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&DrawingScaleValue);
01168     if (ok) ok = pCXaraFileRecord->ReadINT32(&DrawingUnits);
01169     if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&RealScaleValue);
01170     if (ok) ok = pCXaraFileRecord->ReadINT32(&RealUnits);
01171 
01172     // Any problems then return immediately
01173     if (!ok)
01174         return FALSE;
01175 
01176     // Convert the reference into unittype
01177     UnitListComponent * pUnitsComponent = GetUnitDocComponent();
01178     ERROR2IF(pUnitsComponent == NULL,FALSE,"HandleSpreadScalingRecord No units doc component present");
01179 
01180     Unit* pDrawingUnit = pUnitsComponent->GetReadUnitReference(DrawingUnits);
01181     if (pDrawingUnit)
01182     {
01183         DrawingAbbr = pDrawingUnit->GetSpecifier();
01184         DrawingPrefix = pDrawingUnit->IsPrefix();
01185     }
01186     else
01187         return FALSE;
01188 
01189     Unit* pRealUnit = pUnitsComponent->GetReadUnitReference(RealUnits);
01190     if (pRealUnit)
01191     {
01192         RealAbbr = pRealUnit->GetSpecifier();
01193         RealPrefix = pRealUnit->IsPrefix();
01194     }
01195     else
01196         return FALSE;
01197 
01198     //if (RealType == NOTYPE || DrawingType == NOTYPE)
01199     //  ERROR2(FALSE,"HandleSpreadScalingRecord bad real and/or drawing unit types");
01200 
01201     Spread* pSpread = GetSpread();
01202     ERROR2IF(pSpread == NULL,FALSE,"HandleSpreadScalingRecord No spread");
01203 
01204     DimScale* pDimScale = pSpread->GetPtrDimScale();
01205     ERROR2IF(pDimScale == NULL,FALSE,"HandleSpreadScalingRecord No pDimScale");
01206 
01207     // Set up the scale factor strings with this new info
01208     // Could do with functions to set the scale factor and units directly but if that's the
01209     // way DimScale wants it then thats the way it is going to get it!
01210     String_32 DrawingScale;
01211     String_32 RealScale;
01212     INT32 DecimalPlaces  = 6;
01213     if (DrawingPrefix)
01214     {
01215         DrawingScale += DrawingAbbr;
01216     }
01217     if (ok) ok = Convert::DoubleToString( DrawingScaleValue, &DrawingScale, DecimalPlaces);
01218     if (!DrawingPrefix)
01219     {
01220         DrawingScale += DrawingAbbr;
01221     }
01222 
01223     if (RealPrefix)
01224         RealScale += RealAbbr;
01225     if (ok) ok = Convert::DoubleToString( RealScaleValue, &RealScale, DecimalPlaces);
01226     if (!RealPrefix)
01227         RealScale += RealAbbr;
01228     
01229     if (ok)
01230     {
01231         // Set up a possibly new active state
01232         pDimScale->SetActiveState(Active);
01233         // Now set up all the other aspects
01234         ok = pDimScale->SetDrawingScaleStr(DrawingScale);
01235         if (ok) ok = pDimScale->SetRealScaleStr(RealScale);
01236         if (ok) ok = pDimScale->SetScaleFactor();
01237     }
01238 
01239 #ifdef __WXMAC__
01240 PORTNOTE("MacPort", "Horrendous bodge - One of the above functions returns ok = FALSE. Another ReadDOUBLE problem?")
01241 return TRUE;
01242 #endif
01243 
01244     return ok;
01245 #else
01246     return TRUE;
01247 #endif
01248 }
01249 
01250 
01251 /********************************************************************************************
01252 
01253 >   virtual void DocumentRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord,
01254                                                                  StringBase* pStr)
01255 
01256     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01257     Created:    24/6/96
01258     Inputs:     pRecord = ptr to a record
01259                 pStr = ptr to string to update
01260     Returns:    -
01261     Purpose:    This provides descriptions for the document records.
01262     Errors:     -
01263     SeeAlso:    -
01264 
01265 ********************************************************************************************/
01266 
01267 #ifdef XAR_TREE_DIALOG
01268 void DocumentRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord, StringBase* pStr)
01269 {
01270     if (pStr == NULL || pRecord == NULL)
01271         return;
01272 
01273     // Call base class first
01274     // This outputs the tag and size
01275     CamelotRecordHandler::GetRecordDescriptionText(pRecord,pStr);
01276 
01277     TCHAR s[256];
01278     BOOL ok = TRUE;
01279 
01280     UINT32 Tag = pRecord->GetTag();
01281     switch (Tag)
01282     {
01283         case TAG_DOCUMENT:
01284             break;
01285 
01286         case TAG_SPREAD:
01287             break;
01288 
01289         case TAG_CHAPTER:
01290             break;
01291 
01292         case TAG_SETSENTINEL:
01293             break;
01294 
01295         case TAG_SETPROPERTY:
01296             break;
01297 
01298         case TAG_SPREADINFORMATION:
01299         {
01300             (*pStr) += _T("Spread Information record\r\n\r\n");
01301             
01302             // Width, Height of page
01303             MILLIPOINT Width = 0;
01304             MILLIPOINT Height = 0;
01305             if (ok) ok = pRecord->ReadINT32(&Width);
01306             if (ok) ok = pRecord->ReadINT32(&Height);
01307             camSprintf(s,_T("Page width \t: %d\r\n"),Width);
01308             (*pStr) += s;
01309             camSprintf(s,_T("Page height \t: %d\r\n"),Height);
01310             (*pStr) += s;
01311             
01312             // <Margin : MILLIPOINT>    The margin to add around all four sides of the pages in the spread to make up the pasteboard. 
01313             // <Bleed : MILLIPOINT> Bleed margin to add around all pages in this spread. (0 means none)
01314             MILLIPOINT Margin = 0;
01315             MILLIPOINT Bleed = 0;
01316             if (ok) ok = pRecord->ReadINT32(&Margin);
01317             if (ok) ok = pRecord->ReadINT32(&Bleed);
01318             camSprintf(s,_T("Margin around spread : %d\r\n"),Margin);
01319             (*pStr) += s;
01320             camSprintf(s,_T("Bleed around spread : %d\r\n"),Bleed);
01321             (*pStr) += s;
01322 
01323             // <SpreadFlags : BYTE> Flags for the current spread.
01324             // SpreadFlags ::= DoublePageSpread | ShowDropShadow | ShowFoldLine
01325             // ShowDropShadow flag to say whether we apply a page shadow behind the page
01326             // ShowFoldLine flag to say whether a fold line is required.
01327             // DoublePageSpread flag to say whether one or two pages are present 
01328             BOOL Dps = TRUE;
01329             BOOL ShowDropShadow = TRUE;
01330             BYTE FlagsWord = 0; 
01331             if (ok) ok = pRecord->ReadBYTE(&FlagsWord);
01332             if (FlagsWord & 4)
01333                 Dps = TRUE;
01334             else
01335                 Dps = FALSE; 
01336             if (FlagsWord & 2)
01337                 ShowDropShadow = TRUE;
01338             else
01339             camSprintf(s,_T("Double page spread : %d\r\n"),Dps);
01340             (*pStr) += s;
01341             camSprintf(s,_T("Show drop shadow : %d\r\n"),ShowDropShadow);
01342             (*pStr) += s;
01343 
01344             break;
01345         }
01346         case TAG_PAGE:
01347             break;
01348 
01349         case TAG_LAYERDETAILS:
01350         case TAG_GUIDELAYERDETAILS:
01351         {
01352             BYTE Flags;
01353             String_256 Name;
01354             INT32 ColRef = 0;
01355 
01356             pRecord->ReadBYTE(&Flags);
01357             pRecord->ReadUnicode(&Name);//Name, Name.MaxLength());
01358             if (Tag == TAG_GUIDELAYERDETAILS)
01359             {
01360                 (*pStr) += _T("Guide layer details\r\n\r\n");
01361                 pRecord->ReadINT32(&ColRef);
01362             }
01363             else
01364             {
01365                 (*pStr) += _T("Standard layer details\r\n\r\n");
01366             }
01367 
01368             (*pStr) += _T("Flags\r\n");
01369             camSprintf(s,_T("Visible:\t%d\r\n"),    (Flags & TAG_LAYER_FLAG_VISIBLE)    != 0); (*pStr) += s;
01370             camSprintf(s,_T("Locked:\t%d\r\n"), (Flags & TAG_LAYER_FLAG_LOCKED)     != 0); (*pStr) += s;
01371             camSprintf(s,_T("Printable:\t%d\r\n"),  (Flags & TAG_LAYER_FLAG_PRINTABLE)  != 0); (*pStr) += s;
01372             camSprintf(s,_T("Active:\t%d\r\n"), (Flags & TAG_LAYER_FLAG_ACTIVE)     != 0); (*pStr) += s;
01373             camSprintf(s,_T("PageBackground:\t%d\r\n"),(Flags & TAG_LAYER_FLAG_PAGEBACKGROUND)  != 0); (*pStr) += s;
01374             (*pStr) += _T("\r\n");
01375 
01376             camSprintf(s,_T("Name: %s\r\n\r\n"),(TCHAR*)Name); (*pStr) += s;
01377             camSprintf(s,_T("Colour reference : %d\r\n"),ColRef); (*pStr) += s;
01378         }
01379         break;
01380 
01381         case TAG_GRIDRULERSETTINGS:
01382         {
01383             double   Divisions    = 0.0;
01384 //          UnitType Unit         = NOTYPE;
01385             UINT32    SubDivisions = 0;
01386             GridType TypeOfGrid   = RECTANGULAR;
01387             BYTE     TypeOfGridB  = 0;
01388             INT32    UnitsRef     = 0L;
01389 
01390             if (ok) ok = pRecord->ReadINT32(&UnitsRef);
01391             camSprintf(s,_T("Grid units : %d\r\n"),UnitsRef);
01392             (*pStr) += s;
01393             if (ok) ok = pRecord->ReadDOUBLE(&Divisions);
01394             camSprintf(s,_T("Grid divisions : %f\r\n"),Divisions);
01395             if (ok) ok = pRecord->ReadUINT32(&SubDivisions);
01396             camSprintf(s,_T("Grid sub divisions : %d\r\n"),SubDivisions);
01397             if (ok) ok = pRecord->ReadBYTE(&TypeOfGridB);
01398             TypeOfGrid = (GridType)TypeOfGridB;
01399             if (TypeOfGrid == RECTANGULAR)
01400                 (*pStr) += _T("Rectangular");
01401             else if (TypeOfGrid == ISOMETRIC)
01402                 (*pStr) += _T("Isometric");
01403             else
01404                 (*pStr) += _T("Unknown");
01405             break;
01406         }
01407 
01408         case TAG_GRIDRULERORIGIN:
01409         {
01410             DocCoord Origin(0,0);
01411             if (ok) ok = pRecord->ReadCoord(&Origin);
01412             camSprintf(s,_T("Grid and Ruler origin : %d, %d\r\n"),Origin.x,Origin.y);
01413             (*pStr) += s;
01414             break;
01415         }
01416 
01417         case TAG_SPREADSCALING_ACTIVE:
01418         case TAG_SPREADSCALING_INACTIVE:
01419         {
01420             if (Tag == TAG_SPREADSCALING_ACTIVE)
01421                 (*pStr) += _T("Spread scaling active \r\n\r\n");
01422             else
01423                 (*pStr) += _T("Spread scaling inactive \r\n\r\n");
01424             
01425             double  DrawingScaleValue   = 1.0;
01426             INT32   DrawingUnits        = 0L;
01427             double  RealScaleValue      = 1.0;
01428             INT32   RealUnits           = 0L;
01429             if (ok) ok = pRecord->ReadDOUBLE(&DrawingScaleValue);
01430             if (ok) ok = pRecord->ReadINT32(&DrawingUnits);
01431             if (ok) ok = pRecord->ReadDOUBLE(&RealScaleValue);
01432             if (ok) ok = pRecord->ReadINT32(&RealUnits);
01433             camSprintf(s,_T("Drawing scale factor \t: %f\r\n"),DrawingScaleValue);
01434             (*pStr) += s;
01435             camSprintf(s,_T("Drawing units ref \t: %d\r\n"),DrawingUnits);
01436             (*pStr) += s;
01437             camSprintf(s,_T("Real scale factor \t\t: %f\r\n"),RealScaleValue);
01438             (*pStr) += s;
01439             camSprintf(s,_T("Real units ref \t: %d\r\n"),RealUnits);
01440             (*pStr) += s;
01441             break;
01442         }
01443 
01444         case TAG_GUIDELINE:
01445         {
01446             BYTE Type;
01447             MILLIPOINT Ordinate;
01448 
01449             pRecord->ReadBYTE(&Type);
01450             pRecord->ReadINT32(&Ordinate);
01451 
01452             camSprintf(s,_T("Type\t: %d\r\n"),INT32(Type)); (*pStr) += s;
01453             camSprintf(s,_T("Type\t: %d\r\n"),Ordinate);    (*pStr) += s;
01454         }
01455         break;
01456 
01457         case TAG_SPREAD_ANIMPROPS:
01458         {
01459             DWORD   Loop                =0;             
01460             DWORD   GlobalDelay         =0;     
01461             DWORD   Dither              =0;         
01462             DWORD   WebPalette          =0;     
01463             DWORD   ColoursPalette      =0; 
01464             DWORD   NumColsInPalette    =0; 
01465             DWORD   FlagsWord           =0;
01466 
01467             if (ok)
01468                 ok = pRecord->ReadUINT32(&Loop);    
01469             if (ok)
01470                 ok = pRecord->ReadUINT32(&GlobalDelay);
01471             if (ok)
01472                 ok = pRecord->ReadUINT32(&Dither);
01473             if (ok)
01474                 ok = pRecord->ReadUINT32(&WebPalette);
01475             if (ok)
01476                 ok = pRecord->ReadUINT32(&ColoursPalette);
01477             if (ok)
01478                 ok = pRecord->ReadUINT32(&NumColsInPalette);
01479             if (ok)
01480                 ok = pRecord->ReadUINT32(&FlagsWord);
01481 
01482             // Decode the flags word into its component parts 
01483             BOOL UseSystemColours = FALSE;
01484             // <SpreadAnimationFlags : WORD>    Flags for the current animation properties.
01485             // SpreadAnimationFlags ::= UseSystemColours
01486             // UseSystemColours flag to say whether we add system colours to the exported palettes
01487             UseSystemColours = ((FlagsWord & 1) ? TRUE : FALSE);
01488     
01489             // Display the info..
01490 
01491             camSprintf(s,_T("Animation Loop \t: %d\r\n"),Loop);
01492                 (*pStr) += s;
01493             camSprintf(s,_T("GlobalDelay \t: %d\r\n"),GlobalDelay);
01494                 (*pStr) += s;
01495             camSprintf(s,_T("Animation Dither \t: %d\r\n"),Dither);
01496                 (*pStr) += s;
01497             camSprintf(s,_T("Palette     \t: %d\r\n"),WebPalette);
01498                 (*pStr) += s;
01499             camSprintf(s,_T("Palette Colours \t: %d\r\n"),ColoursPalette);
01500                 (*pStr) += s;
01501             camSprintf(s,_T("Number of Colours In Palette \t: %d\r\n"),NumColsInPalette);
01502                 (*pStr) += s;
01503             camSprintf(s,_T("Add System Colours \t: %d\r\n"),UseSystemColours);
01504                 (*pStr) += s;
01505 
01506         };
01507         break;
01508 
01509         case TAG_LAYER_FRAMEPROPS:
01510         {
01511             DWORD Delay=0;
01512             BYTE Flags = 0;
01513             
01514             if (ok) ok = pRecord->ReadUINT32(&Delay);
01515             if (ok) ok = pRecord->ReadBYTE(&Flags);
01516             camSprintf(s,_T("Frame Layer Delay \t: %d\r\n"),Delay);                     (*pStr) += s;
01517             camSprintf(s,_T("Solid:\t%d\r\n"),  (Flags & TAG_LAYER_FLAG_SOLID)      != 0);  (*pStr) += s;
01518             camSprintf(s,_T("Overlay:\t%d\r\n"),(Flags & TAG_LAYER_FLAG_OVERLAY)    != 0);  (*pStr) += s;
01519             camSprintf(s,_T("Hidden:\t%d\r\n"), (Flags & TAG_LAYER_FLAG_HIDDEN) != 0);  (*pStr) += s;
01520         }
01521         break;
01522 
01523         case TAG_CURRENTATTRIBUTES:
01524         {
01525             BYTE GroupID;
01526             pRecord->ReadBYTE(&GroupID);
01527             switch(GroupID)
01528             {
01529             case ATTRIBUTEGROUP_INK:
01530                 (*pStr) += _T("Attribute Group ID = INK\r\n");
01531                 break;
01532             case ATTRIBUTEGROUP_TEXT:
01533                 (*pStr) += _T("Attribute Group ID = TEXT\r\n");
01534                 break;
01535             default:
01536                 (*pStr) += _T("Attribute Group ID = UNKNOWN!\r\n");
01537                 break;
01538             }
01539         }
01540         break;
01541 
01542         case TAG_CURRENTATTRIBUTEBOUNDS:
01543         {
01544             DocRect attrBounds;
01545             pRecord->ReadCoord(&attrBounds.lo);
01546             pRecord->ReadCoord(&attrBounds.hi);
01547 
01548             camSprintf(s,_T("lo.x \t: %d\r\n"), attrBounds.lo.x);
01549                 (*pStr) += s;
01550             camSprintf(s,_T("lo.y \t: %d\r\n"), attrBounds.lo.y);
01551                 (*pStr) += s;
01552             camSprintf(s,_T("hi.x \t: %d\r\n"), attrBounds.hi.x);
01553                 (*pStr) += s;
01554             camSprintf(s,_T("hi.y \t: %d\r\n"), attrBounds.hi.y);
01555                 (*pStr) += s;
01556 
01557         }
01558         break;
01559 
01560     }
01561 }
01562 #endif // _DEBUG
01563 
01564 /********************************************************************************************
01565 
01566 >   BOOL DocumentRecordHandler::HandleSpreadAnimPropertiesRecord(CXaraFileRecord* pRec);
01567 
01568     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
01569     Created:    08/05/97
01570     Inputs:     pCXaraFileRecord,  ptr to the record to handle.
01571     Returns:    TRUE if handled successfuly
01572                 FALSE otherwise
01573     Purpose:    Handles the spread information record. Decodes the information and then
01574                 applies it.
01575     Notes:      Karim 07/12/2000 - modified to read in transparent GIF information.
01576 
01577 ********************************************************************************************/
01578 BOOL DocumentRecordHandler::HandleSpreadAnimPropertiesRecord(CXaraFileRecord* pRec)
01579 {
01580     // Ignore this record if we are importing into an existing file
01581     if (IsImporting())
01582         return TRUE;
01583 
01584     UINT32 Tag = pRec->GetTag();
01585     ERROR2IF(pRec == NULL,FALSE,"pCXaraFileRecord is NULL");
01586     ERROR2IF(Tag != TAG_SPREAD_ANIMPROPS,FALSE,"I do not handle this tag type!");
01587 
01588     // Get a ptr to the last spread and test for NULL.
01589     Spread* pLastSpread = GetLastSpreadInserted();
01590     if (pLastSpread == NULL)
01591     {
01592         ERROR3("I don't have a 'last spread' ptr");
01593         return TRUE;
01594     }
01595 
01596     BOOL ok = TRUE;
01597 
01598     // Read the Animation information.
01599     UINT32  Loop                =0;             
01600     UINT32  GlobalDelay         =0;     
01601     UINT32  Dither              =0;         
01602     UINT32  WebPalette          =0;     
01603     UINT32  ColoursPalette      =0; 
01604     UINT32  NumColsInPalette    =0; 
01605     UINT32  FlagsWord           =0;
01606 
01607     if (ok)
01608         ok = pRec->ReadUINT32(&Loop);   
01609     if (ok)
01610         ok = pRec->ReadUINT32(&GlobalDelay);
01611     if (ok)
01612         ok = pRec->ReadUINT32(&Dither);
01613     if (ok)
01614         ok = pRec->ReadUINT32(&WebPalette);
01615     if (ok)
01616         ok = pRec->ReadUINT32(&ColoursPalette);
01617     if (ok)
01618         ok = pRec->ReadUINT32(&NumColsInPalette);
01619     if (ok)
01620         ok = pRec->ReadUINT32(&FlagsWord);
01621 
01622     // Decode the flags word into its component parts 
01623     BOOL UseSystemColours   = FALSE;
01624     BOOL BgTransparent      = FALSE;
01625 
01626     // <SpreadAnimationFlags : WORD>    Flags for the current animation properties.
01627     // SpreadAnimationFlags ::= UseSystemColours
01628     // UseSystemColours flag to say whether we add system colours to the exported palettes
01629     UseSystemColours    = ((FlagsWord & 1) ? TRUE : FALSE);
01630 
01631     // BgTransparent flag says whether or not we're creating a transparent GIF or not.
01632     // To be compatible with CX2, BgTransparent is set if (FlagsWord & 2) is zero,
01633     // as CX2 always does background transparent GIFs and didn't have this new bit.
01634     BgTransparent       = ((FlagsWord & 2) ? FALSE : TRUE);
01635 
01636     // Apply these details to the spread.
01637     if (ok && pLastSpread)
01638     {
01639         // Set the details in the layer.
01640         /*BOOL Worked =*/ pLastSpread->SetSpreadAnimPropertiesParam(Loop, GlobalDelay,(DITHER)Dither,(WEB_PALETTE)WebPalette,
01641                                                                 (PALETTE_COLOURS)ColoursPalette, NumColsInPalette,
01642                                                                 UseSystemColours, BgTransparent);
01643     }
01644     return ok;
01645 };
01646 
01647 
01648 /********************************************************************************************
01649 
01650 >   BOOL HandleFramePropertiesRecord(CXaraFileRecord* pRec);
01651 
01652     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
01653     Created:    08/05/97
01654     Inputs:     pCXaraFileRecord = ptr to record to handle
01655     Returns:    TRUE if handled successfuly
01656                 FALSE otherwise
01657     Purpose:    Handles the Frame Layer Delay record. Decodes the information and then
01658                 applies it.
01659     SeeAlso:    -
01660 
01661 ***********************************************************************************************/
01662 
01663 BOOL DocumentRecordHandler::HandleFramePropertiesRecord(CXaraFileRecord* pRec)
01664 {
01665     ERROR2IF(pRec == NULL,FALSE,"pCXaraFileRecord is NULL");
01666     UINT32 Tag = pRec->GetTag();
01667     ERROR2IF(Tag != TAG_LAYER_FRAMEPROPS,FALSE,"I do not handle this tag type");
01668 
01669     // Get a ptr to the last inserted layer and check for NULL.
01670     Layer* pLastLayer = GetLastLayerInserted();
01671     if (pLastLayer == NULL)
01672     {
01673         ERROR3("I don't have a 'last layer' ptr!");
01674         return TRUE;
01675     }
01676 
01677     UINT32 Delay=0;
01678     BYTE Flags = 0;
01679     BOOL ok =TRUE;
01680 
01681     // Read the record and pass the details onto the layer.
01682     if (ok) ok = pRec->ReadUINT32(&Delay);
01683     if (ok) ok = pRec->ReadBYTE(&Flags);
01684 
01685     if (ok) pLastLayer->SetFrameDelay(Delay);
01686 
01687     pLastLayer->SetSolid((Flags & TAG_LAYER_FLAG_SOLID)   != 0);
01688     pLastLayer->SetOverlay((Flags & TAG_LAYER_FLAG_OVERLAY) != 0);
01689     pLastLayer->SetHiddenFrame((Flags & TAG_LAYER_FLAG_HIDDEN) != 0);
01690 
01691     pLastLayer->SetFrame(TRUE); 
01692     // Frame layers must always be foreground layers!
01693     pLastLayer->SetBackground(FALSE); 
01694     
01695     return ok;
01696 };
01697 
01698 
01699 
01700 /********************************************************************************************
01701 >   BOOL DocumentRecordHandler::HandleSetSentinelRecord(CXaraFileRecord* pRec)
01702 
01703     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
01704     Created:    28/9/99
01705     Inputs:     pRec    ---     the (TAG_SETSENTINEL) record to process
01706     Returns:    TRUE if handled successfully.
01707     Purpose:    Handles insertion for a NodeSetSentinel record.
01708     SeeAlso:    DocumentRecordHandler::HandleRecord; DocumentRecordHandler::GetTagList;
01709                 NodeSetSentinel
01710 ********************************************************************************************/
01711 
01712 BOOL DocumentRecordHandler::HandleSetSentinelRecord(CXaraFileRecord* pRec)
01713 {
01714     ERROR2IF(pRec == 0, FALSE,
01715                 "DocumentRecordHandler::HandleSetSentinelRecord: no record");
01716     ERROR2IF_PF(pRec->GetTag() != TAG_SETSENTINEL, FALSE,
01717                 ("SetSentinel: I don't handle records with the tag (%d)", pRec->GetTag()));
01718 
01719     // If this is not the first SetSentinel handled then ignore the rest of the file.
01720     IncSetSentinelInsertedCount();
01721     if (GetSetSentinelInsertedCount() > 1) EndOfFile();
01722 
01723     // Tell the handler to insert the following records as children of the sentinel.
01724     SetInsertContextNode(GetDocument()->GetSetSentinel());
01725     InsertNextNodeAsChild();
01726 
01727     // Success.
01728     return TRUE;
01729 }
01730 
01731 
01732 
01733 /********************************************************************************************
01734 >   BOOL DocumentRecordHandler::HandleSetPropertyRecord(CXaraFileRecord* pRec)
01735 
01736     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
01737     Created:    28/9/99
01738     Inputs:     pRec    ---     the (TAG_SETPROPERTY) record to process
01739     Returns:    TRUE if handled successfully.
01740     Purpose:    Handles insertion for a NodeSetProperty record.
01741     SeeAlso:    DocumentRecordHandler::HandleRecord; DocumentRecordHandler::GetTagList;
01742                 NodeSetProperty
01743 ********************************************************************************************/
01744 
01745 BOOL DocumentRecordHandler::HandleSetPropertyRecord(CXaraFileRecord* pRec)
01746 {
01747     ERROR2IF(pRec == 0, FALSE,
01748                 "DocumentRecordHandler::HandleSetPropertyRecord: no record");
01749     ERROR2IF_PF(pRec->GetTag() != TAG_SETPROPERTY, FALSE,
01750                 ("SetProperty: I don't handle records with the tag (%d)", pRec->GetTag()));
01751 
01752     // Read in the property's set name and number of associated properties.
01753     String_256 strName;
01754     short n;
01755     if (!pRec->ReadUnicode(&strName) ||
01756         !pRec->ReadINT16(&n))
01757             return FALSE;
01758 
01759     // If the set already has a property then don't input.  This will reject
01760     // duplicate properties on imports. (justin)
01761 // no longer reject duplicate nodes. We need this data! Instead duplicates are removed later (sjk 21/9/00)
01762 //  if (GetDocument()->GetSetSentinel()->FindPropertyNode(strName) != 0)
01763 //      return TRUE;
01764 
01765     // Create a new set property with a full complement of default properties.
01766     NodeSetProperty* pProp = new NodeSetProperty(strName);
01767     ERRORIF( pProp == 0 || !pProp->CreateDefaults(), _R(IDE_NOMORE_MEMORY), FALSE );
01768 
01769     BOOL ok = TRUE;
01770 
01771     // Read in each property in ascending index order.  Stop reading if we reach a
01772     // property index that this build doesn't know about.
01773     while (n--)
01774     {
01775         short nType;
01776         if (!pRec->ReadINT16(&nType))
01777         {
01778             ok = FALSE;
01779             break;
01780         }
01781         if (nType >= SGNameProp::nPropertyCount)
01782             break;
01783         if (!pProp->GetProperty(nType)->Read(pRec))
01784         {
01785             ok = FALSE;
01786             break;
01787         }
01788     }
01789 
01790     // the data in this property node is not correct
01791     // the default data for a property node is used instead
01792     // which the user shouldn't notice much of a change
01793     if (!ok)
01794     {
01795         delete pProp;
01796         pProp = NULL;
01797         // Create a new set property with a full complement of default properties.
01798         pProp = new NodeSetProperty(strName);
01799         ERRORIF(pProp == 0 || !pProp->CreateDefaults(), _R(IDE_NOMORE_MEMORY), FALSE );
01800     }
01801 
01802     pProp->m_Imported = TRUE;
01803 
01804     // Insert the property into the tree.
01805     if (!InsertNode(pProp))
01806         return FALSE;
01807 
01808     // If importing into a document, rather than loading, then try to create undo
01809     // actions for the new attachments.  In an extremely bodgy way we also create
01810     // undo records for the TemplateAttributes we've imported.
01811     if (IsImporting())
01812     {
01813         SelOperation* pSelOp = GetBaseCamelotFilter()->GetImportSelOp();
01814         if (pSelOp != 0)
01815         {
01816             HideNodeAction* pHideAct;
01817             if (AC_FAIL == HideNodeAction::Init(pSelOp, pSelOp->GetUndoActions(),
01818                                                 pProp, TRUE, (Action**) &pHideAct) )
01819                     return FALSE;
01820 
01821             TemplateAttribute* pAttr = GetDocument()->GetSetSentinel()->GetNameAttr(strName);
01822             //ERROR3IF(pAttr == 0, "DocumentRecordHandler::HandleSetPropertyRecord: no name");
01823 
01824             if (pAttr && AC_FAIL == HideNodeAction::Init(pSelOp, pSelOp->GetUndoActions(),
01825                                                 pAttr, TRUE, (Action**) &pHideAct) )
01826                     return FALSE;
01827 
01828         }
01829     }
01830 
01831     // Success.
01832     return TRUE;
01833 }
01834 
01835 
01836 
01837 /********************************************************************************************
01838 >   BOOL DocumentRecordHandler::HandleBarPropertyRecord(CXaraFileRecord* pRec)
01839 
01840     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
01841     Created:    28/9/99
01842     Inputs:     pRec    ---     the (TAG_BARPROPERTY) record to process
01843     Returns:    TRUE if handled successfully.
01844     Purpose:    Handles insertion for a NodeBarProperty record.
01845     SeeAlso:    DocumentRecordHandler::HandleRecord; DocumentRecordHandler::GetTagList;
01846                 NodeSetProperty
01847 ********************************************************************************************/
01848 
01849 BOOL DocumentRecordHandler::HandleBarPropertyRecord(CXaraFileRecord* pRec)
01850 {
01851 PORTNOTE("dialog","DocumentRecordHandler::HandleBarPropertyRecord - do nothing")
01852 #ifndef EXCLUDE_FROM_XARALX
01853     ERROR2IF(pRec == 0, FALSE,
01854                 "DocumentRecordHandler::HandleBarPropertyRecord: no record");
01855     ERROR2IF_PF(pRec->GetTag() != TAG_BARPROPERTY, FALSE,
01856                 ("BarProperty: I don't handle records with the tag (%d)", pRec->GetTag()));
01857 
01858     // Find the existing NodeBarProperty (there is always one).
01859     NodeSetSentinel* pSentry = Document::GetCurrent()->GetSetSentinel();
01860     ERROR3IF(pSentry == 0, "DocumentRecordHandler::HandleBarPropertyRecord: no sentry");
01861     NodeBarProperty* pBarProp = pSentry->FindBarProperty();
01862     ERROR3IF(pBarProp == 0, "DocumentRecordHandler::HandleBarPropertyRecord: no properties");
01863 
01864     g_NoOfBarsBeforeImport = pBarProp->HowMany();
01865 
01866     // Read in the how many array entries were previously written out, if any.
01867     INT32 nBars;
01868     if (!pRec->ReadINT32(&nBars)) return FALSE;
01869     if (nBars == 0) return TRUE;
01870 
01871     // If importing then duplicate and hide the old NodeBarProperty, otherwise 
01872     // clear out all existing entries.
01873     if (IsImporting())
01874     {
01875         SelOperation* pSelOp = GetBaseCamelotFilter()->GetImportSelOp();
01876         if (pSelOp != 0)
01877         {
01878             // Try to duplicate the old bar properties.
01879             NodeBarProperty* pCopy;
01880             ALLOC_WITH_FAIL(pCopy, ((NodeBarProperty*) pBarProp->SimpleCopy()), pSelOp);
01881             if (pCopy == 0) return FALSE;
01882 
01883             // Try to attach the duplicate bar properties in the right place.
01884             pCopy->AttachNode(pSentry, LASTCHILD);
01885             HideNodeAction* pHideAct;
01886             if (AC_FAIL == HideNodeAction::Init(pSelOp, pSelOp->GetUndoActions(),
01887                                                 pCopy, TRUE, (Action**) &pHideAct))
01888                 return FALSE;
01889 
01890             // Try to hide the old bar properties, and substitute the new for the old.
01891             if (!pSelOp->DoHideNode(pBarProp, TRUE, 0, TRUE)) return FALSE;
01892             pBarProp = pCopy;
01893         }
01894     }
01895     else
01896         pBarProp->Clear();
01897 
01898     // Read in each property in ascending index order.
01899     for (INT32 i = 0; i < nBars; i++)
01900     {
01901         BarDataType bdt;
01902         BYTE nCode; 
01903         if (!pRec->ReadINT32(&bdt.Spacing) || !pRec->ReadBYTE(&nCode) || !pRec->ReadBYTE(&bdt.SameSize))
01904             return FALSE;
01905 
01906         bdt.IsLive = nCode & 1;     
01907         bdt.IsHorizontal = (nCode >> 1) & 1;
01908         bdt.RequiresShuffle = (nCode >> 2) & 1;
01909         bdt.ButtonsExtend = (nCode >> 3) & 1;
01910         bdt.ButtonsScale = (nCode >> 4) & 1;
01911         bdt.GroupsStretch = (nCode >> 5) & 1;
01912 
01913         if (pBarProp->HowMany() < MAX_BAR_PROPERTIES) pBarProp->Add(bdt);
01914     } 
01915 #endif  
01916     // Success.
01917     return TRUE;
01918 }
01919 
01920 /********************************************************************************************
01921 
01922 >   BOOL DocumentRecordHandler::HandleCurrentAttrsRecord(CXaraFileRecord* pCXaraFileRecord)
01923 
01924     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01925     Created:    19/03/2004
01926     Inputs:     pCXaraFileRecord = ptr to record to handle
01927     Returns:    TRUE if handled successfuly
01928                 FALSE otherwise
01929     Purpose:    Handles the given record.
01930                 The record has to be a document record
01931     SeeAlso:    -
01932 
01933 ********************************************************************************************/
01934 
01935 BOOL DocumentRecordHandler::HandleCurrentAttrsRecord(CXaraFileRecord* pCXaraFileRecord)
01936 {
01937     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
01938     ERROR2IF(!(pCXaraFileRecord->GetTag() == TAG_CURRENTATTRIBUTES || pCXaraFileRecord->GetTag() == TAG_CURRENTATTRIBUTEBOUNDS), FALSE, "I don't handle this tag type");
01939 
01940     BOOL bOK = TRUE;
01941 
01942     if (pCXaraFileRecord->GetTag() == TAG_CURRENTATTRIBUTES)
01943     {
01944         // Something clever needs to be done here to allow the child attribute TAGs
01945         // of this TAG to behave differently, and make themselves current rather than
01946         // adding themselves to the document tree.
01947         //
01948         // Set the special flag that makes InsertNode behave differently!
01949         // Keep on going until we get a TAG_UP
01950         // Then set the flag back again...
01951         // (Bodgy but quicker and simpler than deriving a special filter class to behave that way)
01952         CCRuntimeClass* pGroupType = NULL;
01953 
01954         BYTE groupid = 0;
01955         bOK = pCXaraFileRecord->ReadBYTE(&groupid);
01956 
01957         if (groupid == ATTRIBUTEGROUP_INK)
01958             pGroupType = CC_RUNTIME_CLASS(NodeRenderableInk);
01959 
01960         else if (groupid == ATTRIBUTEGROUP_TEXT)
01961             pGroupType = CC_RUNTIME_CLASS(BaseTextClass);
01962 
01963         else
01964         {
01965             ERROR3("Unknown Attribute Group ID");
01966 //          bOK = FALSE;
01967             pGroupType = NULL;  // Skip this current attr group
01968         }
01969 
01970         if (bOK && pGroupType!=NULL)
01971         {
01972             pBaseCamelotFilter->SetInsertMode(INSERTMODE_SETCURRENTATTRIBUTE, pGroupType);
01973             bOK = pBaseCamelotFilter->ReadFileUntil(TAG_UP);
01974             pBaseCamelotFilter->SetInsertMode(INSERTMODE_ATTACHTOTREE);
01975         }
01976     }
01977     else if (pCXaraFileRecord->GetTag() == TAG_CURRENTATTRIBUTEBOUNDS)
01978     {
01979         NodeAttribute* pLastCurrentAttr = pBaseCamelotFilter->GetLastCurrentAttrInserted();
01980         if (pLastCurrentAttr && pLastCurrentAttr->IsKindOf(CC_RUNTIME_CLASS(AttrFillGeometry)))
01981         {
01982             DocRect newBounds;
01983             if (bOK) bOK = pCXaraFileRecord->ReadCoord(&newBounds.lo);
01984             if (bOK) bOK = pCXaraFileRecord->ReadCoord(&newBounds.hi);
01985             ((AttrFillGeometry*)pLastCurrentAttr)->SetBoundingRect(newBounds);
01986         }
01987     }
01988 
01989     return bOK;
01990 }
01991 
01992 
01993 
01994 
01995 /********************************************************************************************
01996 
01997 >   BOOL DocumentRecordHandler::HandleDuplicationOffsetRecord(CXaraFileRecord* pCXaraFileRecord)
01998 
01999     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02000     Created:    31/7/96
02001     Inputs:     pCXaraFileRecord = ptr to record to handle
02002     Returns:    TRUE if handled successfuly
02003                 FALSE otherwise
02004     Purpose:    Handles the given record.
02005                 The record has to be a TAG_DUPLICATIONOFFSET record
02006     SeeAlso:    -
02007 
02008 ********************************************************************************************/
02009 
02010 BOOL DocumentRecordHandler::HandleDuplicationOffsetRecord(CXaraFileRecord* pCXaraFileRecord)
02011 {
02012     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"pCXaraFileRecord is NULL");
02013     ERROR2IF(pCXaraFileRecord->GetTag() != TAG_DUPLICATIONOFFSET,FALSE,"I don't handle this tag type");
02014 
02015     BOOL bOK = TRUE;
02016     Document* pDoc = Document::GetCurrent();
02017     if (pDoc)
02018     {
02019         DocCoord newOffset;
02020         if (bOK) bOK = pCXaraFileRecord->ReadINT32(&(newOffset.x));
02021         if (bOK) bOK = pCXaraFileRecord->ReadINT32(&(newOffset.y));
02022         if (bOK) pDoc->SetDuplicationOffset(newOffset);
02023     }
02024 
02025     return bOK;
02026 }
02027 
02028 
02029 
02030 

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