{ Copyright (C) <2005> chmspecialparser.pas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. } { See the file COPYING.LCL, included in this distribution, for details about the copyright. } unit ChmSpecialParser; {$mode objfpc}{$H+} //{$INLINING ON} interface uses Classes, Forms, SysUtils, Controls, ComCtrls; type TContentTreeNode = class(TTreeNode) private fUrl: String; public property Url:String read fUrl write fUrl; end; TContentNode = record Name: String; Url: String; LineCount: Integer; end; TIndexItem = class(TListITem) private fUrl: String; public property Url:String read fUrl write fUrl; end; { TContentsFiller } TContentsFiller = class(TObject) private fTreeView: TTreeView; fStream: TStream; fText: TStringList; fBranchCount: DWord; fStop: PBoolean; procedure CustomCreateContentTreeItem(Sender: TCustomTreeView; var ATreeNode: TTreenode); function AddULTree(StartLine, EndLine: Integer; ParentNode: TTreeNode): Boolean; function GetULEnd(StartLine: Integer): Integer; function GetLIData(StartLine: Integer): TContentNode; public constructor Create(ATreeView: TTreeView; AStream: TStream; StopBoolean: PBoolean); procedure DoFill; //inline; end; { TIndexFiller } TIndexFiller = class(TObject) private fListView: TListView; fStream: TStream; fText: TStringList; function GetLIEnd(StartLine: Integer): Integer; function GetNextLI(StartLine: Integer): Integer; function AddLIObjects(StartLine: Integer): Integer; function LineHasLI(ALine: Integer): Boolean; public constructor Create(AListView: TListView; AStream: TStream); procedure DoFill; end; implementation function FixURL(URL: String):String; var X: LongInt; begin X := Pos('%20', Url); while X > 0 do begin Delete(Url, X, 3); Insert(' ', Url, X); X := Pos('%20', Url); end; Result := Url; end; { TContentsFiller } procedure TContentsFiller.CustomCreateContentTreeItem(Sender: TCustomTreeView; var ATreeNode: TTreenode); begin ATreeNode := TContentTreeNode.Create(TTreeView(Sender).Items); end; function TContentsFiller.AddULTree(StartLine, EndLine: Integer; ParentNode: TTreeNode): Boolean; var X: LongInt; TreeNode: TContentTreeNode = nil; NodeInfo: TContentNode; ULEnd: Integer; begin Result := True; Inc(fBranchCount); for X := StartLine to EndLine do begin if Pos('
  • ', fText.Strings[X]) > 0 then begin NodeInfo := GetLIData(X); TreeNode := TContentTreeNode(fTreeView.Items.AddChild(ParentNode, NodeInfo.Name)); TreeNode.Url := NodeInfo.Url; Inc(PInteger(@X)^, NodeInfo.LineCount); // >:D end; if (X <> StartLine) and (Pos('