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.

398 lines
10 KiB

  1. // adsqryView.cpp : implementation of the CAdsqryView class
  2. //
  3. #include "stdafx.h"
  4. #include "viewex.h"
  5. #include "adsqDoc.h"
  6. #include "adsqView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAdsqryView
  14. IMPLEMENT_DYNCREATE(CAdsqryView, CListView )
  15. BEGIN_MESSAGE_MAP(CAdsqryView, CListView )
  16. //{{AFX_MSG_MAP(CAdsqryView)
  17. ON_WM_VSCROLL()
  18. //}}AFX_MSG_MAP
  19. // Standard printing commands
  20. END_MESSAGE_MAP()
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CAdsqryView construction/destruction
  23. extern CViewExApp NEAR theApp;
  24. extern TCHAR szOpen[ MAX_PATH ];
  25. /***********************************************************
  26. Function:
  27. Arguments:
  28. Return:
  29. Purpose:
  30. Author(s):
  31. Revision:
  32. Date:
  33. ***********************************************************/
  34. CAdsqryView::CAdsqryView()
  35. {
  36. // TODO: add construction code here
  37. m_nLastInsertedRow = -1;
  38. m_nColumnsCount = 0;
  39. }
  40. /***********************************************************
  41. Function:
  42. Arguments:
  43. Return:
  44. Purpose:
  45. Author(s):
  46. Revision:
  47. Date:
  48. ***********************************************************/
  49. CAdsqryView::~CAdsqryView()
  50. {
  51. }
  52. /***********************************************************
  53. Function:
  54. Arguments:
  55. Return:
  56. Purpose:
  57. Author(s):
  58. Revision:
  59. Date:
  60. ***********************************************************/
  61. BOOL CAdsqryView::PreCreateWindow(CREATESTRUCT& cs)
  62. {
  63. // TODO: Modify the Window class or styles here by modifying
  64. // the CREATESTRUCT cs
  65. cs.style |= LVS_REPORT;
  66. return CListView::PreCreateWindow(cs);
  67. }
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CAdsqryView diagnostics
  70. #ifdef _DEBUG
  71. void CAdsqryView::AssertValid() const
  72. {
  73. CListView::AssertValid();
  74. }
  75. void CAdsqryView::Dump(CDumpContext& dc) const
  76. {
  77. CListView::Dump(dc);
  78. }
  79. CAdsqryDoc* CAdsqryView::GetDocument() // non-debug version is inline
  80. {
  81. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAdsqryDoc)));
  82. return (CAdsqryDoc*)m_pDocument;
  83. }
  84. #endif //_DEBUG
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CAdsqryView message handlers
  87. /***********************************************************
  88. Function: CAdsqryView::OnInitialUpdate
  89. Arguments:
  90. Return:
  91. Purpose:
  92. Author(s):
  93. Revision:
  94. Date:
  95. ***********************************************************/
  96. void CAdsqryView::OnInitialUpdate()
  97. {
  98. CListView ::OnInitialUpdate();
  99. CreateColumns( );
  100. AddRows( );
  101. }
  102. /***********************************************************
  103. Function: CAdsqryView::AddColumns
  104. Arguments:
  105. Return:
  106. Purpose:
  107. Author(s):
  108. Revision:
  109. Date:
  110. ***********************************************************/
  111. void CAdsqryView::AddColumns( int nRow )
  112. {
  113. int nColumnCount, nIdx, nColumn;
  114. CString strColumn;
  115. LV_COLUMN lvColumn;
  116. CADsDataSource* pDataSource;
  117. CAdsqryDoc* pDoc;
  118. pDoc = GetDocument( );
  119. pDataSource = pDoc->GetADsDataSource( );
  120. nColumnCount = pDataSource->GetColumnsCount( nRow );
  121. for( nIdx = 0; nIdx < nColumnCount ; nIdx++ )
  122. {
  123. pDataSource->GetColumnText( nRow, nIdx, strColumn );
  124. for( nColumn = 0; nColumn < m_nColumnsCount ; nColumn++ )
  125. {
  126. if( m_strColumns[ nColumn ] == strColumn )
  127. break;
  128. }
  129. if( nColumn == m_nColumnsCount )
  130. {
  131. m_strColumns.Add( strColumn );
  132. m_nColumnsCount++;
  133. lvColumn.iSubItem = m_nColumnsCount - 1;
  134. lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  135. lvColumn.fmt = LVCFMT_LEFT;
  136. lvColumn.pszText = strColumn.GetBuffer( 256 );
  137. lvColumn.cx = GetListCtrl( ).GetStringWidth( _T("WWWWWWWWWW") ) + 15;
  138. GetListCtrl( ).InsertColumn( m_nColumnsCount - 1, &lvColumn );
  139. TRACE( _T("Found new Column %s\n"), (LPCTSTR)strColumn );
  140. }
  141. }
  142. }
  143. /***********************************************************
  144. Function: CAdsqryView::CreateColumns
  145. Arguments:
  146. Return:
  147. Purpose:
  148. Author(s):
  149. Revision:
  150. Date:
  151. ***********************************************************/
  152. void CAdsqryView::CreateColumns( void )
  153. {
  154. /* int nCol;
  155. LV_COLUMN lvColumn;
  156. CADsDataSource* pDataSource;
  157. CAdsqryDoc* pDoc;
  158. CString strColumn;
  159. pDoc = GetDocument( );
  160. pDataSource = pDoc->GetADsDataSource( );
  161. m_nColumnsCount = pDataSource->GetColumnsCount( );
  162. for( nCol = 0 ; nCol < m_nColumnsCount ; nCol++ )
  163. {
  164. pDataSource->GetColumnText( nCol, strColumn );
  165. lvColumn.iSubItem = nCol;
  166. lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  167. lvColumn.fmt = LVCFMT_LEFT;
  168. lvColumn.pszText = strColumn.GetBuffer( 256 );
  169. lvColumn.cx = GetListCtrl( ).GetStringWidth( _T("WWWWWWWWWW") ) + 15;
  170. GetListCtrl( ).InsertColumn( nCol, &lvColumn );
  171. }*/
  172. }
  173. /***********************************************************
  174. Function: CAdsqryView::ClearContent
  175. Arguments:
  176. Return:
  177. Purpose:
  178. Author(s):
  179. Revision:
  180. Date:
  181. ***********************************************************/
  182. void CAdsqryView::ClearContent( void )
  183. {
  184. GetListCtrl( ).DeleteAllItems( );
  185. m_nLastInsertedRow = -1;
  186. }
  187. /***********************************************************
  188. Function: CAdsqryView::AddRows
  189. Arguments:
  190. Return:
  191. Purpose:
  192. Author(s):
  193. Revision:
  194. Date:
  195. ***********************************************************/
  196. void CAdsqryView::AddRows( void )
  197. {
  198. int nCol;
  199. int nTopIndex, nPageItems;
  200. int nRowIndex;
  201. CADsDataSource* pDataSource;
  202. CAdsqryDoc* pDoc;
  203. pDoc = GetDocument( );
  204. pDataSource = pDoc->GetADsDataSource( );
  205. nTopIndex = GetListCtrl( ).GetTopIndex( );
  206. nPageItems = GetListCtrl( ).GetCountPerPage( );
  207. if( m_nLastInsertedRow < nTopIndex + 2 * nPageItems )
  208. {
  209. HCURSOR aCursor, oldCursor;
  210. aCursor = LoadCursor( NULL, IDC_WAIT );
  211. oldCursor = SetCursor( aCursor );
  212. // we must add extra items in the list view
  213. for( nRowIndex = m_nLastInsertedRow + 1 ;
  214. nRowIndex < nTopIndex + 2 * nPageItems ;
  215. nRowIndex++ )
  216. {
  217. CString strValue;
  218. BOOL bWork = FALSE;
  219. AddColumns( nRowIndex );
  220. for( nCol = 0; nCol < m_nColumnsCount ; nCol++ )
  221. {
  222. CString strColumnName;
  223. strColumnName = m_strColumns.GetAt( nCol );
  224. if( pDataSource->GetValue( nRowIndex, nCol, strValue ) ||
  225. pDataSource->GetValue( nRowIndex, strColumnName, strValue ) )
  226. {
  227. LV_ITEM lvItem;
  228. TCHAR* pszText;
  229. pszText = (TCHAR*) malloc( strValue.GetLength( ) + 10 );
  230. if(NULL != pszText)
  231. {
  232. _tcscpy( pszText, _T("") );
  233. if( !nCol )
  234. {
  235. _itot( nRowIndex + 1, pszText, 10 );
  236. _tcscat( pszText, _T(") ") );
  237. }
  238. _tcscat( pszText, strValue.GetBuffer( strValue.GetLength( ) + 1 ) );
  239. bWork = TRUE;
  240. memset( &lvItem, 0, sizeof(lvItem) );
  241. lvItem.mask = LVIF_TEXT | LVIF_STATE;
  242. lvItem.state = 0;
  243. lvItem.stateMask = 0;
  244. lvItem.iItem = nRowIndex;
  245. lvItem.iSubItem = nCol;
  246. lvItem.pszText = pszText;
  247. lvItem.cchTextMax = _tcslen( pszText );
  248. if( nCol == 0)
  249. {
  250. GetListCtrl( ).InsertItem(&lvItem);
  251. }
  252. else
  253. {
  254. GetListCtrl( ).SetItem(&lvItem);
  255. }
  256. free( pszText );
  257. }
  258. }
  259. }
  260. if( bWork )
  261. {
  262. m_nLastInsertedRow++;
  263. }
  264. }
  265. SetCursor( oldCursor );
  266. }
  267. }
  268. /***********************************************************
  269. Function: CAdsqryView::OnVScroll
  270. Arguments:
  271. Return:
  272. Purpose:
  273. Author(s):
  274. Revision:
  275. Date:
  276. ***********************************************************/
  277. void CAdsqryView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  278. {
  279. // TODO: Add your message handler code here and/or call default
  280. CListView ::OnVScroll(nSBCode, nPos, pScrollBar);
  281. //if( nSBCode == SB_LINEDOWN || nSBCode == SB_PAGEDOWN )
  282. {
  283. AddRows( );
  284. }
  285. }
  286. /***********************************************************
  287. Function: CAdsqryView::OnChildNotify
  288. Arguments:
  289. Return:
  290. Purpose:
  291. Author(s):
  292. Revision:
  293. Date:
  294. ***********************************************************/
  295. BOOL CAdsqryView::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  296. {
  297. // TODO: Add your specialized code here and/or call the base class
  298. NMHDR* pHeader;
  299. int nSel;
  300. CADsDataSource* pDataSource;
  301. CAdsqryDoc* pDoc;
  302. CString strADsPath;
  303. while( TRUE )
  304. {
  305. if( message != WM_NOTIFY )
  306. break;
  307. pHeader = (NMHDR*)lParam;
  308. if( pHeader->code != NM_DBLCLK )
  309. break;
  310. if( !GetListCtrl( ).GetSelectedCount( ) )
  311. break;
  312. nSel = GetListCtrl( ).GetNextItem( -1, LVNI_SELECTED );;
  313. if( -1 == nSel )
  314. break;
  315. pDoc = GetDocument( );
  316. pDataSource = pDoc->GetADsDataSource( );
  317. pDataSource->GetADsPath( nSel, strADsPath );
  318. _tcscpy( szOpen, strADsPath.GetBuffer( MAX_PATH ) );
  319. theApp.OpenDocumentFile( strADsPath.GetBuffer( MAX_PATH ) );
  320. return TRUE;
  321. }
  322. return CListView::OnChildNotify(message, wParam, lParam, pLResult);
  323. }