2018-02-06 06:50:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1993 Johannes Ruscheinski
|
|
|
|
* Copyright (C) 1993 David Metcalfe
|
|
|
|
* Copyright (C) 1994 Alexandre Julliard
|
2018-02-11 17:19:53 +01:00
|
|
|
* Copyright (C) 2008 by Reece H. Dunn
|
2018-02-06 06:50:21 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
* TODO
|
|
|
|
* Styles
|
|
|
|
* - BS_NOTIFY: is it complete?
|
|
|
|
* - BS_RIGHTBUTTON: same as BS_LEFTTEXT
|
|
|
|
*
|
|
|
|
* Messages
|
|
|
|
* - WM_CHAR: Checks a (manual or automatic) check box on '+' or '=', clears it on '-' key.
|
|
|
|
* - WM_SETFOCUS: For (manual or automatic) radio buttons, send the parent window BN_CLICKED
|
|
|
|
* - WM_NCCREATE: Turns any BS_OWNERDRAW button into a BS_PUSHBUTTON button.
|
|
|
|
* - WM_SYSKEYUP
|
|
|
|
* - BCM_GETIDEALSIZE
|
|
|
|
* - BCM_GETIMAGELIST
|
|
|
|
* - BCM_GETTEXTMARGIN
|
|
|
|
* - BCM_SETIMAGELIST
|
|
|
|
* - BCM_SETTEXTMARGIN
|
|
|
|
*
|
|
|
|
* Notifications
|
|
|
|
* - BCN_HOTITEMCHANGE
|
|
|
|
* - BN_DISABLE
|
|
|
|
* - BN_PUSHED/BN_HILITE
|
|
|
|
* + BN_KILLFOCUS: is it OK?
|
|
|
|
* - BN_PAINT
|
|
|
|
* + BN_SETFOCUS: is it OK?
|
|
|
|
* - BN_UNPUSHED/BN_UNHILITE
|
|
|
|
* - NM_CUSTOMDRAW
|
|
|
|
*
|
|
|
|
* Structures/Macros/Definitions
|
|
|
|
* - BUTTON_IMAGELIST
|
|
|
|
* - NMBCHOTITEM
|
|
|
|
* - Button_GetIdealSize
|
|
|
|
* - Button_GetImageList
|
|
|
|
* - Button_GetTextMargin
|
|
|
|
* - Button_SetImageList
|
|
|
|
* - Button_SetTextMargin
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define OEMRESOURCE
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
2018-02-11 17:19:53 +01:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "uxtheme.h"
|
|
|
|
#include "vssym32.h"
|
2018-02-06 06:50:21 +01:00
|
|
|
#include "wine/debug.h"
|
2018-02-13 14:19:58 +01:00
|
|
|
#include "wine/heap.h"
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
#include "comctl32.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(button);
|
|
|
|
|
|
|
|
/* undocumented flags */
|
|
|
|
#define BUTTON_NSTATES 0x0F
|
|
|
|
#define BUTTON_BTNPRESSED 0x40
|
|
|
|
#define BUTTON_UNKNOWN2 0x20
|
|
|
|
#define BUTTON_UNKNOWN3 0x10
|
|
|
|
|
|
|
|
#define BUTTON_NOTIFY_PARENT(hWnd, code) \
|
|
|
|
do { /* Notify parent which has created this button control */ \
|
|
|
|
TRACE("notification " #code " sent to hwnd=%p\n", GetParent(hWnd)); \
|
|
|
|
SendMessageW(GetParent(hWnd), WM_COMMAND, \
|
|
|
|
MAKEWPARAM(GetWindowLongPtrW((hWnd),GWLP_ID), (code)), \
|
|
|
|
(LPARAM)(hWnd)); \
|
|
|
|
} while(0)
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
typedef struct _BUTTON_INFO
|
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
LONG state;
|
|
|
|
HFONT font;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
HICON icon;
|
|
|
|
HBITMAP bitmap;
|
|
|
|
HANDLE image;
|
|
|
|
} u;
|
|
|
|
} BUTTON_INFO;
|
|
|
|
|
|
|
|
static UINT BUTTON_CalcLabelRect( const BUTTON_INFO *infoPtr, HDC hdc, RECT *rc );
|
|
|
|
static void PB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action );
|
|
|
|
static void CB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action );
|
|
|
|
static void GB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action );
|
|
|
|
static void UB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action );
|
|
|
|
static void OB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action );
|
2018-02-06 06:50:21 +01:00
|
|
|
static void BUTTON_CheckAutoRadioButton( HWND hwnd );
|
|
|
|
|
|
|
|
#define MAX_BTN_TYPE 16
|
|
|
|
|
|
|
|
static const WORD maxCheckState[MAX_BTN_TYPE] =
|
|
|
|
{
|
|
|
|
BST_UNCHECKED, /* BS_PUSHBUTTON */
|
|
|
|
BST_UNCHECKED, /* BS_DEFPUSHBUTTON */
|
|
|
|
BST_CHECKED, /* BS_CHECKBOX */
|
|
|
|
BST_CHECKED, /* BS_AUTOCHECKBOX */
|
|
|
|
BST_CHECKED, /* BS_RADIOBUTTON */
|
|
|
|
BST_INDETERMINATE, /* BS_3STATE */
|
|
|
|
BST_INDETERMINATE, /* BS_AUTO3STATE */
|
|
|
|
BST_UNCHECKED, /* BS_GROUPBOX */
|
|
|
|
BST_UNCHECKED, /* BS_USERBUTTON */
|
|
|
|
BST_CHECKED, /* BS_AUTORADIOBUTTON */
|
|
|
|
BST_UNCHECKED, /* BS_PUSHBOX */
|
2018-02-06 06:50:22 +01:00
|
|
|
BST_UNCHECKED, /* BS_OWNERDRAW */
|
|
|
|
BST_UNCHECKED, /* BS_SPLITBUTTON */
|
|
|
|
BST_UNCHECKED, /* BS_DEFSPLITBUTTON */
|
|
|
|
BST_UNCHECKED, /* BS_COMMANDLINK */
|
|
|
|
BST_UNCHECKED /* BS_DEFCOMMANDLINK */
|
2018-02-06 06:50:21 +01:00
|
|
|
};
|
|
|
|
|
2018-02-11 17:19:53 +01:00
|
|
|
/* These are indices into a states array to determine the theme state for a given theme part. */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
STATE_NORMAL,
|
|
|
|
STATE_DISABLED,
|
|
|
|
STATE_HOT,
|
|
|
|
STATE_PRESSED,
|
|
|
|
STATE_DEFAULTED
|
|
|
|
} ButtonState;
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
typedef void (*pfPaint)( const BUTTON_INFO *infoPtr, HDC hdc, UINT action );
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
static const pfPaint btnPaintFunc[MAX_BTN_TYPE] =
|
|
|
|
{
|
|
|
|
PB_Paint, /* BS_PUSHBUTTON */
|
|
|
|
PB_Paint, /* BS_DEFPUSHBUTTON */
|
|
|
|
CB_Paint, /* BS_CHECKBOX */
|
|
|
|
CB_Paint, /* BS_AUTOCHECKBOX */
|
|
|
|
CB_Paint, /* BS_RADIOBUTTON */
|
|
|
|
CB_Paint, /* BS_3STATE */
|
|
|
|
CB_Paint, /* BS_AUTO3STATE */
|
|
|
|
GB_Paint, /* BS_GROUPBOX */
|
|
|
|
UB_Paint, /* BS_USERBUTTON */
|
|
|
|
CB_Paint, /* BS_AUTORADIOBUTTON */
|
|
|
|
NULL, /* BS_PUSHBOX */
|
2018-02-06 06:50:22 +01:00
|
|
|
OB_Paint, /* BS_OWNERDRAW */
|
|
|
|
PB_Paint, /* BS_SPLITBUTTON */
|
|
|
|
PB_Paint, /* BS_DEFSPLITBUTTON */
|
|
|
|
PB_Paint, /* BS_COMMANDLINK */
|
|
|
|
PB_Paint /* BS_DEFCOMMANDLINK */
|
2018-02-06 06:50:21 +01:00
|
|
|
};
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
typedef void (*pfThemedPaint)( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused);
|
2018-02-11 17:19:53 +01:00
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
static void PB_ThemedPaint( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused);
|
|
|
|
static void CB_ThemedPaint( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused);
|
|
|
|
static void GB_ThemedPaint( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused);
|
2018-02-11 17:19:53 +01:00
|
|
|
|
|
|
|
static const pfThemedPaint btnThemedPaintFunc[MAX_BTN_TYPE] =
|
|
|
|
{
|
|
|
|
PB_ThemedPaint, /* BS_PUSHBUTTON */
|
|
|
|
PB_ThemedPaint, /* BS_DEFPUSHBUTTON */
|
|
|
|
CB_ThemedPaint, /* BS_CHECKBOX */
|
|
|
|
CB_ThemedPaint, /* BS_AUTOCHECKBOX */
|
|
|
|
CB_ThemedPaint, /* BS_RADIOBUTTON */
|
|
|
|
CB_ThemedPaint, /* BS_3STATE */
|
|
|
|
CB_ThemedPaint, /* BS_AUTO3STATE */
|
|
|
|
GB_ThemedPaint, /* BS_GROUPBOX */
|
|
|
|
NULL, /* BS_USERBUTTON */
|
|
|
|
CB_ThemedPaint, /* BS_AUTORADIOBUTTON */
|
|
|
|
NULL, /* BS_PUSHBOX */
|
|
|
|
NULL, /* BS_OWNERDRAW */
|
|
|
|
NULL, /* BS_SPLITBUTTON */
|
|
|
|
NULL, /* BS_DEFSPLITBUTTON */
|
|
|
|
NULL, /* BS_COMMANDLINK */
|
|
|
|
NULL, /* BS_DEFCOMMANDLINK */
|
|
|
|
};
|
|
|
|
|
2018-02-06 06:50:21 +01:00
|
|
|
static inline UINT get_button_type( LONG window_style )
|
|
|
|
{
|
|
|
|
return (window_style & BS_TYPEMASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* paint a button of any type */
|
2018-02-15 09:00:09 +01:00
|
|
|
static inline void paint_button( BUTTON_INFO *infoPtr, LONG style, UINT action )
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
if (btnPaintFunc[style] && IsWindowVisible(infoPtr->hwnd))
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
HDC hdc = GetDC( infoPtr->hwnd );
|
|
|
|
btnPaintFunc[style]( infoPtr, hdc, action );
|
|
|
|
ReleaseDC( infoPtr->hwnd, hdc );
|
2018-02-06 06:50:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve the button text; returned buffer must be freed by caller */
|
2018-02-15 09:00:09 +01:00
|
|
|
static inline WCHAR *get_button_text( const BUTTON_INFO *infoPtr )
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
INT len = GetWindowTextLengthW( infoPtr->hwnd );
|
2018-02-13 14:19:58 +01:00
|
|
|
WCHAR *buffer = heap_alloc( (len + 1) * sizeof(WCHAR) );
|
2018-02-13 14:19:57 +01:00
|
|
|
if (buffer)
|
2018-02-15 09:00:09 +01:00
|
|
|
GetWindowTextW( infoPtr->hwnd, buffer, len + 1 );
|
2018-02-06 06:50:21 +01:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:37:23 +01:00
|
|
|
HRGN set_control_clipping( HDC hdc, const RECT *rect )
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
|
|
|
RECT rc = *rect;
|
|
|
|
HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
|
|
|
|
|
|
|
|
if (GetClipRgn( hdc, hrgn ) != 1)
|
|
|
|
{
|
|
|
|
DeleteObject( hrgn );
|
|
|
|
hrgn = 0;
|
|
|
|
}
|
|
|
|
DPtoLP( hdc, (POINT *)&rc, 2 );
|
|
|
|
if (GetLayout( hdc ) & LAYOUT_RTL) /* compensate for the shifting done by IntersectClipRect */
|
|
|
|
{
|
|
|
|
rc.left++;
|
|
|
|
rc.right++;
|
|
|
|
}
|
|
|
|
IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom );
|
|
|
|
return hrgn;
|
|
|
|
}
|
|
|
|
|
2018-02-11 17:19:53 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* Convert button styles to flags used by DrawText.
|
|
|
|
*/
|
|
|
|
static UINT BUTTON_BStoDT( DWORD style, DWORD ex_style )
|
|
|
|
{
|
|
|
|
UINT dtStyle = DT_NOCLIP; /* We use SelectClipRgn to limit output */
|
|
|
|
|
|
|
|
/* "Convert" pushlike buttons to pushbuttons */
|
|
|
|
if (style & BS_PUSHLIKE)
|
|
|
|
style &= ~BS_TYPEMASK;
|
|
|
|
|
|
|
|
if (!(style & BS_MULTILINE))
|
|
|
|
dtStyle |= DT_SINGLELINE;
|
|
|
|
else
|
|
|
|
dtStyle |= DT_WORDBREAK;
|
|
|
|
|
|
|
|
switch (style & BS_CENTER)
|
|
|
|
{
|
|
|
|
case BS_LEFT: /* DT_LEFT is 0 */ break;
|
|
|
|
case BS_RIGHT: dtStyle |= DT_RIGHT; break;
|
|
|
|
case BS_CENTER: dtStyle |= DT_CENTER; break;
|
|
|
|
default:
|
|
|
|
/* Pushbutton's text is centered by default */
|
|
|
|
if (get_button_type(style) <= BS_DEFPUSHBUTTON) dtStyle |= DT_CENTER;
|
|
|
|
/* all other flavours have left aligned text */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ex_style & WS_EX_RIGHT) dtStyle = DT_RIGHT | (dtStyle & ~(DT_LEFT | DT_CENTER));
|
|
|
|
|
|
|
|
/* DrawText ignores vertical alignment for multiline text,
|
|
|
|
* but we use these flags to align label manually.
|
|
|
|
*/
|
|
|
|
if (get_button_type(style) != BS_GROUPBOX)
|
|
|
|
{
|
|
|
|
switch (style & BS_VCENTER)
|
|
|
|
{
|
|
|
|
case BS_TOP: /* DT_TOP is 0 */ break;
|
|
|
|
case BS_BOTTOM: dtStyle |= DT_BOTTOM; break;
|
|
|
|
case BS_VCENTER: /* fall through */
|
|
|
|
default: dtStyle |= DT_VCENTER; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* GroupBox's text is always single line and is top aligned. */
|
|
|
|
dtStyle |= DT_SINGLELINE;
|
|
|
|
|
|
|
|
return dtStyle;
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:50:21 +01:00
|
|
|
static LRESULT CALLBACK BUTTON_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
BUTTON_INFO *infoPtr = (BUTTON_INFO *)GetWindowLongPtrW(hWnd, 0);
|
2018-02-06 06:50:21 +01:00
|
|
|
RECT rect;
|
|
|
|
POINT pt;
|
|
|
|
LONG style = GetWindowLongW( hWnd, GWL_STYLE );
|
|
|
|
UINT btn_type = get_button_type( style );
|
2018-02-11 17:19:54 +01:00
|
|
|
LONG state, new_state;
|
2018-02-06 06:50:21 +01:00
|
|
|
HANDLE oldHbitmap;
|
2018-02-11 17:19:53 +01:00
|
|
|
HTHEME theme;
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
if (!IsWindow( hWnd )) return 0;
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
if (!infoPtr && (uMsg != WM_NCCREATE))
|
|
|
|
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
|
|
|
|
2018-02-06 06:50:21 +01:00
|
|
|
pt.x = (short)LOWORD(lParam);
|
|
|
|
pt.y = (short)HIWORD(lParam);
|
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_GETDLGCODE:
|
|
|
|
switch(btn_type)
|
|
|
|
{
|
2018-02-07 14:13:09 +01:00
|
|
|
case BS_COMMANDLINK:
|
2018-02-06 06:50:21 +01:00
|
|
|
case BS_USERBUTTON:
|
|
|
|
case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
|
2018-02-07 14:13:09 +01:00
|
|
|
case BS_DEFCOMMANDLINK:
|
2018-02-06 06:50:21 +01:00
|
|
|
case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
|
|
|
|
case BS_RADIOBUTTON:
|
|
|
|
case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
|
|
|
|
case BS_GROUPBOX: return DLGC_STATIC;
|
2018-02-07 14:13:09 +01:00
|
|
|
case BS_SPLITBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON | DLGC_WANTARROWS;
|
|
|
|
case BS_DEFSPLITBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON | DLGC_WANTARROWS;
|
2018-02-06 06:50:21 +01:00
|
|
|
default: return DLGC_BUTTON;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_ENABLE:
|
2018-02-11 17:19:53 +01:00
|
|
|
theme = GetWindowTheme( hWnd );
|
|
|
|
if (theme)
|
|
|
|
RedrawWindow( hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW );
|
|
|
|
else
|
2018-02-15 09:00:09 +01:00
|
|
|
paint_button( infoPtr, btn_type, ODA_DRAWENTIRE );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_NCCREATE:
|
|
|
|
infoPtr = heap_alloc_zero( sizeof(*infoPtr) );
|
|
|
|
SetWindowLongPtrW( hWnd, 0, (LONG_PTR)infoPtr );
|
|
|
|
infoPtr->hwnd = hWnd;
|
|
|
|
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
|
|
|
|
|
|
|
case WM_NCDESTROY:
|
|
|
|
SetWindowLongPtrW( hWnd, 0, 0 );
|
|
|
|
heap_free(infoPtr);
|
2018-02-06 06:50:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CREATE:
|
|
|
|
if (btn_type >= MAX_BTN_TYPE)
|
|
|
|
return -1; /* abort */
|
|
|
|
|
|
|
|
/* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
|
|
|
|
if (btn_type == BS_USERBUTTON )
|
|
|
|
{
|
|
|
|
style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON;
|
|
|
|
SetWindowLongW( hWnd, GWL_STYLE, style );
|
|
|
|
}
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->state = BST_UNCHECKED;
|
2018-02-11 17:19:53 +01:00
|
|
|
OpenThemeData( hWnd, WC_BUTTONW );
|
2018-02-06 06:50:21 +01:00
|
|
|
return 0;
|
|
|
|
|
2018-02-11 17:19:53 +01:00
|
|
|
case WM_DESTROY:
|
|
|
|
theme = GetWindowTheme( hWnd );
|
|
|
|
CloseThemeData( theme );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_THEMECHANGED:
|
|
|
|
theme = GetWindowTheme( hWnd );
|
|
|
|
CloseThemeData( theme );
|
|
|
|
OpenThemeData( hWnd, WC_BUTTONW );
|
|
|
|
break;
|
|
|
|
|
2018-02-06 06:50:21 +01:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
if (btn_type == BS_OWNERDRAW)
|
|
|
|
{
|
|
|
|
HDC hdc = (HDC)wParam;
|
|
|
|
RECT rc;
|
|
|
|
HBRUSH hBrush;
|
|
|
|
HWND parent = GetParent(hWnd);
|
|
|
|
if (!parent) parent = hWnd;
|
|
|
|
hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hdc, (LPARAM)hWnd);
|
|
|
|
if (!hBrush) /* did the app forget to call defwindowproc ? */
|
|
|
|
hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN,
|
|
|
|
(WPARAM)hdc, (LPARAM)hWnd);
|
|
|
|
GetClientRect(hWnd, &rc);
|
|
|
|
FillRect(hdc, &rc, hBrush);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case WM_PRINTCLIENT:
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
|
|
|
PAINTSTRUCT ps;
|
2018-02-11 17:19:53 +01:00
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
theme = GetWindowTheme( hWnd );
|
|
|
|
hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
|
|
|
|
|
2018-02-14 12:05:15 +01:00
|
|
|
if (theme && btnThemedPaintFunc[btn_type])
|
2018-02-11 17:19:53 +01:00
|
|
|
{
|
|
|
|
ButtonState drawState;
|
|
|
|
UINT dtflags;
|
|
|
|
|
|
|
|
if (IsWindowEnabled( hWnd ))
|
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
if (infoPtr->state & BST_PUSHED) drawState = STATE_PRESSED;
|
|
|
|
else if (infoPtr->state & BST_HOT) drawState = STATE_HOT;
|
|
|
|
else if (infoPtr->state & BST_FOCUS) drawState = STATE_DEFAULTED;
|
2018-02-11 17:19:53 +01:00
|
|
|
else drawState = STATE_NORMAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
drawState = STATE_DISABLED;
|
|
|
|
|
|
|
|
dtflags = BUTTON_BStoDT(style, GetWindowLongW(hWnd, GWL_EXSTYLE));
|
2018-02-15 09:00:09 +01:00
|
|
|
btnThemedPaintFunc[btn_type](theme, infoPtr, hdc, drawState, dtflags, infoPtr->state & BST_FOCUS);
|
2018-02-11 17:19:53 +01:00
|
|
|
}
|
|
|
|
else if (btnPaintFunc[btn_type])
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
|
|
|
int nOldMode = SetBkMode( hdc, OPAQUE );
|
2018-02-15 09:00:09 +01:00
|
|
|
btnPaintFunc[btn_type]( infoPtr, hdc, ODA_DRAWENTIRE );
|
2018-02-06 06:50:21 +01:00
|
|
|
SetBkMode(hdc, nOldMode); /* reset painting mode */
|
|
|
|
}
|
2018-02-11 17:19:53 +01:00
|
|
|
|
2018-02-06 06:50:21 +01:00
|
|
|
if ( !wParam ) EndPaint( hWnd, &ps );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
if (wParam == VK_SPACE)
|
|
|
|
{
|
|
|
|
SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->state |= BUTTON_BTNPRESSED;
|
2018-02-06 06:50:21 +01:00
|
|
|
SetCapture( hWnd );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_LBUTTONDBLCLK:
|
|
|
|
if(style & BS_NOTIFY ||
|
|
|
|
btn_type == BS_RADIOBUTTON ||
|
|
|
|
btn_type == BS_USERBUTTON ||
|
|
|
|
btn_type == BS_OWNERDRAW)
|
|
|
|
{
|
|
|
|
BUTTON_NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
SetCapture( hWnd );
|
|
|
|
SetFocus( hWnd );
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->state |= BUTTON_BTNPRESSED;
|
2018-02-06 06:50:21 +01:00
|
|
|
SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_KEYUP:
|
|
|
|
if (wParam != VK_SPACE)
|
|
|
|
break;
|
|
|
|
/* fall through */
|
|
|
|
case WM_LBUTTONUP:
|
2018-02-15 09:00:09 +01:00
|
|
|
state = infoPtr->state;
|
2018-02-06 06:50:21 +01:00
|
|
|
if (!(state & BUTTON_BTNPRESSED)) break;
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->state &= BUTTON_NSTATES;
|
2018-02-06 06:50:21 +01:00
|
|
|
if (!(state & BST_PUSHED))
|
|
|
|
{
|
|
|
|
ReleaseCapture();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
|
|
|
|
GetClientRect( hWnd, &rect );
|
|
|
|
if (uMsg == WM_KEYUP || PtInRect( &rect, pt ))
|
|
|
|
{
|
|
|
|
switch(btn_type)
|
|
|
|
{
|
|
|
|
case BS_AUTOCHECKBOX:
|
2018-02-15 09:00:09 +01:00
|
|
|
SendMessageW( hWnd, BM_SETCHECK, !(infoPtr->state & BST_CHECKED), 0 );
|
2018-02-06 06:50:21 +01:00
|
|
|
break;
|
|
|
|
case BS_AUTORADIOBUTTON:
|
|
|
|
SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 );
|
|
|
|
break;
|
|
|
|
case BS_AUTO3STATE:
|
2018-02-15 09:00:09 +01:00
|
|
|
SendMessageW( hWnd, BM_SETCHECK, (infoPtr->state & BST_INDETERMINATE) ? 0 :
|
|
|
|
((infoPtr->state & 3) + 1), 0 );
|
2018-02-06 06:50:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ReleaseCapture();
|
|
|
|
BUTTON_NOTIFY_PARENT(hWnd, BN_CLICKED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ReleaseCapture();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CAPTURECHANGED:
|
|
|
|
TRACE("WM_CAPTURECHANGED %p\n", hWnd);
|
|
|
|
if (hWnd == (HWND)lParam) break;
|
2018-02-15 09:00:09 +01:00
|
|
|
if (infoPtr->state & BUTTON_BTNPRESSED)
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->state &= BUTTON_NSTATES;
|
|
|
|
if (infoPtr->state & BST_PUSHED)
|
|
|
|
SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
|
2018-02-06 06:50:21 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_MOUSEMOVE:
|
2018-02-11 17:19:53 +01:00
|
|
|
{
|
|
|
|
TRACKMOUSEEVENT mouse_event;
|
|
|
|
|
|
|
|
mouse_event.cbSize = sizeof(TRACKMOUSEEVENT);
|
|
|
|
mouse_event.dwFlags = TME_QUERY;
|
|
|
|
if (!TrackMouseEvent(&mouse_event) || !(mouse_event.dwFlags & (TME_HOVER | TME_LEAVE)))
|
|
|
|
{
|
|
|
|
mouse_event.dwFlags = TME_HOVER | TME_LEAVE;
|
|
|
|
mouse_event.hwndTrack = hWnd;
|
|
|
|
mouse_event.dwHoverTime = 1;
|
|
|
|
TrackMouseEvent(&mouse_event);
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:50:21 +01:00
|
|
|
if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
|
|
|
|
{
|
|
|
|
GetClientRect( hWnd, &rect );
|
|
|
|
SendMessageW( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
|
|
|
|
}
|
|
|
|
break;
|
2018-02-11 17:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSEHOVER:
|
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->state |= BST_HOT;
|
2018-02-11 17:19:53 +01:00
|
|
|
InvalidateRect( hWnd, NULL, FALSE );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->state &= ~BST_HOT;
|
2018-02-11 17:19:53 +01:00
|
|
|
InvalidateRect( hWnd, NULL, FALSE );
|
|
|
|
break;
|
|
|
|
}
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
case WM_SETTEXT:
|
|
|
|
{
|
|
|
|
/* Clear an old text here as Windows does */
|
|
|
|
if (IsWindowVisible(hWnd))
|
|
|
|
{
|
|
|
|
HDC hdc = GetDC(hWnd);
|
|
|
|
HBRUSH hbrush;
|
|
|
|
RECT client, rc;
|
|
|
|
HWND parent = GetParent(hWnd);
|
|
|
|
UINT message = (btn_type == BS_PUSHBUTTON ||
|
|
|
|
btn_type == BS_DEFPUSHBUTTON ||
|
|
|
|
btn_type == BS_USERBUTTON ||
|
|
|
|
btn_type == BS_OWNERDRAW) ?
|
|
|
|
WM_CTLCOLORBTN : WM_CTLCOLORSTATIC;
|
|
|
|
|
|
|
|
if (!parent) parent = hWnd;
|
|
|
|
hbrush = (HBRUSH)SendMessageW(parent, message,
|
|
|
|
(WPARAM)hdc, (LPARAM)hWnd);
|
|
|
|
if (!hbrush) /* did the app forget to call DefWindowProc ? */
|
|
|
|
hbrush = (HBRUSH)DefWindowProcW(parent, message,
|
|
|
|
(WPARAM)hdc, (LPARAM)hWnd);
|
|
|
|
|
|
|
|
GetClientRect(hWnd, &client);
|
|
|
|
rc = client;
|
|
|
|
/* FIXME: check other BS_* handlers */
|
|
|
|
if (btn_type == BS_GROUPBOX)
|
|
|
|
InflateRect(&rc, -7, 1); /* GB_Paint does this */
|
2018-02-15 09:00:09 +01:00
|
|
|
BUTTON_CalcLabelRect(infoPtr, hdc, &rc);
|
2018-02-06 06:50:21 +01:00
|
|
|
/* Clip by client rect bounds */
|
|
|
|
if (rc.right > client.right) rc.right = client.right;
|
|
|
|
if (rc.bottom > client.bottom) rc.bottom = client.bottom;
|
|
|
|
FillRect(hdc, &rc, hbrush);
|
|
|
|
ReleaseDC(hWnd, hdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam );
|
|
|
|
if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */
|
|
|
|
InvalidateRect( hWnd, NULL, TRUE );
|
|
|
|
else
|
2018-02-15 09:00:09 +01:00
|
|
|
paint_button( infoPtr, btn_type, ODA_DRAWENTIRE );
|
2018-02-06 06:50:21 +01:00
|
|
|
return 1; /* success. FIXME: check text length */
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_SETFONT:
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->font = (HFONT)wParam;
|
2018-02-06 06:50:21 +01:00
|
|
|
if (lParam) InvalidateRect(hWnd, NULL, TRUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_GETFONT:
|
2018-02-15 09:00:09 +01:00
|
|
|
return (LRESULT)infoPtr->font;
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
case WM_SETFOCUS:
|
|
|
|
TRACE("WM_SETFOCUS %p\n",hWnd);
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->state |= BST_FOCUS;
|
|
|
|
paint_button( infoPtr, btn_type, ODA_FOCUS );
|
2018-02-06 06:50:21 +01:00
|
|
|
if (style & BS_NOTIFY)
|
|
|
|
BUTTON_NOTIFY_PARENT(hWnd, BN_SETFOCUS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_KILLFOCUS:
|
|
|
|
TRACE("WM_KILLFOCUS %p\n",hWnd);
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->state &= ~BST_FOCUS;
|
|
|
|
paint_button( infoPtr, btn_type, ODA_FOCUS );
|
2018-02-06 06:50:21 +01:00
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
if ((infoPtr->state & BUTTON_BTNPRESSED) && GetCapture() == hWnd)
|
2018-02-06 06:50:21 +01:00
|
|
|
ReleaseCapture();
|
|
|
|
if (style & BS_NOTIFY)
|
|
|
|
BUTTON_NOTIFY_PARENT(hWnd, BN_KILLFOCUS);
|
|
|
|
|
|
|
|
InvalidateRect( hWnd, NULL, FALSE );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SYSCOLORCHANGE:
|
|
|
|
InvalidateRect( hWnd, NULL, FALSE );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BM_SETSTYLE:
|
|
|
|
btn_type = wParam & BS_TYPEMASK;
|
|
|
|
style = (style & ~BS_TYPEMASK) | btn_type;
|
|
|
|
SetWindowLongW( hWnd, GWL_STYLE, style );
|
|
|
|
|
|
|
|
/* Only redraw if lParam flag is set.*/
|
|
|
|
if (lParam)
|
|
|
|
InvalidateRect( hWnd, NULL, TRUE );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BM_CLICK:
|
|
|
|
SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 );
|
|
|
|
SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BM_SETIMAGE:
|
|
|
|
/* Check that image format matches button style */
|
|
|
|
switch (style & (BS_BITMAP|BS_ICON))
|
|
|
|
{
|
|
|
|
case BS_BITMAP:
|
|
|
|
if (wParam != IMAGE_BITMAP) return 0;
|
|
|
|
break;
|
|
|
|
case BS_ICON:
|
|
|
|
if (wParam != IMAGE_ICON) return 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2018-02-15 09:00:09 +01:00
|
|
|
oldHbitmap = infoPtr->u.image;
|
|
|
|
infoPtr->u.image = (HANDLE)lParam;
|
2018-02-06 06:50:21 +01:00
|
|
|
InvalidateRect( hWnd, NULL, FALSE );
|
|
|
|
return (LRESULT)oldHbitmap;
|
|
|
|
|
|
|
|
case BM_GETIMAGE:
|
2018-02-15 09:00:09 +01:00
|
|
|
return (LRESULT)infoPtr->u.image;
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
case BM_GETCHECK:
|
2018-02-15 09:00:09 +01:00
|
|
|
return infoPtr->state & 3;
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
case BM_SETCHECK:
|
|
|
|
if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type];
|
|
|
|
if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON))
|
|
|
|
{
|
|
|
|
style = wParam ? style | WS_TABSTOP : style & ~WS_TABSTOP;
|
|
|
|
SetWindowLongW( hWnd, GWL_STYLE, style );
|
|
|
|
}
|
2018-02-15 09:00:09 +01:00
|
|
|
if ((infoPtr->state & 3) != wParam)
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->state = (infoPtr->state & ~3) | wParam;
|
2018-02-11 17:19:55 +01:00
|
|
|
InvalidateRect( hWnd, NULL, FALSE );
|
2018-02-06 06:50:21 +01:00
|
|
|
}
|
|
|
|
if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD))
|
|
|
|
BUTTON_CheckAutoRadioButton( hWnd );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BM_GETSTATE:
|
2018-02-15 09:00:09 +01:00
|
|
|
return infoPtr->state;
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
case BM_SETSTATE:
|
2018-02-15 09:00:09 +01:00
|
|
|
state = infoPtr->state;
|
2018-02-11 17:19:54 +01:00
|
|
|
new_state = wParam ? BST_PUSHED : 0;
|
|
|
|
|
|
|
|
if ((state ^ new_state) & BST_PUSHED)
|
|
|
|
{
|
|
|
|
if (wParam)
|
|
|
|
state |= BST_PUSHED;
|
|
|
|
else
|
|
|
|
state &= ~BST_PUSHED;
|
2018-02-06 06:50:21 +01:00
|
|
|
|
2018-02-11 17:19:54 +01:00
|
|
|
if (btn_type == BS_USERBUTTON)
|
|
|
|
BUTTON_NOTIFY_PARENT( hWnd, (state & BST_PUSHED) ? BN_HILITE : BN_UNHILITE );
|
2018-02-15 09:00:09 +01:00
|
|
|
infoPtr->state = state;
|
2018-02-11 17:19:54 +01:00
|
|
|
|
|
|
|
InvalidateRect( hWnd, NULL, FALSE );
|
|
|
|
}
|
2018-02-06 06:50:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_NCHITTEST:
|
|
|
|
if(btn_type == BS_GROUPBOX) return HTTRANSPARENT;
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* BUTTON_CalcLabelRect
|
|
|
|
*
|
|
|
|
* Calculates label's rectangle depending on button style.
|
|
|
|
*
|
|
|
|
* Returns flags to be passed to DrawText.
|
|
|
|
* Calculated rectangle doesn't take into account button state
|
|
|
|
* (pushed, etc.). If there is nothing to draw (no text/image) output
|
|
|
|
* rectangle is empty, and return value is (UINT)-1.
|
|
|
|
*/
|
2018-02-15 09:00:09 +01:00
|
|
|
static UINT BUTTON_CalcLabelRect(const BUTTON_INFO *infoPtr, HDC hdc, RECT *rc)
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
|
|
|
|
LONG ex_style = GetWindowLongW( infoPtr->hwnd, GWL_EXSTYLE );
|
2018-02-06 06:50:21 +01:00
|
|
|
WCHAR *text;
|
|
|
|
ICONINFO iconInfo;
|
|
|
|
BITMAP bm;
|
|
|
|
UINT dtStyle = BUTTON_BStoDT( style, ex_style );
|
|
|
|
RECT r = *rc;
|
|
|
|
INT n;
|
|
|
|
|
|
|
|
/* Calculate label rectangle according to label type */
|
|
|
|
switch (style & (BS_ICON|BS_BITMAP))
|
|
|
|
{
|
|
|
|
case BS_TEXT:
|
|
|
|
{
|
|
|
|
HFONT hFont, hPrevFont = 0;
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
if (!(text = get_button_text( infoPtr ))) goto empty_rect;
|
2018-02-06 06:50:21 +01:00
|
|
|
if (!text[0])
|
|
|
|
{
|
2018-02-13 14:19:58 +01:00
|
|
|
heap_free( text );
|
2018-02-06 06:50:21 +01:00
|
|
|
goto empty_rect;
|
|
|
|
}
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
if ((hFont = infoPtr->font)) hPrevFont = SelectObject( hdc, hFont );
|
2018-02-06 06:50:21 +01:00
|
|
|
DrawTextW(hdc, text, -1, &r, dtStyle | DT_CALCRECT);
|
|
|
|
if (hPrevFont) SelectObject( hdc, hPrevFont );
|
2018-02-13 14:19:58 +01:00
|
|
|
heap_free( text );
|
2018-02-06 06:50:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BS_ICON:
|
2018-02-15 09:00:09 +01:00
|
|
|
if (!GetIconInfo(infoPtr->u.icon, &iconInfo))
|
2018-02-06 06:50:21 +01:00
|
|
|
goto empty_rect;
|
|
|
|
|
|
|
|
GetObjectW (iconInfo.hbmColor, sizeof(BITMAP), &bm);
|
|
|
|
|
|
|
|
r.right = r.left + bm.bmWidth;
|
|
|
|
r.bottom = r.top + bm.bmHeight;
|
|
|
|
|
|
|
|
DeleteObject(iconInfo.hbmColor);
|
|
|
|
DeleteObject(iconInfo.hbmMask);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BS_BITMAP:
|
2018-02-15 09:00:09 +01:00
|
|
|
if (!GetObjectW( infoPtr->u.bitmap, sizeof(BITMAP), &bm))
|
2018-02-06 06:50:21 +01:00
|
|
|
goto empty_rect;
|
|
|
|
|
|
|
|
r.right = r.left + bm.bmWidth;
|
|
|
|
r.bottom = r.top + bm.bmHeight;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
empty_rect:
|
|
|
|
rc->right = r.left;
|
|
|
|
rc->bottom = r.top;
|
|
|
|
return (UINT)-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Position label inside bounding rectangle according to
|
|
|
|
* alignment flags. (calculated rect is always left-top aligned).
|
|
|
|
* If label is aligned to any side - shift label in opposite
|
|
|
|
* direction to leave extra space for focus rectangle.
|
|
|
|
*/
|
|
|
|
switch (dtStyle & (DT_CENTER|DT_RIGHT))
|
|
|
|
{
|
|
|
|
case DT_LEFT: r.left++; r.right++; break;
|
|
|
|
case DT_CENTER: n = r.right - r.left;
|
|
|
|
r.left = rc->left + ((rc->right - rc->left) - n) / 2;
|
|
|
|
r.right = r.left + n; break;
|
|
|
|
case DT_RIGHT: n = r.right - r.left;
|
|
|
|
r.right = rc->right - 1;
|
|
|
|
r.left = r.right - n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (dtStyle & (DT_VCENTER|DT_BOTTOM))
|
|
|
|
{
|
|
|
|
case DT_TOP: r.top++; r.bottom++; break;
|
|
|
|
case DT_VCENTER: n = r.bottom - r.top;
|
|
|
|
r.top = rc->top + ((rc->bottom - rc->top) - n) / 2;
|
|
|
|
r.bottom = r.top + n; break;
|
|
|
|
case DT_BOTTOM: n = r.bottom - r.top;
|
|
|
|
r.bottom = rc->bottom - 1;
|
|
|
|
r.top = r.bottom - n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*rc = r;
|
|
|
|
return dtStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* BUTTON_DrawTextCallback
|
|
|
|
*
|
|
|
|
* Callback function used by DrawStateW function.
|
|
|
|
*/
|
|
|
|
static BOOL CALLBACK BUTTON_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy)
|
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
|
|
|
|
SetRect(&rc, 0, 0, cx, cy);
|
|
|
|
DrawTextW(hdc, (LPCWSTR)lp, -1, &rc, (UINT)wp);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* BUTTON_DrawLabel
|
|
|
|
*
|
|
|
|
* Common function for drawing button label.
|
|
|
|
*/
|
2018-02-15 09:00:09 +01:00
|
|
|
static void BUTTON_DrawLabel(const BUTTON_INFO *infoPtr, HDC hdc, UINT dtFlags, const RECT *rc)
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
|
|
|
DRAWSTATEPROC lpOutputProc = NULL;
|
|
|
|
LPARAM lp;
|
|
|
|
WPARAM wp = 0;
|
|
|
|
HBRUSH hbr = 0;
|
2018-02-15 09:00:09 +01:00
|
|
|
UINT flags = IsWindowEnabled(infoPtr->hwnd) ? DSS_NORMAL : DSS_DISABLED;
|
|
|
|
LONG state = infoPtr->state;
|
|
|
|
LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
|
2018-02-06 06:50:21 +01:00
|
|
|
WCHAR *text = NULL;
|
|
|
|
|
|
|
|
/* FIXME: To draw disabled label in Win31 look-and-feel, we probably
|
|
|
|
* must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
|
|
|
|
* I don't have Win31 on hand to verify that, so I leave it as is.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((style & BS_PUSHLIKE) && (state & BST_INDETERMINATE))
|
|
|
|
{
|
|
|
|
hbr = GetSysColorBrush(COLOR_GRAYTEXT);
|
|
|
|
flags |= DSS_MONO;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (style & (BS_ICON|BS_BITMAP))
|
|
|
|
{
|
|
|
|
case BS_TEXT:
|
|
|
|
/* DST_COMPLEX -- is 0 */
|
|
|
|
lpOutputProc = BUTTON_DrawTextCallback;
|
2018-02-15 09:00:09 +01:00
|
|
|
if (!(text = get_button_text( infoPtr ))) return;
|
2018-02-06 06:50:21 +01:00
|
|
|
lp = (LPARAM)text;
|
|
|
|
wp = dtFlags;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BS_ICON:
|
|
|
|
flags |= DST_ICON;
|
2018-02-15 09:00:09 +01:00
|
|
|
lp = (LPARAM)infoPtr->u.icon;
|
2018-02-06 06:50:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BS_BITMAP:
|
|
|
|
flags |= DST_BITMAP;
|
2018-02-15 09:00:09 +01:00
|
|
|
lp = (LPARAM)infoPtr->u.bitmap;
|
2018-02-06 06:50:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawStateW(hdc, hbr, lpOutputProc, lp, wp, rc->left, rc->top,
|
|
|
|
rc->right - rc->left, rc->bottom - rc->top, flags);
|
2018-02-13 14:19:58 +01:00
|
|
|
heap_free( text );
|
2018-02-06 06:50:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Push Button Functions
|
|
|
|
*/
|
2018-02-15 09:00:09 +01:00
|
|
|
static void PB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
|
|
|
RECT rc, r;
|
|
|
|
UINT dtFlags, uState;
|
|
|
|
HPEN hOldPen, hpen;
|
|
|
|
HBRUSH hOldBrush;
|
|
|
|
INT oldBkMode;
|
|
|
|
COLORREF oldTxtColor;
|
|
|
|
HFONT hFont;
|
2018-02-15 09:00:09 +01:00
|
|
|
LONG state = infoPtr->state;
|
|
|
|
LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
|
2018-02-06 06:50:21 +01:00
|
|
|
BOOL pushedState = (state & BST_PUSHED);
|
|
|
|
HWND parent;
|
|
|
|
HRGN hrgn;
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
GetClientRect( infoPtr->hwnd, &rc );
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
/* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
|
2018-02-15 09:00:09 +01:00
|
|
|
if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
|
|
|
|
parent = GetParent(infoPtr->hwnd);
|
|
|
|
if (!parent) parent = infoPtr->hwnd;
|
|
|
|
SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)infoPtr->hwnd );
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
hrgn = set_control_clipping( hDC, &rc );
|
|
|
|
|
|
|
|
hpen = CreatePen( PS_SOLID, 1, GetSysColor(COLOR_WINDOWFRAME));
|
|
|
|
hOldPen = SelectObject(hDC, hpen);
|
|
|
|
hOldBrush = SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
|
|
|
|
oldBkMode = SetBkMode(hDC, TRANSPARENT);
|
|
|
|
|
|
|
|
if (get_button_type(style) == BS_DEFPUSHBUTTON)
|
|
|
|
{
|
|
|
|
if (action != ODA_FOCUS)
|
|
|
|
Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
|
|
|
|
InflateRect( &rc, -1, -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* completely skip the drawing if only focus has changed */
|
|
|
|
if (action == ODA_FOCUS) goto draw_focus;
|
|
|
|
|
|
|
|
uState = DFCS_BUTTONPUSH;
|
|
|
|
|
|
|
|
if (style & BS_FLAT)
|
|
|
|
uState |= DFCS_MONO;
|
|
|
|
else if (pushedState)
|
|
|
|
{
|
|
|
|
if (get_button_type(style) == BS_DEFPUSHBUTTON )
|
|
|
|
uState |= DFCS_FLAT;
|
|
|
|
else
|
|
|
|
uState |= DFCS_PUSHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state & (BST_CHECKED | BST_INDETERMINATE))
|
|
|
|
uState |= DFCS_CHECKED;
|
|
|
|
|
|
|
|
DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
|
|
|
|
|
|
|
|
/* draw button label */
|
|
|
|
r = rc;
|
2018-02-15 09:00:09 +01:00
|
|
|
dtFlags = BUTTON_CalcLabelRect(infoPtr, hDC, &r);
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
if (dtFlags == (UINT)-1L)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (pushedState)
|
|
|
|
OffsetRect(&r, 1, 1);
|
|
|
|
|
|
|
|
oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) );
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
BUTTON_DrawLabel(infoPtr, hDC, dtFlags, &r);
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
SetTextColor( hDC, oldTxtColor );
|
|
|
|
|
|
|
|
draw_focus:
|
|
|
|
if (action == ODA_FOCUS || (state & BST_FOCUS))
|
|
|
|
{
|
|
|
|
InflateRect( &rc, -2, -2 );
|
|
|
|
DrawFocusRect( hDC, &rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
SelectObject( hDC, hOldPen );
|
|
|
|
SelectObject( hDC, hOldBrush );
|
|
|
|
SetBkMode(hDC, oldBkMode);
|
|
|
|
SelectClipRgn( hDC, hrgn );
|
|
|
|
if (hrgn) DeleteObject( hrgn );
|
|
|
|
DeleteObject( hpen );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Check Box & Radio Button Functions
|
|
|
|
*/
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
static void CB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
|
|
|
RECT rbox, rtext, client;
|
|
|
|
HBRUSH hBrush;
|
|
|
|
int delta, text_offset, checkBoxWidth, checkBoxHeight;
|
|
|
|
UINT dtFlags;
|
|
|
|
HFONT hFont;
|
2018-02-15 09:00:09 +01:00
|
|
|
LONG state = infoPtr->state;
|
|
|
|
LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
|
|
|
|
LONG ex_style = GetWindowLongW( infoPtr->hwnd, GWL_EXSTYLE );
|
2018-02-06 06:50:21 +01:00
|
|
|
HWND parent;
|
|
|
|
HRGN hrgn;
|
|
|
|
|
|
|
|
if (style & BS_PUSHLIKE)
|
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
PB_Paint( infoPtr, hDC, action );
|
2018-02-06 06:50:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
GetClientRect(infoPtr->hwnd, &client);
|
2018-02-06 06:50:21 +01:00
|
|
|
rbox = rtext = client;
|
|
|
|
|
|
|
|
checkBoxWidth = 12 * GetDeviceCaps( hDC, LOGPIXELSX ) / 96 + 1;
|
|
|
|
checkBoxHeight = 12 * GetDeviceCaps( hDC, LOGPIXELSY ) / 96 + 1;
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
|
2018-02-06 06:50:21 +01:00
|
|
|
GetCharWidthW( hDC, '0', '0', &text_offset );
|
|
|
|
text_offset /= 2;
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
parent = GetParent(infoPtr->hwnd);
|
|
|
|
if (!parent) parent = infoPtr->hwnd;
|
|
|
|
hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
|
2018-02-06 06:50:21 +01:00
|
|
|
if (!hBrush) /* did the app forget to call defwindowproc ? */
|
2018-02-15 09:00:09 +01:00
|
|
|
hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
|
2018-02-06 06:50:21 +01:00
|
|
|
hrgn = set_control_clipping( hDC, &client );
|
|
|
|
|
|
|
|
if (style & BS_LEFTTEXT || ex_style & WS_EX_RIGHT)
|
|
|
|
{
|
|
|
|
rtext.right -= checkBoxWidth + text_offset;
|
|
|
|
rbox.left = rbox.right - checkBoxWidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rtext.left += checkBoxWidth + text_offset;
|
|
|
|
rbox.right = checkBoxWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Since WM_ERASEBKGND does nothing, first prepare background */
|
|
|
|
if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
|
|
|
|
if (action == ODA_DRAWENTIRE) FillRect( hDC, &client, hBrush );
|
|
|
|
|
|
|
|
/* Draw label */
|
|
|
|
client = rtext;
|
2018-02-15 09:00:09 +01:00
|
|
|
dtFlags = BUTTON_CalcLabelRect(infoPtr, hDC, &rtext);
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
/* Only adjust rbox when rtext is valid */
|
|
|
|
if (dtFlags != (UINT)-1L)
|
|
|
|
{
|
|
|
|
rbox.top = rtext.top;
|
|
|
|
rbox.bottom = rtext.bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw the check-box bitmap */
|
|
|
|
if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
|
|
|
|
{
|
|
|
|
UINT flags;
|
|
|
|
|
|
|
|
if ((get_button_type(style) == BS_RADIOBUTTON) ||
|
|
|
|
(get_button_type(style) == BS_AUTORADIOBUTTON)) flags = DFCS_BUTTONRADIO;
|
|
|
|
else if (state & BST_INDETERMINATE) flags = DFCS_BUTTON3STATE;
|
|
|
|
else flags = DFCS_BUTTONCHECK;
|
|
|
|
|
|
|
|
if (state & (BST_CHECKED | BST_INDETERMINATE)) flags |= DFCS_CHECKED;
|
|
|
|
if (state & BST_PUSHED) flags |= DFCS_PUSHED;
|
|
|
|
|
|
|
|
if (style & WS_DISABLED) flags |= DFCS_INACTIVE;
|
|
|
|
|
|
|
|
/* rbox must have the correct height */
|
|
|
|
delta = rbox.bottom - rbox.top - checkBoxHeight;
|
|
|
|
|
|
|
|
if (style & BS_TOP) {
|
|
|
|
if (delta > 0) {
|
|
|
|
rbox.bottom = rbox.top + checkBoxHeight;
|
|
|
|
} else {
|
|
|
|
rbox.top -= -delta/2 + 1;
|
|
|
|
rbox.bottom = rbox.top + checkBoxHeight;
|
|
|
|
}
|
|
|
|
} else if (style & BS_BOTTOM) {
|
|
|
|
if (delta > 0) {
|
|
|
|
rbox.top = rbox.bottom - checkBoxHeight;
|
|
|
|
} else {
|
|
|
|
rbox.bottom += -delta/2 + 1;
|
|
|
|
rbox.top = rbox.bottom - checkBoxHeight;
|
|
|
|
}
|
|
|
|
} else { /* Default */
|
|
|
|
if (delta > 0) {
|
|
|
|
int ofs = (delta / 2);
|
|
|
|
rbox.bottom -= ofs + 1;
|
|
|
|
rbox.top = rbox.bottom - checkBoxHeight;
|
|
|
|
} else if (delta < 0) {
|
|
|
|
int ofs = (-delta / 2);
|
|
|
|
rbox.top -= ofs + 1;
|
|
|
|
rbox.bottom = rbox.top + checkBoxHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawFrameControl( hDC, &rbox, DFC_BUTTON, flags );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dtFlags == (UINT)-1L) /* Noting to draw */
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (action == ODA_DRAWENTIRE)
|
2018-02-15 09:00:09 +01:00
|
|
|
BUTTON_DrawLabel(infoPtr, hDC, dtFlags, &rtext);
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
/* ... and focus */
|
|
|
|
if (action == ODA_FOCUS || (state & BST_FOCUS))
|
|
|
|
{
|
|
|
|
rtext.left--;
|
|
|
|
rtext.right++;
|
|
|
|
IntersectRect(&rtext, &rtext, &client);
|
|
|
|
DrawFocusRect( hDC, &rtext );
|
|
|
|
}
|
|
|
|
SelectClipRgn( hDC, hrgn );
|
|
|
|
if (hrgn) DeleteObject( hrgn );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* BUTTON_CheckAutoRadioButton
|
|
|
|
*
|
|
|
|
* hwnd is checked, uncheck every other auto radio button in group
|
|
|
|
*/
|
|
|
|
static void BUTTON_CheckAutoRadioButton( HWND hwnd )
|
|
|
|
{
|
|
|
|
HWND parent, sibling, start;
|
|
|
|
|
|
|
|
parent = GetParent(hwnd);
|
|
|
|
/* make sure that starting control is not disabled or invisible */
|
|
|
|
start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!sibling) break;
|
|
|
|
if ((hwnd != sibling) &&
|
|
|
|
((GetWindowLongW( sibling, GWL_STYLE) & BS_TYPEMASK) == BS_AUTORADIOBUTTON))
|
|
|
|
SendMessageW( sibling, BM_SETCHECK, BST_UNCHECKED, 0 );
|
|
|
|
sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
|
|
|
|
} while (sibling != start);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Group Box Functions
|
|
|
|
*/
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
static void GB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
|
|
|
RECT rc, rcFrame;
|
|
|
|
HBRUSH hbr;
|
|
|
|
HFONT hFont;
|
|
|
|
UINT dtFlags;
|
|
|
|
TEXTMETRICW tm;
|
2018-02-15 09:00:09 +01:00
|
|
|
LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
|
2018-02-06 06:50:21 +01:00
|
|
|
HWND parent;
|
|
|
|
HRGN hrgn;
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
|
2018-02-06 06:50:21 +01:00
|
|
|
/* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
|
2018-02-15 09:00:09 +01:00
|
|
|
parent = GetParent(infoPtr->hwnd);
|
|
|
|
if (!parent) parent = infoPtr->hwnd;
|
|
|
|
hbr = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
|
2018-02-06 06:50:21 +01:00
|
|
|
if (!hbr) /* did the app forget to call defwindowproc ? */
|
2018-02-15 09:00:09 +01:00
|
|
|
hbr = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
|
|
|
|
GetClientRect( infoPtr->hwnd, &rc);
|
2018-02-06 06:50:21 +01:00
|
|
|
rcFrame = rc;
|
|
|
|
hrgn = set_control_clipping( hDC, &rc );
|
|
|
|
|
|
|
|
GetTextMetricsW (hDC, &tm);
|
|
|
|
rcFrame.top += (tm.tmHeight / 2) - 1;
|
|
|
|
DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT | ((style & BS_FLAT) ? BF_FLAT : 0));
|
|
|
|
|
|
|
|
InflateRect(&rc, -7, 1);
|
2018-02-15 09:00:09 +01:00
|
|
|
dtFlags = BUTTON_CalcLabelRect(infoPtr, hDC, &rc);
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
if (dtFlags != (UINT)-1)
|
|
|
|
{
|
|
|
|
/* Because buttons have CS_PARENTDC class style, there is a chance
|
|
|
|
* that label will be drawn out of client rect.
|
|
|
|
* But Windows doesn't clip label's rect, so do I.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* There is 1-pixel margin at the left, right, and bottom */
|
|
|
|
rc.left--; rc.right++; rc.bottom++;
|
|
|
|
FillRect(hDC, &rc, hbr);
|
|
|
|
rc.left++; rc.right--; rc.bottom--;
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
BUTTON_DrawLabel(infoPtr, hDC, dtFlags, &rc);
|
2018-02-06 06:50:21 +01:00
|
|
|
}
|
|
|
|
SelectClipRgn( hDC, hrgn );
|
|
|
|
if (hrgn) DeleteObject( hrgn );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* User Button Functions
|
|
|
|
*/
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
static void UB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
HBRUSH hBrush;
|
|
|
|
HFONT hFont;
|
2018-02-15 09:00:09 +01:00
|
|
|
LONG state = infoPtr->state;
|
2018-02-06 06:50:21 +01:00
|
|
|
HWND parent;
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
GetClientRect( infoPtr->hwnd, &rc);
|
2018-02-06 06:50:21 +01:00
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
|
2018-02-06 06:50:21 +01:00
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
parent = GetParent(infoPtr->hwnd);
|
|
|
|
if (!parent) parent = infoPtr->hwnd;
|
|
|
|
hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
|
2018-02-06 06:50:21 +01:00
|
|
|
if (!hBrush) /* did the app forget to call defwindowproc ? */
|
2018-02-15 09:00:09 +01:00
|
|
|
hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
FillRect( hDC, &rc, hBrush );
|
|
|
|
if (action == ODA_FOCUS || (state & BST_FOCUS))
|
|
|
|
DrawFocusRect( hDC, &rc );
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case ODA_FOCUS:
|
2018-02-15 09:00:09 +01:00
|
|
|
BUTTON_NOTIFY_PARENT( infoPtr->hwnd, (state & BST_FOCUS) ? BN_SETFOCUS : BN_KILLFOCUS );
|
2018-02-06 06:50:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ODA_SELECT:
|
2018-02-15 09:00:09 +01:00
|
|
|
BUTTON_NOTIFY_PARENT( infoPtr->hwnd, (state & BST_PUSHED) ? BN_HILITE : BN_UNHILITE );
|
2018-02-06 06:50:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Ownerdrawn Button Functions
|
|
|
|
*/
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
static void OB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
|
2018-02-06 06:50:21 +01:00
|
|
|
{
|
2018-02-15 09:00:09 +01:00
|
|
|
LONG state = infoPtr->state;
|
2018-02-06 06:50:21 +01:00
|
|
|
DRAWITEMSTRUCT dis;
|
2018-02-15 09:00:09 +01:00
|
|
|
LONG_PTR id = GetWindowLongPtrW( infoPtr->hwnd, GWLP_ID );
|
2018-02-06 06:50:21 +01:00
|
|
|
HWND parent;
|
2018-03-01 12:38:33 +01:00
|
|
|
HFONT hFont;
|
2018-02-06 06:50:21 +01:00
|
|
|
HRGN hrgn;
|
|
|
|
|
|
|
|
dis.CtlType = ODT_BUTTON;
|
|
|
|
dis.CtlID = id;
|
|
|
|
dis.itemID = 0;
|
|
|
|
dis.itemAction = action;
|
|
|
|
dis.itemState = ((state & BST_FOCUS) ? ODS_FOCUS : 0) |
|
|
|
|
((state & BST_PUSHED) ? ODS_SELECTED : 0) |
|
2018-02-15 09:00:09 +01:00
|
|
|
(IsWindowEnabled(infoPtr->hwnd) ? 0: ODS_DISABLED);
|
|
|
|
dis.hwndItem = infoPtr->hwnd;
|
2018-02-06 06:50:21 +01:00
|
|
|
dis.hDC = hDC;
|
|
|
|
dis.itemData = 0;
|
2018-02-15 09:00:09 +01:00
|
|
|
GetClientRect( infoPtr->hwnd, &dis.rcItem );
|
2018-02-06 06:50:21 +01:00
|
|
|
|
2018-03-01 12:38:33 +01:00
|
|
|
if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
|
2018-02-15 09:00:09 +01:00
|
|
|
parent = GetParent(infoPtr->hwnd);
|
|
|
|
if (!parent) parent = infoPtr->hwnd;
|
|
|
|
SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)infoPtr->hwnd );
|
2018-02-06 06:50:21 +01:00
|
|
|
|
|
|
|
hrgn = set_control_clipping( hDC, &dis.rcItem );
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
SendMessageW( GetParent(infoPtr->hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
|
2018-02-06 06:50:21 +01:00
|
|
|
SelectClipRgn( hDC, hrgn );
|
|
|
|
if (hrgn) DeleteObject( hrgn );
|
|
|
|
}
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
static void PB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused)
|
2018-02-11 17:19:53 +01:00
|
|
|
{
|
|
|
|
static const int states[] = { PBS_NORMAL, PBS_DISABLED, PBS_HOT, PBS_PRESSED, PBS_DEFAULTED };
|
|
|
|
|
|
|
|
RECT bgRect, textRect;
|
2018-02-15 09:00:09 +01:00
|
|
|
HFONT font = infoPtr->font;
|
2018-02-11 17:19:53 +01:00
|
|
|
HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL;
|
|
|
|
int state = states[ drawState ];
|
2018-02-15 09:00:09 +01:00
|
|
|
WCHAR *text = get_button_text(infoPtr);
|
2018-02-11 17:19:53 +01:00
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
GetClientRect(infoPtr->hwnd, &bgRect);
|
2018-02-11 17:19:53 +01:00
|
|
|
GetThemeBackgroundContentRect(theme, hDC, BP_PUSHBUTTON, state, &bgRect, &textRect);
|
|
|
|
|
|
|
|
if (IsThemeBackgroundPartiallyTransparent(theme, BP_PUSHBUTTON, state))
|
2018-02-15 09:00:09 +01:00
|
|
|
DrawThemeParentBackground(infoPtr->hwnd, hDC, NULL);
|
2018-02-11 17:19:53 +01:00
|
|
|
DrawThemeBackground(theme, hDC, BP_PUSHBUTTON, state, &bgRect, NULL);
|
|
|
|
if (text)
|
|
|
|
{
|
|
|
|
DrawThemeText(theme, hDC, BP_PUSHBUTTON, state, text, lstrlenW(text), dtFlags, 0, &textRect);
|
2018-02-13 14:19:58 +01:00
|
|
|
heap_free(text);
|
2018-02-11 17:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (focused)
|
|
|
|
{
|
|
|
|
MARGINS margins;
|
|
|
|
RECT focusRect = bgRect;
|
|
|
|
|
|
|
|
GetThemeMargins(theme, hDC, BP_PUSHBUTTON, state, TMT_CONTENTMARGINS, NULL, &margins);
|
|
|
|
|
|
|
|
focusRect.left += margins.cxLeftWidth;
|
|
|
|
focusRect.top += margins.cyTopHeight;
|
|
|
|
focusRect.right -= margins.cxRightWidth;
|
|
|
|
focusRect.bottom -= margins.cyBottomHeight;
|
|
|
|
|
|
|
|
DrawFocusRect( hDC, &focusRect );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hPrevFont) SelectObject(hDC, hPrevFont);
|
|
|
|
}
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
static void CB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused)
|
2018-02-11 17:19:53 +01:00
|
|
|
{
|
|
|
|
static const int cb_states[3][5] =
|
|
|
|
{
|
|
|
|
{ CBS_UNCHECKEDNORMAL, CBS_UNCHECKEDDISABLED, CBS_UNCHECKEDHOT, CBS_UNCHECKEDPRESSED, CBS_UNCHECKEDNORMAL },
|
|
|
|
{ CBS_CHECKEDNORMAL, CBS_CHECKEDDISABLED, CBS_CHECKEDHOT, CBS_CHECKEDPRESSED, CBS_CHECKEDNORMAL },
|
|
|
|
{ CBS_MIXEDNORMAL, CBS_MIXEDDISABLED, CBS_MIXEDHOT, CBS_MIXEDPRESSED, CBS_MIXEDNORMAL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int rb_states[2][5] =
|
|
|
|
{
|
|
|
|
{ RBS_UNCHECKEDNORMAL, RBS_UNCHECKEDDISABLED, RBS_UNCHECKEDHOT, RBS_UNCHECKEDPRESSED, RBS_UNCHECKEDNORMAL },
|
|
|
|
{ RBS_CHECKEDNORMAL, RBS_CHECKEDDISABLED, RBS_CHECKEDHOT, RBS_CHECKEDPRESSED, RBS_CHECKEDNORMAL }
|
|
|
|
};
|
|
|
|
|
|
|
|
SIZE sz;
|
|
|
|
RECT bgRect, textRect;
|
|
|
|
HFONT font, hPrevFont = NULL;
|
2018-02-15 09:00:09 +01:00
|
|
|
int checkState = infoPtr->state & 3;
|
|
|
|
DWORD dwStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
|
2018-02-11 17:19:53 +01:00
|
|
|
UINT btn_type = get_button_type( dwStyle );
|
|
|
|
int part = (btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON) ? BP_RADIOBUTTON : BP_CHECKBOX;
|
|
|
|
int state = (part == BP_CHECKBOX)
|
|
|
|
? cb_states[ checkState ][ drawState ]
|
|
|
|
: rb_states[ checkState ][ drawState ];
|
2018-02-15 09:00:09 +01:00
|
|
|
WCHAR *text = get_button_text(infoPtr);
|
2018-02-11 17:19:53 +01:00
|
|
|
LOGFONTW lf;
|
|
|
|
BOOL created_font = FALSE;
|
|
|
|
|
|
|
|
HRESULT hr = GetThemeFont(theme, hDC, part, state, TMT_FONT, &lf);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
font = CreateFontIndirectW(&lf);
|
|
|
|
if (!font)
|
|
|
|
TRACE("Failed to create font\n");
|
|
|
|
else {
|
|
|
|
TRACE("font = %s\n", debugstr_w(lf.lfFaceName));
|
|
|
|
hPrevFont = SelectObject(hDC, font);
|
|
|
|
created_font = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
2018-02-15 09:00:09 +01:00
|
|
|
font = (HFONT)SendMessageW(infoPtr->hwnd, WM_GETFONT, 0, 0);
|
2018-02-11 17:19:53 +01:00
|
|
|
hPrevFont = SelectObject(hDC, font);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(GetThemePartSize(theme, hDC, part, state, NULL, TS_DRAW, &sz)))
|
|
|
|
sz.cx = sz.cy = 13;
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
GetClientRect(infoPtr->hwnd, &bgRect);
|
2018-02-11 17:19:53 +01:00
|
|
|
GetThemeBackgroundContentRect(theme, hDC, part, state, &bgRect, &textRect);
|
|
|
|
|
|
|
|
if (dtFlags & DT_SINGLELINE) /* Center the checkbox / radio button to the text. */
|
|
|
|
bgRect.top = bgRect.top + (textRect.bottom - textRect.top - sz.cy) / 2;
|
|
|
|
|
|
|
|
/* adjust for the check/radio marker */
|
|
|
|
bgRect.bottom = bgRect.top + sz.cy;
|
|
|
|
bgRect.right = bgRect.left + sz.cx;
|
|
|
|
textRect.left = bgRect.right + 6;
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
DrawThemeParentBackground(infoPtr->hwnd, hDC, NULL);
|
2018-02-11 17:19:53 +01:00
|
|
|
|
|
|
|
DrawThemeBackground(theme, hDC, part, state, &bgRect, NULL);
|
|
|
|
if (text)
|
|
|
|
{
|
|
|
|
DrawThemeText(theme, hDC, part, state, text, lstrlenW(text), dtFlags, 0, &textRect);
|
|
|
|
|
|
|
|
if (focused)
|
|
|
|
{
|
|
|
|
RECT focusRect;
|
|
|
|
|
|
|
|
focusRect = textRect;
|
|
|
|
|
|
|
|
DrawTextW(hDC, text, lstrlenW(text), &focusRect, dtFlags | DT_CALCRECT);
|
|
|
|
|
|
|
|
if (focusRect.right < textRect.right) focusRect.right++;
|
|
|
|
focusRect.bottom = textRect.bottom;
|
|
|
|
|
|
|
|
DrawFocusRect( hDC, &focusRect );
|
|
|
|
}
|
|
|
|
|
2018-02-13 14:19:58 +01:00
|
|
|
heap_free(text);
|
2018-02-11 17:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (created_font) DeleteObject(font);
|
|
|
|
if (hPrevFont) SelectObject(hDC, hPrevFont);
|
|
|
|
}
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
static void GB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused)
|
2018-02-11 17:19:53 +01:00
|
|
|
{
|
|
|
|
static const int states[] = { GBS_NORMAL, GBS_DISABLED, GBS_NORMAL, GBS_NORMAL, GBS_NORMAL };
|
|
|
|
|
|
|
|
RECT bgRect, textRect, contentRect;
|
|
|
|
int state = states[ drawState ];
|
2018-02-15 09:00:09 +01:00
|
|
|
WCHAR *text = get_button_text(infoPtr);
|
2018-02-11 17:19:53 +01:00
|
|
|
LOGFONTW lf;
|
|
|
|
HFONT font, hPrevFont = NULL;
|
|
|
|
BOOL created_font = FALSE;
|
|
|
|
|
|
|
|
HRESULT hr = GetThemeFont(theme, hDC, BP_GROUPBOX, state, TMT_FONT, &lf);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
font = CreateFontIndirectW(&lf);
|
|
|
|
if (!font)
|
|
|
|
TRACE("Failed to create font\n");
|
|
|
|
else {
|
|
|
|
hPrevFont = SelectObject(hDC, font);
|
|
|
|
created_font = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
2018-02-15 09:00:09 +01:00
|
|
|
font = (HFONT)SendMessageW(infoPtr->hwnd, WM_GETFONT, 0, 0);
|
2018-02-11 17:19:53 +01:00
|
|
|
hPrevFont = SelectObject(hDC, font);
|
|
|
|
}
|
|
|
|
|
2018-02-15 09:00:09 +01:00
|
|
|
GetClientRect(infoPtr->hwnd, &bgRect);
|
2018-02-11 17:19:53 +01:00
|
|
|
textRect = bgRect;
|
|
|
|
|
|
|
|
if (text)
|
|
|
|
{
|
|
|
|
SIZE textExtent;
|
|
|
|
GetTextExtentPoint32W(hDC, text, lstrlenW(text), &textExtent);
|
|
|
|
bgRect.top += (textExtent.cy / 2);
|
|
|
|
textRect.left += 10;
|
|
|
|
textRect.bottom = textRect.top + textExtent.cy;
|
|
|
|
textRect.right = textRect.left + textExtent.cx + 4;
|
|
|
|
|
|
|
|
ExcludeClipRect(hDC, textRect.left, textRect.top, textRect.right, textRect.bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
GetThemeBackgroundContentRect(theme, hDC, BP_GROUPBOX, state, &bgRect, &contentRect);
|
|
|
|
ExcludeClipRect(hDC, contentRect.left, contentRect.top, contentRect.right, contentRect.bottom);
|
|
|
|
|
|
|
|
if (IsThemeBackgroundPartiallyTransparent(theme, BP_GROUPBOX, state))
|
2018-02-15 09:00:09 +01:00
|
|
|
DrawThemeParentBackground(infoPtr->hwnd, hDC, NULL);
|
2018-02-11 17:19:53 +01:00
|
|
|
DrawThemeBackground(theme, hDC, BP_GROUPBOX, state, &bgRect, NULL);
|
|
|
|
|
|
|
|
SelectClipRgn(hDC, NULL);
|
|
|
|
|
|
|
|
if (text)
|
|
|
|
{
|
|
|
|
InflateRect(&textRect, -2, 0);
|
|
|
|
DrawThemeText(theme, hDC, BP_GROUPBOX, state, text, lstrlenW(text), 0, 0, &textRect);
|
2018-02-13 14:19:58 +01:00
|
|
|
heap_free(text);
|
2018-02-11 17:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (created_font) DeleteObject(font);
|
|
|
|
if (hPrevFont) SelectObject(hDC, hPrevFont);
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:50:21 +01:00
|
|
|
void BUTTON_Register(void)
|
|
|
|
{
|
|
|
|
WNDCLASSW wndClass;
|
|
|
|
|
|
|
|
memset(&wndClass, 0, sizeof(wndClass));
|
|
|
|
wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC;
|
|
|
|
wndClass.lpfnWndProc = BUTTON_WindowProc;
|
|
|
|
wndClass.cbClsExtra = 0;
|
2018-02-15 09:00:09 +01:00
|
|
|
wndClass.cbWndExtra = sizeof(BUTTON_INFO *);
|
2018-02-06 06:50:21 +01:00
|
|
|
wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
|
|
|
|
wndClass.hbrBackground = NULL;
|
|
|
|
wndClass.lpszClassName = WC_BUTTONW;
|
|
|
|
RegisterClassW(&wndClass);
|
|
|
|
}
|