+ 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;
+}
+
+/* static */
+wxInputHandler *wxToolBar::GetStdInputHandler(wxInputHandler *handlerDef)
+{
+ static wxStdToolbarInputHandler s_handler(handlerDef);
+
+ return &s_handler;
+}
+
+// ============================================================================
+// 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)
+ {
+ // During capture we only care of the captured tool
+ if (tool && (tool != m_toolCapture))
+ tool = NULL;
+
+ if (tool == m_toolLast)
+ return true;
+
+ if (tool)
+ consumer->PerformAction( wxACTION_BUTTON_PRESS, m_toolCapture->GetId() );
+ else
+ consumer->PerformAction( wxACTION_BUTTON_RELEASE, m_toolCapture->GetId() );
+
+ m_toolLast = tool;
+ }
+ else
+ {
+ if (tool == m_toolLast)
+ return true;
+
+ if (m_toolLast)
+ {
+ // Leave old tool if any
+ consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolLast->GetId() );
+ }
+
+ if (tool)
+ {
+ // Enter new tool if any
+ consumer->PerformAction( wxACTION_TOOLBAR_ENTER, tool->GetId() );
+ }
+
+ m_toolLast = tool;
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
+bool wxStdToolbarInputHandler::HandleFocus(wxInputConsumer *consumer,
+ const wxFocusEvent& WXUNUSED(event))
+{
+ if ( m_toolCapture )
+ {
+ // We shouldn't be left with a highlighted button
+ consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolCapture->GetId() );
+ }
+
+ return true;
+}
+
+bool wxStdToolbarInputHandler::HandleActivation(wxInputConsumer *consumer,
+ bool activated)
+{
+ if (m_toolCapture && !activated)
+ {
+ // We shouldn't be left with a highlighted button
+ consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolCapture->GetId() );
+ }
+
+ return true;