From 5ac7be7a9f08c036273e028f2c9d400b6f879005 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 8 Aug 2002 09:10:04 +0000 Subject: [PATCH] Applied patch [ 592363 ] Owner Draw Round 2 fixes This patch fixes the following items in the owner draw code: * When an item is disabled, yet highlighted, the code will now retrieve the user's system settings for greyed-out text and use that color. Previously, the code had continued to print the disabled text with an embossed effect, which looked bad when the item was highlighted. * Menu formatting, such as hot-key underlining (example, "&Open"), has been fixed. * Measurements and alignments with accelerators/hot-keys has been fixed. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16401 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/ownerdrw.cpp | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/msw/ownerdrw.cpp b/src/msw/ownerdrw.cpp index 8334e32fe5..40aad406ba 100644 --- a/src/msw/ownerdrw.cpp +++ b/src/msw/ownerdrw.cpp @@ -112,6 +112,18 @@ bool wxOwnerDrawn::OnMeasureItem(size_t *pwidth, size_t *pheight) dc.GetTextExtent(str, (long *)pwidth, (long *)pheight); + if (!m_strAccel.IsEmpty()) + { + // measure the accelerator string, and add it's width to + // the total item width, plus 16 (Accelerators are right justified, + // with the right edge of the text rectangle 16 pixels left of + // the right edge of the menu) + + int accel_width, accel_height; + dc.GetTextExtent(m_strAccel, &accel_width, &accel_height); + *pwidth += (accel_width + 16); + } + // JACS: items still look too tightly packed, so adding 5 pixels. (*pheight) = (*pheight) + 5; @@ -180,7 +192,14 @@ bool wxOwnerDrawn::OnDrawItem(wxDC& dc, DWORD colBack, colText; if ( st & wxODSelected ) { colBack = GetSysColor(COLOR_HIGHLIGHT); - colText = GetSysColor(COLOR_HIGHLIGHTTEXT); + if (!(st & wxODDisabled)) + { + colText = GetSysColor(COLOR_HIGHLIGHTTEXT); + } + else + { + colText = GetSysColor(COLOR_GRAYTEXT); + } } else { // fall back to default colors if none explicitly specified @@ -236,23 +255,24 @@ bool wxOwnerDrawn::OnDrawItem(wxDC& dc, HFONT hPrevFont = (HFONT) ::SelectObject(hdc, hfont); - wxString strStrippedName = wxStripMenuCodes(m_strName); + wxString strMenuText = m_strName.BeforeFirst('\t'); ::DrawState(hdc, NULL, NULL, - (LPARAM)strStrippedName.c_str(), strStrippedName.length(), + (LPARAM)strMenuText.c_str(), strMenuText.length(), x, rc.y + 1, rc.GetWidth(), rc.GetHeight(), - DST_PREFIXTEXT | (st & wxODDisabled ? DSS_DISABLED : 0)); + DST_PREFIXTEXT | + (((st & wxODDisabled) && !(st & wxODSelected)) ? DSS_DISABLED : 0)); if ( !m_strAccel.empty() ) { - RECT r; - r.top = rc.GetTop() + 1; - r.left = rc.GetLeft(); - r.right = rc.GetRight() - 16; - r.bottom = rc.GetBottom(); - - DrawText(hdc, m_strAccel, m_strAccel.length(), &r, - DT_SINGLELINE | DT_RIGHT); + int accel_width, accel_height; + dc.GetTextExtent(m_strAccel, &accel_width, &accel_height); + + ::DrawState(hdc, NULL, NULL, + (LPARAM)m_strAccel.c_str(), m_strAccel.length(), + rc.GetRight() - accel_width - 16, rc.y + 1, 0, 0, + DST_TEXT | + (((st & wxODDisabled) && !(st & wxODSelected)) ? DSS_DISABLED : 0)); } (void)SelectObject(hdc, hPrevBrush); -- 2.47.2