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