Source code of Windows XP (NT5)
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.

200 lines
5.0 KiB

  1. #include "RightTopView.h"
  2. #include "PortsPage.h"
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6. IMPLEMENT_DYNCREATE( RightTopView, CListView )
  7. BEGIN_MESSAGE_MAP( RightTopView, CListView )
  8. ON_NOTIFY(HDN_ITEMCLICK, 0, OnColumnClick)
  9. END_MESSAGE_MAP()
  10. Document*
  11. RightTopView::GetDocument()
  12. {
  13. return ( Document *) m_pDocument;
  14. }
  15. void
  16. RightTopView::OnInitialUpdate()
  17. {
  18. //
  19. // set images for this view.
  20. //
  21. GetListCtrl().SetImageList( GetDocument()->m_images48x48,
  22. LVSIL_SMALL );
  23. //
  24. // set the style, we only want report
  25. // view
  26. //
  27. // get present style.
  28. LONG presentStyle;
  29. presentStyle = GetWindowLong( m_hWnd, GWL_STYLE );
  30. // Set the last error to zero to avoid confusion.
  31. // See sdk for SetWindowLong.
  32. SetLastError(0);
  33. // set new style.
  34. SetWindowLong( m_hWnd,
  35. GWL_STYLE,
  36. presentStyle | LVS_REPORT );
  37. //
  38. // we will register
  39. // with the document class,
  40. // as we are the list pane
  41. //
  42. GetDocument()->registerListPane( this );
  43. // initially nothing has been clicked.
  44. m_sort_column = -1;
  45. }
  46. void RightTopView::OnColumnClick(NMHDR* pNotifyStruct, LRESULT* pResult)
  47. {
  48. HTREEITEM hdlSelItem;
  49. hdlSelItem = GetDocument()->getLeftPane().GetSelectedItem();
  50. TVITEM selItem;
  51. selItem.hItem = hdlSelItem;
  52. selItem.mask = TVIF_IMAGE ;
  53. GetDocument()->getLeftPane().GetItem( &selItem );
  54. // We only handle column clicks for port rules.
  55. if( selItem.iImage != 2 )
  56. {
  57. return;
  58. }
  59. LPNMLISTVIEW lv = ( LPNMLISTVIEW) pNotifyStruct;
  60. vector<PortsPage::PortData> ports;
  61. int index;
  62. // get all the port rules presently in the list.
  63. for( index = 0; index < GetListCtrl().GetItemCount(); ++index )
  64. {
  65. PortsPage::PortData portData;
  66. wchar_t buffer[Common::BUF_SIZE];
  67. GetListCtrl().GetItemText( index, 0, buffer, Common::BUF_SIZE );
  68. portData.start_port = buffer;
  69. GetListCtrl().GetItemText( index, 1, buffer, Common::BUF_SIZE );
  70. portData.end_port = buffer;
  71. GetListCtrl().GetItemText( index, 2, buffer, Common::BUF_SIZE );
  72. portData.protocol = buffer;
  73. GetListCtrl().GetItemText( index, 3, buffer, Common::BUF_SIZE );
  74. portData.mode = buffer;
  75. GetListCtrl().GetItemText( index, 4, buffer, Common::BUF_SIZE );
  76. portData.priority = buffer;
  77. GetListCtrl().GetItemText( index, 5, buffer, Common::BUF_SIZE );
  78. portData.load = buffer;
  79. GetListCtrl().GetItemText( index, 6, buffer, Common::BUF_SIZE );
  80. portData.affinity = buffer;
  81. ports.push_back( portData );
  82. }
  83. // sort these port rules depending upon the header which has
  84. // been clicked.
  85. switch( lv->iItem )
  86. {
  87. case 0 :
  88. // user has clicked start port.
  89. sort( ports.begin(), ports.end(), comp_start_port() );
  90. break;
  91. case 1:
  92. // user has clicked end port
  93. sort( ports.begin(), ports.end(), comp_end_port() );
  94. break;
  95. case 2:
  96. // user has clicked protocol
  97. sort( ports.begin(), ports.end(), comp_protocol() );
  98. break;
  99. case 3:
  100. // user has clicked mode
  101. sort( ports.begin(), ports.end(), comp_mode() );
  102. break;
  103. case 4:
  104. // user has clicked priority
  105. sort( ports.begin(), ports.end(), comp_priority_int() );
  106. break;
  107. case 5:
  108. // user has clicked load
  109. sort( ports.begin(), ports.end(), comp_load_int() );
  110. break;
  111. case 6:
  112. // user has clicked affinity
  113. sort( ports.begin(), ports.end(), comp_affinity() );
  114. break;
  115. default:
  116. break;
  117. }
  118. /* If we are sorting by the same column we were previously sorting by,
  119. then we reverse the sort order. */
  120. if( m_sort_column == lv->iItem )
  121. {
  122. m_sort_ascending = !m_sort_ascending;
  123. }
  124. else
  125. {
  126. // default sort is ascending.
  127. m_sort_ascending = true;
  128. }
  129. m_sort_column = lv->iItem;
  130. int portIndex;
  131. int itemCount = GetListCtrl().GetItemCount();
  132. for( index = 0; index < itemCount; ++index )
  133. {
  134. if( m_sort_ascending == true )
  135. {
  136. portIndex = index;
  137. }
  138. else
  139. {
  140. portIndex = ( itemCount - 1 ) - index;
  141. }
  142. GetListCtrl().SetItemText( index, 0, ports[portIndex].start_port );
  143. GetListCtrl().SetItemText( index, 1, ports[portIndex].end_port );
  144. GetListCtrl().SetItemText( index, 2, ports[portIndex].protocol );
  145. GetListCtrl().SetItemText( index, 3, ports[portIndex].mode );
  146. GetListCtrl().SetItemText( index, 4, ports[portIndex].priority );
  147. GetListCtrl().SetItemText( index, 5, ports[portIndex].load );
  148. GetListCtrl().SetItemText( index, 6, ports[portIndex].affinity );
  149. }
  150. return;
  151. }