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.

121 lines
3.4 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 listboxes.cpp
  25. * @brief Implementation of class for displaying footprint list and component lists.
  26. */
  27. #include <fctsys.h>
  28. #include <macros.h>
  29. #include <cvpcb.h>
  30. #include <cvpcb_mainframe.h>
  31. #include <listboxes.h>
  32. #include <cvpcb_id.h>
  33. /******************************************************************************
  34. * Basic class (from wxListView) to display component and footprint lists
  35. * Not directly used: the 2 list boxes actually used are derived from it
  36. ******************************************************************************/
  37. ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
  38. const wxPoint& aLocation, const wxSize& aSize,
  39. long aStyle) :
  40. wxListView( aParent, aId, aLocation, aSize, LISTBOX_STYLE | aStyle ), columnWidth(0)
  41. {
  42. InsertColumn( 0, wxEmptyString );
  43. }
  44. ITEMS_LISTBOX_BASE::~ITEMS_LISTBOX_BASE()
  45. {
  46. }
  47. void ITEMS_LISTBOX_BASE::UpdateWidth( int aLine )
  48. {
  49. // Less than zero: recalculate width of all items.
  50. if( aLine < 0 )
  51. {
  52. columnWidth = 0;
  53. for( int ii = 0; ii < GetItemCount(); ii++ )
  54. {
  55. UpdateLineWidth( (unsigned)ii );
  56. }
  57. }
  58. // Zero or above: update from a single line.
  59. else
  60. {
  61. if( aLine < GetItemCount() )
  62. UpdateLineWidth( (unsigned)aLine );
  63. }
  64. }
  65. /*
  66. * Calculate the width of the given line, and increase the column width
  67. * if needed. This is effectively the wxListCtrl code for autosizing.
  68. * NB. it relies on the caller checking the given line number is valid.
  69. */
  70. void ITEMS_LISTBOX_BASE::UpdateLineWidth( unsigned aLine )
  71. {
  72. wxClientDC dc( this );
  73. wxCoord w;
  74. int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
  75. dc.SetFont( GetFont() );
  76. dc.GetTextExtent( GetItemText( aLine, 0 ) + " ", &w, NULL );
  77. newWidth += w;
  78. if( newWidth > columnWidth )
  79. {
  80. columnWidth = newWidth;
  81. SetColumnWidth( 0, columnWidth );
  82. }
  83. }
  84. /*
  85. * Return an index for the selected item
  86. */
  87. int ITEMS_LISTBOX_BASE::GetSelection()
  88. {
  89. return GetFirstSelected();
  90. }
  91. /* Removes all selection in list
  92. */
  93. void ITEMS_LISTBOX_BASE::DeselectAll()
  94. {
  95. for( int i = 0; i < GetItemCount(); i++ )
  96. Select( i, false );
  97. }
  98. CVPCB_MAINFRAME* ITEMS_LISTBOX_BASE::GetParent() const
  99. {
  100. return (CVPCB_MAINFRAME*) wxListView::GetParent();
  101. }