PageRenderTime 57ms CodeModel.GetById 10ms app.highlight 42ms RepoModel.GetById 1ms app.codeStats 0ms

/ideintf/idehelpintf.pas

http://github.com/graemeg/lazarus
Pascal | 193 lines | 118 code | 31 blank | 44 comment | 5 complexity | 4c5b6172fda0ebcbbb9aeb0d3b3f7b78 MD5 | raw file
  1{  $Id: helpintf.pas 9271 2006-05-13 12:00:43Z mattias $  }
  2{
  3 *****************************************************************************
  4 *                                                                           *
  5 *  See the file COPYING.modifiedLGPL.txt, included in this distribution,    *
  6 *  for details about the copyright.                                         *
  7 *                                                                           *
  8 *  This program is distributed in the hope that it will be useful,          *
  9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
 11 *                                                                           *
 12 *****************************************************************************
 13
 14  Author: Mattias Gaertner
 15
 16  Abstract:
 17    This unit defines various base classes for the Help System used by the IDE.
 18}
 19unit IDEHelpIntf;
 20
 21{$mode objfpc}{$H+}
 22
 23interface
 24
 25uses
 26  Classes, SysUtils, LCLProc, Forms, Controls, HelpIntfs, LazHelpIntf,
 27  TextTools;
 28
 29type
 30  { THelpDBIRegExprMessage
 31    Help registration item for matching a message (e.g. a fpc warning) with
 32    a regular expression.
 33    For example a line like
 34      "/usr/share/lazarus/components/synedit/syneditkeycmds.pp(532,10) Warning: Function result does not seem to be set"
 35     could be matched with
 36      Expression=') Warning: Function result does not seem to be set'
 37    }
 38
 39  THelpDBIRegExprMessage = class(THelpDBIMessage)
 40  private
 41    FExpression: string;
 42    FModifierStr: string;
 43  public
 44    constructor Create(TheNode: THelpNode; const RegularExpression,
 45                       TheModifierStr: string);
 46    function MessageMatches(const TheMessage: string; MessageParts: TStrings
 47                            ): boolean; override;
 48    property Expression: string read FExpression write FExpression;
 49    property ModifierStr: string read FModifierStr write FModifierStr;
 50  end;
 51
 52  { TBaseHelpManager }
 53
 54  TBaseHelpManager = class(TComponent)
 55  public
 56    procedure ConnectMainBarEvents; virtual; abstract;
 57    procedure LoadHelpOptions; virtual; abstract;
 58    procedure SaveHelpOptions; virtual; abstract;
 59
 60    function ShowHelpForSourcePosition(const Filename: string;
 61                                       const CodePos: TPoint;
 62                                       var ErrMsg: string): TShowHelpResult; virtual; abstract;
 63    procedure ShowHelpForMessage(Line: integer); virtual; abstract;
 64    procedure ShowHelpForObjectInspector(Sender: TObject); virtual; abstract;
 65    function CreateHint(aHintWindow: THintWindow; ScreenPos: TPoint;
 66                    const BaseURL: string; var TheHint: string;
 67                    out HintWinRect: TRect): boolean; virtual; abstract;
 68
 69    function ConvertSourcePosToPascalHelpContext(const CaretPos: TPoint;
 70                            const Filename: string): TPascalHelpContextList; virtual; abstract;
 71  end;
 72  
 73
 74var
 75  LazarusHelp: TBaseHelpManager; // initialized by the IDE
 76
 77type
 78  { TIDEHTMLControlIntf }
 79
 80  TIDEHTMLControlIntf = interface
 81    function GetURL: string;
 82    procedure SetURL(const AValue: string);
 83    property URL: string read GetURL write SetURL;
 84    procedure SetHTMLContent(Stream: TStream);
 85    procedure GetPreferredControlSize(out AWidth, AHeight: integer);
 86  end;
 87
 88  { TAbstractIDEHTMLProvider
 89    An instance of this class connects 3 parts:
 90     1. IDE html files  (via implementation)
 91     2. a html viewer control (via ControlIntf)
 92     3. IDE or designtime package code
 93    All three can communicate. }
 94
 95  TAbstractIDEHTMLProvider = class(TComponent)
 96  protected
 97    FBaseURL: string;
 98    FControlIntf: TIDEHTMLControlIntf;
 99    procedure SetBaseURL(const AValue: string); virtual;
