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.

116 lines
3.0 KiB

3 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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 listbox_base.cpp
  25. * @brief Implementation of class for displaying footprint and symbol lists.
  26. */
  27. #include <cvpcb_mainframe.h>
  28. #include <listboxes.h>
  29. #include <wx/dcclient.h>
  30. ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
  31. const wxPoint& aLocation, const wxSize& aSize,
  32. long aStyle ) :
  33. wxListView( aParent, aId, aLocation, aSize, LISTBOX_STYLE | aStyle ),
  34. columnWidth( 0 )
  35. {
  36. InsertColumn( 0, wxEmptyString );
  37. }
  38. ITEMS_LISTBOX_BASE::~ITEMS_LISTBOX_BASE()
  39. {
  40. }
  41. void ITEMS_LISTBOX_BASE::UpdateWidth( int aLine )
  42. {
  43. wxClientDC dc( this );
  44. int itemCount = GetItemCount();
  45. // Less than zero: recalculate width of all items.
  46. if( aLine < 0 )
  47. {
  48. columnWidth = 0;
  49. for( int ii = 0; ii < itemCount; ii++ )
  50. {
  51. UpdateLineWidth( (unsigned)ii, dc );
  52. }
  53. }
  54. // Zero or above: update from a single line.
  55. else
  56. {
  57. if( aLine < itemCount )
  58. UpdateLineWidth( (unsigned)aLine, dc );
  59. }
  60. }
  61. void ITEMS_LISTBOX_BASE::UpdateLineWidth( unsigned aLine, wxClientDC& dc )
  62. {
  63. wxCoord w;
  64. int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
  65. wxString str;
  66. dc.SetFont( GetFont() );
  67. if( IsVirtual() )
  68. str = OnGetItemText( aLine, 0 );
  69. else
  70. str = GetItemText( aLine, 0 );
  71. str += wxS( " " );
  72. dc.GetTextExtent( str, &w, nullptr );
  73. newWidth += w;
  74. if( newWidth > columnWidth )
  75. {
  76. columnWidth = newWidth;
  77. SetColumnWidth( 0, columnWidth );
  78. }
  79. }
  80. int ITEMS_LISTBOX_BASE::GetSelection()
  81. {
  82. return GetFirstSelected();
  83. }
  84. void ITEMS_LISTBOX_BASE::DeselectAll()
  85. {
  86. for( int i = GetFirstSelected(); i >= 0; i = GetNextSelected( i ) )
  87. {
  88. Select( i, false );
  89. }
  90. }
  91. CVPCB_MAINFRAME* ITEMS_LISTBOX_BASE::GetParent() const
  92. {
  93. return (CVPCB_MAINFRAME*) wxListView::GetParent();
  94. }