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.

325 lines
8.2 KiB

  1. ///////////////////////////////////////////////////////////
  2. //
  3. //
  4. // SIZEBAR.cpp - CSizeBar control encapsulates the sizebar
  5. //
  6. //
  7. //
  8. // Copyright (C) 1996-1997 Microsoft Corporation. All rights reserved.
  9. ///////////////////////////////////////////////////////////
  10. //
  11. // Includes
  12. //
  13. #include "header.h"
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static const char THIS_FILE[] = __FILE__;
  17. #endif
  18. #include "system.h"
  19. #include "secwin.h"
  20. #include "contain.h"
  21. // For ID_TAB_CONTROL
  22. #include "resource.h"
  23. #include "windowsx.h"
  24. // For the ScreenRectToClientRect Function.
  25. #include "navpane.h"
  26. ///////////////////////////////////////////////////////////
  27. //
  28. // external functions.
  29. //
  30. ///////////////////////////////////////////////////////////
  31. //
  32. // Constructor
  33. //
  34. CSizeBar::CSizeBar()
  35. : m_hWnd(NULL),
  36. m_hWndParent(NULL),
  37. m_pWinType(NULL),
  38. m_bDragging(false)
  39. {
  40. }
  41. ///////////////////////////////////////////////////////////
  42. //
  43. // Destructor
  44. //
  45. CSizeBar::~CSizeBar()
  46. {
  47. if ( IsValidWindow(m_hWnd) )
  48. {
  49. DestroyWindow( m_hWnd);
  50. }
  51. }
  52. ///////////////////////////////////////////////////////////
  53. //
  54. // Operations
  55. ///////////////////////////////////////////////////////////
  56. //
  57. // Create
  58. //
  59. bool
  60. CSizeBar::Create(CHHWinType* pWinType)
  61. {
  62. // Validate
  63. ASSERT(pWinType) ;
  64. ASSERT(IsValidWindow(pWinType->GetHwnd())) ;
  65. // Save
  66. m_hWndParent = pWinType->GetHwnd();
  67. m_pWinType = pWinType ;
  68. // Calc the size
  69. RECT rcSizeBar ;
  70. CalcSize(&rcSizeBar) ;
  71. // Create the window.
  72. m_hWnd = CreateWindow(txtSizeBarChildWindowClass, NULL,
  73. WS_CHILD | WS_VISIBLE,
  74. rcSizeBar.left, rcSizeBar.top,
  75. RECT_WIDTH(rcSizeBar), RECT_HEIGHT(rcSizeBar),
  76. m_hWndParent, NULL, _Module.GetModuleInstance(), NULL);
  77. if (m_hWnd)
  78. {
  79. // Set the userdata to our this pointer.
  80. SetWindowLongPtr(m_hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
  81. return true;
  82. }
  83. else
  84. return false ;
  85. }
  86. ///////////////////////////////////////////////////////////
  87. //
  88. // ResizeWindow
  89. void
  90. CSizeBar::ResizeWindow()
  91. {
  92. // Validate
  93. ASSERT(IsValidWindow(hWnd())) ;
  94. // Calculate our size.
  95. RECT rc;
  96. CalcSize(&rc); // This will be the navigation window.
  97. // Size the window.
  98. MoveWindow(hWnd(), rc.left, rc.top,
  99. RECT_WIDTH(rc), RECT_HEIGHT(rc),
  100. TRUE); // need to repaint the sizebar when their is a margin on the right
  101. // end of the toolbar so the ghost of the sizebar is removed
  102. // Redraw the sizebar.
  103. Draw() ;
  104. }
  105. ///////////////////////////////////////////////////////////
  106. //
  107. // RegisterWindowClass
  108. //
  109. void
  110. CSizeBar::RegisterWindowClass()
  111. {
  112. WNDCLASS wc;
  113. ZeroMemory(&wc, sizeof(WNDCLASS)); // clear all members
  114. wc.hInstance = _Module.GetModuleInstance();
  115. wc.hbrBackground = (HBRUSH) COLOR_WINDOW;
  116. //wc.lpszMenuName = MAKEINTRESOURCE(HH_MENU);
  117. wc.lpfnWndProc = s_SizeBarProc;
  118. wc.lpszClassName = txtSizeBarChildWindowClass;
  119. wc.hCursor = LoadCursor(NULL, IDC_SIZEWE);
  120. VERIFY(RegisterClass(&wc));
  121. }
  122. ///////////////////////////////////////////////////////////
  123. //
  124. // Access Functions
  125. //
  126. ///////////////////////////////////////////////////////////
  127. //
  128. // Width
  129. //
  130. int
  131. CSizeBar::Width()
  132. {
  133. // Current the width is fixed, but based on metrics.
  134. return GetSystemMetrics(SM_CXSIZEFRAME);
  135. }
  136. ///////////////////////////////////////////////////////////
  137. //
  138. // Internal Helper Functions
  139. //
  140. ///////////////////////////////////////////////////////////
  141. //
  142. // CalcSize
  143. //
  144. void
  145. CSizeBar::CalcSize(RECT* prect)
  146. {
  147. ASSERT(m_pWinType) ;
  148. // Get the size of the HTML Help window.
  149. RECT rectHtml ;
  150. ::GetWindowRect(m_pWinType->GetHTMLHwnd(), &rectHtml );
  151. // Convert to the coordinates of help window itself.
  152. ScreenRectToClientRect(m_hWndParent, &rectHtml) ;
  153. // Now use this information to create our rectangle.
  154. prect->left = rectHtml.left - Width() ;
  155. prect->right = prect->left + Width() ;
  156. prect->top = rectHtml.top ;
  157. prect->bottom = rectHtml.bottom ;
  158. }
  159. ///////////////////////////////////////////////////////////
  160. //
  161. // Draw
  162. //
  163. void
  164. CSizeBar::Draw()
  165. {
  166. // Get a dc to draw in.
  167. HDC hdc = GetDC(hWnd()) ;
  168. // get the rectangle to draw on.
  169. RECT rc ;
  170. GetClientRect(hWnd(), &rc) ;
  171. // Draw the edge.
  172. DrawEdge(hdc, &rc, EDGE_ETCHED,
  173. m_bDragging ? (BF_TOPLEFT | BF_BOTTOMRIGHT | BF_MIDDLE) :(BF_TOPLEFT | BF_BOTTOM | BF_MIDDLE)) ;
  174. // Clean up.
  175. ReleaseDC(hWnd(), hdc) ;
  176. }
  177. ///////////////////////////////////////////////////////////
  178. //
  179. // Member function Window Proc
  180. //
  181. LRESULT
  182. CSizeBar::SizeBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  183. {
  184. switch (msg)
  185. {
  186. case WM_LBUTTONDOWN:
  187. if ( wParam == MK_LBUTTON && m_pWinType)
  188. {
  189. SetCapture(hwnd); // capture the mouse to this window.
  190. m_offset = GET_X_LPARAM(lParam) ; // The initial x position happens to be the offset.
  191. m_bDragging = true ;
  192. }
  193. break;
  194. case WM_LBUTTONUP:
  195. if (m_bDragging && (GetCapture() == hwnd))
  196. {
  197. ReleaseCapture(); // release the mouse capture from this window.
  198. //TODO - This nasty code uses to many internal members of CHHWinType...
  199. // Get the rectangle for the sizebar.
  200. RECT rcSizeBar ;
  201. GetWindowRect(m_hWnd, &rcSizeBar) ;
  202. ScreenRectToClientRect(m_pWinType->GetHwnd(), &rcSizeBar) ;
  203. // Change the left size of the Topic pane.
  204. m_pWinType->rcHTML.left = rcSizeBar.right;
  205. // move the Nav Pane
  206. ASSERT(m_pWinType->GetNavigationHwnd());
  207. if (m_pWinType->IsExpandedNavPane() &&
  208. IsValidWindow(m_pWinType->hwndNavigation))
  209. {
  210. m_pWinType->rcNav.right = rcSizeBar.left;
  211. }
  212. // resize the tab control and its' dialogs. This will also resize the sizebar and draw it.
  213. ::ResizeWindow(m_pWinType, false); // This is the one defined in wndproc.cpp. Don't recalc the sizes. Use the ones we've set.
  214. m_bDragging = false ;
  215. }
  216. break;
  217. case WM_MOUSEMOVE:
  218. if (m_bDragging)
  219. {
  220. ASSERT(m_pWinType) ;
  221. // Get the rectangle for the htmlhelp window.
  222. RECT rcHelpWin;
  223. GetClientRect(m_pWinType->GetHwnd(), &rcHelpWin);
  224. // Get the rectangle for the sizebar.
  225. RECT rcSizeBar ;
  226. GetWindowRect(m_hWnd, &rcSizeBar) ;
  227. // Calculate the new position.
  228. ScreenRectToClientRect(m_pWinType->GetHwnd(), &rcSizeBar) ;
  229. rcSizeBar.left += GET_X_LPARAM(lParam) - m_offset ;
  230. // The width of rcSizeBar is now not correct.
  231. // Validate the new position.
  232. if ( (rcSizeBar.left > MinimumPaneWidth()) && // Check left side.
  233. (rcSizeBar.left + Width() < rcHelpWin.right - MinimumTopicWidth()) ) // Check right boundary.
  234. {
  235. // Move it.
  236. SetWindowPos(m_hWnd, NULL,
  237. rcSizeBar.left,
  238. rcSizeBar.top,
  239. 0,0,
  240. SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER) ;
  241. }
  242. }
  243. break;
  244. case WM_PAINT:
  245. {
  246. // Draw an edige on the left side of the size bar.
  247. PAINTSTRUCT ps;
  248. HDC hdc = BeginPaint(hwnd, &ps) ;
  249. Draw() ;
  250. EndPaint(hwnd, &ps) ;
  251. }
  252. break ;
  253. case WM_ERASEBKGND:
  254. return 1; // We don't want the background erased.
  255. default:
  256. return DefWindowProc(hwnd, msg, wParam, lParam);
  257. }
  258. return 0;
  259. }
  260. ///////////////////////////////////////////////////////////
  261. //
  262. // Callbacks
  263. //
  264. ///////////////////////////////////////////////////////////
  265. //
  266. // Static Window Proc
  267. //
  268. LRESULT WINAPI
  269. CSizeBar::s_SizeBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  270. {
  271. CSizeBar* pThis = reinterpret_cast<CSizeBar*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
  272. if (pThis)
  273. return pThis->SizeBarProc(hwnd, msg, wParam, lParam) ;
  274. else
  275. return DefWindowProc(hwnd, msg, wParam, lParam);
  276. }