Commit 8257ebeb authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Code cleanup

parents 43fe809d e095b07c
Loading
Loading
Loading
Loading
+49 −89
Original line number Original line Diff line number Diff line
@@ -8,6 +8,7 @@
#include "common.h"
#include "common.h"
#include "macros.h"
#include "macros.h"
#include "kicad_string.h"
#include "kicad_string.h"
#include "dialog_helpers.h"




enum listbox {
enum listbox {
@@ -26,55 +27,44 @@ BEGIN_EVENT_TABLE( WinEDAListBox, wxDialog )
END_EVENT_TABLE()
END_EVENT_TABLE()




/* Used to display a list of elements for selection.
/**
 * ITEMLIST* = pointer to the list of names
 * Used to display a list of elements for selection, and display comment of info lines
 * = Reftext preselection
 * about the selected item.
 * = Movefct callback function to display comments
 * @param aParent = apointeur to the parent window
 * @param aTitle = the title shown on top.
 * @param aItemList = a wxArrayString: the list of elements.
 * @param aRefText = an item name if an item must be preselected.
 * @param aCallBackFunction callback function to display comments
 * @param aPos = position of the dialog.
 */
 */
WinEDAListBox::WinEDAListBox( WinEDA_DrawFrame* parent, const wxString& title,
WinEDAListBox::WinEDAListBox( WinEDA_DrawFrame* aParent, const wxString& aTitle,
                              const wxChar** itemlist, const wxString& reftext,
                              const wxArrayString& aItemList, const wxString& aRefText,
                              void(* movefct)(wxString& Text) ,
                              void(* aCallBackFunction)(wxString& Text), wxPoint aPos ) :
                              const wxColour& colour, wxPoint dialog_position ) :
    wxDialog( aParent, wxID_ANY, aTitle, aPos, wxDefaultSize,
    wxDialog( parent, -1, title, dialog_position, wxDefaultSize,
              wxDEFAULT_DIALOG_STYLE | MAYBE_RESIZE_BORDER )
              wxDEFAULT_DIALOG_STYLE | MAYBE_RESIZE_BORDER )
{
{
    const wxChar** names;
    m_callBackFct = aCallBackFunction;

    m_messages    = NULL;
    m_ItemList = itemlist;
    m_Parent   = parent;
    m_MoveFct  = movefct;
    m_WinMsg   = NULL;
    SetReturnCode( -1 );


    wxBoxSizer* GeneralBoxSizer = new wxBoxSizer( wxVERTICAL );
    wxBoxSizer* GeneralBoxSizer = new wxBoxSizer( wxVERTICAL );


    SetSizer( GeneralBoxSizer );
    SetSizer( GeneralBoxSizer );


    m_List = new wxListBox( this, ID_LISTBOX_LIST, wxDefaultPosition,
    m_listBox = new wxListBox( this, ID_LISTBOX_LIST, wxDefaultPosition,
                            wxSize( 300, 200 ), 0, NULL,
                            wxSize( 300, 200 ), 0, NULL,
                            wxLB_NEEDED_SB | wxLB_SINGLE | wxLB_HSCROLL );
                            wxLB_NEEDED_SB | wxLB_SINGLE | wxLB_HSCROLL );


    if( colour != wxNullColour )
    GeneralBoxSizer->Add( m_listBox, 0, wxGROW | wxALL, 5 );
    {
        m_List->SetBackgroundColour( colour );
        m_List->SetForegroundColour( *wxBLACK );
    }

    GeneralBoxSizer->Add( m_List, 0, wxGROW | wxALL, 5 );


    if( itemlist )
    InsertItems( aItemList, 0 );
    {
        for( names = m_ItemList; *names != NULL; names++ )
            m_List->Append( *names );
    }


    if( m_MoveFct )
    if( m_callBackFct )
    {
    {
        m_WinMsg = new wxTextCtrl( this, -1, wxEmptyString,
        m_messages = new wxTextCtrl( this, -1, wxEmptyString,
                                   wxDefaultPosition, wxSize( -1, 60 ),
                                   wxDefaultPosition, wxSize( -1, 60 ),
                                   wxTE_READONLY | wxTE_MULTILINE );
                                   wxTE_READONLY | wxTE_MULTILINE );


        GeneralBoxSizer->Add( m_WinMsg, 0, wxGROW | wxALL, 5 );
        GeneralBoxSizer->Add( m_messages, 0, wxGROW | wxALL, 5 );
    }
    }


    wxSizer* buttonSizer = CreateButtonSizer( wxOK | wxCANCEL );
    wxSizer* buttonSizer = CreateButtonSizer( wxOK | wxCANCEL );
@@ -84,33 +74,8 @@ WinEDAListBox::WinEDAListBox( WinEDA_DrawFrame* parent, const wxString& title,


    GetSizer()->Fit( this );
    GetSizer()->Fit( this );
    GetSizer()->SetSizeHints( this );
    GetSizer()->SetSizeHints( this );

    if( dialog_position == wxDefaultPosition )
    {
    Centre();
    Centre();
}
}
    else    // Ensure the window dialog is inside the main window :
    {
        wxPoint pos = dialog_position;
        wxPoint maxpos;
        maxpos.x = parent->GetPosition().x + parent->GetSize().x;
        maxpos.y = parent->GetPosition().y + parent->GetSize().y;
        wxPoint endpoint;
        endpoint.x = pos.x + GetSize().x;
        endpoint.y = pos.y + GetSize().y;

        if( endpoint.x > maxpos.x )
            pos.x -= endpoint.x - maxpos.x;
        if( endpoint.y > maxpos.y )
            pos.y -= endpoint.y - maxpos.y;

        if( pos.x < parent->GetPosition().x )
            pos.x = parent->GetPosition().x;
        if( pos.y < parent->GetPosition().y )
            pos.y = parent->GetPosition().y;
        Move( pos );
    }
}




WinEDAListBox::~WinEDAListBox()
WinEDAListBox::~WinEDAListBox()
@@ -121,9 +86,9 @@ WinEDAListBox::~WinEDAListBox()
void WinEDAListBox::MoveMouseToOrigin()
void WinEDAListBox::MoveMouseToOrigin()
{
{
    int    x, y, w, h;
    int    x, y, w, h;
    wxSize list_size = m_List->GetSize();
    wxSize list_size = m_listBox->GetSize();
    int    orgx = m_List->GetRect().GetLeft();
    int    orgx = m_listBox->GetRect().GetLeft();
    int    orgy = m_List->GetRect().GetTop();
    int    orgy = m_listBox->GetRect().GetTop();


    wxClientDisplayRect( &x, &y, &w, &h );
    wxClientDisplayRect( &x, &y, &w, &h );


@@ -133,27 +98,26 @@ void WinEDAListBox::MoveMouseToOrigin()


wxString WinEDAListBox::GetTextSelection()
wxString WinEDAListBox::GetTextSelection()
{
{
    wxString text = m_List->GetStringSelection();
    wxString text = m_listBox->GetStringSelection();

    return text;
    return text;
}
}




void WinEDAListBox::Append( const wxString& item )
void WinEDAListBox::Append( const wxString& item )
{
{
    m_List->Append( item );
    m_listBox->Append( item );
}
}




void WinEDAListBox::InsertItems( const wxArrayString& itemlist, int position )
void WinEDAListBox::InsertItems( const wxArrayString& itemlist, int position )
{
{
    m_List->InsertItems( itemlist, position );
    m_listBox->InsertItems( itemlist, position );
}
}




void WinEDAListBox::OnCancelClick( wxCommandEvent& event )
void WinEDAListBox::OnCancelClick( wxCommandEvent& event )
{
{
    EndModal( -1 );
    EndModal( wxID_CANCEL );
}
}




@@ -161,35 +125,31 @@ void WinEDAListBox::ClickOnList( wxCommandEvent& event )
{
{
    wxString text;
    wxString text;


    if( m_MoveFct )
    if( m_callBackFct )
    {
    {
        m_WinMsg->Clear();
        m_messages->Clear();
        text = m_List->GetStringSelection();
        text = m_listBox->GetStringSelection();
        m_MoveFct( text );
        m_callBackFct( text );
        m_WinMsg->WriteText( text );
        m_messages->WriteText( text );
    }
    }
}
}




void WinEDAListBox::D_ClickOnList( wxCommandEvent& event )
void WinEDAListBox::D_ClickOnList( wxCommandEvent& event )
{
{
    int ii = m_List->GetSelection();
    EndModal( wxID_OK );

    EndModal( ii );
}
}




void WinEDAListBox::OnOkClick( wxCommandEvent& event )
void WinEDAListBox::OnOkClick( wxCommandEvent& event )
{
{
    int ii = m_List->GetSelection();
    EndModal( wxID_OK );

    EndModal( ii );
}
}




void WinEDAListBox::OnClose( wxCloseEvent& event )
void WinEDAListBox::OnClose( wxCloseEvent& event )
{
{
    EndModal( -1 );
    EndModal( wxID_CANCEL );
}
}




@@ -203,7 +163,7 @@ static int SortItems( const wxString** ptr1, const wxString** ptr2 )


void WinEDAListBox:: SortList()
void WinEDAListBox:: SortList()
{
{
    int ii, NbItems = m_List->GetCount();
    int ii, NbItems = m_listBox->GetCount();
    const wxString** BufList;
    const wxString** BufList;


    if( NbItems <= 0 )
    if( NbItems <= 0 )
@@ -212,16 +172,16 @@ void WinEDAListBox:: SortList()
    BufList = (const wxString**) MyZMalloc( 100 * NbItems * sizeof(wxString*) );
    BufList = (const wxString**) MyZMalloc( 100 * NbItems * sizeof(wxString*) );
    for( ii = 0; ii < NbItems; ii++ )
    for( ii = 0; ii < NbItems; ii++ )
    {
    {
        BufList[ii] = new wxString( m_List->GetString (ii) );
        BufList[ii] = new wxString( m_listBox->GetString( ii ) );
    }
    }


    qsort( BufList, NbItems, sizeof(wxString*),
    qsort( BufList, NbItems, sizeof(wxString*),
           ( int( * ) ( const void*, const void* ) )SortItems );
           ( int( * ) ( const void*, const void* ) )SortItems );


    m_List->Clear();
    m_listBox->Clear();
    for( ii = 0; ii < NbItems; ii++ )
    for( ii = 0; ii < NbItems; ii++ )
    {
    {
        m_List->Append( *BufList[ii] );
        m_listBox->Append( *BufList[ii] );
        delete BufList[ii];
        delete BufList[ii];
    }
    }


+1 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@
#include "wxstruct.h"
#include "wxstruct.h"
#include "confirm.h"
#include "confirm.h"
#include "kicad_device_context.h"
#include "kicad_device_context.h"
#include "dialog_helpers.h"


#include <wx/fontdlg.h>
#include <wx/fontdlg.h>


+1 −63
Original line number Original line Diff line number Diff line
@@ -2,14 +2,10 @@
/* wxwineda.cpp */
/* wxwineda.cpp */
/****************/
/****************/


#ifdef __GNUG__
#pragma implementation
#endif

#include "fctsys.h"
#include "fctsys.h"
#include "common.h"
#include "common.h"
#include "wxstruct.h"
#include "wxstruct.h"

#include "dialog_helpers.h"


/*
/*
 * Text entry dialog to enter one or more lines of text.
 * Text entry dialog to enter one or more lines of text.
@@ -390,61 +386,3 @@ void WinEDA_ValueCtrl::Enable( bool enbl )
    m_ValueCtrl->Enable( enbl );
    m_ValueCtrl->Enable( enbl );
    m_Text->Enable( enbl );
    m_Text->Enable( enbl );
}
}


/**********************************************************************/
/* Class to display and edit a double precision floating point value. */
/**********************************************************************/
WinEDA_DFloatValueCtrl::WinEDA_DFloatValueCtrl( wxWindow* parent,
                                                const wxString& title,
                                                double value,
                                                wxBoxSizer* BoxSizer )
{
    wxString buffer;
    wxString label = title;

    m_Value = value;

    m_Text = new wxStaticText( parent, -1, label );

    BoxSizer->Add( m_Text, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );

    buffer.Printf( wxT( "%f" ), m_Value );
    m_ValueCtrl = new   wxTextCtrl( parent, -1, buffer );

    BoxSizer->Add( m_ValueCtrl, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
}


WinEDA_DFloatValueCtrl::~WinEDA_DFloatValueCtrl()
{
    delete m_ValueCtrl;
    delete m_Text;
}


double WinEDA_DFloatValueCtrl::GetValue()
{
    double coord = 0;

    m_ValueCtrl->GetValue().ToDouble( &coord );
    return coord;
}


void WinEDA_DFloatValueCtrl::SetValue( double new_value )
{
    wxString buffer;

    m_Value = new_value;

    buffer.Printf( wxT( "%f" ), m_Value );
    m_ValueCtrl->SetValue( buffer );
}


void WinEDA_DFloatValueCtrl::Enable( bool enbl )
{
    m_ValueCtrl->Enable( enbl );
    m_Text->Enable( enbl );
}
+8 −5
Original line number Original line Diff line number Diff line
@@ -14,6 +14,7 @@
#include "general.h"
#include "general.h"
#include "protos.h"
#include "protos.h"
#include "class_library.h"
#include "class_library.h"
#include "dialog_helpers.h"


#include <boost/foreach.hpp>
#include <boost/foreach.hpp>


@@ -64,13 +65,15 @@ wxString DataBaseGetName( WinEDA_DrawFrame* frame, wxString& Keys, wxString& Buf
        return wxEmptyString;
        return wxEmptyString;
    }
    }


    wxSingleChoiceDialog dlg( frame, wxEmptyString, _( "Select Component" ),
    // Show candidate list:
                              nameList );
    wxString cmpname;

    WinEDAListBox dlg( frame, _( "Select Component" ),
    if( dlg.ShowModal() == wxID_CANCEL || dlg.GetStringSelection().IsEmpty() )
                               nameList, cmpname, DisplayCmpDoc );
    if( dlg.ShowModal() != wxID_OK )
        return wxEmptyString;
        return wxEmptyString;


    return dlg.GetStringSelection();
    cmpname = dlg.GetTextSelection();
    return cmpname;
}
}




+1 −0
Original line number Original line Diff line number Diff line
@@ -15,6 +15,7 @@
#include "protos.h"
#include "protos.h"
#include "class_library.h"
#include "class_library.h"
#include "sch_component.h"
#include "sch_component.h"
#include "dialog_helpers.h"


#include "dialog_edit_component_in_schematic.h"
#include "dialog_edit_component_in_schematic.h"


Loading