opnode.cpp

Go to the documentation of this file.
00001 // $Id: opnode.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // Implementation of the node operations
00099 
00100 #include "camtypes.h"
00101 //#include "selop.h"     - in camtypes.h [AUTOMATICALLY REMOVED]
00102 //#include "nodeattr.h"  - in camtypes.h [AUTOMATICALLY REMOVED]
00103 #include "opnode.h" 
00104 
00105 #include "objchge.h"    
00106 //#include "app.h"   - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "attrmgr.h"   - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "tmpltres.h" 
00109 
00110 
00111 DECLARE_SOURCE( "$Revision: 1282 $" );
00112 
00113 CC_IMPLEMENT_DYNAMIC(RemoveAttributeParam, OpParam)
00114 CC_IMPLEMENT_DYNCREATE(OpRemoveAttributeFromSelection, SelOperation)
00115 
00116 #define new CAM_DEBUG_NEW
00117 
00118 
00119 #define ENSURE_NOT_NULL(Pointer)        ERROR2IF(Pointer == NULL, 0, "NULL Args")
00120 #ifndef VOID_ENSURE_NOT_NULL
00121 #define VOID_ENSURE_NOT_NULL(p)     if (p == NULL) {    ERROR2RAW("NULL Args")  }
00122 #endif
00123 #define ENSURE_KIND(pNode, Kind)        ERROR3IF(!pNode->IS_KIND_OF(Kind), "pNode is not kind of " #Kind);
00124 
00125 /********************************************************************************************
00126 
00127 >   BOOL OpRemoveAttributeFromSelection::Declare()
00128 
00129     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from Will - I wish I hadn't)
00130     Created:    09/07/97
00131 
00132     Purpose:    Declares the OpDescriptor for OpRemoveAttributeFromSelection. Should be
00133                 called on start up.
00134 
00135     Returns:    TRUE if the operation could be successfully initialised 
00136                 FALSE if no more memory could be allocated 
00137                 
00138 ********************************************************************************************/
00139 BOOL OpRemoveAttributeFromSelection::Declare()
00140 {
00141     
00142     // Register the opdescriptors for the OpRemoveAttributeFromSelection operation
00143 
00144     return (RegisterOpDescriptor(   0,
00145                                     _R(IDS_DELETEATTROP),
00146                                     CC_RUNTIME_CLASS(OpRemoveAttributeFromSelection),
00147                                     OPTOKEN_DELETEATTR,
00148                                     OpRemoveAttributeFromSelection::GetState,
00149                                     0,  /* help ID */
00150                                     0,
00151                                     0,
00152                                     0,
00153                                     SYSTEMBAR_ILLEGAL,          // For now !
00154                                     FALSE,                      // Receive messages
00155                                     FALSE,
00156                                     FALSE,
00157                                     0,
00158                                     0 // (GREY_WHEN_NO_CURRENT_DOC | GREY_WHEN_NO_SELECTION)
00159            )); 
00160 }               
00161 
00162 
00163 /********************************************************************************************
00164 
00165 >   OpState OpRemoveAttributeFromSelection::GetState(String_256*, OpDescriptor* OpDesc)
00166 
00167     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from Will - I wish I hadn't)
00168     Created:    09/07/97
00169 
00170     Purpose:    For finding OpRemoveAttributeFromSelection state.
00171 
00172     Returns:    The state of the OpRemoveAttributeFromSelection operation
00173 
00174     Notes:      Always available cos it ain't in no menu
00175                 
00176 ********************************************************************************************/
00177 OpState OpRemoveAttributeFromSelection::GetState(String_256*, OpDescriptor* OpDesc)
00178 {
00179     OpState OpSt;
00180 
00181     OpSt.Greyed = ( FALSE );  
00182                                                 
00183     return(OpSt);   
00184 }
00185 
00186 
00187 /********************************************************************************************
00188 
00189 >   virtual void OpRemoveAttributeFromSelection::GetOpName(String_256* OpName) 
00190 
00191     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from Will - I wish I hadn't)
00192     Created:    09/07/97
00193 
00194     Purpose:    The GetOpName fn is overridden so that we return back a description 
00195                 appropriate to the type of attribute that the operation applies. 
00196 
00197     Outputs:    The undo string for the operation
00198 
00199 ********************************************************************************************/
00200 void OpRemoveAttributeFromSelection::GetOpName(String_256* OpName) 
00201 { 
00202     *OpName += String_256(_R(IDS_ATTR_CHANGE));
00203 }  
00204 
00205 
00206 /********************************************************************************************
00207 
00208 >   virtual void OpRemoveAttributeFromSelection::DoWithParam(OpDescriptor* pOpDesc, OpParam* pOpParam)
00209 
00210     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from Will - I wish I hadn't)
00211     Created:    09/07/97
00212 
00213     Purpose:    Performs the OpRemoveAttributeFromSelection operation.
00214                 It removes all attributes with the given AttributeIdentifier from the
00215                 selected objects.
00216 
00217     Inputs:     pOpDesc:    See base class
00218                 pOpParam:   A RemoveAttributeParam containing the AttributeIdentifier of
00219                             the attributes to remove.
00220 
00221 ********************************************************************************************/
00222 void OpRemoveAttributeFromSelection::DoWithParam(OpDescriptor* pOpDesc, OpParam* pOpParam)
00223 {    
00224     VOID_ENSURE_NOT_NULL(pOpParam);
00225     ENSURE_KIND(pOpParam, RemoveAttributeParam);
00226 
00227     const RemoveAttributeParam* const pRemoveParam = (RemoveAttributeParam*)pOpParam;
00228 
00229     // Objects used to mark changed nodes, so that parents will update after attr replacement
00230     ObjChangeFlags cFlags;
00231     cFlags.Attribute    = TRUE;
00232     ObjChangeParam ObjChange(OBJCHANGE_STARTING,cFlags,NULL,this);
00233 
00234     BOOL Ok = TRUE;
00235 
00236     Ok = DoStartSelOp(FALSE, FALSE, FALSE, FALSE);  // FALSE's == don't render the blobs
00237 
00238     // Obtain the current selection
00239     SelRange* const pSelRange = GetApplication()->FindSelection();
00240     Ok = (pSelRange != NULL);
00241 
00242     if (Ok)
00243     {
00244 
00245         if (Ok)
00246         {
00247             Range CurrentSelection(*pSelRange);
00248             // Mark nodes that will allow this to happen, 
00249             // and error if no nodes will let it happen
00250     
00251             Ok = CurrentSelection.AllowOp(&ObjChange);
00252         }
00253     }
00254 
00255     if (Ok)
00256     {
00257         AttributeIdentifier AttrIDToDelete = pRemoveParam->GetAttrIDToDelete();
00258 
00259         Node* pNode = pSelRange->FindFirst();
00260         while (pNode != NULL && Ok)
00261         {
00262             NodeAttribute* const pAttr = FindAttributeOfClassID(pNode, AttrIDToDelete);
00263             if (pAttr != NULL)
00264             {
00265                 Ok = DoRemove(pAttr);
00266             }
00267 
00268             pNode = pSelRange->FindNext(pNode);
00269         }
00270     }
00271 
00272     if (Ok)
00273     {
00274         // Update all parents of this
00275         ObjChange.Define(OBJCHANGE_FINISHED,cFlags,NULL,this);
00276         Ok = UpdateChangedNodes(&ObjChange);
00277     }
00278 
00279     if (!Ok)
00280     {
00281         FailAndExecute();
00282     }
00283 
00284     End(); // End of operation
00285 } 
00286 
00287 
00288 /********************************************************************************************
00289 
00290 >   NodeAttribute* OpRemoveAttributeFromSelection::FindAttributeOfClassID(Node* const pNode, 
00291                                                                 AttributeIdentifier AttrID)
00292 
00293     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00294     Created:    08//07/97
00295 
00296     Purpose:    Support function to find an attribute of the given class
00297 
00298     Inputs:     pNode : The attribute to go
00299                 AttrID: The AttributeIdentifier of the attribute to find
00300 
00301     Returns:    An attribute of the given class or NULL if none found
00302 
00303 ********************************************************************************************/
00304 NodeAttribute* OpRemoveAttributeFromSelection::FindAttributeOfClassID(Node* const pNode, AttributeIdentifier AttrID)
00305 {
00306     NodeAttribute* pAttr = NodeAttribute::FindFirstAppliedAttr(pNode);
00307 
00308     while (pAttr)
00309     {
00310         if (pAttr->GetAttributeClassID() == AttrID)
00311             return pAttr;
00312 
00313         pAttr = NodeAttribute::FindPrevAppliedAttr(pAttr);
00314     }
00315 
00316     return NULL;
00317 }
00318 
00319 
00320 
00321 /********************************************************************************************
00322 
00323 >   BOOL OpRemoveAttributeFromSelection::DoRemove(NodeAttribute* const pOldAttr)
00324 
00325     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00326     Created:    08//07/97
00327 
00328     Purpose:    Support function to remove the attribute
00329 
00330     Inputs:     pOldAttr : The attribute to go
00331     Returns:    TRUE if successful 
00332                 FALSE if the operation should be aborted (TIDYUP THEN CALL End()!) 
00333 
00334 ********************************************************************************************/
00335 BOOL OpRemoveAttributeFromSelection::DoRemove(NodeAttribute* const pOldAttr)
00336 {
00337     ENSURE_NOT_NULL(pOldAttr);      // well use a reference then!
00338 
00339     BOOL Ok = TRUE;
00340 
00341     Node* CurrentNode = pOldAttr->FindParent();
00342     ERROR3IF(CurrentNode == NULL, "Can't find parent node in Replace Attr");
00343 
00344     // Now we have done with the old attribute, so lets hide it, so
00345     // the changes can be undone
00346     Ok = DoHideNode(pOldAttr, 
00347                     TRUE,       // Include the subtree size (not that there is one)
00348                     NULL,       // the hidden node
00349                     TRUE);      // make sure the attribute's HidingNode function is called
00350 
00351     return Ok;
00352 }

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