ItemTreeView.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:7k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // ItemTreeView.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "GUI_Outlook.h"
  22. #include "ItemTreeView.h"
  23. #include "MainFrm.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. typedef enum
  30. {
  31. IDX_OUTLOOK_TODAY,
  32. IDX_CALENDAR,
  33. IDX_CONTACTS,
  34. IDX_DELETED_ITEMS,
  35. IDX_DRAFTS,
  36. IDX_INBOX,
  37. IDX_JOURNAL,
  38. IDX_NOTES,
  39. IDX_OUTBOX,
  40. IDX_SENT_ITEMS,
  41. IDX_TASKS,
  42. IDX_COUNT
  43. } TREE_INDEX;
  44. typedef struct
  45. {
  46. UINT    m_nIndex;
  47. UINT    m_nTextID;
  48. UINT    m_nIconID;
  49. }
  50. TREE_ENTRY;
  51. static TREE_ENTRY TreeEntries[] =
  52. {
  53. { IDX_OUTLOOK_TODAY,    IDS_OUTLOOK_TODAY,  IDI_OUTLOOK_TODAY   },
  54. { IDX_CALENDAR,         IDS_CALENDAR,       IDI_CALENDAR        },
  55. { IDX_CONTACTS,         IDS_CONTACTS,       IDI_CONTACTS        },
  56. { IDX_DELETED_ITEMS,    IDS_DELETED_ITEMS,  IDI_DELETED_ITEMS   },
  57. { IDX_DRAFTS,           IDS_DRAFTS,         IDI_DRAFTS          },
  58. { IDX_INBOX,            IDS_INBOX,          IDI_INBOX           },
  59. { IDX_JOURNAL,          IDS_JOURNAL,        IDI_JOURNAL         },
  60. { IDX_NOTES,            IDS_NOTES,          IDI_NOTES           },
  61. { IDX_OUTBOX,           IDS_OUTBOX,         IDI_OUTBOX          },
  62. { IDX_SENT_ITEMS,       IDS_SENT_ITEMS,     IDI_SENT_ITEMS      },
  63. { IDX_TASKS,            IDS_TASKS,          IDI_TASKS           }
  64. };
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CItemTreeView
  67. IMPLEMENT_DYNCREATE(CItemTreeView, CView)
  68. CItemTreeView::CItemTreeView()
  69. {
  70. }
  71. CItemTreeView::~CItemTreeView()
  72. {
  73. m_ilTreeIcons.DeleteImageList();
  74. }
  75. BEGIN_MESSAGE_MAP(CItemTreeView, CView)
  76. //{{AFX_MSG_MAP(CItemTreeView)
  77. ON_WM_CREATE()
  78. ON_WM_WINDOWPOSCHANGED()
  79. ON_BN_CLICKED(IDC_CAPT_BUTTON, OnCaptButton)
  80. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_CTRL, OnSelchanged)
  81. ON_WM_SYSCOLORCHANGE()
  82. //}}AFX_MSG_MAP
  83. END_MESSAGE_MAP()
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CItemTreeView drawing
  86. void CItemTreeView::OnDraw(CDC* /*pDC*/)
  87. {
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CItemTreeView diagnostics
  91. #ifdef _DEBUG
  92. void CItemTreeView::AssertValid() const
  93. {
  94. CView::AssertValid();
  95. }
  96. void CItemTreeView::Dump(CDumpContext& dc) const
  97. {
  98. CView::Dump(dc);
  99. }
  100. #endif //_DEBUG
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CItemTreeView message handlers
  103. int CItemTreeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  104. {
  105. if (CView::OnCreate(lpCreateStruct) == -1)
  106. return -1;
  107. // Create the caption.
  108. if (!m_wndCaption.Create( this, _T("Folder List"), CPWS_EX_RAISED_EDGE | CPWS_EX_CLOSEBUTTON,
  109. WS_VISIBLE | SS_CENTER | SS_CENTERIMAGE, CRect(0,0,0,0), IDC_CAPT_BUTTON ))
  110. {
  111. TRACE0( "Unable to create caption.n" );
  112. return -1;
  113. }
  114. // create the tree control.
  115. if (!m_wndTreeCtrl.Create (WS_VISIBLE|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS,
  116. CRect(0,0,0,0), this, IDC_TREE_CTRL))
  117. {
  118. TRACE0( "Unable to create tree control.n" );
  119. return -1;
  120. }
  121. // create the image lists used by the caption and tree controls.
  122. if (!InitializeImageLists())
  123. return -1;
  124. // fill the tree control.
  125. if (!InitilalizeTreeControl())
  126. return -1;
  127. return 0;
  128. }
  129. void CItemTreeView::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
  130. {
  131. CView::OnWindowPosChanged(lpwndpos);
  132. // Move the caption and tree control to their correct locations.
  133. if( ::IsWindow( m_wndCaption.m_hWnd ) )
  134. {
  135. ::SetWindowPos( m_wndCaption.m_hWnd, NULL, 0, 0, lpwndpos->cx - 2, 19,
  136. SWP_NOZORDER | SWP_NOACTIVATE );
  137. }
  138. if( ::IsWindow( m_wndTreeCtrl.m_hWnd ) )
  139. {
  140. ::SetWindowPos( m_wndTreeCtrl.m_hWnd, NULL, 0, 19, lpwndpos->cx - 2, lpwndpos->cy-21,
  141. SWP_NOZORDER | SWP_NOACTIVATE );
  142. }
  143. }
  144. void CItemTreeView::OnCaptButton()
  145. {
  146. CMainFrame* pFrameWnd = (CMainFrame*)GetParentFrame();
  147. ASSERT_KINDOF (CMainFrame, pFrameWnd);
  148. pFrameWnd->CloseTreeViewPane();
  149. }
  150. void CItemTreeView::OnSelchanged(NMHDR* /*pNMHDR*/, LRESULT* pResult)
  151. {
  152. // Get the selected tree item and its icon.
  153. int nImage;
  154. HTREEITEM htItem = m_wndTreeCtrl.GetSelectedItem();
  155. if (htItem != NULL)
  156. {
  157. m_wndTreeCtrl.GetItemImage( htItem, nImage, nImage );
  158. CMainFrame* pFrameWnd = (CMainFrame*)GetParentFrame();
  159. ASSERT_KINDOF (CMainFrame, pFrameWnd);
  160. pFrameWnd->UpdateCaption(m_wndTreeCtrl.GetItemText( htItem ),
  161. m_ilTreeIcons.ExtractIcon(nImage));
  162. }
  163. *pResult = 0;
  164. }
  165. BOOL CItemTreeView::PreCreateWindow(CREATESTRUCT& cs)
  166. {
  167. if (!CView::PreCreateWindow(cs))
  168. return FALSE;
  169. // TODO: Add your specialized code here and/or call the base class
  170. cs.style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
  171. return TRUE;
  172. }
  173. BOOL CItemTreeView::InitilalizeTreeControl()
  174. {
  175. // Set the tree controls image list.
  176. m_wndTreeCtrl.SetImageList (&m_ilTreeIcons, TVSIL_NORMAL);
  177. // TODO: Add items to the tree control.
  178. HTREEITEM hItem = NULL;
  179. CString   str;
  180. int nEntry;
  181. for (nEntry = 0; nEntry < _countof(TreeEntries); nEntry++)
  182. {
  183. TREE_ENTRY* pEntry = &TreeEntries[nEntry];
  184. str.LoadString (pEntry->m_nTextID);
  185. if (nEntry == 0)
  186. hItem = m_wndTreeCtrl.InsertItem (str, pEntry->m_nIndex, pEntry->m_nIndex);
  187. else
  188. m_wndTreeCtrl.InsertItem (str, pEntry->m_nIndex, pEntry->m_nIndex, hItem);
  189. }
  190. m_wndTreeCtrl.SetItemBold (hItem, TRUE);
  191. m_wndTreeCtrl.Expand (hItem, TVE_EXPAND);
  192. m_wndTreeCtrl.SetItemState(hItem, TVIS_SELECTED, TVIS_SELECTED);
  193. m_wndTreeCtrl.EnableMultiSelect(FALSE);
  194. return TRUE;
  195. }
  196. BOOL CItemTreeView::InitializeImageLists()
  197. {
  198. // Create the image list used by the tree control.
  199. if (!m_ilTreeIcons.Create(16, 16, ILC_MASK|ILC_COLOR32, 2, 1))
  200. return FALSE;
  201. // Load icons displayed in the tree control and add them to the image list.
  202. int nEntry;
  203. for (nEntry = 0; nEntry < _countof(TreeEntries); nEntry++)
  204. {
  205. TREE_ENTRY* pEntry = &TreeEntries[nEntry];
  206. HICON hIcon = AfxGetApp()->LoadIcon(pEntry->m_nIconID);
  207. ASSERT(hIcon);
  208. m_ilTreeIcons.Add (hIcon);
  209. }
  210. return TRUE;
  211. }
  212. void CItemTreeView::OnSysColorChange()
  213. {
  214. CView::OnSysColorChange();
  215. m_wndCaption.SetCaptionColors(
  216. ::GetSysColor(COLOR_3DFACE),
  217. ::GetSysColor(COLOR_3DFACE),
  218. ::GetSysColor(COLOR_BTNTEXT) );
  219. }