X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3216dbf5dccab8ed6dc0245b7e5c998738ef51d7..3242feb1c09fd28c5a41ed1ee76e37d56213f19b:/src/univ/toolbar.cpp diff --git a/src/univ/toolbar.cpp b/src/univ/toolbar.cpp index 6692e1fbff..3db0500631 100644 --- a/src/univ/toolbar.cpp +++ b/src/univ/toolbar.cpp @@ -29,13 +29,15 @@ #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" @@ -67,12 +69,30 @@ public: // no position yet m_x = m_y = -1; + + // not pressed yet + m_isInverted = FALSE; } + // is this tool pressed, even temporarily? (this is different from being + // permanently toggled which is what IsToggled() returns) + bool IsPressed() const + { return CanBeToggled() ? IsToggled() != m_isInverted : m_isInverted; } + + // are we temporarily pressed/unpressed? + bool IsInverted() const { return m_isInverted; } + + // press the tool temporarily by inverting its toggle state + void Invert() { m_isInverted = !m_isInverted; } + public: // the tool position (the size is known by the toolbar itself) int m_x, m_y; + +private: + // TRUE if the tool is pressed + bool m_isInverted; }; // ============================================================================ @@ -96,7 +116,7 @@ void wxToolBar::Init() m_maxWidth = m_maxHeight = 0; - m_toolPressed = + m_toolPressed = NULL; m_toolCurrent = NULL; wxRenderer *renderer = GetRenderer(); @@ -467,7 +487,10 @@ void wxToolBar::DoDraw(wxControlRenderer *renderer) flags |= wxCONTROL_DISABLED; } - if ( tool->IsToggled() ) + if ( tool == m_toolPressed ) + flags |= wxCONTROL_FOCUSED; + + if ( ((wxToolBarTool *)tool)->IsPressed() ) flags |= wxCONTROL_PRESSED; wxString label; @@ -491,43 +514,40 @@ void wxToolBar::Press() { wxCHECK_RET( m_toolCurrent, _T("no tool to press?") ); - m_toolPressed = m_toolCurrent; - if ( !m_toolPressed->IsToggled() ) - { - m_toolPressed->Toggle(TRUE); + wxLogTrace(_T("toolbar"), + _T("Button '%s' pressed."), + m_toolCurrent->GetShortHelp().c_str()); - RefreshTool(m_toolPressed); - } + // this is the tool whose state is going to change + m_toolPressed = (wxToolBarTool *)m_toolCurrent; + + // we must toggle it regardless of whether it is a checkable tool or not, + // so use Invert() and not Toggle() here + m_toolPressed->Invert(); + + RefreshTool(m_toolPressed); } void wxToolBar::Release() { wxCHECK_RET( m_toolPressed, _T("no tool to release?") ); - if ( m_toolPressed->IsToggled() ) - { - m_toolPressed->Toggle(FALSE); + wxLogTrace(_T("toolbar"), + _T("Button '%s' released."), + m_toolCurrent->GetShortHelp().c_str()); - RefreshTool(m_toolPressed); + wxASSERT_MSG( m_toolPressed->IsInverted(), _T("release unpressed button?") ); - m_toolPressed = NULL; - } + m_toolPressed->Invert(); + + RefreshTool(m_toolPressed); } void wxToolBar::Toggle() { - wxCHECK_RET( m_toolPressed, _T("no tool to toggle?") ); - - // the togglable tools should keep their state when the mouse is released - if ( !m_toolPressed->CanBeToggled() ) - { - m_toolPressed->Toggle(); - } - - RefreshTool(m_toolPressed); - m_toolCurrent = m_toolPressed; - m_toolPressed = NULL; + + Release(); Click(); } @@ -536,7 +556,21 @@ void wxToolBar::Click() { wxCHECK_RET( m_toolCurrent, _T("no tool to click?") ); - OnLeftClick(m_toolCurrent->GetId(), m_toolCurrent->IsToggled()); + bool isToggled; + if ( m_toolCurrent->CanBeToggled() ) + { + m_toolCurrent->Toggle(); + + RefreshTool(m_toolCurrent); + + isToggled = m_toolCurrent->IsToggled(); + } + else // simple non-checkable tool + { + isToggled = FALSE; + } + + OnLeftClick(m_toolCurrent->GetId(), isToggled); } bool wxToolBar::PerformAction(const wxControlAction& action, @@ -612,6 +646,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) { @@ -659,3 +707,5 @@ bool wxStdToolbarInputHandler::HandleActivation(wxInputConsumer *consumer, return TRUE; } +#endif // wxUSE_TOOLBAR +