100    procedure SetControlIntf(const AValue: TIDEHTMLControlIntf); virtual;
101  public
102    constructor Create(TheOwner: TComponent); override;
103    destructor Destroy; override;
104    function GetStream(const URL: string
105      ): TStream; virtual; abstract; { provider assumes ownership of returned TStream
106                                       and increases internal reference count.
107                                       If not found it raises an exception. }
108    procedure ReleaseStream(const URL: string); virtual; abstract;
109    property BaseURL: string read FBaseURL write SetBaseURL;// fallback for relative URLs
110    function BuildURL(const CurBaseURL, CurURL: string): string; virtual;
111    property ControlIntf: TIDEHTMLControlIntf read FControlIntf write SetControlIntf;
112  end;
113
114  TCreateIDEHTMLControlEvent =
115    function(Owner: TComponent; var Provider: TAbstractIDEHTMLProvider): TControl;
116  TCreateIDEHTMLProviderEvent =
117    function(Owner: TComponent): TAbstractIDEHTMLProvider;
118
119var
120  CreateIDEHTMLControl: TCreateIDEHTMLControlEvent = nil;// will be set by the IDE
121    // and overidden by a package like turbopoweriprodsgn.lpk
122  CreateIDEHTMLProvider: TCreateIDEHTMLProviderEvent = nil;// will be set by the IDE
123
124
125implementation
126
127
128{ THelpDBIRegExprMessage }
129
130constructor THelpDBIRegExprMessage.Create(TheNode: THelpNode;
131  const RegularExpression, TheModifierStr: string);
132begin
133  Node:=TheNode;
134  FExpression:=RegularExpression;
135  FModifierStr:=TheModifierStr;
136end;
137
138function THelpDBIRegExprMessage.MessageMatches(const TheMessage: string;
139  MessageParts: TStrings): boolean;
140begin
141  Result:=REMatches(TheMessage,Expression,ModifierStr);
142  //writeln('THelpDBIRegExprMessage.MessageMatches TheMessage="',TheMessage,'" Expression="',Expression,'" Result=',Result);
143end;
144
145{ TAbstractIDEHTMLProvider }
146
147procedure TAbstractIDEHTMLProvider.SetBaseURL(const AValue: string);
148begin
149  if FBaseURL=AValue then exit;
150  FBaseURL:=AValue;
151end;
152
153procedure TAbstractIDEHTMLProvider.SetControlIntf(
154  const AValue: TIDEHTMLControlIntf);
155begin
156  if FControlIntf=AValue then exit;
157  FControlIntf:=AValue;
158end;
159
160constructor TAbstractIDEHTMLProvider.Create(TheOwner: TComponent);
161begin
162  inherited Create(TheOwner);
163end;
164
165destructor TAbstractIDEHTMLProvider.Destroy;
166begin
167  FControlIntf:=nil; // decrease reference count
168  inherited Destroy;
169end;
170
171function TAbstractIDEHTMLProvider.BuildURL(const CurBaseURL, CurURL: string
172  ): string;
173var
174  URLType: string;
175  URLPath: string;
176  URLParams: string;
177begin
178  Result:=CurURL;
179  SplitURL(CurURL,URLType,URLPath,URLParams);
180  //DebugLn(['TAbstractIDEHTMLProvider.BuildURL CurURL=',CurURL,' URLType=',URLType,' URLPath=',URLPath,' URLParams=',URLParams]);
181  if URLType='' then begin
182    // no URLType => use CurURL as URLPath
183    Result:=CurURL;
184    //DebugLn(['TAbstractIDEHTMLProvider.BuildURL AAA1 ',Result]);
185    if not URLFilenameIsAbsolute(Result) then
186      Result:=CurBaseURL+Result;
187  end else begin
188    Result:=CurURL;
189  end;
190end;
191
192end.
193