ReactOS 0.4.15-dev-6656-gbbb33a6
atltypes.h
Go to the documentation of this file.
1/*
2 * ReactOS ATL
3 *
4 * Copyright 2016 Mark Jansen
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#pragma once
22
23
24class CSize;
25class CRect;
26
27
28class CPoint : public tagPOINT
29{
30public:
31
32 CPoint() throw()
33 {
34 x = y = 0;
35 }
36
37 CPoint(int initX, int initY) throw()
38 {
39 x = initX;
40 y = initY;
41 }
42
43 CPoint(POINT initPt) throw()
44 {
45 *((POINT*)this) = initPt;
46 }
47
48 CPoint(SIZE initSize) throw()
49 {
50 *((SIZE*)this) = initSize;
51 }
52
53 CPoint(LPARAM dwPoint) throw()
54 {
55 x = LOWORD(dwPoint);
56 y = HIWORD(dwPoint);
57 }
58
59 void Offset(int xOffset, int yOffset) throw()
60 {
61 x += xOffset;
62 y += yOffset;
63 }
64
65 void Offset(POINT point) throw()
66 {
68 }
69
70 void Offset(SIZE size) throw()
71 {
72 Offset(size.cx, size.cy);
73 }
74
75 BOOL operator==(POINT point) const throw()
76 {
77 return (x == point.x && y == point.y);
78 }
79
80 BOOL operator!=(POINT point) const throw()
81 {
82 return !(*this == point);
83 }
84
85 void operator+=(SIZE size) throw()
86 {
87 Offset(size);
88 }
89
90 void operator+=(POINT point) throw()
91 {
93 }
94
95 void operator-=(SIZE size) throw()
96 {
97 Offset(-size.cx, -size.cy);
98 }
99
100 void operator-=(POINT point) throw()
101 {
102 Offset(-point.x, -point.y);
103 }
104
105 CPoint operator+(SIZE size) const throw()
106 {
107 return CPoint(x + size.cx, y + size.cy);
108 }
109
111 {
112 return CPoint(x + point.x, y + point.y);
113 }
114
115 CRect operator+(const RECT* lpRect) const throw();
116
117 CSize operator-(POINT point) const throw();
118
119 CPoint operator-(SIZE size) const throw()
120 {
121 return CPoint(x - size.cx, y - size.cy);
122 }
123
124 CRect operator-(const RECT* lpRect) const throw();
125
126 CPoint operator-() const throw()
127 {
128 return CPoint(-x, -y);
129 }
130};
131
132class CSize : public tagSIZE
133{
134public:
135 CSize() throw()
136 {
137 cx = cy = 0;
138 }
139
140 CSize(int initCX, int initCY) throw()
141 {
142 cx = initCX;
143 cy = initCY;
144 }
145
146 CSize(SIZE initSize) throw()
147 {
148 *((SIZE*)this) = initSize;
149 }
150
151 CSize(POINT initPt) throw()
152 {
153 *((POINT*)this) = initPt;
154 }
155
157 {
158 cx = LOWORD(dwSize);
159 cy = HIWORD(dwSize);
160 }
161
162 BOOL operator==(SIZE size) const throw()
163 {
164 return (size.cx == cx && size.cy == cy);
165 }
166
167 BOOL operator!=(SIZE size) const throw()
168 {
169 return !(*this == size);
170 }
171
172 void operator+=(SIZE size) throw()
173 {
174 cx += size.cx;
175 cy += size.cy;
176 }
177
178 void operator-=(SIZE size) throw()
179 {
180 cx -= size.cx;
181 cy -= size.cy;
182 }
183
184 CSize operator+(SIZE size) const throw()
185 {
186 return CSize(cx + size.cx, cy + size.cy);
187 }
188
190 {
191 return CPoint(cx + point.x, cy + point.y);
192 }
193
194 CRect operator+(const RECT* lpRect) const throw();
195
196 CSize operator-(SIZE size) const throw()
197 {
198 return CSize(cx - size.cx, cy - size.cy);
199 }
200
202 {
203 return CPoint(cx - point.x, cy - point.y);
204 }
205
206 CRect operator-(const RECT* lpRect) const throw();
207
208 CSize operator-() const throw()
209 {
210 return CSize(-cx, -cy);
211 }
212};
213
214
215inline CSize CPoint::operator-(POINT point) const throw()
216{
217 return CSize(x - point.x, y - point.y);
218}
219
220
221class CRect : public tagRECT
222{
223public:
224 CRect() throw()
225 {
226 left = top = right = bottom = 0;
227 }
228
229 CRect(int l, int t, int r, int b) throw()
230 {
231 left = l;
232 top = t;
233 right = r;
234 bottom = b;
235 }
236
237 CRect(const RECT& srcRect) throw()
238 {
239 left = srcRect.left;
240 top = srcRect.top;
241 right = srcRect.right;
242 bottom = srcRect.bottom;
243 }
244
245 CRect(LPCRECT lpSrcRect) throw()
246 {
247 left = lpSrcRect->left;
248 top = lpSrcRect->top;
249 right = lpSrcRect->right;
250 bottom = lpSrcRect->bottom;
251 }
252
254 {
255 left = point.x;
256 top = point.y;
257 right = point.x + size.cx;
258 bottom = point.y + size.cy;
259 }
260
261 CRect(POINT topLeft, POINT bottomRight) throw()
262 {
263 left = topLeft.x;
264 top = topLeft.y;
265 right = bottomRight.x;
266 bottom = bottomRight.y;
267 }
268
270 {
271 return ((CPoint*)this)[1];
272 }
273
274 const CPoint& BottomRight() const throw()
275 {
276 return ((const CPoint*)this)[1];
277 }
278
279 CPoint CenterPoint() const throw()
280 {
281 return CPoint(left + (Width() >> 1), top + (Height() >> 1));
282 }
283
284 void CopyRect(LPCRECT lpSrcRect) throw()
285 {
286 ::CopyRect(this, lpSrcRect);
287 }
288
289 void DeflateRect(int x, int y) throw()
290 {
291 ::InflateRect(this, -x, -y);
292 }
293
294 void DeflateRect(SIZE size) throw()
295 {
296 ::InflateRect(this, -size.cx, -size.cy);
297 }
298
299 void DeflateRect(LPCRECT lpRect) throw()
300 {
301 DeflateRect(lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
302 }
303
304 void DeflateRect(int l, int t, int r, int b) throw()
305 {
306 left += l;
307 top += t;
308 right -= r;
309 bottom -= b;
310 }
311
312 BOOL EqualRect(LPCRECT lpRect) const throw()
313 {
314 return ::EqualRect(this, lpRect);
315 }
316
317
318 int Height() const throw()
319 {
320 return bottom - top;
321 }
322
323 void InflateRect(int x, int y) throw()
324 {
325 ::InflateRect(this, x, y);
326 }
327
328 void InflateRect(SIZE size) throw()
329 {
330 ::InflateRect(this, size.cx, size.cy);
331 }
332
333 void InflateRect(LPCRECT lpRect) throw()
334 {
335 InflateRect(lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
336 }
337
338 void InflateRect(int l, int t, int r, int b) throw()
339 {
340 left -= l;
341 top -= t;
342 right += r;
343 bottom += b;
344 }
345
346 BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2) throw()
347 {
348 return ::IntersectRect(this, lpRect1, lpRect2);
349 }
350
351 BOOL IsRectEmpty() const throw()
352 {
353 return ::IsRectEmpty(this);
354 }
355
356 BOOL IsRectNull() const throw()
357 {
358 return (left == 0 && right == 0 &&
359 top == 0 && bottom == 0);
360 }
361
362 //void MoveToX(int x) throw()
363 //void MoveToXY(int x, int y) throw()
364 //void MoveToXY(POINT point) throw()
365 //void MoveToY(int y) throw()
366 //void NormalizeRect() throw()
367
368 void OffsetRect(int x, int y) throw()
369 {
370 ::OffsetRect(this, x, y);
371 }
372
373 void OffsetRect(POINT point) throw()
374 {
375 ::OffsetRect(this, point.x, point.y);
376 }
377
378 void OffsetRect(SIZE size) throw()
379 {
380 ::OffsetRect(this, size.cx, size.cy);
381 }
382
383 BOOL PtInRect(POINT point) const throw()
384 {
385 return ::PtInRect(this, point);
386 }
387 //void SetRect(int x1, int y1, int x2, int y2) throw()
388 //void SetRectEmpty() throw()
389 //CSize Size() const throw()
390 //BOOL SubtractRect(LPCRECT lpRectSrc1, LPCRECT lpRectSrc2) throw()
391
392 CPoint& TopLeft() throw()
393 {
394 return ((CPoint*)this)[0];
395 }
396
397 const CPoint& TopLeft() const throw()
398 {
399 return ((const CPoint*)this)[0];
400 }
401
402 BOOL UnionRect(LPCRECT lpRect1, LPCRECT lpRect2) throw()
403 {
404 return ::UnionRect(this, lpRect1, lpRect2);
405 }
406
407 int Width() const throw()
408 {
409 return right - left;
410 }
411
412
413 BOOL operator==(const RECT& rect) const throw()
414 {
415 return (left == rect.left &&
416 top == rect.top &&
417 right == rect.right &&
418 bottom == rect.bottom);
419 }
420
421 BOOL operator!=(const RECT& rect) const throw()
422 {
423 return !(*this == rect);
424 }
425
426 void operator=(const RECT& srcRect) throw()
427 {
428 left = srcRect.left;
429 top = srcRect.top;
430 right = srcRect.right;
431 bottom = srcRect.bottom;
432 }
433
434 void operator+=(POINT point) throw()
435 {
437 }
438
439 void operator+=(SIZE size) throw()
440 {
442 }
443
444 void operator+=(LPCRECT lpRect) throw()
445 {
446 InflateRect(lpRect);
447 }
448
449 void operator-=(POINT point) throw()
450 {
452 }
453
454 void operator-=(SIZE size) throw()
455 {
456 OffsetRect(-size.cx, -size.cy);
457 }
458
459 void operator-=(LPCRECT lpRect) throw()
460 {
461 DeflateRect(lpRect);
462 }
463
464
465 CRect operator+(POINT point) const throw()
466 {
467 CRect r(this);
468 r.OffsetRect(point);
469 return r;
470 }
471
472 CRect operator+(LPCRECT lpRect) const throw()
473 {
474 CRect r(this);
475 r.InflateRect(lpRect);
476 return r;
477 }
478
479 CRect operator+(SIZE size) const throw()
480 {
481 CRect r(this);
482 r.OffsetRect(size);
483 return r;
484 }
485
486 CRect operator-(POINT point) const throw()
487 {
488 CRect r(this);
489 r.OffsetRect(-point.x, -point.y);
490 return r;
491 }
492
493 CRect operator-(SIZE size) const throw()
494 {
495 CRect r(this);
496 r.OffsetRect(-size.cx, -size.cy);
497 return r;
498 }
499
500 CRect operator-(LPCRECT lpRect) const throw()
501 {
502 CRect r(this);
503 r.DeflateRect(lpRect);
504 return r;
505 }
506
507 void operator&=(const RECT& rect) throw()
508 {
509 IntersectRect(this, &rect);
510 }
511
512 CRect operator&(const RECT& rect2) const throw()
513 {
514 CRect r;
515 r.IntersectRect(this, &rect2);
516 return r;
517 }
518
519 void operator|=(const RECT& rect) throw()
520 {
521 UnionRect(this, &rect);
522 }
523
524 CRect operator|(const RECT& rect2) const throw()
525 {
526 CRect r;
527 r.UnionRect(this, &rect2);
528 return r;
529 }
530
531 operator LPRECT() throw()
532 {
533 return this;
534 }
535
536 operator LPCRECT() const throw()
537 {
538 return this;
539 }
540};
541
542inline CRect CPoint::operator+(const RECT* lpRect) const throw()
543{
544 CRect r(lpRect);
545 r += *this;
546 return r;
547}
548
549inline CRect CPoint::operator-(const RECT* lpRect) const throw()
550{
551 CRect r(lpRect);
552 r -= *this;
553 return r;
554}
555
556inline CRect CSize::operator+(const RECT* lpRect) const throw()
557{
558 CRect r(lpRect);
559 r += *this;
560 return r;
561}
562
563inline CRect CSize::operator-(const RECT* lpRect) const throw()
564{
565 CRect r(lpRect);
566 r -= *this;
567 return r;
568}
569
int yOffset
Definition: appswitch.c:59
int xOffset
Definition: appswitch.c:59
r l[0]
Definition: byte_order.h:168
void Offset(POINT point)
Definition: atltypes.h:65
void Offset(int xOffset, int yOffset)
Definition: atltypes.h:59
void operator+=(POINT point)
Definition: atltypes.h:90
void operator-=(SIZE size)
Definition: atltypes.h:95
BOOL operator==(POINT point) const
Definition: atltypes.h:75
CPoint operator-(SIZE size) const
Definition: atltypes.h:119
CPoint operator+(POINT point) const
Definition: atltypes.h:110
CPoint operator-() const
Definition: atltypes.h:126
CPoint(POINT initPt)
Definition: atltypes.h:43
void operator-=(POINT point)
Definition: atltypes.h:100
void Offset(SIZE size)
Definition: atltypes.h:70
CPoint(int initX, int initY)
Definition: atltypes.h:37
void operator+=(SIZE size)
Definition: atltypes.h:85
CPoint(LPARAM dwPoint)
Definition: atltypes.h:53
BOOL operator!=(POINT point) const
Definition: atltypes.h:80
CPoint operator+(SIZE size) const
Definition: atltypes.h:105
CPoint()
Definition: atltypes.h:32
CPoint(SIZE initSize)
Definition: atltypes.h:48
BOOL PtInRect(POINT point) const
Definition: atltypes.h:383
CRect(POINT topLeft, POINT bottomRight)
Definition: atltypes.h:261
void DeflateRect(LPCRECT lpRect)
Definition: atltypes.h:299
CPoint CenterPoint() const
Definition: atltypes.h:279
CRect(int l, int t, int r, int b)
Definition: atltypes.h:229
BOOL IsRectNull() const
Definition: atltypes.h:356
void InflateRect(LPCRECT lpRect)
Definition: atltypes.h:333
void DeflateRect(int l, int t, int r, int b)
Definition: atltypes.h:304
void OffsetRect(POINT point)
Definition: atltypes.h:373
void OffsetRect(SIZE size)
Definition: atltypes.h:378
const CPoint & BottomRight() const
Definition: atltypes.h:274
int Width() const
Definition: atltypes.h:407
CRect operator-(LPCRECT lpRect) const
Definition: atltypes.h:500
BOOL operator==(const RECT &rect) const
Definition: atltypes.h:413
CRect(LPCRECT lpSrcRect)
Definition: atltypes.h:245
void InflateRect(int l, int t, int r, int b)
Definition: atltypes.h:338
const CPoint & TopLeft() const
Definition: atltypes.h:397
CRect operator&(const RECT &rect2) const
Definition: atltypes.h:512
void operator+=(LPCRECT lpRect)
Definition: atltypes.h:444
void operator-=(SIZE size)
Definition: atltypes.h:454
BOOL EqualRect(LPCRECT lpRect) const
Definition: atltypes.h:312
CRect operator+(SIZE size) const
Definition: atltypes.h:479
void OffsetRect(int x, int y)
Definition: atltypes.h:368
void operator+=(SIZE size)
Definition: atltypes.h:439
void DeflateRect(SIZE size)
Definition: atltypes.h:294
CRect operator-(SIZE size) const
Definition: atltypes.h:493
CPoint & TopLeft()
Definition: atltypes.h:392
void operator-=(POINT point)
Definition: atltypes.h:449
void operator&=(const RECT &rect)
Definition: atltypes.h:507
CRect operator+(LPCRECT lpRect) const
Definition: atltypes.h:472
BOOL UnionRect(LPCRECT lpRect1, LPCRECT lpRect2)
Definition: atltypes.h:402
void CopyRect(LPCRECT lpSrcRect)
Definition: atltypes.h:284
CRect()
Definition: atltypes.h:224
void InflateRect(SIZE size)
Definition: atltypes.h:328
int Height() const
Definition: atltypes.h:318
void operator=(const RECT &srcRect)
Definition: atltypes.h:426
void InflateRect(int x, int y)
Definition: atltypes.h:323
CRect operator-(POINT point) const
Definition: atltypes.h:486
void operator|=(const RECT &rect)
Definition: atltypes.h:519
BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2)
Definition: atltypes.h:346
void operator-=(LPCRECT lpRect)
Definition: atltypes.h:459
CRect operator+(POINT point) const
Definition: atltypes.h:465
CRect(POINT point, SIZE size)
Definition: atltypes.h:253
void operator+=(POINT point)
Definition: atltypes.h:434
CPoint & BottomRight()
Definition: atltypes.h:269
CRect operator|(const RECT &rect2) const
Definition: atltypes.h:524
CRect(const RECT &srcRect)
Definition: atltypes.h:237
BOOL operator!=(const RECT &rect) const
Definition: atltypes.h:421
BOOL IsRectEmpty() const
Definition: atltypes.h:351
void DeflateRect(int x, int y)
Definition: atltypes.h:289
void operator+=(SIZE size)
Definition: atltypes.h:172
CSize operator-(SIZE size) const
Definition: atltypes.h:196
CSize(SIZE initSize)
Definition: atltypes.h:146
BOOL operator!=(SIZE size) const
Definition: atltypes.h:167
CSize()
Definition: atltypes.h:135
CPoint operator-(POINT point) const
Definition: atltypes.h:201
BOOL operator==(SIZE size) const
Definition: atltypes.h:162
CPoint operator+(POINT point) const
Definition: atltypes.h:189
void operator-=(SIZE size)
Definition: atltypes.h:178
CSize(int initCX, int initCY)
Definition: atltypes.h:140
CSize operator+(SIZE size) const
Definition: atltypes.h:184
CSize operator-() const
Definition: atltypes.h:208
CSize(DWORD dwSize)
Definition: atltypes.h:156
CSize(POINT initPt)
Definition: atltypes.h:151
POINTL point
Definition: edittest.c:50
RECT rect2
Definition: edittest.c:51
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble t
Definition: gl.h:2047
GLsizeiptr size
Definition: glext.h:5919
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
GLdouble GLdouble right
Definition: glext.h:10859
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLint left
Definition: glext.h:7726
GLint GLint bottom
Definition: glext.h:7726
#define b
Definition: ke_i.h:79
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define LOWORD(l)
Definition: pedump.c:82
& rect
Definition: startmenu.cpp:1413
LONG y
Definition: windef.h:330
LONG x
Definition: windef.h:329
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
LONG cx
Definition: windef.h:334
LONG cy
Definition: windef.h:335
#define HIWORD(l)
Definition: typedefs.h:247
#define LPCRECT
Definition: precomp.h:29
#define LPRECT
Definition: precomp.h:28
LONG_PTR LPARAM
Definition: windef.h:208