Tue Sep 28 19:59:21 1993 David Metcalfe * [windows/win.c] Implemented support for windows with no borders. Added GetParent(), GetDlgCtrlID(), GetWindowText() and GetWindowTextLength() functions. * [misc/xt.c] Added processing of WM_GETTEXT and WM_GETTEXTLENGTH messages to DefWindowProc and Implemented MessageBeep(). * [windows/syscolor.c] Added preliminary system color support. * [controls/button1.c] Mods to new button control and integration with Wine. Tue Sep 28 19:59:21 1993 Johannes Ruscheinski * [controls/button1.c] New button control using GDI functions. Tue Sep 28 19:59:21 1993 Eric Youngdale * [debugger/*] Added debugging capabilities to Wine Sat Sep 25 13:22:50 1993 Alexandre Julliard (julliard@di.epfl.ch) * [objects/region.c] Bug fix Fri Sep 24 07:35:11 1993 Bob Amstadt (bob at pooh) * [tools/build.c] Changed the entry point code to reduce the standard entry point size from 22 bytes to 10 bytes. This leaves about 4000 free entry points instead of the 800 in version 0.4.2. * [loader/resource.c] Rewrote functions to allow loading of resources from any DLL. * [loader/wine.c] [include/wine.h] Added functions GetFilenameFromInstance() and GetFileInfo() to search for a loaded file based on its instance handle. Added a field in struct w_files to make searching by an instance handle faster. Tue Sep 21 09:57:01 1993 miguel@roxanne.nuclecu.unam.mx (Miguel de Icaza) * [misc/profile.c] Implementation of .INI file handling Mon Sep 20 10:54:32 1993 David Metcalfe * [misc/profile.c.old] Implementation of .INI file handling Mon Sep 20 10:54:32 1993 John Brezak * [controls/WinButton.c] Bug fix with call to XtVaSetValues. Mon Sep 20 10:54:32 1993 Alexandre Julliard * [windows/win.c] Quick patch to get colormaps to work with button widget. Mon Sep 20 02:42:54 1993 (yngvi@hafro.is) * misc/keyboard.c: Ifdefed out some bogus Ansi<->Oem conversion functions * misc/lstr.c: New file with string functions like lstr* IsChar* *Ansi* Wed Sep 15 20:35:10 1993 John Brezak * [loader/signal.c] Additional changes to support NetBSD. Wed Sep 15 22:19:22 1993 Martin Ayotte * [windows/graphics.c] Added FrameRect function Tue Sep 14 13:54:45 1993 Alexandre Julliard * [objects/color.c] [objects/palette.c] Preliminary support for private color map. * [windows/class.c] Implemented CS_CLASSDC style. * [windows/dce.c] Moved DCEs to USER heap. Implemented class and window DCs. * [windows/event.c] Implemented CS_DBLCLKS style. * [windows/graphics.c] Bug fix in SetPixel(). * [windows/win.c] Implemented CS_OWNDC style. Implemented Get/SetWindowLong(). * [controls/menu.c] [windows/class.c] [windows/clipping.c] [windows/dce.c] [windows/message.c] [windows/win.c] Moved windows from global heap to USER heap.
351 lines
8.8 KiB
C
351 lines
8.8 KiB
C
/* File: button.c -- MS-Windows(tm) compatible "Button" replacement widget
|
|
*
|
|
* programmed by Johannes Ruscheinski for the Linux WABI
|
|
* project.
|
|
* (C) 1993 by Johannes Ruscheinski
|
|
*
|
|
* Modifications by David Metcalfe
|
|
*/
|
|
|
|
#include <windows.h>
|
|
#include "win.h"
|
|
|
|
LONG ButtonWndProc(HWND hWnd, WORD uMsg, WORD wParam, LONG lParam);
|
|
|
|
static COLORREF color_windowframe, color_btnface, color_btnshadow,
|
|
color_btntext, color_btnhighlight;
|
|
|
|
static BOOL pressed;
|
|
|
|
#define NOTIFY_PARENT(hWndCntrl, wNotifyCode) \
|
|
SendMessage(GetParent(hWndCntrl), WM_COMMAND, \
|
|
GetDlgCtrlID(hWndCntrl), MAKELPARAM(hWndCntrl, wNotifyCode));
|
|
#define DIM(array) ((sizeof array)/(sizeof array[0]))
|
|
|
|
static LONG PB_Paint(HWND hWnd);
|
|
static LONG PB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam);
|
|
static LONG PB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam);
|
|
static LONG PB_LButtonDblClk(HWND hWnd, WORD wParam, LONG lParam);
|
|
static void DrawRaisedPushButton(HDC hDC, HWND hButton, RECT rc);
|
|
static void DrawPressedPushButton(HDC hDC, HWND hButton, RECT rc);
|
|
|
|
typedef struct
|
|
{
|
|
LONG (*paintfn)();
|
|
LONG (*lButtonDownfn)();
|
|
LONG (*lButtonUpfn)();
|
|
LONG (*lButtonDblClkfn)();
|
|
} BTNFN;
|
|
|
|
#define MAX_BTN_TYPE 2
|
|
|
|
static BTNFN btnfn[MAX_BTN_TYPE] =
|
|
{
|
|
{
|
|
(LONG(*)())PB_Paint, /* BS_PUSHBUTTON */
|
|
(LONG(*)())PB_LButtonDown,
|
|
(LONG(*)())PB_LButtonUp,
|
|
(LONG(*)())PB_LButtonDblClk
|
|
},
|
|
{
|
|
(LONG(*)())PB_Paint, /* BS_DEFPUSHBUTTON */
|
|
(LONG(*)())PB_LButtonDown,
|
|
(LONG(*)())PB_LButtonUp,
|
|
(LONG(*)())PB_LButtonDblClk
|
|
}
|
|
};
|
|
|
|
|
|
LONG ButtonWndProc(HWND hWnd, WORD uMsg, WORD wParam, LONG lParam)
|
|
{
|
|
LONG lResult = 0;
|
|
HDC hDC;
|
|
RECT rc;
|
|
|
|
WND *wndPtr = WIN_FindWndPtr(hWnd);
|
|
LONG style = wndPtr->dwStyle & 0x0000000F;
|
|
|
|
switch (uMsg) {
|
|
/* case WM_GETDLGCODE:
|
|
lResult = DLGC_BUTTON;
|
|
break;
|
|
*/
|
|
case WM_ENABLE:
|
|
InvalidateRect(hWnd, NULL, FALSE);
|
|
break;
|
|
|
|
case WM_CREATE:
|
|
if (style < 0L || style >= (LONG)DIM(btnfn))
|
|
lResult = -1L;
|
|
else
|
|
{
|
|
/* initialise colours used for button rendering: */
|
|
color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
|
|
color_btnface = GetSysColor(COLOR_BTNFACE);
|
|
color_btnshadow = GetSysColor(COLOR_BTNSHADOW);
|
|
color_btntext = GetSysColor(COLOR_BTNTEXT);
|
|
color_btnhighlight = GetSysColor(COLOR_BTNHIGHLIGHT);
|
|
|
|
pressed = FALSE;
|
|
lResult = 0L;
|
|
}
|
|
break;
|
|
|
|
case WM_PAINT:
|
|
(btnfn[style].paintfn)(hWnd);
|
|
break;
|
|
|
|
case WM_LBUTTONDOWN:
|
|
(btnfn[style].lButtonDownfn)(hWnd, wParam, lParam);
|
|
break;
|
|
|
|
case WM_LBUTTONUP:
|
|
(btnfn[style].lButtonUpfn)(hWnd, wParam, lParam);
|
|
break;
|
|
|
|
case WM_LBUTTONDBLCLK:
|
|
(btnfn[style].lButtonDblClkfn)(hWnd, wParam, lParam);
|
|
break;
|
|
|
|
case WM_SETFOCUS:
|
|
break;
|
|
|
|
case WM_KILLFOCUS:
|
|
InvalidateRect(hWnd, NULL, FALSE);
|
|
UpdateWindow(hWnd);
|
|
break;
|
|
|
|
case WM_SYSCOLORCHANGE:
|
|
color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
|
|
color_btnface = GetSysColor(COLOR_BTNFACE);
|
|
color_btnshadow = GetSysColor(COLOR_BTNSHADOW);
|
|
color_btntext = GetSysColor(COLOR_BTNTEXT);
|
|
color_btnhighlight = GetSysColor(COLOR_BTNHIGHLIGHT);
|
|
InvalidateRect(hWnd, NULL, TRUE);
|
|
break;
|
|
|
|
default:
|
|
lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
|
|
break;
|
|
}
|
|
|
|
GlobalUnlock(hWnd);
|
|
return lResult;
|
|
}
|
|
|
|
|
|
/**********************************************************************
|
|
* Push Button Functions
|
|
*/
|
|
|
|
static LONG PB_Paint(HWND hWnd)
|
|
{
|
|
PAINTSTRUCT ps;
|
|
RECT rc;
|
|
HDC hDC;
|
|
|
|
hDC = BeginPaint(hWnd, &ps);
|
|
GetClientRect(hWnd, &rc);
|
|
if (pressed)
|
|
DrawPressedPushButton(hDC, hWnd, rc);
|
|
else
|
|
DrawRaisedPushButton(hDC, hWnd, rc);
|
|
EndPaint(hWnd, &ps);
|
|
}
|
|
|
|
static LONG PB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam)
|
|
{
|
|
/* SetFocus(hWnd); */
|
|
SetCapture(hWnd);
|
|
pressed = TRUE;
|
|
InvalidateRect(hWnd, NULL, FALSE);
|
|
UpdateWindow(hWnd);
|
|
}
|
|
|
|
static LONG PB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam)
|
|
{
|
|
RECT rc;
|
|
|
|
pressed = FALSE;
|
|
ReleaseCapture();
|
|
GetClientRect(hWnd, &rc);
|
|
if (PtInRect(&rc, MAKEPOINT(lParam)))
|
|
NOTIFY_PARENT(hWnd, BN_CLICKED);
|
|
InvalidateRect(hWnd, NULL, FALSE);
|
|
UpdateWindow(hWnd);
|
|
}
|
|
|
|
static LONG PB_LButtonDblClk(HWND hWnd, WORD wParam, LONG lParam)
|
|
{
|
|
RECT rc;
|
|
|
|
GetClientRect(hWnd, &rc);
|
|
if (PtInRect(&rc, MAKEPOINT(lParam)))
|
|
NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
|
|
}
|
|
|
|
static void DrawRaisedPushButton(HDC hDC, HWND hButton, RECT rc)
|
|
{
|
|
HPEN hOldPen, hFramePen;
|
|
HBRUSH hOldBrush, hShadowBrush, hHighlightBrush, hBackgrndBrush;
|
|
HRGN rgn1, rgn2, rgn;
|
|
int len;
|
|
static char text[50+1];
|
|
POINT points[6];
|
|
DWORD dwTextSize;
|
|
int delta;
|
|
TEXTMETRIC tm;
|
|
int i;
|
|
|
|
hFramePen = CreatePen(PS_SOLID, 1, color_windowframe);
|
|
hBackgrndBrush = CreateSolidBrush(color_btnface);
|
|
|
|
hOldPen = (HPEN)SelectObject(hDC, (HANDLE)hFramePen);
|
|
hOldBrush = (HBRUSH)SelectObject(hDC, (HANDLE)hBackgrndBrush);
|
|
SetBkMode(hDC, TRANSPARENT);
|
|
|
|
rgn = CreateRectRgn(0, 0, 0, 0);
|
|
rgn1 = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
|
|
|
|
SendMessage(GetParent(hButton), WM_CTLCOLOR, (WORD)hDC,
|
|
MAKELPARAM(hButton, CTLCOLOR_BTN));
|
|
Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
|
|
|
|
/* draw button label, if any: */
|
|
len = GetWindowText(hButton, text, sizeof text);
|
|
if (len >= 1) {
|
|
rc.left--; rc.bottom--;
|
|
DrawText(hDC, text, len, &rc,
|
|
DT_SINGLELINE | DT_CENTER| DT_VCENTER);
|
|
}
|
|
|
|
/* draw button highlight */
|
|
points[0].x = rc.left+2;
|
|
points[0].y = rc.bottom;
|
|
points[1].x = rc.left+4;
|
|
points[1].y = rc.bottom-2;
|
|
points[2].x = rc.left+4;
|
|
points[2].y = rc.top+3;
|
|
points[3].x = rc.right-3;
|
|
points[3].y = rc.top+3;
|
|
points[4].x = rc.right-1;
|
|
points[4].y = rc.top+1;
|
|
points[5].x = rc.left+2;
|
|
points[5].y = rc.top+1;
|
|
hHighlightBrush = CreateSolidBrush(color_btnhighlight);
|
|
rgn2 = CreatePolygonRgn(points, DIM(points), ALTERNATE);
|
|
CombineRgn(rgn, rgn1, rgn2, RGN_AND);
|
|
FillRgn(hDC, rgn2, hHighlightBrush);
|
|
|
|
/* draw button shadow: */
|
|
points[0].x = rc.left+2;
|
|
points[0].y = rc.bottom;
|
|
points[1].x = rc.left+4;
|
|
points[1].y = rc.bottom-2;
|
|
points[2].x = rc.right-3;
|
|
points[2].y = rc.bottom-2;
|
|
points[3].x = rc.right-3;
|
|
points[3].y = rc.top+3;
|
|
points[4].x = rc.right-1;
|
|
points[4].y = rc.top;
|
|
points[5].x = rc.right-1;
|
|
points[5].y = rc.bottom;
|
|
hShadowBrush = CreateSolidBrush(color_btnshadow);
|
|
rgn2 = CreatePolygonRgn(points, DIM(points), ALTERNATE);
|
|
CombineRgn(rgn, rgn1, rgn2, RGN_AND);
|
|
FillRgn(hDC, rgn2, hShadowBrush);
|
|
|
|
#if 0
|
|
/* do we have the focus? */
|
|
if (len >= 1 && GetFocus() == hButton) {
|
|
dwTextSize = GetTextExtent(hDC, text, len);
|
|
delta = ((rc.right - rc.left) - LOWORD(dwTextSize) + 1) >> 1;
|
|
rc.left += delta; rc.right -= delta;
|
|
GetTextMetrics(hDC, &tm);
|
|
delta = ((rc.bottom - rc.top) -
|
|
tm.tmHeight + tm.tmInternalLeading) >> 1;
|
|
rc.top += delta; rc.bottom -= delta;
|
|
DrawFocusRect(hDC, &rc);
|
|
}
|
|
#endif
|
|
|
|
SelectObject(hDC, (HANDLE)hOldPen);
|
|
SelectObject(hDC, (HANDLE)hOldBrush);
|
|
DeleteObject((HANDLE)hFramePen);
|
|
DeleteObject((HANDLE)hShadowBrush);
|
|
DeleteObject((HANDLE)hBackgrndBrush);
|
|
DeleteObject((HANDLE)rgn1);
|
|
#if 0
|
|
DeleteObject((HANDLE)rgn2);
|
|
DeleteObject((HANDLE)rgn);
|
|
#endif
|
|
}
|
|
|
|
|
|
static void DrawPressedPushButton(HDC hDC, HWND hButton, RECT rc)
|
|
{
|
|
HPEN hOldPen, hShadowPen, hFramePen;
|
|
HBRUSH hOldBrush, hBackgrndBrush;
|
|
HRGN rgn1, rgn2, rgn;
|
|
int len;
|
|
static char text[50+1];
|
|
DWORD dwTextSize;
|
|
int delta;
|
|
TEXTMETRIC tm;
|
|
|
|
hFramePen = CreatePen(PS_SOLID, 1, color_windowframe);
|
|
hBackgrndBrush = CreateSolidBrush(color_btnface);
|
|
|
|
hOldBrush = (HBRUSH)SelectObject(hDC, (HANDLE)hBackgrndBrush);
|
|
hOldPen = (HPEN)SelectObject(hDC, (HANDLE)hFramePen);
|
|
SetBkMode(hDC, TRANSPARENT);
|
|
|
|
/* give parent a chance to alter parameters: */
|
|
SendMessage(GetParent(hButton), WM_CTLCOLOR, (WORD)hDC,
|
|
MAKELPARAM(hButton, CTLCOLOR_BTN));
|
|
Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
|
|
|
|
/* draw button shadow: */
|
|
hShadowPen = CreatePen(PS_SOLID, 1, color_btnshadow);
|
|
SelectObject(hDC, (HANDLE)hShadowPen);
|
|
MoveTo(hDC, rc.left+1, rc.bottom-1);
|
|
LineTo(hDC, rc.left+1, rc.top+1);
|
|
LineTo(hDC, rc.right-1, rc.top+1);
|
|
|
|
/* draw button label, if any: */
|
|
len = GetWindowText(hButton, text, sizeof text);
|
|
if (len >= 1) {
|
|
rc.top++; rc.left++;
|
|
DrawText(hDC, text, len, &rc,
|
|
DT_SINGLELINE | DT_CENTER| DT_VCENTER);
|
|
}
|
|
|
|
#if 0
|
|
/* do we have the focus? */
|
|
if (len >= 1 && GetFocus() == hButton) {
|
|
dwTextSize = GetTextExtent(hDC, text, len);
|
|
delta = ((rc.right - rc.left) - LOWORD(dwTextSize)) >> 1;
|
|
rc.left += delta; rc.right -= delta;
|
|
GetTextMetrics(hDC, &tm);
|
|
delta = ((rc.bottom - rc.top) -
|
|
tm.tmHeight + tm.tmInternalLeading) >> 1;
|
|
rc.top += delta; rc.bottom -= delta;
|
|
DrawFocusRect(hDC, &rc);
|
|
}
|
|
#endif
|
|
|
|
SelectObject(hDC, (HANDLE)hOldPen);
|
|
SelectObject(hDC, (HANDLE)hOldBrush);
|
|
DeleteObject((HANDLE)hBackgrndBrush);
|
|
DeleteObject(SelectObject(hDC, (HANDLE)hFramePen));
|
|
DeleteObject(SelectObject(hDC, (HANDLE)hShadowPen));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|