comctl32/updown: Simplify buddy subclassing using SetWindowSubclass chain.

This commit is contained in:
Nikolay Sivov 2009-12-22 02:42:31 +03:00 committed by Alexandre Julliard
parent 705aee525a
commit 6cc141ff59
2 changed files with 20 additions and 33 deletions

View File

@ -481,8 +481,7 @@ static void test_updown_buddy(void)
if (pSetWindowSubclass) if (pSetWindowSubclass)
{ {
/* updown uses subclass helpers for buddy on >5.8x systems */ /* updown uses subclass helpers for buddy on >5.8x systems */
todo_wine ok(GetPropA(buddy, "CC32SubclassInfo") != NULL, "Expected CC32SubclassInfo property\n");
ok(GetPropA(buddy, "CC32SubclassInfo") != NULL, "Expected CC32SubclassInfo property\n");
} }
DestroyWindow(updown); DestroyWindow(updown);

View File

@ -100,9 +100,9 @@ typedef struct
#define UPDOWN_GetInfoPtr(hwnd) ((UPDOWN_INFO *)GetWindowLongPtrW (hwnd,0)) #define UPDOWN_GetInfoPtr(hwnd) ((UPDOWN_INFO *)GetWindowLongPtrW (hwnd,0))
#define COUNT_OF(a) (sizeof(a)/sizeof(a[0])) #define COUNT_OF(a) (sizeof(a)/sizeof(a[0]))
static const WCHAR BUDDY_UPDOWN_HWND[] = { 'b', 'u', 'd', 'd', 'y', 'U', 'p', 'D', 'o', 'w', 'n', 'H', 'W', 'N', 'D', 0 }; /* id used for SetWindowSubclass */
static const WCHAR BUDDY_SUPERCLASS_WNDPROC[] = { 'b', 'u', 'd', 'd', 'y', 'S', 'u', 'p', 'p', 'e', 'r', #define BUDDY_SUBCLASSID 1
'C', 'l', 'a', 's', 's', 'W', 'n', 'd', 'P', 'r', 'o', 'c', 0 };
static void UPDOWN_DoAction (UPDOWN_INFO *infoPtr, int delta, int action); static void UPDOWN_DoAction (UPDOWN_INFO *infoPtr, int delta, int action);
/*********************************************************************** /***********************************************************************
@ -518,14 +518,13 @@ static LRESULT UPDOWN_MouseWheel(UPDOWN_INFO *infoPtr, WPARAM wParam)
* control. * control.
*/ */
static LRESULT CALLBACK static LRESULT CALLBACK
UPDOWN_Buddy_SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) UPDOWN_Buddy_SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
UINT_PTR uId, DWORD_PTR ref_data)
{ {
WNDPROC superClassWndProc = (WNDPROC)GetPropW(hwnd, BUDDY_SUPERCLASS_WNDPROC); UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr((HWND)ref_data);
HWND upDownHwnd = GetPropW(hwnd, BUDDY_UPDOWN_HWND);
UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(upDownHwnd);
TRACE("hwnd=%p, wndProc=%p, uMsg=%04x, wParam=%08lx, lParam=%08lx\n", TRACE("hwnd=%p, uMsg=%04x, wParam=%08lx, lParam=%08lx\n",
hwnd, superClassWndProc, uMsg, wParam, lParam); hwnd, uMsg, wParam, lParam);
switch(uMsg) switch(uMsg)
{ {
@ -542,7 +541,7 @@ UPDOWN_Buddy_SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
break; break;
} }
return CallWindowProcW( superClassWndProc, hwnd, uMsg, wParam, lParam); return DefSubclassProc(hwnd, uMsg, wParam, lParam);
} }
/*********************************************************************** /***********************************************************************
@ -559,7 +558,6 @@ static HWND UPDOWN_SetBuddy (UPDOWN_INFO* infoPtr, HWND bud)
{ {
RECT budRect; /* new coord for the buddy */ RECT budRect; /* new coord for the buddy */
int x, width; /* new x position and width for the up-down */ int x, width; /* new x position and width for the up-down */
WNDPROC baseWndProc;
WCHAR buddyClass[40]; WCHAR buddyClass[40];
HWND ret; HWND ret;
@ -567,20 +565,15 @@ static HWND UPDOWN_SetBuddy (UPDOWN_INFO* infoPtr, HWND bud)
ret = infoPtr->Buddy; ret = infoPtr->Buddy;
/* there is already a body assigned */ /* there is already a buddy assigned */
if (infoPtr->Buddy) RemovePropW(infoPtr->Buddy, BUDDY_UPDOWN_HWND); if (infoPtr->Buddy) RemoveWindowSubclass(infoPtr->Buddy, UPDOWN_Buddy_SubclassProc,
BUDDY_SUBCLASSID);
if(!IsWindow(bud)) if (!IsWindow(bud)) bud = NULL;
bud = 0;
/* Store buddy window handle */ /* Store buddy window handle */
infoPtr->Buddy = bud; infoPtr->Buddy = bud;
if(bud) { if(bud) {
/* keep upDown ctrl hwnd in a buddy property */
SetPropW( bud, BUDDY_UPDOWN_HWND, infoPtr->Self);
/* Store buddy window class type */ /* Store buddy window class type */
infoPtr->BuddyType = BUDDY_TYPE_UNKNOWN; infoPtr->BuddyType = BUDDY_TYPE_UNKNOWN;
if (GetClassNameW(bud, buddyClass, COUNT_OF(buddyClass))) { if (GetClassNameW(bud, buddyClass, COUNT_OF(buddyClass))) {
@ -590,15 +583,9 @@ static HWND UPDOWN_SetBuddy (UPDOWN_INFO* infoPtr, HWND bud)
infoPtr->BuddyType = BUDDY_TYPE_LISTBOX; infoPtr->BuddyType = BUDDY_TYPE_LISTBOX;
} }
if (infoPtr->dwStyle & UDS_ARROWKEYS) { if (infoPtr->dwStyle & UDS_ARROWKEYS)
/* Note that I don't clear the BUDDY_SUPERCLASS_WNDPROC property SetWindowSubclass(bud, UPDOWN_Buddy_SubclassProc, BUDDY_SUBCLASSID,
when we reset the upDown ctrl buddy to another buddy because it is not (DWORD_PTR)infoPtr->Self);
good to break the window proc chain. */
if (!GetPropW(bud, BUDDY_SUPERCLASS_WNDPROC)) {
baseWndProc = (WNDPROC)SetWindowLongPtrW(bud, GWLP_WNDPROC, (LPARAM)UPDOWN_Buddy_SubclassProc);
SetPropW(bud, BUDDY_SUPERCLASS_WNDPROC, baseWndProc);
}
}
/* Get the rect of the buddy relative to its parent */ /* Get the rect of the buddy relative to its parent */
GetWindowRect(infoPtr->Buddy, &budRect); GetWindowRect(infoPtr->Buddy, &budRect);
@ -892,8 +879,9 @@ static LRESULT WINAPI UpDownWindowProc(HWND hwnd, UINT message, WPARAM wParam, L
case WM_DESTROY: case WM_DESTROY:
Free (infoPtr->AccelVect); Free (infoPtr->AccelVect);
if(infoPtr->Buddy) RemovePropW(infoPtr->Buddy, BUDDY_UPDOWN_HWND); if (infoPtr->Buddy)
RemoveWindowSubclass(infoPtr->Buddy, UPDOWN_Buddy_SubclassProc,
BUDDY_SUBCLASSID);
Free (infoPtr); Free (infoPtr);
SetWindowLongPtrW (hwnd, 0, 0); SetWindowLongPtrW (hwnd, 0, 0);
theme = GetWindowTheme (hwnd); theme = GetWindowTheme (hwnd);