kicad/common/displlst.cpp

260 lines
6.7 KiB
C++
Raw Normal View History

/********************************/
/* MODULE displlst.cpp */
/********************************/
#include "fctsys.h"
#include "wxstruct.h"
#include "gr_basic.h"
#include "common.h"
2007-11-05 07:07:00 +00:00
#include "macros.h"
#include "kicad_string.h"
2007-12-11 23:12:37 +00:00
/***********************/
/* class WinEDAListBox */
/***********************/
enum listbox {
2007-10-07 03:08:24 +00:00
ID_LISTBOX_LIST = 8000
};
2007-12-11 23:12:37 +00:00
BEGIN_EVENT_TABLE( WinEDAListBox, wxDialog )
EVT_BUTTON( wxID_OK, WinEDAListBox::OnOkClick )
EVT_BUTTON( wxID_CANCEL, WinEDAListBox::OnCancelClick )
EVT_LISTBOX( ID_LISTBOX_LIST, WinEDAListBox::ClickOnList )
EVT_LISTBOX_DCLICK( ID_LISTBOX_LIST, WinEDAListBox::D_ClickOnList )
EVT_CHAR( WinEDAListBox::OnKeyEvent )
EVT_CHAR_HOOK( WinEDAListBox::OnKeyEvent )
EVT_CLOSE( WinEDAListBox::OnClose )
END_EVENT_TABLE()
2007-12-11 23:12:37 +00:00
/*******************************/
/* Constructeur et destructeur */
/*******************************/
/* Permet l'affichage d'une liste d'elements pour selection.
2007-12-11 23:12:37 +00:00
* itemlist = pointeur sur la liste des pinteurs de noms
* reftext = preselection
* movefct = fonction de cr<EFBFBD>ation de commentaires a afficher
*/
WinEDAListBox::WinEDAListBox( WinEDA_DrawFrame* parent, const wxString& title,
const wxChar** itemlist, const wxString& reftext,
2007-12-11 23:12:37 +00:00
void(* movefct)(wxString& Text) ,
const wxColour& colour, wxPoint dialog_position ) :
wxDialog( parent, -1, title, dialog_position, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | MAYBE_RESIZE_BORDER )
{
2007-12-11 23:12:37 +00:00
const wxChar** names;
m_ItemList = itemlist;
m_Parent = parent;
m_MoveFct = movefct;
m_WinMsg = NULL;
SetReturnCode( -1 );
wxBoxSizer* GeneralBoxSizer = new wxBoxSizer( wxVERTICAL );
2007-12-11 23:12:37 +00:00
SetSizer( GeneralBoxSizer );
m_List = new wxListBox( this, ID_LISTBOX_LIST, wxDefaultPosition,
wxSize( 300, 200 ), 0, NULL,
2007-12-11 23:12:37 +00:00
wxLB_NEEDED_SB | wxLB_SINGLE | wxLB_HSCROLL );
if( colour != wxNullColour )
{
m_List->SetBackgroundColour( colour );
m_List->SetForegroundColour( *wxBLACK );
}
GeneralBoxSizer->Add( m_List, 0, wxGROW | wxALL, 5 );
2007-12-11 23:12:37 +00:00
if( itemlist )
{
for( names = m_ItemList; *names != NULL; names++ )
2007-12-11 23:12:37 +00:00
m_List->Append( *names );
}
2007-12-11 23:12:37 +00:00
if( m_MoveFct )
{
m_WinMsg = new wxTextCtrl( this, -1, wxEmptyString,
wxDefaultPosition, wxSize( -1, 60 ),
wxTE_READONLY | wxTE_MULTILINE );
2007-12-11 23:12:37 +00:00
GeneralBoxSizer->Add( m_WinMsg, 0, wxGROW | wxALL, 5 );
}
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 );
if( dialog_position == wxDefaultPosition )
2007-12-11 23:12:37 +00:00
{
Centre();
}
else // Ensure the window dialog is on screen :
{
wxPoint pos;
m_Parent->GetPosition( &pos.x, &pos.y );
if( pos.x < 0 )
pos.x = 0;
if( pos.y < 0 )
pos.y = 0;
pos.x += 20; pos.y += 30;
Move( pos );
}
}
2007-12-11 23:12:37 +00:00
WinEDAListBox::~WinEDAListBox()
{
}
/******************************************/
void WinEDAListBox::MoveMouseToOrigin()
/******************************************/
{
2007-12-11 23:12:37 +00:00
int x, y, w, h;
wxSize list_size = m_List->GetSize();
int orgx = m_List->GetRect().GetLeft();
int orgy = m_List->GetRect().GetTop();
wxClientDisplayRect( &x, &y, &w, &h );
WarpPointer( x + orgx + 20, y + orgy + (list_size.y / 2) );
}
2007-12-11 23:12:37 +00:00
/*********************************************/
wxString WinEDAListBox::GetTextSelection()
/*********************************************/
{
2007-12-11 23:12:37 +00:00
wxString text = m_List->GetStringSelection();
return text;
2007-05-06 16:03:28 +00:00
}
2007-12-11 23:12:37 +00:00
/***************************************************************/
2007-12-11 23:12:37 +00:00
void WinEDAListBox::Append( const wxString& item )
/***************************************************************/
{
2007-12-11 23:12:37 +00:00
m_List->Append( item );
}
2007-12-11 23:12:37 +00:00
/******************************************************************************/
2007-12-11 23:12:37 +00:00
void WinEDAListBox::InsertItems( const wxArrayString& itemlist, int position )
/******************************************************************************/
{
2007-12-11 23:12:37 +00:00
m_List->InsertItems( itemlist, position );
}
2007-12-11 23:12:37 +00:00
/************************************************/
2007-12-11 23:12:37 +00:00
void WinEDAListBox::OnCancelClick( wxCommandEvent& event )
/************************************************/
{
2007-12-11 23:12:37 +00:00
EndModal( -1 );
}
2007-12-11 23:12:37 +00:00
/*****************************************************/
2007-12-11 23:12:37 +00:00
void WinEDAListBox::ClickOnList( wxCommandEvent& event )
/*****************************************************/
{
2007-12-11 23:12:37 +00:00
wxString text;
if( m_MoveFct )
{
m_WinMsg->Clear();
text = m_List->GetStringSelection();
m_MoveFct( text );
m_WinMsg->WriteText( text.GetData() );
}
}
2007-12-11 23:12:37 +00:00
/*******************************************************/
2007-12-11 23:12:37 +00:00
void WinEDAListBox::D_ClickOnList( wxCommandEvent& event )
/*******************************************************/
{
2007-12-11 23:12:37 +00:00
int ii = m_List->GetSelection();
EndModal( ii );
}
/***********************************************/
2007-12-11 23:12:37 +00:00
void WinEDAListBox::OnOkClick( wxCommandEvent& event )
/***********************************************/
{
2007-12-11 23:12:37 +00:00
int ii = m_List->GetSelection();
EndModal( ii );
}
2007-12-11 23:12:37 +00:00
/***********************************************/
2007-12-11 23:12:37 +00:00
void WinEDAListBox::OnClose( wxCloseEvent& event )
/***********************************************/
{
2007-12-11 23:12:37 +00:00
EndModal( -1 );
}
/********************************************************************/
2007-12-11 23:12:37 +00:00
static int SortItems( const wxString** ptr1, const wxString** ptr2 )
/********************************************************************/
2007-12-11 23:12:37 +00:00
/* Routines de comparaison pour le tri tri alphabetique,
2007-10-07 03:08:24 +00:00
* avec traitement des nombres en tant que valeur numerique
*/
{
2007-12-11 23:12:37 +00:00
return StrNumICmp( (*ptr1)->GetData(), (*ptr2)->GetData() );
}
/************************************/
2007-09-01 12:00:30 +00:00
void WinEDAListBox:: SortList()
/************************************/
{
2007-12-11 23:12:37 +00:00
int ii, NbItems = m_List->GetCount();
const wxString** BufList;
2007-12-11 23:12:37 +00:00
if( NbItems <= 0 )
return;
2007-12-11 23:12:37 +00:00
BufList = (const wxString**) MyZMalloc( 100 * NbItems * sizeof(wxString*) );
for( ii = 0; ii < NbItems; ii++ )
{
BufList[ii] = new wxString( m_List->GetString (ii) );
}
2007-12-11 23:12:37 +00:00
qsort( BufList, NbItems, sizeof(wxString*),
( int( * ) ( const void*, const void* ) )SortItems );
2007-12-11 23:12:37 +00:00
m_List->Clear();
for( ii = 0; ii < NbItems; ii++ )
{
m_List->Append( *BufList[ii] );
delete BufList[ii];
}
2007-12-11 23:12:37 +00:00
free( BufList );
}
/****************************************************/
2007-12-11 23:12:37 +00:00
void WinEDAListBox::OnKeyEvent( wxKeyEvent& event )
/****************************************************/
{
2007-12-11 23:12:37 +00:00
event.Skip();
}