]>
git.saurik.com Git - wxWidgets.git/blob - 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
7 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
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
26 #ifndef DSS_HIDEPREFIX
27 #define DSS_HIDEPREFIX 0x0200
30 // ----------------------------------------------------------------------------
31 // constants for base class
32 // ----------------------------------------------------------------------------
34 int wxOwnerDrawnBase::ms_defaultMargin
= 3;
36 // ============================================================================
37 // implementation of wxOwnerDrawn class
38 // ============================================================================
41 bool wxOwnerDrawn::OnDrawItem(wxDC
& dc
, const wxRect
& rc
,
42 wxODAction
, wxODStatus stat
)
44 // we do nothing if item isn't ownerdrawn
45 if ( !IsOwnerDrawn() )
48 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
49 HDC hdc
= GetHdcOf(*impl
);
52 wxCopyRectToRECT(rc
, rect
);
55 // set the font and colors
59 wxColour colText
, colBack
;
60 GetColourToUse(stat
, colText
, colBack
);
62 SelectInHDC
selFont(hdc
, GetHfontOf(font
));
64 wxMSWImpl::wxTextColoursChanger
textCol(hdc
, colText
, colBack
);
65 wxMSWImpl::wxBkModeChanger
bkMode(hdc
, wxBRUSHSTYLE_TRANSPARENT
);
68 AutoHBRUSH
hbr(wxColourToPalRGB(colBack
));
69 SelectInHDC
selBrush(hdc
, hbr
);
71 ::FillRect(hdc
, &rect
, hbr
);
73 // using native API because it recognizes '&'
75 wxString text
= GetName();
78 ::GetTextExtentPoint32(hdc
, text
.c_str(), text
.length(), &sizeRect
);
80 int flags
= DST_PREFIXTEXT
;
81 if ( (stat
& wxODDisabled
) && !(stat
& wxODSelected
) )
82 flags
|= DSS_DISABLED
;
84 if ( (stat
& wxODHidePrefix
) )
85 flags
|= DSS_HIDEPREFIX
;
87 int x
= rc
.x
+ GetMarginWidth();
88 int y
= rc
.y
+ (rc
.GetHeight() - sizeRect
.cy
) / 2;
89 int cx
= rc
.GetWidth() - GetMarginWidth();
92 ::DrawState(hdc
, NULL
, NULL
, wxMSW_CONV_LPARAM(text
),
93 text
.length(), x
, y
, cx
, cy
, flags
);
95 } // reset to default the font, colors and brush
97 if (stat
& wxODHasFocus
)
98 ::DrawFocusRect(hdc
, &rect
);
103 // ----------------------------------------------------------------------------
104 // global helper functions implemented here
105 // ----------------------------------------------------------------------------
107 BOOL
wxDrawStateBitmap(HDC hDC
, HBITMAP hBitmap
, int x
, int y
, UINT uState
)
109 // determine size of bitmap image
111 if ( !::GetObject(hBitmap
, sizeof(BITMAP
), &bmp
) )
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
);
136 result
= ::DrawState(hDC
, NULL
, NULL
, (LPARAM
)hBitmap
, 0, x
, y
,
137 bmp
.bmWidth
, bmp
.bmHeight
,
138 DST_BITMAP
| DSS_DISABLED
);
142 wxFAIL_MSG( wxT("DrawStateBitmap: unknown wxDSBStates value") );
149 #endif // wxUSE_OWNER_DRAWN