Clean up GetHBitmapForMenu.
Merge wxMenuItem::GetHBitmapForMenuCheckable and ::DoGetHBitmapForMenu into wxMenuItem::GetHBitmapForMenu. Change its boolean parameter to an enum specifying the kind of bitmap that is wanted (normal, checked, or unchecked). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76760 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -117,11 +117,15 @@ private:
|
|||||||
bool MSWMustUseOwnerDrawn();
|
bool MSWMustUseOwnerDrawn();
|
||||||
#endif // wxUSE_OWNER_DRAWN
|
#endif // wxUSE_OWNER_DRAWN
|
||||||
|
|
||||||
// helper function to get a handle for normal bitmap associated with item
|
enum BitmapKind
|
||||||
WXHBITMAP GetHBitmapForMenu(bool checked = true);
|
{
|
||||||
|
Normal,
|
||||||
|
Checked,
|
||||||
|
Unchecked
|
||||||
|
};
|
||||||
|
|
||||||
// helper function to get a handle for checkable bitmap associated with item
|
// helper function to get a handle for bitmap associated with item
|
||||||
WXHBITMAP GetHBitmapForMenuCheckable(bool checked);
|
WXHBITMAP GetHBitmapForMenu(BitmapKind kind);
|
||||||
|
|
||||||
// helper function to set/change the bitmap
|
// helper function to set/change the bitmap
|
||||||
void DoSetBitmap(const wxBitmap& bmp, bool bChecked);
|
void DoSetBitmap(const wxBitmap& bmp, bool bChecked);
|
||||||
|
@@ -573,13 +573,13 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
|
|||||||
if ( pItem->IsCheckable() )
|
if ( pItem->IsCheckable() )
|
||||||
{
|
{
|
||||||
mii.fMask |= MIIM_CHECKMARKS;
|
mii.fMask |= MIIM_CHECKMARKS;
|
||||||
mii.hbmpChecked = pItem->GetHBitmapForMenuCheckable(true);
|
mii.hbmpChecked = pItem->GetHBitmapForMenu(wxMenuItem::Checked);
|
||||||
mii.hbmpUnchecked = pItem->GetHBitmapForMenuCheckable(false);
|
mii.hbmpUnchecked = pItem->GetHBitmapForMenu(wxMenuItem::Unchecked);
|
||||||
}
|
}
|
||||||
else if ( pItem->GetBitmap().IsOk() )
|
else if ( pItem->GetBitmap().IsOk() )
|
||||||
{
|
{
|
||||||
mii.fMask |= MIIM_BITMAP;
|
mii.fMask |= MIIM_BITMAP;
|
||||||
mii.hbmpItem = pItem->GetHBitmapForMenu();
|
mii.hbmpItem = pItem->GetHBitmapForMenu(wxMenuItem::Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
mii.cch = itemText.length();
|
mii.cch = itemText.length();
|
||||||
|
@@ -807,13 +807,13 @@ void wxMenuItem::DoSetBitmap(const wxBitmap& bmp, bool bChecked)
|
|||||||
if ( IsCheckable() )
|
if ( IsCheckable() )
|
||||||
{
|
{
|
||||||
mii.fMask = MIIM_CHECKMARKS;
|
mii.fMask = MIIM_CHECKMARKS;
|
||||||
mii.hbmpChecked = GetHBitmapForMenuCheckable(true);
|
mii.hbmpChecked = GetHBitmapForMenu(Checked);
|
||||||
mii.hbmpUnchecked = GetHBitmapForMenuCheckable(false);
|
mii.hbmpUnchecked = GetHBitmapForMenu(Unchecked);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mii.fMask = MIIM_BITMAP;
|
mii.fMask = MIIM_BITMAP;
|
||||||
mii.hbmpItem = GetHBitmapForMenu();
|
mii.hbmpItem = GetHBitmapForMenu(Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !::SetMenuItemInfo(GetHMenuOf(m_parentMenu), itemPos, TRUE, &mii) )
|
if ( !::SetMenuItemInfo(GetHMenuOf(m_parentMenu), itemPos, TRUE, &mii) )
|
||||||
@@ -1184,52 +1184,6 @@ bool wxMenuItem::OnDrawItem(wxDC& dc, const wxRect& rc,
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
// Returns the HBITMAP to use in MENUITEMINFO, either for hBmpItem (then
|
|
||||||
// forCheckableItem is false) or for hbmpChecked/hBmpUnchecked
|
|
||||||
// usage (forCheckableItem is true). The difference is needed because
|
|
||||||
// HBMMENU_CALLBACK can only be used for hBmpItem items.
|
|
||||||
HBITMAP DoGetHBitmapForMenu(wxMenuItem *menuItem,
|
|
||||||
bool checked, bool forCheckableItem)
|
|
||||||
{
|
|
||||||
// Under versions of Windows older than Vista we can't pass HBITMAP
|
|
||||||
// directly as hbmpItem for 2 reasons:
|
|
||||||
// 1. We can't draw it with transparency then (this is not
|
|
||||||
// very important now but would be with themed menu bg)
|
|
||||||
// 2. Worse, Windows inverts the bitmap for the selected
|
|
||||||
// item and this looks downright ugly
|
|
||||||
//
|
|
||||||
// So we prefer to instead draw it ourselves in MSWOnDrawItem() by using
|
|
||||||
// HBMMENU_CALLBACK for normal menu items when inserting it. And use
|
|
||||||
// NULL for checkable menu items as hbmpChecked/hBmpUnchecked does not
|
|
||||||
// support HBMMENU_CALLBACK.
|
|
||||||
//
|
|
||||||
// However under Vista using HBMMENU_CALLBACK causes the entire menu to be
|
|
||||||
// drawn using the classic theme instead of the current one and it does
|
|
||||||
// handle transparency just fine so do use the real bitmap there
|
|
||||||
#if wxUSE_IMAGE
|
|
||||||
if ( wxGetWinVersion() >= wxWinVersion_Vista )
|
|
||||||
{
|
|
||||||
wxBitmap bmp = menuItem->GetBitmap(checked);
|
|
||||||
if ( bmp.IsOk() )
|
|
||||||
{
|
|
||||||
// we must use PARGB DIB for the menu bitmaps so ensure that we do
|
|
||||||
wxImage img(bmp.ConvertToImage());
|
|
||||||
if ( !img.HasAlpha() )
|
|
||||||
{
|
|
||||||
img.InitAlpha();
|
|
||||||
menuItem->SetBitmap(img, checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
return GetHbitmapOf(menuItem->GetBitmap(checked));
|
|
||||||
}
|
|
||||||
//else: bitmap is not set
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif // wxUSE_IMAGE
|
|
||||||
|
|
||||||
return forCheckableItem ? NULL : HBMMENU_CALLBACK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// helper function for draw coloured check mark
|
// helper function for draw coloured check mark
|
||||||
void DrawColorCheckMark(HDC hdc, int x, int y, int cx, int cy, HDC hdcCheckMask, int idxColor)
|
void DrawColorCheckMark(HDC hdc, int x, int y, int cx, int cy, HDC hdcCheckMask, int idxColor)
|
||||||
{
|
{
|
||||||
@@ -1422,17 +1376,47 @@ bool wxMenuItem::MSWMustUseOwnerDrawn()
|
|||||||
|
|
||||||
#endif // wxUSE_OWNER_DRAWN
|
#endif // wxUSE_OWNER_DRAWN
|
||||||
|
|
||||||
// returns the HBITMAP to use in MENUITEMINFO for hBmpItem member
|
// returns the HBITMAP to use in MENUITEMINFO
|
||||||
HBITMAP wxMenuItem::GetHBitmapForMenu(bool checked)
|
HBITMAP wxMenuItem::GetHBitmapForMenu(BitmapKind kind)
|
||||||
{
|
{
|
||||||
return ::DoGetHBitmapForMenu(this, checked, false /*for checkable item?*/);
|
// Under versions of Windows older than Vista we can't pass HBITMAP
|
||||||
}
|
// directly as hbmpItem for 2 reasons:
|
||||||
|
// 1. We can't draw it with transparency then (this is not
|
||||||
|
// very important now but would be with themed menu bg)
|
||||||
|
// 2. Worse, Windows inverts the bitmap for the selected
|
||||||
|
// item and this looks downright ugly
|
||||||
|
//
|
||||||
|
// So we prefer to instead draw it ourselves in MSWOnDrawItem() by using
|
||||||
|
// HBMMENU_CALLBACK for normal menu items when inserting it. And use
|
||||||
|
// NULL for checkable menu items as hbmpChecked/hBmpUnchecked does not
|
||||||
|
// support HBMMENU_CALLBACK.
|
||||||
|
//
|
||||||
|
// However under Vista using HBMMENU_CALLBACK causes the entire menu to be
|
||||||
|
// drawn using the classic theme instead of the current one and it does
|
||||||
|
// handle transparency just fine so do use the real bitmap there
|
||||||
|
#if wxUSE_IMAGE
|
||||||
|
if ( wxGetWinVersion() >= wxWinVersion_Vista )
|
||||||
|
{
|
||||||
|
bool checked = (kind != Unchecked);
|
||||||
|
wxBitmap bmp = GetBitmap(checked);
|
||||||
|
if ( bmp.IsOk() )
|
||||||
|
{
|
||||||
|
// we must use PARGB DIB for the menu bitmaps so ensure that we do
|
||||||
|
wxImage img(bmp.ConvertToImage());
|
||||||
|
if ( !img.HasAlpha() )
|
||||||
|
{
|
||||||
|
img.InitAlpha();
|
||||||
|
SetBitmap(img, checked);
|
||||||
|
}
|
||||||
|
|
||||||
// returns the HBITMAP to use in MENUITEMINFO for hbmpChecked and
|
return GetHbitmapOf(GetBitmap(checked));
|
||||||
// hbmpUnchecked member
|
}
|
||||||
HBITMAP wxMenuItem::GetHBitmapForMenuCheckable(bool checked)
|
//else: bitmap is not set
|
||||||
{
|
return NULL;
|
||||||
return ::DoGetHBitmapForMenu(this, checked, true /*for checkable item?*/);
|
}
|
||||||
|
#endif // wxUSE_IMAGE
|
||||||
|
|
||||||
|
return (kind == Normal) ? HBMMENU_CALLBACK : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxMenuItem::MSGetMenuItemPos() const
|
int wxMenuItem::MSGetMenuItemPos() const
|
||||||
|
Reference in New Issue
Block a user