00001 // $Id: slicetool.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 // Header for the Slice tool implementation 00099 00100 #ifndef INC_SLICETOOL 00101 #define INC_SLICETOOL 00102 00103 #define OPTOKEN_SLICE_DRAGBOX _T("SliceDragBox") 00104 #define OPTOKEN_SLICE_TRANSLATE _T("SliceTranslate") 00105 00106 #include "dragtool.h" 00107 //#include "doccoord.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00108 //#include "bars.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 #include "selector.h" // to derive OpSliceDragBox from OpSelectorDragBox. 00110 #include "ngscan.h" // to derive CompileCollisionBoxScan from NodeScan. 00111 //#include "listitem.h" // to derive RectList from List. - in camtypes.h [AUTOMATICALLY REMOVED] 00112 //#include "list.h" // for List. - in camtypes.h [AUTOMATICALLY REMOVED] 00113 //#include "docrect.h" // for DocRect. - in camtypes.h [AUTOMATICALLY REMOVED] 00114 #include "transop.h" // to derive OpSliceTranslate from TransOperation. 00115 00116 class Cursor; 00117 class Spread; 00118 class SliceInfoBarOp; 00119 00120 00121 00122 /******************************************************************************************** 00123 00124 > class SliceTool : public DragTool 00125 00126 Author: Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com> / Simon Knight 00127 Created: September 1999 00128 Purpose: SliceTool is actually a misnomer. 00129 This tool is used for creating rollover buttons and bars for web pages. 00130 00131 ********************************************************************************************/ 00132 class CCAPI SliceTool : public DragTool 00133 { 00134 // Give tool name in memory dumps 00135 CC_DECLARE_MEMDUMP(SliceTool); 00136 00137 friend class OpSliceDragBox; 00138 friend class OpSliceTranslate; 00139 00140 public: 00141 SliceTool(); 00142 virtual ~SliceTool(); 00143 00144 // Standard calls your tool must provide 00145 virtual BOOL Init(); 00146 virtual void Describe(void* InfoPtr); 00147 virtual UINT32 GetID() { return TOOLID_SLICETOOL; }; 00148 00149 // called by our infobar to send us view-change messages. 00150 void ViewChanged(const DocViewMsg& msg); 00151 00152 // Render some tool blobs for us. 00153 virtual void RenderToolBlobs(Spread* pSpread, DocRect* pClipRect); 00154 00155 // my tool blobs _are_ rendered on the selection, thank you very much :o) 00156 virtual BOOL AreToolBlobsRenderedOnSelection() { return TRUE; } 00157 00158 00159 // Some very common event handlers 00160 virtual void SelectChange(BOOL isSelected); 00161 virtual void OnClick( DocCoord, ClickType, ClickModifiers, Spread* ); 00162 virtual BOOL OnKeyPress(KeyPress* pKey); 00163 virtual void OnMouseMove(DocCoord PointerPos,Spread* pSpread, ClickModifiers ClickMods); 00164 virtual BOOL GetStatusLineText(String_256* ptext, Spread* pSpread, DocCoord DocPos, ClickModifiers ClickMods); 00165 00166 // Called when the view or selection changes. 00167 virtual void SelectionHasChanged(); 00168 00169 // Some useful static functions 00170 static SliceInfoBarOp* GetSliceInfoBarOp() { return pSliceInfoBarOp; } 00171 static BOOL IsCurrentTool() { return CurrentTool; } 00172 00173 protected: 00174 // updates the slice tool's information about the current selection. 00175 virtual BOOL UpdateSelectionInfo(); 00176 00177 // pre-, mid- and post-processing for mouse clicks. 00178 virtual BOOL PreProcessClick(); 00179 virtual BOOL ProcessObjectClick(); 00180 virtual void PostProcessClick(); 00181 virtual NodeRenderableInk* FindPreProcessClickNode( Spread* pSpread, 00182 DocCoord ClickPos, 00183 BOOL Interruptible = FALSE ); 00184 00185 // the SliceTool's mouse-click handlers. 00186 virtual void HandleSingleClick(); 00187 virtual void HandleDoubleClick(); 00188 virtual void HandleDragClick(); 00189 virtual void HandleButtonUp(); 00190 00191 // to let the user tab through the selection. 00192 virtual void HandleTabKey(BOOL bIsShifted); 00193 00194 // feedback functions. 00195 static void SetStatusText(UINT32 nStringID); 00196 static void SetStatusText(String_256* pStr); 00197 virtual void SetKeyDownCursor(ClickModifiers cmMods); 00198 virtual void FigureUserFeedback(Spread* pSpread, 00199 DocCoord dcPos, 00200 ClickModifiers cmods, 00201 BOOL DoSlowTests, 00202 String_256* pStr, 00203 Cursor** ppPointerShape); 00204 BOOL Append(String_256* pStr, UINT32 StringID); 00205 BOOL Append(String_256* pStr, String_256 String); 00206 BOOL Append(String_256* pStr, ClickModifiers cmods, 00207 UINT32 SelectID, 00208 UINT32 AddID, 00209 UINT32 RemoveID, 00210 NodeRenderableInk* pActionNode = NULL); 00211 BOOL Append(String_256* pStr, ClickModifiers cmods, 00212 String_256 SelectTemplate, 00213 String_256 AddTemplate, 00214 String_256 RemoveTemplate, 00215 NodeRenderableInk* pActionNode = NULL); 00216 00217 BOOL IsTranslateShortcut(ClickModifiers cmods) const; 00218 BOOL IsClickModified(ClickModifiers cmods) const; 00219 BOOL IsSelectUnderClick(ClickModifiers cmods) const; 00220 BOOL IsSelectMemberClick(ClickModifiers cmods) const; 00221 BOOL IsSelectLeafClick(ClickModifiers cmods) const; 00222 00223 // drag handling functions. 00224 void DoTranslate(); // mouse-drag transform. 00225 void DoDragBox(); // non-transform drag. 00226 void MakeSelectionValidForDrag(); // checks & may alter the selection, for dragging. 00227 00228 // These provide some shorthand to the FindSimple/FindCompound hit-testing functions in 00229 // NodeRenderableInk. They are "hard-wired" to use the current click position. 00230 NodeRenderableInk* FindFrom(NodeRenderableInk* pSimpleNode) const; 00231 00232 // Forward declaration of click action code... 00233 enum ClickActionCode; 00234 00235 // Determine what action needs to be taken in response to a click 00236 ClickActionCode DetermineClickAction(NodeRenderableInk** ppActionNode, 00237 NodeRenderableInk* pLastClickNode, 00238 NodeRenderableInk* pClickSimpleNode, 00239 NodeRenderableInk* pClickCompoundNode, 00240 Spread* pStartSpread, 00241 DocCoord ClickStart, 00242 ClickModifiers ClickMods); 00243 ClickActionCode CycleClickAction(NodeRenderableInk** ppActionNode, 00244 NodeRenderableInk* pClickCompoundNode, 00245 ClickActionCode foundAction, 00246 ClickActionCode cycleAction); 00247 BOOL ValidateLastClickUnder(NodeRenderableInk* pLastClickNode, Spread* pStartSpread, DocCoord ClickStart); 00248 BOOL ValidateLastClickInside(NodeRenderableInk* pLastClickNode, NodeRenderableInk* pClickSimpleNode); 00249 00251 // 00252 // protected member variables 00253 // 00254 00255 // cursors. 00256 Cursor* pcNormalSliceCursor; 00257 Cursor* pcAdjustCursor; 00258 Cursor* pcUnderCursor; 00259 Cursor* pcInsideCursor; 00260 Cursor* pcUnderAdjustCursor; 00261 Cursor* pcInsideAdjustCursor; 00262 Cursor* pcLeafCursor; 00263 Cursor* pcLeafAdjustCursor; 00264 00265 Cursor* pcALLCursor; 00266 Cursor* pcHorzGuideCursor; 00267 Cursor* pcVertGuideCursor; 00268 00269 // click state variables. 00270 DocCoord ClickStart; 00271 Spread* StartSpread; 00272 ClickModifiers ClickMods; 00273 ClickType TypeOfClick; 00274 00275 // general selection state variables. 00276 Spread* SelectionSpread; 00277 SelRange* SelectRange; 00278 DocRect SelectionRect; 00279 BOOL m_bSliceToolSetSel; 00280 00281 // the rectangle which we use to draw our tool blobs. 00282 DocRect m_drBlobRect; 00283 00284 // select-under state variables. 00285 NodeRenderableInk* pClickSimpleNode; 00286 NodeRenderableInk* pClickCompoundNode; 00287 NodeRenderableInk* pLastClickNode; 00288 NodeRenderableInk* pPreProcClickNode; 00289 00290 // various codes, for modifying click type. 00291 enum ClickActionCode { 00292 CLICKACTION_NONE, 00293 CLICKACTION_SELNONE, 00294 CLICKACTION_SELNODE, 00295 CLICKACTION_SELUNDER, 00296 CLICKACTION_SELUNDERCYCLE, 00297 CLICKACTION_SELUNDERFAIL, 00298 CLICKACTION_SELUNDERFAIL2, 00299 CLICKACTION_SELINSIDE, 00300 CLICKACTION_SELINSIDECYCLE, 00301 CLICKACTION_SELINSIDEFAIL, 00302 CLICKACTION_SELINSIDEFAIL2, 00303 CLICKACTION_SELLEAF 00304 }; 00305 00306 // general description of named sets currently selected. 00307 enum SetSelectionState 00308 { 00309 NoSetsSelected, 00310 HalfSetsSelected, 00311 FullSetsSelected 00312 }; 00313 00314 // what named sets are currently selected. 00315 enum SetSelectionState m_SetSelectionState; 00316 00317 // this must be a member variable, as it is accessed during 00318 // slice-tool drag operation. 00319 TransformBoundingData BoundingData; 00320 00321 // called to notify the tool that a drag has finished, 00322 // so it can tidy up cursors etc. appropriately. 00323 virtual BOOL DragFinished(DragEndType det); 00324 00325 private: 00326 void DisplayStatusBarHelp(DocCoord DocPos, Spread* pSpread, ClickModifiers ClickMods); 00327 void GetCurrentStatusText(String_256* ptext, Spread* pSpread, DocCoord DocPos, ClickModifiers ClickMods); 00328 00329 BOOL CreateCursors(); // Create your tool's cursors in this func 00330 void DestroyCursors(); // Destroy your tool's cursors in this func 00331 00332 static BOOL CurrentTool; // Can be useful to keep a "is my tool current?" flag 00333 static SliceInfoBarOp* pSliceInfoBarOp; // Ptr to your tool's infobar 00334 00335 Cursor* pcCurrentCursor; // The cursor your tool is currently displaying 00336 INT32 CurrentCursorID; // ID of the current cursor you're displaying 00337 // Standard tool static vars 00338 static char* FamilyName; // The Tools Family Name 00339 static char* ToolName; // The Tool Name 00340 static char* Purpose; // What the tool is for 00341 static char* Author; // Who wrote it 00342 00343 // whether we're currently ignoring selchanged messages or not. 00344 BOOL m_fIgnoreSelChange; 00345 }; 00346 00347 00348 //----------------------------------------------- 00349 //----------------------------------------------- 00350 //----------------------------------------------- 00351 //----------------------------------------------- 00352 00353 00354 00355 /******************************************************************************************** 00356 00357 > class SliceInfoBarOp : public InformationBarOp 00358 00359 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00360 Created: 3/10/94 00361 Purpose: Class for handling the tool's information bar. 00362 00363 ********************************************************************************************/ 00364 00365 class TemplateAttribute; 00366 00367 class SliceInfoBarOp : public InformationBarOp 00368 { 00369 CC_DECLARE_DYNCREATE( SliceInfoBarOp ) 00370 public: 00371 SliceInfoBarOp() { m_InfoBarCreated = FALSE; m_TopVisibleState = -1; m_EditingBar = FALSE; pSliceTool = NULL; }; 00372 INT32 FindCurrentState(); // no longer static 00373 00374 BOOL m_InfoBarCreated; // this refers to the info bar confusingly no the bar the info bar makes 00375 00376 MsgResult Message(Msg* Msg); // All messages to the info bar come through here 00377 00378 void OnSelectionChanged(); 00379 static BOOL ScanFromNodeForBarMembers(Node * pNode, String_256 &BarName, String_256 * pButtonName = NULL); 00380 00381 // set the SliceInfoBarOp's SliceTool pointer. 00382 void SetSliceTool(SliceTool* pTool) { pSliceTool = pTool; }; 00383 void UpdateCurrentStateGadget(); 00384 00385 00386 protected: 00387 String_256 GetNextUnusedBarName(Range * pSel, BOOL * pFromSel); 00388 BOOL m_EditingBar; 00389 INT32 m_TopVisibleState; // the state layer that the user can see - ie the one they are most likely to be refering to 00390 00391 // Karim 19/10/1999 - a pointer to the slice tool which is associated with this info-bar. 00392 SliceTool* pSliceTool; 00393 }; 00394 00395 00396 00397 /******************************************************************************************** 00398 00399 > class SliceInfoBarOpCreate : public BarCreate 00400 00401 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00402 Created: 3/10/94 00403 Purpose: Class for creating SliceInfoBarOps. 00404 Derived classes of BarCreate are used by DialogBarOp::ReadBarsFromFile() 00405 00406 ********************************************************************************************/ 00407 00408 class SliceInfoBarOpCreate : public BarCreate 00409 { 00410 public: 00411 DialogBarOp* Create() { return (new SliceInfoBarOp); } 00412 }; 00413 00414 00415 00416 //----------------------------------------------- 00417 //----------------------------------------------- 00418 //----------------------------------------------- 00419 //----------------------------------------------- 00420 00421 00422 00423 /******************************************************************* 00424 00425 > class OpSliceDragBox : public OpSelectorDragBox 00426 00427 Author: Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com> 00428 Created: 11/10/1999 00429 Purpose: Drag box class for the SliceTool. 00430 Allows the user to select a number of named sets, by dragging a box 00431 around some objects on the document. All objects sharing the same names 00432 as those inside the box will then be selected. 00433 00434 NB funnily enough, this class inherits functionality from OpSelectorDragBox. 00435 00436 *******************************************************************/ 00437 class OpSliceDragBox : public OpSelectorDragBox 00438 { 00439 // allow dynamic creation of this class. 00440 CC_DECLARE_DYNCREATE(OpSliceDragBox); 00441 00442 public: 00443 00444 // The all important Do functions 00445 void StartDragBox( Spread* pSpread, DocCoord Anchor, ClickModifiers); 00446 00447 // Virtual function needed for the dragging operations to work 00448 virtual void DragFinished(DocCoord, ClickModifiers, Spread*, BOOL, BOOL bSolidDrag); 00449 00450 // These functions required for the OpDescriptor class 00451 static BOOL Declare(); 00452 static OpState GetState(String_256* Description, OpDescriptor*); 00453 }; 00454 00455 00456 00457 //----------------------------------------------- 00458 //----------------------------------------------- 00459 //----------------------------------------------- 00460 //----------------------------------------------- 00461 00462 00463 00464 class CCAPI RectListItem : public ListItem 00465 { 00466 public: 00467 RectListItem(DocRect source); 00468 DocRect GetRect(); 00469 00470 protected: 00471 DocRect m_Rect; 00472 }; 00473 00474 00475 00476 //----------------------------------------------- 00477 //----------------------------------------------- 00478 //----------------------------------------------- 00479 //----------------------------------------------- 00480 00481 00482 00483 /******************************************************************************************** 00484 00485 > class OpSliceTranslate : public TransOperation 00486 00487 Author: Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>, from Rik's OpTranslateTrans code. 00488 Created: 13/10/1999 00489 Purpose: This is the Slice tool's Translate operation, which is similar in behaviour 00490 to OpTranslateTrans, except that we inform the user during the drag if the 00491 current selection's bounds overlap those of an unselected named set (button). 00492 When doing an immediate transform the params to DoWithParams() are :- 00493 Param1 - All the standard transform data 00494 Param2 - A pointer to a DocCoord that holds to offset translate by. 00495 00496 ********************************************************************************************/ 00497 00498 class OpSliceTranslate : public TransOperation 00499 { 00500 // Give my name in memory dumps 00501 CC_DECLARE_DYNCREATE(OpSliceTranslate); 00502 00503 public: 00504 // Construction/Destruction 00505 OpSliceTranslate(); 00506 00507 // These functions required for the OpDescriptor class 00508 static BOOL Declare(); 00509 virtual BOOL ShouldPointerBeOffset(); 00510 00511 // Entry point to start an interactive version of the transform 00512 virtual void DragStarted( TransformData*, 00513 DragTool*, 00514 TransformBoundingData*, 00515 DocCoord, 00516 Spread*, 00517 ClickModifiers, 00518 DocCoord ClickOffset = DocCoord(0, 0), 00519 Node* NodeToTrans = NULL, 00520 DragType dragtype = DRAGTYPE_AUTOSCROLL ); 00521 virtual void DragFinished(DocCoord, ClickModifiers, Spread*, BOOL, BOOL bSolidDrag); 00522 00523 // render blobs on or off the page. 00524 // Karim MacDonald 07/02/2000; removed - see slicetool.cpp 00525 // virtual void RenderDragBlobs(DocRect ClipRect, Spread* pSpread); 00526 00527 protected: 00528 // Routines for checking bounding-box collisions against 00529 // other named sets during a drag. 00530 void CompileCollisionBoxList(); 00531 BOOL TestBoundingBoxCollision(DocRect* pTestRect, Spread* pSpread); 00532 00533 // snap functionality, so the selection can snap to one of our list of collision rects. 00534 BOOL SnapRectToBoxList(Spread* pSpread, DocRect* pDocRect, const DocCoord& PrevCoord, 00535 const DocCoord& CurCoord); 00536 00537 private: 00538 // Function to help at the start of an immediate transform 00539 virtual void InitTransformImmediate(OpParam*); 00540 00541 // function to build the appropriate transform matrix 00542 virtual void InitTransformOnDrag(DocCoord, ClickModifiers); 00543 virtual void UpdateTransformOnDrag(DocCoord, Spread*, ClickModifiers&); 00544 virtual void BuildMatrix(); 00545 virtual void ConstrainDrag(DocCoord*); 00546 virtual BOOL CanChangeSpread(); 00547 00549 // 00550 // Member Variables 00551 // 00552 00553 protected: 00554 // a list of bounding boxes to collision-detect against. 00555 // I've got a feeling this should really be a RectList or some such thing. 00556 List m_lBoxes; 00557 00558 // state variables, used for rendering collision rectangle blobs if 00559 // the dragged selection hits the bounding box of an unselected named set. 00560 BOOL m_bDrawingBlobs; 00561 DocRect m_DragRect; 00562 00563 private: 00564 DocCoord LastPos; 00565 DocCoord OriginalGridOffset; 00566 }; 00567 00568 00569 00570 #endif // INC_SliceTool