void wxMenuItem::Init() { m_vRadioGroup.m_nStart = -1; m_bIsRadioGroupStart = FALSE; #if wxUSE_OWNER_DRAWN // // Set default menu colors // SetTextColour(wxNullColour); SetBackgroundColour(wxNullColour); // // We don't want normal items be owner-drawn // SetOwnerDrawn(false); #endif // wxUSE_OWNER_DRAWN } // end of wxMenuItem::Init
void wxMenuItem::Init() { #if wxUSE_OWNER_DRAWN // when the color is not valid, wxOwnerDraw takes the default ones. // If we set the colors here and they are changed by the user during // the execution, then the colors are not updated until the application // is restarted and our menus look bad SetTextColour(wxNullColour); SetBackgroundColour(wxNullColour); // setting default colors switched ownerdraw on: switch it off again SetOwnerDrawn(false); // switch ownerdraw back on if using a non default margin if ( !IsSeparator() ) SetMarginWidth(GetMarginWidth()); #endif // wxUSE_OWNER_DRAWN }
void wxMenuItem::DoSetBitmap(const wxBitmap& bmp, bool bChecked) { if ( bChecked ) { if ( m_bmpChecked.IsSameAs(bmp) ) return; m_bmpChecked = bmp; } else { if ( m_bmpUnchecked.IsSameAs(bmp) ) return; m_bmpUnchecked = bmp; } #if wxUSE_OWNER_DRAWN // already marked as owner-drawn, cannot be reverted if ( IsOwnerDrawn() ) return; if ( MSWMustUseOwnerDrawn() ) { SetOwnerDrawn(true); // Parent menu has to be rearranged/recalculated in this case // (all other menu items have to be also set to owner-drawn mode). if ( m_parentMenu ) { size_t pos; wxMenuItem *item = m_parentMenu->FindChildItem(GetMSWId(), &pos); if ( item ) { wxCHECK_RET( item == this, wxS("Non unique menu item ID?") ); m_parentMenu->Remove(this); m_parentMenu->Insert(pos, this); } //else: the item hasn't been inserted into the parent menu yet } return; } #endif // wxUSE_OWNER_DRAWN // the item can be not attached to any menu yet and SetBitmap() is still // valid to call in this case and should do nothing else if ( !m_parentMenu ) return; HMENU hMenu = GetHMenuOf(m_parentMenu); if ( !hMenu ) return; const UINT id = GetMSWId(); const UINT state = ::GetMenuState(hMenu, id, MF_BYCOMMAND); if ( state == (UINT)-1 ) return; // update the bitmap of the native menu item // don't set hbmpItem for the checkable items as it would // be used for both checked and unchecked state WinStruct<MENUITEMINFO> mii; if ( IsCheckable() ) { mii.fMask = MIIM_CHECKMARKS; mii.hbmpChecked = GetHBitmapForMenu(true); mii.hbmpUnchecked = GetHBitmapForMenu(false); } else { mii.fMask = MIIM_BITMAP; mii.hbmpItem = GetHBitmapForMenu(); } if ( !::SetMenuItemInfo(hMenu, id, FALSE, &mii) ) { wxLogLastError(wxT("SetMenuItemInfo")); } }