npaper.cpp

Go to the documentation of this file.
00001 // $Id: npaper.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 // NodeRenderablePaper class implementation
00100 
00101 /*
00102 //*/
00103 
00104 #include "camtypes.h"
00105 //#include "npaper.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "mario.h"
00108 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 #include "nodedoc.h"
00110 //#include "oilcoord.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111   
00112 CC_IMPLEMENT_DYNAMIC(NodeRenderablePaper, NodeRenderableBounded)
00113 
00114  
00115 /***********************************************************************************************
00116 
00117 >    NodeRenderablePaper::NodeRenderablePaper() 
00118 
00119      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00120      Created:   13/5/93
00121      Inputs:    -
00122      Outputs:   
00123      Returns:   -
00124               
00125      Purpose: This constructor creates a NodeRenderablePaper linked to no other with all status
00126               flags false and uninitialised bounding and pasteboard rectangles.            
00127             
00128      Errors:    
00129 
00130 ***********************************************************************************************/
00131  
00132 
00133 NodeRenderablePaper::NodeRenderablePaper(): NodeRenderableBounded()
00134 {
00135 } 
00136   
00137   
00138 /***********************************************************************************************
00139 
00140 >   void NodeRenderablePaper::NodeRenderablePaper
00141     (
00142         Node* ContextNode,  
00143         AttachNodeDirection Direction,  
00144         BOOL Locked = FALSE, 
00145         BOOL Mangled = FALSE,  
00146         BOOL Marked = FALSE, 
00147         BOOL Selected = FALSE, 
00148     )
00149 
00150     Author:  Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00151     Created: 26/4/93             
00152     
00153     Inputs: ContextNode: Pointer to a node which this node is to be attached to.     
00154     
00155             Direction: 
00156             
00157                 Specifies the direction in which this node is to be attached to the 
00158                 ContextNode. The values this variable can take are as follows: 
00159                                   
00160                 PREV      : Attach node as a previous sibling of the context node
00161                 NEXT      : Attach node as a next sibling of the context node
00162                 FIRSTCHILD: Attach node as the first child of the context node
00163                 LASTCHILD : Attach node as a last child of the context node                               
00164                           
00165             The remaining inputs specify the status of the node: 
00166             
00167             Locked:     Is node locked ?
00168             Mangled:    Is node mangled ?
00169             Marked:     Is node marked ?
00170             Selected:   Is node selected ?
00171             
00172     Outputs:   -
00173     Returns:   - 
00174     Purpose: This method initialises the node and links it to ContextNode in the
00175              direction specified by Direction. All necessary tree links are
00176              updated.     
00177              
00178     Errors:  An assertion error will occur if ContextNode is NULL
00179 
00180 
00181 ***********************************************************************************************/
00182 
00183 NodeRenderablePaper::NodeRenderablePaper(Node* ContextNode,  
00184                     AttachNodeDirection Direction,  
00185                     BOOL Locked, 
00186                     BOOL Mangled,  
00187                     BOOL Marked, 
00188                     BOOL Selected   
00189               ):NodeRenderableBounded(ContextNode, Direction, Locked, Mangled, Marked, 
00190                 Selected) 
00191 { 
00192 } 
00193 
00194 
00195 /********************************************************************************************
00196 
00197 >   BOOL NodeRenderablePaper::NeedsToRender(RenderRegion *pRender)
00198 
00199     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00200     Created:    24/05/94
00201     Inputs:     pRender - the render region in question (NULL if none)
00202     Returns:    FALSE => we never want to render paper objects while rendering ink objects.
00203     Purpose:    Indicate that we don't want to render paper objects in the ink loop.
00204     SeeAlso:    NodeRenderablePaper::NeedsToExport
00205 
00206 ********************************************************************************************/
00207 
00208 SubtreeRenderState NodeRenderablePaper::RenderSubtree(RenderRegion* pRender, Node** ppNextNode, BOOL bClip)
00209 {
00210     if (pRender && pRender->RenderPaperAsInk())
00211         return SUBTREE_ROOTANDCHILDREN;
00212 
00213     return SUBTREE_NORENDER;
00214 }
00215 
00216 
00217 
00218 
00219 /********************************************************************************************
00220 
00221 >   BOOL NodeRenderablePaper::IsPaper() const
00222 
00223     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00224     Created:    25/11/94
00225     Returns:    TRUE => we are a paper node.
00226     Purpose:    Indicate that we ARE paper! (Overrides virtual func in Node.)
00227     SeeAlso:    Node::IsPaper
00228 
00229 ********************************************************************************************/
00230 
00231 BOOL NodeRenderablePaper::IsPaper() const
00232 {
00233     return TRUE;
00234 }
00235 
00236 
00237 
00238 
00239 /********************************************************************************************
00240 
00241 >   BOOL NodeRenderablePaper::NeedsToExport(RenderRegion *pRender, BOOL VisibleLayersOnly = FALSE,
00242                                             BOOL CheckSelected = FALSE)
00243 
00244     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00245     Created:    23/03/94
00246     Inputs:     pRender - A pointer to the current export region (null if none)
00247                 VisibleLayersOnly - TRUE => remove nodes which are on invisible layers
00248                                    - FALSE => export everything
00249                 CheckSelected - TRUE => we check if object selected and only export selected bjects
00250                               - FALSE => we don't bother checking for selection or not
00251     Returns:    FALSE => we never want to export NodeRenderablePaper objects.
00252     Purpose:    Indicate that we don't want to export this class of nodes.
00253     SeeAlso:    NodeRenderablePaper::NeedsToRender
00254 
00255 ********************************************************************************************/
00256 
00257 BOOL NodeRenderablePaper::NeedsToExport(RenderRegion *pRender, BOOL VisibleLayersOnly, BOOL CheckSelected)
00258 {
00259     return FALSE;
00260 }
00261 
00262      
00263 /***********************************************************************************************
00264 > Node* NodeRenderablePaper::SimpleCopy() // Private method  
00265 
00266     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00267     Created:    28/4/93
00268     
00269     Inputs:       
00270     Outputs:    
00271     Returns:    A copy of the node or NULL if memory runs out
00272          
00273     Purpose:    This method returns a shallow copy of the node with all Node pointers NULL. 
00274                 The function is virtual, and must be defined for all derived classes.  
00275     
00276     Errors:     If memory runs out when trying to copy, then ERROR is called with an out of memory
00277                 error and the function returns NULL. 
00278    
00279 
00280 **********************************************************************************************/
00281      
00282 Node* NodeRenderablePaper::SimpleCopy()
00283 {
00284     NodeRenderablePaper* NodeCopy; 
00285     NodeCopy = new NodeRenderablePaper();
00286     ERRORIF(NodeCopy == NULL, _R(IDE_NOMORE_MEMORY), NULL); 
00287     CopyNodeContents(NodeCopy);   
00288     return (NodeCopy);
00289 }               
00290 
00291 
00292 /***********************************************************************************************
00293 >   void NodeRenderablePaper::CopyNodeContents(Node* NodeCopy)
00294 
00295     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00296     Created:    28/4/93
00297     
00298     Inputs:     -     
00299     Outputs:    A copy of this node
00300    
00301     Returns:    -
00302          
00303     Purpose:    This method copies the node's contents to the node pointed to by NodeCopy.
00304               
00305     Errors:     An assertion failure will occur if NodeCopy is NULL
00306     
00307     Scope:      protected
00308                                      
00309 ***********************************************************************************************/
00310 
00311 void NodeRenderablePaper::CopyNodeContents(NodeRenderablePaper* NodeCopy)
00312 {                         
00313     ENSURE(NodeCopy != NULL,"Trying to copy a node's contents into a NULL node");  
00314     NodeRenderableBounded::CopyNodeContents(NodeCopy); 
00315     NodeCopy->PasteboardRect = PasteboardRect;         
00316 }       
00317    
00318                                              
00319 /***********************************************************************************************
00320 >   void NodeRenderablePaper::PolyCopyNodeContents(NodeRenderable* pNodeCopy)
00321 
00322     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00323     Created:    18/12/2003
00324     Outputs:    -
00325     Purpose:    Polymorphically copies the contents of this node to another
00326     Errors:     An assertion failure will occur if NodeCopy is NULL
00327     Scope:      protected
00328                                      
00329 ***********************************************************************************************/
00330 
00331 void NodeRenderablePaper::PolyCopyNodeContents(NodeRenderable* pNodeCopy)
00332 {
00333     ENSURE(pNodeCopy, "Trying to copy a node's contents into a NULL node");
00334     ENSURE(IS_A(pNodeCopy, NodeRenderablePaper), "PolyCopyNodeContents given wrong dest node type");
00335 
00336     if (IS_A(pNodeCopy, NodeRenderablePaper))
00337         CopyNodeContents((NodeRenderablePaper*)pNodeCopy);
00338 }
00339 
00340 
00341 
00342 /***********************************************************************************************
00343 
00344 >   virtual void NodeRenderablePaper::ChangePasteboardRect(const DocRect& PasteRect)
00345 
00346     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00347     Created:    25/4/93
00348     Inputs:     PasteRect: Rectangle representing the outer limits of the pasteboard 
00349                             
00350     Outputs:    -
00351     Returns:    -               
00352     
00353     Purpose:    To change the pasteboard rectangle of this node, and then if necessary
00354                 recursively change the pasteboard rectangles of all its parents. 
00355                 
00356                 The method also changes the document extents in the NodeDocument node at 
00357                 the root of the tree. 
00358                 
00359     Errors:     An assertion failure will occur if the parent of a paper object is not a 
00360                 paper object or the root of the tree is not a NodeDocument
00361     
00362     Scope:      protected
00363 
00364     SeeAlso:    NodeRenderablePaper::SetInitialPasteboardRect
00365 
00366 ***********************************************************************************************/
00367 
00368 void NodeRenderablePaper::ChangePasteboardRect(const DocRect& PasteRect)  
00369 {   
00370     // Check if the pasteboard rectangle should be changed
00371     if (PasteboardRect != PasteRect)
00372     {
00373         PasteboardRect = PasteRect;  // Set the pasteboard rectangle     
00374                            
00375         // If the node has a parent then we will need to change its    
00376         // Pasteboard rectangle
00377         if (Parent != NULL)   
00378         {
00379             // CombinedSiblingPasteboardRectangle will be the smallest rectangle which 
00380             // surrounds all sibling pasteboard rectangles.  
00381             DocRect CombinedSiblingPasteboardRectangle; 
00382         
00383             // Take the union of this nodes Pasteboard rectangle with all its siblings 
00384             // pasteboard rectangles. 
00385             Node* CurrentNode = this->FindParent()->FindFirstChild(); 
00386             while (CurrentNode != NULL)
00387             {       
00388                 if (CurrentNode->IsKindOf(CC_RUNTIME_CLASS(NodeRenderablePaper)))   
00389                 {
00390                     CombinedSiblingPasteboardRectangle = CombinedSiblingPasteboardRectangle.Union(
00391                         ( ((NodeRenderablePaper*)CurrentNode)->GetPasteboardRect(FALSE)) ); 
00392                 }           
00393                 CurrentNode = CurrentNode->FindNext();      
00394             }       
00395                                       
00396             // The parent of a paper object should always be a paper object
00397             ENSURE(Parent->IsKindOf(CC_RUNTIME_CLASS(NodeRenderablePaper)), 
00398                    "The parent of a paper object was not a paper object"); 
00399             
00400             // Call the routine recursively to set the parents pasteboard rectangle  
00401             ((NodeRenderablePaper*)Parent)->ChangePasteboardRect(
00402                 CombinedSiblingPasteboardRectangle);  
00403         }       
00404         else
00405         {
00406             // The root of the tree should be a NodeDocument
00407             ENSURE(this->IsKindOf(CC_RUNTIME_CLASS(NodeDocument)),
00408                    "When trying to set the document extents no\nNodeDocument node was found at the root of the tree");
00409             // Set the document extents
00410             ((NodeDocument*)this)->SetExtents(); 
00411         }
00412     }   
00413 }         
00414 
00415                                              
00416 /***********************************************************************************************
00417 
00418 >   virtual void NodeRenderablePaper::SetInitialPasteboardRect(const DocRect& PasteRect)
00419 
00420     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00421     Created:    25/4/93
00422     Inputs:     PasteRect: Rectangle representing the outer limits of the pasteboard 
00423                             
00424     Outputs:    -
00425     Returns:    -                                          
00426                 
00427     Purpose:    To set the initial pasteboard rectangle of this node, and then change the 
00428                 pasteboard rectangles of all its parents. 
00429                     
00430                 The method also changes the document extents in the NodeDocument node at 
00431                 the root of the tree. 
00432                 
00433     Errors:     An assertion failure will occur if the parent of a paper object is not a 
00434                 paper object or the root of the tree is not a NodeDocument.  
00435                 
00436     Scope:      protected
00437                 
00438     SeeAlso:    NodeRenderablePaper::ChangePasteboardRectangle
00439 
00440 ***********************************************************************************************/
00441 
00442 void NodeRenderablePaper::SetInitialPasteboardRect(const DocRect& PasteRect)  
00443 {    
00444     // Check if the pasteboard rectangle should be changed
00445     if (PasteboardRect != PasteRect)
00446     {
00447         PasteboardRect = PasteRect;  // Set the pasteboard rectangle     
00448                            
00449         // If the node has a parent then we will need to change its    
00450         // Pasteboard rectangle
00451         if (Parent != NULL)   
00452         {
00453             // The parent of a paper object should always be a paper object
00454             ENSURE(Parent->IsKindOf(CC_RUNTIME_CLASS(NodeRenderablePaper)),
00455                    "The parent of a paper object was not a paper object!");   
00456               
00457             // Union the parents pasteboard rectangle with this nodes pasteboard
00458             // rectangle to obtain the parents new pasteboard rectangle.   
00459             DocRect NewParentPasteboardRectangle = 
00460                 ((NodeRenderablePaper*)Parent)->GetPasteboardRect(FALSE); 
00461             NewParentPasteboardRectangle = NewParentPasteboardRectangle.Union(PasteRect);     
00462                 
00463             // Call the routine recursively to set the parent's pasteboard rectangle     
00464             ((NodeRenderablePaper*)Parent)->SetInitialPasteboardRect
00465                 (NewParentPasteboardRectangle);   
00466         }   
00467         else
00468         {
00469             // The root of the tree should be a NodeDocument
00470             ENSURE(this->IsKindOf(CC_RUNTIME_CLASS(NodeDocument)), 
00471                    "The root of the document tree was not a NodeDocument node");    
00472             // Set the document extents
00473             ((NodeDocument*)this)->SetExtents(); 
00474         }
00475     }   
00476 }                          
00477 
00478 /*********************************************************************************************
00479 
00480 >    virtual DocRect NodeRenderablePaper::GetPasteboardRect(BOOL Pixelise = TRUE,
00481                                                             View *pView = NULL) const
00482 
00483      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00484      Created:   13/5/93
00485      Inputs:    Pixelise - whether or not to pixelise the pasteboard rectangle before
00486                            returning it.
00487                 pView - the view to pixelise to (not used if Pixelise is FALSE).
00488      Outputs:   The objects pasteboard rectangle
00489      Returns:   -
00490               
00491      Purpose:   For obtaining the objects pasteboard rectangle   
00492             
00493      Errors:    
00494 
00495 **********************************************************************************************/
00496 
00497 DocRect NodeRenderablePaper::GetPasteboardRect(BOOL Pixelise, View *pView) const
00498 {
00499     DocRect temp = PasteboardRect;
00500 
00501     if (Pixelise)
00502     {
00503         // "Pixelise" the position of the spread.
00504         // Effectively, this ensures that the spread will be aligned to a whole pixel boundary
00505         // and allows both GDraw and GDI to consistently plot the same pixels when rendering
00506         // the same primitive
00507         if (pView != NULL)
00508         {
00509             temp.lo.Pixelise(pView);
00510             temp.hi.Pixelise(pView);
00511         }
00512         else
00513         {
00514             temp.lo.Pixelise();
00515             temp.hi.Pixelise();
00516         }
00517     }
00518 
00519     return (temp); 
00520 
00521 //  return (PasteboardRect); 
00522 }       
00523 
00524 
00525 /********************************************************************************************
00526 
00527 >   void* NodeRenderablePaper::GetDebugDetails(StringBase* Str) 
00528 
00529     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00530     Created:    21/9/93
00531     Inputs:     -
00532     Outputs:    Str: String giving debug info about the node
00533     Returns:    -
00534     Purpose:    For obtaining debug information about the Node
00535     Errors:     -
00536     SeeAlso:    -
00537 
00538 ********************************************************************************************/
00539 
00540      
00541 void NodeRenderablePaper::GetDebugDetails(StringBase* Str) 
00542 {
00543 #ifdef _DEBUG
00544     NodeRenderableBounded::GetDebugDetails(Str);  
00545     
00546     String_256 TempStr; 
00547     if (!PasteboardRect.IsValid())
00548     { 
00549         TempStr = TEXT("\r\nPasteboard Rectangle = *INVALID*\r\n"); 
00550     }
00551     else 
00552         TempStr._MakeMsg(TEXT("\r\nPasteboard Rectangle\r\n   Low(#1%ld, #2%ld)\r\n   High(#3%ld, #4%ld)\r\n"),    
00553                     PasteboardRect.LowCorner().x,  
00554                     PasteboardRect.LowCorner().y,
00555                     PasteboardRect.HighCorner().x,  
00556                     PasteboardRect.HighCorner().y);      
00557                     
00558     (*Str)+=TempStr; 
00559 #endif
00560 }    

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