xCHM  1.23
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CHMFile Class Reference

Mostly a C++ wrapper around the CHMLIB facilities. Concrete class. More...

#include <chmfile.h>

Public Member Functions

 CHMFile ()
 Default constructor.
 
 CHMFile (const wxString &archiveName)
 This constructor attempts to open the .chm file passed as it's argument. If it fails, IsOk() will return false. More...
 
 ~CHMFile ()
 Destructor. If a file has been succesfully opened, it closes it.
 
wxString HomePage () const
 Gets the name of the default page in the archive. More...
 
wxString TopicsFile () const
 Gets name of the .hhc file in the archive that could potentially be used to generate content information from. More...
 
wxString ArchiveName () const
 Gets the filename of the currently opened .chm file. More...
 
wxString IndexFile () const
 Gets name of the .hhk file in the archive that could potentially be used to generate content information from. More...
 
wxString Title () const
 Gets the name of the opened .chm. More...
 
bool IsOk () const
 Checks if the last attempt to load a .chm file was succesful. More...
 
bool HasChanged ()
 Checks if a 'ms-its' link has been clicked and the chm changed.
 
wxFontEncoding DesiredEncoding () const
 Determines the encoding that the CHM creator would like me to use. To be used in combination with DefaultFont(). More...
 
wxString DefaultFont () const
 Determines the font to use for special charsets. More...
 
bool LoadCHM (const wxString &archiveName)
 Attempts to load a .chm file from disk. More...
 
void CloseCHM ()
 Closes the currently opened .chm, or does nothing if none opened.
 
bool GetTopicsTree (wxTreeCtrl *toBuild)
 Attempts to fill a wxTreeCtrl by parsing the topics file. More...
 
bool GetIndex (CHMListCtrl *toBuild)
 Attempts to fill a CHMListCtrl by parsing the index file. More...
 
bool LoadContextIDs ()
 Attempts to build an index of context-ID/page pairs from the file. More...
 
bool IsValidCID (const int contextID)
 Checks whether or not the context ID is valid for the loaded file. More...
 
wxString GetPageByCID (const int contextID)
 Looks up the page referred to by the context-ID. More...
 
bool AreContextIDsLoaded () const
 Have the context-IDs been loaded into memory or not. More...
 
bool IndexSearch (const wxString &text, bool wholeWords, bool titlesOnly, CHMSearchResults *results)
 Fast search using the $FIftiMain file in the .chm. More...
 
bool ResolveObject (const wxString &fileName, chmUnitInfo *ui)
 Looks up fileName in the archive. More...
 
size_t RetrieveObject (chmUnitInfo *ui, unsigned char *buffer, off_t fileOffset, size_t bufferSize)
 Retrieves an uncompressed chunk of a file in the .chm. More...
 

Private Member Functions

wxFontEncoding GetFontEncFromCharSet (int cs)
 Helper. Translates from Win32 encodings to generic wxWidgets ones.
 
wxFontEncoding GetFontEncFromLCID (uint32_t lcid)
 Helper. Translates from MS-specific LCID.
 
bool GetArchiveInfo ()
 Helper. Initializes most of the private data members.
 
uint32_t GetLeafNodeOffset (const wxString &text, uint32_t initalOffset, uint32_t buffSize, uint16_t treeDepth, chmUnitInfo *ui)
 Helper. Returns the $FIftiMain offset of leaf node or 0.
 
bool ProcessWLC (uint64_t wlc_count, uint64_t wlc_size, uint32_t wlc_offset, unsigned char ds, unsigned char dr, unsigned char cs, unsigned char cr, unsigned char ls, unsigned char lr, chmUnitInfo *uifmain, chmUnitInfo *uitbl, chmUnitInfo *uistrings, chmUnitInfo *topics, chmUnitInfo *urlstr, CHMSearchResults *results)
 Helper. Processes the word location code entries while searching.
 
bool InfoFromWindows ()
 Looks up as much information as possible from #WINDOWS/#STRINGS.
 
bool InfoFromSystem ()
 Looks up as much information as possible from #SYSTEM.
 
