+ wxLogTrace(_T("toolbar"), _T("Button '%s' released."), tool->GetShortHelp().c_str());
+
+ wxASSERT_MSG( tool->IsInverted(), _T("release unpressed button?") );
+
+ tool->Invert();
+
+ RefreshTool( tool );
+ }
+ else if ( action == wxACTION_TOOLBAR_CLICK )
+ {
+ bool isToggled;
+ if ( tool->CanBeToggled() )
+ {
+ tool->Toggle();
+
+ RefreshTool( tool );
+
+ isToggled = tool->IsToggled();
+ }
+ else // simple non-checkable tool
+ {
+ isToggled = false;
+ }
+ OnLeftClick( tool->GetId(), isToggled );
+ }
+ else if ( action == wxACTION_TOOLBAR_ENTER )
+ {
+ wxCHECK_MSG( tool, false, _T("no tool to enter?") );
+
+ if ( HasFlag(wxTB_FLAT) && tool->IsEnabled() )
+ {
+ tool->SetUnderMouse( true );
+
+ if ( !tool->IsToggled() )
+ RefreshTool( tool );
+ }
+ }
+ else if ( action == wxACTION_TOOLBAR_LEAVE )
+ {
+ wxCHECK_MSG( tool, false, _T("no tool to leave?") );
+
+ if ( HasFlag(wxTB_FLAT) && tool->IsEnabled() )
+ {
+ tool->SetUnderMouse( false );
+
+ if ( !tool->IsToggled() )
+ RefreshTool( tool );
+ }
+ }
+ else
+ return wxControl::PerformAction(action, numArg, strArg);
+
+ return true;
+}
+
+// ============================================================================
+// wxStdToolbarInputHandler implementation
+// ============================================================================
+
+wxStdToolbarInputHandler::wxStdToolbarInputHandler(wxInputHandler *handler)
+ : wxStdInputHandler(handler)
+{
+ m_winCapture = NULL;
+ m_toolCapture = NULL;
+ m_toolLast = NULL;
+}
+
+bool wxStdToolbarInputHandler::HandleKey(wxInputConsumer *consumer,
+ const wxKeyEvent& event,
+ bool pressed)
+{
+ // TODO: when we have a current button we should allow the arrow
+ // keys to move it
+ return wxStdInputHandler::HandleKey(consumer, event, pressed);
+}
+
+bool wxStdToolbarInputHandler::HandleMouse(wxInputConsumer *consumer,
+ const wxMouseEvent& event)
+{
+ wxToolBar *tbar = wxStaticCast(consumer->GetInputWindow(), wxToolBar);
+ wxToolBarToolBase *tool = tbar->FindToolForPosition(event.GetX(), event.GetY());
+
+ if ( event.Button(1) )
+ {
+
+ if ( event.LeftDown() || event.LeftDClick() )
+ {
+ if ( !tool || !tool->IsEnabled() )
+ return true;
+
+ m_winCapture = tbar;
+ m_winCapture->CaptureMouse();
+
+ m_toolCapture = tool;
+
+ consumer->PerformAction( wxACTION_BUTTON_PRESS, tool->GetId() );
+
+ return true;
+ }
+ else if ( event.LeftUp() )
+ {
+ if ( m_winCapture )
+ {
+ m_winCapture->ReleaseMouse();
+ m_winCapture = NULL;
+ }
+
+ if (m_toolCapture)
+ {
+ if ( tool == m_toolCapture )
+ consumer->PerformAction( wxACTION_BUTTON_TOGGLE, m_toolCapture->GetId() );
+ else
+ consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolCapture->GetId() );
+ }
+
+ m_toolCapture = NULL;
+
+ return true;
+ }
+ //else: don't do anything special about the double click
+ }
+
+ return wxStdInputHandler::HandleMouse(consumer, event);
+}
+
+bool wxStdToolbarInputHandler::HandleMouseMove(wxInputConsumer *consumer,
+ const wxMouseEvent& event)
+{
+ if ( !wxStdInputHandler::HandleMouseMove(consumer, event) )
+ {
+ wxToolBar *tbar = wxStaticCast(consumer->GetInputWindow(), wxToolBar);
+
+ wxToolBarTool *tool;
+ if ( event.Leaving() )
+ {
+ // We cannot possibly be over a tool when
+ // leaving the toolbar
+ tool = NULL;
+ }
+ else
+ {
+ tool = (wxToolBarTool*) tbar->FindToolForPosition( event.GetX(), event.GetY() );
+ }
+
+ if (m_toolCapture)