Added more support for buddy windows in the updown control.

This commit is contained in:
Francis Beaudet 1999-07-30 18:00:28 +00:00 committed by Alexandre Julliard
parent 06e8886ee8
commit 9b7fa1922a
1 changed files with 111 additions and 29 deletions

View File

@ -48,6 +48,7 @@ DEFAULT_DEBUG_CHANNEL(updown)
#define DEFAULT_XSEP 0 /* default separation between buddy and crtl */ #define DEFAULT_XSEP 0 /* default separation between buddy and crtl */
#define DEFAULT_ADDTOP 0 /* amount to extend above the buddy window */ #define DEFAULT_ADDTOP 0 /* amount to extend above the buddy window */
#define DEFAULT_ADDBOT 0 /* amount to extend below the buddy window */ #define DEFAULT_ADDBOT 0 /* amount to extend below the buddy window */
#define DEFAULT_BUDDYBORDER 2 /* Width/height of the buddy border */
/* Work constants */ /* Work constants */
@ -113,6 +114,22 @@ static BOOL UPDOWN_OffsetVal(HWND hwnd, int delta)
return TRUE; return TRUE;
} }
/***********************************************************************
* UPDOWN_HasBuddyBorder [Internal]
*
* When we have a buddy set and that we are aligned on our buddy, we
* want to draw a sunken edge to make like we are part of that control.
*/
static BOOL UPDOWN_HasBuddyBorder(HWND hwnd)
{
UPDOWN_INFO* infoPtr = UPDOWN_GetInfoPtr (hwnd);
DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
return ( ((dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)) != 0) &&
(SendMessageA(hwnd, UDM_GETBUDDY, 0, 0) != 0) &&
(lstrcmpiA(infoPtr->szBuddyClass, "EDIT") == 0 ) );
}
/*********************************************************************** /***********************************************************************
* UPDOWN_GetArrowRect * UPDOWN_GetArrowRect
* wndPtr - pointer to the up-down wnd * wndPtr - pointer to the up-down wnd
@ -123,23 +140,43 @@ static BOOL UPDOWN_OffsetVal(HWND hwnd, int delta)
*/ */
static void UPDOWN_GetArrowRect (HWND hwnd, RECT *rect, BOOL incr) static void UPDOWN_GetArrowRect (HWND hwnd, RECT *rect, BOOL incr)
{ {
DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
int len; /* will hold the width or height */ int len; /* will hold the width or height */
GetClientRect (hwnd, rect); GetClientRect (hwnd, rect);
if (GetWindowLongA (hwnd, GWL_STYLE) & UDS_HORZ) { /*
len = rect->right - rect->left; /* compute the width */ * Make sure we calculate the rectangle to fit even if we draw the
if (incr) * border.
rect->left = len/2+1; */
if (UPDOWN_HasBuddyBorder(hwnd))
{
if (dwStyle & UDS_ALIGNLEFT)
rect->left+=DEFAULT_BUDDYBORDER;
else else
rect->right = len/2; rect->right-=DEFAULT_BUDDYBORDER;
InflateRect(rect, 0, -DEFAULT_BUDDYBORDER);
}
/*
* We're calculating the midpoint to figure-out where the
* separation between the buttons will lay. We make sure that we
* round the uneven numbers by adding 1.
*/
if (dwStyle & UDS_HORZ) {
len = rect->right - rect->left + 1; /* compute the width */
if (incr)
rect->left = rect->left + len/2;
else
rect->right = rect->left + len/2;
} }
else { else {
len = rect->bottom - rect->top; /* compute the height */ len = rect->bottom - rect->top + 1; /* compute the height */
if (incr) if (incr)
rect->bottom = len/2; rect->bottom = rect->top + len/2;
else else
rect->top = len/2+1; rect->top = rect->top + len/2;
} }
} }
@ -276,6 +313,25 @@ static BOOL UPDOWN_SetBuddyInt (HWND hwnd)
return TRUE; return TRUE;
} }
/***********************************************************************
* UPDOWN_DrawBuddyBorder [Internal]
*
* When we have a buddy set and that we are aligned on our buddy, we
* want to draw a sunken edge to make like we are part of that control.
*/
static void UPDOWN_DrawBuddyBorder (HWND hwnd, HDC hdc)
{
DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
RECT clientRect;
GetClientRect(hwnd, &clientRect);
if (dwStyle & UDS_ALIGNLEFT)
DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_BOTTOM | BF_LEFT | BF_TOP);
else
DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_BOTTOM | BF_RIGHT | BF_TOP);
}
/*********************************************************************** /***********************************************************************
* UPDOWN_Draw [Internal] * UPDOWN_Draw [Internal]
* *
@ -288,6 +344,12 @@ static void UPDOWN_Draw (HWND hwnd, HDC hdc)
BOOL prssed; BOOL prssed;
RECT rect; RECT rect;
/*
* Draw the common border between ourselves and our buddy.
*/
if (UPDOWN_HasBuddyBorder(hwnd))
UPDOWN_DrawBuddyBorder(hwnd, hdc);
/* Draw the incr button */ /* Draw the incr button */
UPDOWN_GetArrowRect (hwnd, &rect, TRUE); UPDOWN_GetArrowRect (hwnd, &rect, TRUE);
prssed = (infoPtr->Flags & FLAG_INCR) && (infoPtr->Flags & FLAG_MOUSEIN); prssed = (infoPtr->Flags & FLAG_INCR) && (infoPtr->Flags & FLAG_MOUSEIN);
@ -331,13 +393,17 @@ static void UPDOWN_Refresh (HWND hwnd)
* Asynchronous drawing (must ONLY be used in WM_PAINT). * Asynchronous drawing (must ONLY be used in WM_PAINT).
* Calls UPDOWN_Draw. * Calls UPDOWN_Draw.
*/ */
static void UPDOWN_Paint (HWND hwnd) static void UPDOWN_Paint (HWND hwnd, HDC passedDC)
{ {
PAINTSTRUCT ps; PAINTSTRUCT ps;
HDC hdc; HDC hdc = passedDC;
if (passedDC == 0)
hdc = BeginPaint (hwnd, &ps); hdc = BeginPaint (hwnd, &ps);
UPDOWN_Draw (hwnd, hdc); UPDOWN_Draw (hwnd, hdc);
if (passedDC == 0)
EndPaint (hwnd, &ps); EndPaint (hwnd, &ps);
} }
@ -356,7 +422,7 @@ static BOOL UPDOWN_SetBuddy (HWND hwnd, HWND hwndBud)
UPDOWN_INFO* infoPtr = UPDOWN_GetInfoPtr (hwnd); UPDOWN_INFO* infoPtr = UPDOWN_GetInfoPtr (hwnd);
DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE); DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
RECT budRect; /* new coord for the buddy */ RECT budRect; /* new coord for the buddy */
int x; /* new x position and width for the up-down */ int x,width; /* new x position and width for the up-down */
/* Is it a valid bud? */ /* Is it a valid bud? */
if(!IsWindow(hwndBud)) if(!IsWindow(hwndBud))
@ -423,10 +489,25 @@ static BOOL UPDOWN_SetBuddy (HWND hwnd, HWND hwndBud)
/* now position the up/down */ /* now position the up/down */
/* Since the UDS_ALIGN* flags were used, */ /* Since the UDS_ALIGN* flags were used, */
/* we will pick the position and size of the window. */ /* we will pick the position and size of the window. */
width = DEFAULT_WIDTH;
SetWindowPos (hwnd, 0, x, budRect.top-DEFAULT_ADDTOP,DEFAULT_WIDTH, /*
(budRect.bottom-budRect.top)+DEFAULT_ADDTOP+DEFAULT_ADDBOT, * If the updown has a buddy border, it has to overlap with the buddy
SWP_NOACTIVATE|SWP_NOZORDER); * to look as if it is integrated with the buddy control.
* We nudge the control or change it size to overlap.
*/
if (UPDOWN_HasBuddyBorder(hwnd))
{
if(dwStyle & UDS_ALIGNRIGHT)
x-=DEFAULT_BUDDYBORDER;
else
width+=DEFAULT_BUDDYBORDER;
}
SetWindowPos (hwnd, infoPtr->Buddy,
x, budRect.top-DEFAULT_ADDTOP,
width, (budRect.bottom-budRect.top)+DEFAULT_ADDTOP+DEFAULT_ADDBOT,
SWP_NOACTIVATE);
return TRUE; return TRUE;
} }
@ -672,7 +753,8 @@ LRESULT WINAPI UpDownWindowProc(HWND hwnd, UINT message, WPARAM wParam,
case WM_ENABLE: case WM_ENABLE:
if (dwStyle & WS_DISABLED) if (dwStyle & WS_DISABLED)
UPDOWN_CancelMode (hwnd); UPDOWN_CancelMode (hwnd);
UPDOWN_Paint (hwnd);
UPDOWN_Refresh (hwnd);
break; break;
case WM_TIMER: case WM_TIMER:
@ -741,7 +823,7 @@ LRESULT WINAPI UpDownWindowProc(HWND hwnd, UINT message, WPARAM wParam,
break; break;
case WM_PAINT: case WM_PAINT:
UPDOWN_Paint (hwnd); UPDOWN_Paint (hwnd, (HDC)wParam);
break; break;
case UDM_GETACCEL: case UDM_GETACCEL: