// Replaces a bitmap, optionally passing a mask bitmap. // Note that wxImageList creates new bitmaps, so you may delete // 'bitmap' and 'mask'. bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxBitmap& mask) { HBITMAP hbmp; #if wxUSE_WXDIB && wxUSE_IMAGE // See the comment in Add() above. AutoHBITMAP hbmpRelease; if ( bitmap.HasAlpha() ) { hbmp = wxDIB(bitmap.ConvertToImage(), wxDIB::PixelFormat_NotPreMultiplied).Detach(); hbmpRelease.Init(hbmp); } else #endif // wxUSE_WXDIB && wxUSE_IMAGE hbmp = GetHbitmapOf(bitmap); AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask)); if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) ) { wxLogLastError(wxT("ImageList_Replace()")); return false; } return true; }
// Adds a bitmap, and optionally a mask bitmap. // Note that wxImageList creates new bitmaps, so you may delete // 'bitmap' and 'mask'. int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask) { HBITMAP hbmp; #if wxUSE_WXDIB && wxUSE_IMAGE // wxBitmap normally stores alpha in pre-multiplied format but // ImageList_Draw() does pre-multiplication internally so we need to undo // the pre-multiplication here. Converting back and forth like this is, of // course, very inefficient but it's better than wrong appearance so we do // this for now until a better way can be found. AutoHBITMAP hbmpRelease; if ( bitmap.HasAlpha() ) { hbmp = wxDIB(bitmap.ConvertToImage(), wxDIB::PixelFormat_NotPreMultiplied).Detach(); hbmpRelease.Init(hbmp); } else #endif // wxUSE_WXDIB && wxUSE_IMAGE hbmp = GetHbitmapOf(bitmap); AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask)); int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask); if ( index == -1 ) { wxLogError(_("Couldn't add an image to the image list.")); } return index; }
void wxMenuItem::DrawStdCheckMark(WXHDC hdc_, const RECT* rc, wxODStatus stat) { HDC hdc = (HDC)hdc_; #if wxUSE_UXTHEME wxUxThemeEngine* theme = MenuDrawData::GetUxThemeEngine(); if ( theme ) { wxUxThemeHandle hTheme(GetMenu()->GetWindow(), L"MENU"); const MenuDrawData* data = MenuDrawData::Get(); // rect for background must be without check margins RECT rcBg = *rc; data->CheckMargin.UnapplyFrom(rcBg); POPUPCHECKBACKGROUNDSTATES stateCheckBg = (stat & wxODDisabled) ? MCB_DISABLED : MCB_NORMAL; theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPCHECKBACKGROUND, stateCheckBg, &rcBg, NULL); POPUPCHECKSTATES stateCheck; if ( GetKind() == wxITEM_CHECK ) { stateCheck = (stat & wxODDisabled) ? MC_CHECKMARKDISABLED : MC_CHECKMARKNORMAL; } else { stateCheck = (stat & wxODDisabled) ? MC_BULLETDISABLED : MC_BULLETNORMAL; } theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPCHECK, stateCheck, rc, NULL); } else #endif // wxUSE_UXTHEME { int cx = rc->right - rc->left; int cy = rc->bottom - rc->top; // first create mask of check mark MemoryHDC hdcMask(hdc); MonoBitmap hbmpMask(cx, cy); SelectInHDC selMask(hdcMask,hbmpMask); // then draw a check mark into it UINT stateCheck = (GetKind() == wxITEM_CHECK) ? DFCS_MENUCHECK : DFCS_MENUBULLET; RECT rect = { 0, 0, cx, cy }; ::DrawFrameControl(hdcMask, &rect, DFC_MENU, stateCheck); // first draw shadow if disabled if ( (stat & wxODDisabled) && !(stat & wxODSelected) ) { DrawColorCheckMark(hdc, rc->left + 1, rc->top + 1, cx, cy, hdcMask, COLOR_3DHILIGHT); } // then draw a check mark int color = COLOR_MENUTEXT; if ( stat & wxODDisabled ) color = COLOR_BTNSHADOW; else if ( stat & wxODSelected ) color = COLOR_HIGHLIGHTTEXT; DrawColorCheckMark(hdc, rc->left, rc->top, cx, cy, hdcMask, color); } }