00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __CHMFILE_H_
00024 #define __CHMFILE_H_
00025
00026 #include <config.h>
00027 #include <stdint.h>
00028 #include <chm_lib.h>
00029 #include <wx/filefn.h>
00030 #include <wx/string.h>
00031 #include <wx/hashmap.h>
00032 #include <wx/font.h>
00033 #include <wx/string.h>
00034 #include <string>
00035
00036
00037
00038 class wxTreeCtrl;
00039 class CHMListCtrl;
00040 class UCharPtr;
00041 class wxCSConv;
00042
00043
00045 WX_DECLARE_STRING_HASH_MAP(wxString, CHMSearchResults);
00047 WX_DECLARE_HASH_MAP( int, wxString, wxIntegerHash, wxIntegerEqual, CHMIDMap );
00048
00049
00051 #define MAX_SEARCH_RESULTS 512
00052
00053
00054
00056 class CHMFile {
00057 public:
00059 CHMFile();
00060
00066 CHMFile(const wxString& archiveName);
00067
00069 ~CHMFile();
00070
00071
00078 wxString HomePage() const { return _home; }
00079
00087 wxString TopicsFile() const { return _topicsFile; }
00088
00095 wxString ArchiveName() const { return _filename; }
00096
00104 wxString IndexFile() const { return _indexFile; }
00105
00111 wxString Title() const { return _title; }
00112
00119 bool IsOk() const { return _chmFile != NULL; }
00120
00122 bool HasChanged();
00123
00129 wxFontEncoding DesiredEncoding() const { return _enc; }
00130
00135 wxString DefaultFont() const { return _font; }
00136
00142 bool LoadCHM(const wxString& archiveName);
00143
00145 void CloseCHM();
00146
00156 bool GetTopicsTree(wxTreeCtrl *toBuild);
00157
00158
00168 bool GetIndex(CHMListCtrl* toBuild);
00169
00170
00176 bool LoadContextIDs();
00177
00184 bool IsValidCID( const int contextID );
00185
00192 wxString GetPageByCID( const int contextID );
00193
00198 bool AreContextIDsLoaded() const { return !_cidMap.empty(); }
00199
00210 bool IndexSearch(const wxString& text, bool wholeWords,
00211 bool titlesOnly, CHMSearchResults *results);
00212
00223 bool ResolveObject(const wxString& fileName, chmUnitInfo *ui);
00224
00234 size_t RetrieveObject(chmUnitInfo *ui, unsigned char *buffer,
00235 off_t fileOffset, size_t bufferSize);
00236
00237 private:
00239 wxFontEncoding GetFontEncFromCharSet(int cs);
00240
00242 wxFontEncoding GetFontEncFromLCID(uint32_t lcid);
00243
00245 bool GetArchiveInfo();
00246
00248 uint32_t GetLeafNodeOffset(const wxString& text,
00249 uint32_t initalOffset,
00250 uint32_t buffSize,
00251 uint16_t treeDepth,
00252 chmUnitInfo *ui);
00253
00255 bool ProcessWLC(uint64_t wlc_count, uint64_t wlc_size,
00256 uint32_t wlc_offset, unsigned char ds,
00257 unsigned char dr, unsigned char cs,
00258 unsigned char cr, unsigned char ls,
00259 unsigned char lr, chmUnitInfo *uifmain,
00260 chmUnitInfo* uitbl, chmUnitInfo *uistrings,
00261 chmUnitInfo* topics, chmUnitInfo *urlstr,
00262 CHMSearchResults *results);
00263
00265 bool InfoFromWindows();
00266
00268 bool InfoFromSystem();
00269
00271 bool BinaryTOC(wxTreeCtrl *toBuild, const wxCSConv& cv);
00272
00274 void RecurseLoadBTOC(UCharPtr& topidx, UCharPtr& topics,
00275 UCharPtr& strings, UCharPtr& urltbl,
00276 UCharPtr& urlstr, uint32_t offset,
00277 const wxCSConv& cv,
00278 wxTreeCtrl *toBuild, int level);
00279
00281 bool GetItem(UCharPtr& topics, UCharPtr& strings, UCharPtr& urltbl,
00282 UCharPtr& urlstr, uint32_t index, wxTreeCtrl* tree,
00283 CHMListCtrl* list, const wxString& idxName,
00284 int level, bool local);
00285
00287 bool BinaryIndex(CHMListCtrl* toBuild, const wxCSConv& cv);
00288
00290 bool ConvertFromUnicode(std::string& value, unsigned char* buffer,
00291 size_t bufferLength);
00292
00293 private:
00294 chmFile* _chmFile;
00295 wxString _filename;
00296 wxString _home;
00297 wxString _topicsFile;
00298 wxString _indexFile;
00299 wxString _title;
00300 wxString _font;
00301 wxFontEncoding _enc;
00302 CHMIDMap _cidMap;
00303
00304 private:
00306 CHMFile(const CHMFile&);
00307
00309 CHMFile& operator=(const CHMFile&);
00310 };
00311
00312
00313 #endif // __CHMFILE_H_
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328