Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/comctl32/dpa.c | 6 +++--- dlls/comctl32/tests/dpa.c | 2 +- include/commctrl.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/dlls/comctl32/dpa.c b/dlls/comctl32/dpa.c index 36b3a422e8c..6dce9575b59 100644 --- a/dlls/comctl32/dpa.c +++ b/dlls/comctl32/dpa.c @@ -524,9 +524,9 @@ HDPA WINAPI DPA_Clone (const HDPA hdpa, HDPA hdpaNew) * Success: pointer * Failure: NULL */ -LPVOID WINAPI DPA_GetPtr (HDPA hdpa, INT nIndex) +LPVOID WINAPI DPA_GetPtr (HDPA hdpa, INT_PTR nIndex) { - TRACE("(%p %d)\n", hdpa, nIndex); + TRACE("(%p %ld)\n", hdpa, nIndex);
if (!hdpa) return NULL; @@ -535,7 +535,7 @@ LPVOID WINAPI DPA_GetPtr (HDPA hdpa, INT nIndex) return NULL; } if ((nIndex < 0) || (nIndex >= hdpa->nItemCount)) { - WARN("not enough pointers in array (%d vs %d).\n",nIndex,hdpa->nItemCount); + WARN("not enough pointers in array (%ld vs %d).\n",nIndex,hdpa->nItemCount); return NULL; }
diff --git a/dlls/comctl32/tests/dpa.c b/dlls/comctl32/tests/dpa.c index cbe3ab7fb2b..4a446a8e2c5 100644 --- a/dlls/comctl32/tests/dpa.c +++ b/dlls/comctl32/tests/dpa.c @@ -49,7 +49,7 @@ static PVOID (WINAPI *pDPA_DeletePtr)(HDPA,INT); static BOOL (WINAPI *pDPA_Destroy)(HDPA); static VOID (WINAPI *pDPA_DestroyCallback)(HDPA,PFNDPAENUMCALLBACK,PVOID); static VOID (WINAPI *pDPA_EnumCallback)(HDPA,PFNDPAENUMCALLBACK,PVOID); -static INT (WINAPI *pDPA_GetPtr)(HDPA,INT); +static PVOID (WINAPI *pDPA_GetPtr)(HDPA,INT_PTR); static INT (WINAPI *pDPA_GetPtrIndex)(HDPA,PVOID); static BOOL (WINAPI *pDPA_Grow)(HDPA,INT); static INT (WINAPI *pDPA_InsertPtr)(HDPA,INT,PVOID); diff --git a/include/commctrl.h b/include/commctrl.h index dfd2f4a37d2..97e2fcc4df0 100644 --- a/include/commctrl.h +++ b/include/commctrl.h @@ -5170,7 +5170,7 @@ BOOL WINAPI DPA_Destroy(HDPA); LPVOID WINAPI DPA_DeletePtr(HDPA, INT); BOOL WINAPI DPA_DeleteAllPtrs(HDPA); BOOL WINAPI DPA_SetPtr(HDPA, INT, LPVOID); -LPVOID WINAPI DPA_GetPtr(HDPA, INT); +LPVOID WINAPI DPA_GetPtr(HDPA, INT_PTR); INT WINAPI DPA_GetPtrIndex(HDPA, LPCVOID); ULONGLONG WINAPI DPA_GetSize(HDPA); BOOL WINAPI DPA_Grow(HDPA, INT);
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/comctl32/listview.c | 69 ++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 46 deletions(-)
diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c index 150771b8937..ee67193ff27 100644 --- a/dlls/comctl32/listview.c +++ b/dlls/comctl32/listview.c @@ -254,10 +254,6 @@ typedef struct tagLISTVIEW_INFO INT nItemHeight; INT nItemWidth;
- /* sorting */ - PFNLVCOMPARE pfnCompare; /* sorting callback pointer */ - LPARAM lParamSort; - /* style */ DWORD dwStyle; /* the cached window GWL_STYLE */ DWORD dwLvExStyle; /* extended listview style */ @@ -9232,52 +9228,31 @@ static INT LISTVIEW_SetView(LISTVIEW_INFO *infoPtr, DWORD nView)
/* LISTVIEW_SetWorkAreas */
-/*** - * DESCRIPTION: - * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS - * - * PARAMETER(S): - * [I] first : pointer to first ITEM_INFO to compare - * [I] second : pointer to second ITEM_INFO to compare - * [I] lParam : HWND of control - * - * RETURN: - * if first comes before second : negative - * if first comes after second : positive - * if first and second are equivalent : zero - */ +struct sorting_context +{ + LISTVIEW_INFO *infoPtr; + PFNLVCOMPARE compare_func; + LPARAM lParam; +}; + +/* DPA_Sort() callback used for LVM_SORTITEMS */ static INT WINAPI LISTVIEW_CallBackCompare(LPVOID first, LPVOID second, LPARAM lParam) { - LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)lParam; - ITEM_INFO* lv_first = DPA_GetPtr( first, 0 ); - ITEM_INFO* lv_second = DPA_GetPtr( second, 0 ); + struct sorting_context *context = (struct sorting_context *)lParam; + ITEM_INFO* lv_first = DPA_GetPtr( first, 0 ); + ITEM_INFO* lv_second = DPA_GetPtr( second, 0 );
- /* Forward the call to the client defined callback */ - return (infoPtr->pfnCompare)( lv_first->lParam , lv_second->lParam, infoPtr->lParamSort ); + return context->compare_func(lv_first->lParam, lv_second->lParam, context->lParam); }
-/*** - * DESCRIPTION: - * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX - * - * PARAMETER(S): - * [I] first : pointer to first ITEM_INFO to compare - * [I] second : pointer to second ITEM_INFO to compare - * [I] lParam : HWND of control - * - * RETURN: - * if first comes before second : negative - * if first comes after second : positive - * if first and second are equivalent : zero - */ +/* DPA_Sort() callback used for LVM_SORTITEMSEX */ static INT WINAPI LISTVIEW_CallBackCompareEx(LPVOID first, LPVOID second, LPARAM lParam) { - LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)lParam; - INT first_idx = DPA_GetPtrIndex( infoPtr->hdpaItems, first ); - INT second_idx = DPA_GetPtrIndex( infoPtr->hdpaItems, second ); + struct sorting_context *context = (struct sorting_context *)lParam; + INT first_idx = DPA_GetPtrIndex( context->infoPtr->hdpaItems, first ); + INT second_idx = DPA_GetPtrIndex( context->infoPtr->hdpaItems, second );
- /* Forward the call to the client defined callback */ - return (infoPtr->pfnCompare)( first_idx, second_idx, infoPtr->lParamSort ); + return context->compare_func(first_idx, second_idx, context->lParam); }
/*** @@ -9301,6 +9276,7 @@ static BOOL LISTVIEW_SortItems(LISTVIEW_INFO *infoPtr, PFNLVCOMPARE pfnCompare, ITEM_INFO *lpItem; LPVOID selectionMarkItem = NULL; LPVOID focusedItem = NULL; + struct sorting_context context; int i;
TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare, lParamSort); @@ -9322,12 +9298,13 @@ static BOOL LISTVIEW_SortItems(LISTVIEW_INFO *infoPtr, PFNLVCOMPARE pfnCompare, if (infoPtr->nFocusedItem >= 0) focusedItem = DPA_GetPtr(infoPtr->hdpaItems, infoPtr->nFocusedItem);
- infoPtr->pfnCompare = pfnCompare; - infoPtr->lParamSort = lParamSort; + context.infoPtr = infoPtr; + context.compare_func = pfnCompare; + context.lParam = lParamSort; if (IsEx) - DPA_Sort(infoPtr->hdpaItems, LISTVIEW_CallBackCompareEx, (LPARAM)infoPtr); + DPA_Sort(infoPtr->hdpaItems, LISTVIEW_CallBackCompareEx, (LPARAM)&context); else - DPA_Sort(infoPtr->hdpaItems, LISTVIEW_CallBackCompare, (LPARAM)infoPtr); + DPA_Sort(infoPtr->hdpaItems, LISTVIEW_CallBackCompare, (LPARAM)&context);
/* restore selection ranges */ for (i=0; i < infoPtr->nItemCount; i++)
Issue reported by Haoyang Chen.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/comctl32/listview.c | 17 ++++++++++------- include/commctrl.h | 1 + 2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c index ee67193ff27..799ec509f33 100644 --- a/dlls/comctl32/listview.c +++ b/dlls/comctl32/listview.c @@ -9230,7 +9230,7 @@ static INT LISTVIEW_SetView(LISTVIEW_INFO *infoPtr, DWORD nView)
struct sorting_context { - LISTVIEW_INFO *infoPtr; + HDPA items; PFNLVCOMPARE compare_func; LPARAM lParam; }; @@ -9249,8 +9249,8 @@ static INT WINAPI LISTVIEW_CallBackCompare(LPVOID first, LPVOID second, LPARAM l static INT WINAPI LISTVIEW_CallBackCompareEx(LPVOID first, LPVOID second, LPARAM lParam) { struct sorting_context *context = (struct sorting_context *)lParam; - INT first_idx = DPA_GetPtrIndex( context->infoPtr->hdpaItems, first ); - INT second_idx = DPA_GetPtrIndex( context->infoPtr->hdpaItems, second ); + INT first_idx = DPA_GetPtrIndex( context->items, first ); + INT second_idx = DPA_GetPtrIndex( context->items, second );
return context->compare_func(first_idx, second_idx, context->lParam); } @@ -9272,7 +9272,7 @@ static INT WINAPI LISTVIEW_CallBackCompareEx(LPVOID first, LPVOID second, LPARAM static BOOL LISTVIEW_SortItems(LISTVIEW_INFO *infoPtr, PFNLVCOMPARE pfnCompare, LPARAM lParamSort, BOOL IsEx) { - HDPA hdpaSubItems; + HDPA hdpaSubItems, hdpaItems; ITEM_INFO *lpItem; LPVOID selectionMarkItem = NULL; LPVOID focusedItem = NULL; @@ -9288,6 +9288,7 @@ static BOOL LISTVIEW_SortItems(LISTVIEW_INFO *infoPtr, PFNLVCOMPARE pfnCompare,
/* if there are 0 or 1 items, there is no need to sort */ if (infoPtr->nItemCount < 2) return TRUE; + if (!(hdpaItems = DPA_Clone(infoPtr->hdpaItems, NULL))) return FALSE;
/* clear selection */ ranges_clear(infoPtr->selectionRanges); @@ -9298,13 +9299,15 @@ static BOOL LISTVIEW_SortItems(LISTVIEW_INFO *infoPtr, PFNLVCOMPARE pfnCompare, if (infoPtr->nFocusedItem >= 0) focusedItem = DPA_GetPtr(infoPtr->hdpaItems, infoPtr->nFocusedItem);
- context.infoPtr = infoPtr; + context.items = hdpaItems; context.compare_func = pfnCompare; context.lParam = lParamSort; if (IsEx) - DPA_Sort(infoPtr->hdpaItems, LISTVIEW_CallBackCompareEx, (LPARAM)&context); + DPA_Sort(hdpaItems, LISTVIEW_CallBackCompareEx, (LPARAM)&context); else - DPA_Sort(infoPtr->hdpaItems, LISTVIEW_CallBackCompare, (LPARAM)&context); + DPA_Sort(hdpaItems, LISTVIEW_CallBackCompare, (LPARAM)&context); + DPA_Destroy(infoPtr->hdpaItems); + infoPtr->hdpaItems = hdpaItems;
/* restore selection ranges */ for (i=0; i < infoPtr->nItemCount; i++) diff --git a/include/commctrl.h b/include/commctrl.h index 97e2fcc4df0..5614f64a979 100644 --- a/include/commctrl.h +++ b/include/commctrl.h @@ -5165,6 +5165,7 @@ typedef PVOID (CALLBACK *PFNDPAMERGE)(UINT,PVOID,PVOID,LPARAM); #define DPAM_UNION 0x00000004 #define DPAM_INTERSECT 0x00000008
+HDPA WINAPI DPA_Clone(const HDPA, HDPA); HDPA WINAPI DPA_Create(INT); BOOL WINAPI DPA_Destroy(HDPA); LPVOID WINAPI DPA_DeletePtr(HDPA, INT);
Please ignore this one, it fails on additional tests.