3 using System.Collections;
4 using System.Windows.Forms;
6 using HtmlHelp.ChmDecoding;
11 /// The class <c>TOCItem</c> implements a toc-entry item
13 public sealed class TOCItem
16 /// Constant for standard folder (closed) image index (HH2 image list)
18 public const int STD_FOLDER_HH2 = 4;
20 /// Constant for standard folder (opened) image index (HH2 image list)
22 public const int STD_FOLDER_OPEN_HH2 = 6;
24 /// Constant for standard file image index (HH2 image list)
26 public const int STD_FILE_HH2 = 16;
29 /// Constant for standard folder (closed) image index (HH1 image list)
31 public const int STD_FOLDER_HH1 = 0;
33 /// Constant for standard folder (opened) image index (HH1 image list)
35 public const int STD_FOLDER_OPEN_HH1 = 1;
37 /// Constant for standard file image index (HH1 image list)
39 public const int STD_FILE_HH1 = 10;
42 /// Internal flag specifying the data extraction mode used for this item
44 private DataMode _tocMode = DataMode.TextBased;
46 /// Internal member storing the offset (only used in binary tocs)
48 private int _offset = 0;
50 /// Internal member storing the offset of the next item(only used in binary tocs)
52 private int _offsetNext = 0;
54 /// Internal member storing a merge link.
55 /// If the target file is in the merged files list of the CHM,
56 /// this item will be replaced with the target TOC or Topic, if not it will
57 /// be removed from TOC.
59 private string _mergeLink = "";
61 /// Internal member storing the toc name
63 private string _name = "";
65 /// Internal member storing the toc loca (content file)
67 private string _local = "";
69 /// Internal member storing all associated information type strings
71 private ArrayList _infoTypeStrings = new ArrayList();
73 /// Internal member storing the associated chm file
75 private string _chmFile = "";
77 /// Internal member storing the image index
79 private int _imageIndex = -1;
81 /// Internal member storing the offset of the associated topic entry (for binary tocs)
83 private int _topicOffset = -1;
85 /// Internal member storing the toc children
87 private ArrayList _children = new ArrayList();
89 /// Internal member storing the parameter collection
91 private Hashtable _otherParams = new Hashtable();
93 /// Internal member storing the associated chmfile object
95 private CHMFile _associatedFile = null;
99 private TOCItem _parent=null;
102 /// Holds a pointer to the next item in the TOC
104 public TOCItem Next=null;
107 /// Holds a pointer to the previous item in the TOC
109 public TOCItem Prev=null;
112 /// Holds a pointer to the TreeNode where this TOC Item is used
114 public System.Windows.Forms.TreeNode treeNode=null;
117 /// Constructor of the class used during text-based data extraction
119 /// <param name="name">name of the item</param>
120 /// <param name="local">local content file</param>
121 /// <param name="ImageIndex">image index</param>
122 /// <param name="chmFile">associated chm file</param>
123 public TOCItem(string name, string local, int ImageIndex, string chmFile)
125 _tocMode = DataMode.TextBased;
128 _imageIndex = ImageIndex;
133 /// Constructor of the class used during binary data extraction
135 /// <param name="topicOffset">offset of the associated topic entry</param>
136 /// <param name="ImageIndex">image index to use</param>
137 /// <param name="associatedFile">associated chm file</param>
138 public TOCItem(int topicOffset, int ImageIndex, CHMFile associatedFile)
140 _tocMode = DataMode.Binary;
141 _associatedFile = associatedFile;
142 _chmFile = associatedFile.ChmFilePath;
143 _topicOffset = topicOffset;
144 _imageIndex = ImageIndex;
148 /// Standard constructor
156 /// Dump the class data to a binary writer
158 /// <param name="writer">writer to write the data</param>
159 /// <param name="writeFilename">true if the chmfile name should be written</param>
160 internal void Dump(ref BinaryWriter writer, bool writeFilename)
162 writer.Write((int)_tocMode);
163 writer.Write(_topicOffset);
166 if((_tocMode == DataMode.TextBased)||(_topicOffset<0))
168 writer.Write(_local);
171 writer.Write(_imageIndex);
173 writer.Write(_mergeLink);
176 writer.Write(_chmFile);
178 writer.Write(_infoTypeStrings.Count);
180 for(int i=0; i<_infoTypeStrings.Count; i++)
181 writer.Write( (_infoTypeStrings[i]).ToString() );
183 writer.Write(_children.Count);
185 for(int i=0; i<_children.Count; i++)
187 TOCItem child = ((TOCItem)(_children[i]));
188 child.Dump(ref writer, writeFilename);
193 /// Dump the class data to a binary writer
195 /// <param name="writer">writer to write the data</param>
196 internal void Dump(ref BinaryWriter writer)
198 Dump(ref writer, false);
202 /// Reads the object data from a dump store
204 /// <param name="reader">reader to read the data</param>
205 /// <param name="readFilename">true if the chmfile name should be read</param>
206 internal void ReadDump(ref BinaryReader reader, bool readFilename)
209 _tocMode = (DataMode)reader.ReadInt32();
210 _topicOffset = reader.ReadInt32();
211 _name = reader.ReadString();
213 if((_tocMode == DataMode.TextBased)||(_topicOffset<0))
215 _local = reader.ReadString();
218 _imageIndex = reader.ReadInt32();
220 _mergeLink = reader.ReadString();
223 _chmFile = reader.ReadString();
225 int nCnt = reader.ReadInt32();
227 for(i=0; i<nCnt; i++)
229 string sIT = reader.ReadString();
230 _infoTypeStrings.Add(sIT);
233 nCnt = reader.ReadInt32();
235 if(_associatedFile != null)
236 _chmFile = _associatedFile.ChmFilePath;
238 for(i=0; i<nCnt; i++)
240 TOCItem child = new TOCItem();
241 child.AssociatedFile = _associatedFile;
243 child.ReadDump(ref reader, readFilename);
245 if(_associatedFile != null)
246 child.ChmFile = _associatedFile.ChmFilePath;
247 else if(!readFilename)
248 child.ChmFile = _chmFile;
251 _children.Add(child);
253 if(child.MergeLink.Length > 0)
254 _associatedFile.MergLinks.Add(child);
259 /// Reads the object data from a dump store
261 /// <param name="reader">reader to read the data</param>
262 internal void ReadDump(ref BinaryReader reader)
264 ReadDump(ref reader, false);
269 /// Gets/Sets the data extraction mode with which this item was created.
271 internal DataMode TocMode
273 get { return _tocMode; }
274 set { _tocMode = value; }
278 /// Gets/Sets the offset of the associated topic entry
280 internal int TopicOffset
282 get { return _topicOffset; }
283 set { _topicOffset = value; }
287 /// Gets/Sets the associated CHMFile instance
289 internal CHMFile AssociatedFile
291 get { return _associatedFile; }
294 _associatedFile = value;
299 /// Gets/Sets the offset of the item.
301 /// <remarks>Only used in binary tocs</remarks>
304 get { return _offset; }
305 set { _offset = value; }
309 /// Gets/Sets the offset of the next item.
311 /// <remarks>Only used in binary tocs</remarks>
312 internal int OffsetNext
314 get { return _offsetNext; }
315 set { _offsetNext = value; }
319 /// Gets the ArrayList which holds all information types/categories this item is associated
321 internal ArrayList InfoTypeStrings
323 get { return _infoTypeStrings; }
327 /// Gets/Sets the parent of this item
329 public TOCItem Parent
331 get { return _parent; }
332 set { _parent = value; }
336 /// Gets/Sets the mergelink for this item.
337 /// <b>You should not set the mergedlink by your own !</b>
338 /// This is only for loading merged CHMs.
340 public string MergeLink
342 get { return _mergeLink; }
343 set { _mergeLink = value; }
347 /// Gets/Sets the name of the item
353 if(_mergeLink.Length > 0)
356 if(_name.Length <= 0)
358 if((_tocMode == DataMode.Binary )&&(_associatedFile!=null))
360 if( _topicOffset >= 0)
362 TopicEntry te = (TopicEntry) (_associatedFile.TopicsFile[_topicOffset]);
380 /// Gets/Sets the local of the item
386 if(_mergeLink.Length > 0)
389 if(_local.Length <= 0)
391 if((_tocMode == DataMode.Binary )&&(_associatedFile!=null))
393 if( _topicOffset >= 0)
395 TopicEntry te = (TopicEntry) (_associatedFile.TopicsFile[_topicOffset]);
406 set { _local = value; }
410 /// Gets/Sets the chm file
412 public string ChmFile
416 if(_associatedFile!=null)
417 return _associatedFile.ChmFilePath;
421 set { _chmFile = value; }
425 /// Gets the url for the webbrowser for this file
433 if( (sL.ToLower().IndexOf("http://") >= 0) ||
434 (sL.ToLower().IndexOf("https://") >= 0) ||
435 (sL.ToLower().IndexOf("mailto:") >= 0) ||
436 (sL.ToLower().IndexOf("ftp://") >= 0) ||
437 (sL.ToLower().IndexOf("ms-its:") >= 0))
440 return HtmlHelpSystem.UrlPrefix + ChmFile + "::/" + sL;
445 /// Gets/Sets the image index of the item
447 /// <remarks>Set this to -1 for a default icon</remarks>
448 public int ImageIndex
452 if( _imageIndex == -1)
456 if((_associatedFile != null) && (_associatedFile.ImageTypeFolder))
458 // get the value which should be added, to display folders instead of books
459 if(HtmlHelpSystem.UseHH2TreePics)
466 if( _children.Count > 0)
467 return (HtmlHelpSystem.UseHH2TreePics ? (STD_FOLDER_HH2+nFolderAdd) : (STD_FOLDER_HH1+nFolderAdd));
469 return (HtmlHelpSystem.UseHH2TreePics ? STD_FILE_HH2 : STD_FILE_HH1);
473 set { _imageIndex = value; }
477 /// Gets/Sets the children of this item.
479 /// <remarks>Each entry in the ArrayList is of type TOCItem</remarks>
480 public ArrayList Children
482 get { return _children; }
483 set { _children = value; }
487 /// Gets the internal hashtable storing all params
489 public Hashtable Params
491 get { return _otherParams; }