2011-11-08 16:37:25 +00:00
|
|
|
/**
|
|
|
|
* @file displlst.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <dialog_helpers.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum listbox {
|
2007-10-07 03:08:24 +00:00
|
|
|
ID_LISTBOX_LIST = 8000
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
BEGIN_EVENT_TABLE( EDA_LIST_DIALOG, wxDialog )
|
|
|
|
EVT_BUTTON( wxID_OK, EDA_LIST_DIALOG::OnOkClick )
|
|
|
|
EVT_BUTTON( wxID_CANCEL, EDA_LIST_DIALOG::OnCancelClick )
|
|
|
|
EVT_LISTBOX( ID_LISTBOX_LIST, EDA_LIST_DIALOG::ClickOnList )
|
|
|
|
EVT_LISTBOX_DCLICK( ID_LISTBOX_LIST, EDA_LIST_DIALOG::D_ClickOnList )
|
|
|
|
EVT_CHAR( EDA_LIST_DIALOG::OnKeyEvent )
|
|
|
|
EVT_CHAR_HOOK( EDA_LIST_DIALOG::OnKeyEvent )
|
|
|
|
EVT_CLOSE( EDA_LIST_DIALOG::OnClose )
|
2007-06-05 12:10:51 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
|
|
|
|
const wxArrayString& aItemList, const wxString& aRefText,
|
|
|
|
void(* aCallBackFunction)(wxString& Text), wxPoint aPos ) :
|
2012-10-18 19:31:40 +00:00
|
|
|
DIALOG_SHIM( aParent, wxID_ANY, aTitle, aPos, wxDefaultSize,
|
2009-09-02 18:12:45 +00:00
|
|
|
wxDEFAULT_DIALOG_STYLE | MAYBE_RESIZE_BORDER )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
m_callBackFct = aCallBackFunction;
|
|
|
|
m_messages = NULL;
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
wxBoxSizer* GeneralBoxSizer = new wxBoxSizer( wxVERTICAL );
|
2007-12-11 23:12:37 +00:00
|
|
|
|
|
|
|
SetSizer( GeneralBoxSizer );
|
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
m_listBox = new wxListBox( this, ID_LISTBOX_LIST, wxDefaultPosition,
|
2012-10-18 19:31:40 +00:00
|
|
|
wxDefaultSize, 0, NULL,
|
2011-01-21 19:30:59 +00:00
|
|
|
wxLB_NEEDED_SB | wxLB_SINGLE | wxLB_HSCROLL );
|
2012-10-18 19:31:40 +00:00
|
|
|
m_listBox->SetMinSize( wxSize( 200, 200 ) );
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2012-05-14 15:23:20 +00:00
|
|
|
GeneralBoxSizer->Add( m_listBox, 2, wxGROW | wxALL, 5 );
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
InsertItems( aItemList, 0 );
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2012-10-18 19:31:40 +00:00
|
|
|
if( !aRefText.IsEmpty() ) // try to select the item matching aRefText
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < aItemList.GetCount(); ii++ )
|
|
|
|
if( aItemList[ii] == aRefText )
|
|
|
|
{
|
|
|
|
m_listBox->SetSelection( ii );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( m_callBackFct )
|
2009-09-02 18:12:45 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
m_messages = new wxTextCtrl( this, -1, wxEmptyString,
|
2012-10-18 19:31:40 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2011-09-06 19:42:46 +00:00
|
|
|
wxTE_READONLY | wxTE_MULTILINE );
|
2012-10-18 19:31:40 +00:00
|
|
|
m_messages->SetMinSize( wxSize( -1, 60 ) );
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2012-05-14 15:23:20 +00:00
|
|
|
GeneralBoxSizer->Add( m_messages, 1, wxGROW | wxALL, 5 );
|
2007-12-11 23:12:37 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
wxSizer* buttonSizer = CreateButtonSizer( wxOK | wxCANCEL );
|
|
|
|
|
|
|
|
if( buttonSizer )
|
|
|
|
GeneralBoxSizer->Add( buttonSizer, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2010-11-19 18:50:23 +00:00
|
|
|
Centre();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_LIST_DIALOG::~EDA_LIST_DIALOG()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void EDA_LIST_DIALOG::MoveMouseToOrigin()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-12-11 23:12:37 +00:00
|
|
|
int x, y, w, h;
|
2010-11-19 18:50:23 +00:00
|
|
|
wxSize list_size = m_listBox->GetSize();
|
|
|
|
int orgx = m_listBox->GetRect().GetLeft();
|
|
|
|
int orgy = m_listBox->GetRect().GetTop();
|
2007-12-11 23:12:37 +00:00
|
|
|
|
|
|
|
wxClientDisplayRect( &x, &y, &w, &h );
|
|
|
|
|
|
|
|
WarpPointer( x + orgx + 20, y + orgy + (list_size.y / 2) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
wxString EDA_LIST_DIALOG::GetTextSelection()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
wxString text = m_listBox->GetStringSelection();
|
2007-12-11 23:12:37 +00:00
|
|
|
return text;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void EDA_LIST_DIALOG::Append( const wxString& item )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
m_listBox->Append( item );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void EDA_LIST_DIALOG::InsertItems( const wxArrayString& itemlist, int position )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
m_listBox->InsertItems( itemlist, position );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void EDA_LIST_DIALOG::OnCancelClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_CANCEL );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void EDA_LIST_DIALOG::ClickOnList( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-12-11 23:12:37 +00:00
|
|
|
wxString text;
|
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( m_callBackFct )
|
2007-12-11 23:12:37 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
m_messages->Clear();
|
|
|
|
text = m_listBox->GetStringSelection();
|
|
|
|
m_callBackFct( text );
|
|
|
|
m_messages->WriteText( text );
|
2007-12-11 23:12:37 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void EDA_LIST_DIALOG::D_ClickOnList( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_OK );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void EDA_LIST_DIALOG::OnOkClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_OK );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void EDA_LIST_DIALOG::OnClose( wxCloseEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_CANCEL );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Sort alphabetically, case insensitive.
|
2007-10-07 03:08:24 +00:00
|
|
|
*/
|
2011-11-08 16:37:25 +00:00
|
|
|
static int SortItems( const wxString& item1, const wxString& item2 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-08 16:37:25 +00:00
|
|
|
return StrNumCmp( item1, item2, INT_MAX, true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
void EDA_LIST_DIALOG::SortList()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-08 16:37:25 +00:00
|
|
|
wxArrayString list = m_listBox->GetStrings();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
if( list.IsEmpty() )
|
2007-12-11 23:12:37 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
list.Sort( SortItems );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
m_listBox->Clear();
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
m_listBox->Append( list );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void EDA_LIST_DIALOG::OnKeyEvent( wxKeyEvent& event )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-12-11 23:12:37 +00:00
|
|
|
event.Skip();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|