Commit bdca3c5e authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

All control state handling is now performed in wxUpdateUIEvent handlers.

* Old control state handling code completely removed in all applications.
* Factor common control state handlers into EDA_DRAW_FRAME.
* Replaced EDA_ITEM test for newness with IsNew() method.
* Factor vertical right toolbar command handlers out of giant edit command
  switch statement in EESchema and PCBNew.
parent c476ae44
Loading
Loading
Loading
Loading
+88 −52
Original line number Original line Diff line number Diff line
@@ -44,13 +44,23 @@ BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, EDA_BASE_FRAME )
                    EDA_DRAW_FRAME::OnZoom )
                    EDA_DRAW_FRAME::OnZoom )
    EVT_MENU_RANGE( ID_POPUP_GRID_LEVEL_1000, ID_POPUP_GRID_USER,
    EVT_MENU_RANGE( ID_POPUP_GRID_LEVEL_1000, ID_POPUP_GRID_USER,
                    EDA_DRAW_FRAME::OnSelectGrid )
                    EDA_DRAW_FRAME::OnSelectGrid )

    EVT_TOOL( ID_TB_OPTIONS_SHOW_GRID, EDA_DRAW_FRAME::OnToggleGridState )
    EVT_TOOL_RANGE( ID_TB_OPTIONS_SELECT_UNIT_MM, ID_TB_OPTIONS_SELECT_UNIT_INCH,
                    EDA_DRAW_FRAME::OnSelectUnits )
    EVT_TOOL( ID_TB_OPTIONS_SELECT_CURSOR, EDA_DRAW_FRAME::OnToggleCrossHairStyle )

    EVT_UPDATE_UI( wxID_UNDO, EDA_DRAW_FRAME::OnUpdateUndo )
    EVT_UPDATE_UI( wxID_REDO, EDA_DRAW_FRAME::OnUpdateRedo )
    EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_GRID, EDA_DRAW_FRAME::OnUpdateGrid )
    EVT_UPDATE_UI( ID_TB_OPTIONS_SELECT_CURSOR, EDA_DRAW_FRAME::OnUpdateCrossHairStyle )
    EVT_UPDATE_UI_RANGE( ID_TB_OPTIONS_SELECT_UNIT_MM, ID_TB_OPTIONS_SELECT_UNIT_INCH,
                         EDA_DRAW_FRAME::OnUpdateUnits )
END_EVENT_TABLE()
END_EVENT_TABLE()




EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* father, int idtype,
EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* father, int idtype, const wxString& title,
                                    const wxString& title,
                                const wxPoint& pos, const wxSize& size, long style ) :
                                    const wxPoint& pos, const wxSize& size,
                                    long style ) :
    EDA_BASE_FRAME( father, idtype, title, pos, size, style )
    EDA_BASE_FRAME( father, idtype, title, pos, size, style )
{
{
    wxSize minsize;
    wxSize minsize;
@@ -154,6 +164,79 @@ void EDA_DRAW_FRAME::OnMenuOpen( wxMenuEvent& event )
}
}




void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent )
{
    SetGridVisibility( !IsGridVisible() );
    DrawPanel->Refresh();
}


void EDA_DRAW_FRAME::OnSelectUnits( wxCommandEvent& aEvent )
{

    if( aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_MM && g_UserUnit != MILLIMETRES )
    {
        g_UserUnit = MILLIMETRES;
        UpdateStatusBar();
    }
    else if( aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_INCH && g_UserUnit != INCHES )
    {
        g_UserUnit = INCHES;
        UpdateStatusBar();
    }
}


void EDA_DRAW_FRAME::OnToggleCrossHairStyle( wxCommandEvent& aEvent )
{
    INSTALL_UNBUFFERED_DC( dc, DrawPanel );
    DrawPanel->CrossHairOff( &dc );
    m_CursorShape = !m_CursorShape;
    DrawPanel->CrossHairOn( &dc );
}


void EDA_DRAW_FRAME::OnUpdateUndo( wxUpdateUIEvent& aEvent )
{
    if( GetScreen() )
        aEvent.Enable( GetScreen()->GetUndoCommandCount() > 0 );
}


void EDA_DRAW_FRAME::OnUpdateRedo( wxUpdateUIEvent& aEvent )
{
    if( GetScreen() )
        aEvent.Enable( GetScreen()->GetRedoCommandCount() > 0 );
}


