Make wxMSW owner drawn menu item code more clear and correct.

The user-visible effect of this change is that removing the item from the menu
and adding it back doesn't lose its icon any more.

At the code level, wxMenuItem::SetBitmaps() and related methods are
implemented outside of "#if wxUSE_OWNER_DRAWN" which allows to use them even
in minimalistic library builds. And IsOwnerDrawn() is not used any more to
determine whether the item has bitmaps, just only if it's really owner drawn,
making the code more clear and fixing at least the bug above and possible more.

Closes #13878.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76202 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-03-27 00:02:28 +00:00
parent d94b858bc9
commit da319a87cd
4 changed files with 72 additions and 71 deletions

View File

@@ -15,9 +15,10 @@
// headers
// ----------------------------------------------------------------------------
#include "wx/bitmap.h"
#if wxUSE_OWNER_DRAWN
#include "wx/ownerdrw.h"
#include "wx/bitmap.h"
struct tagRECT;
#endif
@@ -72,8 +73,6 @@ public:
);
#endif
#if wxUSE_OWNER_DRAWN
void SetBitmaps(const wxBitmap& bmpChecked,
const wxBitmap& bmpUnchecked = wxNullBitmap)
{
@@ -86,15 +85,16 @@ public:
DoSetBitmap(bmp, bChecked);
}
const wxBitmap& GetBitmap(bool bChecked = true) const
{ return (bChecked ? m_bmpChecked : m_bmpUnchecked); }
#if wxUSE_OWNER_DRAWN
void SetDisabledBitmap(const wxBitmap& bmpDisabled)
{
m_bmpDisabled = bmpDisabled;
SetOwnerDrawn(true);
}
const wxBitmap& GetBitmap(bool bChecked = true) const
{ return (bChecked ? m_bmpChecked : m_bmpUnchecked); }
const wxBitmap& GetDisabledBitmap() const
{ return m_bmpDisabled; }
@@ -115,6 +115,7 @@ private:
// helper function to determine if the item must be owner-drawn
bool MSWMustUseOwnerDrawn();
#endif // wxUSE_OWNER_DRAWN
// helper function to get a handle of bitmap associated with item
WXHBITMAP GetHBitmapForMenu(bool checked = true);
@@ -122,27 +123,16 @@ private:
// helper function to set/change the bitmap
void DoSetBitmap(const wxBitmap& bmp, bool bChecked);
#else // !wxUSE_OWNER_DRAWN
// Provide stubs for the public functions above to ensure that the code
// still compiles without wxUSE_OWNER_DRAWN -- it makes sense to just drop
// the bitmaps then instead of failing compilation.
void SetBitmaps(const wxBitmap& WXUNUSED(bmpChecked),
const wxBitmap& WXUNUSED(bmpUnchecked) = wxNullBitmap) { }
void SetBitmap(const wxBitmap& WXUNUSED(bmp),
bool WXUNUSED(bChecked) = true) { }
const wxBitmap& GetBitmap() const { return wxNullBitmap; }
#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
private:
// common part of all ctors
void Init();
#if wxUSE_OWNER_DRAWN
// item bitmaps
wxBitmap m_bmpChecked, // bitmap to put near the item
m_bmpUnchecked, // (checked is used also for 'uncheckable' items)
m_bmpDisabled;
m_bmpUnchecked; // (checked is used also for 'uncheckable' items)
#if wxUSE_OWNER_DRAWN
wxBitmap m_bmpDisabled;
#endif // wxUSE_OWNER_DRAWN
// Give wxMenu access to our MSWMustUseOwnerDrawn() and GetHBitmapForMenu().