bool BinaryTOC (wxTreeCtrl *toBuild)
 Load binary TOC (if available)
 
void RecurseLoadBTOC (UCharPtr &topidx, UCharPtr &topics, UCharPtr &strings, UCharPtr &urltbl, UCharPtr &urlstr, uint32_t offset, wxTreeCtrl *toBuild, int level)
 Try to recursively load the binary topics tree.
 
bool GetItem (UCharPtr &topics, UCharPtr &strings, UCharPtr &urltbl, UCharPtr &urlstr, uint32_t index, wxTreeCtrl *tree, CHMListCtrl *list, const wxString &idxName, int level, bool local)
 Retrieve the data (name/URL) for a single entry (TOC or index)
 
bool BinaryIndex (CHMListCtrl *toBuild, const wxCSConv &cv)
 Get the binary index (if available)
 
bool ConvertFromUnicode (std::string &value, unsigned char *buffer, size_t bufferLength)
 Get a regular string from a generic buffer of length bufferLength.
 
 CHMFile (const CHMFile &)
 No copy construction allowed.
 
CHMFileoperator= (const CHMFile &)
 No assignments.
 

Private Attributes

chmFile * _chmFile
 
wxString _filename
 
wxString _home
 
wxString _topicsFile
 
wxString _indexFile
 
wxString _title
 
wxString _font
 
wxFontEncoding _enc
 
CHMIDMap _cidMap
 

Detailed Description

Mostly a C++ wrapper around the CHMLIB facilities. Concrete class.

Constructor & Destructor Documentation

CHMFile::CHMFile ( const wxString &  archiveName)

This constructor attempts to open the .chm file passed as it's argument. If it fails, IsOk() will return false.

Parameters
archiveNameThe .chm filename on disk.

References LoadCHM().

Member Function Documentation

wxString CHMFile::ArchiveName ( ) const
inline

Gets the filename of the currently opened .chm file.

Returns
The filename of the currently opened archive, relative to the root of the filesystem, or the empty string if no archive has been opened.

Referenced by CHMInputStream::Init(), CHMFrame::LoadBookmarks(), CHMFrame::LoadContextID(), CHMListCtrl::LoadSelected(), CHMFrame::OnBookmarkSel(), CHMFrame::OnHome(), CHMFrame::OnSelectionChanged(), CHMFrame::SaveBookmarks(), and CHMFrame::UpdateCHMInfo().

bool CHMFile::AreContextIDsLoaded ( ) const
inline

Have the context-IDs been loaded into memory or not.

Returns
true if they have, false if not.
wxString CHMFile::DefaultFont ( ) const
inline

Determines the font to use for special charsets.

Returns
Detected font recommendation.

Referenced by CHMFrame::UpdateCHMInfo().

wxFontEncoding CHMFile::DesiredEncoding ( ) const
inline

Determines the encoding that the CHM creator would like me to use. To be used in combination with DefaultFont().

Returns
Desired encoding.

Referenced by CHMFrame::UpdateCHMInfo().

bool CHMFile::GetIndex ( CHMListCtrl toBuild)

Attempts to fill a CHMListCtrl by parsing the index file.

Parameters
toBuildPointer to the list control to be filled. If the index file is not available, the list control is unmodified. The lost must be empty before passing it to this function.
Returns
true if it's possible to build the tree, false otherwise.

References BinaryIndex(), HHCParser::parse(), ResolveObject(), and RetrieveObject().

Referenced by CHMFrame::UpdateCHMInfo().

wxString CHMFile::GetPageByCID ( const int  contextID)

Looks up the page referred to by the context-ID.

Parameters
contextIDThe context-ID to look up
Returns
the page referred to by the context-ID, or file root"/" if ID is invalid.

Referenced by CHMFrame::LoadContextID().

bool CHMFile::GetTopicsTree ( wxTreeCtrl *  toBuild)

Attempts to fill a wxTreeCtrl by parsing the topics file.

Parameters
toBuildPointer to the tree to be filled. If the topics file is not available, the tree is unmodified. The tree must be empty before passing it to this function.
Returns
true if it's possible to build the tree, false otherwise.

