Commit 9f7ca344 authored by charras's avatar charras

eeschema: Viewlib: listboxes for lib or component selection are now resizable

parent d96039a1
......@@ -4,6 +4,12 @@ KiCad ChangeLog 2009
Please add newer entries at the top, list the date and your name with
email address.
2009-apr-10 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================
++eeschema:
Viewlib: listboxes for lib or component selection are now resizable
2009-apr-07 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================
++pcbnew:
......
......@@ -145,9 +145,13 @@ void DIALOG_EESCHEMA_CONFIG::OnOkClick( wxCommandEvent& event )
g_NetFormat = m_NetFormatBox->GetSelection() + NET_TYPE_PCBNEW;
// Set new default path lib
if ( g_UserLibDirBuffer != m_LibDirCtrl->GetValue() )
{
g_UserLibDirBuffer = m_LibDirCtrl->GetValue();
m_LibListChanged = true;
}
// Set new active lib list
// Set new active library list if the list of default path was modified
if( m_LibListChanged )
{
// Recreate lib list
......
......@@ -17,23 +17,28 @@
/* class WinEDA_ViewlibFrame */
/*****************************/
BEGIN_EVENT_TABLE( WinEDA_ViewlibFrame, WinEDA_DrawFrame )
EVT_CLOSE( WinEDA_ViewlibFrame::OnCloseWindow )
EVT_SIZE( WinEDA_ViewlibFrame::OnSize )
EVT_ACTIVATE( WinEDA_DrawFrame::OnActivate )
/* Window events */
EVT_CLOSE( WinEDA_ViewlibFrame::OnCloseWindow )
EVT_SIZE( WinEDA_ViewlibFrame::OnSize )
EVT_ACTIVATE( WinEDA_DrawFrame::OnActivate )
EVT_TOOL_RANGE( ID_LIBVIEW_START_H_TOOL, ID_LIBVIEW_END_H_TOOL,
WinEDA_ViewlibFrame::Process_Special_Functions )
/* Sash drag events */
EVT_SASH_DRAGGED( ID_LIBVIEW_LIBWINDOW, WinEDA_ViewlibFrame::OnSashDrag )
EVT_SASH_DRAGGED( ID_LIBVIEW_CMPWINDOW, WinEDA_ViewlibFrame::OnSashDrag )
EVT_TOOL_RANGE( ID_ZOOM_IN, ID_ZOOM_PAGE, WinEDA_ViewlibFrame::OnZoom )
EVT_TOOL( ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC,
/* Toolbar events */
EVT_TOOL_RANGE( ID_LIBVIEW_START_H_TOOL, ID_LIBVIEW_END_H_TOOL,
WinEDA_ViewlibFrame::Process_Special_Functions )
EVT_TOOL_RANGE( ID_ZOOM_IN, ID_ZOOM_PAGE, WinEDA_ViewlibFrame::OnZoom )
EVT_TOOL( ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC,
WinEDA_ViewlibFrame::ExportToSchematicLibraryPart )
EVT_KICAD_CHOICEBOX( ID_LIBVIEW_SELECT_PART_NUMBER,
EVT_KICAD_CHOICEBOX( ID_LIBVIEW_SELECT_PART_NUMBER,
WinEDA_ViewlibFrame::Process_Special_Functions )
EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, WinEDA_ViewlibFrame::ClickOnLibList )
EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, WinEDA_ViewlibFrame::ClickOnCmpList )
/* listbox events */
EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, WinEDA_ViewlibFrame::ClickOnLibList )
EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, WinEDA_ViewlibFrame::ClickOnCmpList )
END_EVENT_TABLE()
......@@ -42,16 +47,17 @@ END_EVENT_TABLE()
* The library viewer does not have any menus so add an accelerator table to
* the main frame.
*/
static wxAcceleratorEntry accels[] = {
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F1, ID_POPUP_ZOOM_IN ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F2, ID_POPUP_ZOOM_OUT ),
static wxAcceleratorEntry accels[] =
{
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F1, ID_ZOOM_IN ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F2, ID_ZOOM_OUT ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F3, ID_ZOOM_REDRAW ),
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F4, ID_POPUP_ZOOM_CENTER )
wxAcceleratorEntry( wxACCEL_NORMAL, WXK_F4, ID_ZOOM_PAGE )
};
#define ACCEL_TABLE_CNT ( sizeof( accels ) / sizeof( wxAcceleratorEntry ) )
#define EXTRA_BORDER_SIZE 2
/******************************************************************************/
WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
LibraryStruct* Library,
......@@ -63,12 +69,15 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
wxAcceleratorTable table( ACCEL_TABLE_CNT, accels );
m_FrameName = wxT( "ViewlibFrame" );
m_ConfigPath = wxT( "LibraryViewer" );
// Give an icon
SetIcon( wxIcon( library_browse_xpm ) );
m_CmpList = NULL;
m_LibList = NULL;
m_LibListWindow = NULL;
m_CmpListWindow = NULL;
m_Semaphore = semaphore;
if( m_Semaphore )
......@@ -76,33 +85,58 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
SetBaseScreen( new SCH_SCREEN() );
GetScreen()->m_Center = true; // set to true to have the coordinates origine -0,0) centered on screen
LoadSettings();
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
ReCreateHToolbar();
ReCreateVToolbar();
wxSize size = GetClientSize();
size.y -= m_MsgFrameHeight + 2;
m_LibListSize.y = size.y;
wxPoint win_pos( 0, 0 );
if( Library == NULL )
{
m_LibListSize.x = 150; // Width of library list
m_LibListSize.y = -1;
m_LibList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxPoint( 0, 0 ),
m_LibListSize, 0, NULL, wxLB_HSCROLL );
// Creates the libraries window display
m_LibListWindow =
new wxSashLayoutWindow( this, ID_LIBVIEW_LIBWINDOW, win_pos, m_LibListSize,
wxCLIP_CHILDREN | wxSW_3D, wxT(
"LibWindow" ) );
m_LibListWindow->SetOrientation( wxLAYOUT_VERTICAL );
m_LibListWindow->SetAlignment( wxLAYOUT_LEFT );
m_LibListWindow->SetSashVisible( wxSASH_RIGHT, TRUE );
m_LibListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
m_LibList = new wxListBox( m_LibListWindow, ID_LIBVIEW_LIB_LIST, wxPoint( 0, 0 ),
m_LibListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0),
0, NULL, wxLB_HSCROLL );
m_LibList->SetFont( *g_DialogFont );
m_LibList->SetBackgroundColour( wxColour( 255, 255, 255 ) ); // Library background listbox color (white)
m_LibList->SetForegroundColour( wxColour( 0, 0, 0 ) ); // Library foreground listbox color (black)
}
else
{
g_CurrentViewLibraryName = Library->m_Name;
m_LibListSize.x = 0;
}
m_CmpListSize.x = 150; // Width of component list
m_CmpListSize.y = -1;
m_CmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST,
wxPoint( m_LibListSize.x, 0 ),
m_CmpListSize, 0, NULL, wxLB_HSCROLL );
// Creates the component window display
m_CmpListSize.y = size.y;
win_pos.x = m_LibListSize.x;
win_pos.y = 0;
m_CmpListWindow = new wxSashLayoutWindow( this, ID_LIBVIEW_CMPWINDOW,
win_pos, m_CmpListSize,
wxCLIP_CHILDREN | wxSW_3D, wxT( "CmpWindow" ) );
m_CmpListWindow->SetOrientation( wxLAYOUT_VERTICAL );
// m_CmpListWindow->SetAlignment( wxLAYOUT_LEFT );
m_CmpListWindow->SetSashVisible( wxSASH_RIGHT, TRUE );
m_CmpListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
m_CmpList = new wxListBox( m_CmpListWindow, ID_LIBVIEW_CMP_LIST,
wxPoint( 0, 0 ),
m_CmpListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0),
0, NULL, wxLB_HSCROLL );
m_CmpList->SetFont( *g_DialogFont );
m_CmpList->SetBackgroundColour( wxColour( 255, 255, 255 ) ); // Component background listbox color (white)
m_CmpList->SetForegroundColour( wxColour( 0, 0, 0 ) ); // Component foreground listbox color (black)
LoadSettings();
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
ReCreateHToolbar();
ReCreateVToolbar();
if( m_LibList )
ReCreateListLib();
DisplayLibInfos();
......@@ -137,17 +171,56 @@ void WinEDA_ViewlibFrame::OnCloseWindow( wxCloseEvent& Event )
}
/****************************************************/
void WinEDA_ViewlibFrame::OnSashDrag( wxSashEvent& event )
/****************************************************/
/* Resize sub windows when dragging a sash window border
*/
{
if( event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE )
return;
m_LibListSize.y = GetClientSize().y - m_MsgFrameHeight;
m_CmpListSize.y = m_LibListSize.y;
switch( event.GetId() )
{
case ID_LIBVIEW_LIBWINDOW:
if( m_LibListWindow )
{
m_LibListSize.x = event.GetDragRect().width;
m_LibListWindow->SetSize( m_LibListSize );
m_CmpListWindow->SetPosition( wxPoint( m_LibListSize.x, 0 ) );
}
break;
case ID_LIBVIEW_CMPWINDOW:
m_CmpListSize.x = event.GetDragRect().width;
m_CmpListWindow->SetSize( m_CmpListSize );
break;
}
// Now, we must recalculate the position and size of subwindows
wxSizeEvent SizeEv;
OnSize( SizeEv );
// Ensure the panel is always redrawn (sometimes some garbage remains):
DrawPanel->Refresh();
}
/*****************************************************/
void WinEDA_ViewlibFrame::OnSize( wxSizeEvent& SizeEv )
/*****************************************************/
{
wxSize size;
wxSize clientsize;
wxSize maintoolbar_size;
wxSize Vtoolbar_size;
GetClientSize( &size.x, &size.y );
m_FrameSize = size;
size.y -= m_MsgFrameHeight;
clientsize = GetClientSize();
m_FrameSize = clientsize;
clientsize.y -= m_MsgFrameHeight;
if( m_HToolBar )
{
......@@ -157,32 +230,37 @@ void WinEDA_ViewlibFrame::OnSize( wxSizeEvent& SizeEv )
if( m_VToolBar )
{
Vtoolbar_size = m_VToolBar->GetSize();
m_VToolBar->SetSize( size.x - maintoolbar_size.y, 0, -1, size.y );
m_VToolBar->SetSize( clientsize.x - maintoolbar_size.y, 0, -1, clientsize.y );
}
if( MsgPanel )
{
MsgPanel->SetSize( 0, size.y, size.x, m_MsgFrameHeight );
MsgPanel->SetSize( 0, clientsize.y, clientsize.x, m_MsgFrameHeight );
}
if( DrawPanel )
{
DrawPanel->SetSize( m_LibListSize.x + m_CmpListSize.x, 0,
size.x - Vtoolbar_size.x - m_LibListSize.x - m_CmpListSize.x,
size.y );
clientsize.x - Vtoolbar_size.x - m_LibListSize.x - m_CmpListSize.x,
clientsize.y );
}
if( m_LibList )
if( m_LibList && m_LibListWindow )
{
m_LibListSize.y = size.y;
m_LibList->SetSize( 0, 0, m_LibListSize.x, m_LibListSize.y );
m_LibListSize.y = clientsize.y - 2;
m_LibListWindow->SetSize( m_LibListSize );
m_LibList->SetSize( m_LibListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0) );
}
if( m_CmpList )
if( m_CmpList && m_CmpListWindow )
{
m_CmpListSize.y = size.y;
m_CmpList->SetSize( m_LibListSize.x, 0, m_CmpListSize.x, m_CmpListSize.y );
m_CmpListSize.y = clientsize.y - 2;
m_CmpListWindow->SetSize( m_CmpListSize );
m_CmpListWindow->SetPosition( wxPoint( m_LibListSize.x, 0 ) );
m_CmpList->SetSize( m_CmpListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0) );
}
SizeEv.Skip();
}
......@@ -265,6 +343,9 @@ void WinEDA_ViewlibFrame::ReCreateListLib()
void WinEDA_ViewlibFrame::ReCreateListCmp()
/***********************************************/
{
if( m_CmpList == NULL )
return;
int ii;
EDA_LibComponentStruct* LibEntry = NULL;
LibraryStruct* Library = FindLibrary( g_CurrentViewLibraryName.GetData() );
......@@ -339,3 +420,57 @@ void WinEDA_ViewlibFrame::ExportToSchematicLibraryPart( wxCommandEvent& event )
g_CurrentViewComponentName.Empty();
Close( TRUE );
}
#define LIBLIST_WIDTH_KEY wxT("Liblist_width")
#define CMPLIST_WIDTH_KEY wxT("Cmplist_width")
/**
* Load library viewer frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get loaded.
*/
void WinEDA_ViewlibFrame::LoadSettings( )
{
wxConfig* cfg ;
WinEDA_DrawFrame::LoadSettings();
wxConfigPathChanger cpc( wxGetApp().m_EDA_Config, m_ConfigPath );
cfg = wxGetApp().m_EDA_Config;
m_LibListSize.x = 150; // default width of libs list
m_CmpListSize.x = 150; // default width of component list
cfg->Read( LIBLIST_WIDTH_KEY, &m_LibListSize.x );
cfg->Read( CMPLIST_WIDTH_KEY, &m_CmpListSize.x );
// set parameters to a resonnable value
if ( m_LibListSize.x > m_FrameSize.x/2 )
m_LibListSize.x = m_FrameSize.x/2;
if ( m_CmpListSize.x > m_FrameSize.x/2 )
m_CmpListSize.x = m_FrameSize.x/2;
}
/**
* Save library viewer frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get saved.
*/
void WinEDA_ViewlibFrame::SaveSettings()
{
wxConfig* cfg;
WinEDA_DrawFrame::SaveSettings();
wxConfigPathChanger cpc( wxGetApp().m_EDA_Config, m_ConfigPath );
cfg = wxGetApp().m_EDA_Config;
if ( m_LibListSize.x )
cfg->Write( LIBLIST_WIDTH_KEY, m_LibListSize.x );
cfg->Write( CMPLIST_WIDTH_KEY, m_CmpListSize.x );
}
......@@ -392,8 +392,8 @@ enum main_id {
ID_LIBVIEW_SELECT_PART_NUMBER,
ID_LIBVIEW_LIB_LIST,
ID_LIBVIEW_CMP_LIST,
ID_LIBVIEW_UNUSED0,
ID_LIBVIEW_UNUSED1,
ID_LIBVIEW_LIBWINDOW,
ID_LIBVIEW_CMPWINDOW,
ID_LIBVIEW_UNUSED3,
ID_LIBVIEW_UNUSED4,
ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC, // Used in Htoolbar, specific function
......
......@@ -495,17 +495,27 @@ protected:
};
/************************************************************************************************/
/************************************************************************************************/
class LibraryStruct;
class WinEDA_ViewlibFrame : public WinEDA_DrawFrame
{
public:
private:
WinEDAChoiceBox* SelpartBox;
wxListBox* m_LibList;
wxSize m_LibListSize;
wxListBox* m_CmpList;
wxSize m_CmpListSize;
// List of libraries (for selection
wxSashLayoutWindow* m_LibListWindow; // The redimensionnable window to display the lib list
wxListBox* m_LibList; // The list of libs
wxSize m_LibListSize; // size of the window
// List of components in the selected library
wxSashLayoutWindow* m_CmpListWindow; // The redimensionnable window to display the component list
wxListBox* m_CmpList; // The list of components
wxSize m_CmpListSize; // size of the window
// Flags
wxSemaphore* m_Semaphore; // != NULL if the frame must emulate a modal dialog
wxString m_ConfigPath; // subpath for configuartion
public:
WinEDA_ViewlibFrame( wxWindow* father,
......@@ -515,6 +525,7 @@ public:
~WinEDA_ViewlibFrame();
void OnSize( wxSizeEvent& event );
void OnSashDrag( wxSashEvent& event );
void ReCreateListLib();
void ReCreateListCmp();
void Process_Special_Functions( wxCommandEvent& event );
......@@ -532,6 +543,9 @@ public:
void GeneralControle( wxDC* DC, wxPoint MousePositionInPixels );
void LoadSettings();
void SaveSettings();
private:
void SelectCurrentLibrary();
void SelectAndViewLibraryPart( int option );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment