win32: use ThemeServices to draw TBitBtn (maybe fix issue #0013920)

git-svn-id: trunk@20538 -
This commit is contained in:
paul 2009-06-09 06:27:08 +00:00
parent adb0522aff
commit dda7ce7306

View File

@ -148,12 +148,22 @@ var
{$ENDIF} {$ENDIF}
procedure DrawBitmap(AState: TButtonState; UseThemes: Boolean); procedure DrawBitmap(AState: TButtonState; UseThemes: Boolean);
const
ButtonsDetail: array[TButtonState] of TThemedButton = (
{ bsUp } tbPushButtonNormal,
{ bsDisabled } tbPushButtonDisabled,
{ bsDown } tbPushButtonPressed,
{ bsExclusive } tbPushButtonNormal,
{ bsHot } tbPushButtonHot
);
var var
TextFlags: integer; // flags for caption (enabled or disabled) TextFlags: integer; // flags for caption (enabled or disabled)
glyphWidth, glyphHeight: integer; glyphWidth, glyphHeight: integer;
OldBitmapHandle: HBITMAP; // Handle of the provious bitmap in hdcNewBitmap OldBitmapHandle: HBITMAP; // Handle of the provious bitmap in hdcNewBitmap
AIndex: Integer; AIndex: Integer;
AEffect: TGraphicsDrawEffect; AEffect: TGraphicsDrawEffect;
Details: TThemedElementDetails;
begin begin
glyphWidth := srcWidth; glyphWidth := srcWidth;
glyphHeight := srcHeight; glyphHeight := srcHeight;
@ -215,19 +225,28 @@ var
end; end;
end; end;
SetBkMode(hdcNewBitmap, TRANSPARENT); SetBkMode(hdcNewBitmap, TRANSPARENT);
{$IFDEF WindowsUnicodeSupport} if not UseThemes then
if UnicodeEnabledOS then
begin begin
ButtonCaptionW := UTF8ToUTF16(ButtonCaption); {$IFDEF WindowsUnicodeSupport}
DrawStateW(hdcNewBitmap, 0, nil, LPARAM(ButtonCaptionW), 0, XDestText, YDestText, 0, 0, TextFlags); if UnicodeEnabledOS then
begin
ButtonCaptionW := UTF8ToUTF16(ButtonCaption);
DrawStateW(hdcNewBitmap, 0, nil, LPARAM(ButtonCaptionW), 0, XDestText, YDestText, 0, 0, TextFlags);
end
else begin
ButtonCaptionA := Utf8ToAnsi(ButtonCaption);
DrawState(hdcNewBitmap, 0, nil, LPARAM(ButtonCaptionA), 0, XDestText, YDestText, 0, 0, TextFlags);
end;
{$ELSE}
DrawState(hdcNewBitmap, 0, nil, LPARAM(ButtonCaption), 0, XDestText, YDestText, 0, 0, TextFlags);
{$ENDIF}
end end
else begin else
ButtonCaptionA := Utf8ToAnsi(ButtonCaption); begin
DrawState(hdcNewBitmap, 0, nil, LPARAM(ButtonCaptionA), 0, XDestText, YDestText, 0, 0, TextFlags); Details := ThemeServices.GetElementDetails(ButtonsDetail[AState]);
ThemeServices.DrawText(hdcNewBitmap, Details, ButtonCaption,
Rect(XDestText, YDestText, XDestText + TextSize.cx, YDestText + TextSize.cy), 0, 0);
end; end;
{$ELSE}
DrawState(hdcNewBitmap, 0, nil, LPARAM(ButtonCaption), 0, XDestText, YDestText, 0, 0, TextFlags);
{$ENDIF}
SelectObject(hdcNewBitmap, OldBitmapHandle); SelectObject(hdcNewBitmap, OldBitmapHandle);
end; end;