-// draw the item
-bool wxOwnerDrawn::OnDrawItem(wxDC& dc,
- const wxRect& rc,
- wxODAction act,
- wxODStatus st)
-{
- // we do nothing on focus change
- if ( act == wxODFocusChanged )
- return true;
-
-
- // this flag determines whether or not an edge will
- // be drawn around the bitmap. In most "windows classic"
- // applications, a 1-pixel highlight edge is drawn around
- // the bitmap of an item when it is selected. However,
- // with the new "luna" theme, no edge is drawn around
- // the bitmap because the background is white (this applies
- // only to "non-XP style" menus w/ bitmaps --
- // see IE 6 menus for an example)
-
- bool draw_bitmap_edge = true;
-
- // set the colors
- // --------------
- DWORD colBack, colText;
- if ( st & wxODSelected ) {
- colBack = GetSysColor(COLOR_HIGHLIGHT);
- if (!(st & wxODDisabled))
- {
- colText = GetSysColor(COLOR_HIGHLIGHTTEXT);
- }
- else
- {
- colText = GetSysColor(COLOR_GRAYTEXT);
- }
- }
- else {
- // fall back to default colors if none explicitly specified
- colBack = m_colBack.Ok() ? wxColourToPalRGB(m_colBack)
- : GetSysColor(COLOR_MENU);
- colText = m_colText.Ok() ? wxColourToPalRGB(m_colText)
- : GetSysColor(COLOR_MENUTEXT);
- }
-
-
- // don't draw an edge around the bitmap, if background is white ...
- DWORD menu_bg_color = GetSysColor(COLOR_MENU);
- if ( ( GetRValue( menu_bg_color ) >= 0xf0 &&
- GetGValue( menu_bg_color ) >= 0xf0 &&
- GetBValue( menu_bg_color ) >= 0xf0 )
- )
- {
- draw_bitmap_edge = false;
- }
-
-
- HDC hdc = GetHdcOf(dc);
- COLORREF colOldText = ::SetTextColor(hdc, colText),
- colOldBack = ::SetBkColor(hdc, colBack);
-
- // *2, as in wxSYS_EDGE_Y
- int margin = GetMarginWidth() + 2 * wxSystemSettings::GetMetric(wxSYS_EDGE_X);
-
- // select the font and draw the text
- // ---------------------------------
-
-
- // determine where to draw and leave space for a check-mark.
- // + 1 pixel to separate the edge from the highlight rectangle
- int xText = rc.x + margin + 1;
-
-
- // using native API because it recognizes '&'
- if ( IsOwnerDrawn() )
- {
- int nPrevMode = SetBkMode(hdc, TRANSPARENT);
- AutoHBRUSH hbr(colBack);
- SelectInHDC selBrush(hdc, hbr);
-
- RECT rectFill = { rc.GetLeft(), rc.GetTop(),
- rc.GetRight() + 1, rc.GetBottom() + 1 };
-
- if ( (st & wxODSelected) && m_bmpChecked.Ok() && draw_bitmap_edge ) {
- // only draw the highlight under the text, not under
- // the bitmap or checkmark
- rectFill.left = xText;
- }
-
- FillRect(hdc, &rectFill, hbr);
-
- // use default font if no font set
- wxFont fontToUse = GetFontToUse();
- SelectInHDC selFont(hdc, GetHfontOf(fontToUse));