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