using System; using System.IO; using System.Text; using System.Collections; using HtmlHelp.ChmDecoding; namespace HtmlHelp { /// /// The class IndexItem implements an help-index item /// public sealed class IndexItem : IComparable { /// /// Internal member storing the keyword /// private string _keyWord = ""; /// /// Internal member storing all associated information type strings /// private ArrayList _infoTypeStrings = new ArrayList(); /// /// Internal member storing the flag if this is a see-also keyword /// private bool _isSeeAlso = false; /// /// Internal member storing the indent of the keyword /// private int _indent = 0; /// /// Internal member storing the last index of the keyword in the seperated list /// private int _charIndex = 0; /// /// Internal member storing the entry index /// private int _entryIndex = 0; /// /// Internal member storing an array of see-also values /// private string[] _seeAlso = new string[0]; /// /// Internal member storing an array of topic offsets /// private int[] _nTopics = new int[0]; /// /// Internal member storing the topics /// private ArrayList _Topics = null; /// /// Associated CHMFile instance /// private CHMFile _chmFile = null; /// /// Internal flag specifying the chm file path /// private string _chmFileName = ""; /// /// Constructor of the class /// /// associated CHMFile instance /// keyword /// true if it is a see-also keyword /// indent of the entry /// char index of the last keyword in the separated list /// index of the entry /// string array with see-also values /// integer array with topic offsets internal IndexItem(CHMFile chmFile, string keyWord, bool isSeeAlso, int indent, int charIndex, int entryIndex, string[] seeAlsoValues, int[] topicOffsets) { _chmFile = chmFile; _chmFileName = _chmFile.ChmFilePath; _keyWord = keyWord; _isSeeAlso = isSeeAlso; _indent = indent; _charIndex = charIndex; _entryIndex = entryIndex; _seeAlso = seeAlsoValues; _nTopics = topicOffsets; } /// /// Standard constructor /// public IndexItem() { } #region Data dumping /// /// Dump the class data to a binary writer /// /// writer to write the data /// true if the chm filename should be written internal void Dump(ref BinaryWriter writer, bool writeFileName) { int i=0; writer.Write(_keyWord); writer.Write(_isSeeAlso); writer.Write(_indent); if(writeFileName) writer.Write(_chmFileName); writer.Write(_infoTypeStrings.Count); for(i=0; i<_infoTypeStrings.Count; i++) writer.Write( (_infoTypeStrings[i]).ToString() ); writer.Write(_seeAlso.Length); for(i=0; i<_seeAlso.Length; i++) { if(_seeAlso[i] == null) writer.Write(""); else writer.Write( _seeAlso[i] ); } writer.Write(Topics.Count); for(i=0; i /// 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 /// filelist from helpsystem internal bool ReadDump(ref BinaryReader reader, ArrayList filesList) { int i=0; _keyWord = reader.ReadString(); _isSeeAlso = reader.ReadBoolean(); _indent = reader.ReadInt32(); _chmFileName = reader.ReadString(); foreach(CHMFile curFile in filesList) { if(curFile.ChmFilePath == _chmFileName) { _chmFile = curFile; break; } } if(_chmFile==null) return false; int nCnt = reader.ReadInt32(); for(i=0; i /// Reads the object data from a dump store /// /// reader to read the data internal void ReadDump(ref BinaryReader reader) { int i=0; _keyWord = reader.ReadString(); _isSeeAlso = reader.ReadBoolean(); _indent = reader.ReadInt32(); int nCnt = reader.ReadInt32(); for(i=0; i /// Implements the compareto method which allows sorting. /// /// object to compare to /// See IComparable.CompareTo() public int CompareTo(object obj) { if( obj.GetType() == this.GetType() ) { IndexItem cmp = (IndexItem)obj; return this.KeyWordPath.CompareTo( cmp.KeyWordPath ); } return 0; } /// /// Gets/Sets the associated CHMFile instance /// internal CHMFile ChmFile { get { return _chmFile; } set { _chmFile = value; } } /// /// Gets the ArrayList which holds all information types/categories this item is associated /// internal ArrayList InfoTypeStrings { get { return _infoTypeStrings; } } /// /// Adds a see-also string to the index item and marks it as see also item /// /// see also string to add internal void AddSeeAlso(string seeAlsoString) { string[] seeAlso = new string[ _seeAlso.Length +1 ]; for(int i=0; i<_seeAlso.Length; i++) seeAlso[i] = _seeAlso[i]; seeAlso[_seeAlso.Length] = seeAlsoString; _seeAlso = seeAlso; _isSeeAlso = true; } /// /// Gets/Sets the full keyword-path of this item ( ", " separated list) /// public string KeyWordPath { get { return _keyWord; } set { _keyWord = value; } } /// /// Gets the keyword of this item /// public string KeyWord { get { return _keyWord.Substring(_charIndex, _keyWord.Length-_charIndex); } } /// /// Gets the keyword of this item with prefixing indent spaces /// public string IndentKeyWord { get { string sKW = this.KeyWord; StringBuilder sb = new StringBuilder("",this.Indent*3 + sKW.Length); for(int i=0; i /// Gets/Sets the see-also flag of this item /// public bool IsSeeAlso { get { return _isSeeAlso; } set { _isSeeAlso = value; } } /// /// Gets/Sets the listbox indent for this item /// public int Indent { get { return _indent; } set { _indent = value; } } /// /// Gets/Sets the character index of an indent keyword /// public int CharIndex { get { return _charIndex; } set { _charIndex = value; } } /// /// Gets the see-also values of this item /// public string[] SeeAlso { get { return _seeAlso; } } /// /// Gets an array with the associated topics /// public ArrayList Topics { get { if( _Topics == null ) { if(IsSeeAlso) { _Topics = new ArrayList(); } else { if( (_chmFile != null) && (_chmFile.TopicsFile != null) ) { _Topics = new ArrayList(); for(int i=0; i<_nTopics.Length; i++) { IndexTopic newTopic = IndexTopic.FromTopicEntry((TopicEntry)_chmFile.TopicsFile.TopicTable[ _nTopics[i] ]); newTopic.AssociatedFile = _chmFile; _Topics.Add( newTopic ); } } else { _Topics = new ArrayList(); } } } return _Topics; } } } }