⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tntjvlabel.pas

📁 TntExUpdate 是 流行的 TntUnicodeControls控件的扩展包.包括很难找到的 TntJVCL 也在里面. TntSysUtils2.pas/TntSysUtilsEx.pa
💻 PAS
📖 第 1 页 / 共 4 页
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: JvLabel.PAS, released on 2001-02-28.

The Initial Developer of the Original Code is S?stien Buysse [sbuysse att buypin dott com]
Portions created by S?stien Buysse are Copyright (C) 2001 S?stien Buysse.
All Rights Reserved.

Contributor(s):
Michael Beck [mbeck att bigfoot dott com].
Peter Thornqvist [peter3 at sourceforge dot net]

You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net

Changes:
2005-07-20:(dejoy)
  * TTntJvCustomLabel implemented interface of IJvHotTrack.
2005-04-02:
  * Fixed (Added) support for Alignment when used with Angle. (Layout still to do)
  * Fixed Shadow (was not visible when JvLabel not Transparent).
  * Fixed RoundedFrame (was not visible when not Transparent).
2004-04-05:
  * Add property RoundedFrame in TTntJvCustomLabel (Integer>0 is the radius corner)
2003-10-19:
  * Moved TTntJvCustomLabel from JvxCtrls to this unit
2003-09-13:
  * Turned TTntJvCustomLabel into a consumer.
    Notes: * angled labels will simply use the current item's Text to render and ignore any provider
             specified rendering implementations.
           * D5 users: when changing a property that might clear out the provider (Caption,
             ImageIndex and Image) you can run into Access Violations if the Provider property is
             collapsed. This is due to a limitation in D5 property editors and can not be solved.
2003-08-17:
  * Implementation moved to TTntJvCustomLabel. TTntJvLabel now only publishes properties and events.
2003-03-24:
  * JvHotLink merged into JvLabel:
    To simulate JvHotlink, set AutoOpenURL to True, modify HotTrackFont to fit and assign
    a URL (or file-path) to the URL property.
  * JvAngleLabel merged into JvLabel: set Angle > 0 and font to a TrueTrype font to rotate the text // peter3

  Contributor(s):
    Dierk schmid
    Stephane Bischoff (Tief)
    Dejoy Den

Known Issues:
* AutoSize calculations aren't correct when RoundedFrame and/or Shadow are active
-----------------------------------------------------------------------------}
// $Id: JvLabel.pas,v 1.83 2006/01/23 18:28:55 elahn Exp $

unit TntJvLabel;

{$I jvcl.inc}

interface

uses
  {$IFDEF UNITVERSIONING}
  JclUnitVersioning,
  {$ENDIF UNITVERSIONING}
  Windows, TntWindows, Messages, Classes, Graphics, TntGraphics, Controls, StdCtrls, ImgList,
  JvTypes, JvComponent, TntJvComponent, JvDataProvider, JvExControls, JvVCL5Utils, JvLabel;

