]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/ownerdrw.cpp
0b0a8e513e88ce4a6e9f0455396b93717cebd91b
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"
25 #include "wx/msw/wrapcctl.h" // for HIMAGELIST
27 #ifndef DSS_HIDEPREFIX
28 #define DSS_HIDEPREFIX 0x0200
31 // ----------------------------------------------------------------------------
32 // constants for base class
33 // ----------------------------------------------------------------------------
35 int wxOwnerDrawnBase::ms_defaultMargin
= 3;
37 // ============================================================================
38 // implementation of wxOwnerDrawn class
39 // ============================================================================
42 bool wxOwnerDrawn::OnDrawItem(wxDC
& dc
, const wxRect
& rc
,
43 wxODAction
, wxODStatus stat
)
45 // we do nothing if item isn't ownerdrawn
46 if ( !IsOwnerDrawn() )
49 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
50 HDC hdc
= GetHdcOf(*impl
);
53 wxCopyRectToRECT(rc
, rect
);
56 // set the font and colors
60 wxColour colText
, colBack
;
61 GetColourToUse(stat
, colText
, colBack
);
63 SelectInHDC
selFont(hdc
, GetHfontOf(font
));
65 wxMSWImpl::wxTextColoursChanger
textCol(hdc
, colText
, colBack
);
66 wxMSWImpl::wxBkModeChanger
bkMode(hdc
, wxBRUSHSTYLE_TRANSPARENT
);
69 AutoHBRUSH
hbr(wxColourToPalRGB(colBack
));
70 SelectInHDC
selBrush(hdc
, hbr
);
72 ::FillRect(hdc
, &rect
, hbr
);
74 // using native API because it recognizes '&'
76 wxString text
= GetName();
79 ::GetTextExtentPoint32(hdc
, text
.c_str(), text
.length(), &sizeRect
);
81 int flags
= DST_PREFIXTEXT
;
82 if ( (stat
& wxODDisabled
) && !(stat
& wxODSelected
) )
83 flags
|= DSS_DISABLED
;
85 if ( (stat
& wxODHidePrefix
) )
86 flags
|= DSS_HIDEPREFIX
;
88 int x
= rc
.x
+ GetMarginWidth();
89 int y
= rc
.y
+ (rc
.GetHeight() - sizeRect
.cy
) / 2;
90 int cx
= rc
.GetWidth() - GetMarginWidth();
93 ::DrawState(hdc
, NULL
, NULL
, wxMSW_CONV_LPARAM(text
),
94 text
.length(), x
, y
, cx
, cy
, flags
);
96 } // reset to default the font, colors and brush
98 if (stat
& wxODHasFocus
)
99 ::DrawFocusRect(hdc
, &rect
);
104 // ----------------------------------------------------------------------------
105 // global helper functions implemented here
106 // ----------------------------------------------------------------------------
108 BOOL
wxDrawStateBitmap(HDC hDC
, HBITMAP hBitmap
, int x
, int y
, UINT uState
)
110 // determine size of bitmap image
112 if ( !::GetObject(hBitmap
, sizeof(BITMAP
), &bmp
) )
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
);
137 result
= ::DrawState(hDC
, NULL
, NULL
, (LPARAM
)hBitmap
, 0, x
, y
,
138 bmp
.bmWidth
, bmp
.bmHeight
,
139 DST_BITMAP
| DSS_DISABLED
);
143 wxFAIL_MSG( wxT("DrawStateBitmap: unknown wxDSBStates value") );
150 #endif // wxUSE_OWNER_DRAWN