kicad/cvpcb/listboxes.h

236 lines
7.7 KiB
C
Raw Permalink Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
2021-06-08 19:39:47 +00:00
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef LISTBOXES_H
#define LISTBOXES_H
2007-05-06 16:03:28 +00:00
#include <wx/listctrl.h>
#include <footprint_filter.h>
#include <memory>
2007-05-06 16:03:28 +00:00
/* Forward declarations of all top-level window classes. */
class CVPCB_MAINFRAME;
class COMPONENT;
class FOOTPRINT_LIST;
#define LISTBOX_STYLE ( wxBORDER_NONE | wxLC_NO_HEADER | wxLC_REPORT | wxLC_VIRTUAL | \
wxVSCROLL | wxHSCROLL )
2007-05-06 16:03:28 +00:00
2021-07-16 20:13:26 +00:00
/**
* Base class to display symbol and footprint lists.
*/
class ITEMS_LISTBOX_BASE : public wxListView
2007-05-06 16:03:28 +00:00
{
public:
ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
2020-01-11 21:14:09 +00:00
const wxPoint& aLocation = wxDefaultPosition,
const wxSize& aSize = wxDefaultSize, long aStyle = 0 );
2007-05-06 16:03:28 +00:00
~ITEMS_LISTBOX_BASE();
2007-05-06 16:03:28 +00:00
/**
* @return the index of the selected item in lists allowing only one item selected
* and the index of the first selected item in lists allowing many selection
*/
2021-07-16 20:13:26 +00:00
int GetSelection();
/**
2021-07-16 20:13:26 +00:00
* Remove all selection in lists which can have more than one item selected.
*/
void DeselectAll();
virtual CVPCB_MAINFRAME* GetParent() const;
2021-06-08 19:39:47 +00:00
/**
* Update the width of the column based on its contents.
*
* @param aLine is the line to calculate the width from. If positive, the
* width will only be increased if needed. If negative, we start from
* scratch and all lines are considered, i.e., the column may be shrunk.
*/
void UpdateWidth( int aLine = -1 );
private:
2021-07-16 20:13:26 +00:00
/**
* Calculate the width of the given line, and increase the column width
* if needed. This is effectively the wxListCtrl code for autosizing.
* NB. it relies on the caller checking the given line number is valid.
*/
void UpdateLineWidth( unsigned aLine, wxClientDC& dc );
int columnWidth;
2007-05-06 16:03:28 +00:00
};
class FOOTPRINTS_LISTBOX : public ITEMS_LISTBOX_BASE
2007-05-06 16:03:28 +00:00
{
public:
/**
* Filter setting constants. The filter type is a bitwise OR of these flags,
* and only footprints matching all selected filter types are shown.
*/
enum FP_FILTER_T: int
{
UNFILTERED_FP_LIST = 0,
FILTERING_BY_COMPONENT_FP_FILTERS = 0x0001,
FILTERING_BY_PIN_COUNT = 0x0002,
FILTERING_BY_LIBRARY = 0x0004
};
2020-01-11 21:14:09 +00:00
FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
~FOOTPRINTS_LISTBOX();
int GetCount();
void SetSelection( int aIndex, bool aState = true );
void SetSelectedFootprint( const LIB_ID& aFPID );
void SetString( unsigned linecount, const wxString& text );
void AppendLine( const wxString& text );
/**
2021-06-08 19:39:47 +00:00
* Populate the wxListCtrl with the footprints from \a aList that meet the filter
* criteria defined by \a aFilterType.
*
* @param aList is a #FOOTPRINT_LIST item containing the footprints.
* @param aLibName is wxString containing the name of the selected library. Can be
* wxEmptyString.
* @param aComponent is the #COMPONENT used by the filtering criteria. Can be NULL.
2021-06-08 19:39:47 +00:00
* @param aFootPrintFilterPattern is the filter used to filter list by names.
* @param aFilterType defines the criteria to filter \a aList.
*/
2020-01-11 21:14:09 +00:00
void SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName, COMPONENT* aComponent,
const wxString& aFootPrintFilterPattern, int aFilterType );
wxString GetSelectedFootprint();
/**
2021-06-08 19:39:47 +00:00
* This overloaded function MUST be provided for the wxLC_VIRTUAL mode
* because real data is not handled by ITEMS_LISTBOX_BASE.
*/
2016-09-24 18:53:15 +00:00
wxString OnGetItemText( long item, long column ) const override;
// Events functions:
void OnLeftClick( wxListEvent& event );
void OnLeftDClick( wxListEvent& event );
void OnChar( wxKeyEvent& event );
2021-06-08 19:39:47 +00:00
DECLARE_EVENT_TABLE();
private:
wxArrayString m_footprintList;
};
class LIBRARY_LISTBOX : public ITEMS_LISTBOX_BASE
{
public:
2020-01-11 21:14:09 +00:00
LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
~LIBRARY_LISTBOX();
int GetCount();
void SetSelection( int index, bool State = true );
void SetString( unsigned linecount, const wxString& text );
void AppendLine( const wxString& text );
2022-07-10 00:15:36 +00:00
void Finish();
void ClearList();
wxString GetSelectedLibrary();
2016-09-24 18:53:15 +00:00
wxString OnGetItemText( long item, long column ) const override;
void OnSelectLibrary( wxListEvent& event );
/**
2021-06-08 19:39:47 +00:00
* Called on a key press.
*
2021-07-16 20:13:26 +00:00
* Call default handler for some special keys, and for "ASCII" keys, select the first
2021-06-08 19:39:47 +00:00
* footprint that the name starts by the letter.
*
* This is the default behavior of a listbox, but because we use virtual lists, the
* listbox does not know anything to what is displayed, we must handle this behavior
* here. Furthermore the footprint name is not at the beginning of displayed lines
* (the first word is the line number).
*/
void OnChar( wxKeyEvent& event );
2021-06-08 19:39:47 +00:00
DECLARE_EVENT_TABLE();
private:
wxArrayString m_libraryList;
2007-05-06 16:03:28 +00:00
};
2021-09-27 11:55:53 +00:00
class SYMBOLS_LISTBOX : public ITEMS_LISTBOX_BASE
2007-05-06 16:03:28 +00:00
{
public:
2021-09-27 11:55:53 +00:00
SYMBOLS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
2007-05-06 16:03:28 +00:00
2021-09-27 11:55:53 +00:00
~SYMBOLS_LISTBOX();
void Clear();
int GetCount();
/**
2021-06-08 19:39:47 +00:00
* This overloaded function MUST be provided for the wxLC_VIRTUAL mode
* because real data is not handled by #ITEMS_LISTBOX_BASE.
*/
2016-09-24 18:53:15 +00:00
wxString OnGetItemText( long item, long column ) const override;
wxListItemAttr* OnGetItemAttr( long item) const override;
/*
* Enable or disable an item
*/
void SetSelection( int index, bool State = true );
void SetString( unsigned linecount, const wxString& text );
void AppendLine( const wxString& text );
void AppendWarning( int index );
void RemoveWarning( int index );
// Events functions:
/**
2021-06-08 19:39:47 +00:00
* Called on a key press.
*
2021-07-16 20:13:26 +00:00
* Call default handler for some special keys, and for "ASCII" keys, select the first
2021-06-08 19:39:47 +00:00
* component that the name starts by the letter.
*
* This is the default behavior of a listbox, but because we use virtual lists, the
* listbox does not know anything to what is displayed, we must handle this behavior
* here. Furthermore the reference of components is not at the beginning of displayed
* lines (the first word is the line number).
*/
void OnChar( wxKeyEvent& event );
void OnSelectComponent( wxListEvent& event );
2021-06-08 19:39:47 +00:00
DECLARE_EVENT_TABLE();
public:
2021-09-27 11:55:53 +00:00
wxArrayString m_SymbolList;
private:
std::vector<long> m_symbolWarning;
std::unique_ptr<wxListItemAttr> m_warningAttr;
2007-05-06 16:03:28 +00:00
};
#endif //#ifndef LISTBOXES_H