type
 (***
  TShadowPosition = (spLeftTop, spLeftBottom, spRightBottom, spRightTop);
  TJvLabelRotateAngle = -360..360;
  TJvTextEllipsis = (teNone, teWordEllipsis, tePathEllipsis, teEndEllipsis);

  TAngleInfo = record
    TextWidth: Integer;
    TextHeight: Integer;
    TextGapWidth: Integer;
    TextGapHeight: Integer;
    TotalWidth: Integer;
    TotalHeight: Integer;
    PosX: Integer;
    PosY: Integer;
  end;
  ***)

  TTntJvCustomLabel = class(TTntJvGraphicControlCE, IJvHotTrack)
  private
    FFocusControl: TWinControl;
    FAlignment: TAlignment;
    FAutoSize: Boolean;
    FLayout: TTextLayout;
    FShadowColor: TColor;
    FShadowSize: Byte;
    FShadowPos: TShadowPosition;
    FWordWrap: Boolean;
    FShowAccelChar: Boolean;
    FShowFocus: Boolean;
    FFocused: Boolean;
    FDragging: Boolean;
    FImageIndex: TImageIndex;
    FImages: TCustomImageList;
    FChangeLink: TChangeLink;
    FHotTrack: Boolean;
    FHotTrackFont: TFont;
    FHotTrackFontOptions: TJvTrackFontOptions;
    FHotTrackOptions: TJvHotTrackOptions;

    FAutoOpenURL: Boolean;
    FURL: string;
    FAngle: TJvLabelRotateAngle;
    FSpacing: Integer;
    FConsumerSvc: TJvDataConsumer;
    FNeedsResize: Boolean;
    FTextEllipsis: TJvTextEllipsis;
    FFrameColor: TColor;
    FRoundedFrame: Integer; // DS
    FMarginLeft: Integer;
    FMarginTop: Integer;
    FMarginRight: Integer;
    FMarginBottom: Integer;
    function GetTransparent: Boolean;
    procedure UpdateTracking;
    procedure SetAlignment(Value: TAlignment);
    procedure SetFocusControl(Value: TWinControl);
    procedure SetLayout(Value: TTextLayout);
    procedure SetMargin(Value: Integer);
    procedure SetShadowColor(Value: TColor);
    procedure SetShadowSize(Value: Byte);
    procedure SetShadowPos(Value: TShadowPosition);
    procedure SetShowAccelChar(Value: Boolean);
    procedure SetTransparent(Value: Boolean);
    procedure SetWordWrap(Value: Boolean);
    procedure SetShowFocus(Value: Boolean);
    procedure SetImageIndex(Value: TImageIndex);
    procedure SetImages(Value: TCustomImageList);
    procedure DoImagesChange(Sender: TObject);
    procedure DrawAngleText(var Rect: TRect; Flags: Word; HasImage: Boolean;
      ShadowSize: Byte; ShadowColor: TColorRef; ShadowPos: TShadowPosition);
    procedure SetAngle(Value: TJvLabelRotateAngle);
    procedure SetSpacing(Value: Integer);
    procedure SetTextEllipsis(Value: TJvTextEllipsis);
    procedure SetFrameColor(const Value: TColor);
    procedure SetRoundedFrame(const Value: Integer);
    function GetMargin: Integer;
    procedure HotFontChanged(Sender: TObject);

    {IJvHotTrack}  //added by dejoy 2005-07-20
    function GetHotTrack: Boolean;
    function GetHotTrackFont: TFont;
    function GetHotTrackFontOptions: TJvTrackFontOptions;
    function GetHotTrackOptions: TJvHotTrackOptions;
    procedure SetHotTrack(Value: Boolean);
    procedure SetHotTrackFont(Value: TFont);
    procedure SetHotTrackFontOptions(Value: TJvTrackFontOptions);
    procedure SetHotTrackOptions(Value: TJvHotTrackOptions);
  protected
    procedure DoDrawCaption(var Rect: TRect; Flags: Integer); virtual;
    procedure DoProviderDraw(var Rect: TRect; Flags: Integer); virtual;
    procedure FocusChanged(AControl: TWinControl); override;
    procedure TextChanged; override;
    procedure FontChanged; override;
    function WantKey(Key: Integer; Shift: TShiftState;
      const KeyText: WideString): Boolean; override;
    procedure EnabledChanged; override;

    procedure DoDrawText(var Rect: TRect; Flags: Integer); virtual;
    procedure AdjustBounds; virtual;
    {$IFDEF VCL}
    procedure SetAutoSize(Value: Boolean); override;
    {$ENDIF VCL}
    {$IFDEF VisualCLX}
    procedure SetAutoSize(Value: Boolean); virtual;
    {$ENDIF VisualCLX}

    // MarginXxx do not update the control.
    property MarginLeft: Integer read FMarginLeft write FMarginLeft;
    property MarginTop: Integer read FMarginTop write FMarginTop;
    property MarginRight: Integer read FMarginRight write FMarginRight;
    property MarginBottom: Integer read FMarginBottom write FMarginBottom;

    function GetDefaultFontColor: TColor; virtual;
    function GetLabelCaption: WideString; virtual;
    function IsValidImage: Boolean;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer); override;
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
    procedure Click; override;
    procedure Paint; override;
    procedure Loaded; override;
    procedure MouseEnter(Control: TControl); override;
    procedure MouseLeave(Control: TControl); override;
    function GetImageWidth: Integer; virtual;
    function GetImageHeight: Integer; virtual;
    procedure SetConsumerService(Value: TJvDataConsumer);
    function ProviderActive: Boolean;
    procedure ConsumerServiceChanged(Sender: TJvDataConsumer; Reason: TJvDataConsumerChangeReason);
    procedure NonProviderChange;
    property Angle: TJvLabelRotateAngle read FAngle write SetAngle default 0;
    property AutoOpenURL: Boolean read FAutoOpenURL write FAutoOpenURL default True;

    property HotTrack: Boolean read GetHotTrack write SetHotTrack default False;
    property HotTrackFont: TFont read GetHotTrackFont write SetHotTrackFont;
    property HotTrackFontOptions: TJvTrackFontOptions read GetHotTrackFontOptions write SetHotTrackFontOptions default
      DefaultTrackFontOptions;
    property HotTrackOptions: TJvHotTrackOptions read GetHotTrackOptions write SetHotTrackOptions;

    property NeedsResize: Boolean read FNeedsResize write FNeedsResize;

    property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
    property AutoSize: Boolean read FAutoSize write SetAutoSize default True;
    property FocusControl: TWinControl read FFocusControl write SetFocusControl;
    property FrameColor: TColor read FFrameColor write SetFrameColor default clNone;
    property Images: TCustomImageList read FImages write SetImages;
    property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
    property TextEllipsis: TJvTextEllipsis read FTextEllipsis write SetTextEllipsis default teNone;
    // specifies the offset between the right edge of the image and the left edge of the text (in pixels)
    property Spacing: Integer read FSpacing write SetSpacing default 4;
    property Layout: TTextLayout read FLayout write SetLayout default tlTop;
    property Margin: Integer read GetMargin write SetMargin default 0;
    property RoundedFrame: Integer read FRoundedFrame write SetRoundedFrame default 0; //DS
    property ShadowColor: TColor read FShadowColor write SetShadowColor default clBtnHighlight;
    property ShadowSize: Byte read FShadowSize write SetShadowSize default 0;
    property ShadowPos: TShadowPosition read FShadowPos write SetShadowPos default spRightBottom;
    property ShowAccelChar: Boolean read FShowAccelChar write SetShowAccelChar default True;
    property ShowFocus: Boolean read FShowFocus write SetShowFocus default False;
    property Transparent: Boolean read GetTransparent write SetTransparent default False;
    property URL: string read FURL write FURL;
    property Provider: TJvDataConsumer read FConsumerSvc write SetConsumerService;
    property WordWrap: Boolean read FWordWrap write SetWordWrap default False;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property Canvas;
    property MouseOver;
    procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
  end;

  TTntJvLabel = class(TTntJvCustomLabel)
  published
    property Action;
    property Align;
    property Alignment;
    property AutoSize;
    property Caption;
    property Color;
    {$IFDEF VCL}
    property DragCursor;
    property BiDiMode;
    property DragKind;
    property ParentBiDiMode;
    {$ENDIF VCL}
    property DragMode;
    property Enabled;
    property FocusControl;
    property FrameColor;
    property Font;
    property Anchors;
    property Constraints;
    property Layout;
    property Margin;
    property ParentColor;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property RoundedFrame;
    property ShadowColor;
    property ShadowSize;
    property ShadowPos;
    property ShowAccelChar;
    property ShowFocus;
    property ShowHint;
    property Transparent;
    property Visible;
    property WordWrap;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnMouseEnter;
    property OnMouseLeave;
    property OnStartDrag;
    property OnContextPopup;

    property Angle;
    property AutoOpenURL;
    property HintColor;
    property HotTrack;
    property HotTrackFont;
    property HotTrackFontOptions;
    property HotTrackOptions;
    property Images;
    property ImageIndex;
    property Provider;
    property Spacing;
    property TextEllipsis;
    property URL;
    property OnParentColorChange;
    property CaptionEditor;
  end;

