]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/tbar95.cpp
Applied patch [ 1310251 ] Fixed a pixel depth bug converting wxImageb to wxBitmap
[wxWidgets.git] / src / msw / tbar95.cpp
index 1286461f05f30afe1b34c85cdf8d72b0ad5f63a3..174a4630ee9ea1e85712d77f136d3778101cfff0 100644 (file)
 // headers
 // ----------------------------------------------------------------------------
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-    #pragma implementation "tbar95.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -93,9 +89,6 @@
 // these values correspond to those used by comctl32.dll
 #define DEFAULTBITMAPX   16
 #define DEFAULTBITMAPY   15
-#define DEFAULTBUTTONX   24
-#define DEFAULTBUTTONY   24
-#define DEFAULTBARHEIGHT 27
 
 // ----------------------------------------------------------------------------
 // wxWin macros
@@ -245,25 +238,20 @@ bool wxToolBar::Create(wxWindow *parent,
     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
     SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
 
-    // workaround for flat toolbar on Windows XP classic style
+    // workaround for flat toolbar on Windows XP classic style: we have to set
+    // the style after creating the control, doing it at creation time doesn't
+    // work
 #if wxUSE_UXTHEME
     if ( style & wxTB_FLAT )
     {
-        wxUxThemeEngine *p = wxUxThemeEngine::Get();
-        if ( !p || !p->IsThemeActive() )
-        {
-            DWORD dwToolbarStyle;
+        LRESULT style = ::SendMessage(GetHwnd(), TB_GETSTYLE, 0, 0L);
 
-            dwToolbarStyle = (DWORD)::SendMessage(GetHwnd(), TB_GETSTYLE, 0, 0L );
-
-            if ((dwToolbarStyle & TBSTYLE_FLAT) == 0)
-            {
-                dwToolbarStyle |= TBSTYLE_FLAT;
-                ::SendMessage(GetHwnd(), TB_SETSTYLE, 0, (LPARAM)dwToolbarStyle );
-            }
+        if ( !(style & TBSTYLE_FLAT) )
+        {
+            ::SendMessage(GetHwnd(), TB_SETSTYLE, 0, style | TBSTYLE_FLAT);
         }
     }
-#endif
+#endif // wxUSE_UXTHEME
 
     return true;
 }
@@ -521,6 +509,12 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
 
 void wxToolBar::CreateDisabledImageList()
 {
+    if (m_disabledImgList != NULL)
+    {
+        delete m_disabledImgList;
+        m_disabledImgList = NULL;
+    }
+
     // as we can't use disabled image list with older versions of comctl32.dll,
     // don't even bother creating it
     if ( wxTheApp->GetComCtl32Version() >= 470 )
@@ -540,14 +534,12 @@ void wxToolBar::CreateDisabledImageList()
                                             bmpDisabled.GetMask() != NULL,
                                             GetToolsCount()
                                         );
-                return;
+                break;
             }
         }
 
         // we don't have any disabled bitmaps
     }
-
-    m_disabledImgList = NULL;
 }
 
 bool wxToolBar::Realize()
@@ -562,21 +554,18 @@ bool wxToolBar::Realize()
     const bool isVertical = HasFlag(wxTB_VERTICAL);
 
     bool doRemap, doRemapBg, doTransparent;
-#ifdef __WXWINCE__
-    doRemapBg = false;
-    doRemap = false;
-    doTransparent = false;
-#else
-    if (wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 2)
+    doRemapBg = doRemap = doTransparent = false;
+
+#ifndef __WXWINCE__
+    int remapValue = (-1);
+    if (wxSystemOptions::HasOption(wxT("msw.remap")))
+        remapValue = wxSystemOptions::GetOptionInt(wxT("msw.remap"));
+
+    doTransparent = (remapValue == 2);
+    if (!doTransparent)
     {
-        doRemapBg = doRemap = false;
-        doTransparent = true;
-    }
-    else
-    {   doRemap = !wxSystemOptions::HasOption(wxT("msw.remap"))
-            || wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 1;
+        doRemap = (remapValue != 0);
         doRemapBg = !doRemap;
-        doTransparent = false;
     }
 #endif
 
@@ -611,13 +600,15 @@ bool wxToolBar::Realize()
         sizeBmp.x = m_defaultWidth;
         sizeBmp.y = m_defaultHeight;
 
