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.

89 lines
3.0 KiB

4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 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. class wxGrid;
  29. class PCB_LAYER_BOX_SELECTOR;
  30. //-------- Custom wxGridCellRenderers --------------------------------------------------
  31. class GRID_CELL_LAYER_RENDERER : public wxGridCellStringRenderer
  32. {
  33. public:
  34. GRID_CELL_LAYER_RENDERER( PCB_BASE_FRAME* aFrame );
  35. ~GRID_CELL_LAYER_RENDERER() override;
  36. void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
  37. const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
  38. private:
  39. PCB_BASE_FRAME* m_frame;
  40. };
  41. //-------- Custom wxGridCellEditors ----------------------------------------------------
  42. //
  43. // Note: this implementation is an adaptation of wxGridCellChoiceEditor
  44. class GRID_CELL_LAYER_SELECTOR : public wxGridCellEditor
  45. {
  46. public:
  47. GRID_CELL_LAYER_SELECTOR( PCB_BASE_FRAME* aFrame, LSET forbiddenLayers );
  48. wxGridCellEditor* Clone() const override;
  49. void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
  50. wxString GetValue() const override;
  51. void SetSize( const wxRect& aRect ) override;
  52. void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
  53. bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *newval ) override;
  54. void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
  55. void Reset() override;
  56. protected:
  57. // Event handlers to properly dismiss the layer selector when it loses focus
  58. void onComboDropDown( wxCommandEvent& aEvent );
  59. void onComboCloseUp( wxCommandEvent& aEvent );
  60. PCB_LAYER_BOX_SELECTOR* LayerBox() const
  61. {
  62. return static_cast<PCB_LAYER_BOX_SELECTOR*>( m_control );
  63. }
  64. PCB_BASE_FRAME* m_frame;
  65. LSET m_mask;
  66. int m_value;
  67. wxDECLARE_NO_COPY_CLASS( GRID_CELL_LAYER_SELECTOR );
  68. };
  69. #endif // GRID_LAYER_BOX_HELPERS_H