FormToolbar.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////
  19. //
  20. // FormToolbarClass.CPP
  21. //
  22. // Module defining a CControlBar derived class which is used to implement
  23. // floating or dockable toolbars containing dialogs.
  24. //
  25. //
  26. #include "StdAfx.H"
  27. #include "FormToolbar.H"
  28. #include "DockableForm.H"
  29. BEGIN_MESSAGE_MAP(FormToolbarClass, CControlBar)
  30. //{{AFX_MSG_MAP(FormToolbarClass)
  31. ON_WM_SIZE()
  32. ON_WM_ERASEBKGND()
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. //////////////////////////////////////////////////////////////
  36. //
  37. // Local constants
  38. //
  39. const int BORDER_TOP = 6;
  40. const int BORDER_BOTTOM = 6;
  41. const int BORDER_LEFT = 6;
  42. const int BORDER_RIGHT = 6;
  43. //////////////////////////////////////////////////////////////
  44. //
  45. // FormToolbarClass
  46. //
  47. FormToolbarClass::FormToolbarClass (void)
  48. : m_pCForm (NULL)
  49. {
  50. m_minSize.cx = 100;
  51. m_minSize.cy = 100;
  52. return ;
  53. }
  54. //////////////////////////////////////////////////////////////
  55. //
  56. // ~FormToolbarClass
  57. //
  58. FormToolbarClass::~FormToolbarClass (void)
  59. {
  60. if (m_pCForm) {
  61. // Free the dockable form
  62. delete m_pCForm;
  63. m_pCForm = NULL;
  64. }
  65. return ;
  66. }
  67. //////////////////////////////////////////////////////////////
  68. //
  69. // Create
  70. //
  71. BOOL
  72. FormToolbarClass::Create
  73. (
  74. DockableFormClass *pCFormClass,
  75. LPCTSTR pszWindowName,
  76. CWnd *pCParentWnd,
  77. UINT uiID
  78. )
  79. {
  80. ASSERT (pCFormClass);
  81. m_pCForm = pCFormClass;
  82. // Allow the base class to process this message
  83. RECT rect = { 0 };
  84. BOOL retval = CWnd::Create (NULL, pszWindowName, WS_CHILD | WS_VISIBLE, rect, pCParentWnd, uiID);
  85. if (retval) {
  86. // Ask the dockable form to create itself
  87. retval = m_pCForm->Create (this, 101);
  88. CRect rect;
  89. rect = m_pCForm->Get_Form_Rect ();
  90. m_minSize.cx = rect.Width ();
  91. m_minSize.cy = rect.Height ();
  92. m_minSize.cx += BORDER_LEFT + BORDER_RIGHT;
  93. m_minSize.cy += BORDER_TOP + BORDER_BOTTOM;
  94. SetWindowPos (NULL, 0, 0, m_minSize.cx, m_minSize.cy, SWP_NOZORDER | SWP_NOMOVE);
  95. m_pCForm->SetWindowPos (NULL, BORDER_LEFT, BORDER_TOP, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  96. // Allow the toolbar to be resized
  97. // Allow the toolbar to be docked either to the right or left
  98. SetBarStyle (GetBarStyle() | CBRS_SIZE_DYNAMIC);
  99. EnableDocking (CBRS_ALIGN_RIGHT | CBRS_ALIGN_LEFT);
  100. }
  101. // Return the TRUE/FALSE result code
  102. return retval;
  103. }
  104. //////////////////////////////////////////////////////////////
  105. //
  106. // OnSize
  107. //
  108. void
  109. FormToolbarClass::OnSize
  110. (
  111. UINT nType,
  112. int cx,
  113. int cy
  114. )
  115. {
  116. // Allow the base class to process this message
  117. CControlBar::OnSize(nType, cx, cy);
  118. if (m_pCForm && (cx > 0) && (cy > 0)) {
  119. // Get the bounding rectangle
  120. CRect rect;
  121. GetClientRect (rect);
  122. // Resize the dockable form window
  123. m_pCForm->SetWindowPos (NULL,
  124. 0,
  125. 0,
  126. rect.Width () - (BORDER_LEFT + BORDER_RIGHT),
  127. rect.Height () - (BORDER_TOP + BORDER_BOTTOM),
  128. SWP_NOZORDER | SWP_NOMOVE);
  129. }
  130. return ;
  131. }
  132. //////////////////////////////////////////////////////////////
  133. //
  134. // OnEraseBkgnd
  135. //
  136. BOOL
  137. FormToolbarClass::OnEraseBkgnd (CDC* pDC)
  138. {
  139. // Get the bounding rectangle
  140. RECT rect;
  141. GetClientRect (&rect);
  142. // Paint the background light gray
  143. ::FillRect (*pDC, &rect, (HBRUSH)(COLOR_3DFACE + 1));
  144. // Allow the base class to process this message
  145. return CControlBar::OnEraseBkgnd(pDC);
  146. }