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

📄 tntjvradiogroup.pas

📁 TntExUpdate 是 流行的 TntUnicodeControls控件的扩展包.包括很难找到的 TntJVCL 也在里面. TntSysUtils2.pas/TntSysUtilsEx.pa
💻 PAS
字号:
{-----------------------------------------------------------------------------
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: JvRadioGroup.PAS, released on 2001-02-28.

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

Contributor(s): Michael Beck [mbeck att bigfoot dott com].

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

Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvRadioGroup.pas,v 1.41 2005/02/17 10:20:46 marquardt Exp $

unit TntJvRadioGroup;

{$I jvcl.inc}

interface

uses
  {$IFDEF UNITVERSIONING}
  JclUnitVersioning,
  {$ENDIF UNITVERSIONING}
  Windows, TntWindows, Messages,
  SysUtils, Classes, Graphics, TntGraphics, Controls, TntControls, Forms, StdCtrls, ExtCtrls, ToolWin,
  JvJCLUtils, JvThemes, JvExControls, JvExExtCtrls, TntJvExExtCtrls;

type
  TTntJvRadioGroupHintEvent = procedure(Sender: TObject; Index: Integer;
    var AHint: TWideCaption) of object;

  TTntJvRadioGroup = class(TTntJvExRadioGroup, IJvDenySubClassing)
  private
    FReadOnly: Boolean;
    FEdgeBorders: TEdgeBorders;
    FEdgeInner: TEdgeStyle;
    FEdgeOuter: TEdgeStyle;
    FCaptionVisible: Boolean;
    FOnItemHint: TTntJvRadioGroupHintEvent;
    procedure SetEdgeBorders(const Value: TEdgeBorders);
    procedure SetEdgeInner(const Value: TEdgeStyle);
    procedure SetEdgeOuter(const Value: TEdgeStyle);
    procedure SetCaptionVisible(Value: Boolean);
  protected
    procedure Paint; override;
    function CanModify: Boolean; override;
    procedure GetItemHint(Index: Integer; var AHint: TWideCaption); virtual;
    function HintShow(var HintInfo: THintInfo): Boolean; override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property CaptionVisible: Boolean read FCaptionVisible write SetCaptionVisible;
    property EdgeBorders: TEdgeBorders read FEdgeBorders write SetEdgeBorders default [ebLeft, ebTop, ebRight, ebBottom];
    property EdgeInner: TEdgeStyle read FEdgeInner write SetEdgeInner default esRaised;
    property EdgeOuter: TEdgeStyle read FEdgeOuter write SetEdgeOuter default esLowered;
    property HintColor;
    {$IFDEF JVCLThemesEnabledD56}
    property ParentBackground default True;
    {$ENDIF JVCLThemesEnabledD56}
    property ReadOnly: Boolean read FReadOnly write FReadOnly default False;
    property OnMouseEnter;
    property OnMouseLeave;
    property OnItemHint: TTntJvRadioGroupHintEvent read FOnItemHint write FOnItemHint;
    property OnParentColorChange;
  end;

{$IFDEF UNITVERSIONING}
const
  UnitVersioning: TUnitVersionInfo = (
    RCSfile: '$RCSfile: JvRadioGroup.pas,v $';
    Revision: '$Revision: 1.41 $';
    Date: '$Date: 2005/02/17 10:20:46 $';
    LogPath: 'JVCL'run'
  );
{$ENDIF UNITVERSIONING}

implementation

uses
  Math, TntWideStrUtils;

constructor TTntJvRadioGroup.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FEdgeBorders := [ebLeft, ebTop, ebRight, ebBottom];
  FEdgeInner := esRaised;
  FEdgeOuter := esLowered;
  FCaptionVisible := True;
  {$IFDEF JVCLThemesEnabledD56}
  IncludeThemeStyle(Self, [csParentBackground]);
  {$ENDIF JVCLThemesEnabledD56}
end;

procedure TTntJvRadioGroup.Paint;
const
  InnerStyles: array [TEdgeStyle] of Integer =
    (0, BDR_RAISEDINNER, BDR_SUNKENINNER);
  OuterStyles: array [TEdgeStyle] of Integer =
    (0, BDR_RAISEDOUTER, BDR_SUNKENOUTER);
  Ctl3DStyles: array [Boolean] of Integer =
    (BF_MONO, 0);
var
  H: Integer;
  R: TRect;
  Flags: Longint;
  {$IFDEF JVCLThemesEnabled}
  Details: TThemedElementDetails;
  ClipRect, CaptionRect: TRect;
  {$ENDIF JVCLThemesEnabled}
begin
  {$IFDEF JVCLThemesEnabled}
  if ThemeServices.ThemesEnabled then
  begin
    if Enabled then
      Details := ThemeServices.GetElementDetails(tbGroupBoxNormal)
    else
      Details := ThemeServices.GetElementDetails(tbGroupBoxDisabled);
    R := ClientRect;
    Inc(R.Top, Canvas.TextHeight('0') div 2);

    if EdgeBorders <> [] then
    begin
      ClipRect := R;
      if EdgeBorders <> [ebLeft, ebTop, ebRight, ebBottom] then
      begin
        //ClipRect := R;
        if not (ebLeft in EdgeBorders) then
          Inc(ClipRect.Left, 3);
        if not (ebRight in EdgeBorders) then
          Dec(ClipRect.Right, 3);
        if not (ebTop in EdgeBorders) then
          Inc(ClipRect.Top, 3);
        if not (ebBottom in EdgeBorders) then
          Dec(ClipRect.Bottom, 3);
      end;
      ThemeServices.DrawElement(Canvas.Handle, Details, R, @ClipRect);
    end;
    if CaptionVisible then
    begin
      CaptionRect := Rect(8, 0, Min(WideCanvasTextWidth(Canvas,Caption) + 8, ClientWidth - 8), Canvas.TextHeight(Caption));

      if ParentBackground then
        DrawThemedBackground(Self, Canvas.Handle, CaptionRect, Parent.Brush.Handle, True)
      else
      begin
        Canvas.Brush.Color := Self.Color;
        DrawThemedBackground(Self, Canvas, CaptionRect, False);
      end;

      { Theme functions may delete the font, so need to refresh
        (see also remark at TCustomActionControl.Paint) }
      Canvas.Font.Assign(Font);
      Canvas.Refresh;

      ThemeServices.DrawText(Canvas.Handle, Details, Caption, CaptionRect, DT_LEFT, 0);
    end;
    Exit;
  end;
  {$ENDIF JVCLThemesEnabled}
  with Canvas do
  begin
    Font := Self.Font;
    H := TextHeight('0');
    R := Rect(0, H div 2 - 1, Width, Height);
    Windows.DrawEdge(Handle, R, InnerStyles[FEdgeInner] or OuterStyles[FEdgeOuter],
      Byte(FEdgeBorders) {$IFDEF VCL} or Ctl3DStyles[Ctl3D] {$ENDIF} or BF_ADJUST);
    if (Caption <> '') and CaptionVisible then
    begin
      if not UseRightToLeftAlignment then
        R := Rect(8, 0, 0, H)
      else
        R := Rect(R.Right - WideCanvasTextWidth(Canvas,Caption) - 8, 0, 0, H);
      Flags := DrawTextBiDiModeFlags(DT_SINGLELINE);

      // (rom) unified VCL/VisualCLX version
      Tnt_DrawTextW(Canvas.Handle, PWideChar(Caption), Length(Caption), R, Flags or DT_CALCRECT);
      Brush.Color := Color;
      SetBkMode(Handle, OPAQUE);
      Tnt_DrawTextW(Canvas.Handle, PWideChar(Caption), Length(Caption), R, Flags);
    end;
  end;
end;

function TTntJvRadioGroup.CanModify: Boolean;
begin
  if FReadOnly then
    Result := False
  else
    Result := inherited CanModify;
end;

procedure TTntJvRadioGroup.SetEdgeBorders(const Value: TEdgeBorders);
begin
  if FEdgeBorders <> Value then
  begin
    FEdgeBorders := Value;
    Invalidate;
  end;
end;

procedure TTntJvRadioGroup.SetEdgeInner(const Value: TEdgeStyle);
begin
  if FEdgeInner <> Value then
  begin
    FEdgeInner := Value;
    Invalidate;
  end;
end;

procedure TTntJvRadioGroup.SetEdgeOuter(const Value: TEdgeStyle);
begin
  if FEdgeOuter <> Value then
  begin
    FEdgeOuter := Value;
    Invalidate;
  end;
end;

procedure TTntJvRadioGroup.SetCaptionVisible(Value: Boolean);
begin
  if FCaptionVisible <> Value then
  begin
    FCaptionVisible := Value;
    Invalidate;
  end;
end;

procedure TTntJvRadioGroup.GetItemHint(Index: Integer; var AHint: TWideCaption);
begin
  if Assigned(FOnItemHint) then
    FOnItemHint(Self, Index, AHint);
end;

function TTntJvRadioGroup.HintShow(var HintInfo: THintInfo): Boolean;
var
  AItemX, AItemY,
  AHeight, AWidth, VertCount: Integer;
  ARect: TRect;
  WS: TWideCaption;
begin
  Result := False;
  with HintInfo do
  begin
    ARect := ClientRect;
    HintStr := Hint; // set default
    if Items.Count > 0 then
    begin
      VertCount := (Items.Count div Columns) + Ord(Items.Count mod Columns <> 0);
      AHeight := Height div VertCount;
      AWidth  := Width div Columns;
      if (AHeight > 0) then
      begin
        AItemX := CursorPos.X div AWidth;
        AItemY := CursorPos.Y div AHeight;
        if AItemY + AItemX * VertCount< Items.Count then
        begin
          WS := TWideCaption(HintStr);
          GetItemHint(AItemY + AItemX * VertCount, WS);
          ARect := Rect(AItemX * AWidth, AHeight * AItemY,
            AItemX * AWidth + AWidth, AHeight * AItemY + AHeight);
        end;
      end;
      CursorRect := ARect;
    end;
  end;
end;

{$IFDEF UNITVERSIONING}
initialization
  RegisterUnitVersion(HInstance, UnitVersioning);

finalization
  UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}

end.

⌨️ 快捷键说明

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