// events.h - Events subroutines. // // (c) 2012-2015 Xestia Software Development. // // This file is part of Xestia Address Book. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see #include #include #include "../vcard/vcard.h" #include "../frmMain.h" #ifndef EVENTS_H #define EVENTS_H /* // Could have been DECLARE_EVENT_TYPE( MyFooCommandEvent, -1 ) // Not needed if you only use the event-type in one .cpp file DECLARE_EVENT_TYPE(ContactConflictCmdEnv, 7000); // A custom event that transports a whole wxString. class ContactConflictEvent: public wxCommandEvent { public: ContactConflictEvent( wxEventType commandType = ContactConflictCmdEnv, int id = 0 ) : wxCommandEvent(commandType, id) { } // You *must* copy here the data to be transported ContactConflictEvent( const ContactConflictEvent &event ) : wxCommandEvent(event) { this->SetData( event.GetText(), event.GetLocalData(), event.GetServerData() ); } // Required for sending with wxPostEvent() wxEvent* Clone() const { return new ContactConflictEvent(*this); } wxString GetText() const { return Filename; } vCard GetLocalData() const { return LocalData; } vCard GetServerData() const { return ServerData; } void SetData( const wxString& text, vCard LocalDataInc, vCard ServerDataInc ) { Filename = text; LocalData = LocalDataInc; ServerData = ServerDataInc; } private: wxString Filename; vCard LocalData; vCard ServerData; }; typedef void (wxEvtHandler::*ContactConflictEventFunction)(ContactConflictEvent &); // This #define simplifies the one below, and makes the syntax less // ugly if you want to use Connect() instead of an event table. #define ContactConflictEventHandler(func) \ (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)\\ wxStaticCastEvent(ContactConflictEventFunction, &func) // Define the event table entry. Yes, it really *does* end in a comma. #define EVT_CONTACTCONFLICT(id, fn) \ DECLARE_EVENT_TABLE_ENTRY( ContactConflictCmdEnv, id, wxID_ANY, \\ (wxObjectEventFunction)(wxEventFunction) \\ (wxCommandEventFunction) wxStaticCastEvent( \\ ContactConflictEventFunction, &fn ), (wxObject*) NULL ), // Optionally, you can do a similar #define for EVT_MYFOO_RANGE. #define EVT_CONTACTCONFLICT_RANGE(id1,id2, fn) \ DECLARE_EVENT_TABLE_ENTRY( ContactConflictCmdEnv, id1, id2, \\ ContactConflictEventHandler(fn), (wxObject*) NULL ), // If you want to use the custom event to send more than one sort // of data, or to more than one place, make it easier by providing // named IDs in an enumeration. enum { Foo_DoFirstThing = 1, Foo_DoSecondThing, Foo_DoThirdThing }; */ #endif