1 // events.h - Events subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book 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.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
21 #include "../vcard/vcard.h"
22 #include "../frmMain.h"
29 // Could have been DECLARE_EVENT_TYPE( MyFooCommandEvent, -1 )
30 // Not needed if you only use the event-type in one .cpp file
31 DECLARE_EVENT_TYPE(ContactConflictCmdEnv, 7000);
33 // A custom event that transports a whole wxString.
34 class ContactConflictEvent: public wxCommandEvent
37 ContactConflictEvent( wxEventType commandType = ContactConflictCmdEnv, int id = 0 )
38 : wxCommandEvent(commandType, id) { }
40 // You *must* copy here the data to be transported
41 ContactConflictEvent( const ContactConflictEvent &event )
42 : wxCommandEvent(event) { this->SetData( event.GetText(), event.GetLocalData(), event.GetServerData() ); }
44 // Required for sending with wxPostEvent()
45 wxEvent* Clone() const { return new ContactConflictEvent(*this); }
47 wxString GetText() const { return Filename; }
48 vCard GetLocalData() const { return LocalData; }
49 vCard GetServerData() const { return ServerData; }
50 void SetData( const wxString& text, vCard LocalDataInc, vCard ServerDataInc ) {
52 LocalData = LocalDataInc;
53 ServerData = ServerDataInc;
62 typedef void (wxEvtHandler::*ContactConflictEventFunction)(ContactConflictEvent &);
64 // This #define simplifies the one below, and makes the syntax less
65 // ugly if you want to use Connect() instead of an event table.
66 #define ContactConflictEventHandler(func) \
67 (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)\\
68 wxStaticCastEvent(ContactConflictEventFunction, &func)
70 // Define the event table entry. Yes, it really *does* end in a comma.
71 #define EVT_CONTACTCONFLICT(id, fn) \
72 DECLARE_EVENT_TABLE_ENTRY( ContactConflictCmdEnv, id, wxID_ANY, \\
73 (wxObjectEventFunction)(wxEventFunction) \\
74 (wxCommandEventFunction) wxStaticCastEvent( \\
75 ContactConflictEventFunction, &fn ), (wxObject*) NULL ),
77 // Optionally, you can do a similar #define for EVT_MYFOO_RANGE.
78 #define EVT_CONTACTCONFLICT_RANGE(id1,id2, fn) \
79 DECLARE_EVENT_TABLE_ENTRY( ContactConflictCmdEnv, id1, id2, \\
80 ContactConflictEventHandler(fn), (wxObject*) NULL ),
82 // If you want to use the custom event to send more than one sort
83 // of data, or to more than one place, make it easier by providing
84 // named IDs in an enumeration.
85 enum { Foo_DoFirstThing = 1, Foo_DoSecondThing, Foo_DoThirdThing };