]>
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 #if !USE_SHARED_LIBRARY
23 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
26 #define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1)
28 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
30 const wxSize
& size
, long style
,
31 const wxValidator
& validator
,
34 m_buttonBitmap
= bitmap
;
36 SetValidator(validator
);
38 parent
->AddChild(this);
40 m_backgroundColour
= parent
->GetBackgroundColour() ;
41 m_foregroundColour
= parent
->GetForegroundColour() ;
42 m_windowStyle
= style
;
46 if ( style
& wxBU_AUTODRAW
)
48 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
49 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
58 m_windowId
= NewControlId();
62 if ( width
== -1 && bitmap
.Ok())
63 width
= bitmap
.GetWidth() + 2*m_marginX
;
65 if ( height
== -1 && bitmap
.Ok())
66 height
= bitmap
.GetHeight() + 2*m_marginY
;
70 m_hWnd = (WXHWND)CreateWindowEx
75 WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_OWNERDRAW ,
83 // Subclass again for purposes of dialog editing mode
86 SetFont(parent
->GetFont()) ;
88 SetSize(x
, y
, width
, height
);
93 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
95 m_buttonBitmap
= bitmap
;
100 bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item)
102 #if defined(__WIN95__)
103 long style = GetWindowLong((HWND) GetHWND(), GWL_STYLE);
104 if (style & BS_BITMAP)
106 // Let default procedure draw the bitmap, which is defined
107 // in the Windows resource.
112 LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT) item;
114 wxBitmap* bitmap = &m_buttonBitmap;
116 UINT state = lpDIS->itemState;
117 if ((state & ODS_SELECTED) && m_buttonBitmapSelected.Ok())
118 bitmap = &m_buttonBitmapSelected;
119 else if ((state & ODS_FOCUS) && m_buttonBitmapFocus.Ok())
120 bitmap = &m_buttonBitmapFocus;
121 else if ((state & ODS_DISABLED) && m_buttonBitmapDisabled.Ok())
122 bitmap = &m_buttonBitmapDisabled;
127 HDC hDC = lpDIS->hDC;
128 HDC memDC = ::CreateCompatibleDC(hDC);
130 HBITMAP old = (HBITMAP) ::SelectObject(memDC, (HBITMAP) bitmap->GetHBITMAP());
135 int x = lpDIS->rcItem.left;
136 int y = lpDIS->rcItem.top;
137 int width = lpDIS->rcItem.right - x;
138 int height = lpDIS->rcItem.bottom - y;
140 // Draw the face, if auto-drawing
141 if ( GetWindowStyleFlag() & wxBU_AUTODRAW )
142 DrawFace((WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom,
143 ((state & ODS_SELECTED) == ODS_SELECTED));
145 // Centre the bitmap in the control area
146 int x1 = (int) (x + ((width - bitmap->GetWidth()) / 2));
147 int y1 = (int) (y + ((height - bitmap->GetHeight()) / 2));
149 if ( (state & ODS_SELECTED) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
155 ::BitBlt(hDC, x1, y1, bitmap->GetWidth(), bitmap->GetHeight(), memDC, 0, 0, SRCCOPY);
157 if ( (state & ODS_DISABLED) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
158 DrawButtonDisable( (WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom, TRUE ) ;
159 else if ( (state & ODS_FOCUS) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
160 DrawButtonFocus( (WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom, ((state & ODS_SELECTED) == ODS_SELECTED));
162 ::SelectObject(memDC, old);
170 void wxBitmapButton::DrawFace( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool sel
)
183 ms_color = GetSysColor(COLOR_WINDOWFRAME) ;
184 penBorder = CreatePen(PS_SOLID,0,ms_color) ;
186 ms_color = GetSysColor(COLOR_BTNSHADOW) ;
187 penShadow = CreatePen(PS_SOLID,0,ms_color) ;
189 ms_color = GetSysColor(COLOR_BTNHIGHLIGHT) ;
190 penLight = CreatePen(PS_SOLID,0,ms_color) ;
192 ms_color = GetSysColor(COLOR_BTNFACE) ;
193 brushFace = CreateSolidBrush(ms_color) ;
195 oldp = (HPEN) SelectObject( (HDC) dc, GetStockObject( NULL_PEN ) ) ;
196 oldb = (HBRUSH) SelectObject( (HDC) dc, brushFace ) ;
197 Rectangle( (HDC) dc, left, top, right, bottom ) ;
198 SelectObject( (HDC) dc, penBorder) ;
199 MoveToEx((HDC) dc,left+1,top,NULL);LineTo((HDC) dc,right-1,top);
200 MoveToEx((HDC) dc,left,top+1,NULL);LineTo((HDC) dc,left,bottom-1);
201 MoveToEx((HDC) dc,left+1,bottom-1,NULL);LineTo((HDC) dc,right-1,bottom-1);
202 MoveToEx((HDC) dc,right-1,top+1,NULL);LineTo((HDC) dc,right-1,bottom-1);
204 SelectObject( (HDC) dc, penShadow) ;
207 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
208 LineTo((HDC) dc, left+1 ,top+1) ;
209 LineTo((HDC) dc, right-2 ,top+1) ;
213 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
214 LineTo((HDC) dc, right-2 ,bottom-2) ;
215 LineTo((HDC) dc, right-2 ,top) ;
216 MoveToEx((HDC) dc,left+2 ,bottom-3 ,NULL) ;
217 LineTo((HDC) dc, right-3 ,bottom-3) ;
218 LineTo((HDC) dc, right-3 ,top+1) ;
220 SelectObject( (HDC) dc, penLight) ;
222 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
223 LineTo((HDC) dc, left+1 ,top+1) ;
224 LineTo((HDC) dc, right-2 ,top+1) ;
226 SelectObject((HDC) dc,oldp) ;
227 SelectObject((HDC) dc,oldb) ;
229 DeleteObject(penBorder);
230 DeleteObject(penLight);
231 DeleteObject(penShadow);
232 DeleteObject(brushFace);
236 #define FOCUS_MARGIN 6
238 void wxBitmapButton::DrawButtonFocus( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool sel
)
246 rect.bottom = bottom;
247 InflateRect( &rect, - FOCUS_MARGIN, - FOCUS_MARGIN ) ;
249 OffsetRect( &rect, 1, 1 ) ;
250 DrawFocusRect( (HDC) dc, &rect ) ;
254 // extern HBRUSH wxDisableButtonBrush;
256 void wxBitmapButton::DrawButtonDisable( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool with_marg
)
260 HBRUSH old = (HBRUSH) SelectObject( (HDC) dc, wxDisableButtonBrush ) ;
263 ::PatBlt( (HDC) dc, left + m_marginX, top + m_marginY,
264 right - 2 * m_marginX, bottom - 2 * m_marginY,
270 else ::PatBlt( (HDC) dc, left, top, right, bottom,
276 ::SelectObject( (HDC) dc, old ) ;
280 void wxBitmapButton::SetDefault()
282 wxButton::SetDefault();