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 24 class CSize; 25 class CRect; 26 27 28 class CPoint : public tagPOINT 29 { 30 public: 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 { 67 Offset(point.x, point.y); 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 { 92 Offset(point); 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 110 CPoint operator+(POINT point) const throw() 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 132 class CSize : public tagSIZE 133 { 134 public: 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 156 CSize(DWORD dwSize) throw() 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 189 CPoint operator+(POINT point) const throw() 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 201 CPoint operator-(POINT point) const throw() 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 215 CSize CPoint::operator-(POINT point) const throw() 216 { 217 return CSize(x - point.x, y - point.y); 218 } 219 220 221 class CRect : public tagRECT 222 { 223 public: 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 253 CRect(POINT point, SIZE size) throw() 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 269 CPoint& BottomRight() throw() 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 { 436 OffsetRect(point); 437 } 438 439 void operator+=(SIZE size) throw() 440 { 441 OffsetRect(size); 442 } 443 444 void operator+=(LPCRECT lpRect) throw() 445 { 446 InflateRect(lpRect); 447 } 448 449 void operator-=(POINT point) throw() 450 { 451 OffsetRect(-point.x, -point.y); 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 542 CRect CPoint::operator+(const RECT* lpRect) const throw() 543 { 544 CRect r(lpRect); 545 r += *this; 546 return r; 547 } 548 549 CRect CPoint::operator-(const RECT* lpRect) const throw() 550 { 551 CRect r(lpRect); 552 r -= *this; 553 return r; 554 } 555 556 CRect CSize::operator+(const RECT* lpRect) const throw() 557 { 558 CRect r(lpRect); 559 r += *this; 560 return r; 561 } 562 563 CRect CSize::operator-(const RECT* lpRect) const throw() 564 { 565 CRect r(lpRect); 566 r -= *this; 567 return r; 568 } 569 570