]> git.saurik.com Git - wxWidgets.git/blame - src/x11/gsockx11.cpp
removed (unused) nCtlColor parameter of OnCtlColor(); added MSWControlColor(); implem...
[wxWidgets.git] / src / x11 / gsockx11.cpp
CommitLineData
bf703528
DE
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockmot.c
4 * Purpose: GSocket: X11 part
65571936 5 * Licence: The wxWindows licence
bf703528
DE
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
22typedef void (*wxSocketCallback) (int fd, void* data);
23
24typedef enum
25{ wxSocketTableInput, wxSocketTableOutput } wxSocketTableType ;
26
a371f703
JJ
27extern "C" void wxRegisterSocketCallback(int fd, wxSocketTableType socketType, wxSocketCallback cback, void* data);
28extern "C" void wxUnregisterSocketCallback(int fd, wxSocketTableType socketType);
bf703528
DE
29
30
31static void _GSocket_X11_Input(int *fid, void* data)
32{
33 GSocket *socket = (GSocket *)data;
34
0a647691 35 socket->Detected_Read();
bf703528
DE
36}
37
38static void _GSocket_X11_Output(int *fid, void* data)
39{
40 GSocket *socket = (GSocket *)data;
41
0a647691 42 socket->Detected_Write();
bf703528
DE
43}
44
0a647691
DE
45bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
46{ return true; }
47
48bool GSocketGUIFunctionsTableConcrete::OnInit(void)
bf703528
DE
49{
50 return 1;
51}
52
0a647691 53void GSocketGUIFunctionsTableConcrete::OnExit(void)
bf703528
DE
54{
55}
56
0a647691 57bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
bf703528
DE
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
948c96ef 67 return true;
bf703528
DE
68}
69
0a647691 70void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
bf703528
DE
71{
72 free(socket->m_gui_dependent);
73}
74
0a647691 75void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
bf703528
DE
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
0a647691 113void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
bf703528
DE
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
0a647691 138void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
bf703528 139{
0a647691
DE
140 Install_Callback(socket, GSOCK_INPUT);
141 Install_Callback(socket, GSOCK_OUTPUT);
bf703528
DE
142}
143
0a647691 144void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
bf703528 145{
0a647691
DE
146 Uninstall_Callback(socket, GSOCK_INPUT);
147 Uninstall_Callback(socket, GSOCK_OUTPUT);
bf703528
DE
148}
149
150#else /* !wxUSE_SOCKETS */
151
152/* some compilers don't like having empty source files */
153static int wxDummyGsockVar = 0;
154
155#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */