ResizableFormView.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // ResizableFormView.cpp : implementation file
  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. #include "stdafx.h"
  17. #include "ResizableFormView.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CResizableFormView
  25. IMPLEMENT_DYNAMIC(CResizableFormView, CFormView)
  26. inline void CResizableFormView::Construct()
  27. {
  28. m_bInitDone = FALSE;
  29. }
  30. CResizableFormView::CResizableFormView(UINT nIDTemplate)
  31. : CFormView(nIDTemplate)
  32. {
  33. Construct();
  34. }
  35. CResizableFormView::CResizableFormView(LPCTSTR lpszTemplateName)
  36. : CFormView(lpszTemplateName)
  37. {
  38. Construct();
  39. }
  40. CResizableFormView::~CResizableFormView()
  41. {
  42. }
  43. BEGIN_MESSAGE_MAP(CResizableFormView, CFormView)
  44. //{{AFX_MSG_MAP(CResizableFormView)
  45. ON_WM_SIZE()
  46. ON_WM_ERASEBKGND()
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CResizableFormView diagnostics
  51. #ifdef _DEBUG
  52. void CResizableFormView::AssertValid() const
  53. {
  54. CFormView::AssertValid();
  55. }
  56. void CResizableFormView::Dump(CDumpContext& dc) const
  57. {
  58. CFormView::Dump(dc);
  59. }
  60. #endif //_DEBUG
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CResizableFormView message handlers
  63. void CResizableFormView::OnSize(UINT nType, int cx, int cy)
  64. {
  65. CFormView::OnSize(nType, cx, cy);
  66. if (m_bInitDone)
  67. ArrangeLayout();
  68. }
  69. void CResizableFormView::OnInitialUpdate()
  70. {
  71. CFormView::OnInitialUpdate();
  72. m_bInitDone = TRUE;
  73. // MDI child need this
  74. ArrangeLayout();
  75. }
  76. void CResizableFormView::GetTotalClientRect(LPRECT lpRect)
  77. {
  78. GetClientRect(lpRect);
  79. // get scrollable size
  80. CSize size = GetTotalSize();
  81. // before initialization, "size" is dialog template size
  82. if (!m_bInitDone)
  83. {
  84. lpRect->right = lpRect->left + size.cx;
  85. lpRect->bottom = lpRect->top + size.cy;
  86. return;
  87. }
  88. // otherwise, give correct size if scrollbars active
  89. if (m_nMapMode < 0) // scrollbars disabled
  90. return;
  91. // enlarge reported client area when needed
  92. CRect rect(lpRect);
  93. if (rect.Width() < size.cx)
  94. lpRect->right = lpRect->left + size.cx;
  95. if (rect.Height() < size.cy)
  96. lpRect->bottom = lpRect->top + size.cy;
  97. }
  98. BOOL CResizableFormView::OnEraseBkgnd(CDC* pDC)
  99. {
  100. ClipChildren(pDC); // avoid flickering
  101. return CFormView::OnEraseBkgnd(pDC);
  102. }