]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | /////////////////////////////////////////////////////////////////////////////// |
f38924e8 | 2 | // Name: src/msw/ownerdrw.cpp |
2bda0e17 KB |
3 | // Purpose: implementation of wxOwnerDrawn class |
4 | // Author: Vadim Zeitlin | |
98fbab9e | 5 | // Modified by: Marcin Malich |
2bda0e17 | 6 | // Created: 13.11.97 |
2bda0e17 | 7 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> |
65571936 | 8 | // Licence: wxWindows licence |
2bda0e17 KB |
9 | /////////////////////////////////////////////////////////////////////////////// |
10 | ||
2bda0e17 KB |
11 | // For compilers that support precompilation, includes "wx.h". |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
f38924e8 | 15 | #pragma hdrstop |
2bda0e17 KB |
16 | #endif |
17 | ||
55e04bbd VZ |
18 | #if wxUSE_OWNER_DRAWN |
19 | ||
2bda0e17 | 20 | #include "wx/ownerdrw.h" |
74052fe8 | 21 | #include "wx/msw/dc.h" |
98fbab9e VZ |
22 | #include "wx/msw/private.h" |
23 | #include "wx/msw/private/dc.h" | |
c9980eb8 | 24 | #include "wx/msw/wrapcctl.h" // for HIMAGELIST |
8ee64db5 | 25 | |
fb582e40 VZ |
26 | #ifndef DSS_HIDEPREFIX |
27 | #define DSS_HIDEPREFIX 0x0200 | |
28 | #endif | |
29 | ||
98fbab9e VZ |
30 | // ---------------------------------------------------------------------------- |
31 | // constants for base class | |
32 | // ---------------------------------------------------------------------------- | |
810ca882 | 33 | |
98fbab9e | 34 | int wxOwnerDrawnBase::ms_defaultMargin = 3; |
9ba4b498 | 35 | |
2bda0e17 KB |
36 | // ============================================================================ |
37 | // implementation of wxOwnerDrawn class | |
38 | // ============================================================================ | |
39 | ||
2bda0e17 | 40 | // draw the item |
98fbab9e VZ |
41 | bool wxOwnerDrawn::OnDrawItem(wxDC& dc, const wxRect& rc, |
42 | wxODAction, wxODStatus stat) | |
2bda0e17 | 43 | { |
98fbab9e VZ |
44 | // we do nothing if item isn't ownerdrawn |
45 | if ( !IsOwnerDrawn() ) | |
46 | return true; | |
92218ce6 | 47 | |
888dde65 RR |
48 | wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); |
49 | HDC hdc = GetHdcOf(*impl); | |
2bda0e17 | 50 | |
85ee88cd VZ |
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 | ||
2bda0e17 | 67 | |
85ee88cd VZ |
68 | AutoHBRUSH hbr(wxColourToPalRGB(colBack)); |
69 | SelectInHDC selBrush(hdc, hbr); | |
d9cf726b | 70 | |
85ee88cd | 71 | ::FillRect(hdc, &rect, hbr); |
d9cf726b | 72 | |
85ee88cd | 73 | // using native API because it recognizes '&' |
2bda0e17 | 74 | |
85ee88cd | 75 | wxString text = GetName(); |
d9cf726b | 76 | |
85ee88cd VZ |
77 | SIZE sizeRect; |
78 | ::GetTextExtentPoint32(hdc, text.c_str(), text.length(), &sizeRect); | |
fb582e40 | 79 | |
85ee88cd VZ |
80 | int flags = DST_PREFIXTEXT; |
81 | if ( (stat & wxODDisabled) && !(stat & wxODSelected) ) | |
82 | flags |= DSS_DISABLED; | |
fb582e40 | 83 | |
85ee88cd VZ |
84 | if ( (stat & wxODHidePrefix) ) |
85 | flags |= DSS_HIDEPREFIX; | |
fb582e40 | 86 | |
85ee88cd VZ |
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; | |
92218ce6 | 91 | |
017dc06b | 92 | ::DrawState(hdc, NULL, NULL, wxMSW_CONV_LPARAM(text), |
85ee88cd | 93 | text.length(), x, y, cx, cy, flags); |
07cf98cb | 94 | |
85ee88cd | 95 | } // reset to default the font, colors and brush |
cb0bcdd6 | 96 | |
85ee88cd VZ |
97 | if (stat & wxODHasFocus) |
98 | ::DrawFocusRect(hdc, &rect); | |
2bda0e17 | 99 | |
92218ce6 | 100 | return true; |
2bda0e17 KB |
101 | } |
102 | ||
0a1f7784 VZ |
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: | |
9a83f860 | 142 | wxFAIL_MSG( wxT("DrawStateBitmap: unknown wxDSBStates value") ); |
0a1f7784 VZ |
143 | result = FALSE; |
144 | } | |
145 | ||
146 | return result; | |
147 | } | |
148 | ||
1b24a68e | 149 | #endif // wxUSE_OWNER_DRAWN |