00001 // $Id: colormgr.h 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 00099 // colormgr.h - Centralised colour management class 00100 00101 #ifndef INC_COLORMGR 00102 #define INC_COLORMGR 00103 00104 #include "colourix.h" 00105 #include "collist.h" 00106 //#include "pump.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 //#include "undoop.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00108 #include "colmsg.h" 00109 //#include "xaracms.h" 00110 00111 class Document; 00112 class AttrFillGeometry; 00113 class AttrStrokeColour; 00114 00115 00116 /******************************************************************************************** 00117 00118 > class ColourManager : public MessageHandler 00119 00120 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00121 Created: 11/5/94 00122 Purpose: This class provides miscellaneous shared functions for use by 00123 various colour entities. The provided functions are currently: 00124 00125 * Determine the current colour list 00126 00127 This is the Indexed Colour list for the SelectedDocument 00128 (if any). It is displayed by the colour bar, and/or edited 00129 by the Colour Manager Dialogue. 00130 00131 * Find a suitable global or document-specific colour context to use 00132 00133 * Handle colour system state changes 00134 00135 Messages are sent whenever the current list changes. 00136 This happens when: 00137 00138 1) A colour is inserted/deleted/edited in the 00139 SelectedDocument, 00140 00141 2) The SelectedDocument changes, 00142 00143 3) The Colour List is deselected (i.e. when there is 00144 no SelectedDocument, there is no available list) 00145 00146 These messages allow the colour manager dialogues and 00147 colour bar (and other clients) to update their contents 00148 (or hide, etc) when such changes occur. 00149 00150 Other processing (invalidating colour caches, etc) may 00151 also occur in some cases. This is all handled internally by 00152 the ColourManager. 00153 00154 * Copy or create new colours 00155 00156 * Find "Useful" colours for the editor to edit and the colour 00157 line/gallery to display. 00158 00159 * Miscellaneous other useful functions. See colormgr.h for details 00160 of currently available functions 00161 00162 00163 SeeAlso: ColourBar; ColourMgrDlg; ColourChangingMsg; ColourList 00164 Documentation: HowToUse\colours95.doc 00165 00166 ********************************************************************************************/ 00167 00168 class ColourManager : public MessageHandler 00169 { 00170 CC_DECLARE_DYNAMIC( ColourManager ) 00171 00172 public: // Initialisation/Deinitialisation 00173 ColourManager(); 00174 00175 static BOOL Init(void); 00176 static void Deinit(void); 00177 // Initialisation/DeInitialisation of the colour systems 00178 00179 00180 public: // Finding an appropriate ColourList or ColourContext to use 00181 static ColourList *GetColourList(BOOL InvalidateCache = FALSE); 00182 // ColourList for the SELECTED doc 00183 00184 static ColourList *GetCurrentColourList(void); 00185 // ColourList for the CURRENT doc (eek!) 00186 00187 static ColourContext *GetColourContext(ColourModel Model, Document *ScopeDocument = NULL); 00188 static ColourContext *GetColourContext(ColourModel Model, View *ScopeView); 00189 // Find an appropriate global or document/view-specific colour context 00190 00191 static void SelViewContextHasChanged(void); 00192 // Cause a redraw of the selected view, plus the colour editor, line, gallery, 00193 // etc, via a broadcast of ColourChangingMsg::SELVIEWCONTEXTCHANGED 00194 00195 00196 public: // System notification veneers 00197 static void ColourHasChanged(Document *ScopeDoc, ColourList *ColList, IndexedColour *Col); 00198 static void ColourHasChangedInvisible(Document *ScopeDoc, ColourList *ColList, 00199 IndexedColour *Col); 00200 // Broadcast the fact that a colour has changed 00201 00202 static void ColourListHasChanged(ColourList *ColList); 00203 // Broadcast the fact that a colour list has changed 00204 00205 static BOOL HideColours(ColourList *ColList, IndexedColour **ColourArray, 00206 BOOL ForceDelete); 00207 // Hide (delete-with-undo) all colours in a given NULL terminated list 00208 00209 static BOOL UnHideColours(ColourList *ColList, IndexedColour **ColourArray); 00210 // Unhide (undelete/create-with-undo) all colours in a given NULL terminated list 00211 00212 static BOOL ChangeColour(ColourList *ColList, 00213 IndexedColour *NewDefn, IndexedColour *Target, 00214 BOOL ChangeisInvisible = FALSE); 00215 // Change a colour's definition, with undo 00216 00217 static void ForceRedrawOfChangedColours(Document *ScopeDoc, IndexedColour **Colours); 00218 // Force redraw any portions of the document which reference any of the 00219 // given NULL-terminated list of IndexedColours 00220 00221 00222 public: // Colour copying/creation 00223 static IndexedColour *GenerateNewNamedColour(ColourList *ParentList, 00224 IndexedColour *SourceColour); 00225 // Create a new named IndexedColour, copying the definition from the SourceColour, 00226 // or from the current Fill Colour attribute, if possible. 00227 00228 static IndexedColour *GenerateNewUnnamedColour(ColourList *ParentList, 00229 DocColour *SourceColour); 00230 // Creates a new unnamed colour, taking its definition from the given DocColour 00231 // (which may well reference an IndexedColour). The new colour will be automatically 00232 // added to the given colour list, and will be auto-deleted when no longer in use 00233 00234 static void EnsureColourIsInDocument(Document *SourceDoc, Document *DestDoc, 00235 DocColour *SourceAndResultCol); 00236 // Ensures that the given colour is safe to use in the given document. Possibly 00237 // copies the parent colour and redirects the given DocColour to the copy in the 00238 // dest document in order to ensure that you are safe. 00239 00240 00241 public: // Finding current/useful colours 00242 static BOOL GetCurrentLineAndFillAttrs(AttrStrokeColour **LineAttr, 00243 AttrFillGeometry **FillAttr); 00244 // Finds the current fill/stroke attributes (semi-internal use only - see below) 00245 00246 static BOOL GetCurrentLineAndFillColours(DocColour **LineCol, DocColour **FillCol, 00247 DocColour **EndGradFill = NULL); 00248 // Finds the current fill/stroke colours, if any. If EndGradFill is non-NULL, then 00249 // grad fills will return start and end colours if both selected. 00250 00251 static void FindColourOfInterestToUser(IndexedColour **ResultCol, 00252 ColourList **ResultList = NULL); 00253 static void FindColourOfInterestToUser(DocColour *ResultCol, 00254 ColourList **ResultList = NULL, 00255 BOOL WantLineColour = FALSE); 00256 // Finds the colour (if any) which is of most "interest" to the user. 00257 // That is, sortof the 'current' colour which should be shown in the colour 00258 // editor, and used to copy new colours from, etc. This is a colour from a 00259 // weird selecion including colour of selected fill blobs, objects in the 00260 // selection, current colours, etc. Just trust me. Can return NULL/NULL. 00261 00262 00263 protected: 00264 static ColourList *CurrentColourList; 00265 static Document *ScopeDocument; 00266 00267 protected: 00268 MsgResult Message(Msg* Msg); // Overridden message reciever 00269 }; 00270 00271 00272 00273 00274 00275 00276 /******************************************************************************************** 00277 00278 > class OpHideColours: public UndoableOperation 00279 00280 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00281 Created: 3/6/94 00282 Purpose: An operation which will delete 00283 00284 Scope: Private - for use only by the ColourManager 00285 00286 SeeAlso: ActionHideColours; 00287 ColourManager::HideColours; ColourManager::UnHideColours 00288 00289 ********************************************************************************************/ 00290 00291 00292 // Structure for passing the data indicating what the Op is expected to do 00293 typedef struct 00294 { 00295 ColourList *ParentList; // The ColourList in which the colours reside 00296 IndexedColour **Colours; // Pointer to NULL terminated list of (IndexedColour *)'s 00297 BOOL HideThem; // TRUE to hide, FALSE to unhide, the colours 00298 BOOL ForceDelete; // TRUE = Forcibly delete all colours in the list 00299 // FALSE = Only delete colours not in use 00300 } HideColoursInfo; 00301 00302 00303 00304 00305 #define OPTOKEN_HIDECOLOURS _T("DeleteColours") // Optoken for the Colour hiding operation 00306 #define OPTOKEN_SHOWCOLOURS _T("CreateColours") // Optoken for the Colour unhiding operation 00307 00308 class CCAPI OpHideColours: public UndoableOperation 00309 { 00310 CC_DECLARE_DYNCREATE( OpHideColours ) 00311 00312 public: 00313 OpHideColours(); 00314 static BOOL Init(); 00315 static OpState GetState(String_256*, OpDescriptor*); 00316 void Do(OpDescriptor *); 00317 void DoWithParam(OpDescriptor *, OpParam *Param); 00318 00319 virtual BOOL Undo(); 00320 virtual BOOL Redo(); 00321 virtual void GetOpName(String_256*); 00322 00323 00324 private: 00325 IndexedColour **Colours; // Pointer to NULL terminated list of IndexedColourPtrs 00326 ColourList *ParentColList; // Pointer to the colour list in which these colours reside 00327 BOOL HideThem; // TRUE if we're a "delete colours" op, FALSE if we're a "create colours" 00328 00329 private: 00330 NodeAttribute *HideAttrNode(Node *CurNode, DocColour *TheColour); 00331 void KillColourRef(DocColour *Perpetrator, IndexedColourPtr *ColourMap); 00332 void HideColourRefs(void); 00333 00334 void RemoveColour(DocColour *Ref, INT32 *LastColour); 00335 void RemoveReferencedColours(void); 00336 }; 00337 00338 00339 00340 /******************************************************************************************** 00341 00342 > class ActionHideColours: public Action 00343 00344 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00345 Created: 3/6/94 00346 Purpose: When executed, sets/clears an IndexedColour's 'deleted' flag, so that 00347 it becomes {un}hidden - this is then un/redoable by using a HideAction with 00348 the opposite 'HideFlag' value. 00349 00350 Scope: Private - for use only by the ColourManager 00351 00352 SeeAlso: OpHideColours 00353 00354 ********************************************************************************************/ 00355 00356 class CCAPI ActionHideColours : public Action 00357 { 00358 CC_DECLARE_DYNCREATE( ActionHideColours ) 00359 00360 public: 00361 ActionHideColours(); 00362 ~ActionHideColours(); 00363 00364 virtual void Slaughter(void); 00365 virtual ActionCode Execute(); 00366 00367 static ActionCode Init(Operation* const pOp, 00368 ActionList* pActionList, 00369 UINT32 ActionSize, 00370 ColourList *ParentList, // ColourList in which the cols reside 00371 IndexedColour* Colour[], // NULL terminated list of colours 00372 // to be processed 00373 BOOL HideThem, // TRUE = Hide, FALSE = UnHide 00374 Action** NewAction); 00375 00376 private: 00377 ColourList *ParentList; // The list in which the colours reside 00378 IndexedColour **ChangeColour; // The Colours to change 00379 BOOL HideFlag; // How to change them (Hide/UnHide) 00380 }; 00381 00382 00383 00384 00385 00386 00387 00388 00389 /******************************************************************************************** 00390 00391 > class OpColourChange: public UndoableOperation 00392 00393 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00394 Created: 3/6/94 00395 Purpose: This class represents the ColourChange operation which is created by the 00396 ColourManager to make changes to the definition of an IndexedColour. This 00397 allows edits of an IndexedColour to be undone/redone. 00398 00399 Scope: Private - for use only by the ColourManager 00400 00401 SeeAlso: ActionColourChange; 00402 00403 ********************************************************************************************/ 00404 00405 #define OPTOKEN_COLOURCHANGE _T("ColourChange") // Optoken for the Colour change operation 00406 00407 00408 typedef struct 00409 { 00410 ColourList *ParentList; // The list in which the change is taking place 00411 IndexedColour *NewDefn; // The new definition of the colour (undo record) 00412 IndexedColour *Target; // The colour to be changed (redo record) 00413 BOOL InvisibleChange; // The change is 'visible' (should cause redraw of 00414 // objects coloured in this colour) 00415 } ColourChangeInfo; 00416 00417 00418 00419 class CCAPI OpColourChange: public UndoableOperation 00420 { 00421 CC_DECLARE_DYNCREATE( OpColourChange ) 00422 00423 public: 00424 OpColourChange(); 00425 ~OpColourChange(); 00426 00427 static BOOL Init(); 00428 static OpState GetState(String_256 *, OpDescriptor *); 00429 void Do(OpDescriptor *); 00430 void DoWithParam(OpDescriptor *, OpParam *); 00431 00432 virtual void PerformMergeProcessing(void); 00433 00434 virtual BOOL Undo(); 00435 virtual BOOL Redo(); 00436 00437 protected: 00438 IndexedColour *UndoRecord; // We 'own' the UndoRecord & are responsible for deleting it 00439 IndexedColour *RedoRecord; // We do not own the redo record - it is just useful info 00440 // for operation merging purposes 00441 }; 00442 00443 00444 00445 /******************************************************************************************** 00446 00447 > class ActionColourChange: public Action 00448 00449 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00450 Created: 3/6/94 00451 Friends: OpColourChange 00452 00453 Purpose: When executed, this copies the IndexedColour 'Defn' over the top of 00454 the IndexedColour 'Target', so that Target is redefined. This is used 00455 to undo/redo colour edits. A flag 'ChangeIsinvisible' is used to tell 00456 whether to broadcast a ColourChangingMsg COLOURUPDATED or 00457 COLOURUPDATEDINVISIBLE when the change is applied. 00458 00459 Scope: Private - for use only by the ColourManager 00460 00461 SeeAlso: OpColourChange 00462 00463 ********************************************************************************************/ 00464 00465 class CCAPI ActionColourChange : public Action 00466 { 00467 CC_DECLARE_DYNCREATE( ActionColourChange ) 00468 00469 friend class OpColourChange; // Allows the Op's merging code to alter 'IsInvisible' 00470 00471 public: 00472 ActionColourChange(); 00473 ~ActionColourChange(); 00474 virtual ActionCode Execute(); 00475 static ActionCode Init(Operation* const pOp, 00476 ActionList *pActionList, 00477 UINT32 ActionSize, 00478 IndexedColour *TheTarget, 00479 IndexedColour *TheNewDefn, 00480 BOOL ChangeIsInvisible, 00481 Action **NewAction); 00482 00483 protected: 00484 BOOL IsInvisible; 00485 00486 private: 00487 IndexedColour *Target; 00488 IndexedColour *NewDefn; 00489 }; 00490 00491 00492 00493 00494 00495 /******************************************************************************************** 00496 00497 > class OpRedrawColours: public UndoableOperation 00498 00499 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00500 Created: 24/1/96 00501 00502 Purpose: This non-undoable operation is used by the colour manager to redraw all 00503 nodes of the document which have been affected by changes to a colour or 00504 colours. 00505 00506 It achieves this by doing an AllowOp pass over the document tree, marking 00507 all affected nodes, then causing a redraw of the marked nodes. 00508 00509 Scope: Private - for use only by the ColourManager 00510 00511 SeeAlso: ColourManager::ForceRedrawOfChangedColours 00512 00513 ********************************************************************************************/ 00514 00515 typedef struct 00516 { 00517 Document *ScopeDoc; 00518 IndexedColour **Colours; 00519 } OpRedrawColoursInfo; 00520 00521 00522 #define OPTOKEN_REDRAWCOLOURS _T("RedrawColours") // Optoken for the RedrawColours operation 00523 00524 class CCAPI OpRedrawColours : public Operation 00525 { 00526 CC_DECLARE_DYNCREATE( OpRedrawColours ) 00527 00528 public: 00529 OpRedrawColours(); 00530 ~OpRedrawColours(); 00531 00532 static BOOL Init(); 00533 static OpState GetState(String_256 *, OpDescriptor *); 00534 void Do(OpDescriptor *); 00535 void DoWithParam(OpDescriptor *, OpParam *); 00536 }; 00537 00538 00539 #endif 00540 00541