ReactOS 0.4.15-dev-7670-g69b08be
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() noexcept
33 {
34 x = y = 0;
35 }
36
37 CPoint(int initX, int initY) noexcept
38 {
39 x = initX;
40 y = initY;
41 }
42
43 CPoint(POINT initPt) noexcept
44 {
45 *((POINT*)this) = initPt;
46 }
47
48 CPoint(SIZE initSize) noexcept
49 {
50 *((SIZE*)this) = initSize;
51 }
52
53 CPoint(LPARAM dwPoint) noexcept
54 {
55 x = LOWORD(dwPoint);
56 y = HIWORD(dwPoint);
57 }
58
59 void Offset(int xOffset, int yOffset) noexcept
60 {
61 x += xOffset;
62 y += yOffset;
63 }
64
65 void Offset(POINT point) noexcept
66 {
68 }
69
70 void Offset(SIZE size) noexcept
71 {
72 Offset(size.cx, size.cy);
73 }
74
75 BOOL operator==(POINT point) const noexcept
76 {
77 return (x == point.x && y == point.y);
78 }
79
80 BOOL operator!=(POINT point) const noexcept
81 {
82 return !(*this == point);
83 }
84
85 void operator+=(SIZE size) noexcept
86 {
87 Offset(size);
88 }
89
90 void operator+=(POINT point) noexcept
91 {
93 }
94
95 void operator-=(SIZE size) noexcept
96 {
97 Offset(-size.cx, -size.cy);
98 }
99
100 void operator-=(POINT point) noexcept
101 {
102 Offset(-point.x, -point.y);
103 }
104
105 CPoint operator+(SIZE size) const noexcept
106 {
107 return CPoint(x + size.cx, y + size.cy);
108 }
109
110 CPoint operator+(POINT point) const noexcept
111 {
112 return CPoint(x + point.x, y + point.y);
113 }
114
115 CRect operator+(const RECT* lpRect) const noexcept;
116
117 CSize operator-(POINT point) const noexcept;
118
119 CPoint operator-(SIZE size) const noexcept
120 {
121 return CPoint(x - size.cx, y - size.cy);
122 }
123
124 CRect operator-(const RECT* lpRect) const noexcept;
125
127 {
128 return CPoint(-x, -y);
129 }
130};
131
132class CSize : public tagSIZE
133{
134public:
135 CSize() noexcept
136 {
137 cx = cy = 0;
138 }
139
140 CSize(int initCX, int initCY) noexcept
141 {
142 cx = initCX;
143 cy = initCY;
144 }
145
146 CSize(SIZE initSize) noexcept
147 {
148 *((SIZE*)this) = initSize;
149 }
150
151 CSize(POINT initPt) noexcept
152 {
153 *((POINT*)this) = initPt;
154 }
155
157 {
158 cx = LOWORD(dwSize);
159 cy = HIWORD(dwSize);
160 }
161
162 BOOL operator==(SIZE size) const noexcept
163 {
164 return (size.cx == cx && size.cy == cy);
165 }
166
167 BOOL operator!=(SIZE size) const noexcept
168 {
169 return !(*this == size);
170 }
171
172 void operator+=(SIZE size) noexcept
173 {
174 cx += size.cx;
175 cy += size.cy;
176 }
177
178 void operator-=(SIZE size) noexcept
179 {
180 cx -= size.cx;
181 cy -= size.cy;
182 }
183
184 CSize operator+(SIZE size) const noexcept
185 {
186 return CSize(cx + size.cx, cy + size.cy);
187 }
188
189 CPoint operator+(POINT point) const noexcept
190 {
191 return CPoint(cx + point.x, cy + point.y);
192 }
193
194 CRect operator+(const RECT* lpRect) const noexcept;
195
196 CSize operator-(SIZE size) const noexcept
197 {
198 return CSize(cx - size.cx, cy - size.cy);
199 }
200
201 CPoint operator-(POINT point) const noexcept
202 {
203 return CPoint(cx - point.x, cy - point.y);
204 }
205
206 CRect operator-(const RECT* lpRect) const noexcept;
207
209 {
210 return CSize(-cx, -cy);
211 }
212};
213
214
215inline CSize CPoint::operator-(POINT point) const noexcept
216{
217 return CSize(x - point.x, y - point.y);
218}
219
220
221class CRect : public tagRECT
222{
223public:
224 CRect() noexcept
225 {
226 left = top = right = bottom = 0;
227 }
228
229 CRect(int l, int t, int r, int b) noexcept
230 {
231 left = l;
232 top = t;
233 right = r;
234 bottom = b;
235 }
236
237 CRect(const RECT& srcRect) noexcept
238 {
239 left = srcRect.left;
240 top = srcRect.top;
241 right = srcRect.right;
242 bottom = srcRect.bottom;
243 }
244
245 CRect(LPCRECT lpSrcRect) noexcept
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) noexcept
262 {
263 left = topLeft.x;
264 top = topLeft.y;
265 right = bottomRight.x;
266 bottom = bottomRight.y;
267 }
268
269 CPoint& BottomRight() noexcept
270 {
271 return ((CPoint*)this)[1];
272 }
273
274 const CPoint& BottomRight() const noexcept
275 {
276 return ((const CPoint*)this)[1];
277 }
278
280 {
281 return CPoint(left + (Width() >> 1), top + (Height() >> 1));
282 }
283
284 void CopyRect(LPCRECT lpSrcRect) noexcept
285 {
286 ::CopyRect(this, lpSrcRect);
287 }
288
289 void DeflateRect(int x, int y) noexcept
290 {
291 ::InflateRect(this, -x, -y);
292 }
293
294 void DeflateRect(SIZE size) noexcept
295 {
296 ::InflateRect(this, -size.cx, -size.cy);
297 }
298
299 void DeflateRect(LPCRECT lpRect) noexcept
300 {
301 DeflateRect(lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
302 }
303
304 void DeflateRect(int l, int t, int r, int b) noexcept
305 {
306 left += l;
307 top += t;
308 right -= r;
309 bottom -= b;
310 }
311
312 BOOL EqualRect(LPCRECT lpRect) const noexcept
313 {
314 return ::EqualRect(this, lpRect);
315 }
316
317
318 int Height() const noexcept
319 {
320 return bottom - top;
321 }
322
323 void InflateRect(int x, int y) noexcept
324 {
325 ::InflateRect(this, x, y);
326 }
327
328 void InflateRect(SIZE size) noexcept
329 {
330 ::InflateRect(this, size.cx, size.cy);
331 }
332
333 void InflateRect(LPCRECT lpRect) noexcept
334 {
335 InflateRect(lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
336 }
337
338 void InflateRect(int l, int t, int r, int b) noexcept
339 {
340 left -= l;
341 top -= t;
342 right += r;
343 bottom += b;
344 }
345
346 BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2) noexcept
347 {
348 return ::IntersectRect(this, lpRect1, lpRect2);
349 }
350
352 {
353 return ::IsRectEmpty(this);
354 }
355
357 {
358 return (left == 0 && right == 0 &&
359 top == 0 && bottom == 0);
360 }
361
362 void MoveToX(int x) noexcept
363 {
364 int dx = x - left;
365 left = x;
366 right += dx;
367 }
368
369 void MoveToY(int y) noexcept
370 {
371 int dy = y - top;
372 top = y;
373 bottom += dy;
374 }
375
376 void MoveToXY(int x, int y) noexcept
377 {
378 MoveToX(x);
379 MoveToY(y);
380 }
381
382 void MoveToXY(POINT point) noexcept
383 {
385 }
386
387 void NormalizeRect() noexcept
388 {
389 if (left > right)
390 {
391 LONG tmp = left;
392 left = right;
393 right = tmp;
394 }
395 if (top > bottom)
396 {
397 LONG tmp = top;
398 top = bottom;
399 bottom = tmp;
400 }
401 }
402
403 void OffsetRect(int x, int y) noexcept
404 {
405 ::OffsetRect(this, x, y);
406 }
407
408 void OffsetRect(POINT point) noexcept
409 {
410 ::OffsetRect(this, point.x, point.y);
411 }
412
413 void OffsetRect(SIZE size) noexcept
414 {
415 ::OffsetRect(this, size.cx, size.cy);
416 }
417
418 BOOL PtInRect(POINT point) const noexcept
419 {
420 return ::PtInRect(this, point);
421 }
422
423 void SetRect(int x1, int y1, int x2, int y2) noexcept
424 {
425 left = x1;
426 top = y1;
427 right = x2;
428 bottom = y2;
429 }
430
431 void SetRectEmpty() noexcept
432 {
433 ZeroMemory(this, sizeof(*this));
434 }
435
436 CSize Size() const noexcept
437 {
438 return CSize(Width(), Height());
439 }
440
441 BOOL SubtractRect(LPCRECT lpRectSrc1, LPCRECT lpRectSrc2) noexcept
442 {
443 return ::SubtractRect(this, lpRectSrc1, lpRectSrc2);
444 }
445
446 CPoint& TopLeft() noexcept
447 {
448 return ((CPoint*)this)[0];
449 }
450
451 const CPoint& TopLeft() const noexcept
452 {
453 return ((const CPoint*)this)[0];
454 }
455
456 BOOL UnionRect(LPCRECT lpRect1, LPCRECT lpRect2) noexcept
457 {
458 return ::UnionRect(this, lpRect1, lpRect2);
459 }
460
461 int Width() const noexcept
462 {
463 return right - left;
464 }
465
466
467 BOOL operator==(const RECT& rect) const noexcept
468 {
469 return (left == rect.left &&
470 top == rect.top &&
471 right == rect.right &&
472 bottom == rect.bottom);
473 }
474
475 BOOL operator!=(const RECT& rect) const noexcept
476 {
477 return !(*this == rect);
478 }
479
480 void operator=(const RECT& srcRect) noexcept
481 {
482 left = srcRect.left;
483 top = srcRect.top;
484 right = srcRect.right;
485 bottom = srcRect.bottom;
486 }
487
488 void operator+=(POINT point) noexcept
489 {
491 }
492
493 void operator+=(SIZE size) noexcept
494 {
496 }
497
498 void operator+=(LPCRECT lpRect) noexcept
499 {
500 InflateRect(lpRect);
501 }
502
503 void operator-=(POINT point) noexcept
504 {
506 }
507
508 void operator-=(SIZE size) noexcept
509 {
510 OffsetRect(-size.cx, -size.cy);
511 }
512
513 void operator-=(LPCRECT lpRect) noexcept
514 {
515 DeflateRect(lpRect);
516 }
517
518
519 CRect operator+(POINT point) const noexcept
520 {
521 CRect r(this);
522 r.OffsetRect(point);
523 return r;
524 }
525
526 CRect operator+(LPCRECT lpRect) const noexcept
527 {
528 CRect r(this);
529 r.InflateRect(lpRect);
530 return r;
531 }
532
533 CRect operator+(SIZE size) const noexcept
534 {
535 CRect r(this);
536 r.OffsetRect(size);
537 return r;
538 }
539
540 CRect operator-(POINT point) const noexcept
541 {
542 CRect r(this);
543 r.OffsetRect(-point.x, -point.y);
544 return r;
545 }
546
547 CRect operator-(SIZE size) const noexcept
548 {
549 CRect r(this);
550 r.OffsetRect(-size.cx, -size.cy);
551 return r;
552 }
553
554 CRect operator-(LPCRECT lpRect) const noexcept
555 {
556 CRect r(this);
557 r.DeflateRect(lpRect);
558 return r;
559 }
560
561 void operator&=(const RECT& rect) noexcept
562 {
563 IntersectRect(this, &rect);
564 }
565
566 CRect operator&(const RECT& rect2) const noexcept
567 {
568 CRect r;
569 r.IntersectRect(this, &rect2);
570 return r;
571 }
572
573 void operator|=(const RECT& rect) noexcept
574 {
575 UnionRect(this, &rect);
576 }
577
578 CRect operator|(const RECT& rect2) const noexcept
579 {
580 CRect r;
581 r.UnionRect(this, &rect2);
582 return r;
583 }
584
585 operator LPRECT() noexcept
586 {
587 return this;
588 }
589
590 operator LPCRECT() const noexcept
591 {
592 return this;
593 }
594};
595
596inline CRect CPoint::operator+(const RECT* lpRect) const noexcept
597{
598 CRect r(lpRect);
599 r += *this;
600 return r;
601}
602
603inline CRect CPoint::operator-(const RECT* lpRect) const noexcept
604{
605 CRect r(lpRect);
606 r -= *this;
607 return r;
608}
609
610inline CRect CSize::operator+(const RECT* lpRect) const noexcept
611{
612 CRect r(lpRect);
613 r += *this;
614 return r;
615}
616
617inline CRect CSize::operator-(const RECT* lpRect) const noexcept
618{
619 CRect r(lpRect);
620 r -= *this;
621 return r;
622}
623
int yOffset
Definition: appswitch.c:59
int xOffset
Definition: appswitch.c:59
r l[0]
Definition: byte_order.h:168
BOOL operator==(POINT point) const noexcept
Definition: atltypes.h:75
void operator-=(POINT point) noexcept
Definition: atltypes.h:100
void operator+=(SIZE size) noexcept
Definition: atltypes.h:85
CPoint(int initX, int initY) noexcept
Definition: atltypes.h:37
void Offset(POINT point) noexcept
Definition: atltypes.h:65
void Offset(int xOffset, int yOffset) noexcept
Definition: atltypes.h:59
CPoint operator+(SIZE size) const noexcept
Definition: atltypes.h:105
void operator+=(POINT point) noexcept
Definition: atltypes.h:90
CPoint() noexcept
Definition: atltypes.h:32
void Offset(SIZE size) noexcept
Definition: atltypes.h:70
void operator-=(SIZE size) noexcept
Definition: atltypes.h:95
CPoint operator-() const noexcept
Definition: atltypes.h:126
CPoint(POINT initPt) noexcept
Definition: atltypes.h:43
CPoint(SIZE initSize) noexcept
Definition: atltypes.h:48
CPoint operator-(SIZE size) const noexcept
Definition: atltypes.h:119
CPoint(LPARAM dwPoint) noexcept
Definition: atltypes.h:53
BOOL operator!=(POINT point) const noexcept
Definition: atltypes.h:80
CPoint operator+(POINT point) const noexcept
Definition: atltypes.h:110
BOOL IsRectNull() const noexcept
Definition: atltypes.h:356
CRect() noexcept
Definition: atltypes.h:224
CRect(POINT point, SIZE size) noexcept
Definition: atltypes.h:253
void SetRectEmpty() noexcept
Definition: atltypes.h:431
void InflateRect(SIZE size) noexcept
Definition: atltypes.h:328
BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2) noexcept
Definition: atltypes.h:346
BOOL operator==(const RECT &rect) const noexcept
Definition: atltypes.h:467
void InflateRect(int x, int y) noexcept
Definition: atltypes.h:323
CRect operator+(POINT point) const noexcept
Definition: atltypes.h:519
void MoveToX(int x) noexcept
Definition: atltypes.h:362
CRect(LPCRECT lpSrcRect) noexcept
Definition: atltypes.h:245
CRect operator&(const RECT &rect2) const noexcept
Definition: atltypes.h:566
CPoint CenterPoint() const noexcept
Definition: atltypes.h:279
void CopyRect(LPCRECT lpSrcRect) noexcept
Definition: atltypes.h:284
void OffsetRect(int x, int y) noexcept
Definition: atltypes.h:403
void DeflateRect(int l, int t, int r, int b) noexcept
Definition: atltypes.h:304
void OffsetRect(SIZE size) noexcept
Definition: atltypes.h:413
void operator-=(LPCRECT lpRect) noexcept
Definition: atltypes.h:513
BOOL PtInRect(POINT point) const noexcept
Definition: atltypes.h:418
void DeflateRect(SIZE size) noexcept
Definition: atltypes.h:294
const CPoint & BottomRight() const noexcept
Definition: atltypes.h:274
void NormalizeRect() noexcept
Definition: atltypes.h:387
void OffsetRect(POINT point) noexcept
Definition: atltypes.h:408
void operator&=(const RECT &rect) noexcept
Definition: atltypes.h:561
void operator-=(POINT point) noexcept
Definition: atltypes.h:503
CPoint & BottomRight() noexcept
Definition: atltypes.h:269
CRect operator+(LPCRECT lpRect) const noexcept
Definition: atltypes.h:526
BOOL UnionRect(LPCRECT lpRect1, LPCRECT lpRect2) noexcept
Definition: atltypes.h:456
void operator-=(SIZE size) noexcept
Definition: atltypes.h:508
CRect(POINT topLeft, POINT bottomRight) noexcept
Definition: atltypes.h:261
BOOL SubtractRect(LPCRECT lpRectSrc1, LPCRECT lpRectSrc2) noexcept
Definition: atltypes.h:441
void operator=(const RECT &srcRect) noexcept
Definition: atltypes.h:480
CRect operator+(SIZE size) const noexcept
Definition: atltypes.h:533
CRect(int l, int t, int r, int b) noexcept
Definition: atltypes.h:229
void SetRect(int x1, int y1, int x2, int y2) noexcept
Definition: atltypes.h:423
CRect operator-(SIZE size) const noexcept
Definition: atltypes.h:547
int Width() const noexcept
Definition: atltypes.h:461
CSize Size() const noexcept
Definition: atltypes.h:436
const CPoint & TopLeft() const noexcept
Definition: atltypes.h:451
int Height() const noexcept
Definition: atltypes.h:318
CRect(const RECT &srcRect) noexcept
Definition: atltypes.h:237
void MoveToXY(POINT point) noexcept
Definition: atltypes.h:382
BOOL IsRectEmpty() const noexcept
Definition: atltypes.h:351
void InflateRect(int l, int t, int r, int b) noexcept
Definition: atltypes.h:338
void DeflateRect(LPCRECT lpRect) noexcept
Definition: atltypes.h:299
void operator+=(SIZE size) noexcept
Definition: atltypes.h:493
void InflateRect(LPCRECT lpRect) noexcept
Definition: atltypes.h:333
void MoveToY(int y) noexcept
Definition: atltypes.h:369
CRect operator-(POINT point) const noexcept
Definition: atltypes.h:540
void operator+=(LPCRECT lpRect) noexcept
Definition: atltypes.h:498
CRect operator|(const RECT &rect2) const noexcept
Definition: atltypes.h:578
void DeflateRect(int x, int y) noexcept
Definition: atltypes.h:289
BOOL operator!=(const RECT &rect) const noexcept
Definition: atltypes.h:475
void operator+=(POINT point) noexcept
Definition: atltypes.h:488
BOOL EqualRect(LPCRECT lpRect) const noexcept
Definition: atltypes.h:312
void MoveToXY(int x, int y) noexcept
Definition: atltypes.h:376
CPoint & TopLeft() noexcept
Definition: atltypes.h:446
void operator|=(const RECT &rect) noexcept
Definition: atltypes.h:573
CRect operator-(LPCRECT lpRect) const noexcept
Definition: atltypes.h:554
void operator-=(SIZE size) noexcept
Definition: atltypes.h:178
CSize(int initCX, int initCY) noexcept
Definition: atltypes.h:140
CPoint operator-(POINT point) const noexcept
Definition: atltypes.h:201
CSize(DWORD dwSize) noexcept
Definition: atltypes.h:156
CSize operator-() const noexcept
Definition: atltypes.h:208
CSize(POINT initPt) noexcept
Definition: atltypes.h:151
CPoint operator+(POINT point) const noexcept
Definition: atltypes.h:189
CSize(SIZE initSize) noexcept
Definition: atltypes.h:146
BOOL operator!=(SIZE size) const noexcept
Definition: atltypes.h:167
BOOL operator==(SIZE size) const noexcept
Definition: atltypes.h:162
CSize() noexcept
Definition: atltypes.h:135
CSize operator-(SIZE size) const noexcept
Definition: atltypes.h:196
CSize operator+(SIZE size) const noexcept
Definition: atltypes.h:184
void operator+=(SIZE size) noexcept
Definition: atltypes.h:172
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
GLint dy
Definition: linetemp.h:97
GLint dx
Definition: linetemp.h:97
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
long LONG
Definition: pedump.c:60
& rect
Definition: startmenu.cpp:1413
LONG y
Definition: windef.h:330
LONG x
Definition: windef.h:329
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
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
#define ZeroMemory
Definition: winbase.h:1712
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3710
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG y1
Definition: winddi.h:3709
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3708
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG _In_ LONG y2
Definition: winddi.h:3711
LONG_PTR LPARAM
Definition: windef.h:208
#define const
Definition: zconf.h:233