swffiltr.cpp

Go to the documentation of this file.
00001 // $Id: swffiltr.cpp 1611 2006-07-30 11:22:17Z 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 /* $Header: /Camelot/kernel/swffiltr.cpp 12    1/12/04 17:20 Phil $ */
00099 
00100 #include "camtypes.h"   // Camelot data types.
00101 #include "page.h"       // For Page.
00102 //#include "ops.h"      // For Operation. - in camtypes.h [AUTOMATICALLY REMOVED]
00103 //#include "selop.h"        // For SelOperation. - in camtypes.h [AUTOMATICALLY REMOVED]
00104 //#include "ccfile.h"       // For CCLexFile. - in camtypes.h [AUTOMATICALLY REMOVED]
00105 //#include "document.h" // For Document, DocCoord. - in camtypes.h [AUTOMATICALLY REMOVED]
00106 //#include "pathname.h" // For PathName. - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "spread.h"       // For Spread. - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "doccolor.h" // For colours. - in camtypes.h [AUTOMATICALLY REMOVED]
00109 #include "progress.h"   // For progress functions.
00110 //#include "nev.h"      // Resources for error messages.
00111 #include "nodeshad.h"   // For NodeShadow.
00112 #include "userattr.h"   // Needed for TemplateAttribute.
00113 //#include "cxfrech.h"  // Needed for TemplateAttribute. - in camtypes.h [AUTOMATICALLY REMOVED]
00114 #include "tmpltatr.h"   // For TemplateAttribute.
00115 
00116 //#include "oilfltrs.h" // For FlashOILFilter. - in camtypes.h [AUTOMATICALLY REMOVED]
00117 //#include "fillattr.h" // Filter attributes. - in camtypes.h [AUTOMATICALLY REMOVED]
00118 //#include "filtrres.h" // Resources for this class.
00119 #include "bitfilt.h"    // For static drawing size function.
00120 //#include "simon.h"        // Button name resources.
00121 
00122 #include "swfrndr.h"    // Definition of FlashRenderRegion.
00123 #include "swfexpdc.h"   // Declaration of FlashExportDC.
00124 #include "swftext.h"    // Definition of FlashFormatText class.
00125 #include "swfplace.h"   // For FlashPlaceObject.
00126 
00127 #include "swffiltr.h"   // Definition of this class.
00128 #include "layer.h"
00129 
00130 CC_IMPLEMENT_DYNAMIC ( FlashFilter, VectorFilter )
00131 
00132 #define new CAM_DEBUG_NEW
00133 
00134 /********************************************************************************************
00135 
00136 >   BOOL FlashFilter::FlashFilter()
00137 
00138     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00139     Created:    18/8/99
00140     Returns:    Void.
00141     Purpose:    Filter constructor, and initialises the default settings.
00142 
00143 ********************************************************************************************/
00144 
00145 FlashFilter::FlashFilter()
00146 {
00147     // Set up filter descriptions.
00148     FilterName.Load(_R(IDT_FLASH_FILTERNAME));
00149     FilterInfo.Load(_R(IDT_FLASH_FILTERINFO));
00150     FilterID = FILTERID_FLASH;
00151 
00152     ExportMsgID = _R(IDT_EXPORTMSG_FLASH);
00153 
00154     Flags.CanImport = FALSE;
00155     Flags.CanExport = TRUE;
00156 
00157     mpBackgroundNode = NULL;
00158     mpBackgroundCol = NULL;
00159 
00160 #if 0
00161     // No attributes yet
00162     DefLineWidthAttr = NULL;
00163     DefLineColAttr = NULL;
00164     DefFillColAttr = NULL;
00165 #endif
00166 }
00167 
00168 /********************************************************************************************
00169 
00170 >   BOOL FlashFilter::Init()
00171 
00172     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00173     Created:    18/8/99
00174     Returns:    TRUE if Filter initialised, otherwise FALSE.
00175     Purpose:    Initialise the filter (attaches a FlashOILFilter object).
00176     SeeAlso:    FlashOILFilter
00177 
00178 ********************************************************************************************/
00179 
00180 BOOL FlashFilter::Init ( void )
00181 {
00182     // Get the OILFilter object
00183     pOILFilter = new FlashOILFilter(this);
00184     if (pOILFilter == NULL)
00185         return FALSE;
00186 
00187     mOnlySelected = FALSE;
00188 
00189     // All ok
00190     return TRUE;
00191 }
00192 
00193 /********************************************************************************************
00194 
00195 >   BOOL FlashFilter::DoImport ( SelOperation *Op,
00196                                  CCLexFile* pFile, 
00197                                  Document *DestDoc,
00198                                  BOOL AutoChosen,
00199                                  ImportPosition *Pos,
00200                                  KernelBitmap** ppImportedBitmap,
00201                                  DocCoord* pPosTranslate,
00202                                  String_256* URL )
00203 
00204     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00205     Created:    18/8/99
00206     Returns:    FALSE.
00207     Purpose:    Place holder function for Flash import. Since the filter only exports, a
00208                 false value is always returned.
00209     SeeAlso:    DoExport
00210 
00211 ********************************************************************************************/
00212 
00213 BOOL FlashFilter::DoImport ( SelOperation *Op,
00214                              CCLexFile* pFile, 
00215                              Document *DestDoc,
00216                              BOOL AutoChosen,
00217                              ImportPosition *Pos,
00218                              KernelBitmap** ppImportedBitmap,
00219                              DocCoord* pPosTranslate,
00220                              String_256* URL )
00221 {
00222     // Import operations aren't supported. Therefore return FALSE.
00223     return FALSE;
00224 }
00225 
00226 /********************************************************************************************
00227 
00228 >   BOOL FlashFilter::DoExport ( Operation* pOp,
00229                                  CCLexFile* pFile,
00230                                  PathName* pPath, 
00231                                  Document* TheDocument,
00232                                  BOOL ShowOptions)
00233 
00234     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00235     Created:    18/8/99
00236     Returns:    TRUE if export succeeds, otherwise FALSE.
00237     Purpose:    Place holder function for Flash export until real function is done.
00238     SeeAlso:    DoImport
00239 
00240 ********************************************************************************************/
00241 
00242 BOOL FlashFilter::DoExport ( Operation* pOp,
00243                              CCLexFile* pFile,
00244                              PathName* pPath, 
00245                              Document* pDoc,
00246                              BOOL ShowOptions )
00247 {
00248     Spread              *pSpread    = GetFirstSpread ( pDoc );          // First spread.
00249     FlashRenderRegion   SWFRegion;                                      // Render region.
00250     FlashExportDC       ExDC        ( this );                           // Export DC.
00251     View                *pView      = (View*) pDoc->GetFirstDocView (); // Use current view.
00252 
00253     // Reset the static variables used to maintain the count of the number of Flash objects
00254     // exported of the various types. Without this, Camelot gets a bit confused, and the
00255     // export doesn't quite work.
00256     FlashPlaceObject::ResetStatics ();
00257     
00258     // Get a reference to the selected nodes.
00259     Range               Selection   ( * ( GetApplication ()->FindSelection () ) );
00260 
00261     // If a selection has been made, only export the selected nodes. This if statement
00262     // sets up the local and global variables for either of the options.
00263     if ( Selection.FindFirst () != NULL )
00264     {
00265         // A selection has been made, so don't render everything in the drawing.
00266         mOnlySelected = TRUE;
00267         mPageRect   = Selection.GetBoundingRect ();
00268     }
00269     else
00270     {
00271         // Export all nodes.
00272         mOnlySelected = FALSE;
00273 
00274         // Use a static method in the bitmap filter to extract the size of the drawing to
00275         // render to the file.
00276         mPageRect = BaseBitmapFilter::GetSizeOfDrawing ( pSpread );
00277     }
00278 
00279     // Get the background colour.
00280 
00281     DocColour BackgroundCol = GetPageColour ( pSpread, &mpBackgroundNode );
00282     mpBackgroundCol = &BackgroundCol;
00283 
00284     // Set up the origin of the bounding rectangle according to the Flash file specification.
00285     DocCoord            Origin      ( mPageRect.lo.x, mPageRect.hi.y );     // Flash's lox, loy.
00286 
00287     // Initialise the render region.
00288     SWFRegion.Init ();
00289     SWFRegion.SetBackgroundColour (BackgroundCol);
00290 
00291     // Create an ExportDC within the render region.
00292     SWFRegion.AttachDevice ( pView, &ExDC, pSpread );
00293 
00294     // Get the position of the first page, and set as origin, and convert to SWF co-ords.
00295     ExDC.SetOrigin ( Origin );
00296 
00297     // Ensure file is open: - If closed, attempt to open it.
00298     //                      - If unopenable, return error.
00299     if ( !pFile->isOpen () )
00300     {
00301         if ( pFile->IsKindOf ( CC_RUNTIME_CLASS ( CCDiskFile ) ) )
00302         {
00303             if ( !OpenExportFile ( ( CCDiskFile* ) pFile, pPath ) )
00304                 return FALSE;
00305         }
00306         else
00307         {
00308             TRACEUSER ( "Graeme", _T("Tried to open non-CCDiskFile in FlashFilter::DoExport\n") );
00309             return FALSE;
00310         }
00311     }
00312 
00313     // Initialise the export DC with the file.
00314     ExDC.Init ( pFile );
00315 
00316     // Export Render the tree using the base Filter class method.
00317     ExportRender ( &SWFRegion );
00318 
00319     // Wrap up the file. Tasks to be done are:
00320     // (1) Write end of frame.
00321     // (2) End the file.
00322     // (3) Go back and plug holes in the header struct. (Size of file.)
00323     ExDC.EndFile ();
00324 
00325     return TRUE;
00326 }
00327 
00328 void FlashFilter::CleanUpAfterExport( BOOL Success )
00329 {
00330     mpBackgroundNode = NULL;
00331     mpBackgroundCol = NULL;
00332 }
00333 
00334 
00335 /********************************************************************************************
00336 
00337 >   DocColour FlashFilter::GetPageColour ( Spread *pSpread )
00338 
00339     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00340     Created:    27/08/99
00341     Inputs:     pSpread - Pointer to the current spread.
00342     Returns:    DocColour - the colour of the page background.
00343     Purpose:    Used to get the page colour.
00344     Errors:     -
00345     SeeAlso:    Page::GetPageColour()
00346 
00347 ********************************************************************************************/
00348 
00349 DocColour FlashFilter::GetPageColour ( Spread* pSpread,
00350                                        Node** pBackground )
00351 {
00352     // Calculate the background colour
00353     DocColour dcol ( COLOUR_WHITE );        // Default to white.
00354     *pBackground = NULL;
00355 
00356     Layer *pLayer = pSpread->FindFirstPageBackgroundLayer();
00357     if (pLayer)
00358     {
00359         Node * pNode = pLayer->FindFirstChild();
00360         while (pNode && !pNode->IsLayer())
00361         {
00362             if (!pNode->IsNodeHidden())
00363             {
00364                 if (pNode->IsARegularShape())
00365                 {
00366                     Node *pAttrNode = pNode->FindFirstChild();
00367                     if ( pAttrNode && pAttrNode->IsAnAttribute()
00368                          && pAttrNode->IsKindOf(CC_RUNTIME_CLASS(AttrFlatFill)))
00369                     {
00370                         dcol = *(((AttrFlatFill *)pAttrNode)->GetStartColour());
00371                         *pBackground = pNode;
00372                     }
00373                 }
00374             }
00375             pNode = pNode->FindNext();
00376         }
00377     }
00378 
00379     return dcol;
00380 }
00381 
00382 /********************************************************************************************
00383 
00384 >   virtual BOOL FlashFilter::WriteNodes ( RenderRegion *pRegion,
00385                                            ExportDC *pDC,
00386                                            BOOL VisibleLayersOnly,
00387                                            BOOL CheckSelected,
00388                                            BOOL ShowProgress )
00389     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00390     Created:    21/9/99
00391     Inputs:     pRegion                 - The render region to export to.
00392                 pDc                     - Device context to use, can be NULL.
00393                 VisibleLayersOnly       - Use visible layers or not
00394                 CheckSelected           - Only export selected nodes.
00395                 ShowProgress            - TRUE then start up a progress bar or FALSE assume
00396                                           the caller has done it.
00397     Returns:    TRUE if the export process completed successfully, FALSE if an error occured.
00398     Purpose:    This is a modified version of the base Filter class' ExportRenderNodes, and
00399                 as a result contains Flash specific code. The only real modification has been
00400                 to jump past any nodes in the background layer, which Flash doesn't render.
00401     SeeAlso:    Filter::ExportRenderNodes
00402 
00403 ********************************************************************************************/
00404 
00405 BOOL FlashFilter::WriteNodes ( RenderRegion *pRegion,
00406                                ExportDC *pDC,
00407                                BOOL VisibleLayersOnly,
00408                                BOOL CheckSelected,
00409                                BOOL ShowProgress )
00410 {
00411     // Loop through the tree as usual.
00412     // while ( Nodes Left to Export )
00413 
00414     // if ( Node is a TextStory )
00415     // Create a text record.
00416     // Create a font record if that font hasn't been defined yet.
00417     // Create a place object tag.
00418 
00419     // else
00420     // Create a path record.
00421     // If the path is identical to a previous path, don't store it.
00422     // If the fill is a bitmap fill, make a bitmap record.
00423     // Write a place object tag out.
00424 
00425 #ifdef DO_EXPORT
00426 
00427     // Export the file, but catch any file errors.
00428     try
00429     {
00430         // This function parses through the Camelot tree in common with the other export
00431         // loops. Unlike the other loops, it builds up four linked lists as dictionaries
00432         // of shapes, fonts, and bitmaps, which are then rendered into a file by the
00433         // ExportAll () call at the end of the loop.
00434 
00435         // Future work: Add functions to compare strings and paths to ensure that repeated
00436         // objects or strings are stored once, and invoked several times, rather than
00437         // writing multiple instances to the file.
00438 
00439         // Create a FlashRenderRegion and FlashExportDC pointers by casting the stock ones.
00440         FlashExportDC       *pFDC   = ( FlashExportDC* ) CCDC::ConvertFromNativeDC(pRegion->GetRenderDC ());
00441         FlashRenderRegion   *pFRR   = ( FlashRenderRegion* ) pRegion;
00442 
00443         // Find the first node that we should export from this spread
00444         Spread *pSpread = pRegion->GetRenderSpread ();
00445 /*
00446         Node *pLayer = ( Node * ) pSpread->FindFirstLayer ();
00447         Node *pNode = pSpread->FindFirstForExport( pRegion, TRUE, VisibleLayersOnly, CheckSelected );
00448 
00449         if ( mpBackground != NULL && pNode == mpBackground )
00450         {
00451             // Move onto the next node.
00452             pNode = pNode->FindNextForExport( pRegion, TRUE, VisibleLayersOnly, CheckSelected );
00453         }
00454 
00455         // Create file header, and write it.
00456         pFDC->CreateHeader ( mBackground, mPageRect );
00457 
00458         while ( pNode != NULL )
00459         {
00460             // Declare variables.
00461             LayerState  ThisLayer   = GetButtonState ( pNode );
00462             String_256  ButtonName;
00463 
00464             // Limit the progress display to legal values.
00465             if ( pNode->IsNodeRenderableClass() )
00466             {
00467                 CurrentProgressLimit = NumNodes + ( ( NodeRenderable * ) pNode )
00468                                         -> GetSizeOfExport ( this );
00469             }
00470 
00471             // Set the layer state.
00472             pFRR->SetLayerState ( ThisLayer );
00473 
00474             // Get the layer ID, so that we can tell if it's a button or not.
00475             if ( ThisLayer != NO_BUTTON && GetButtonName ( pNode, ButtonName ) )
00476             {
00477                 // The name has been successfully extracted, and is passed into the render
00478                 // region.
00479                 pFRR->SetButtonName ( ( TCHAR* ) ButtonName );
00480             }
00481             else
00482             {
00483                 // A NULL pointer in this function instructs the RenderRegion to treat the
00484                 // next node as an ordinary shape, rather than a button.
00485                 pFRR->SetButtonName ( NULL );
00486             }
00487 
00488             // Attempt to render the node using custom export code.
00489             if ( !pNode->ExportRender ( pRegion ) )
00490             {
00491                 // No special export rendering - just use the normal rendering
00492                 pNode->Render ( pRegion );      
00493             }
00494 
00495             NumNodes = CurrentProgressLimit;        // Update progress counter.
00496 
00497             if ( NumNodes > ( LastExportProgressUpdate + UpdateEvery ) )
00498             {
00499                 LastExportProgressUpdate = NumNodes;
00500 
00501                 // If we are rendering in strips then we need to add an offset to
00502                 // the position of the progress bar.
00503                 if ( !ContinueSlowJob ( ProgressOffset + NumNodes ) )
00504                 {
00505                     // Error; close down and exit nicely.
00506                     // Must set an error otherwise we will get the dreaded reporting error
00507                     // when none set message.
00508                     // If no error message ID set in this filter then use default
00509                     if ( StopExportMsgID == 0 )
00510                         Error::SetError ( _R(IDW_CANCELEXPORT) );
00511                     else
00512                         Error::SetError ( StopExportMsgID );
00513                     pRegion->StopRender ();
00514                     if ( ShowProgress )
00515                         EndSlowJob ();
00516                     return FALSE;
00517                 }
00518             }
00519 
00520             // Find another one to export
00521             pNode = pNode->FindNextForExport ( pRegion, TRUE, VisibleLayersOnly,
00522                                                CheckSelected );
00523 
00524             if ( mpBackground != NULL && pNode == mpBackground )
00525             {
00526                 // Move onto the next node.
00527                 pNode = pNode->FindNextForExport ( pRegion, TRUE, VisibleLayersOnly,
00528                                                    CheckSelected );
00529             }
00530         }
00531 */
00532         // Create file header, and write it.
00533         pFDC->CreateHeader(*mpBackgroundCol, mPageRect);
00534 
00535         FlashRenderCallback MyCallback(this, pFRR, VisibleLayersOnly, CheckSelected, mpBackgroundNode);
00536         pRegion->RenderTree(pSpread, FALSE, FALSE, &MyCallback);
00537 
00538         // Call the main export function.
00539         pFRR->ExportAll ();
00540     }
00541 
00542     // Handle any file errors, or other exceptions.
00543     catch ( CFileException )
00544     {
00545         // Didn't work - report failure to caller.
00546         if ( pDC )
00547             pDC->ExportFile->SetThrowExceptions ( FALSE );
00548         pRegion->StopRender ();
00549         if ( ShowProgress )
00550             EndSlowJob ();
00551         return FALSE;
00552     }
00553 
00554     // All ok
00555     return TRUE;
00556 #else
00557     return FALSE;
00558 #endif
00559 }
00560 
00561 /********************************************************************************************
00562 
00563 >   BOOL FlashRenderCallback::BeforeNode(RenderRegion* pRegion, Node* pNode)
00564 
00565     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00566     Created:    01/12/2004
00567     Inputs:     pNode - pointer to node about to be rendered by RenderTree
00568                 pRender - pointer to RenderRegion running RenderTree loop
00569     Outputs:    -
00570     Returns:    TRUE if node can be rendered
00571                 FALSE if not
00572     Purpose:    Handle the callback from RenderTree that has been requested by Filter
00573 
00574 ********************************************************************************************/
00575 
00576 BOOL FlashRenderCallback::BeforeNode(RenderRegion* pRegion, Node* pNode)
00577 {
00578     // If this is the background node, ignore it
00579     if (m_pBackgroundNode != NULL && pNode == m_pBackgroundNode)
00580         return FALSE;
00581 
00582     // Declare variables.
00583     LayerState  ThisLayer = m_pFilter->GetButtonState(pNode);
00584     String_256  ButtonName;
00585 
00586     // Set the layer state.
00587     m_pFRR->SetLayerState(ThisLayer);
00588 
00589     // Get the layer ID, so that we can tell if it's a button or not.
00590     if (ThisLayer != NO_BUTTON && m_pFilter->GetButtonName(pNode, ButtonName))
00591     {
00592         // The name has been successfully extracted, and is passed into the render
00593         // region.
00594         m_pFRR->SetButtonName((TCHAR*)ButtonName);
00595     }
00596     else
00597     {
00598         // A NULL pointer in this function instructs the RenderRegion to treat the
00599         // next node as an ordinary shape, rather than a button.
00600         m_pFRR->SetButtonName(NULL);
00601     }
00602 
00603     // Update the progress display
00604     if (pNode->IsNodeRenderableClass())
00605         m_pFilter->UpdateFilterProgress(((NodeRenderable*)pNode)->GetSizeOfExport(m_pFilter));
00606     else
00607         m_pFilter->UpdateFilterProgress(0);             // For back compatibility with previous version of this code
00608 
00609     // Render (export) the node that we have, using special export rendering if it exists.
00610     BOOL bExportRendered = pNode->ExportRender(pRegion);
00611 
00612     return (!bExportRendered);                      // If not exported let RenderTree do it, return TRUE
00613 }
00614 
00615 
00616 /********************************************************************************************
00617 
00618 >   BOOL FlashRenderCallback::BeforeSubtree(RenderRegion* pRegion,
00619                                             Node* pNode,
00620                                             Node** ppNextNode,
00621                                             BOOL bClip,
00622                                             SubtreeRenderState* pState)
00623 
00624     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00625     Created:    30/11/2004
00626     Inputs:     pNode - pointer to node about to be rendered by RenderTree
00627                 pRender - pointer to RenderRegion running RenderTree loop
00628     Outputs:    pNextNode - pointer to node where navigation should continue
00629                 State - Navigation state for RenderTree state machine
00630     Returns:    TRUE if we've returned a valid SubRenderState
00631                 FALSE if not
00632     Purpose:    Handle the callback from RenderTree that has been requested by Filter
00633 
00634 ********************************************************************************************/
00635 
00636 BOOL FlashRenderCallback::BeforeSubtree(RenderRegion* pRegion,
00637                                          Node* pNode,
00638                                          Node** ppNextNode,
00639                                          BOOL bClip,
00640                                          SubtreeRenderState* pState)
00641 {
00642     // We're not counting so let normal, smart navigation take place
00643     if (pNode->NeedsToExport(pRegion, m_bVisibleLayersOnly, m_bSelectedOnly))
00644     {
00645         // This node does need to be exported
00646         // Tell the node at the root of the subtree that we're about to export it and it's children
00647         pNode->PreExportRender(pRegion);
00648         return FALSE;                       // Tell RenderTree we want normal navigation to take place
00649     }
00650     else
00651     {
00652         *pState = SUBTREE_NORENDER;         // Tell RenderTree we want to forcibly skip this node
00653         return TRUE;
00654     }
00655 }
00656 
00657 
00658 /********************************************************************************************
00659 
00660 >   virtual BOOL FlashFilter::ExportSelectionOnly()
00661 
00662     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00663     Created:    21/12/99
00664     Returns:    True if this filter wants check if an object is selected or not and so export
00665                 only the selected items Or False if want to export everything. (The value of
00666                 mOnlySelected.)
00667     Purpose:    Determines if the filter wants to export only selected items.
00668     SeeAlso:    FlashFilter::ExportRender;
00669 
00670 ********************************************************************************************/
00671 
00672 BOOL FlashFilter::ExportSelectionOnly(BOOL MaskedRender)
00673 {
00674     // Flash defaults to attempt to export a selection first.
00675     return mOnlySelected;
00676 }
00677 
00678 /********************************************************************************************
00679 
00680 >   virtual BOOL FlashFilter::ExportVisibleLayersOnly()
00681 
00682     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00683     Created:    2/11/00
00684     Inputs:     -
00685     Returns:    TRUE    - Only export visible layers.
00686                 FALSE   - Export everything.
00687     Purpose:    Determines if the filter wants to export only visible layers.
00688                 NB. This base class version does the default action of making the filter
00689                 export everything including hidden layers.
00690     SeeAlso:    Filter::ExportRender;
00691                 Filter::VisibleLayersOnly
00692 
00693 ********************************************************************************************/
00694 
00695 BOOL FlashFilter::ExportVisibleLayersOnly()
00696 {
00697     // The Flash filter should ignore hidden layers. Unfortunately the button system uses
00698     // hidden layers for its state, so export them in any case.
00699     return FALSE;
00700 }   
00701 
00702 /********************************************************************************************
00703 
00704 >   LayerState FlashFilter::GetButtonState ( Node *pNode )
00705 
00706     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00707     Created:    18/1/00
00708     Returns:    LayerState - The layer on which this node resides, or NO_BUTTON if it's on a
00709                 regular layer.
00710     Purpose:    Tests to see whether the node is part of a roll-over button or not.
00711     SeeAlso:    FlashFilter::ExportRenderNodes
00712 
00713 ********************************************************************************************/
00714 
00715 LayerState FlashFilter::GetButtonState ( Node *pNode )
00716 {
00717     // This function catches button codes, which are inconveniently scattered
00718     // throughout the tree, and uses this information to rebuild the list of nodes to
00719     // export into the correct form for buttons.
00720     Node        *pParent    = pNode->FindParent ();
00721     LayerState  ThisLayer   = NO_BUTTON;
00722 
00723     // Browse up the tree until we either find a layer node, or run out of tree.
00724     while ( pParent != NULL )
00725     {
00726         if ( pParent->IsLayer () )
00727         {
00728             // Extract the layer's name...
00729             String_256  LayerName   = ( ( Layer* ) pParent )->GetLayerID ();
00730 
00731             // ... set up comparison strings...
00732             String_256  Clicked ( _R(IDS_ROLLOVER_CLICKED) );       // = "Clicked"
00733             String_256  Default ( _R(IDS_ROLLOVER_DEFAULT) );       // = "Default"
00734             String_256  Mouse ( _R(IDS_ROLLOVER_MOUSE) );           // = "Mouse"
00735             String_256  Selected ( _R(IDS_ROLLOVER_SELECTED) );     // = "Selected"
00736 
00737             // ... and use these to identify whether it's a button layer, and what part
00738             // of the button it forms.
00739             if ( LayerName.IsIdentical ( Clicked ) )
00740             {
00741                 ThisLayer = CLICKED;
00742             }
00743             else if ( LayerName.IsIdentical ( Default ) )
00744             {
00745                 ThisLayer = DEFAULT;
00746             }
00747             else if ( LayerName.IsIdentical ( Mouse ) )
00748             {
00749                 ThisLayer = MOUSE;
00750             }
00751             else if ( LayerName.IsIdentical ( Selected ) )
00752             {
00753                 ThisLayer = SELECTED;
00754             }
00755 
00756             // Break out of the while loop.
00757             break;
00758         }
00759 
00760         // If it's not a layer, grab the next node and continue.
00761         pParent = pParent->FindParent ();
00762     }
00763 
00764     return ThisLayer;
00765 }
00766 
00767 /********************************************************************************************
00768 
00769 >   BOOL FlashFilter::GetButtonName ( Node *pNode,
00770                                       String_256 &ButtonName )
00771 
00772     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00773     Created:    18/1/00
00774     Returns:    True if a button has been found, otherwise false.
00775     Purpose:    If the node has a template attribute containing the name, this function loads
00776                 it into the ButtonName string, and returns TRUE indicating that it's been
00777                 found. Basically it extracts an ID name from a template.
00778     SeeAlso:    FlashFilter::ExportRenderNodes (), FlashFilter::GetButtonState ()
00779 
00780 ********************************************************************************************/
00781 
00782 BOOL FlashFilter::GetButtonName ( Node *pNode,
00783                                   String_256 &ButtonName )
00784 {
00785     // We have a potential button candidate. Now check to see whether or not
00786     // it has a Templater Attribute node. If it does, get the name of the
00787     // button, and export it using the export DC.
00788     Node        *pChild     = pNode->FindFirstChild ();
00789     BOOL        FoundButton = FALSE;
00790 
00791     // Ensure that the string is empty.
00792     ButtonName.Empty ();
00793 
00794     // Try to find a TemplateAttribte amongst the node's children.
00795     while ( pChild != NULL && !FoundButton )
00796     {
00797         // If one is found, the object is a button.
00798         if ( pChild->IsKindOf ( CC_RUNTIME_CLASS ( TemplateAttribute ) ) )
00799         {
00800             // It's a button! First extract the button's name.
00801             ButtonName = ( ( TemplateAttribute * ) pChild )->GetParam ();
00802 
00803             // Break out of the loop.
00804             FoundButton = TRUE;
00805         }
00806         else
00807         {
00808             // Otherwise parse the next record.
00809             pChild = pChild->FindNext ();
00810         }
00811     }
00812 
00813     // Return whether a button has been found.
00814     return FoundButton;
00815 }

Generated on Sat Nov 10 03:47:07 2007 for Camelot by  doxygen 1.4.4