wxDC::LogicalToDevice{Rel}() now return unmirrored coordinates in RTL under wxMSW

Ditto for wxDC::DeviceToLogical{Rel}() functions.

In RTL layout, these functions always return unmirrored coordinates under wxGTK3
and wxQt. This is now the case under wxMSW too for consistency and also to fix
double-mirroring problem when passing the transformed coordinates to GDI drawing
functions. See wxGrid::Render() for example.
This commit is contained in:
AliKet
2026-05-16 14:12:48 +01:00
parent a99e0f821e
commit 49b4e65fac
2 changed files with 36 additions and 0 deletions
+28
View File
@@ -141,6 +141,34 @@ private:
wxDECLARE_NO_COPY_CLASS(wxBkModeChanger);
};
// ----------------------------------------------------------------------------
// Class to temporarily disable RTL layout if already set on the device context
// ----------------------------------------------------------------------------
// For consistency with wxGTK and wxQt, wxDC::LogicalToDevice{Rel}() and
// DeviceToLogical{Rel}() functions should return unmirrored coordinates
// in RTL layout to avoid double-mirroring when their results are passed
// to GDI drawing functions.
class wxScopedRTLDisabler
{
public:
explicit wxScopedRTLDisabler(HDC hdc)
: m_hdc(hdc), m_oldLayoutDir(::SetLayout(hdc, 0))
{
}
~wxScopedRTLDisabler()
{
::SetLayout(m_hdc, m_oldLayoutDir);
}
private:
HDC m_hdc;
const DWORD m_oldLayoutDir;
wxDECLARE_NO_COPY_CLASS(wxScopedRTLDisabler);
};
} // namespace wxMSWImpl
#endif // _MSW_PRIVATE_DC_H_
+8
View File
@@ -1969,6 +1969,8 @@ void wxMSWDCImpl::SetDeviceOrigin(wxCoord x, wxCoord y)
wxPoint wxMSWDCImpl::DeviceToLogical(wxCoord x, wxCoord y) const
{
wxScopedRTLDisabler disableRTL(GetHdc());
POINT p;
p.x = x;
p.y = y;
@@ -2015,6 +2017,8 @@ wxPoint wxMSWDCImpl::DeviceToLogical(wxCoord x, wxCoord y) const
wxPoint wxMSWDCImpl::LogicalToDevice(wxCoord x, wxCoord y) const
{
wxScopedRTLDisabler disableRTL(GetHdc());
POINT p;
p.x = x;
p.y = y;
@@ -2024,6 +2028,8 @@ wxPoint wxMSWDCImpl::LogicalToDevice(wxCoord x, wxCoord y) const
wxSize wxMSWDCImpl::DeviceToLogicalRel(int x, int y) const
{
wxScopedRTLDisabler disableRTL(GetHdc());
POINT p[2];
p[0].x = 0;
p[0].y = 0;
@@ -2035,6 +2041,8 @@ wxSize wxMSWDCImpl::DeviceToLogicalRel(int x, int y) const
wxSize wxMSWDCImpl::LogicalToDeviceRel(int x, int y) const
{
wxScopedRTLDisabler disableRTL(GetHdc());
POINT p[2];
p[0].x = 0;
p[0].y = 0;