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.

171 lines
4.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  5. //
  6. // File: brmodel.hxx
  7. //
  8. // Contents:
  9. //
  10. // History: 15 Aug 1996 DLee Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #pragma once
  14. const unsigned MAX_FORCE = 16;
  15. const unsigned MAX_INIT_DOCS = 4;
  16. class CQueryResults;
  17. //
  18. // The multifile browser is structured as follows:
  19. //
  20. // Model
  21. // |
  22. // +-> array of Documents
  23. // |
  24. // +-> array of Hits
  25. // |
  26. // +-> array of Positions
  27. //
  28. // Therefore, next/prev file correspond to movement within
  29. // the array of Documents in the Model.
  30. //
  31. // Next/prev hit correspond to movement within the current
  32. // Document's array of Hits.
  33. //
  34. // The viewer extracts its Position data from the array
  35. // of Positions in the current Hit in the current Docuement.
  36. //
  37. class Model
  38. {
  39. public:
  40. Model ();
  41. ~Model ();
  42. SCODE CollectFiles ( CQueryResult *pResult );
  43. void Force ( char* pStr );
  44. //
  45. // Initialization methods
  46. //
  47. SCODE InitDocument();
  48. //
  49. // Next/Prev document selection routines
  50. //
  51. SCODE NextDoc();
  52. BOOL PrevDoc();
  53. BOOL isLastDoc() {
  54. return(_cDoc == 0 || _iDoc == _cDoc - 1);
  55. }
  56. BOOL isFirstDoc() {
  57. return(_iDoc == 0);
  58. }
  59. BOOL isLastHit() {
  60. return(_cDoc == 0 || _hitIter.isLastHit());
  61. }
  62. BOOL isFirstHit() {
  63. return(_cDoc == 0 || _hitIter.isFirstHit());
  64. }
  65. BOOL isSavedCurrent() { return _hitIter.isSavedCurrent(); }
  66. int HitCount() { return _hitIter.HitCount(); }
  67. int CurrentHit() { return _hitIter.CurrentHit(); }
  68. int ParaCount() { return _hitIter.ParaCount(); }
  69. //
  70. // The rest of the routines are relative to the current document
  71. //
  72. inline void HiliteAll( BOOL f );
  73. void RestoreHilite() { _hitIter.RestoreHit(); }
  74. BOOL IsHiliteAll() { return _fHiliteAll; }
  75. const WCHAR* Filename() { return _aDoc[_iDoc]->Filename(); }
  76. int Paras() const { return _aDoc[_iDoc]->Paras(); }
  77. int MaxParaLen() const{ return _aDoc[_iDoc]->MaxParaLen(); }
  78. BOOL GetLine (int nPara, int off, int& cwc, WCHAR* buf) const
  79. { return _aDoc[_iDoc]->GetLine(nPara, off, cwc, buf); }
  80. void GetWord(int nPara, int offSrc, int cwcSrc, WCHAR* buf)
  81. { _aDoc[_iDoc]->GetWord(nPara, offSrc, cwcSrc, buf ); }
  82. WCHAR * GetBuffer()
  83. { return _aDoc[_iDoc]->Buffer(); }
  84. WCHAR * GetBufferEnd()
  85. { return _aDoc[_iDoc]->BufEnd(); }
  86. int GetPositionCount() const { return _hitIter.GetPositionCount(); }
  87. Position GetPosition ( int i ) const { return _hitIter.GetPosition(i); }
  88. //
  89. // Search methods
  90. //
  91. WCHAR * Buffer() { return _aDoc[_iDoc]->Buffer(); }
  92. const WCHAR * BufEnd() const { return _aDoc[_iDoc]->BufEnd(); }
  93. ChunkOffset OffsetToChunkOffset ( ULONG offset ) const
  94. {
  95. return _aDoc[_iDoc]->OffsetToChunkOffset (offset);
  96. }
  97. ULONG FirstHit() { return _hitIter.FirstHit(); }
  98. ULONG PrevHit() { return _hitIter.PrevHit(); }
  99. ULONG NextHit() { return _hitIter.NextHit(); }
  100. ParaLine const * GetParaLine () const { return _aDoc[_iDoc]->GetParaLine(); }
  101. private:
  102. BOOL isForced(unsigned idx);
  103. unsigned _cForce;
  104. unsigned _aForce[MAX_FORCE];
  105. Document ** _aDoc;
  106. unsigned _cDoc;
  107. unsigned _iDoc;
  108. HitIter _hitIter;
  109. CQueryResult * _pResult;
  110. BOOL _fHiliteAll;
  111. ISearchQueryHits* _pSearch;
  112. };
  113. inline SCODE Model::NextDoc()
  114. {
  115. if (_cDoc != 0 && _iDoc + 1 < _cDoc )
  116. {
  117. _iDoc++;
  118. if (_iDoc >= MAX_INIT_DOCS)
  119. _aDoc[_iDoc - MAX_INIT_DOCS]->Free();
  120. return InitDocument();
  121. }
  122. return E_FAIL;
  123. }
  124. inline BOOL Model::PrevDoc()
  125. {
  126. if (_cDoc != 0 && _iDoc > 0 )
  127. {
  128. _iDoc--;
  129. return InitDocument();
  130. }
  131. return(FALSE);
  132. }
  133. inline void Model::HiliteAll( BOOL f )
  134. {
  135. if ( !IsHiliteAll() )
  136. _hitIter.SaveHit();
  137. _fHiliteAll = f;
  138. }