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.

229 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-2012 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 cvstruct.h
  25. */
  26. #ifndef CVSTRUCT_H
  27. #define CVSTRUCT_H
  28. #include <wx/listctrl.h>
  29. /* Forward declarations of all top-level window classes. */
  30. class CVPCB_MAINFRAME;
  31. class COMPONENT;
  32. class FOOTPRINT_LIST;
  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, const wxSize& aSize,
  41. long aStyle = wxLC_SINGLE_SEL );
  42. ~ITEMS_LISTBOX_BASE();
  43. int GetSelection();
  44. virtual CVPCB_MAINFRAME* GetParent() const;
  45. /* Function UpdateWidth
  46. *
  47. * Update the width of the column based on its contents.
  48. *
  49. * @param aLine is the line to calculate the width from. If positive, the
  50. * width will only be increased if needed. If negative, we start from
  51. * scratch and all lines are considered, i.e., the column may be shrunk.
  52. */
  53. void UpdateWidth( int aLine = -1 );
  54. private:
  55. void UpdateLineWidth( unsigned aLine );
  56. int columnWidth;
  57. };
  58. /******************************************/
  59. /* ListBox showing the list of footprints */
  60. /******************************************/
  61. class FOOTPRINTS_LISTBOX : public ITEMS_LISTBOX_BASE
  62. {
  63. private:
  64. wxArrayString m_footprintList;
  65. public:
  66. enum FP_FILTER_T
  67. {
  68. UNFILTERED = 0,
  69. BY_COMPONENT = 0x0001,
  70. BY_PIN_COUNT = 0x0002,
  71. BY_LIBRARY = 0x0004,
  72. };
  73. FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
  74. const wxPoint& loc, const wxSize& size );
  75. ~FOOTPRINTS_LISTBOX();
  76. int GetCount();
  77. void SetSelection( int index, bool State = true );
  78. void SetString( unsigned linecount, const wxString& text );
  79. void AppendLine( const wxString& text );
  80. /**
  81. * Function SetFootprints
  82. * populates the wxListCtrl with the footprints from \a aList that meet the filter
  83. * criteria defined by \a aFilterType.
  84. *
  85. * @param aList is a #FOOTPRINT_LIST item containing the footprints.
  86. * @param aLibName is wxString containing the name of the selected library. Can be
  87. * wxEmptyString.
  88. * @param aComponent is the #COMPONENT used by the filtering criteria. Can be NULL.
  89. * @param aFilterType defines the criteria to filter \a aList.
  90. */
  91. void SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
  92. COMPONENT* aComponent, int aFilterType );
  93. wxString GetSelectedFootprint();
  94. /**
  95. * Function OnGetItemText
  96. * this overloaded function MUST be provided for the wxLC_VIRTUAL mode
  97. * because real data is not handled by ITEMS_LISTBOX_BASE
  98. */
  99. wxString OnGetItemText( long item, long column ) const;
  100. // Events functions:
  101. void OnLeftClick( wxListEvent& event );
  102. void OnLeftDClick( wxListEvent& event );
  103. void OnChar( wxKeyEvent& event );
  104. DECLARE_EVENT_TABLE()
  105. };
  106. /******************************************/
  107. /* ListBox showing the list of library */
  108. /******************************************/
  109. class LIBRARY_LISTBOX : public ITEMS_LISTBOX_BASE
  110. {
  111. wxArrayString m_libraryList;
  112. public:
  113. LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
  114. const wxPoint& loc, const wxSize& size );
  115. ~LIBRARY_LISTBOX();
  116. int GetCount();
  117. void SetSelection( int index, bool State = true );
  118. void SetString( unsigned linecount, const wxString& text );
  119. void AppendLine( const wxString& text );
  120. void SetLibraryList( const wxArrayString& aList );
  121. wxString GetSelectedLibrary();
  122. wxString OnGetItemText( long item, long column ) const;
  123. // Events functions:
  124. void OnLeftClick( wxListEvent& event );
  125. void OnSelectLibrary( wxListEvent& event );
  126. /**
  127. * Function OnChar
  128. * called on a key pressed
  129. * Call default handler for some special keys,
  130. * and for "ascii" keys, select the first footprint
  131. * that the name starts by the letter.
  132. * This is the defaut behaviour of a listbox, but because we use
  133. * virtual lists, the listbox does not know anything to what is displayed,
  134. * we must handle this behaviour here.
  135. * Furthermore the footprint name is not at the beginning of
  136. * displayed lines (the first word is the line number)
  137. */
  138. void OnChar( wxKeyEvent& event );
  139. DECLARE_EVENT_TABLE()
  140. };
  141. /****************************************************/
  142. /* ListBox showing the list of schematic components */
  143. /****************************************************/
  144. class COMPONENTS_LISTBOX : public ITEMS_LISTBOX_BASE
  145. {
  146. public:
  147. wxArrayString m_ComponentList;
  148. public:
  149. COMPONENTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
  150. const wxPoint& loc, const wxSize& size );
  151. ~COMPONENTS_LISTBOX();
  152. void Clear();
  153. int GetCount();
  154. /**
  155. * Function OnGetItemText
  156. * this overloaded function MUST be provided for the wxLC_VIRTUAL mode
  157. * because real data is not handled by ITEMS_LISTBOX_BASE
  158. */
  159. wxString OnGetItemText( long item, long column ) const;
  160. /*
  161. * Enable or disable an item
  162. */
  163. void SetSelection( int index, bool State = true );
  164. void SetString( unsigned linecount, const wxString& text );
  165. void AppendLine( const wxString& text );
  166. // Events functions:
  167. /**
  168. * Function OnChar
  169. * called on a key pressed
  170. * Call default handler for some special keys,
  171. * and for "ascii" keys, select the first component
  172. * that the name starts by the letter.
  173. * This is the default behavior of a listbox, but because we use
  174. * virtual lists, the listbox does not know anything to what is displayed,
  175. * we must handle this behavior here.
  176. * Furthermore the reference of components is not at the beginning of
  177. * displayed lines (the first word is the line number)
  178. */
  179. void OnChar( wxKeyEvent& event );
  180. void OnSelectComponent( wxListEvent& event );
  181. DECLARE_EVENT_TABLE()
  182. };
  183. #endif //#ifndef CVSTRUCT_H