Improve handling of right-to-left support in wxStaticBox on wxMSW.

Back in #8101 I made fixes for wxStaticBox and right-to-left handling under Windows.

While this worked fine in wx2.8, the old patch has some unfortunate consequences on wx3:
* Since the box is always set to LTR, its children also inherit LTR
* Text was always right-aligned

This follow-up patch removes the RTL-specific code from wxStaticBox. Instead, the wxMemoryDC in wxStaticBox::OnPaint is made to inherit attributes from the wxPaintDC.

Tested on XP (both XP and classic theme), Windows 7 and 8.1

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76783 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Tim Kosse
2014-06-28 09:49:45 +00:00
parent 0f84eca7c6
commit 0cfbdae7e9

View File

@@ -76,9 +76,6 @@ bool wxStaticBox::Create(wxWindow *parent,
if ( !MSWCreateControl(wxT("BUTTON"), label, pos, size) )
return false;
// Always use LTR layout. Otherwise, the label would be mirrored.
SetLayoutDirection(wxLayout_LeftToRight);
#ifndef __WXWINCE__
if (!wxSystemOptions::IsFalse(wxT("msw.staticbox.optimized-paint")))
{
@@ -117,12 +114,6 @@ WXDWORD wxStaticBox::MSWGetStyle(long style, WXDWORD *exstyle) const
styleWin |= BS_GROUPBOX;
if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
{
// Make sure label is on the right
styleWin |= BS_RIGHT;
}
return styleWin;
}
@@ -391,7 +382,7 @@ void wxStaticBox::PaintBackground(wxDC& dc, const RECT& rc)
::FillRect(GetHdcOf(*impl), &rc, hbr);
}
void wxStaticBox::PaintForeground(wxDC& dc, const RECT& rc)
void wxStaticBox::PaintForeground(wxDC& dc, const RECT&)
{
wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
MSWDefWindowProc(WM_PAINT, (WPARAM)GetHdcOf(*impl), 0);
@@ -407,10 +398,6 @@ void wxStaticBox::PaintForeground(wxDC& dc, const RECT& rc)
HDC hdc = GetHdcOf(*impl);
::SetTextColor(hdc, GetForegroundColour().GetPixel());
const bool rtl = wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft;
if ( rtl )
::SetTextAlign(hdc, TA_RTLREADING | TA_RIGHT);
// Get dimensions of the label
const wxString label = GetLabel();
@@ -458,18 +445,9 @@ void wxStaticBox::PaintForeground(wxDC& dc, const RECT& rc)
// FIXME: value of x is hardcoded as this is what it is on my system,
// no idea if it's true everywhere
RECT dimensions = {0, 0, 0, y};
if ( !rtl )
{
x = 9;
dimensions.left = x;
dimensions.right = x + width;
}
else
{
x = rc.right - 7;
dimensions.left = x - width;
dimensions.right = x;
}
x = 9;
dimensions.left = x;
dimensions.right = x + width;
// need to adjust the rectangle to cover all the label background
dimensions.left -= 2;
@@ -505,18 +483,9 @@ void wxStaticBox::PaintForeground(wxDC& dc, const RECT& rc)
}
// now draw the text
if ( !rtl )
{
RECT rc2 = { x, 0, x + width, y };
::DrawText(hdc, label.t_str(), label.length(), &rc2,
drawTextFlags);
}
else // RTL
{
RECT rc2 = { x, 0, x - width, y };
::DrawText(hdc, label.t_str(), label.length(), &rc2,
drawTextFlags | DT_RTLREADING);
}
RECT rc2 = { x, 0, x + width, y };
::DrawText(hdc, label.t_str(), label.length(), &rc2,
drawTextFlags);
}
#endif // wxUSE_UXTHEME
}
@@ -525,9 +494,10 @@ void wxStaticBox::OnPaint(wxPaintEvent& WXUNUSED(event))
{
RECT rc;
::GetClientRect(GetHwnd(), &rc);
wxPaintDC dc(this);
// draw the entire box in a memory DC
wxMemoryDC memdc;
wxMemoryDC memdc(&dc);
wxBitmap bitmap(rc.right, rc.bottom);
memdc.SelectObject(bitmap);
@@ -540,7 +510,6 @@ void wxStaticBox::OnPaint(wxPaintEvent& WXUNUSED(event))
// note that it seems to be faster to do 4 small blits here and then paint
// directly into wxPaintDC than painting background in wxMemoryDC and then
// blitting everything at once to wxPaintDC, this is why we do it like this
wxPaintDC dc(this);
int borderTop, border;
GetBordersForSizer(&borderTop, &border);