chmfile.h

00001 /*
00002 
00003   Copyright (C) 2003  Razvan Cojocaru <razvanco@gmx.net>
00004  
00005   This program is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009   
00010   This program is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU General Public License for more details.
00014   
00015   You should have received a copy of the GNU General Public License
00016   along with this program; if not, write to the Free Software
00017   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 #include <string>
00033 
00034 
00035 // Forward declarations.
00036 class wxTreeCtrl;
00037 class CHMListCtrl;
00038 class UCharPtr;
00039 class wxCSConv;
00040 
00041 
00043 WX_DECLARE_STRING_HASH_MAP(wxString, CHMSearchResults);
00045 WX_DECLARE_HASH_MAP( int, wxString, wxIntegerHash, wxIntegerEqual, CHMIDMap );
00046 
00047 
00049 #define MAX_SEARCH_RESULTS 512
00050 
00051 
00052 
00054 class CHMFile {
00055 public:
00057         CHMFile();
00058         
00064         CHMFile(const wxString& archiveName);
00065 
00067         ~CHMFile();
00068 
00069         
00076         wxString HomePage() const { return _home; }
00077 
00085         wxString TopicsFile() const { return _topicsFile; }
00086 
00093         wxString ArchiveName() const { return _filename; }
00094 
00102         wxString IndexFile() const { return _indexFile; }
00103 
00109         wxString Title() const { return _title; }
00110 
00117         bool IsOk() const { return _chmFile != NULL; }
00118 
00120         bool HasChanged();
00121 
00127         wxFontEncoding DesiredEncoding() const { return _enc; }
00128 
00133         wxString DefaultFont() const { return _font; }
00134 
00140         bool LoadCHM(const wxString& archiveName);
00141 
00143         void CloseCHM();
00144 
00154         bool GetTopicsTree(wxTreeCtrl *toBuild);
00155 
00156 
00166         bool GetIndex(CHMListCtrl* toBuild);
00167 
00168 
00174         bool LoadContextIDs();
00175 
00182         bool IsValidCID( const int contextID );
00183 
00190         wxString GetPageByCID( const int contextID );
00191 
00196         bool AreContextIDsLoaded() const { return !_cidMap.empty(); } 
00197 
00208         bool IndexSearch(const wxString& text, bool wholeWords, 
00209                          bool titlesOnly, CHMSearchResults *results);
00210 
00221         bool ResolveObject(const wxString& fileName, chmUnitInfo *ui);
00222 
00232         size_t RetrieveObject(chmUnitInfo *ui, unsigned char *buffer,
00233                               off_t fileOffset, size_t bufferSize);
00234 
00235 private:
00237         wxFontEncoding GetFontEncFromCharSet(int cs);
00238 
00240         wxFontEncoding GetFontEncFromLCID(u_int32_t lcid);
00241 
00243         bool GetArchiveInfo();
00244 
00246         u_int32_t GetLeafNodeOffset(const wxString& text,
00247                                     u_int32_t initalOffset,
00248                                     u_int32_t buffSize,
00249                                     u_int16_t treeDepth,
00250                                     chmUnitInfo *ui);
00251 
00253         bool ProcessWLC(u_int64_t wlc_count, u_int64_t wlc_size,
00254                         u_int32_t wlc_offset, unsigned char ds,
00255                         unsigned char dr, unsigned char cs,
00256                         unsigned char cr, unsigned char ls,
00257                         unsigned char lr, chmUnitInfo *uifmain,
00258                         chmUnitInfo* uitbl, chmUnitInfo *uistrings,
00259                         chmUnitInfo* topics, chmUnitInfo *urlstr,
00260                         CHMSearchResults *results);
00261 
00263         bool InfoFromWindows();
00264 
00266         bool InfoFromSystem();
00267 
00269         bool BinaryTOC(wxTreeCtrl *toBuild, const wxCSConv& cv);
00270 
00272         void RecurseLoadBTOC(UCharPtr& topidx, UCharPtr& topics,
00273                              UCharPtr& strings, UCharPtr& urltbl,
00274                              UCharPtr& urlstr, u_int32_t offset, 
00275                              const wxCSConv& cv,
00276                              wxTreeCtrl *toBuild, int level);
00277 
00279         bool GetItem(UCharPtr& topics, UCharPtr& strings, UCharPtr& urltbl,
00280                      UCharPtr& urlstr, u_int32_t index, wxTreeCtrl *toBuild,
00281                      CHMListCtrl* toBuild, const wxString& idxName,
00282                      const wxCSConv& cv, int level, bool local);
00283 
00285         bool BinaryIndex(CHMListCtrl* toBuild, const wxCSConv& cv);
00286 
00288         bool ConvertFromUnicode(std::string& value, unsigned char* buffer,
00289                                 size_t bufferLength);
00290 
00291 private:
00292         chmFile* _chmFile;
00293         wxString _filename;
00294         wxString _home;
00295         wxString _topicsFile;
00296         wxString _indexFile;
00297         wxString _title;
00298         wxString _font;
00299         wxFontEncoding _enc;
00300         CHMIDMap _cidMap;
00301 
00302 private:
00304         CHMFile(const CHMFile&);
00305 
00307         CHMFile& operator=(const CHMFile&);
00308 };
00309 
00310 
00311 #endif // __CHMFILE_H_
00312 
00313 
00314 /*
00315   Local Variables:
00316   mode: c++
00317   c-basic-offset: 8
00318   tab-width: 8
00319   c-indent-comments-syntactically-p: t
00320   c-tab-always-indent: t
00321   indent-tabs-mode: t
00322   End:
00323 */
00324 
00325 // vim:shiftwidth=8:autoindent:tabstop=8:noexpandtab:softtabstop=8
00326 

Generated on Tue Apr 24 20:17:36 2007 for xCHM by  doxygen 1.4.7