fixes to toolbar, seems to work

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14430 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2002-02-28 18:07:03 +00:00
parent cb78397f14
commit 5a73d082f0
3 changed files with 58 additions and 32 deletions

View File

@ -129,11 +129,12 @@ private:
wxCoord m_maxWidth,
m_maxHeight;
// the current tool or NULL
// the tool over which the mouse currently is or NULL
wxToolBarToolBase *m_toolCurrent;
// the currently pressed tool or NULL
wxToolBarToolBase *m_toolPressed;
// the tool which currently has the mouse capture (i.e. the one user is
// pressing) or NULL
wxToolBarTool *m_toolPressed;
DECLARE_DYNAMIC_CLASS(wxToolBar)
};

View File

@ -74,9 +74,7 @@ bool wxToolBarToolBase::Enable(bool enable)
bool wxToolBarToolBase::Toggle(bool toggle)
{
// wxUniv toolbar toggles even non-checkable tools temporarily - should we
// change the code there or just allow doing it?
//wxASSERT_MSG( m_isToggle, _T("can't toggle this tool") );
wxASSERT_MSG( m_isToggle, _T("can't toggle this tool") );
if ( m_toggled == toggle )
return FALSE;

View File

@ -67,12 +67,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 +114,7 @@ void wxToolBar::Init()
m_maxWidth =
m_maxHeight = 0;
m_toolPressed =
m_toolPressed = NULL;
m_toolCurrent = NULL;
wxRenderer *renderer = GetRenderer();
@ -467,7 +485,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 +512,35 @@ void wxToolBar::Press()
{
wxCHECK_RET( m_toolCurrent, _T("no tool to press?") );
m_toolPressed = m_toolCurrent;
if ( !m_toolPressed->IsToggled() )
{
m_toolPressed->Toggle(TRUE);
// this is the tool whose state is going to change
m_toolPressed = (wxToolBarTool *)m_toolCurrent;
RefreshTool(m_toolPressed);
}
// 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);
wxASSERT_MSG( m_toolPressed->IsInverted(), _T("release unpressed button?") );
RefreshTool(m_toolPressed);
m_toolPressed->Invert();
m_toolPressed = NULL;
}
RefreshTool(m_toolPressed);
// we're going to lose the mouse capture
m_toolPressed = NULL;
}
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 +549,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,