InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ISnapTo.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Paul Sorrick
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __ISNAPTO__
25 #define __ISNAPTO__
26 
27 #include "PMTypes.h"
28 #include "PMPoint.h"
29 #include "PMRect.h"
30 #include "PMMatrix.h"
31 
32 //----------------------------------------------------------------------------------------
33 // Forward Declarations
34 //----------------------------------------------------------------------------------------
35 
36 class IControlView;
37 class PMPoint;
38 class IHierarchy;
39 class UIDList;
40 class IPathGeometry;
41 
42 //----------------------------------------------------------------------------------------
43 // ISnapTo: Abstract interface for doing snap to
44 //----------------------------------------------------------------------------------------
45 
46 typedef int32 SnapFlags;
47 typedef int32 SnapType;
48 const PMReal kInvalidSnapValue = 10000000.0;
49 
50 class ISnapTo : public IPMUnknown
51 {
52  public:
53 
54  // Snapping flags for SnapFlags data type.
55  enum
56  {
57  kSnapNothing = 0x0000, // Snap to nothing
58  kSnapRulerGuides = 0x0001, // Snap to ruler guides
59  kSnapSmartGuides = 0x0002, // Snap to smart guides
60  kSnapMarginGuides = 0x0004, // Snap to margin guides
61  kSnapColumnGuides = 0x0008, // Snap to column guides on page
62  kSnapPage = 0x0010, // Snap to page outline (and pasteboard)
63  kSnapGrid = 0x0020, // Snap to drawing grid
64  kSnapBaselineGrid = 0x0040, // Snap to baseline grid
65  kSnapRulerTickmarks = 0x0080, // Snap to ruler tick marks (ruler guides w/ shift key)
66  kSnapSelection = 0x0100, // Snap to selection (reference point)
67  kSnapAllGuides = kSnapRulerGuides + kSnapMarginGuides + kSnapColumnGuides + kSnapSmartGuides,
68  kSnapAllGrids = kSnapGrid + kSnapBaselineGrid,
69  kSnapAllPageMarks = kSnapAllGuides + kSnapAllGrids + kSnapPage,
70  };
71 
72  // Snapping values for SnapType data type.
73  enum
74  {
75  kSnapNone = 0x00000000, // No snapping in any direction
76  kSnapX = 0x00000001, // Snap along x direction within a test area
77  kSnapY = 0x00000002, // Snap along y direction within a test area
78  kSnapXandY = kSnapX + kSnapY, // Typical case, snap along x or y coordinate hit within a test area
79  kSnapAnyX = 0x00000004, // When doing x coordinate snapping, snap along any x coordinate hit (e.g. vertical ruler guide), not just within the test area. Typically specified along with kSnapX.
80  kSnapAnyY = 0x00000008, // When doing y coordinate snapping, snap along any y coordinate hit (e.g. horizonal ruler guide), not just within the test area. Typically specified along with kSnapY.
81  kSnapAllX = 0x00000004 + kSnapX, // Snap along all x coordinates hit. Use for point tracking such as guide tracking where client wants snapping along an entire x line.
82  kSnapAllY = 0x00000008 + kSnapY, // Snap along all y coordinates hit. Use for point tracking such as guide tracking where client wants snapping along an entire y line.
83  kSnapAllXandY = kSnapAllX + kSnapAllY,// Snap along all x or y coordinates hit. Use for point tracking such as zero point tracking where client wants snapping along an entire x/y crosshair line.
84  kSnapInvalid = 0x00000010, // Invalid state
85  kSnapSkipCenters = 0x00000020 // For gap tool, don't snap to the centers in x or y
86  };
87 
88  // Method to Initialize the snapping code. Should be called before SetSnapFlags to
89  // clear old settings. Automatically called in trackers derived from CTracker.
90  virtual void Init(IControlView* theView) = 0;
91 
92  // Methods to get/set item list of items being moved.
93  // List is empty when not moving objects (e.g. resizing, creating a page item)
94  virtual const UIDList* GetItemList() const = 0;
95  virtual void SetItemList(const UIDList& itemList) = 0;
96 
97  // Methods to get/set initial point DoSnapTo is called with (usually a mouse point)
98  virtual const PMPoint& GetInitialPoint() const = 0;
99  virtual void SetInitialPoint(const PMPoint& initialPoint) = 0;
100 
101  // Methods to get/set the current point index of point passed to ISnapTo::DoSnapToPoint, ISnapToService::FindSnapPoint
102  // There are two variations. The first is the point index adjusted for the items transformation.
103  // The second is the items actual point index.
104  virtual const PMRect::PointIndex GetPointIndex() const = 0;
105  virtual void SetPointIndex(const PMRect::PointIndex pointIndex) = 0;
106 
107  virtual const PMRect::PointIndex GetActualPointIndex() const = 0;
108  virtual void SetActualPointIndex(const PMRect::PointIndex pointIndex) = 0;
109 
110  // Methods to get/set whether snapping is currently enabled for this tracker.
111  virtual bool16 GetSnappingEnabled() const = 0;
112  virtual void SetSnappingEnabled(bool16 enabled) = 0;
113 
114  // Get/Set methods for what snapping flags are currently set (what we are snapping to)
115  virtual SnapFlags GetSnapFlags() const = 0;
116  virtual void SetSnapFlags(IControlView* theView, SnapFlags flags) = 0;
117 
118  // Get/Set the type for desired x or y direction(s) snapping. Used for calls to DoSnapTo in CTracker.cpp.
119  virtual SnapType GetSnapType() const = 0;
120  virtual void SetSnapType(SnapType flags) = 0;
121 
122  // Method to actually do snapping. Returns how the point/rect was snapped.
123  virtual SnapType DoSnapTo(IControlView* theView, // View to snap in
124  PMPoint& thePoint, // Point to snap (or mouse point when snapping a rect)
125  PMRect* theRect = nil, // Rectangle to snap, used when moving objects
126  SnapType snapType = kSnapXandY) = 0;// How to snap the point(s)
127 
128  // Sub methods called from DoSnapTo based on point or rect.
129  // These methods call each method below if its flag is turned on.
130  // Returns how the point was snapped.
131  virtual SnapType DoSnapToPoint(IControlView* theView, // View to snap in
132  PMPoint& thePoint, // Point to snap
133  PMRect* theRect, // Rect being snapped (might be nil)
134  SnapType snapType = kSnapXandY) = 0; // How to snap the point
135 
136  // Returns how the rect was snapped.
137  virtual SnapType DoSnapToRect(IControlView* theView, // View to snap in
138  PMPoint& thePoint, // Mouse point at time of call to DoSnapTo
139  PMRect* theRect, // Rectangle being snapped
140  SnapType snapType = kSnapXandY) = 0; // How to snap the rectangle
141 
142  // Various types of snapping, called when the corresponding flag is set. Returns how the point was snapped.
143  virtual SnapType SnapToRulerTickmarks(IControlView* theView, PMPoint& thePoint, SnapType snapType = kSnapXandY) = 0;
144  virtual SnapType SnapToRulerGuides(IControlView* theView, PMPoint& thePoint, SnapType snapType = kSnapXandY) = 0;
145  virtual SnapType SnapToMarginGuides(IControlView* theView, PMPoint& thePoint, SnapType snapType = kSnapXandY) = 0;
146  virtual SnapType SnapToColumnGuides(IControlView* theView, PMPoint& thePoint, SnapType snapType = kSnapX) = 0;
147  virtual SnapType SnapToGrid(IControlView* theView, PMPoint& thePoint, SnapType snapType = kSnapXandY) = 0;
148  virtual SnapType SnapToBaselineGrid(IControlView* theView, PMPoint& thePoint, SnapType snapType = kSnapY) = 0;
149  virtual SnapType SnapToPage(IControlView* theView, PMPoint& thePoint, SnapType snapType = kSnapY) = 0;
150 
151  // Method used when collecting guides on the page and master page.
152  // Used privately within a callback within SnapToRulerGuides to collect guides.
153  virtual void Add( const PMMatrix &rXform, IHierarchy *pPageItem ) = 0;
154 
155  // Helper methods
156  virtual bool16 MouseOverPage(IControlView* theView, PMPoint& thePoint, PMRect& pageRect, int32& pageIndex) = 0;
157 
158  // Performance Optimization for Layout view dragging:
159  // LayoutWidget asks SnapTo client to decide if a particular mouse move should trigger snapping
160  // Default behavior is to only snap when mouse movement is relatively slow - otherwise the hittest overhead can slow down the drag appreciably
161  enum eShouldSnap
162  {
163  kShouldSnapDrag_UseDefault = -1, // Use default behavior of layoutView (only snaps when movement is "slow")
164  kShouldSnapDrag_No = 0, // Do not snap this time
165  kShouldSnapDrag_Yes = 1 // Do snapping
166  };
167 
168  // Should snap at this time? Return kShouldSnapDrag_UseDefault to get pre-2.0 behavior.
169  virtual eShouldSnap ShouldSnapDragOverLayoutView(IControlView* layoutView, // View to snap in
170  const PMPoint& thePoint, // Raw mouse point
171  const PMPoint& theConstrainedPoint, // Constrained mouse point
172  const PMPoint& thePreviousPoint, // Previous raw mouse point
173  const PMReal zoomFactor, // zoom factor of layout view
174  const PMRect& theRect) const = 0; // item bounds
175 
176 };
177 
178 #endif