00001 // $Id: attrmgr.h 751 2006-03-31 15:43: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 /* 00099 */ 00100 00101 #ifndef INC_ATTRMGR 00102 #define INC_ATTRMGR 00103 00104 #include "list.h" 00105 #include "listitem.h" 00106 #include "doccolor.h" 00107 #include "msg.h" // Used to include msg.h - must be done because of rampant circular #includes!!!!! 00108 #include "range.h" 00109 #include "nodeattr.h" 00110 00111 class NodeRenderableInk; 00112 class AttributeValue; 00113 class Node; 00114 class ColourList; 00115 00116 // Graeme (21/3/00): 00117 // The AttributeIndex typedef has been moved into nodeattr.h. This allows me to create a method 00118 // within the NodeAttribute class to return the attribute index. So, if you're looking for this 00119 // list, you need to see the other file. 00120 00121 const INT32 NUM_BASE_ATTRS = ATTR_FIRST_FREE_ID; 00122 const INT32 NUM_ATTR_GROUPS = 2; // Increase this everytime a new attribute group is added 00123 // Currently there are only two (text, and graphic). 00124 00125 // Tim's default attribute structures 00126 00127 class AttributeEntry : public SimpleCCObject 00128 { 00129 public: 00130 // Pointer to the attribute for this entry 00131 AttributeValue *pAttr; 00132 00133 // TRUE if this attribute is temporary and should be deleted when it's finished with. 00134 BOOL Temp : 2; 00135 00136 // If TRUE then this attribute should not be added to a path (see ApplyBasedOnDefaults). 00137 BOOL Ignore : 2; 00138 }; 00139 00140 class NodeTypeEntry 00141 { 00142 public: 00143 // The type of node that this attribute can be applied to. 00144 CCRuntimeClass *pNodeType; 00145 }; 00146 00147 00148 /******************************************************************************************** 00149 00150 > class CurrentAttributeGroup: public CCObject 00151 00152 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00153 Created: 29/11/93 00154 Purpose: The current attribute group object consists of a group identifier, and a list of 00155 attribute nodes which belong to the group. It is used by the AttributeManager 00156 00157 SeeAlso: AttributeManager 00158 00159 ********************************************************************************************/ 00160 00161 class AttributeGroup: public ListItem 00162 { 00163 public: 00164 CCRuntimeClass* AttrGroup; // Group identifier 00165 CCRuntimeClass* BaseGroup; // The base group (Can be NULL) 00166 00167 NodeAttribute* AttrListHd; // List of current attributes in the group 00168 00169 String_256 GroupName; // Used for UI descriptions 00170 00171 }; 00172 00173 00174 /******************************************************************************************** 00175 00176 > class AttributeGroupItem: public ListItem 00177 00178 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00179 Created: 6/4/95 00180 Purpose: AttributeGroupItem 00181 SeeAlso: - 00182 00183 ********************************************************************************************/ 00184 00185 00186 class AttributeGroupItem: public ListItem 00187 { 00188 public: 00189 CCRuntimeClass* AttrGroup; 00190 }; 00191 00192 00193 /******************************************************************************************** 00194 00195 > class AttributeManager : public CCObject 00196 00197 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00198 Created: 29/11/93 00199 00200 Purpose: The attribute manager is currently responsible for managing the application 00201 of current attributes. It contains a list of Attribute groups along with 00202 instances of current attributes which belong to each group. An attribute group 00203 is identified by the RuntimeClass of an object 00204 00205 Each Document should have its own set of current attributes 00206 00207 It has been extended to store default attribute information by Tim 00208 00209 SeeAlso: - 00210 00211 ********************************************************************************************/ 00212 00213 // This class tidied by Simon 22/09/95 00214 // Try to keep it clean eh ! 00215 class AttributeManager: public CCObject 00216 { 00217 friend class BaseCamelotFilter; 00218 00219 public: 00220 00221 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00222 // Construction/destruction and initialisation 00223 AttributeManager(); 00224 ~AttributeManager(); 00225 00226 // Instance initialisation 00227 BOOL InitInstance(); 00228 // Initialises current attributes 00229 00230 // Static initialisation (Stuff Tim knows about) 00231 static BOOL InitDefaults(); 00232 // Static initialiser (mostly Tim's default stuff) 00233 static void Deinit(); 00234 // Static de-initialiser 00235 00236 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00237 // Fns for applying attributes to objects. 00238 // From Simon 00239 // In the future these fns could perhaps be merged into one AttributesSelected fn 00240 // taking a range of objects to apply the attribute/attributes too. This would me much 00241 // neater. The AttributeSelected and ApplyAttribToNode fns are currently a little 00242 // rampant, 00243 // At the time I wrote the AttributesSelected fn it was thought too dangerous to change 00244 // these fundamental routines 00245 00246 static void AttributeSelected(NodeAttribute* Attrib, NodeAttribute* OldAttr = NULL); 00247 // For applying attributes to the selection 00248 00249 static void AttributesSelected(List& AttribsToApply, UINT32 OpName); 00250 // For applying a set of attributes to the selection (as used by PasteAttributes). 00251 00252 static void ApplyAttribToNode(NodeRenderableInk* InkNode, NodeAttribute* NewAttr); 00253 // For applying attributes to a specific Object (For drag n' drop) 00254 00255 enum AttrsToMakeCurrent { ALL, NOT_APPLIED, NONE }; 00256 // Type used by AttributesToMakeCurrent 00257 00258 AttrsToMakeCurrent GetAttributesToMakeCurrent(List& Attribs, 00259 List& AttrGroupsList, 00260 BOOL bPasteAttrs); 00261 // Called to determine which attributes in the Attribs list to make current. 00262 // Similar to WeShouldMakeAttrCurrent. Used by AttributesSelected. 00263 00264 private: 00265 static void ApplyAttribToNodeHelper(NodeRenderableInk* InkNode, NodeAttribute* NewAttr); 00266 00267 00268 public: 00269 00270 static void ReplaceAttributes(NodeAttribute* Attrib, List* OldAttrs); 00271 // Called by OpGrad after modifying a complex fill 00272 00273 00274 // Both these fns are sort of private, they are currently public cos Will needs to 00275 // access them from his fill stuff 00276 BOOL WeShouldMakeAttrCurrent(BOOL AttributeApplied, NodeAttribute* pAttr, List* pAttrGroupList, 00277 BOOL DroppedAttr = FALSE, BOOL AttrDroppedOntoPage = FALSE); 00278 // Called to determine if an attribute being applied should be made current 00279 00280 00281 00282 static void UpdateCurrentAttr(NodeAttribute* Attr, BOOL Mutate, List* pAttrGroupList, 00283 BOOL TellWorld = TRUE); 00284 // Not to be confused with UpdateCurrentAttribute. Updates current attrs in the specified 00285 // list of attribute groups. Not very clean this fn 00286 static BOOL UpdateCurrentAppliedAttr(NodeAttribute* pAttr, List* pAttrGroupList, BOOL bAttrApplied, BOOL bMutate); 00287 static BOOL UpdateAfterAttrApplied(NodeAttribute* pAttr); 00288 00289 static BOOL CanBeAppliedToSelection(NodeAttribute* Attrib, List* pAttrGroups); 00290 // This function would ideally live in the SelRange. It determines if the attribute can 00291 // be applied to at least one object in the selection. Used to determine if we should 00292 // apply the attribute or not! 00293 00294 static BOOL CanBeAppliedToNode(NodeRenderableInk* pObject, 00295 NodeAttribute* Attrib, List* pAttrGroups); 00296 00297 00298 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00299 // Fns which deal with current attributes 00300 // 00301 00302 BOOL ApplyCurrentAttribsToNode(NodeRenderableInk* Node); 00303 // This is the fn that people call prior to DoInserting a new object into the tree 00304 // it attaches the current attributes from the attribute group associated with the object. 00305 00306 NodeAttribute* GetSelToolCurrentAttribute(CCRuntimeClass* AttrType); 00307 00308 NodeAttribute* GetCurrentAttribute(CCRuntimeClass* AttrGroup, 00309 CCRuntimeClass* AttrType); 00310 00311 void GetCurrentLineAndFillColour(CCRuntimeClass* AttrGroup, DocColour* LineCol, 00312 DocColour* FillCol); 00313 00314 BOOL WriteCurrentAttributes(BaseCamelotFilter* pFilter); 00315 00316 private: 00317 00318 // Internal fns for creating / accessing attribute groups 00319 00320 BOOL CreateCurrentAttributeGroup(CCRuntimeClass* AttrGroup, CCRuntimeClass* BaseGroup, 00321 String_256& GrpName); 00322 // Creates a CurrentAttributeGroup ( Called from InitInstance) 00323 00324 NodeAttribute* UpdateCurrentAttribute(CCRuntimeClass* AttrGroup, 00325 NodeAttribute* Attribute, 00326 BOOL fCheckTransparency = TRUE, 00327 BOOL DefiningGroups = FALSE, 00328 BOOL TellWorld = TRUE, 00329 BOOL bForceNewValue = FALSE); 00330 // Adds attribute to specified group 00331 00332 AttributeGroup* GetAttributeGroup(CCRuntimeClass* GroupID); 00333 // Returns pointer to attribute group 00334 00335 void AddAttributeToGroup(AttributeGroup* pAttrGroup, NodeAttribute* Attribute, 00336 BOOL fCheckTransparency, 00337 BOOL TellWorld = TRUE, 00338 BOOL bRetainValues = FALSE); 00339 // Helper function for UpdateCurrentAttribute 00340 00341 BOOL WriteCurrentAttributeGroupRecord(BaseCamelotFilter* pFilter, AttributeGroup* pGroup); 00342 00343 public: 00344 00345 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00346 // Functions to handle default attributes (maintained globally) 00347 // (Tim's stuff) 00348 00349 static void FindDefaultColour(ColourList *ColList, UINT32 NameResID, DocColour *Result); 00350 00351 static UINT32 RegisterDefaultAttribute(CCRuntimeClass *pNodeType, AttributeValue *pValue); 00352 // Pass in a default attribute value object, and it returns the unique ID allocated 00353 // for that attribute. 00354 00355 static AttributeEntry *GetDefaultAttributes(); 00356 // Get an array of default attribute entries. 00357 00358 static NodeAttribute* GetDefaultAttribute(AttrIndex AttrID); 00359 static AttributeValue* GetDefaultAttributeVal(AttrIndex AttrID); 00360 // Added by Ilan 00361 00362 static BOOL GetDefaultAttribute(AttrIndex aiToGet, AttributeValue* pavReturn); 00363 //Added by Graham 25/3/97 00364 //Get a particular default attribute (e.g. the default Web Address attribute) 00365 00366 static UINT32 GetNumAttributes(); 00367 // Find out how many attributes have been registered. 00368 00369 static BOOL ApplyBasedOnDefaults(Node *Target, AttributeEntry *AttrsToApply); 00370 // Given a set of attributes, apply the ones that differ from the defaults to the node. 00371 // Used in the filters 00372 00373 00374 00375 00376 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00377 // Other fns 00378 00379 void UpdateForDeletedColours(ColourList *ParentList); 00380 // Ensures no current attributes are using deleted colours. 00381 // Called by the ColourManager when colour lists change. 00382 // Nobody else should call it! 00383 00384 static NodeAttribute* GetOtherAttrToApply(NodeAttribute* AttrApplied, BOOL* IsMutate); 00385 // Will's magic 00386 00387 public: 00388 00389 // Attribute application preference vars 00390 static BOOL LastAttrAppliedBecomesCurrent; 00391 static BOOL AskBeforeSettingCurrentAttr; 00392 00393 static BOOL ShouldAskAboutContoneColours; 00394 static BOOL HaveAskedAboutContoneColours; 00395 static BOOL UserCancelledContoneColours; 00396 00397 static BOOL SendMessages; 00398 00399 static DocColour DefaultBlack; 00400 static DocColour DefaultWhite; 00401 00402 static NodeRenderableInk* pLastNodeAppliedTo; 00403 static DocRect LastAppliedBounds; 00404 00405 private: 00406 static BOOL RegisterBasicAttributes(); 00407 static BOOL EnsureTableSpaceAvailable(); 00408 00409 List AttrGroupList; 00410 // Contains a list of all current attribute groups 00411 00412 static AttributeEntry *DefaultAttrValues; 00413 // Array of default attributes. 00414 00415 static NodeTypeEntry *DefaultNodeAttrs; 00416 // Array of default NodeAttributes. 00417 00418 static UINT32 NumAttributes; 00419 // Number of attributes that have been registered. 00420 00421 static UINT32 AttributeTableSize; 00422 // Size of the attribute table(s). 00423 00424 }; 00425 00426 /******************************************************************************************** 00427 00428 > class CurrentAttrChangedMsg: public Msg 00429 00430 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00431 Created: 15/8/94 00432 Purpose: This message is sent whenever the current attributes are updated. 00433 SeeAlso: - 00434 00435 ********************************************************************************************/ 00436 00437 class CurrentAttrChangedMsg: public Msg 00438 { 00439 CC_DECLARE_DYNAMIC(CurrentAttrChangedMsg); 00440 public: 00441 00442 CurrentAttrChangedMsg() { } 00443 }; 00444 00445 /******************************************************************************************** 00446 00447 > class CommonAttributeItem: public ListItem 00448 00449 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00450 Created: 3/8/94 00451 Purpose: This ListItem is used by Range::FindCommonAttributes. 00452 00453 SeeAlso: NodeRenderableInk::FactorOutCommonAttributes 00454 SeeAlso: Range::FindCommonAttributes 00455 SeeAlso: CommonAttributeSet 00456 00457 ********************************************************************************************/ 00458 00459 class CommonAttributeItem: public ListItem 00460 { 00461 00462 public: 00463 CommonAttributeItem(CCRuntimeClass* AtrType, NodeAttribute* pAttrib=NULL, 00464 Range::CommonAttribResult status = Range::ATTR_NONE) 00465 { AttrType = AtrType; pAttr = pAttrib; Status = status; pAttrIsCopy = FALSE; }; 00466 00467 ~CommonAttributeItem(); 00468 00469 00470 // Initialiser method for creating a CommonAttributeTypeItem with a copy of the pAttrib 00471 // This is useful if CommonAttributeItems are cached. 00472 BOOL InitSafeAttrItem(CCRuntimeClass* AtrType, NodeAttribute* pAttrib=NULL, 00473 Range::CommonAttribResult status = Range::ATTR_NONE); 00474 00475 // Clears the CommonAttrItem's result fields 00476 void ClearResults() { if (pAttrIsCopy && pAttr) 00477 delete pAttr; 00478 pAttr = NULL; 00479 Status = Range::ATTR_NONE; }; 00480 00481 CCRuntimeClass* AttrType; // The RuntimeClass of the attribute 00482 NodeAttribute* pAttr; // A pointer to an instance of an attribute with AttrType 00483 // Runtime class - can be NULL 00484 00485 Range::CommonAttribResult Status; // One of the following values:- 00486 00487 // ATTR_COMMON - pAttr will point at an instance of the 00488 // common attribute 00489 00490 // ATTR_NONE - There is no common attribute, cos there were 00491 // no items in the range, or none of the items 00492 // required the attribute. In this situation 00493 // pAttr points at the current attribute for 00494 // the selected tool. This is useful cos it's 00495 // the attribute you would display in this 00496 // situation. 00497 00498 // ATTR_MANY - There is no common attribute, cos 2 or more 00499 // objects had different attributes of type 00500 // AttrType.in this situation pAttr will be NULL. 00501 // In this situation 'MANY' would normally be 00502 // displayed. 00503 private: 00504 BOOL pAttrIsCopy; // Is pAttr a pointer to an attribute, or a copy. If it is a 00505 // copy then it is the responsibility of the CommonAttributeItem's 00506 // destructor to destroy it. 00507 00508 }; 00509 00510 00511 #endif