]> git.saurik.com Git - wxWidgets.git/blob - src/x11/gsockx11.cpp
using backward compatible calls for HitTest hack
[wxWidgets.git] / src / x11 / gsockx11.cpp
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockmot.c
4 * Purpose: GSocket: X11 part
5 * Licence: The wxWindows licence
6 * CVSID: $Id$
7 * ------------------------------------------------------------------------- */
8
9 #include "wx/setup.h"
10
11 #if wxUSE_SOCKETS
12
13 #include <stdlib.h>
14 #include "wx/gsocket.h"
15 #include "wx/unix/gsockunx.h"
16
17 /*
18 * FIXME: have these in a common header instead of being repeated
19 * in evtloop.cpp and gsockx11.c
20 */
21
22 typedef void (*wxSocketCallback) (int fd, void* data);
23
24 typedef enum
25 { wxSocketTableInput, wxSocketTableOutput } wxSocketTableType ;
26
27 extern "C" void wxRegisterSocketCallback(int fd, wxSocketTableType socketType, wxSocketCallback cback, void* data);
28 extern "C" void wxUnregisterSocketCallback(int fd, wxSocketTableType socketType);
29
30
31 static void _GSocket_X11_Input(int *fid, void* data)
32 {
33 GSocket *socket = (GSocket *)data;
34
35 socket->Detected_Read();
36 }
37
38 static void _GSocket_X11_Output(int *fid, void* data)
39 {
40 GSocket *socket = (GSocket *)data;
41
42 socket->Detected_Write();
43 }
44
45 bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
46 { return true; }
47
48 bool GSocketGUIFunctionsTableConcrete::OnInit(void)
49 {
50 return 1;
51 }
52
53 void GSocketGUIFunctionsTableConcrete::OnExit(void)
54 {
55 }
56
57 bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
58 {
59 int *m_id;
60
61 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
62 m_id = (int *)(socket->m_gui_dependent);
63
64 m_id[0] = -1;
65 m_id[1] = -1;
66
67 return true;
68 }
69
70 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
71 {
72 free(socket->m_gui_dependent);
73 }
74
75 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
76 {
77 int *m_id = (int *)(socket->m_gui_dependent);
78 int c;
79
80 if (socket->m_fd == -1)
81 return;
82
83 switch (event)
84 {
85 case GSOCK_LOST: /* fall-through */
86 case GSOCK_INPUT: c = 0; break;
87 case GSOCK_OUTPUT: c = 1; break;
88 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
89 default: return;
90 }
91
92 #if 0
93 if (m_id[c] != -1)
94 XtRemoveInput(m_id[c]);
95 #endif /* 0 */
96
97 if (c == 0)
98 {
99 m_id[0] = socket->m_fd;
100
101 wxRegisterSocketCallback(socket->m_fd, wxSocketTableInput,
102 (wxSocketCallback) _GSocket_X11_Input, (void*) socket);
103 }
104 else
105 {
106 m_id[1] = socket->m_fd;
107
108 wxRegisterSocketCallback(socket->m_fd, wxSocketTableOutput,
109 (wxSocketCallback) _GSocket_X11_Output, (void*) socket);
110 }
111 }
112
113 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
114 {
115 int *m_id = (int *)(socket->m_gui_dependent);
116 int c;
117
118 switch (event)
119 {
120 case GSOCK_LOST: /* fall-through */
121 case GSOCK_INPUT: c = 0; break;
122 case GSOCK_OUTPUT: c = 1; break;
123 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
124 default: return;
125 }
126
127 if (m_id[c] != -1)
128 {
129 if (c == 0)
130 wxUnregisterSocketCallback(m_id[c], wxSocketTableInput);
131 else
132 wxUnregisterSocketCallback(m_id[c], wxSocketTableOutput);
133 }
134
135 m_id[c] = -1;
136 }
137
138 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
139 {
140 Install_Callback(socket, GSOCK_INPUT);
141 Install_Callback(socket, GSOCK_OUTPUT);
142 }
143
144 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
145 {
146 Uninstall_Callback(socket, GSOCK_INPUT);
147 Uninstall_Callback(socket, GSOCK_OUTPUT);
148 }
149
150 #else /* !wxUSE_SOCKETS */
151
152 /* some compilers don't like having empty source files */
153 static int wxDummyGsockVar = 0;
154
155 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */