void wxRendererXP::DrawItemSelectionRect(wxWindow *win, wxDC& dc, const wxRect& rect, int flags) { wxUxThemeHandle hTheme(win, L"LISTVIEW"); const int itemState = GetListItemState(flags); wxUxThemeEngine* const te = wxUxThemeEngine::Get(); if ( te->IsThemePartDefined(hTheme, LVP_LISTITEM, itemState) ) { RECT rc; wxCopyRectToRECT(rect, rc); if ( te->IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTITEM, itemState) ) te->DrawThemeParentBackground(GetHwndOf(win), GetHdcOf(dc.GetTempHDC()), &rc); te->DrawThemeBackground(hTheme, GetHdcOf(dc.GetTempHDC()), LVP_LISTITEM, itemState, &rc, 0); } else { m_rendererNative.DrawItemSelectionRect(win, dc, rect, flags); } }
LRESULT CTDCTaskListCtrl::OnListCustomDraw(NMLVCUSTOMDRAW* pLVCD) { HWND hwndList = pLVCD->nmcd.hdr.hwndFrom; int nItem = (int)pLVCD->nmcd.dwItemSpec; DWORD dwTaskID = pLVCD->nmcd.lItemlParam; if (hwndList == m_lcColumns) { // columns handled by base class return CTDCTaskCtrlBase::OnListCustomDraw(pLVCD); } switch (pLVCD->nmcd.dwDrawStage) { case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW; case CDDS_ITEMPREPAINT: { CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc); BOOL bAlternate = (IsColumnLineOdd(nItem) && HasColor(m_crAltLine)); COLORREF crBack = (bAlternate ? m_crAltLine : GetSysColor(COLOR_WINDOW)); if (HasStyle(TDCS_TASKCOLORISBACKGROUND)) { GetTaskTextColors(dwTaskID, pLVCD->clrText, pLVCD->clrTextBk); if (pLVCD->clrTextBk != CLR_NONE) crBack = pLVCD->clrTextBk; } pLVCD->clrTextBk = pLVCD->clrText = crBack; if (!OsIsXP()) { GraphicsMisc::FillItemRect(pDC, &pLVCD->nmcd.rc, crBack, m_lcTasks); ListView_SetBkColor(m_lcTasks, crBack); } return (CDRF_NOTIFYPOSTPAINT | CDRF_NEWFONT); // always } break; case CDDS_ITEMPOSTPAINT: { const TODOITEM* pTDI = NULL; const TODOSTRUCTURE* pTDS = NULL; DWORD dwTaskID = GetTaskID(nItem), dwTrueID(dwTaskID); if (m_data.GetTask(dwTrueID, pTDI, pTDS)) { CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc); CFont* pOldFont = pDC->SelectObject(GetTaskFont(pTDI, pTDS, FALSE)); GM_ITEMSTATE nState = GetListItemState(nItem); BOOL bSelected = (nState != GMIS_NONE); BOOL bAlternate = (IsColumnLineOdd(nItem) && HasColor(m_crAltLine)); COLORREF crBack, crText; VERIFY(GetTaskTextColors(pTDI, pTDS, crText, crBack, (dwTaskID != dwTrueID), bSelected)); // draw background CRect rRow(pLVCD->nmcd.rc); // extra for XP if (OsIsXP()) m_lcTasks.GetItemRect(nItem, rRow, LVIR_BOUNDS); CRect rItem; GetItemTitleRect(nItem, TDCTR_LABEL, rItem, pDC, pTDI->sTitle); DrawTasksRowBackground(pDC, rRow, rItem, nState, bAlternate, crBack); // draw text DrawColumnText(pDC, pTDI->sTitle, rItem, DT_LEFT, crText, TRUE); rItem.right = (rItem.left + pDC->GetTextExtent(pTDI->sTitle).cx + LV_COLPADDING); // cleanup pDC->SelectObject(pOldFont); // render comment text DrawCommentsText(pDC, rRow, rItem, pTDI, pTDS); } // restore default back colour ListView_SetBkColor(m_lcTasks, GetSysColor(COLOR_WINDOW)); return CDRF_SKIPDEFAULT; // always } break; } return CDRF_DODEFAULT; }
GM_ITEMSTATE CTDCTaskListCtrl::GetColumnItemState(int nItem) const { return GetListItemState(nItem); }
void wxRendererXP::DrawItemText(wxWindow* win, wxDC& dc, const wxString& text, const wxRect& rect, int align, int flags, wxEllipsizeMode ellipsizeMode) { wxUxThemeHandle hTheme(win, L"LISTVIEW"); const int itemState = GetListItemState(flags); wxUxThemeEngine* te = wxUxThemeEngine::Get(); if ( te->DrawThemeTextEx && // Might be not available if we're under XP te->IsThemePartDefined(hTheme, LVP_LISTITEM, itemState) ) { RECT rc; wxCopyRectToRECT(rect, rc); DTTOPTS textOpts; textOpts.dwSize = sizeof(textOpts); textOpts.dwFlags = DTT_STATEID; textOpts.iStateId = itemState; if (flags & wxCONTROL_DISABLED) { textOpts.dwFlags |= DTT_TEXTCOLOR; textOpts.crText = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT).GetPixel(); } DWORD textFlags = DT_NOPREFIX; if ( align & wxALIGN_CENTER_HORIZONTAL ) textFlags |= DT_CENTER; else if ( align & wxALIGN_RIGHT ) { textFlags |= DT_RIGHT; rc.right--; // Alignment is inconsistent with DrawLabel otherwise } else textFlags |= DT_LEFT; if ( align & wxALIGN_BOTTOM ) textFlags |= DT_BOTTOM; else if ( align & wxALIGN_CENTER_VERTICAL ) textFlags |= DT_VCENTER; else textFlags |= DT_TOP; const wxString* drawText = &text; wxString ellipsizedText; switch ( ellipsizeMode ) { case wxELLIPSIZE_NONE: // no flag required break; case wxELLIPSIZE_START: case wxELLIPSIZE_MIDDLE: // no native support for this ellipsize modes, use wxWidgets // implementation (may not be 100% accurate because per // definition the theme defines the font but should be close // enough with current windows themes) drawText = &ellipsizedText; ellipsizedText = wxControl::Ellipsize(text, dc, ellipsizeMode, rect.width, wxELLIPSIZE_FLAGS_NONE); break; case wxELLIPSIZE_END: textFlags |= DT_END_ELLIPSIS; break; } te->DrawThemeTextEx(hTheme, dc.GetHDC(), LVP_LISTITEM, itemState, drawText->wchar_str(), -1, textFlags, &rc, &textOpts); } else { m_rendererNative.DrawItemText(win, dc, text, rect, align, flags, ellipsizeMode); } }