You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
7.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef LISTBOXES_H
  24. #define LISTBOXES_H
  25. #include <wx/listctrl.h>
  26. #include <footprint_filter.h>
  27. #include <memory>
  28. /* Forward declarations of all top-level window classes. */
  29. class CVPCB_MAINFRAME;
  30. class COMPONENT;
  31. class FOOTPRINT_LIST;
  32. #define LISTBOX_STYLE ( wxBORDER_NONE | wxLC_NO_HEADER | wxLC_REPORT | wxLC_VIRTUAL | \
  33. wxVSCROLL | wxHSCROLL )
  34. /**
  35. * Base class to display symbol and footprint lists.
  36. */
  37. class ITEMS_LISTBOX_BASE : public wxListView
  38. {
  39. public:
  40. ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
  41. const wxPoint& aLocation = wxDefaultPosition,
  42. const wxSize& aSize = wxDefaultSize, long aStyle = 0 );
  43. ~ITEMS_LISTBOX_BASE();
  44. /**
  45. * @return the index of the selected item in lists allowing only one item selected
  46. * and the index of the first selected item in lists allowing many selection
  47. */
  48. int GetSelection();
  49. /**
  50. * Remove all selection in lists which can have more than one item selected.
  51. */
  52. void DeselectAll();
  53. virtual CVPCB_MAINFRAME* GetParent() const;
  54. /**
  55. * Update the width of the column based on its contents.
  56. *
  57. * @param aLine is the line to calculate the width from. If positive, the
  58. * width will only be increased if needed. If negative, we start from
  59. * scratch and all lines are considered, i.e., the column may be shrunk.
  60. */
  61. void UpdateWidth( int aLine = -1 );
  62. private:
  63. /**
  64. * Calculate the width of the given line, and increase the column width
  65. * if needed. This is effectively the wxListCtrl code for autosizing.
  66. * NB. it relies on the caller checking the given line number is valid.
  67. */
  68. void UpdateLineWidth( unsigned aLine, wxClientDC& dc );
  69. int columnWidth;
  70. };
  71. class FOOTPRINTS_LISTBOX : public ITEMS_LISTBOX_BASE
  72. {
  73. public:
  74. /**
  75. * Filter setting constants. The filter type is a bitwise OR of these flags,
  76. * and only footprints matching all selected filter types are shown.
  77. */
  78. enum FP_FILTER_T: int
  79. {
  80. UNFILTERED_FP_LIST = 0,
  81. FILTERING_BY_COMPONENT_FP_FILTERS = 0x0001,
  82. FILTERING_BY_PIN_COUNT = 0x0002,
  83. FILTERING_BY_LIBRARY = 0x0004
  84. };
  85. FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
  86. ~FOOTPRINTS_LISTBOX();
  87. int GetCount();
  88. void SetSelection( int aIndex, bool aState = true );
  89. void SetSelectedFootprint( const LIB_ID& aFPID );
  90. void SetString( unsigned linecount, const wxString& text );
  91. void AppendLine( const wxString& text );
  92. /**
  93. * Populate the wxListCtrl with the footprints from \a aList that meet the filter
  94. * criteria defined by \a aFilterType.
  95. *
  96. * @param aList is a #FOOTPRINT_LIST item containing the footprints.
  97. * @param aLibName is wxString containing the name of the selected library. Can be
  98. * wxEmptyString.
  99. * @param aComponent is the #COMPONENT used by the filtering criteria. Can be NULL.
  100. * @param aFootPrintFilterPattern is the filter used to filter list by names.
  101. * @param aFilterType defines the criteria to filter \a aList.
  102. */
  103. void SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName, COMPONENT* aComponent,
  104. const wxString& aFootPrintFilterPattern, int aFilterType );
  105. wxString GetSelectedFootprint();
  106. /**
  107. * This overloaded function MUST be provided for the wxLC_VIRTUAL mode
  108. * because real data is not handled by ITEMS_LISTBOX_BASE.
  109. */
  110. wxString OnGetItemText( long item, long column ) const override;
  111. // Events functions:
  112. void OnLeftClick( wxListEvent& event );
  113. void OnLeftDClick( wxListEvent& event );
  114. void OnChar( wxKeyEvent& event );
  115. DECLARE_EVENT_TABLE();
  116. private:
  117. wxArrayString m_footprintList;
  118. };
  119. class LIBRARY_LISTBOX : public ITEMS_LISTBOX_BASE
  120. {
  121. public:
  122. LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
  123. ~LIBRARY_LISTBOX();
  124. int GetCount();
  125. void SetSelection( int index, bool State = true );
  126. void SetString( unsigned linecount, const wxString& text );
  127. void AppendLine( const wxString& text );
  128. void Finish();
  129. void ClearList();
  130. wxString GetSelectedLibrary();
  131. wxString OnGetItemText( long item, long column ) const override;
  132. void OnSelectLibrary( wxListEvent& event );
  133. /**
  134. * Called on a key press.
  135. *
  136. * Call default handler for some special keys, and for "ASCII" keys, select the first
  137. * footprint that the name starts by the letter.
  138. *
  139. * This is the default behavior of a listbox, but because we use virtual lists, the
  140. * listbox does not know anything to what is displayed, we must handle this behavior
  141. * here. Furthermore the footprint name is not at the beginning of displayed lines
  142. * (the first word is the line number).
  143. */
  144. void OnChar( wxKeyEvent& event );
  145. DECLARE_EVENT_TABLE();
  146. private:
  147. wxArrayString m_libraryList;
  148. };
  149. class SYMBOLS_LISTBOX : public ITEMS_LISTBOX_BASE
  150. {
  151. public:
  152. SYMBOLS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
  153. ~SYMBOLS_LISTBOX();
  154. void Clear();
  155. int GetCount();
  156. /**
  157. * This overloaded function MUST be provided for the wxLC_VIRTUAL mode
  158. * because real data is not handled by #ITEMS_LISTBOX_BASE.
  159. */
  160. wxString OnGetItemText( long item, long column ) const override;
  161. wxListItemAttr* OnGetItemAttr( long item) const override;
  162. /*
  163. * Enable or disable an item
  164. */
  165. void SetSelection( int index, bool State = true );
  166. void SetString( unsigned linecount, const wxString& text );
  167. void AppendLine( const wxString& text );
  168. void AppendWarning( int index );
  169. void RemoveWarning( int index );
  170. // Events functions:
  171. /**
  172. * Called on a key press.
  173. *
  174. * Call default handler for some special keys, and for "ASCII" keys, select the first
  175. * component that the name starts by the letter.
  176. *
  177. * This is the default behavior of a listbox, but because we use virtual lists, the
  178. * listbox does not know anything to what is displayed, we must handle this behavior
  179. * here. Furthermore the reference of components is not at the beginning of displayed
  180. * lines (the first word is the line number).
  181. */
  182. void OnChar( wxKeyEvent& event );
  183. void OnSelectComponent( wxListEvent& event );
  184. DECLARE_EVENT_TABLE();
  185. public:
  186. wxArrayString m_SymbolList;
  187. private:
  188. std::vector<long> m_symbolWarning;
  189. std::unique_ptr<wxListItemAttr> m_warningAttr;
  190. };
  191. #endif //#ifndef LISTBOXES_H