]> git.saurik.com Git - wxWidgets.git/blob - src/msw/ownerdrw.cpp
Compilation fix for !wxUSE_OWNER_DRAWN.
[wxWidgets.git] / src / msw / ownerdrw.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/ownerdrw.cpp
3 // Purpose: implementation of wxOwnerDrawn class
4 // Author: Vadim Zeitlin
5 // Modified by: Marcin Malich
6 // Created: 13.11.97
7 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_OWNER_DRAWN
19
20 #include "wx/ownerdrw.h"
21 #include "wx/msw/dc.h"
22 #include "wx/msw/private.h"
23 #include "wx/msw/private/dc.h"
24 #include "wx/msw/wrapcctl.h" // for HIMAGELIST
25
26 #ifndef DSS_HIDEPREFIX
27 #define DSS_HIDEPREFIX 0x0200
28 #endif
29
30 // ----------------------------------------------------------------------------
31 // constants for base class
32 // ----------------------------------------------------------------------------
33
34 int wxOwnerDrawnBase::ms_defaultMargin = 3;
35
36 // ============================================================================
37 // implementation of wxOwnerDrawn class
38 // ============================================================================
39
40 // draw the item
41 bool wxOwnerDrawn::OnDrawItem(wxDC& dc, const wxRect& rc,
42 wxODAction, wxODStatus stat)
43 {
44 // we do nothing if item isn't ownerdrawn
45 if ( !IsOwnerDrawn() )
46 return true;
47
48 wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
49 HDC hdc = GetHdcOf(*impl);
50
51 RECT rect;
52 wxCopyRectToRECT(rc, rect);
53
54 {
55 // set the font and colors
56 wxFont font;
57 GetFontToUse(font);
58
59 wxColour colText, colBack;
60 GetColourToUse(stat, colText, colBack);
61
62 SelectInHDC selFont(hdc, GetHfontOf(font));
63
64 wxMSWImpl::wxTextColoursChanger textCol(hdc, colText, colBack);
65 wxMSWImpl::wxBkModeChanger bkMode(hdc, wxBRUSHSTYLE_TRANSPARENT);
66
67
68 AutoHBRUSH hbr(wxColourToPalRGB(colBack));
69 SelectInHDC selBrush(hdc, hbr);
70
71 ::FillRect(hdc, &rect, hbr);
72
73 // using native API because it recognizes '&'
74
75 wxString text = GetName();
76
77 SIZE sizeRect;
78 ::GetTextExtentPoint32(hdc, text.c_str(), text.length(), &sizeRect);
79
80 int flags = DST_PREFIXTEXT;
81 if ( (stat & wxODDisabled) && !(stat & wxODSelected) )
82 flags |= DSS_DISABLED;
83
84 if ( (stat & wxODHidePrefix) )
85 flags |= DSS_HIDEPREFIX;
86
87 int x = rc.x + GetMarginWidth();
88 int y = rc.y + (rc.GetHeight() - sizeRect.cy) / 2;
89 int cx = rc.GetWidth() - GetMarginWidth();
90 int cy = sizeRect.cy;
91
92 ::DrawState(hdc, NULL, NULL, wxMSW_CONV_LPARAM(text),
93 text.length(), x, y, cx, cy, flags);
94
95 } // reset to default the font, colors and brush
96
97 if (stat & wxODHasFocus)
98 ::DrawFocusRect(hdc, &rect);
99
100 return true;
101 }
102
103 // ----------------------------------------------------------------------------
104 // global helper functions implemented here
105 // ----------------------------------------------------------------------------
106
107 BOOL wxDrawStateBitmap(HDC hDC, HBITMAP hBitmap, int x, int y, UINT uState)
108 {
109 // determine size of bitmap image
110 BITMAP bmp;
111 if ( !::GetObject(hBitmap, sizeof(BITMAP), &bmp) )
112 return FALSE;
113
114 BOOL result;
115
116 switch ( uState )
117 {
118 case wxDSB_NORMAL:
119 case wxDSB_SELECTED:
120 {
121 // uses image list functions to draw
122 // - normal bitmap with support transparency
123 // (image list internally create mask etc.)
124 // - blend bitmap with the background colour
125 // (like default selected items)
126 HIMAGELIST hIml = ::ImageList_Create(bmp.bmWidth, bmp.bmHeight,
127 ILC_COLOR32 | ILC_MASK, 1, 1);
128 ::ImageList_Add(hIml, hBitmap, NULL);
129 UINT fStyle = uState == wxDSB_SELECTED ? ILD_SELECTED : ILD_NORMAL;
130 result = ::ImageList_Draw(hIml, 0, hDC, x, y, fStyle);
131 ::ImageList_Destroy(hIml);
132 }
133 break;
134
135 case wxDSB_DISABLED:
136 result = ::DrawState(hDC, NULL, NULL, (LPARAM)hBitmap, 0, x, y,
137 bmp.bmWidth, bmp.bmHeight,
138 DST_BITMAP | DSS_DISABLED);
139 break;
140
141 default:
142 wxFAIL_MSG( wxT("DrawStateBitmap: unknown wxDSBStates value") );
143 result = FALSE;
144 }
145
146 return result;
147 }
148
149 #endif // wxUSE_OWNER_DRAWN