void EDA_DRAW_FRAME::OnUpdateUnits( wxUpdateUIEvent& aEvent )
{
    bool enable;

    enable = ( ((aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_MM) && (g_UserUnit == MILLIMETRES))
            || ((aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_INCH) && (g_UserUnit == INCHES)) );

    aEvent.Check( enable );
    DisplayUnitsMsg();
}


void EDA_DRAW_FRAME::OnUpdateGrid( wxUpdateUIEvent& aEvent )
{
    wxString tool_tip = IsGridVisible() ? _( "Hide grid" ) : _( "Show grid" );

    aEvent.Check( IsGridVisible() );
    m_OptionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_GRID, tool_tip );
}


void EDA_DRAW_FRAME::OnUpdateCrossHairStyle( wxUpdateUIEvent& aEvent )
{
    aEvent.Check( m_CursorShape );
}


// Virtual function
// Virtual function
void EDA_DRAW_FRAME::ReCreateAuxiliaryToolbar()
void EDA_DRAW_FRAME::ReCreateAuxiliaryToolbar()
{
{
@@ -177,6 +260,7 @@ void EDA_DRAW_FRAME::ToolOnRightClick( wxCommandEvent& event )
{
{
}
}



/**
/**
 * Function PrintPage (virtual)
 * Function PrintPage (virtual)
 * used to print a page
 * used to print a page
@@ -307,15 +391,6 @@ void EDA_DRAW_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
}
}




void EDA_DRAW_FRAME::SetToolbars()
{
    DisplayUnitsMsg();

    if( m_auimgr.GetManagedWindow() )
        m_auimgr.Update();
}


void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
{
{
    SetStatusText( msg, 5 );
    SetStatusText( msg, 5 );
@@ -379,53 +454,14 @@ void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )


    // Change DrawPanel cursor if requested.
    // Change DrawPanel cursor if requested.
    if( DrawPanel && aCursor >= 0 )
    if( DrawPanel && aCursor >= 0 )
    {
        DrawPanel->SetCursor( aCursor );
        DrawPanel->SetCursor( aCursor );
    }


    DisplayToolMsg( aToolMsg );
    DisplayToolMsg( aToolMsg );


    if( aId < 0 )
    if( aId < 0 )
        return;
        return;


    // Old Tool ID_NO_SELECT_BUTT active or inactive if no new tool.
    if( m_ID_current_state )
    {
        if( m_VToolBar )
            m_VToolBar->ToggleTool( m_ID_current_state, FALSE );

        if( m_AuxVToolBar )
            m_AuxVToolBar->ToggleTool( m_ID_current_state, FALSE );
    }
    else
    {
        if( aId )
        {
            if( m_VToolBar )
                m_VToolBar->ToggleTool( ID_NO_SELECT_BUTT, FALSE );

            if( m_AuxVToolBar )
                m_AuxVToolBar->ToggleTool( m_ID_current_state, FALSE );
        }
        else if( m_VToolBar )
            m_VToolBar->ToggleTool( ID_NO_SELECT_BUTT, TRUE );
    }

    if( aId )
    {
        if( m_VToolBar )
            m_VToolBar->ToggleTool( aId, TRUE );

        if( m_AuxVToolBar )
            m_AuxVToolBar->ToggleTool( aId, TRUE );
    }
    else if( m_VToolBar )
        m_VToolBar->ToggleTool( ID_NO_SELECT_BUTT, TRUE );

    m_ID_current_state = aId;
    m_ID_current_state = aId;

    if( m_VToolBar )
        m_VToolBar->Refresh( );
}
}




+7 −5
Original line number Original line Diff line number Diff line
@@ -16,7 +16,7 @@


#define CURSOR_SIZE 12           // Cursor size in pixels
#define CURSOR_SIZE 12           // Cursor size in pixels


#define CLIP_BOX_PADDING 1
#define CLIP_BOX_PADDING 2


/* Definitions for enabling and disabling debugging features in drawpanel.cpp.
/* Definitions for enabling and disabling debugging features in drawpanel.cpp.
 * Please don't forget to turn these off before making any commits to Launchpad.
 * Please don't forget to turn these off before making any commits to Launchpad.
@@ -749,6 +749,8 @@ void EDA_DRAW_PANEL::OnMouseLeaving( wxMouseEvent& event )
        cmd.SetEventObject( this );
        cmd.SetEventObject( this );
        GetEventHandler()->ProcessEvent( cmd );
        GetEventHandler()->ProcessEvent( cmd );
    }
    }

    event.Skip();
}
}




@@ -882,7 +884,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
    wxPoint pos = CalcUnscrolledPosition( event.GetPosition() );
    wxPoint pos = CalcUnscrolledPosition( event.GetPosition() );


    /* Compute the cursor position in drawing (logical) units. */
    /* Compute the cursor position in drawing (logical) units. */
    screen->m_MousePosition = event.GetLogicalPosition( DC );
    screen->SetMousePosition( event.GetLogicalPosition( DC ) );


    int kbstat = 0;
    int kbstat = 0;


@@ -902,7 +904,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
    // Calling Double Click and Click functions :
    // Calling Double Click and Click functions :
    if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
    if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
    {
    {
        GetParent()->OnLeftDClick( &DC, screen->m_MousePosition );
        GetParent()->OnLeftDClick( &DC, screen->RefPos( true ) );


        // 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
@@ -914,7 +916,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
        // 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.m_State == STATE_NO_BLOCK && !ignoreNextLeftButtonRelease )
        if( screen->m_BlockLocate.m_State == STATE_NO_BLOCK && !ignoreNextLeftButtonRelease )
            GetParent()->OnLeftClick( &DC, screen->m_MousePosition );
            GetParent()->OnLeftClick( &DC, screen->RefPos( true ) );


        ignoreNextLeftButtonRelease = false;
        ignoreNextLeftButtonRelease = false;
    }
    }
@@ -1140,7 +1142,7 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )


    // Compute the cursor position in drawing units.  Also known as logical units to wxDC.
    // Compute the cursor position in drawing units.  Also known as logical units to wxDC.
    pos = wxPoint( DC.DeviceToLogicalX( pos.x ), DC.DeviceToLogicalY( pos.y ) );
    pos = wxPoint( DC.DeviceToLogicalX( pos.x ), DC.DeviceToLogicalY( pos.y ) );
    Screen->m_MousePosition = pos;
    Screen->SetMousePosition( pos );


    GetParent()->GeneralControle( &DC, pos );
    GetParent()->GeneralControle( &DC, pos );


+0 −1
Original line number Original line Diff line number Diff line
@@ -69,7 +69,6 @@ void DIALOG_FOOTPRINTS_DISPLAY_OPTIONS::UpdateObjectSettings( void )
    m_Parent->m_DisplayModText = m_TextDisplayOption->GetSelection();
    m_Parent->m_DisplayModText = m_TextDisplayOption->GetSelection();
    m_Parent->m_DisplayPadNum  = m_IsShowPadNum->GetValue();
    m_Parent->m_DisplayPadNum  = m_IsShowPadNum->GetValue();
    m_Parent->m_DisplayPadFill = m_IsShowPadFill->GetValue();
    m_Parent->m_DisplayPadFill = m_IsShowPadFill->GetValue();
    m_Parent->SetToolbars();
    m_Parent->DrawPanel->Refresh();
    m_Parent->DrawPanel->Refresh();
}
}


