]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/tbar95.cpp
Deprecate wxPathExists, make wxDirExists used everywhere, minor source cleaning.
[wxWidgets.git] / src / msw / tbar95.cpp
index 56f1bc60c57d2f1121871e6fc19a513c2f8812e0..7ea83bd343b65db73824bd93083091830e1092d1 100644 (file)
@@ -397,7 +397,7 @@ WXDWORD wxToolBar::MSWGetStyle(long style, WXDWORD *exstyle) const
     if ( style & (wxTB_FLAT | wxTB_HORZ_LAYOUT) )
     {
         // static as it doesn't change during the program lifetime
-        static int s_verComCtl = wxTheApp->GetComCtl32Version();
+        static int s_verComCtl = wxApp::GetComCtl32Version();
 
         // comctl32.dll 4.00 doesn't support the flat toolbars and using this
         // style with 6.00 (part of Windows XP) leads to the toolbar with
@@ -659,12 +659,17 @@ bool wxToolBar::Realize()
             if ( tool->IsButton() )
             {
                 const wxBitmap& bmp = tool->GetNormalBitmap();
+
+                const int w = bmp.GetWidth();
+                const int h = bmp.GetHeight();
+
                 if ( bmp.Ok() )
                 {
-                    int xOffset = wxMax(0, (m_defaultWidth - bmp.GetWidth())/2);
-                    int yOffset = wxMax(0, (m_defaultHeight - bmp.GetHeight())/2);
+                    int xOffset = wxMax(0, (m_defaultWidth - w)/2);
+                    int yOffset = wxMax(0, (m_defaultHeight - h)/2);
+
                     // notice the last parameter: do use mask
-                    dcAllButtons.DrawBitmap(bmp, x+xOffset, yOffset, true);
+                    dcAllButtons.DrawBitmap(bmp, x + xOffset, yOffset, true);
                 }
                 else
                 {
@@ -675,31 +680,34 @@ bool wxToolBar::Realize()
                 if ( m_disabledImgList )
                 {
                     wxBitmap bmpDisabled = tool->GetDisabledBitmap();
+#if wxUSE_IMAGE
                     if ( !bmpDisabled.Ok() )
                     {
-#if wxUSE_IMAGE
                         // no disabled bitmap specified but we still need to
                         // fill the space in the image list with something, so
                         // we grey out the normal bitmap
-                        wxImage img = bmp.ConvertToImage();
-#if 0
-                        img.SetMaskColour(wxLIGHT_GREY->Red(),
-                                          wxLIGHT_GREY->Green(),
-                                          wxLIGHT_GREY->Blue());
-#endif
                         wxImage imgGreyed;
-                        wxCreateGreyedImage(img, imgGreyed);
+                        wxCreateGreyedImage(bmp.ConvertToImage(), imgGreyed);
 
-                        bmpDisabled = wxBitmap(imgGreyed);
-#if 0
-                        bmpDisabled.SetMask(new wxMask(bmpDisabled, *wxLIGHT_GREY));
+                        // we need to have light grey background colour for
+                        // MapBitmap() to work correctly
+                        for ( int y = 0; y < h; y++ )
+                        {
+                            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());
+                            }
+                        }
 
-                        MapBitmap(bmpDisabled.GetHBITMAP(),
-                                  bmpDisabled.GetWidth(),
-                                  bmpDisabled.GetHeight());
-#endif // 0
-#endif // wxUSE_IMAGE
+                        bmpDisabled = wxBitmap(imgGreyed);
                     }
+#endif // wxUSE_IMAGE
+
+                    MapBitmap(bmpDisabled.GetHBITMAP(), w, h);
 
                     m_disabledImgList->Add(bmpDisabled);
                 }
@@ -731,7 +739,7 @@ bool wxToolBar::Realize()
         if ( oldToolBarBitmap )
         {
 #ifdef TB_REPLACEBITMAP
-            if ( wxTheApp->GetComCtl32Version() >= 400 )
+            if ( wxApp::GetComCtl32Version() >= 400 )
             {
                 TBREPLACEBITMAP replaceBitmap;
                 replaceBitmap.hInstOld = NULL;
@@ -813,7 +821,7 @@ bool wxToolBar::Realize()
         // don't add separators to the vertical toolbar with old comctl32.dll
         // versions as they didn't handle this properly
         if ( isVertical && tool->IsSeparator() &&
-                wxTheApp->GetComCtl32Version() <= 472 )
+                wxApp::GetComCtl32Version() <= 472 )
         {
             continue;
         }
@@ -867,7 +875,30 @@ bool wxToolBar::Realize()
                             // radio items
                             button.fsState |= TBSTATE_CHECKED;
 
-                            tool->Toggle(true);
+                            if (tool->Toggle(true))
+                            {
+                                DoToggleTool(tool, true);
+                            }
+                        }
+                        else if (tool->IsToggled())
+                        {
+                            wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious();
+                            int prevIndex = i - 1;
+                            while ( nodePrev )
+                            {
+                                TBBUTTON& prevButton = buttons[prevIndex];
+                                wxToolBarToolBase *tool = nodePrev->GetData();
+                                if ( !tool->IsButton() || tool->GetKind() != wxITEM_RADIO )
+                                    break;
+                                
+                                if ( tool->Toggle(false) )
+                                {
+                                    DoToggleTool(tool, false);
+                                }
+                                prevButton.fsState = TBSTATE_ENABLED;
+                                nodePrev = nodePrev->GetPrevious();
+                                prevIndex--;
+                            }                            
                         }
 
                         isRadio = true;
@@ -946,7 +977,7 @@ bool wxToolBar::Realize()
 #ifdef TB_SETBUTTONINFO
         // available in headers, now check whether it is available now
         // (during run-time)
-        if ( wxTheApp->GetComCtl32Version() >= 471 )
+        if ( wxApp::GetComCtl32Version() >= 471 )
         {
             // set the (underlying) separators width to be that of the
             // control
@@ -1160,7 +1191,7 @@ wxSize wxToolBar::GetToolSize() const
 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 ) \
     && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) \
     && !defined (__DIGITALMARS__)
-    if ( wxTheApp->GetComCtl32Version() >= 470 )
+    if ( wxApp::GetComCtl32Version() >= 470 )
     {
         DWORD dw = ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE, 0, 0);
 
@@ -1213,7 +1244,7 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
 
     // if comctl32 version < 4.71 wxToolBar95 adds dummy spacers
 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
-    if ( wxTheApp->GetComCtl32Version() >= 471 )
+    if ( wxApp::GetComCtl32Version() >= 471 )
     {
         return m_tools.Item((size_t)index)->GetData();
     }