Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0006600 [JEDI VCL] 00 JVCL Components feature N/A 2017-10-21 15:57 2017-10-21 16:01
Reporter tetardd View Status public  
Assigned To
Priority normal Resolution open  
Status new   Product Version 3.48
Summary 0006600: Changed to TJvArrowButton to make it easy to ownerdraw
Description I 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.

Additional Information
Tags No tags attached.
Attached Files ? file icon JvArrayButton.pas [^] (19,650 bytes) 2017-10-21 15:57

- Relationships

-  Notes
(0021437)
tetardd (reporter)
2017-10-21 16:01

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


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker