View Issue Details

IDProjectCategoryView StatusLast Update
0001494JEDI VCL00 JVCL Componentspublic2004-03-18 15:19
ReporterglchapmanAssigned Touser72 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0001494: TJvTransparentButton invalidation problems (TextChanged and csOpaque)
DescriptionI'm using Delphi 5, where the default behavior for a TControl is to ignore CM_TEXTCHANGED messages (I don't know if this is different in later versions). Nothing in the inheritance chain from TControl to TJvTransparentButton introduces a handler for CM_TEXTCHANGED, so a change of Caption is not immediately shown in the button.

One way to fix this (perhaps not the best), is to introduce this method:

procedure TJvCustomGraphicButton.TextChanged;
begin
  RepaintBackground;
end;

In the above, simply calling Invalidate does not always get the whole button redrawn. When Transparent is true, the button should not have csOpaque in its control style. Unfortunately, setting the FrameStyle to something other than fsExplorer will cause Flat to be set to false, which (in TJvCustomGraphicButton.SetFlat) causes csOpaque to be included in the ControlStyle.

So it looks like something like the attached diff is needed(I hate overriding RepaintBackground for this purpose, but it gets the job done).

Presumably, something similar is needed for TJvTransparentButton2.

TagsNo tags attached.

Activities

2004-03-18 12:07

 

JvTransparentButton.pas.diff (3,074 bytes)
--- JvTransparentButton.pas.orig	2004-03-18 12:06:04.000000000 -0800
+++ JvTransparentButton.pas	2004-03-18 12:15:26.000000000 -0800
@@ -85,20 +85,21 @@
     procedure SetFrameStyle(Value: TJvFrameStyle);
     procedure SetTransparent(Value: Boolean);
     procedure SetBorderWidth(Value: Cardinal);
     procedure GlyphChanged(Sender: TObject);
   protected
     procedure AddGlyphs(aGlyph: TBitmap; AColor: TColor; Value: Integer);
     procedure PaintButton(Canvas: TCanvas); override;
     procedure PaintFrame(Canvas: TCanvas); override;
     procedure DrawTheText(ARect: TRect; Canvas: TCanvas); virtual;
     procedure DrawTheBitmap(ARect: TRect; Canvas: TCanvas); virtual;
+    procedure RepaintBackground; override;
     procedure ActionChange(Sender: TObject; CheckDefaults: Boolean);override;
     function GetActionLinkClass: TControlActionLinkClass; override;
   public
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
     property Canvas;
   published
     property Action;
     property Align;
     property AutoGray: Boolean read FAutoGray write SetAutoGray default True;
@@ -412,20 +413,21 @@
 constructor TJvTransparentButton.Create(AOwner: TComponent);
 begin
   inherited Create(AOwner);
   AllowAllUp := True;
   FNumGlyphs := 1;
   FAutoGray := True;
   FShowPressed := True;
   FOffset := 1;
   FBorderSize := 1;
   FTransparent := True;
+  ControlStyle:= ControlStyle - [csOpaque];
 
   FImList := TImageList.Create(self);
   FGlyph := TBitmap.Create;
   FGrayGlyph := TBitmap.Create;
   FDisabledGlyph := TBitmap.Create;
   FGlyph.OnChange := GlyphChanged;
 
   FNumGlyphs := 1;
   FSpacing := 2;
   FTextAlign := ttaCenter;
@@ -510,20 +512,24 @@
     Flat := FOutline = fsExplorer;
     Invalidate;
   end;
 end;
 
 procedure TJvTransparentButton.SetTransparent(Value: Boolean);
 begin
   if FTransparent <> Value then
   begin
     FTransparent := Value;
+    if FTransparent then
+      ControlStyle:= ControlStyle - [csOpaque]
+    else if not Flat then
+      ControlStyle:= ControlStyle + [csOpaque];
     Invalidate;
   end;
 end;
 
 procedure TJvTransparentButton.SetBorderWidth(Value: Cardinal);
 begin
   if FBorderSize <> Value then
   begin
     FBorderSize := Value;
     Invalidate;
@@ -823,20 +829,27 @@
       InflateRect(HelpRect, -BorderWidth - 1, -BorderWidth - 1);
       Canvas.Brush.Bitmap := Pattern;
       Self.Canvas.FillRect(HelpRect);
     end;
 
     ImageList_DrawEx(Handle, Index, Canvas.Handle, ARect.Left, ARect.Top, 0, 0,
       clNone, clNone, ILD_TRANSPARENT);
   end;
 end;
 
+procedure TJvTransparentButton.RepaintBackground;
+begin
+  if Transparent then
+    ControlStyle:= ControlStyle - [csOpaque];
+  inherited;
+end;
+
 procedure TJvTransparentButton.GlyphChanged(Sender: TObject);
 var
   GlyphNum: Integer;
 begin
   Invalidate;
   GlyphNum := 1;
   if (Glyph <> nil) and (Glyph.Height > 0) then
   begin
     if Glyph.Width mod Glyph.Height = 0 then
     begin

anonymous

2004-03-18 13:00

viewer   ~0003379

Another quick note about TJvTransparentButton: it publishes Align but not Anchors. Is this an oversight? It seems like if you're going to support Align, you might as well support Anchors as well since they are so closely tied together.

glchapman

2004-03-18 13:01

reporter   ~0003380

Both the original report and the first bugnote were contributed by me (I didn't realize I wasn't logged in).

user72

2004-03-18 13:20

  ~0003381

I will have a look

user72

2004-03-18 15:19

  ~0003386

Fixed in CVS.Properties published as well.

Issue History

Date Modified Username Field Change
2004-03-18 12:07 anonymous New Issue
2004-03-18 12:07 anonymous File Added: JvTransparentButton.pas.diff
2004-03-18 13:00 anonymous Note Added: 0003379
2004-03-18 13:01 glchapman Note Added: 0003380
2004-03-18 13:20 user72 Note Added: 0003381
2004-03-18 13:20 user72 Reporter anonymous => glchapman
2004-03-18 13:20 user72 Assigned To => user72
2004-03-18 13:20 user72 Status new => acknowledged
2004-03-18 15:19 user72 Status acknowledged => resolved
2004-03-18 15:19 user72 Resolution open => fixed
2004-03-18 15:19 user72 Note Added: 0003386