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:
Maarten Bent
2019-01-10 22:24:45 +01:00
parent fd2cf1f4e2
commit 56fab0aabb
3 changed files with 42 additions and 15 deletions

View File

@@ -895,9 +895,9 @@ public:
void SetDropEffect( wxDragResult effect ) { m_dropEffect = effect; }
wxDragResult GetDropEffect() const { return m_dropEffect; }
// for plaforms (currently only OSX) that support Drag/Drop insertion of items,
// this is the proposed child index for the insertion
void SetProposedDropIndex(int index) { m_proposedDropIndex = index; }
int GetProposedDropIndex() const { return m_proposedDropIndex;}
// this is the proposed child index for the insertion
void SetProposedDropIndex(int index) { m_proposedDropIndex = index; }
int GetProposedDropIndex() const { return m_proposedDropIndex;}
#endif // wxUSE_DRAG_AND_DROP
virtual wxEvent *Clone() const wxOVERRIDE { return new wxDataViewEvent(*this); }

View File

@@ -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

View File

@@ -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));
}
// ---------------------------------------------------------
@@ -2770,11 +2776,8 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData
}
else
{
if ( m_rowHeightCache )
{
// specific position (row) is unclear, so clear whole height cache
m_rowHeightCache->Clear();
}
// specific position (row) is unclear, so clear whole height cache
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)