Source code of Windows XP (NT5)
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.

104 lines
3.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999
  5. //
  6. // File: Resizer.cxx
  7. //
  8. // Contents: Implementation of the CResizer class
  9. //
  10. // Written by Joe Porkka
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.hxx"
  14. #include "Resizer.h"
  15. CResizer::CResizer()
  16. : _hWnd(0), _pResizeInfo(0)
  17. {
  18. memset(&_winRect, 0, sizeof(_winRect));
  19. }
  20. void CResizer::Init(HWND win, CResizeInfo *pResizeInfo)
  21. {
  22. _hWnd = win;
  23. _pResizeInfo = pResizeInfo;
  24. GetClientRect(_hWnd, &_winRect);
  25. for(CResizeInfo *p = _pResizeInfo; p->_id; ++p)
  26. {
  27. InitCtrl(p);
  28. }
  29. }
  30. CResizer::~CResizer()
  31. {
  32. }
  33. void CResizer::NewSize() const
  34. {
  35. RECT newDlgSize;
  36. GetClientRect(_hWnd, &newDlgSize);
  37. for(CResizeInfo *p = _pResizeInfo; p->_id; ++p)
  38. {
  39. RECT newpos = p->_Rect;
  40. if (p->_Flags & sf_Width)
  41. { // Adjust the width
  42. int w = (p->_Rect.right - p->_Rect.left) + (newDlgSize.right - _winRect.right);
  43. newpos.right = newpos.left + w;
  44. }
  45. if (p->_Flags & sf_Height)
  46. { // Adjust the height
  47. int h = (p->_Rect.bottom - p->_Rect.top) + (newDlgSize.bottom - _winRect.bottom);
  48. newpos.bottom = newpos.top + h;
  49. }
  50. if (p->_Flags & sf_Left)
  51. { // adjust left edge
  52. int w = p->_Rect.right - p->_Rect.left;
  53. newpos.left = newDlgSize.right - (_winRect.right - p->_Rect.left);
  54. newpos.right = newpos.left + w;
  55. }
  56. if (p->_Flags & sf_Top)
  57. { // adjust top edge
  58. int h = p->_Rect.bottom - p->_Rect.top;
  59. newpos.top = newDlgSize.bottom - (_winRect.bottom - p->_Rect.top);
  60. newpos.bottom = newpos.top + h;
  61. }
  62. if (p->_Flags & sf_HalfLeftWidth)
  63. { // adjust left edge & width by half width delta
  64. // int w = p->_Rect.right - p->_Rect.left;
  65. int widthdelta = newDlgSize.right - _winRect.right;
  66. newpos.left = p->_Rect.left + widthdelta / 2;
  67. newpos.right = p->_Rect.right + widthdelta;
  68. }
  69. if (p->_Flags & sf_HalfTopHeight)
  70. { // adjust left edge & width by half width delta
  71. int heightdelta = newDlgSize.bottom - _winRect.bottom;
  72. newpos.top = p->_Rect.top + heightdelta / 2;
  73. newpos.bottom = p->_Rect.bottom + heightdelta;
  74. }
  75. if (p->_Flags & sf_HalfWidth)
  76. { // adjust left edge & width by half width delta
  77. int widthdelta = newDlgSize.right - _winRect.right;
  78. newpos.right = p->_Rect.right + widthdelta - widthdelta / 2;
  79. }
  80. if (p->_Flags & sf_HalfHeight)
  81. { // adjust left edge & width by half width delta
  82. int heightdelta = newDlgSize.bottom - _winRect.bottom;
  83. newpos.bottom = p->_Rect.bottom + heightdelta - heightdelta / 2;
  84. }
  85. SetWindowPos(GetDlgItem(_hWnd, p->_id), 0, newpos.left, newpos.top, newpos.right - newpos.left, newpos.bottom - newpos.top, SWP_NOZORDER);
  86. }
  87. }
  88. void CResizer::InitCtrl(CResizeInfo *p)
  89. {
  90. GetWindowRect(GetDlgItem(_hWnd, p->_id), &p->_Rect);
  91. MapWindowPoints(0, _hWnd, (POINT *)&p->_Rect, 2); // Map abs coordinates of control to dialog relative.
  92. }