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.

221 lines
7.2 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. /* Forward declarations of all top-level window classes. */
  28. class CVPCB_MAINFRAME;
  29. class COMPONENT;
  30. class FOOTPRINT_LIST;
  31. #define LISTBOX_STYLE ( wxBORDER_NONE | wxLC_NO_HEADER | wxLC_REPORT | wxLC_VIRTUAL | \
  32. wxVSCROLL | wxHSCROLL )
  33. class ITEMS_LISTBOX_BASE : public wxListView
  34. {
  35. public:
  36. ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
  37. const wxPoint& aLocation = wxDefaultPosition,
  38. const wxSize& aSize = wxDefaultSize, long aStyle = 0 );
  39. ~ITEMS_LISTBOX_BASE();
  40. /**
  41. * @return the index of the selected item in lists allowing only one item selected
  42. * and the index of the first selected item in lists allowing many selection
  43. */
  44. int GetSelection();
  45. /**
  46. * Removes all selection in lists which can have more than one item selected
  47. */
  48. void DeselectAll();
  49. virtual CVPCB_MAINFRAME* GetParent() const;
  50. /**
  51. * Update the width of the column based on its contents.
  52. *
  53. * @param aLine is the line to calculate the width from. If positive, the
  54. * width will only be increased if needed. If negative, we start from
  55. * scratch and all lines are considered, i.e., the column may be shrunk.
  56. */
  57. void UpdateWidth( int aLine = -1 );
  58. private:
  59. void UpdateLineWidth( unsigned aLine );
  60. int columnWidth;
  61. };
  62. class FOOTPRINTS_LISTBOX : public ITEMS_LISTBOX_BASE
  63. {
  64. public:
  65. /**
  66. * Filter setting constants. The filter type is a bitwise OR of these flags,
  67. * and only footprints matching all selected filter types are shown.
  68. */
  69. enum FP_FILTER_T: int
  70. {
  71. UNFILTERED_FP_LIST = 0,
  72. FILTERING_BY_COMPONENT_FP_FILTERS = 0x0001,
  73. FILTERING_BY_PIN_COUNT = 0x0002,
  74. FILTERING_BY_LIBRARY = 0x0004
  75. };
  76. FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
  77. ~FOOTPRINTS_LISTBOX();
  78. int GetCount();
  79. void SetSelection( int index, bool State = true );
  80. void SetSelectedFootprint( const LIB_ID& aFPID );
  81. void SetString( unsigned linecount, const wxString& text );
  82. void AppendLine( const wxString& text );
  83. /**
  84. * Populate the wxListCtrl with the footprints from \a aList that meet the filter
  85. * criteria defined by \a aFilterType.
  86. *
  87. * @param aList is a #FOOTPRINT_LIST item containing the footprints.
  88. * @param aLibName is wxString containing the name of the selected library. Can be
  89. * wxEmptyString.
  90. * @param aComponent is the #COMPONENT used by the filtering criteria. Can be NULL.
  91. * @param aFootPrintFilterPattern is the filter used to filter list by names.
  92. * @param aFilterType defines the criteria to filter \a aList.
  93. */
  94. void SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName, COMPONENT* aComponent,
  95. const wxString &aFootPrintFilterPattern, int aFilterType );
  96. wxString GetSelectedFootprint();
  97. /**
  98. * This overloaded function MUST be provided for the wxLC_VIRTUAL mode
  99. * because real data is not handled by ITEMS_LISTBOX_BASE.
  100. */
  101. wxString OnGetItemText( long item, long column ) const override;
  102. // Events functions:
  103. void OnLeftClick( wxListEvent& event );
  104. void OnLeftDClick( wxListEvent& event );
  105. void OnChar( wxKeyEvent& event );
  106. DECLARE_EVENT_TABLE();
  107. private:
  108. wxArrayString m_footprintList;
  109. };
  110. class LIBRARY_LISTBOX : public ITEMS_LISTBOX_BASE
  111. {
  112. public:
  113. LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
  114. ~LIBRARY_LISTBOX();
  115. int GetCount();
  116. void SetSelection( int index, bool State = true );
  117. void SetString( unsigned linecount, const wxString& text );
  118. void AppendLine( const wxString& text );
  119. void SetLibraryList( const wxArrayString& aList );
  120. wxString GetSelectedLibrary();
  121. wxString OnGetItemText( long item, long column ) const override;
  122. // Events functions:
  123. void OnLeftClick( wxListEvent& event );
  124. void OnSelectLibrary( wxListEvent& event );
  125. /**
  126. * Called on a key press.
  127. *
  128. * Call default handler for some special keys, and for "ascii" keys, select the first
  129. * footprint that the name starts by the letter.
  130. *
  131. * This is the default behavior of a listbox, but because we use virtual lists, the
  132. * listbox does not know anything to what is displayed, we must handle this behavior
  133. * here. Furthermore the footprint name is not at the beginning of displayed lines
  134. * (the first word is the line number).
  135. */
  136. void OnChar( wxKeyEvent& event );
  137. DECLARE_EVENT_TABLE();
  138. private:
  139. wxArrayString m_libraryList;
  140. };
  141. class COMPONENTS_LISTBOX : public ITEMS_LISTBOX_BASE
  142. {
  143. public:
  144. COMPONENTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
  145. ~COMPONENTS_LISTBOX();
  146. void Clear();
  147. int GetCount();
  148. /**
  149. * This overloaded function MUST be provided for the wxLC_VIRTUAL mode
  150. * because real data is not handled by #ITEMS_LISTBOX_BASE.
  151. */
  152. wxString OnGetItemText( long item, long column ) const override;
  153. /*
  154. * Enable or disable an item
  155. */
  156. void SetSelection( int index, bool State = true );
  157. void SetString( unsigned linecount, const wxString& text );
  158. void AppendLine( const wxString& text );
  159. // Events functions:
  160. /**
  161. * Called on a key press.
  162. *
  163. * Call default handler for some special keys, and for "ascii" keys, select the first
  164. * component that the name starts by the letter.
  165. *
  166. * This is the default behavior of a listbox, but because we use virtual lists, the
  167. * listbox does not know anything to what is displayed, we must handle this behavior
  168. * here. Furthermore the reference of components is not at the beginning of displayed
  169. * lines (the first word is the line number).
  170. */
  171. void OnChar( wxKeyEvent& event );
  172. void OnSelectComponent( wxListEvent& event );
  173. DECLARE_EVENT_TABLE();
  174. public:
  175. wxArrayString m_ComponentList;
  176. };
  177. #endif //#ifndef LISTBOXES_H