PageRenderTime 18ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/htmlhelp_ipro/htmlhelp2viewer.pas

http://github.com/graemeg/lazarus
Pascal | 154 lines | 88 code | 29 blank | 37 comment | 1 complexity | aabedaa9bca8d8b93314453382c00de3 MD5 | raw file
  1{
  2 ***************************************************************************
  3 *                                                                         *
  4 *   This source is free software; you can redistribute it and/or modify   *
  5 *   it under the terms of the GNU General Public License as published by  *
  6 *   the Free Software Foundation; either version 2 of the License, or     *
  7 *   (at your option) any later version.                                   *
  8 *                                                                         *
  9 *   This code is distributed in the hope that it will be useful, but      *
 10 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 12 *   General Public License for more details.                              *
 13 *                                                                         *
 14 *   A copy of the GNU General Public License is available on the World    *
 15 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 16 *   obtain it by writing to the Free Software Foundation,                 *
 17 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 18 *                                                                         *
 19 ***************************************************************************
 20
 21  Abstract:
 22    This example implements a help viewer using the turbo power
 23    ipro browser component.
 24    
 25    procedure RegisterHelpViewer;
 26    
 27    need to be called to register this viewer. The sample calls it in the
 28    OnCreate of the main form.
 29}
 30
 31unit HtmlHelp2Viewer;
 32
 33{$mode objfpc}{$H+}
 34
 35interface
 36
 37uses
 38  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
 39  LCLProc, IpHtml, Buttons, helpintfs, lazhelpintf, ComCtrls, ipfilebroker,
 40  iputils;
 41
 42type
 43
 44  { THelpViewerForm }
 45  
 46  THelpViewerForm = class(TForm)
 47    IHP: TIpHtmlPanel;
 48    DataProvider: TIpFileDataProvider;
 49    Panel1: TPanel;
 50    IndexButton: TSpeedButton;
 51    BackButton: TSpeedButton;
 52    ForwardButton: TSpeedButton;
 53    StatusBar1: TStatusBar;
 54    procedure BackButtonClick(Sender: TObject);
 55    procedure ForwardButtonClick(Sender: TObject);
 56    procedure IHPDocumentOpen(Sender: TObject);
 57    procedure IHPHotChange(Sender: TObject);
 58    procedure IndexButtonClick(Sender: TObject);
 59  private
 60  public
 61    { public declarations }
 62    procedure showURL(URL : String);
 63  end; 
 64
 65var
 66  HelpViewerForm: THelpViewerForm;
 67
 68procedure RegisterHelpViewer;
 69
 70implementation
 71
 72{$R htmlhelp2viewer.lfm}
 73
 74type
 75
 76  { THTMLHelpViewer }
 77
 78  THTMLHelpViewer = class(THelpViewer)
 79  private
 80  public
 81    constructor Create(TheOwner: TComponent); override;
 82    function ShowNode(Node: THelpNode; var ErrMsg: string): TShowHelpResult; override;
 83  published
 84    property AutoRegister;
 85  end;
 86
 87{ THTMLHelpViewer }
 88
 89constructor THTMLHelpViewer.Create(TheOwner: TComponent);
 90begin
 91  inherited Create(TheOwner);
 92  AddSupportedMimeType('text/html');
 93end;
 94
 95function THTMLHelpViewer.ShowNode(Node: THelpNode; var ErrMsg: string): TShowHelpResult;
 96begin
 97  DebugLn (Format('THTMLHelpViewer.ShowNode: URL:"%s" ID:"%s" Context:"%d"',[Node.URL,Node.ID,Node.Context]));
 98  HelpViewerForm.ShowURL(Node.URL);
 99  result := shrSuccess;  // we should return a "better" result ;-)
100end;
101
102var Help_Viewer : THTMLHelpViewer = nil;
103
104procedure RegisterHelpViewer;
105begin
106  if Help_Viewer = nil then                      // if not already done
107  begin
108    Help_Viewer := THTMLHelpViewer.Create(nil);  // create the viewer and
109    Help_Viewer.RegisterSelf;                    // register it in the help system
110  end;
111end;
112
113{ THelpViewerForm }
114
115procedure THelpViewerForm.IndexButtonClick(Sender: TObject);
116begin
117  ShowHelpOrErrorForKeyword('','HTML/index.html');  // HTML is case sensitive
118end;
119
120// Show URL of a link in Status Bar
121procedure THelpViewerForm.IHPHotChange(Sender: TObject);
122begin
123  StatusBar1.Panels[0].Text := IHP.HotURL;
124end;
125
126procedure THelpViewerForm.BackButtonClick(Sender: TObject);
127begin
128  IHP.GoBack;
129end;
130
131procedure THelpViewerForm.ForwardButtonClick(Sender: TObject);
132begin
133  IHP.GoForward;
134end;
135
136procedure THelpViewerForm.IHPDocumentOpen(Sender: TObject);
137begin
138  BackButton.Enabled := IHP.canGoBack;
139  ForwardButton.Enabled := IHP.canGoForward;
140end;
141
142procedure THelpViewerForm.showURL(URL : String);
143begin
144  Show;
145  URL := expandLocalHtmlFileName (URL);
146  IHP.OpenURL(URL);
147  BringToFront;  // needed if already open and another help is shown
148end;
149
150finalization
151  FreeAndNil(Help_Viewer);
152
153end.
154