/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. Abstract:
  21. This example implements a help viewer using the turbo power
  22. ipro browser component.
  23. procedure RegisterHelpViewer;
  24. need to be called to register this viewer. The sample calls it in the
  25. OnCreate of the main form.
  26. }
  27. unit HtmlHelp2Viewer;
  28. {$mode objfpc}{$H+}
  29. interface
  30. uses
  31. Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  32. LCLProc, IpHtml, Buttons, helpintfs, lazhelpintf, ComCtrls, ipfilebroker,
  33. iputils;
  34. type
  35. { THelpViewerForm }
  36. THelpViewerForm = class(TForm)
  37. IHP: TIpHtmlPanel;
  38. DataProvider: TIpFileDataProvider;
  39. Panel1: TPanel;
  40. IndexButton: TSpeedButton;
  41. BackButton: TSpeedButton;
  42. ForwardButton: TSpeedButton;
  43. StatusBar1: TStatusBar;
  44. procedure BackButtonClick(Sender: TObject);
  45. procedure ForwardButtonClick(Sender: TObject);
  46. procedure IHPDocumentOpen(Sender: TObject);
  47. procedure IHPHotChange(Sender: TObject);
  48. procedure IndexButtonClick(Sender: TObject);
  49. private
  50. public
  51. { public declarations }
  52. procedure showURL(URL : String);
  53. end;
  54. var
  55. HelpViewerForm: THelpViewerForm;
  56. procedure RegisterHelpViewer;
  57. implementation
  58. {$R htmlhelp2viewer.lfm}
  59. type
  60. { THTMLHelpViewer }
  61. THTMLHelpViewer = class(THelpViewer)
  62. private
  63. public
  64. constructor Create(TheOwner: TComponent); override;
  65. function ShowNode(Node: THelpNode; var ErrMsg: string): TShowHelpResult; override;
  66. published
  67. property AutoRegister;
  68. end;
  69. { THTMLHelpViewer }
  70. constructor THTMLHelpViewer.Create(TheOwner: TComponent);
  71. begin
  72. inherited Create(TheOwner);
  73. AddSupportedMimeType('text/html');
  74. end;
  75. function THTMLHelpViewer.ShowNode(Node: THelpNode; var ErrMsg: string): TShowHelpResult;
  76. begin
  77. DebugLn (Format('THTMLHelpViewer.ShowNode: URL:"%s" ID:"%s" Context:"%d"',[Node.URL,Node.ID,Node.Context]));
  78. HelpViewerForm.ShowURL(Node.URL);
  79. result := shrSuccess; // we should return a "better" result ;-)
  80. end;
  81. var Help_Viewer : THTMLHelpViewer = nil;
  82. procedure RegisterHelpViewer;
  83. begin
  84. if Help_Viewer = nil then // if not already done
  85. begin
  86. Help_Viewer := THTMLHelpViewer.Create(nil); // create the viewer and
  87. Help_Viewer.RegisterSelf; // register it in the help system
  88. end;
  89. end;
  90. { THelpViewerForm }
  91. procedure THelpViewerForm.IndexButtonClick(Sender: TObject);
  92. begin
  93. ShowHelpOrErrorForKeyword('','HTML/index.html'); // HTML is case sensitive
  94. end;
  95. // Show URL of a link in Status Bar
  96. procedure THelpViewerForm.IHPHotChange(Sender: TObject);
  97. begin
  98. StatusBar1.Panels[0].Text := IHP.HotURL;
  99. end;
  100. procedure THelpViewerForm.BackButtonClick(Sender: TObject);
  101. begin
  102. IHP.GoBack;
  103. end;
  104. procedure THelpViewerForm.ForwardButtonClick(Sender: TObject);
  105. begin
  106. IHP.GoForward;
  107. end;
  108. procedure THelpViewerForm.IHPDocumentOpen(Sender: TObject);
  109. begin
  110. BackButton.Enabled := IHP.canGoBack;
  111. ForwardButton.Enabled := IHP.canGoForward;
  112. end;
  113. procedure THelpViewerForm.showURL(URL : String);
  114. begin
  115. Show;
  116. URL := expandLocalHtmlFileName (URL);
  117. IHP.OpenURL(URL);
  118. BringToFront; // needed if already open and another help is shown
  119. end;
  120. finalization
  121. FreeAndNil(Help_Viewer);
  122. end.