]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: bmpbuttn.cpp | |
3 | // Purpose: wxBitmapButton | |
37f214d5 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
37f214d5 | 6 | // Created: 10/13/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
37f214d5 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
37f214d5 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
0e320a79 | 14 | |
db16e5c3 DW |
15 | #if wxUSE_BMPBUTTON |
16 | ||
37f214d5 | 17 | #ifndef WX_PRECOMP |
0e320a79 | 18 | #include "wx/bmpbuttn.h" |
37f214d5 DW |
19 | #endif |
20 | ||
21 | #include "wx/os2/private.h" | |
22 | ||
0e320a79 | 23 | |
0e320a79 | 24 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) |
0e320a79 | 25 | |
37f214d5 DW |
26 | #define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1) |
27 | ||
db16e5c3 DW |
28 | bool wxBitmapButton::Create( |
29 | wxWindow* pParent | |
30 | , wxWindowID vId | |
31 | , const wxBitmap& rBitmap | |
32 | , const wxPoint& rPos | |
33 | , const wxSize& rSize | |
34 | , long lStyle | |
5d4b632b | 35 | #if wxUSE_VALIDATORS |
db16e5c3 | 36 | , const wxValidator& rValidator |
5d4b632b | 37 | #endif |
db16e5c3 DW |
38 | , const wxString& rsName |
39 | ) | |
0e320a79 | 40 | { |
db16e5c3 DW |
41 | m_bmpNormal = rBitmap; |
42 | SetName(rsName); | |
5d4b632b | 43 | #if wxUSE_VALIDATORS |
db16e5c3 | 44 | SetValidator(rValidator); |
5d4b632b | 45 | #endif |
37f214d5 | 46 | |
db16e5c3 | 47 | pParent->AddChild(this); |
0e320a79 | 48 | |
db16e5c3 DW |
49 | m_backgroundColour = pParent->GetBackgroundColour() ; |
50 | m_foregroundColour = pParent->GetForegroundColour() ; | |
51 | m_windowStyle = lStyle; | |
0e320a79 | 52 | |
db16e5c3 | 53 | if (lStyle & wxBU_AUTODRAW) |
37f214d5 DW |
54 | { |
55 | m_marginX = wxDEFAULT_BUTTON_MARGIN; | |
56 | m_marginY = wxDEFAULT_BUTTON_MARGIN; | |
57 | } | |
58 | ||
db16e5c3 DW |
59 | int nX = rPos.x; |
60 | int nY = rPos.y; | |
61 | int nWidth = rSize.x; | |
62 | int nHeight = rSize.y; | |
0e320a79 | 63 | |
db16e5c3 | 64 | if (vId == -1) |
0e320a79 DW |
65 | m_windowId = NewControlId(); |
66 | else | |
db16e5c3 DW |
67 | m_windowId = vId; |
68 | ||
69 | if (nWidth == -1 && rBitmap.Ok()) | |
a5799260 | 70 | nWidth = rBitmap.GetWidth() + 4 * m_marginX; |
db16e5c3 DW |
71 | |
72 | if (nHeight == -1 && rBitmap.Ok()) | |
a5799260 | 73 | nHeight = rBitmap.GetHeight() + 4 * m_marginY; |
db16e5c3 DW |
74 | |
75 | ULONG ulOS2Style = WS_VISIBLE | WS_TABSTOP | BS_USERBUTTON; | |
76 | ||
77 | if (m_windowStyle & wxCLIP_SIBLINGS) | |
78 | ulOS2Style |= WS_CLIPSIBLINGS; | |
79 | ||
80 | m_hWnd = (WXHWND)::WinCreateWindow( GetHwndOf(pParent) | |
81 | ,WC_BUTTON | |
82 | ,wxT("") | |
83 | ,ulOS2Style | |
84 | ,0, 0, 0, 0 | |
85 | ,GetHwndOf(pParent) | |
86 | ,HWND_TOP | |
87 | ,m_windowId | |
88 | ,NULL | |
89 | ,NULL | |
90 | ); | |
91 | ||
92 | // | |
93 | //Subclass again for purposes of dialog editing mode | |
94 | // | |
37f214d5 | 95 | SubclassWin(m_hWnd); |
db16e5c3 DW |
96 | SetFont(*wxSMALL_FONT); |
97 | SetSize( nX | |
98 | ,nY | |
99 | ,nWidth | |
100 | ,nHeight | |
101 | ); | |
102 | return TRUE; | |
103 | } // end of wxBitmapButton::Create | |
37f214d5 | 104 | |
db16e5c3 DW |
105 | bool wxBitmapButton::OS2OnDraw( |
106 | WXDRAWITEMSTRUCT* pItem | |
107 | ) | |
0e320a79 | 108 | { |
db16e5c3 DW |
109 | PUSERBUTTON pUser = (PUSERBUTTON)pItem; |
110 | bool bAutoDraw = (GetWindowStyleFlag() & wxBU_AUTODRAW) != 0; | |
0e320a79 | 111 | |
db16e5c3 | 112 | if (!pUser) |
37f214d5 | 113 | return FALSE; |
37f214d5 | 114 | |
db16e5c3 DW |
115 | wxBitmap* pBitmap; |
116 | RECTL vRect; | |
117 | bool bIsSelected = pUser->fsState & BDS_HILITED; | |
118 | wxClientDC vDc(this); | |
119 | ||
120 | if (bIsSelected && m_bmpSelected.Ok()) | |
121 | pBitmap = &m_bmpSelected; | |
122 | else if ((pUser->fsState & BDS_DEFAULT) && m_bmpFocus.Ok()) | |
123 | pBitmap = &m_bmpFocus; | |
124 | else if ((pUser->fsState & BDS_DISABLED) && m_bmpDisabled.Ok()) | |
125 | pBitmap = &m_bmpDisabled; | |
126 | else | |
127 | pBitmap = &m_bmpNormal; | |
37f214d5 | 128 | |
db16e5c3 | 129 | if (!pBitmap->Ok() ) |
37f214d5 DW |
130 | return FALSE; |
131 | ||
37f214d5 | 132 | |
db16e5c3 | 133 | // |
37f214d5 | 134 | // Centre the bitmap in the control area |
db16e5c3 DW |
135 | // |
136 | int nX = 0; | |
137 | int nY = 0; | |
138 | int nX1 = 0; | |
139 | int nY1 = 0; | |
140 | int nWidth = vDc.m_vRclPaint.xRight - vDc.m_vRclPaint.xLeft; | |
141 | int nHeight = vDc.m_vRclPaint.xRight - vDc.m_vRclPaint.xLeft; | |
142 | int nBmpWidth = pBitmap->GetWidth(); | |
143 | int nBmpHeight = pBitmap->GetHeight(); | |
144 | ||
145 | nX1 = nX + (nWidth - nBmpWidth) / 2; | |
146 | nY1 = nX + (nHeight - nBmpHeight) / 2; | |
147 | ||
148 | if (bIsSelected && bAutoDraw) | |
37f214d5 | 149 | { |
db16e5c3 DW |
150 | nX1++; |
151 | nY1++; | |
37f214d5 DW |
152 | } |
153 | ||
db16e5c3 DW |
154 | // |
155 | // Draw the button face | |
156 | // | |
157 | { | |
158 | DrawFace( vDc | |
159 | ,bIsSelected | |
160 | ); | |
161 | } | |
37f214d5 | 162 | |
db16e5c3 DW |
163 | // |
164 | // Draw the bitmap | |
165 | // | |
166 | vDc.DrawBitmap( *pBitmap | |
167 | ,nX1 | |
168 | ,nY1 | |
169 | ,TRUE | |
170 | ); | |
171 | ||
172 | // | |
173 | // Draw focus / disabled state, if auto-drawing | |
174 | // | |
175 | if ((pUser->fsState == BDS_DISABLED) && bAutoDraw) | |
37f214d5 | 176 | { |
db16e5c3 DW |
177 | DrawButtonDisable( vDc |
178 | ,*pBitmap | |
179 | ); | |
37f214d5 | 180 | } |
db16e5c3 | 181 | else if ((pUser->fsState == BDS_DEFAULT) && bAutoDraw) |
37f214d5 | 182 | { |
db16e5c3 | 183 | DrawButtonFocus(vDc); |
37f214d5 | 184 | } |
db16e5c3 DW |
185 | return TRUE; |
186 | } // end of wxBitmapButton::OS2OnDraw | |
37f214d5 | 187 | |
db16e5c3 DW |
188 | void wxBitmapButton::DrawFace ( |
189 | wxClientDC& rDC | |
190 | , bool bSel | |
191 | ) | |
37f214d5 | 192 | { |
db16e5c3 DW |
193 | // |
194 | // Set up drawing colors | |
195 | // | |
a5799260 DW |
196 | wxPen vHiLitePen(wxColour(255, 255, 255), 2, wxSOLID); // White |
197 | wxPen vDarkShadowPen(wxColour(85, 85, 85), 2, wxSOLID); | |
db16e5c3 DW |
198 | wxColour vFaceColor(wxColour(204, 204, 204)); // Light Grey |
199 | ||
200 | // | |
201 | // Draw the main button face | |
202 | // | |
203 | ::WinFillRect(rDC.GetHPS(), &rDC.m_vRclPaint, vFaceColor.GetPixel()); | |
204 | ||
205 | // | |
206 | // Draw the border | |
207 | // | |
208 | rDC.SetPen(bSel ? vDarkShadowPen : vHiLitePen); | |
db16e5c3 | 209 | rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1 |
a5799260 DW |
210 | ,rDC.m_vRclPaint.yTop - 1 |
211 | ,rDC.m_vRclPaint.xRight - 1 | |
212 | ,rDC.m_vRclPaint.yTop - 1 | |
db16e5c3 DW |
213 | ); |
214 | rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1 | |
a5799260 | 215 | ,rDC.m_vRclPaint.yTop - 1 |
db16e5c3 | 216 | ,rDC.m_vRclPaint.xLeft + 1 |
a5799260 | 217 | ,rDC.m_vRclPaint.yBottom + 1 |
db16e5c3 DW |
218 | ); |
219 | ||
a5799260 | 220 | rDC.SetPen(bSel ? vHiLitePen : vDarkShadowPen); |
db16e5c3 | 221 | rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1 |
a5799260 | 222 | ,rDC.m_vRclPaint.yBottom + 1 |
db16e5c3 | 223 | ,rDC.m_vRclPaint.xRight - 1 |
a5799260 | 224 | ,rDC.m_vRclPaint.yBottom + 1 |
db16e5c3 DW |
225 | ); |
226 | rDC.DrawLine( rDC.m_vRclPaint.xRight - 1 | |
db16e5c3 | 227 | ,rDC.m_vRclPaint.yTop - 1 |
a5799260 DW |
228 | ,rDC.m_vRclPaint.xRight - 1 |
229 | ,rDC.m_vRclPaint.yBottom + 1 | |
db16e5c3 | 230 | ); |
a5799260 | 231 | |
db16e5c3 DW |
232 | } // end of wxBitmapButton::DrawFace |
233 | ||
234 | void wxBitmapButton::DrawButtonFocus ( | |
235 | wxClientDC& rDC | |
236 | ) | |
37f214d5 | 237 | { |
db16e5c3 DW |
238 | wxPen vBlackPen(wxColour(0, 0, 0), 2, wxSOLID); |
239 | ||
240 | // | |
241 | // Draw a thick black line around the outside of the button | |
242 | // | |
243 | rDC.SetPen(vBlackPen); | |
244 | rDC.DrawLine( rDC.m_vRclPaint.xLeft | |
245 | ,rDC.m_vRclPaint.yTop | |
246 | ,rDC.m_vRclPaint.xRight | |
247 | ,rDC.m_vRclPaint.yTop | |
248 | ); | |
249 | rDC.DrawLine( rDC.m_vRclPaint.xRight | |
250 | ,rDC.m_vRclPaint.yTop | |
251 | ,rDC.m_vRclPaint.xRight | |
252 | ,rDC.m_vRclPaint.yBottom | |
253 | ); | |
254 | rDC.DrawLine( rDC.m_vRclPaint.xRight | |
255 | ,rDC.m_vRclPaint.yBottom | |
256 | ,rDC.m_vRclPaint.xLeft | |
257 | ,rDC.m_vRclPaint.yBottom | |
258 | ); | |
259 | rDC.DrawLine( rDC.m_vRclPaint.xLeft | |
260 | ,rDC.m_vRclPaint.yBottom | |
261 | ,rDC.m_vRclPaint.xLeft | |
262 | ,rDC.m_vRclPaint.yTop | |
263 | ); | |
264 | } // end of wxBitmapButton::DrawButtonFocus | |
265 | ||
266 | void wxBitmapButton::DrawButtonDisable( | |
267 | wxClientDC& rDC | |
268 | , wxBitmap& rBmp | |
269 | ) | |
270 | { | |
271 | wxPen vGreyPen(wxColour(128, 128, 128), 2, wxSOLID); | |
272 | ||
273 | // | |
274 | // Draw a thick black line around the outside of the button | |
275 | // | |
276 | rDC.SetPen(vGreyPen); | |
277 | rDC.DrawLine( rDC.m_vRclPaint.xLeft | |
278 | ,rDC.m_vRclPaint.yTop | |
279 | ,rDC.m_vRclPaint.xRight | |
280 | ,rDC.m_vRclPaint.yTop | |
281 | ); | |
282 | rDC.DrawLine( rDC.m_vRclPaint.xRight | |
283 | ,rDC.m_vRclPaint.yTop | |
284 | ,rDC.m_vRclPaint.xRight | |
285 | ,rDC.m_vRclPaint.yBottom | |
286 | ); | |
287 | rDC.DrawLine( rDC.m_vRclPaint.xRight | |
288 | ,rDC.m_vRclPaint.yBottom | |
289 | ,rDC.m_vRclPaint.xLeft | |
290 | ,rDC.m_vRclPaint.yBottom | |
291 | ); | |
292 | rDC.DrawLine( rDC.m_vRclPaint.xLeft | |
293 | ,rDC.m_vRclPaint.yBottom | |
294 | ,rDC.m_vRclPaint.xLeft | |
295 | ,rDC.m_vRclPaint.yTop | |
296 | ); | |
297 | wxDisableBitmap(rBmp, vGreyPen.GetColour().GetPixel()); | |
298 | } // end of wxBitmapButton::DrawButtonDisable | |
37f214d5 DW |
299 | |
300 | void wxBitmapButton::SetDefault() | |
301 | { | |
302 | wxButton::SetDefault(); | |
303 | } | |
db16e5c3 DW |
304 | |
305 | #endif // ndef for wxUSE_BMPBUTTON | |
306 |