InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MSystemUtils.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: ?
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 __MSystemUtils__
25 #define __MSystemUtils__
26 
27 #include "MSysType.h"
28 #include "ISession.h"
29 #include "WorkspaceID.h"
30 
31 #define MTOOLBOX
32 #define QUICKDRAW
33 #define QUARTZ
34 #define HITOOLBOX
35 
36 inline bool _CheckResultFunc(const char* caller, intptr_t result, intptr_t okResult, const char* codeString, const char* fileStr, int32 lineNo)
37 {
38  ASSERT_MSG(result == okResult, FORMAT_ARGS("%s: %s returned error: %p, called from file: %s at line %d \n", caller, codeString, result, fileStr, lineNo));
39  return result == okResult;
40 }
41 
42 #define MAC_CHECKERROR(err, routinename) ASSERT_MSG(err == noErr, FORMAT_ARGS("%s returned error: %d\n", #routinename, err))
43 //#define MAC_CHECKRESULT(code) {OSStatus err = code; ASSERT_MSG(err == noErr, FORMAT_ARGS("%s returned error: %d\n", #code, err));}
44 #define MAC_CHECKRESULT(code) _CheckResultFunc("MAC_CHECKRESULT", (int32) code, (int32) noErr, #code,__FILE__,__LINE__)
45 
46 
47 // The following macros allow use as l-values
48 #define SysPointH( point ) (point).x
49 #define SysPointV( point ) (point).y
50 
51 inline SysCoord SysRectLeft(const SysRect& sysRect)
52  { return sysRect.origin.x; }
53 inline SysCoord SysRectTop(const SysRect& sysRect)
54  { return sysRect.origin.y; }
55 inline SysCoord SysRectRight(const SysRect& sysRect)
56  { return (sysRect.origin.x + sysRect.size.width); }
57 inline SysCoord SysRectBottom(const SysRect& sysRect)
58  { return (sysRect.origin.y + sysRect.size.height); }
59 inline SysCoord SysRectWidth(const SysRect& sysRect)
60  { return sysRect.size.width; }
61 inline SysCoord SysRectHeight(const SysRect& sysRect )
62  { return sysRect.size.height; }
63 inline SysCoord SysRectCenterH(const SysRect& sysRect)
64  { return int32(sysRect.origin.x + sysRect.size.width/2.); }
65 inline SysCoord SysRectCenterV(const SysRect& sysRect )
66  { return int32(sysRect.origin.y + sysRect.size.height/2.); }
67 
68 // These should not be inlined, since, the new coordinate(s) often contains some combination of existing coordinates.
69 // Also note that thes functions are design for compatibility with rectangles that based on (top,left,bottom,right)
70 // Thus SetSysRectLeft changes both origin.x and size.width of the underlying HIRect...(Beware)
71 #ifdef PUBLIC_BUILD
72 #endif
73  void SetSysRectLeft(SysRect& sysRect, SysCoord left);
74  void SetSysRectTop(SysRect& sysRect, SysCoord top);
75  void SetSysRectRight(SysRect& sysRect, SysCoord right);
76  void SetSysRectBottom(SysRect& sysRect, SysCoord bottom);
77  void SetSysRectWidth(SysRect& sysRect, SysCoord width);
78  void SetSysRectHeight(SysRect& sysRect, SysCoord height);
79  void SetSysRect(SysRect& rect, SysCoord left, SysCoord top, SysCoord right, SysCoord bottom);
80  void SetSysRectLTRB(SysRect& rect, SysCoord left, SysCoord top, SysCoord right, SysCoord bottom);
81  void SetSysRectLTWH(SysRect& rect, SysCoord left, SysCoord top, SysCoord width, SysCoord height);
82 #ifdef PUBLIC_BUILD
83 #endif
84 
85 inline void SetSysPoint(SysPoint& pt, SysCoord x, SysCoord y)
86 {
87  pt.x = x; pt.y = y;
88 }
89 
90 
91 #define SysRgnBBOX( rgn ) GetRegionRect(rgn)
92 inline SysRect GetRegionRect( ConstSysRgn rgn )
93 {
94  SysRect aRect;
95  MTOOLBOX::HIShapeGetBounds(rgn,&aRect);
96  return aRect;
97 }
98 
99 #ifdef PUBLIC_BUILD
100 #endif
101  void GetRegionRectData( ConstSysRgn rgn, std::vector<SysRect>& rectsVec );
102 #ifdef PUBLIC_BUILD
103 #endif
104 
105 inline bool16 SysPointInSysRect( const SysPoint& p, const SysRect& r )
106  { return (MTOOLBOX::CGRectContainsPoint( r, p ) == true); }
107 
108 inline bool16 EmptySysRect( const SysRect& r )
109  { return (MTOOLBOX::CGRectIsEmpty( r ) == true); }
110 
111 inline bool16 IntersectSysRect(const SysRect& src1, const SysRect& src2, SysRect& dst)
112 {
113  dst = MTOOLBOX::CGRectIntersection(src1, src2);
114  if(MTOOLBOX::CGRectIsNull(dst))
115  dst = MTOOLBOX::CGRectMake(0,0,0,0);
116 
117  return (MTOOLBOX::CGRectIsEmpty(dst) != true);
118 }
119 
120 inline void UnionSysRect(const SysRect& src1, const SysRect& src2, SysRect& dst)
121  { dst = MTOOLBOX::CGRectUnion(src1, src2); }
122 
123 inline void InsetSysRect(SysRect& rt, SysCoord deltaX, SysCoord deltaY)
124  { rt = MTOOLBOX::CGRectInset(rt, deltaX, deltaY); }
125 
126 inline void OffsetSysRect(SysRect& rt, SysCoord deltaX, SysCoord deltaY)
127  { rt = MTOOLBOX::CGRectOffset(rt, deltaX, deltaY); }
128 
129 inline void SysRectMakeZeroOrigin(SysRect& rt)
130  { rt = MTOOLBOX::CGRectOffset(rt, -rt.origin.x, -rt.origin.y); }
131 
132 
133 //=== SysRgn ========================
134 
135 inline SysRgn CreateSysRgn()
136  { return MTOOLBOX::HIShapeCreateMutable(); }
137 
138 inline void DeleteSysRgn(ConstSysRgn sysRgn)
139  { MTOOLBOX::CFRelease (sysRgn); }
140 
141 inline SysRgn CopySysRgn(ConstSysRgn sysRgn)
142  { return MTOOLBOX::HIShapeCreateMutableCopy(sysRgn); }
143 
144 inline void CopySysRgn(ConstSysRgn srcRgn, SysRgn dstRgn)
145 {
146 #if defined(ID_ENABLE_DEBUGGING)
147  OSStatus err =
148 #endif
149  MTOOLBOX::HIShapeSetWithShape(dstRgn, srcRgn);;
150  ASSERT_MSG(err == noErr, "HIShapeSetWithShape failed!");
151 }
152 
153 inline SysRgn CreateRectSysRgn (const SysRect& sysRect)
154  { return MTOOLBOX::HIShapeCreateMutableWithRect(&sysRect); }
155 
156 inline bool16 SysPointInSysRgn( const SysPoint& p, ConstSysRgn rgn)
157 {
158  if(rgn)
159  return MTOOLBOX::HIShapeContainsPoint(rgn, &p);
160  else
161  return kFalse;
162 }
163 
164 inline bool16 SysRectIntersectsSysRgn(ConstSysRgn rgn, const SysRect *rect)
165 {
166  if(rgn)
167  {
168  return MTOOLBOX::HIShapeIntersectsRect(rgn, rect);
169  }
170  else
171  return kFalse;
172 }
173 
174 #define RectInSysRgn(rgn, rect) SysRectIntersectsSysRgn(rgn, rect)
175 
176 inline bool16 EqualSysRgn(ConstSysRgn rgn1, ConstSysRgn rgn2)
177 {
178  if (MTOOLBOX::HIShapeIsEmpty(rgn1))
179  {
180  if (MTOOLBOX::HIShapeIsEmpty(rgn2))
181  return kTrue;
182  else
183  return kFalse;
184  }
185  else if (MTOOLBOX::HIShapeIsEmpty(rgn2))
186  {
187  return kFalse;
188  }
189 
190 
191  HIShapeRef diffShape = MTOOLBOX::HIShapeCreateDifference(rgn1, rgn2);
192  bool16 result = MTOOLBOX::HIShapeIsEmpty(diffShape);
193  MTOOLBOX::CFRelease(diffShape);
194  return result;
195 }
196 
197 inline void UnionSysRgn(ConstSysRgn srcRgn1, ConstSysRgn srcRgn2, SysRgn destRgn)
198 {
199 #if defined(ID_ENABLE_DEBUGGING)
200  OSStatus err =
201 #endif
202  MTOOLBOX::HIShapeUnion(srcRgn1, srcRgn2, destRgn);
203  ASSERT_MSG(err == noErr, "HIShapeUnion failed!");
204 }
205 
206 inline void DiffSysRgn(ConstSysRgn srcRgn, ConstSysRgn removeRgn, SysRgn destRgn)
207 {
208 #if defined(ID_ENABLE_DEBUGGING)
209  OSStatus err =
210 #endif
211  MTOOLBOX::HIShapeDifference(srcRgn, removeRgn, destRgn);
212  ASSERT_MSG(err == noErr, "HIShapeDifference failed!");
213 }
214 
215 inline void IntersectSysRgn(ConstSysRgn srcRgn1, ConstSysRgn srcRgn2, SysRgn destRgn)
216 {
217 #if defined(ID_ENABLE_DEBUGGING)
218  OSStatus err =
219 #endif
220  MTOOLBOX::HIShapeIntersect (srcRgn1, srcRgn2, destRgn);
221  ASSERT_MSG(err == noErr, "HIShapeIntersect failed!");
222 }
223 
224 inline bool16 EmptySysRgn(ConstSysRgn theRgn)
225  { return (MTOOLBOX::HIShapeIsEmpty(theRgn) == true); }
226 
227 inline void XorSysRgn(ConstSysRgn srcRgn1, ConstSysRgn srcRgn2, SysRgn destRgn)
228 {
229 #if defined(ID_ENABLE_DEBUGGING)
230  OSStatus err =
231 #endif
232  MTOOLBOX::HIShapeXor(srcRgn1, srcRgn2, destRgn);
233  ASSERT_MSG(err == noErr, "HIShapeXor failed!");
234 }
235 
236 inline void OffsetSysRgn(SysRgn rgn, SysCoord deltaX, SysCoord deltaY)
237 {
238 #if defined(ID_ENABLE_DEBUGGING)
239  OSStatus err =
240 #endif
241  MTOOLBOX::HIShapeOffset (rgn, deltaX, deltaY);
242  ASSERT_MSG(err == noErr, "HIShapeOffset failed!");
243 }
244 
245 inline void InsetSysRgn(SysRgn rgn, SysCoord deltaX, SysCoord deltaY)
246 {
247 #if defined(ID_ENABLE_DEBUGGING)
248  OSStatus err =
249 #endif
250  MTOOLBOX::HIShapeInset (rgn, deltaX, deltaY);
251  ASSERT_MSG(err == noErr, "HIShapeInset failed!");
252 }
253 
254 //=== SysWireframe ========================
255 inline SysRect GetRegionRect( SysWireframe rgn )
256  { return ::GetRegionRect((ConstSysRgn) rgn); }
257 inline SysWireframe CreateSysWireframe()
258  { return ::CreateSysRgn(); }
259 
260 inline SysWireframe CreateRectSysWireframe (SysRect sysRect)
261  { return ::CreateRectSysRgn(sysRect); }
262 
263 inline void DeleteSysWireframe(SysWireframe sysRgn)
264  { ::DeleteSysRgn(sysRgn); }
265 
266 inline SysWireframe CopySysWireframe(SysWireframe sysRgn)
267  { return ::CopySysRgn(sysRgn); }
268 
269 inline void CopySysWireframe(SysWireframe srcRgn, SysWireframe dstRgn)
270  { ::CopySysRgn(srcRgn, dstRgn); }
271 
272 inline void OffsetSysWireframe(SysWireframe rgn, int32 deltaX, int32 deltaY)
273  { ::OffsetSysRgn(rgn, deltaX, deltaY); }
274 
275 inline void InsetSysWireframe(SysWireframe rgn, int32 deltaX, int32 deltaY)
276  { ::InsetSysRgn(rgn, deltaX, deltaY); }
277 
278 inline void UnionSysWireframe(SysWireframe srcRgn1, SysWireframe srcRgn2, SysWireframe destRgn)
279  { ::UnionSysRgn(srcRgn1, srcRgn2, destRgn); }
280 
281 inline void DiffSysWireframe(SysWireframe srcRgn, SysWireframe removeRgn, SysWireframe destRgn)
282  { ::DiffSysRgn(srcRgn, removeRgn, destRgn); }
283 
284 inline void IntersectSysWireframe(SysWireframe srcRgn1, SysWireframe srcRgn2, SysWireframe destRgn)
285  { ::IntersectSysRgn(srcRgn1, srcRgn2, destRgn); }
286 
287 inline void XorSysWireframe(SysWireframe srcRgn1, SysWireframe srcRgn2, SysWireframe destRgn)
288  { ::XorSysRgn(srcRgn1, srcRgn2, destRgn); }
289 
290 //=== MISC ========================
291 
292  SysPoint GetMousePosition();
293 
294 inline SysRect operator-(const SysRect& rt1, const SysRect& rt2)
295 {
296  SysRect result;
297 
298  result.origin.x = rt1.origin.x - rt2.origin.x;
299  result.origin.y = rt1.origin.y - rt2.origin.y;
300  result.size.width = rt1.size.width - rt2.size.width;
301  result.size.height = rt1.size.height - rt2.size.height;
302 
303  return result;
304 }
305 
306 inline SysRect operator+(const SysRect& rt1, const SysRect& rt2)
307 {
308  SysRect result;
309 
310  result.origin.x = rt1.origin.x + rt2.origin.x;
311  result.origin.y = rt1.origin.y + rt2.origin.y;
312  result.size.width = rt1.size.width + rt2.size.width;
313  result.size.height = rt1.size.height + rt2.size.height;
314 
315  return result;
316 }
317 
318 
319 
320 // void EraseSysRect(SysPort port, const SysRect *theRect);
321 // void EraseSysRgn(SysPort port, const SysRgn theRgn);
322 
323 // QDRgn GetAvailableWindowPositioningRegion(void);
324 
325  Boolean IsFrontProcess(void);
326 
327 
328 inline uint32 GetCaretTime()
329 {
330  // GetCaretTime is not supported in 64 bit applications and is obsolete in regular 32 bit os x. Replacing with it's default
331  // return value of 34. There is still a windows version we use in WSystemUtils.h.
332  return 34;
333 }
334 
335 namespace SystemUtils
336 {
337  uint32 TickCount();
338  uint64 Milliseconds();
339  uint64 Microseconds();
340 }
341 
342 #endif
343  // __MSystemUtils__