mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-09-25 17:15:45 +08:00
Move code for updating sizers on DPI change to wxSizer itself
Replacing the existing global UpdateSizerOnDPIChange() with a member function will allow accessing private wxSizer variables in it (see the next commit) and making it virtual will allow overriding it in the derived classes to update more fields on DPI change. No real changes yet. This commit is best viewed with Git --color-moved option.
This commit is contained in:
@@ -748,6 +748,15 @@ public:
|
||||
virtual bool InformFirstDirection( int WXUNUSED(direction), int WXUNUSED(size), int WXUNUSED(availableOtherDir) )
|
||||
{ return false; }
|
||||
|
||||
// Update stored dimensions expressed in logical pixels on DPI change.
|
||||
// This is only needed on the platforms where logical pixels differ from
|
||||
// the physical ones, e.g MSW.
|
||||
//
|
||||
// This is an internal function, only called by wxWidgets itself.
|
||||
#ifndef wxHAS_DPI_INDEPENDENT_PIXELS
|
||||
virtual void UpdateOnDPIChange(wxSize oldDPI, wxSize newDPI);
|
||||
#endif // !wxHAS_DPI_INDEPENDENT_PIXELS
|
||||
|
||||
protected:
|
||||
wxSize m_size;
|
||||
wxSize m_minSize;
|
||||
|
||||
@@ -33,6 +33,10 @@
|
||||
#include "wx/listimpl.cpp"
|
||||
#include "wx/private/window.h"
|
||||
|
||||
#ifndef wxHAS_DPI_INDEPENDENT_PIXELS
|
||||
#include "wx/private/rescale.h"
|
||||
#endif // !wxHAS_DPI_INDEPENDENT_PIXELS
|
||||
|
||||
#include <memory>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -1615,6 +1619,44 @@ bool wxSizer::IsShown( size_t index ) const
|
||||
return node->GetData()->IsShown();
|
||||
}
|
||||
|
||||
#ifndef wxHAS_DPI_INDEPENDENT_PIXELS
|
||||
|
||||
// Recursively update the sizer and any child sizers and spacers.
|
||||
void wxSizer::UpdateOnDPIChange(wxSize oldDPI, wxSize newDPI)
|
||||
{
|
||||
for ( wxSizerItemList::compatibility_iterator
|
||||
node = GetChildren().GetFirst();
|
||||
node;
|
||||
node = node->GetNext() )
|
||||
{
|
||||
wxSizerItem* sizerItem = node->GetData();
|
||||
|
||||
int border = sizerItem->GetBorder();
|
||||
border = wxRescaleCoord(border).From(oldDPI).To(newDPI);
|
||||
sizerItem->SetBorder(border);
|
||||
|
||||
// only scale sizers and spacers, not windows
|
||||
if ( sizerItem->IsSizer() || sizerItem->IsSpacer() )
|
||||
{
|
||||
wxSize min = sizerItem->GetMinSize();
|
||||
min = wxRescaleCoord(min).From(oldDPI).To(newDPI);
|
||||
sizerItem->SetMinSize(min);
|
||||
|
||||
if ( sizerItem->IsSpacer() )
|
||||
{
|
||||
wxSize size = sizerItem->GetSize();
|
||||
size = wxRescaleCoord(size).From(oldDPI).To(newDPI);
|
||||
sizerItem->SetDimension(wxDefaultPosition, size);
|
||||
}
|
||||
|
||||
// Update any child sizers if this is a sizer
|
||||
if ( wxSizer* childSizer = sizerItem->GetSizer() )
|
||||
childSizer->UpdateOnDPIChange(oldDPI, newDPI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !wxHAS_DPI_INDEPENDENT_PIXELS
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxGridSizer
|
||||
|
||||
+2
-41
@@ -4983,46 +4983,6 @@ void wxWindowMSW::MSWUpdateFontOnDPIChange(const wxSize& newDPI)
|
||||
}
|
||||
}
|
||||
|
||||
// Called from MSWUpdateonDPIChange() to recursively update the window
|
||||
// sizer and any child sizers and spacers.
|
||||
static void UpdateSizerOnDPIChange(wxSizer* sizer, wxSize oldDPI, wxSize newDPI)
|
||||
{
|
||||
if ( !sizer )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for ( wxSizerItemList::compatibility_iterator
|
||||
node = sizer->GetChildren().GetFirst();
|
||||
node;
|
||||
node = node->GetNext() )
|
||||
{
|
||||
wxSizerItem* sizerItem = node->GetData();
|
||||
|
||||
int border = sizerItem->GetBorder();
|
||||
border = wxRescaleCoord(border).From(oldDPI).To(newDPI);
|
||||
sizerItem->SetBorder(border);
|
||||
|
||||
// only scale sizers and spacers, not windows
|
||||
if ( sizerItem->IsSizer() || sizerItem->IsSpacer() )
|
||||
{
|
||||
wxSize min = sizerItem->GetMinSize();
|
||||
min = wxRescaleCoord(min).From(oldDPI).To(newDPI);
|
||||
sizerItem->SetMinSize(min);
|
||||
|
||||
if ( sizerItem->IsSpacer() )
|
||||
{
|
||||
wxSize size = sizerItem->GetSize();
|
||||
size = wxRescaleCoord(size).From(oldDPI).To(newDPI);
|
||||
sizerItem->SetDimension(wxDefaultPosition, size);
|
||||
}
|
||||
|
||||
// Update any child sizers if this is a sizer
|
||||
UpdateSizerOnDPIChange(sizerItem->GetSizer(), oldDPI, newDPI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
wxWindowMSW::MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI)
|
||||
{
|
||||
@@ -5041,7 +5001,8 @@ wxWindowMSW::MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI)
|
||||
MSWUpdateFontOnDPIChange(newDPI);
|
||||
|
||||
// update sizers
|
||||
UpdateSizerOnDPIChange(GetSizer(), oldDPI, newDPI);
|
||||
if ( wxSizer* const sizer = GetSizer() )
|
||||
sizer->UpdateOnDPIChange(oldDPI, newDPI);
|
||||
|
||||
// update children
|
||||
for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
|
||||
|
||||
Reference in New Issue
Block a user