[PATCH v3 0/3] MR10059: comctl32: Fix the bug when the cInitial is too large which lead to...
I'm sorry I have pushed another mr for this topic due to my fault for pushing to the master branch of my forked project. This is about the failure of CreateDIBSection in ImageList_Create. Last discussion is in !10039 (https://gitlab.winehq.org/wine/wine/-/merge_requests/10039). I have made my last fix in https://gitlab.winehq.org/wine/wine/-/merge_requests/10039#note_129134. Please review it again @zhiyi . I am sorry for making a new merge request again. -- v3: comctl32: Expand only when the range is exceeded in ImageList_Add. comctl32: Fix the bug when the cInitial is too large which lead to CreateDIBSection fails. comctl32/tests: Add tests for the large cInitial in ImageList_CreateImage. https://gitlab.winehq.org/wine/wine/-/merge_requests/10059
From: Kun Yang <yangkun@uniontech.com> Logs: test ImageList_CreateImage for a large cInitial and determine the value of cMaxImage. Signed-off-by: Kun Yang <yangkun@uniontech.com> --- dlls/comctl32/tests/imagelist.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/dlls/comctl32/tests/imagelist.c b/dlls/comctl32/tests/imagelist.c index 68ad0ce7a4c..1109d689d43 100644 --- a/dlls/comctl32/tests/imagelist.c +++ b/dlls/comctl32/tests/imagelist.c @@ -2207,6 +2207,12 @@ static void test_create_destroy(void) INT cx, cy; BOOL rc; INT ret; + HDC hdc; + HBITMAP hbm; + BITMAPINFO bmi; + void *bits; + IMAGEINFO info; + BOOL result; /* list with zero or negative image dimensions */ himl = pImageList_Create(0, 0, ILC_COLOR16, 0, 3); @@ -2263,6 +2269,31 @@ static void test_create_destroy(void) ok(himl == NULL, "got %p\n", himl); himl = pImageList_Create(1, -1, ILC_COLORDDB, 4, 4); ok(himl == NULL, "got %p\n", himl); + + /* Test create large cInitial image count */ + himl = pImageList_Create(32, 32, ILC_COLOR32 | ILC_MASK, 0xc0c0c0, 1); + hdc = CreateCompatibleDC(NULL); + memset(&bmi, 0, sizeof(bmi)); + bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); + bmi.bmiHeader.biWidth = 32; + bmi.bmiHeader.biHeight = -32; + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biBitCount = 32; + bmi.bmiHeader.biCompression = BI_RGB; + hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &bits, NULL, 0); + ret = pImageList_AddMasked(himl, hbm, RGB(0, 0, 0)); + ret = pImageList_GetImageInfo(himl, 0, &info); + ok(ret, "got %d\n", ret); + todo_wine + ok(info.hbmImage != NULL, "got %p\n", info.hbmImage); + ok(info.hbmMask != NULL, "got %p\n", info.hbmMask); + + /* Test cMaxImage = 1 when created by large cInitial image count */ + result = pImageList_Replace(himl, 0, hbm, NULL); + ok(result == TRUE, "failed to replace bitmap 1\n"); + result = pImageList_Replace(himl, 1, hbm, NULL); + todo_wine + ok(result == FALSE, "succesffuly replaced bitmap 2, wrong\n"); } static void check_color_table(const char *name, HDC hdc, HIMAGELIST himl, UINT ilc, -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10059
From: Kun Yang <yangkun@uniontech.com> Logs: When CreateDIBSection does not return a valid hbitmap, the source image is lost that only masked icon is shown in imagelist. Signed-off-by: Kun Yang <yangkun@uniontech.com> --- dlls/comctl32/imagelist.c | 9 +++++++++ dlls/comctl32/tests/imagelist.c | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dlls/comctl32/imagelist.c b/dlls/comctl32/imagelist.c index ab65bca7c07..5788bf22a53 100644 --- a/dlls/comctl32/imagelist.c +++ b/dlls/comctl32/imagelist.c @@ -3089,6 +3089,15 @@ static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count) } } hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, NULL, 0, 0); + if(!hbmNewBitmap) + { + UINT newImageCount = 1; + /*if CreateDIBSection failed, allocate for 1 image only.*/ + bmi->bmiHeader.biHeight = newImageCount * himl->cy; + hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, NULL, 0, 0); + /*the max image count is set to 1, expand when exceeded.*/ + himl->cMaxImage = newImageCount; + } } else /*if (ilc == ILC_COLORDDB)*/ { diff --git a/dlls/comctl32/tests/imagelist.c b/dlls/comctl32/tests/imagelist.c index 1109d689d43..6c7be6a7319 100644 --- a/dlls/comctl32/tests/imagelist.c +++ b/dlls/comctl32/tests/imagelist.c @@ -2284,7 +2284,6 @@ static void test_create_destroy(void) ret = pImageList_AddMasked(himl, hbm, RGB(0, 0, 0)); ret = pImageList_GetImageInfo(himl, 0, &info); ok(ret, "got %d\n", ret); - todo_wine ok(info.hbmImage != NULL, "got %p\n", info.hbmImage); ok(info.hbmMask != NULL, "got %p\n", info.hbmMask); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10059
From: Kun Yang <yangkun@uniontech.com> Logs: Aligning with Windows behavior. Signed-off-by: Kun Yang <yangkun@uniontech.com> --- dlls/comctl32/imagelist.c | 2 +- dlls/comctl32/tests/imagelist.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/dlls/comctl32/imagelist.c b/dlls/comctl32/imagelist.c index 5788bf22a53..83daacc02db 100644 --- a/dlls/comctl32/imagelist.c +++ b/dlls/comctl32/imagelist.c @@ -335,7 +335,7 @@ IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl, INT nImageCount) TRACE("%p has allocated %d, max %d, grow %d images\n", himl, himl->cCurImage, himl->cMaxImage, himl->cGrow); - if (himl->cCurImage + nImageCount < himl->cMaxImage) + if (himl->cCurImage + nImageCount <= himl->cMaxImage) return; nNewCount = himl->cMaxImage + max(nImageCount, himl->cGrow) + 1; diff --git a/dlls/comctl32/tests/imagelist.c b/dlls/comctl32/tests/imagelist.c index 6c7be6a7319..ca023b63bc0 100644 --- a/dlls/comctl32/tests/imagelist.c +++ b/dlls/comctl32/tests/imagelist.c @@ -2291,7 +2291,6 @@ static void test_create_destroy(void) result = pImageList_Replace(himl, 0, hbm, NULL); ok(result == TRUE, "failed to replace bitmap 1\n"); result = pImageList_Replace(himl, 1, hbm, NULL); - todo_wine ok(result == FALSE, "succesffuly replaced bitmap 2, wrong\n"); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10059
participants (2)
-
Kun Yang -
Kun Yang (@yangkun)