]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/gsockgtk.c
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[wxWidgets.git] / src / gtk1 / gsockgtk.c
CommitLineData
dbd300df
GL
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockgtk.c
4 * Purpose: GSocket: GTK part
5 * CVSID: $Id$
6 * -------------------------------------------------------------------------
7 */
3646fd68
VZ
8#include "wx/setup.h"
9
10#if wxUSE_SOCKETS
11
a324a7bc 12#include <stdlib.h>
483249fc 13#include <stdio.h>
d422d01e
RR
14#include "gdk/gdk.h"
15#include "glib.h"
16#include "wx/gsocket.h"
1a9469d7 17#include "wx/unix/gsockunx.h"
a324a7bc 18
483249fc
GRG
19
20void _GSocket_GDK_Input(gpointer data,
21 gint source,
22 GdkInputCondition condition)
a324a7bc
GL
23{
24 GSocket *socket = (GSocket *)data;
25
aa8fb7a0 26 if (condition & GDK_INPUT_READ)
a324a7bc 27 _GSocket_Detected_Read(socket);
aa8fb7a0 28 if (condition & GDK_INPUT_WRITE)
a324a7bc 29 _GSocket_Detected_Write(socket);
a324a7bc
GL
30}
31
32void _GSocket_GUI_Init(GSocket *socket)
33{
34 int i;
35 gint *m_id;
36
483249fc 37 socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
a324a7bc
GL
38 m_id = (gint *)(socket->m_gui_dependent);
39
483249fc
GRG
40 m_id[0] = -1;
41 m_id[1] = -1;
a324a7bc
GL
42}
43
44void _GSocket_GUI_Destroy(GSocket *socket)
45{
a324a7bc
GL
46 free(socket->m_gui_dependent);
47}
48
39b91eca 49void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 50{
483249fc 51 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 52 int c;
a324a7bc 53
483249fc
GRG
54 if (socket->m_fd == -1)
55 return;
a324a7bc 56
483249fc
GRG
57 switch (event)
58 {
59 case GSOCK_LOST: /* fall-through */
60 case GSOCK_INPUT: c = 0; break;
61 case GSOCK_OUTPUT: c = 1; break;
62 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
63 default: return;
a324a7bc
GL
64 }
65
66 if (m_id[c] != -1)
67 gdk_input_remove(m_id[c]);
68
483249fc
GRG
69 m_id[c] = gdk_input_add(socket->m_fd,
70 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
71 _GSocket_GDK_Input,
72 (gpointer)socket);
a324a7bc
GL
73}
74
39b91eca 75void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 76{
483249fc 77 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 78 int c;
a324a7bc 79
483249fc
GRG
80 switch (event)
81 {
82 case GSOCK_LOST: /* fall-through */
83 case GSOCK_INPUT: c = 0; break;
84 case GSOCK_OUTPUT: c = 1; break;
85 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
86 default: return;
a324a7bc
GL
87 }
88
89 if (m_id[c] != -1)
90 gdk_input_remove(m_id[c]);
91
92 m_id[c] = -1;
93}
94
483249fc 95void _GSocket_Enable_Events(GSocket *socket)
a324a7bc 96{
483249fc
GRG
97 _GSocket_Install_Callback(socket, GSOCK_INPUT);
98 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
a324a7bc
GL
99}
100
483249fc 101void _GSocket_Disable_Events(GSocket *socket)
a324a7bc 102{
483249fc
GRG
103 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
104 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
a324a7bc 105}
3646fd68
VZ
106
107#endif /* wxUSE_SOCKETS */