📄 jvqlinklabel.pas
字号:
Result := Node.Text
else
raise ELinkLabelError.CreateRes(@RsEUnableToLocateMode);
end;
function TJvCustomLinkLabel.GetLinkColor: TColor;
begin
Result := FRenderer.LinkColor;
end;
function TJvCustomLinkLabel.GetLinkColorClicked: TColor;
begin
Result := FRenderer.LinkColorClicked;
end;
function TJvCustomLinkLabel.GetLinkColorHot: TColor;
begin
Result := FRenderer.LinkColorHot;
end;
function TJvCustomLinkLabel.GetLinkStyle: TFontStyles;
begin
Result := FRenderer.LinkStyle;
end;
function TJvCustomLinkLabel.GetTransparent: Boolean;
begin
Result := not (csOpaque in ControlStyle);
end;
procedure TJvCustomLinkLabel.HandleDynamicNode(out Source: string; const Node: TDynamicNode);
begin
if Assigned(Node) then
DoDynamicTagInit(Source, Node.Number);
end;
function TJvCustomLinkLabel.IsActiveLinkNodeClicked: Boolean;
begin
Result := Assigned(FActiveLinkNode);
if Result then
Result := FActiveLinkNode.State = lsClicked;
end;
procedure TJvCustomLinkLabel.Loaded;
begin
inherited Loaded;
FOriginalCursor := Cursor;
end;
procedure TJvCustomLinkLabel.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
ActivateLinkNodeAtPos(Point(X, Y), lsClicked);
end;
procedure TJvCustomLinkLabel.MouseMove(Shift: TShiftState; X, Y: Integer);
var
Pt: TPoint; // Bianconi #2
begin
inherited MouseMove(Shift, X, Y);
// Bianconi #2
Pt := Point(X - FNodeTree.Root.StartingPoint.X,Y - FNodeTree.Root.StartingPoint.Y);
if FNodeTree.IsPointInNodeClass(Pt, TLinkNode) then
begin
Cursor := LinkCursor;
if FHotLinks and not IsActiveLinkNodeClicked then
ActivateLinkNodeAtPos(Point(X, Y), lsHot);
end
else
begin
Cursor := FOriginalCursor;
if FHotLinks and not IsActiveLinkNodeClicked then
DeactivateActiveLinkNode;
end;
end;
procedure TJvCustomLinkLabel.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
NodeAtPoint: TLinkNode;
Pt: TPoint; // Bianconi #2
begin
inherited MouseUp(Button, Shift, X, Y);
// Bianconi #2
Pt := Point(X - FNodeTree.Root.StartingPoint.X,Y - FNodeTree.Root.StartingPoint.Y);
if FNodeTree.IsPointInNodeClass(Pt, TLinkNode) then
begin
NodeAtPoint := FNodeTree.GetNodeAtPointOfClass(Pt, TLinkNode) as TLinkNode;
if Assigned(NodeAtPoint) then
DoLinkClicked(NodeAtPoint.Number, NodeAtPoint.Text, NodeAtPoint.Param); // added LinkParam by Cetkovsky
end;
DeactivateActiveLinkNode;
end;
// Bianconi
procedure TJvCustomLinkLabel.Paint;
var
TmpBmp: TBitmap;
TmpRect: TRect;
begin
TmpBmp := nil;
if Assigned(FNodeTree) then
try
Canvas.Font := Font;
if not Transparent then
begin
// repaint canvas
Canvas.Brush.Color := Color;
Canvas.Brush.Style := bsSolid;
DrawThemedBackground(Self, Canvas, ClientRect);
end;
Canvas.Brush.Style := bsClear;
TmpBmp := TBitmap.Create;
TmpRect := ClientRect;
TmpBmp.Height := TmpRect.Bottom - (FMarginHeight shl 1) + 1; // TmpRect.Top = 0, ignore it
TmpBmp.Width := TmpRect.Right - (FMarginWidth shl 1) + 1; // TmpRect.left = 0, ignore it
TmpBmp.Canvas.Font.Assign(Canvas.Font);
TmpBmp.Canvas.Pen.Assign(Canvas.Pen);
// Initialize background of canvas
// You should choose a color diferent from your links colors to made it visible
TmpBmp.Canvas.Brush.Color := Color;
TmpBmp.Canvas.Brush.Style := bsSolid;
TmpBmp.Canvas.FillRect(Rect(0,0,TmpBmp.Width - 1,TmpBmp.Height - 1));
// Set new start point
// The new start point is relative to temporary canvas, Left & Top Corner
FNodeTree.Root.StartingPoint := Point(0,0); // Bianconi #2
FRenderer.RenderTree(TmpBmp.Canvas, Rect(0,0,TmpBmp.Width - 1,TmpBmp.Height - 1), FNodeTree);
// Set new height e don't draw in this pass.
// Wait for next paint event.
// Allow correctly layout position and improve some performance
if FAutoHeight and
(Align in [alNone, alTop, alBottom]) and
(ClientHeight <> (FRenderer.GetTextHeight + (FMarginHeight shl 1)) ) then
ClientHeight := FRenderer.GetTextHeight + (FMarginHeight shl 1)
else
begin
TmpRect := ClientRect;
InflateRect(TmpRect,-FMarginWidth,-FMarginHeight);
case FLayout of
tlTop:
begin
// Nothing to do
end;
tlCenter:
begin
TmpRect.Top := TmpRect.Top +
(TmpRect.Bottom - TmpRect.Top - FRenderer.GetTextHeight) div 2;
if TmpRect.Top < FMarginHeight then
TmpRect.Top := FMarginHeight;
end;
tlBottom:
begin
TmpRect.Top := TmpRect.Bottom - FRenderer.GetTextHeight;
if TmpRect.Top < FMarginHeight then
TmpRect.Top := FMarginHeight;
end;
end;
// Adjust Root start point relative to control's canvas.
FNodeTree.Root.StartingPoint := Point(TmpRect.Left, TmpRect.Top); // Bianconi #2
// VisualCLX: most be done after the bitmap is drawn.
TmpBmp.Transparent := True;
TmpBmp.TransparentMode := tmFixed;
TmpBmp.TransparentColor := Color;
Canvas.Draw(TmpRect.Left,TmpRect.Top,TmpBmp);
end;
finally
TmpBmp.Free;
end;
end;
// End of Bianconi
procedure TJvCustomLinkLabel.Resize;
begin
inherited Resize;
// Bianconi -> ClientRect.Bottom - FMarginHeight
// MarginHeight is applied on Top and Bottom values, exactly as MargimWidth
// FRect := Rect(ClientRect.Left + FMarginWidth, ClientRect.Top + FMarginHeight,
// ClientRect.Right - FMarginWidth, ClientRect.Bottom - FMarginHeight);
// end of Bianconi
end;
procedure TJvCustomLinkLabel.SetAutoHeight(const Value: Boolean);
begin
if FAutoHeight <> Value then
begin
FAutoHeight := Value;
Invalidate;
end;
end;
procedure TJvCustomLinkLabel.SetText(const Value: TCaption);
begin
if Value <> Caption then
begin
Text.Clear;
inherited SetText(Value);
FCaption := Value;
Text.Add(Caption);
FActiveLinkNode := nil; // We're about to free the tree containing the node it's pointing to
FNodeTree.Free;
ResetNodeCount;
FNodeTree := FParser.Parse(Value);
SynchronizeRootAndFont;
Invalidate;
DoCaptionChanged;
end;
end;
procedure TJvCustomLinkLabel.SetLinkColor(const Value: TColor);
begin
if Value <> GetLinkColor then
begin
FRenderer.LinkColor := Value;
Invalidate;
end;
end;
procedure TJvCustomLinkLabel.SetLinkColorClicked(const Value: TColor);
begin
if Value <> GetLinkColorClicked then
FRenderer.LinkColorClicked := Value;
end;
procedure TJvCustomLinkLabel.SetLinkColorHot(const Value: TColor);
begin
FRenderer.LinkColorHot := Value;
end;
procedure TJvCustomLinkLabel.SetLinkStyle(const Value: TFontStyles);
begin
if Value <> GetLinkStyle then
begin
FRenderer.LinkStyle := Value;
Invalidate;
end;
end;
// Bianconi
function TJvCustomLinkLabel.GetLinkCursor: TCursor;
begin
Result := FLinkCursor;
end;
// Bianconi
procedure TJvCustomLinkLabel.SetLinkCursor(AValue: TCursor);
begin
FLinkCursor := AValue;
end;
procedure TJvCustomLinkLabel.SetMarginHeight(const Value: Integer);
begin
if FMarginHeight <> Value then
begin
FMarginHeight := Value;
Resize;
Invalidate;
end;
end;
procedure TJvCustomLinkLabel.SetMarginWidth(const Value: Integer);
begin
if FMarginWidth <> Value then
begin
FMarginWidth := Value;
Resize;
Invalidate;
end;
end;
function TJvCustomLinkLabel.GetStrings: TStrings;
begin
Result := FText;
end;
procedure TJvCustomLinkLabel.SetStrings(const Value: TStrings);
begin
FText.Assign(Value); inherited SetText(FText.Text);
end;
// Bianconi
procedure TJvCustomLinkLabel.SetLayout(AValue: TTextLayout);
begin
if FLayout <> AValue then
begin
FLayout := AValue;
Invalidate;
end;
end;
// end of Bianconi
procedure TJvCustomLinkLabel.SetTransparent(const Value: Boolean);
begin
if Transparent <> Value then
begin
if Value then
begin
ControlStyle := ControlStyle - [csOpaque];
end
else
begin
ControlStyle := ControlStyle + [csOpaque];
end;
Invalidate;
end;
end;
procedure TJvCustomLinkLabel.SynchronizeRootAndFont;
begin
if Assigned(FNodeTree) then
with FNodeTree.Root do
begin
Styles := Font.Style;
Color := Font.Color;
end;
end;
procedure TJvCustomLinkLabel.UpdateDynamicTag(Number: Integer; const Source: string);
var
NodeEnum: INodeEnumerator;
Parser: IParser;
CurrentNode: TDynamicNode;
begin
NodeEnum := FNodeTree.GetTopLevelNodeEnumerator(TDynamicNode);
while NodeEnum.HasNext do
begin
CurrentNode := NodeEnum.GetNext as TDynamicNode;
if CurrentNode.Number = Number then
begin
Parser := CreateParser;
CurrentNode.DestroyChildren;
Parser.AddSourceTreeToDynamicNode(CurrentNode, Source);
Repaint;
Exit;
end;
end;
raise ELinkLabelError.CreateRes(@RsETagNotFound);
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvQLinkLabel.pas,v $';
Revision: '$Revision: 1.24 $';
Date: '$Date: 2004/12/21 09:45:18 $';
LogPath: 'JVCL\run'
);
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -