New property LinkFont added
https links now supported git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4325 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
ec22eb1154
commit
cb0209ced1
@ -26,12 +26,12 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
|
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
|
||||||
ExtCtrls, LCLIntf,AboutScrolltextunit;
|
ExtCtrls, LCLIntf,LCLTranslator,AboutScrolltextunit;
|
||||||
|
|
||||||
const
|
const
|
||||||
C_TEXTFILENAME = 'scrolling.txt';
|
C_TEXTFILENAME = 'scrolling.txt';
|
||||||
C_TEXTRESOURCENAME = 'scrolltext'; //Note: LResouces unit needed
|
C_TEXTRESOURCENAME = 'scrolltext'; //Note: LResources unit needed
|
||||||
C_VERSION = '1.0.0.0';
|
C_VERSION = '1.0.1.0';
|
||||||
|
|
||||||
type
|
type
|
||||||
TTextSource = (stStringlist, stTextfile, stResource);
|
TTextSource = (stStringlist, stTextfile, stResource);
|
||||||
@ -50,6 +50,7 @@ type
|
|||||||
FStepSize: integer;
|
FStepSize: integer;
|
||||||
FTimer: TTimer;
|
FTimer: TTimer;
|
||||||
FFont: TFont;
|
FFont: TFont;
|
||||||
|
FLinkFont:TFont;
|
||||||
FBackColor: TColor;
|
FBackColor: TColor;
|
||||||
fTextFileName: string;
|
fTextFileName: string;
|
||||||
fResourceName: string;
|
fResourceName: string;
|
||||||
@ -62,6 +63,7 @@ type
|
|||||||
procedure DrawScrollingText(Sender: TObject);
|
procedure DrawScrollingText(Sender: TObject);
|
||||||
procedure SetLines(AValue: TStrings);
|
procedure SetLines(AValue: TStrings);
|
||||||
procedure SetFont(AValue: TFont);
|
procedure SetFont(AValue: TFont);
|
||||||
|
procedure SetLinkFont(AValue: TFont);
|
||||||
protected
|
protected
|
||||||
procedure DoOnChangeBounds; override;
|
procedure DoOnChangeBounds; override;
|
||||||
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
|
||||||
@ -90,6 +92,8 @@ type
|
|||||||
property BackColor: TColor read fBackColor write fBackColor default clWindow;
|
property BackColor: TColor read fBackColor write fBackColor default clWindow;
|
||||||
// Sets the font properties of the scrolling text
|
// Sets the font properties of the scrolling text
|
||||||
property Font: TFont read fFont write SetFont;
|
property Font: TFont read fFont write SetFont;
|
||||||
|
// Sets the font properties of links in the scrolling text
|
||||||
|
property LinkFont: TFont read fLinkFont write SetLinkFont;
|
||||||
// Source of the text to display.
|
// Source of the text to display.
|
||||||
// If TextSource=stTextfile 'scrolling.txt' should be in the deployed app folder
|
// If TextSource=stTextfile 'scrolling.txt' should be in the deployed app folder
|
||||||
// if TextSource=stResource be sure to add LResources to your uses clause
|
// if TextSource=stResource be sure to add LResources to your uses clause
|
||||||
@ -119,6 +123,11 @@ begin
|
|||||||
fFont.Assign(AValue);
|
fFont.Assign(AValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TScrollingText.SetLinkFont(AValue: TFont);
|
||||||
|
begin
|
||||||
|
fLinkFont.Assign(AValue);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TScrollingText.SetLines(AValue: TStrings);
|
procedure TScrollingText.SetLines(AValue: TStrings);
|
||||||
begin
|
begin
|
||||||
fLines.Assign(AValue);
|
fLines.Assign(AValue);
|
||||||
@ -238,8 +247,8 @@ begin
|
|||||||
|
|
||||||
//reset buffer font
|
//reset buffer font
|
||||||
FBuffer.Canvas.Font := fFont;
|
FBuffer.Canvas.Font := fFont;
|
||||||
FBuffer.Canvas.Font.Style := [];
|
FBuffer.Canvas.Font.Style := fFont.Style;
|
||||||
FBuffer.Canvas.Font.Color := fFont.Color;// clBlack;
|
FBuffer.Canvas.Font.Color := fFont.Color;
|
||||||
|
|
||||||
//skip empty lines
|
//skip empty lines
|
||||||
if Length(s) > 0 then
|
if Length(s) > 0 then
|
||||||
@ -249,20 +258,24 @@ begin
|
|||||||
begin
|
begin
|
||||||
s := copy(s, 2, Length(s) - 1);
|
s := copy(s, 2, Length(s) - 1);
|
||||||
FBuffer.Canvas.Font.Style := [fsBold];
|
FBuffer.Canvas.Font.Style := [fsBold];
|
||||||
end
|
end;
|
||||||
else
|
|
||||||
begin
|
begin
|
||||||
//check for url
|
//check for url
|
||||||
if (Pos('http://', s) = 1) OR (Pos('mailto:', s) = 1) then
|
if (Pos('http://', s) <> 0)
|
||||||
|
OR (Pos('https://', s) <> 0)
|
||||||
|
OR (Pos('mailto:', s) <> 0) then
|
||||||
begin
|
begin
|
||||||
|
FBuffer.Canvas.Font := FLinkFont;
|
||||||
if i = FActiveLine then
|
if i = FActiveLine then
|
||||||
begin
|
begin
|
||||||
FBuffer.Canvas.Font.Style := [fsUnderline];
|
FBuffer.Canvas.Font.Style := FBuffer.Canvas.Font.Style+[fsUnderline];
|
||||||
FBuffer.Canvas.Font.Color := clRed;
|
//FBuffer.Canvas.Font.Color := clRed;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
FBuffer.Canvas.Font.Color := clBlue;
|
//FBuffer.Canvas.Font.Color := clBlue;
|
||||||
end;
|
end
|
||||||
|
else FBuffer.Canvas.Font := FFont;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
w := FBuffer.Canvas.TextWidth(s);
|
w := FBuffer.Canvas.TextWidth(s);
|
||||||
@ -279,7 +292,9 @@ end;
|
|||||||
function TScrollingText.ActiveLineIsURL: boolean;
|
function TScrollingText.ActiveLineIsURL: boolean;
|
||||||
begin
|
begin
|
||||||
if (FActiveLine > 0) and (FActiveLine < FLines.Count) then
|
if (FActiveLine > 0) and (FActiveLine < FLines.Count) then
|
||||||
Result := (Pos('http://', FLines[FActiveLine]) = 1) OR (Pos('mailto:', FLines[FActiveLine]) = 1)
|
Result := (Pos('http://', FLines[FActiveLine]) <> 0)
|
||||||
|
OR (Pos('https:', FLines[FActiveLine]) <> 0)
|
||||||
|
OR (Pos('mailto:', FLines[FActiveLine]) <> 0)
|
||||||
else
|
else
|
||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
@ -292,11 +307,38 @@ end;
|
|||||||
|
|
||||||
procedure TScrollingText.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
procedure TScrollingText.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
||||||
X, Y: integer);
|
X, Y: integer);
|
||||||
|
var
|
||||||
|
s:string;
|
||||||
begin
|
begin
|
||||||
inherited MouseDown(Button, Shift, X, Y);
|
inherited MouseDown(Button, Shift, X, Y);
|
||||||
|
if ActiveLineIsURL and
|
||||||
if ActiveLineIsURL then
|
((Pos('http://', FLines[FActiveLine]) OR (Pos('https://', FLines[FActiveLine]))<> 0)) then
|
||||||
OpenURL(FLines[FActiveLine]);
|
begin
|
||||||
|
s:=FLines[FActiveLine];
|
||||||
|
if (Pos(' ',s))=0 then s:=Copy(s,Pos('http://',s),MaxInt)
|
||||||
|
else begin
|
||||||
|
if Pos(' ',s)<Pos('http://',s) then s:=Copy(s,Pos('http://',s),MaxInt);
|
||||||
|
if (Pos(' ',s))=0 then s:=Copy(s,Pos('http://',s),MaxInt)
|
||||||
|
else s:=Copy(s,Pos('http://',s),(Pos(' ',s)-Pos('http://',s)));
|
||||||
|
end;
|
||||||
|
if (Pos(' ',s))=0 then s:=Copy(s,Pos('https://',s),MaxInt)
|
||||||
|
else begin
|
||||||
|
if Pos(' ',s)<Pos('https://',s) then s:=Copy(s,Pos('https://',s),MaxInt);
|
||||||
|
if (Pos(' ',s))=0 then s:=Copy(s,Pos('https://',s),MaxInt)
|
||||||
|
else s:=Copy(s,Pos('https://',s),(Pos(' ',s)-Pos('https://',s)));
|
||||||
|
end;
|
||||||
|
OpenURL(s);
|
||||||
|
end
|
||||||
|
else if ActiveLineIsURL and (Pos('mailto:', FLines[FActiveLine]) <> 0) then begin
|
||||||
|
s:=FLines[FActiveLine];
|
||||||
|
if (Pos(' ',s))=0 then s:=Copy(s,Pos('mailto:',s),MaxInt)
|
||||||
|
else begin
|
||||||
|
if Pos(' ',s)<Pos('mailto:',s) then s:=Copy(s,Pos('mailto:',s),MaxInt);
|
||||||
|
if (Pos(' ',s))=0 then s:=Copy(s,Pos('mailto:',s),MaxInt)
|
||||||
|
else s:=Copy(s,Pos('mailto:',s),(Pos(' ',s)-Pos('mailto:',s)));
|
||||||
|
end;
|
||||||
|
OpenURL(s);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TScrollingText.MouseMove(Shift: TShiftState; X, Y: integer);
|
procedure TScrollingText.MouseMove(Shift: TShiftState; X, Y: integer);
|
||||||
@ -325,7 +367,9 @@ begin
|
|||||||
FTimer.Interval := 30;
|
FTimer.Interval := 30;
|
||||||
FBuffer := TBitmap.Create;
|
FBuffer := TBitmap.Create;
|
||||||
FFont := TFont.Create;
|
FFont := TFont.Create;
|
||||||
|
FLinkFont := TFont.Create;
|
||||||
FFont.Size := 10;
|
FFont.Size := 10;
|
||||||
|
FLinkFont.Size := 10;
|
||||||
fBackColor := clWindow;
|
fBackColor := clWindow;
|
||||||
|
|
||||||
FStepSize := 1;
|
FStepSize := 1;
|
||||||
@ -363,6 +407,7 @@ begin
|
|||||||
FTimer.Free;
|
FTimer.Free;
|
||||||
FBuffer.Free;
|
FBuffer.Free;
|
||||||
FFont.Free;
|
FFont.Free;
|
||||||
|
FLinkFont.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user