Refactor owner-drawing code.
Only keep common code in the base class and extract all menu/listbox-specific stuff into derived classes. This makes the code cleaner and more maintainable but introduces some problems in wxCheckListBox appearance which will be fixed by the next patch. Closes #10635. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63220 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
96
src/common/ownerdrwcmn.cpp
Normal file
96
src/common/ownerdrwcmn.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/ownerdrwcmn.cpp
|
||||
// Purpose: wxOwnerDrawn class methods common to all platforms
|
||||
// Author: Marcin Malich
|
||||
// Modified by:
|
||||
// Created: 2009-09-22
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2009 Marcin Malich <me@malcom.pl>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_OWNER_DRAWN
|
||||
|
||||
#include "wx/ownerdrw.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/window.h"
|
||||
#include "wx/font.h"
|
||||
#include "wx/colour.h"
|
||||
#include "wx/dcmemory.h"
|
||||
#include "wx/settings.h"
|
||||
#include "wx/utils.h"
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
bool wxOwnerDrawnBase::OnMeasureItem(size_t *width, size_t *height)
|
||||
{
|
||||
if ( IsOwnerDrawn() )
|
||||
{
|
||||
wxMemoryDC dc;
|
||||
wxFont font;
|
||||
GetFontToUse(font);
|
||||
dc.SetFont(font);
|
||||
|
||||
// item name/text without mnemonics
|
||||
wxString name = wxStripMenuCodes(GetName(), wxStrip_Mnemonics);
|
||||
|
||||
wxCoord w, h;
|
||||
dc.GetTextExtent(name, &w, &h);
|
||||
|
||||
*width = w + m_margin;
|
||||
*height = h;
|
||||
}
|
||||
else
|
||||
{
|
||||
*width = 0;
|
||||
*height = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxOwnerDrawnBase::GetFontToUse(wxFont& font) const
|
||||
{
|
||||
font = m_font.IsOk() ? m_font : *wxNORMAL_FONT;
|
||||
}
|
||||
|
||||
void wxOwnerDrawnBase::GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const
|
||||
{
|
||||
if ( stat & wxODSelected )
|
||||
{
|
||||
colText = wxSystemSettings::GetColour(
|
||||
!(stat & wxODDisabled) ? wxSYS_COLOUR_HIGHLIGHTTEXT
|
||||
: wxSYS_COLOUR_GRAYTEXT);
|
||||
|
||||
colBack = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
|
||||
}
|
||||
else
|
||||
{
|
||||
// fall back to default colors if none explicitly specified
|
||||
colText = m_colText.Ok() ? m_colText
|
||||
: wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT);
|
||||
colBack = m_colBack.Ok() ? m_colBack
|
||||
: wxSystemSettings::GetColour(wxSYS_COLOUR_MENU);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // wxUSE_OWNER_DRAWN
|
||||
Reference in New Issue
Block a user