~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/chmhelp/packages/idehelp/chmprog.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
unit ChmProg;
 
2
 
 
3
{$mode objfpc}{$H+}
 
4
 
 
5
interface
 
6
 
 
7
uses
 
8
  Classes, SysUtils,
 
9
  Dialogs, FileUtil, LazFileUtils, LazLogger,
 
10
  LazHelpIntf, HelpIntfs,
 
11
  IDEHelpIntf, MacroIntf;
 
12
 
 
13
const
 
14
  sFPCCompilerDirectives = 'FreePascal Compiler directives';
 
15
 
 
16
type
 
17
 
 
18
  { TFPCDirectivesHelpDatabase }
 
19
 
 
20
  TFPCDirectivesHelpDatabase = class(THelpDatabase)
 
21
  private
 
22
    FCHMSearchPath: string;
 
23
    FDirectiveNodes: TFPList;
 
24
    function SearchForDirective(ADirective: string;
 
25
      var ListOfNodes: THelpNodeQueryList): Boolean;
 
26
    procedure ClearDirectiveNodes;
 
27
  public
 
28
    constructor Create(TheOwner: TComponent); override;
 
29
    destructor Destroy; override;
 
30
    function GetNodesForDirective(const HelpDirective: string;
 
31
      var ListOfNodes: THelpNodeQueryList;
 
32
      var ErrMsg: string): TShowHelpResult; override;
 
33
    function ShowHelp(Query: THelpQuery; {%H-}BaseNode, NewNode: THelpNode;
 
34
                      {%H-}QueryItem: THelpQueryItem;
 
35
                      var ErrMsg: string): TShowHelpResult; override;
 
36
    function GetCHMSearchPath: string;
 
37
    property CHMSearchPath: string read FCHMSearchPath write FCHMSearchPath;
 
38
    function FindCHMFile: string;
 
39
  end;
 
40
 
 
41
procedure RegisterFPCDirectivesHelpDatabase;
 
42
 
 
43
var
 
44
  FPCDirectivesHelpDatabase: TFPCDirectivesHelpDatabase = nil;
 
45
 
 
46
implementation
 
47
 
 
48
uses chmreader, chmFiftiMain;
 
49
 
 
50
procedure RegisterFPCDirectivesHelpDatabase;
 
51
begin
 
52
  if not Assigned(FPCDirectivesHelpDatabase) then
 
53
    FPCDirectivesHelpDatabase :=
 
54
      TFPCDirectivesHelpDatabase(HelpDatabases.CreateHelpDatabase(
 
55
        sFPCCompilerDirectives, TFPCDirectivesHelpDatabase, true));
 
56
end;
 
57
 
 
58
{ TFPCDirectivesHelpDatabase }
 
59
 
 
60
function TFPCDirectivesHelpDatabase.SearchForDirective(ADirective: string;
 
61
  var ListOfNodes: THelpNodeQueryList): Boolean;
 
62
var
 
63
  chm: TChmFileList;
 
64
  fchm: TChmReader;
 
65
  DocTitle, URL: string;
 
66
  ms: TMemoryStream;
 
67
  SearchReader: TChmSearchReader;
 
68
  TitleResults: TChmWLCTopicArray;
 
69
  i, k: Integer;
 
70
  DirectiveNode: THelpNode;
 
71
  Filename: String;
 
72
begin
 
73
  ADirective := UpperCase(ADirective);
 
74
  Result := False;
 
75
 
 
76
  Filename:=FindCHMFile;
 
77
  if Filename='' then exit;
 
78
 
 
79
  chm := TChmFileList.Create(Utf8ToSys(Filename));
 
80
  try
 
81
    if chm.Count = 0 then Exit;
 
82
    fchm := chm.Chm[0];
 
83
 
 
84
    if fchm.SearchReader = nil then
 
85
    begin
 
86
      ms := fchm.GetObject('/$FIftiMain');
 
87
      if ms = nil then Exit;
 
88
      SearchReader := TChmSearchReader.Create(ms, True); //frees the stream when done
 
89
      fchm.SearchReader := SearchReader;
 
90
    end
 
91
    else
 
92
      SearchReader := fchm.SearchReader;
 
93
    SearchReader.LookupWord(Copy(ADirective, 2, MaxInt), TitleResults);
 
94
    for k := 0 to High(TitleResults) do
 
95
    begin
 
96
      URL := fchm.LookupTopicByID(TitleResults[k].TopicIndex, DocTitle);
 
97
      i := Pos(ADirective, DocTitle);
 
98
      if (i = 0) or (Length(DocTitle) >= i + Length(ADirective))
 
99
        and (upCase(DocTitle[i + Length(ADirective)]) in ['A'..'Z','0'..'9']) then Continue;
 
100
      if (Length(URL) > 0) and (URL[1] = '/') then
 
