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