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

Graph program

Development Platform:

Visual C++

  1. // COptionTree
  2. //
  3. // License
  4. // -------
  5. // This code is provided "as is" with no expressed or implied warranty.
  6. // 
  7. // You may use this code in a commercial product with or without acknowledgement.
  8. // However you may not sell this code or any modification of this code, this includes 
  9. // commercial libraries and anything else for profit.
  10. //
  11. // I would appreciate a notification of any bugs or bug fixes to help the control grow.
  12. //
  13. // History:
  14. // --------
  15. // See License.txt for full history information.
  16. //
  17. //
  18. // Copyright (c) 1999-2002 
  19. // ComputerSmarts.net 
  20. // mattrmiller@computersmarts.net
  21. #ifndef OT_OPTIONTREE
  22. #define OT_OPTIONTREE
  23. #if _MSC_VER > 1000
  24. #pragma once
  25. #endif // _MSC_VER > 1000
  26. // OptionTree.h : header file
  27. //
  28. // Added Headers
  29. //#include "CommonRes.h"
  30. #include "OptionTreeInfo.h"
  31. #include "OptionTreeList.h"
  32. #include "OptionTreeItem.h"
  33. #include "OptionTreeDef.h"
  34. #include "OptionTreeItemEdit.h"
  35. #include "OptionTreeItemStatic.h"
  36. #include "OptionTreeItemComboBox.h"
  37. #include "OptionTreeItemColorComboBox.h"
  38. #include "OptionTreeItemLineTypeComboBox.h"
  39. #include "OptionTreeItemLineThikComboBox.h"
  40. #include "OptionTreeItemCheckBox.h"
  41. #include "OptionTreeItemFont.h"
  42. #include "OptionTreeItemFile.h"
  43. #include "OptionTreeItemRadio.h"
  44. #include "OptionTreeItemSpinner.h"
  45. #include "OptionTreeItemColor.h"
  46. #include "OptionTreeItemHyperLink.h"
  47. // Definitions
  48. typedef BOOL (CALLBACK* ENUM_OPTIONITEMPROC)(COptionTree* otProp, COptionTreeItem* otiItem, LPARAM lParam);
  49. // CPropTree WM_NOTIFY notification structure
  50. typedef struct _NMOPTIONTREE
  51. {
  52.     NMHDR hDR;
  53. COptionTreeItem* otiItem;
  54. } NMOPTIONTREE, *PNMOPTIONTREE, FAR *LPNMOPTIONTREE;
  55. // Global Functions
  56. // -- Draw dark horizontal line
  57. static void _DrawDarkHLine(HDC hdc, long lX, long lY, long lWidth)
  58. {
  59. CRect rcPaint(lX, lY, lX + lWidth, lY + 1);
  60. int nOldBack = SetBkColor(hdc, GetSysColor(COLOR_BTNSHADOW));
  61. // GDI calls driver directly
  62. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, rcPaint, 0, 0, 0); 
  63. // Restore
  64. SetBkColor(hdc, nOldBack);
  65. }
  66. // -- Draw dark vertical line
  67. static void _DrawDarkVLine(HDC hdc, long lX, long lY, long lHeight)
  68. {
  69. CRect rcPaint(lX, lY, lX + 1, lY + lHeight);
  70. int nOldBack = SetBkColor(hdc, GetSysColor(COLOR_BTNSHADOW));
  71. // GDI calls driver directly
  72. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, rcPaint, 0, 0, 0); 
  73. // Restore
  74. SetBkColor(hdc, nOldBack);
  75. }
  76. // -- Draw lite horizontal line
  77. static void _DrawLiteHLine(HDC hdc, long lX, long lY, long lWidth)
  78. {
  79. HBRUSH hbr = (HBRUSH )CDC::GetHalftoneBrush()->GetSafeHandle();
  80. SetBrushOrgEx(hdc, 0, 0, NULL);
  81. UnrealizeObject(hbr);
  82. HBRUSH holdbr = (HBRUSH )SelectObject(hdc, hbr);
  83. COLORREF rcOldColor = SetTextColor(hdc, GetSysColor(COLOR_BTNSHADOW));
  84. int nOldBack = SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
  85. PatBlt(hdc, lX, lY, lWidth, 1, PATCOPY);
  86. SelectObject(hdc, holdbr);
  87. SetTextColor(hdc, rcOldColor);
  88. SetBkColor(hdc, nOldBack);
  89. }
  90. // -- Draw lite vertical line
  91. static void _DrawLiteVLine(HDC hdc, long lX, long lY, long lHeight)
  92. {
  93. HBRUSH hbr = (HBRUSH )CDC::GetHalftoneBrush()->GetSafeHandle();
  94. SetBrushOrgEx(hdc, 0, 0, NULL);
  95. UnrealizeObject(hbr);
  96. HBRUSH holdbr = (HBRUSH )SelectObject(hdc, hbr);
  97. COLORREF rcOldColor = SetTextColor(hdc, GetSysColor(COLOR_BTNSHADOW));
  98. int nOldBack = SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
  99. PatBlt(hdc, lX, lY, 1, lHeight, PATCOPY);
  100. SelectObject(hdc, holdbr);
  101. SetTextColor(hdc, rcOldColor);
  102. SetBkColor(hdc, nOldBack);
  103. }
  104. // -- Draw selection rectangle
  105. static void _DrawSelectRect(HDC hdc, long lX, long lY, long lWidth)
  106. {
  107. HBRUSH hbr = (HBRUSH )CDC::GetHalftoneBrush()->GetSafeHandle();
  108. SetBrushOrgEx(hdc, 0, 0, NULL);
  109. UnrealizeObject(hbr);
  110. HBRUSH holdbr = (HBRUSH )SelectObject(hdc, hbr);
  111. COLORREF rcOldColor = SetTextColor(hdc, GetSysColor(COLOR_3DHILIGHT));
  112. int nOldBack = SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
  113. PatBlt(hdc, lX, lY, lWidth, 1, PATCOPY);
  114. SelectObject(hdc, holdbr);
  115. SetTextColor(hdc, rcOldColor);
  116. SetBkColor(hdc, nOldBack);
  117. }
  118. // -- Draw splitter bar selected
  119. static void _DrawXorBar(HDC hdc, int x1, int y1, int nWidth, int nHeight)
  120. {
  121. // Declare variables
  122. static WORD _dotPatternBmp[8] = { 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055};
  123. HBITMAP hbm;
  124. HBRUSH  hbr, hbrushOld;
  125. // Create a monochrome checkered pattern
  126. hbm = CreateBitmap(8, 8, 1, 1, _dotPatternBmp);
  127. hbr = CreatePatternBrush(hbm);
  128.     
  129. SetBrushOrgEx(hdc, x1, y1, 0);
  130. hbrushOld = (HBRUSH)SelectObject(hdc, hbr);
  131.     
  132. // Draw the checkered rectangle to the screen
  133. PatBlt(hdc, x1, y1, nWidth, nHeight, PATINVERT);
  134.     
  135. SelectObject(hdc, hbrushOld);
  136.     
  137. DeleteObject(hbr);
  138. DeleteObject(hbm);
  139. }
  140. // -- Make short string
  141. static LPCTSTR _MakeShortString(CDC* pDC, LPCTSTR lpszLong, int nWidth, int nOffset)
  142. {
  143. // Declare variables
  144. const _TCHAR szThreeDots[]=_T("...");
  145. int nStringLen = lstrlen(lpszLong);
  146. static _TCHAR szShort[MAX_PATH];
  147. int nAddLen;
  148. // Validate length
  149. if(nStringLen == 0 || pDC->GetTextExtent(lpszLong,nStringLen).cx + nOffset <= nWidth)
  150. {
  151. return lpszLong;
  152. }
  153. // Shorten
  154. lstrcpy(szShort, lpszLong);
  155. nAddLen = pDC->GetTextExtent(szThreeDots,sizeof(szThreeDots)).cx;
  156. for(int i = nStringLen - 1; i > 0; i--)
  157. {
  158. szShort[i] = 0;
  159. if(pDC->GetTextExtent(szShort, i).cx + nOffset + nAddLen <= nWidth)
  160. {
  161. break;
  162. }
  163. }
  164. lstrcat(szShort, szThreeDots);
  165. return szShort;
  166. }
  167. // Classes
  168. class COptionTree;
  169. /////////////////////////////////////////////////////////////////////////////
  170. // COptionTree window
  171. class COptionTree : public CWnd
  172. {
  173. // Construction
  174. public:
  175. COptionTree();
  176. virtual ~COptionTree();
  177. BOOL Create(DWORD dwStyle, RECT rcRect, CWnd* pParentWnd, DWORD dwTreeOptions, UINT nID);
  178. // Attributes
  179. public:
  180. // Operations
  181. public:
  182. // Overrides
  183. // ClassWizard generated virtual function overrides
  184. //{{AFX_VIRTUAL(COptionTree)
  185. //}}AFX_VIRTUAL
  186. // Implementation
  187. public:
  188. void Expand(COptionTreeItem *pItem, BOOL bExpand);
  189. void ExpandAllItems();
  190. void ShadeRootItems(BOOL bShade);
  191. BOOL GetShadeRootItems();
  192. void ShadeExpandColumn(BOOL bShade);
  193. BOOL GetShadeExpandColumn();
  194. void ClearAllLabelRect();
  195. CRect GetLargestVisibleLabel();
  196. void SetNotify(BOOL bNotify, CWnd *pWnd);
  197. BOOL GetNotify();
  198. void SetDefInfoTextNoSel(BOOL bNoSelect);
  199. BOOL GetDefInfoTextNoSel();
  200. DWORD GetTreeOptions();
  201. BOOL IsSingleSelection();
  202. COptionTreeItem * FocusNext();
  203. COptionTreeItem * FocusPrev();
  204. COptionTreeItem * FocusLast();
  205. BOOL IsDisableInput();
  206. COptionTreeItem * InsertItem(COptionTreeItem* otiItem, COptionTreeItem* otiParent = NULL);
  207. void ClearVisibleList();
  208. void SetColumn(long lColumn);
  209. long GetColumn();
  210. void DeleteItem(COptionTreeItem* otiItem);
  211. void DeleteAllItems();
  212. void SetOriginOffset(long lOffset);
  213. BOOL IsItemVisible(COptionTreeItem* otiItem);
  214. void UpdatedItems();
  215. void RefreshItems(COptionTreeItem* otiItem = NULL);
  216. void UpdateMoveAllItems();
  217. void EnsureVisible(COptionTreeItem* otiItem);
  218. void SetFocusedItem(COptionTreeItem* otiItem);
  219. COptionTreeItem * FocusFirst();
  220. void SelectItems(COptionTreeItem* otiItem, BOOL bSelect);
  221. void DisableInput(BOOL bDisable = TRUE);
  222. COptionTreeItem * FindItem(const POINT& pt);
  223. COptionTreeItem * FindItem(UINT uCtrlID);
  224. long HitTest(const POINT& pt);
  225. void AddToVisibleList(COptionTreeItem* otiItem);
  226. COptionTreeItem * GetVisibleList();
  227. COptionTreeItem * GetFocusedItem();
  228. COptionTreeItem * GetRootItem();
  229. BOOL GetShowInfoWindow();
  230. void ShowInfoWindow(BOOL bShow);
  231. static CFont* GetNormalFont();
  232. static CFont* GetBoldFont();
  233. const POINT& GetOrigin();
  234. CWnd* GetCtrlParent();
  235. LRESULT SendNotify(UINT uNotifyCode, COptionTreeItem* otiItem = NULL);
  236. // Generated message map functions
  237. protected:
  238. BOOL EnumItems(COptionTreeItem* otiItem, ENUM_OPTIONITEMPROC enumProc, LPARAM lParam = 0L);
  239. static BOOL CALLBACK EnumFindItem(COptionTree* otProp, COptionTreeItem* otiItem, LPARAM lParam);
  240. static BOOL CALLBACK EnumMoveAll(COptionTree* otProp, COptionTreeItem* otiItem, LPARAM lParam);
  241. static BOOL CALLBACK EnumNotifyExpand(COptionTree* otProp, COptionTreeItem* otiItem, LPARAM lParam);
  242. static BOOL CALLBACK EnumRefreshAll(COptionTree* otProp, COptionTreeItem* otiItem, LPARAM lParam);
  243. static BOOL CALLBACK EnumExpandAll(COptionTree* otProp, COptionTreeItem* otiItem, LPARAM lParam);
  244. static BOOL CALLBACK EnumSelectAll(COptionTree* otProp, COptionTreeItem* otiItem, LPARAM lParam);
  245. static BOOL CALLBACK EnumGetLargestVisibleLabelRect(COptionTree* otProp, COptionTreeItem* otiItem, LPARAM lParam);
  246. static BOOL CALLBACK EnumClearAllLabelRect(COptionTree* otProp, COptionTreeItem* otiItem, LPARAM lParam);
  247. void DeleteGlobalResources();
  248. void InitGlobalResources();
  249. void ResizeAllWindows(int cx, int cy);
  250. void Delete(COptionTreeItem* otiItem);
  251. //{{AFX_MSG(COptionTree)
  252. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  253. afx_msg void OnSize(UINT nType, int cx, int cy);
  254. afx_msg void OnEnable(BOOL bEnable);
  255. afx_msg void OnSysColorChange();
  256. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  257. afx_msg void OnPaint();
  258. afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
  259. afx_msg void OnSetFocus(CWnd* pOldWnd);
  260. afx_msg void OnKillFocus(CWnd* pNewWnd);
  261. //}}AFX_MSG
  262. DECLARE_MESSAGE_MAP()
  263. // Variables
  264. protected:
  265. static CFont* m_fNormalFont;
  266. static CFont* m_fBoldFont;
  267. static UINT m_uInstanceCount;
  268. static COptionTreeItem *m_otiFound;
  269. DWORD m_dwTreeOptions;
  270. COptionTreeInfo m_otInfo;
  271. COptionTreeItem m_otiRoot;
  272. COptionTreeItem* m_otiVisibleList;
  273. COptionTreeItem* m_otiFocus;
  274. CPoint m_ptOrigin;
  275. COptionTreeList m_otlList;
  276. BOOL m_bDisableInput;
  277. UINT m_uLastUID;
  278. static CRect m_rcLargestLabel;
  279. CWnd *m_pNotify;
  280. };
  281. /////////////////////////////////////////////////////////////////////////////
  282. //{{AFX_INSERT_LOCATION}}
  283. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  284. #endif // !OT_OPTIONTREE