Counter Strike : Global Offensive Source Code
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.

267 lines
8.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implements a special dockable dialog bar that activates itself when
  4. // the mouse cursor moves over it. This enables stacking of the
  5. // bars with only a small portion of each visible.
  6. //
  7. // $Workfile: $
  8. // $Date: $
  9. //
  10. //-----------------------------------------------------------------------------
  11. // $Log: $
  12. //
  13. // $NoKeywords: $
  14. //=============================================================================//
  15. #include "stdafx.h"
  16. #include "hammer.h"
  17. #include "HammerBar.h"
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include <tier0/memdbgon.h>
  20. BEGIN_MESSAGE_MAP(CHammerBar, CDialogBar)
  21. ON_WM_SETCURSOR()
  22. END_MESSAGE_MAP()
  23. //-----------------------------------------------------------------------------
  24. // Purpose: Automagically bring this bar to the top when the mouse cursor passes
  25. // over it.
  26. // Input : pWnd -
  27. // nHitTest -
  28. // message -
  29. // Output : Always returns FALSE.
  30. //-----------------------------------------------------------------------------
  31. BOOL CHammerBar::OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message)
  32. {
  33. if (APP()->IsActiveApp())
  34. {
  35. // The control bar window is actually our grandparent.
  36. CWnd *pwnd = GetParent();
  37. if (pwnd != NULL)
  38. {
  39. pwnd = pwnd->GetParent();
  40. if (pwnd != NULL)
  41. {
  42. pwnd->BringWindowToTop();
  43. }
  44. }
  45. }
  46. //this wasn't being called and fixes some minor cursor problems.
  47. return CWnd::OnSetCursor( pWnd, nHitTest, message );
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Purpose: called automatically on a resize.
  51. // calls the function to move the bar's controls around on a resize.
  52. // also calls the CWnd OnSize so it can do what it needs to.
  53. // Input : passed in by windows
  54. // UINT nType
  55. // int cx - change in width
  56. // int cy - change in height
  57. // Output : void
  58. //-----------------------------------------------------------------------------
  59. void CHammerBar::OnSize( UINT nType, int cx, int cy )
  60. {
  61. CWnd::OnSize( nType, cx, cy );
  62. AdjustControls();
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Purpose: called by windows when the edges of the dialog are clicked
  66. // returns the size of the dialog
  67. // Input : passed automatically by windows
  68. // int nLength - amount the dialog edge has moved
  69. // DWORD dwMode - type of dialog/movement we are dealing with
  70. // Output : CSize - size of the dialog
  71. //-----------------------------------------------------------------------------
  72. CSize CHammerBar::CalcDynamicLayout(int nLength, DWORD dwMode)
  73. {
  74. CSize newSize;
  75. // If the bar is docked, use the default size
  76. if ( (dwMode & LM_VERTDOCK) || (dwMode & LM_HORZDOCK) )
  77. {
  78. m_sizeDocked.cy = m_sizeFloating.cy;
  79. return m_sizeDocked;
  80. }
  81. //if the bar is floating, use the current floating size
  82. if ( dwMode & LM_MRUWIDTH )
  83. {
  84. return m_sizeFloating;
  85. }
  86. // In all other cases, we are changing the length with a drag
  87. if ( dwMode & LM_LENGTHY )
  88. {
  89. //the bar is being resized in the y direction
  90. newSize = CSize( m_sizeFloating.cx, m_sizeFloating.cy = nLength );
  91. }
  92. else
  93. {
  94. //the bar is being resized in the x direction
  95. newSize = CSize( m_sizeFloating.cx = nLength, m_sizeFloating.cy);
  96. }
  97. CString textTitle;
  98. GetWindowText( textTitle );
  99. //it should not be possible that a bar with no name could be dynamic; this check is just to be safe
  100. if ( !textTitle.IsEmpty() )
  101. {
  102. //writing the new size of the bar to the registry
  103. textTitle = "FloatingBarSize\\" + textTitle;
  104. APP()->WriteProfileInt( textTitle, "floatX", newSize.cx );
  105. APP()->WriteProfileInt( textTitle, "floatY", newSize.cy );
  106. }
  107. return newSize;
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose: creates the CHammerBar.
  111. // makes sure a bar created with this old function isn't dyanmic
  112. // initializes size variables.
  113. // Input : CWnd *pParentWnd
  114. // UINT nIDTemplate - the ID of the dialog to be created
  115. // UINT nStyle - the type of dialog we are making
  116. // UINT nID -
  117. // Output : BOOL - TRUE on success
  118. //-----------------------------------------------------------------------------
  119. BOOL CHammerBar::Create( CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID )
  120. {
  121. //cannot have a dynamic bar with this Create function; must use the one that takes the window name
  122. UINT nStyleFixed = nStyle & ~CBRS_SIZE_DYNAMIC;
  123. if ( !CDialogBar::Create(pParentWnd,nIDTemplate,nStyleFixed,nID) )
  124. return FALSE;
  125. m_sizeFloating = m_sizeDocked = m_sizeDefault;
  126. return TRUE;
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Purpose: creates the CHammerBar.
  130. // initializes size variables.
  131. // reads saved dimension information from registry
  132. // Input : CWnd *pParentWnd
  133. // UINT nIDTemplate - the ID of the dialog to be created
  134. // UINT nStyle - the type of dialog we are making
  135. // UINT nID -
  136. // Output : BOOL - TRUE on success
  137. //-----------------------------------------------------------------------------
  138. BOOL CHammerBar::Create( CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID, char *pszName )
  139. {
  140. UINT nStyleFixed = nStyle;
  141. if ( *pszName == 0 )
  142. {
  143. //did not give a title and cannot have a dynamic bar. Routing back through old create
  144. return Create( pParentWnd, nIDTemplate, nStyle, nID );
  145. }
  146. else
  147. {
  148. if ( !CDialogBar::Create(pParentWnd,nIDTemplate,nStyleFixed,nID) )
  149. return FALSE;
  150. SetWindowText( pszName );
  151. CString textTitle;
  152. textTitle = "FloatingBarSize\\" + CString(pszName);
  153. //read size from registry
  154. m_sizeFloating.cx = APP()->GetProfileInt( textTitle, "floatX", m_sizeDefault.cx );
  155. m_sizeFloating.cy = APP()->GetProfileInt( textTitle, "floatY", m_sizeDefault.cy );
  156. m_sizeDocked = m_sizeDefault;
  157. }
  158. return TRUE;
  159. }
  160. //-----------------------------------------------------------------------------
  161. // Purpose: moves controls based on their placement information
  162. //
  163. // Input : void
  164. //
  165. // Output : void
  166. //-----------------------------------------------------------------------------
  167. void CHammerBar::AdjustControls( void )
  168. {
  169. CRect HammerBarPos;
  170. GetWindowRect( &HammerBarPos );
  171. int nHammerBarHeight = HammerBarPos.Height();
  172. int nHammerBarWidth = HammerBarPos.Width();
  173. for( int iControl = 0; iControl < m_ControlList.Count(); iControl++ )
  174. {
  175. ControlInfo_t currentControl = m_ControlList[ iControl ];
  176. int nDialogID = currentControl.m_nIDDialogItem;
  177. int nControlWidthDifference = currentControl.m_nWidthBuffer;
  178. int nControlHeightDifference = currentControl.m_nHeightBuffer;
  179. DWORD dwPlacement = currentControl.m_dwPlacementFlag;
  180. CWnd* pControl = GetDlgItem( nDialogID );
  181. if ( pControl != NULL )
  182. {
  183. if ( dwPlacement & GROUP_BOX )
  184. {
  185. pControl->SetWindowPos( NULL, 0, 0, nHammerBarWidth - nControlWidthDifference ,
  186. nHammerBarHeight - nControlHeightDifference, SWP_NOMOVE|SWP_NOZORDER );
  187. }
  188. if ( dwPlacement & BOTTOM_JUSTIFY )
  189. {
  190. CRect controlPos;
  191. pControl->GetWindowRect( &controlPos );
  192. pControl->SetWindowPos( NULL, controlPos.left - HammerBarPos.left,
  193. HammerBarPos.Height() - currentControl.m_nPosY, 0, 0, SWP_NOSIZE|SWP_NOZORDER );
  194. }
  195. if ( dwPlacement & RIGHT_JUSTIFY )
  196. {
  197. CRect controlPos;
  198. pControl->GetWindowRect( &controlPos );
  199. pControl->SetWindowPos( NULL, HammerBarPos.Width() - currentControl.m_nPosX,
  200. controlPos.top - HammerBarPos.top, 0, 0, SWP_NOSIZE|SWP_NOZORDER );
  201. }
  202. }
  203. }
  204. }
  205. //-----------------------------------------------------------------------------
  206. // Purpose: adds controls to the CHammerBar
  207. // determines position and stretch settings based on default design /
  208. // Input : int nIDTemplate - ID from .rc file of control to be added
  209. // DWORD dwPlacementFlag - placement information
  210. // GROUP_BOX - will be stretched to fit new size
  211. // BOTTOM_JUSTIFY - will move with the bottom of the dialog
  212. // RIGHT_JUSTIFY - will move with the right side of the dialog//
  213. // Output : void
  214. //-----------------------------------------------------------------------------
  215. void CHammerBar::AddControl( int nIDTemplate, DWORD dwPlacementFlag )
  216. {
  217. ControlInfo_t newControl;
  218. newControl.m_nIDDialogItem = nIDTemplate;
  219. newControl.m_dwPlacementFlag = dwPlacementFlag;
  220. CWnd *pControl = GetDlgItem( nIDTemplate );
  221. if ( pControl != NULL )
  222. {
  223. CRect controlPos, hammerBarPos;
  224. pControl->GetWindowRect( &controlPos );
  225. GetWindowRect( &hammerBarPos );
  226. newControl.m_nHeightBuffer = m_sizeDefault.cy - controlPos.Height();
  227. newControl.m_nWidthBuffer = m_sizeDefault.cx - controlPos.Width();
  228. newControl.m_nPosX = m_sizeDefault.cx + hammerBarPos.left - controlPos.left;
  229. newControl.m_nPosY = m_sizeDefault.cy + hammerBarPos.top - controlPos.top;
  230. m_ControlList.AddToTail( newControl );
  231. }
  232. }
  233. CHammerBar::~CHammerBar()
  234. {
  235. m_ControlList.RemoveAll();
  236. }