00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __CHMFILE_H_
00023 #define __CHMFILE_H_
00024
00025 #include <config.h>
00026 #include <chm_lib.h>
00027 #include <wx/filefn.h>
00028 #include <wx/string.h>
00029 #include <wx/hashmap.h>
00030 #include <wx/font.h>
00031 #include <wx/string.h>
00032
00033
00034
00035 class wxTreeCtrl;
00036 class CHMListCtrl;
00037
00038
00040 WX_DECLARE_STRING_HASH_MAP(wxString, CHMSearchResults);
00042 WX_DECLARE_HASH_MAP( int, wxString, wxIntegerHash, wxIntegerEqual, CHMIDMap );
00043
00044
00046 #define MAX_SEARCH_RESULTS 512
00047
00048
00049 #ifdef wxUSE_UNICODE
00050
00051 # define CURRENT_CHAR_STRING(x) \
00052 wxString(reinterpret_cast<const char *>(x), wxConvISO8859_1)
00053
00054 #else
00055
00056 # define CURRENT_CHAR_STRING(x) \
00057 wxString(reinterpret_cast<const char *>(x))
00058
00059 #endif
00060
00061
00063 class CHMFile {
00064 public:
00066 CHMFile();
00067
00073 CHMFile(const wxString& archiveName);
00074
00076 ~CHMFile();
00077
00078
00085 wxString HomePage() const { return _home; }
00086
00094 wxString TopicsFile() const { return _topicsFile; }
00095
00102 wxString ArchiveName() const { return _filename; }
00103
00111 wxString IndexFile() const { return _indexFile; }
00112
00118 wxString Title() const { return _title; }
00119
00125 wxString DefaultFont() const { return _font; }
00126
00133 bool IsOk() const { return _chmFile != NULL; }
00134
00136 bool HasChanged();
00137
00143 wxFontEncoding DesiredEncoding() const { return _enc; }
00144
00150 bool LoadCHM(const wxString& archiveName);
00151
00153 void CloseCHM();
00154
00164 bool GetTopicsTree(wxTreeCtrl *toBuild);
00165
00175 bool GetIndex(CHMListCtrl* toBuild);
00176
00177
00183 bool LoadContextIDs();
00184
00191 bool IsValidCID( const int contextID );
00192
00199 wxString GetPageByCID( const int contextID );
00200
00205 bool AreContextIDsLoaded() const { return !_cidMap.empty(); }
00206
00217 bool IndexSearch(const wxString& text, bool wholeWords,
00218 bool titlesOnly, CHMSearchResults *results);
00219
00230 bool ResolveObject(const wxString& fileName, chmUnitInfo *ui);
00231
00241 size_t RetrieveObject(chmUnitInfo *ui, unsigned char *buffer,
00242 off_t fileOffset, size_t bufferSize);
00243
00244 private:
00246 wxFontEncoding GetFontEncFromCharSet(int cs);
00247
00249 bool GetArchiveInfo();
00250
00252 u_int32_t GetLeafNodeOffset(const wxString& text,
00253 u_int32_t initalOffset,
00254 u_int32_t buffSize,
00255 u_int16_t treeDepth,
00256 chmUnitInfo *ui);
00257
00259 bool ProcessWLC(u_int64_t wlc_count, u_int64_t wlc_size,
00260 u_int32_t wlc_offset, unsigned char ds,
00261 unsigned char dr, unsigned char cs,
00262 unsigned char cr, unsigned char ls,
00263 unsigned char lr, chmUnitInfo *uifmain,
00264 chmUnitInfo* uitbl, chmUnitInfo *uistrings,
00265 chmUnitInfo* topics, chmUnitInfo *urlstr,
00266 CHMSearchResults *results);
00267
00269 void GetFileAsString(wxString& str, chmUnitInfo *ui);
00270
00272 bool InfoFromWindows();
00273
00275 bool InfoFromSystem();
00276
00277 private:
00278 chmFile* _chmFile;
00279 wxString _filename;
00280 wxString _home;
00281 wxString _topicsFile;
00282 wxString _indexFile;
00283 wxString _title;
00284 wxString _font;
00285 wxFontEncoding _enc;
00286 CHMIDMap _cidMap;
00287
00288 private:
00290 CHMFile(const CHMFile&);
00291
00293 CHMFile& operator=(const CHMFile&);
00294 };
00295
00296
00297 #endif // __CHMFILE_H_