function DrawShadowTextW(Canvas: TCanvas; Str: PWideChar; Count: Integer; var Rect: TRect;
  Format: Word; ShadowSize: Byte; ShadowColor: TColorRef;
  ShadowPos: TShadowPosition): Integer;

(**
procedure FrameRounded(Canvas: TCanvas; ARect: TRect; AColor: TColor; R: Integer);

function CalculateAlignment(Alignment: TAlignment; Angle: Integer; X, Y: Real;
  Info: TAngleInfo): TPoint;
**)
procedure CalculateAngleInfoW(Canvas: TCanvas; Angle: Integer; Text: WideString;
  Rect: TRect; var Info: TAngleInfo; AutoSize: Boolean = True;
  Alignment: TAlignment = taLeftJustify);

{$IFDEF UNITVERSIONING}
const
  UnitVersioning: TUnitVersionInfo = (
    RCSfile: '$RCSfile: JvLabel.pas,v $';
    Revision: '$Revision: 1.83 $';
    Date: '$Date: 2006/01/23 18:28:55 $';
    LogPath: 'JVCL'run'
  );
{$ENDIF UNITVERSIONING}

implementation

uses
  SysUtils, Math, Forms,
  JvDataProviderIntf, JvConsts, JvThemes, JvJCLUtils, JvJVCLUtils, TntWideStrUtils;

