Fix font size of wxMenuItem with custom font on DPI change
Recalculate MenuDrawData sizes after the DPI changes, and reset the maximum accelerator width.
This commit is contained in:
@@ -29,7 +29,6 @@
|
|||||||
#include "wx/stockitem.h"
|
#include "wx/stockitem.h"
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/app.h"
|
|
||||||
#include "wx/dcmemory.h"
|
#include "wx/dcmemory.h"
|
||||||
#include "wx/font.h"
|
#include "wx/font.h"
|
||||||
#include "wx/bitmap.h"
|
#include "wx/bitmap.h"
|
||||||
@@ -235,28 +234,41 @@ public:
|
|||||||
|
|
||||||
bool Theme; // is data initialized for FullTheme?
|
bool Theme; // is data initialized for FullTheme?
|
||||||
|
|
||||||
static const MenuDrawData* Get()
|
int dpi; // DPI used for calculating sizes
|
||||||
|
|
||||||
|
static const MenuDrawData* Get(wxMenu* menu)
|
||||||
{
|
{
|
||||||
|
const wxWindow* window = menu->GetWindow();
|
||||||
// notice that s_menuData can't be created as a global variable because
|
// notice that s_menuData can't be created as a global variable because
|
||||||
// it needs a window to initialize and no windows exist at the time of
|
// it needs a window to initialize and no windows exist at the time of
|
||||||
// globals initialization yet
|
// globals initialization yet
|
||||||
if ( !ms_instance )
|
if ( !ms_instance )
|
||||||
{
|
{
|
||||||
static MenuDrawData s_menuData;
|
static MenuDrawData s_menuData(window);
|
||||||
ms_instance = &s_menuData;
|
ms_instance = &s_menuData;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_UXTHEME
|
#if wxUSE_UXTHEME
|
||||||
bool theme = MenuLayout() == FullTheme;
|
bool theme = MenuLayout() == FullTheme;
|
||||||
if ( ms_instance->Theme != theme )
|
if ( ms_instance->Theme != theme )
|
||||||
ms_instance->Init();
|
{
|
||||||
|
ms_instance->Init(window);
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif // wxUSE_UXTHEME
|
#endif // wxUSE_UXTHEME
|
||||||
|
{
|
||||||
|
if ( ms_instance->dpi != window->GetDPI().y )
|
||||||
|
{
|
||||||
|
ms_instance->Init(window);
|
||||||
|
menu->ResetMaxAccelWidth();
|
||||||
|
}
|
||||||
|
}
|
||||||
return ms_instance;
|
return ms_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuDrawData()
|
MenuDrawData(const wxWindow* window)
|
||||||
{
|
{
|
||||||
Init();
|
Init(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -296,17 +308,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Init();
|
void Init(wxWindow const* window);
|
||||||
|
|
||||||
static MenuDrawData* ms_instance;
|
static MenuDrawData* ms_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
MenuDrawData* MenuDrawData::ms_instance = NULL;
|
MenuDrawData* MenuDrawData::ms_instance = NULL;
|
||||||
|
|
||||||
void MenuDrawData::Init()
|
void MenuDrawData::Init(wxWindow const* window)
|
||||||
{
|
{
|
||||||
#if wxUSE_UXTHEME
|
#if wxUSE_UXTHEME
|
||||||
const wxWindow* window = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
|
|
||||||
if ( IsUxThemeActive() )
|
if ( IsUxThemeActive() )
|
||||||
{
|
{
|
||||||
wxUxThemeHandle hTheme(window, L"MENU");
|
wxUxThemeHandle hTheme(window, L"MENU");
|
||||||
@@ -348,7 +359,8 @@ void MenuDrawData::Init()
|
|||||||
|
|
||||||
wxUxThemeFont themeFont;
|
wxUxThemeFont themeFont;
|
||||||
::GetThemeSysFont(hTheme, TMT_MENUFONT, themeFont.GetPtr());
|
::GetThemeSysFont(hTheme, TMT_MENUFONT, themeFont.GetPtr());
|
||||||
Font = wxFont(wxNativeFontInfo(themeFont.GetLOGFONT(), window));
|
// Use NULL window for wxNativeFontInfo, height it is already at the correct ppi
|
||||||
|
Font = wxFont(wxNativeFontInfo(themeFont.GetLOGFONT(), NULL));
|
||||||
|
|
||||||
Theme = true;
|
Theme = true;
|
||||||
|
|
||||||
@@ -407,6 +419,7 @@ void MenuDrawData::Init()
|
|||||||
|
|
||||||
AlwaysShowCues = value == 1;
|
AlwaysShowCues = value == 1;
|
||||||
|
|
||||||
|
dpi = window->GetDPI().y;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
@@ -783,7 +796,7 @@ wxString wxMenuItem::GetName() const
|
|||||||
|
|
||||||
bool wxMenuItem::OnMeasureItem(size_t *width, size_t *height)
|
bool wxMenuItem::OnMeasureItem(size_t *width, size_t *height)
|
||||||
{
|
{
|
||||||
const MenuDrawData* data = MenuDrawData::Get();
|
const MenuDrawData* data = MenuDrawData::Get(GetMenu());
|
||||||
|
|
||||||
if ( IsOwnerDrawn() )
|
if ( IsOwnerDrawn() )
|
||||||
{
|
{
|
||||||
@@ -875,7 +888,7 @@ bool wxMenuItem::OnMeasureItem(size_t *width, size_t *height)
|
|||||||
bool wxMenuItem::OnDrawItem(wxDC& dc, const wxRect& rc,
|
bool wxMenuItem::OnDrawItem(wxDC& dc, const wxRect& rc,
|
||||||
wxODAction WXUNUSED(act), wxODStatus stat)
|
wxODAction WXUNUSED(act), wxODStatus stat)
|
||||||
{
|
{
|
||||||
const MenuDrawData* data = MenuDrawData::Get();
|
const MenuDrawData* data = MenuDrawData::Get(GetMenu());
|
||||||
|
|
||||||
wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
|
wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
|
||||||
HDC hdc = GetHdcOf(*impl);
|
HDC hdc = GetHdcOf(*impl);
|
||||||
@@ -1167,7 +1180,7 @@ void wxMenuItem::DrawStdCheckMark(WXHDC hdc_, const RECT* rc, wxODStatus stat)
|
|||||||
{
|
{
|
||||||
wxUxThemeHandle hTheme(GetMenu()->GetWindow(), L"MENU");
|
wxUxThemeHandle hTheme(GetMenu()->GetWindow(), L"MENU");
|
||||||
|
|
||||||
const MenuDrawData* data = MenuDrawData::Get();
|
const MenuDrawData* data = MenuDrawData::Get(GetMenu());
|
||||||
|
|
||||||
// rect for background must be without check margins
|
// rect for background must be without check margins
|
||||||
RECT rcBg = *rc;
|
RECT rcBg = *rc;
|
||||||
@@ -1234,7 +1247,8 @@ void wxMenuItem::GetFontToUse(wxFont& font) const
|
|||||||
{
|
{
|
||||||
font = GetFont();
|
font = GetFont();
|
||||||
if ( !font.IsOk() )
|
if ( !font.IsOk() )
|
||||||
font = MenuDrawData::Get()->Font;
|
font = MenuDrawData::Get(GetMenu())->Font;
|
||||||
|
font.WXAdjustToPPI(GetMenu()->GetWindow()->GetDPI());
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMenuItem::GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const
|
void wxMenuItem::GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const
|
||||||
|
Reference in New Issue
Block a user