]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
16 #include "wx/bmpbuttn.h"
19 #include "wx/os2/private.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
24 #define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1)
26 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
28 const wxSize
& size
, long style
,
30 const wxValidator
& validator
,
34 m_buttonBitmap
= bitmap
;
37 SetValidator(validator
);
40 parent
->AddChild(this);
42 m_backgroundColour
= parent
->GetBackgroundColour() ;
43 m_foregroundColour
= parent
->GetForegroundColour() ;
44 m_windowStyle
= style
;
48 if ( style
& wxBU_AUTODRAW
)
50 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
51 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
60 m_windowId
= NewControlId();
64 if ( width
== -1 && bitmap
.Ok())
65 width
= bitmap
.GetWidth() + 2*m_marginX
;
67 if ( height
== -1 && bitmap
.Ok())
68 height
= bitmap
.GetHeight() + 2*m_marginY
;
72 m_hWnd = (WXHWND)CreateWindowEx
77 WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_OWNERDRAW ,
85 // Subclass again for purposes of dialog editing mode
88 SetFont(parent
->GetFont()) ;
90 SetSize(x
, y
, width
, height
);
95 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
97 m_buttonBitmap
= bitmap
;
102 bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item)
104 #if defined(__WIN95__)
105 long style = GetWindowLong((HWND) GetHWND(), GWL_STYLE);
106 if (style & BS_BITMAP)
108 // Let default procedure draw the bitmap, which is defined
109 // in the Windows resource.
114 LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT) item;
116 wxBitmap* bitmap = &m_buttonBitmap;
118 UINT state = lpDIS->itemState;
119 if ((state & ODS_SELECTED) && m_buttonBitmapSelected.Ok())
120 bitmap = &m_buttonBitmapSelected;
121 else if ((state & ODS_FOCUS) && m_buttonBitmapFocus.Ok())
122 bitmap = &m_buttonBitmapFocus;
123 else if ((state & ODS_DISABLED) && m_buttonBitmapDisabled.Ok())
124 bitmap = &m_buttonBitmapDisabled;
129 HDC hDC = lpDIS->hDC;
130 HDC memDC = ::CreateCompatibleDC(hDC);
132 HBITMAP old = (HBITMAP) ::SelectObject(memDC, (HBITMAP) bitmap->GetHBITMAP());
137 int x = lpDIS->rcItem.left;
138 int y = lpDIS->rcItem.top;
139 int width = lpDIS->rcItem.right - x;
140 int height = lpDIS->rcItem.bottom - y;
142 // Draw the face, if auto-drawing
143 if ( GetWindowStyleFlag() & wxBU_AUTODRAW )
144 DrawFace((WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom,
145 ((state & ODS_SELECTED) == ODS_SELECTED));
147 // Centre the bitmap in the control area
148 int x1 = (int) (x + ((width - bitmap->GetWidth()) / 2));
149 int y1 = (int) (y + ((height - bitmap->GetHeight()) / 2));
151 if ( (state & ODS_SELECTED) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
157 ::BitBlt(hDC, x1, y1, bitmap->GetWidth(), bitmap->GetHeight(), memDC, 0, 0, SRCCOPY);
159 if ( (state & ODS_DISABLED) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
160 DrawButtonDisable( (WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom, TRUE ) ;
161 else if ( (state & ODS_FOCUS) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
162 DrawButtonFocus( (WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom, ((state & ODS_SELECTED) == ODS_SELECTED));
164 ::SelectObject(memDC, old);
172 void wxBitmapButton::DrawFace( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool sel
)
185 ms_color = GetSysColor(COLOR_WINDOWFRAME) ;
186 penBorder = CreatePen(PS_SOLID,0,ms_color) ;
188 ms_color = GetSysColor(COLOR_BTNSHADOW) ;
189 penShadow = CreatePen(PS_SOLID,0,ms_color) ;
191 ms_color = GetSysColor(COLOR_BTNHIGHLIGHT) ;
192 penLight = CreatePen(PS_SOLID,0,ms_color) ;
194 ms_color = GetSysColor(COLOR_BTNFACE) ;
195 brushFace = CreateSolidBrush(ms_color) ;
197 oldp = (HPEN) SelectObject( (HDC) dc, GetStockObject( NULL_PEN ) ) ;
198 oldb = (HBRUSH) SelectObject( (HDC) dc, brushFace ) ;
199 Rectangle( (HDC) dc, left, top, right, bottom ) ;
200 SelectObject( (HDC) dc, penBorder) ;
201 MoveToEx((HDC) dc,left+1,top,NULL);LineTo((HDC) dc,right-1,top);
202 MoveToEx((HDC) dc,left,top+1,NULL);LineTo((HDC) dc,left,bottom-1);
203 MoveToEx((HDC) dc,left+1,bottom-1,NULL);LineTo((HDC) dc,right-1,bottom-1);
204 MoveToEx((HDC) dc,right-1,top+1,NULL);LineTo((HDC) dc,right-1,bottom-1);
206 SelectObject( (HDC) dc, penShadow) ;
209 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
210 LineTo((HDC) dc, left+1 ,top+1) ;
211 LineTo((HDC) dc, right-2 ,top+1) ;
215 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
216 LineTo((HDC) dc, right-2 ,bottom-2) ;
217 LineTo((HDC) dc, right-2 ,top) ;
218 MoveToEx((HDC) dc,left+2 ,bottom-3 ,NULL) ;
219 LineTo((HDC) dc, right-3 ,bottom-3) ;
220 LineTo((HDC) dc, right-3 ,top+1) ;
222 SelectObject( (HDC) dc, penLight) ;
224 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
225 LineTo((HDC) dc, left+1 ,top+1) ;
226 LineTo((HDC) dc, right-2 ,top+1) ;
228 SelectObject((HDC) dc,oldp) ;
229 SelectObject((HDC) dc,oldb) ;
231 DeleteObject(penBorder);
232 DeleteObject(penLight);
233 DeleteObject(penShadow);
234 DeleteObject(brushFace);
238 #define FOCUS_MARGIN 6
240 void wxBitmapButton::DrawButtonFocus( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool sel
)
248 rect.bottom = bottom;
249 InflateRect( &rect, - FOCUS_MARGIN, - FOCUS_MARGIN ) ;
251 OffsetRect( &rect, 1, 1 ) ;
252 DrawFocusRect( (HDC) dc, &rect ) ;
256 // extern HBRUSH wxDisableButtonBrush;
258 void wxBitmapButton::DrawButtonDisable( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool with_marg
)
262 HBRUSH old = (HBRUSH) SelectObject( (HDC) dc, wxDisableButtonBrush ) ;
265 ::PatBlt( (HDC) dc, left + m_marginX, top + m_marginY,
266 right - 2 * m_marginX, bottom - 2 * m_marginY,
272 else ::PatBlt( (HDC) dc, left, top, right, bottom,
278 ::SelectObject( (HDC) dc, old ) ;
282 void wxBitmapButton::SetDefault()
284 wxButton::SetDefault();