From: Vadim Zeitlin Date: Mon, 22 Sep 2003 00:43:36 +0000 (+0000) Subject: added wxOwnerDrawn::SetOwnerDrawn() and SetDisabledBitmap(); corrected calculation... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/104032545eaccb86693c41d8e49319b5b6deea86 added wxOwnerDrawn::SetOwnerDrawn() and SetDisabledBitmap(); corrected calculation of menu width and drawing of accels for disabled items (parts of patch 758598) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23794 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index b688689e8a..f1ddb7ee4e 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -47,6 +47,7 @@ All: - wxDateTime::ParseDateTime() implemented (Linus McCabe) - wxHTTP::GetResponse() added (David Nock) +- added conversions to/from UTF 16/32 LE/BE (Andreas Pflug) All (GUI): @@ -59,6 +60,7 @@ wxMSW: - wxTextCtrl::GetValue() works with text in non default encoding - changed wxCrashReport to generate minidumps instead of text files - wxRadioButtons are now checked when they get focus (standard behaviour) +- several fixes to owner drawn menu items (Christian Sturmlechner) wxGTK: diff --git a/include/wx/ownerdrw.h b/include/wx/ownerdrw.h index b2b144c9bd..6adb938d1b 100644 --- a/include/wx/ownerdrw.h +++ b/include/wx/ownerdrw.h @@ -67,9 +67,16 @@ public: { m_bmpChecked = bmpChecked; m_bOwnerDrawn = TRUE; } + void SetDisabledBitmap( const wxBitmap& bmpDisabled ) + { m_bmpDisabled = bmpDisabled; + m_bOwnerDrawn = TRUE; } + const wxBitmap& GetBitmap(bool bChecked = TRUE) const { return (bChecked ? m_bmpChecked : m_bmpUnchecked); } + const wxBitmap& GetDisabledBitmap() const + { return m_bmpDisabled; } + // the height of the menu checkmark (or bitmap) is determined by the font // for the current item, but the width should be always the same (for the // items to be aligned), so by default it's taken to be the same as for @@ -102,6 +109,9 @@ public: // want to change, say, the color for the item but only if it is owner-drawn // (see wxMenuItem::wxMenuItem for example) bool IsOwnerDrawn() const { return m_bOwnerDrawn; } + + // switch on/off owner-drawing the item + void SetOwnerDrawn(bool ownerDrawn = TRUE) { m_bOwnerDrawn = ownerDrawn; } void ResetOwnerDrawn() { m_bOwnerDrawn = FALSE; } public: @@ -143,7 +153,8 @@ private: wxColour m_colText, // color ----"---"---"---- m_colBack; // background color wxBitmap m_bmpChecked, // bitmap to put near the item - m_bmpUnchecked; // (checked is used also for 'uncheckable' items) + m_bmpUnchecked, // (checked is used also for 'uncheckable' items) + m_bmpDisabled; size_t m_nHeight, // font height m_nMinHeight, // minimum height, as determined by user's system settings diff --git a/src/msw/ownerdrw.cpp b/src/msw/ownerdrw.cpp index 665acc4c9d..2670d5464a 100644 --- a/src/msw/ownerdrw.cpp +++ b/src/msw/ownerdrw.cpp @@ -50,7 +50,7 @@ public: #if defined(__WXMSW__) && defined(__WIN32__) && defined(SM_CXMENUCHECK) NONCLIENTMETRICS nm; nm.cbSize = sizeof(NONCLIENTMETRICS); - SystemParametersInfo(SPI_GETNONCLIENTMETRICS,0,&nm,0); + SystemParametersInfo(SPI_GETNONCLIENTMETRICS,0,&nm,0); ms_systemMenuButtonWidth = nm.iMenuHeight; ms_systemMenuHeight = nm.iMenuHeight; @@ -100,9 +100,9 @@ wxOwnerDrawn::wxOwnerDrawn(const wxString& str, // get the default menu height and font from the system NONCLIENTMETRICS nm; nm.cbSize = sizeof (NONCLIENTMETRICS); - SystemParametersInfo (SPI_GETNONCLIENTMETRICS,0,&nm,0); + SystemParametersInfo (SPI_GETNONCLIENTMETRICS,0,&nm,0); m_nMinHeight = nm.iMenuHeight; - + // nm.iMenuWidth is the system default for the width of // menu icons and checkmarks if (ms_nDefaultMarginWidth == 0) @@ -125,12 +125,14 @@ wxOwnerDrawn::wxOwnerDrawn(const wxString& str, m_nHeight = 0; m_nMarginWidth = ms_nLastMarginWidth; m_nMinHeight = wxMSWSystemMenuFontModule::ms_systemMenuHeight; + + m_bmpDisabled = wxNullBitmap; } // these items will be set during the first invocation of the c'tor, // because the values will be determined by checking the system settings, -// which is a chunk of code +// which is a chunk of code size_t wxOwnerDrawn::ms_nDefaultMarginWidth = 0; size_t wxOwnerDrawn::ms_nLastMarginWidth = 0; @@ -161,21 +163,9 @@ 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; - } - // add space at the end of the menu for the submenu expansion arrow // this will also allow offsetting the accel string from the right edge - *pwidth += (size_t) (GetDefaultMarginWidth() * 1.5); + *pwidth += (size_t) (GetDefaultMarginWidth() * 1.5) + 16; // JACS: items still look too tightly packed, so adding 5 pixels. (*pheight) = (*pheight) + 5; @@ -196,21 +186,16 @@ bool wxOwnerDrawn::OnMeasureItem(size_t *pwidth, size_t *pheight) // Does BMP encroach on default check menu position? size_t adjustedWidth = m_bmpChecked.GetWidth() + (wxSystemSettings::GetMetric(wxSYS_EDGE_X) * 2); -// if (ms_nDefaultMarginWidth < adjustedWidth) -// *pwidth += adjustedWidth - ms_nDefaultMarginWidth; // Do we need to widen margin to fit BMP? if ((size_t)GetMarginWidth() != adjustedWidth) SetMarginWidth(adjustedWidth); - - // add the size of the bitmap to our total size... - *pwidth += GetMarginWidth(); } // add the size of the bitmap to our total size - even if we don't have // a bitmap we leave room for one... *pwidth += GetMarginWidth(); - + // make sure that this item is at least as // tall as the user's system settings specify if (*pheight < m_nMinHeight) @@ -343,6 +328,7 @@ bool wxOwnerDrawn::OnDrawItem(wxDC& dc, DST_PREFIXTEXT | (((st & wxODDisabled) && !(st & wxODSelected)) ? DSS_DISABLED : 0)); + /* Right alignment does not work with DSS_DISABLED (Windows98) - why? if ( !m_strAccel.empty() ) { // right align accel string with right edge of menu ( offset by the margin width ) @@ -355,6 +341,22 @@ bool wxOwnerDrawn::OnDrawItem(wxDC& dc, (((st & wxODDisabled) && !(st & wxODSelected)) ? DSS_DISABLED : 0)); ::SetTextAlign(hdc, TA_LEFT); } + */ + + // ::SetTextAlign(hdc, TA_RIGHT) doesn't work with DSS_DISABLED or DSS_MONO as last parameter + // in DrawState() (at least with Windows98). So we have to take care of right alignment ourselves. + if ( !m_strAccel.empty() ) + { + int accel_width, accel_height; + dc.GetTextExtent(m_strAccel, &accel_width, &accel_height); + // right align accel string with right edge of menu ( offset by the margin width ) + ::DrawState(hdc, NULL, NULL, + (LPARAM)m_strAccel.c_str(), m_strAccel.length(), + rc.GetWidth()-GetMarginWidth()-accel_width, rc.y+(int) ((rc.GetHeight()-sizeRect.cy)/2.0), + rc.GetWidth()-GetMarginWidth()-accel_width, sizeRect.cy, + DST_TEXT | + (((st & wxODDisabled) && !(st & wxODSelected)) ? DSS_DISABLED : 0)); + } (void)SelectObject(hdc, hPrevBrush); (void)SelectObject(hdc, hPrevFont); @@ -400,8 +402,11 @@ bool wxOwnerDrawn::OnDrawItem(wxDC& dc, } } else { + wxBitmap bmp( // for disabled items we use m_bmpDisabled if it exists + ( GetDisabledBitmap() != wxNullBitmap && ( st & wxODDisabled ) ) ? GetDisabledBitmap() : // for uncheckable item we use only the 'checked' bitmap - wxBitmap bmp(GetBitmap(IsCheckable() ? ((st & wxODChecked) != 0) : TRUE)); + GetBitmap(IsCheckable() ? ((st & wxODChecked) != 0) : TRUE) + ); if ( bmp.Ok() ) { wxMemoryDC dcMem(&dc); dcMem.SelectObject(bmp);