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 #if wxUSE_UNICODE
00050
00051 # define CURRENT_CHAR_STRING(x) \
00052 wxString(reinterpret_cast<const char *>(x), wxConvISO8859_1)
00053
00054 # define CURRENT_CHAR_STRING_CV(x, cv) \
00055 wxString(reinterpret_cast<const char *>(x), cv)
00056
00057 #else
00058
00059 # define CURRENT_CHAR_STRING(x) \
00060 wxString(reinterpret_cast<const char *>(x))
00061
00062 # define CURRENT_CHAR_STRING_CV(x, cv) \
00063 wxString(reinterpret_cast<const char *>(x))
00064
00065
00066 #endif
00067
00068
00070 class CHMFile {
00071 public:
00073 CHMFile();
00074
00080 CHMFile(const wxString& archiveName);
00081
00083 ~CHMFile();
00084
00085
00092 wxString HomePage() const { return _home; }
00093
00101 wxString TopicsFile() const { return _topicsFile; }
00102
00109 wxString ArchiveName() const { return _filename; }
00110
00118 wxString IndexFile() const { return _indexFile; }
00119
00125 wxString Title() const { return _title; }
00126
00133 bool IsOk() const { return _chmFile != NULL; }
00134
00136 bool HasChanged();
00137
00143 wxFontEncoding DesiredEncoding() const { return _enc; }
00144
00149 wxString DefaultFont() const { return _font; }
00150
00156 bool LoadCHM(const wxString& archiveName);
00157
00159 void CloseCHM();
00160
00170 bool GetTopicsTree(wxTreeCtrl *toBuild);
00171
00181 bool GetIndex(CHMListCtrl* toBuild);
00182
00183
00189 bool LoadContextIDs();
00190
00197 bool IsValidCID( const int contextID );
00198
00205 wxString GetPageByCID( const int contextID );
00206
00211 bool AreContextIDsLoaded() const { return !_cidMap.empty(); }
00212
00223 bool IndexSearch(const wxString& text, bool wholeWords,
00224 bool titlesOnly, CHMSearchResults *results);
00225
00236 bool ResolveObject(const wxString& fileName, chmUnitInfo *ui);
00237
00247 size_t RetrieveObject(chmUnitInfo *ui, unsigned char *buffer,
00248 off_t fileOffset, size_t bufferSize);
00249
00250 private:
00252 wxFontEncoding GetFontEncFromCharSet(int cs);
00253
00255 wxFontEncoding GetFontEncFromLCID(u_int32_t lcid);
00256
00258 bool GetArchiveInfo();
00259
00261 u_int32_t GetLeafNodeOffset(const wxString& text,
00262 u_int32_t initalOffset,
00263 u_int32_t buffSize,
00264 u_int16_t treeDepth,
00265 chmUnitInfo *ui);
00266
00268 bool ProcessWLC(u_int64_t wlc_count, u_int64_t wlc_size,
00269 u_int32_t wlc_offset, unsigned char ds,
00270 unsigned char dr, unsigned char cs,
00271 unsigned char cr, unsigned char ls,
00272 unsigned char lr, chmUnitInfo *uifmain,
00273 chmUnitInfo* uitbl, chmUnitInfo *uistrings,
00274 chmUnitInfo* topics, chmUnitInfo *urlstr,
00275 CHMSearchResults *results);
00276
00278 void GetFileAsString(wxString& str, chmUnitInfo *ui);
00279
00281 bool InfoFromWindows();
00282
00284 bool InfoFromSystem();
00285
00286 private:
00287 chmFile* _chmFile;
00288 wxString _filename;
00289 wxString _home;
00290 wxString _topicsFile;
00291 wxString _indexFile;
00292 wxString _title;
00293 wxString _font;
00294 wxFontEncoding _enc;
00295 CHMIDMap _cidMap;
00296
00297 private:
00299 CHMFile(const CHMFile&);
00300
00302 CHMFile& operator=(const CHMFile&);
00303 };
00304
00305
00306 #endif // __CHMFILE_H_