-// ctor
-// ----
-wxOwnerDrawn::wxOwnerDrawn(const wxString& str,
- bool bCheckable,
- bool bMenuItem)
- : m_strName(str)
-{
- if ( ms_nDefaultMarginWidth == 0 )
- {
- ms_nDefaultMarginWidth = ::GetSystemMetrics(SM_CXMENUCHECK) +
- wxSystemSettings::GetMetric(wxSYS_EDGE_X);
- ms_nLastMarginWidth = ms_nDefaultMarginWidth;
- }
-
- m_bCheckable = bCheckable;
- m_bOwnerDrawn = false;
- m_isMenuItem = bMenuItem;
- m_nHeight = 0;
- m_nMarginWidth = ms_nLastMarginWidth;
-}
-
-wxOwnerDrawn::~wxOwnerDrawn()
-{
-}
-
-bool wxOwnerDrawn::IsMenuItem() const
-{
- return m_isMenuItem;
-}
-
-
-// these items will be set during the first invocation of the ctor,
-// because the values will be determined by checking the system settings,
-// which is a chunk of code
-size_t wxOwnerDrawn::ms_nDefaultMarginWidth = 0;
-size_t wxOwnerDrawn::ms_nLastMarginWidth = 0;
-
-
-// drawing
-// -------
-
-wxFont wxOwnerDrawn::GetFontToUse() const
-{
- wxFont font = m_font;
- if ( !font.Ok() )
- {
- if ( IsMenuItem() )
- font = *wxMSWSystemMenuFontModule::ms_systemMenuFont;
-
- if ( !font.Ok() )
- font = *wxNORMAL_FONT;
- }
-
- return font;
-}
-
-// get size of the item
-// The item size includes the menu string, the accel string,
-// the bitmap and size for a submenu expansion arrow...
-bool wxOwnerDrawn::OnMeasureItem(size_t *pwidth, size_t *pheight)
-{
- if ( IsOwnerDrawn() )
- {
- wxMemoryDC dc;
-
- wxString str = wxStripMenuCodes(m_strName);
-
- // if we have a valid accel string, then pad out
- // the menu string so that the menu and accel string are not
- // placed on top of each other.
- if ( !m_strAccel.empty() )
- {
- str.Pad(str.length()%8);
- str += m_strAccel;
- }
-
- dc.SetFont(GetFontToUse());
-
- wxCoord w, h;
- dc.GetTextExtent(str, &w, &h);
- *pwidth = w;
- *pheight = h;
-
- // 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 += GetMarginWidth() + 16;
- }
- else // don't draw the text, just the bitmap (if any)
- {
- *pwidth =
- *pheight = 0;
- }
-
- // increase size to accommodate bigger bitmaps if necessary
- if (m_bmpChecked.Ok())
- {
- // Is BMP height larger than text height?
- size_t adjustedHeight = m_bmpChecked.GetHeight();
- if ( *pheight < adjustedHeight )
- *pheight = adjustedHeight;
-
- const size_t widthBmp = m_bmpChecked.GetWidth();
- if ( IsOwnerDrawn() )
- {
- // widen the margin to fit the bitmap if necessary
- if ((size_t)GetMarginWidth() < widthBmp)
- SetMarginWidth(widthBmp);
- }
- else // we must allocate enough space for the bitmap
- {
- *pwidth += widthBmp;
- }
- }
-
- // add a 4-pixel separator, otherwise menus look cluttered
- *pwidth += 4;
-
- // make sure that this item is at least as tall as the system menu height
- const size_t heightStd = wxMSWSystemMenuFontModule::ms_systemMenuHeight;
- if ( *pheight < heightStd )
- *pheight = heightStd;
-
- // remember height for use in OnDrawItem
- m_nHeight = *pheight;
-
- return true;
-}
-