]>
Commit | Line | Data |
---|---|---|
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 | #if wxUSE_VALIDATORS | |
32 | # if defined(__VISAGECPP__) | |
33 | const wxValidator* validator, | |
34 | # else | |
35 | const wxValidator& validator, | |
36 | # endif | |
37 | #endif | |
38 | const wxString& name) | |
39 | { | |
40 | m_buttonBitmap = bitmap; | |
41 | SetName(name); | |
42 | #if wxUSE_VALIDATORS | |
43 | SetValidator(validator); | |
44 | #endif | |
45 | ||
46 | parent->AddChild(this); | |
47 | ||
48 | m_backgroundColour = parent->GetBackgroundColour() ; | |
49 | m_foregroundColour = parent->GetForegroundColour() ; | |
50 | m_windowStyle = style; | |
51 | m_marginX = 0; | |
52 | m_marginY = 0; | |
53 | ||
54 | if ( style & wxBU_AUTODRAW ) | |
55 | { | |
56 | m_marginX = wxDEFAULT_BUTTON_MARGIN; | |
57 | m_marginY = wxDEFAULT_BUTTON_MARGIN; | |
58 | } | |
59 | ||
60 | int x = pos.x; | |
61 | int y = pos.y; | |
62 | int width = size.x; | |
63 | int height = size.y; | |
64 | ||
65 | if (id == -1) | |
66 | m_windowId = NewControlId(); | |
67 | else | |
68 | m_windowId = id; | |
69 | ||
70 | if ( width == -1 && bitmap.Ok()) | |
71 | width = bitmap.GetWidth() + 2*m_marginX; | |
72 | ||
73 | if ( height == -1 && bitmap.Ok()) | |
74 | height = bitmap.GetHeight() + 2*m_marginY; | |
75 | ||
76 | // TODO: | |
77 | /* | |
78 | m_hWnd = (WXHWND)CreateWindowEx | |
79 | ( | |
80 | 0, | |
81 | wxT("BUTTON"), | |
82 | wxT(""), | |
83 | WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_OWNERDRAW , | |
84 | 0, 0, 0, 0, | |
85 | GetWinHwnd(parent), | |
86 | (HMENU)m_windowId, | |
87 | wxGetInstance(), | |
88 | NULL | |
89 | ); | |
90 | */ | |
91 | // Subclass again for purposes of dialog editing mode | |
92 | SubclassWin(m_hWnd); | |
93 | ||
94 | SetFont(parent->GetFont()) ; | |
95 | ||
96 | SetSize(x, y, width, height); | |
97 | ||
98 | return FALSE; | |
99 | } | |
100 | ||
101 | void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) | |
102 | { | |
103 | m_buttonBitmap = bitmap; | |
104 | } | |
105 | ||
106 | // TODO: | |
107 | /* | |
108 | bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item) | |
109 | { | |
110 | #if defined(__WIN95__) | |
111 | long style = GetWindowLong((HWND) GetHWND(), GWL_STYLE); | |
112 | if (style & BS_BITMAP) | |
113 | { | |
114 | // Let default procedure draw the bitmap, which is defined | |
115 | // in the Windows resource. | |
116 | return FALSE; | |
117 | } | |
118 | #endif | |
119 | ||
120 | LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT) item; | |
121 | ||
122 | wxBitmap* bitmap = &m_buttonBitmap; | |
123 | ||
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; | |
131 | ||
132 | if ( !bitmap->Ok() ) | |
133 | return FALSE; | |
134 | ||
135 | HDC hDC = lpDIS->hDC; | |
136 | HDC memDC = ::CreateCompatibleDC(hDC); | |
137 | ||
138 | HBITMAP old = (HBITMAP) ::SelectObject(memDC, (HBITMAP) bitmap->GetHBITMAP()); | |
139 | ||
140 | if (!old) | |
141 | return FALSE; | |
142 | ||
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; | |
147 | ||
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)); | |
152 | ||
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)); | |
156 | ||
157 | if ( (state & ODS_SELECTED) && (GetWindowStyleFlag() & wxBU_AUTODRAW) ) | |
158 | { | |
159 | x1 ++; | |
160 | y1 ++; | |
161 | } | |
162 | ||
163 | ::BitBlt(hDC, x1, y1, bitmap->GetWidth(), bitmap->GetHeight(), memDC, 0, 0, SRCCOPY); | |
164 | ||
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)); | |
169 | ||
170 | ::SelectObject(memDC, old); | |
171 | ||
172 | ::DeleteDC(memDC); | |
173 | ||
174 | return TRUE; | |
175 | } | |
176 | */ | |
177 | ||
178 | void wxBitmapButton::DrawFace( WXHDC dc, int left, int top, int right, int bottom, bool sel ) | |
179 | { | |
180 | // TODO: | |
181 | /* | |
182 | HPEN oldp; | |
183 | HBRUSH oldb ; | |
184 | ||
185 | HPEN penBorder; | |
186 | HPEN penLight; | |
187 | HPEN penShadow; | |
188 | HBRUSH brushFace; | |
189 | COLORREF ms_color; | |
190 | ||
191 | ms_color = GetSysColor(COLOR_WINDOWFRAME) ; | |
192 | penBorder = CreatePen(PS_SOLID,0,ms_color) ; | |
193 | ||
194 | ms_color = GetSysColor(COLOR_BTNSHADOW) ; | |
195 | penShadow = CreatePen(PS_SOLID,0,ms_color) ; | |
196 | ||
197 | ms_color = GetSysColor(COLOR_BTNHIGHLIGHT) ; | |
198 | penLight = CreatePen(PS_SOLID,0,ms_color) ; | |
199 | ||
200 | ms_color = GetSysColor(COLOR_BTNFACE) ; | |
201 | brushFace = CreateSolidBrush(ms_color) ; | |
202 | ||
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); | |
211 | ||
212 | SelectObject( (HDC) dc, penShadow) ; | |
213 | if (sel) | |
214 | { | |
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) ; | |
218 | } | |
219 | else | |
220 | { | |
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) ; | |
227 | ||
228 | SelectObject( (HDC) dc, penLight) ; | |
229 | ||
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) ; | |
233 | } | |
234 | SelectObject((HDC) dc,oldp) ; | |
235 | SelectObject((HDC) dc,oldb) ; | |
236 | ||
237 | DeleteObject(penBorder); | |
238 | DeleteObject(penLight); | |
239 | DeleteObject(penShadow); | |
240 | DeleteObject(brushFace); | |
241 | */ | |
242 | } | |
243 | ||
244 | #define FOCUS_MARGIN 6 | |
245 | ||
246 | void wxBitmapButton::DrawButtonFocus( WXHDC dc, int left, int top, int right, int bottom, bool sel ) | |
247 | { | |
248 | // TODO: | |
249 | /* | |
250 | RECT rect; | |
251 | rect.left = left; | |
252 | rect.top = top; | |
253 | rect.right = right; | |
254 | rect.bottom = bottom; | |
255 | InflateRect( &rect, - FOCUS_MARGIN, - FOCUS_MARGIN ) ; | |
256 | if ( sel ) | |
257 | OffsetRect( &rect, 1, 1 ) ; | |
258 | DrawFocusRect( (HDC) dc, &rect ) ; | |
259 | */ | |
260 | } | |
261 | ||
262 | // extern HBRUSH wxDisableButtonBrush; | |
263 | ||
264 | void wxBitmapButton::DrawButtonDisable( WXHDC dc, int left, int top, int right, int bottom, bool with_marg ) | |
265 | { | |
266 | // TODO: | |
267 | /* | |
268 | HBRUSH old = (HBRUSH) SelectObject( (HDC) dc, wxDisableButtonBrush ) ; | |
269 | ||
270 | if ( with_marg ) | |
271 | ::PatBlt( (HDC) dc, left + m_marginX, top + m_marginY, | |
272 | right - 2 * m_marginX, bottom - 2 * m_marginY, | |
273 | #ifdef __SALFORDC__ | |
274 | 0xfa0089L ) ; | |
275 | #else | |
276 | 0xfa0089UL ) ; | |
277 | #endif | |
278 | else ::PatBlt( (HDC) dc, left, top, right, bottom, | |
279 | #ifdef __SALFORDC__ | |
280 | 0xfa0089L ) ; | |
281 | #else | |
282 | 0xfa0089UL ) ; | |
283 | #endif | |
284 | ::SelectObject( (HDC) dc, old ) ; | |
285 | */ | |
286 | } | |
287 | ||
288 | void wxBitmapButton::SetDefault() | |
289 | { | |
290 | wxButton::SetDefault(); | |
291 | } |