1 //////////////////////////////////////////////////////////////////////////
2 //
3 // pgAdmin III - PostgreSQL Tools
4 //
5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team
6 // This software is released under the PostgreSQL Licence
7 //
8 // pgQueryResultEvent.h - Query Result Event from the pgQueryThread
9 //
10 //////////////////////////////////////////////////////////////////////////
11 
12 #ifndef PGQUERYRESULTEVENT_H
13 #define PGQUERYRESULTEVENT_H
14 
15 #include "wx/wx.h"
16 #include "wx/event.h"
17 
18 class pgBatchQuery;
19 
20 extern const wxEventType PGQueryResultEvent;
21 
22 
23 class pgQueryResultEvent : public wxCommandEvent
24 {
25 public:
26 	pgQueryResultEvent(unsigned long _thrdId, pgBatchQuery *_qry, int _id = 0);
27 	pgQueryResultEvent(const pgQueryResultEvent &_ev);
28 
29 	// Required for sending with wxPostEvent()
Clone()30 	wxEvent *Clone() const
31 	{
32 		return new pgQueryResultEvent(*this);
33 	}
34 
GetQuery()35 	pgBatchQuery *GetQuery()
36 	{
37 		return m_query;
38 	}
GetThreadID()39 	unsigned long GetThreadID()
40 	{
41 		return m_thrdId;
42 	}
43 
44 	enum
45 	{
46 		PGQ_RESULT_ERROR = -8,
47 		PGQ_EXECUTION_CANCELLED = -7,
48 		PGQ_ERROR_CONSUME_INPUT = -6,
49 		PGQ_ERROR_SEND_QUERY = -5,
50 		PGQ_ERROR_EXECUTE_CALLABLE = -4,
51 		PGQ_ERROR_PREPARE_CALLABLE = -3,
52 		PGQ_STRING_INVALID = -2,
53 		PGQ_CONN_LOST = -1,
54 	};
55 
56 private:
57 	pgBatchQuery  *m_query;
58 	// Thread Id (pgQueryThread)
59 	unsigned long m_thrdId;
60 };
61 
62 typedef void (wxEvtHandler::*pgQueryResultEventFunc)(pgQueryResultEvent &);
63 
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 pgQueryResultEventHandler(func)                              \
67 	(wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction) \
68 	wxStaticCastEvent(pgQueryResultEventFunc, &func)
69 
70 // Define the event table entry. Yes, it really *does* end in a comma.
71 #define EVT_PGQUERYRESULT(id, fn)                                \
72 	DECLARE_EVENT_TABLE_ENTRY(PGQueryResultEvent, id, wxID_ANY,  \
73 	pgQueryResultEventHandler(fn), (wxObject*) NULL),
74 
75 #define EVT_PGQUERYRESULT_RANGE(id1, id2, fn)               \
76 	DECLARE_EVENT_TABLE_ENTRY(PGQueryResultEvent, id1, id2, \
77 	pgQueryResultEventHandler(fn), (wxObject*) NULL),
78 
79 #endif // PGQUERYRESULTEVENT_H
80