-
Notifications
You must be signed in to change notification settings - Fork 1
/
cahtml.pas
1186 lines (1059 loc) · 35.3 KB
/
cahtml.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit caHTML;
{$INCLUDE ca.inc}
interface
uses
Windows, SysUtils, Messages, Classes, caUtils, caClasses, caMatrix, Graphics,
caGraphics;
type
TcaHTMLAlignment = (haLeft, haRight, haTop, haTexttop, haMiddle,
haAbsMiddle, haBaseline, haBottom, haAbsBottom);
//----------------------------------------------------------------------------
// TcaHTMLFont
//----------------------------------------------------------------------------
TcaFontNumber = 0..3;
TcaHTMLFont = class(TObject)
private
FBold: Boolean;
FColor: String;
FSize: Integer;
FTypeFace: String;
public
procedure Assign(ASourceFont: TcaHTMLFont);
property Bold: Boolean read FBold write FBold;
property Color: String read FColor write FColor;
property Size: Integer read FSize write FSize;
property TypeFace: String read FTypeFace write FTypeFace;
end;
//----------------------------------------------------------------------------
// TcaHTML
//----------------------------------------------------------------------------
TcaHTML = class(TcaStringList)
private
FDefaultCellHeight: Integer;
FFontBold: Boolean;
FFont1: TcaHTMLFont;
FFont2: TcaHTMLFont;
FFont3: TcaHTMLFont;
function GetAlignment(AAlign: TcaHTMLAlignment): String;
procedure AddHeading(ALevel: Integer; const AText: String);
procedure SetFont(const ABold: Boolean; const AColorName: String; ASize: Integer; ATypeFace: String);
public
constructor Create;
destructor Destroy; override;
procedure Blank;
procedure Body(ABackColor: String = ''; const ABackImage: String = ''; AOnLoad: String = '';
ALink: String = ''; AVLink: String = ''; AALink: String = ''; ATextColor: String = '');
procedure Bold(const AText: String = '');
procedure CheckBox(const AName, AText: String; AChecked: Boolean; AFontNumber: TcaFontNumber = 0);
procedure Data(AWidth: Integer; AHeight: Integer = 0; AAlign: TcaHTMLAlignment = haLeft; AText: String = '';
AFontNumber: TcaFontNumber = 0; ABackColor: String = '';
AVAlign: TcaHTMLAlignment = haMiddle; AEndData: Boolean = True);
procedure EndBody;
procedure EndBold;
procedure EndData;
procedure EndFont;
procedure EndForm;
procedure EndHead;
procedure EndHRef;
procedure EndHTML;
procedure EndItalic;
procedure EndOrderedList;
procedure EndPara;
procedure EndRow;
procedure EndSelect;
procedure EndTable;
procedure EndUnderline;
procedure EndUnOrderedList;
procedure Font(AFontNumber: TcaFontNumber); overload;
procedure Font(const ABold: Boolean; const AColorName: String; ASize: Integer; const ATypeFace: String); overload;
procedure Form(const AName, AAction: String; const AMethod: String = 'POST');
procedure H1(const AText: String);
procedure H2(const AText: String);
procedure H3(const AText: String);
procedure H4(const AText: String);
procedure H5(const AText: String);
procedure H6(const AText: String);
procedure Head;
procedure HiddenField(const AName, AValue: String);
procedure HorzRule;
procedure HRef(const AURL: String; const ATarget: String = '';
const AOnMouseOver: String = ''; const AOnMouseOut: String = '';
const AOnMouseDown: String = ''; const AOnMouseUp: String = '');
procedure HTML;
procedure HTMLHead(const ATitle: String);
procedure Image(const AImage: String; AWidth: Integer = 0; AHeight: Integer = 0; ABorder: Integer = 0;
const AOnClick: String = ''; AAlign: TcaHTMLAlignment = haLeft; const AAlt: String = '';
AEndHRef: Boolean = False);
procedure RadioOption(const AName, AText, AValue: String; AChecked: Boolean; AFontNumber: Integer = 0);
procedure InputText(const AName: String; AValue: String = ''; ASize: Integer = 0;
AMaxLength: Integer = 0; APassword: Boolean = False);
procedure Italic(const AText: String = '');
procedure ListItem(const AText: String);
procedure OrderedList;
procedure Para(const AText: String = ''; AFontNumber: TcaFontNumber = 0);
procedure Row;
procedure Select(AName: String; ASize: Integer);
procedure SelectOption(const AText, AValue: String; ASelected: Boolean = False);
procedure SubmitButton(const AName, ACaption: String);
procedure Table(AWidth: Integer; AUsesPercent: Boolean = False; ABorder: Integer = 0; AHeight: Integer = 0; AExtraHTML: String = '');
procedure TextArea(const AName, AValue: String; ACols, ARows: Integer; AFontNumber: TcaFontNumber = 0);
procedure Title(const AText: String);
procedure Underline;
procedure UnOrderedList;
property DefaultCellHeight: Integer read FDefaultCellHeight write FDefaultCellHeight;
property Font1: TcaHTMLFont read FFont1;
property Font2: TcaHTMLFont read FFont2;
property Font3: TcaHTMLFont read FFont3;
end;
//----------------------------------------------------------------------------
// TcaWebPage
//----------------------------------------------------------------------------
TcaProcessWebTagEvent = procedure(Sender: TObject; const TagStr: String; var NewStr: String) of object;
TcaWebPage = class(TObject)
private
FAppName: String;
FBackColor: String;
FBackImage: String;
FDebugTables: Boolean;
FDocsFolder: String;
FHiddenFields: TStrings;
FHoverColor: String;
FLAlign: TcaHTMLAlignment;
FLinkActiveColor: String;
FLinkColor: String;
FLinkVisitedColor: String;
FLWidth: Integer;
FOnLoad: String;
FOnProcessTag: TcaProcessWebTagEvent;
FPage: TcaHTML;
FRadioName: String;
FRAlign: TcaHTMLAlignment;
FRWidth: Integer;
FScriptsFolder: String;
FText: String;
FTextColor: String;
function GetFont1: TcaHTMLFont;
function GetFont2: TcaHTMLFont;
function GetFont3: TcaHTMLFont;
function GetHTML: String;
function MakeHelpLink(const ACaption, AHelp: String): String;
function CleanText(const AText: String): String;
function CleanURL(const AText: String): String;
procedure FindTags(const S: String; var Tag1, Tag2: Integer);
procedure ProcessTags;
function GetDefaultCellHeight: Integer;
procedure SetDefaultCellHeight(const Value: Integer);
protected
function GetPageName: String; virtual;
function BuildLinkURL(const AFromSuffix, AToSuffix, AExtra: String): String;
procedure BuildBackLink(const AText: String);
procedure BuildLink(const AText, AFromSuffix, AToSuffix, AExtra: String);
procedure BuildLinkImage(const AImage, AURL, ATarget, AStatus, AAlt: String;
AUseRow: Boolean = True; AUseTable: Boolean = True);
procedure BuildLinkText(const AText: String; AFontNumber: TcaFontNumber = 0);
procedure BuildSubmitLink(const AText, AToPage: String);
procedure BuildPage; virtual;
procedure DoGetTableExtraHTML(var AExtraHTML: String); virtual;
procedure DoProcessTag(const TagStr: String; var NewStr: String); virtual;
public
constructor Create;
destructor Destroy; override;
procedure BeginForm; virtual;
procedure BeginPage(const ATitle: String; AFontNumber: TcaFontNumber = 0; AKillFocusRect: Boolean = False);
procedure BeginRadio(const ACaption, AName, AHelp: String; AFontNumber: TcaFontNumber = 0);
procedure BeginSelect(const ACaption, AName, AHelp: String; AFontNumber: TcaFontNumber = 0);
procedure BeginTable(AWidth: Integer; AUsesPercent: Boolean = False; ABorder: Integer = 0; AHeight: Integer = 0);
procedure BeginText;
procedure BlankRow;
procedure DoubleText(const ALeftText, ARightText: String; AFontNumber: TcaFontNumber = 0);
procedure EndFont;
procedure EndForm;
procedure EndPage;
procedure EndPara;
procedure EndRadio;
procedure EndSelect;
procedure EndTable;
procedure EndText(AFontNumber: TcaFontNumber = 0);
procedure LeftText(const AText: String; AFontNumber: TcaFontNumber = 0);
procedure LoadFromFile(const AFileName: String);
procedure Para(const AText: String = ''; AFontNumber: TcaFontNumber = 0);
procedure Radio(const AText, AValue: String; AChecked: Boolean; AFontNumber: TcaFontNumber = 0);
procedure RightText(const AText: String; AFontNumber: TcaFontNumber = 0);
procedure Select(const AText, AValue: String; ASelected: Boolean = False);
procedure AddText(const AText: String);
procedure TextArea(const AName, AValue: String; ACols, ARows: Integer; AFontNumber: TcaFontNumber = 0);
procedure TextLine(const AText: String; AFontNumber: TcaFontNumber = 0);
property BackColor: String read FBackColor write FBackColor;
property BackImage: String read FBackImage write FBackImage;
property DebugTables: Boolean read FDebugTables write FDebugTables;
property DefaultCellHeight: Integer read GetDefaultCellHeight write SetDefaultCellHeight;
property DocsFolder: String read FDocsFolder write FDocsFolder;
property Font1: TcaHTMLFont read GetFont1;
property Font2: TcaHTMLFont read GetFont2;
property Font3: TcaHTMLFont read GetFont3;
property HoverColor: String read FHoverColor write FHoverColor;
property HTML: String read GetHTML;
property LAlign: TcaHTMLAlignment read FLAlign write FLAlign;
property LinkActiveColor: String read FLinkActiveColor write FLinkActiveColor;
property LinkColor: String read FLinkColor write FLinkColor;
property LinkVisitedColor: String read FLinkVisitedColor write FLinkVisitedColor;
property LWidth: Integer read FLWidth write FLWidth;
property OnLoad: String read FOnLoad write FOnLoad;
property OnProcessTag: TcaProcessWebTagEvent read FOnProcessTag write FOnProcessTag;
property Page: TcaHTML read FPage;
property PageName: String read GetPageName;
property RAlign: TcaHTMLAlignment read FRAlign write FRAlign;
property RWidth: Integer read FRWidth write FRWidth;
property ScriptsFolder: String read FScriptsFolder write FScriptsFolder;
property TextColor: String read FTextColor write FTextColor;
end;
function Lorum: String;
function PostModern: String;
implementation
function Lorum: String;
begin
Result := 'lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem nonummy ';
Result := Result + 'nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat. ut ';
Result := Result + 'wisis enim ad minim veniam, quis nostrud exerci tution ullamcorper suscipit ';
Result := Result + 'lobortis nisl ut aliquip ex ea commodo consequat. duis te feugifacilisi. ';
Result := Result + 'duis autem dolor in hendrerit in vulputate velit esse molestie consequat, ';
Result := Result + 'vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et ';
Result := Result + 'iusto odio dignissim qui blandit praesent luptatum zzril delenit au gue ';
Result := Result + 'duis dolore te feugat nulla facilisi. ut wisi enim ad minim veniam, quis ';
Result := Result + 'nostrud exerci taion ullamcorper suscipit lobortis nisl ut aliquip ex en ';
Result := Result + 'commodo consequat.';
end;
function PostModern: String;
begin
Result := 'Latin-looking words arranged in nonsensical sentences, set in columns to give the ';
Result := Result + 'appearance of text on a page. Dummy text is used by the designer to help ';
Result := Result + 'approximate the look of a page at a stage in the design process before the ';
Result := Result + 'written text has been received. This way the designer is able, in a very real ';
Result := Result + 'sense, to shape the material presence of words before they are written and before ';
Result := Result + 'their meaning is known. Conventionally, due to constraints of time, ability, budget, ';
Result := Result + 'and habit, the designer is not the author. So conventionally, the student of ';
Result := Result + 'typography is not encouraged to write (or even read prepared copy) which would waste ';
Result := Result + 'valuable time spent getting to grips with the mechanics of text layout. Such ';
Result := Result + 'established working/teaching methods increase the danger of the typographer ';
Result := Result + 'becoming detached from the meaning of texts. The treatment of copy in purely ';
Result := Result + 'formal terms, reduced to blocks of texture on a page, has lead to the typographer''s ';
Result := Result + 'obsession with craft and disregard of meaning. Dummy text is text that is not ';
Result := Result + 'meant to be read, but only looked at; a shape. The choice of latin is crucial to ';
Result := Result + 'this function in that it is a dead language. Working with dummy text, the ';
Result := Result + 'designer only brings into play part of his/her array of tools/skills to convey ';
Result := Result + 'meaning.';
end;
//----------------------------------------------------------------------------
// TcaHTMLFont
//----------------------------------------------------------------------------
procedure TcaHTMLFont.Assign(ASourceFont: TcaHTMLFont);
begin
Bold := ASourceFont.Bold;
Color := ASourceFont.Color;
Size := ASourceFont.Size;
TypeFace := ASourceFont.TypeFace;
end;
//----------------------------------------------------------------------------
// TcaHTML
//----------------------------------------------------------------------------
constructor TcaHTML.Create;
begin
inherited;
FFont1 := TcaHTMLFont.Create;
FFont2 := TcaHTMLFont.Create;
FFont3 := TcaHTMLFont.Create;
end;
destructor TcaHTML.Destroy;
begin
FFont1.Free;
FFont2.Free;
FFont3.Free;
inherited;
end;
procedure TcaHTML.AddHeading(ALevel: Integer; const AText: String);
begin
Add(Format('<h%d>%s</h%d>', [ALevel, AText, ALevel]));
end;
procedure TcaHTML.Blank;
begin
Add('<br>');
end;
procedure TcaHTML.Bold(const AText: String = '');
var
BoldStr: String;
begin
BoldStr := '<b>';
if AText <> '' then BoldStr := BoldStr + Format('%s</b>', [AText]);
Add(BoldStr);
end;
procedure TcaHTML.H1(const AText: String);
begin
AddHeading(1, AText);
end;
procedure TcaHTML.H2(const AText: String);
begin
AddHeading(2, AText);
end;
procedure TcaHTML.H3(const AText: String);
begin
AddHeading(3, AText);
end;
procedure TcaHTML.H4(const AText: String);
begin
AddHeading(4, AText);
end;
procedure TcaHTML.H5(const AText: String);
begin
AddHeading(5, AText);
end;
procedure TcaHTML.H6(const AText: String);
begin
AddHeading(6, AText);
end;
procedure TcaHTML.HTMLHead(const ATitle: String);
begin
HTML;
Head;
Title(ATitle);
EndHead;
end;
procedure TcaHTML.HorzRule;
begin
Add('<hr>');
end;
procedure TcaHTML.Italic(const AText: String = '');
var
ItalicStr: String;
begin
ItalicStr := '<i>';
if AText <> '' then ItalicStr := ItalicStr + Format('%s</i>', [AText]);
Add(ItalicStr);
end;
procedure TcaHTML.Title(const AText: String);
begin
Add(Format('<title>%s</title>', [AText]));
end;
procedure TcaHTML.EndHead;
begin
Add('</head>');
end;
procedure TcaHTML.Head;
begin
Add('<head>');
end;
procedure TcaHTML.EndHTML;
begin
Add('</html>');
end;
procedure TcaHTML.HTML;
begin
Add('<html>');
end;
procedure TcaHTML.EndBody;
begin
Add('</body>');
end;
procedure TcaHTML.Body(ABackColor: String = ''; const ABackImage: String = ''; AOnLoad: String = '';
ALink: String = ''; AVLink: String = ''; AALink: String = ''; ATextColor: String = '');
var
BodyStr: String;
begin
BodyStr := '<body ';
if ABackColor <> '' then
BodyStr := BodyStr + Format('bgcolor="%s" ', [ABackColor]);
if ABackImage <> '' then
BodyStr := BodyStr + Format('background="%s" ', [ABackImage]);
if AOnLoad <> '' then
BodyStr := BodyStr + Format('onload="%s" ', [AOnLoad]);
if ALink <> '' then
BodyStr := BodyStr + Format('link="%s" ', [ALink]);
if AVLink <> '' then
BodyStr := BodyStr + Format('vlink="%s" ', [AVLink]);
if AALink <> '' then
BodyStr := BodyStr + Format('alink="%s" ', [AALink]);
if ATextColor <> '' then
BodyStr := BodyStr + Format('text="%s" ', [ATextColor]);
BodyStr := Trim(BodyStr) + '>';
Add(BodyStr);
end;
procedure TcaHTML.Data(AWidth: Integer; AHeight: Integer = 0; AAlign: TcaHTMLAlignment = haLeft; AText: String = '';
AFontNumber: TcaFontNumber = 0; ABackColor: String = '';
AVAlign: TcaHTMLAlignment = haMiddle; AEndData: Boolean = True);
var
AlignStr: String;
VAlignStr: String;
DataStr: String;
CellHeight: Integer;
begin
if AHeight = 0 then
CellHeight := FDefaultCellHeight
else
CellHeight := AHeight;
AlignStr := GetAlignment(AAlign);
VAlignStr := GetAlignment(AVAlign);
if AText = '' then
begin
DataStr := Format('<td width="%d" align="%s" valign="%s" ', [AWidth, AlignStr, VAlignStr]);
if CellHeight <> 0 then DataStr := DataStr + Format('height="%d" ', [CellHeight]);
if ABackColor <> '' then DataStr := DataStr + Format('bgcolor="%s" ', [ABackColor]);
DataStr := Trim(DataStr) + '>';
Add(DataStr);
end
else
begin
AText := StringReplace(AText, '_', ' ', [rfReplaceAll]);
DataStr := Format('<td width="%d" align="%s" ', [AWidth, AlignStr]);
if CellHeight <> 0 then DataStr := DataStr + Format('height="%d" ', [CellHeight]);
if ABackColor <> '' then DataStr := DataStr + Format('bgcolor="%s" ', [ABackColor]);
Add(Trim(DataStr) + '>');
if AFontNumber > 0 then Font(AFontNumber);
Add(AText);
if AFontNumber > 0 then EndFont;
if AEndData then EndData;
end;
end;
procedure TcaHTML.EndBold;
begin
Add('</b>');
end;
procedure TcaHTML.EndData;
begin
Add('</td>');
end;
procedure TcaHTML.EndFont;
begin
Add('</font>');
if FFontBold then
begin
Add('</b>');
FFontBold := False;
end;
end;
procedure TcaHTML.EndForm;
begin
Add('</form>');
end;
procedure TcaHTML.EndHRef;
begin
Add('</a>');
end;
procedure TcaHTML.EndItalic;
begin
Add('</i>');
end;
procedure TcaHTML.EndOrderedList;
begin
Add('</ol>');
end;
procedure TcaHTML.EndPara;
begin
Add('</p>');
end;
procedure TcaHTML.Image(const AImage: String; AWidth: Integer = 0; AHeight: Integer = 0; ABorder: Integer = 0;
const AOnClick: String = ''; AAlign: TcaHTMLAlignment = haLeft; const AAlt: String = '';
AEndHRef: Boolean = False);
var
ImgStr: String;
AlignStr: String;
begin
AlignStr := GetAlignment(AAlign);
ImgStr := Format('<img src="%s" ', [AImage]);
if AWidth <> 0 then ImgStr := ImgStr + Format('width="%d" ', [AWidth]);
if AHeight <> 0 then ImgStr := ImgStr + Format('height="%d" ', [AHeight]);
ImgStr := ImgStr + Format('border="%d" ', [ABorder]);
if AOnClick <> '' then ImgStr := ImgStr + Format('onclick="%s" ', [AOnClick]);
if AAlt <> '' then ImgStr := ImgStr + Format('alt="%s" ', [AAlt]);
ImgStr := Trim(ImgStr) + '>';
if AEndHRef then ImgStr := ImgStr + '</a>';
Add(ImgStr);
end;
procedure TcaHTML.Para(const AText: String = ''; AFontNumber: TcaFontNumber = 0);
begin
if AText <> '' then
begin
if AFontNumber > 0 then Font(AFontNumber);
Add('<p>' + AText + '</p>');
if AFontNumber > 0 then EndFont;
end
else
Add('<p>');
end;
procedure TcaHTML.Font(AFontNumber: TcaFontNumber);
begin
case AFontNumber of
1: SetFont(FFont1.Bold, FFont1.Color, FFont1.Size, FFont1.TypeFace);
2: SetFont(FFont2.Bold, FFont2.Color, FFont2.Size, FFont2.TypeFace);
3: SetFont(FFont3.Bold, FFont3.Color, FFont3.Size, FFont3.TypeFace);
end;
end;
procedure TcaHTML.Font(const ABold: Boolean; const AColorName: String; ASize: Integer; const ATypeFace: String);
begin
SetFont(ABold, AColorName, ASize, ATypeFace);
end;
procedure TcaHTML.SetFont(const ABold: Boolean; const AColorName: String; ASize: Integer; ATypeFace: String);
var
FontStr: String;
begin
FontStr := '<font ';
if AColorName <> '' then FontStr := FontStr + Format('color="%s" ', [AColorName]);
FontStr := FontStr + Format('size="%d" ', [ASize]);
if ATypeFace <> '' then FontStr := FontStr + Format('face="%s" ', [ATypeFace]);
FontStr := Trim(FontStr) + '>';
if ABold then
begin
FontStr := FontStr + '<b>';
FFontBold := True;
end;
Add(FontStr);
end;
procedure TcaHTML.EndRow;
begin
Add('</tr>');
Add('');
end;
function TcaHTML.GetAlignment(AAlign: TcaHTMLAlignment): String;
begin
case AAlign of
haLeft: Result := 'Left';
haRight: Result := 'Right';
haTop: Result := 'Top';
haTexttop: Result := 'Texttop';
haMiddle: Result := 'Middle';
haAbsMiddle: Result := 'AbsMiddle';
haBaseline: Result := 'Baseline';
haBottom: Result := 'Bottom';
haAbsBottom: Result := 'AbsBottom';
else
Result := '';
end;
end;
procedure TcaHTML.Row;
begin
Add('<tr>');
end;
procedure TcaHTML.EndSelect;
begin
Add('</select>');
end;
procedure TcaHTML.EndTable;
begin
Add('</table>');
end;
procedure TcaHTML.EndUnOrderedList;
begin
Add('</ul>');
end;
procedure TcaHTML.EndUnderline;
begin
Add('</u>');
end;
procedure TcaHTML.Form(const AName, AAction: String; const AMethod: String = 'POST');
begin
Add(Format('<form name="%s" action="%s" method="%s">', [AName, AAction, AMethod]));
end;
procedure TcaHTML.HRef(const AURL: String; const ATarget: String = '';
const AOnMouseOver: String = ''; const AOnMouseOut: String = '';
const AOnMouseDown: String = ''; const AOnMouseUp: String = '');
var
HRefStr: String;
begin
HRefStr := Format('<a href="%s" ', [AURL]);
if ATarget <> '' then HRefStr := HRefStr + Format('target="%s" ', [ATarget]);
if AOnMouseOver <> '' then HRefStr := HRefStr + Format('OnMouseOver="%s" ', [AOnMouseOver]);
if AOnMouseOut <> '' then HRefStr := HRefStr + Format('OnMouseOut="%s" ', [AOnMouseOut]);
if AOnMouseDown <> '' then HRefStr := HRefStr + Format('OnMouseDown="%s" ', [AOnMouseDown]);
if AOnMouseUp <> '' then HRefStr := HRefStr + Format('OnMouseUp="%s" ', [AOnMouseUp]);
HRefStr := Trim(HRefStr) + '>';
Add(HRefStr);
end;
procedure TcaHTML.HiddenField(const AName, AValue: String);
var
HidPos: Integer;
Index: Integer;
PageStr: String;
begin
for Index := Count - 1 downto 0 do
begin
PageStr := Strings[Index];
HidPos := Pos(Format('<input type=hidden name="%s"', [AName]), PageStr);
if HidPos >= 1 then Self.Delete(Index);
end;
Add(Format('<input type=hidden name="%s" value="%s">', [AName, AValue]));
end;
procedure TcaHTML.RadioOption(const AName, AText, AValue: String; AChecked: Boolean; AFontNumber: Integer = 0);
var
RadioStr: String;
begin
RadioStr := Format('<input name="%s" type=radio value=%s ', [AName, AValue]);
if AChecked then RadioStr := RadioStr + 'checked ';
RadioStr := Trim(RadioStr) + '>';
Add(RadioStr);
Font(AFontNumber);
Add(AText);
EndFont;
end;
procedure TcaHTML.CheckBox(const AName, AText: String; AChecked: Boolean; AFontNumber: TcaFontNumber = 0);
var
CheckStr: String;
begin
CheckStr := Format('<input NAME="%s" type=checkbox value=checkbox ', [AName]);
if AChecked then CheckStr := CheckStr + 'checked ';
CheckStr := Trim(CheckStr) + '>';
Add(CheckStr);
Font(AFontNumber);
Add(AText);
EndFont;
end;
procedure TcaHTML.TextArea(const AName, AValue: String; ACols, ARows: Integer; AFontNumber: TcaFontNumber = 0);
var
TextAreaStr: String;
begin
TextAreaStr := Format('<textarea name="%s" cols="%d" rows="%d">', [AName, ACols, ARows]);
Font(AFontNumber);
Add(TextAreaStr);
Add(AValue);
Add('</textarea>');
EndFont;
end;
procedure TcaHTML.InputText(const AName: String; AValue: String = ''; ASize: Integer = 0;
AMaxLength: Integer = 0; APassword: Boolean = False);
var
InputStr: String;
begin
if APassword then
InputStr := '<input type=password '
else
InputStr := '<input type=text ';
if AName <> '' then InputStr := InputStr + Format('name="%s" ', [AName]);
if AValue <> '' then InputStr := InputStr + Format('value="%s" ', [AValue]);
if ASize <> 0 then InputStr := InputStr + Format('size="%d" ', [ASize]);
if AMaxLength <> 0 then InputStr := InputStr + Format('maxlength="%d" ', [AMaxLength]);
InputStr := Trim(InputStr) + '>';
Add(InputStr);
end;
procedure TcaHTML.ListItem(const AText: String);
begin
Add(Format('<li>%s', [AText]));
end;
procedure TcaHTML.OrderedList;
begin
Add('<ol>');
end;
procedure TcaHTML.Select(AName: String; ASize: Integer);
begin
Add(Format('<select name="%s" size="%d">', [AName, ASize]));
end;
procedure TcaHTML.SelectOption(const AText, AValue: String; ASelected: Boolean = False);
var
SelStr: String;
begin
SelStr := '';
if ASelected then SelStr := 'selected ';
Add(Format('<option %svalue="%s">%s</option>', [SelStr, AValue, AText]));
end;
procedure TcaHTML.SubmitButton(const AName, ACaption: String);
begin
Add(Format('<input type=submit name="%s" value="%s">', [AName, ACaption]));
end;
procedure TcaHTML.Table(AWidth: Integer; AUsesPercent: Boolean = False; ABorder: Integer = 0; AHeight: Integer = 0; AExtraHTML: String = '');
var
TblStr: String;
PctStr: String;
begin
TblStr := '<table ';
PctStr := '';
if AUsesPercent then PctStr := '%';
if AWidth <> 0 then TblStr := TblStr + Format('width="%d%s" ', [AWidth, PctStr]);
TblStr := TblStr + Format('border="%d" ', [ABorder]);
if AHeight <> 0 then TblStr := TblStr + Format('height="%d" ', [AHeight]);
TblStr := Trim(TblStr) + AExtraHTML + '>';
Add(TblStr);
end;
procedure TcaHTML.UnOrderedList;
begin
Add('<ul>');
end;
procedure TcaHTML.Underline;
begin
Add('<u>');
end;
//----------------------------------------------------------------------------
// TcaWebPage
//----------------------------------------------------------------------------
constructor TcaWebPage.Create;
begin
inherited;
FPage := TcaHTML.Create;
FLAlign := haRight;
FLWidth := 300;
FRAlign := haLeft;
FRWidth := 200;
FAppName := LowerCase(Utils.AppName);
FHiddenFields := TStringList.Create;
end;
destructor TcaWebPage.Destroy;
begin
FPage.Free;
FHiddenFields.Free;
inherited;
end;
procedure TcaWebPage.BeginPage(const ATitle: String; AFontNumber: TcaFontNumber = 0; AKillFocusRect: Boolean = False);
begin
FPage.Clear;
FPage.HTMLHead(CleanText(ATitle));
if FHoverColor <> '' then
begin
FPage.Add('<style type="text/css">');
FPage.Add('a:link, a:visited {text-decoration: none}');
FPage.Add(Format('a:hover {background: %s}', [FHoverColor]));
FPage.Add('a:focus {outline: none}');
FPage.Add('</style>');
end;
if AKillFocusRect then
begin
FPage.Add('<script>');
FPage.Add('<!-- cloaking enabled');
FPage.Add('function ssh() {');
FPage.Add('window.focus(); }');
FPage.Add('// cloaking disabled -->');
FPage.Add('</script>');
end;
FPage.Body(FBackColor, FBackImage, FOnLoad, FLinkColor, FLinkVisitedColor, FLinkActiveColor, FTextColor);
if AFontNumber > 0 then FPage.Font(AFontNumber);
if ATitle <> '' then FPage.Para(CleanText(ATitle));
if AFontNumber > 0 then EndFont;
end;
procedure TcaWebPage.EndPage;
begin
FPage.EndBody;
FPage.EndHTML;
end;
procedure TcaWebPage.BeginTable(AWidth: Integer; AUsesPercent: Boolean = False; ABorder: Integer = 0; AHeight: Integer = 0);
var
ExtraHTML: String;
begin
if FDebugTables then ABorder := 1;
ExtraHTML := '';
DoGetTableExtraHTML(ExtraHTML);
FPage.Table(AWidth, AUsesPercent, ABorder, AHeight, ExtraHTML);
end;
procedure TcaWebPage.EndTable;
begin
FPage.EndTable;
end;
procedure TcaWebPage.BeginSelect(const ACaption, AName, AHelp: String; AFontNumber: TcaFontNumber = 0);
begin
FPage.Row;
FPage.Data(FLWidth, 0, FLAlign, MakeHelpLink(ACaption, AHelp), AFontNumber);
FPage.Data(FRWidth, 0);
FPage.Select(AName, 1);
end;
procedure TcaWebPage.Select(const AText, AValue: String; ASelected: Boolean = False);
begin
FPage.SelectOption(CleanText(AText), AValue, ASelected);
end;
procedure TcaWebPage.EndSelect;
begin
FPage.EndSelect;
FPage.EndData;
FPage.EndRow;
end;
procedure TcaWebPage.BeginRadio(const ACaption, AName, AHelp: String; AFontNumber: TcaFontNumber = 0);
begin
FPage.Row;
FPage.Data(FLWidth, 0, FLAlign, MakeHelpLink(ACaption, AHelp), AFontNumber);
FPage.Data(FRWidth);
FRadioName := AName;
end;
procedure TcaWebPage.Radio(const AText, AValue: String; AChecked: Boolean; AFontNumber: TcaFontNumber = 0);
begin
FPage.RadioOption(FRadioName, CleanText(AText), AValue, AChecked, AFontNumber);
end;
procedure TcaWebPage.EndRadio;
begin
FPage.EndData;
FPage.EndRow;
end;
procedure TcaWebPage.BlankRow;
begin
FPage.Row;
FPage.Data(FLWidth, 0, FLAlign, '_');
FPage.Data(FRWidth, 0, FRAlign, '_');
FPage.EndRow;
end;
procedure TcaWebPage.LeftText(const AText: String; AFontNumber: TcaFontNumber = 0);
begin
FPage.Row;
FPage.Data(FLWidth, 0, FLAlign, CleanText(AText), AFontNumber);
FPage.Data(FRWidth, 0, FRAlign, '_');
FPage.EndRow;
end;
procedure TcaWebPage.RightText(const AText: String; AFontNumber: TcaFontNumber = 0);
begin
FPage.Row;
FPage.Data(FLWidth, 0, FLAlign, '_');
FPage.Data(FRWidth, 0, FRAlign, CleanText(AText), AFontNumber);
FPage.EndRow;
end;
procedure TcaWebPage.DoubleText(const ALeftText, ARightText: String; AFontNumber: TcaFontNumber = 0);
begin
FPage.Row;
FPage.Data(FLWidth, 0, FLAlign, CleanText(ALeftText), AFontNumber);
FPage.Data(FRWidth, 0, FRAlign, CleanText(ARightText), AFontNumber);
FPage.EndRow;
end;
procedure TcaWebPage.Para(const AText: String = ''; AFontNumber: TcaFontNumber = 0);
begin
FPage.Para(CleanText(AText), AFontNumber);
end;
function TcaWebPage.CleanText(const AText: String): String;
var
S: String;
begin
S := StringReplace(AText, '%20', ' ', [rfReplaceAll]);
Result := StringReplace(S, '_', ' ', [rfReplaceAll]);
end;
function TcaWebPage.CleanURL(const AText: String): String;
begin
Result := StringReplace(AText, ' ', '%20', [rfReplaceAll]);
end;
procedure TcaWebPage.BeginText;
begin
FText := '';
end;
procedure TcaWebPage.EndText(AFontNumber: TcaFontNumber = 0);
begin
FPage.Font(AFontNumber);
FPage.Add(FText);
FPage.EndFont;
FText := '';
end;
procedure TcaWebPage.AddText(const AText: String);
begin
FText := FText + ' ' + AText;
end;
procedure TcaWebPage.BeginForm;
begin
Page.Form(PageName, '/' + FScriptsFolder + '/' + Utils.AppName);
end;
procedure TcaWebPage.BuildLinkText(const AText: String; AFontNumber: TcaFontNumber = 0);
begin
Page.Bold;
Page.Underline;
TextLine(AText, AFontNumber);
Page.EndUnderline;
Page.EndBold;
end;
procedure TcaWebPage.BuildBackLink(const AText: String);
begin
BeginTable(360);
BlankRow;
FPage.Row;
FPage.Data(120);
FPage.EndData;
FPage.Data(120);
FPage.HRef('javascript:history.back();');
BuildLinkText(AText, 3);
FPage.EndHRef;
FPage.EndData;
FPage.EndRow;
EndTable;
end;
procedure TcaWebPage.BuildLink(const AText, AFromSuffix, AToSuffix, AExtra: String);
var
FromHRef: String;
ToHRef: String;
begin
BeginTable(360);
BlankRow;
FPage.Row;
FPage.Data(120);
FPage.EndData;
FPage.Data(120);
FromHRef := Utils.AppName + '?pagefrom=' + PageName + AFromSuffix;
ToHRef := '&pageto=' + PageName + AToSuffix;
FPage.HRef(FromHRef + ToHRef + '&' + AExtra);
BuildLinkText(AText, 3);
FPage.EndHRef;
FPage.EndData;
FPage.EndRow;
EndTable;
end;
procedure TcaWebPage.BuildLinkImage(const AImage, AURL, ATarget, AStatus, AAlt: String;
AUseRow: Boolean = True; AUseTable: Boolean = True);
var
OnMouseOver: String;
OnMouseOut: String;
begin
if AUseTable then BeginTable(500, False, 0, 40);
if AUseRow then Page.Row;
Page.Data(500, 0, haRight, '', 0, '', haMiddle, False);
OnMouseOver := Format('window.status=''%s''; return true;', [AStatus]);
OnMouseOut := 'window.status=''''';
Page.HRef(AURL, ATarget, OnMouseOver, OnMouseOut);
Page.Image(AImage, 176, 40, 0, '', haBottom, AAlt);
Page.EndHRef;