]> git.saurik.com Git - wxWidgets.git/blame - src/common/ownerdrwcmn.cpp
Restored wxNotebook::HitTest for wxOSX-Carbon.
[wxWidgets.git] / src / common / ownerdrwcmn.cpp
CommitLineData
98fbab9e
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/common/ownerdrwcmn.cpp
3// Purpose: wxOwnerDrawn class methods common to all platforms
4// Author: Marcin Malich
5// Modified by:
6// Created: 2009-09-22
7// RCS-ID: $Id$
8// Copyright: (c) 2009 Marcin Malich <me@malcom.pl>
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#if wxUSE_OWNER_DRAWN
28
29#include "wx/ownerdrw.h"
30
31#ifndef WX_PRECOMP
32 #include "wx/window.h"
33 #include "wx/font.h"
34 #include "wx/colour.h"
35 #include "wx/dcmemory.h"
36 #include "wx/settings.h"
37 #include "wx/utils.h"
38#endif
39
40// ============================================================================
41// implementation
42// ============================================================================
43
44bool wxOwnerDrawnBase::OnMeasureItem(size_t *width, size_t *height)
45{
46 if ( IsOwnerDrawn() )
47 {
48 wxMemoryDC dc;
49 wxFont font;
50 GetFontToUse(font);
51 dc.SetFont(font);
52
53 // item name/text without mnemonics
54 wxString name = wxStripMenuCodes(GetName(), wxStrip_Mnemonics);
55
56 wxCoord w, h;
57 dc.GetTextExtent(name, &w, &h);
58
59 *width = w + m_margin;
60 *height = h;
61 }
62 else
63 {
64 *width = 0;
65 *height = 0;
66 }
67
68 return true;
69}
70
71void wxOwnerDrawnBase::GetFontToUse(wxFont& font) const
72{
73 font = m_font.IsOk() ? m_font : *wxNORMAL_FONT;
74}
75
76void wxOwnerDrawnBase::GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const
77{
78 if ( stat & wxODSelected )
79 {
80 colText = wxSystemSettings::GetColour(
81 !(stat & wxODDisabled) ? wxSYS_COLOUR_HIGHLIGHTTEXT
82 : wxSYS_COLOUR_GRAYTEXT);
83
84 colBack = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
85 }
86 else
87 {
88 // fall back to default colors if none explicitly specified
aa4919ed
VZ
89
90 if ( stat & wxODDisabled )
91 {
92 colText = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
93 }
94 else
95 {
96 colText = m_colText.Ok() ? m_colText
97 : wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT);
98 }
99
98fbab9e
VZ
100 colBack = m_colBack.Ok() ? m_colBack
101 : wxSystemSettings::GetColour(wxSYS_COLOUR_MENU);
102 }
103}
104
105#endif // wxUSE_OWNER_DRAWN