]>
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
,
32 # if defined(__VISAGECPP__)
33 const wxValidator
* validator
,
35 const wxValidator
& validator
,
40 m_buttonBitmap
= bitmap
;
43 SetValidator(validator
);
46 parent
->AddChild(this);
48 m_backgroundColour
= parent
->GetBackgroundColour() ;
49 m_foregroundColour
= parent
->GetForegroundColour() ;
50 m_windowStyle
= style
;
54 if ( style
& wxBU_AUTODRAW
)
56 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
57 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
66 m_windowId
= NewControlId();
70 if ( width
== -1 && bitmap
.Ok())
71 width
= bitmap
.GetWidth() + 2*m_marginX
;
73 if ( height
== -1 && bitmap
.Ok())
74 height
= bitmap
.GetHeight() + 2*m_marginY
;
78 m_hWnd = (WXHWND)CreateWindowEx
83 WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_OWNERDRAW ,
91 // Subclass again for purposes of dialog editing mode
94 SetFont(parent
->GetFont()) ;
96 SetSize(x
, y
, width
, height
);
101 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
103 m_buttonBitmap
= bitmap
;
108 bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item)
110 #if defined(__WIN95__)
111 long style = GetWindowLong((HWND) GetHWND(), GWL_STYLE);
112 if (style & BS_BITMAP)
114 // Let default procedure draw the bitmap, which is defined
115 // in the Windows resource.
120 LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT) item;
122 wxBitmap* bitmap = &m_buttonBitmap;
124 UINT state = lpDIS->itemState;
125 if ((state & ODS_SELECTED) && m_buttonBitmapSelected.Ok())
126 bitmap = &m_buttonBitmapSelected;
127 else if ((state & ODS_FOCUS) && m_buttonBitmapFocus.Ok())
128 bitmap = &m_buttonBitmapFocus;
129 else if ((state & ODS_DISABLED) && m_buttonBitmapDisabled.Ok())
130 bitmap = &m_buttonBitmapDisabled;
135 HDC hDC = lpDIS->hDC;
136 HDC memDC = ::CreateCompatibleDC(hDC);
138 HBITMAP old = (HBITMAP) ::SelectObject(memDC, (HBITMAP) bitmap->GetHBITMAP());
143 int x = lpDIS->rcItem.left;
144 int y = lpDIS->rcItem.top;
145 int width = lpDIS->rcItem.right - x;
146 int height = lpDIS->rcItem.bottom - y;
148 // Draw the face, if auto-drawing
149 if ( GetWindowStyleFlag() & wxBU_AUTODRAW )
150 DrawFace((WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom,
151 ((state & ODS_SELECTED) == ODS_SELECTED));
153 // Centre the bitmap in the control area
154 int x1 = (int) (x + ((width - bitmap->GetWidth()) / 2));
155 int y1 = (int) (y + ((height - bitmap->GetHeight()) / 2));
157 if ( (state & ODS_SELECTED) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
163 ::BitBlt(hDC, x1, y1, bitmap->GetWidth(), bitmap->GetHeight(), memDC, 0, 0, SRCCOPY);
165 if ( (state & ODS_DISABLED) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
166 DrawButtonDisable( (WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom, TRUE ) ;
167 else if ( (state & ODS_FOCUS) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
168 DrawButtonFocus( (WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom, ((state & ODS_SELECTED) == ODS_SELECTED));
170 ::SelectObject(memDC, old);
178 void wxBitmapButton::DrawFace( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool sel
)
191 ms_color = GetSysColor(COLOR_WINDOWFRAME) ;
192 penBorder = CreatePen(PS_SOLID,0,ms_color) ;
194 ms_color = GetSysColor(COLOR_BTNSHADOW) ;
195 penShadow = CreatePen(PS_SOLID,0,ms_color) ;
197 ms_color = GetSysColor(COLOR_BTNHIGHLIGHT) ;
198 penLight = CreatePen(PS_SOLID,0,ms_color) ;
200 ms_color = GetSysColor(COLOR_BTNFACE) ;
201 brushFace = CreateSolidBrush(ms_color) ;
203 oldp = (HPEN) SelectObject( (HDC) dc, GetStockObject( NULL_PEN ) ) ;
204 oldb = (HBRUSH) SelectObject( (HDC) dc, brushFace ) ;
205 Rectangle( (HDC) dc, left, top, right, bottom ) ;
206 SelectObject( (HDC) dc, penBorder) ;
207 MoveToEx((HDC) dc,left+1,top,NULL);LineTo((HDC) dc,right-1,top);
208 MoveToEx((HDC) dc,left,top+1,NULL);LineTo((HDC) dc,left,bottom-1);
209 MoveToEx((HDC) dc,left+1,bottom-1,NULL);LineTo((HDC) dc,right-1,bottom-1);
210 MoveToEx((HDC) dc,right-1,top+1,NULL);LineTo((HDC) dc,right-1,bottom-1);
212 SelectObject( (HDC) dc, penShadow) ;
215 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
216 LineTo((HDC) dc, left+1 ,top+1) ;
217 LineTo((HDC) dc, right-2 ,top+1) ;
221 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
222 LineTo((HDC) dc, right-2 ,bottom-2) ;
223 LineTo((HDC) dc, right-2 ,top) ;
224 MoveToEx((HDC) dc,left+2 ,bottom-3 ,NULL) ;
225 LineTo((HDC) dc, right-3 ,bottom-3) ;
226 LineTo((HDC) dc, right-3 ,top+1) ;
228 SelectObject( (HDC) dc, penLight) ;
230 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
231 LineTo((HDC) dc, left+1 ,top+1) ;
232 LineTo((HDC) dc, right-2 ,top+1) ;
234 SelectObject((HDC) dc,oldp) ;
235 SelectObject((HDC) dc,oldb) ;
237 DeleteObject(penBorder);
238 DeleteObject(penLight);
239 DeleteObject(penShadow);
240 DeleteObject(brushFace);
244 #define FOCUS_MARGIN 6
246 void wxBitmapButton::DrawButtonFocus( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool sel
)
254 rect.bottom = bottom;
255 InflateRect( &rect, - FOCUS_MARGIN, - FOCUS_MARGIN ) ;
257 OffsetRect( &rect, 1, 1 ) ;
258 DrawFocusRect( (HDC) dc, &rect ) ;
262 // extern HBRUSH wxDisableButtonBrush;
264 void wxBitmapButton::DrawButtonDisable( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool with_marg
)
268 HBRUSH old = (HBRUSH) SelectObject( (HDC) dc, wxDisableButtonBrush ) ;
271 ::PatBlt( (HDC) dc, left + m_marginX, top + m_marginY,
272 right - 2 * m_marginX, bottom - 2 * m_marginY,
278 else ::PatBlt( (HDC) dc, left, top, right, bottom,
284 ::SelectObject( (HDC) dc, old ) ;
288 void wxBitmapButton::SetDefault()
290 wxButton::SetDefault();