Skip to content

Commit

Permalink
Merge branch 'print-preview-hidpi'
Browse files Browse the repository at this point in the history
High DPI-related fixes in wxArtProvider.

Closes #23127.

See #23131.
  • Loading branch information
vadz committed Jan 15, 2023
2 parents 0ccf681 + 9e56123 commit 4f6aa5a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
25 changes: 24 additions & 1 deletion src/common/artprov.cpp
Expand Up @@ -191,7 +191,30 @@ class wxBitmapBundleImplArt : public wxBitmapBundleImpl
// ones should just override CreateBitmapBundle() directly), so we only
// return the original bitmap scale, but hope that perhaps the provider
// will have other (e.g. x2) scales too, when our GetBitmap() is called.
return i++ ? 0.0 : m_bitmapScale;
//
// We also suppose that the art provider can always return a good (i.e.
// not obtained by rescaling) bitmap at scale 1, even if the original
// bitmap had a higher scale factor. This is necessary to allow using
// bitmaps on a secondary monitor using standard DPI when the primary
// monitor uses high DPI, as the art provider always uses the primary
// monitor DPI (being global, it can't do anything else).
switch ( i++ )
{
case 0:
// As explained above, this is always supported.
return 1.0;

case 1:
// If we already have a bitmap in a higher DPI, we can be sure
// that we can provide it too.
if ( m_bitmapScale != 1.0 )
return m_bitmapScale;
wxFALLTHROUGH;

default:
// No other scales supported.
return 0.0;
}
}

private:
Expand Down
2 changes: 1 addition & 1 deletion src/common/artstd.cpp
Expand Up @@ -232,7 +232,7 @@ wxDefaultArtProvider::CreateBitmapBundle(const wxArtID& id,
// We currently handle just a single SVG here.
if ( id == wxART_WX_LOGO )
{
wxSize sizeDef = size != wxDefaultSize ? size : GetSizeHint(client);
wxSize sizeDef = size != wxDefaultSize ? size : GetDIPSizeHint(client);
if ( sizeDef == wxDefaultSize )
{
// We really need some default size here.
Expand Down
2 changes: 1 addition & 1 deletion src/common/arttango.cpp
Expand Up @@ -209,7 +209,7 @@ wxTangoArtProvider::CreateBitmapBundle(const wxArtID& id,
if ( entry.id != id )
continue;

wxSize sizeDef = size != wxDefaultSize ? size : GetSizeHint(client);
wxSize sizeDef = size != wxDefaultSize ? size : GetDIPSizeHint(client);
if (sizeDef == wxDefaultSize)
{
// We really need some default size here, so keep using the same
Expand Down
4 changes: 2 additions & 2 deletions src/common/prntbase.cpp
Expand Up @@ -1517,8 +1517,8 @@ class SizerWithButtons
// We don't use (smaller) images inside a button with a text label but
// rather toolbar-like bitmap buttons hence use wxART_TOOLBAR and not
// wxART_BUTTON here.
wxBitmap bmp = wxArtProvider::GetBitmap(artId, wxART_TOOLBAR);
wxBitmapButton * const btn = new wxBitmapButton(m_parent, btnId, bmp);
wxBitmapBundle bb = wxArtProvider::GetBitmapBundle(artId, wxART_TOOLBAR);
wxBitmapButton * const btn = new wxBitmapButton(m_parent, btnId, bb);
btn->SetToolTip(tooltip);

Add(btn);
Expand Down
10 changes: 8 additions & 2 deletions src/msw/artmsw.cpp
Expand Up @@ -276,14 +276,20 @@ wxSize wxArtProvider::GetNativeDIPSizeHint(const wxArtClient& client)
}
else if ( client == wxART_FRAME_ICON )
{
// We're supposed to return a DPI-independent value here, but
// ::GetSystemMetrics() uses the primary monitor DPI, so undo this by
// explicitly dividing by its scale.
return wxSize(::GetSystemMetrics(SM_CXSMICON),
::GetSystemMetrics(SM_CYSMICON));
::GetSystemMetrics(SM_CYSMICON))
/ wxDisplay().GetScaleFactor();
}
else if ( client == wxART_CMN_DIALOG ||
client == wxART_MESSAGE_BOX )
{
// As above, we need to convert to DIPs explicitly.
return wxSize(::GetSystemMetrics(SM_CXICON),
::GetSystemMetrics(SM_CYICON));
::GetSystemMetrics(SM_CYICON))
/ wxDisplay().GetScaleFactor();
}
else if (client == wxART_BUTTON)
{
Expand Down

0 comments on commit 4f6aa5a

Please sign in to comment.