using System;
using System.IO;
using System.Collections;
using System.Windows.Forms;
using HtmlHelp.ChmDecoding;
namespace HtmlHelp
{
///
/// The class TOCItem implements a toc-entry item
///
public sealed class TOCItem
{
///
/// Constant for standard folder (closed) image index (HH2 image list)
///
public const int STD_FOLDER_HH2 = 4;
///
/// Constant for standard folder (opened) image index (HH2 image list)
///
public const int STD_FOLDER_OPEN_HH2 = 6;
///
/// Constant for standard file image index (HH2 image list)
///
public const int STD_FILE_HH2 = 16;
///
/// Constant for standard folder (closed) image index (HH1 image list)
///
public const int STD_FOLDER_HH1 = 0;
///
/// Constant for standard folder (opened) image index (HH1 image list)
///
public const int STD_FOLDER_OPEN_HH1 = 1;
///
/// Constant for standard file image index (HH1 image list)
///
public const int STD_FILE_HH1 = 10;
///
/// Internal flag specifying the data extraction mode used for this item
///
private DataMode _tocMode = DataMode.TextBased;
///
/// Internal member storing the offset (only used in binary tocs)
///
private int _offset = 0;
///
/// Internal member storing the offset of the next item(only used in binary tocs)
///
private int _offsetNext = 0;
///
/// Internal member storing a merge link.
/// If the target file is in the merged files list of the CHM,
/// this item will be replaced with the target TOC or Topic, if not it will
/// be removed from TOC.
///
private string _mergeLink = "";
///
/// Internal member storing the toc name
///
private string _name = "";
///
/// Internal member storing the toc loca (content file)
///
private string _local = "";
///
/// Internal member storing all associated information type strings
///
private ArrayList _infoTypeStrings = new ArrayList();
///
/// Internal member storing the associated chm file
///
private string _chmFile = "";
///
/// Internal member storing the image index
///
private int _imageIndex = -1;
///
/// Internal member storing the offset of the associated topic entry (for binary tocs)
///
private int _topicOffset = -1;
///
/// Internal member storing the toc children
///
private ArrayList _children = new ArrayList();
///
/// Internal member storing the parameter collection
///
private Hashtable _otherParams = new Hashtable();
///
/// Internal member storing the associated chmfile object
///
private CHMFile _associatedFile = null;
///
/// Parent item
///
private TOCItem _parent=null;
///
/// Holds a pointer to the next item in the TOC
///
public TOCItem Next=null;
///
/// Holds a pointer to the previous item in the TOC
///
public TOCItem Prev=null;
///
/// Holds a pointer to the TreeNode where this TOC Item is used
///
public System.Windows.Forms.TreeNode treeNode=null;
///
/// Constructor of the class used during text-based data extraction
///
/// name of the item
/// local content file
/// image index
/// associated chm file
public TOCItem(string name, string local, int ImageIndex, string chmFile)
{
_tocMode = DataMode.TextBased;
_name = name;
_local = local;
_imageIndex = ImageIndex;
_chmFile = chmFile;
}
///
/// Constructor of the class used during binary data extraction
///
/// offset of the associated topic entry
/// image index to use
/// associated chm file
public TOCItem(int topicOffset, int ImageIndex, CHMFile associatedFile)
{
_tocMode = DataMode.Binary;
_associatedFile = associatedFile;
_chmFile = associatedFile.ChmFilePath;
_topicOffset = topicOffset;
_imageIndex = ImageIndex;
}
///
/// Standard constructor
///
public TOCItem()
{
}
#region Data dumping
///
/// Dump the class data to a binary writer
///
/// writer to write the data
/// true if the chmfile name should be written
internal void Dump(ref BinaryWriter writer, bool writeFilename)
{
writer.Write((int)_tocMode);
writer.Write(_topicOffset);
writer.Write(_name);
if((_tocMode == DataMode.TextBased)||(_topicOffset<0))
{
writer.Write(_local);
}
writer.Write(_imageIndex);
writer.Write(_mergeLink);
if(writeFilename)
writer.Write(_chmFile);
writer.Write(_infoTypeStrings.Count);
for(int i=0; i<_infoTypeStrings.Count; i++)
writer.Write( (_infoTypeStrings[i]).ToString() );
writer.Write(_children.Count);
for(int i=0; i<_children.Count; i++)
{
TOCItem child = ((TOCItem)(_children[i]));
child.Dump(ref writer, writeFilename);
}
}
///
/// Dump the class data to a binary writer
///
/// writer to write the data
internal void Dump(ref BinaryWriter writer)
{
Dump(ref writer, false);
}
///
/// Reads the object data from a dump store
///
/// reader to read the data
/// true if the chmfile name should be read
internal void ReadDump(ref BinaryReader reader, bool readFilename)
{
int i=0;
_tocMode = (DataMode)reader.ReadInt32();
_topicOffset = reader.ReadInt32();
_name = reader.ReadString();
if((_tocMode == DataMode.TextBased)||(_topicOffset<0))
{
_local = reader.ReadString();
}
_imageIndex = reader.ReadInt32();
_mergeLink = reader.ReadString();
if(readFilename)
_chmFile = reader.ReadString();
int nCnt = reader.ReadInt32();
for(i=0; i 0)
_associatedFile.MergLinks.Add(child);
}
}
///
/// Reads the object data from a dump store
///
/// reader to read the data
internal void ReadDump(ref BinaryReader reader)
{
ReadDump(ref reader, false);
}
#endregion
///
/// Gets/Sets the data extraction mode with which this item was created.
///
internal DataMode TocMode
{
get { return _tocMode; }
set { _tocMode = value; }
}
///
/// Gets/Sets the offset of the associated topic entry
///
internal int TopicOffset
{
get { return _topicOffset; }
set { _topicOffset = value; }
}
///
/// Gets/Sets the associated CHMFile instance
///
internal CHMFile AssociatedFile
{
get { return _associatedFile; }
set
{
_associatedFile = value;
}
}
///
/// Gets/Sets the offset of the item.
///
/// Only used in binary tocs
internal int Offset
{
get { return _offset; }
set { _offset = value; }
}
///
/// Gets/Sets the offset of the next item.
///
/// Only used in binary tocs
internal int OffsetNext
{
get { return _offsetNext; }
set { _offsetNext = value; }
}
///
/// Gets the ArrayList which holds all information types/categories this item is associated
///
internal ArrayList InfoTypeStrings
{
get { return _infoTypeStrings; }
}
///
/// Gets/Sets the parent of this item
///
public TOCItem Parent
{
get { return _parent; }
set { _parent = value; }
}
///
/// Gets/Sets the mergelink for this item.
/// You should not set the mergedlink by your own !
/// This is only for loading merged CHMs.
///
public string MergeLink
{
get { return _mergeLink; }
set { _mergeLink = value; }
}
///
/// Gets/Sets the name of the item
///
public string Name
{
get
{
if(_mergeLink.Length > 0)
return "";
if(_name.Length <= 0)
{
if((_tocMode == DataMode.Binary )&&(_associatedFile!=null))
{
if( _topicOffset >= 0)
{
TopicEntry te = (TopicEntry) (_associatedFile.TopicsFile[_topicOffset]);
if(te != null)
{
return te.Title;
}
}
}
}
return _name;
}
set
{
_name = value;
}
}
///
/// Gets/Sets the local of the item
///
public string Local
{
get
{
if(_mergeLink.Length > 0)
return "";
if(_local.Length <= 0)
{
if((_tocMode == DataMode.Binary )&&(_associatedFile!=null))
{
if( _topicOffset >= 0)
{
TopicEntry te = (TopicEntry) (_associatedFile.TopicsFile[_topicOffset]);
if(te != null)
{
return te.Locale;
}
}
}
}
return _local;
}
set { _local = value; }
}
///
/// Gets/Sets the chm file
///
public string ChmFile
{
get
{
if(_associatedFile!=null)
return _associatedFile.ChmFilePath;
return _chmFile;
}
set { _chmFile = value; }
}
///
/// Gets the url for the webbrowser for this file
///
public string Url
{
get
{
string sL = Local;
if( (sL.ToLower().IndexOf("http://") >= 0) ||
(sL.ToLower().IndexOf("https://") >= 0) ||
(sL.ToLower().IndexOf("mailto:") >= 0) ||
(sL.ToLower().IndexOf("ftp://") >= 0) ||
(sL.ToLower().IndexOf("ms-its:") >= 0))
return sL;
return HtmlHelpSystem.UrlPrefix + ChmFile + "::/" + sL;
}
}
///
/// Gets/Sets the image index of the item
///
/// Set this to -1 for a default icon
public int ImageIndex
{
get
{
if( _imageIndex == -1)
{
int nFolderAdd = 0;
if((_associatedFile != null) && (_associatedFile.ImageTypeFolder))
{
// get the value which should be added, to display folders instead of books
if(HtmlHelpSystem.UseHH2TreePics)
nFolderAdd = 8;
else
nFolderAdd = 4;
}
if( _children.Count > 0)
return (HtmlHelpSystem.UseHH2TreePics ? (STD_FOLDER_HH2+nFolderAdd) : (STD_FOLDER_HH1+nFolderAdd));
return (HtmlHelpSystem.UseHH2TreePics ? STD_FILE_HH2 : STD_FILE_HH1);
}
return _imageIndex;
}
set { _imageIndex = value; }
}
///
/// Gets/Sets the children of this item.
///
/// Each entry in the ArrayList is of type TOCItem
public ArrayList Children
{
get { return _children; }
set { _children = value; }
}
///
/// Gets the internal hashtable storing all params
///
public Hashtable Params
{
get { return _otherParams; }
}
}
}