Commit 2f7706e8 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Reduced number of switched events, allowing to use VIEW_CONTROLS, even if...

Reduced number of switched events, allowing to use VIEW_CONTROLS, even if there is no extra event dispatcher.
parent 0fc93666
Loading
Loading
Loading
Loading
+52 −30
Original line number Original line Diff line number Diff line
@@ -73,6 +73,20 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
    Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this );
    Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this );
    Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this );
    Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this );


    const wxEventType events[] =
    {
        wxEVT_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK,
        wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK,
        wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_DCLICK,
        wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR, KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE
    };

    BOOST_FOREACH( wxEventType eventType, events )
    {
        Connect( eventType, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ),
                 NULL, m_eventDispatcher );
    }

    // Set up timer that prevents too frequent redraw commands
    // Set up timer that prevents too frequent redraw commands
    m_refreshTimer.SetOwner( this );
    m_refreshTimer.SetOwner( this );
    m_pendingRefresh = false;
    m_pendingRefresh = false;
@@ -171,46 +185,43 @@ void EDA_DRAW_PANEL_GAL::SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher )
{
{
    m_eventDispatcher = aEventDispatcher;
    m_eventDispatcher = aEventDispatcher;


    const wxEventType events[] =
#if wxCHECK_VERSION( 3, 0, 0 )
    if( m_eventDispatcher )
    {
    {
        wxEVT_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK,
        m_parent->Connect( wxEVT_TOOL,
        wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK,
                           wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
        wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_DCLICK,
                           NULL, m_eventDispatcher );
        wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR, KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE
    }
    };
    else

    const wxEventType commands[] =
    {
    {
#if wxCHECK_VERSION( 3, 0, 0 )
        // While loops are used to be sure, that we are removing all event handlers
        wxEVT_TOOL
        while( m_parent->Disconnect( wxEVT_TOOL,
                                     wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
                                     NULL, m_eventDispatcher ) );
    }
#else
#else
        wxEVT_COMMAND_MENU_SELECTED, wxEVT_COMMAND_TOOL_CLICKED
#endif
    };

    if( m_eventDispatcher )
    if( m_eventDispatcher )
    {
    {
        BOOST_FOREACH( wxEventType eventType, events )
        m_parent->Connect( wxEVT_COMMAND_MENU_SELECTED,
            Connect( eventType, wxEventHandler( TOOL_DISPATCHER::DispatchWxEvent ),
                           wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
                           NULL, m_eventDispatcher );
                           NULL, m_eventDispatcher );


        BOOST_FOREACH( wxEventType eventType, commands )
        m_parent->Connect( wxEVT_COMMAND_TOOL_CLICKED,
            m_parent->Connect( eventType,
                           wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
                           wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
                           NULL, m_eventDispatcher );
                           NULL, m_eventDispatcher );
    }
    }
    else
    else
    {
    {
        // While loops are used to be sure, that we are removing all event handlers
        // While loops are used to be sure, that we are removing all event handlers
        BOOST_FOREACH( wxEventType eventType, events )
        while( m_parent->Disconnect( wxEVT_COMMAND_MENU_SELECTED,
            while( Disconnect( eventType, wxEventHandler( TOOL_DISPATCHER::DispatchWxEvent ),
                                     wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
                                     NULL, m_eventDispatcher ) );
                                     NULL, m_eventDispatcher ) );


        BOOST_FOREACH( wxEventType eventType, commands )
        while( m_parent->Disconnect( wxEVT_COMMAND_TOOL_CLICKED,
            while( m_parent->Disconnect( eventType,
                                     wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
                                     wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
                                     NULL, m_eventDispatcher ) );
                                     NULL, m_eventDispatcher ) );
    }
    }
#endif
}
}




@@ -292,6 +303,17 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType )
}
}




void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent )
{
    if( !m_eventDispatcher )
        aEvent.Skip();
    else
        m_eventDispatcher->DispatchWxEvent( aEvent );

    Refresh();
}


void EDA_DRAW_PANEL_GAL::onEnter( wxEvent& aEvent )
void EDA_DRAW_PANEL_GAL::onEnter( wxEvent& aEvent )
{
{
    // Getting focus is necessary in order to receive key events properly
    // Getting focus is necessary in order to receive key events properly
+0 −2
Original line number Original line Diff line number Diff line
@@ -281,8 +281,6 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
    if( evt )
    if( evt )
        m_toolMgr->ProcessEvent( *evt );
        m_toolMgr->ProcessEvent( *evt );


    static_cast<PCB_BASE_FRAME*>( m_toolMgr->GetEditFrame() )->GetGalCanvas()->Refresh();

    // pass the event to the GUI, it might still be interested in it
    // pass the event to the GUI, it might still be interested in it
    aEvent.Skip();
    aEvent.Skip();
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -147,6 +147,7 @@ public:
protected:
protected:
    void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
    void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
    void onSize( wxSizeEvent& aEvent );
    void onSize( wxSizeEvent& aEvent );
    void onEvent( wxEvent& aEvent );
    void onEnter( wxEvent& aEvent );
    void onEnter( wxEvent& aEvent );
    void onRefreshTimer( wxTimerEvent& aEvent );
    void onRefreshTimer( wxTimerEvent& aEvent );