prnmkcom.cpp

Go to the documentation of this file.
00001 // $Id: prnmkcom.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 //
00099 // Author  : Mike
00100 // Created : 31/07/96
00101 // Purpose : The PrintMarks Doc Component and all its helper classes.
00102 
00103 /*
00104 */
00105 
00106 #include "camtypes.h"
00107 
00108 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "camfiltr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "cxfrec.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "cxfrech.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 #include "cxftags.h"
00113 #include "layer.h"
00114 //#include "group.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 #include "prnmkcom.h"
00116 //#include "prnmks.h"
00117 
00118 CC_IMPLEMENT_DYNAMIC(PrintMarksComponent, DocComponent)
00119 CC_IMPLEMENT_DYNAMIC(PrintMarkComponentClass, DocComponentClass)
00120 CC_IMPLEMENT_DYNAMIC(DocPrintMarkList, List)
00121 CC_IMPLEMENT_DYNCREATE(DocPrintMark, ListItem)
00122 
00123 DECLARE_SOURCE("$Revision: 1282 $");
00124 
00125 // Declare smart memory handling in Debug builds
00126 #define new CAM_DEBUG_NEW
00127 
00128 
00129 /********************************************************************************************
00130 
00131 >   DocPrintMark::DocPrintMark()
00132 
00133     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00134     Created:    31/07/96
00135     Purpose:
00136     SeeAlso:
00137 
00138 ********************************************************************************************/
00139 
00140 DocPrintMark::DocPrintMark()
00141 {
00142     Handle=0;
00143 }
00144 
00145 DocPrintMark::DocPrintMark(UINT32 hndle)
00146 {
00147     Handle=hndle;
00148 }
00149 
00150 /********************************************************************************************
00151 
00152 >   DocPrintMark::~DocPrintMark()
00153 
00154     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00155     Created:    31/07/96
00156     Purpose:
00157     SeeAlso:
00158 
00159 ********************************************************************************************/
00160 
00161 DocPrintMark::~DocPrintMark()
00162 {
00163 }
00164 
00165 
00166 /********************************************************************************************
00167 
00168 >   DocPrintMarkList::DocPrintMarkList()
00169 
00170     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00171     Created:    31/07/96
00172     Purpose:
00173     SeeAlso:
00174 
00175 ********************************************************************************************/
00176 
00177 DocPrintMarkList::DocPrintMarkList()
00178 {
00179     Virgin=TRUE;
00180 }
00181 
00182 
00183 /********************************************************************************************
00184 
00185 >   DocPrintMarkList::~DocPrintMarkList()
00186 
00187     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00188     Created:    31/07/96
00189     Purpose:
00190     SeeAlso:
00191 
00192 ********************************************************************************************/
00193 
00194 DocPrintMarkList::~DocPrintMarkList()
00195 {
00196     RemoveAllMarks();
00197 }
00198 
00199 BOOL DocPrintMarkList::AddMark(UINT32 handle)
00200 {
00201     DocPrintMark* pMark = new DocPrintMark(handle);
00202     if (pMark)
00203     {
00204         AddTail(pMark);
00205         Virgin=FALSE;
00206     }
00207     return (pMark!=NULL);
00208 }
00209 
00210 void DocPrintMarkList::RemoveMark(UINT32 handle)
00211 {
00212     DocPrintMark* pMark = FindMark(handle);
00213     if (pMark)
00214     {
00215         RemoveItem(pMark);
00216         delete pMark;
00217     }
00218     else
00219     {
00220         TRACEUSER( "Mike", _T("Unable to find mark during DocPrintMarkList::RemoveMark()"));
00221     }
00222 }
00223 
00224 void DocPrintMarkList::RemoveAllMarks()
00225 {
00226     DocPrintMark* pItem;
00227     while ((pItem=((DocPrintMark*)RemoveTail()))!=NULL)
00228         delete pItem;
00229 }
00230 
00231 /*****************************************************************************************
00232 
00233 >   DocPrintMark* DocPrintMarkList::FindMark(UINT32 SearchHandle) const
00234 
00235     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00236     Created:    23/07/96
00237     Inputs:     SearchHandle = the handle of the mark to search for
00238     Returns:    A pointer to the print mark described by this handle (NULL if none)
00239     Purpose:    Try to find a print mark in the doc component, using its handle
00240 
00241 *****************************************************************************************/
00242 
00243 DocPrintMark* DocPrintMarkList::FindMark(UINT32 SearchHandle) const
00244 {
00245     DocPrintMark* pItem = GetFirstMark();
00246     while (pItem)
00247     {
00248         if (pItem->GetHandle() == SearchHandle)
00249             return pItem;
00250         pItem = GetNextMark(pItem);
00251     }
00252     return NULL;
00253 }
00254 
00255 
00256 /********************************************************************************************
00257 
00258 >   BOOL PrintMarkComponentClass::Init()
00259 
00260     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00261     Created:    31/07/96
00262     Returns:    TRUE if all went well;
00263                 FALSE if not.
00264     Purpose:    Register the print marks document component with the main application.
00265     Errors:     Out of memory.
00266     SeeAlso:    DocComponent
00267 
00268 ********************************************************************************************/
00269 
00270 BOOL PrintMarkComponentClass::Init()
00271 {
00272     // Instantiate a component class to register with the application.
00273     PrintMarkComponentClass *pClass = new PrintMarkComponentClass;
00274     if (pClass == NULL)
00275         return FALSE;
00276 
00277     // Register it
00278     GetApplication()->RegisterDocComponent(pClass);
00279 
00280     // All ok
00281     return TRUE;
00282 }
00283 
00284 
00285 /********************************************************************************************
00286 
00287 >   BOOL PrintMarkComponentClass::AddComponent(BaseDocument *pDocument)
00288 
00289     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00290     Created:    31/07/96
00291     Inputs:     pDocument - the document to add the print to.
00292     Returns:    TRUE if the printmark component was added ok;
00293                 FALSE if not.
00294     Purpose:    Add a printmark component to the specified document.
00295     Errors:     Out of memory
00296     SeeAlso:    PrintComponentClass
00297 
00298 ********************************************************************************************/
00299 
00300 BOOL PrintMarkComponentClass::AddComponent(BaseDocument *pDocument)
00301 {
00302     ERROR2IF(pDocument==NULL,FALSE,"NULL document passed to PrintMarkCompClass:Add");
00303     
00304     // Check to see if this document already has a colour list; if so, leave it alone.
00305     if (pDocument->GetDocComponent(CC_RUNTIME_CLASS(PrintMarksComponent)) != NULL)
00306         return TRUE;
00307 
00308     // Ok - create the print mark component.
00309     PrintMarksComponent *pComponent = new PrintMarksComponent();
00310     if (pComponent==NULL)
00311         return FALSE;
00312 
00313     // All ok - add the component to the document.
00314     pDocument->AddDocComponent(pComponent);
00315     return TRUE;
00316 }
00317 
00318 
00319 
00320 /********************************************************************************************
00321 
00322 >   PrintMarksComponent::PrintMarksComponent()
00323 
00324     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00325     Created:    31/07/96
00326     Purpose:
00327     SeeAlso:
00328 
00329 ********************************************************************************************/
00330 
00331 PrintMarksComponent::PrintMarksComponent()
00332 {
00333     CustomPreviousContext = NULL;
00334     CustomCurrentContext  = NULL;
00335     pNewMark = NULL;
00336 }
00337 
00338 /********************************************************************************************
00339 
00340 >   PrintMarksComponent::~PrintMarksComponent()
00341 
00342     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00343     Created:    31/07/96
00344     Purpose:
00345     SeeAlso:
00346 
00347 ********************************************************************************************/
00348 
00349 PrintMarksComponent::~PrintMarksComponent()
00350 {
00351 }
00352 
00353 
00354 
00355 /********************************************************************************************
00356 
00357 >   BOOL PrintMarksComponent::AddMark(UINT32 handle)
00358 
00359     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00360     Created:    31/07/96
00361     Purpose:    Adds a print mark reference to our component list
00362     SeeAlso:
00363 
00364 ********************************************************************************************/
00365 
00366 BOOL PrintMarksComponent::AddMark(UINT32 handle)
00367 {
00368     // it may well be there already!
00369     if (DocMarks.FindMark(handle))
00370         return TRUE;
00371     return DocMarks.AddMark(handle);        
00372 }
00373 
00374 
00375 
00376 /********************************************************************************************
00377 
00378 >   void PrintMarksComponent::RemoveMark(UINT32 handle)
00379 
00380     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00381     Created:    31/07/96
00382     Purpose:    Remove a print marks component from the list.
00383     SeeAlso:
00384 
00385 ********************************************************************************************/
00386 
00387 void PrintMarksComponent::RemoveMark(UINT32 handle)
00388 {
00389     DocMarks.RemoveMark(handle);
00390 }
00391 
00392 
00393 /********************************************************************************************
00394 
00395 >   void PrintMarksComponent::RemoveAllMarks()
00396 
00397     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00398     Created:    31/07/96
00399     Purpose:    Empty the list of all marks
00400     SeeAlso:
00401 
00402 ********************************************************************************************/
00403 
00404 void PrintMarksComponent::RemoveAllMarks()
00405 {
00406     DocMarks.RemoveAllMarks();
00407 }
00408 
00409 
00410 
00411 /********************************************************************************************
00412 
00413 >   DocPrintMark* PrintMarksComponent::FindMark(UINT32 handle) const
00414 
00415     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00416     Created:    31/07/96
00417     Inputs:     handle = the handle of the mark to search for
00418     Returns:    A pointer to the print mark described by this handle (NULL if none)
00419     Purpose:    Try to find a print mark in the doc component, using the print mark handle
00420     SeeAlso:
00421 
00422 ********************************************************************************************/
00423 
00424 DocPrintMark* PrintMarksComponent::FindMark(UINT32 handle) const
00425 {
00426     return DocMarks.FindMark(handle);
00427 }
00428 
00429 
00430 /********************************************************************************************
00431 
00432 >   BOOL PrintMarksComponent::IsVirgin() const
00433 
00434     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00435     Created:    31/07/96
00436     Returns:    TRUE - if no print mark has ever been added to this print mark component
00437                 FALSE - if some have in past history
00438     Purpose:    Is this a virgin print marks component, ie has it never had a print mark
00439                 added to it?
00440 
00441 ********************************************************************************************/
00442 
00443 BOOL PrintMarksComponent::IsVirgin() const
00444 {
00445     return DocMarks.IsVirgin();
00446 }
00447 
00448 
00449 /********************************************************************************************
00450 
00451 >   BOOL PrintMarksComponent::StartImport(BaseCamelotFilter *pFilter)
00452 
00453     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00454     Created:    31/07/96
00455     Inputs:     pFilter - the BaseCamelotFilter filter that is being used to import a file.
00456     Returns:    TRUE if the component was able to prepare for importing;
00457                 FALSE if not (e.g. out of memory)
00458     Purpose:
00459     SeeAlso:    DocComponent
00460 
00461 ********************************************************************************************/
00462 
00463 BOOL PrintMarksComponent::StartImport(BaseCamelotFilter *pFilter)
00464 {
00465     if (pFilter == NULL)
00466     {
00467         ERROR3("PrintMarksComponent::StartImport filter is null!");
00468         return TRUE;
00469     }
00470 
00471     CustomPreviousContext = NULL;
00472     CustomCurrentContext  = NULL;
00473     pNewMark = NULL;
00474 
00475     // If we're importing into an existing document, we ignore all printer mark
00476     // information in the file being imported.
00477     if (pFilter->IsImporting())
00478         return(TRUE);
00479 
00480     // Before importing, we delete all existing marks, so that the loaded file overrides
00481     // the settings already present in the document.
00482     RemoveAllMarks();
00483 
00484     return TRUE;
00485 }
00486 
00487 
00488 /********************************************************************************************
00489 
00490 >   BOOL PrintMarksComponent::EndImport(BaseCamelotFilter *pFilter, BOOL Success)
00491 
00492     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00493     Created:    31/07/96
00494     Inputs:     pFilter - the BaseCamelotFilter filter that is being used to import a file.
00495                 Success - TRUE => The import was successful;
00496                          FALSE => The import failed - abandon any changes.
00497     Returns:    TRUE if the component was able to end the importing;
00498                 FALSE if not (e.g. out of memory)
00499     Purpose:
00500     SeeAlso:    DocComponent
00501 
00502 ********************************************************************************************/
00503 
00504 BOOL PrintMarksComponent::EndImport(BaseCamelotFilter *pFilter, BOOL Success)
00505 {
00506 /*
00507     if (pFilter==NULL)
00508     {
00509         ERROR3("PrintMarksComponent::EndImport filter is null!");
00510         return TRUE;
00511     }
00512 
00513     if (Success)
00514     {
00515 
00516     }
00517     else
00518     {
00519 
00520     }
00521 */
00522     CustomPreviousContext = NULL;
00523     CustomCurrentContext  = NULL;
00524     pNewMark = NULL;
00525 
00526     return TRUE;
00527 }
00528 
00529 
00530 
00531 /********************************************************************************************
00532 
00533 >   BOOL PrintMarksComponent::StartExport(BaseCamelotFilter *pFilter)
00534 
00535     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00536     Created:    31/07/96
00537     Inputs:     pFilter - the BaseCamelotFilter filter that is being used to export a file.
00538     Returns:    TRUE if the component was able to prepare for exporting;
00539                 FALSE if not (e.g. out of memory)
00540     Purpose:
00541     SeeAlso:    DocComponent
00542 
00543 ********************************************************************************************/
00544 
00545 BOOL PrintMarksComponent::StartExport(BaseCamelotFilter *pFilter)
00546 {
00547 #if !defined(EXCLUDE_FROM_RALPH)
00548 /*
00549     if (pFilter == NULL)
00550     {
00551         ERROR3("PrintMarksComponent::StartExport filter is null!");
00552         return TRUE;
00553     }
00554 
00555 */
00556 #endif
00557     return TRUE;
00558 }
00559 
00560 
00561 
00562 /********************************************************************************************
00563 
00564 >   BOOL PrintMarksComponent::EndExport(BaseCamelotFilter *pFilter, BOOL Success)
00565 
00566     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00567     Created:    31/07/96
00568     Inputs:     pFilter - the BaseCamelotFilter filter that is being used to import a file.
00569                 Success - True if everything went swimmingly, False if just a clean up is required.
00570     Returns:    TRUE if the component was able to end the importing;
00571                 FALSE if not (e.g. out of memory)
00572     Purpose:
00573     SeeAlso:    DocComponent
00574 
00575 ********************************************************************************************/
00576 
00577 BOOL PrintMarksComponent::EndExport(BaseCamelotFilter *pFilter, BOOL Success)
00578 {
00579     BOOL ok = TRUE;
00580 
00581 // WEBSTER - markn 14/2/97
00582 // No print records needed in Webster
00583 #ifndef WEBSTER
00584 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00585     if (pFilter == NULL)
00586     {
00587         ERROR3("PrintMarksComponent::EndExport filter is null!");
00588         return(ok);
00589     }
00590 
00591     if (!Success || pFilter->IsWebFilter()) // Don't export to web files, or if we have failed
00592         return(ok);
00593 
00594 
00595     // Find the Print mark manager and it's PrintMark cache
00596     PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager();
00597     if (pMarksMan == NULL)
00598         return(ok);
00599 
00600     // Export the list of marks
00601     DocPrintMark *pItem = DocMarks.GetFirstMark();
00602     while (ok && pItem != NULL)
00603     {
00604         // From our item, find the actual PrintMark definition in the PMM cache
00605         PrintMarkItem *pMarkItem = pMarksMan->PMMCache.FindMark(pItem->GetHandle());
00606         if (pMarkItem != NULL)
00607             ok = ExportPrintMark(pFilter, pMarkItem);
00608 
00609         pItem = DocMarks.GetNextMark(pItem);
00610     }
00611 #endif
00612 #endif // WEBSTER
00613     return ok;
00614 }
00615 
00616 
00617 
00618 /********************************************************************************************
00619 
00620 >   BOOL PrintMarksComponent::ExportPrintMark(BaseCamelotFilter *pFilter, PrintMarkItem *pMarkItem)
00621 
00622     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00623     Created:    26/8/96
00624 
00625     Inputs:     pFilter - the BaseCamelotFilter filter that is being used to export a file.
00626                 pMarkItem - The print mark to be exported
00627 
00628     Returns:    TRUE if export was successful
00629 
00630     Purpose:    To export a print mark
00631 
00632     Notes:      Print marks, if disabled, will not be exported. i.e. only needed data
00633                 is actually saved to the file.
00634 
00635                 Print marks are saved in 2 formats:
00636                     TAG_PRINTMARKDEFAULT - Default (built in) marks - a 1-byte record
00637                     indicates which mark to use by quoting its ID byte.
00638 
00639                     TAG_PRINTMARKCUSTOM - User (custom) marks - The record is zero length,
00640                     but is followed by a TAG_DOWN, a clipart tree, and a TAG_UP.
00641 
00642                     NOTE that custom marks are currently not handled.
00643 
00644 ********************************************************************************************/
00645 
00646 BOOL PrintMarksComponent::ExportPrintMark(BaseCamelotFilter *pFilter, PrintMarkItem *pMarkItem)
00647 {
00648     BOOL ok = TRUE;
00649 
00650     PORTNOTETRACE("print","PrintMarksComponent::ExportPrintMark - do nothing");
00651 #ifndef EXCLUDE_FROM_XARALX
00652     ERROR3IF(pFilter == NULL || pMarkItem == NULL, "Illegal NULL params");
00653 
00654     PrintMark *pMarkInfo = pMarkItem->GetPrintMark();
00655     if (pMarkInfo == NULL)
00656     {
00657         ERROR3("PrintMarkItem with no PrintMark");
00658         return(FALSE);
00659     }
00660 
00661     if (pMarkInfo->IsCustom())
00662     {
00663         // A custom mark consists of a PrintMarkCustom record, defining where the
00664         // mark goes, what it's called, etc, followed records for the clipart subtree
00665         CXaraFileRecord Rec(TAG_PRINTMARKCUSTOM, TAG_PRINTMARKCUSTOM_SIZE);
00666         if (ok) ok = Rec.Init();
00667 
00668         // Write out the print mark info
00669         //  Type (bitmap ID), menu text string, orientation, positions
00670         if (ok)  ok = Rec.WriteBYTE((BYTE) pMarkInfo->GetType());
00671         if (ok)  ok = Rec.WriteBYTE((BYTE) pMarkInfo->GetOrientation());
00672         
00673         if (ok)
00674         {
00675             MarkPosition *Pos = pMarkInfo->GetFirstPosition();
00676             while (ok && Pos != NULL)
00677             {
00678                 ok = Rec.WriteBYTE((BYTE) Pos->GetRegion());                    // Write the region
00679                 if (ok) ok = Rec.WriteBYTE(Pos->GetFormat().GetAsFlagByte());   // Write the format
00680 
00681                 Pos = pMarkInfo->GetNextPosition(Pos);
00682             }
00683 
00684             if (ok) ok = Rec.WriteBYTE(MarkRegion_FileFormatTerminator);        // Terminate the list
00685         }
00686 
00687         if (ok)  ok = Rec.WriteUnicode(pMarkInfo->GetMarkMenuText());           // Write the mark name
00688 
00689         // Finish off this record
00690         if (ok) pFilter->Write(&Rec);
00691 
00692 
00693         // OK, now write the print mark "clipart" subtree to the file...
00694         if (ok) ok = pFilter->WriteZeroSizedRecord(TAG_DOWN);
00695         
00696         // BLOCK
00697         {
00698             // Find the Glyph subtree. We could strip off the default attributes
00699             // that Mike keeps around, but they only add a tiny amount (100 bytes
00700             // or so) to the file, and save a lot of problems getting attribute-completeness
00701             // when reloading the mark.
00702             Node *GlyphRoot = pMarkItem->GetMarkGlyph();
00703             if (GlyphRoot == NULL)
00704             {
00705                 ERROR3("Custom printers mark with no glyph");
00706                 ok = FALSE;
00707             }
00708 
00709             if (ok) ok = pFilter->WriteNodes(GlyphRoot);
00710         }
00711         if (ok) ok = pFilter->WriteZeroSizedRecord(TAG_UP);
00712     }
00713     else
00714     {
00715         // --- Write the record
00716         CXaraFileRecord Rec(TAG_PRINTMARKDEFAULT, TAG_PRINTMARKDEFAULT_SIZE);
00717         if (ok) ok = Rec.Init();
00718 
00719         if (ok) ok = Rec.WriteBYTE(pMarkInfo->GetIDByte());
00720 
00721         // --- Finally, output the record
00722         if (ok)
00723             pFilter->Write(&Rec);
00724     }
00725 #endif
00726     return(ok);
00727 }
00728 
00729 
00730 
00731 /********************************************************************************************
00732 
00733 >   void PrintMarksComponent::ImportDefaultPrintMark(CXaraFileRecord* Rec)
00734 
00735     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00736     Created:    29/8/96
00737 
00738     Inputs:     Rec - The TAG_PRINTMARKDEFAULT print mark record to be imported
00739 
00740     Purpose:    To import a default print mark
00741 
00742 ********************************************************************************************/
00743 
00744 void PrintMarksComponent::ImportDefaultPrintMark(CXaraFileRecord* Rec)
00745 {
00746     PORTNOTETRACE("print","PrintMarksComponent::ExportPrintMark - do nothing");
00747 #ifndef EXCLUDE_FROM_XARALX
00748     ERROR3IF(Rec == NULL, "Illegal NULL params");
00749     BYTE ID = 0;
00750     BOOL ok = Rec->ReadBYTE(&ID);
00751 
00752     if (!ok)
00753         return;
00754 
00755     // Find the Print mark manager and it's PrintMark cache
00756     PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager();
00757     if (pMarksMan == NULL)
00758         return;
00759 
00760     // Search the PMMCache list for a PrintMark with the given ID byte
00761     UINT32 Handle = 0;
00762     BOOL Found = FALSE;
00763     PrintMarkItem *pItem = pMarksMan->PMMCache.GetFirstMark();
00764     while (pItem != NULL)
00765     {
00766         PrintMark *pMark = pItem->GetPrintMark();
00767         if (pMark != NULL && pMark->GetIDByte() == ID)
00768         {
00769             Handle = pItem->GetHandle();
00770             Found  = TRUE;
00771             break;
00772         }
00773 
00774         pItem = pMarksMan->PMMCache.GetNextMark(pItem);
00775     }
00776 
00777     // If we found a mark, then Handle is its PMM handle - Add an entry to our
00778     // list of Enabled marks.
00779     if (Found)
00780         AddMark(Handle);
00781 #endif
00782 }
00783 
00784 
00785 
00786 /********************************************************************************************
00787 
00788 >   void PrintMarksComponent::StartImportCustomPrintMark(CamelotRecordHandler *pHandler,
00789                                                             CXaraFileRecord* Rec)
00790     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00791     Created:    29/8/96
00792 
00793     Inputs:     pHandler - the record handler that called us
00794                 Rec - The TAG_PRINTMARKCUSTOM print mark record to be imported
00795     
00796     Purpose:    To start import of a custom print mark
00797                 This is called when a TAG_PRINTMARKCUSTOM is found in the importing file.
00798                 The tag is followed by a subtree (beginning with a NodeGroup).
00799 
00800                 We create a blank layer node, and point the importer at it, so that the
00801                 subtree imports where _we_ want it. When the final TAG_UP record of the
00802                 subtree is read, we will be clled back in EndImportCustomPrintMark to
00803                 complete the job.
00804 
00805     SeeAlso:    PrintMarksComponent::EndImportCustomPrintMark
00806 
00807 ********************************************************************************************/
00808 
00809 void PrintMarksComponent::StartImportCustomPrintMark(CamelotRecordHandler *pHandler, CXaraFileRecord* Rec)
00810 {
00811     PORTNOTETRACE("print","PrintMarksComponent::StartImportCustomPrintMark - do nothing");
00812 #ifndef EXCLUDE_FROM_XARALX
00813     ERROR3IF(CustomCurrentContext != NULL || CustomPreviousContext != NULL ||
00814                 pNewMark != NULL, "StartImportCustomPrintMark called while importing another custom mark?!");
00815 
00816     // Find the Print mark manager and it's PrintMark cache
00817     PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager();
00818     if (pMarksMan == NULL)
00819         return;
00820 
00821     // Create a PrintMark encapsulating all the data in this record
00822     pNewMark = new PrintMarkItem;
00823     if (!pNewMark)
00824         return;
00825 
00826     PrintMark *pMarkInfo = pNewMark->GetPrintMark();
00827     pMarkInfo->SetCustomOrDefault(TRUE);                                // This is a custom mark
00828 
00829 
00830     // --- Now read the print mark info
00831     BOOL ok = TRUE;
00832     BYTE Temp;
00833 
00834     if (ok)  ok = Rec->ReadBYTE(&Temp);
00835     if (ok)  pMarkInfo->SetType((MarkType) Temp);
00836 
00837     if (ok)  ok = Rec->ReadBYTE(&Temp);
00838     if (ok)  pMarkInfo->SetOrientation((MarkOrient) Temp);
00839     
00840     while (ok)                                                          // Read all format positions
00841     {
00842         ok = Rec->ReadBYTE(&Temp);
00843         if (ok)
00844         {
00845             if (Temp == (BYTE) MarkRegion_FileFormatTerminator)         // End of list - break out of loop
00846                 break;
00847 
00848             MarkPosition *NewPos = new MarkPosition;                    // New position
00849             if (NewPos == NULL)
00850                 ok = FALSE;
00851             else
00852             {
00853                 NewPos->Initialise();
00854                 NewPos->SetRegion((MarkRegion) Temp);                   // Set region from first byte
00855 
00856                 ok = Rec->ReadBYTE(&Temp);
00857                 if (ok)
00858                 {
00859                     MarkFormat NewFormat;
00860                     NewFormat.SetFromFlagByte(Temp);                    // Set format from second byte
00861 
00862                     NewPos->SetFormat(NewFormat);
00863 
00864                     pMarkInfo->AddNewPosition(NewPos);                  // And add to the mark's positions
00865                 }
00866                 else
00867                     delete NewPos;
00868             }
00869         }
00870     }
00871 
00872     String_256 MenuName;
00873     if (ok)  ok = Rec->ReadUnicode((TCHAR *)MenuName, 255);             // Read the mark name
00874     if (ok)  pMarkInfo->SetMarkMenuText(&MenuName);
00875 
00876     if (ok)
00877     {
00878         // --- Finally, prepare for import of the following clipart subtree
00879         // Remember the current import context node
00880         CustomPreviousContext = pHandler->GetInsertContextNode();
00881 
00882         // Create a layer and set up the import system to import the mark into it
00883         // If this fails, then it'll just find somewhere "sensible" to import into
00884         CustomCurrentContext  = new Layer;
00885         pHandler->SetInsertContextNode(CustomCurrentContext);
00886     }
00887 
00888     // And now sit back and wait for the End call...
00889 #endif
00890 }
00891 
00892 
00893 
00894 /********************************************************************************************
00895 
00896 >   void PrintMarksComponent::EndImportCustomPrintMark(CamelotRecordHandler *pHandler)
00897 
00898     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00899     Created:    29/8/96
00900 
00901     Inputs:     pHandler - the record handler that called us
00902 
00903     Purpose:    To end the import a custom print mark - see the SeeAlso for details.
00904 
00905     SeeAlso:    PrintMarksComponent::StartImportCustomPrintMark
00906 
00907 ********************************************************************************************/
00908 
00909 void PrintMarksComponent::EndImportCustomPrintMark(CamelotRecordHandler *pHandler)
00910 {
00911     PORTNOTETRACE("print","PrintMarksComponent::EndImportCustomPrintMark - do nothing");
00912 #ifndef EXCLUDE_FROM_XARALX
00913     ERROR3IF(CustomCurrentContext == NULL || pNewMark == NULL, "EndImportCustomPrintMark - StartImportCustomMark not called/failed");
00914 
00915     // Find the Print mark manager and it's PrintMark cache
00916     PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager();
00917     if (pMarksMan == NULL)
00918         return;
00919 
00920     // Restore the previous import context node
00921     pHandler->SetInsertContextNode(CustomPreviousContext);
00922 
00923     // Complete the mark and add it to the PMM cache
00924     NodeGroup *Glyph = (NodeGroup *)CustomCurrentContext->FindFirstChild();
00925     ERROR3IF(Glyph == NULL, "Import of custom mark subtree must have failed");
00926     if (Glyph != NULL)
00927     {
00928         ERROR3IF(!Glyph->IsKindOf(CC_RUNTIME_CLASS(NodeGroup)), "Imported print mark doesn't start with a group");
00929 
00930         Glyph->UnlinkNodeFromTree(NULL);
00931         UINT32 MarkHandle = pMarksMan->PMMCache.AddNewMark(pNewMark, Glyph);
00932 
00933         // Add a reference to the mark to ourself, so the mark is enabled
00934         AddMark(MarkHandle);
00935     }
00936     else
00937     {
00938         // Try not to leak too much!
00939         delete pNewMark;
00940     }
00941 
00942     // Tidy up
00943     pNewMark = NULL;
00944     CustomPreviousContext = NULL;
00945     delete CustomCurrentContext;
00946     CustomCurrentContext = NULL;
00947 #endif
00948 }
00949 

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