PagePeopleList.cpp
上传用户:geanq888
上传日期:2007-01-03
资源大小:316k
文件大小:9k
源码类别:

Ftp客户端

开发平台:

Visual C++

  1. // PagePeopleList.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "netmanager.h"
  5. #include "PagePeople.h"
  6. #include "PagePeopleList.h"
  7. #include "GlobalsExtern.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CPagePeopleList
  15. CPagePeopleList::CPagePeopleList()
  16. {
  17. }
  18. CPagePeopleList::~CPagePeopleList()
  19. {
  20. }
  21. BEGIN_MESSAGE_MAP(CPagePeopleList, CTreeCtrl)
  22. //{{AFX_MSG_MAP(CPagePeopleList)
  23. ON_NOTIFY_REFLECT(TVN_BEGINLABELEDIT, OnBeginlabeledit)
  24. ON_NOTIFY_REFLECT(TVN_ENDLABELEDIT, OnEndlabeledit)
  25. ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
  26. ON_NOTIFY_REFLECT(TVN_KEYDOWN, OnKeydown)
  27. ON_COMMAND(IDM_PEOPLE_FINGER, OnPeopleFinger)
  28. ON_COMMAND(IDM_PEOPLE_REMOVE, OnPeopleRemove)
  29. ON_WM_CONTEXTMENU()
  30. ON_COMMAND(IDM_PEOPLE_RENAME, OnPeopleRename)
  31. ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
  32. ON_COMMAND(IDM_PEOPLE_CHECKALL, OnPeopleCheckall)
  33. ON_COMMAND(IDM_PEOPLE_ACTIVE, OnPeopleActive)
  34. ON_NOTIFY_REFLECT(TVN_BEGINDRAG, OnBegindrag)
  35. ON_WM_MOUSEMOVE()
  36. ON_WM_LBUTTONUP()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CPagePeopleList message handlers
  41. void CPagePeopleList::OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult) 
  42. {
  43. TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
  44.   GetEditControl()->LimitText(40);
  45. *pResult = 0;
  46. }
  47. /////////////////////////////////////////////////////////////////////////////
  48. void CPagePeopleList::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) 
  49. {
  50. TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
  51.   HTREEITEM hItemCurrent = GetSelectedItem();
  52.   CEdit* pCurrent = GetEditControl();
  53.   CString sCurrent;
  54.   pCurrent->GetWindowText(sCurrent);
  55.   SetItemText(hItemCurrent, sCurrent);
  56. *pResult = 0;
  57. }
  58. /////////////////////////////////////////////////////////////////////////////
  59. BOOL CPagePeopleList::PreTranslateMessage(MSG* pMsg) 
  60. {
  61.   if(pMsg->message == WM_KEYDOWN)
  62.   {
  63.     // When an item is being edited make sure the edit control
  64.     // receives certain important key strokes
  65.     if(GetEditControl() && (pMsg->wParam == VK_RETURN 
  66.                             || pMsg->wParam == VK_DELETE 
  67.                             || pMsg->wParam == VK_ESCAPE
  68.                             || GetKeyState(VK_CONTROL) 
  69.                            )
  70.       )
  71.     {
  72.       ::TranslateMessage(pMsg);
  73.       ::DispatchMessage(pMsg);
  74.       return TRUE;                            // DO NOT process further
  75.     }
  76.   }
  77. return CTreeCtrl::PreTranslateMessage(pMsg);
  78. }
  79. /////////////////////////////////////////////////////////////////////////////
  80. void CPagePeopleList::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 
  81. {
  82. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  83.   HTREEITEM hCurrItem = GetSelectedItem();
  84.   if(GetItemState(hCurrItem, TVIF_STATE) & TVIS_BOLD)
  85.     ((CPagePeople*)GetParent())->m_Active.SetCheck(1);
  86.   else
  87.     ((CPagePeople*)GetParent())->m_Active.SetCheck(0);
  88.   if((GetItemState(hCurrItem, TVIS_STATEIMAGEMASK) & TVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK(ICON_MANUAL))   //je manual?
  89.     ((CPagePeople*)GetParent())->m_IsManual.SetCheck(1);
  90.   else
  91.     ((CPagePeople*)GetParent())->m_IsManual.SetCheck(0);
  92.   if((GetItemState(hCurrItem, TVIS_STATEIMAGEMASK) & TVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK(ICON_MAIL))  //kontroluje mail?
  93.     ((CPagePeople*)GetParent())->m_ActiveMail.SetCheck(1);
  94.   else
  95.     ((CPagePeople*)GetParent())->m_ActiveMail.SetCheck(0);
  96.   if(!GetParentItem(hCurrItem))
  97.   {
  98.     // server
  99.     ((CPagePeople*)GetParent())->m_IsManual.EnableWindow(TRUE);
  100.     ((CPagePeople*)GetParent())->m_ActiveMail.EnableWindow(FALSE);
  101.   }
  102.   else
  103.   {
  104.     // user
  105.     ((CPagePeople*)GetParent())->m_IsManual.EnableWindow(FALSE);
  106.     if((GetItemState(GetParentItem(hCurrItem), TVIS_STATEIMAGEMASK) & TVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK(ICON_MANUAL))   //je manual?
  107.       ((CPagePeople*)GetParent())->m_ActiveMail.EnableWindow(FALSE);
  108.     else
  109.       ((CPagePeople*)GetParent())->m_ActiveMail.EnableWindow(TRUE);
  110.   }
  111. *pResult = 0;
  112. }
  113. /////////////////////////////////////////////////////////////////////////////
  114. void CPagePeopleList::OnKeydown(NMHDR* pNMHDR, LRESULT* pResult) 
  115. {
  116. TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)pNMHDR;
  117.   HTREEITEM hCurrItem = GetSelectedItem();
  118.   if(hCurrItem != NULL)
  119.   {
  120.     switch(pTVKeyDown->wVKey)
  121.     {
  122.       case VK_F3:
  123.         ((CPagePeople*)GetParent())->OnFingerCurrent();
  124.         break;
  125.       case VK_F2:
  126.         EditLabel(hCurrItem);
  127.         break;
  128.       
  129.       case VK_DELETE:
  130.         if(MessageBox("Remove this item???", NULL, MB_ICONQUESTION | MB_YESNO) == IDYES)
  131.         {
  132.           g_WriteToHistory(TRUE, "[People] Removed " + GetItemText(hCurrItem));
  133.           DeleteItem(hCurrItem);
  134.         }
  135.         break;
  136.       
  137.       case VK_SPACE:
  138.         SwitchPeopleActive();
  139.         break;
  140.     }
  141.   }
  142. *pResult = 0;
  143. }
  144. /////////////////////////////////////////////////////////////////////////////
  145. void CPagePeopleList::OnContextMenu(CWnd* pWnd, CPoint point) 
  146. {
  147.   CMenu popMenu; 
  148.   CPoint posMouse; 
  149.   GetCursorPos(&posMouse); 
  150.   popMenu.LoadMenu(IDR_PEOPLEMENU); 
  151.   HTREEITEM hCurrItem = GetSelectedItem();
  152.   if(hCurrItem && GetItemState(hCurrItem, TVIF_STATE) & TVIS_BOLD)
  153.     popMenu.GetSubMenu(0)->CheckMenuItem(IDM_PEOPLE_ACTIVE, MF_CHECKED | MF_BYCOMMAND);
  154.   else
  155.     popMenu.GetSubMenu(0)->CheckMenuItem(IDM_PEOPLE_ACTIVE, MF_UNCHECKED | MF_BYCOMMAND);
  156.   popMenu.GetSubMenu(0)->TrackPopupMenu(0, posMouse.x, posMouse.y, this);
  157. }
  158. /////////////////////////////////////////////////////////////////////////////
  159. void CPagePeopleList::OnPeopleFinger() 
  160. {
  161.   ((CPagePeople*)GetParent())->OnFingerCurrent();
  162. }
  163. /////////////////////////////////////////////////////////////////////////////
  164. void CPagePeopleList::OnPeopleRename() 
  165. {
  166.   EditLabel(GetSelectedItem());
  167. }
  168. /////////////////////////////////////////////////////////////////////////////
  169. void CPagePeopleList::OnPeopleRemove() 
  170. {
  171.   if(MessageBox("Remove this item???", NULL, MB_ICONQUESTION | MB_YESNO) == IDYES)
  172.   {
  173.     g_WriteToHistory(TRUE, "[People] Removed " + GetItemText(GetSelectedItem()));
  174.     DeleteItem(GetSelectedItem());
  175.   }
  176. }
  177. /////////////////////////////////////////////////////////////////////////////
  178. void CPagePeopleList::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) 
  179. {
  180.   if(GetSelectedItem())
  181.   {
  182.     CPoint point;
  183.     GetCursorPos(&point);
  184.     OnContextMenu(this, point);
  185.   *pResult = 0;
  186.   }
  187. }
  188. /////////////////////////////////////////////////////////////////////////////
  189. void CPagePeopleList::OnPeopleCheckall() 
  190. {
  191.   ((CPagePeople*)GetParent())->OnCheckAll();
  192. }
  193. /////////////////////////////////////////////////////////////////////////////
  194. void CPagePeopleList::OnPeopleActive() 
  195. {
  196.   SwitchPeopleActive();
  197. }
  198. /////////////////////////////////////////////////////////////////////////////
  199. void CPagePeopleList::SwitchPeopleActive() 
  200. {
  201.   HTREEITEM hCurrItem = GetSelectedItem();
  202.   SetItemData(hCurrItem, 0);
  203.   if(GetItemState(hCurrItem, TVIF_STATE) & TVIS_BOLD)
  204.   {
  205.     SetItemState(hCurrItem, NULL, TVIS_BOLD);
  206.     ((CPagePeople*)GetParent())->m_Active.SetCheck(0);
  207.   }
  208.   else
  209.   {
  210.     SetItemState(hCurrItem, TVIS_BOLD, TVIS_BOLD);
  211.     ((CPagePeople*)GetParent())->m_Active.SetCheck(1);
  212.   }
  213.   ((CPagePeople*)GetParent())->IfCanCheckAll();
  214. }
  215. /////////////////////////////////////////////////////////////////////////////
  216. void CPagePeopleList::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult) 
  217. {
  218. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  219.   m_dragItem = pNMTreeView->itemNew.hItem;
  220.   if(GetParentItem(m_dragItem) != NULL)
  221.   {
  222.     CImageList* pDragImage;
  223.     pDragImage = CreateDragImage(m_dragItem);
  224.     SelectItem(m_dragItem);
  225.     pDragImage->BeginDrag(0, CPoint(0,0));
  226.     pDragImage->DragEnter(this, pNMTreeView->ptDrag);
  227.     SetCapture();
  228.     m_bIsDragging = TRUE;
  229.     delete pDragImage;
  230.   }
  231. *pResult = 0;
  232. }
  233. /////////////////////////////////////////////////////////////////////////////
  234. void CPagePeopleList::OnMouseMove(UINT nFlags, CPoint point) 
  235. {
  236.   if(m_bIsDragging != FALSE)
  237.   {
  238.     CPoint ptTree(point);
  239.     MapWindowPoints(this, &ptTree, 1);
  240.     CImageList::DragMove(ptTree);
  241.     UINT uHitTest = TVHT_ONITEM;
  242.     m_dragTarget = HitTest(ptTree, &uHitTest);
  243.   }
  244. CTreeCtrl::OnMouseMove(nFlags, point);
  245. }
  246. /////////////////////////////////////////////////////////////////////////////
  247. void CPagePeopleList::OnLButtonUp(UINT nFlags, CPoint point) 
  248. {
  249.   if(m_bIsDragging != FALSE)
  250.   {
  251.     CImageList::DragLeave(this);
  252.     CImageList::EndDrag();
  253.     ReleaseCapture();
  254.     m_bIsDragging = FALSE;
  255.     if(m_dragTarget != NULL)
  256.     {
  257.       HTREEITEM hParent;
  258.       HTREEITEM hInsertedItem;
  259.       hParent = GetParentItem(m_dragTarget);
  260.       CString szLabel = GetItemText(m_dragItem);
  261.       if(hParent != NULL)
  262.         hInsertedItem = InsertItem(szLabel, 1, 1, hParent, m_dragTarget);
  263.       else
  264.         hInsertedItem = InsertItem(szLabel, 1, 1, m_dragTarget, TVI_FIRST);
  265.       UINT nState = TVIS_BOLD | TVIS_STATEIMAGEMASK;
  266.       SetItemState(hInsertedItem, GetItemState(m_dragItem, nState), nState);
  267.       DeleteItem(m_dragItem);
  268.     }
  269.   }
  270.   else
  271.    CTreeCtrl::OnLButtonUp(nFlags, point);
  272. }
  273. /////////////////////////////////////////////////////////////////////////////