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.

310 lines
9.6 KiB

  1. // ncbrowseView.cpp : implementation of the CNcbrowseView class
  2. //
  3. #include "stdafx.h"
  4. #include "ncbrowse.h"
  5. #include "ncbrowseDoc.h"
  6. #include "ncbrowseView.h"
  7. #include "LeftView.h"
  8. #include "NCEditView.h"
  9. #include <commctrl.h>
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CNcbrowseView
  17. IMPLEMENT_DYNCREATE(CNcbrowseView, CListView)
  18. BEGIN_MESSAGE_MAP(CNcbrowseView, CListView)
  19. //{{AFX_MSG_MAP(CNcbrowseView)
  20. ON_WM_CREATE()
  21. ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnItemchanged)
  22. ON_WM_KEYUP()
  23. //}}AFX_MSG_MAP
  24. // Standard printing commands
  25. ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
  26. ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
  27. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
  28. END_MESSAGE_MAP()
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CNcbrowseView construction/destruction
  31. CNcbrowseView::CNcbrowseView()
  32. {
  33. // TODO: add construction code here
  34. dwCurrentItems = 0;
  35. }
  36. CNcbrowseView::~CNcbrowseView()
  37. {
  38. }
  39. BOOL CNcbrowseView::PreCreateWindow(CREATESTRUCT& cs)
  40. {
  41. // TODO: Modify the Window class or styles here by modifying
  42. // the CREATESTRUCT cs
  43. return CListView::PreCreateWindow(cs);
  44. }
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CNcbrowseView drawing
  47. void CNcbrowseView::OnDraw(CDC* pDC)
  48. {
  49. // TODO: add draw code for native data here
  50. }
  51. void CNcbrowseView::OnInitialUpdate()
  52. {
  53. CListView::OnInitialUpdate();
  54. // TODO: You may populate your ListView with items by directly accessing
  55. // its list control through a call to GetListCtrl().
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CNcbrowseView printing
  59. BOOL CNcbrowseView::OnPreparePrinting(CPrintInfo* pInfo)
  60. {
  61. // default preparation
  62. return DoPreparePrinting(pInfo);
  63. }
  64. void CNcbrowseView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  65. {
  66. // TODO: add extra initialization before printing
  67. }
  68. void CNcbrowseView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  69. {
  70. // TODO: add cleanup after printing
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CNcbrowseView diagnostics
  74. #ifdef _DEBUG
  75. void CNcbrowseView::AssertValid() const
  76. {
  77. CListView::AssertValid();
  78. }
  79. void CNcbrowseView::Dump(CDumpContext& dc) const
  80. {
  81. CListView::Dump(dc);
  82. }
  83. CNcbrowseDoc* CNcbrowseView::GetDocument() // non-debug version is inline
  84. {
  85. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNcbrowseDoc)));
  86. return (CNcbrowseDoc*)m_pDocument;
  87. }
  88. #endif //_DEBUG
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CNcbrowseView message handlers
  91. void CNcbrowseView::OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
  92. {
  93. //TODO: add code to react to the user changing the view style of your window
  94. }
  95. int CNcbrowseView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  96. {
  97. if (CListView::OnCreate(lpCreateStruct) == -1)
  98. return -1;
  99. // Give the document a pointer to this view
  100. GetDocument()->m_pListView = this;
  101. CImageList *MyImageList = new CImageList;
  102. MyImageList->Create(32,32, ILC_COLOR8, 0, 4);
  103. MyImageList->Add(AfxGetApp()->LoadIcon(IDI_LINE));
  104. CImageList *MyImageList2 = new CImageList;
  105. MyImageList2->Create(16, 16, ILC_COLOR8, 0, 4);
  106. MyImageList2->Add(AfxGetApp()->LoadIcon(IDI_LINE));
  107. CListCtrl& refListCtrl = GetListCtrl();
  108. refListCtrl.SetImageList(MyImageList, LVSIL_NORMAL);
  109. refListCtrl.SetImageList(MyImageList2, LVSIL_SMALL);
  110. refListCtrl.ModifyStyle(LVS_TYPEMASK, LVS_REPORT | LVS_SHOWSELALWAYS);
  111. refListCtrl.SetExtendedStyle
  112. (refListCtrl.GetExtendedStyle()|LVS_EX_FULLROWSELECT );
  113. HWND hwndListCtrl = refListCtrl.GetSafeHwnd();
  114. HFONT hFont;
  115. hFont = (HFONT)GetStockObject(SYSTEM_FIXED_FONT);
  116. refListCtrl.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);
  117. refListCtrl.InsertColumn(0, _T("Line#"));
  118. refListCtrl.InsertColumn(1, _T("Proc.Thrd"));
  119. refListCtrl.InsertColumn(2, _T("Tag"));
  120. refListCtrl.InsertColumn(3, _T("Description"));
  121. refListCtrl.SetColumnWidth( 0, 75);
  122. refListCtrl.SetColumnWidth( 1, 90);
  123. refListCtrl.SetColumnWidth( 2, 150);
  124. refListCtrl.SetColumnWidth( 3, 2000);
  125. m_dwOldThreadColWidth = 90;
  126. m_dwOldTagColWidth = 150;
  127. return 0;
  128. }
  129. void CNcbrowseView::UpdateInfo(DWORD dwProcThread, LPCTSTR pszFilter)
  130. {
  131. CNcbrowseDoc* pDoc = GetDocument();
  132. ASSERT_VALID(pDoc);
  133. CListCtrl& refListCtrl = GetListCtrl();
  134. CNCSpewFile& NCSpewFile = pDoc->GetSpewFile();
  135. if (dwProcThread)
  136. {
  137. const CNCEntryList *pEntryList = NULL;
  138. DWORD dwNewThreadColWidth = 0;
  139. DWORD dwNewTagColWidth = 0;
  140. refListCtrl.SetRedraw(FALSE);
  141. if (dwProcThread & 0xffff0000)
  142. {
  143. for (CSpewList::const_iterator i = NCSpewFile.m_Spews.begin(); i != NCSpewFile.m_Spews.end(); i++)
  144. {
  145. CNCThreadList::const_iterator pThread = i->second.m_NCThreadList.find(dwProcThread);
  146. if (pThread != i->second.m_NCThreadList.end())
  147. {
  148. pEntryList = &(pThread->second.m_lsLines);
  149. break;
  150. }
  151. }
  152. DWORD dwThreadColWidth = refListCtrl.GetColumnWidth( 1 );
  153. if (dwThreadColWidth)
  154. {
  155. m_dwOldThreadColWidth = dwThreadColWidth;
  156. }
  157. dwNewThreadColWidth = 0;
  158. }
  159. else
  160. {
  161. pEntryList = &(NCSpewFile.m_Spews[dwProcThread].m_lsLines);
  162. dwNewThreadColWidth = m_dwOldThreadColWidth;
  163. }
  164. if (pszFilter)
  165. {
  166. DWORD dwTagColWidth = refListCtrl.GetColumnWidth( 2 );
  167. if (dwTagColWidth)
  168. {
  169. m_dwOldTagColWidth = dwTagColWidth;
  170. }
  171. dwNewTagColWidth = 0;
  172. }
  173. else
  174. {
  175. dwNewTagColWidth = m_dwOldTagColWidth;
  176. }
  177. if (pEntryList)
  178. {
  179. HCURSOR hPrevCursor;
  180. if ( (pEntryList->size() > 100) || (dwCurrentItems > 100) )
  181. {
  182. hPrevCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  183. }
  184. refListCtrl.DeleteAllItems();
  185. CNCEntryList::const_iterator iLines;
  186. for (iLines = pEntryList->begin(); iLines != pEntryList->end(); iLines++)
  187. {
  188. if ( (!pszFilter) || (!_tcscmp(pszFilter, iLines->m_szTag.c_str())) )
  189. {
  190. TCHAR szItemName[8192];
  191. _stprintf(szItemName, _T("%d"), iLines->m_dwLineNumber);
  192. LVITEM LvItem;
  193. ZeroMemory(&LvItem, sizeof(LVITEM));
  194. LvItem.mask = LVIF_TEXT | LVIF_INDENT | LVIF_IMAGE | LVIF_PARAM;
  195. LvItem.pszText = szItemName;
  196. LvItem.iSubItem = 0;
  197. LvItem.iItem = iLines->m_dwLineNumber;
  198. LvItem.iIndent = iLines->m_dwLevel;
  199. LvItem.iImage = 0;
  200. LvItem.lParam = iLines->m_dwLineNumber;
  201. DWORD dwItem = refListCtrl.InsertItem(&LvItem);
  202. _stprintf(szItemName, _T("%03x.%03x"), iLines->m_dwProcessId, iLines->m_dwThreadId);
  203. ZeroMemory(&LvItem, sizeof(LVITEM));
  204. LvItem.mask = LVIF_TEXT;
  205. LvItem.pszText = szItemName;
  206. LvItem.iItem = dwItem;
  207. LvItem.iSubItem = 1;
  208. refListCtrl.SetItem(&LvItem);
  209. _stprintf(szItemName, _T("%s"), iLines->m_szTag.c_str());
  210. ZeroMemory(&LvItem, sizeof(LVITEM));
  211. LvItem.mask = LVIF_TEXT;
  212. LvItem.pszText = szItemName;
  213. LvItem.iItem = dwItem;
  214. LvItem.iSubItem = 2;
  215. refListCtrl.SetItem(&LvItem);
  216. _stprintf(szItemName, _T("%s"), iLines->m_szDescription.c_str());
  217. ZeroMemory(&LvItem, sizeof(LVITEM));
  218. LvItem.mask = LVIF_TEXT;
  219. LvItem.pszText = szItemName;
  220. LvItem.iItem = dwItem;
  221. LvItem.iSubItem = 3;
  222. refListCtrl.SetItem(&LvItem);
  223. }
  224. }
  225. if ( (pEntryList->size() > 100) || (dwCurrentItems > 100) )
  226. {
  227. SetCursor(hPrevCursor);
  228. }
  229. dwCurrentItems = pEntryList->size();
  230. }
  231. refListCtrl.SetRedraw(TRUE);
  232. refListCtrl.SetColumnWidth( 1, dwNewThreadColWidth);
  233. refListCtrl.SetColumnWidth( 2, dwNewTagColWidth);
  234. }
  235. return;
  236. }
  237. void CNcbrowseView::OnItemchanged(NMHDR* pNMHDR, LRESULT* pResult)
  238. {
  239. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  240. // TODO: Add your control notification handler code here
  241. CListCtrl& refListCtrl = GetListCtrl();
  242. DWORD dwLineNum = refListCtrl.GetItemData(pNMListView->iItem);
  243. GetDocument()->m_pEditView->ScrollToLine(dwLineNum);
  244. *pResult = 0;
  245. }
  246. void CNcbrowseView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
  247. {
  248. // TODO: Add your message handler code here and/or call default
  249. CListView::OnKeyUp(nChar, nRepCnt, nFlags);
  250. }