const
  Alignments: array [TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
  WordWraps: array [Boolean] of Word = (0, DT_WORDBREAK);

//=== { TTntJvCustomLabel } =====================================================

(***
function CalculateAlignment(Alignment: TAlignment; Angle: Integer; X, Y: Real; Info: TAngleInfo): TPoint;
begin
  with Info do
    case Angle of
      0..89:
        case Alignment of
          taLeftJustify:
            Result := Point(0, Round(Y + (TotalHeight - 2 * TextGapHeight) / 2));
          taCenter:
            Result := Point(Round(X - TotalWidth / 2), Round(Y + (TotalHeight - 2 * TextGapHeight) / 2));
          taRightJustify:
            Result := Point(Round(X * 2 - TotalWidth), Round(Y + (TotalHeight - 2 * TextGapHeight) / 2));
        end;
      90..179:
        case Alignment of
          taLeftJustify:
            Result := Point(TextWidth, Round(Y + TotalHeight / 2));
          taCenter:
            Result := Point(Round(X + (TotalWidth - 2 * TextGapWidth) / 2), Round(Y + TotalHeight / 2));
          taRightJustify:
            Result := Point(Round(X * 2 - TextGapWidth), Round(Y + TotalHeight / 2));
        end;
      180..269:
        case Alignment of
          taLeftJustify:
            Result := Point(TotalWidth, Round(Y - (TotalHeight - 2 * TextGapHeight) / 2));
          taCenter:
            Result := Point(Round(X + TotalWidth / 2), Round(Y - (TotalHeight - 2 * TextGapHeight) / 2));
          taRightJustify:
            Result := Point(Round(X * 2), Round(Y - (TotalHeight - 2 * TextGapHeight) / 2));
        end;
      else
        case Alignment of
          taLeftJustify:
            Result := Point(TextGapWidth, Round(Y - TotalHeight / 2));
          taCenter:
            Result := Point(Round(X - (TotalWidth - 2 * TextGapWidth) / 2), Round(Y - TotalHeight / 2));
          taRightJustify:
            Result := Point(Round(X * 2 - TextWidth), Round(Y - TotalHeight / 2));
        end;
    end;
end;
***)

procedure CalculateAngleInfoW(Canvas: TCanvas; Angle: Integer; Text: WideString;
  Rect: TRect; var Info: TAngleInfo; AutoSize: Boolean = True;
  Alignment: TAlignment = taLeftJustify);
var
  TxtWdt, TxtHgt: Extended;
  AngleB, X, Y: Real;
  Origin: TPoint;
begin
  // Calculate intermediate values
  case Angle of
    0..89:
      AngleB := DegToRad(90 - Angle);
    90..179:
      AngleB := DegToRad(Angle - 90);
    180..269:
      AngleB := DegToRad(270 - Angle);
  else {270..359}
    AngleB := DegToRad(Angle - 270);
  end;
  with Canvas do
  begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -