OSDN Git Service

Handling key and mouse events in listctrl is improved
[molby/Molby.git] / wxSources / MyIPCSupport.cpp
1 /*
2  *  MyIPCSupport.cpp
3  *  Molby
4  *
5  *  Created by Toshi Nagata on 12/10/10.
6  *  Copyright 2012 Toshi Nagata. All rights reserved.
7  *
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation version 2 of the License.
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
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/wx.h"
23 #endif
24
25
26 #if defined(__WXMSW__)
27
28 #include "MyIPCSupport.h"
29 #include "MyApp.h"
30
31 wxString *gIPCServiceName = NULL;
32
33 bool
34 MyClientConnection::OnDisconnect()
35 {
36         return wxGetApp().m_client->Disconnect();
37 }
38
39 MyClient::MyClient()
40 {
41         m_clientConnection = NULL;
42 }
43
44 MyClient::~MyClient()
45 {
46         Disconnect();
47 }
48         
49 bool
50 MyClient::Disconnect()
51 {
52         if (m_clientConnection != NULL) {
53         if (m_clientConnection->Disconnect()) {
54             m_clientConnection = NULL;
55             return true;
56         } else return false;
57     } else return true;
58 }
59
60 wxConnectionBase *
61 MyClient::OnMakeConnection()
62 {
63         if (m_clientConnection == NULL)
64                 m_clientConnection = new MyClientConnection;
65         return m_clientConnection;
66 }
67
68 bool
69 MyServerConnection::OnDisconnect()
70 {
71         return wxGetApp().m_server->Disconnect();
72 }
73
74 bool
75 MyServerConnection::OnExecute(const wxString& topic, const void *data, size_t size, wxIPCFormat format)
76 {
77         if (topic == MOLBY_IPC_TOPIC) {
78                 wxString files((wxChar *)data);
79                 wxGetApp().RequestOpenFilesByEvent(files);
80                 return true;
81         } else return false;
82 }
83
84 MyServer::MyServer()
85 {
86         m_serverConnection = NULL;
87 }
88
89 MyServer::~MyServer()
90 {
91         Disconnect();
92 }
93
94 bool
95 MyServer::Disconnect()
96 {
97         if (m_serverConnection != NULL) {
98         if (m_serverConnection->Disconnect()) {
99             m_serverConnection = NULL;
100             return true;
101         } else return false;
102     } else return true;
103 }
104
105 wxConnectionBase *
106 MyServer::OnAcceptConnection(const wxString &topic)
107 {
108     if (topic == MOLBY_IPC_TOPIC) {
109                 if (m_serverConnection == NULL)
110                         m_serverConnection = new MyServerConnection();
111         return m_serverConnection;
112     }
113     return NULL;
114 }
115
116 #endif  // defined(__WXMSW__)