101
        Delete(URL, 1, 1);
 
102
      if URL = '' then Continue;
 
103
      DirectiveNode := THelpNode.CreateURL(Self, ADirective, 'prog.chm://' + URL);
 
104
      DirectiveNode.Title := 'FPC directives: ' + DocTitle;
 
105
      CreateNodeQueryListAndAdd(DirectiveNode, nil, ListOfNodes, True);
 
106
      FDirectiveNodes.Add(DirectiveNode);
 
107
      Result := True;
 
108
    end;
 
109
 
 
110
    fchm.Free;
 
111
  finally
 
112
    chm.Free;
 
113
  end;
 
114
end;
 
115
 
 
116
procedure TFPCDirectivesHelpDatabase.ClearDirectiveNodes;
 
117
var i: Integer;
 
118
begin
 
119
  for i := 0 to FDirectiveNodes.Count - 1 do
 
120
    TObject(FDirectiveNodes[i]).Free;
 
121
  FDirectiveNodes.Clear;
 
122
end;
 
123
 
 
124
constructor TFPCDirectivesHelpDatabase.Create(TheOwner: TComponent);
 
125
begin
 
126
  inherited Create(TheOwner);
 
127
  FDirectiveNodes := TFPList.Create;
 
128
end;
 
129
 
 
130
destructor TFPCDirectivesHelpDatabase.Destroy;
 
131
begin
 
132
  ClearDirectiveNodes;
 
133
  FDirectiveNodes.Free;
 
134
  inherited Destroy;
 
135
end;
 
136
 
 
137
function TFPCDirectivesHelpDatabase.GetNodesForDirective(
 
138
  const HelpDirective: string; var ListOfNodes: THelpNodeQueryList;
 
139
  var ErrMsg: string): TShowHelpResult;
 
140
var
 
141
  Directive: String;
 
142
  Filename: String;
 
143
begin
 
144
  Result := shrHelpNotFound;
 
145
  if (csDesigning in ComponentState) then Exit;
 
146
  if (FPCDirectiveHelpPrefix<>'')
 
147
  and (LeftStr(HelpDirective, Length(FPCDirectiveHelpPrefix)) = FPCDirectiveHelpPrefix) then
 
148
  begin
 
149
    Filename:=FindCHMFile;
 
150
    debugln(['TFPCDirectivesHelpDatabase.GetNodesForDirective ',Filename]);
 
151
    if (Filename='') then
 
152
    begin
 
153
      Result := shrDatabaseNotFound;
 
154
      ErrMsg := Format('prog.chm not found. Please put prog.chm help file in '+ LineEnding
 
155
                       + '%s' +  LineEnding
 
156
                       +'or set the path to it with "HelpFilesPath" in '
 
157
                       +' Environment Options -> Help -> Help Options ->' + LineEnding
 
158
                       +'under Viewers - CHM Help Viewer', [FCHMSearchPath]);
 
159
      Exit;
 
160
    end;
 
161
    // HelpDirective starts with DirectivePrefix
 
162
    Directive := Copy(HelpDirective, Length(FPCDirectiveHelpPrefix) + 1, Length(HelpDirective));
 
163
    ClearDirectiveNodes;
 
164
    if SearchForDirective(Directive, ListOfNodes) then
 
165
      Result := shrSuccess;
 
166
  end;
 
167
end;
 
168
 
 
169
function TFPCDirectivesHelpDatabase.ShowHelp(Query: THelpQuery; BaseNode,
 
170
  NewNode: THelpNode; QueryItem: THelpQueryItem; var ErrMsg: string
 
171
  ): TShowHelpResult;
 
172
var
 
173
  Viewer: THelpViewer;
 
174
begin
 
175
  Result:=shrHelpNotFound;
 
176
  if not (Query is THelpQueryDirective) then exit;
 
177
  Result := FindViewer('text/html', ErrMsg, Viewer);
 
178
  if Result <> shrSuccess then Exit;
 
179
  Result := Viewer.ShowNode(NewNode, ErrMsg);
 
180
end;
 
181
 
 
182
function TFPCDirectivesHelpDatabase.GetCHMSearchPath: string;
 
183
begin
 
184
  Result:=FCHMSearchPath;
 
185
  if Result='' then begin
 
186
    Result := '$(LazarusDir)/docs/html;$(LazarusDir)/docs/chm';
 
187
    IDEMacros.SubstituteMacros(Result);
 
188
    Result:=MinimizeSearchPath(SetDirSeparators(Result));
 
189
  end;
 
190
end;
 
191
 
 
192
function TFPCDirectivesHelpDatabase.FindCHMFile: string;
 
193
begin
 
194
  Result:=SearchFileInPath('prog.chm','',GetCHMSearchPath,';',[]);
 
195
end;
 
196
 
 
197
end.
 
198