Handle DPI change in wxSplitterWindow

Adjust the minimum pane size to the new DPI.
Keep the sash in the same relative position.
This commit is contained in:
Maarten Bent
2022-03-08 22:16:50 +01:00
parent e43895e531
commit 1ecebd5c7c
2 changed files with 25 additions and 0 deletions

View File

@@ -201,6 +201,8 @@ public:
// Adjusts the panes
void OnSize(wxSizeEvent& event);
void OnDPIChanged(wxDPIChangedEvent& event);
// In live mode, resize child windows in idle time
void OnInternalIdle() wxOVERRIDE;
@@ -295,6 +297,7 @@ protected:
bool m_needUpdating:1;
bool m_permitUnsplitAlways:1;
bool m_isHot:1;
bool m_sizeAfterDPIChange:1;
private:
wxDECLARE_DYNAMIC_CLASS(wxSplitterWindow);

View File

@@ -35,6 +35,11 @@
#include "wx/osx/private/available.h"
#endif
#ifdef __WINDOWS__
// We only need it to get ::MulDiv() declaration, used by wxMulDivInt32().
#include "wx/msw/wrapwin.h"
#endif
#include "wx/renderer.h"
#include <stdlib.h>
@@ -61,6 +66,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent, wxNotifyEvent);
wxBEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow)
EVT_PAINT(wxSplitterWindow::OnPaint)
EVT_SIZE(wxSplitterWindow::OnSize)
EVT_DPI_CHANGED(wxSplitterWindow::OnDPIChanged)
EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent)
EVT_MOUSE_CAPTURE_LOST(wxSplitterWindow::OnMouseCaptureLost)
@@ -140,6 +146,7 @@ void wxSplitterWindow::Init()
m_needUpdating = false;
m_isHot = false;
m_sizeAfterDPIChange = false;
}
wxSplitterWindow::~wxSplitterWindow()
@@ -473,6 +480,13 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
// Apply gravity if we use it.
int delta = (int) ( (size - old_size)*m_sashGravity );
if ( m_sizeAfterDPIChange )
{
// Keep the same relative position.
delta = wxMulDivInt32(size, m_sashPosition, old_size) - m_sashPosition;
m_sizeAfterDPIChange = false;
}
// If delta == 0 then sash will be set according to the windows min size.
if ( delta != 0 )
{
@@ -520,6 +534,14 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
SizeWindows();
}
void wxSplitterWindow::OnDPIChanged(wxDPIChangedEvent& event)
{
m_minimumPaneSize = event.ScaleX(m_minimumPaneSize);
m_sizeAfterDPIChange = true;
event.Skip();
}
void wxSplitterWindow::SetSashGravity(double gravity)
{
wxCHECK_RET( gravity >= 0. && gravity <= 1.,