nodeclip.cpp

Go to the documentation of this file.
00001 // $Id: nodeclip.cpp 1361 2006-06-25 16:43:38Z 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 // Implementation of NodeClipView.
00100 //
00101 
00102 #include "camtypes.h"   // pre-compiled header
00103 #include "nodeclip.h"   // header file
00104 //#include "clipres.h"  // ClipView resources
00105 
00106 //#include "cxfrec.h"       // save/load - in camtypes.h [AUTOMATICALLY REMOVED]
00107 #include "cxftags.h"    //
00108 //#include "camfiltr.h" // - in camtypes.h [AUTOMATICALLY REMOVED]
00109 
00110 //#include "mario.h"        // for _R(IDE_NOMORE_MEMORY)
00111 
00112 DECLARE_SOURCE("$Revision: 1361 $");
00113 
00114 // dynamic class creation stuff.
00115 CC_IMPLEMENT_DYNCREATE(NodeClipView, NodeRenderableInk)
00116 
00117 // Declare smart memory handling in Debug builds
00118 #define new CAM_DEBUG_NEW
00119 
00120 /********************************************************************************************
00121 
00122 >   NodeClipView::NodeClipView()
00123 
00124     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00125     Created:    10 February 2000
00126     Purpose:    Default constructor.
00127     Errors: 
00128     See also:   
00129 
00130 ********************************************************************************************/
00131 NodeClipView::NodeClipView() : NodeRenderableInk()
00132 {
00133     // member variable initialisation.
00134     m_pRegion   = NULL;
00135     m_pContext  = NULL;
00136     m_bRenderingForward = FALSE;
00137     m_pSavedRegion  = NULL;
00138     m_bGDrawClipRegionSet = FALSE;
00139 
00140     m_ClipRegionAttribute.SetResponsibleForGrouping (FALSE);
00141 }
00142 
00143 
00144 
00145 /********************************************************************************************
00146 
00147 >   NodeClipView::NodeClipView( Node* pContextNode,
00148                                 AttachNodeDirection Direction,
00149                                 BOOL Locked     = FALSE,
00150                                 BOOL Mangled    = FALSE,
00151                                 BOOL Marked     = FALSE,
00152                                 BOOL Selected   = FALSE )
00153     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00154     Created:    10 February 2000
00155     Inputs:     pContextNode    points to the node to which to attach this node.
00156                 Direction       the direction in which this node is to be attached to 
00157                                 pContextNode. Possible values:
00158 
00159                 PREV        Attach node as a previous sibling of the context node.
00160                 NEXT        Attach node as a next sibling of the context node.
00161                 FIRSTCHILD  Attach node as the first child of the context node.
00162                 LASTCHILD   Attach node as a last child of the context node.
00163 
00164                 Locked      is node locked?
00165                 Mangled     is node mangled?
00166                 Marked      is node marked?
00167                 Selected    is node selected?
00168 
00169     Purpose:    This method initialises the node and links it to pContextNode in the
00170                 direction specified by Direction. All necessary tree links are updated.
00171                 Most of the work is carried out by base constructors.
00172 
00173     Errors:     An ENSURE error will occur if pContextNode is NULL.
00174     See also:   
00175 
00176 ********************************************************************************************/
00177 NodeClipView::NodeClipView( Node* pContextNode,  
00178                             AttachNodeDirection Direction,  
00179                             BOOL Locked, 
00180                             BOOL Mangled,  
00181                             BOOL Marked, 
00182                             BOOL Selected )
00183             : NodeRenderableInk(pContextNode, Direction, Locked, Mangled, Marked, Selected) 
00184 {
00185     // member variable initialisation.
00186     m_pRegion   = NULL;
00187     m_pContext  = NULL;
00188     m_bRenderingForward = FALSE;
00189     m_pSavedRegion  = NULL;
00190     m_bGDrawClipRegionSet = FALSE;
00191 
00192     m_ClipRegionAttribute.SetResponsibleForGrouping (FALSE);
00193 }
00194 
00195 
00196 
00197 /********************************************************************************************
00198 
00199 >   NodeClipView::~NodeClipView()
00200 
00201     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00202     Created:    10 February 2000
00203     Purpose:    Destructor.
00204     Errors: 
00205     See also:   
00206 
00207 ********************************************************************************************/
00208 NodeClipView::~NodeClipView()
00209 {
00210     // delete and clear member variables.
00211     if (m_pRegion   != NULL)
00212         delete [] m_pRegion; m_pRegion = NULL;
00213     if (m_pContext  != NULL)
00214         delete [] ((BYTE *)m_pContext); m_pContext = NULL;
00215 }
00216 
00217 
00218 
00219 /********************************************************************************************
00220 
00221 >   virtual DocRect NodeClipView::GetBoundingRect(BOOL DontUseAttrs, BOOL HitTest)
00222 
00223     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00224     Created:    10 February 2000
00225     Inputs:     DontUseAttrs    TRUE of you want to ignore all the node's attributes.
00226                 HitTest         TRUE if being called during a hit-test.
00227     Returns:    The bounding rectangle of this node.
00228 
00229     Purpose:    Find this node's bounding rectangle. If the rectangle is known to be valid 
00230                 then it is simply returned. If IsBoundingRectValid is FALSE then the rect 
00231                 is recalculated before it is returned and the validity flag reset.
00232     See also:   
00233 
00234 ********************************************************************************************/
00235 DocRect NodeClipView::GetBoundingRect(BOOL DontUseAttrs, BOOL HitTest)
00236 {
00237     // we want our Render() fuction to be called whenever that of our parent NCVC is called,
00238     // therefore we need the same size bounding rect.
00239     Node* pNCVC = FindParent();
00240     if (pNCVC != NULL && pNCVC->IsANodeClipViewController())
00241         return ((NodeRenderableInk*)pNCVC)->GetBoundingRect(DontUseAttrs, HitTest);
00242     else
00243         return DocRect(0, 0, 0, 0);
00244 }
00245 
00246 
00247 
00248 /********************************************************************************************
00249 
00250 >   virtual DocRect NodeClipView::GetBlobBoundingRect()
00251 
00252     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00253     Created:    10 February 2000
00254     Returns:    The bounding rectangle of this node with its blobs drawn.
00255     Purpose:    Get this node's bounding rectangle when its blobs are drawn.
00256     Errors: 
00257     See also:   GetBoundingRect().
00258 
00259 ********************************************************************************************/
00260 DocRect NodeClipView::GetBlobBoundingRect()
00261 {
00262     // TODO:
00263     //  need to investigate exactly when this method is used, as I don't think I should 
00264     //  implement it for an invisible node, but I'm not sure...
00265 
00266     return DocRect(0, 0, 0, 0);
00267 }
00268 
00269 
00270 
00271 /********************************************************************************************
00272 
00273 >   BOOL NodeClipView::NeedsToRender(RenderRegion* pRender)
00274 
00275     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00276     Created:    05 May 2000
00277     Inputs:     pRender     the render-region we're rendering into.
00278     Returns:    TRUE always.
00279 
00280     Purpose:    Whether or not we need to render. Most NodeRenderableBounded's do a check
00281                 on intersection with the render-region's clip-rect here, however we may
00282                 sometimes need to render when we *don't* intersect the clip-rect, but one of 
00283                 our right-siblings does. So we'll just return TRUE from this whatever.
00284 
00285     Notes:      In future it may pay to test the bounds of all our right-siblings, however
00286                 what if there are nested ClipView's? I get the feeling that not rendering
00287                 in that case would probably screw things up for on of our multi-clipped 
00288                 grand-children.
00289 
00290 ********************************************************************************************/
00291 
00292 SubtreeRenderState NodeClipView::RenderSubtree(RenderRegion* pRender, Node** ppNextNode, BOOL bClip)
00293 {
00294     return SUBTREE_ROOTANDCHILDREN;
00295 }
00296 
00297 
00298 
00299 /********************************************************************************************
00300 
00301 >   virtual void NodeClipView::Render(RenderRegion* pRender)
00302 
00303     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00304     Created:    10 February 2000
00305     Inputs:     pRender     points to a render region to render into.
00306 
00307     Purpose:    Render method. See NodeClipViewController::Render() for complete details
00308                 on what should happen when.
00309 
00310                 If we think we're in a forward rendering loop, then set GDraw's clipping
00311                 region by rendering our ClipRegionAttribute.
00312 
00313                 If we think we're in a backward rendering loop, then do nothing.
00314     Errors:     
00315     See also:   NodeClipViewController::Render()
00316 
00317 ********************************************************************************************/
00318 void NodeClipView::Render(RenderRegion* pRender)
00319 {
00320 // DEBUG
00321 //  TRACEUSER( "Karim", _T("NCV::Render; Tag %d\n"), Tag);
00322 
00323     // In the hit-test render-loop we do *not*
00324     // want to directly cause any clipping. at all other times, we render away.
00325     if (!pRender->IsHitDetect())
00326         SetGDrawClippingRegion(pRender);
00327 }
00328 
00329 
00330 
00331 /********************************************************************************************
00332 
00333 >   void RenderClipAttr(RenderRegion* pRender)
00334 
00335     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00336     Created:    13 April 2000
00337     Inputs:     
00338     Outputs:    
00339     Returns:    
00340     Purpose:    
00341     Errors:     
00342     See also:   
00343 
00344 ********************************************************************************************/
00345 void NodeClipView::RenderClipAttr(RenderRegion* pRender)
00346 {
00347     m_ClipRegionAttribute.Render(pRender);
00348 }
00349 
00350 
00351 
00352 /********************************************************************************************
00353 
00354 >   void NodeClipView::SetGDrawClippingRegion()
00355 
00356     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00357     Created:    14/02/2000
00358     Inputs:     pRender     points to the region which we shall be clipping inside.
00359     Outputs:    GDraw's current clipping region may have been changed by this method.
00360     Returns:    
00361     Purpose:    Work out the path of my keyhole node, save GDraw's rendering context and
00362                 tell GDraw to clip to that path.
00363 
00364     Errors:     ERROR3 if pKeyhole cannot be converted to paths.
00365                 In release builds, we just quit, with no clipping.
00366     See also:   RestoreGDrawClippingRegion()
00367 
00368 ********************************************************************************************/
00369 void NodeClipView::SetGDrawClippingRegion(RenderRegion* pRender)
00370 {
00371     m_ClipRegionAttribute.Render(pRender);
00372 }
00373 
00374 
00375 
00376 /********************************************************************************************
00377 
00378 >   BOOL NodeClipView::RestoreGDrawClippingRegion(BOOL fFirstInRenderLoop = FALSE)
00379 
00380     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00381     Created:    11/02/2000
00382     Inputs:     fFirstInRenderLoop      whether or not we are being called at the start of a
00383                                         ClipView render-process.
00384     Returns:    TRUE if we restored the region and did it successfully,
00385                 FALSE otherwise.
00386     Purpose:    If GDraw's clipping region has been set but not yet restored, then attempt
00387                 to restore it from the copy we made when it was set.
00388 
00389     Errors:     
00390     See also:   SetGDrawClippingRegion()
00391 
00392 ********************************************************************************************/
00393 BOOL NodeClipView::RestoreGDrawClippingRegion(BOOL fFirstInRenderLoop)
00394 {
00395     return TRUE;
00396 }
00397 
00398 
00399 
00400 /********************************************************************************************
00401 
00402 >   virtual void NodeClipView::RenderEorDrag(RenderRegion* pRender)
00403 
00404     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00405     Created:    10 February 2000
00406     Inputs:     pRender     pointer to the render region to render into.
00407     Purpose:    Render this node as eor-blobs into the given render region.
00408 
00409     Errors: 
00410     See also:   See Render() for info.
00411 
00412 ********************************************************************************************/
00413 void NodeClipView::RenderEorDrag(RenderRegion* pRender)
00414 {
00415 }
00416 
00417 
00418 
00419 /********************************************************************************************
00420 
00421 >   virtual String NodeClipView::Describe(BOOL Plural, BOOL Verbose)
00422 
00423     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00424     Created:    11 April 2000
00425     Inputs:     Plural      whether to pluralise the description.
00426                 Verbose     short or long version.
00427     Returns:    A string description of this node.
00428     Purpose:    Get a string description, for use in menus and infobar etc.
00429     Errors:     
00430     See also:   
00431 
00432 ********************************************************************************************/
00433 String NodeClipView::Describe(BOOL Plural, BOOL Verbose)
00434 {
00435     if (Plural)
00436         return(String(_R(IDS_CLIPVIEW_DESCRP)));
00437     else
00438         return(String(_R(IDS_CLIPVIEW_DESCRS)));
00439 }
00440 
00441 
00442 
00443 /********************************************************************************************
00444 
00445 >   virtual UINT32 NodeClipView::GetNodeSize() const 
00446 
00447     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00448     Created:    10 February 2000
00449     Returns:    The size of the node in bytes.
00450     Purpose:    Obtain the size of a NodeClipView object.
00451 
00452     See also:   Node::GetSubtreeSize
00453 
00454 ********************************************************************************************/
00455 UINT32 NodeClipView::GetNodeSize() const 
00456 {
00457     return sizeof(NodeClipView);
00458 }
00459 
00460 
00461 
00462 /********************************************************************************************
00463 
00464 >   void NodeClipView::Transform(TransformBase &Trans)
00465 
00466     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00467     Created:    10 February 2000
00468     Inputs:     Trans   non-const reference to a description of the transformation.
00469     Outputs:    This node will be transformed appropriately.
00470     Purpose:    Perform a transformation on this node.
00471     Errors:     
00472     See also:   
00473 
00474 ********************************************************************************************/
00475 void NodeClipView::Transform(TransformBase &Trans)
00476 {
00477     // leave it up to the base class...
00478     NodeRenderableInk::Transform(Trans);
00479 }
00480 
00481 
00482 
00483 /********************************************************************************************
00484 
00485 >   BOOL NodeClipView::WritePreChildrenWeb(BaseCamelotFilter* pFilter)
00486 
00487     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00488     Created:    10 February 2000
00489     Inputs:     pFilter     pointer to a camelot file filter.
00490 
00491     Returns:    TRUE if successful,
00492                 FALSE otherwise.
00493     Purpose:    Writes this node out to a camelot document.
00494     Errors:     ERROR2 if pFilter is NULL.
00495     See also:   
00496 
00497 ********************************************************************************************/
00498 BOOL NodeClipView::WritePreChildrenWeb(BaseCamelotFilter* pFilter)
00499 {
00500     // validate input.
00501     ERROR2IF(pFilter == NULL, FALSE, "NULL parameter");
00502     
00503     CXaraFileRecord Rec(TAG_CLIPVIEW, TAG_CLIPVIEW_SIZE);
00504 
00505     BOOL    ok = Rec.Init();
00506     if (ok) ok = (pFilter->Write(&Rec) != 0);
00507 
00508     return ok;
00509 }
00510 
00511 
00512 
00513 /********************************************************************************************
00514 
00515 >   BOOL NodeClipView::WritePreChildrenNative(BaseCamelotFilter* pFilter)
00516 
00517     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00518     Created:    10 February 2000
00519     Inputs:     pFilter     pointer to a camelot file filter.
00520 
00521     Returns:    TRUE if successful,
00522                 FALSE otherwise.
00523     Purpose:    Writes this node out to a camelot document.
00524     Errors:     
00525     See also:   
00526 
00527 ********************************************************************************************/
00528 BOOL NodeClipView::WritePreChildrenNative(BaseCamelotFilter* pFilter)
00529 {
00530     return WritePreChildrenWeb(pFilter);
00531 }
00532 
00533 
00534 
00535 /********************************************************************************************
00536 
00537 >   BOOL NodeClipView::PostImport()
00538 
00539     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00540     Created:    10 February 2000
00541     Returns:    TRUE if success,
00542                 FALSE if unsuccessful.
00543     Purpose:    Performs any necessary post-processing once the object has been read in
00544                 from a file.
00545     Errors:     
00546     See also:   
00547 
00548 ********************************************************************************************/
00549 BOOL NodeClipView::PostImport()
00550 {
00551     // re-initialise our pointer to our keyhole node.
00552     return TRUE;
00553 }
00554 
00555 
00556 
00557 /********************************************************************************************
00558 
00559 >   virtual Node* NodeClipView::SimpleCopy()
00560 
00561     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00562     Created:    10 February 2000
00563     Returns:    A copy of this node, or
00564                 NULL if unsuccessful.
00565     Purpose:    Copy this node.
00566     Errors:     ERROR1 returning NULL if we couldn't allocate memory for the new node.
00567     See also:   Node::SimpleCopy()
00568 
00569 ********************************************************************************************/
00570 Node* NodeClipView::SimpleCopy()
00571 {
00572     NodeClipView* pNodeCopy = new NodeClipView;
00573     ERROR1IF(pNodeCopy == NULL, NULL, _R(IDE_NOMORE_MEMORY));
00574     CopyNodeContents(pNodeCopy);
00575 
00576     return pNodeCopy;
00577 }
00578 
00579 
00580 
00581 /********************************************************************************************
00582 
00583 >   virtual void NodeClipView::CopyNodeContents(NodeClipView* pNodeCopy)
00584 
00585     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00586     Created:    10 February 2000
00587     Inputs:     pNodeCopy   the node to copy our contents into.
00588     Purpose:    Copy this node's contents into pNodeCopy.
00589     Errors:     
00590     See also:   Node::CopyNodeContents()
00591 
00592 ********************************************************************************************/
00593 void NodeClipView::CopyNodeContents(NodeClipView* pNodeCopy)
00594 {
00595     // call base-class implementation; this will also perform necessary validation for us.
00596     NodeRenderableInk::CopyNodeContents(pNodeCopy);
00597 
00598     // TODO:
00599     //  Any other relevant copying.
00600 }
00601 
00602 
00603 
00604 /***********************************************************************************************
00605 >   void NodeClipView::PolyCopyNodeContents(NodeRenderable* pNodeCopy)
00606 
00607     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00608     Created:    18/12/2003
00609     Outputs:    -
00610     Purpose:    Polymorphically copies the contents of this node to another
00611     Errors:     An assertion failure will occur if NodeCopy is NULL
00612     Scope:      protected
00613                                      
00614 ***********************************************************************************************/
00615 
00616 void NodeClipView::PolyCopyNodeContents(NodeRenderable* pNodeCopy)
00617 {
00618     ENSURE(pNodeCopy, "Trying to copy a node's contents into a NULL node");
00619     ENSURE(IS_A(pNodeCopy, NodeClipView), "PolyCopyNodeContents given wrong dest node type");
00620 
00621     if (IS_A(pNodeCopy, NodeClipView))
00622         CopyNodeContents((NodeClipView*)pNodeCopy);
00623 }
00624 
00625 
00626 

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