Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

306 lines
11 KiB

  1. // LeftView.cpp : implementation of the CLeftView class
  2. //
  3. #include "stdafx.h"
  4. #include "ncbrowse.h"
  5. #include "ncbrowseDoc.h"
  6. #include "LeftView.h"
  7. #include "ncbrowseView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CLeftView
  15. IMPLEMENT_DYNCREATE(CLeftView, CTreeView)
  16. BEGIN_MESSAGE_MAP(CLeftView, CTreeView)
  17. //{{AFX_MSG_MAP(CLeftView)
  18. ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
  19. ON_WM_CREATE()
  20. //}}AFX_MSG_MAP
  21. // Standard printing commands
  22. ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CTreeView::OnFilePrintPreview)
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CLeftView construction/destruction
  28. const DWORD dwNumIcons = 3;
  29. CLeftView::CLeftView()
  30. {
  31. // TODO: add construction code here
  32. }
  33. CLeftView::~CLeftView()
  34. {
  35. }
  36. BOOL CLeftView::PreCreateWindow(CREATESTRUCT& cs)
  37. {
  38. // TODO: Modify the Window class or styles here by modifying
  39. // the CREATESTRUCT cs
  40. return CTreeView::PreCreateWindow(cs);
  41. }
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CLeftView drawing
  44. void CLeftView::OnDraw(CDC* pDC)
  45. {
  46. CNcbrowseDoc* pDoc = GetDocument();
  47. ASSERT_VALID(pDoc);
  48. // TODO: add draw code for native data here
  49. }
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CLeftView printing
  52. BOOL CLeftView::OnPreparePrinting(CPrintInfo* pInfo)
  53. {
  54. // default preparation
  55. return DoPreparePrinting(pInfo);
  56. }
  57. void CLeftView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  58. {
  59. // TODO: add extra initialization before printing
  60. }
  61. void CLeftView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  62. {
  63. // TODO: add cleanup after printing
  64. }
  65. void CLeftView::OnInitialUpdate()
  66. {
  67. CTreeView::OnInitialUpdate();
  68. CTreeCtrl& refTreeCtrl = GetTreeCtrl();
  69. CNcbrowseDoc* pDoc = GetDocument();
  70. ASSERT_VALID(pDoc);
  71. CNCSpewFile& NCSpewFile = pDoc->GetSpewFile();
  72. if (&NCSpewFile)
  73. {
  74. HTREEITEM hti = TVI_LAST;
  75. DWORD dwLevel = 0;
  76. for (CSpewList::const_iterator i = NCSpewFile.m_Spews.begin(); i != NCSpewFile.m_Spews.end(); i++)
  77. {
  78. dwLevel++;
  79. TCHAR szItemName[MAX_PATH];
  80. _stprintf(szItemName, _T("%s"), i->second.szSpewName.c_str());
  81. TVINSERTSTRUCT TvSpew;
  82. ZeroMemory(&TvSpew, sizeof(TvSpew));
  83. TvSpew.hParent = TVI_ROOT;
  84. TvSpew.hInsertAfter = hti;
  85. TvSpew.itemex.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  86. TvSpew.itemex.pszText = szItemName;
  87. TvSpew.itemex.cchTextMax = _tcslen(szItemName);
  88. TvSpew.itemex.lParam = dwLevel;
  89. TvSpew.itemex.iImage = 0;
  90. TvSpew.itemex.iSelectedImage = TvSpew.itemex.iImage + dwNumIcons;
  91. hti = refTreeCtrl.InsertItem(&TvSpew);
  92. HTREEITEM htsi = TVI_LAST;
  93. CNCTagMap::const_iterator iTags;
  94. for (iTags = i->second.m_Tags.begin(); iTags != i->second.m_Tags.end(); iTags++)
  95. {
  96. DWORD dwLineCount = iTags->second;
  97. TCHAR szItemName[MAX_PATH];
  98. _stprintf(szItemName, _T("%s (%d)"), iTags->first.c_str(), iTags->second);
  99. TVINSERTSTRUCT TvThread;
  100. ZeroMemory(&TvThread, sizeof(TvThread));
  101. TvThread.hParent = hti;
  102. TvThread.hInsertAfter = htsi;
  103. TvThread.itemex.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  104. TvThread.itemex.pszText = szItemName;
  105. TvThread.itemex.cchTextMax = _tcslen(szItemName);
  106. TvThread.itemex.lParam = 0;
  107. TvThread.itemex.iImage = 2;
  108. TvThread.itemex.iSelectedImage = TvThread.itemex.iImage + dwNumIcons;
  109. htsi = refTreeCtrl.InsertItem(&TvThread);
  110. CNCThreadList::const_iterator iThread;
  111. for (iThread = i->second.m_NCThreadList.begin(); iThread != i->second.m_NCThreadList.end(); iThread++)
  112. {
  113. if (iThread->second.m_Tags.find(iTags->first) != iThread->second.m_Tags.end())
  114. {
  115. DWORD dwLineCount = iThread->second.m_lsLines.size();
  116. TCHAR szItemName[MAX_PATH];
  117. _stprintf(szItemName, _T("%03x.%03x"), iThread->second.m_dwProcessId, iThread->second.m_dwThreadID);
  118. TVINSERTSTRUCT TvThread;
  119. ZeroMemory(&TvThread, sizeof(TvThread));
  120. TvThread.hParent = htsi;
  121. TvThread.hInsertAfter = TVI_LAST;
  122. TvThread.itemex.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  123. TvThread.itemex.pszText = szItemName;
  124. TvThread.itemex.cchTextMax = _tcslen(szItemName);
  125. TvThread.itemex.lParam = iThread->first;
  126. TvThread.itemex.iImage = 1;
  127. TvThread.itemex.iSelectedImage = TvThread.itemex.iImage + dwNumIcons;
  128. refTreeCtrl.InsertItem(&TvThread);
  129. }
  130. }
  131. }
  132. htsi = TVI_LAST;
  133. DWORD dwTotalLines = 0;
  134. CNCThreadList::const_iterator iThread;
  135. for (iThread = i->second.m_NCThreadList.begin(); iThread != i->second.m_NCThreadList.end(); iThread++)
  136. {
  137. DWORD dwLineCount = iThread->second.m_lsLines.size();
  138. dwTotalLines += dwLineCount;
  139. TCHAR szItemName[MAX_PATH];
  140. _stprintf(szItemName, _T("%03x.%03x (%d)"), iThread->second.m_dwProcessId, iThread->second.m_dwThreadID, dwLineCount);
  141. TVINSERTSTRUCT TvThread;
  142. ZeroMemory(&TvThread, sizeof(TvThread));
  143. TvThread.hParent = hti;
  144. TvThread.hInsertAfter = htsi;
  145. TvThread.itemex.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  146. TvThread.itemex.pszText = szItemName;
  147. TvThread.itemex.cchTextMax = _tcslen(szItemName);
  148. TvThread.itemex.lParam = iThread->first;
  149. TvThread.itemex.iImage = 1;
  150. TvThread.itemex.iSelectedImage = TvThread.itemex.iImage + dwNumIcons;
  151. htsi = refTreeCtrl.InsertItem(&TvThread);
  152. CNCTagMap::const_iterator iTags;
  153. for (iTags = iThread->second.m_Tags.begin(); iTags != iThread->second.m_Tags.end(); iTags++)
  154. {
  155. DWORD dwLineCount = iTags->second;
  156. TCHAR szItemName[MAX_PATH];
  157. _stprintf(szItemName, _T("%s (%d)"), iTags->first.c_str(), iTags->second);
  158. TVINSERTSTRUCT TvThread;
  159. ZeroMemory(&TvThread, sizeof(TvThread));
  160. TvThread.hParent = htsi;
  161. TvThread.hInsertAfter = TVI_LAST;
  162. TvThread.itemex.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  163. TvThread.itemex.pszText = szItemName;
  164. TvThread.itemex.cchTextMax = _tcslen(szItemName);
  165. TvThread.itemex.lParam = 0;
  166. TvThread.itemex.iImage = 2;
  167. TvThread.itemex.iSelectedImage = TvThread.itemex.iImage + dwNumIcons;
  168. refTreeCtrl.InsertItem(&TvThread);
  169. }
  170. }
  171. _stprintf(szItemName, _T("%s (%d)"), i->second.szSpewName.c_str(), dwTotalLines);
  172. refTreeCtrl.SetItemText(hti, szItemName);
  173. refTreeCtrl.Expand(hti, TVE_EXPAND);
  174. }
  175. }
  176. // TODO: You may populate your TreeView with items by directly accessing
  177. // its tree control through a call to GetTreeCtrl().
  178. }
  179. /////////////////////////////////////////////////////////////////////////////
  180. // CLeftView diagnostics
  181. #ifdef _DEBUG
  182. void CLeftView::AssertValid() const
  183. {
  184. CTreeView::AssertValid();
  185. }
  186. void CLeftView::Dump(CDumpContext& dc) const
  187. {
  188. CTreeView::Dump(dc);
  189. }
  190. CNcbrowseDoc* CLeftView::GetDocument() // non-debug version is inline
  191. {
  192. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNcbrowseDoc)));
  193. return (CNcbrowseDoc*)m_pDocument;
  194. }
  195. #endif //_DEBUG
  196. /////////////////////////////////////////////////////////////////////////////
  197. // CLeftView message handlers
  198. void CLeftView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
  199. {
  200. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  201. // TODO: Add your control notification handler code here
  202. DWORD lParam = pNMTreeView->itemNew.lParam;
  203. LPCTSTR szFilter = NULL;
  204. CString ItemText;
  205. if (!lParam)
  206. {
  207. CTreeCtrl& refTreeCtrl = GetTreeCtrl();
  208. HTREEITEM hParent = refTreeCtrl.GetParentItem( pNMTreeView->itemNew.hItem);
  209. lParam = refTreeCtrl.GetItemData(hParent);
  210. ItemText = refTreeCtrl.GetItemText(pNMTreeView->itemNew.hItem);
  211. ItemText += _T(' ');
  212. DWORD dwSpace = ItemText.Find(_T(' '));
  213. ItemText = ItemText.Left(dwSpace);
  214. szFilter = ItemText;
  215. }
  216. else
  217. {
  218. CTreeCtrl& refTreeCtrl = GetTreeCtrl();
  219. HTREEITEM hParent = refTreeCtrl.GetParentItem( pNMTreeView->itemNew.hItem);
  220. if (hParent)
  221. {
  222. if (!refTreeCtrl.GetItemData(hParent))
  223. {
  224. ItemText = refTreeCtrl.GetItemText(hParent);
  225. ItemText += _T(' ');
  226. DWORD dwSpace = ItemText.Find(_T(' '));
  227. ItemText = ItemText.Left(dwSpace);
  228. szFilter = ItemText;
  229. }
  230. }
  231. }
  232. GetDocument()->m_pListView->UpdateInfo(lParam, szFilter);
  233. *pResult = 0;
  234. }
  235. int CLeftView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  236. {
  237. lpCreateStruct->style |= TVS_SHOWSELALWAYS | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;
  238. if (CTreeView::OnCreate(lpCreateStruct) == -1)
  239. return -1;
  240. // Give the document a pointer to this view
  241. GetDocument()->m_pTreeView = this;
  242. CImageList *MyImageList = new CImageList;
  243. MyImageList->Create(16, 16, ILC_COLOR32, 0, 4);
  244. MyImageList->Add(AfxGetApp()->LoadIcon(IDI_SPEW));
  245. MyImageList->Add(AfxGetApp()->LoadIcon(IDI_THREAD));
  246. MyImageList->Add(AfxGetApp()->LoadIcon(IDI_FILTER));
  247. MyImageList->Add(AfxGetApp()->LoadIcon(IDI_SPEW_SEL));
  248. MyImageList->Add(AfxGetApp()->LoadIcon(IDI_THREAD_SEL));
  249. MyImageList->Add(AfxGetApp()->LoadIcon(IDI_FILTER_SEL));
  250. CTreeCtrl& refTreeCtrl = GetTreeCtrl();
  251. refTreeCtrl.SetImageList(MyImageList, TVSIL_NORMAL);
  252. refTreeCtrl.SetImageList(MyImageList, TVSIL_STATE);
  253. return 0;
  254. }