1 |
(* ***** BEGIN LICENSE BLOCK *****
|
2 |
* Version: MPL 1.1
|
3 |
*
|
4 |
* The contents of this file are subject to the Mozilla Public License Version
|
5 |
* 1.1 (the "License"); you may not use this file except in compliance with
|
6 |
* the License. You may obtain a copy of the License at
|
7 |
* http://www.mozilla.org/MPL/
|
8 |
*
|
9 |
* Software distributed under the License is distributed on an "AS IS" basis,
|
10 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
11 |
* for the specific language governing rights and limitations under the
|
12 |
* License.
|
13 |
*
|
14 |
* The Original Code is TurboPower SysTools
|
15 |
*
|
16 |
* The Initial Developer of the Original Code is
|
17 |
* TurboPower Software
|
18 |
*
|
19 |
* Portions created by the Initial Developer are Copyright (C) 1996-2002
|
20 |
* the Initial Developer. All Rights Reserved.
|
21 |
*
|
22 |
* Contributor(s):
|
23 |
*
|
24 |
* ***** END LICENSE BLOCK ***** *)
|
25 |
|
26 |
{*********************************************************}
|
27 |
{* _STTOHTML.PAS 3.00 *}
|
28 |
{*********************************************************}
|
29 |
|
30 |
{$I STDEFINE.INC}
|
31 |
{$I STCOMDEF.INC}
|
32 |
unit _StToHTML;
|
33 |
|
34 |
interface
|
35 |
|
36 |
uses
|
37 |
ComObj, ActiveX, AxCtrls, Classes, StStrms, StToHTML, SysTools_TLB, _StUtil, StdVcl;
|
38 |
|
39 |
type
|
40 |
TStToHTML = class(TAutoObject, IConnectionPointContainer, IStToHTML)
|
41 |
private { Private declarations }
|
42 |
FConnectionPoints: TConnectionPoints;
|
43 |
FConnectionPoint: TConnectionPoint;
|
44 |
FSinkList: TList;
|
45 |
FEvents: IStToHTMLEvents;
|
46 |
|
47 |
FSourceToHTML : StToHTML.TStStreamToHTML;
|
48 |
FKeywords : IStStringList;
|
49 |
FCommentMarkers: IStStringList;
|
50 |
FEmbeddedHTML : IStStringList;
|
51 |
FPageFooter : IStStringList;
|
52 |
FPageHeader : IStStringList;
|
53 |
FStringMarkers : IStStringList;
|
54 |
|
55 |
FIsLicensed : Boolean;
|
56 |
|
57 |
procedure _OnProgress(Sender : TObject; Percent : Word);
|
58 |
public { Public declarations }
|
59 |
procedure Initialize; override;
|
60 |
destructor Destroy; override;
|
61 |
protected {Protected declarations }
|
62 |
{ IConnectionPointContainer }
|
63 |
property ConnectionPoints: TConnectionPoints read FConnectionPoints
|
64 |
implements IConnectionPointContainer;
|
65 |
procedure EventSinkChanged(const EventSink: IUnknown); override;
|
66 |
|
67 |
{ IStToHTML properties (GET) }
|
68 |
function Get_CaseSensitve: WordBool; safecall;
|
69 |
function Get_CommentMarkers: IStStringList; safecall;
|
70 |
function Get_EmbeddedHTML: IStStringList; safecall;
|
71 |
function Get_FixedLineLength: Integer; safecall;
|
72 |
function Get_Keywords: IStStringList; safecall;
|
73 |
function Get_LineTermChar: WideString; safecall;
|
74 |
function Get_LineTerminator: TStLineTerminator; safecall;
|
75 |
function Get_PageFooter: IStStringList; safecall;
|
76 |
function Get_PageHeader: IStStringList; safecall;
|
77 |
function Get_Stream: OleVariant; safecall;
|
78 |
function Get_StringMarkers: IStStringList; safecall;
|
79 |
function Get_WordDelimeters: WideString; safecall;
|
80 |
|
81 |
{ IStToHTML properties (SET) }
|
82 |
procedure Set_CaseSensitve(Value: WordBool); safecall;
|
83 |
procedure Set_CommentMarkers(const Value: IStStringList); safecall;
|
84 |
procedure Set_EmbeddedHTML(const Value: IStStringList); safecall;
|
85 |
procedure Set_FixedLineLength(Value: Integer); safecall;
|
86 |
procedure Set_Keywords(const Value: IStStringList); safecall;
|
87 |
procedure Set_LineTermChar(const Value: WideString); safecall;
|
88 |
procedure Set_LineTerminator(Value: TStLineTerminator); safecall;
|
89 |
procedure Set_PageFooter(const Value: IStStringList); safecall;
|
90 |
procedure Set_PageHeader(const Value: IStStringList); safecall;
|
91 |
procedure Set_Stream(Value: OleVariant); safecall;
|
92 |
procedure Set_StringMarkers(const Value: IStStringList); safecall;
|
93 |
procedure Set_WordDelimeters(const Value: WideString); safecall;
|
94 |
|
95 |
{ IStToHTML methods }
|
96 |
procedure Clear; safecall;
|
97 |
procedure GenerateHTML; safecall;
|
98 |
procedure LoadFromFile(const FileName: WideString); safecall;
|
99 |
procedure SaveToFile(const FileName: WideString); safecall;
|
100 |
function License(const Key: WideString): WordBool; safecall;
|
101 |
end;
|
102 |
|
103 |
implementation
|
104 |
|
105 |
uses ComServ {$IFDEF LICENSE}, StComLic {$ENDIF};
|
106 |
|
107 |
{ ********** TStSourceToHTML Interface - IConnectionPointContainer Methods *************** }
|
108 |
procedure TStToHTML.EventSinkChanged(const EventSink: IUnknown);
|
109 |
begin
|
110 |
FEvents := EventSink as IStToHTMLEvents;
|
111 |
if FConnectionPoint <> nil then
|
112 |
FSinkList := FConnectionPoint.SinkList;
|
113 |
end;
|
114 |
|
115 |
{ ********** TStSourceToHTML Interface *************************************************** }
|
116 |
procedure TStToHTML.Initialize;
|
117 |
begin
|
118 |
inherited Initialize;
|
119 |
FConnectionPoints := TConnectionPoints.Create(Self);
|
120 |
if AutoFactory.EventTypeInfo <> nil then
|
121 |
FConnectionPoint := FConnectionPoints.CreateConnectionPoint(
|
122 |
AutoFactory.EventIID, ckSingle, EventConnect)
|
123 |
else FConnectionPoint := nil;
|
124 |
|
125 |
{$IFDEF LICENSE}
|
126 |
FIsLicensed := False;
|
127 |
{$ELSE}
|
128 |
FIsLicensed := True;
|
129 |
{$ENDIF}
|
130 |
|
131 |
FSourceToHTML := StToHTML.TStStreamToHTML.Create;
|
132 |
FSourceToHTML.InputStream := Classes.TMemoryStream.Create;
|
133 |
FSourceToHTML.OutputStream := Classes.TMemoryStream.Create;
|
134 |
|
135 |
FKeywords := TStStringList.Create(FSourceToHTML.Keywords);
|
136 |
FCommentMarkers := TStStringList.Create(FSourceToHTML.CommentMarkers);
|
137 |
FEmbeddedHTML := TStStringList.Create(FSourceToHTML.EmbeddedHTML);
|
138 |
FPageFooter := TStStringList.Create(FSourceToHTML.PageFooter);
|
139 |
FPageHeader := TStStringList.Create(FSourceToHTML.PageHeader);
|
140 |
FStringMarkers := TStStringList.Create(FSourceToHTML.StringMarkers);
|
141 |
|
142 |
FSourceToHTML.OnProgress := _OnProgress;
|
143 |
end;
|
144 |
|
145 |
destructor TStToHTML.Destroy;
|
146 |
begin
|
147 |
if Assigned(FSourceToHTML.InputStream) then
|
148 |
FSourceToHTML.InputStream.Free;
|
149 |
|
150 |
if Assigned(FSourceToHTML.OutputStream) then
|
151 |
FSourceToHTML.OutputStream.Free;
|
152 |
|
153 |
FKeywords := nil;
|
154 |
FCommentMarkers := nil;
|
155 |
FEmbeddedHTML := nil;
|
156 |
FPageFooter := nil;
|
157 |
FPageHeader := nil;
|
158 |
FStringMarkers := nil;
|
159 |
|
160 |
FSourceToHTML.Free;
|
161 |
|
162 |
inherited Destroy;
|
163 |
end;
|
164 |
|
165 |
{ ********** TStSourceToHTML Events ****************************************************** }
|
166 |
procedure TStToHTML._OnProgress(Sender : TObject; Percent : Word);
|
167 |
begin
|
168 |
if Assigned(FEvents) then
|
169 |
FEvents.OnProgress(Percent);
|
170 |
end;
|
171 |
|
172 |
{ ********** TStSourceToHTML Properties *** (Get) **************************************** }
|
173 |
function TStToHTML.Get_CaseSensitve: WordBool;
|
174 |
begin
|
175 |
{$IFDEF LICENSE}
|
176 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
177 |
OleError(CLASS_E_NOTLICENSED);
|
178 |
{$ENDIF}
|
179 |
Result := FSourceToHTML.CaseSensitive;
|
180 |
end;
|
181 |
|
182 |
function TStToHTML.Get_CommentMarkers: IStStringList;
|
183 |
begin
|
184 |
{$IFDEF LICENSE}
|
185 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
186 |
OleError(CLASS_E_NOTLICENSED);
|
187 |
{$ENDIF}
|
188 |
Result := FCommentMarkers;
|
189 |
end;
|
190 |
|
191 |
function TStToHTML.Get_EmbeddedHTML: IStStringList;
|
192 |
begin
|
193 |
{$IFDEF LICENSE}
|
194 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
195 |
OleError(CLASS_E_NOTLICENSED);
|
196 |
{$ENDIF}
|
197 |
Result := FEmbeddedHTML;
|
198 |
end;
|
199 |
|
200 |
function TStToHTML.Get_FixedLineLength: Integer;
|
201 |
begin
|
202 |
{$IFDEF LICENSE}
|
203 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
204 |
OleError(CLASS_E_NOTLICENSED);
|
205 |
{$ENDIF}
|
206 |
Result := FSourceToHTML.InFixedLineLength;
|
207 |
end;
|
208 |
|
209 |
function TStToHTML.Get_LineTermChar: WideString;
|
210 |
begin
|
211 |
{$IFDEF LICENSE}
|
212 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
213 |
OleError(CLASS_E_NOTLICENSED);
|
214 |
{$ENDIF}
|
215 |
Result := FSourceToHTML.InLineTermChar;
|
216 |
end;
|
217 |
|
218 |
function TStToHTML.Get_LineTerminator: TStLineTerminator;
|
219 |
begin
|
220 |
{$IFDEF LICENSE}
|
221 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
222 |
OleError(CLASS_E_NOTLICENSED);
|
223 |
{$ENDIF}
|
224 |
Result := TStLineTerminator(FSourceToHTML.InLineTerminator);
|
225 |
end;
|
226 |
|
227 |
function TStToHTML.Get_PageFooter: IStStringList;
|
228 |
begin
|
229 |
{$IFDEF LICENSE}
|
230 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
231 |
OleError(CLASS_E_NOTLICENSED);
|
232 |
{$ENDIF}
|
233 |
Result := FPageFooter;
|
234 |
end;
|
235 |
|
236 |
function TStToHTML.Get_PageHeader: IStStringList;
|
237 |
begin
|
238 |
{$IFDEF LICENSE}
|
239 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
240 |
OleError(CLASS_E_NOTLICENSED);
|
241 |
{$ENDIF}
|
242 |
Result := FPageHeader;
|
243 |
end;
|
244 |
|
245 |
function TStToHTML.Get_Stream: OleVariant;
|
246 |
begin
|
247 |
{$IFDEF LICENSE}
|
248 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
249 |
OleError(CLASS_E_NOTLICENSED);
|
250 |
{$ENDIF}
|
251 |
Result := StStreamToOleVariant(FSourceToHTML.OutputStream);
|
252 |
end;
|
253 |
|
254 |
function TStToHTML.Get_StringMarkers: IStStringList;
|
255 |
begin
|
256 |
{$IFDEF LICENSE}
|
257 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
258 |
OleError(CLASS_E_NOTLICENSED);
|
259 |
{$ENDIF}
|
260 |
Result := FStringMarkers;
|
261 |
end;
|
262 |
|
263 |
function TStToHTML.Get_WordDelimeters: WideString;
|
264 |
begin
|
265 |
{$IFDEF LICENSE}
|
266 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
267 |
OleError(CLASS_E_NOTLICENSED);
|
268 |
{$ENDIF}
|
269 |
Result := FSourceToHTML.WordDelimiters;
|
270 |
end;
|
271 |
|
272 |
{ ********** TStSourceToHTML Properties *** (Set) **************************************** }
|
273 |
procedure TStToHTML.Set_CaseSensitve(Value: WordBool);
|
274 |
begin
|
275 |
{$IFDEF LICENSE}
|
276 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
277 |
OleError(CLASS_E_NOTLICENSED);
|
278 |
{$ENDIF}
|
279 |
FSourceToHTML.CaseSensitive := Value;
|
280 |
end;
|
281 |
|
282 |
procedure TStToHTML.Set_CommentMarkers(const Value: IStStringList);
|
283 |
var
|
284 |
MS : TStream;
|
285 |
begin
|
286 |
{$IFDEF LICENSE}
|
287 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
288 |
OleError(CLASS_E_NOTLICENSED);
|
289 |
{$ENDIF}
|
290 |
MS := nil;
|
291 |
try
|
292 |
MS := StOleVariantToStream(Value.Stream, True);
|
293 |
FSourceToHTML.CommentMarkers.LoadFromStream(MS);
|
294 |
finally
|
295 |
MS.Free;
|
296 |
end;
|
297 |
end;
|
298 |
|
299 |
procedure TStToHTML.Set_EmbeddedHTML(const Value: IStStringList);
|
300 |
var
|
301 |
MS : TStream;
|
302 |
begin
|
303 |
{$IFDEF LICENSE}
|
304 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
305 |
OleError(CLASS_E_NOTLICENSED);
|
306 |
{$ENDIF}
|
307 |
MS := nil;
|
308 |
try
|
309 |
MS := StOleVariantToStream(Value.Stream, True);
|
310 |
FSourceToHTML.EmbeddedHTML.LoadFromStream(MS);
|
311 |
finally
|
312 |
MS.Free;
|
313 |
end;
|
314 |
end;
|
315 |
|
316 |
procedure TStToHTML.Set_FixedLineLength(Value: Integer);
|
317 |
begin
|
318 |
{$IFDEF LICENSE}
|
319 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
320 |
OleError(CLASS_E_NOTLICENSED);
|
321 |
{$ENDIF}
|
322 |
FSourceToHTML.InFixedLineLength := Value;
|
323 |
end;
|
324 |
|
325 |
function TStToHTML.Get_Keywords: IStStringList;
|
326 |
begin
|
327 |
{$IFDEF LICENSE}
|
328 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
329 |
OleError(CLASS_E_NOTLICENSED);
|
330 |
{$ENDIF}
|
331 |
Result := FKeywords;
|
332 |
end;
|
333 |
|
334 |
procedure TStToHTML.Set_Keywords(const Value: IStStringList);
|
335 |
begin
|
336 |
{$IFDEF LICENSE}
|
337 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
338 |
OleError(CLASS_E_NOTLICENSED);
|
339 |
{$ENDIF}
|
340 |
FKeywords := Value;
|
341 |
end;
|
342 |
|
343 |
procedure TStToHTML.Set_LineTermChar(const Value: WideString);
|
344 |
begin
|
345 |
{$IFDEF LICENSE}
|
346 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
347 |
OleError(CLASS_E_NOTLICENSED);
|
348 |
{$ENDIF}
|
349 |
FSourceToHTML.InLineTermChar := Char(Value[1]);
|
350 |
end;
|
351 |
|
352 |
procedure TStToHTML.Set_LineTerminator(Value: TStLineTerminator);
|
353 |
begin
|
354 |
{$IFDEF LICENSE}
|
355 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
356 |
OleError(CLASS_E_NOTLICENSED);
|
357 |
{$ENDIF}
|
358 |
FSourceToHTML.InLineTerminator := StStrms.TStLineTerminator(Value);
|
359 |
end;
|
360 |
|
361 |
procedure TStToHTML.Set_PageFooter(const Value: IStStringList);
|
362 |
var
|
363 |
MS : TStream;
|
364 |
begin
|
365 |
{$IFDEF LICENSE}
|
366 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
367 |
OleError(CLASS_E_NOTLICENSED);
|
368 |
{$ENDIF}
|
369 |
MS := nil;
|
370 |
try
|
371 |
MS := StOleVariantToStream(Value.Stream, True);
|
372 |
FSourceToHTML.PageFooter.LoadFromStream(MS);
|
373 |
finally
|
374 |
MS.Free;
|
375 |
end;
|
376 |
end;
|
377 |
|
378 |
procedure TStToHTML.Set_PageHeader(const Value: IStStringList);
|
379 |
var
|
380 |
MS : TStream;
|
381 |
begin
|
382 |
{$IFDEF LICENSE}
|
383 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
384 |
OleError(CLASS_E_NOTLICENSED);
|
385 |
{$ENDIF}
|
386 |
MS := nil;
|
387 |
try
|
388 |
MS := StOleVariantToStream(Value.Stream, True);
|
389 |
FSourceToHTML.PageHeader.LoadFromStream(MS);
|
390 |
finally
|
391 |
MS.Free;
|
392 |
end;
|
393 |
end;
|
394 |
|
395 |
procedure TStToHTML.Set_Stream(Value: OleVariant);
|
396 |
begin
|
397 |
{$IFDEF LICENSE}
|
398 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
399 |
OleError(CLASS_E_NOTLICENSED);
|
400 |
{$ENDIF}
|
401 |
FSourceToHTML.InputStream.CopyFrom(StOleVariantToStream(Value, True), 0);
|
402 |
FSourceToHTML.InputStream.Position := 0;
|
403 |
end;
|
404 |
|
405 |
procedure TStToHTML.Set_StringMarkers(const Value: IStStringList);
|
406 |
var
|
407 |
MS : TStream;
|
408 |
begin
|
409 |
{$IFDEF LICENSE}
|
410 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
411 |
OleError(CLASS_E_NOTLICENSED);
|
412 |
{$ENDIF}
|
413 |
MS := nil;
|
414 |
try
|
415 |
MS := StOleVariantToStream(Value.Stream, True);
|
416 |
FSourceToHTML.StringMarkers.LoadFromStream(MS);
|
417 |
finally
|
418 |
MS.Free;
|
419 |
end;
|
420 |
end;
|
421 |
|
422 |
procedure TStToHTML.Set_WordDelimeters(const Value: WideString);
|
423 |
begin
|
424 |
{$IFDEF LICENSE}
|
425 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
426 |
OleError(CLASS_E_NOTLICENSED);
|
427 |
{$ENDIF}
|
428 |
FSourceToHTML.WordDelimiters := Value;
|
429 |
end;
|
430 |
|
431 |
{ ********** TStSourceToHTML Methods ***************************************************** }
|
432 |
procedure TStToHTML.Clear;
|
433 |
begin
|
434 |
{$IFDEF LICENSE}
|
435 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
436 |
OleError(CLASS_E_NOTLICENSED);
|
437 |
{$ENDIF}
|
438 |
TMemoryStream(FSourceToHTML.InputStream).Clear;
|
439 |
end;
|
440 |
|
441 |
procedure TStToHTML.GenerateHTML;
|
442 |
begin
|
443 |
{$IFDEF LICENSE}
|
444 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
445 |
OleError(CLASS_E_NOTLICENSED);
|
446 |
{$ENDIF}
|
447 |
FSourceToHTML.GenerateHTML;
|
448 |
end;
|
449 |
|
450 |
procedure TStToHTML.LoadFromFile(const FileName: WideString);
|
451 |
begin
|
452 |
{$IFDEF LICENSE}
|
453 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
454 |
OleError(CLASS_E_NOTLICENSED);
|
455 |
{$ENDIF}
|
456 |
TMemoryStream(FSourceToHTML.InputStream).LoadFromFile(FileName);
|
457 |
end;
|
458 |
|
459 |
procedure TStToHTML.SaveToFile(const FileName: WideString);
|
460 |
begin
|
461 |
{$IFDEF LICENSE}
|
462 |
if (not FIsLicensed) or (not COMHasBeenLicensed) then
|
463 |
OleError(CLASS_E_NOTLICENSED);
|
464 |
{$ENDIF}
|
465 |
TMemoryStream(FSourceToHTML.OutputStream).SaveToFile(FileName);
|
466 |
end;
|
467 |
|
468 |
function TStToHTML.License(const Key: WideString): WordBool;
|
469 |
begin
|
470 |
{$IFDEF LICENSE}
|
471 |
Result := COMIsValidKey(Key);
|
472 |
|
473 |
{ License the objects used in this class }
|
474 |
FKeywords.License(Key);
|
475 |
FCommentMarkers.License(Key);
|
476 |
FEmbeddedHTML.License(Key);
|
477 |
FPageFooter.License(Key);
|
478 |
FPageHeader.License(Key);
|
479 |
FStringMarkers.License(Key);
|
480 |
|
481 |
{$ELSE}
|
482 |
Result := True;
|
483 |
{$ENDIF}
|
484 |
FIsLicensed := Result;
|
485 |
end;
|
486 |
|
487 |
initialization
|
488 |
TAutoObjectFactory.Create(ComServer, TStToHTML, Class_StToHTML, ciMultiInstance, tmBoth);
|
489 |
end.
|