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