Switch toolbar palettes to use AUI drag event

This isn't as much a hack as trying to detect it ourselves and
hope we don't clobber the internal toolbar workings.
This commit is contained in:
Ian McInerney 2020-09-27 22:26:12 +01:00
parent 39995341d9
commit 6dfe7b6eb0
2 changed files with 17 additions and 22 deletions

View File

@ -162,7 +162,6 @@ void ACTION_TOOLBAR_PALETTE::onCharHook( wxKeyEvent& aEvent )
ACTION_TOOLBAR::ACTION_TOOLBAR( EDA_BASE_FRAME* parent, wxWindowID id, const wxPoint& pos, ACTION_TOOLBAR::ACTION_TOOLBAR( EDA_BASE_FRAME* parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style ) : const wxSize& size, long style ) :
wxAuiToolBar( parent, id, pos, size, style ), wxAuiToolBar( parent, id, pos, size, style ),
m_paletteMoving( false ),
m_paletteTimer( nullptr ), m_paletteTimer( nullptr ),
m_auiManager( nullptr ), m_auiManager( nullptr ),
m_toolManager( parent->GetToolManager() ), m_toolManager( parent->GetToolManager() ),
@ -174,12 +173,12 @@ ACTION_TOOLBAR::ACTION_TOOLBAR( EDA_BASE_FRAME* parent, wxWindowID id, const wxP
NULL, this ); NULL, this );
Connect( wxEVT_AUITOOLBAR_RIGHT_CLICK, wxAuiToolBarEventHandler( ACTION_TOOLBAR::onToolRightClick ), Connect( wxEVT_AUITOOLBAR_RIGHT_CLICK, wxAuiToolBarEventHandler( ACTION_TOOLBAR::onToolRightClick ),
NULL, this ); NULL, this );
Connect( wxEVT_AUITOOLBAR_BEGIN_DRAG, wxAuiToolBarEventHandler( ACTION_TOOLBAR::onItemDrag ),
NULL, this );
Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( ACTION_TOOLBAR::onMouseClick ), Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( ACTION_TOOLBAR::onMouseClick ),
NULL, this ); NULL, this );
Connect( wxEVT_LEFT_UP, wxMouseEventHandler( ACTION_TOOLBAR::onMouseClick ), Connect( wxEVT_LEFT_UP, wxMouseEventHandler( ACTION_TOOLBAR::onMouseClick ),
NULL, this ); NULL, this );
Connect( wxEVT_MOTION, wxMouseEventHandler( ACTION_TOOLBAR::onMouseMotion ),
NULL, this );
Connect( m_paletteTimer->GetId(), wxEVT_TIMER, wxTimerEventHandler( ACTION_TOOLBAR::onTimerDone ), Connect( m_paletteTimer->GetId(), wxEVT_TIMER, wxTimerEventHandler( ACTION_TOOLBAR::onTimerDone ),
NULL, this ); NULL, this );
} }
@ -471,35 +470,33 @@ void ACTION_TOOLBAR::onMouseClick( wxMouseEvent& aEvent )
// Start the popup conditions if it is a left mouse click and the tool clicked is a group // Start the popup conditions if it is a left mouse click and the tool clicked is a group
if( aEvent.LeftDown() && ( m_actionGroups.find( item->GetId() ) != m_actionGroups.end() ) ) if( aEvent.LeftDown() && ( m_actionGroups.find( item->GetId() ) != m_actionGroups.end() ) )
{
m_paletteMoving = true;
m_paletteTimer->StartOnce( PALETTE_OPEN_DELAY ); m_paletteTimer->StartOnce( PALETTE_OPEN_DELAY );
}
// Clear the popup conditions if it is a left up, because that implies a click happened // Clear the popup conditions if it is a left up, because that implies a click happened
if( aEvent.LeftUp() ) if( aEvent.LeftUp() )
{
m_paletteMoving = false;
m_paletteTimer->Stop(); m_paletteTimer->Stop();
} }
}
// Skip the event so wx can continue processing the mouse event // Skip the event so wx can continue processing the mouse event
aEvent.Skip(); aEvent.Skip();
} }
void ACTION_TOOLBAR::onMouseMotion( wxMouseEvent& aEvent ) void ACTION_TOOLBAR::onItemDrag( wxAuiToolBarEvent& aEvent )
{ {
if( m_paletteMoving ) int toolId = aEvent.GetToolId();
{
wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() ); if( m_actionGroups.find( toolId ) != m_actionGroups.end() )
{
wxAuiToolBarItem* item = FindTool( toolId );
if( item )
popupPalette( item ); popupPalette( item );
// Don't skip this event since we are handling it
return;
} }
// Skip the event so wx can continue processing the mouse event // Skip since we don't care about it
aEvent.Skip(); aEvent.Skip();
} }
@ -554,7 +551,6 @@ void ACTION_TOOLBAR::onPaletteEvent( wxCommandEvent& aEvent )
void ACTION_TOOLBAR::popupPalette( wxAuiToolBarItem* aItem ) void ACTION_TOOLBAR::popupPalette( wxAuiToolBarItem* aItem )
{ {
// Clear all popup conditions // Clear all popup conditions
m_paletteMoving = false;
m_paletteTimer->Stop(); m_paletteTimer->Stop();
wxWindow* parent = dynamic_cast<wxWindow*>( m_toolManager->GetToolHolder() ); wxWindow* parent = dynamic_cast<wxWindow*>( m_toolManager->GetToolHolder() );

View File

@ -289,10 +289,10 @@ protected:
///> Handler for a mouse up/down event ///> Handler for a mouse up/down event
void onMouseClick( wxMouseEvent& aEvent ); void onMouseClick( wxMouseEvent& aEvent );
///> Handler for a mouse motion event ///> Handler for when a drag event occurs on an item
void onMouseMotion( wxMouseEvent& aEvent ); void onItemDrag( wxAuiToolBarEvent& aEvent );
///> The default tool event handler. ///> The default tool event handler
void onToolEvent( wxAuiToolBarEvent& aEvent ); void onToolEvent( wxAuiToolBarEvent& aEvent );
///> Handle a right-click on a menu item ///> Handle a right-click on a menu item
@ -310,8 +310,7 @@ protected:
const wxRect& aRect ) override; const wxRect& aRect ) override;
protected: protected:
// Items used to determine when the palette should be opened after a group item is pressed // Timer used to determine when the palette should be opened after a group item is pressed
bool m_paletteMoving;
wxTimer* m_paletteTimer; wxTimer* m_paletteTimer;
wxAuiManager* m_auiManager; wxAuiManager* m_auiManager;