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

对话框与窗口

开发平台:

Visual C++

  1. // TaskPanelView.cpp : implementation of the CTaskPanelView class
  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 "TaskPanel.h"
  22. #include "TaskPanelDoc.h"
  23. #include "TaskPanelView.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. class CTaskPanelIconItem : public CXTPTaskPanelGroupItem
  30. {
  31. public:
  32. CTaskPanelIconItem(HICON hIcon)
  33. {
  34. m_hIcon = hIcon;
  35. }
  36. ~CTaskPanelIconItem()
  37. {
  38. DestroyIcon(m_hIcon);
  39. }
  40. CRect OnReposition(CRect rc)
  41. {
  42. m_rcItem =  rc;
  43. m_rcItem.bottom = m_rcItem.top + 32;
  44. return m_rcItem;
  45. }
  46. void OnDrawItem(CDC* pDC, CRect rc)
  47. {
  48. pDC->DrawState(CPoint(rc.CenterPoint().x - 16, rc.CenterPoint().y - 16), 0, m_hIcon, 0, (CBrush*)NULL);
  49. }
  50. HICON m_hIcon;
  51. };
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CTaskPanelView
  54. IMPLEMENT_DYNCREATE(CTaskPanelView, CXTListView)
  55. BEGIN_MESSAGE_MAP(CTaskPanelView, CXTListView)
  56. //{{AFX_MSG_MAP(CTaskPanelView)
  57. ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnItemchanged)
  58. ON_WM_KEYDOWN()
  59. //}}AFX_MSG_MAP
  60. // Standard printing commands
  61. ON_COMMAND(ID_FILE_PRINT, CXTListView::OnFilePrint)
  62. ON_COMMAND(ID_FILE_PRINT_DIRECT, CXTListView::OnFilePrint)
  63. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CXTListView::OnFilePrintPreview)
  64. END_MESSAGE_MAP()
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CTaskPanelView construction/destruction
  67. CTaskPanelView::CTaskPanelView()
  68. {
  69. m_ilIcons.Create(32, 32, ILC_COLOR32|ILC_MASK, 0, 1);
  70. CBitmap bmp;
  71. if (XTPImageManager()->IsAlphaIconsImageListSupported())
  72. {
  73. bmp.Attach((HBITMAP)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_FILEICONS_ALPHA),
  74. IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_CREATEDIBSECTION));
  75. m_ilIcons.Add(&bmp, (CBitmap*)NULL);
  76. } else
  77. {
  78. bmp.LoadBitmap(IDB_FILEICONS_NORMAL);
  79. m_ilIcons.Add(&bmp, RGB(0, 0xFF, 0));
  80. }
  81. }
  82. CTaskPanelView::~CTaskPanelView()
  83. {
  84. }
  85. BOOL CTaskPanelView::PreCreateWindow(CREATESTRUCT& cs)
  86. {
  87. // TODO: Modify the Window class or styles here by modifying
  88. //  the CREATESTRUCT cs
  89. cs.style |= LVS_ICON|LVS_AUTOARRANGE|WS_TABSTOP;
  90. return CXTListView::PreCreateWindow(cs);
  91. }
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CTaskPanelView drawing
  94. void CTaskPanelView::OnDraw(CDC* /*pDC*/)
  95. {
  96. CTaskPanelDoc* pDoc = GetDocument();
  97. ASSERT_VALID(pDoc);
  98. // TODO: add draw code for native data here
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CTaskPanelView printing
  102. BOOL CTaskPanelView::OnPreparePrinting(CPrintInfo* pInfo)
  103. {
  104. // default preparation
  105. return DoPreparePrinting(pInfo);
  106. }
  107. void CTaskPanelView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  108. {
  109. // TODO: add extra initialization before printing
  110. }
  111. void CTaskPanelView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  112. {
  113. // TODO: add cleanup after printing
  114. }
  115. /////////////////////////////////////////////////////////////////////////////
  116. // CTaskPanelView diagnostics
  117. #ifdef _DEBUG
  118. void CTaskPanelView::AssertValid() const
  119. {
  120. CXTListView::AssertValid();
  121. }
  122. void CTaskPanelView::Dump(CDumpContext& dc) const
  123. {
  124. CXTListView::Dump(dc);
  125. }
  126. CTaskPanelDoc* CTaskPanelView::GetDocument() // non-debug version is inline
  127. {
  128. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTaskPanelDoc)));
  129. return (CTaskPanelDoc*)m_pDocument;
  130. }
  131. #endif //_DEBUG
  132. CXTPTaskPanel* CTaskPanelView::GetTaskPanel()
  133. {
  134. CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
  135. ASSERT(pFrame);
  136. CXTPTaskPanel* pPanel = &pFrame->m_wndTaskPanel;
  137. ASSERT(pPanel->GetSafeHwnd());
  138. return pPanel;
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CTaskPanelView message handlers
  142. void CTaskPanelView::OnInitialUpdate()
  143. {
  144. CXTListView::OnInitialUpdate();
  145. CListCtrl& wndList = GetListCtrl();
  146. wndList.SetImageList(&m_ilIcons, LVSIL_NORMAL);
  147. wndList.InsertItem(LVIF_TEXT|LVIF_PARAM|LVIF_IMAGE, 0, _T("Tools"), 0, 0, 0, TRUE);
  148. wndList.InsertItem(LVIF_TEXT|LVIF_PARAM|LVIF_IMAGE, 1, _T("Source"), 0, 0, 0, TRUE);
  149. wndList.InsertItem(LVIF_TEXT|LVIF_PARAM|LVIF_IMAGE, 2, _T("Program Files"), 0, 0, 0, TRUE);
  150. wndList.InsertItem(LVIF_TEXT|LVIF_PARAM|LVIF_IMAGE, 3, _T("Windows"), 0, 0, 0, TRUE);
  151. wndList.InsertItem(LVIF_TEXT|LVIF_PARAM|LVIF_IMAGE, 4, _T("Sound"), 0, 0, 1, FALSE);
  152. wndList.InsertItem(LVIF_TEXT|LVIF_PARAM|LVIF_IMAGE, 5, _T("Bitmap"), 0, 0, 2, FALSE);
  153. }
  154. void CTaskPanelView::OnItemchanged(NMHDR* /*pNMHDR*/, LRESULT* pResult)
  155. {
  156. //NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  157. //pNMListView;
  158. CListCtrl& wndList = GetListCtrl();
  159. int nCount = wndList.GetSelectedCount();
  160. CXTPTaskPanel* pPanel = GetTaskPanel();
  161. CXTPTaskPanelGroup* pGroupFiles = pPanel->FindGroup(ID_TASKGROUP_FILES);
  162. if (!pGroupFiles)
  163. return;
  164. ASSERT(pGroupFiles);
  165. pGroupFiles->GetItems()->Clear();
  166. if (nCount == 0)
  167. {
  168. pGroupFiles->AddLinkItem(ID_TASKITEM_NEWFOLDER, 3);
  169. pGroupFiles->AddLinkItem(ID_TASKITEM_PUBLISH, 4);
  170. pGroupFiles->AddLinkItem(ID_TASKITEM_SHARE, 5);
  171. }
  172. else if (nCount == 1)
  173. {
  174. pGroupFiles->AddLinkItem(ID_TASKITEM_RENAME, 10)->SetCaption(_T("Rename this file"));
  175. pGroupFiles->AddLinkItem(ID_TASKITEM_MOVE, 11)->SetCaption(_T("Move this file"));
  176. pGroupFiles->AddLinkItem(ID_TASKITEM_COPY, 12)->SetCaption(_T("Copy this file"));
  177. pGroupFiles->AddLinkItem(ID_TASKITEM_PUBLISH, 4)->SetCaption(_T("Publish this file to the Web"));
  178. pGroupFiles->AddLinkItem(ID_TASKITEM_EMAIL, 13)->SetCaption(_T("E-mail this file"));
  179. pGroupFiles->AddLinkItem(ID_TASKITEM_PRINT, 14)->SetCaption(_T("Print this file"));
  180. pGroupFiles->AddLinkItem(ID_TASKITEM_DELETE, 15)->SetCaption(_T("Delete this file"));
  181. }
  182. else
  183. {
  184. pGroupFiles->AddLinkItem(ID_TASKITEM_MOVE, 11)->SetCaption(_T("Move the selected items"));
  185. pGroupFiles->AddLinkItem(ID_TASKITEM_COPY, 12)->SetCaption(_T("Copy the selected items"));
  186. pGroupFiles->AddLinkItem(ID_TASKITEM_PUBLISH, 4)->SetCaption(_T("Publish tthe selected items to the Web"));
  187. pGroupFiles->AddLinkItem(ID_TASKITEM_EMAIL, 13)->SetCaption(_T("E-mail the selected items"));
  188. pGroupFiles->AddLinkItem(ID_TASKITEM_PRINT, 14)->SetCaption(_T("Print the selected items"));
  189. pGroupFiles->AddLinkItem(ID_TASKITEM_DELETE, 15)->SetCaption(_T("Delete the selected items"));
  190. }
  191. CXTPTaskPanelGroup* pGroupDetails = pPanel->FindGroup(ID_TASKGROUP_DETAILS);
  192. ASSERT(pGroupDetails);
  193. pGroupDetails->GetItems()->Clear();
  194. if (nCount == 0)
  195. {
  196. CXTPTaskPanelGroupItem* pItemDisk = pGroupDetails->AddTextItem(_T("Local Disk (C:)"));
  197. pItemDisk->SetBold(TRUE);
  198. pItemDisk->GetMargins().SetRectEmpty();
  199. pGroupDetails->AddTextItem(_T("Local Disk"));
  200. pGroupDetails->AddTextItem(_T("File Sytem: FAT32"));
  201. pGroupDetails->AddTextItem(_T("Free Space: 23,3 GB"));
  202. pGroupDetails->AddTextItem(_T("Total Size: 76,2 GB"));
  203. }
  204. else if (nCount == 1)
  205. {
  206. int nIndex = wndList.GetNextItem(-1, LVNI_SELECTED );
  207. if (nIndex == 5)
  208. {
  209. pGroupDetails->GetItems()->Add(new CTaskPanelIconItem(m_ilIcons.ExtractIcon(2)), 0);
  210. }
  211. CString strText = wndList.GetItemText(nIndex, 0);
  212. CXTPTaskPanelGroupItem* pItemSelected = pGroupDetails->AddTextItem(strText);
  213. pItemSelected->SetBold(TRUE);
  214. pItemSelected->GetMargins().SetRectEmpty();
  215. pGroupDetails->AddTextItem(wndList.GetItemData(nIndex)? _T("File Folder"): _T("File"));
  216. pGroupDetails->AddTextItem(_T("Date Modified: 2 october, 2003"));
  217. pGroupDetails->AddTextItem(_T("Size 3,65 KB"));
  218. }
  219. else
  220. {
  221. CString strSelected;
  222. strSelected.Format(_T("%i items selected."), nCount);
  223. pGroupDetails->AddTextItem(strSelected);
  224. }
  225. *pResult = 0;
  226. }
  227. void CTaskPanelView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  228. {
  229. if (nChar == VK_TAB)
  230. {
  231. HWND hWnd = ::GetNextDlgTabItem(::GetParent(m_hWnd), m_hWnd, FALSE);
  232. if (hWnd)
  233. ::SetFocus(hWnd);
  234. return;
  235. }
  236. CXTListView::OnKeyDown(nChar, nRepCnt, nFlags);
  237. }