Commit 1671432a authored by jean-pierre charras's avatar jean-pierre charras
Browse files

All: Fix an usually unwanted behavior in kicad: When closing a dialog (mainly...

All: Fix an usually unwanted behavior in kicad: When closing a dialog (mainly ERC, DRC and recently a component selection by the library viewer on a double click) the mouse release left button event (which is seen by the parent after closing the dialog, becuse it is actually made in the parent) generate an unwanted command (item selection, component place ...)
This event can be now skipped if needed by calling  EDA_DRAW_FRAME::SkipNextLeftButtonReleaseEvent() from the dialog.
Very minor other fixes
parents 3e7c4a76 14fcf7f9
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -209,6 +209,20 @@ void EDA_DRAW_FRAME::OnMenuOpen( wxMenuEvent& event )
    event.Skip();
    event.Skip();
}
}


/* function SkipNextLeftButtonReleaseEvent
 * after calling this function, if the left mouse button
 * is down, the next left mouse button release event will be ignored.
 * It is is usefull for instance when closing a dialog on a mouse click,
 * to skip the next mouse left button release event
 * by the parent window, because the mouse button
 * clicked on the dialog is often released in the parent frame,
 * and therefore creates a left button released mouse event
 * which can be unwanted in some cases
 */
void EDA_DRAW_FRAME::SkipNextLeftButtonReleaseEvent()
{
   m_canvas->SetIgnoreLeftButtonReleaseEvent( true );
}


