]> git.saurik.com Git - wxWidgets.git/blobdiff - src/univ/toolbar.cpp
fixed a (harmless) BoundsChecker warning
[wxWidgets.git] / src / univ / toolbar.cpp
index ce2d9b67af08275f871c3d884f008798387ec4e4..2ce2dacdb8834a006893f6a2125e5f089daad7ba 100644 (file)
     #pragma hdrstop
 #endif
 
+#if wxUSE_TOOLBAR
+
 #ifndef WX_PRECOMP
     #include "wx/utils.h"
     #include "wx/app.h"
-
-    #include "wx/univ/renderer.h"
 #endif
 
+#include "wx/univ/renderer.h"
+
 #include "wx/toolbar.h"
 #include "wx/image.h"
 
@@ -53,16 +55,17 @@ static const wxCoord INVALID_WIDTH = -1;
 class WXDLLEXPORT wxToolBarTool : public wxToolBarToolBase
 {
 public:
-    wxToolBarTool( wxToolBarBase *tbar = (wxToolBarBase *)NULL,
-                   int id = wxID_SEPARATOR,
-                   const wxBitmap& bitmap1 = wxNullBitmap,
-                   const wxBitmap& bitmap2 = wxNullBitmap,
-                   bool toggle = FALSE,
-                   wxObject *clientData = (wxObject *) NULL,
-                   const wxString& shortHelpString = wxEmptyString,
-                   const wxString& longHelpString = wxEmptyString )
-        : wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle, clientData,
-                            shortHelpString, longHelpString)
+    wxToolBarTool(wxToolBar *tbar,
+                  int id,
+                  const wxString& label,
+                  const wxBitmap& bmpNormal,
+                  const wxBitmap& bmpDisabled,
+                  wxItemKind kind,
+                  wxObject *clientData,
+                  const wxString& shortHelp,
+                  const wxString& longHelp)
+        : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind,
+                            clientData, shortHelp, longHelp)
     {
         // no position yet
         m_x =
@@ -228,7 +231,7 @@ void wxToolBar::DoEnableTool(wxToolBarToolBase *tool, bool enable)
     // created disabled-state bitmap on demand
     if ( !enable && !tool->GetDisabledBitmap().Ok() )
     {
-        wxImage image( tool->GetNormalBitmap() );
+        wxImage image( tool->GetNormalBitmap().ConvertToImage() );
 
         // TODO: don't hardcode 180
         unsigned char bg_red = 180;
@@ -276,7 +279,7 @@ void wxToolBar::DoEnableTool(wxToolBarToolBase *tool, bool enable)
             }
         }
 
-        tool->SetDisabledBitmap( image.ConvertToBitmap() );
+        tool->SetDisabledBitmap(image);
     }
 
     RefreshTool(tool);
@@ -295,15 +298,16 @@ void wxToolBar::DoSetToggle(wxToolBarToolBase *tool, bool WXUNUSED(toggle))
 }
 
 wxToolBarToolBase *wxToolBar::CreateTool(int id,
-                                         const wxBitmap& bitmap1,
-                                         const wxBitmap& bitmap2,
-                                         bool toggle,
+                                         const wxString& label,
+                                         const wxBitmap& bmpNormal,
+                                         const wxBitmap& bmpDisabled,
+                                         wxItemKind kind,
                                          wxObject *clientData,
-                                         const wxString& shortHelpString,
-                                         const wxString& longHelpString)
+                                         const wxString& shortHelp,
+                                         const wxString& longHelp)
 {
-    return new wxToolBarTool( this, id, bitmap1, bitmap2, toggle,
-                              clientData, shortHelpString, longHelpString);
+    return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
+                             clientData, shortHelp, longHelp);
 }
 
 wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
@@ -512,6 +516,10 @@ void wxToolBar::Press()
 {
     wxCHECK_RET( m_toolCurrent, _T("no tool to press?") );
 
+    wxLogTrace(_T("toolbar"),
+               _T("Button '%s' pressed."),
+               m_toolCurrent->GetShortHelp().c_str());
+
     // this is the tool whose state is going to change
     m_toolPressed = (wxToolBarTool *)m_toolCurrent;
 
@@ -526,14 +534,15 @@ void wxToolBar::Release()
 {
     wxCHECK_RET( m_toolPressed, _T("no tool to release?") );
 
+    wxLogTrace(_T("toolbar"),
+               _T("Button '%s' released."),
+               m_toolCurrent->GetShortHelp().c_str());
+
     wxASSERT_MSG( m_toolPressed->IsInverted(), _T("release unpressed button?") );
 
     m_toolPressed->Invert();
 
     RefreshTool(m_toolPressed);
-
-    // we're going to lose the mouse capture
-    m_toolPressed = NULL;
 }
 
 void wxToolBar::Toggle()
@@ -639,6 +648,20 @@ bool wxStdToolbarInputHandler::HandleKey(wxInputConsumer *consumer,
     return wxStdInputHandler::HandleKey(consumer, event, pressed);
 }
 
+bool wxStdToolbarInputHandler::HandleMouse(wxInputConsumer *consumer,
+                                           const wxMouseEvent& event)
+{
+    // don't let the base class press the disabled buttons but simply ignore
+    // all events on them
+    wxToolBar *tbar = wxStaticCast(consumer->GetInputWindow(), wxToolBar);
+    wxToolBarToolBase *tool = tbar->FindToolForPosition(event.GetX(), event.GetY());
+
+    if ( !tool || !tool->IsEnabled() )
+        return TRUE;
+
+    return wxStdButtonInputHandler::HandleMouse(consumer, event);
+}
+
 bool wxStdToolbarInputHandler::HandleMouseMove(wxInputConsumer *consumer,
                                                const wxMouseEvent& event)
 {
@@ -686,3 +709,5 @@ bool wxStdToolbarInputHandler::HandleActivation(wxInputConsumer *consumer,
     return TRUE;
 }
 
+#endif // wxUSE_TOOLBAR
+