1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/ownerdrw.cpp
3 // Purpose: implementation of wxOwnerDrawn class
4 // Author: Vadim Zeitlin
5 // Modified by: Marcin Malich
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/ownerdrw.h"
22 #include "wx/msw/dc.h"
23 #include "wx/msw/private.h"
24 #include "wx/msw/private/dc.h"
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 // set the font and colors
52 wxColour colText
, colBack
;
53 GetColourToUse(stat
, colText
, colBack
);
55 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
56 HDC hdc
= GetHdcOf(*impl
);
58 SelectInHDC
selFont(hdc
, GetHfontOf(font
));
60 wxMSWImpl
::wxTextColoursChanger
textCol(hdc
, colText
, colBack
);
61 wxMSWImpl
::wxBkModeChanger
bkMode(hdc
, wxBRUSHSTYLE_TRANSPARENT
);
64 AutoHBRUSH
hbr(wxColourToPalRGB(colBack
));
65 SelectInHDC
selBrush(hdc
, hbr
);
68 wxCopyRectToRECT(rc
, rectFill
);
69 ::FillRect(hdc
, &rectFill
, hbr
);
71 // using native API because it recognizes '&'
73 wxString text
= GetName();
76 ::GetTextExtentPoint32(hdc
, text
.c_str(), text
.length(), &sizeRect
);
78 int flags
= DST_PREFIXTEXT
;
79 if ( (stat
& wxODDisabled
) && !(stat
& wxODSelected
) )
80 flags
|= DSS_DISABLED
;
82 if ( (stat
& wxODHidePrefix
) )
83 flags
|= DSS_HIDEPREFIX
;
85 int x
= rc
.x
+ GetMarginWidth();
86 int y
= rc
.y
+ (rc
.GetHeight() - sizeRect
.cy
) / 2;
87 int cx
= rc
.GetWidth() - GetMarginWidth();
90 ::DrawState(hdc
, NULL
, NULL
, (LPARAM
)text
.wx_str(),
91 text
.length(), x
, y
, cx
, cy
, flags
);
96 // ----------------------------------------------------------------------------
97 // global helper functions implemented here
98 // ----------------------------------------------------------------------------
100 BOOL
wxDrawStateBitmap(HDC hDC
, HBITMAP hBitmap
, int x
, int y
, UINT uState
)
102 // determine size of bitmap image
104 if ( !::GetObject(hBitmap
, sizeof(BITMAP
), &bmp
) )
114 // uses image list functions to draw
115 // - normal bitmap with support transparency
116 // (image list internally create mask etc.)
117 // - blend bitmap with the background colour
118 // (like default selected items)
119 HIMAGELIST hIml
= ::ImageList_Create(bmp
.bmWidth
, bmp
.bmHeight
,
120 ILC_COLOR32
| ILC_MASK
, 1, 1);
121 ::ImageList_Add(hIml
, hBitmap
, NULL
);
122 UINT fStyle
= uState
== wxDSB_SELECTED ? ILD_SELECTED
: ILD_NORMAL
;
123 result
= ::ImageList_Draw(hIml
, 0, hDC
, x
, y
, fStyle
);
124 ::ImageList_Destroy(hIml
);
129 result
= ::DrawState(hDC
, NULL
, NULL
, (LPARAM
)hBitmap
, 0, x
, y
,
130 bmp
.bmWidth
, bmp
.bmHeight
,
131 DST_BITMAP
| DSS_DISABLED
);
135 wxFAIL_MSG( wxT("DrawStateBitmap: unknown wxDSBStates value") );
142 #endif // wxUSE_OWNER_DRAWN