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.

100 lines
2.9 KiB

  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. #pragma once
  24. #include <map>
  25. #include <wx/event.h>
  26. #include <wx/window.h>
  27. class wxListBox;
  28. // Declare LISTBOX_TRICKS events
  29. wxDECLARE_EVENT( EDA_EVT_LISTBOX_COPY, wxCommandEvent );
  30. wxDECLARE_EVENT( EDA_EVT_LISTBOX_CUT, wxCommandEvent );
  31. wxDECLARE_EVENT( EDA_EVT_LISTBOX_PASTE, wxCommandEvent );
  32. wxDECLARE_EVENT( EDA_EVT_LISTBOX_DELETE, wxCommandEvent );
  33. wxDECLARE_EVENT( EDA_EVT_LISTBOX_DUPLICATE, wxCommandEvent );
  34. // The event when the tricks change something
  35. wxDECLARE_EVENT( EDA_EVT_LISTBOX_CHANGED, wxCommandEvent );
  36. class LISTBOX_TRICKS : public wxEvtHandler
  37. {
  38. public:
  39. LISTBOX_TRICKS( wxWindow& aWindow, wxListBox& aListBox );
  40. ~LISTBOX_TRICKS();
  41. /**
  42. * These are the ids for the menu.
  43. */
  44. enum MENU_ID
  45. {
  46. ID_COPY = wxID_HIGHEST + 1,
  47. ID_CUT,
  48. ID_PASTE,
  49. ID_DELETE,
  50. ID_DUPLICATE,
  51. };
  52. void SetMenuLabels( const std::map<MENU_ID, wxString>& aItems );
  53. private:
  54. // Custom event handlers
  55. void OnListBoxCopy( wxCommandEvent& aEvent );
  56. void OnListBoxCut( wxCommandEvent& aEvent );
  57. void OnListBoxPaste( wxCommandEvent& aEvent );
  58. void OnListBoxDelete( wxCommandEvent& aEvent );
  59. void OnListBoxDuplicate( wxCommandEvent& aEvent );
  60. // UI event handlers
  61. void OnListBoxRDown( wxMouseEvent& aEvent );
  62. void OnListBoxKeyDown( wxKeyEvent& aEvent );
  63. // Internals
  64. void listBoxCopy();
  65. void listBoxCut();
  66. void listBoxPaste();
  67. wxArrayString listBoxGetSelected() const;
  68. /**
  69. * Delete the selected filters.
  70. *
  71. * Returns the indexes of the deleted filters (which won't be valid anymore).
  72. */
  73. wxArrayInt listBoxDeleteSelected();
  74. /**
  75. * Duplicate the selected filters.
  76. */
  77. void listBoxDuplicateSelected();
  78. std::map<MENU_ID, wxString> m_menuStrings;
  79. wxWindow& m_parent;
  80. wxListBox& m_listBox;
  81. };