]>
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 const wxValidator
& validator
,
36 m_buttonBitmap
= bitmap
;
39 SetValidator(validator
);
42 parent
->AddChild(this);
44 m_backgroundColour
= parent
->GetBackgroundColour() ;
45 m_foregroundColour
= parent
->GetForegroundColour() ;
46 m_windowStyle
= style
;
50 if ( style
& wxBU_AUTODRAW
)
52 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
53 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
62 m_windowId
= NewControlId();
66 if ( width
== -1 && bitmap
.Ok())
67 width
= bitmap
.GetWidth() + 2*m_marginX
;
69 if ( height
== -1 && bitmap
.Ok())
70 height
= bitmap
.GetHeight() + 2*m_marginY
;
74 m_hWnd = (WXHWND)CreateWindowEx
79 WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_OWNERDRAW ,
87 // Subclass again for purposes of dialog editing mode
90 SetFont(parent
->GetFont()) ;
92 SetSize(x
, y
, width
, height
);
97 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
99 m_buttonBitmap
= bitmap
;
104 bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item)
106 #if defined(__WIN95__)
107 long style = GetWindowLong((HWND) GetHWND(), GWL_STYLE);
108 if (style & BS_BITMAP)
110 // Let default procedure draw the bitmap, which is defined
111 // in the Windows resource.
116 LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT) item;
118 wxBitmap* bitmap = &m_buttonBitmap;
120 UINT state = lpDIS->itemState;
121 if ((state & ODS_SELECTED) && m_buttonBitmapSelected.Ok())
122 bitmap = &m_buttonBitmapSelected;
123 else if ((state & ODS_FOCUS) && m_buttonBitmapFocus.Ok())
124 bitmap = &m_buttonBitmapFocus;
125 else if ((state & ODS_DISABLED) && m_buttonBitmapDisabled.Ok())
126 bitmap = &m_buttonBitmapDisabled;
131 HDC hDC = lpDIS->hDC;
132 HDC memDC = ::CreateCompatibleDC(hDC);
134 HBITMAP old = (HBITMAP) ::SelectObject(memDC, (HBITMAP) bitmap->GetHBITMAP());
139 int x = lpDIS->rcItem.left;
140 int y = lpDIS->rcItem.top;
141 int width = lpDIS->rcItem.right - x;
142 int height = lpDIS->rcItem.bottom - y;
144 // Draw the face, if auto-drawing
145 if ( GetWindowStyleFlag() & wxBU_AUTODRAW )
146 DrawFace((WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom,
147 ((state & ODS_SELECTED) == ODS_SELECTED));
149 // Centre the bitmap in the control area
150 int x1 = (int) (x + ((width - bitmap->GetWidth()) / 2));
151 int y1 = (int) (y + ((height - bitmap->GetHeight()) / 2));
153 if ( (state & ODS_SELECTED) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
159 ::BitBlt(hDC, x1, y1, bitmap->GetWidth(), bitmap->GetHeight(), memDC, 0, 0, SRCCOPY);
161 if ( (state & ODS_DISABLED) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
162 DrawButtonDisable( (WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom, TRUE ) ;
163 else if ( (state & ODS_FOCUS) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
164 DrawButtonFocus( (WXHDC) hDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right, lpDIS->rcItem.bottom, ((state & ODS_SELECTED) == ODS_SELECTED));
166 ::SelectObject(memDC, old);
174 void wxBitmapButton::DrawFace( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool sel
)
187 ms_color = GetSysColor(COLOR_WINDOWFRAME) ;
188 penBorder = CreatePen(PS_SOLID,0,ms_color) ;
190 ms_color = GetSysColor(COLOR_BTNSHADOW) ;
191 penShadow = CreatePen(PS_SOLID,0,ms_color) ;
193 ms_color = GetSysColor(COLOR_BTNHIGHLIGHT) ;
194 penLight = CreatePen(PS_SOLID,0,ms_color) ;
196 ms_color = GetSysColor(COLOR_BTNFACE) ;
197 brushFace = CreateSolidBrush(ms_color) ;
199 oldp = (HPEN) SelectObject( (HDC) dc, GetStockObject( NULL_PEN ) ) ;
200 oldb = (HBRUSH) SelectObject( (HDC) dc, brushFace ) ;
201 Rectangle( (HDC) dc, left, top, right, bottom ) ;
202 SelectObject( (HDC) dc, penBorder) ;
203 MoveToEx((HDC) dc,left+1,top,NULL);LineTo((HDC) dc,right-1,top);
204 MoveToEx((HDC) dc,left,top+1,NULL);LineTo((HDC) dc,left,bottom-1);
205 MoveToEx((HDC) dc,left+1,bottom-1,NULL);LineTo((HDC) dc,right-1,bottom-1);
206 MoveToEx((HDC) dc,right-1,top+1,NULL);LineTo((HDC) dc,right-1,bottom-1);
208 SelectObject( (HDC) dc, penShadow) ;
211 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
212 LineTo((HDC) dc, left+1 ,top+1) ;
213 LineTo((HDC) dc, right-2 ,top+1) ;
217 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
218 LineTo((HDC) dc, right-2 ,bottom-2) ;
219 LineTo((HDC) dc, right-2 ,top) ;
220 MoveToEx((HDC) dc,left+2 ,bottom-3 ,NULL) ;
221 LineTo((HDC) dc, right-3 ,bottom-3) ;
222 LineTo((HDC) dc, right-3 ,top+1) ;
224 SelectObject( (HDC) dc, penLight) ;
226 MoveToEx((HDC) dc,left+1 ,bottom-2 ,NULL) ;
227 LineTo((HDC) dc, left+1 ,top+1) ;
228 LineTo((HDC) dc, right-2 ,top+1) ;
230 SelectObject((HDC) dc,oldp) ;
231 SelectObject((HDC) dc,oldb) ;
233 DeleteObject(penBorder);
234 DeleteObject(penLight);
235 DeleteObject(penShadow);
236 DeleteObject(brushFace);
240 #define FOCUS_MARGIN 6
242 void wxBitmapButton::DrawButtonFocus( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool sel
)
250 rect.bottom = bottom;
251 InflateRect( &rect, - FOCUS_MARGIN, - FOCUS_MARGIN ) ;
253 OffsetRect( &rect, 1, 1 ) ;
254 DrawFocusRect( (HDC) dc, &rect ) ;
258 // extern HBRUSH wxDisableButtonBrush;
260 void wxBitmapButton::DrawButtonDisable( WXHDC dc
, int left
, int top
, int right
, int bottom
, bool with_marg
)
264 HBRUSH old = (HBRUSH) SelectObject( (HDC) dc, wxDisableButtonBrush ) ;
267 ::PatBlt( (HDC) dc, left + m_marginX, top + m_marginY,
268 right - 2 * m_marginX, bottom - 2 * m_marginY,
274 else ::PatBlt( (HDC) dc, left, top, right, bottom,
280 ::SelectObject( (HDC) dc, old ) ;
284 void wxBitmapButton::SetDefault()
286 wxButton::SetDefault();