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.

92 lines
3.1 KiB

9 months ago
4 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. #ifndef GRID_LAYER_BOX_HELPERS_H
  24. #define GRID_LAYER_BOX_HELPERS_H
  25. #include <wx/generic/gridctrl.h>
  26. #include <wx/generic/grideditors.h>
  27. #include "pcb_layer_box_selector.h"
  28. #include <lset.h>
  29. class wxGrid;
  30. class PCB_LAYER_BOX_SELECTOR;
  31. //-------- Custom wxGridCellRenderers --------------------------------------------------
  32. class GRID_CELL_LAYER_RENDERER : public wxGridCellStringRenderer
  33. {
  34. public:
  35. GRID_CELL_LAYER_RENDERER( PCB_BASE_FRAME* aFrame );
  36. ~GRID_CELL_LAYER_RENDERER() override;
  37. void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
  38. const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
  39. private:
  40. PCB_BASE_FRAME* m_frame;
  41. };
  42. //-------- Custom wxGridCellEditors ----------------------------------------------------
  43. //
  44. // Note: this implementation is an adaptation of wxGridCellChoiceEditor
  45. class GRID_CELL_LAYER_SELECTOR : public wxGridCellEditor
  46. {
  47. public:
  48. GRID_CELL_LAYER_SELECTOR( PCB_BASE_FRAME* aFrame, const LSET& forbiddenLayers,
  49. bool aShowNonActivated = false );
  50. wxGridCellEditor* Clone() const override;
  51. void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
  52. wxString GetValue() const override;
  53. void SetSize( const wxRect& aRect ) override;
  54. void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
  55. bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *newval ) override;
  56. void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
  57. void Reset() override;
  58. protected:
  59. // Event handlers to properly dismiss the layer selector when it loses focus
  60. void onComboDropDown( wxCommandEvent& aEvent );
  61. void onComboCloseUp( wxCommandEvent& aEvent );
  62. PCB_LAYER_BOX_SELECTOR* LayerBox() const
  63. {
  64. return static_cast<PCB_LAYER_BOX_SELECTOR*>( m_control );
  65. }
  66. PCB_BASE_FRAME* m_frame;
  67. LSET m_mask;
  68. bool m_showNonActivated;
  69. int m_value;
  70. wxDECLARE_NO_COPY_CLASS( GRID_CELL_LAYER_SELECTOR );
  71. };
  72. #endif // GRID_LAYER_BOX_HELPERS_H