]> git.saurik.com Git - wxWidgets.git/commitdiff
don't use HBMMENU_CALLBACK under Windows Vista as this results in losing the themed...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 21 Mar 2009 21:31:21 +0000 (21:31 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 21 Mar 2009 21:31:21 +0000 (21:31 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59707 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/menu.cpp

index b7c688c171ed54f9f3b083a705076be5a71c4797..0876b1a5732457acb290acc240258e174a09c4b2 100644 (file)
@@ -33,6 +33,7 @@
     #include "wx/utils.h"
     #include "wx/intl.h"
     #include "wx/log.h"
     #include "wx/utils.h"
     #include "wx/intl.h"
     #include "wx/log.h"
+    #include "wx/image.h"
 #endif
 
 #if wxUSE_OWNER_DRAWN
 #endif
 
 #if wxUSE_OWNER_DRAWN
@@ -490,20 +491,44 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
                 mii.wID = id;
             }
 
                 mii.wID = id;
             }
 
-            // we can't pass HBITMAP directly as hbmpItem for 2 reasons:
-            //  1. we can't draw it with transparency then (this is not
+            // Under versions of Windows older than Vista we can't pass HBITMAP
+            // directly as hbmpItem for 2 reasons:
+            //  1. We can't draw it with transparency then (this is not
             //     very important now but would be with themed menu bg)
             //     very important now but would be with themed menu bg)
-            //  2. worse, Windows inverts the bitmap for the selected
+            //  2. Worse, Windows inverts the bitmap for the selected
             //     item and this looks downright ugly
             //
             //     item and this looks downright ugly
             //
-            // so instead draw it ourselves in MSWOnDrawItem()
+            // so we prefer to instead draw it ourselves in MSWOnDrawItem().
             mii.dwItemData = reinterpret_cast<ULONG_PTR>(pItem);
             if ( pItem->IsCheckable() )
             {
                 mii.hbmpChecked =
                 mii.hbmpUnchecked = HBMMENU_CALLBACK;
             }
             mii.dwItemData = reinterpret_cast<ULONG_PTR>(pItem);
             if ( pItem->IsCheckable() )
             {
                 mii.hbmpChecked =
                 mii.hbmpUnchecked = HBMMENU_CALLBACK;
             }
-            mii.hbmpItem = HBMMENU_CALLBACK;
+
+            // However under Vista using HBMMENU_CALLBACK causes the entire
+            // menu to be drawn using the classic theme instead of the current
+            // one and it does handle transparency just fine so do use the real
+            // bitmap there
+#if wxUSE_IMAGE
+            if ( wxGetWinVersion() >= wxWinVersion_Vista )
+            {
+                // but we need to have transparency for this to work so ensure
+                // that we do
+                wxImage img(pItem->GetBitmap().ConvertToImage());
+                if ( !img.HasAlpha() )
+                {
+                    img.InitAlpha();
+                    pItem->SetBitmap(img);
+                }
+
+                mii.hbmpItem = GetHbitmapOf(pItem->GetBitmap());
+            }
+            else // pre-Vista
+#endif // wxUSE_IMAGE
+            {
+                mii.hbmpItem = HBMMENU_CALLBACK;
+            }
 
             ok = ::InsertMenuItem(GetHmenu(), pos, TRUE /* by pos */, &mii);
             if ( !ok )
 
             ok = ::InsertMenuItem(GetHmenu(), pos, TRUE /* by pos */, &mii);
             if ( !ok )