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.

188 lines
5.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: model.cxx
  7. //
  8. // Contents: The Model part of the browser
  9. //
  10. //--------------------------------------------------------------------------
  11. #include <pch.cxx>
  12. #pragma hdrstop
  13. #define TheSearch _pSearch
  14. //+-------------------------------------------------------------------------
  15. //
  16. // Member: Model::Model, public
  17. //
  18. // Synopsis:
  19. //
  20. //--------------------------------------------------------------------------
  21. Model::Model ()
  22. : _pResult(0),
  23. _aDoc(0),
  24. _cForce(0),
  25. _fHiliteAll( FALSE ),
  26. _iDoc(0),
  27. _pSearch(0)
  28. {}
  29. //+-------------------------------------------------------------------------
  30. //
  31. // Member: Model::~Model, public
  32. //
  33. // Synopsis:
  34. //
  35. //--------------------------------------------------------------------------
  36. Model::~Model()
  37. {
  38. for ( unsigned i = 0; i < _cDoc; i++ )
  39. delete _aDoc[i];
  40. delete []_aDoc;
  41. delete _pResult;
  42. if (TheSearch)
  43. TheSearch->Release();
  44. }
  45. //+-------------------------------------------------------------------------
  46. //
  47. // Member: Model::Force, public
  48. //
  49. // Synopsis: Display a subset of files
  50. //
  51. //--------------------------------------------------------------------------
  52. void Model::Force ( char* pStr )
  53. {
  54. while (_cForce < MAX_FORCE && isdigit(*pStr) )
  55. {
  56. _aForce[_cForce] = (unsigned)atoi ( pStr );
  57. _cForce++;
  58. while (*pStr && isdigit(*pStr) )
  59. pStr++;
  60. while (*pStr && isspace(*pStr))
  61. pStr++;
  62. }
  63. }
  64. typedef HRESULT (__stdcall * PFnMakeISearch)( ISearchQueryHits ** ppSearch,
  65. DBCOMMANDTREE const * pRst,
  66. WCHAR const * pwcPath );
  67. PFnMakeISearch g_pMakeISearch = 0;
  68. SCODE MyMakeISearch( ISearchQueryHits **ppSearch,
  69. DBCOMMANDTREE const * pRst,
  70. WCHAR const * pwcPath )
  71. {
  72. if ( 0 == g_pMakeISearch )
  73. {
  74. #ifdef _WIN64
  75. char const * pcMakeISearch = "?MakeISearch@@YAJPEAPEAUISearchQueryHits@@PEAVCDbRestriction@@PEBG@Z";
  76. #else
  77. char const * pcMakeISearch = "?MakeISearch@@YGJPAPAUISearchQueryHits@@PAVCDbRestriction@@PBG@Z";
  78. #endif
  79. g_pMakeISearch = (PFnMakeISearch) GetProcAddress( GetModuleHandle( L"query.dll" ), pcMakeISearch );
  80. if ( 0 == g_pMakeISearch )
  81. return HRESULT_FROM_WIN32( GetLastError() );
  82. }
  83. return g_pMakeISearch( ppSearch,
  84. pRst,
  85. pwcPath );
  86. } //MyMakeISearch
  87. //+-------------------------------------------------------------------------
  88. //
  89. // Member: Model::CollectFiles, public
  90. //
  91. // Synopsis: Parse command line, get restriction and list of docs,
  92. // create array of docs, initialize the first one.
  93. // In response to window creation
  94. //
  95. //--------------------------------------------------------------------------
  96. SCODE Model::CollectFiles ( CQueryResult *pResult )
  97. {
  98. _pResult = pResult;
  99. _cDoc = 1;
  100. _aDoc = new Document * [ _cDoc ];
  101. unsigned countSoFar = 0;
  102. for ( unsigned iDoc = 0; iDoc< _cDoc; iDoc++)
  103. {
  104. if (_cForce == 0 || isForced(iDoc))
  105. {
  106. Document * newDoc = new Document( pResult->_pwcPath,
  107. 1000,
  108. pResult->_fDeleteWhenDone );
  109. //
  110. // Insert into sorted list of documents
  111. //
  112. unsigned i=0;
  113. while ( i < countSoFar && newDoc->Rank() <= _aDoc[i]->Rank() )
  114. i++;
  115. // _aDoc[i]->Rank() > newDoc->Rank() || i == countSoFar
  116. for ( unsigned j = countSoFar; j > i; j-- )
  117. _aDoc[j] = _aDoc[j-1];
  118. _aDoc[i] = newDoc;
  119. countSoFar++;
  120. }
  121. }
  122. _iDoc = 0;
  123. _cDoc = countSoFar;
  124. SCODE sc = MyMakeISearch( &TheSearch, _pResult->_pTree, pResult->_pwcPath );
  125. if ( !FAILED( sc ) && 0 != TheSearch )
  126. return InitDocument();
  127. return sc;
  128. }
  129. //+-------------------------------------------------------------------------
  130. //
  131. // Member: Model::isForced, public
  132. //
  133. // Synopsis: Check if idx is on a forced list
  134. //
  135. //--------------------------------------------------------------------------
  136. BOOL Model::isForced(unsigned idx)
  137. {
  138. for (unsigned i = 0; i < _cForce; i++)
  139. if (_aForce[i] == idx)
  140. return(TRUE);
  141. return(FALSE);
  142. }
  143. //+-------------------------------------------------------------------------
  144. //
  145. // Member: Model::InitDocument, public
  146. //
  147. // Synopsis: Initialize current document
  148. //
  149. //--------------------------------------------------------------------------
  150. SCODE Model::InitDocument()
  151. {
  152. if ( 0 == _cDoc )
  153. return E_FAIL;
  154. SCODE sc = S_OK;
  155. if ( !_aDoc[_iDoc]->IsInit() )
  156. sc = _aDoc[_iDoc]->Init( TheSearch );
  157. if ( SUCCEEDED( sc ) )
  158. _hitIter.Init ( _aDoc[_iDoc] );
  159. return sc;
  160. }