blob: d4fac467e5bd4608b6a9b57f3d9ac95edccb2ea8 [file] [log] [blame]
Alexandre Julliard0e607781993-11-03 19:23:37 +00001/* File: button.c -- Button type widgets
Alexandre Julliardf41aeca1993-09-14 16:47:10 +00002 *
Alexandre Julliard0e607781993-11-03 19:23:37 +00003 * Copyright (C) 1993 Johannes Ruscheinski
4 * Copyright (C) 1993 David Metcalfe
Alexandre Julliardaca05781994-10-17 18:12:41 +00005 * Copyright (C) 1994 Alexandre Julliard
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00006 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Alexandre Julliard2787be81995-05-22 18:23:01 +000020 */
Alexandre Julliard0e607781993-11-03 19:23:37 +000021
Jeff Garzikc3e1f721999-02-19 15:42:11 +000022#include <string.h>
Alexandre Julliardde424282001-08-10 22:51:42 +000023#include <stdlib.h>
24
Patrik Stridvall6cc47d42000-03-08 18:26:56 +000025#include "winbase.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000026#include "windef.h"
27#include "wingdi.h"
Michael Vekslerca1bc861999-01-01 18:57:33 +000028#include "wine/winuser16.h"
Alexandre Julliard91222da2000-12-10 23:01:33 +000029#include "controls.h"
Alexandre Julliarda41b2cf2001-01-15 20:12:55 +000030#include "user.h"
Alexandre Julliard940d58c1994-09-16 09:24:37 +000031
Alexandre Julliardde424282001-08-10 22:51:42 +000032/* GetWindowLong offsets for window extra information */
33#define STATE_GWL_OFFSET 0
34#define HFONT_GWL_OFFSET (sizeof(LONG))
35#define HIMAGE_GWL_OFFSET (2*sizeof(LONG))
36#define NB_EXTRA_BYTES (3*sizeof(LONG))
Alexandre Julliard91222da2000-12-10 23:01:33 +000037
38 /* Button state values */
39#define BUTTON_UNCHECKED 0x00
40#define BUTTON_CHECKED 0x01
41#define BUTTON_3STATE 0x02
42#define BUTTON_HIGHLIGHTED 0x04
43#define BUTTON_HASFOCUS 0x08
44#define BUTTON_NSTATES 0x0F
45 /* undocumented flags */
46#define BUTTON_BTNPRESSED 0x40
47#define BUTTON_UNKNOWN2 0x20
48#define BUTTON_UNKNOWN3 0x10
49
Dmitry Timoshkova081e232002-05-20 18:21:29 +000050static UINT BUTTON_CalcLabelRect( HWND hwnd, HDC hdc, RECT *rc );
Alexandre Julliardde424282001-08-10 22:51:42 +000051static void PB_Paint( HWND hwnd, HDC hDC, UINT action );
52static void CB_Paint( HWND hwnd, HDC hDC, UINT action );
53static void GB_Paint( HWND hwnd, HDC hDC, UINT action );
54static void UB_Paint( HWND hwnd, HDC hDC, UINT action );
55static void OB_Paint( HWND hwnd, HDC hDC, UINT action );
56static void BUTTON_CheckAutoRadioButton( HWND hwnd );
Alexandre Julliard91222da2000-12-10 23:01:33 +000057static LRESULT WINAPI ButtonWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
58static LRESULT WINAPI ButtonWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
Alexandre Julliardf0b23541993-09-29 12:21:49 +000059
Alexandre Julliarde399fc31993-11-24 17:08:56 +000060#define MAX_BTN_TYPE 12
Alexandre Julliardf0b23541993-09-29 12:21:49 +000061
Alexandre Julliardd90840e1996-06-11 16:02:08 +000062static const WORD maxCheckState[MAX_BTN_TYPE] =
Alexandre Julliardf0b23541993-09-29 12:21:49 +000063{
Alexandre Julliardaca05781994-10-17 18:12:41 +000064 BUTTON_UNCHECKED, /* BS_PUSHBUTTON */
65 BUTTON_UNCHECKED, /* BS_DEFPUSHBUTTON */
66 BUTTON_CHECKED, /* BS_CHECKBOX */
67 BUTTON_CHECKED, /* BS_AUTOCHECKBOX */
68 BUTTON_CHECKED, /* BS_RADIOBUTTON */
69 BUTTON_3STATE, /* BS_3STATE */
70 BUTTON_3STATE, /* BS_AUTO3STATE */
71 BUTTON_UNCHECKED, /* BS_GROUPBOX */
72 BUTTON_UNCHECKED, /* BS_USERBUTTON */
73 BUTTON_CHECKED, /* BS_AUTORADIOBUTTON */
74 BUTTON_UNCHECKED, /* Not defined */
75 BUTTON_UNCHECKED /* BS_OWNERDRAW */
Alexandre Julliardf0b23541993-09-29 12:21:49 +000076};
77
Alexandre Julliardde424282001-08-10 22:51:42 +000078typedef void (*pfPaint)( HWND hwnd, HDC hdc, UINT action );
Alexandre Julliardaca05781994-10-17 18:12:41 +000079
Alexandre Julliardd90840e1996-06-11 16:02:08 +000080static const pfPaint btnPaintFunc[MAX_BTN_TYPE] =
Alexandre Julliardaca05781994-10-17 18:12:41 +000081{
82 PB_Paint, /* BS_PUSHBUTTON */
83 PB_Paint, /* BS_DEFPUSHBUTTON */
84 CB_Paint, /* BS_CHECKBOX */
85 CB_Paint, /* BS_AUTOCHECKBOX */
86 CB_Paint, /* BS_RADIOBUTTON */
87 CB_Paint, /* BS_3STATE */
88 CB_Paint, /* BS_AUTO3STATE */
89 GB_Paint, /* BS_GROUPBOX */
90 UB_Paint, /* BS_USERBUTTON */
91 CB_Paint, /* BS_AUTORADIOBUTTON */
92 NULL, /* Not defined */
93 OB_Paint /* BS_OWNERDRAW */
94};
95
Alexandre Julliarda3960291999-02-26 11:11:13 +000096static HBITMAP hbitmapCheckBoxes = 0;
Alexandre Julliard940d58c1994-09-16 09:24:37 +000097static WORD checkBoxWidth = 0, checkBoxHeight = 0;
98
Alexandre Julliardf0b23541993-09-29 12:21:49 +000099
Alexandre Julliard91222da2000-12-10 23:01:33 +0000100/*********************************************************************
101 * button class descriptor
102 */
103const struct builtin_class_descr BUTTON_builtin_class =
104{
105 "Button", /* name */
106 CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
107 ButtonWndProcA, /* procA */
108 ButtonWndProcW, /* procW */
Alexandre Julliardde424282001-08-10 22:51:42 +0000109 NB_EXTRA_BYTES, /* extra */
Alexandre Julliard91222da2000-12-10 23:01:33 +0000110 IDC_ARROWA, /* cursor */
111 0 /* brush */
112};
113
114
Alexandre Julliardde424282001-08-10 22:51:42 +0000115inline static LONG get_button_state( HWND hwnd )
116{
117 return GetWindowLongA( hwnd, STATE_GWL_OFFSET );
118}
119
120inline static void set_button_state( HWND hwnd, LONG state )
121{
122 SetWindowLongA( hwnd, STATE_GWL_OFFSET, state );
123}
124
125inline static HFONT get_button_font( HWND hwnd )
126{
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000127 return (HFONT)GetWindowLongA( hwnd, HFONT_GWL_OFFSET );
Alexandre Julliardde424282001-08-10 22:51:42 +0000128}
129
130inline static void set_button_font( HWND hwnd, HFONT font )
131{
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000132 SetWindowLongA( hwnd, HFONT_GWL_OFFSET, (LONG)font );
Alexandre Julliardde424282001-08-10 22:51:42 +0000133}
134
135inline static UINT get_button_type( LONG window_style )
136{
137 return (window_style & 0x0f);
138}
139
140/* paint a button of any type */
141inline static void paint_button( HWND hwnd, LONG style, UINT action )
142{
143 if (btnPaintFunc[style] && IsWindowVisible(hwnd))
144 {
145 HDC hdc = GetDC( hwnd );
146 btnPaintFunc[style]( hwnd, hdc, action );
147 ReleaseDC( hwnd, hdc );
148 }
149}
150
151/* retrieve the button text; returned buffer must be freed by caller */
152inline static WCHAR *get_button_text( HWND hwnd )
153{
154 INT len = GetWindowTextLengthW( hwnd );
155 WCHAR *buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) );
156 if (buffer) GetWindowTextW( hwnd, buffer, len + 1 );
157 return buffer;
158}
159
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000160/***********************************************************************
Alexandre Julliardde424282001-08-10 22:51:42 +0000161 * ButtonWndProc_common
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000162 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000163static LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg,
164 WPARAM wParam, LPARAM lParam, BOOL unicode )
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000165{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000166 RECT rect;
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +0000167 POINT pt;
Alexandre Julliardde424282001-08-10 22:51:42 +0000168 LONG style = GetWindowLongA( hWnd, GWL_STYLE );
169 UINT btn_type = get_button_type( style );
170 LONG state;
Pascal Lessard026f7051999-04-15 15:49:36 +0000171 HANDLE oldHbitmap;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000172
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +0000173 pt.x = LOWORD(lParam);
174 pt.y = HIWORD(lParam);
175
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000176 switch (uMsg)
177 {
178 case WM_GETDLGCODE:
Alexandre Julliardde424282001-08-10 22:51:42 +0000179 switch(btn_type)
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000180 {
181 case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
182 case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
183 case BS_RADIOBUTTON:
184 case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
185 default: return DLGC_BUTTON;
186 }
Alexandre Julliardaca05781994-10-17 18:12:41 +0000187
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000188 case WM_ENABLE:
Alexandre Julliardde424282001-08-10 22:51:42 +0000189 paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000190 break;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000191
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000192 case WM_CREATE:
193 if (!hbitmapCheckBoxes)
194 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000195 BITMAP bmp;
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000196 hbitmapCheckBoxes = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CHECKBOXES));
197 GetObjectW( hbitmapCheckBoxes, sizeof(bmp), &bmp );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000198 checkBoxWidth = bmp.bmWidth / 4;
199 checkBoxHeight = bmp.bmHeight / 3;
200 }
Vincent Bérone35580f2002-06-21 22:25:17 +0000201 if (btn_type >= MAX_BTN_TYPE)
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000202 return -1; /* abort */
Alexandre Julliardde424282001-08-10 22:51:42 +0000203 set_button_state( hWnd, BUTTON_UNCHECKED );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000204 return 0;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000205
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000206 case WM_ERASEBKGND:
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000207 return 1;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000208
209 case WM_PAINT:
Alexandre Julliardde424282001-08-10 22:51:42 +0000210 if (btnPaintFunc[btn_type])
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000211 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000212 PAINTSTRUCT ps;
213 HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
Sheri Steeves13ffd582000-06-11 20:08:46 +0000214 int nOldMode = SetBkMode( hdc, OPAQUE );
Alexandre Julliardde424282001-08-10 22:51:42 +0000215 (btnPaintFunc[btn_type])( hWnd, hdc, ODA_DRAWENTIRE );
Sheri Steeves13ffd582000-06-11 20:08:46 +0000216 SetBkMode(hdc, nOldMode); /* reset painting mode */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000217 if( !wParam ) EndPaint( hWnd, &ps );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000218 }
219 break;
220
Dmitry Timoshkovf92a7771999-12-05 23:51:15 +0000221 case WM_KEYDOWN:
222 if (wParam == VK_SPACE)
223 {
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000224 SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
Alexandre Julliardde424282001-08-10 22:51:42 +0000225 set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
Dmitry Timoshkovf92a7771999-12-05 23:51:15 +0000226 }
227 break;
Vincent Béron9a624912002-05-31 23:06:46 +0000228
Eric Kohl65ab1b01998-11-22 17:53:27 +0000229 case WM_LBUTTONDBLCLK:
Alexandre Julliardde424282001-08-10 22:51:42 +0000230 if(style & BS_NOTIFY ||
231 btn_type == BS_RADIOBUTTON ||
232 btn_type == BS_USERBUTTON ||
233 btn_type == BS_OWNERDRAW)
234 {
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000235 SendMessageW( GetParent(hWnd), WM_COMMAND,
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000236 MAKEWPARAM( GetWindowLongA(hWnd,GWL_ID), BN_DOUBLECLICKED ),
237 (LPARAM)hWnd);
Rein Klazes61b15de1999-09-27 11:38:47 +0000238 break;
239 }
240 /* fall through */
Rein Klazesdbb4ad81999-07-31 11:10:52 +0000241 case WM_LBUTTONDOWN:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000242 SetCapture( hWnd );
Luc Tourangeau70cd8cb1999-07-10 11:57:29 +0000243 SetFocus( hWnd );
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000244 SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
Alexandre Julliardde424282001-08-10 22:51:42 +0000245 set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000246 break;
247
Dmitry Timoshkovf92a7771999-12-05 23:51:15 +0000248 case WM_KEYUP:
249 if (wParam != VK_SPACE)
250 break;
251 /* fall through */
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000252 case WM_LBUTTONUP:
Alexandre Julliardde424282001-08-10 22:51:42 +0000253 state = get_button_state( hWnd );
254 if (!(state & BUTTON_BTNPRESSED)) break;
255 state &= BUTTON_NSTATES;
256 set_button_state( hWnd, state );
257 if (!(state & BUTTON_HIGHLIGHTED))
258 {
Rein Klazes61b15de1999-09-27 11:38:47 +0000259 ReleaseCapture();
260 break;
261 }
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000262 SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
Rein Klazes61b15de1999-09-27 11:38:47 +0000263 ReleaseCapture();
Alexandre Julliarda3960291999-02-26 11:11:13 +0000264 GetClientRect( hWnd, &rect );
Dmitry Timoshkovf92a7771999-12-05 23:51:15 +0000265 if (uMsg == WM_KEYUP || PtInRect( &rect, pt ))
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000266 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000267 state = get_button_state( hWnd );
268 switch(btn_type)
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000269 {
270 case BS_AUTOCHECKBOX:
Alexandre Julliardde424282001-08-10 22:51:42 +0000271 SendMessageW( hWnd, BM_SETCHECK, !(state & BUTTON_CHECKED), 0 );
Alexandre Julliardaca05781994-10-17 18:12:41 +0000272 break;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000273 case BS_AUTORADIOBUTTON:
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000274 SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 );
Alexandre Julliardaca05781994-10-17 18:12:41 +0000275 break;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000276 case BS_AUTO3STATE:
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000277 SendMessageW( hWnd, BM_SETCHECK,
Alexandre Julliardde424282001-08-10 22:51:42 +0000278 (state & BUTTON_3STATE) ? 0 : ((state & 3) + 1), 0 );
Alexandre Julliardecc37121994-11-22 16:31:29 +0000279 break;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000280 }
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000281 SendMessageW( GetParent(hWnd), WM_COMMAND,
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000282 MAKEWPARAM( GetWindowLongA(hWnd,GWL_ID), BN_CLICKED ), (LPARAM)hWnd);
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000283 }
284 break;
Alexandre Julliardecc37121994-11-22 16:31:29 +0000285
Rein Klazes61b15de1999-09-27 11:38:47 +0000286 case WM_CAPTURECHANGED:
Alexandre Julliardde424282001-08-10 22:51:42 +0000287 state = get_button_state( hWnd );
288 if (state & BUTTON_BTNPRESSED)
289 {
290 state &= BUTTON_NSTATES;
291 set_button_state( hWnd, state );
292 if (state & BUTTON_HIGHLIGHTED) SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
Rein Klazes61b15de1999-09-27 11:38:47 +0000293 }
294 break;
295
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000296 case WM_MOUSEMOVE:
Rein Klazes0e4cf6c2002-01-15 20:27:30 +0000297 if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000298 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000299 GetClientRect( hWnd, &rect );
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000300 SendMessageW( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000301 }
302 break;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000303
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000304 case WM_SETTEXT:
Dmitry Timoshkova081e232002-05-20 18:21:29 +0000305 {
306 /* Clear an old text here as Windows does */
307 HDC hdc = GetDC(hWnd);
308 HBRUSH hbrush;
309 RECT client, rc;
310
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000311 hbrush = (HBRUSH)SendMessageW(GetParent(hWnd), WM_CTLCOLORSTATIC,
312 (WPARAM)hdc, (LPARAM)hWnd);
Dmitry Timoshkova081e232002-05-20 18:21:29 +0000313 if (!hbrush) /* did the app forget to call DefWindowProc ? */
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000314 hbrush = (HBRUSH)DefWindowProcW(GetParent(hWnd), WM_CTLCOLORSTATIC,
315 (WPARAM)hdc, (LPARAM)hWnd);
Dmitry Timoshkova081e232002-05-20 18:21:29 +0000316
317 GetClientRect(hWnd, &client);
318 rc = client;
319 BUTTON_CalcLabelRect(hWnd, hdc, &rc);
320 /* Clip by client rect bounds */
321 if (rc.right > client.right) rc.right = client.right;
322 if (rc.bottom > client.bottom) rc.bottom = client.bottom;
323 FillRect(hdc, &rc, hbrush);
324 ReleaseDC(hWnd, hdc);
325
Alexandre Julliardde424282001-08-10 22:51:42 +0000326 if (unicode) DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam );
327 else DefWindowProcA( hWnd, WM_SETTEXT, wParam, lParam );
Dmitry Timoshkova081e232002-05-20 18:21:29 +0000328 if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */
329 InvalidateRect( hWnd, NULL, TRUE );
330 else
331 paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000332 return 1; /* success. FIXME: check text length */
Dmitry Timoshkova081e232002-05-20 18:21:29 +0000333 }
Alexandre Julliardaca05781994-10-17 18:12:41 +0000334
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000335 case WM_SETFONT:
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000336 set_button_font( hWnd, (HFONT)wParam );
Alexandre Julliardde424282001-08-10 22:51:42 +0000337 if (lParam) paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000338 break;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000339
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000340 case WM_GETFONT:
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000341 return (LRESULT)get_button_font( hWnd );
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000342
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000343 case WM_SETFOCUS:
Alexandre Julliardde424282001-08-10 22:51:42 +0000344 if ((btn_type == BS_RADIOBUTTON || btn_type == BS_AUTORADIOBUTTON) && (GetCapture() != hWnd) &&
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000345 !(SendMessageW(hWnd, BM_GETCHECK, 0, 0) & BST_CHECKED))
Luc Tourangeau70cd8cb1999-07-10 11:57:29 +0000346 {
Vincent Béron9a624912002-05-31 23:06:46 +0000347 /* The notification is sent when the button (BS_AUTORADIOBUTTON)
Andreas Mohr20cd9352000-09-12 23:40:40 +0000348 is unchecked and the focus was not given by a mouse click. */
Alexandre Julliardde424282001-08-10 22:51:42 +0000349 if (btn_type == BS_AUTORADIOBUTTON)
350 SendMessageW( hWnd, BM_SETCHECK, BUTTON_CHECKED, 0 );
351 SendMessageW( GetParent(hWnd), WM_COMMAND,
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000352 MAKEWPARAM( GetWindowLongA(hWnd,GWL_ID), BN_CLICKED ), (LPARAM)hWnd);
Luc Tourangeau70cd8cb1999-07-10 11:57:29 +0000353 }
Alexandre Julliardde424282001-08-10 22:51:42 +0000354 set_button_state( hWnd, get_button_state(hWnd) | BUTTON_HASFOCUS );
355 paint_button( hWnd, btn_type, ODA_FOCUS );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000356 break;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000357
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000358 case WM_KILLFOCUS:
Alexandre Julliardde424282001-08-10 22:51:42 +0000359 set_button_state( hWnd, get_button_state(hWnd) & ~BUTTON_HASFOCUS );
360 paint_button( hWnd, btn_type, ODA_FOCUS );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000361 InvalidateRect( hWnd, NULL, TRUE );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000362 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000363
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000364 case WM_SYSCOLORCHANGE:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000365 InvalidateRect( hWnd, NULL, FALSE );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000366 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000367
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000368 case BM_SETSTYLE16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000369 case BM_SETSTYLE:
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000370 if ((wParam & 0x0f) >= MAX_BTN_TYPE) break;
Alexandre Julliardde424282001-08-10 22:51:42 +0000371 btn_type = wParam & 0x0f;
372 style = (style & ~0x0f) | btn_type;
373 SetWindowLongA( hWnd, GWL_STYLE, style );
Sheri Steeves13ffd582000-06-11 20:08:46 +0000374
375 /* Only redraw if lParam flag is set.*/
376 if (lParam)
Alexandre Julliardde424282001-08-10 22:51:42 +0000377 paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
Sheri Steeves13ffd582000-06-11 20:08:46 +0000378
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000379 break;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000380
Dmitry Timoshkov6fb62f52000-01-29 22:09:40 +0000381 case BM_CLICK:
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000382 SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 );
383 SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 );
Dmitry Timoshkov6fb62f52000-01-29 22:09:40 +0000384 break;
385
Pascal Lessard026f7051999-04-15 15:49:36 +0000386 case BM_SETIMAGE:
Alexandre Julliardde424282001-08-10 22:51:42 +0000387 /* Check that image format matches button style */
388 switch (style & (BS_BITMAP|BS_ICON))
389 {
390 case BS_BITMAP:
391 if (wParam != IMAGE_BITMAP) return 0;
392 break;
393 case BS_ICON:
394 if (wParam != IMAGE_ICON) return 0;
395 break;
396 default:
397 return 0;
398 }
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000399 oldHbitmap = (HBITMAP)SetWindowLongA( hWnd, HIMAGE_GWL_OFFSET, lParam );
Serge Ivanov6117fc42000-09-13 00:00:55 +0000400 InvalidateRect( hWnd, NULL, FALSE );
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000401 return (LRESULT)oldHbitmap;
Pascal Lessard026f7051999-04-15 15:49:36 +0000402
403 case BM_GETIMAGE:
Alexandre Julliardde424282001-08-10 22:51:42 +0000404 return GetWindowLongA( hWnd, HIMAGE_GWL_OFFSET );
Pascal Lessard026f7051999-04-15 15:49:36 +0000405
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000406 case BM_GETCHECK16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000407 case BM_GETCHECK:
Alexandre Julliardde424282001-08-10 22:51:42 +0000408 return get_button_state( hWnd ) & 3;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000409
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000410 case BM_SETCHECK16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000411 case BM_SETCHECK:
Alexandre Julliardde424282001-08-10 22:51:42 +0000412 if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type];
413 state = get_button_state( hWnd );
Bill Medlandb1537252001-12-11 00:16:23 +0000414 if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON))
415 {
416 if (wParam) style |= WS_TABSTOP;
417 else style &= ~WS_TABSTOP;
418 SetWindowLongA( hWnd, GWL_STYLE, style );
419 }
Alexandre Julliardde424282001-08-10 22:51:42 +0000420 if ((state & 3) != wParam)
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000421 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000422 set_button_state( hWnd, (state & ~3) | wParam );
423 paint_button( hWnd, btn_type, ODA_SELECT );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000424 }
Alexandre Julliardde424282001-08-10 22:51:42 +0000425 if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED) && (style & WS_CHILD))
426 BUTTON_CheckAutoRadioButton( hWnd );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000427 break;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000428
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000429 case BM_GETSTATE16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000430 case BM_GETSTATE:
Alexandre Julliardde424282001-08-10 22:51:42 +0000431 return get_button_state( hWnd );
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000432
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000433 case BM_SETSTATE16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000434 case BM_SETSTATE:
Alexandre Julliardde424282001-08-10 22:51:42 +0000435 state = get_button_state( hWnd );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000436 if (wParam)
437 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000438 if (state & BUTTON_HIGHLIGHTED) break;
439 set_button_state( hWnd, state | BUTTON_HIGHLIGHTED );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000440 }
441 else
442 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000443 if (!(state & BUTTON_HIGHLIGHTED)) break;
444 set_button_state( hWnd, state & ~BUTTON_HIGHLIGHTED );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000445 }
Alexandre Julliardde424282001-08-10 22:51:42 +0000446 paint_button( hWnd, btn_type, ODA_SELECT );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000447 break;
448
Alexandre Julliard98779062000-12-07 23:39:16 +0000449 case WM_NCHITTEST:
Alexandre Julliardde424282001-08-10 22:51:42 +0000450 if(btn_type == BS_GROUPBOX) return HTTRANSPARENT;
Alexandre Julliard98779062000-12-07 23:39:16 +0000451 /* fall through */
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000452 default:
Alexandre Julliard98779062000-12-07 23:39:16 +0000453 return unicode ? DefWindowProcW(hWnd, uMsg, wParam, lParam) :
454 DefWindowProcA(hWnd, uMsg, wParam, lParam);
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000455 }
456 return 0;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000457}
458
Marcus Meissner9aded511999-05-01 10:23:45 +0000459/***********************************************************************
Alexandre Julliard98779062000-12-07 23:39:16 +0000460 * ButtonWndProcW
Marcus Meissner9aded511999-05-01 10:23:45 +0000461 * The button window procedure. This is just a wrapper which locks
462 * the passed HWND and calls the real window procedure (with a WND*
463 * pointer pointing to the locked windowstructure).
464 */
Alexandre Julliard91222da2000-12-10 23:01:33 +0000465static LRESULT WINAPI ButtonWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
Marcus Meissner9aded511999-05-01 10:23:45 +0000466{
Alexandre Julliardde424282001-08-10 22:51:42 +0000467 if (!IsWindow( hWnd )) return 0;
468 return ButtonWndProc_common( hWnd, uMsg, wParam, lParam, TRUE );
Marcus Meissner9aded511999-05-01 10:23:45 +0000469}
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000470
Alexandre Julliard98779062000-12-07 23:39:16 +0000471
472/***********************************************************************
473 * ButtonWndProcA
474 */
Alexandre Julliard91222da2000-12-10 23:01:33 +0000475static LRESULT WINAPI ButtonWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
Alexandre Julliard98779062000-12-07 23:39:16 +0000476{
Alexandre Julliardde424282001-08-10 22:51:42 +0000477 if (!IsWindow( hWnd )) return 0;
478 return ButtonWndProc_common( hWnd, uMsg, wParam, lParam, FALSE );
Alexandre Julliard98779062000-12-07 23:39:16 +0000479}
480
481
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000482/**********************************************************************
Serge Ivanov6117fc42000-09-13 00:00:55 +0000483 * Convert button styles to flags used by DrawText.
484 * TODO: handle WS_EX_RIGHT extended style.
485 */
486static UINT BUTTON_BStoDT(DWORD style)
487{
488 UINT dtStyle = DT_NOCLIP; /* We use SelectClipRgn to limit output */
489
490 /* "Convert" pushlike buttons to pushbuttons */
491 if (style & BS_PUSHLIKE)
492 style &= ~0x0F;
493
494 if (!(style & BS_MULTILINE))
495 dtStyle |= DT_SINGLELINE;
496 else
497 dtStyle |= DT_WORDBREAK;
498
499 switch (style & BS_CENTER)
500 {
501 case BS_LEFT: /* DT_LEFT is 0 */ break;
502 case BS_RIGHT: dtStyle |= DT_RIGHT; break;
503 case BS_CENTER: dtStyle |= DT_CENTER; break;
504 default:
505 /* Pushbutton's text is centered by default */
Alexandre Julliardde424282001-08-10 22:51:42 +0000506 if (get_button_type(style) <= BS_DEFPUSHBUTTON) dtStyle |= DT_CENTER;
Serge Ivanov6117fc42000-09-13 00:00:55 +0000507 /* all other flavours have left aligned text */
508 }
509
510 /* DrawText ignores vertical alignment for multiline text,
511 * but we use these flags to align label manualy.
512 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000513 if (get_button_type(style) != BS_GROUPBOX)
Serge Ivanov6117fc42000-09-13 00:00:55 +0000514 {
515 switch (style & BS_VCENTER)
516 {
517 case BS_TOP: /* DT_TOP is 0 */ break;
518 case BS_BOTTOM: dtStyle |= DT_BOTTOM; break;
519 case BS_VCENTER: /* fall through */
520 default: dtStyle |= DT_VCENTER; break;
521 }
522 }
523 else
524 /* GroupBox's text is always single line and is top aligned. */
525 dtStyle |= DT_SINGLELINE;
526
527 return dtStyle;
528}
529
530/**********************************************************************
531 * BUTTON_CalcLabelRect
532 *
533 * Calculates label's rectangle depending on button style.
534 *
535 * Returns flags to be passed to DrawText.
536 * Calculated rectangle doesn't take into account button state
537 * (pushed, etc.). If there is nothing to draw (no text/image) output
538 * rectangle is empty, and return value is (UINT)-1.
539 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000540static UINT BUTTON_CalcLabelRect(HWND hwnd, HDC hdc, RECT *rc)
Serge Ivanov6117fc42000-09-13 00:00:55 +0000541{
Alexandre Julliardde424282001-08-10 22:51:42 +0000542 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
543 WCHAR *text;
Serge Ivanov6117fc42000-09-13 00:00:55 +0000544 ICONINFO iconInfo;
545 BITMAP bm;
Alexandre Julliardde424282001-08-10 22:51:42 +0000546 UINT dtStyle = BUTTON_BStoDT(style);
Serge Ivanov6117fc42000-09-13 00:00:55 +0000547 RECT r = *rc;
548 INT n;
549
550 /* Calculate label rectangle according to label type */
Alexandre Julliardde424282001-08-10 22:51:42 +0000551 switch (style & (BS_ICON|BS_BITMAP))
Serge Ivanov6117fc42000-09-13 00:00:55 +0000552 {
553 case BS_TEXT:
Alexandre Julliardde424282001-08-10 22:51:42 +0000554 if (!(text = get_button_text( hwnd ))) goto empty_rect;
555 if (!text[0])
556 {
557 HeapFree( GetProcessHeap(), 0, text );
558 goto empty_rect;
559 }
560 DrawTextW(hdc, text, -1, &r, dtStyle | DT_CALCRECT);
561 HeapFree( GetProcessHeap(), 0, text );
562 break;
Serge Ivanov6117fc42000-09-13 00:00:55 +0000563
564 case BS_ICON:
Alexandre Julliardde424282001-08-10 22:51:42 +0000565 if (!GetIconInfo((HICON)GetWindowLongA( hwnd, HIMAGE_GWL_OFFSET ), &iconInfo))
Serge Ivanov6117fc42000-09-13 00:00:55 +0000566 goto empty_rect;
567
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000568 GetObjectW (iconInfo.hbmColor, sizeof(BITMAP), &bm);
Serge Ivanov6117fc42000-09-13 00:00:55 +0000569
570 r.right = r.left + bm.bmWidth;
571 r.bottom = r.top + bm.bmHeight;
572
573 DeleteObject(iconInfo.hbmColor);
574 DeleteObject(iconInfo.hbmMask);
575 break;
576
577 case BS_BITMAP:
Alexandre Julliardde424282001-08-10 22:51:42 +0000578 if (!GetObjectW( (HANDLE)GetWindowLongA( hwnd, HIMAGE_GWL_OFFSET ), sizeof(BITMAP), &bm))
Serge Ivanov6117fc42000-09-13 00:00:55 +0000579 goto empty_rect;
580
581 r.right = r.left + bm.bmWidth;
582 r.bottom = r.top + bm.bmHeight;
583 break;
584
585 default:
Vincent Béron9a624912002-05-31 23:06:46 +0000586 empty_rect:
Serge Ivanov6117fc42000-09-13 00:00:55 +0000587 r.right = r.left;
588 r.bottom = r.top;
589 return (UINT)(LONG)-1;
590 }
591
592 /* Position label inside bounding rectangle according to
593 * alignment flags. (calculated rect is always left-top aligned).
594 * If label is aligned to any side - shift label in opposite
595 * direction to leave extra space for focus rectangle.
596 */
597 switch (dtStyle & (DT_CENTER|DT_RIGHT))
598 {
599 case DT_LEFT: r.left++; r.right++; break;
600 case DT_CENTER: n = r.right - r.left;
601 r.left = rc->left + ((rc->right - rc->left) - n) / 2;
602 r.right = r.left + n; break;
603 case DT_RIGHT: n = r.right - r.left;
604 r.right = rc->right - 1;
605 r.left = r.right - n;
606 break;
607 }
608
609 switch (dtStyle & (DT_VCENTER|DT_BOTTOM))
610 {
611 case DT_TOP: r.top++; r.bottom++; break;
612 case DT_VCENTER: n = r.bottom - r.top;
613 r.top = rc->top + ((rc->bottom - rc->top) - n) / 2;
614 r.bottom = r.top + n; break;
615 case DT_BOTTOM: n = r.bottom - r.top;
616 r.bottom = rc->bottom - 1;
617 r.top = r.bottom - n;
618 break;
619 }
620
621 *rc = r;
622 return dtStyle;
623}
624
625
626/**********************************************************************
627 * BUTTON_DrawTextCallback
628 *
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000629 * Callback function used by DrawStateW function.
Serge Ivanov6117fc42000-09-13 00:00:55 +0000630 */
631static BOOL CALLBACK BUTTON_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy)
632{
Joerg Mayerabe635c2000-11-11 00:38:37 +0000633 RECT rc;
634 rc.left = 0;
635 rc.top = 0;
636 rc.right = cx;
637 rc.bottom = cy;
Serge Ivanov6117fc42000-09-13 00:00:55 +0000638
639 DrawTextW(hdc, (LPCWSTR)lp, -1, &rc, (UINT)wp);
640 return TRUE;
641}
642
643
644/**********************************************************************
645 * BUTTON_DrawLabel
646 *
647 * Common function for drawing button label.
648 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000649static void BUTTON_DrawLabel(HWND hwnd, HDC hdc, UINT dtFlags, RECT *rc)
Serge Ivanov6117fc42000-09-13 00:00:55 +0000650{
Serge Ivanov6117fc42000-09-13 00:00:55 +0000651 DRAWSTATEPROC lpOutputProc = NULL;
652 LPARAM lp;
653 WPARAM wp = 0;
654 HBRUSH hbr = 0;
Alexandre Julliardde424282001-08-10 22:51:42 +0000655 UINT flags = IsWindowEnabled(hwnd) ? DSS_NORMAL : DSS_DISABLED;
656 LONG state = get_button_state( hwnd );
657 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
658 WCHAR *text = NULL;
Serge Ivanov6117fc42000-09-13 00:00:55 +0000659
Dimitrie O. Paun693cca52002-01-29 03:12:19 +0000660 /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
Serge Ivanov6117fc42000-09-13 00:00:55 +0000661 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
662 * I don't have Win31 on hand to verify that, so I leave it as is.
663 */
664
Alexandre Julliardde424282001-08-10 22:51:42 +0000665 if ((style & BS_PUSHLIKE) && (state & BUTTON_3STATE))
Serge Ivanov6117fc42000-09-13 00:00:55 +0000666 {
667 hbr = GetSysColorBrush(COLOR_GRAYTEXT);
668 flags |= DSS_MONO;
669 }
670
Alexandre Julliardde424282001-08-10 22:51:42 +0000671 switch (style & (BS_ICON|BS_BITMAP))
Serge Ivanov6117fc42000-09-13 00:00:55 +0000672 {
673 case BS_TEXT:
674 /* DST_COMPLEX -- is 0 */
675 lpOutputProc = BUTTON_DrawTextCallback;
Alexandre Julliardde424282001-08-10 22:51:42 +0000676 if (!(text = get_button_text( hwnd ))) return;
677 lp = (LPARAM)text;
Serge Ivanov6117fc42000-09-13 00:00:55 +0000678 wp = (WPARAM)dtFlags;
679 break;
680
681 case BS_ICON:
682 flags |= DST_ICON;
Alexandre Julliardde424282001-08-10 22:51:42 +0000683 lp = GetWindowLongA( hwnd, HIMAGE_GWL_OFFSET );
Serge Ivanov6117fc42000-09-13 00:00:55 +0000684 break;
685
686 case BS_BITMAP:
687 flags |= DST_BITMAP;
Alexandre Julliardde424282001-08-10 22:51:42 +0000688 lp = GetWindowLongA( hwnd, HIMAGE_GWL_OFFSET );
Serge Ivanov6117fc42000-09-13 00:00:55 +0000689 break;
690
691 default:
692 return;
693 }
694
695 DrawStateW(hdc, hbr, lpOutputProc, lp, wp, rc->left, rc->top,
696 rc->right - rc->left, rc->bottom - rc->top, flags);
Alexandre Julliardde424282001-08-10 22:51:42 +0000697 if (text) HeapFree( GetProcessHeap(), 0, text );
Serge Ivanov6117fc42000-09-13 00:00:55 +0000698}
699
700/**********************************************************************
Alexandre Julliardde424282001-08-10 22:51:42 +0000701 * Push Button Functions
Francis Beaudet9b4748b1999-07-18 15:29:43 +0000702 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000703static void PB_Paint( HWND hwnd, HDC hDC, UINT action )
Francis Beaudet9b4748b1999-07-18 15:29:43 +0000704{
Serge Ivanov6117fc42000-09-13 00:00:55 +0000705 RECT rc, focus_rect, r;
706 UINT dtFlags;
707 HRGN hRgn;
708 HPEN hOldPen;
709 HBRUSH hOldBrush;
710 INT oldBkMode;
711 COLORREF oldTxtColor;
Alexandre Julliardde424282001-08-10 22:51:42 +0000712 HFONT hFont;
713 LONG state = get_button_state( hwnd );
714 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
715 BOOL pushedState = (state & BUTTON_HIGHLIGHTED);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000716
Alexandre Julliardde424282001-08-10 22:51:42 +0000717 GetClientRect( hwnd, &rc );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000718
Serge Ivanov6117fc42000-09-13 00:00:55 +0000719 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
Alexandre Julliardde424282001-08-10 22:51:42 +0000720 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000721 SendMessageW( GetParent(hwnd), WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd );
Alexandre Julliard4344c362002-05-20 18:15:28 +0000722 hOldPen = (HPEN)SelectObject(hDC, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
Alexandre Julliarda3960291999-02-26 11:11:13 +0000723 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
Serge Ivanov6117fc42000-09-13 00:00:55 +0000724 oldBkMode = SetBkMode(hDC, TRANSPARENT);
Dennis Björklund767b0991999-07-15 16:07:19 +0000725
726 if ( TWEAK_WineLook == WIN31_LOOK)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000727 {
Serge Ivanov6117fc42000-09-13 00:00:55 +0000728 COLORREF clr_wnd = GetSysColor(COLOR_WINDOW);
Dennis Björklund767b0991999-07-15 16:07:19 +0000729 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
730
Serge Ivanov6117fc42000-09-13 00:00:55 +0000731 SetPixel( hDC, rc.left, rc.top, clr_wnd);
732 SetPixel( hDC, rc.left, rc.bottom-1, clr_wnd);
733 SetPixel( hDC, rc.right-1, rc.top, clr_wnd);
734 SetPixel( hDC, rc.right-1, rc.bottom-1, clr_wnd);
Dennis Björklund767b0991999-07-15 16:07:19 +0000735 InflateRect( &rc, -1, -1 );
Alexandre Julliardaca05781994-10-17 18:12:41 +0000736 }
Vincent Béron9a624912002-05-31 23:06:46 +0000737
Alexandre Julliardde424282001-08-10 22:51:42 +0000738 if (get_button_type(style) == BS_DEFPUSHBUTTON)
Alexandre Julliardaca05781994-10-17 18:12:41 +0000739 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000740 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
Dennis Björklund767b0991999-07-15 16:07:19 +0000741 InflateRect( &rc, -1, -1 );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000742 }
743
Dennis Björklund767b0991999-07-15 16:07:19 +0000744 if (TWEAK_WineLook == WIN31_LOOK)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000745 {
Francis Beaudet9b4748b1999-07-18 15:29:43 +0000746 if (pushedState)
Dennis Björklund767b0991999-07-15 16:07:19 +0000747 {
748 /* draw button shadow: */
749 SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW));
750 PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY );
751 PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY );
Dennis Björklund767b0991999-07-15 16:07:19 +0000752 } else {
753 rc.right++, rc.bottom++;
754 DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT );
Dennis Björklund767b0991999-07-15 16:07:19 +0000755 rc.right--, rc.bottom--;
756 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000757 }
Dennis Björklund767b0991999-07-15 16:07:19 +0000758 else
759 {
Serge Ivanov6117fc42000-09-13 00:00:55 +0000760 UINT uState = DFCS_BUTTONPUSH | DFCS_ADJUSTRECT;
Dennis Björklund767b0991999-07-15 16:07:19 +0000761
Alexandre Julliardde424282001-08-10 22:51:42 +0000762 if (style & BS_FLAT)
Serge Ivanov6117fc42000-09-13 00:00:55 +0000763 uState |= DFCS_MONO;
764 else if (pushedState)
Dennis Björklund767b0991999-07-15 16:07:19 +0000765 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000766 if (get_button_type(style) == BS_DEFPUSHBUTTON )
Dennis Björklund767b0991999-07-15 16:07:19 +0000767 uState |= DFCS_FLAT;
768 else
769 uState |= DFCS_PUSHED;
770 }
771
Alexandre Julliardde424282001-08-10 22:51:42 +0000772 if (state & (BUTTON_CHECKED | BUTTON_3STATE))
Serge Ivanov6117fc42000-09-13 00:00:55 +0000773 uState |= DFCS_CHECKED;
774
Dennis Björklund767b0991999-07-15 16:07:19 +0000775 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
Dennis Björklund767b0991999-07-15 16:07:19 +0000776
777 focus_rect = rc;
Dennis Björklund767b0991999-07-15 16:07:19 +0000778 }
779
Serge Ivanov6117fc42000-09-13 00:00:55 +0000780 /* draw button label */
781 r = rc;
Alexandre Julliardde424282001-08-10 22:51:42 +0000782 dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &r);
Serge Ivanov6117fc42000-09-13 00:00:55 +0000783
784 if (dtFlags == (UINT)-1L)
785 goto cleanup;
786
787 if (pushedState)
788 OffsetRect(&r, 1, 1);
789
790 if(TWEAK_WineLook == WIN31_LOOK)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000791 {
Serge Ivanov6117fc42000-09-13 00:00:55 +0000792 focus_rect = r;
793 InflateRect(&focus_rect, 2, 0);
Pascal Lessard026f7051999-04-15 15:49:36 +0000794 }
Dennis Björklund767b0991999-07-15 16:07:19 +0000795
Serge Ivanov6117fc42000-09-13 00:00:55 +0000796 hRgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
797 SelectClipRgn(hDC, hRgn);
798
799 oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) );
800
Alexandre Julliardde424282001-08-10 22:51:42 +0000801 BUTTON_DrawLabel(hwnd, hDC, dtFlags, &r);
Serge Ivanov6117fc42000-09-13 00:00:55 +0000802
803 SetTextColor( hDC, oldTxtColor );
804 SelectClipRgn(hDC, 0);
805 DeleteObject(hRgn);
806
Alexandre Julliardde424282001-08-10 22:51:42 +0000807 if (state & BUTTON_HASFOCUS)
Dennis Björklund767b0991999-07-15 16:07:19 +0000808 {
809 InflateRect( &focus_rect, -1, -1 );
Serge Ivanov6117fc42000-09-13 00:00:55 +0000810 IntersectRect(&focus_rect, &focus_rect, &rc);
Dennis Björklund767b0991999-07-15 16:07:19 +0000811 DrawFocusRect( hDC, &focus_rect );
812 }
813
Serge Ivanov6117fc42000-09-13 00:00:55 +0000814 cleanup:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000815 SelectObject( hDC, hOldPen );
816 SelectObject( hDC, hOldBrush );
Serge Ivanov6117fc42000-09-13 00:00:55 +0000817 SetBkMode(hDC, oldBkMode);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000818}
819
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000820/**********************************************************************
Alexandre Julliardecc37121994-11-22 16:31:29 +0000821 * Check Box & Radio Button Functions
Alexandre Julliardaca05781994-10-17 18:12:41 +0000822 */
823
Alexandre Julliardde424282001-08-10 22:51:42 +0000824static void CB_Paint( HWND hwnd, HDC hDC, UINT action )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000825{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000826 RECT rbox, rtext, client;
827 HBRUSH hBrush;
Serge Ivanov6117fc42000-09-13 00:00:55 +0000828 int delta;
Serge Ivanov6117fc42000-09-13 00:00:55 +0000829 UINT dtFlags;
830 HRGN hRgn;
Alexandre Julliardde424282001-08-10 22:51:42 +0000831 HFONT hFont;
832 LONG state = get_button_state( hwnd );
833 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000834
Alexandre Julliardde424282001-08-10 22:51:42 +0000835 if (style & BS_PUSHLIKE)
Francis Beaudet9b4748b1999-07-18 15:29:43 +0000836 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000837 PB_Paint( hwnd, hDC, action );
Patrik Stridvall0e38aa71999-07-31 17:34:43 +0000838 return;
Francis Beaudet9b4748b1999-07-18 15:29:43 +0000839 }
840
Alexandre Julliardde424282001-08-10 22:51:42 +0000841 GetClientRect(hwnd, &client);
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000842 rbox = rtext = client;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000843
Alexandre Julliardde424282001-08-10 22:51:42 +0000844 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000845
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000846 hBrush = (HBRUSH)SendMessageW(GetParent(hwnd), WM_CTLCOLORSTATIC,
847 (WPARAM)hDC, (LPARAM)hwnd);
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000848 if (!hBrush) /* did the app forget to call defwindowproc ? */
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000849 hBrush = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC,
850 (WPARAM)hDC, (LPARAM)hwnd );
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000851
Vincent Béron9a624912002-05-31 23:06:46 +0000852 if (style & BS_LEFTTEXT)
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000853 {
854 /* magic +4 is what CTL3D expects */
Alexandre Julliard0e607781993-11-03 19:23:37 +0000855
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000856 rtext.right -= checkBoxWidth + 4;
857 rbox.left = rbox.right - checkBoxWidth;
858 }
Vincent Béron9a624912002-05-31 23:06:46 +0000859 else
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000860 {
861 rtext.left += checkBoxWidth + 4;
862 rbox.right = checkBoxWidth;
863 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000864
Serge Ivanov6117fc42000-09-13 00:00:55 +0000865 /* Draw the check-box bitmap */
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000866 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
Vincent Béron9a624912002-05-31 23:06:46 +0000867 {
Dmitry Timoshkovb32c0002001-02-23 01:32:05 +0000868 /* Since WM_ERASEBKGND does nothing, first prepare background */
869 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
870 else FillRect( hDC, &client, hBrush );
871
Dennis Björklund9af3eba1999-09-13 16:06:17 +0000872 if( TWEAK_WineLook == WIN31_LOOK )
873 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000874 HDC hMemDC = CreateCompatibleDC( hDC );
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000875 int x = 0, y = 0;
Francis Beaudetf22ff401999-09-03 12:35:18 +0000876 delta = (rbox.bottom - rbox.top - checkBoxHeight) / 2;
877
878 /* Check in case the client area is smaller than the checkbox bitmap */
879 if (delta < 0) delta = 0;
Alexandre Julliard902da691995-11-05 14:39:02 +0000880
Alexandre Julliardde424282001-08-10 22:51:42 +0000881 if (state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth;
882 if (state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth;
883 if ((get_button_type(style) == BS_RADIOBUTTON) ||
884 (get_button_type(style) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
885 else if (state & BUTTON_3STATE) y += 2 * checkBoxHeight;
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000886
Francis Beaudet49936031999-09-03 15:07:21 +0000887 /* The bitmap for the radio button is not aligned with the
888 * left of the window, it is 1 pixel off. */
Alexandre Julliardde424282001-08-10 22:51:42 +0000889 if ((get_button_type(style) == BS_RADIOBUTTON) ||
890 (get_button_type(style) == BS_AUTORADIOBUTTON))
Francis Beaudet49936031999-09-03 15:07:21 +0000891 rbox.left += 1;
892
Alexandre Julliarda3960291999-02-26 11:11:13 +0000893 SelectObject( hMemDC, hbitmapCheckBoxes );
894 BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth,
Huw D M Davies2d617be1998-12-08 09:14:09 +0000895 checkBoxHeight, hMemDC, x, y, SRCCOPY );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000896 DeleteDC( hMemDC );
Dennis Björklund9af3eba1999-09-13 16:06:17 +0000897 }
898 else
899 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000900 UINT flags;
Dennis Björklund9af3eba1999-09-13 16:06:17 +0000901
Alexandre Julliardde424282001-08-10 22:51:42 +0000902 if ((get_button_type(style) == BS_RADIOBUTTON) ||
903 (get_button_type(style) == BS_AUTORADIOBUTTON)) flags = DFCS_BUTTONRADIO;
904 else if (state & BUTTON_3STATE) flags = DFCS_BUTTON3STATE;
905 else flags = DFCS_BUTTONCHECK;
Dennis Björklund9af3eba1999-09-13 16:06:17 +0000906
Alexandre Julliardde424282001-08-10 22:51:42 +0000907 if (state & (BUTTON_CHECKED | BUTTON_3STATE)) flags |= DFCS_CHECKED;
908 if (state & BUTTON_HIGHLIGHTED) flags |= DFCS_PUSHED;
Dennis Björklund9af3eba1999-09-13 16:06:17 +0000909
Alexandre Julliardde424282001-08-10 22:51:42 +0000910 if (style & WS_DISABLED) flags |= DFCS_INACTIVE;
Dennis Björklund9af3eba1999-09-13 16:06:17 +0000911
Vincent Béron9a624912002-05-31 23:06:46 +0000912 /* rbox must have the correct height */
Susan Farleyb09c6ef2000-06-04 01:32:59 +0000913 delta = rbox.bottom - rbox.top - checkBoxHeight;
Vincent Béron9a624912002-05-31 23:06:46 +0000914 if (delta > 0)
915 {
Susan Farleyb09c6ef2000-06-04 01:32:59 +0000916 int ofs = (abs(delta) / 2);
917 rbox.bottom -= ofs + 1;
918 rbox.top = rbox.bottom - checkBoxHeight;
919 }
920 else if (delta < 0)
921 {
922 int ofs = (abs(delta) / 2);
923 rbox.top -= ofs + 1;
924 rbox.bottom = rbox.top + checkBoxHeight;
925 }
926
Alexandre Julliardde424282001-08-10 22:51:42 +0000927 DrawFrameControl( hDC, &rbox, DFC_BUTTON, flags );
Dennis Björklund9af3eba1999-09-13 16:06:17 +0000928 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000929 }
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000930
Serge Ivanov6117fc42000-09-13 00:00:55 +0000931 /* Draw label */
932 client = rtext;
Alexandre Julliardde424282001-08-10 22:51:42 +0000933 dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rtext);
Serge Ivanov6117fc42000-09-13 00:00:55 +0000934
935 if (dtFlags == (UINT)-1L) /* Noting to draw */
936 return;
937 hRgn = CreateRectRgn(client.left, client.top, client.right, client.bottom);
938 SelectClipRgn(hDC, hRgn);
939 DeleteObject(hRgn);
940
941 if (action == ODA_DRAWENTIRE)
Alexandre Julliardde424282001-08-10 22:51:42 +0000942 BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rtext);
Serge Ivanov6117fc42000-09-13 00:00:55 +0000943
944 /* ... and focus */
Alexandre Julliardaca05781994-10-17 18:12:41 +0000945 if ((action == ODA_FOCUS) ||
Alexandre Julliardde424282001-08-10 22:51:42 +0000946 ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS)))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000947 {
Serge Ivanov6117fc42000-09-13 00:00:55 +0000948 rtext.left--;
949 rtext.right++;
950 IntersectRect(&rtext, &rtext, &client);
951 DrawFocusRect( hDC, &rtext );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000952 }
Serge Ivanov6117fc42000-09-13 00:00:55 +0000953 SelectClipRgn(hDC, 0);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000954}
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000955
956
Alexandre Julliard0e607781993-11-03 19:23:37 +0000957/**********************************************************************
Alexandre Julliardecc37121994-11-22 16:31:29 +0000958 * BUTTON_CheckAutoRadioButton
959 *
Alexandre Julliardde424282001-08-10 22:51:42 +0000960 * hwnd is checked, uncheck every other auto radio button in group
Alexandre Julliardecc37121994-11-22 16:31:29 +0000961 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000962static void BUTTON_CheckAutoRadioButton( HWND hwnd )
Alexandre Julliardecc37121994-11-22 16:31:29 +0000963{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000964 HWND parent, sibling, start;
Alexandre Julliardde424282001-08-10 22:51:42 +0000965
966 parent = GetParent(hwnd);
967 /* make sure that starting control is not disabled or invisible */
968 start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000969 do
970 {
971 if (!sibling) break;
Alexandre Julliardde424282001-08-10 22:51:42 +0000972 if ((hwnd != sibling) &&
973 ((GetWindowLongA( sibling, GWL_STYLE) & 0x0f) == BS_AUTORADIOBUTTON))
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +0000974 SendMessageW( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000975 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000976 } while (sibling != start);
Alexandre Julliardecc37121994-11-22 16:31:29 +0000977}
978
979
980/**********************************************************************
Alexandre Julliard0e607781993-11-03 19:23:37 +0000981 * Group Box Functions
982 */
983
Alexandre Julliardde424282001-08-10 22:51:42 +0000984static void GB_Paint( HWND hwnd, HDC hDC, UINT action )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000985{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000986 RECT rc, rcFrame;
Serge Ivanov6117fc42000-09-13 00:00:55 +0000987 HBRUSH hbr;
Alexandre Julliardde424282001-08-10 22:51:42 +0000988 HFONT hFont;
Serge Ivanov6117fc42000-09-13 00:00:55 +0000989 UINT dtFlags;
Alexandre Julliardde424282001-08-10 22:51:42 +0000990 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000991
Alexandre Julliardaca05781994-10-17 18:12:41 +0000992 if (action != ODA_DRAWENTIRE) return;
993
Alexandre Julliardde424282001-08-10 22:51:42 +0000994 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
Serge Ivanov6117fc42000-09-13 00:00:55 +0000995 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000996 hbr = (HBRUSH)SendMessageW(GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd);
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000997 if (!hbr) /* did the app forget to call defwindowproc ? */
Michael Stefaniuc95591a62002-10-28 20:11:40 +0000998 hbr = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC,
999 (WPARAM)hDC, (LPARAM)hwnd);
Serge Ivanov6117fc42000-09-13 00:00:55 +00001000
Alexandre Julliardde424282001-08-10 22:51:42 +00001001 GetClientRect( hwnd, &rc);
Huw D M Davies2d617be1998-12-08 09:14:09 +00001002 if (TWEAK_WineLook == WIN31_LOOK) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001003 HPEN hPrevPen = SelectObject( hDC,
Alexandre Julliard4344c362002-05-20 18:15:28 +00001004 SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
Alexandre Julliarda3960291999-02-26 11:11:13 +00001005 HBRUSH hPrevBrush = SelectObject( hDC,
1006 GetStockObject(NULL_BRUSH) );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001007
Alexandre Julliarda3960291999-02-26 11:11:13 +00001008 Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 );
1009 SelectObject( hDC, hPrevBrush );
1010 SelectObject( hDC, hPrevPen );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001011 } else {
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +00001012 TEXTMETRICW tm;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001013 rcFrame = rc;
1014
Dmitry Timoshkov2b4be4b2000-11-28 23:51:48 +00001015 GetTextMetricsW (hDC, &tm);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001016 rcFrame.top += (tm.tmHeight / 2) - 1;
Alexandre Julliardde424282001-08-10 22:51:42 +00001017 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT | ((style & BS_FLAT) ? BF_FLAT : 0));
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001018 }
1019
Serge Ivanov6117fc42000-09-13 00:00:55 +00001020 InflateRect(&rc, -7, 1);
Alexandre Julliardde424282001-08-10 22:51:42 +00001021 dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rc);
Serge Ivanov6117fc42000-09-13 00:00:55 +00001022
1023 if (dtFlags == (UINT)-1L)
1024 return;
1025
1026 /* Because buttons have CS_PARENTDC class style, there is a chance
1027 * that label will be drawn out of client rect.
1028 * But Windows doesn't clip label's rect, so do I.
1029 */
1030
1031 /* There is 1-pixel marging at the left, right, and bottom */
1032 rc.left--; rc.right++; rc.bottom++;
1033 FillRect(hDC, &rc, hbr);
1034 rc.left++; rc.right--; rc.bottom--;
1035
Alexandre Julliardde424282001-08-10 22:51:42 +00001036 BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rc);
Alexandre Julliard0e607781993-11-03 19:23:37 +00001037}
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001038
1039
Alexandre Julliard0e607781993-11-03 19:23:37 +00001040/**********************************************************************
1041 * User Button Functions
1042 */
1043
Alexandre Julliardde424282001-08-10 22:51:42 +00001044static void UB_Paint( HWND hwnd, HDC hDC, UINT action )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001045{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001046 RECT rc;
1047 HBRUSH hBrush;
Alexandre Julliardde424282001-08-10 22:51:42 +00001048 HFONT hFont;
1049 LONG state = get_button_state( hwnd );
Alexandre Julliard0e607781993-11-03 19:23:37 +00001050
Alexandre Julliardaca05781994-10-17 18:12:41 +00001051 if (action == ODA_SELECT) return;
1052
Alexandre Julliardde424282001-08-10 22:51:42 +00001053 GetClientRect( hwnd, &rc);
Alexandre Julliard0e607781993-11-03 19:23:37 +00001054
Alexandre Julliardde424282001-08-10 22:51:42 +00001055 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
Alexandre Julliardd23a82b2001-09-19 20:37:04 +00001056
Michael Stefaniuc95591a62002-10-28 20:11:40 +00001057 hBrush = (HBRUSH)SendMessageW(GetParent(hwnd), WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd);
Alexandre Julliardd23a82b2001-09-19 20:37:04 +00001058 if (!hBrush) /* did the app forget to call defwindowproc ? */
Michael Stefaniuc95591a62002-10-28 20:11:40 +00001059 hBrush = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORBTN,
1060 (WPARAM)hDC, (LPARAM)hwnd);
Alexandre Julliard0e607781993-11-03 19:23:37 +00001061
Alexandre Julliarda3960291999-02-26 11:11:13 +00001062 FillRect( hDC, &rc, hBrush );
Alexandre Julliardaca05781994-10-17 18:12:41 +00001063 if ((action == ODA_FOCUS) ||
Alexandre Julliardde424282001-08-10 22:51:42 +00001064 ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS)))
Alexandre Julliarda3960291999-02-26 11:11:13 +00001065 DrawFocusRect( hDC, &rc );
Alexandre Julliard0e607781993-11-03 19:23:37 +00001066}
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001067
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001068
1069/**********************************************************************
1070 * Ownerdrawn Button Functions
1071 */
1072
Alexandre Julliardde424282001-08-10 22:51:42 +00001073static void OB_Paint( HWND hwnd, HDC hDC, UINT action )
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001074{
Alexandre Julliardde424282001-08-10 22:51:42 +00001075 LONG state = get_button_state( hwnd );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001076 DRAWITEMSTRUCT dis;
Dave Hawkesfcd35212000-07-15 21:31:42 +00001077 HRGN clipRegion;
1078 RECT clipRect;
Alexandre Julliardde424282001-08-10 22:51:42 +00001079 UINT id = GetWindowLongA( hwnd, GWL_ID );
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001080
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001081 dis.CtlType = ODT_BUTTON;
Alexandre Julliardde424282001-08-10 22:51:42 +00001082 dis.CtlID = id;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001083 dis.itemID = 0;
1084 dis.itemAction = action;
Alexandre Julliardde424282001-08-10 22:51:42 +00001085 dis.itemState = ((state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
1086 ((state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
1087 (IsWindowEnabled(hwnd) ? 0: ODS_DISABLED);
1088 dis.hwndItem = hwnd;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001089 dis.hDC = hDC;
1090 dis.itemData = 0;
Alexandre Julliardde424282001-08-10 22:51:42 +00001091 GetClientRect( hwnd, &dis.rcItem );
Dennis Björklund767b0991999-07-15 16:07:19 +00001092
Alexandre Julliardde424282001-08-10 22:51:42 +00001093 clipRegion = CreateRectRgnIndirect(&dis.rcItem);
Dave Hawkesfcd35212000-07-15 21:31:42 +00001094 if (GetClipRgn(hDC, clipRegion) != 1)
1095 {
1096 DeleteObject(clipRegion);
Francois Gougetd2667a42002-12-02 18:10:57 +00001097 clipRegion=NULL;
Dave Hawkesfcd35212000-07-15 21:31:42 +00001098 }
1099 clipRect = dis.rcItem;
Alexandre Julliardde424282001-08-10 22:51:42 +00001100 DPtoLP(hDC, (LPPOINT) &clipRect, 2);
Dave Hawkesfcd35212000-07-15 21:31:42 +00001101 IntersectClipRect(hDC, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
1102
Dennis Björklund767b0991999-07-15 16:07:19 +00001103 SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
Alexandre Julliardde424282001-08-10 22:51:42 +00001104 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
1105 SelectClipRgn(hDC, clipRegion);
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001106}