Improve wxDataView on DPI change
Fix the row heights after a DPI change and adjust the column widths. Use DPIChangedEvent instead of MSWUpdateFontOnDPIChange because the child controls (m_clientArea, m_headerArea) need to update their font sizes first.
This commit is contained in:
@@ -316,6 +316,8 @@ protected:
|
||||
|
||||
virtual void DoEnableSystemTheme(bool enable, wxWindow* window) wxOVERRIDE;
|
||||
|
||||
void OnDPIChanged(wxDPIChangedEvent& event);
|
||||
|
||||
public: // utility functions not part of the API
|
||||
|
||||
// returns the "best" width for the idx-th column
|
||||
|
@@ -193,7 +193,7 @@ int wxDataViewColumn::GetWidth() const
|
||||
switch ( m_width )
|
||||
{
|
||||
case wxCOL_WIDTH_DEFAULT:
|
||||
return wxDVC_DEFAULT_WIDTH;
|
||||
return wxWindow::FromDIP(wxDVC_DEFAULT_WIDTH, m_owner);
|
||||
|
||||
case wxCOL_WIDTH_AUTOSIZE:
|
||||
wxCHECK_MSG( m_owner, wxDVC_DEFAULT_WIDTH, "no owner control" );
|
||||
@@ -709,8 +709,7 @@ public:
|
||||
bool Cleared();
|
||||
void Resort()
|
||||
{
|
||||
if ( m_rowHeightCache )
|
||||
m_rowHeightCache->Clear();
|
||||
ClearRowHeightCache();
|
||||
|
||||
if (!IsVirtualList())
|
||||
{
|
||||
@@ -718,6 +717,11 @@ public:
|
||||
}
|
||||
UpdateDisplay();
|
||||
}
|
||||
void ClearRowHeightCache()
|
||||
{
|
||||
if ( m_rowHeightCache )
|
||||
m_rowHeightCache->Clear();
|
||||
}
|
||||
|
||||
SortOrder GetSortOrder() const
|
||||
{
|
||||
@@ -1188,7 +1192,8 @@ wxSize wxDataViewTextRenderer::GetSize() const
|
||||
return GetTextExtent(m_text);
|
||||
}
|
||||
else
|
||||
return wxSize(wxDVC_DEFAULT_RENDERER_SIZE,wxDVC_DEFAULT_RENDERER_SIZE);
|
||||
return GetView()->FromDIP(wxSize(wxDVC_DEFAULT_RENDERER_SIZE,
|
||||
wxDVC_DEFAULT_RENDERER_SIZE));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
@@ -1251,7 +1256,8 @@ wxSize wxDataViewBitmapRenderer::GetSize() const
|
||||
else if (m_icon.IsOk())
|
||||
return wxSize( m_icon.GetWidth(), m_icon.GetHeight() );
|
||||
|
||||
return wxSize(wxDVC_DEFAULT_RENDERER_SIZE,wxDVC_DEFAULT_RENDERER_SIZE);
|
||||
return GetView()->FromDIP(wxSize(wxDVC_DEFAULT_RENDERER_SIZE,
|
||||
wxDVC_DEFAULT_RENDERER_SIZE));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
@@ -2769,12 +2775,9 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData
|
||||
m_count = list_model->GetCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m_rowHeightCache )
|
||||
{
|
||||
// specific position (row) is unclear, so clear whole height cache
|
||||
m_rowHeightCache->Clear();
|
||||
}
|
||||
ClearRowHeightCache();
|
||||
|
||||
wxDataViewTreeNode *parentNode = FindNode(parent);
|
||||
|
||||
@@ -3039,8 +3042,7 @@ bool wxDataViewMainWindow::Cleared()
|
||||
m_selection.Clear();
|
||||
m_currentRow = (unsigned)-1;
|
||||
|
||||
if ( m_rowHeightCache )
|
||||
m_rowHeightCache->Clear();
|
||||
ClearRowHeightCache();
|
||||
|
||||
if (GetModel())
|
||||
{
|
||||
@@ -5107,6 +5109,7 @@ void wxDataViewMainWindow::UpdateColumnSizes()
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase);
|
||||
wxBEGIN_EVENT_TABLE(wxDataViewCtrl, wxDataViewCtrlBase)
|
||||
EVT_SIZE(wxDataViewCtrl::OnSize)
|
||||
EVT_DPI_CHANGED(wxDataViewCtrl::OnDPIChanged)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
wxDataViewCtrl::~wxDataViewCtrl()
|
||||
@@ -5251,6 +5254,28 @@ void wxDataViewCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
|
||||
}
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::OnDPIChanged(wxDPIChangedEvent& event)
|
||||
{
|
||||
if ( m_clientArea )
|
||||
{
|
||||
m_clientArea->ClearRowHeightCache();
|
||||
m_clientArea->SetRowHeight(m_clientArea->GetDefaultRowHeight());
|
||||
}
|
||||
|
||||
for ( unsigned i = 0; i < m_cols.size(); ++i )
|
||||
{
|
||||
int minWidth = m_cols[i]->GetMinWidth();
|
||||
if ( minWidth > 0 )
|
||||
minWidth = minWidth * event.GetNewDPI().x / event.GetOldDPI().x;
|
||||
m_cols[i]->SetMinWidth(minWidth);
|
||||
|
||||
int width = m_cols[i]->WXGetManuallySetWidth();
|
||||
if ( width > 0 )
|
||||
width = width * event.GetNewDPI().x / event.GetOldDPI().x;
|
||||
m_cols[i]->SetWidth(width);
|
||||
}
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::SetFocus()
|
||||
{
|
||||
if (m_clientArea)
|
||||
|
Reference in New Issue
Block a user