EGButtonsBar.h
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 9k
Category:

Graph program

Development Platform:

Visual C++

  1. #pragma once
  2. class COMemDC : public CDC
  3. {
  4. public:
  5.     // constructor sets up the memory DC
  6.     COMemDC(CDC* pDC) : CDC()
  7.     {
  8.         ASSERT(pDC != NULL);
  9.         m_pDC = pDC;
  10.         m_pOldBitmap = NULL;
  11.         m_bMemDC = !pDC->IsPrinting();
  12.               
  13.         if (m_bMemDC)    // Create a Memory DC
  14.         {
  15.             pDC->GetClipBox(&m_rect);
  16.             CreateCompatibleDC(pDC);
  17.             m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
  18.             m_pOldBitmap = SelectObject(&m_bitmap);
  19.             SetWindowOrg(m_rect.left, m_rect.top);
  20.         }
  21.         else        // Make a copy of the relevent parts of the current DC for printing
  22.         {
  23.             m_bPrinting = pDC->m_bPrinting;
  24.             m_hDC       = pDC->m_hDC;
  25.             m_hAttribDC = pDC->m_hAttribDC;
  26.         }
  27.     }
  28.     
  29.     // Destructor copies the contents of the mem DC to the original DC
  30.     ~COMemDC()
  31.     {
  32.         if (m_bMemDC) 
  33.         {    
  34.             // Copy the offscreen bitmap onto the screen.
  35.             m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
  36.                           this, m_rect.left, m_rect.top, SRCCOPY);
  37.             //Swap back the original bitmap.
  38.             SelectObject(m_pOldBitmap);
  39.         } else {
  40.             // All we need to do is replace the DC with an illegal value,
  41.             // this keeps us from accidently deleting the handles associated with
  42.             // the CDC that was passed to the constructor.
  43.             m_hDC = m_hAttribDC = NULL;
  44.         }
  45.     }
  46.     // Allow usage as a pointer
  47.     COMemDC* operator->() {return this;}
  48.         
  49.     // Allow usage as a pointer
  50.     operator COMemDC*() {return this;}
  51. private:
  52.     CBitmap  m_bitmap;      // Offscreen bitmap
  53.     CBitmap* m_pOldBitmap;  // bitmap originally found in CMemDC
  54.     CDC*     m_pDC;         // Saves CDC passed in constructor
  55.     CRect    m_rect;        // Rectangle of drawing area.
  56.     BOOL     m_bMemDC;      // TRUE if CDC really is a Memory DC.
  57. };
  58. /////////////////////////////////////////////////////////////////////////////
  59. /* *****************************************************************
  60. ** CEGButtonsBar - a sort-of outlook bar-style control
  61.     ****************************************************************/
  62. // CEGButtonsBar
  63. class CEGButtonsFolder
  64. {
  65. public:
  66. CEGButtonsFolder();
  67. virtual ~CEGButtonsFolder();
  68. CString csName;
  69. HICON hIcon;
  70. DWORD dwStyle;
  71. CRect rcItem;
  72. CPtrArray m_Items;
  73. DWORD lParam;
  74. UINT nCommandID;
  75. };
  76. class CEGButtonsItem
  77. {
  78. public:
  79. CEGButtonsItem();
  80. virtual ~CEGButtonsItem();
  81. CString csName;
  82. DWORD dwStyle;
  83. CRect rcItem;
  84. CPtrArray m_SubItems;
  85. };
  86. class CEGButtonsSubItem
  87. {
  88. public:
  89. CEGButtonsSubItem();
  90. virtual ~CEGButtonsSubItem();
  91. CString csName;
  92. HICON hIcon;
  93. DWORD dwStyle;
  94. CRect rcItem;
  95. DWORD lParam;
  96. HWND hHostedWnd;
  97. int iLastStatus;
  98. };
  99. // Helper class that integrates in the MFC command handler chain 
  100. class CEGButtonsCCmdUI : public CCmdUI
  101. {
  102. public:
  103. CEGButtonsCCmdUI() { iRes = 0; pSI = NULL; };
  104. int iRes;
  105. CEGButtonsSubItem * pSI;
  106. virtual void Enable(BOOL /* bOn */ = TRUE) 
  107. iRes |= 1; 
  108. };
  109. virtual void SetCheck(int nCheck = 1) 
  110. if (nCheck) iRes |= 2;
  111. };
  112. virtual void SetRadio(BOOL bOn = TRUE)
  113. if (bOn) iRes |= 4;
  114. };
  115. virtual void SetText(LPCTSTR lpszText)
  116. pSI->csName = lpszText;
  117. };
  118. };
  119. class CEGButtonsBar : public CControlBar
  120. {
  121. DECLARE_DYNAMIC(CEGButtonsBar)
  122. BOOL m_bIsMouseInside;
  123. public:
  124. enum { USE_LAST_INSERT = -1 };
  125. enum { OCL_SELECT = 0, OCL_RADIO = 1, OCL_COMMAND = 2, OCL_CHECK = 3,  OCL_HWND = 4 };
  126. CEGButtonsBar();
  127. virtual ~CEGButtonsBar();
  128. int m_iSize;
  129. int m_iSplitterSize;
  130. int m_iDragging;
  131. int m_iDragoffset;
  132. CRect m_dragRectBegin;
  133. CRect m_dragRect;
  134. HCURSOR hDragCur;
  135. HCURSOR hHandCur;
  136. bool  bTrackCur;
  137. CEGButtonsSubItem * pLastHilink;
  138. CRect rcInnerRect;
  139. int iHiFolder, iHiLink;
  140. int iHilinkFolder, iHilinkItem;
  141. CFont ftCaption;
  142. CString m_csCaption;
  143. COLORREF m_crBackCaption;
  144. COLORREF m_crTextCaption;
  145. COLORREF m_crCmdLink;
  146. COLORREF m_crCmdOther;
  147. COLORREF m_crBackground;
  148. COLORREF m_crDisabled;
  149. CPtrArray   m_Folders;
  150. int m_iNumFoldersDisplayed;
  151. int m_iFolderHeight;
  152. int m_iItemHeight;
  153. int m_iSubItemHeight;
  154. int m_iSelectedFolder;
  155. CFont ftFolders;
  156. CFont ftItems;
  157. CFont ftHotItems;
  158. // Adds a folder to the control.
  159. int AddFolderRes(const char * m_strName, UINT iIcoID, DWORD lParam = 0, UINT nCmdID = 0);
  160. // Adds a folder to the control.
  161. int AddFolder(const char * m_strName, HICON hIcon, DWORD lParam = 0, UINT nCmdID = 0);
  162. // Remove a folder from the control.
  163. bool  RemoveFolder(int ind);
  164. int AddSubItem(const char * m_strName, int iIcoID, DWORD dwStyle, DWORD lParam = 0, int iFolder = USE_LAST_INSERT, int iFolderItem = USE_LAST_INSERT);
  165. int AddSubItem(const char * m_strName, HICON hIcon, DWORD dwStyle, DWORD lParam = 0, int iFolder = USE_LAST_INSERT, int iFolderItem = USE_LAST_INSERT);
  166. // Adds a subitem to a folder.item. Supports the following styles:
  167. // OCL_SELECT, OCL_RADIO, OCL_COMMAND, OCL_CHECK - or a child window.
  168. int AddSubItem(HWND hHosted, bool bStretch = false, int iFolder = USE_LAST_INSERT, int iFolderItem = USE_LAST_INSERT);
  169. // Adds an item to a folder. An item is a separating label / line which will contains subitems.
  170. int AddFolderItem(const char * m_strItemName, DWORD dwStyle = 0, int iFolder = USE_LAST_INSERT);
  171. // Overriddable; perform the drawing of a folder.
  172. virtual void DrawButton(CDC * pDC, CEGButtonsFolder * o, bool bSel, bool bOver);
  173. // Overriddable; perform the drawing of an item.
  174. virtual void DrawItem(CDC * pDC, CEGButtonsFolder * o, CEGButtonsItem * i);
  175. // Overriddable; perform the drawing of a subitem.
  176. virtual void DrawSubItem(CDC * pDC, CEGButtonsFolder * oFolder, CEGButtonsItem * iItem, CEGButtonsSubItem * pSubItem, bool bOver);
  177. // Here the standard colors for the control are defined. You can modify them here.
  178. virtual void SetupColors();
  179. void OnInvertTracker(const CRect& rect);
  180. // returns actual size of the control to the docking framework.
  181. CSize CalcFixedLayout (BOOL /*bStretch*/, BOOL bHorz);
  182. // Performs the drawing of the gradient graphic if compiled with WINVER >= 0x0500. 
  183. // It makes use of gdiplus.lib.
  184. void DrawGradientRect(CDC * pDC, CRect &rect, COLORREF cr1, COLORREF cr2, DWORD dwStyle = GRADIENT_FILL_RECT_V);
  185. // Allows to select a particular folder. The bAnimation flag tells if we wish a scrolling animation to be performed.
  186. int GetCurFolder( );
  187. void SetCurFolder(int f, bool bAnimation = true, BOOL bNotify = FALSE);
  188. // Executes the animation from current folder to folder F and sets it as current selected folder.
  189. void AnimateToFolder(int f);
  190. protected:
  191. DECLARE_MESSAGE_MAP()
  192. public:
  193. bool Create(CWnd * pParent, int iId);
  194. afx_msg void OnPaint();
  195. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  196. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  197. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  198. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  199. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  200. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  201. afx_msg void OnSize(UINT nType, int cx, int cy);
  202. afx_msg LRESULT OnMouseLeave( WPARAM wParam, LPARAM lParam );
  203. // Control which element is under the point. The function returns:
  204. // 0 = nothing; 1 = folder is valid; 2 = folder.item is valid, 4 = folder.item.subitem is valid
  205. int HitTest(int & iFolder, int & iItem, int & iSubItem, CPoint point);
  206. // Invalidates all the folder.items.subitems areas' internal structure (not on video)
  207. void ClearRects(void);
  208. // Perform the UI idle updating for the check/radio/select subitems
  209. virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
  210. CEGButtonsSubItem * GetSubItem(int f, int i, int s);
  211. CEGButtonsItem * GetItem(int f, int i);
  212. CEGButtonsFolder * GetFolder(int f);
  213. // Draw the big caption above the control. Makes the inner area (passed with rect) smaller on return.
  214. void DrawCaption(CDC * pDC, CRect & rect);
  215. // Draw all the folders (calling DrawButton when needed)
  216. void DrawButtons(CDC * pDC, CRect & rect);
  217. // Draw all the items (calling DrawItem when needed)
  218. void DrawItems(CDC * pDC, CEGButtonsFolder * oFolder, CRect & rect);
  219. // Draw all the subitems (calling DrawSubItem when needed)
  220. void DrawSubItems(CDC * pDC, CEGButtonsFolder * oFolder, CEGButtonsItem * iItem, CRect & rect);
  221. };