Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 1 | /* File: button.c -- Button type widgets |
Alexandre Julliard | f41aeca | 1993-09-14 16:47:10 +0000 | [diff] [blame] | 2 | * |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 3 | * Copyright (C) 1993 Johannes Ruscheinski |
| 4 | * Copyright (C) 1993 David Metcalfe |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 5 | * Copyright (C) 1994 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 6 | * |
| 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 Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 20 | */ |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 21 | |
Jeff Garzik | c3e1f72 | 1999-02-19 15:42:11 +0000 | [diff] [blame] | 22 | #include <string.h> |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 23 | #include <stdlib.h> |
| 24 | |
Patrik Stridvall | 6cc47d4 | 2000-03-08 18:26:56 +0000 | [diff] [blame] | 25 | #include "winbase.h" |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 26 | #include "windef.h" |
| 27 | #include "wingdi.h" |
Michael Veksler | ca1bc86 | 1999-01-01 18:57:33 +0000 | [diff] [blame] | 28 | #include "wine/winuser16.h" |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 29 | #include "controls.h" |
Alexandre Julliard | a41b2cf | 2001-01-15 20:12:55 +0000 | [diff] [blame] | 30 | #include "user.h" |
Alexandre Julliard | 940d58c | 1994-09-16 09:24:37 +0000 | [diff] [blame] | 31 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 32 | /* 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 Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 37 | |
| 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 Timoshkov | a081e23 | 2002-05-20 18:21:29 +0000 | [diff] [blame] | 50 | static UINT BUTTON_CalcLabelRect( HWND hwnd, HDC hdc, RECT *rc ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 51 | static void PB_Paint( HWND hwnd, HDC hDC, UINT action ); |
| 52 | static void CB_Paint( HWND hwnd, HDC hDC, UINT action ); |
| 53 | static void GB_Paint( HWND hwnd, HDC hDC, UINT action ); |
| 54 | static void UB_Paint( HWND hwnd, HDC hDC, UINT action ); |
| 55 | static void OB_Paint( HWND hwnd, HDC hDC, UINT action ); |
| 56 | static void BUTTON_CheckAutoRadioButton( HWND hwnd ); |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 57 | static LRESULT WINAPI ButtonWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); |
| 58 | static LRESULT WINAPI ButtonWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 59 | |
Alexandre Julliard | e399fc3 | 1993-11-24 17:08:56 +0000 | [diff] [blame] | 60 | #define MAX_BTN_TYPE 12 |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 61 | |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 62 | static const WORD maxCheckState[MAX_BTN_TYPE] = |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 63 | { |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 64 | 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 Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 78 | typedef void (*pfPaint)( HWND hwnd, HDC hdc, UINT action ); |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 79 | |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 80 | static const pfPaint btnPaintFunc[MAX_BTN_TYPE] = |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 81 | { |
| 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 Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 96 | static HBITMAP hbitmapCheckBoxes = 0; |
Alexandre Julliard | 940d58c | 1994-09-16 09:24:37 +0000 | [diff] [blame] | 97 | static WORD checkBoxWidth = 0, checkBoxHeight = 0; |
| 98 | |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 99 | |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 100 | /********************************************************************* |
| 101 | * button class descriptor |
| 102 | */ |
| 103 | const 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 109 | NB_EXTRA_BYTES, /* extra */ |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 110 | IDC_ARROWA, /* cursor */ |
| 111 | 0 /* brush */ |
| 112 | }; |
| 113 | |
| 114 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 115 | inline static LONG get_button_state( HWND hwnd ) |
| 116 | { |
| 117 | return GetWindowLongA( hwnd, STATE_GWL_OFFSET ); |
| 118 | } |
| 119 | |
| 120 | inline static void set_button_state( HWND hwnd, LONG state ) |
| 121 | { |
| 122 | SetWindowLongA( hwnd, STATE_GWL_OFFSET, state ); |
| 123 | } |
| 124 | |
| 125 | inline static HFONT get_button_font( HWND hwnd ) |
| 126 | { |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 127 | return (HFONT)GetWindowLongA( hwnd, HFONT_GWL_OFFSET ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | inline static void set_button_font( HWND hwnd, HFONT font ) |
| 131 | { |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 132 | SetWindowLongA( hwnd, HFONT_GWL_OFFSET, (LONG)font ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | inline static UINT get_button_type( LONG window_style ) |
| 136 | { |
| 137 | return (window_style & 0x0f); |
| 138 | } |
| 139 | |
| 140 | /* paint a button of any type */ |
| 141 | inline 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 */ |
| 152 | inline 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 Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 160 | /*********************************************************************** |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 161 | * ButtonWndProc_common |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 162 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 163 | static LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg, |
| 164 | WPARAM wParam, LPARAM lParam, BOOL unicode ) |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 165 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 166 | RECT rect; |
Patrik Stridvall | 0f8bc5b | 1999-04-22 16:27:50 +0000 | [diff] [blame] | 167 | POINT pt; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 168 | LONG style = GetWindowLongA( hWnd, GWL_STYLE ); |
| 169 | UINT btn_type = get_button_type( style ); |
| 170 | LONG state; |
Pascal Lessard | 026f705 | 1999-04-15 15:49:36 +0000 | [diff] [blame] | 171 | HANDLE oldHbitmap; |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 172 | |
Patrik Stridvall | 0f8bc5b | 1999-04-22 16:27:50 +0000 | [diff] [blame] | 173 | pt.x = LOWORD(lParam); |
| 174 | pt.y = HIWORD(lParam); |
| 175 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 176 | switch (uMsg) |
| 177 | { |
| 178 | case WM_GETDLGCODE: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 179 | switch(btn_type) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 180 | { |
| 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 Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 187 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 188 | case WM_ENABLE: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 189 | paint_button( hWnd, btn_type, ODA_DRAWENTIRE ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 190 | break; |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 191 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 192 | case WM_CREATE: |
| 193 | if (!hbitmapCheckBoxes) |
| 194 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 195 | BITMAP bmp; |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 196 | hbitmapCheckBoxes = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CHECKBOXES)); |
| 197 | GetObjectW( hbitmapCheckBoxes, sizeof(bmp), &bmp ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 198 | checkBoxWidth = bmp.bmWidth / 4; |
| 199 | checkBoxHeight = bmp.bmHeight / 3; |
| 200 | } |
Vincent Béron | e35580f | 2002-06-21 22:25:17 +0000 | [diff] [blame] | 201 | if (btn_type >= MAX_BTN_TYPE) |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 202 | return -1; /* abort */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 203 | set_button_state( hWnd, BUTTON_UNCHECKED ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 204 | return 0; |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 205 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 206 | case WM_ERASEBKGND: |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 207 | return 1; |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 208 | |
| 209 | case WM_PAINT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 210 | if (btnPaintFunc[btn_type]) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 211 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 212 | PAINTSTRUCT ps; |
| 213 | HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps ); |
Sheri Steeves | 13ffd58 | 2000-06-11 20:08:46 +0000 | [diff] [blame] | 214 | int nOldMode = SetBkMode( hdc, OPAQUE ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 215 | (btnPaintFunc[btn_type])( hWnd, hdc, ODA_DRAWENTIRE ); |
Sheri Steeves | 13ffd58 | 2000-06-11 20:08:46 +0000 | [diff] [blame] | 216 | SetBkMode(hdc, nOldMode); /* reset painting mode */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 217 | if( !wParam ) EndPaint( hWnd, &ps ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 218 | } |
| 219 | break; |
| 220 | |
Dmitry Timoshkov | f92a777 | 1999-12-05 23:51:15 +0000 | [diff] [blame] | 221 | case WM_KEYDOWN: |
| 222 | if (wParam == VK_SPACE) |
| 223 | { |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 224 | SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 225 | set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED ); |
Dmitry Timoshkov | f92a777 | 1999-12-05 23:51:15 +0000 | [diff] [blame] | 226 | } |
| 227 | break; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 228 | |
Eric Kohl | 65ab1b0 | 1998-11-22 17:53:27 +0000 | [diff] [blame] | 229 | case WM_LBUTTONDBLCLK: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 230 | if(style & BS_NOTIFY || |
| 231 | btn_type == BS_RADIOBUTTON || |
| 232 | btn_type == BS_USERBUTTON || |
| 233 | btn_type == BS_OWNERDRAW) |
| 234 | { |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 235 | SendMessageW( GetParent(hWnd), WM_COMMAND, |
Alexandre Julliard | d23a82b | 2001-09-19 20:37:04 +0000 | [diff] [blame] | 236 | MAKEWPARAM( GetWindowLongA(hWnd,GWL_ID), BN_DOUBLECLICKED ), |
| 237 | (LPARAM)hWnd); |
Rein Klazes | 61b15de | 1999-09-27 11:38:47 +0000 | [diff] [blame] | 238 | break; |
| 239 | } |
| 240 | /* fall through */ |
Rein Klazes | dbb4ad8 | 1999-07-31 11:10:52 +0000 | [diff] [blame] | 241 | case WM_LBUTTONDOWN: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 242 | SetCapture( hWnd ); |
Luc Tourangeau | 70cd8cb | 1999-07-10 11:57:29 +0000 | [diff] [blame] | 243 | SetFocus( hWnd ); |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 244 | SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 245 | set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 246 | break; |
| 247 | |
Dmitry Timoshkov | f92a777 | 1999-12-05 23:51:15 +0000 | [diff] [blame] | 248 | case WM_KEYUP: |
| 249 | if (wParam != VK_SPACE) |
| 250 | break; |
| 251 | /* fall through */ |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 252 | case WM_LBUTTONUP: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 253 | 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 Klazes | 61b15de | 1999-09-27 11:38:47 +0000 | [diff] [blame] | 259 | ReleaseCapture(); |
| 260 | break; |
| 261 | } |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 262 | SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 ); |
Rein Klazes | 61b15de | 1999-09-27 11:38:47 +0000 | [diff] [blame] | 263 | ReleaseCapture(); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 264 | GetClientRect( hWnd, &rect ); |
Dmitry Timoshkov | f92a777 | 1999-12-05 23:51:15 +0000 | [diff] [blame] | 265 | if (uMsg == WM_KEYUP || PtInRect( &rect, pt )) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 266 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 267 | state = get_button_state( hWnd ); |
| 268 | switch(btn_type) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 269 | { |
| 270 | case BS_AUTOCHECKBOX: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 271 | SendMessageW( hWnd, BM_SETCHECK, !(state & BUTTON_CHECKED), 0 ); |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 272 | break; |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 273 | case BS_AUTORADIOBUTTON: |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 274 | SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 ); |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 275 | break; |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 276 | case BS_AUTO3STATE: |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 277 | SendMessageW( hWnd, BM_SETCHECK, |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 278 | (state & BUTTON_3STATE) ? 0 : ((state & 3) + 1), 0 ); |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 279 | break; |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 280 | } |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 281 | SendMessageW( GetParent(hWnd), WM_COMMAND, |
Alexandre Julliard | d23a82b | 2001-09-19 20:37:04 +0000 | [diff] [blame] | 282 | MAKEWPARAM( GetWindowLongA(hWnd,GWL_ID), BN_CLICKED ), (LPARAM)hWnd); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 283 | } |
| 284 | break; |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 285 | |
Rein Klazes | 61b15de | 1999-09-27 11:38:47 +0000 | [diff] [blame] | 286 | case WM_CAPTURECHANGED: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 287 | 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 Klazes | 61b15de | 1999-09-27 11:38:47 +0000 | [diff] [blame] | 293 | } |
| 294 | break; |
| 295 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 296 | case WM_MOUSEMOVE: |
Rein Klazes | 0e4cf6c | 2002-01-15 20:27:30 +0000 | [diff] [blame] | 297 | if ((wParam & MK_LBUTTON) && GetCapture() == hWnd) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 298 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 299 | GetClientRect( hWnd, &rect ); |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 300 | SendMessageW( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 301 | } |
| 302 | break; |
Alexandre Julliard | 940d58c | 1994-09-16 09:24:37 +0000 | [diff] [blame] | 303 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 304 | case WM_SETTEXT: |
Dmitry Timoshkov | a081e23 | 2002-05-20 18:21:29 +0000 | [diff] [blame] | 305 | { |
| 306 | /* Clear an old text here as Windows does */ |
| 307 | HDC hdc = GetDC(hWnd); |
| 308 | HBRUSH hbrush; |
| 309 | RECT client, rc; |
| 310 | |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 311 | hbrush = (HBRUSH)SendMessageW(GetParent(hWnd), WM_CTLCOLORSTATIC, |
| 312 | (WPARAM)hdc, (LPARAM)hWnd); |
Dmitry Timoshkov | a081e23 | 2002-05-20 18:21:29 +0000 | [diff] [blame] | 313 | if (!hbrush) /* did the app forget to call DefWindowProc ? */ |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 314 | hbrush = (HBRUSH)DefWindowProcW(GetParent(hWnd), WM_CTLCOLORSTATIC, |
| 315 | (WPARAM)hdc, (LPARAM)hWnd); |
Dmitry Timoshkov | a081e23 | 2002-05-20 18:21:29 +0000 | [diff] [blame] | 316 | |
| 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 326 | if (unicode) DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam ); |
| 327 | else DefWindowProcA( hWnd, WM_SETTEXT, wParam, lParam ); |
Dmitry Timoshkov | a081e23 | 2002-05-20 18:21:29 +0000 | [diff] [blame] | 328 | 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 Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 332 | return 1; /* success. FIXME: check text length */ |
Dmitry Timoshkov | a081e23 | 2002-05-20 18:21:29 +0000 | [diff] [blame] | 333 | } |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 334 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 335 | case WM_SETFONT: |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 336 | set_button_font( hWnd, (HFONT)wParam ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 337 | if (lParam) paint_button( hWnd, btn_type, ODA_DRAWENTIRE ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 338 | break; |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 339 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 340 | case WM_GETFONT: |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 341 | return (LRESULT)get_button_font( hWnd ); |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 342 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 343 | case WM_SETFOCUS: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 344 | if ((btn_type == BS_RADIOBUTTON || btn_type == BS_AUTORADIOBUTTON) && (GetCapture() != hWnd) && |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 345 | !(SendMessageW(hWnd, BM_GETCHECK, 0, 0) & BST_CHECKED)) |
Luc Tourangeau | 70cd8cb | 1999-07-10 11:57:29 +0000 | [diff] [blame] | 346 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 347 | /* The notification is sent when the button (BS_AUTORADIOBUTTON) |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 348 | is unchecked and the focus was not given by a mouse click. */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 349 | if (btn_type == BS_AUTORADIOBUTTON) |
| 350 | SendMessageW( hWnd, BM_SETCHECK, BUTTON_CHECKED, 0 ); |
| 351 | SendMessageW( GetParent(hWnd), WM_COMMAND, |
Alexandre Julliard | d23a82b | 2001-09-19 20:37:04 +0000 | [diff] [blame] | 352 | MAKEWPARAM( GetWindowLongA(hWnd,GWL_ID), BN_CLICKED ), (LPARAM)hWnd); |
Luc Tourangeau | 70cd8cb | 1999-07-10 11:57:29 +0000 | [diff] [blame] | 353 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 354 | set_button_state( hWnd, get_button_state(hWnd) | BUTTON_HASFOCUS ); |
| 355 | paint_button( hWnd, btn_type, ODA_FOCUS ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 356 | break; |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 357 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 358 | case WM_KILLFOCUS: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 359 | set_button_state( hWnd, get_button_state(hWnd) & ~BUTTON_HASFOCUS ); |
| 360 | paint_button( hWnd, btn_type, ODA_FOCUS ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 361 | InvalidateRect( hWnd, NULL, TRUE ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 362 | break; |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 363 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 364 | case WM_SYSCOLORCHANGE: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 365 | InvalidateRect( hWnd, NULL, FALSE ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 366 | break; |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 367 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 368 | case BM_SETSTYLE16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 369 | case BM_SETSTYLE: |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 370 | if ((wParam & 0x0f) >= MAX_BTN_TYPE) break; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 371 | btn_type = wParam & 0x0f; |
| 372 | style = (style & ~0x0f) | btn_type; |
| 373 | SetWindowLongA( hWnd, GWL_STYLE, style ); |
Sheri Steeves | 13ffd58 | 2000-06-11 20:08:46 +0000 | [diff] [blame] | 374 | |
| 375 | /* Only redraw if lParam flag is set.*/ |
| 376 | if (lParam) |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 377 | paint_button( hWnd, btn_type, ODA_DRAWENTIRE ); |
Sheri Steeves | 13ffd58 | 2000-06-11 20:08:46 +0000 | [diff] [blame] | 378 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 379 | break; |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 380 | |
Dmitry Timoshkov | 6fb62f5 | 2000-01-29 22:09:40 +0000 | [diff] [blame] | 381 | case BM_CLICK: |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 382 | SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 ); |
| 383 | SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 ); |
Dmitry Timoshkov | 6fb62f5 | 2000-01-29 22:09:40 +0000 | [diff] [blame] | 384 | break; |
| 385 | |
Pascal Lessard | 026f705 | 1999-04-15 15:49:36 +0000 | [diff] [blame] | 386 | case BM_SETIMAGE: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 387 | /* 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 Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 399 | oldHbitmap = (HBITMAP)SetWindowLongA( hWnd, HIMAGE_GWL_OFFSET, lParam ); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 400 | InvalidateRect( hWnd, NULL, FALSE ); |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 401 | return (LRESULT)oldHbitmap; |
Pascal Lessard | 026f705 | 1999-04-15 15:49:36 +0000 | [diff] [blame] | 402 | |
| 403 | case BM_GETIMAGE: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 404 | return GetWindowLongA( hWnd, HIMAGE_GWL_OFFSET ); |
Pascal Lessard | 026f705 | 1999-04-15 15:49:36 +0000 | [diff] [blame] | 405 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 406 | case BM_GETCHECK16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 407 | case BM_GETCHECK: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 408 | return get_button_state( hWnd ) & 3; |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 409 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 410 | case BM_SETCHECK16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 411 | case BM_SETCHECK: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 412 | if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type]; |
| 413 | state = get_button_state( hWnd ); |
Bill Medland | b153725 | 2001-12-11 00:16:23 +0000 | [diff] [blame] | 414 | 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 420 | if ((state & 3) != wParam) |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 421 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 422 | set_button_state( hWnd, (state & ~3) | wParam ); |
| 423 | paint_button( hWnd, btn_type, ODA_SELECT ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 424 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 425 | if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED) && (style & WS_CHILD)) |
| 426 | BUTTON_CheckAutoRadioButton( hWnd ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 427 | break; |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 428 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 429 | case BM_GETSTATE16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 430 | case BM_GETSTATE: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 431 | return get_button_state( hWnd ); |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 432 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 433 | case BM_SETSTATE16: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 434 | case BM_SETSTATE: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 435 | state = get_button_state( hWnd ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 436 | if (wParam) |
| 437 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 438 | if (state & BUTTON_HIGHLIGHTED) break; |
| 439 | set_button_state( hWnd, state | BUTTON_HIGHLIGHTED ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 440 | } |
| 441 | else |
| 442 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 443 | if (!(state & BUTTON_HIGHLIGHTED)) break; |
| 444 | set_button_state( hWnd, state & ~BUTTON_HIGHLIGHTED ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 445 | } |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 446 | paint_button( hWnd, btn_type, ODA_SELECT ); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 447 | break; |
| 448 | |
Alexandre Julliard | 9877906 | 2000-12-07 23:39:16 +0000 | [diff] [blame] | 449 | case WM_NCHITTEST: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 450 | if(btn_type == BS_GROUPBOX) return HTTRANSPARENT; |
Alexandre Julliard | 9877906 | 2000-12-07 23:39:16 +0000 | [diff] [blame] | 451 | /* fall through */ |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 452 | default: |
Alexandre Julliard | 9877906 | 2000-12-07 23:39:16 +0000 | [diff] [blame] | 453 | return unicode ? DefWindowProcW(hWnd, uMsg, wParam, lParam) : |
| 454 | DefWindowProcA(hWnd, uMsg, wParam, lParam); |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 455 | } |
| 456 | return 0; |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 459 | /*********************************************************************** |
Alexandre Julliard | 9877906 | 2000-12-07 23:39:16 +0000 | [diff] [blame] | 460 | * ButtonWndProcW |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 461 | * 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 Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 465 | static LRESULT WINAPI ButtonWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 466 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 467 | if (!IsWindow( hWnd )) return 0; |
| 468 | return ButtonWndProc_common( hWnd, uMsg, wParam, lParam, TRUE ); |
Marcus Meissner | 9aded51 | 1999-05-01 10:23:45 +0000 | [diff] [blame] | 469 | } |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 470 | |
Alexandre Julliard | 9877906 | 2000-12-07 23:39:16 +0000 | [diff] [blame] | 471 | |
| 472 | /*********************************************************************** |
| 473 | * ButtonWndProcA |
| 474 | */ |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 475 | static LRESULT WINAPI ButtonWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) |
Alexandre Julliard | 9877906 | 2000-12-07 23:39:16 +0000 | [diff] [blame] | 476 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 477 | if (!IsWindow( hWnd )) return 0; |
| 478 | return ButtonWndProc_common( hWnd, uMsg, wParam, lParam, FALSE ); |
Alexandre Julliard | 9877906 | 2000-12-07 23:39:16 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 482 | /********************************************************************** |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 483 | * Convert button styles to flags used by DrawText. |
| 484 | * TODO: handle WS_EX_RIGHT extended style. |
| 485 | */ |
| 486 | static 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 506 | if (get_button_type(style) <= BS_DEFPUSHBUTTON) dtStyle |= DT_CENTER; |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 507 | /* 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 513 | if (get_button_type(style) != BS_GROUPBOX) |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 514 | { |
| 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 540 | static UINT BUTTON_CalcLabelRect(HWND hwnd, HDC hdc, RECT *rc) |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 541 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 542 | LONG style = GetWindowLongA( hwnd, GWL_STYLE ); |
| 543 | WCHAR *text; |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 544 | ICONINFO iconInfo; |
| 545 | BITMAP bm; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 546 | UINT dtStyle = BUTTON_BStoDT(style); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 547 | RECT r = *rc; |
| 548 | INT n; |
| 549 | |
| 550 | /* Calculate label rectangle according to label type */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 551 | switch (style & (BS_ICON|BS_BITMAP)) |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 552 | { |
| 553 | case BS_TEXT: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 554 | 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 Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 563 | |
| 564 | case BS_ICON: |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 565 | if (!GetIconInfo((HICON)GetWindowLongA( hwnd, HIMAGE_GWL_OFFSET ), &iconInfo)) |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 566 | goto empty_rect; |
| 567 | |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 568 | GetObjectW (iconInfo.hbmColor, sizeof(BITMAP), &bm); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 569 | |
| 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 578 | if (!GetObjectW( (HANDLE)GetWindowLongA( hwnd, HIMAGE_GWL_OFFSET ), sizeof(BITMAP), &bm)) |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 579 | 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éron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 586 | empty_rect: |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 587 | 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 Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 629 | * Callback function used by DrawStateW function. |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 630 | */ |
| 631 | static BOOL CALLBACK BUTTON_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy) |
| 632 | { |
Joerg Mayer | abe635c | 2000-11-11 00:38:37 +0000 | [diff] [blame] | 633 | RECT rc; |
| 634 | rc.left = 0; |
| 635 | rc.top = 0; |
| 636 | rc.right = cx; |
| 637 | rc.bottom = cy; |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 638 | |
| 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 649 | static void BUTTON_DrawLabel(HWND hwnd, HDC hdc, UINT dtFlags, RECT *rc) |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 650 | { |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 651 | DRAWSTATEPROC lpOutputProc = NULL; |
| 652 | LPARAM lp; |
| 653 | WPARAM wp = 0; |
| 654 | HBRUSH hbr = 0; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 655 | 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 Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 659 | |
Dimitrie O. Paun | 693cca5 | 2002-01-29 03:12:19 +0000 | [diff] [blame] | 660 | /* FIXME: To draw disabled label in Win31 look-and-feel, we probably |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 661 | * 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 665 | if ((style & BS_PUSHLIKE) && (state & BUTTON_3STATE)) |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 666 | { |
| 667 | hbr = GetSysColorBrush(COLOR_GRAYTEXT); |
| 668 | flags |= DSS_MONO; |
| 669 | } |
| 670 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 671 | switch (style & (BS_ICON|BS_BITMAP)) |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 672 | { |
| 673 | case BS_TEXT: |
| 674 | /* DST_COMPLEX -- is 0 */ |
| 675 | lpOutputProc = BUTTON_DrawTextCallback; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 676 | if (!(text = get_button_text( hwnd ))) return; |
| 677 | lp = (LPARAM)text; |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 678 | wp = (WPARAM)dtFlags; |
| 679 | break; |
| 680 | |
| 681 | case BS_ICON: |
| 682 | flags |= DST_ICON; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 683 | lp = GetWindowLongA( hwnd, HIMAGE_GWL_OFFSET ); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 684 | break; |
| 685 | |
| 686 | case BS_BITMAP: |
| 687 | flags |= DST_BITMAP; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 688 | lp = GetWindowLongA( hwnd, HIMAGE_GWL_OFFSET ); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 689 | 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 697 | if (text) HeapFree( GetProcessHeap(), 0, text ); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | /********************************************************************** |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 701 | * Push Button Functions |
Francis Beaudet | 9b4748b | 1999-07-18 15:29:43 +0000 | [diff] [blame] | 702 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 703 | static void PB_Paint( HWND hwnd, HDC hDC, UINT action ) |
Francis Beaudet | 9b4748b | 1999-07-18 15:29:43 +0000 | [diff] [blame] | 704 | { |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 705 | RECT rc, focus_rect, r; |
| 706 | UINT dtFlags; |
| 707 | HRGN hRgn; |
| 708 | HPEN hOldPen; |
| 709 | HBRUSH hOldBrush; |
| 710 | INT oldBkMode; |
| 711 | COLORREF oldTxtColor; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 712 | HFONT hFont; |
| 713 | LONG state = get_button_state( hwnd ); |
| 714 | LONG style = GetWindowLongA( hwnd, GWL_STYLE ); |
| 715 | BOOL pushedState = (state & BUTTON_HIGHLIGHTED); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 716 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 717 | GetClientRect( hwnd, &rc ); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 718 | |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 719 | /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 720 | if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 721 | SendMessageW( GetParent(hwnd), WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd ); |
Alexandre Julliard | 4344c36 | 2002-05-20 18:15:28 +0000 | [diff] [blame] | 722 | hOldPen = (HPEN)SelectObject(hDC, SYSCOLOR_GetPen(COLOR_WINDOWFRAME)); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 723 | hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE)); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 724 | oldBkMode = SetBkMode(hDC, TRANSPARENT); |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 725 | |
| 726 | if ( TWEAK_WineLook == WIN31_LOOK) |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 727 | { |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 728 | COLORREF clr_wnd = GetSysColor(COLOR_WINDOW); |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 729 | Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); |
| 730 | |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 731 | 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örklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 735 | InflateRect( &rc, -1, -1 ); |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 736 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 737 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 738 | if (get_button_type(style) == BS_DEFPUSHBUTTON) |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 739 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 740 | Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 741 | InflateRect( &rc, -1, -1 ); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 744 | if (TWEAK_WineLook == WIN31_LOOK) |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 745 | { |
Francis Beaudet | 9b4748b | 1999-07-18 15:29:43 +0000 | [diff] [blame] | 746 | if (pushedState) |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 747 | { |
| 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örklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 752 | } else { |
| 753 | rc.right++, rc.bottom++; |
| 754 | DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT ); |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 755 | rc.right--, rc.bottom--; |
| 756 | } |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 757 | } |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 758 | else |
| 759 | { |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 760 | UINT uState = DFCS_BUTTONPUSH | DFCS_ADJUSTRECT; |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 761 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 762 | if (style & BS_FLAT) |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 763 | uState |= DFCS_MONO; |
| 764 | else if (pushedState) |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 765 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 766 | if (get_button_type(style) == BS_DEFPUSHBUTTON ) |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 767 | uState |= DFCS_FLAT; |
| 768 | else |
| 769 | uState |= DFCS_PUSHED; |
| 770 | } |
| 771 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 772 | if (state & (BUTTON_CHECKED | BUTTON_3STATE)) |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 773 | uState |= DFCS_CHECKED; |
| 774 | |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 775 | DrawFrameControl( hDC, &rc, DFC_BUTTON, uState ); |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 776 | |
| 777 | focus_rect = rc; |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 778 | } |
| 779 | |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 780 | /* draw button label */ |
| 781 | r = rc; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 782 | dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &r); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 783 | |
| 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 Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 791 | { |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 792 | focus_rect = r; |
| 793 | InflateRect(&focus_rect, 2, 0); |
Pascal Lessard | 026f705 | 1999-04-15 15:49:36 +0000 | [diff] [blame] | 794 | } |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 795 | |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 796 | hRgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom); |
| 797 | SelectClipRgn(hDC, hRgn); |
| 798 | |
| 799 | oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) ); |
| 800 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 801 | BUTTON_DrawLabel(hwnd, hDC, dtFlags, &r); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 802 | |
| 803 | SetTextColor( hDC, oldTxtColor ); |
| 804 | SelectClipRgn(hDC, 0); |
| 805 | DeleteObject(hRgn); |
| 806 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 807 | if (state & BUTTON_HASFOCUS) |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 808 | { |
| 809 | InflateRect( &focus_rect, -1, -1 ); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 810 | IntersectRect(&focus_rect, &focus_rect, &rc); |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 811 | DrawFocusRect( hDC, &focus_rect ); |
| 812 | } |
| 813 | |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 814 | cleanup: |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 815 | SelectObject( hDC, hOldPen ); |
| 816 | SelectObject( hDC, hOldBrush ); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 817 | SetBkMode(hDC, oldBkMode); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 820 | /********************************************************************** |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 821 | * Check Box & Radio Button Functions |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 822 | */ |
| 823 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 824 | static void CB_Paint( HWND hwnd, HDC hDC, UINT action ) |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 825 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 826 | RECT rbox, rtext, client; |
| 827 | HBRUSH hBrush; |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 828 | int delta; |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 829 | UINT dtFlags; |
| 830 | HRGN hRgn; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 831 | HFONT hFont; |
| 832 | LONG state = get_button_state( hwnd ); |
| 833 | LONG style = GetWindowLongA( hwnd, GWL_STYLE ); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 834 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 835 | if (style & BS_PUSHLIKE) |
Francis Beaudet | 9b4748b | 1999-07-18 15:29:43 +0000 | [diff] [blame] | 836 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 837 | PB_Paint( hwnd, hDC, action ); |
Patrik Stridvall | 0e38aa7 | 1999-07-31 17:34:43 +0000 | [diff] [blame] | 838 | return; |
Francis Beaudet | 9b4748b | 1999-07-18 15:29:43 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 841 | GetClientRect(hwnd, &client); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 842 | rbox = rtext = client; |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 843 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 844 | if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 845 | |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 846 | hBrush = (HBRUSH)SendMessageW(GetParent(hwnd), WM_CTLCOLORSTATIC, |
| 847 | (WPARAM)hDC, (LPARAM)hwnd); |
Alexandre Julliard | d23a82b | 2001-09-19 20:37:04 +0000 | [diff] [blame] | 848 | if (!hBrush) /* did the app forget to call defwindowproc ? */ |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 849 | hBrush = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC, |
| 850 | (WPARAM)hDC, (LPARAM)hwnd ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 851 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 852 | if (style & BS_LEFTTEXT) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 853 | { |
| 854 | /* magic +4 is what CTL3D expects */ |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 855 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 856 | rtext.right -= checkBoxWidth + 4; |
| 857 | rbox.left = rbox.right - checkBoxWidth; |
| 858 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 859 | else |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 860 | { |
| 861 | rtext.left += checkBoxWidth + 4; |
| 862 | rbox.right = checkBoxWidth; |
| 863 | } |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 864 | |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 865 | /* Draw the check-box bitmap */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 866 | if (action == ODA_DRAWENTIRE || action == ODA_SELECT) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 867 | { |
Dmitry Timoshkov | b32c000 | 2001-02-23 01:32:05 +0000 | [diff] [blame] | 868 | /* 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örklund | 9af3eba | 1999-09-13 16:06:17 +0000 | [diff] [blame] | 872 | if( TWEAK_WineLook == WIN31_LOOK ) |
| 873 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 874 | HDC hMemDC = CreateCompatibleDC( hDC ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 875 | int x = 0, y = 0; |
Francis Beaudet | f22ff40 | 1999-09-03 12:35:18 +0000 | [diff] [blame] | 876 | 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 Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 880 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 881 | 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 Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 886 | |
Francis Beaudet | 4993603 | 1999-09-03 15:07:21 +0000 | [diff] [blame] | 887 | /* The bitmap for the radio button is not aligned with the |
| 888 | * left of the window, it is 1 pixel off. */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 889 | if ((get_button_type(style) == BS_RADIOBUTTON) || |
| 890 | (get_button_type(style) == BS_AUTORADIOBUTTON)) |
Francis Beaudet | 4993603 | 1999-09-03 15:07:21 +0000 | [diff] [blame] | 891 | rbox.left += 1; |
| 892 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 893 | SelectObject( hMemDC, hbitmapCheckBoxes ); |
| 894 | BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth, |
Huw D M Davies | 2d617be | 1998-12-08 09:14:09 +0000 | [diff] [blame] | 895 | checkBoxHeight, hMemDC, x, y, SRCCOPY ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 896 | DeleteDC( hMemDC ); |
Dennis Björklund | 9af3eba | 1999-09-13 16:06:17 +0000 | [diff] [blame] | 897 | } |
| 898 | else |
| 899 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 900 | UINT flags; |
Dennis Björklund | 9af3eba | 1999-09-13 16:06:17 +0000 | [diff] [blame] | 901 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 902 | 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örklund | 9af3eba | 1999-09-13 16:06:17 +0000 | [diff] [blame] | 906 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 907 | if (state & (BUTTON_CHECKED | BUTTON_3STATE)) flags |= DFCS_CHECKED; |
| 908 | if (state & BUTTON_HIGHLIGHTED) flags |= DFCS_PUSHED; |
Dennis Björklund | 9af3eba | 1999-09-13 16:06:17 +0000 | [diff] [blame] | 909 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 910 | if (style & WS_DISABLED) flags |= DFCS_INACTIVE; |
Dennis Björklund | 9af3eba | 1999-09-13 16:06:17 +0000 | [diff] [blame] | 911 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 912 | /* rbox must have the correct height */ |
Susan Farley | b09c6ef | 2000-06-04 01:32:59 +0000 | [diff] [blame] | 913 | delta = rbox.bottom - rbox.top - checkBoxHeight; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 914 | if (delta > 0) |
| 915 | { |
Susan Farley | b09c6ef | 2000-06-04 01:32:59 +0000 | [diff] [blame] | 916 | 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 927 | DrawFrameControl( hDC, &rbox, DFC_BUTTON, flags ); |
Dennis Björklund | 9af3eba | 1999-09-13 16:06:17 +0000 | [diff] [blame] | 928 | } |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 929 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 930 | |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 931 | /* Draw label */ |
| 932 | client = rtext; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 933 | dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rtext); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 934 | |
| 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 942 | BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rtext); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 943 | |
| 944 | /* ... and focus */ |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 945 | if ((action == ODA_FOCUS) || |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 946 | ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS))) |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 947 | { |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 948 | rtext.left--; |
| 949 | rtext.right++; |
| 950 | IntersectRect(&rtext, &rtext, &client); |
| 951 | DrawFocusRect( hDC, &rtext ); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 952 | } |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 953 | SelectClipRgn(hDC, 0); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 954 | } |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 955 | |
| 956 | |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 957 | /********************************************************************** |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 958 | * BUTTON_CheckAutoRadioButton |
| 959 | * |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 960 | * hwnd is checked, uncheck every other auto radio button in group |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 961 | */ |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 962 | static void BUTTON_CheckAutoRadioButton( HWND hwnd ) |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 963 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 964 | HWND parent, sibling, start; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 965 | |
| 966 | parent = GetParent(hwnd); |
| 967 | /* make sure that starting control is not disabled or invisible */ |
| 968 | start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 969 | do |
| 970 | { |
| 971 | if (!sibling) break; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 972 | if ((hwnd != sibling) && |
| 973 | ((GetWindowLongA( sibling, GWL_STYLE) & 0x0f) == BS_AUTORADIOBUTTON)) |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 974 | SendMessageW( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 975 | sibling = GetNextDlgGroupItem( parent, sibling, FALSE ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 976 | } while (sibling != start); |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | |
| 980 | /********************************************************************** |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 981 | * Group Box Functions |
| 982 | */ |
| 983 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 984 | static void GB_Paint( HWND hwnd, HDC hDC, UINT action ) |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 985 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 986 | RECT rc, rcFrame; |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 987 | HBRUSH hbr; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 988 | HFONT hFont; |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 989 | UINT dtFlags; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 990 | LONG style = GetWindowLongA( hwnd, GWL_STYLE ); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 991 | |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 992 | if (action != ODA_DRAWENTIRE) return; |
| 993 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 994 | if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 995 | /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */ |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 996 | hbr = (HBRUSH)SendMessageW(GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd); |
Alexandre Julliard | d23a82b | 2001-09-19 20:37:04 +0000 | [diff] [blame] | 997 | if (!hbr) /* did the app forget to call defwindowproc ? */ |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 998 | hbr = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC, |
| 999 | (WPARAM)hDC, (LPARAM)hwnd); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 1000 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1001 | GetClientRect( hwnd, &rc); |
Huw D M Davies | 2d617be | 1998-12-08 09:14:09 +0000 | [diff] [blame] | 1002 | if (TWEAK_WineLook == WIN31_LOOK) { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1003 | HPEN hPrevPen = SelectObject( hDC, |
Alexandre Julliard | 4344c36 | 2002-05-20 18:15:28 +0000 | [diff] [blame] | 1004 | SYSCOLOR_GetPen(COLOR_WINDOWFRAME)); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1005 | HBRUSH hPrevBrush = SelectObject( hDC, |
| 1006 | GetStockObject(NULL_BRUSH) ); |
Huw D M Davies | 2d617be | 1998-12-08 09:14:09 +0000 | [diff] [blame] | 1007 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1008 | Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 ); |
| 1009 | SelectObject( hDC, hPrevBrush ); |
| 1010 | SelectObject( hDC, hPrevPen ); |
Huw D M Davies | 2d617be | 1998-12-08 09:14:09 +0000 | [diff] [blame] | 1011 | } else { |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 1012 | TEXTMETRICW tm; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1013 | rcFrame = rc; |
| 1014 | |
Dmitry Timoshkov | 2b4be4b | 2000-11-28 23:51:48 +0000 | [diff] [blame] | 1015 | GetTextMetricsW (hDC, &tm); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1016 | rcFrame.top += (tm.tmHeight / 2) - 1; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1017 | DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT | ((style & BS_FLAT) ? BF_FLAT : 0)); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 1020 | InflateRect(&rc, -7, 1); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1021 | dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rc); |
Serge Ivanov | 6117fc4 | 2000-09-13 00:00:55 +0000 | [diff] [blame] | 1022 | |
| 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 Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1036 | BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rc); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 1037 | } |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 1038 | |
| 1039 | |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 1040 | /********************************************************************** |
| 1041 | * User Button Functions |
| 1042 | */ |
| 1043 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1044 | static void UB_Paint( HWND hwnd, HDC hDC, UINT action ) |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 1045 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1046 | RECT rc; |
| 1047 | HBRUSH hBrush; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1048 | HFONT hFont; |
| 1049 | LONG state = get_button_state( hwnd ); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 1050 | |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 1051 | if (action == ODA_SELECT) return; |
| 1052 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1053 | GetClientRect( hwnd, &rc); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 1054 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1055 | if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); |
Alexandre Julliard | d23a82b | 2001-09-19 20:37:04 +0000 | [diff] [blame] | 1056 | |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 1057 | hBrush = (HBRUSH)SendMessageW(GetParent(hwnd), WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd); |
Alexandre Julliard | d23a82b | 2001-09-19 20:37:04 +0000 | [diff] [blame] | 1058 | if (!hBrush) /* did the app forget to call defwindowproc ? */ |
Michael Stefaniuc | 95591a6 | 2002-10-28 20:11:40 +0000 | [diff] [blame] | 1059 | hBrush = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORBTN, |
| 1060 | (WPARAM)hDC, (LPARAM)hwnd); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 1061 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1062 | FillRect( hDC, &rc, hBrush ); |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 1063 | if ((action == ODA_FOCUS) || |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1064 | ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS))) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1065 | DrawFocusRect( hDC, &rc ); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 1066 | } |
Alexandre Julliard | f0b2354 | 1993-09-29 12:21:49 +0000 | [diff] [blame] | 1067 | |
Alexandre Julliard | e399fc3 | 1993-11-24 17:08:56 +0000 | [diff] [blame] | 1068 | |
| 1069 | /********************************************************************** |
| 1070 | * Ownerdrawn Button Functions |
| 1071 | */ |
| 1072 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1073 | static void OB_Paint( HWND hwnd, HDC hDC, UINT action ) |
Alexandre Julliard | e399fc3 | 1993-11-24 17:08:56 +0000 | [diff] [blame] | 1074 | { |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1075 | LONG state = get_button_state( hwnd ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1076 | DRAWITEMSTRUCT dis; |
Dave Hawkes | fcd3521 | 2000-07-15 21:31:42 +0000 | [diff] [blame] | 1077 | HRGN clipRegion; |
| 1078 | RECT clipRect; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1079 | UINT id = GetWindowLongA( hwnd, GWL_ID ); |
Alexandre Julliard | e399fc3 | 1993-11-24 17:08:56 +0000 | [diff] [blame] | 1080 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1081 | dis.CtlType = ODT_BUTTON; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1082 | dis.CtlID = id; |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1083 | dis.itemID = 0; |
| 1084 | dis.itemAction = action; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1085 | 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 Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 1089 | dis.hDC = hDC; |
| 1090 | dis.itemData = 0; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1091 | GetClientRect( hwnd, &dis.rcItem ); |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 1092 | |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1093 | clipRegion = CreateRectRgnIndirect(&dis.rcItem); |
Dave Hawkes | fcd3521 | 2000-07-15 21:31:42 +0000 | [diff] [blame] | 1094 | if (GetClipRgn(hDC, clipRegion) != 1) |
| 1095 | { |
| 1096 | DeleteObject(clipRegion); |
Francois Gouget | d2667a4 | 2002-12-02 18:10:57 +0000 | [diff] [blame] | 1097 | clipRegion=NULL; |
Dave Hawkes | fcd3521 | 2000-07-15 21:31:42 +0000 | [diff] [blame] | 1098 | } |
| 1099 | clipRect = dis.rcItem; |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1100 | DPtoLP(hDC, (LPPOINT) &clipRect, 2); |
Dave Hawkes | fcd3521 | 2000-07-15 21:31:42 +0000 | [diff] [blame] | 1101 | IntersectClipRect(hDC, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); |
| 1102 | |
Dennis Björklund | 767b099 | 1999-07-15 16:07:19 +0000 | [diff] [blame] | 1103 | SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) ); |
Alexandre Julliard | de42428 | 2001-08-10 22:51:42 +0000 | [diff] [blame] | 1104 | SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis ); |
| 1105 | SelectClipRgn(hDC, clipRegion); |
Alexandre Julliard | e399fc3 | 1993-11-24 17:08:56 +0000 | [diff] [blame] | 1106 | } |