References BinaryTOC(), HHCParser::parse(), ResolveObject(), and RetrieveObject().

Referenced by CHMFrame::UpdateCHMInfo().

wxString CHMFile::HomePage ( ) const
inline

Gets the name of the default page in the archive.

Returns
The home page name, with a '/' added in front and relative to the root of the archive filesystem. If no .chm has been opened, the returned value is "/".

Referenced by CHMInputStream::CHMInputStream(), CHMFrame::OnHome(), and CHMFSHandler::OpenFile().

wxString CHMFile::IndexFile ( ) const
inline

Gets name of the .hhk file in the archive that could potentially be used to generate content information from.

Returns
The index file name, with a '/' added in front and relative to the root of the archive filesystem. If no .chm has been opened, the return value is an empty string.
bool CHMFile::IndexSearch ( const wxString &  text,
bool  wholeWords,
bool  titlesOnly,
CHMSearchResults *  results 
)

Fast search using the $FIftiMain file in the .chm.

Parameters
textThe text we're looking for.
wholeWordsAre we looking for whole words only?
titlesOnlyAre we looking for titles only?
resultsA string-string hashmap that will hold the results in case of successful search. The keys are the URLs and the values are the page titles.
Returns
true if the search succeeded, false otherwise.

References GetLeafNodeOffset(), and ProcessWLC().

Referenced by CHMSearchPanel::OnSearch().

bool CHMFile::IsOk ( ) const
inline

Checks if the last attempt to load a .chm file was succesful.

Returns
true, if the last attempt to load a .chm file was succesful, false otherwise.

Referenced by CHMInputStream::Init().

bool CHMFile::IsValidCID ( const int  contextID)

Checks whether or not the context ID is valid for the loaded file.

Parameters
contextIDThe context-ID to check.
Returns
TRUE if the context ID is valid. FALSE otherwise.

Referenced by CHMFrame::LoadContextID().

bool CHMFile::LoadCHM ( const wxString &  archiveName)

Attempts to load a .chm file from disk.

Parameters
archiveNameThe .chm filename on disk.
Returns
true on success, false on failure.

References CloseCHM(), GetArchiveInfo(), and LoadContextIDs().

Referenced by CHMFile().

bool CHMFile::LoadContextIDs ( )

Attempts to build an index of context-ID/page pairs from the file.

Returns
true if it's possible to buld the tree, false otherwise.

Referenced by LoadCHM().

bool CHMFile::ResolveObject ( const wxString &  fileName,
chmUnitInfo *  ui 
)

Looks up fileName in the archive.

Parameters
fileNameThe file name to look up in the archive, qualified with '/' standing for the root of the archive filesystem.
uiA pointer to CHMLIB specific data about the file. The parameter gets filled with useful data if the lookup was succesful.
Returns
true if the file exists in the archive, false otherwise.

Referenced by CHMInputStream::CHMInputStream(), GetIndex(), and GetTopicsTree().

size_t CHMFile::RetrieveObject ( chmUnitInfo *  ui,
unsigned char *  buffer,
off_t  fileOffset,
size_t  bufferSize 
)

Retrieves an uncompressed chunk of a file in the .chm.

Parameters
uiPointer to a CHMLIB specific data structure obtained from a succesful call to ResolveObject().
bufferThe buffer to place the chunk into.
fileOffsetWhere does the chunk we want begin in the file?
bufferSizeThe size of the buffer.
Returns
0 on error, length of chunk retrieved otherwise.

Referenced by GetIndex(), GetTopicsTree(), and CHMInputStream::OnSysRead().

wxString CHMFile::Title ( ) const
inline

Gets the name of the opened .chm.

Returns
The name of the opened document, or an empty string if no .chm has been loaded.

Referenced by CHMFrame::UpdateCHMInfo().

wxString CHMFile::TopicsFile ( ) const
inline

Gets name of the .hhc file in the archive that could potentially be used to generate content information from.

Returns
The topics file name, with a '/' added in front and relative to the root of the archive filesystem. If no .chm has been opened, the return value is an empty string.

The documentation for this class was generated from the following files: