lcl, win32: use GetTextExtent as suggested in MSDN to get the correct text bounds before use of DrawThemeText() (issue #0021964)

git-svn-id: trunk@41646 -
This commit is contained in:
paul 2013-06-10 05:58:07 +00:00
parent da07c70180
commit 951d803183
4 changed files with 46 additions and 7 deletions

View File

@ -847,6 +847,7 @@ type
procedure DoShowWindow; override;
procedure UpdateRegion;
procedure SetColor(Value: TColor); override;
function UseThemes: Boolean;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

View File

@ -87,7 +87,7 @@ begin
if not HandleAllocated then
Exit;
if (Color = clInfoBk) or (Color = clDefault) then
if UseThemes then
begin
Details := ThemeServices.GetElementDetails(tttStandardNormal);
ARect := ClientRect;
@ -104,6 +104,11 @@ begin
UpdateRegion;
end;
function THintWindow.UseThemes: Boolean;
begin
Result := (Color = clInfoBk) or (Color = clDefault);
end;
function THintWindow.GetDrawTextFlags: Cardinal;
var
EffectiveAlignment: TAlignment;
@ -150,7 +155,7 @@ var
Details: TThemedElementDetails;
begin
ARect := ClientRect;
if (Color = clInfoBk) or (Color = clDefault) then
if UseThemes then
begin
// draw using themes
Details := ThemeServices.GetElementDetails(tttStandardNormal);
@ -240,15 +245,19 @@ end;
function THintWindow.CalcHintRect(MaxWidth: Integer; const AHint: String;
AData: Pointer): TRect;
begin
if AHint='' then
if AHint = '' then
begin
Result:=Rect(0,0,0,0);
exit;
Result := Rect(0, 0, 0, 0);
Exit;
end;
if MaxWidth <= 0 then
MaxWidth := Screen.Width - 4 * HintBorderWidth;
Result := Rect(0, 0, MaxWidth, Screen.Height - 4 * HintBorderWidth);
DrawText(Canvas.GetUpdatedHandle([csFontValid]), PChar(AHint), Length(AHint),
if UseThemes then
Result := ThemeServices.GetTextExtent(Canvas.GetUpdatedHandle([csFontValid]),
ThemeServices.GetElementDetails(tttStandardNormal), AHint, DT_NOPREFIX or DT_WORDBREAK, @Result)
else
DrawText(Canvas.GetUpdatedHandle([csFontValid]), PChar(AHint), Length(AHint),
Result, DT_CALCRECT or DT_NOPREFIX or DT_WORDBREAK);
inc(Result.Right, 4 * HintBorderWidth);
inc(Result.Bottom, 4 * HintBorderWidth);

View File

@ -37,6 +37,7 @@ type
function GetDetailRegion(DC: HDC; Details: TThemedElementDetails; const R: TRect): HRGN; override;
function GetStockImage(StockID: LongInt; out Image, Mask: HBitmap): Boolean; override;
function GetOption(AOption: TThemeOption): Integer; override;
function GetTextExtent(DC: HDC; Details: TThemedElementDetails; const S: String; Flags: Cardinal; BoundingRect: PRect): TRect; override;
procedure DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect;
ClipRect: PRect = nil); override;
@ -280,6 +281,22 @@ begin
end;
end;
function TWin32ThemeServices.GetTextExtent(DC: HDC; Details: TThemedElementDetails;
const S: String; Flags: Cardinal; BoundingRect: PRect): TRect;
var
w: widestring;
begin
if ThemesEnabled then
with Details do
begin
w := UTF8ToUTF16(S);
GetThemeTextExtent(Theme[Element], DC, Part, State, PWideChar(W), Length(W),
Flags, BoundingRect, Result);
end
else
Result := inherited GetTextExtent(DC, Details, S, Flags, BoundingRect);
end;
function TWin32ThemeServices.UseThemes: Boolean;
begin
Result := UxTheme.UseThemes and (GetFileVersion(comctl32) >= ComCtlVersionIE6);

View File

@ -479,6 +479,7 @@ type
function GetDetailRegion(DC: HDC; Details: TThemedElementDetails; const R: TRect): HRGN; virtual;
function GetStockImage(StockID: LongInt; out Image, Mask: HBitmap): Boolean; virtual;
function GetOption(AOption: TThemeOption): Integer; virtual;
function GetTextExtent(DC: HDC; Details: TThemedElementDetails; const S: String; Flags: Cardinal; BoundingRect: PRect): TRect; virtual;
function ColorToRGB(Color: LongInt; Details: PThemedElementDetails = nil): COLORREF;
function ContentRect(DC: HDC; Details: TThemedElementDetails; BoundingRect: TRect): TRect; virtual;
@ -821,7 +822,8 @@ end;
//----------------------------------------------------------------------------------------------------------------------
function TThemeServices.GetElementDetails(Detail: TThemedListview): TThemedElementDetails;
function TThemeServices.GetElementDetails(Detail: TThemedListView
): TThemedElementDetails;
var
Base: Integer;
begin
@ -1911,6 +1913,16 @@ begin
end;
end;
function TThemeServices.GetTextExtent(DC: HDC; Details: TThemedElementDetails;
const S: String; Flags: Cardinal; BoundingRect: PRect): TRect;
begin
if Assigned(BoundingRect) then
Result := BoundingRect^
else
Result := Rect(0, 0, 0, 0);
LCLIntf.DrawText(DC, PChar(S), Length(S), Result, DT_CALCRECT or Flags);
end;
//----------------------------------------------------------------------------------------------------------------------
function TThemeServices.ColorToRGB(Color: LongInt; Details: PThemedElementDetails = nil): COLORREF;