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.

421 lines
9.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: docksite.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __DOCKSITE_H__
  11. #define __DOCKSITE_H__
  12. #include "controls.h"
  13. // DockSite.h : header file
  14. //
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CDockSite window
  17. // Forward references
  18. class CDockWindow;
  19. class CDockSite;
  20. class CReBar;
  21. template <class T>
  22. class CDockManager
  23. {
  24. // Construction
  25. public:
  26. CDockManager();
  27. ~CDockManager();
  28. //Operations
  29. public:
  30. // Add a site
  31. BOOL Attach(T* pSite);
  32. BOOL Detach(T* pSite);
  33. void RemoveAll();
  34. virtual void BeginLayout(int nWindows = 5);
  35. virtual void EndLayout();
  36. virtual void RenderDockSites(HWND hView, CRect& clientRect);
  37. protected:
  38. CList<T*, T*>* m_pManagedSites; // Array of View's that have docksite
  39. HDWP m_hDWP; // Handle for BeginDeferWindowPos
  40. };
  41. template <class T>
  42. CDockManager<T>::CDockManager()
  43. {
  44. m_pManagedSites = new CList<T*, T*>;
  45. m_hDWP = 0;
  46. }
  47. template <class T>
  48. CDockManager<T>::~CDockManager()
  49. {
  50. delete m_pManagedSites;
  51. }
  52. template <class T>
  53. BOOL CDockManager<T>::Attach(T* pView)
  54. {
  55. ASSERT(pView != NULL);
  56. return (m_pManagedSites->AddTail(pView) != NULL);
  57. }
  58. template <class T>
  59. BOOL CDockManager<T>::Detach(T* pView)
  60. {
  61. ASSERT(pView != NULL);
  62. POSITION pos = m_pManagedSites->Find(pView);
  63. if (pos == NULL)
  64. return FALSE;
  65. return m_pManagedSites->RemoveAt(pos);
  66. }
  67. template <class T>
  68. void CDockManager<T>::RemoveAll()
  69. {
  70. m_pManagedSites->RemoveAll();
  71. }
  72. template <class T>
  73. void CDockManager<T>::BeginLayout(int nWindows)
  74. {
  75. m_hDWP = ::BeginDeferWindowPos(nWindows);
  76. }
  77. template <class T>
  78. void CDockManager<T>::EndLayout()
  79. {
  80. ::EndDeferWindowPos(m_hDWP);
  81. m_hDWP = 0;
  82. }
  83. template <class T>
  84. void CDockManager<T>::RenderDockSites(HWND hView, CRect& clientRect)
  85. {
  86. ASSERT(m_hDWP != 0);
  87. T* pDockSite;
  88. POSITION pos = m_pManagedSites->GetHeadPosition();
  89. // No sites in to manage
  90. if (pos == NULL)
  91. return ;
  92. // Save a copy of the full client rect
  93. CRect savedClient;
  94. CRect totalSite(0,0,0,0);
  95. CPoint point(0, 0);
  96. int yTop = 0;
  97. int yBottom = clientRect.bottom;
  98. savedClient.CopyRect(&clientRect);
  99. while (pos)
  100. {
  101. pDockSite = m_pManagedSites->GetNext(pos);
  102. ASSERT(pDockSite != NULL);
  103. // Set the y coordinate for the site layout logic
  104. if (pDockSite->GetStyle() == CDockSite::DSS_TOP)
  105. point.y = yTop;
  106. else
  107. point.y = yBottom;
  108. pDockSite->RenderLayout(m_hDWP, clientRect, point);
  109. // totalSite = saveRect - clientRect
  110. totalSite = savedClient;
  111. totalSite -= clientRect;
  112. // Adjust the y coordinate for the next site in the list
  113. if (pDockSite->GetStyle() == CDockSite::DSS_TOP)
  114. yTop += totalSite.Height();
  115. else
  116. yBottom -= totalSite.Height();
  117. // client rect before the site adjusts it
  118. savedClient = clientRect;
  119. }
  120. // Position the view window
  121. ::DeferWindowPos(m_hDWP, hView, NULL, savedClient.left, // x
  122. savedClient.top+yTop, //y
  123. savedClient.Width(),
  124. savedClient.Height(),
  125. SWP_NOZORDER|SWP_NOACTIVATE);
  126. }
  127. class CDockSite
  128. {
  129. // Construction
  130. public:
  131. enum DSS_STYLE
  132. {
  133. DSS_TOP = 0, // Locate site at the window top
  134. DSS_BOTTOM, // Locate site at the window bottom
  135. DSS_LEFT, // Locate site at the window left-side
  136. DSS__RIGHT, //
  137. };
  138. public:
  139. CDockSite();
  140. // Create this site for the parent window pParent and allocate room for 10 CDockWindows.
  141. BOOL Create(DSS_STYLE style=DSS_TOP);
  142. // Operations
  143. public:
  144. public:
  145. // Add a window to be docked to this site
  146. BOOL Attach(CDockWindow* pWnd);
  147. // Remove a window from the site
  148. BOOL Detach(CDockWindow* pWnd);
  149. // Compute all the regions sizes for layout
  150. bool IsVisible();
  151. void Toggle();
  152. DSS_STYLE GetStyle();
  153. virtual void RenderLayout(HDWP& hdwp, CRect& clientRect, CPoint& xyLocation);
  154. virtual void Show(BOOL bState = TRUE);
  155. // Attributes
  156. private:
  157. CList<CDockWindow*, CDockWindow*>* m_pManagedWindows; // Array of CDockWindow
  158. CWnd* m_pParentWnd; // Window that contains the docksite
  159. DSS_STYLE m_style; // Style of the site
  160. CRect m_rect; // Rectangle for the docksite size
  161. BOOL m_bVisible; // Docksite visible or hidded
  162. // Implementation
  163. public:
  164. virtual ~CDockSite();
  165. };
  166. /////////////////////////////////////////////////////////////////////////////
  167. inline CDockSite::DSS_STYLE CDockSite::GetStyle()
  168. {
  169. return m_style;
  170. }
  171. inline bool CDockSite::IsVisible()
  172. {
  173. return (m_bVisible != FALSE);
  174. }
  175. inline void CDockSite::Toggle()
  176. {
  177. Show(!m_bVisible);
  178. }
  179. /////////////////////////////////////////////////////////////////////////////
  180. // CDockWindow window
  181. class CDockWindow : public CWnd
  182. {
  183. DECLARE_DYNAMIC (CDockWindow)
  184. enum DWS_STYLE
  185. {
  186. DWS_HORIZONTAL, // Place window horizontally within the site
  187. DWS_VERTICAL, // Place window vetically within the site
  188. };
  189. // Construction
  190. public:
  191. CDockWindow();
  192. // Attributes
  193. public:
  194. // Operations
  195. public:
  196. // Given the maxRect, determine the toolwindow size and calculate size
  197. virtual CRect CalculateSize(CRect maxRect) = 0;
  198. // Top level create to initialize the CDockWindow and control
  199. virtual BOOL Create(CWnd* pParentWnd, DWORD dwStyle, UINT nID) = 0;
  200. // Make visible/hidden
  201. virtual void Show(BOOL bState);
  202. bool IsVisible();
  203. void SetVisible(BOOL bState);
  204. private:
  205. BOOL m_bVisible;
  206. // Overrides
  207. // ClassWizard generated virtual function overrides
  208. //{{AFX_VIRTUAL(CDockWindow)
  209. protected:
  210. virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
  211. //}}AFX_VIRTUAL
  212. // Implementation
  213. public:
  214. virtual ~CDockWindow();
  215. // Generated message map functions
  216. protected:
  217. //{{AFX_MSG(CDockWindow)
  218. afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
  219. //}}AFX_MSG
  220. DECLARE_MESSAGE_MAP()
  221. };
  222. inline bool CDockWindow::IsVisible()
  223. {
  224. return (m_bVisible != FALSE);
  225. };
  226. inline void CDockWindow::SetVisible(BOOL bState)
  227. {
  228. m_bVisible = bState & 0x1;
  229. };
  230. /////////////////////////////////////////////////////////////////////////////
  231. /////////////////////////////////////////////////////////////////////////////
  232. // CStatBar window
  233. struct STATUSBARPANE
  234. {
  235. // default to sunken text with stretchy width
  236. STATUSBARPANE() { m_style = 0; m_width = -1; }
  237. int m_width;
  238. UINT m_style;
  239. CString m_paneText;
  240. };
  241. class CStatBar : public CDockWindow
  242. {
  243. DECLARE_DYNAMIC(CStatBar)
  244. // Construction
  245. public:
  246. CStatBar();
  247. // Attributes
  248. public:
  249. private:
  250. int m_nCount; // number of panes
  251. STATUSBARPANE* m_pPaneInfo; // array of pane structures, default is 10, no realloc implemented
  252. // Operations
  253. public:
  254. BOOL Create(CWnd* pParentWnd, DWORD dwStyle, UINT nID);
  255. CRect CalculateSize(CRect maxRect);
  256. void GetItemRect(int nIndex, LPRECT lpRect);
  257. void SetPaneStyle(int nIndex, UINT nStyle);
  258. BOOL CreatePanes(UINT* pIndicatorArray=NULL, int nCount=10);
  259. void SetPaneText(int nIndex, LPCTSTR lpszText, BOOL bUpdate = TRUE);
  260. void UpdateAllPanes(int clientWidth);
  261. // Overrides
  262. // ClassWizard generated virtual function overrides
  263. //{{AFX_VIRTUAL(CStatBar)
  264. //}}AFX_VIRTUAL
  265. // Implementation
  266. public:
  267. virtual ~CStatBar();
  268. // Generated message map functions
  269. protected:
  270. //{{AFX_MSG(CStatBar)
  271. afx_msg void OnSize(UINT nType, int cx, int cy);
  272. //}}AFX_MSG
  273. DECLARE_MESSAGE_MAP()
  274. private:
  275. };
  276. /////////////////////////////////////////////////////////////////////////////
  277. /////////////////////////////////////////////////////////////////////////////
  278. /////////////////////////////////////////////////////////////////////////////
  279. // CRebarDockWindow window
  280. #define SIZEABLEREBAR_GUTTER 6
  281. #define SIZEABLEREBAR_WINDOW _T("SizeableRebar")
  282. class CRebarDockWindow : public CDockWindow
  283. {
  284. // Construction
  285. public:
  286. CRebarDockWindow();
  287. // Attributes
  288. public:
  289. private:
  290. enum { ID_REBAR = 0x1000 };
  291. CRebarWnd m_wndRebar;
  292. bool m_bTracking;
  293. // Operations
  294. public:
  295. BOOL Create(CWnd* pParentWnd, DWORD dwStyle, UINT nID);
  296. CRect CalculateSize(CRect maxRect);
  297. void UpdateWindowSize(void);
  298. BOOL InsertBand(LPREBARBANDINFO lprbbi);
  299. LRESULT SetBandInfo(UINT uBand, LPREBARBANDINFO lprbbi);
  300. CRebarWnd* GetRebar ()
  301. { return &m_wndRebar; }
  302. // Overrides
  303. // ClassWizard generated virtual function overrides
  304. //{{AFX_VIRTUAL(CRebarDockWindow)
  305. protected:
  306. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  307. //}}AFX_VIRTUAL
  308. // Implementation
  309. public:
  310. virtual ~CRebarDockWindow();
  311. // Generated message map functions
  312. protected:
  313. //{{AFX_MSG(CRebarDockWindow)
  314. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  315. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  316. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  317. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  318. afx_msg void OnSize(UINT nType, int cx, int cy);
  319. //}}AFX_MSG
  320. DECLARE_MESSAGE_MAP()
  321. };
  322. /////////////////////////////////////////////////////////////////////////////
  323. /////////////////////////////////////////////////////////////////////////////
  324. //{{AFX_INSERT_LOCATION}}
  325. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  326. #endif // __DOCKSITE_H__