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.

315 lines
7.6 KiB

  1. // File: GenContainers.h
  2. #ifndef _GENCONTAINERS_H_
  3. #define _GENCONTAINERS_H_
  4. #include "GenWindow.h"
  5. // A bordered window class. A BorderWindow will layout its children on the 8
  6. // points of the compas plus the center. The creator should set the m_uParts
  7. // member to a bitmask of flags saying which parts are actually used. Then the
  8. // children will be layed out in those parts, in the order of the Parts enum
  9. class // DECLSPEC_UUID("")
  10. CBorderWindow : public CGenWindow
  11. {
  12. public:
  13. // Which parts of the border window are filled with children. The order of
  14. // the children in the window is the same as the order of these contants
  15. enum Parts
  16. {
  17. TopLeft = 0x0001,
  18. Top = 0x0002,
  19. TopRight = 0x0004,
  20. Left = 0x0008,
  21. Center = 0x0010,
  22. Right = 0x0020,
  23. BottomLeft = 0x0040,
  24. Bottom = 0x0080,
  25. BottomRight = 0x0100,
  26. } ;
  27. enum { NumParts = 9 } ;
  28. // BUGBUG georgep: We should probably use setters and getters for all of
  29. // these, so we can force a relayout
  30. // The horizontal gap between components
  31. int m_hGap;
  32. // The vertical gap between components
  33. int m_vGap;
  34. // One of the Alignment enum
  35. UINT m_uParts : 9;
  36. // Default constructor; inits a few intrinsics
  37. CBorderWindow();
  38. // Create the window
  39. BOOL Create(
  40. HWND hWndParent // The parent of the toolbar window
  41. );
  42. #if FALSE
  43. HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID riid, LPVOID *ppv)
  44. {
  45. if (__uuidof(CBorderWindow) == riid)
  46. {
  47. *ppv = this;
  48. AddRef();
  49. return(S_OK);
  50. }
  51. return(CGenWindow::QueryInterface(riid, ppv));
  52. }
  53. #endif // FALSE
  54. virtual void GetDesiredSize(SIZE *ppt);
  55. virtual void Layout();
  56. protected:
  57. virtual ~CBorderWindow() {}
  58. // Forward WM_COMMAND messages to the parent window
  59. virtual LRESULT ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  60. virtual void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
  61. private:
  62. UINT CBorderWindow::GetDesiredSize(
  63. HWND hwnds[CBorderWindow::NumParts],
  64. SIZE sizes[CBorderWindow::NumParts],
  65. int rows[3],
  66. int cols[3],
  67. SIZE *psize);
  68. } ;
  69. // A toolbar window class. A toolbar window will layout its children generally
  70. // from left-to-right or top-to-bottom, with margins around and gaps between
  71. // children, filling the window if specified. See the definitions for the
  72. // public fields.
  73. class DECLSPEC_UUID("{0BFB8454-ACA4-11d2-9C97-00C04FB17782}")
  74. CToolbar : public CGenWindow
  75. {
  76. public:
  77. // Where to align the children in the direction perpendicular to the flow:
  78. // in a horizontal toolbar, TopLeft will mean Top,and BottomRight will
  79. // mean Bottom
  80. enum Alignment
  81. {
  82. TopLeft = 0,
  83. Center,
  84. BottomRight,
  85. Fill,
  86. } ;
  87. // BUGBUG georgep: We should probably use setters and getters for all of
  88. // these, so we can force a relayout
  89. // The maximum gap between components
  90. int m_gap;
  91. // The left and right margin
  92. int m_hMargin;
  93. // The top and bottom margin
  94. int m_vMargin;
  95. // Start index of right-aligned children; they will still get layed out
  96. // left to right
  97. UINT m_uRightIndex;
  98. // One of the Alignment enum
  99. // HACKHACK georgep: I need to use an extra bit, or C++ gets confused by
  100. // the top bit (thinks it's signed)
  101. Alignment m_nAlignment : 3;
  102. // Vertical layout if TRUE
  103. BOOL m_bVertical : 1;
  104. // If TRUE, the child before m_uRightIndex will fill the center are of the
  105. // toolbar
  106. BOOL m_bHasCenterChild : 1;
  107. // HACKHACK georgep: Layout in reverse order if TRUE; this lets me fix
  108. // weird tabbing order problems
  109. BOOL m_bReverseOrder : 1;
  110. // Set this if you don't want the gaps calculated in the desired size
  111. BOOL m_bMinDesiredSize : 1;
  112. // Default constructor; inits a few intrinsics
  113. CToolbar();
  114. // Create the toolbar window
  115. BOOL Create(
  116. HWND hWndParent, // The parent of the toolbar window
  117. DWORD dwExStyle=0 // The extended style of the toolbar window
  118. );
  119. HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID riid, LPVOID *ppv)
  120. {
  121. if (__uuidof(CToolbar) == riid)
  122. {
  123. *ppv = this;
  124. AddRef();
  125. return(S_OK);
  126. }
  127. return(CGenWindow::QueryInterface(riid, ppv));
  128. }
  129. IGenWindow* FindControl(int nID);
  130. virtual void GetDesiredSize(SIZE *ppt);
  131. virtual void Layout();
  132. protected:
  133. virtual ~CToolbar() {}
  134. // Forward WM_COMMAND messages to the parent window
  135. virtual LRESULT ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  136. virtual void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
  137. private:
  138. void AdjustPos(POINT *pPos, SIZE *pSize, UINT width);
  139. // Get the first child to layout
  140. HWND GetFirstKid();
  141. // Get the next child to layout
  142. HWND GetNextKid(
  143. HWND hwndCurrent // The current child
  144. );
  145. } ;
  146. // Just makes the first child fill the client area
  147. class CFillWindow : public CGenWindow
  148. {
  149. public:
  150. // Just makes the first child fill the client area
  151. virtual void Layout();
  152. virtual void GetDesiredSize(SIZE *psize);
  153. // Get the info necessary for displaying a tooltip
  154. virtual void GetSharedTooltipInfo(TOOLINFO *pti);
  155. protected:
  156. HWND GetChild() { return(GetTopWindow(GetWindow())); }
  157. } ;
  158. // Maybe someday I will add a label for this, and multiple border types
  159. class CEdgedWindow : public CGenWindow
  160. {
  161. private:
  162. enum { s_nBorder = 2 };
  163. int GetBorderWidth() { return(s_nBorder); }
  164. public:
  165. // BUGBUG georgep: We should probably use setters and getters for all of
  166. // these, so we can force a relayout
  167. // The left and right margin
  168. int m_hMargin;
  169. // The top and bottom margin
  170. int m_vMargin;
  171. CEdgedWindow();
  172. ~CEdgedWindow();
  173. BOOL Create(HWND hwndParent);
  174. // Just makes the first child fill the client area - the border
  175. virtual void Layout();
  176. virtual void GetDesiredSize(SIZE *psize);
  177. void SetHeader(CGenWindow *pHeader);
  178. CGenWindow *GetHeader() { return(m_pHeader); }
  179. private:
  180. CGenWindow *m_pHeader;
  181. // Get the content window
  182. HWND GetContentWindow();
  183. void OnPaint(HWND hwnd);
  184. protected:
  185. LRESULT ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  186. } ;
  187. class CLayeredView : public CGenWindow
  188. {
  189. public:
  190. enum LayoutStyle
  191. {
  192. Center = 0,
  193. Fill,
  194. NumStyles
  195. } ;
  196. // I should make accessor methods for this
  197. // The layout style for the window
  198. LayoutStyle m_lStyle;
  199. CLayeredView() : m_lStyle(Center) {}
  200. BOOL Create(
  201. HWND hwndParent, // The parent of this window
  202. DWORD dwExStyle=WS_EX_CONTROLPARENT // The extended style
  203. );
  204. virtual void GetDesiredSize(SIZE *psize);
  205. virtual void Layout();
  206. } ;
  207. class DECLSPEC_UUID("{5D573806-CD09-11d2-9CA9-00C04FB17782}")
  208. CFrame : public CFillWindow
  209. {
  210. public:
  211. BOOL Create(
  212. HWND hWndOwner, // Window owner
  213. LPCTSTR szWindowName, // Window name
  214. DWORD dwStyle, // Window style
  215. DWORD dwEXStyle, // Extended window style
  216. int x, // Window pos: x
  217. int y, // Window pos: y
  218. int nWidth, // Window size: width
  219. int nHeight, // Window size: height
  220. HINSTANCE hInst, // The hInstance to create the window on
  221. HICON hIcon=NULL, // The icon for the window
  222. HMENU hmMain=NULL, // Window menu
  223. LPCTSTR szClassName=NULL // The class name to use
  224. );
  225. HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID riid, LPVOID *ppv)
  226. {
  227. if (__uuidof(CFrame) == riid)
  228. {
  229. *ppv = this;
  230. AddRef();
  231. return(S_OK);
  232. }
  233. return(CFillWindow::QueryInterface(riid, ppv));
  234. }
  235. virtual void OnDesiredSizeChanged();
  236. BOOL SetForeground();
  237. // Update the size immediately
  238. void Resize();
  239. void MoveEnsureVisible(int x, int y);
  240. protected:
  241. virtual LRESULT ProcessMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  242. private:
  243. // Handle messages
  244. void OnPaletteChanged(HWND hwnd, HWND hwndPaletteChange);
  245. BOOL OnQueryNewPalette(HWND hwnd);
  246. // Delayed resizing when the desired size changes
  247. static void Resize(CGenWindow *pThis, WPARAM wParam);
  248. // Select and realize the proper palette
  249. BOOL SelAndRealizePalette(BOOL bBackground);
  250. } ;
  251. #endif // _GENCONTAINERS_H_