cxftree.cpp

Go to the documentation of this file.
00001 // $Id: cxftree.cpp 1688 2006-08-10 12:05:20Z gerry $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // The Camelot debug tree dialog.
00100 
00101 
00102 #include "camtypes.h"
00103 
00104 #include "cxftree.h"
00105 //#include "node.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "simon.h"
00108 #include "oildbug.h"
00109 #include "nodedoc.h"
00110 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "ccobject.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 #include "nodetext.h"
00113 //#include <ios.h>
00114 #include "bubbleid.h"
00115 
00116 //#include "filtrres.h"
00117 
00118 //#include "cxftree.h"
00119 #include "cxfile.h"
00120 #include "cxftfile.h"
00121 #include "cxftags.h"
00122 //#include "camfiltr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00123 
00124 // new tree control stuff
00125 #include "clipint.h"
00126 #include "keypress.h"
00127 #include "vkextra.h"
00128 #include "insertnd.h"
00129 
00130 #ifdef XAR_TREE_DIALOG
00131 
00132 CC_IMPLEMENT_DYNCREATE(CXFTreeDlg, DialogOp)
00133 CC_IMPLEMENT_DYNAMIC(CXFTreeDlgRecordHandler,CXaraFileRecordHandler)
00134 
00135 CC_IMPLEMENT_DYNAMIC(CXFNode, CCObject)
00136 
00137 CC_IMPLEMENT_MEMDUMP(CXFNodeTypeStatistics,ListItem)
00138 CC_IMPLEMENT_MEMDUMP(CXFNodeTypeStatisticsList,List)
00139 
00140 // This will get Camelot to display the filename and linenumber of any memory allocations
00141 // that are not released at program exit
00142 #define new CAM_DEBUG_NEW
00143 
00144 CXFTreeDlg* CXFTreeDlg::pCurrentCXFTreeDlg = NULL;
00145 BOOL CXFTreeDlg::s_bExpandClicked = FALSE;
00146 
00147 /********************************************************************************************
00148 
00149 >   CXFTreeDlg::CXFTreeDlg()
00150 
00151     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00152     Created:    7/6/96
00153     Purpose:    Create a debug tree dialog operation. Sets up the string used to hold
00154                 node details.
00155 
00156 ********************************************************************************************/
00157 
00158 CXFTreeDlg::CXFTreeDlg(): DialogOp(CXFTreeDlg::IDD(), MODELESS) 
00159 {
00160     pRoot           = NULL;
00161     pContextNode    = NULL;
00162     EndOfFile       = FALSE;
00163     AddNextAsChild  = FALSE;
00164     Level           = 0;
00165     MaxIndex        = 0;
00166 
00167     EditStr = new StringBase;
00168     if (!EditStr || !EditStr->Alloc(0x100000)) return;
00169 
00170     CXFTreeDlg::pCurrentCXFTreeDlg = this;
00171 }
00172 
00173 
00174 /********************************************************************************************
00175 
00176 >   CXFTreeDlg::~CXFTreeDlg()
00177 
00178     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00179     Created:    7/6/96
00180     Purpose:    Cleans up a debug tree dialog operation.
00181 
00182 ********************************************************************************************/
00183 
00184 CXFTreeDlg::~CXFTreeDlg()     
00185 {
00186     Delete(pRoot);
00187     pRoot = NULL;
00188 
00189     // Deallocate the node details string.
00190     delete EditStr;
00191 
00192     CXFTreeDlg::pCurrentCXFTreeDlg = NULL;
00193 }
00194 
00195 
00196 
00197 /********************************************************************************************
00198 
00199 >   void CXFTreeDlg::Do(OpDescriptor*)
00200 
00201     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00202     Created:    7/6/96
00203     Inputs:     Ignored
00204     Purpose:    The 'Do' function for the debug tree dialog. Just creates and opens the
00205                 dialog.
00206 
00207 ********************************************************************************************/
00208 
00209 void CXFTreeDlg::Do(OpDescriptor*)
00210 {
00211     Create();
00212     Open();
00213 }
00214 
00215 
00216 
00217 /********************************************************************************************
00218 
00219 >   BOOL CXFTreeDlg::Init()
00220 
00221     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00222     Created:    7/6/96
00223     Returns:    TRUE if intialised ok;
00224                 FALSE if not.
00225     Purpose:    Initialise the preferences, and register the OpDescriptor for this dialog.
00226 
00227 ********************************************************************************************/
00228 
00229 BOOL CXFTreeDlg::Init()
00230 {
00231     // Register our OpDescriptor
00232     return (RegisterOpDescriptor(
00233                                  0,
00234                                  _R(IDS_CXFTREEDLG), 
00235                                  CC_RUNTIME_CLASS(CXFTreeDlg),
00236                                  OPTOKEN_CXFTREEDLG,
00237                                  CXFTreeDlg::GetState,
00238                                  0, /* help ID */
00239                                  _R(IDBBL_DEBUGTREEDLG),
00240                                  0  /* bitmap ID */));
00241 }
00242 
00243 /********************************************************************************************
00244 
00245 >   BOOL CXFTreeDlg::Create()
00246 
00247     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00248     Created:    7/6/96
00249     Returns:    TRUE if setup ok;
00250                 FALSE if not.
00251     Purpose:    Create and setup the debug tree dialog.
00252 
00253 ********************************************************************************************/
00254 
00255 BOOL CXFTreeDlg::Create()
00256 {
00257     if (DialogOp::Create())
00258     {
00259         EnableGadget(_R(IDC_DEBUGTREE_EXPAND),  TRUE);
00260         EnableGadget(_R(IDC_DEBUGTREE_DUMP),    FALSE);
00261         EnableGadget(_R(IDC_DEBUGTREE_HIDDEN),  FALSE);
00262         EnableGadget(_R(IDC_DEBUGTREE_SELNONLY),FALSE);
00263         EnableGadget(_R(IDC_DEBUGTREE_REFRESH), FALSE);
00264 
00265         InitialiseNewTreeControl();
00266     }
00267 
00268     return TRUE; 
00269 }
00270 
00271 
00272 
00273 /********************************************************************************************
00274 
00275 >   OpState CXFTreeDlg::GetState(String_256*, OpDescriptor*)
00276 
00277     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00278     Created:    7/6/96
00279     Purpose:    The usual.
00280 
00281 ********************************************************************************************/
00282 
00283 OpState CXFTreeDlg::GetState(String_256*, OpDescriptor*)
00284 {
00285     OpState OpSt;
00286     return(OpSt);
00287 }
00288 /********************************************************************************************
00289 
00290 >   void CXFTreeDlg::ShowFile(TCHAR* pFile)
00291 
00292     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00293     Created:    7/6/96
00294     Input:      pFile = ptr to file name
00295     Purpose:    Set up the initial debug tree display
00296     SeeAlso:    CXFTreeDlg::GetTree
00297 
00298 ********************************************************************************************/
00299 
00300 void CXFTreeDlg::ShowFile(TCHAR* pFile)
00301 {
00302     String_256 s = pFile;
00303     SetFileName(s);
00304 
00305     CreateTree();
00306 }  
00307 
00308 
00309 void CXFTreeDlg::DeInit()
00310 {
00311     DeleteAllValues(_R(IDC_DEBUGTREE_TREE));
00312 
00313     Delete(pRoot);
00314     pRoot = NULL;
00315 } 
00316 
00317 
00318 void CXFTreeDlg::Delete(CXFNode* pNode)
00319 {
00320     if (pNode == NULL)
00321         return;
00322 
00323     while (pNode)
00324     {
00325         CXFNode* pNext = pNode->GetNext();
00326 
00327         CXFNode* pChild = pNode->GetChild();
00328         if (pChild)
00329         {
00330             Delete(pChild);
00331         }
00332 
00333         delete pNode;
00334         pNode = pNext;
00335     }
00336 }
00337 
00338 void CXFTreeDlg::SetFileName(String_256& ThisFileName)
00339 {
00340     FileName = ThisFileName;
00341 }
00342 
00343 
00344 void CXFTreeDlg::CreateTree()
00345 {
00346     // Delete the items from the tree control and also delete our tree
00347     DeleteAllValues(_R(IDC_DEBUGTREE_TREE));
00348     Delete(pRoot);
00349     pRoot = NULL;
00350 
00351     // Init vars before reading the file
00352     AddNextAsChild = FALSE;
00353     Level = 0;
00354     pContextNode = NULL;
00355 
00356     ListOfNodeTypeStats.DeleteAll();
00357 
00358     PathName* pPath = new PathName(FileName);
00359 
00360     if (pPath != NULL && pPath->IsValid())
00361     {
00362         CCDiskFile* pFile = new CCDiskFile(*pPath,ios::in | ios::binary);
00363 
00364         if (pFile != NULL)
00365         {
00366             EndOfFile = FALSE;
00367             CXaraFile* pCXFile = NULL;
00368 
00369 PORTNOTE("other", "Removed wix reading - uses COM object")
00370 #if FALSE
00371             char Buf[10];
00372             pFile->read(Buf, 10);
00373             // reset to the begining
00374             pFile->seek(0);
00375 
00376             if ((memcmp(Buf, "FLARETEXT", 9) == 0) &&
00377                 ((Buf[9] == 13) || (Buf[9] == 10)))
00378             {
00379                 pCXFile = new CXaraTemplateFile();      // template so use new class
00380             }
00381             else
00382 #endif
00383             {
00384                 pCXFile = new CXaraFile();              // use original class
00385             }
00386 
00387             if (pCXFile != NULL)
00388             {
00389                 CXaraFileRecordHandler* pHandler = new CXFTreeDlgRecordHandler(this,pCXFile);
00390                 if (pHandler != NULL)
00391                 {
00392                     pCXFile->SetDefaultRecordHandler(pHandler);
00393 
00394                     if (pCXFile->OpenToRead(pFile))
00395                     {
00396                         BOOL ok = TRUE;
00397 
00398                         while (!EndOfFile && ok)
00399                             ok = pCXFile->ReadNextRecord();
00400 
00401                         pCXFile->Close();
00402                     }
00403 
00404                     delete pHandler;
00405                     pHandler = NULL;
00406                 }
00407                 delete pCXFile;
00408             }
00409             delete pFile;
00410         }
00411     }
00412 
00413     if (pPath != NULL)
00414         delete pPath;
00415 
00416 //  ListOfNodeTypeStats.Dump(this);
00417     ListOfNodeTypeStats.DeleteAll();
00418 
00419     CTreeItemID hThisItem = AddOneItem(CTreeItemID(), FileName, CTreeItemID(), m_idxPage, NULL);
00420 
00421     // AddItemsToNewTreeControl doesn't add siblings now so we must loop
00422     CTreeItemID hContext;
00423     CXFNode* pNode = pRoot;
00424     while (pNode)
00425     {
00426         hContext = AddItemToNewTreeControl(hThisItem, hContext, pNode, TRUE);
00427         pNode = pNode->GetNext();
00428     }
00429 }
00430 
00431 //------------------------------------------------------------------
00432 //------------------------------------------------------------------
00433 
00434 void CXFTreeDlg::AddNode(CXFNode* pNode)
00435 {
00436     if (pNode == NULL)
00437         return;
00438 
00439     ListOfNodeTypeStats.Update(pNode);
00440 
00441     if (pRoot == NULL)
00442     {
00443         pRoot = pNode;
00444         return;
00445     }
00446 
00447     if (pContextNode == NULL)
00448         pContextNode = pRoot;
00449 
00450     if (pContextNode != NULL)
00451     {
00452         switch (pNode->GetTag())
00453         {
00454             case TAG_UP:
00455                 AddNextAsChild = FALSE;
00456                 Level--;
00457                 break;
00458 
00459             case TAG_DOWN:
00460                 AddNextAsChild = TRUE;
00461                 Level++;
00462                 break;
00463         }
00464 
00465         if (pContextNode != NULL)
00466         {
00467             if (AddNextAsChild)
00468             {
00469                 CXFNode* pChildNode = pContextNode->GetChild();
00470                 if (pChildNode != NULL)
00471                 {
00472                     TRACEUSER( "Markn", _T("Take cover - context node has already got children"));
00473 
00474                     while (pChildNode->GetNext() != NULL)
00475                         pChildNode = pChildNode->GetNext();
00476 
00477                     pChildNode->SetNext(pNode);
00478                     pNode->SetPrevious(pChildNode);
00479                     pNode->SetParent(pChildNode->GetParent());
00480                 }
00481                 else
00482                 {
00483                     pContextNode->SetChild(pNode);
00484                     pNode->SetParent(pContextNode);
00485                 }
00486 
00487                 AddNextAsChild = FALSE;
00488                 pContextNode = pNode;
00489             }
00490             else
00491             {
00492                 pContextNode->SetNext(pNode);
00493                 pNode->SetPrevious(pContextNode);
00494                 pNode->SetParent(pContextNode->GetParent());
00495 
00496                 if (pNode->GetTag() == TAG_UP)
00497                     pContextNode = pNode->GetParent();
00498                 else
00499                     pContextNode = pNode;
00500             }
00501         }
00502     }
00503 }
00504 
00505 /********************************************************************************************
00506 
00507 >   CXaraFileRecordHandler* CXaraFile::FindHandler(UINT32 Tag)
00508 
00509     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00510     Created:    28/5/96
00511     Inputs:     Tag = the tag value of a record
00512     Returns:    -
00513     Purpose:    Finds the record handler that's been registered to handle a record with the given tag value
00514     SeeAlso:    ReadNextRecord()
00515     Scope:      -
00516 
00517 ********************************************************************************************/
00518 
00519 CXaraFileRecordHandler* CXFTreeDlg::FindHandler(UINT32 Tag)
00520 {
00521     List* pRecordHandlerList = BaseCamelotFilter::GetRecordHandlers();
00522 
00523     ERROR3IF(pRecordHandlerList == NULL,"pRecordHandlerList is NULL");
00524 
00525     if (pRecordHandlerList != NULL)
00526     {
00527         CXaraFileRecordHandler* pHandler = (CXaraFileRecordHandler*) pRecordHandlerList->GetHead();
00528         while (pHandler != NULL)
00529         {
00530             if (pHandler->IsTagInList(Tag))
00531                 return pHandler;
00532 
00533             pHandler = (CXaraFileRecordHandler*) pRecordHandlerList->GetNext(pHandler);
00534         }
00535     }
00536 
00537     return NULL;
00538 }
00539 
00540 void CXFTreeDlg::GetTagText(CXFNode* pNode,String_256& Str)
00541 {
00542     if (pNode != NULL)
00543         GetTagText(pNode->GetTag(),Str);
00544 }
00545 
00546 void CXFTreeDlg::GetTagText(UINT32 Tag,String_256& Str)
00547 {
00548     CXaraFileRecordHandler* pHandler = FindHandler(Tag);
00549 
00550     if (pHandler != NULL)
00551         pHandler->GetTagText(Tag,Str);
00552 }
00553 
00554 
00555 void CXFTreeDlg::ShowNodeDebugInfoForNode(CXFNode *pNode)
00556 {  
00557     if (pNode != NULL)
00558     {
00559         (*EditStr).Empty();
00560 
00561         pNode->ResetReadPos();
00562 
00563         CXaraFileRecordHandler* pHandler = FindHandler(pNode->GetTag());
00564         if (pHandler != NULL)
00565             pHandler->GetRecordDescriptionText(pNode->GetCXaraFileRecord(),EditStr);
00566         else
00567         {
00568             TCHAR s[256];
00569             camSprintf(s,_T("CAN'T FIND HANDLER FOR TAG (%d)\r\nMissing from a handler's tag list perhaps?\r\n"),pNode->GetTag());
00570             (*EditStr) += s;
00571         }
00572 
00573         // Copy this string into the edit control.
00574         SetStringGadgetValue(_R(IDC_DEBUGTREE_DETAILS), *EditStr);
00575     }
00576 }  
00577 
00578 
00579 /********************************************************************************************
00580 
00581 >   MsgResult CXFTreeDlg::Message( Msg* Message)                               
00582 
00583     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00584     Created:    7/6/96
00585     Inputs:     Msg - the message to handle.
00586     Returns:    -
00587     Purpose:    Handles messages for this dialog.
00588 
00589 ********************************************************************************************/
00590 
00591 MsgResult CXFTreeDlg::Message( Msg* Message)
00592 {
00593     if (IS_OUR_DIALOG_MSG(Message))
00594     {
00595         DialogMsg* Msg = (DialogMsg*) Message;
00596         if ((Msg->DlgMsg == DIM_COMMIT || Msg->DlgMsg == DIM_CANCEL)) 
00597         {
00598             DeInit();
00599             Close(); // Hide the dialog
00600             End();
00601         }
00602         else if ((Msg->GadgetID == _R(IDC_DEBUGTREE_EXPAND))
00603              && (Msg->DlgMsg == DIM_LFT_BN_CLICKED))
00604         {
00605             // Expand the tree  
00606             ExpandNewTree();
00607         }
00608         else if ((Msg->GadgetID == _R(IDC_DEBUGTREE_TREE)) && (Msg->DlgMsg == DIM_SELECTION_CHANGED))
00609         {
00610             // Get the node out of the item
00611             CTreeItemID hItem = GetTreeGadgetFirstSelectedItem(_R(IDC_DEBUGTREE_TREE));
00612             if (hItem.IsOk())
00613             {
00614                 CCObject* pNode = GetTreeGadgetItemData(_R(IDC_DEBUGTREE_TREE), hItem);
00615                 if (pNode)
00616                     ShowNodeDebugInfoForNode((CXFNode*)pNode);
00617             }
00618         }
00619 
00620         return (DLG_EAT_IF_HUNGRY(Msg)); 
00621     }
00622     return OK; 
00623 }
00624 
00625 
00626 
00627 //------------------------------------------------------------------
00628 
00629 CXFTreeDlgRecordHandler::CXFTreeDlgRecordHandler(CXFTreeDlg * pThisDlg,CXaraFile* pThisCXFile)
00630 {
00631     ERROR3IF(pThisDlg    == NULL,"Null pThisDlg");
00632     ERROR3IF(pThisCXFile == NULL,"Null pThisCXFile");
00633 
00634     pCXFDlg = pThisDlg;
00635     pCXFile = pThisCXFile;
00636 }
00637 
00638 //------------------------------------------------------------------
00639 
00640 BOOL CXFTreeDlgRecordHandler::HandleRecord(CXaraFileRecord* pRecord)
00641 {
00642     ERROR2IF(pRecord == NULL,FALSE,"NULL record given!");
00643     ERROR2IF(pCXFDlg == NULL,FALSE,"NULL pCXFDlg!");
00644     ERROR2IF(pCXFile == NULL,FALSE,"NULL pCXFile!");
00645 
00646     CXFNode* pNode = new CXFNode(pRecord);
00647 
00648     pCXFDlg->AddNode(pNode);
00649 
00650     switch (pRecord->GetTag())
00651     {
00652         case TAG_STARTCOMPRESSION:
00653             // Ask the compression system to be turned on
00654             pCXFile->SetCompression(TRUE);
00655             break;
00656         case TAG_ENDCOMPRESSION:
00657             // Ask the compression system to be turned off
00658             pCXFile->SetCompression(FALSE);
00659             break;
00660 
00661         case TAG_ENDOFFILE:
00662             pCXFDlg->SetEndOfFile(TRUE);
00663             break;
00664     }
00665 
00666     return TRUE;
00667 }
00668 
00669 BOOL CXFTreeDlgRecordHandler::HandleStreamedRecord(CXaraFile * pCXFile, UINT32 Tag,UINT32 Size,UINT32 RecordNumber)
00670 {
00671     ERROR2IF(pCXFDlg == NULL,FALSE,"NULL pCXFDlg!");
00672     ERROR2IF(pCXFile == NULL,FALSE,"NULL pCXFile!");
00673 
00674     CXaraFileRecord* pRecord = new CXaraFileRecord(Tag,Size);
00675     if (pRecord == NULL || !pRecord->Init(TRUE))
00676         return TRUE;
00677 
00678     pRecord->SetRecordNumber(RecordNumber);
00679 
00680     CXFNode* pNode = new CXFNode(pRecord);      // Constructor makes a copy of the record
00681     delete pRecord;
00682     pRecord = NULL;
00683 
00684     pCXFDlg->AddNode(pNode);
00685 
00686     switch (Tag)
00687     {
00688         case TAG_STARTCOMPRESSION:
00689             // Ask the compression system to be turned on
00690             pCXFile->SetCompression(TRUE);
00691             break;
00692         case TAG_ENDCOMPRESSION:
00693             // Ask the compression system to be turned off
00694             pCXFile->SetCompression(FALSE);
00695             break;
00696 
00697         case TAG_ENDOFFILE:
00698             pCXFDlg->SetEndOfFile(TRUE);
00699             break;
00700     }
00701 
00702     return TRUE;
00703 }
00704 
00705 
00706 /********************************************************************************************
00707 
00708 >   virtual BOOL CXFTreeDlgRecordHandler::IsStreamed(UINT32 Tag)
00709 
00710     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00711     Created:    13/6/96
00712     Inputs:     The tag of the record
00713     Returns:    TRUE if this is a streamed record
00714                 FALSE otherwise
00715     Purpose:    Function to find out if the record is streamed or not.
00716     Errors:     -
00717     SeeAlso:    -
00718 
00719 ********************************************************************************************/
00720 
00721 BOOL CXFTreeDlgRecordHandler::IsStreamed(UINT32 Tag)
00722 {
00723     switch (Tag)
00724     {
00725         case TAG_STARTCOMPRESSION:
00726         case TAG_ENDCOMPRESSION:
00727             return TRUE;
00728             break;
00729     }
00730 
00731     return FALSE;
00732 }
00733 
00734 
00735 //------------------------------------------------------------------
00736 //------------------------------------------------------------------
00737 
00738 CXFNode::CXFNode(CXaraFileRecord* pThisRecord)
00739 {
00740     pRecord     = NULL;
00741     pNext       = NULL;
00742     pPrevious   = NULL;
00743     pParent     = NULL;
00744     pChild      = NULL;
00745 
00746     DoShowChildren = FALSE;
00747 
00748     if (pThisRecord != NULL)
00749         pRecord = pThisRecord->GetCopy();
00750 }
00751 
00752 CXFNode::~CXFNode()
00753 {
00754     if (pRecord != NULL)
00755         delete pRecord;
00756 }
00757 
00758 UINT32 CXFNode::GetTag()
00759 {
00760     if (pRecord != NULL)
00761         return pRecord->GetTag();
00762 
00763     return UINT32(-1);
00764 }
00765 
00766 UINT32 CXFNode::GetSize()
00767 {
00768     if (pRecord != NULL)
00769         return pRecord->GetSize();
00770 
00771     return UINT32(-1);
00772 }
00773 
00774 void CXFNode::ResetReadPos()
00775 {
00776     if (pRecord != NULL)
00777         pRecord->ResetReadPos();
00778 }
00779 
00780 
00781 //---------------------------------------------------------------------------------------------------
00782 //---------------------------------------------------------------------------------------------------
00783 //---------------------------------------------------------------------------------------------------
00784 
00785 void CXFNodeTypeStatisticsList::Update(CXFNode* pNode)
00786 {
00787     CXFNodeTypeStatistics* pItem = FindNodeType(pNode->GetTag());
00788 
00789     if (pItem == NULL)
00790     {
00791         pItem = new CXFNodeTypeStatistics(pNode->GetTag());
00792         if (pItem != NULL)
00793             Add(pItem);
00794     }
00795 
00796     if (pItem != NULL)
00797     {
00798         pItem->IncNumOccurances();
00799         pItem->AddToTotalSize(pNode->GetSize());
00800     }
00801 }
00802 
00803 void CXFNodeTypeStatisticsList::Dump(CXFTreeDlg* pDlg)
00804 {
00805     TRACE( _T("\nRecord stats:\n\n"));
00806 
00807     CXFNodeTypeStatistics* pItem = GetHead();
00808 
00809     String_256 Str;
00810 
00811     while (pItem != NULL)
00812     {
00813         pDlg->GetTagText(pItem->GetTag(),Str);
00814 
00815         INT32 o = pItem->GetNumOccurances();
00816         INT32 s = pItem->GetTotalSize();
00817 
00818         TRACE( _T("%s\t%d\t%d\t%d\n"),(TCHAR*)Str,o,s,(o*8)+s);
00819 
00820         pItem = GetNext(pItem);
00821     }
00822 }
00823 
00824 
00825 CXFNodeTypeStatistics* CXFNodeTypeStatisticsList::FindNodeType(UINT32 Tag)
00826 {
00827     CXFNodeTypeStatistics* pItem = GetHead();
00828     while (pItem != NULL)
00829     {
00830         if (pItem->GetTag() == Tag)
00831             return pItem;
00832 
00833         pItem = GetNext(pItem);
00834     }
00835 
00836     return NULL;
00837 }
00838 
00839 
00840 void CXFNodeTypeStatisticsList::Add(CXFNodeTypeStatistics* pNodeType)
00841 {
00842     AddTail(pNodeType);
00843 }
00844 
00845 CXFNodeTypeStatistics* CXFNodeTypeStatisticsList::GetHead()
00846 {
00847     return (CXFNodeTypeStatistics*)List::GetHead();
00848 }
00849 
00850 CXFNodeTypeStatistics* CXFNodeTypeStatisticsList::GetNext(CXFNodeTypeStatistics* pItem)
00851 {
00852     return (CXFNodeTypeStatistics*)List::GetNext(pItem);
00853 }
00854 
00855 
00856 /********************************************************************************************
00857 
00858 New TreeView Control stuff by Richard - 14/3/97
00859 
00860 ********************************************************************************************/
00861 
00862 
00863 /********************************************************************************************
00864 
00865 >   CTreeItemID CXFTreeDlg::AddOneItem(CTreeItemID hParent, const StringBase& str, CTreeItemID hInsAfter,
00866                                                                      INT32 iImage, CXFNode *pNode)
00867 
00868     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00869     Created:    15/02/97
00870     Purpose:    This function fills out the TV_ITEM and TV_INSERTSTRUCT structures 
00871                 and adds the item to the tree view control.
00872 
00873 ********************************************************************************************/
00874 
00875 CTreeItemID CXFTreeDlg::AddOneItem(CTreeItemID hParent, const StringBase& str, CTreeItemID hInsAfter, INT32 iImage, CXFNode *pNode)
00876 {
00877     return SetTreeGadgetItem(_R(IDC_DEBUGTREE_TREE), hParent, str, hInsAfter, iImage, pNode);
00878 }
00879 
00880 
00881 /********************************************************************************************
00882 
00883 >   INT32 CXFTreeDlg::GetImageForNode(CXFNode *pNode)
00884 
00885     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00886     Created:    15/02/97
00887     Purpose:    Return an imagelist item (icon) for the given node.
00888 
00889 ********************************************************************************************/
00890 
00891 INT32 CXFTreeDlg::GetImageForNode(CXFNode *pNode)
00892 {
00893     INT32 iImage = m_idxGeneralTag;
00894 
00895     if(pNode != NULL)
00896     {
00897         UINT32 Tag = pNode->GetTag();
00898 
00899         switch(Tag)
00900         {
00901             case TAG_UP:
00902                 iImage = m_idxUp;
00903                 break;
00904 
00905             case TAG_DOWN:
00906                 iImage = m_idxDown;
00907                 break;
00908 
00909             case TAG_STARTCOMPRESSION:
00910             case TAG_ENDCOMPRESSION:
00911                 iImage = m_idxCompression;
00912                 break;
00913 
00914             case TAG_DOCUMENT:
00915             case TAG_CHAPTER:
00916             case TAG_SPREAD:
00917             case TAG_LAYER:
00918             case TAG_PAGE:
00919             case TAG_SPREADINFORMATION:
00920                 iImage = m_idxPage;
00921                 break;
00922 
00923             case TAG_DEFINERGBCOLOUR:
00924             case TAG_DEFINECOMPLEXCOLOUR:
00925                 iImage = m_idxDefineColour;
00926                 break;
00927 
00928             case TAG_PREVIEWBITMAP_BMP:
00929             case TAG_PREVIEWBITMAP_GIF:
00930             case TAG_PREVIEWBITMAP_JPEG:
00931             case TAG_PREVIEWBITMAP_PNG:
00932             case TAG_PREVIEWBITMAP_TIFFLZW:
00933             case TAG_DEFINEBITMAP_BMP:
00934             case TAG_DEFINEBITMAP_GIF:
00935             case TAG_DEFINEBITMAP_JPEG:
00936             case TAG_DEFINEBITMAP_PNG:
00937             case TAG_DEFINEBITMAP_BMPZIP:
00938             case TAG_DEFINESOUND_WAV:
00939             case TAG_DEFINEBITMAP_JPEG8BPP:
00940             case TAG_NODE_BITMAP:
00941             case TAG_NODE_CONTONEDBITMAP:
00942                 iImage = m_idxDefineBitmap;
00943                 break;
00944 
00945             case TAG_GROUP:
00946             case TAG_COMPOUNDRENDER:
00947             case TAG_LIVE_EFFECT:
00948             case TAG_LOCKED_EFFECT:
00949             case TAG_FEATHER_EFFECT:
00950             case TAG_GROUPTRANSP:
00951             case TAG_CACHEDNODESGROUP:
00952                 iImage = m_idxGroup;
00953                 break;
00954 
00955             case TAG_PATH:
00956             case TAG_PATH_FILLED:
00957             case TAG_PATH_STROKED:
00958             case TAG_PATH_FILLED_STROKED:
00959             case TAG_BLEND:
00960             case TAG_BLENDER:
00961             case TAG_BLENDER_CURVEPROP:
00962             case TAG_BLENDER_CURVEANGLES:
00963             case TAG_BLEND_PATH:
00964             case TAG_MOULD_ENVELOPE:
00965             case TAG_MOULD_PERSPECTIVE:
00966             case TAG_MOULD_GROUP:
00967             case TAG_MOULD_PATH:
00968             case TAG_PATH_FLAGS:
00969             case TAG_GUIDELINE:
00970             case TAG_PATH_RELATIVE:
00971             case TAG_PATH_RELATIVE_FILLED:
00972             case TAG_PATH_RELATIVE_STROKED:
00973             case TAG_PATH_RELATIVE_FILLED_STROKED:
00974             case TAG_PATHREF_IDENTICAL:
00975             case TAG_PATHREF_TRANSFORM:
00976             case TAG_ELLIPSE_SIMPLE:
00977             case TAG_ELLIPSE_COMPLEX:
00978             case TAG_RECTANGLE_SIMPLE:
00979             case TAG_RECTANGLE_SIMPLE_REFORMED:
00980             case TAG_RECTANGLE_SIMPLE_STELLATED:
00981             case TAG_RECTANGLE_SIMPLE_STELLATED_REFORMED:
00982             case TAG_RECTANGLE_SIMPLE_ROUNDED:
00983             case TAG_RECTANGLE_SIMPLE_ROUNDED_REFORMED:
00984             case TAG_RECTANGLE_SIMPLE_ROUNDED_STELLATED:
00985             case TAG_RECTANGLE_SIMPLE_ROUNDED_STELLATED_REFORMED:
00986             case TAG_RECTANGLE_COMPLEX:
00987             case TAG_RECTANGLE_COMPLEX_REFORMED:
00988             case TAG_RECTANGLE_COMPLEX_STELLATED:
00989             case TAG_RECTANGLE_COMPLEX_STELLATED_REFORMED:
00990             case TAG_RECTANGLE_COMPLEX_ROUNDED:
00991             case TAG_RECTANGLE_COMPLEX_ROUNDED_REFORMED:
00992             case TAG_RECTANGLE_COMPLEX_ROUNDED_STELLATED:
00993             case TAG_RECTANGLE_COMPLEX_ROUNDED_STELLATED_REFORMED:
00994             case TAG_POLYGON_COMPLEX:
00995             case TAG_POLYGON_COMPLEX_REFORMED:
00996             case TAG_POLYGON_COMPLEX_STELLATED:
00997             case TAG_POLYGON_COMPLEX_STELLATED_REFORMED:
00998             case TAG_POLYGON_COMPLEX_ROUNDED:
00999             case TAG_POLYGON_COMPLEX_ROUNDED_REFORMED:
01000             case TAG_POLYGON_COMPLEX_ROUNDED_STELLATED:
01001             case TAG_POLYGON_COMPLEX_ROUNDED_STELLATED_REFORMED:
01002             case TAG_REGULAR_SHAPE_PHASE_1:
01003             case TAG_REGULAR_SHAPE_PHASE_2:
01004                 iImage = m_idxShape;
01005                 break;
01006 
01007             case TAG_FLATFILL:
01008             case TAG_LINECOLOUR:
01009             case TAG_LINEWIDTH:
01010             case TAG_LINEARFILL:
01011             case TAG_LINEARFILL3POINT:
01012             case TAG_LINEARFILLMULTISTAGE:
01013             case TAG_LINEARFILLMULTISTAGE3POINT:
01014             case TAG_CIRCULARFILL:
01015             case TAG_ELLIPTICALFILL:
01016             case TAG_CONICALFILL:
01017             case TAG_BITMAPFILL:
01018             case TAG_CONTONEBITMAPFILL:
01019             case TAG_FRACTALFILL:
01020             case TAG_FILLEFFECT_FADE:
01021             case TAG_FILLEFFECT_RAINBOW:
01022             case TAG_FILLEFFECT_ALTRAINBOW:
01023             case TAG_FILL_REPEATING:
01024             case TAG_FILL_NONREPEATING:
01025             case TAG_FILL_REPEATINGINVERTED:
01026             case TAG_FILL_REPEATING_EXTRA:
01027             case TAG_FLATTRANSPARENTFILL:
01028             case TAG_LINEARTRANSPARENTFILL:
01029             case TAG_LINEARTRANSPARENTFILL3POINT:
01030             case TAG_CIRCULARTRANSPARENTFILL:
01031             case TAG_ELLIPTICALTRANSPARENTFILL:
01032             case TAG_CONICALTRANSPARENTFILL:
01033             case TAG_BITMAPTRANSPARENTFILL:
01034             case TAG_FRACTALTRANSPARENTFILL:
01035             case TAG_LINETRANSPARENCY:
01036             case TAG_STARTCAP:
01037             case TAG_ENDCAP:
01038             case TAG_JOINSTYLE:
01039             case TAG_MITRELIMIT:
01040             case TAG_WINDINGRULE:
01041             case TAG_QUALITY:
01042             case TAG_TRANSPARENTFILL_REPEATING:
01043             case TAG_TRANSPARENTFILL_NONREPEATING:
01044             case TAG_TRANSPARENTFILL_REPEATINGINVERTED:
01045             case TAG_DASHSTYLE:
01046             case TAG_DEFINEDASH:
01047             case TAG_ARROWHEAD:
01048             case TAG_ARROWTAIL:
01049             case TAG_DEFINEARROW:
01050             case TAG_DEFINEDASH_SCALED:
01051             case TAG_USERVALUE:
01052             case TAG_WEBADDRESS:
01053             case TAG_WEBADDRESS_BOUNDINGBOX:
01054             case TAG_FLATFILL_NONE:
01055             case TAG_FLATFILL_BLACK:
01056             case TAG_FLATFILL_WHITE:
01057             case TAG_LINECOLOUR_NONE:
01058             case TAG_LINECOLOUR_BLACK:
01059             case TAG_LINECOLOUR_WHITE:
01060             case TAG_SQUAREFILL:
01061             case TAG_SQUARETRANSPARENTFILL:
01062             case TAG_THREECOLFILL:
01063             case TAG_THREECOLTRANSPARENTFILL:
01064             case TAG_FOURCOLFILL:
01065             case TAG_FOURCOLTRANSPARENTFILL:
01066             case TAG_VARIABLEWIDTHFUNC:
01067             case TAG_VARIABLEWIDTHTABLE:
01068             case TAG_STROKETYPE:
01069             case TAG_STROKEDEFINITION:
01070             case TAG_STROKEAIRBRUSH:
01071             case TAG_NOISEFILL:
01072             case TAG_NOISETRANSPARENTFILL:
01073             case TAG_WIZOP:
01074                 iImage = m_idxAttribute;
01075                 break;
01076 
01077             case TAG_SETSENTINEL:
01078                 iImage = m_idxSentinelNode; break;
01079 
01080             case TAG_SETPROPERTY:
01081                 iImage = m_idxSetProperty; break;
01082         }
01083     }
01084 
01085     return iImage;
01086 }
01087 
01088 /********************************************************************************************
01089 
01090 >   CTreeItemID CXFTreeDlg::AddItemToNewTreeControl(CTreeItemID hParentItem, CTreeItemID hInsAfterItem, CXFNode *pNode, BOOL bAddChildren)
01091 
01092     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01093     Created:    15/02/97
01094     Purpose:    Recursively add this item and all its children to the tree control
01095                 No longer adds siblings as this guarantees a stack overflow if there is 
01096                 any very large sibling list.
01097 
01098 ********************************************************************************************/
01099 
01100 CTreeItemID CXFTreeDlg::AddItemToNewTreeControl(CTreeItemID hParentItem, CTreeItemID hInsAfterItem, CXFNode *pNode, BOOL bAddChildren)
01101 {
01102     if(pNode == NULL)
01103         return CTreeItemID();
01104 
01105     String_256 NodeText; //(((TCHAR*)(pNode->GetRuntimeClass()->m_lpszClassName)));
01106 
01107     GetTagText(pNode, NodeText);
01108     INT32 iImage = GetImageForNode(pNode);
01109 
01110     CTreeItemID hThisItem = AddOneItem(hParentItem, NodeText, hInsAfterItem, iImage, pNode);
01111 
01112     // Check to see if this node has any children
01113     CXFNode *pChild = pNode->GetChild();
01114     if (pChild && bAddChildren)
01115     {
01116         CTreeItemID hInsContext;
01117 
01118         while (pChild != NULL)
01119         {
01120             // Add to the tree control
01121             hInsContext = AddItemToNewTreeControl(hThisItem, hInsContext, pChild, bAddChildren);
01122             pChild = pChild->GetNext();
01123         }
01124     }
01125 
01126     return hThisItem;
01127 }
01128 
01129 
01130 
01131 /********************************************************************************************
01132 
01133 >   BOOL CXFTreeDlg::InitialiseNewTreeControl(void)
01134 
01135     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01136     Created:    15/02/97
01137     Purpose:    Sets up the ImageList for the tree control
01138 
01139 ********************************************************************************************/
01140 
01141 BOOL CXFTreeDlg::InitialiseNewTreeControl(void)
01142 {
01143     CGadgetImageList NewImageList(16, 16);
01144     m_idxGeneralTag     = NewImageList.Add(_R(IDB_CXFTREE_GENERALTAG));
01145     m_idxDefineBitmap   = NewImageList.Add(_R(IDB_CXFTREE_DEFINEBITMAP));
01146     m_idxDefineColour   = NewImageList.Add(_R(IDB_CXFTREE_DEFINECOLOUR));
01147     m_idxCompression    = NewImageList.Add(_R(IDB_CXFTREE_COMPRESSION));
01148     m_idxDown           = NewImageList.Add(_R(IDB_CXFTREE_DOWN));
01149     m_idxUp             = NewImageList.Add(_R(IDB_CXFTREE_UP));
01150     m_idxGroup          = NewImageList.Add(_R(IDB_CXFTREE_GROUP));
01151     m_idxPage           = NewImageList.Add(_R(IDB_DEBUGTREE_RENDERABLEPAPER));
01152     m_idxAttribute      = NewImageList.Add(_R(IDB_DEBUGTREE_ATTRIBUTE));
01153     m_idxShape          = NewImageList.Add(_R(IDB_DEBUGTREE_RENDERABLEINK));
01154     m_idxSentinelNode   = NewImageList.Add(_R(IDB_DEBUGTREE_SENTINELNODE));
01155     m_idxSetProperty    = NewImageList.Add(_R(IDB_DEBUGTREE_SETPROPERTY));
01156 
01157     SetGadgetBitmaps(_R(IDC_DEBUGTREE_TREE), NewImageList);
01158 
01159     return(TRUE);
01160 }
01161 
01162 
01163 /********************************************************************************************
01164 
01165 >   BOOL CXFTreeDlg::GetInfoFromTreeItem(CTreeItemID hItem, CXFNode **ppNode, INT32 *pChildren)
01166 
01167     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01168     Created:    15/02/97
01169     Purpose:    Obtains the Node pointer and children flag for the given HTREEITEM.
01170 
01171 ********************************************************************************************/
01172 
01173 BOOL CXFTreeDlg::GetInfoFromTreeItem(CTreeItemID hItem, CXFNode **ppNode, INT32 *pChildren)
01174 {
01175     CCObject* pNode = GetTreeGadgetItemData(_R(IDC_DEBUGTREE_TREE), hItem);
01176     ERROR3IF(!pNode->IsKindOf(CC_RUNTIME_CLASS(CXFNode)), "DebugTreeDlg found a non-CXFNode tree item");
01177     if (!pNode->IsKindOf(CC_RUNTIME_CLASS(CXFNode)))
01178         return FALSE;
01179 
01180     *ppNode     = (CXFNode*)pNode;
01181     *pChildren  = GetTreeGadgetChildrenCount(_R(IDC_DEBUGTREE_TREE), hItem, FALSE);
01182 
01183     return TRUE;
01184 }
01185 
01186 
01187 /********************************************************************************************
01188 
01189 >   void CXFTreeDlg::ExpandNewTree()
01190 
01191     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01192     Created:    14/02/97
01193     Purpose:    Expands the tree display so that the whole tree is displayed in the control.
01194 
01195 ********************************************************************************************/
01196 
01197 void CXFTreeDlg::ExpandNewTree()
01198 {
01199     CTreeItemID hItem = GetTreeGadgetRootItem(_R(IDC_DEBUGTREE_TREE));
01200 //  CTreeItemID hSelectedItem = GetTreeGadgetFirstSelectedItem(_R(IDC_DEBUGTREE_TREE));
01201 
01202     // Loop through the items in the tree control
01203     while (hItem.IsOk())
01204     {
01205         TreeGadgetExpandItem(_R(IDC_DEBUGTREE_TREE), hItem);
01206 //      CTreeItemID hChild = GetTreeGadgetFirstChildItem(_R(IDC_DEBUGTREE_TREE), hItem);
01207 //      if (hChild.IsOk())
01208 //          hItem = hChild;
01209 
01210         // Get the next item
01211         hItem = GetTreeGadgetNextVisItem(_R(IDC_DEBUGTREE_TREE), hItem);
01212     }
01213 
01214 //  if (hSelectedItem.IsOk())
01215 //      SelectTreeGadgetItem(_R(IDC_DEBUGTREE_TREE), hSelectedItem, TRUE );
01216 } 
01217 
01218 #if FALSE
01219 void CXFTreeDlg::ExpandTreeItem(CTreeItemID hItem, BOOL bChildren)
01220 {
01221     if (hItem.IsOk())
01222         TreeGadgetExpandItem(_R(IDC_DEBUGTREE_TREE), hItem);
01223 
01224     if (bChildren)
01225     {
01226         CTreeItemID hChild = GetTreeGadgetFirstChildItem(_R(IDC_DEBUGTREE_TREE), hItem);
01227 
01228         // Loop through the child items
01229         while (hChild.IsOk())
01230         {
01231             ExpandTreeItem(hChild, bChildren);
01232 
01233             // Get the next item
01234             hItem = GetTreeGadgetNextItem(_R(IDC_DEBUGTREE_TREE), hChild);
01235         }
01236     }
01237 } 
01238 #endif
01239 
01240 #endif  // XAR_TREE_DIALOG
01241 

Generated on Sat Nov 10 03:44:59 2007 for Camelot by  doxygen 1.4.4