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