bmpcomp.cpp

Go to the documentation of this file.
00001 // $Id: bmpcomp.cpp 1708 2006-08-17 17:13:38Z 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 // Kernel level parts of bitmap lists
00100 
00101 /*
00102 */
00103 
00104 #include "camtypes.h"
00105 #include "bmpcomp.h"
00106 //#include "bmplist.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "bitmap.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 #include "bitmpinf.h"
00109 #include "bmpsrc.h"
00110 #include "ccbuffil.h"
00111 //#include "list.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00114 //#include "fillattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 //#include "will.h"
00116 #include "nativeps.h"       // The old style EPS native filter, used in v1.1
00117 
00118 #include "clipint.h"
00119 #include "nodebmp.h"
00120 //#include "progress.h"
00121 
00122 #include "toollist.h"
00123 #include "objchge.h"
00124 #include "csrstack.h"
00125 
00126 #include "clipint.h"
00127 #include "ophist.h"
00128 #include "sgliboil.h"
00129 //#include "will2.h"
00130 
00131 #include "expbmp.h"     // ExportedBitmaps handling class
00132 #include "impbmp.h"     // ImportedBitmaps handling class
00133 //#include "camfiltr.h" // BaseCamelotFilter - version 2 native filter - in camtypes.h [AUTOMATICALLY REMOVED]
00134 #include "cxftags.h"    // TAG_DEFINEBITMAP_****
00135 #include "cxfile.h"     // CXF_UNKNOWN_SIZE
00136 //#include "cxfrech.h"  // CXaraFileRecordHandler - in camtypes.h [AUTOMATICALLY REMOVED]
00137 #include "expcol.h"     // ExportedColours handling class
00138 //#include "cxfrec.h"       // CXaraFileRecord handler - in camtypes.h [AUTOMATICALLY REMOVED]
00139 //#include "tim.h"      // _R(IDT_CANT_FIND_FILTER)
00140 //#include "filtrres.h" // _R(IDS_DONT_SUPPORT_BITMAP_TYPE) _R(IDS_NATIVE_BITMAPWARNING)
00141 #include "bitfilt.h"    // BaseBitmapFlter
00142 //#include "fixmem.h"       // CCMalloc, CCFree - in camtypes.h [AUTOMATICALLY REMOVED]
00143 
00144 CC_IMPLEMENT_MEMDUMP( BitmapList, List )
00145 CC_IMPLEMENT_DYNAMIC( BitmapListComponentClass, DocComponentClass )
00146 CC_IMPLEMENT_DYNAMIC( BitmapListComponent, DocComponent )
00147 
00148 // Declare smart memory handling in Debug builds
00149 #define new CAM_DEBUG_NEW
00150 
00151 /**********************************************************************************************
00152 
00153 >   BitmapList::BitmapList()
00154 
00155     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00156     Created:    12/12/94
00157     Inputs:     -
00158     Outputs:    -
00159     Returns:    -
00160     Purpose:    BitmapList constructor
00161 
00162 **********************************************************************************************/
00163 
00164 BitmapList::BitmapList()
00165 {
00166     ParentDoc = NULL;               // Document containing this list
00167 }
00168 
00169 /**********************************************************************************************
00170 
00171 >   BitmapList::~BitmapList()
00172 
00173     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00174     Created:    12/12/94
00175     Inputs:     -
00176     Outputs:    -
00177     Returns:    -
00178     Purpose:    BitmapList destructor
00179 
00180 **********************************************************************************************/
00181 
00182 BitmapList::~BitmapList()
00183 {
00184     ListItem* pItem = GetHead();
00185     ListItem* pNextItem;
00186 
00187     while (pItem)
00188     {
00189         pNextItem = GetNext(pItem);
00190 
00191         KernelBitmap* pBmp = (KernelBitmap*)pItem;
00192 
00193         ERROR3IF(pBmp->GetParentBitmapList() != this, "Bad ParentList ptr found in bitmap (during BitmapList destructor)");
00194         
00195         // if this bitmap is used by a brush we don't want to delete it here.
00196         if (!pBmp->IsUsedByBrush())
00197             delete pBmp;    // This should remove it from the list first
00198         else
00199         {
00200             pBmp->Detach();
00201             RemoveItem(pBmp);
00202         }
00203 
00204         pItem = pNextItem;
00205     }
00206 
00207     // Tidy up the global bitmap list
00208     Camelot.GetGlobalBitmapList()->DeleteAllUnusedBitmaps();
00209 }
00210 
00211 /**********************************************************************************************
00212 
00213 >   void BitmapList::Init(BaseDocument *ParentDocument)
00214 
00215     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00216     Created:    12/12/94
00217     Inputs:     ParentDocument - the parent document of this Bitmap list
00218     Purpose:    BitmapList initialiser. MUST be called after constructing a BitmapList
00219                 in order to correctly initialise it. Note that if ParentDocument is not
00220                 set to a useful value, some operations on Bitmap lists will fail.
00221 
00222 **********************************************************************************************/
00223 
00224 void BitmapList::Init(BaseDocument *ParentDocument)
00225 {
00226     ERROR3IF(ParentDocument == NULL, "NULL ParentDoc in BitmapList::Init!\n");
00227 
00228     // Ensure the default bitmap is always in the list.
00229     KernelBitmap* Default = new KernelBitmap();
00230     Default->Attach(this);
00231 
00232     ParentDoc = ParentDocument;
00233 }
00234 
00235 /**********************************************************************************************
00236 
00237 >   BOOL BitmapList::AddItem(KernelBitmap *Item)
00238 
00239     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00240     Created:    12/12/94
00241     Returns:    TRUE
00242     Purpose:    Adds an item to the tail of the Bitmaplist, and incremeants it's usage count.
00243                 (Unless it's already in the list, in which case it's usage count is just
00244                 bumped up).
00245 
00246 **********************************************************************************************/
00247 
00248 BOOL BitmapList::AddItem(KernelBitmap *Item)
00249 {
00250     ERROR3IF(Item == NULL, "Trying to add NULL item to Bitmap List");
00251     
00252     if (Item == NULL)
00253         return FALSE;
00254 
00255     // Is this Bitmap already in the list ?
00256     LISTPOS pos = FindPosition((ListItem*)Item);
00257 
00258     if (pos == NOT_IN_LIST || pos == EMPTY_LIST)
00259     {
00260         // It's not in the list yet, so add it on the end
00261         AddTail((ListItem*)Item);
00262 
00263         if (ParentDoc != NULL)
00264         {
00265             BROADCAST_TO_ALL(BitmapListChangedMsg(this)); 
00266         }
00267 
00268         return TRUE;
00269     }
00270     else
00271     {
00272         // It's already in the list, so just return
00273         // (It's usage count has already been incremeanted)
00274         return FALSE;
00275     }
00276 }
00277 
00278 /**********************************************************************************************
00279 
00280 >   BOOL BitmapList::RemoveItem(KernelBitmap *Item)
00281 
00282     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00283     Created:    12/12/94
00284     Returns:    TRUE
00285     Purpose:    Removes an item from the list.
00286 
00287 **********************************************************************************************/
00288 
00289 BOOL BitmapList::RemoveItem(KernelBitmap *Item)
00290 {
00291     ERROR3IF(Item == NULL, "Trying to remove NULL item from Bitmap List");
00292     
00293     if (Item == NULL)
00294         return FALSE;
00295 
00296     // Is this Bitmap in the list ?
00297     LISTPOS pos = FindPosition((ListItem*)Item);
00298 
00299     if (pos != NOT_IN_LIST || pos == EMPTY_LIST)
00300     {
00301         // It's not in the list yet, so add it on the end
00302         List::RemoveItem((ListItem*)Item);
00303         Item->m_pParentList = NULL;
00304 
00305         if (ParentDoc != NULL)
00306         {
00307             BROADCAST_TO_ALL(BitmapListChangedMsg(this)); 
00308         }
00309 
00310         return TRUE;
00311     }
00312     else
00313     {
00314         // It's not in the list, so just return
00315         return FALSE;
00316     }
00317 }
00318 
00319 /**********************************************************************************************
00320 
00321 >   BOOL BitmapList::MoveBefore(KernelBitmap *InsertPoint, KernelBitmap *ItemToMove)
00322 
00323     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00324     Created:    12/12/94
00325     Returns:    TRUE
00326     Purpose:    Re-arranges the bitmaps in the list.
00327 
00328 **********************************************************************************************/
00329 
00330 BOOL BitmapList::MoveBefore(KernelBitmap *InsertPoint, KernelBitmap *ItemToMove)
00331 {
00332     List::RemoveItem((ListItem*)ItemToMove);
00333     List::InsertBefore((ListItem*)InsertPoint, (ListItem*)ItemToMove);
00334 
00335     if (ParentDoc != NULL)
00336     {
00337         BROADCAST_TO_ALL(BitmapListChangedMsg(this)); 
00338     }
00339 
00340     return TRUE;
00341 }
00342 
00343 /**********************************************************************************************
00344 
00345 >   BOOL BitmapList::MoveAfter(KernelBitmap *InsertPoint, KernelBitmap *ItemToMove)
00346 
00347     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00348     Created:    12/12/94
00349     Returns:    TRUE
00350     Purpose:    Re-arranges the bitmaps in the list.
00351 
00352 **********************************************************************************************/
00353 
00354 BOOL BitmapList::MoveAfter(KernelBitmap *InsertPoint, KernelBitmap *ItemToMove)
00355 {
00356     List::RemoveItem((ListItem*)ItemToMove);
00357     List::InsertAfter((ListItem*)InsertPoint, (ListItem*)ItemToMove);
00358 
00359     if (ParentDoc != NULL)
00360     {
00361         BROADCAST_TO_ALL(BitmapListChangedMsg(this)); 
00362     }
00363 
00364     return TRUE;
00365 }
00366 
00367 /**********************************************************************************************
00368 
00369 >   BaseDocument *BitmapList::GetParentDocument(void)
00370 
00371     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00372     Created:    12/12/94
00373     Returns:    The document in which this Bitmap list resides
00374     Purpose:    To find the parent document of this Bitmap list
00375 
00376 **********************************************************************************************/
00377 
00378 BaseDocument *BitmapList::GetParentDocument(void)
00379 {
00380     ERROR3IF(ParentDoc == NULL, "Uninitialised BitmapList detected!");
00381     return(ParentDoc);
00382 }
00383 
00384 /**********************************************************************************************
00385 
00386 >   KernelBitmap* BitmapList::FindDuplicateBitmap(OILBitmap* pBitmap)
00387 
00388     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00389     Created:    14/8/96
00390     Purpose:    Looks to see if an identical bitmap is already in the bitmap list
00391 
00392 **********************************************************************************************/
00393 
00394 KernelBitmap* BitmapList::FindDuplicateBitmap(OILBitmap* pOILBitmap)
00395 {
00396     ListItem* pItem = GetHead();
00397     while (pItem != NULL)
00398     {
00399         KernelBitmap* pBmp = (KernelBitmap*)pItem;
00400 
00401         if (pBmp->ActualBitmap &&
00402             pBmp->ActualBitmap != pOILBitmap &&
00403             *pBmp->ActualBitmap == *pOILBitmap)
00404         {
00405             return pBmp;
00406         }
00407 
00408         pItem = GetNext(pItem);
00409     }
00410 
00411     return NULL;
00412 }
00413 
00414 /**********************************************************************************************
00415 
00416 >   KernelBitmap* BitmapList::FindDefaultBitmap()
00417 
00418     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00419     Created:    10/8/96
00420     Purpose:    Finds the default bitmap in this bitmap list
00421 
00422 **********************************************************************************************/
00423 
00424 KernelBitmap* BitmapList::FindDefaultBitmap()
00425 {
00426     ListItem* pItem = GetHead();
00427     while (pItem != NULL)
00428     {
00429         KernelBitmap* pBmp = (KernelBitmap*)pItem;
00430 
00431         if (pBmp->ActualBitmap &&
00432             pBmp->ActualBitmap == OILBitmap::Default)
00433         {
00434             return pBmp;
00435         }
00436 
00437         pItem = GetNext(pItem);
00438     }
00439 
00440     return NULL;
00441 }
00442 
00443 
00444 /********************************************************************************************
00445 
00446 >   BOOL BitmapListComponentClass::Init()
00447 
00448     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00449     Created:    12/12/94
00450     Returns:    TRUE if all went well;
00451                 FALSE if not.
00452     Purpose:    Register the Bitmap list document component with the main application.
00453     Errors:     Out of memory.
00454     SeeAlso:    DocComponent
00455 
00456 ********************************************************************************************/
00457 
00458 BOOL BitmapListComponentClass::Init()
00459 {
00460     // Instantiate a component class to register with the application.
00461     BitmapListComponentClass *pClass = new BitmapListComponentClass;
00462     if (pClass == NULL)
00463         return FALSE;
00464 
00465     // Register it
00466     GetApplication()->RegisterDocComponent(pClass);
00467 
00468     // All ok
00469     return TRUE;
00470 }
00471 
00472 
00473 /********************************************************************************************
00474 
00475 >   BOOL BitmapListComponentClass::AddComponent(BaseDocument *pDocument)
00476 
00477     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00478     Created:    12/12/94
00479     Inputs:     pDocument - the document to add the Bitmap list to.
00480     Returns:    TRUE if the Bitmap list was added ok;
00481                 FALSE if not.
00482     Purpose:    Add a Bitmap list component to the specified document.
00483     Errors:     Out of memory
00484     SeeAlso:    BitmapListComponentClass
00485 
00486 ********************************************************************************************/
00487 
00488 BOOL BitmapListComponentClass::AddComponent(BaseDocument *pDocument)
00489 {
00490     // Check to see if this document already has a Bitmap list; if so, leave it alone.
00491     if (pDocument->GetDocComponent(CC_RUNTIME_CLASS(BitmapListComponent)) != NULL)
00492         return TRUE;
00493 
00494     // No Bitmap list - try to create a new one for this document.
00495     BitmapList *pList = new BitmapList;
00496     if(pList == NULL)
00497         return FALSE;
00498 
00499     pList->Init(pDocument);     // Let the BitmapList know what its parent document is
00500 
00501     // Ok - create the Bitmap list component using this list.
00502     BitmapListComponent *pComponent = new BitmapListComponent(pList);
00503     if (pComponent == NULL)
00504     {
00505         // Out of memory...
00506         delete pList;
00507         return FALSE;
00508     }
00509 
00510     // All ok - add the component to the document.
00511     pDocument->AddDocComponent(pComponent);
00512     return TRUE;
00513 }
00514 
00515 
00516 
00517 /********************************************************************************************
00518 
00519 >   BitmapListComponent::BitmapListComponent()
00520 
00521     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00522     Created:    12/12/94
00523     Purpose:    Construct a Bitmap list component. DO NOT use this constructor. It gives
00524                 and ERROR3 (and sets up this in a semi-safe default state)
00525     SeeAlso:    BitmapListComponent
00526 
00527 ********************************************************************************************/
00528 
00529 BitmapListComponent::BitmapListComponent()
00530 {
00531     ERROR3("BitmapListComponent constructed with default constructor!?\n");
00532 }
00533 
00534 
00535 
00536 /********************************************************************************************
00537 
00538 >   BitmapListComponent::BitmapListComponent(BitmapList *pBmpList)
00539 
00540     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00541     Created:    12/12/94
00542     Inputs:     pColList - the Bitmap list to use for this Bitmap list componet.
00543     Purpose:    Construct a Bitmap list component using the given Bitmap list.
00544     Errors:     ENSURE if pColList is NULL.
00545     SeeAlso:    BitmapListComponent
00546 
00547 ********************************************************************************************/
00548 
00549 BitmapListComponent::BitmapListComponent(BitmapList *pBmpList)
00550 {
00551     ENSURE(pBmpList != NULL, "NULL Bitmap list in Bitmap list component constructor!");
00552 
00553     // Install this Bitmap list.
00554     pBitmaps = pBmpList;
00555 
00556     // Initialise Exporter bitmap list
00557     pExportedBitmaps = NULL;
00558 
00559     // Initialise Importer bitmap list
00560     pImportedBitmaps = NULL;
00561 
00562     // Our link to the BaseCamelotFilter
00563     pCamFilter = NULL;
00564     // Set our variable so that we warn about a possible replacement only once
00565     WarnedBefore = FALSE;
00566 
00567     // Initialise Exporter bitmap list (used for EPS only)
00568     pBitmapsToExport = NULL;
00569 }
00570 
00571 /********************************************************************************************
00572 
00573 >   BitmapListComponent::~BitmapListComponent()
00574 
00575     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00576     Created:    12/12/94
00577     Purpose:    Clean up a Bitmap list component's data structures - deletes the Bitmap
00578                 list.
00579     Errors:     -
00580     SeeAlso:    BitmapListComponent
00581 
00582 ********************************************************************************************/
00583 
00584 BitmapListComponent::~BitmapListComponent()
00585 {
00586     // Delete our Bitmap list.
00587     delete pBitmaps;
00588 
00589     // As we have finished with it now, destroy the list of imported bitmaps
00590     if (pImportedBitmaps)
00591     {
00592         delete pImportedBitmaps;
00593         pImportedBitmaps = NULL;
00594     }
00595 
00596     // As we have finished with it now, destroy the list of exported bitmaps
00597     if (pExportedBitmaps)
00598     {
00599         delete pExportedBitmaps;
00600         pExportedBitmaps = NULL;
00601     }
00602 
00603     if (pBitmapsToExport)
00604     {
00605         delete pBitmapsToExport;
00606         pBitmapsToExport = NULL;
00607     }
00608 }
00609 
00610 
00611 
00612 /********************************************************************************************
00613 
00614 >   BOOL BitmapListComponent::EPSStartImport(EPSFilter *pFilter)
00615 
00616     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00617     Created:    12/12/94
00618     Inputs:     pFilter - the EPS filter that is being used to import a file.
00619     Purpose:    Inform the Bitmap list document component that an EPS import is about to 
00620                 start.
00621     SeeAlso:    DocComponent
00622 
00623 ********************************************************************************************/
00624 
00625 BOOL BitmapListComponent::EPSStartImport(EPSFilter *pFilter)
00626 {
00627     return FALSE;
00628 }
00629 
00630 /********************************************************************************************
00631 
00632 >   void BitmapListComponent::EPSEndImport(EPSFilter *pFilter, BOOL Success)
00633 
00634     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00635     Created:    12/12/94
00636     Inputs:     pFilter - the EPS filter that is being used to import a file.
00637                 Success - TRUE => The import was successful;
00638                          FALSE => The import failed - abandon any changes.
00639     Purpose:    Inform the Bitmap list document component that an EPS import has just 
00640                 finished.
00641     SeeAlso:    DocComponent
00642 
00643 ********************************************************************************************/
00644 
00645 void BitmapListComponent::EPSEndImport(EPSFilter *pFilter, BOOL Success)
00646 {
00647 }
00648 
00649 /********************************************************************************************
00650 
00651 >   BOOL BitmapListComponent::EPSStartExport(EPSFilter *pFilter)
00652 
00653     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00654     Created:    12/12/94
00655     Inputs:     pFilter - the EPS filter that is being used to import a file.
00656     Purpose:    Inform the Bitmap list document component that an EPS export is about to 
00657                 start.
00658     SeeAlso:    DocComponent
00659 
00660 ********************************************************************************************/
00661 
00662 BOOL BitmapListComponent::EPSStartExport(EPSFilter *pFilter)
00663 {
00664 #ifdef DO_EXPORT
00665     ERROR3IF(pBitmapsToExport != NULL, "Why is there an export bitmap list already ?");
00666     
00667     // Build the list of bitmaps to export here ...
00668     pBitmapsToExport = new ExportedBitmaps();
00669 
00670     ERROR3IF(pBitmapsToExport == NULL, "Couldn't create bitmap export list !!");
00671     if (pBitmapsToExport == NULL)
00672         return FALSE;
00673 
00674     Document* ParentDoc = (Document*)pBitmaps->GetParentDocument();
00675     ERROR3IF(ParentDoc == NULL, "Bitmap list has no parent document !!");
00676     if (ParentDoc == NULL)
00677     {
00678         delete pBitmapsToExport;
00679         pBitmapsToExport = NULL;
00680         return FALSE;
00681     }
00682 
00683     UINT32 BitmapNumber = 0;
00684 
00685     // Scan the document's tree for bitmap references
00686     Node* pNode = Node::DocFindFirstDepthFirst(ParentDoc);
00687     while (pNode != NULL)
00688     {
00689         // Ignore hidden nodes
00690         if (!pNode->IsNodeHidden())
00691         {
00692             INT32 Count = 0;
00693 
00694             // Does this node have any bitmaps in it ?
00695             KernelBitmap* pBitmap = pNode->EnumerateBitmaps(Count++);
00696 
00697             while (pBitmap != NULL)
00698             {
00699                 // Check for a deleted bitmap
00700                 if (pBitmap->HasBeenDeleted())
00701                 {
00702                     ERROR2IF(pBitmap->GetParentBitmapList() == NULL, 0L, "Deleted bitmap has no parent list");
00703                     
00704                     // Use the default bitmap instead
00705                     pBitmap = pBitmap->GetParentBitmapList()->FindDefaultBitmap();
00706 
00707                     // There should always be a default bitmap at the start of the list
00708                     ERROR2IF(pBitmap == NULL, 0L, "Couldn't find the default bitmap");
00709                 }
00710 
00711                 // Found a bitmap reference, so ...
00712                 // .. if this bitmap is not in the export list, add it
00713                 if (pBitmapsToExport->GetBitmap(pBitmap) == NULL)
00714                     pBitmapsToExport->AddBitmap(pBitmap, BitmapNumber++);
00715                 
00716                 pBitmap = pNode->EnumerateBitmaps(Count++);             
00717             }
00718         }
00719 
00720         // Move onto the next node in the tree
00721         pNode = pNode->DocFindNextDepthFirst(); 
00722     }
00723 #endif
00724     return TRUE;
00725 }
00726 
00727 /********************************************************************************************
00728 
00729 >   void BitmapListComponent::EPSEndExport(EPSFilter *pFilter, BOOL Success)
00730 
00731     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00732     Created:    12/12/94
00733     Inputs:     pFilter - the EPS filter that is being used to import a file.
00734                 Success - TRUE => The import was successful;
00735                          FALSE => The import failed - abandon any changes.
00736     Purpose:    Inform the Bitmap list document component that an EPS export has just 
00737                 finished.
00738     SeeAlso:    DocComponent
00739 
00740 ********************************************************************************************/
00741 
00742 void BitmapListComponent::EPSEndExport(EPSFilter *pFilter)
00743 {
00744 #ifdef DO_EXPORT
00745     if (pBitmapsToExport)
00746     {
00747         delete pBitmapsToExport;
00748         pBitmapsToExport = NULL;
00749     }
00750 #endif
00751 }
00752 
00753 /********************************************************************************************
00754 
00755 >   BOOL BitmapListComponent::WriteEPSComments(EPSFilter *pFilter)
00756 
00757     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00758     Created:    12/12/94
00759     Inputs:     pFilter - the filter being used to import the EPS file.
00760     Returns:    TRUE if the Bitmap table was written successfully;
00761                 FALSE if not.
00762     Purpose:    Writes out the Bitmap table in the form of EPS comments in the 'header'
00763                 comments of the EPS file.
00764     Errors:     Out of disk space, and similar disk errors.
00765     SeeAlso:    DocComponent::WriteEPSComments;
00766                 DocComponent
00767 
00768 ********************************************************************************************/
00769 
00770 BOOL BitmapListComponent::WriteEPSComments(EPSFilter *pFilter)
00771 {
00772     return TRUE;
00773 }
00774 
00775 
00776 /********************************************************************************************
00777 
00778 >   BOOL BitmapListComponent::WriteScript(EPSFilter* pFilter)
00779 
00780     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00781     Created:    18/1/95
00782     Inputs:     pFilter - the EPS filter that is being used to export a file.
00783     Returns:    TRUE if the Script for this component was written out successfully;
00784                 FALSE if not (e.g. out of disk space etc)
00785     Purpose:    This is called after all the Comments, Prolog etc have been output so that
00786                 DocComponents get a chance to do something right at the start of the real
00787                 EPS data, but before the tree starts to be exported.
00788                 (The base class does nothing)
00789     SeeAlso:    DocComponent::WriteEPSSetup; 
00790                 DocComponent::WriteEPSProlog;
00791                 DocComponent::ProcessEPSComment; 
00792                 DocComponent; 
00793                 EPSFIlter
00794 
00795 ********************************************************************************************/
00796 
00797 BOOL BitmapListComponent::WriteScript(EPSFilter* pFilter)
00798 {
00799 #ifdef DO_EXPORT
00800     // This only happens in Native EPS
00801     if (pFilter->IS_KIND_OF(CamelotNativeEPSFilter))
00802     {
00803         // Find out the context to save to
00804         EPSExportDC *pDC = pFilter->GetExportDC();
00805 
00806         // Make sure that there's a bitmap list to export.
00807         if (pBitmapsToExport == NULL)
00808         {
00809             ERROR3 ( "Why isn't there an export bitmap list (in WriteScript) ?" );
00810             return FALSE;
00811         }
00812 
00813         // Something to mark the start of the bitmap pool
00814         pDC->OutputToken(_T("%%BeginCamelotBitmapPool"));
00815         pDC->OutputNewLine();
00816 
00817         // Tell the filter we are starting to save the bitmap pool
00818         ((CamelotNativeEPSFilter*)pFilter)->IsSavingBitmapPool = TRUE;
00819 
00820         // Find the number of Bitmaps
00821         INT32 TotalBitmaps = pBitmapsToExport->GetCount();
00822 
00823         // Output a comment saying how many bitmaps we have
00824         pDC->OutputToken(_T("%%BitmapPoolCount"));
00825         pDC->OutputValue(TotalBitmaps);
00826         pDC->OutputNewLine();
00827 
00828         INT32 BitmapNum = 0;
00829 
00830         // Find the first bitmap in the list again
00831         ExportBitmap* pExportBitmap = pBitmapsToExport->EnumerateBitmaps();
00832 
00833         while (pExportBitmap != NULL)
00834         {
00835             ERROR3IF(pExportBitmap->RecordNumber != BitmapNum, "Bad bitmap number found when saving bitmap pool");
00836                 
00837             // Save the bitmap out
00838             ExportBitmapPoolItem(BitmapNum, pFilter, pDC, pExportBitmap->pBmp);
00839 
00840             BitmapNum++;
00841 
00842             // Find the next one
00843             pExportBitmap = pBitmapsToExport->EnumerateBitmaps(pExportBitmap);
00844         }
00845 
00846         // Tell the filter we are starting to save the bitmap pool
00847         ((CamelotNativeEPSFilter*)pFilter)->IsSavingBitmapPool = FALSE;
00848 
00849         // Something to mark the start of the bitmap pool
00850         pDC->OutputToken(_T("%%EndCamelotBitmapPool"));
00851         pDC->OutputNewLine();
00852     }
00853 
00854 #endif
00855     return TRUE;
00856 }
00857 
00858 
00859 
00860 /********************************************************************************************
00861 
00862 >   BOOL BitmapListComponent::ExportBitmapPoolItem(INT32 BitmapNum, EPSFilter* pFilter,
00863                                                    EPSExportDC* pDC, KernelBitmap* pBitmap)
00864 
00865     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00866     Created:    19/1/95
00867     Inputs:     BitmapNum - The number of the Kernel bitmap in the pool
00868                 pFilter - The filter that things are being saved in
00869                 pDC - The DC that the saving is happening in
00870                 pBitmap - The Kernel Bitmap to be saved
00871     Returns:    TRUE if it worked, FALSE if not
00872     Purpose:    Does the actual saving for a bitmap pool item. This uses the cbmp token to
00873                 represent the Camelot BitMap Pool object.
00874 
00875 ********************************************************************************************/
00876 
00877 BOOL BitmapListComponent::ExportBitmapPoolItem(INT32 BitmapNum, EPSFilter* pFilter, EPSExportDC* pDC, KernelBitmap* pBitmap)
00878 {
00879 #ifdef DO_EXPORT
00880     ERROR2IF(pBitmap->HasBeenDeleted(), FALSE, "Trying to export a deleted bitmap");
00881     
00882     if (pFilter->IS_KIND_OF(CamelotNativeEPSFilter))
00883     {
00884         // ...then the bitmap object token.
00885         pDC->OutputValue(BitmapNum);            // Output the number of the bitmap
00886         pDC->OutputValue(INT32(0));             // Bitmap pool type (ready for expansion)
00887         pDC->OutputToken(_T("cbmp"));               // Bitmap pool token
00888         pDC->OutputNewLine();
00889         
00890         // ...and then the bitmap data itself.
00891         pFilter->ExportBitmap(*pBitmap);
00892 
00893         // Tell caller we rendered ourselves ok
00894         return TRUE;
00895     }
00896 #endif
00897     return FALSE;
00898 }
00899 
00900 
00901 /********************************************************************************************
00902 
00903 >   ProcessEPSResult BitmapListComponent::ProcessEPSComment(EPSFilter *pFilter, 
00904                                                             const char *pComment)
00905 
00906     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00907     Created:    12/12/94
00908     Inputs:     pFilter - the EPS filter that is being used to import a file.
00909                 pComment - pointer to the comment to process.
00910     Returns:    EPSCommentUnknown    - This EPS comment is not recognised by the document
00911                                        component.
00912                 EPSCommentError      - This EPS comment was recognised by this document
00913                                        component, but it contained an error.
00914                 EPSCommentOK         - This EPS comment was recognised as a legal comment by 
00915                                        this document component, and was processed
00916                                        successfully.
00917     Purpose:    Process an EPS comment - if this is a Bitmap table comment, this component
00918                 will claim it and try to decode it.
00919     Errors:     Badly formed EPS comment.
00920     SeeAlso:    DocComponent::ProcessEPSComment
00921 
00922 ********************************************************************************************/
00923 
00924 ProcessEPSResult BitmapListComponent::ProcessEPSComment(EPSFilter *pFilter, 
00925                                                         const char *pComment)
00926 {
00927     // Ignore all comments
00928     return EPSCommentUnknown;
00929 }
00930 
00931 
00932 
00933 
00934 /********************************************************************************************
00935 
00936 >   void BitmapListComponent::EndOfEPSComment(EPSFilter *pFilter)
00937 
00938     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00939     Created:    12/12/94
00940     Inputs:     pFilter - the EPS filter that is being used to import a file.
00941     Purpose:    Informs the document component that the comment it has been decoding has
00942                 now finished, and it should take whatever action required to act on
00943                 the comment.
00944     SeeAlso:    DocComponent::EndOfPESComment
00945 
00946 ********************************************************************************************/
00947 
00948 void BitmapListComponent::EndOfEPSComment(EPSFilter *pFilter)
00949 {
00950     // Do any cleanup we need to here after loading in a Bitmap table...
00951 }
00952 
00953 
00954 
00955 /********************************************************************************************
00956 
00957 >   INT32 BitmapListComponent::GetSizeOfExport(Filter *pFilter)
00958 
00959     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00960     Created:    27/01/95
00961     Inputs:     pFilter - the export filter that will be used.
00962     Returns:    An approximation of the size of data that will be exported by this
00963                 bitmap list, in terms of nodes. (see NodeRenderable::GetSizeOfExport).
00964     Purpose:    Find out how many nodes will be exported when this bitmap list is exported.
00965                 The node can use the filter to find out how it will be exported, e.g.
00966                 bitmap lists should return a value that reflects whether or not bitmap
00967                 indirection is possible with this filter and so on.
00968                 NB. This is virtual - the default implementation just returns 1 - only
00969                     override if this is not accurate.
00970     SeeAlso:    Node::NeedsToExport; Node::ExportRender; NodeRenderable::GetSizeOfExport
00971 
00972 ********************************************************************************************/
00973 
00974 INT32 BitmapListComponent::GetSizeOfExport(Filter *pFilter)
00975 {
00976 #ifdef DO_EXPORT
00977     // Check if this filter supports bitmap pools
00978     if (pFilter->GetBitmapSupportLevel() != IndirectedBitmapSupport)
00979         // No - just return 1.
00980         return 1;
00981 
00982     ERROR3IF(pBitmapsToExport == NULL, "Why isn't there an export bitmap list (in GetSizeOfExport) ?");
00983     if (pBitmapsToExport == NULL)
00984         return 1;
00985 
00986     INT32 TotalScanlines = 0;
00987 
00988     // Find the first bitmap in the list again
00989     ExportBitmap* pExportBitmap = pBitmapsToExport->EnumerateBitmaps();
00990 
00991     while (pExportBitmap != NULL)
00992     {
00993         KernelBitmap* pBitmap = pExportBitmap->pBmp;
00994 
00995         // Get information on this bitmap.
00996         BitmapInfo Info;
00997         if (!pBitmap->ActualBitmap->GetInfo(&Info))
00998             // Failed for some reason - bodge the answer.
00999             return 1;
01000 
01001         // Add the number of scanlines to our total
01002         TotalScanlines += Info.PixelHeight;
01003 
01004         // Find the next one
01005         pExportBitmap = pBitmapsToExport->EnumerateBitmaps(pExportBitmap);
01006     }
01007     
01008     // Return size to caller.
01009     if (TotalScanlines == 0)
01010         return 1;
01011     else
01012         return TotalScanlines;
01013 #else
01014     return 0;
01015 #endif
01016 }
01017 
01018 
01019 
01020 /********************************************************************************************
01021 
01022 >   virtual BOOL BitmapListComponent::StartComponentCopy();
01023 
01024     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01025     Created:    12/12/94
01026     Inputs:     -
01027     Outputs:    -
01028     Returns:    TRUE if it succeeded. FALSE if the copy must be aborted
01029     Purpose:    This function gets called to prepare for a copy of Bitmaps into
01030                 the document. It sets up the various arrays and other thangs which the
01031                 Bitmap copy will need.
01032     Errors:     ENSURE failure if called when a component copy is already under way.
01033                 Errors will be reported if memory is unavailable
01034     SeeAlso:    BitmapListComponent::EndComponentCopy;
01035                 BitmapListComponent::AbortComponentCopy;
01036                 BitmapListComponent::CopyBitmapAcross
01037 
01038 ********************************************************************************************/
01039 
01040 BOOL BitmapListComponent::StartComponentCopy()
01041 {
01042     return(TRUE);
01043 }
01044 
01045 
01046 
01047 /********************************************************************************************
01048 
01049 >   virtual BOOL BitmapListComponent::EndComponentCopy();
01050 
01051     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01052     Created:    12/12/94
01053     Inputs:     -
01054     Outputs:    -
01055     Returns:    TRUE if it succeeded
01056     Purpose:    Will commit all changes made by doing the component copy, returning TRUE.
01057     Errors:     -
01058     Notes:      May be called multiple times - subsequent calls will be ignored
01059 
01060     SeeAlso:    BitmapListComponent::StartComponentCopy;
01061                 BitmapListComponent::AbortComponentCopy;
01062                 BitmapListComponent::CopyBitmapAcross
01063 
01064 ********************************************************************************************/
01065 
01066 BOOL BitmapListComponent::EndComponentCopy()
01067 {
01068     return(TRUE);
01069 }
01070 
01071 
01072 /********************************************************************************************
01073 
01074 >   virtual void BitmapListComponent::AbortComponentCopy();
01075 
01076     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01077     Created:    12/12/94
01078     Inputs:     -
01079     Outputs:    -
01080     Returns:    -
01081     Purpose:    Will abort all changes made for component copies.
01082                 This means that things such as the Bitmaps referenced by the nodes
01083                 you have just copied do not exist, so you must clean up to the state
01084                 the document was in before you strated copying.
01085     Errors:     -
01086     Notes:      May be called even if StartComponentCopy has not been called.
01087                 May be called multiple times
01088     SeeAlso:    BitmapListComponent::EndComponentCopy;
01089                 BitmapListComponent::AbortComponentCopy;
01090                 BitmapListComponent::CopyBitmapAcross
01091 
01092 ********************************************************************************************/
01093 
01094 void BitmapListComponent::AbortComponentCopy()
01095 {
01096 }
01097 
01098 
01099 /********************************************************************************************
01100 ********************************************************************************************/
01101 
01102 // Remove the following code on all builds but those who want it
01103 
01104 /********************************************************************************************
01105 ********************************************************************************************/
01106 
01107 /********************************************************************************************
01108 
01109 >   BOOL BitmapListComponent::StartImport(BaseCamelotFilter *pFilter)
01110 
01111     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01112     Created:    11/6/96
01113     Inputs:     pFilter - the BaseCamelotFilter filter that is being used to import a file.
01114     Returns:    TRUE if the component was able to prepare for importing;
01115                 FALSE if not (e.g. out of memory)
01116     Purpose:    Inform the bitmap list document component that a Native or Web import is
01117                 about to start.
01118     SeeAlso:    DocComponent
01119 
01120 ********************************************************************************************/
01121 
01122 BOOL BitmapListComponent::StartImport(BaseCamelotFilter *pFilter)
01123 {
01124 TRACEUSER( "Neville", _T("BitmapListComponent::StartImport\n") );
01125     if (pFilter == NULL)
01126     {
01127         ERROR3("BitmapListComponent::StartExport filter is null!");
01128         return TRUE;
01129     }
01130 
01131     // Save this in our link to the BaseCamelotFilter
01132     pCamFilter = pFilter;
01133     // Set our variable so that we warn about a possible replacement only once
01134     WarnedBefore = FALSE;
01135 
01136     // Set up and start the imported bitmap list
01137     pImportedBitmaps = new ImportedBitmaps();
01138     if (pImportedBitmaps == NULL)
01139         return FALSE;
01140 
01141     return TRUE;
01142 }
01143 
01144 /********************************************************************************************
01145 
01146 >   BOOL BitmapListComponent::EndImport(BaseCamelotFilter *pFilter, BOOL Success)
01147 
01148     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01149     Created:    11/6/96
01150     Inputs:     pFilter - the BaseCamelotFilter filter that is being used to import a file.
01151                 Success - TRUE => The import was successful;
01152                          FALSE => The import failed - abandon any changes.
01153     Returns:    TRUE if the component was able to end the importing;
01154                 FALSE if not (e.g. out of memory)
01155     Purpose:    Inform the bitmap list document component that a Native or Web import has
01156                 just finished.
01157     SeeAlso:    DocComponent
01158 
01159 ********************************************************************************************/
01160 
01161 BOOL BitmapListComponent::EndImport(BaseCamelotFilter *pFilter, BOOL Success)
01162 {
01163 TRACEUSER( "Neville", _T("BitmapListComponent::EndImport\n") );
01164     if (pFilter == NULL)
01165     {
01166         ERROR3("BitmapListComponent::EndImport filter is null!");
01167         return TRUE;
01168     }
01169 
01170     // As we have finished with it now, destroy the list of imported bitmaps
01171     if (pImportedBitmaps)
01172     {
01173         delete pImportedBitmaps;
01174         pImportedBitmaps = NULL;
01175     }
01176 
01177     // Null our link to the BaseCamelotFilter
01178     pCamFilter = NULL;
01179     // Set our variable so that we warn about a possible replacement only once
01180     WarnedBefore = FALSE;
01181 
01182     return TRUE;
01183 }
01184 
01185 /********************************************************************************************
01186 
01187 >   KernelBitmap* BitmapListComponent::GetReadBitmapReference(INT32 BitmapRef)
01188 
01189     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01190     Created:    11/6/96
01191     Inputs:     BitmapRef   - The bitmap reference or record number that the record handler has loaded
01192                             from the record.
01193     Outputs:    -
01194     Returns:    pBitmap - A pointer to return the required kernel bitmap
01195     Purpose:    Try and convert a bitmap reference i.e. record number into a previously
01196                 imported bitmap definition which should now be an kernel bitmap in the document.
01197     SeeAlso:    - 
01198 
01199 ********************************************************************************************/
01200 
01201 KernelBitmap* BitmapListComponent::GetReadBitmapReference(INT32 BitmapRef)
01202 {
01203 TRACEUSER( "Neville", _T("GetReadBitmapReference for ref %d\n"), BitmapRef );
01204 
01205     // First check to see if the bitmap refers to any of the built in bitmaps.
01206     // These will have negative record numbers
01207     KernelBitmap* pBitmap = NULL;
01208     if (BitmapRef <= 0)
01209     {
01210         // The only one that exists at present is the default bitmap
01211         if (REF_DEFAULTBITMAP_BUILTIN)
01212         {
01213             // Its the default one so just construct a new kernel bitmap which
01214             // refers to this and return this to the caller
01215             pBitmap = KernelBitmap::MakeKernelBitmap(NULL, NULL);
01216         }
01217         else
01218         {
01219             // If we have a pFilter then ask the default warning handle to append our message
01220             if (pCamFilter)
01221             {
01222                 if (!WarnedBefore)
01223                 {
01224                     pCamFilter->AppendWarning(_R(IDS_NATIVE_BITMAPWARNING));
01225                     WarnedBefore = TRUE;
01226                 }
01227 
01228                 // We have warned the user about problems so just construct a new kernel bitmap which
01229                 // is the default one and return this to the caller
01230                 pBitmap = KernelBitmap::MakeKernelBitmap(NULL, NULL);
01231             }
01232             else
01233                 ERROR2(NULL,"BitmapListComponent::GetReadBitmapReference negative BitmapRef is unknown");
01234         }
01235     }
01236     else
01237     {
01238         // Try and find the specified record number in our colour list
01239         pBitmap = pImportedBitmaps->GetBitmap(BitmapRef);
01240         // If not found then this is a problem as a bitmap must have been defined before its being
01241         // referenced 
01242         if (pBitmap == NULL)
01243         {
01244             // If we have a pFilter then ask the default warning handle to append our message
01245             if (pCamFilter)
01246             {
01247                 if (!WarnedBefore)
01248                 {
01249                     pCamFilter->AppendWarning(_R(IDS_NATIVE_BITMAPWARNING));
01250                     WarnedBefore = TRUE;
01251                 }
01252 
01253                 // We have warned the user about problems so just construct a new kernel bitmap which
01254                 // is the default one and return this to the caller
01255                 pBitmap = KernelBitmap::MakeKernelBitmap(NULL, NULL);
01256             }
01257             else
01258                 ERROR2(NULL,"BitmapListComponent::GetReadBitmapReference BitmapRef cannot be found");
01259         }
01260     }
01261 
01262     return pBitmap;
01263 }
01264 
01265 /********************************************************************************************
01266