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
0004294 [JEDI VCL] 00 JVCL Components tweak always 2007-11-14 03:57 2007-11-30 13:58
Reporter bhe View Status public  
Assigned To AHUser
Priority normal Resolution fixed  
Status resolved   Product Version
Summary 0004294: Avoid dirty cast in TJvDockVSBlock.ResetActiveBlockWidth
Description Solution w/o dirty cast could be:

procedure TJvDockVSBlock.ResetActiveBlockWidth;
var
  I: Integer;
  TextWidth: Integer;
  tHDC: HDC;
  tS: TSize;
begin
  FActiveBlockWidth := 0;

  for I := 0 to VSPaneCount - 1 do
  begin
    // <(bhe)>
    tHDC := GetDC(VSChannel.Parent.Handle);
    try
      tS.cX := 0;
      tS.cY := 0;
      Windows.GetTextExtentPoint32(tHDC, PChar(VSPane[I].FDockForm.Caption),
        Length(VSPane[I].FDockForm.Caption), tS);
      TextWidth := tS.cx + InactiveBlockWidth + 10;
    finally
      ReleaseDC(VSChannel.Parent.Handle, tHDC);
    end;
    // </(bhe)>

    if TextWidth >= VSChannel.ActivePaneSize then
    begin
      FActiveBlockWidth := VSChannel.ActivePaneSize;
      Exit;
    end;

    FActiveBlockWidth := Max(FActiveBlockWidth, TextWidth);
  end;

  if FActiveBlockWidth = 0 then
    FActiveBlockWidth := VSChannel.ActivePaneSize;
end;

Additional Information
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0014036)
AHUser (developer)
2007-11-30 13:57

The GetDC does not garantee that the returned DC has the same font object selected, so the GetTextExtentPoint32 can return a wrong width. Furthermore the DC could be created outside of the for-loop what would make it faster.

I have changed the code to use the is-operator before typecasting. In the case of a TCustomForm it typecasts using the valid cracker-typecast. If it can't typecast the parent, the VSChannel.ActivePaneSize will be used.

- Issue History
Date Modified Username Field Change
2007-11-14 03:57 bhe New Issue
2007-11-30 13:57 AHUser Status new => resolved
2007-11-30 13:57 AHUser Fixed in Version => Daily / SVN
2007-11-30 13:57 AHUser Resolution open => fixed
2007-11-30 13:57 AHUser Assigned To => AHUser
2007-11-30 13:57 AHUser Note Added: 0014036


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