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