View Issue Details

IDProjectCategoryView StatusLast Update
0006600JEDI VCL00 JVCL Componentspublic2018-07-18 15:59
ReportertetarddAssigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status acknowledgedResolutionopen 
Product Version3.48 
Target VersionFixed in Version 
Summary0006600: Changed to TJvArrowButton to make it easy to ownerdraw
DescriptionI have made some changes to the JvArrowButton unit (quite trivial ones) to allow a descendant of TJvArrowButton to be owner drawn (caption and glyph).

The changes are all marked with my name "David Tetard" and some explanation why I made these changes are included in the uploaded file.

TagsNo tags attached.

Relationships

related to 0006601 acknowledged TJvArrowButton - Glyph and caption not properly drawn when using Margin 

Activities

2017-10-21 15:57

 

JvArrayButton.pas (19,650 bytes)

tetardd

2017-10-21 16:01

reporter   ~0021437

I forgot to add, now to owner draw, simply create a descendant of TGlyphButton and override the DrawText and/or DrawGlyph methods (now made protected and virtual) and override the new procedure CreateGlyphButton to use:

FGlyphButton := TMyGlyphButton.Create(Self).

Here is an example:

===================================================
unit Unit4;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Buttons, JvExControls, JvArrowButton;

type
  TDTButtonGlyph = Class(TButtonGlyph)
  Protected
       procedure DrawButtonText(Canvas: TCanvas; const Caption: string;
      TextBounds: TRect; State: TButtonState; Alignment: TAlignment;
      VerticalAlignment: TVerticalAlignment); Override;
  End;

  TDTArrowButton = Class(TJvArrowButton)
  Protected
       Procedure CreateButtonGlyph; Override;
  End;

  TForm4 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    id_DTArrowButton : TDTArrowButton;
  public
    { Public declarations }
  end;

var
  Form4: TForm4;

implementation

Uses JvJCLUtils;

{$R *.dfm}

procedure TForm4.FormCreate(Sender: TObject);
begin
     id_DTArrowButton := TDTArrowButton.Create(Self);
     id_DTArrowButton.Parent := Self;
     id_DTArrowButton.SetBounds(10, 10, 300, 50);

     id_DTArrowButton.Caption := Blah Blah Blah;
end;

{ TDTArrowButton }

procedure TDTArrowButton.CreateButtonGlyph;
begin
     FGlyph := TDTButtonGlyph.Create(Self);
end;

{ TDTButtonGlyph }

procedure TDTButtonGlyph.DrawButtonText(Canvas: TCanvas; const Caption: string; TextBounds: TRect;
  State: TButtonState; Alignment: TAlignment; VerticalAlignment: TVerticalAlignment);
const
  AlignFlags: array[TAlignment] of Integer = (DT_LEFT, DT_RIGHT, DT_CENTER);
  VerticalAlignFlags: array[TVerticalAlignment] of Integer = (DT_TOP, DT_BOTTOM, DT_VCENTER);
var
  S: string;
begin
  S := Caption;
  with Canvas do
  begin
    Brush.Style := bsClear;
    
    // Just to test that it works, all captions will be drawn in blue:
    Font.Color := clBlue;

    if State = bsDisabled then
    begin
      OffsetRect(TextBounds, 1, 1);

      DrawText(Canvas, S, -1, TextBounds, AlignFlags[Alignment] or VerticalAlignFlags[VerticalAlignment] or DT_SINGLELINE);
      OffsetRect(TextBounds, -1, -1);
      Font.Color := clBtnShadow;
      DrawText(Canvas, S, -1, TextBounds, AlignFlags[Alignment] or VerticalAlignFlags[VerticalAlignment] or DT_SINGLELINE);
    end
    else
    begin
      DrawText(Canvas, S, -1, TextBounds, AlignFlags[Alignment] or VerticalAlignFlags[VerticalAlignment] or DT_SINGLELINE);
    end;
  end;
end;

Issue History

Date Modified Username Field Change
2017-10-21 15:57 tetardd New Issue
2017-10-21 15:57 tetardd File Added: JvArrayButton.pas
2017-10-21 16:01 tetardd Note Added: 0021437
2018-07-18 15:59 obones Relationship added related to 0006601
2018-07-18 15:59 obones Status new => acknowledged