]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
1e6feb95 | 2 | // Name: src/msw/bmpbuttn.cpp |
2bda0e17 KB |
3 | // Purpose: wxBitmapButton |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
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__ | |
1e6feb95 | 16 | #pragma hdrstop |
2bda0e17 KB |
17 | #endif |
18 | ||
1e6feb95 VZ |
19 | #if wxUSE_BMPBUTTON |
20 | ||
2bda0e17 | 21 | #ifndef WX_PRECOMP |
10a0bdb1 | 22 | #include "wx/bmpbuttn.h" |
84f19880 | 23 | #include "wx/log.h" |
47e92c41 | 24 | #include "wx/dcmemory.h" |
2bda0e17 KB |
25 | #endif |
26 | ||
27 | #include "wx/msw/private.h" | |
d50dbf7c | 28 | #include "wx/image.h" |
7996ff80 | 29 | #include "wx/msw/uxtheme.h" |
2bda0e17 | 30 | |
bc9fb572 JS |
31 | // ---------------------------------------------------------------------------- |
32 | // macros | |
33 | // ---------------------------------------------------------------------------- | |
34 | ||
35 | #if wxUSE_EXTENDED_RTTI | |
36 | ||
37 | WX_DEFINE_FLAGS( wxBitmapButtonStyle ) | |
38 | ||
3ff066a4 | 39 | wxBEGIN_FLAGS( wxBitmapButtonStyle ) |
bc9fb572 JS |
40 | // new style border flags, we put them first to |
41 | // use them for streaming out | |
3ff066a4 SC |
42 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
43 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
44 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
45 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
46 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
47 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
fcf90ee1 | 48 | |
bc9fb572 | 49 | // old style border flags |
3ff066a4 SC |
50 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
51 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
52 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
53 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
54 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 55 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
56 | |
57 | // standard window styles | |
3ff066a4 SC |
58 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
59 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
60 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
61 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 62 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
63 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
64 | wxFLAGS_MEMBER(wxVSCROLL) | |
65 | wxFLAGS_MEMBER(wxHSCROLL) | |
66 | ||
67 | wxFLAGS_MEMBER(wxBU_AUTODRAW) | |
68 | wxFLAGS_MEMBER(wxBU_LEFT) | |
69 | wxFLAGS_MEMBER(wxBU_RIGHT) | |
70 | wxFLAGS_MEMBER(wxBU_TOP) | |
71 | wxFLAGS_MEMBER(wxBU_BOTTOM) | |
72 | wxEND_FLAGS( wxBitmapButtonStyle ) | |
bc9fb572 JS |
73 | |
74 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxBitmapButton, wxButton,"wx/bmpbuttn.h") | |
75 | ||
3ff066a4 | 76 | wxBEGIN_PROPERTIES_TABLE(wxBitmapButton) |
af498247 | 77 | wxPROPERTY_FLAGS( WindowStyle , wxBitmapButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 78 | wxEND_PROPERTIES_TABLE() |
bc9fb572 | 79 | |
3ff066a4 SC |
80 | wxBEGIN_HANDLERS_TABLE(wxBitmapButton) |
81 | wxEND_HANDLERS_TABLE() | |
bc9fb572 | 82 | |
3ff066a4 | 83 | wxCONSTRUCTOR_5( wxBitmapButton , wxWindow* , Parent , wxWindowID , Id , wxBitmap , Bitmap , wxPoint , Position , wxSize , Size ) |
bc9fb572 JS |
84 | |
85 | #else | |
2bda0e17 | 86 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) |
bc9fb572 | 87 | #endif |
2bda0e17 | 88 | |
a6fd0fde VZ |
89 | BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase) |
90 | EVT_SYS_COLOUR_CHANGED(wxBitmapButton::OnSysColourChanged) | |
1fdc16ad VZ |
91 | EVT_ENTER_WINDOW(wxBitmapButton::OnMouseEnterOrLeave) |
92 | EVT_LEAVE_WINDOW(wxBitmapButton::OnMouseEnterOrLeave) | |
a6fd0fde VZ |
93 | END_EVENT_TABLE() |
94 | ||
066f1b7a SC |
95 | /* |
96 | TODO PROPERTIES : | |
97 | ||
98 | long "style" , wxBU_AUTODRAW | |
99 | bool "default" , 0 | |
100 | bitmap "selected" , | |
101 | bitmap "focus" , | |
102 | bitmap "disabled" , | |
103 | */ | |
104 | ||
a265d21a DS |
105 | bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, |
106 | const wxBitmap& bitmap, | |
107 | const wxPoint& pos, | |
108 | const wxSize& size, long style, | |
109 | const wxValidator& wxVALIDATOR_PARAM(validator), | |
110 | const wxString& name) | |
2bda0e17 | 111 | { |
a265d21a DS |
112 | m_bmpNormal = bitmap; |
113 | SetName(name); | |
11b6a93b VZ |
114 | |
115 | #if wxUSE_VALIDATORS | |
a265d21a | 116 | SetValidator(validator); |
11b6a93b | 117 | #endif // wxUSE_VALIDATORS |
2bda0e17 | 118 | |
a265d21a | 119 | parent->AddChild(this); |
2bda0e17 | 120 | |
a265d21a DS |
121 | m_backgroundColour = parent->GetBackgroundColour(); |
122 | m_foregroundColour = parent->GetForegroundColour(); | |
123 | m_windowStyle = style; | |
2bda0e17 | 124 | |
a265d21a DS |
125 | if ( style & wxBU_AUTODRAW ) |
126 | { | |
1fdc16ad VZ |
127 | m_marginX = |
128 | m_marginY = 4; | |
a265d21a | 129 | } |
2bda0e17 | 130 | |
fcf90ee1 | 131 | if (id == wxID_ANY) |
a265d21a DS |
132 | m_windowId = NewControlId(); |
133 | else | |
134 | m_windowId = id; | |
2bda0e17 | 135 | |
a265d21a | 136 | long msStyle = WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_OWNERDRAW ; |
f6bcfd97 | 137 | |
b0766406 JS |
138 | if ( m_windowStyle & wxCLIP_SIBLINGS ) |
139 | msStyle |= WS_CLIPSIBLINGS; | |
140 | ||
f6bcfd97 BP |
141 | #ifdef __WIN32__ |
142 | if(m_windowStyle & wxBU_LEFT) | |
143 | msStyle |= BS_LEFT; | |
144 | if(m_windowStyle & wxBU_RIGHT) | |
145 | msStyle |= BS_RIGHT; | |
146 | if(m_windowStyle & wxBU_TOP) | |
147 | msStyle |= BS_TOP; | |
148 | if(m_windowStyle & wxBU_BOTTOM) | |
149 | msStyle |= BS_BOTTOM; | |
150 | #endif | |
151 | ||
a265d21a | 152 | m_hWnd = (WXHWND) CreateWindowEx( |
42e69d6b | 153 | 0, |
223d09f6 | 154 | wxT("BUTTON"), |
fda7962d | 155 | wxEmptyString, |
f6bcfd97 | 156 | msStyle, |
33ac7e6f | 157 | 0, 0, 0, 0, |
42e69d6b VZ |
158 | GetWinHwnd(parent), |
159 | (HMENU)m_windowId, | |
160 | wxGetInstance(), | |
161 | NULL | |
162 | ); | |
2bda0e17 | 163 | |
a265d21a DS |
164 | // Subclass again for purposes of dialog editing mode |
165 | SubclassWin(m_hWnd); | |
2bda0e17 | 166 | |
9f884528 RD |
167 | SetPosition(pos); |
168 | SetBestSize(size); | |
2bda0e17 | 169 | |
a265d21a | 170 | return true; |
2bda0e17 KB |
171 | } |
172 | ||
d50dbf7c VZ |
173 | bool wxBitmapButton::SetBackgroundColour(const wxColour& colour) |
174 | { | |
175 | if ( !wxBitmapButtonBase::SetBackgroundColour(colour) ) | |
176 | { | |
177 | // didn't change | |
178 | return false; | |
179 | } | |
180 | ||
181 | // invalidate the brush, it will be recreated the next time it's needed | |
182 | m_brushDisabled = wxNullBrush; | |
183 | ||
184 | return true; | |
185 | } | |
186 | ||
a6fd0fde VZ |
187 | void wxBitmapButton::OnSysColourChanged(wxSysColourChangedEvent& event) |
188 | { | |
189 | m_brushDisabled = wxNullBrush; | |
190 | ||
191 | if ( !IsEnabled() ) | |
192 | { | |
193 | // this change affects our current state | |
194 | Refresh(); | |
195 | } | |
196 | ||
197 | event.Skip(); | |
198 | } | |
199 | ||
1fdc16ad VZ |
200 | void wxBitmapButton::OnMouseEnterOrLeave(wxMouseEvent& event) |
201 | { | |
202 | if ( IsEnabled() && m_bmpHover.Ok() ) | |
203 | Refresh(); | |
204 | ||
205 | event.Skip(); | |
206 | } | |
207 | ||
7996ff80 VZ |
208 | void wxBitmapButton::OnSetBitmap() |
209 | { | |
210 | // if the focus bitmap is specified but hover one isn't, use the focus | |
211 | // bitmap for hovering as well if this is consistent with the current | |
212 | // Windows version look and feel | |
213 | // | |
214 | // rationale: this is compatible with the old wxGTK behaviour and also | |
215 | // makes it much easier to do "the right thing" for all platforms (some of | |
216 | // them, such as Windows XP, have "hot" buttons while others don't) | |
217 | if ( !m_bmpHover.Ok() && | |
218 | m_bmpFocus.Ok() && | |
219 | wxUxThemeEngine::GetIfActive() ) | |
220 | { | |
221 | m_bmpHover = m_bmpFocus; | |
222 | } | |
223 | ||
224 | // this will redraw us | |
225 | wxBitmapButtonBase::OnSetBitmap(); | |
226 | } | |
227 | ||
f6bcfd97 BP |
228 | // VZ: should be at the very least less than wxDEFAULT_BUTTON_MARGIN |
229 | #define FOCUS_MARGIN 3 | |
230 | ||
2bda0e17 KB |
231 | bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item) |
232 | { | |
4676948b | 233 | #ifndef __WXWINCE__ |
ba681060 | 234 | long style = GetWindowLong((HWND) GetHWND(), GWL_STYLE); |
fd3f686c VZ |
235 | if (style & BS_BITMAP) |
236 | { | |
fd3f686c VZ |
237 | // Let default procedure draw the bitmap, which is defined |
238 | // in the Windows resource. | |
a265d21a | 239 | return false; |
fd3f686c | 240 | } |
2bda0e17 KB |
241 | #endif |
242 | ||
243 | LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT) item; | |
47e92c41 GRG |
244 | HDC hDC = lpDIS->hDC; |
245 | UINT state = lpDIS->itemState; | |
246 | bool isSelected = (state & ODS_SELECTED) != 0; | |
247 | bool autoDraw = (GetWindowStyleFlag() & wxBU_AUTODRAW) != 0; | |
2bda0e17 | 248 | |
47e92c41 GRG |
249 | |
250 | // choose the bitmap to use depending on the button state | |
1fdc16ad | 251 | wxBitmap *bitmap; |
2bda0e17 | 252 | |
1e6feb95 VZ |
253 | if ( isSelected && m_bmpSelected.Ok() ) |
254 | bitmap = &m_bmpSelected; | |
1fdc16ad VZ |
255 | else if ( m_bmpHover.Ok() && IsMouseInWindow() ) |
256 | bitmap = &m_bmpHover; | |
1e6feb95 VZ |
257 | else if ((state & ODS_FOCUS) && m_bmpFocus.Ok()) |
258 | bitmap = &m_bmpFocus; | |
259 | else if ((state & ODS_DISABLED) && m_bmpDisabled.Ok()) | |
260 | bitmap = &m_bmpDisabled; | |
d9c8e68e | 261 | else |
1e6feb95 | 262 | bitmap = &m_bmpNormal; |
2bda0e17 | 263 | |
42e69d6b | 264 | if ( !bitmap->Ok() ) |
a265d21a | 265 | return false; |
2bda0e17 | 266 | |
47e92c41 GRG |
267 | // centre the bitmap in the control area |
268 | int x = lpDIS->rcItem.left; | |
269 | int y = lpDIS->rcItem.top; | |
270 | int width = lpDIS->rcItem.right - x; | |
271 | int height = lpDIS->rcItem.bottom - y; | |
272 | int wBmp = bitmap->GetWidth(); | |
273 | int hBmp = bitmap->GetHeight(); | |
f6bcfd97 | 274 | |
a265d21a DS |
275 | int x1,y1; |
276 | ||
f6bcfd97 BP |
277 | if(m_windowStyle & wxBU_LEFT) |
278 | x1 = x + (FOCUS_MARGIN+1); | |
279 | else if(m_windowStyle & wxBU_RIGHT) | |
280 | x1 = x + (width - wBmp) - (FOCUS_MARGIN+1); | |
281 | else | |
282 | x1 = x + (width - wBmp) / 2; | |
283 | ||
284 | if(m_windowStyle & wxBU_TOP) | |
285 | y1 = y + (FOCUS_MARGIN+1); | |
286 | else if(m_windowStyle & wxBU_BOTTOM) | |
287 | y1 = y + (height - hBmp) - (FOCUS_MARGIN+1); | |
288 | else | |
289 | y1 = y + (height - hBmp) / 2; | |
2bda0e17 | 290 | |
47e92c41 | 291 | if ( isSelected && autoDraw ) |
d9c8e68e | 292 | { |
47e92c41 GRG |
293 | x1++; |
294 | y1++; | |
d9c8e68e | 295 | } |
2bda0e17 | 296 | |
47e92c41 | 297 | // draw the face, if auto-drawing |
d9c8e68e VZ |
298 | if ( autoDraw ) |
299 | { | |
300 | DrawFace((WXHDC) hDC, | |
301 | lpDIS->rcItem.left, lpDIS->rcItem.top, | |
302 | lpDIS->rcItem.right, lpDIS->rcItem.bottom, | |
303 | isSelected); | |
304 | } | |
2bda0e17 | 305 | |
47e92c41 GRG |
306 | // draw the bitmap |
307 | wxDC dst; | |
a265d21a DS |
308 | dst.SetHDC((WXHDC) hDC, false); |
309 | dst.DrawBitmap(*bitmap, x1, y1, true); | |
33ac7e6f | 310 | |
47e92c41 | 311 | // draw focus / disabled state, if auto-drawing |
d9c8e68e VZ |
312 | if ( (state & ODS_DISABLED) && autoDraw ) |
313 | { | |
314 | DrawButtonDisable((WXHDC) hDC, | |
315 | lpDIS->rcItem.left, lpDIS->rcItem.top, | |
316 | lpDIS->rcItem.right, lpDIS->rcItem.bottom, | |
a265d21a | 317 | true); |
d9c8e68e VZ |
318 | } |
319 | else if ( (state & ODS_FOCUS) && autoDraw ) | |
320 | { | |
321 | DrawButtonFocus((WXHDC) hDC, | |
322 | lpDIS->rcItem.left, | |
323 | lpDIS->rcItem.top, | |
324 | lpDIS->rcItem.right, | |
325 | lpDIS->rcItem.bottom, | |
326 | isSelected); | |
327 | } | |
2bda0e17 | 328 | |
a265d21a | 329 | return true; |
2bda0e17 KB |
330 | } |
331 | ||
5ab1fa8e GRG |
332 | // GRG Feb/2000, support for bmp buttons with Win95/98 standard LNF |
333 | ||
334 | #if defined(__WIN95__) | |
335 | ||
a265d21a DS |
336 | void wxBitmapButton::DrawFace( WXHDC dc, int left, int top, |
337 | int right, int bottom, bool sel ) | |
2bda0e17 | 338 | { |
d9c8e68e | 339 | HPEN oldp; |
5ab1fa8e | 340 | HPEN penHiLight; |
d9c8e68e VZ |
341 | HPEN penLight; |
342 | HPEN penShadow; | |
5ab1fa8e | 343 | HPEN penDkShadow; |
d9c8e68e | 344 | HBRUSH brushFace; |
2bda0e17 | 345 | |
5ab1fa8e GRG |
346 | // create needed pens and brush |
347 | penHiLight = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DHILIGHT)); | |
348 | penLight = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT)); | |
349 | penShadow = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW)); | |
350 | penDkShadow = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); | |
85b43fbf JS |
351 | // brushFace = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); |
352 | // Taking the background colour fits in better with | |
353 | // Windows XP themes. | |
354 | brushFace = CreateSolidBrush(m_backgroundColour.m_pixel); | |
5ab1fa8e GRG |
355 | |
356 | // draw the rectangle | |
357 | RECT rect; | |
358 | rect.left = left; | |
359 | rect.right = right; | |
360 | rect.top = top; | |
361 | rect.bottom = bottom; | |
362 | FillRect((HDC) dc, &rect, brushFace); | |
363 | ||
364 | // draw the border | |
365 | oldp = (HPEN) SelectObject( (HDC) dc, sel? penDkShadow : penHiLight); | |
4676948b JS |
366 | |
367 | wxDrawLine((HDC) dc, left, top, right-1, top); | |
368 | wxDrawLine((HDC) dc, left, top+1, left, bottom-1); | |
5ab1fa8e GRG |
369 | |
370 | SelectObject( (HDC) dc, sel? penShadow : penLight); | |
4676948b JS |
371 | wxDrawLine((HDC) dc, left+1, top+1, right-2, top+1); |
372 | wxDrawLine((HDC) dc, left+1, top+2, left+1, bottom-2); | |
5ab1fa8e GRG |
373 | |
374 | SelectObject( (HDC) dc, sel? penLight : penShadow); | |
4676948b JS |
375 | wxDrawLine((HDC) dc, left+1, bottom-2, right-1, bottom-2); |
376 | wxDrawLine((HDC) dc, right-2, bottom-3, right-2, top); | |
5ab1fa8e GRG |
377 | |
378 | SelectObject( (HDC) dc, sel? penHiLight : penDkShadow); | |
4676948b JS |
379 | wxDrawLine((HDC) dc, left, bottom-1, right+2, bottom-1); |
380 | wxDrawLine((HDC) dc, right-1, bottom-2, right-1, top-1); | |
5ab1fa8e GRG |
381 | |
382 | // delete allocated resources | |
383 | SelectObject((HDC) dc,oldp); | |
384 | DeleteObject(penHiLight); | |
385 | DeleteObject(penLight); | |
386 | DeleteObject(penShadow); | |
387 | DeleteObject(penDkShadow); | |
388 | DeleteObject(brushFace); | |
389 | } | |
390 | ||
391 | #else | |
2bda0e17 | 392 | |
a265d21a DS |
393 | void wxBitmapButton::DrawFace( WXHDC dc, int left, int top, |
394 | int right, int bottom, bool sel ) | |
5ab1fa8e GRG |
395 | { |
396 | HPEN oldp; | |
397 | HPEN penBorder; | |
398 | HPEN penLight; | |
399 | HPEN penShadow; | |
400 | HBRUSH brushFace; | |
2bda0e17 | 401 | |
5ab1fa8e GRG |
402 | // create needed pens and brush |
403 | penBorder = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_WINDOWFRAME)); | |
404 | penShadow = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); | |
405 | penLight = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNHIGHLIGHT)); | |
406 | brushFace = CreateSolidBrush(COLOR_BTNFACE); | |
2bda0e17 | 407 | |
5ab1fa8e GRG |
408 | // draw the rectangle |
409 | RECT rect; | |
410 | rect.left = left; | |
411 | rect.right = right; | |
412 | rect.top = top; | |
413 | rect.bottom = bottom; | |
414 | FillRect((HDC) dc, &rect, brushFace); | |
2bda0e17 | 415 | |
5ab1fa8e GRG |
416 | // draw the border |
417 | oldp = (HPEN) SelectObject( (HDC) dc, penBorder); | |
d9c8e68e VZ |
418 | MoveToEx((HDC) dc,left+1,top,NULL);LineTo((HDC) dc,right-1,top); |
419 | MoveToEx((HDC) dc,left,top+1,NULL);LineTo((HDC) dc,left,bottom-1); | |
420 | MoveToEx((HDC) dc,left+1,bottom-1,NULL);LineTo((HDC) dc,right-1,bottom-1); | |
421 | MoveToEx((HDC) dc,right-1,top+1,NULL);LineTo((HDC) dc,right-1,bottom-1); | |
2bda0e17 | 422 | |
5ab1fa8e | 423 | SelectObject( (HDC) dc, penShadow); |
fd3f686c VZ |
424 | if (sel) |
425 | { | |
5ab1fa8e GRG |
426 | MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL); |
427 | LineTo((HDC) dc, left+1 ,top+1); | |
428 | LineTo((HDC) dc, right-2 ,top+1); | |
fd3f686c VZ |
429 | } |
430 | else | |
431 | { | |
5ab1fa8e GRG |
432 | MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL); |
433 | LineTo((HDC) dc, right-2 ,bottom-2); | |
434 | LineTo((HDC) dc, right-2 ,top); | |
435 | ||
436 | MoveToEx((HDC) dc,left+2 ,bottom-3 ,NULL); | |
437 | LineTo((HDC) dc, right-3 ,bottom-3); | |
438 | LineTo((HDC) dc, right-3 ,top+1); | |
439 | ||
440 | SelectObject( (HDC) dc, penLight); | |
441 | ||
442 | MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL); | |
443 | LineTo((HDC) dc, left+1 ,top+1); | |
444 | LineTo((HDC) dc, right-2 ,top+1); | |
fd3f686c | 445 | } |
2bda0e17 | 446 | |
5ab1fa8e GRG |
447 | // delete allocated resources |
448 | SelectObject((HDC) dc,oldp); | |
d9c8e68e VZ |
449 | DeleteObject(penBorder); |
450 | DeleteObject(penLight); | |
451 | DeleteObject(penShadow); | |
452 | DeleteObject(brushFace); | |
2bda0e17 KB |
453 | } |
454 | ||
5ab1fa8e GRG |
455 | #endif // defined(__WIN95__) |
456 | ||
457 | ||
a265d21a DS |
458 | void wxBitmapButton::DrawButtonFocus( WXHDC dc, int left, int top, int right, |
459 | int bottom, bool WXUNUSED(sel) ) | |
2bda0e17 | 460 | { |
fd3f686c VZ |
461 | RECT rect; |
462 | rect.left = left; | |
463 | rect.top = top; | |
464 | rect.right = right; | |
465 | rect.bottom = bottom; | |
5ab1fa8e GRG |
466 | InflateRect( &rect, - FOCUS_MARGIN, - FOCUS_MARGIN ); |
467 | ||
468 | // GRG: the focus rectangle should not move when the button is pushed! | |
469 | /* | |
fd3f686c | 470 | if ( sel ) |
5ab1fa8e GRG |
471 | OffsetRect( &rect, 1, 1 ); |
472 | */ | |
a265d21a | 473 | |
5ab1fa8e | 474 | DrawFocusRect( (HDC) dc, &rect ); |
2bda0e17 KB |
475 | } |
476 | ||
d50dbf7c VZ |
477 | void |
478 | wxBitmapButton::DrawButtonDisable( WXHDC dc, | |
479 | int left, int top, int right, int bottom, | |
480 | bool with_marg ) | |
2bda0e17 | 481 | { |
d50dbf7c VZ |
482 | if ( !m_brushDisabled.Ok() ) |
483 | { | |
484 | // draw a bitmap with two black and two background colour pixels | |
485 | wxBitmap bmp(2, 2); | |
486 | wxMemoryDC dc; | |
487 | dc.SelectObject(bmp); | |
488 | dc.SetPen(*wxBLACK_PEN); | |
489 | dc.DrawPoint(0, 0); | |
490 | dc.DrawPoint(1, 1); | |
491 | dc.SetPen(GetBackgroundColour()); | |
492 | dc.DrawPoint(0, 1); | |
493 | dc.DrawPoint(1, 0); | |
494 | ||
495 | m_brushDisabled = wxBrush(bmp); | |
496 | } | |
497 | ||
498 | SelectInHDC selectBrush((HDC)dc, GetHbrushOf(m_brushDisabled)); | |
2bda0e17 | 499 | |
2b268535 VZ |
500 | // ROP for "dest |= pattern" operation -- as it doesn't have a standard |
501 | // name, give it our own | |
a265d21a | 502 | static const DWORD PATTERNPAINT = 0xFA0089UL; |
d9c8e68e VZ |
503 | |
504 | if ( with_marg ) | |
505 | { | |
506 | left += m_marginX; | |
507 | top += m_marginY; | |
508 | right -= 2 * m_marginX; | |
509 | bottom -= 2 * m_marginY; | |
510 | } | |
511 | ||
a265d21a | 512 | ::PatBlt( (HDC) dc, left, top, right, bottom, PATTERNPAINT); |
2bda0e17 KB |
513 | } |
514 | ||
0655ad29 VZ |
515 | void wxBitmapButton::SetDefault() |
516 | { | |
517 | wxButton::SetDefault(); | |
518 | } | |
1e6feb95 | 519 | |
c046274e RD |
520 | wxSize wxBitmapButton::DoGetBestSize() const |
521 | { | |
9266e0ec | 522 | if ( m_bmpNormal.Ok() ) |
c046274e | 523 | { |
31582e4e | 524 | wxSize best(m_bmpNormal.GetWidth() + 2*m_marginX, |
9266e0ec | 525 | m_bmpNormal.GetHeight() + 2*m_marginY); |
31582e4e RD |
526 | CacheBestSize(best); |
527 | return best; | |
c046274e | 528 | } |
e8153940 | 529 | |
9266e0ec VZ |
530 | // no idea what our best size should be, defer to the base class |
531 | return wxBitmapButtonBase::DoGetBestSize(); | |
c046274e RD |
532 | } |
533 | ||
1e6feb95 | 534 | #endif // wxUSE_BMPBUTTON |
e8153940 | 535 |