adjust the minimal menu item height to be lesser than the menubar height; some code cleanup

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51079 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-01-07 18:50:07 +00:00
parent 117f566fcc
commit 55e04bbd7e
2 changed files with 28 additions and 26 deletions

View File

@@ -164,7 +164,6 @@ private:
m_bmpDisabled; m_bmpDisabled;
size_t m_nHeight, // font height size_t m_nHeight, // font height
m_nMinHeight, // minimum height, as determined by user's system settings
m_nMarginWidth; // space occupied by bitmap to the left of the item m_nMarginWidth; // space occupied by bitmap to the left of the item
}; };

View File

@@ -16,9 +16,10 @@
#pragma hdrstop #pragma hdrstop
#endif #endif
#if wxUSE_OWNER_DRAWN
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/window.h" #include "wx/window.h"
#include "wx/msw/private.h"
#include "wx/font.h" #include "wx/font.h"
#include "wx/bitmap.h" #include "wx/bitmap.h"
#include "wx/image.h" #include "wx/image.h"
@@ -33,7 +34,7 @@
#include "wx/ownerdrw.h" #include "wx/ownerdrw.h"
#include "wx/fontutil.h" #include "wx/fontutil.h"
#if wxUSE_OWNER_DRAWN #include "wx/msw/private.h"
#ifndef SPI_GETKEYBOARDCUES #ifndef SPI_GETKEYBOARDCUES
#define SPI_GETKEYBOARDCUES 0x100A #define SPI_GETKEYBOARDCUES 0x100A
@@ -42,27 +43,29 @@
class wxMSWSystemMenuFontModule : public wxModule class wxMSWSystemMenuFontModule : public wxModule
{ {
public: public:
virtual bool OnInit() virtual bool OnInit()
{ {
ms_systemMenuFont = new wxFont; WinStruct<NONCLIENTMETRICS> nm;
::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &nm, 0);
#if defined(__WXMSW__) && defined(__WIN32__) && defined(SM_CXMENUCHECK)
NONCLIENTMETRICS nm;
nm.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,0,&nm,0);
ms_systemMenuButtonWidth = nm.iMenuHeight; ms_systemMenuButtonWidth = nm.iMenuHeight;
ms_systemMenuHeight = nm.iMenuHeight;
// iMenuHeight is the menu bar height and the menu items are less tall,
// although I don't know by how much -- below is the value for my system
ms_systemMenuHeight = nm.iMenuHeight - 4;
// create menu font // create menu font
wxNativeFontInfo info; wxNativeFontInfo info;
memcpy(&info.lf, &nm.lfMenuFont, sizeof(LOGFONT)); memcpy(&info.lf, &nm.lfMenuFont, sizeof(LOGFONT));
ms_systemMenuFont->Create(info); ms_systemMenuFont = new wxFont(info);
if (SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &ms_showCues, 0) == 0) if ( ::SystemParametersInfo(SPI_GETKEYBOARDCUES, 0,
&ms_showCues, 0) == 0 )
{
// if it's not supported, we must be on an old Windows version
// which always shows them
ms_showCues = true; ms_showCues = true;
#endif }
return true; return true;
} }
@@ -74,9 +77,10 @@ public:
} }
static wxFont* ms_systemMenuFont; static wxFont* ms_systemMenuFont;
static int ms_systemMenuButtonWidth; // windows clean install default static int ms_systemMenuButtonWidth;
static int ms_systemMenuHeight; // windows clean install default static int ms_systemMenuHeight;
static bool ms_showCues; static bool ms_showCues;
private: private:
DECLARE_DYNAMIC_CLASS(wxMSWSystemMenuFontModule) DECLARE_DYNAMIC_CLASS(wxMSWSystemMenuFontModule)
}; };
@@ -86,8 +90,8 @@ private:
// SystemParametersInfo() call. // SystemParametersInfo() call.
wxFont* wxMSWSystemMenuFontModule::ms_systemMenuFont = NULL; wxFont* wxMSWSystemMenuFontModule::ms_systemMenuFont = NULL;
int wxMSWSystemMenuFontModule::ms_systemMenuButtonWidth = 18; // windows clean install default int wxMSWSystemMenuFontModule::ms_systemMenuButtonWidth = 18;
int wxMSWSystemMenuFontModule::ms_systemMenuHeight = 18; // windows clean install default int wxMSWSystemMenuFontModule::ms_systemMenuHeight = 18;
bool wxMSWSystemMenuFontModule::ms_showCues = true; bool wxMSWSystemMenuFontModule::ms_showCues = true;
IMPLEMENT_DYNAMIC_CLASS(wxMSWSystemMenuFontModule, wxModule) IMPLEMENT_DYNAMIC_CLASS(wxMSWSystemMenuFontModule, wxModule)
@@ -138,7 +142,6 @@ wxOwnerDrawn::wxOwnerDrawn(const wxString& str,
m_isMenuItem = bMenuItem; m_isMenuItem = bMenuItem;
m_nHeight = 0; m_nHeight = 0;
m_nMarginWidth = ms_nLastMarginWidth; m_nMarginWidth = ms_nLastMarginWidth;
m_nMinHeight = wxMSWSystemMenuFontModule::ms_systemMenuHeight;
} }
wxOwnerDrawn::~wxOwnerDrawn() wxOwnerDrawn::~wxOwnerDrawn()
@@ -151,7 +154,7 @@ bool wxOwnerDrawn::IsMenuItem() const
} }
// these items will be set during the first invocation of the c'tor, // these items will be set during the first invocation of the ctor,
// because the values will be determined by checking the system settings, // because the values will be determined by checking the system settings,
// which is a chunk of code // which is a chunk of code
size_t wxOwnerDrawn::ms_nDefaultMarginWidth = 0; size_t wxOwnerDrawn::ms_nDefaultMarginWidth = 0;
@@ -216,10 +219,9 @@ bool wxOwnerDrawn::OnMeasureItem(size_t *pwidth, size_t *pheight)
// increase size to accommodate bigger bitmaps if necessary // increase size to accommodate bigger bitmaps if necessary
if (m_bmpChecked.Ok()) if (m_bmpChecked.Ok())
{ {
// Is BMP height larger then text height? // Is BMP height larger than text height?
size_t adjustedHeight = m_bmpChecked.GetHeight() + size_t adjustedHeight = m_bmpChecked.GetHeight();
2*wxSystemSettings::GetMetric(wxSYS_EDGE_Y); if ( *pheight < adjustedHeight )
if (*pheight < adjustedHeight)
*pheight = adjustedHeight; *pheight = adjustedHeight;
const size_t widthBmp = m_bmpChecked.GetWidth(); const size_t widthBmp = m_bmpChecked.GetWidth();
@@ -239,8 +241,9 @@ bool wxOwnerDrawn::OnMeasureItem(size_t *pwidth, size_t *pheight)
*pwidth += 4; *pwidth += 4;
// make sure that this item is at least as tall as the system menu height // make sure that this item is at least as tall as the system menu height
if ( *pheight < m_nMinHeight ) const size_t heightStd = wxMSWSystemMenuFontModule::ms_systemMenuHeight;
*pheight = m_nMinHeight; if ( *pheight < heightStd )
*pheight = heightStd;
// remember height for use in OnDrawItem // remember height for use in OnDrawItem
m_nHeight = *pheight; m_nHeight = *pheight;