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