>From 3150bb35099674213826f9168159e077649fa111 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov@codeweavers.com>
Date: Thu, 16 Feb 2012 12:31:54 +0300
Subject: [PATCH 3/3] Fix TB_SETEXTENDEDSTYLE to use mask passed in wParam

---
 dlls/comctl32/tests/toolbar.c |   62 +++++++++++++++++++++++++++++++++++++++++
 dlls/comctl32/toolbar.c       |   18 ++++++-----
 2 files changed, 72 insertions(+), 8 deletions(-)

diff --git a/dlls/comctl32/tests/toolbar.c b/dlls/comctl32/tests/toolbar.c
index 386511a..01e3a41 100644
--- a/dlls/comctl32/tests/toolbar.c
+++ b/dlls/comctl32/tests/toolbar.c
@@ -1840,6 +1840,67 @@ static void test_create(void)
     DestroyWindow(hwnd);
 }
 
+typedef struct {
+    DWORD mask;
+    DWORD style;
+    DWORD style_set;
+} extended_style_t;
+
+static const extended_style_t extended_style_test[] = {
+    {
+      TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER,
+      TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER,
+      TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER,
+    },
+    {
+      TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS,
+      TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS,
+    },
+
+    { 0, TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS },
+    { 0, 0, 0 },
+    { 0, TBSTYLE_EX_DRAWDDARROWS, TBSTYLE_EX_DRAWDDARROWS },
+    { 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS, TBSTYLE_EX_HIDECLIPPEDBUTTONS },
+
+    { 0, 0, 0 },
+    { TBSTYLE_EX_HIDECLIPPEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS, 0 },
+    { TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_HIDECLIPPEDBUTTONS, 0 },
+    { TBSTYLE_EX_DOUBLEBUFFER, TBSTYLE_EX_MIXEDBUTTONS, 0 },
+
+    {
+      TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS,
+      TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS
+    },
+    {
+      TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS,
+      TBSTYLE_EX_DOUBLEBUFFER, TBSTYLE_EX_DOUBLEBUFFER
+    }
+};
+
+static void test_TB_GET_SET_EXTENDEDSTYLE(void)
+{
+    DWORD style, oldstyle, oldstyle2;
+    const extended_style_t *ptr;
+    HWND hwnd;
+    int i;
+
+    rebuild_toolbar(&hwnd);
+
+    for (i = 0; i < sizeof(extended_style_test)/sizeof(extended_style_t); i++)
+    {
+        ptr = &extended_style_test[i];
+
+        oldstyle2 = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
+
+        oldstyle = SendMessageA(hwnd, TB_SETEXTENDEDSTYLE, ptr->mask, ptr->style);
+        ok(oldstyle == oldstyle2, "%d: got old style 0x%08x, expected 0x%08x\n", i, oldstyle, oldstyle2);
+        style = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
+        ok(style == ptr->style_set, "%d: got style 0x%08x, expected 0x%08x\n", i, style, ptr->style_set);
+    }
+
+    DestroyWindow(hwnd);
+}
+
 START_TEST(toolbar)
 {
     WNDCLASSA wc;
@@ -1881,6 +1942,7 @@ START_TEST(toolbar)
     test_tooltip();
     test_get_set_style();
     test_create();
+    test_TB_GET_SET_EXTENDEDSTYLE();
 
     PostQuitMessage(0);
     while(GetMessageA(&msg,0,0,0)) {
diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c
index 7c1815c..7901f86 100644
--- a/dlls/comctl32/toolbar.c
+++ b/dlls/comctl32/toolbar.c
@@ -4481,20 +4481,22 @@ TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
  *  (MSDN says that this parameter is reserved)
  */
 static LRESULT
-TOOLBAR_SetExtendedStyle (TOOLBAR_INFO *infoPtr, LPARAM lParam)
+TOOLBAR_SetExtendedStyle (TOOLBAR_INFO *infoPtr, DWORD mask, DWORD style)
 {
-    DWORD dwOldStyle;
+    DWORD old_style = infoPtr->dwExStyle;
 
-    dwOldStyle = infoPtr->dwExStyle;
-    infoPtr->dwExStyle = (DWORD)lParam;
+    TRACE("mask=0x%08x, style=0x%08x\n", mask, style);
 
-    TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
+    if (mask)
+	infoPtr->dwExStyle = (old_style & ~mask) | (style & mask);
+    else
+	infoPtr->dwExStyle = style;
 
     if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
 	FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
 	      (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
 
-    if ((dwOldStyle ^ infoPtr->dwExStyle) & TBSTYLE_EX_MIXEDBUTTONS)
+    if ((old_style ^ infoPtr->dwExStyle) & TBSTYLE_EX_MIXEDBUTTONS)
         TOOLBAR_CalcToolbar(infoPtr);
     else
         TOOLBAR_LayoutToolbar(infoPtr);
@@ -4502,7 +4504,7 @@ TOOLBAR_SetExtendedStyle (TOOLBAR_INFO *infoPtr, LPARAM lParam)
     TOOLBAR_AutoSize(infoPtr);
     InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
 
-    return (LRESULT)dwOldStyle;
+    return old_style;
 }
 
 
@@ -6629,7 +6631,7 @@ ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 	    return TOOLBAR_SetDrawTextFlags (infoPtr, wParam, lParam);
 
 	case TB_SETEXTENDEDSTYLE:
-	    return TOOLBAR_SetExtendedStyle (infoPtr, lParam);
+	    return TOOLBAR_SetExtendedStyle (infoPtr, wParam, lParam);
 
 	case TB_SETHOTIMAGELIST:
 	    return TOOLBAR_SetHotImageList (infoPtr, wParam, (HIMAGELIST)lParam);
-- 
1.5.6.5

