Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Minor Bug+Patch: Themed Groupbox captions incorrectly drawn

Thanks! I'll apply the patch into the next version.
MaierMan

Minor Bug+Patch: Themed Groupbox captions incorrectly drawn

I already reported this to Mike Lischke (ThemeManager) some time ago:
ThemeManager (and therefore your XPGroupbox code) makes use of GetTextExtent32 instead of GetThemeTextExtent.
This causes incorrect GroupBox caption-drawing if your theme does not use standard font, eg. when the font style is bold.

Screen of Problem:
<invalid link removed>
Patched:
<invalid link removed>
(Theme: ClearLoks/Human)

Patch (Function define according to source/win32/rtl/win/UxTheme.pas)
--- E:\misc\winscp380source-orig\packages\my\XPThemes.pas   Sat Oct 16 19:11:14 2004

+++ E:\misc\winscp380source\packages\my\XPThemes.pas   Thu Mar 16 22:24:10 2006
@@ -31,6 +31,8 @@
     FCloseThemeData: function(hTheme: THandle): HRESULT; stdcall;
     FDrawThemeText: function(hTheme: THandle; hdc: HDC; iPartId, iStateId: Integer; pszText: LPCWSTR; iCharCount: Integer;
       dwTextFlags, dwTextFlags2: DWORD; const pRect: TRect): HRESULT; stdcall;
+    FGetThemeTextExtent: function(hTheme: THandle; hdc: HDC; iPartId, iStateId: Integer; pszText: LPCWSTR; iCharCount: Integer;
+      dwTextFlags: DWORD; pBoundingRect: PRECT; var pExtentRect: TRect): HRESULT; stdcall;
     FIsThemeBackgroundPartiallyTransparent: function(hTheme: THandle; iPartId, iStateId: Integer): BOOL; stdcall;
     FDrawThemeParentBackground: function(hwnd: HWND; hdc: HDC; prc: PRECT): HRESULT; stdcall;
     FGetThemeAppProperties: function: DWORD; stdcall;
@@ -78,6 +80,7 @@
     FOpenThemeData := GetProcAddress(FThemeLib, 'OpenThemeData');
     FCloseThemeData := GetProcAddress(FThemeLib, 'CloseThemeData');
     FDrawThemeText := GetProcAddress(FThemeLib, 'DrawThemeText');
+    FGetThemeTextExtent := GetProcAddress(FThemeLib, 'GetThemeTextExtent');
     FIsThemeBackgroundPartiallyTransparent := GetProcAddress(FThemeLib, 'IsThemeBackgroundPartiallyTransparent');
     FDrawThemeParentBackground := GetProcAddress(FThemeLib, 'DrawThemeParentBackground');
     FGetThemeAppProperties := GetProcAddress(FThemeLib, 'GetThemeAppProperties');
@@ -161,8 +164,9 @@
     if Text <> '' then
     begin
       SetTextColor(DC, Graphics.ColorToRGB(Font.Color));
-      GetTextExtentPoint32(DC, PChar(Text), Length(Text), Size);
-      TextR := Rect(0, 0, Size.cx, Size.cy);
+      WText := Text;
+      XPTheme.FGetThemeTextExtent(GetButtonThemeData, DC, BP_GROUPBOX, StateID,
+        PWideChar(WText), Length(WText), DT_LEFT, nil, TextR);
       if not UseRightToLeftAlignment then
         OffsetRect(TextR, 8, 0)
       else
@@ -185,7 +189,6 @@
     SelectClipRgn(DC, 0);
     if Text <> '' then
     begin
-      WText := Text;
       XPTheme.FDrawThemeText(GetButtonThemeData, DC, BP_GROUPBOX, StateID,
         PWideChar(WText), Length(WText), DT_LEFT, 0, TextR);
     end;