]> git.saurik.com Git - wxWidgets.git/blob - src/os2/bmpbuttn.cpp
Committing in .
[wxWidgets.git] / src / os2 / bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bmpbuttn.cpp
3 // Purpose: wxBitmapButton
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/13/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/bmpbuttn.h"
17 #endif
18
19 #include "wx/os2/private.h"
20
21
22 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
23
24 #define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1)
25
26 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
27 const wxPoint& pos,
28 const wxSize& size, long style,
29 #if wxUSE_VALIDATORS
30 const wxValidator& validator,
31 #endif
32 const wxString& name)
33 {
34 m_buttonBitmap = bitmap;
35 SetName(name);
36 #if wxUSE_VALIDATORS
37 SetValidator(validator);
38 #endif
39
40 parent->AddChild(this);
41
42 m_backgroundColour = parent->GetBackgroundColour() ;
43 m_foregroundColour = parent->GetForegroundColour() ;
44 m_windowStyle = style;
45 m_marginX = 0;
46 m_marginY = 0;
47
48 if ( style & wxBU_AUTODRAW )
49 {
50 m_marginX = wxDEFAULT_BUTTON_MARGIN;
51 m_marginY = wxDEFAULT_BUTTON_MARGIN;
52 }
53
54 int x = pos.x;
55 int y = pos.y;
56 int width = size.x;
57 int height = size.y;
58
59 if (id == -1)
60 m_windowId = NewControlId();
61 else
62 m_windowId = id;
63
64 if ( width == -1 && bitmap.Ok())
65 width = bitmap.GetWidth() + 2*m_marginX;
66
67 if ( height == -1 && bitmap.Ok())
68 height = bitmap.GetHeight() + 2*m_marginY;
69
70 // TODO:
71 /*
72 m_hWnd = (WXHWND)CreateWindowEx
73 (
74 0,
75 wxT("BUTTON"),
76 wxT(""),
77 WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_OWNERDRAW ,
78 0, 0, 0, 0,
79 GetWinHwnd(parent),
80 (HMENU)m_windowId,
81 wxGetInstance(),
82 NULL
83 );
84 */
85 // Subclass again for purposes of dialog editing mode
86 SubclassWin(m_hWnd);
87
88 SetFont(parent->GetFont()) ;
89
90 SetSize(x, y, width, height);
91
92 return FALSE;
93 }
94
95 void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
96 {
97 m_buttonBitmap = bitmap;
98 }
99
100 // TODO:
101 /*
102 bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item)
103 {
104 #if defined(__WIN95__)
105 long style = GetWindowLong((HWND) GetHWND(), GWL_STYLE);
106 if (style & BS_BITMAP)
107 {
108 // Let default procedure draw the bitmap, which is defined
109 // in the Windows resource.
110 return FALSE;
111 }
112 #endif
113
114 LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT) item;
115
116 wxBitmap* bitmap = &m_buttonBitmap;
117
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;
125
126 if ( !bitmap->Ok() )
127 return FALSE;
128
129 HDC hDC = lpDIS->hDC;
130 HDC memDC = ::CreateCompatibleDC(hDC);
131
132 HBITMAP old = (HBITMAP) ::SelectObject(memDC, (HBITMAP) bitmap->GetHBITMAP());
133
134 if (!old)
135 return FALSE;
136
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;
141
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));
146
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));
150
151 if ( (state & ODS_SELECTED) && (GetWindowStyleFlag() & wxBU_AUTODRAW) )
152 {
153 x1 ++;
154 y1 ++;
155 }
156
157 ::BitBlt(hDC, x1, y1, bitmap->GetWidth(), bitmap->GetHeight(), memDC, 0, 0, SRCCOPY);
158
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));
163
164 ::SelectObject(memDC, old);
165
166 ::DeleteDC(memDC);
167
168 return TRUE;
169 }
170 */
171
172 void wxBitmapButton::DrawFace( WXHDC dc, int left, int top, int right, int bottom, bool sel )
173 {
174 // TODO:
175 /*
176 HPEN oldp;
177 HBRUSH oldb ;
178
179 HPEN penBorder;
180 HPEN penLight;
181 HPEN penShadow;
182 HBRUSH brushFace;
183 COLORREF ms_color;
184
185 ms_color = GetSysColor(COLOR_WINDOWFRAME) ;
186 penBorder = CreatePen(PS_SOLID,0,ms_color) ;
187
188 ms_color = GetSysColor(COLOR_BTNSHADOW) ;
189 penShadow = CreatePen(PS_SOLID,0,ms_color) ;
190
191 ms_color = GetSysColor(COLOR_BTNHIGHLIGHT) ;
192 penLight = CreatePen(PS_SOLID,0,ms_color) ;
193
194 ms_color = GetSysColor(COLOR_BTNFACE) ;
195 brushFace = CreateSolidBrush(ms_color) ;
196
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);
205
206 SelectObject( (HDC) dc, penShadow) ;
207 if (sel)
208 {
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) ;
212 }
213 else
214 {
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) ;
221
222 SelectObject( (HDC) dc, penLight) ;
223
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) ;
227 }
228 SelectObject((HDC) dc,oldp) ;
229 SelectObject((HDC) dc,oldb) ;
230
231 DeleteObject(penBorder);
232 DeleteObject(penLight);
233 DeleteObject(penShadow);
234 DeleteObject(brushFace);
235 */
236 }
237
238 #define FOCUS_MARGIN 6
239
240 void wxBitmapButton::DrawButtonFocus( WXHDC dc, int left, int top, int right, int bottom, bool sel )
241 {
242 // TODO:
243 /*
244 RECT rect;
245 rect.left = left;
246 rect.top = top;
247 rect.right = right;
248 rect.bottom = bottom;
249 InflateRect( &rect, - FOCUS_MARGIN, - FOCUS_MARGIN ) ;
250 if ( sel )
251 OffsetRect( &rect, 1, 1 ) ;
252 DrawFocusRect( (HDC) dc, &rect ) ;
253 */
254 }
255
256 // extern HBRUSH wxDisableButtonBrush;
257
258 void wxBitmapButton::DrawButtonDisable( WXHDC dc, int left, int top, int right, int bottom, bool with_marg )
259 {
260 // TODO:
261 /*
262 HBRUSH old = (HBRUSH) SelectObject( (HDC) dc, wxDisableButtonBrush ) ;
263
264 if ( with_marg )
265 ::PatBlt( (HDC) dc, left + m_marginX, top + m_marginY,
266 right - 2 * m_marginX, bottom - 2 * m_marginY,
267 #ifdef __SALFORDC__
268 0xfa0089L ) ;
269 #else
270 0xfa0089UL ) ;
271 #endif
272 else ::PatBlt( (HDC) dc, left, top, right, bottom,
273 #ifdef __SALFORDC__
274 0xfa0089L ) ;
275 #else
276 0xfa0089UL ) ;
277 #endif
278 ::SelectObject( (HDC) dc, old ) ;
279 */
280 }
281
282 void wxBitmapButton::SetDefault()
283 {
284 wxButton::SetDefault();
285 }