-// 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;
-
- // wxColor <-> RGB
- #define ToRGB(col) PALETTERGB(col.Red(), col.Green(), col.Blue())
- #define UnRGB(col) GetRValue(col), GetGValue(col), GetBValue(col)
-
-
- // 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() ? ToRGB(m_colBack) : GetSysColor(COLOR_WINDOW);
- colText = m_colText.Ok() ? ToRGB(m_colText) : GetSysColor(COLOR_WINDOWTEXT);
- }
-
-
- // 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 )
- // ... or if the menu item is disabled
- || ( st & wxODDisabled )
- )
- {
- draw_bitmap_edge = false;
- }
-
-
- #ifdef O_DRAW_NATIVE_API
- #define hdc (HDC)dc.GetHDC()
- COLORREF colOldText = ::SetTextColor(hdc, colText),
- colOldBack = ::SetBkColor(hdc, colBack);
- #else
- dc.SetTextForeground(wxColor(UnRGB(colText)));
- dc.SetTextBackground(wxColor(UnRGB(colBack)));
- #endif
-
- // select the font and draw the text
- // ---------------------------------
-
-
- // determine where to draw and leave space for a check-mark.
- // Add 3 pixel padding so text appears well within highlight rectangle
- int x = rc.x + GetMarginWidth() + 3;
-
-
- // using native API because it reckognizes '&'
- #ifdef O_DRAW_NATIVE_API
- int nPrevMode = SetBkMode(hdc, TRANSPARENT);
- HBRUSH hbr = CreateSolidBrush(colBack),
- hPrevBrush = (HBRUSH)SelectObject(hdc, hbr);
-
- RECT rectFill = { rc.GetLeft(), rc.GetTop(), rc.GetRight()+1, rc.GetBottom() };
-
- if ( st & wxODSelected && m_bmpChecked.Ok() && draw_bitmap_edge) {
- // only draw the highlight under the text, not under
- // the bitmap or checkmark; leave a 1-pixel gap.
- rectFill.left = GetMarginWidth() + 1;
- }