>From 7c2a9af8d1361cb4bef96f9f8dfe884dfa4d9bea Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov@codeweavers.com>
Date: Sun, 29 Jan 2012 19:27:17 +0300
Subject: [PATCH 6/7] Never release state image list

This reverts functional part of commit 1bc331f31f44a382a7f909d79da794d28c233fd7,
it breaks some applications that expect imagelist to be available after
control is destroyed.
---
 dlls/comctl32/tests/treeview.c |   27 +++++++++++++++++++++++++--
 dlls/comctl32/treeview.c       |   14 --------------
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c
index c99d480..8c0ec93 100644
--- a/dlls/comctl32/tests/treeview.c
+++ b/dlls/comctl32/tests/treeview.c
@@ -1607,9 +1607,9 @@ static void test_htreeitem_layout(void)
 
 static void test_TVS_CHECKBOXES(void)
 {
-    HIMAGELIST himl;
+    HIMAGELIST himl, himl2;
+    HWND hTree, hTree2;
     TVITEMA item;
-    HWND hTree;
     DWORD ret;
 
     hTree = create_treeview_control(0);
@@ -1639,6 +1639,10 @@ static void test_TVS_CHECKBOXES(void)
     himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
     ok(himl != NULL, "got %p\n", himl);
 
+    himl2 = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
+    ok(himl2 != NULL, "got %p\n", himl2);
+    ok(himl2 == himl, "got %p, expected %p\n", himl2, himl);
+
     item.hItem = hRoot;
     item.mask = TVIF_STATE;
     item.state = 0;
@@ -1655,6 +1659,25 @@ static void test_TVS_CHECKBOXES(void)
     expect(TRUE, ret);
     ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
 
+    /* create another control and check its checkbox list */
+    hTree2 = create_treeview_control(0);
+    fill_tree(hTree2);
+
+    /* set some index for a child */
+    item.hItem = hChild;
+    item.mask = TVIF_STATE;
+    item.state = INDEXTOSTATEIMAGEMASK(4);
+    item.stateMask = TVIS_STATEIMAGEMASK;
+    ret = SendMessageA(hTree2, TVM_SETITEMA, 0, (LPARAM)&item);
+    expect(TRUE, ret);
+
+    /* enabling check boxes set all items to 1 state image index */
+    SetWindowLongA(hTree2, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
+    himl2 = (HIMAGELIST)SendMessageA(hTree2, TVM_GETIMAGELIST, TVSIL_STATE, 0);
+    ok(himl2 != NULL, "got %p\n", himl2);
+    ok(himl != himl2, "got %p, expected %p\n", himl2, himl);
+
+    DestroyWindow(hTree2);
     DestroyWindow(hTree);
 
     /* the same, but initially created with TVS_CHECKBOXES */
diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c
index c5f3bb3..3f4fdc6 100644
--- a/dlls/comctl32/treeview.c
+++ b/dlls/comctl32/treeview.c
@@ -66,14 +66,7 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(treeview);
 
-enum StateListType
-{
-  OriginInternal,
-  OriginUser
-};
-
 /* internal structures */
-
 typedef struct _TREEITEM    /* HTREEITEM is a _TREEINFO *. */
 {
   HTREEITEM parent;         /* handle to parent or 0 if at root */
@@ -162,7 +155,6 @@ typedef struct tagTREEVIEW_INFO
   HIMAGELIST    himlState;
   int           stateImageHeight;
   int           stateImageWidth;
-  enum StateListType statehimlType;
   HDPA          items;
 
   DWORD lastKeyPressTimestamp;
@@ -1793,11 +1785,8 @@ TREEVIEW_SetImageList(TREEVIEW_INFO *infoPtr, UINT type, HIMAGELIST himlNew)
 	infoPtr->himlState = himlNew;
 
 	if (himlNew)
-	{
 	    ImageList_GetIconSize(himlNew, &infoPtr->stateImageWidth,
 				  &infoPtr->stateImageHeight);
-	    infoPtr->statehimlType = OriginUser;
-	}
 	else
 	{
 	    infoPtr->stateImageWidth = 0;
@@ -4970,7 +4959,6 @@ TREEVIEW_InitCheckboxes(TREEVIEW_INFO *infoPtr)
     int nIndex;
 
     infoPtr->himlState = ImageList_Create(16, 16, ILC_COLOR | ILC_MASK, 3, 0);
-    infoPtr->statehimlType = OriginInternal;
 
     hdcScreen = GetDC(0);
 
@@ -5134,8 +5122,6 @@ TREEVIEW_Destroy(TREEVIEW_INFO *infoPtr)
 
     CloseThemeData (GetWindowTheme (infoPtr->hwnd));
 
-    if (infoPtr->statehimlType == OriginInternal)
-        ImageList_Destroy(infoPtr->himlState);
     /* Deassociate treeview from the window before doing anything drastic. */
     SetWindowLongPtrW(infoPtr->hwnd, 0, 0);
 
-- 
1.5.6.5

