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.

247 lines
8.1 KiB

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