Develop and Download Open Source Software

Browse Subversion Repository

Contents of /htmlhelp.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Mon Nov 7 12:03:00 2011 UTC (12 years, 4 months ago) by shiraishikazuo
File MIME type: text/x-pascal
File size: 5915 byte(s)


1 unit htmlhelp;
2
3 (***************************************)
4 (* Copyright (C) 2003, SHIRAISHI Kazuo *)
5 (***************************************)
6
7
8 interface
9
10 uses
11 SysUtils, Types, Classes, Variants, Graphics, Controls, Forms, Dialogs,
12 ComCtrls, StdCtrls, ExtCtrls;
13
14
15 implementation
16
17 uses
18 HelpIntfs, ShellAPI,
19 listbox,base,MainFrm;
20
21 var
22 CurrentPos:string;
23 KeyWordRec:TStringList;
24
25 function HtmName(s:string):string;
26 var
27 p:integer;
28 begin
29 p:=pos('#',s);
30 if p=0 then p:=length(s)+1;
31 result:=copy(s,1,p-1);
32 end;
33
34 function Anchor(s:string):string;
35 var
36 p:integer;
37 begin
38 p:=pos('#',s);
39 if p=0 then
40 result:=''
41 else
42 result:=copy(s,p+1,length(s)-p);
43 end;
44
45 function LinkSelect(const HelpString: String):string;
46 var
47 i:integer;
48 s:string;
49 begin
50 s:=KeyWordRec.Values[HelpString];
51 if (s='')then
52 result:='basic.htm'
53 else if s[1]<>'"' then
54 result:=s
55 else
56 begin
57 with TStringList.Create do
58 begin
59 CommaText:=s;
60 with TlistForm.create(nil) do
61 begin
62 RadioGroup1.Caption:=HelpString;
63 for i:=0 to (count-1) div 2 do
64 RadioGroup1.items.add(strings[i*2]);
65 RadioGroup1.ItemIndex:=0;
66 RadioGroup1.SetFocus;
67 ShowModal;
68 result:=Strings[RadioGroup1.ItemIndex *2 +1];
69 Free;
70 end;
71 Free;
72 end;
73 end;
74 end;
75
76 var
77 HelpContexts:array [0..999] of string ;
78 ALinks:TStringList;
79
80
81 procedure InitHelpContexts;
82 var
83 F:text;
84 n:integer;
85 s:string;
86 p:integer;
87 c:integer;
88
89 begin
90 assignFile(F,ChangeFileExt(Application.ExeName,'.hcx'));
91 {$I-}
92 Reset(F);
93 if IOResult=0 then
94 begin
95 while not EOF(F) do
96 begin
97 Readln(F,s);
98 p:=pos(' ',s);
99 if p>0 then
100 begin
101 val(copy(s,p,maxint),n, c);
102 if (n>=0) and (n<=999) then HelpContexts[n]:=copy(s,1,p-1);
103 end;
104 end;
105 Close(F);
106 end;
107 {$I+}
108 end;
109
110 procedure InitALinks;
111 begin
112 ALinks:=TStringList.create;
113 ALinks.LoadFromFile(ChangeFileExt(Application.ExeName,'.hlk')) ;
114 end;
115
116
117 type
118 TKeywordHelp = class(TInterfacedObject, ICustomHelpViewer)
119 private
120 FViewerID : Integer;
121 FHelpManager : IHelpManager;
122 public
123 { ICustomHelpViewer }
124 function GetViewerName: string;
125 function UnderstandsKeyword(const HelpString: String): Integer;
126 function GetHelpStrings(const HelpString: String): TStringList;
127 function CanShowTableOfContents: Boolean;
128 procedure ShowHelp(const HelpString: String);
129 procedure ShowTableOfContents;
130 procedure NotifyID(const ViewerID: Integer);
131 procedure SoftShutDown;
132 procedure ShutDown;
133 property HelpManager: IHelpManager read FHelpManager write FHelpManager;
134 property ViewerID: Integer read FViewerID;
135 end;
136
137
138 function TKeywordHelp.CanShowTableOfContents: Boolean;
139 begin
140 Result := FileExists(FHelpManager.GetHelpFile);
141 end;
142
143 function TKeywordHelp.GetViewerName: String;
144 begin
145 Result := 'BASIC Help';
146 end;
147
148 procedure TKeywordHelp.NotifyID(const ViewerID: Integer);
149 begin
150 FViewerID := ViewerID;
151 end;
152
153 function TKeywordHelp.GetHelpStrings(const HelpString: String): TStringList;
154 begin
155 Result := TStringList.Create;
156 Result.Add(HelpString);
157 end;
158
159 procedure TKeywordHelp.ShowHelp(const HelpString: String);
160 begin
161 ShellExecute(FrameForm.Handle, nil, PChar(LinkSelect(HelpString)), nil, nil, 0);
162 //HelpForm.SetBrowser(LinkSelect(HelpString));
163 end;
164
165 procedure TKeywordHelp.ShowTableOfContents;
166 begin
167 ShowHelp('')
168 end;
169
170 procedure TKeywordHelp.ShutDown;
171 begin
172 end;
173
174 procedure TKeywordHelp.SoftShutDown;
175 begin
176 //HelpForm.Close
177 end;
178
179 function TKeywordHelp.UnderstandsKeyword(const HelpString: String): Integer;
180 begin
181 result:=1
182 end;
183
184
185 type TExtendedHelp=class(TkeywordHelp,IExtendedHelpViewer)
186 private
187 public
188 function UnderstandsContext(const ContextID: Integer; const HelpFileName: String): Boolean;
189 procedure DisplayHelpByContext(const ContextID: Integer; const HelpFileName: String);
190 function UnderstandsTopic(const Topic: String): Boolean;
191 procedure DisplayTopic(const Topic: String);
192 end;
193
194 function TExtendedHelp.UnderstandsContext(const ContextID: Integer; const HelpFileName: String): Boolean;
195 begin
196 result:= (ContextID>=0) and (ContextID<=999)
197 end;
198
199
200 procedure TExtendedHelp.DisplayHelpByContext(const ContextID: Integer; const HelpFileName: String);
201 var
202 s:string;
203 begin
204 s:= 'html/'+ALinks.Values[HelpContexts[ContextId]];
205 ShellExecute(FrameForm.Handle, nil, PChar(s), nil, nil, 0);
206
207 //HelpForm.SetBrowser('html/'+ALinks.Values[HelpContexts[ContextId]]);
208 end;
209
210 function TExtendedHelp.UnderstandsTopic(const Topic: String): Boolean;
211 begin
212 result:=false
213 end;
214
215 procedure TExtendedHelp.DisplayTopic(const Topic: String);
216 begin
217 end;
218
219
220 var
221 HelpViewer: TExtendedHelp;
222
223
224
225 procedure InitKeyWordRec;
226 var
227 F:text;
228 s:string;
229 begin
230 KeywordRec:=TStringList.create;
231 KeywordRec.CaseSensitive:=false;
232 AssignFile(F,ChangeFileExt(Application.ExeName,'.hkw'));
233 {$I-}
234 Reset(F);
235 if IOResult=0 then
236 begin
237 while not EOF(F) do
238 begin
239 Readln(F,s);
240 KeywordRec.add(s);
241 end;
242 close(F);
243 end;
244 {$I+}
245 end;
246
247
248
249 initialization
250 //Application.HelpFile:=ChangeFileExt(Application.ExeName,'.htm');
251 //Application.HelpType:=htContext ;
252
253 HelpViewer := TExtendedHelp.Create;
254 HelpIntfs.RegisterViewer(HelpViewer, HelpViewer.FHelpManager);
255 InitKeyWordRec;
256 InitHelpContexts;
257 InitALinks;
258
259 finalization
260 ALinks.Free;
261 KeywordRec.free;
262 with HelpViewer do
263 if Assigned(FHelpManager) then FHelpManager.Release(FViewerID);
264
265 end.
266

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26