?? iwhtmleng.pas
字號:
{***************************************************************************}
{ TMS IntraWeb Component Pack Pro }
{ for Delphi & C++Builder }
{ version 2.2 }
{ }
{ written by TMS Software }
{ copyright ?2002 - 2004 }
{ Email : info@tmssoftware.com }
{ Web : http://www.tmssoftware.com }
{ }
{ The source code is given as is. The author is not responsible }
{ for any possible damage done due to the use of this code. }
{ The component can be freely used in any application. The complete }
{ source code remains property of the author and may not be distributed, }
{ published, given or sold in any form as such. No parts of the source }
{ code can be included in any other component or application without }
{ written authorization of the author. }
{***************************************************************************}
function Text2Color(s:string): TColor;
begin
Result := clBlack;
if (s='clred') then result:=clred else
if (s='clblack') then result:=clblack else
if (s='clblue') then result:=clblue else
if (s='clgreen') then result:=clgreen else
if (s='claqua') then result:=claqua else
if (s='clyellow') then result:=clyellow else
if (s='clfuchsia') then result:=clfuchsia else
if (s='clwhite') then result:=clwhite else
if (s='cllime') then result:=cllime else
if (s='clsilver') then result:=clsilver else
if (s='clgray') then result:=clgray else
if (s='clolive') then result:=clolive else
if (s='clnavy') then result:=clnavy else
if (s='clpurple') then result:=clpurple else
if (s='clteal') then result:=clteal else
if (s='clmaroon') then result:=clmaroon;
if Result <> clBlack then Exit;
if (s='clbackground') then result:=clbackground else
if (s='clactivecaption') then result:=clactivecaption else
if (s='clinactivecaption') then result:=clinactivecaption else
if (s='clmenu') then result:=clmenu else
if (s='clwindow') then result:=clwindow else
if (s='clwindowframe') then result:=clwindowframe else
if (s='clmenutext') then result:=clmenutext else
if (s='clwindowtext') then result:=clwindowtext else
if (s='clcaptiontext') then result:=clcaptiontext else
if (s='clactiveborder') then result:=clactiveborder else
if (s='clinactiveborder') then result:=clinactiveborder else
if (s='clappworkspace') then result:=clappworkspace else
if (s='clhighlight') then result:=clhighlight else
if (s='clhighlighttext') then result:=clhighlighttext else
if (s='clbtnface') then result:=clbtnface else
if (s='clbtnshadow') then result:=clbtnshadow else
if (s='clgraytext') then result:=clgraytext else
if (s='clbtntext') then result:=clbtntext else
if (s='clinactivecaptiontext') then result:=clinactivecaptiontext else
if (s='clbtnhighlight') then result:=clbtnhighlight else
if (s='cl3ddkshadow') then result:=clgraytext else
if (s='cl3dlight') then result:=cl3dlight else
if (s='clinfotext') then result:=clinfotext else
if (s='clinfobk') then result:=clinfobk;
end;
function HexVal(s:string): Integer;
var
i,j: Integer;
begin
if Length(s) < 2 then
begin
Result := 0;
Exit;
end;
if s[1] >= 'A' then
i := ord(s[1]) - ord('A') + 10
else
i := ord(s[1]) - ord('0');
if s[2] >= 'A' then
j := ord(s[2]) - ord('A') + 10
else
j := ord(s[2]) - ord('0');
Result := i shl 4 + j;
end;
function Hex2Color(s:string): TColor;
var
r,g,b: Integer;
begin
r := Hexval(Copy(s,2,2));
g := Hexval(Copy(s,4,2)) shl 8;
b := Hexval(Copy(s,6,2)) shl 16;
Result := TColor(b + g + r);
end;
function IPos(su,s:string):Integer;
begin
Result := Pos(UpperCase(su),UpperCase(s));
end;
function IStrToInt(s:string):Integer;
var
Err,Res: Integer;
begin
Val(s,Res,Err);
Result := Res;
end;
function DBTagStrip(s:string):string;
var
i,j: Integer;
begin
i := Pos('<#',s);
if i > 0 then
begin
Result := Copy(s,1,i - 1);
Delete(s,1,i);
j := Pos('>',s);
if j > 0 then
Delete(s,j,1);
Result := Result + s;
end
else
Result := s;
end;
function CRLFStrip(s:string;break:boolean):string;
var
i: Integer;
begin
Result := '';
for i := 1 to Length(s) do
begin
if not (s[i] in [#13,#10]) then
Result := Result + s[i]
else
if (s[i] = #13) and break then
Result := Result + '<BR>';
end;
end;
function VarPos(su,s:string;var Res:Integer):Integer;
begin
Res := Pos(su,s);
Result := Res;
end;
function TagReplaceString(const Srch,Repl:string;var Dest:string):Boolean;
var
i: Integer;
begin
i := IPos(srch,dest);
if i > 0 then
begin
Result := True;
Delete(Dest,i,Length(Srch));
Dest := Copy(Dest,1,i-1) + Repl + Copy(Dest,i,Length(Dest));
end
else
Result := False;
end;
function HTMLDrawEx(Canvas:TCanvas; s:string; fr:TRect;
FImages: TImageList;
XPos,YPos,FocusLink,HoverLink,ShadowOffset: Integer;
CheckHotSpot,CheckHeight,Print,Selected,Blink,HoverStyle,WordWrap: Boolean;
ResFactor:Double;
URLColor,HoverColor,HoverFontColor,ShadowColor:TColor;
var AnchorVal,StripVal,FocusAnchor: string;
var XSize,YSize,HyperLinks,MouseLink: Integer;
var HoverRect:TRect;ic: TIWHTMLPictureCache; pc: TIWPictureContainer): Boolean;
var
su: string;
r,dr,hr,rr,er: TRect;
htmlwidth,htmlheight: Integer;
Align: TAlignment;
PIndent: Integer;
OldFont: TFont;
CalcFont: TFont;
DrawFont: TFont;
OldCalcFont: TFont;
OldDrawFont: TFont;
Hotspot, ImageHotspot: Boolean;
Anchor,OldAnchor,MouseInAnchor,Error: Boolean;
bgcolor,paracolor,hvrcolor,hvrfntcolor,pencolor,blnkcolor,hifcol,hibcol: TColor;
LastAnchor,OldAnchorVal: string;
IMGSize: TPoint;
isSup,isSub,isPara,isShad: Boolean;
subh,suph,imgali,srchpos,hlcount,licount: Integer;
hrgn,holdfont: THandle;
ListIndex: Integer;
dtp: TDrawTextParams;
Invisible: Boolean;
FoundTag: Boolean;
{new for editing}
nnFit: Integer;
nnSize: TSize;
inspoint: Integer;
nndx: Pointer;
AltImg,ImgIdx,OldImgIdx: Integer;
DrawStyle: DWord;
procedure StartRotated(Canvas:TCanvas;Angle: Integer);
var
LFont:TLogFont;
begin
GetObject(Canvas.Font.Handle,SizeOf(LFont),Addr(LFont));
LFont.lfEscapement := Angle * 10;
LFont.lfOrientation := Angle * 10;
hOldFont:=SelectObject(Canvas.Handle,CreateFontIndirect(LFont));
end;
procedure EndRotated(Canvas:TCanvas);
begin
DeleteObject(SelectObject(Canvas.Handle,hOldFont));
end;
{$WARNINGS OFF}
function HTMLDrawLine(Canvas: TCanvas;var s:string;r: TRect;Calc:Boolean;
var w,h,subh,suph,imgali:Integer;var Align:TAlignment; var PIndent: Integer;
XPos,YPos:Integer;var Hotspot,ImageHotSpot:Boolean):string;
var
su,Res,TagProp,Prop,AltProp,Tagp,LineText:string;
cr: TRect;
linebreak,imgbreak,linkbreak: Boolean;
th,sw,indent,err,bmpx,bmpy: Integer;
TagPos,SpacePos,o,l: Integer;
bmp: TIWHTMLPicture;
ABitmap: TBitmap;
NewColor: TColor;
TagWidth,TagHeight,WordLen,WordLenEx,WordWidth: Integer;
TagChar: Char;
LengthFits, SpaceBreak: Boolean;
begin
Result := '';
LineText := '';
r.Bottom := r.Bottom - Subh;
w := 0;
sw := 0;
LineBreak := False;
ImgBreak := False;
LinkBreak := False;
HotSpot := False;
ImageHotSpot := False;
cr := r;
res := '';
if isPara and not Calc then
begin
Pencolor := Canvas.Pen.Color;
Canvas.Pen.color := Canvas.Brush.Color;
Canvas.Rectangle(fr.Left,r.Top,fr.Right,r.Top + h);
end;
while (Length(s) > 0) and not LineBreak and not ImgBreak do
begin
// get next word or till next HTML tag
TagPos := Pos('<',s);
if WordWrap then
SpacePos := Pos(' ',s)
else
SpacePos := 0;
if (Tagpos > 0) and ((SpacePos > TagPos) or (SpacePos = 0)) then
begin
su := Copy(s,1,TagPos - 1);
end
else
begin
if SpacePos > 0 then
su := Copy(s,1,SpacePos)
else
su := s;
end;
{$IFDEF TMSDEBUG}
DbgMsg(su+ '.');
{$ENDIF}
WordLen := Length(su);
while Pos(' ',su) > 0 do
begin
TagReplacestring(' ',' ',su);
end;
while Pos('<',su) > 0 do
begin
TagReplacestring('<','<',su);
end;
while Pos('>',su) > 0 do
begin
TagReplacestring('>','>',su);
end;
WordLenEx := Length(su);
if WordLen > 0 then
begin
th := Canvas.TextHeight(su);
if isSub and (subh < (th shr 2)) then subh := th shr 2;
if isSup and (suph < (th shr 2)) then suph := th shr 2;
if th > h then
h := th;
StripVal := StripVal + su;
if not Invisible then
begin
// draw mode
if not Calc then
begin
if isSup then
cr.Bottom := cr.Bottom - suph;
if isSub then
cr.Bottom := cr.Bottom + subh;
cr.Bottom := cr.Bottom - imgali;
if isShad then
begin
OffsetRect(cr,ShadowOffset,ShadowOffset);
NewColor := Canvas.Font.Color;
Canvas.Font.Color := ShadowColor;
DrawTextEx(Canvas.Handle,PChar(su),WordLenEx,cr,DrawStyle,nil);
Offsetrect(cr,-ShadowOffset,-ShadowOffset);
Canvas.Font.Color := NewColor;
end;
DrawTextEx(Canvas.Handle,PChar(su),WordLenEx,cr,DrawStyle,nil);
DrawTextEx(Canvas.Handle,PChar(su),WordLenEx,cr,DrawStyle or DT_CALCRECT,nil);
if Anchor and (Hyperlinks - 1 = FocusLink) then
FocusAnchor := LastAnchor;
{$IFDEF TMSDEBUG}
if Anchor then
DbgMsg('drawrect for '+anchorval+' = ['+inttostr(cr.Left)+':'+inttostr(cr.Top)+'] ['+inttostr(cr.right)+':'+inttostr(cr.bottom)+'] @ ['+inttostr(xpos)+':'+inttostr(ypos));
{$ENDIF}
if Error then
begin
Canvas.Pen.Color := clRed;
Canvas.Pen.Width := 1;
l := (cr.Left div 2) * 2;
if (l mod 4)=0 then o := 2 else o := 0;
Canvas.MoveTo(l,r.Bottom + o - 1);
while l < cr.Right do
begin
if o = 2 then o := 0 else o := 2;
Canvas.LineTo(l + 2,r.bottom + o - 1);
Inc(l,2);
end;
// if o = 2 then o := 0 else o := 2;
// Canvas.LineTo(l + 2,r.Bottom + o - 1);
end;
cr.Left := cr.Right;
cr.Right := r.Right;
cr.Bottom := r.Bottom;
cr.Top := r.Top;
end
else
begin
cr := r; //reinitialized each time !
DrawTextEx(Canvas.Handle,PChar(su),WordLenEx,cr,DrawStyle or DT_CALCRECT,nil);
// preparations for editing purposes
if (ypos > cr.Top) and (ypos < cr.bottom) and (xpos > w) then {scan charpos here}
begin
er := rect(w,cr.top,xpos,cr.bottom);
Fillchar(dtp,sizeof(dtp),0);
dtp.cbSize:=sizeof(dtp);
{$IFDEF DELPHI4_LVL}
GetTextExtentExPoint(Canvas.Handle,pChar(su),WordLenEx,xpos-w,@nnfit,nil,nnSize);
{$ELSE}
nndx:=nil; {fix for declaration error in Delphi 3 WINDOWS.PAS}
// GetTextExtentExPoint(Canvas.Handle,pChar(su),WordLenEx,xpos-w,nnfit,integer(nndx^),nnSize);
{$ENDIF}
{this will get the character pos of the insertion point}
if nnfit = WordLen then
InsPoint := InsPoint + WordLen
else
InsPoint := InsPoint + nnfit;
end;
{end of preparations for editing purposes}
{Calculated text width}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -