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
This commit is contained in:
Vadim Zeitlin
2003-09-22 00:43:36 +00:00
parent a637417cf7
commit 104032545e
3 changed files with 43 additions and 25 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -125,6 +125,8 @@ wxOwnerDrawn::wxOwnerDrawn(const wxString& str,
m_nHeight = 0;
m_nMarginWidth = ms_nLastMarginWidth;
m_nMinHeight = wxMSWSystemMenuFontModule::ms_systemMenuHeight;
m_bmpDisabled = wxNullBitmap;
}
@@ -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,15 +186,10 @@ 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
@@ -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);