void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent )
void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent )
{
{
+22 −36
Original line number Original line Diff line number Diff line
@@ -105,6 +105,7 @@ EDA_DRAW_PANEL::EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id,
    m_panScrollbarLimits = false;
    m_panScrollbarLimits = false;
    m_enableAutoPan = true;
    m_enableAutoPan = true;
    m_ignoreMouseEvents = false;
    m_ignoreMouseEvents = false;
    m_ignoreNextLeftButtonRelease = false;


    m_mouseCaptureCallback = NULL;
    m_mouseCaptureCallback = NULL;
    m_endMouseCaptureCallback = NULL;
    m_endMouseCaptureCallback = NULL;
@@ -118,6 +119,7 @@ EDA_DRAW_PANEL::EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id,


    m_requestAutoPan = false;
    m_requestAutoPan = false;
    m_enableBlockCommands = false;
    m_enableBlockCommands = false;
    m_minDragEventCount = 0;


#ifdef __WXMAC__
#ifdef __WXMAC__
    m_defaultCursor = m_currentCursor = wxCURSOR_CROSS;
    m_defaultCursor = m_currentCursor = wxCURSOR_CROSS;
@@ -874,14 +876,6 @@ void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event )


void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
{
{
    /* Used to inhibit a response to a mouse left button release, after a double click
     * (when releasing the left button at the end of the second click.  Used in Eeschema
     * to inhibit a mouse left release command when switching between hierarchical sheets
     * on a double click.
     */
    static bool ignoreNextLeftButtonRelease = false;
    static EDA_DRAW_PANEL* LastPanel = NULL;

    int          localrealbutt = 0, localbutt = 0;
    int          localrealbutt = 0, localbutt = 0;
    BASE_SCREEN* screen = GetScreen();
    BASE_SCREEN* screen = GetScreen();


@@ -893,18 +887,8 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
     */
     */
#define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5
#define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5


    /* Count the drag events.  Used to filter mouse moves before starting a
     * block command.  A block command can be started only if
     * MinDragEventCount > MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND
     * and m_canStartBlock >= 0
     * in order to avoid spurious block commands.
     */
    static int MinDragEventCount;

    if( event.Leaving() )
    if( event.Leaving() )
    {
        m_canStartBlock = -1;
        m_canStartBlock = -1;
    }


    if( !IsMouseCaptured() )          // No mouse capture in progress.
    if( !IsMouseCaptured() )          // No mouse capture in progress.
        m_requestAutoPan = false;
        m_requestAutoPan = false;
@@ -915,9 +899,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
        return;
        return;


    if( !event.IsButton() && !event.Moving() && !event.Dragging() )
    if( !event.IsButton() && !event.Moving() && !event.Dragging() )
    {
        return;
        return;
    }


    if( event.RightDown() )
    if( event.RightDown() )
    {
    {
@@ -970,26 +952,29 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
        // inhibit a response to the mouse left button release,
        // inhibit a response to the mouse left button release,
        // because we have a double click, and we do not want a new
        // because we have a double click, and we do not want a new
        // OnLeftClick command at end of this Double Click
        // OnLeftClick command at end of this Double Click
        ignoreNextLeftButtonRelease = true;
        m_ignoreNextLeftButtonRelease = true;
    }
    }
    else if( event.LeftUp() )
    else if( event.LeftUp() )
    {
    {
        // A block command is in progress: a left up is the end of block
        // A block command is in progress: a left up is the end of block
        // or this is the end of a double click, already seen
        // or this is the end of a double click, already seen
        if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK && !ignoreNextLeftButtonRelease )
        // Note also m_ignoreNextLeftButtonRelease can be set by
        // the call to OnLeftClick(), so do not change it after calling OnLeftClick
        bool ignoreEvt = m_ignoreNextLeftButtonRelease;
        m_ignoreNextLeftButtonRelease = false;

        if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK && !ignoreEvt )
            GetParent()->OnLeftClick( &DC, screen->RefPos( true ) );
            GetParent()->OnLeftClick( &DC, screen->RefPos( true ) );


        ignoreNextLeftButtonRelease = false;
    }
    }

    else if( !event.LeftIsDown() )
    if( !event.LeftIsDown() )
    {
    {
        /* be sure there is a response to a left button release command
        /* be sure there is a response to a left button release command
         * even when a LeftUp event is not seen.  This happens when a
         * even when a LeftUp event is not seen.  This happens when a
         * double click opens a dialog box, and the release mouse button
         * double click opens a dialog box, and the release mouse button
         * is made when the dialog box is open.
         * is made when the dialog box is opened.
         */
         */
        ignoreNextLeftButtonRelease = false;
        m_ignoreNextLeftButtonRelease = false;
    }
    }


    if( event.ButtonDown( wxMOUSE_BTN_MIDDLE ) && m_enableMiddleButtonPan )
    if( event.ButtonDown( wxMOUSE_BTN_MIDDLE ) && m_enableMiddleButtonPan )
@@ -1115,9 +1100,10 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
    /*******************************/
    /*******************************/


    // Command block can't start if mouse is dragging a new panel
    // Command block can't start if mouse is dragging a new panel
    if( LastPanel != this )
    static EDA_DRAW_PANEL* lastPanel;
    if( lastPanel != this )
    {
    {
        MinDragEventCount = 0;
        m_minDragEventCount = 0;
        m_canStartBlock   = -1;
        m_canStartBlock   = -1;
    }
    }


@@ -1129,7 +1115,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
     */
     */
    if( !event.LeftIsDown() && !event.MiddleIsDown() )
    if( !event.LeftIsDown() && !event.MiddleIsDown() )
    {
    {
        MinDragEventCount = 0;
        m_minDragEventCount = 0;
        m_canStartBlock   = 0;
        m_canStartBlock   = 0;


        /* Remember the last cursor position when a drag mouse starts
        /* Remember the last cursor position when a drag mouse starts
@@ -1155,7 +1141,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
            {
            {
                m_requestAutoPan = false;
                m_requestAutoPan = false;
                GetParent()->HandleBlockPlace( &DC );
                GetParent()->HandleBlockPlace( &DC );
                ignoreNextLeftButtonRelease = true;
                m_ignoreNextLeftButtonRelease = true;
            }
            }
        }
        }
        else if( ( m_canStartBlock >= 0 )
        else if( ( m_canStartBlock >= 0 )
@@ -1174,8 +1160,8 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
                // A block command is started if the drag is enough.  A small
                // A block command is started if the drag is enough.  A small
                // drag is ignored (it is certainly a little mouse move when
                // drag is ignored (it is certainly a little mouse move when
                // clicking) not really a drag mouse
                // clicking) not really a drag mouse
                if( MinDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND )
                if( m_minDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND )
                    MinDragEventCount++;
                    m_minDragEventCount++;
                else
                else
                {
                {
                    if( !GetParent()->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos ) )
                    if( !GetParent()->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos ) )
@@ -1250,7 +1236,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
    GetParent()->PrintMsg( msg_debug );
    GetParent()->PrintMsg( msg_debug );
#endif
#endif


    LastPanel = this;
    lastPanel = this;
}
}




+5 −0
Original line number Original line Diff line number Diff line
@@ -205,6 +205,11 @@ void DIALOG_ERC::OnLeftDblClickMarkersList( wxCommandEvent& event )
    {
    {
        m_parent->GetScreen()->SetCrossHairPosition( m_lastMarkerFound->m_Pos );
        m_parent->GetScreen()->SetCrossHairPosition( m_lastMarkerFound->m_Pos );
        m_parent->RedrawScreen( m_lastMarkerFound->m_Pos, true);
        m_parent->RedrawScreen( m_lastMarkerFound->m_Pos, true);
        // prevent a mouse left button release event in
        // coming from the ERC dialog double click
        // ( the button is released after closing this dialog and will generate
        // an unwanted event in  parent frame)
        m_parent->SkipNextLeftButtonReleaseEvent();
        EndModal( 1 );
        EndModal( 1 );
    }
    }
}
}
+0 −1
Original line number Original line Diff line number Diff line
@@ -216,7 +216,6 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC,
{
{
    int unit    = 1;
    int unit    = 1;
    int convert = 1;
    int convert = 1;

    m_itemToRepeat = NULL;
    m_itemToRepeat = NULL;
    m_canvas->SetIgnoreMouseEvents( true );
    m_canvas->SetIgnoreMouseEvents( true );


+8 −8
Original line number Original line Diff line number Diff line
@@ -100,10 +100,10 @@ static wxAcceleratorEntry accels[] =
#define EXTRA_BORDER_SIZE 2
#define EXTRA_BORDER_SIZE 2
#define LIB_VIEW_FRAME_NAME wxT( "ViewlibFrame" )
#define LIB_VIEW_FRAME_NAME wxT( "ViewlibFrame" )


LIB_VIEW_FRAME::LIB_VIEW_FRAME( wxWindow* father, CMP_LIBRARY* Library,
LIB_VIEW_FRAME::LIB_VIEW_FRAME( SCH_BASE_FRAME* aParent, CMP_LIBRARY* aLibrary,
                                wxSemaphore* semaphore, long style ) :
                                wxSemaphore* aSemaphore, long aStyle ) :
    SCH_BASE_FRAME( father, VIEWER_FRAME_TYPE, _( "Library Browser" ),
    SCH_BASE_FRAME( aParent, VIEWER_FRAME_TYPE, _( "Library Browser" ),
                    wxDefaultPosition, wxDefaultSize, style, GetLibViewerFrameName() )
                    wxDefaultPosition, wxDefaultSize, aStyle, GetLibViewerFrameName() )
{
{
    wxAcceleratorTable table( ACCEL_TABLE_CNT, accels );
    wxAcceleratorTable table( ACCEL_TABLE_CNT, accels );


@@ -121,7 +121,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( wxWindow* father, CMP_LIBRARY* Library,
    m_LibList = NULL;
    m_LibList = NULL;
    m_LibListWindow = NULL;
    m_LibListWindow = NULL;
    m_CmpListWindow = NULL;
    m_CmpListWindow = NULL;
    m_Semaphore     = semaphore;
    m_Semaphore     = aSemaphore;
    if( m_Semaphore )
    if( m_Semaphore )
        SetModalMode( true );
        SetModalMode( true );
    m_exportToEeschemaCmpName.Empty();
    m_exportToEeschemaCmpName.Empty();
@@ -146,7 +146,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( wxWindow* father, CMP_LIBRARY* Library,


    wxPoint win_pos( 0, 0 );
    wxPoint win_pos( 0, 0 );


    if( Library == NULL )
    if( aLibrary == NULL )
    {
    {
        // Creates the libraries window display
        // Creates the libraries window display
        m_LibListWindow =
        m_LibListWindow =
@@ -163,7 +163,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( wxWindow* father, CMP_LIBRARY* Library,
    }
    }
    else
    else
    {
    {
        m_libraryName = Library->GetName();
        m_libraryName = aLibrary->GetName();
        m_entryName.Clear();
        m_entryName.Clear();
        m_unit = 1;
        m_unit = 1;
        m_convert = 1;
        m_convert = 1;
@@ -507,7 +507,7 @@ void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
        // Prevent the double click from being as a single click in the parent
        // Prevent the double click from being as a single click in the parent
        // window which would cause the part to be parked rather than staying
        // window which would cause the part to be parked rather than staying
        // in drag mode.
        // in drag mode.
        event.StopPropagation();
        ((SCH_BASE_FRAME*) GetParent())->SkipNextLeftButtonReleaseEvent();
    }
    }
}
}


Loading