ResizableLayout.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // ResizableLayout.h: interface for the CResizableLayout class.
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. //
  5. // Copyright (C) 2000-2001 by Paolo Messina
  6. // (http://www.geocities.com/ppescher - ppescher@yahoo.com)
  7. //
  8. // The contents of this file are subject to the Artistic License (the "License").
  9. // You may not use this file except in compliance with the License.
  10. // You may obtain a copy of the License at:
  11. // http://www.opensource.org/licenses/artistic-license.html
  12. //
  13. // If you find this code useful, credits would be nice!
  14. //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #if !defined(AFX_RESIZABLELAYOUT_H__INCLUDED_)
  17. #define AFX_RESIZABLELAYOUT_H__INCLUDED_
  18. #include <afxtempl.h>
  19. #if _MSC_VER > 1000
  20. #pragma once
  21. #endif // _MSC_VER > 1000
  22. // useful compatibility constants (the only one required is NOANCHOR)
  23. const CSize NOANCHOR(-1,-1),
  24. TOP_LEFT(0,0), TOP_CENTER(50,0), TOP_RIGHT(100,0),
  25. MIDDLE_LEFT(0,50), MIDDLE_CENTER(50,50), MIDDLE_RIGHT(100,50),
  26. BOTTOM_LEFT(0,100), BOTTOM_CENTER(50,100), BOTTOM_RIGHT(100,100);
  27. class CResizableLayout
  28. {
  29. public:
  30. class LayoutInfo
  31. {
  32. public:
  33. HWND hWnd;
  34. UINT nCallbackID;
  35. BOOL bAdjHScroll;
  36. BOOL bNeedRefresh;
  37. // upper-left corner
  38. SIZE sizeTypeTL;
  39. SIZE sizeMarginTL;
  40. // bottom-right corner
  41. SIZE sizeTypeBR;
  42. SIZE sizeMarginBR;
  43. public:
  44. LayoutInfo()
  45. { ZeroMemory(this, sizeof(LayoutInfo)); }
  46. LayoutInfo(HWND hwnd, SIZE tl_t, SIZE tl_m,
  47. SIZE br_t, SIZE br_m, BOOL hscroll, BOOL refresh)
  48. {
  49. hWnd = hwnd;
  50. nCallbackID = 0;
  51. bAdjHScroll = hscroll;
  52. bNeedRefresh = refresh;
  53. sizeTypeTL = tl_t;
  54. sizeMarginTL = tl_m;
  55. sizeTypeBR = br_t;
  56. sizeMarginBR = br_m;
  57. }
  58. };
  59. // list of repositionable controls (in 2 parts: anchors, callbacks)
  60. CArray<LayoutInfo, LayoutInfo&> m_arrLayout;
  61. int m_iFirstCallback; // index of first callback
  62. void EnumAndClipChildWindow(HWND hWnd, CDC* pDC);
  63. protected:
  64. virtual BOOL LikesClipping(HWND hWnd);
  65. virtual BOOL NeedsRefresh(HWND hWnd);
  66. // exclude child windows from the clipping region
  67. void ClipChildren(CDC *pDC);
  68. // override for scrollable or expanding parent windows
  69. virtual void GetTotalClientRect(LPRECT lpRect);
  70. // add anchors to a control, given its HWND
  71. void AddAnchor(HWND hWnd, CSize sizeTypeTL, CSize sizeTypeBR = NOANCHOR);
  72. // add anchors to a control, given its ID
  73. void AddAnchor(UINT nID, CSize sizeTypeTL, CSize sizeTypeBR = NOANCHOR)
  74. {
  75. AddAnchor(::GetDlgItem(GetResizableWnd()->GetSafeHwnd(), nID),
  76. sizeTypeTL, sizeTypeBR);
  77. }
  78. // add a callback (control ID or HWND is unknown or may change)
  79. void AddAnchorCallback(UINT nCallbackID);
  80. // adjust children's layout, when parent's size changes
  81. void ArrangeLayout();
  82. // override to provide dynamic control's layout info
  83. virtual BOOL ArrangeLayoutCallback(LayoutInfo& layout);
  84. // reset layout content
  85. void RemoveAllAnchors()
  86. {
  87. m_arrLayout.RemoveAll();
  88. m_iFirstCallback = 0;
  89. }
  90. virtual CWnd* GetResizableWnd() = 0;
  91. public:
  92. CResizableLayout() { m_iFirstCallback = 0; }
  93. virtual ~CResizableLayout()
  94. {
  95. // just for safety
  96. RemoveAllAnchors();
  97. }
  98. };
  99. #endif // !defined(AFX_RESIZABLELAYOUT_H__INCLUDED_)