Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.4 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // scalingrect.h : gdi based rect with auto scaling for associated window handle
  3. // Copyright (c) Microsoft Corporation 2000.
  4. #pragma once
  5. #ifndef SCALINGRECT_H
  6. #define SCALINGRECT_H
  7. #include <atltmp.h>
  8. #include <throw.h>
  9. #include <trace.h>
  10. #define INVALID_HWND ((HWND) INVALID_HANDLE_VALUE)
  11. typedef CComQIPtr<IOleInPlaceSiteWindowless> PQSiteWindowless;
  12. class CScalingRect : public CRect {
  13. public:
  14. CScalingRect(const long l = 0,
  15. const long t = 0,
  16. const long r = 0,
  17. const long b = 0,
  18. const HWND iOwner = INVALID_HWND) :
  19. CRect(l, t, r, b),
  20. m_hOwner(iOwner),
  21. m_bRequiresSave(true) {}
  22. CScalingRect(const HWND iOwner) : m_bRequiresSave(true) {
  23. if (iOwner == INVALID_HWND) {
  24. CRect(0, 0, 0, 0);
  25. } else if (::IsWindow(iOwner)) {
  26. if (!::GetWindowRect(iOwner, this)) {
  27. THROWCOM(E_UNEXPECTED);
  28. }
  29. } else {
  30. THROWCOM(E_INVALIDARG);
  31. }
  32. m_hOwner = iOwner;
  33. }
  34. CScalingRect(const CSize& sz, const HWND iOwner = INVALID_HWND) :
  35. CRect(CPoint(0, 0), sz),
  36. m_hOwner(iOwner),
  37. m_bRequiresSave(true) {}
  38. CScalingRect(const POINT& pt1, POINT& pt2 = CPoint(0, 0), const HWND iOwner = INVALID_HWND) :
  39. CRect(pt1, pt2),
  40. m_hOwner(iOwner),
  41. m_bRequiresSave(true) {}
  42. CScalingRect(const POINT& pt1, SIZE& sz = CSize(0, 0), const HWND iOwner = INVALID_HWND) :
  43. CRect(pt1, sz),
  44. m_hOwner(iOwner),
  45. m_bRequiresSave(true) {}
  46. CScalingRect(const RECT& iPos,
  47. const HWND iOwner = INVALID_HWND) :
  48. CRect(iPos),
  49. m_hOwner(iOwner),
  50. m_bRequiresSave(true) {}
  51. CScalingRect(const CRect& iPos,
  52. const HWND iOwner = INVALID_HWND) :
  53. CRect(iPos),
  54. m_hOwner(iOwner),
  55. m_bRequiresSave(true) {}
  56. CScalingRect& operator=(const CScalingRect& rhs) {
  57. if (this != &rhs && *this != rhs) {
  58. CRect::operator=(rhs);
  59. if ((m_hOwner != INVALID_HWND) && (rhs.m_hOwner != INVALID_HWND) && (m_hOwner != rhs.m_hOwner)) {
  60. ::MapWindowPoints(rhs.m_hOwner, m_hOwner, reinterpret_cast<LPPOINT>(static_cast<LPRECT>(this)), 2);
  61. }
  62. m_bRequiresSave = true;
  63. }
  64. return *this;
  65. }
  66. CScalingRect& operator=(const CRect& rhs) {
  67. if (this != &rhs && (CRect(*this) != rhs)) {
  68. CRect::operator=(rhs);
  69. m_bRequiresSave = true;
  70. }
  71. return *this;
  72. }
  73. bool operator==(const CScalingRect& rhs) const {
  74. CRect r(rhs);
  75. if (rhs.m_hOwner != INVALID_HWND && m_hOwner != INVALID_HWND && rhs.m_hOwner != m_hOwner) {
  76. ::MapWindowPoints(rhs.m_hOwner, m_hOwner, reinterpret_cast<LPPOINT>(static_cast<LPRECT>(r)), 2);
  77. }
  78. return !!CRect::operator==(r);
  79. }
  80. bool operator !=(const CScalingRect& rhs) const {
  81. return !operator==(rhs);
  82. }
  83. bool operator==(const CRect& rhs) const {
  84. return CRect::operator==(rhs) != 0;
  85. }
  86. bool operator !=(const CRect& rhs) const {
  87. return !operator==(rhs);
  88. }
  89. bool operator==(LPCRECT rhs) const {
  90. return CRect::operator==(*rhs) != 0;
  91. }
  92. bool operator !=(LPCRECT rhs) const {
  93. return !operator==(rhs);
  94. }
  95. bool operator==(const RECT& rhs) const {
  96. return CRect::operator==(rhs) != 0;
  97. }
  98. bool operator !=(const RECT& rhs) const {
  99. return !operator==(rhs);
  100. }
  101. long Width() { return CRect::Width(); }
  102. long Height() { return CRect::Height(); }
  103. void Width(long cx) {
  104. right = left + cx;
  105. }
  106. void Height(long cy) {
  107. bottom = top + cy;
  108. }
  109. HWND Owner() const { return m_hOwner; }
  110. void Owner(const HWND h) {
  111. if (m_hOwner != h) {
  112. if ((m_hOwner != INVALID_HWND) && (h != INVALID_HWND)) {
  113. ::MapWindowPoints(m_hOwner, h, reinterpret_cast<LPPOINT>(static_cast<LPRECT>(this)), 2);
  114. }
  115. m_hOwner = h;
  116. m_bRequiresSave = true;
  117. }
  118. return;
  119. }
  120. bool IsDirty() const { return m_bRequiresSave; }
  121. void Dirty(const bool fVal) { m_bRequiresSave = fVal; }
  122. bool m_bRequiresSave;
  123. private:
  124. HWND m_hOwner;
  125. };
  126. #endif
  127. // end of file scalingrect.h