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.

389 lines
14 KiB

  1. // WWheel.h - HTML Help Word Wheel support
  2. //
  3. // Covers both KeywordLinks and AssociativeLinks
  4. //
  5. //
  6. #ifndef __WWHEEL_H__
  7. #define __WWHEEL_H__
  8. #include <windows.h>
  9. // InfoTech headers
  10. #include "itww.h"
  11. #include "itdb.h"
  12. #include "itrs.h"
  13. #include "itpropl.h"
  14. #include "itcc.h"
  15. #include "fs.h"
  16. // make Don's stuff work
  17. #include <stdio.h>
  18. #ifdef HHCTRL
  19. #include "parserhh.h"
  20. #else
  21. #include "parser.h"
  22. #endif
  23. #include "collect.h"
  24. #include "hhtypes.h"
  25. #include "toc.h"
  26. #include "system.h"
  27. // Centaur defines
  28. #ifndef ITWW_CBKEY_MAX //defined in itww.h
  29. #define ITWW_CBKEY_MAX 1024
  30. #endif
  31. #ifndef ITWW_CBREC_MAX // itww.h does not define this
  32. #define ITWW_CBREC_MAX 8
  33. #endif
  34. // global defines
  35. #define HHWW_MAX_KEYWORD_OBJECT_SIZE (ITWW_CBKEY_MAX-ITWW_CBREC_MAX)
  36. #define HHWW_MAX_KEYWORD_LENGTH (((HHWW_MAX_KEYWORD_OBJECT_SIZE-sizeof(HHKEYINFO)-sizeof(DWORD))/sizeof(WCHAR))-sizeof(WCHAR))
  37. #define HHWW_FONT 0x1 // bit 0
  38. #define HHWW_SEEALSO 0x2 // bit 1
  39. #define HHWW_UID_OVERFLOW 0x4 // bit 2
  40. #define HHWW_PLACEHOLDER 0x8 // bit 3
  41. #define HHWW_KEYWORDLINKS 0x1 // bit 0
  42. #define HHWW_ASSOCIATIVELINKS 0x2 // bit 2
  43. #define HHWW_ERROR ((DWORD)-1)
  44. #define HHWW_MAX_LEVELS 255
  45. #define HHWW_LEVEL_DELIMITER_CHAR 0x01
  46. #define HHWW_LEVEL_DELIMITER_STRING ",\x01"
  47. #define HHWW_LEVEL_DELIMITER_CHAR_OUTPUT ' '
  48. #define HHWW_LEVEL_DELIMITER_STRING_OUTPUT ", "
  49. // the format of our sort key object is as follows:
  50. //
  51. // + Null terminated MBCS string
  52. // + HHKEYINFO structure
  53. // + trailing UIDs (DWORD) or the SeeAlso string
  54. //
  55. // TODO: If we overflow the buffer then the UIDs are stored in the
  56. // occurence data and the SeeAlso string stored as a property
  57. // (STDPROP_USERPROP_BASE+1). For now we truncate overflow data.
  58. // Our sort key information struct
  59. #pragma pack(push, 2)
  60. typedef struct _hhkeyinfo
  61. {
  62. WORD wFlags; // indicates what data is stored with this keyword
  63. WORD wLevel;
  64. DWORD dwLevelOffset;
  65. DWORD dwFont;
  66. DWORD dwCount; // number of UIDs that follow this structure in the sortkey
  67. } HHKEYINFO;
  68. #pragma pack(pop)
  69. // forward references
  70. class CExTitle;
  71. class CExCollection;
  72. class CWordWheel;
  73. class CTitleDatabase;
  74. /////////////////////////////////////////////////////////////////////////////
  75. // class CTitleMapEntry
  76. class CTitleMapEntry SI_COUNT(CTitleMapEntry) {
  77. public:
  78. inline CTitleMapEntry() { m_pTitle = NULL; m_pWordWheel = NULL; m_pDatabase = NULL; m_pKeywordLinks = NULL; m_pAssociativeLinks = NULL; m_pszShortName = NULL; m_dwIndex = HHWW_ERROR; m_dwId = 0; }
  79. inline ~CTitleMapEntry() { if( m_pszShortName ) delete [] (CHAR*) m_pszShortName; }
  80. inline DWORD GetId() { return m_dwId; }
  81. inline DWORD SetId( DWORD dwId ) { m_dwId = dwId; return m_dwId; }
  82. inline CExTitle* GetTitle() { return m_pTitle; }
  83. inline CExTitle* SetTitle( CExTitle* pTitle ) { m_pTitle = pTitle; return m_pTitle; }
  84. inline CTitleDatabase* GetDatabase() { return m_pDatabase; }
  85. inline CTitleDatabase* SetDatabase( CTitleDatabase* pDatabase ) { m_pDatabase = pDatabase; return m_pDatabase; }
  86. inline CWordWheel* GetWordWheel() { return m_pWordWheel; }
  87. inline CWordWheel* SetWordWheel( CWordWheel* pWordWheel ) { m_pWordWheel = pWordWheel; return m_pWordWheel; }
  88. inline CWordWheel* GetKeywordLinks() { return m_pKeywordLinks; }
  89. inline CWordWheel* SetKeywordLinks( CWordWheel* pKeywordLinks ) { m_pKeywordLinks = pKeywordLinks; return m_pKeywordLinks; }
  90. inline CWordWheel* GetAssociativeLinks() { return m_pAssociativeLinks; }
  91. inline CWordWheel* SetAssociativeLinks( CWordWheel* pAssociativeLinks ) { m_pAssociativeLinks = pAssociativeLinks; return m_pAssociativeLinks; }
  92. inline DWORD GetIndex() { return m_dwIndex; }
  93. inline DWORD SetIndex( DWORD dwIndex ) { m_dwIndex = dwIndex; return m_dwIndex; }
  94. inline const CHAR* SetShortName( const CHAR* pszShortName )
  95. { //HH BUG 2807 --- See CheckWordWheels for more info.
  96. if (pszShortName)
  97. {
  98. int iLen = (int)strlen( pszShortName );
  99. if( iLen ) {
  100. m_pszShortName = new char[iLen+1];
  101. strcpy( (CHAR*) m_pszShortName, pszShortName );
  102. }
  103. }
  104. return m_pszShortName;
  105. }
  106. inline const CHAR* GetShortName() { if( m_pTitle ) return m_pTitle->GetInfo2()->GetShortName(); return m_pszShortName; }
  107. inline FILETIME GetFileTime() { if( m_pTitle ) return m_pTitle->GetInfo2()->GetFileTime(); return m_FileTime; }
  108. inline FILETIME SetFileTime( FILETIME FileTime ) { m_FileTime = FileTime; return m_FileTime; }
  109. inline LCID GetLanguage() { if( m_pTitle ) return m_pTitle->GetInfo2()->GetLanguage(); return m_lcid; }
  110. inline LCID SetLanguage( LCID lcid ) { m_lcid = lcid; return m_lcid; }
  111. private:
  112. DWORD m_dwId;
  113. DWORD m_dwIndex;
  114. CExTitle* m_pTitle;
  115. CTitleDatabase* m_pDatabase;
  116. CWordWheel* m_pWordWheel;
  117. CWordWheel* m_pKeywordLinks;
  118. CWordWheel* m_pAssociativeLinks;
  119. const CHAR* m_pszShortName;
  120. FILETIME m_FileTime;
  121. LCID m_lcid;
  122. };
  123. /////////////////////////////////////////////////////////////////////////////
  124. // class CTitleMap
  125. class CTitleMap SI_COUNT(CTitleMap) {
  126. public:
  127. inline CTitleMap() { _CTitleMap(); m_bInit = TRUE; }
  128. inline CTitleMap( const CHAR* pszDatabase ) { _CTitleMap(); m_pszDatabase = pszDatabase; }
  129. inline ~CTitleMap() { Free(); }
  130. BOOL Initialize();
  131. BOOL Free();
  132. inline DWORD GetCount() { Init(); return m_dwCount; }
  133. inline DWORD SetCount( DWORD dwCount ) { Free(); m_dwCount = dwCount; if( m_dwCount ) m_pEntries = new CTitleMapEntry[dwCount]; else m_pEntries = NULL; return m_dwCount; }
  134. inline CExTitle* GetTitle( DWORD dwIndex ) { Init(); if( dwIndex < m_dwCount ) return ((CTitleMapEntry*)(m_pEntries+dwIndex))->GetTitle(); else return NULL; }
  135. inline CExTitle* SetTitle( DWORD dwIndex, CExTitle* pTitle ) { ((CTitleMapEntry*)(m_pEntries+dwIndex))->SetTitle(pTitle); return pTitle; }
  136. inline CTitleMapEntry* GetAt( DWORD dwIndex ) { Init(); if( (m_dwCount != HHWW_ERROR) && (dwIndex < m_dwCount) ) return m_pEntries+dwIndex; else return NULL; }
  137. inline const CHAR* GetDatabase() { return m_pszDatabase; }
  138. inline void Sort( int (FASTCALL *compare)(const void*, const void*)) { Init(); QSort( m_pEntries, m_dwCount, sizeof(CTitleMapEntry), compare ); }
  139. private:
  140. BOOL m_bInit;
  141. const CHAR* m_pszDatabase;
  142. DWORD m_dwCount;
  143. CTitleMapEntry* m_pEntries;
  144. inline void _CTitleMap() { m_pszDatabase = NULL; m_bInit = FALSE; m_dwCount = HHWW_ERROR; m_pEntries = NULL; }
  145. inline BOOL Init() { if( !m_bInit ) Initialize(); return m_bInit; }
  146. };
  147. /////////////////////////////////////////////////////////////////////////////
  148. // class CTitleDatabase declaration (Shared Centaur object)
  149. class CTitleDatabase SI_COUNT(CTitleDatabase) {
  150. public:
  151. CTitleDatabase( CExCollection* pCollection );
  152. CTitleDatabase( CExTitle* pTitle );
  153. CTitleDatabase( const CHAR* pszDatabase );
  154. CTitleDatabase( const WCHAR* pwszDatabase );
  155. ~CTitleDatabase();
  156. BOOL Initialize(CHAR *pszFileName = NULL);
  157. BOOL Free();
  158. inline CExCollection* GetCollection() { return m_pCollection; }
  159. inline CExTitle* GetTitle() { return m_pTitle; }
  160. inline BOOL IsCollection() { Init(); return m_bCollection; }
  161. inline IITDatabase* GetDatabase() { Init(); return m_pDatabase; }
  162. inline CTitleMap* GetTitleMap() { Init(); return m_pTitleMap; }
  163. inline CWordWheel* GetKeywordLinks() { Init(); return m_pKeywordLinks; }
  164. inline CWordWheel* GetAssociativeLinks() { Init(); return m_pAssociativeLinks; }
  165. BOOL MergeWordWheels();
  166. BOOL CheckWordWheels();
  167. BOOL BuildWordWheels();
  168. inline const CHAR* GetPathname() { Init(); return m_pszDatabase; }
  169. #ifdef CHIINDEX
  170. inline BOOL SetAnimation( BOOL bState) { m_bAnimation = bState; return m_bAnimation;}
  171. #endif
  172. private:
  173. BOOL m_bInit;
  174. const WCHAR* m_pwszDatabase;
  175. const CHAR* m_pszDatabase;
  176. CHAR m_szFullPath[_MAX_PATH];
  177. CExCollection* m_pCollection;
  178. CExTitle* m_pTitle;
  179. IITDatabase* m_pDatabase;
  180. BOOL m_bCollection;
  181. CTitleMap* m_pTitleMap;
  182. CWordWheel* m_pKeywordLinks;
  183. CWordWheel* m_pAssociativeLinks;
  184. #ifdef CHIINDEX
  185. BOOL m_bAnimation; // TRUE to display animation during wordwheel build
  186. #endif
  187. void _CTitleDatabase();
  188. inline BOOL Init() { if( !m_bInit ) Initialize(); return m_bInit; }
  189. };
  190. /////////////////////////////////////////////////////////////////////////////
  191. // class CResultsEntry
  192. class CResultsEntry SI_COUNT(CResultsEntry) {
  193. public:
  194. inline CResultsEntry() {}
  195. inline ~CResultsEntry() {}
  196. inline DWORD GetURLId() { return m_dwURLId; }
  197. inline DWORD SetURLId( DWORD dwURLId ) { m_dwURLId = dwURLId; return m_dwURLId; }
  198. inline CExTitle* GetTitle() { return m_pTitle; }
  199. inline CExTitle* SetTitle( CExTitle* pTitle ) { m_pTitle = pTitle; return m_pTitle; }
  200. private:
  201. DWORD m_dwURLId;
  202. CExTitle* m_pTitle;
  203. };
  204. /////////////////////////////////////////////////////////////////////////////
  205. // class CResults declaration
  206. class CResults SI_COUNT(CResults) {
  207. public:
  208. inline CResults() { m_dwIndex = HHWW_ERROR; m_pEntries = NULL; }
  209. inline ~CResults() { Free(); }
  210. inline DWORD GetIndex() { return m_dwIndex; }
  211. inline DWORD SetIndex( DWORD dwIndex, DWORD dwSize )
  212. {
  213. m_dwIndex = dwIndex;
  214. Free();
  215. m_dwSize = dwSize;
  216. if( m_dwSize )
  217. m_pEntries = new CResultsEntry[dwSize];
  218. else
  219. m_pEntries = NULL;
  220. return m_dwIndex;
  221. }
  222. inline DWORD GetCount() { return m_dwSize; }
  223. inline CResultsEntry* GetAt( DWORD dwIndex ) { if(dwIndex < m_dwSize) return m_pEntries+dwIndex; else return NULL; }
  224. private:
  225. DWORD m_dwIndex;
  226. DWORD m_dwSize;
  227. CResultsEntry* m_pEntries;
  228. inline BOOL Free() { if( m_pEntries ) { delete [] m_pEntries; m_pEntries = NULL; } return TRUE; }
  229. };
  230. /////////////////////////////////////////////////////////////////////////////
  231. // class CWordWheelEntry declaration
  232. class CWordWheelEntry SI_COUNT(CWordWheelEntry) {
  233. public:
  234. inline CWordWheelEntry() { m_dwIndex = HHWW_ERROR; }
  235. inline ~CWordWheelEntry() {}
  236. DWORD m_dwIndex;
  237. WCHAR m_wszFullKeyword[HHWW_MAX_KEYWORD_LENGTH+1];
  238. WCHAR m_wszKeyword[HHWW_MAX_KEYWORD_LENGTH+1];
  239. DWORD m_dwLevel;
  240. DWORD m_dwLevelOffset;
  241. DWORD m_dwFlags;
  242. DWORD m_dwFont;
  243. WCHAR m_wszSeeAlso[HHWW_MAX_KEYWORD_LENGTH+1];
  244. };
  245. /////////////////////////////////////////////////////////////////////////////
  246. // class CWordWheel declaration
  247. class CWordWheel SI_COUNT(CWordWheel) {
  248. public:
  249. CWordWheel( CTitleDatabase* pDatabase, const WCHAR* pwszWordWheel, DWORD dwTitleId = 0 );
  250. CWordWheel( CTitleDatabase* pDatabase, const CHAR* pszWordWheel, DWORD dwTitleId = 0 );
  251. ~CWordWheel();
  252. DWORD AddRef();
  253. DWORD Release();
  254. BOOL Initialize();
  255. BOOL Free();
  256. DWORD GetCount();
  257. DWORD GetIndex( const WCHAR* pwszKeyword, BOOL bFragment = TRUE, DWORD* pdwIndexLast = NULL );
  258. DWORD GetIndex( const CHAR* pszKeyword, BOOL bFragment = TRUE, DWORD* pdwIndexLast = NULL );
  259. BOOL GetString( DWORD dwKeyword, WCHAR* pwszBuffer, DWORD cchBuffer = (DWORD)-1, BOOL bFull = FALSE, BOOL bCacheAll = FALSE );
  260. BOOL GetString( DWORD dwKeyword, CHAR* pszBuffer, DWORD cchBuffer = (DWORD)-1, BOOL bFull = FALSE, BOOL bCacheAll = FALSE );
  261. DWORD GetLevel( DWORD dwKeyword );
  262. DWORD GetLevelOffset( DWORD dwKeyword );
  263. BOOL GetSeeAlso( DWORD dwKeyword, WCHAR* pwszBuffer, DWORD cchBuffer = (DWORD)-1 );
  264. BOOL GetSeeAlso( DWORD dwKeyword, CHAR* pszBuffer, DWORD cchBuffer = (DWORD)-1 );
  265. BOOL IsPlaceHolder( DWORD dwKeyword );
  266. DWORD GetHitCount( DWORD dwKeyword );
  267. DWORD GetHit( DWORD dwKeyword, DWORD dwHit, CExTitle** ppTitle = NULL );
  268. inline BOOL GetSorterInstance( DWORD* pdwSorterInstance ) { if( Init() ) { m_pWordWheel->GetSorterInstance(pdwSorterInstance); return TRUE; } return FALSE; }
  269. inline BOOL GetLocaleInfo( DWORD* pdwCodePageId, LCID* plcid ) { if( Init() ) { m_pWordWheel->GetLocaleInfo(pdwCodePageId, plcid); return TRUE; } return FALSE; }
  270. inline CTitleDatabase* GetDatabase() { Init(); return m_pDatabase; }
  271. inline IITWordWheel* GetWordWheel() { Init(); return m_pWordWheel; }
  272. BOOL GetIndexData( DWORD dwKeyword, BOOL bCacheAll = FALSE );
  273. private:
  274. DWORD m_dwRefCount;
  275. const WCHAR* m_pwszWordWheel;
  276. const WCHAR* m_pwszWordWheelIn;
  277. const CHAR* m_pszWordWheelIn;
  278. BOOL m_bInit;
  279. IITWordWheel* m_pWordWheel;
  280. CTitleDatabase* m_pDatabase;
  281. CWordWheelEntry m_CachedEntry;
  282. CResults m_CachedResults;
  283. DWORD m_dwCount;
  284. DWORD m_dwTitleId;
  285. void _CWordWheel();
  286. inline BOOL Init() { if( !m_bInit ) Initialize(); return m_bInit; }
  287. BOOL GetIndexHitData( DWORD dwKeyword );
  288. inline BOOL GetIndexHitData( const VOID* pcvKeywordObject, DWORD cbSize, HHKEYINFO* pInfo, DWORD dwKeyword );
  289. };
  290. /////////////////////////////////////////////////////////////////////////////
  291. // class CWordWheelCompiler declaration
  292. class CWordWheelCompiler SI_COUNT(CWordWheelCompiler) {
  293. public:
  294. CWordWheelCompiler( const CHAR* pszDatabase, const WCHAR* pwszKeywordLinks, const WCHAR* pwszAssociativeLinks, LCID lcid = ((DWORD)-1));
  295. ~CWordWheelCompiler();
  296. IITBuildCollect* m_pBuildCollectKeywordLinks;
  297. IITBuildCollect* m_pBuildCollectAssociativeLinks;
  298. IITPropList* m_pPropList;
  299. HRESULT Initialize();
  300. HRESULT Free();
  301. HRESULT Build();
  302. #ifdef CHIINDEX
  303. inline BOOL SetAnimation( BOOL bState ) { m_bAnimation = bState; return m_bAnimation;}
  304. #endif
  305. private:
  306. BOOL m_bInit;
  307. const CHAR* m_pszDatabase;
  308. const WCHAR* m_pwszKeywordLinks;
  309. const WCHAR* m_pwszAssociativeLinks;
  310. LCID m_lcid;
  311. CHAR m_szDatabase[MAX_PATH];
  312. CFileSystem* m_pFileSystem;
  313. IITDatabase* m_pDatabase;
  314. IPersistStorage* m_pPersistStorageDatabase;
  315. IStorage* m_pStorageKeywordLinks;
  316. IStorage* m_pStorageAssociativeLinks;
  317. IPersistStorage* m_pPersistStorageKeywordLinks;
  318. IPersistStorage* m_pPersistStorageAssociativeLinks;
  319. #ifdef CHIINDEX
  320. BOOL m_bAnimation;
  321. #endif
  322. void _CWordWheelCompiler();
  323. inline BOOL Init() { if( !m_bInit ) Initialize(); return m_bInit; }
  324. };
  325. #endif // __WWHEEL_H__