-        const wxCoord totalBitmapWidth = m_defaultWidth * nTools,
+        const wxCoord totalBitmapWidth  = m_defaultWidth *
+                                          wx_truncate_cast(wxCoord, nTools),
                       totalBitmapHeight = m_defaultHeight;
 
         // Create a bitmap and copy all the tool bitmaps to it
         wxMemoryDC dcAllButtons;
         wxBitmap bitmap(totalBitmapWidth, totalBitmapHeight);
         dcAllButtons.SelectObject(bitmap);
+
 #ifdef __WXWINCE__
         dcAllButtons.SetBackground(wxBrush(wxColour(192,192,192)));
 #else
@@ -642,8 +633,6 @@ bool wxToolBar::Realize()
                 totalBitmapWidth, totalBitmapHeight);
 
             dcAllButtons.SelectObject(bitmap);
-
-
         }
 #endif // !__WXWINCE__
 
@@ -690,17 +679,20 @@ bool wxToolBar::Realize()
                         wxImage imgGreyed;
                         wxCreateGreyedImage(bmp.ConvertToImage(), imgGreyed);
 
-                        // we need to have light grey background colour for
-                        // MapBitmap() to work correctly
-                        for ( int y = 0; y < h; y++ )
+                        if (doRemap)
                         {
-                            for ( int x = 0; x < w; x++ )
+                            // we need to have light grey background colour for
+                            // MapBitmap() to work correctly
+                            for ( int y = 0; y < h; y++ )
                             {
-                                if ( imgGreyed.IsTransparent(x, y) )
-                                    imgGreyed.SetRGB(x, y,
-                                                     wxLIGHT_GREY->Red(),
-                                                     wxLIGHT_GREY->Green(),
-                                                     wxLIGHT_GREY->Blue());
+                                for ( int x = 0; x < w; x++ )
+                                {
+                                    if ( imgGreyed.IsTransparent(x, y) )
+                                        imgGreyed.SetRGB(x, y,
+                                                         wxLIGHT_GREY->Red(),
+                                                         wxLIGHT_GREY->Green(),
+                                                         wxLIGHT_GREY->Blue());
+                                }
                             }
                         }
 
@@ -708,7 +700,10 @@ bool wxToolBar::Realize()
                     }
 #endif // wxUSE_IMAGE
 
-                    MapBitmap(bmpDisabled.GetHBITMAP(), w, h);
+                    if (doRemap)
+                    {
+                        MapBitmap(bmpDisabled.GetHBITMAP(), w, h);
+                    }
 
                     m_disabledImgList->Add(bmpDisabled);
                 }
@@ -731,8 +726,6 @@ bool wxToolBar::Realize()
             // Map to system colours
             hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap,
                 totalBitmapWidth, totalBitmapHeight);
-
-
         }
 
         bool addBitmap = true;
@@ -827,7 +820,6 @@ bool wxToolBar::Realize()
             continue;
         }
 
-
         TBBUTTON& button = buttons[i];
 
         wxZeroMemory(button);
@@ -891,7 +883,7 @@ bool wxToolBar::Realize()
                                 wxToolBarToolBase *tool = nodePrev->GetData();
                                 if ( !tool->IsButton() || tool->GetKind() != wxITEM_RADIO )
                                     break;
-                                
+
                                 if ( tool->Toggle(false) )
                                 {
                                     DoToggleTool(tool, false);
@@ -899,7 +891,7 @@ bool wxToolBar::Realize()
                                 prevButton.fsState = TBSTATE_ENABLED;
                                 nodePrev = nodePrev->GetPrevious();
                                 prevIndex--;
-                            }                            
+                            }
                         }
 
                         isRadio = true;
@@ -1079,6 +1071,8 @@ bool wxToolBar::Realize()
     }
 
     InvalidateBestSize();
+    SetBestFittingSize();
+
     return true;
 }
 
@@ -1243,14 +1237,15 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
         return (wxToolBarToolBase *)NULL;
     }
 
-    // if comctl32 version < 4.71 wxToolBar95 adds dummy spacers
-#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
+    // when TB_SETBUTTONINFO is available (both during compile- and run-time),
+    // we don't use the dummy separators hack
+#ifdef TB_SETBUTTONINFO
     if ( wxApp::GetComCtl32Version() >= 471 )
     {
         return m_tools.Item((size_t)index)->GetData();
     }
     else
-#endif
+#endif // TB_SETBUTTONINFO
     {
         return GetItemSkippingDummySpacers( m_tools, (size_t) index );
     }