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.

94 lines
3.2 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef KIWAY_EXPRESS_H_
  25. #define KIWAY_EXPRESS_H_
  26. // @see http://wiki.wxwidgets.org/Custom_Events_Tutorial
  27. #include <frame_type.h>
  28. #include <mail_type.h>
  29. #include <kicommon.h>
  30. #include <wx/string.h>
  31. #include <wx/event.h>
  32. /**
  33. * Carry a payload from one #KIWAY_PLAYER to another within a #PROJECT.
  34. */
  35. class KICOMMON_API KIWAY_EXPRESS : public wxEvent
  36. {
  37. public:
  38. /**
  39. * Return the destination player id of the message.
  40. */
  41. FRAME_T Dest() { return m_destination; }
  42. /**
  43. * Returns the #MAIL_T associated with this mail.
  44. */
  45. MAIL_T Command()
  46. {
  47. return (MAIL_T) GetId(); // re-purposed control id.
  48. }
  49. /**
  50. * Return the payload, which can be any text but it typically self identifying s-expression.
  51. */
  52. std::string& GetPayload() { return m_payload; }
  53. void SetPayload( const std::string& aPayload ) { m_payload = aPayload; }
  54. KIWAY_EXPRESS* Clone() const override { return new KIWAY_EXPRESS( *this ); }
  55. //KIWAY_EXPRESS() {}
  56. KIWAY_EXPRESS( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
  57. wxWindow* aSource = nullptr );
  58. KIWAY_EXPRESS( const KIWAY_EXPRESS& anOther );
  59. /// The wxEventType argument to wxEvent() and identifies an event class
  60. /// in a hurry. These wxEventTypes also allow a common class to be used
  61. /// multiple ways. Should be allocated at startup by wxNewEventType();
  62. static const wxEventType wxEVENT_ID;
  63. //DECLARE_DYNAMIC_CLASS( KIWAY_EXPRESS )
  64. private:
  65. FRAME_T m_destination; ///< could have been a bitmap indicating multiple recipients.
  66. std::string& m_payload; ///< very often s-expression text, but not always.
  67. // possible new ideas here.
  68. };
  69. typedef void ( wxEvtHandler::*kiwayExpressFunction )( KIWAY_EXPRESS& );
  70. /// Typecast an event handler for the KIWAY_EXPRESS event class
  71. #define kiwayExpressHandler( func ) wxEVENT_HANDLER_CAST( kiwayExpressFunction, func )
  72. /// Event table definition for the KIWAY_EXPRESS event class
  73. #define EVT_KIWAY_EXPRESS( func ) \
  74. wx__DECLARE_EVT0( KIWAY_EXPRESS::wxEVENT_ID, kiwayExpressHandler( func ) )
  75. #endif // KIWAY_EXPRESS_H_