updown: setbuddy(0) fix
Huw D M Davies
h.davies1 at physics.ox.ac.uk
Mon Mar 15 10:29:04 CST 2004
Huw Davies <huw at codeweavers.com>
When setting the buddy to 0 then we must still resize the
updown control.
--
Huw Davies
huw at codeweavers.com
--- dlls/comctl32/updown.c 2004-03-15 15:46:10.000000000 +0000
+++ dlls/comctl32/updown.c 2004-03-15 15:27:27.000000000 +0000
@@ -442,98 +442,109 @@
/***********************************************************************
* UPDOWN_SetBuddy
- * Tests if 'bud' is a valid window handle. If not, returns FALSE.
- * Else, sets it as a new Buddy.
+ *
+ * Sets bud as a new Buddy.
* Then, it should subclass the buddy
* If window has the UDS_ARROWKEYS, it subcalsses the buddy window to
* process the UP/DOWN arrow keys.
* If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
* the size/pos of the buddy and the control are adjusted accordingly.
*/
-static BOOL UPDOWN_SetBuddy (UPDOWN_INFO* infoPtr, HWND bud)
+static HWND UPDOWN_SetBuddy (UPDOWN_INFO* infoPtr, HWND bud)
{
DWORD dwStyle = GetWindowLongW (infoPtr->Self, GWL_STYLE);
RECT budRect; /* new coord for the buddy */
int x, width; /* new x position and width for the up-down */
WNDPROC baseWndProc;
CHAR buddyClass[40];
-
- /* Is it a valid bud? */
- if(!IsWindow(bud)) return FALSE;
+ HWND ret;
TRACE("(hwnd=%p, bud=%p)\n", infoPtr->Self, bud);
+ ret = infoPtr->Buddy;
+
/* there is already a body assigned */
if (infoPtr->Buddy) RemovePropA(infoPtr->Buddy, BUDDY_UPDOWN_HWND);
+ if(!IsWindow(bud))
+ bud = 0;
+
/* Store buddy window handle */
infoPtr->Buddy = bud;
- /* keep upDown ctrl hwnd in a buddy property */
- SetPropA( bud, BUDDY_UPDOWN_HWND, infoPtr->Self);
+ if(bud) {
- /* Store buddy window class type */
- infoPtr->BuddyType = BUDDY_TYPE_UNKNOWN;
- if (GetClassNameA(bud, buddyClass, COUNT_OF(buddyClass))) {
- if (lstrcmpiA(buddyClass, "Edit") == 0)
- infoPtr->BuddyType = BUDDY_TYPE_EDIT;
- else if (lstrcmpiA(buddyClass, "Listbox") == 0)
- infoPtr->BuddyType = BUDDY_TYPE_LISTBOX;
- }
+ /* keep upDown ctrl hwnd in a buddy property */
+ SetPropA( bud, BUDDY_UPDOWN_HWND, infoPtr->Self);
- if(dwStyle & UDS_ARROWKEYS){
- /* Note that I don't clear the BUDDY_SUPERCLASS_WNDPROC property
- when we reset the upDown ctrl buddy to another buddy because it is not
- good to break the window proc chain. */
- if (!GetPropA(bud, BUDDY_SUPERCLASS_WNDPROC)) {
- baseWndProc = (WNDPROC)SetWindowLongW(bud, GWL_WNDPROC, (LPARAM)UPDOWN_Buddy_SubclassProc);
- SetPropA(bud, BUDDY_SUPERCLASS_WNDPROC, (HANDLE)baseWndProc);
- }
- }
+ /* Store buddy window class type */
+ infoPtr->BuddyType = BUDDY_TYPE_UNKNOWN;
+ if (GetClassNameA(bud, buddyClass, COUNT_OF(buddyClass))) {
+ if (lstrcmpiA(buddyClass, "Edit") == 0)
+ infoPtr->BuddyType = BUDDY_TYPE_EDIT;
+ else if (lstrcmpiA(buddyClass, "Listbox") == 0)
+ infoPtr->BuddyType = BUDDY_TYPE_LISTBOX;
+ }
- /* Get the rect of the buddy relative to its parent */
- GetWindowRect(infoPtr->Buddy, &budRect);
- MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Buddy), (POINT *)(&budRect.left), 2);
-
- /* now do the positioning */
- if (dwStyle & UDS_ALIGNLEFT) {
- x = budRect.left;
- budRect.left += DEFAULT_WIDTH + DEFAULT_XSEP;
- } else if (dwStyle & UDS_ALIGNRIGHT) {
- budRect.right -= DEFAULT_WIDTH + DEFAULT_XSEP;
- x = budRect.right+DEFAULT_XSEP;
- } else {
- x = budRect.right+DEFAULT_XSEP;
- }
+ if(dwStyle & UDS_ARROWKEYS){
+ /* Note that I don't clear the BUDDY_SUPERCLASS_WNDPROC property
+ when we reset the upDown ctrl buddy to another buddy because it is not
+ good to break the window proc chain. */
+ if (!GetPropA(bud, BUDDY_SUPERCLASS_WNDPROC)) {
+ baseWndProc = (WNDPROC)SetWindowLongW(bud, GWL_WNDPROC, (LPARAM)UPDOWN_Buddy_SubclassProc);
+ SetPropA(bud, BUDDY_SUPERCLASS_WNDPROC, (HANDLE)baseWndProc);
+ }
+ }
- /* first adjust the buddy to accomodate the up/down */
- SetWindowPos(infoPtr->Buddy, 0, budRect.left, budRect.top,
- budRect.right - budRect.left, budRect.bottom - budRect.top,
- SWP_NOACTIVATE|SWP_NOZORDER);
-
- /* now position the up/down */
- /* Since the UDS_ALIGN* flags were used, */
- /* we will pick the position and size of the window. */
- width = DEFAULT_WIDTH;
-
- /*
- * If the updown has a buddy border, it has to overlap with the buddy
- * to look as if it is integrated with the buddy control.
- * We nudge the control or change it size to overlap.
- */
- if (UPDOWN_HasBuddyBorder(infoPtr)) {
- if(dwStyle & UDS_ALIGNLEFT)
- width += DEFAULT_BUDDYBORDER;
- else
- x -= DEFAULT_BUDDYBORDER;
- }
+ /* Get the rect of the buddy relative to its parent */
+ GetWindowRect(infoPtr->Buddy, &budRect);
+ MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Buddy), (POINT *)(&budRect.left), 2);
+
+ /* now do the positioning */
+ if (dwStyle & UDS_ALIGNLEFT) {
+ x = budRect.left;
+ budRect.left += DEFAULT_WIDTH + DEFAULT_XSEP;
+ } else if (dwStyle & UDS_ALIGNRIGHT) {
+ budRect.right -= DEFAULT_WIDTH + DEFAULT_XSEP;
+ x = budRect.right+DEFAULT_XSEP;
+ } else {
+ x = budRect.right+DEFAULT_XSEP;
+ }
- SetWindowPos(infoPtr->Self, infoPtr->Buddy, x,
- budRect.top - DEFAULT_ADDTOP, width,
- budRect.bottom - budRect.top + DEFAULT_ADDTOP + DEFAULT_ADDBOT,
- SWP_NOACTIVATE);
+ /* first adjust the buddy to accomodate the up/down */
+ SetWindowPos(infoPtr->Buddy, 0, budRect.left, budRect.top,
+ budRect.right - budRect.left, budRect.bottom - budRect.top,
+ SWP_NOACTIVATE|SWP_NOZORDER);
+
+ /* now position the up/down */
+ /* Since the UDS_ALIGN* flags were used, */
+ /* we will pick the position and size of the window. */
+ width = DEFAULT_WIDTH;
+
+ /*
+ * If the updown has a buddy border, it has to overlap with the buddy
+ * to look as if it is integrated with the buddy control.
+ * We nudge the control or change it size to overlap.
+ */
+ if (UPDOWN_HasBuddyBorder(infoPtr)) {
+ if(dwStyle & UDS_ALIGNLEFT)
+ width += DEFAULT_BUDDYBORDER;
+ else
+ x -= DEFAULT_BUDDYBORDER;
+ }
- return TRUE;
+ SetWindowPos(infoPtr->Self, infoPtr->Buddy, x,
+ budRect.top - DEFAULT_ADDTOP, width,
+ budRect.bottom - budRect.top + DEFAULT_ADDTOP + DEFAULT_ADDBOT,
+ SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOZORDER);
+ } else {
+ RECT rect;
+ GetWindowRect(infoPtr->Self, &rect);
+ MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Self), (POINT *)&rect, 2);
+ SetWindowPos(infoPtr->Self, 0, rect.left, rect.top, DEFAULT_WIDTH, rect.bottom - rect.top,
+ SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOZORDER);
+ }
+ return ret;
}
/***********************************************************************
@@ -859,9 +870,7 @@
return (LRESULT)infoPtr->Buddy;
case UDM_SETBUDDY:
- temp = (int)infoPtr->Buddy;
- UPDOWN_SetBuddy (infoPtr, (HWND)wParam);
- return temp;
+ return (LRESULT)UPDOWN_SetBuddy (infoPtr, (HWND)wParam);
case UDM_GETPOS:
temp = UPDOWN_GetBuddyInt (infoPtr);
More information about the wine-patches
mailing list