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.

240 lines
8.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2018 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. /*********************************************************************/
  34. /* ListBox (base class) to display lists of components or footprints */
  35. /*********************************************************************/
  36. class ITEMS_LISTBOX_BASE : public wxListView
  37. {
  38. public:
  39. ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
  40. const wxPoint& aLocation = wxDefaultPosition,
  41. const wxSize& aSize = wxDefaultSize, long aStyle = 0 );
  42. ~ITEMS_LISTBOX_BASE();
  43. /**
  44. * @return the index of the selected item in lists allowing only one item selected
  45. * and the index of the first selected item in lists allowing many selection
  46. */
  47. int GetSelection();
  48. /**
  49. * Removes all selection in lists which can have more than one item selected
  50. */
  51. void DeselectAll();
  52. virtual CVPCB_MAINFRAME* GetParent() const;
  53. /* Function UpdateWidth
  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. void UpdateLineWidth( unsigned aLine );
  64. int columnWidth;
  65. };
  66. /******************************************/
  67. /* ListBox showing the list of footprints */
  68. /******************************************/
  69. class FOOTPRINTS_LISTBOX : public ITEMS_LISTBOX_BASE
  70. {
  71. private:
  72. wxArrayString m_footprintList;
  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 index, bool State = true );
  89. void SetSelectedFootprint( const LIB_ID& aFPID );
  90. void SetString( unsigned linecount, const wxString& text );
  91. void AppendLine( const wxString& text );
  92. /**
  93. * Function SetFootprints
  94. * populates the wxListCtrl with the footprints from \a aList that meet the filter
  95. * criteria defined by \a aFilterType.
  96. *
  97. * @param aList is a #FOOTPRINT_LIST item containing the footprints.
  98. * @param aLibName is wxString containing the name of the selected library. Can be
  99. * wxEmptyString.
  100. * @param aComponent is the #COMPONENT used by the filtering criteria. Can be NULL.
  101. * @param aFootPrintFilterPattern = a filter used to filter list by names
  102. * @param aFilterType defines the criteria to filter \a aList.
  103. */
  104. void SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName, COMPONENT* aComponent,
  105. const wxString &aFootPrintFilterPattern, int aFilterType );
  106. wxString GetSelectedFootprint();
  107. /**
  108. * Function OnGetItemText
  109. * this overloaded function MUST be provided for the wxLC_VIRTUAL mode
  110. * because real data is not handled by ITEMS_LISTBOX_BASE
  111. */
  112. wxString OnGetItemText( long item, long column ) const override;
  113. // Events functions:
  114. void OnLeftClick( wxListEvent& event );
  115. void OnLeftDClick( wxListEvent& event );
  116. void OnChar( wxKeyEvent& event );
  117. DECLARE_EVENT_TABLE()
  118. };
  119. /******************************************/
  120. /* ListBox showing the list of library */
  121. /******************************************/
  122. class LIBRARY_LISTBOX : public ITEMS_LISTBOX_BASE
  123. {
  124. wxArrayString m_libraryList;
  125. public:
  126. LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
  127. ~LIBRARY_LISTBOX();
  128. int GetCount();
  129. void SetSelection( int index, bool State = true );
  130. void SetString( unsigned linecount, const wxString& text );
  131. void AppendLine( const wxString& text );
  132. void SetLibraryList( const wxArrayString& aList );
  133. wxString GetSelectedLibrary();
  134. wxString OnGetItemText( long item, long column ) const override;
  135. // Events functions:
  136. void OnLeftClick( wxListEvent& event );
  137. void OnSelectLibrary( wxListEvent& event );
  138. /**
  139. * Function OnChar
  140. * called on a key pressed
  141. * Call default handler for some special keys,
  142. * and for "ascii" keys, select the first footprint
  143. * that the name starts by the letter.
  144. * This is the defaut behaviour of a listbox, but because we use
  145. * virtual lists, the listbox does not know anything to what is displayed,
  146. * we must handle this behaviour here.
  147. * Furthermore the footprint name is not at the beginning of
  148. * displayed lines (the first word is the line number)
  149. */
  150. void OnChar( wxKeyEvent& event );
  151. DECLARE_EVENT_TABLE()
  152. };
  153. /****************************************************/
  154. /* ListBox showing the list of schematic components */
  155. /****************************************************/
  156. class COMPONENTS_LISTBOX : public ITEMS_LISTBOX_BASE
  157. {
  158. public:
  159. wxArrayString m_ComponentList;
  160. public:
  161. COMPONENTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
  162. ~COMPONENTS_LISTBOX();
  163. void Clear();
  164. int GetCount();
  165. /**
  166. * Function OnGetItemText
  167. * this overloaded function MUST be provided for the wxLC_VIRTUAL mode
  168. * because real data is not handled by ITEMS_LISTBOX_BASE
  169. */
  170. wxString OnGetItemText( long item, long column ) const override;
  171. /*
  172. * Enable or disable an item
  173. */
  174. void SetSelection( int index, bool State = true );
  175. void SetString( unsigned linecount, const wxString& text );
  176. void AppendLine( const wxString& text );
  177. // Events functions:
  178. /**
  179. * Function OnChar
  180. * called on a key pressed
  181. * Call default handler for some special keys,
  182. * and for "ascii" keys, select the first component
  183. * that the name starts by the letter.
  184. * This is the default behavior of a listbox, but because we use
  185. * virtual lists, the listbox does not know anything to what is displayed,
  186. * we must handle this behavior here.
  187. * Furthermore the reference of components is not at the beginning of
  188. * displayed lines (the first word is the line number)
  189. */
  190. void OnChar( wxKeyEvent& event );
  191. void OnSelectComponent( wxListEvent& event );
  192. DECLARE_EVENT_TABLE()
  193. };
  194. #endif //#ifndef LISTBOXES_H