+1 −1
Original line number Original line Diff line number Diff line
@@ -228,7 +228,7 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC )
    if( firstsegment == NULL )
    if( firstsegment == NULL )
        return;
        return;


    if( ( firstsegment->m_Flags & IS_NEW ) == 0 )
    if( !firstsegment->IsNew() )
        return;
        return;


    /* Delete Null segments and Put line it in Drawlist */
    /* Delete Null segments and Put line it in Drawlist */
+2 −2
Original line number Original line Diff line number Diff line
@@ -29,7 +29,7 @@ static void ExitBusEntry( EDA_DRAW_PANEL* Panel, wxDC* DC )
    {
    {
        BusEntry->Draw( Panel, DC, wxPoint( 0, 0 ), g_XorMode );
        BusEntry->Draw( Panel, DC, wxPoint( 0, 0 ), g_XorMode );


        if( BusEntry->m_Flags & IS_NEW )
        if( BusEntry->IsNew() )
        {
        {
            delete BusEntry;
            delete BusEntry;
            Panel->GetScreen()->SetCurItem( NULL );
            Panel->GetScreen()->SetCurItem( NULL );
@@ -85,7 +85,7 @@ void SCH_EDIT_FRAME::StartMoveBusEntry( SCH_BUS_ENTRY* BusEntry, wxDC* DC )
    if( BusEntry == NULL )
    if( BusEntry == NULL )
        return;
        return;


    if( (BusEntry->m_Flags & IS_NEW) == 0 )    // not already in edit, save shape
    if( !BusEntry->IsNew() )    // not already in edit, save shape
    {
    {
        delete g_ItemToUndoCopy;
        delete g_ItemToUndoCopy;
        g_ItemToUndoCopy = BusEntry->Clone();
        g_ItemToUndoCopy = BusEntry->Clone();
Loading