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