]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/gsockgtk.c
wxChoice/wxComboBox background colour change (to get back to where we were);
[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>
16c1f79c
RR
14
15#include <gdk/gdk.h>
16#include <glib.h>
17
d422d01e 18#include "wx/gsocket.h"
1a9469d7 19#include "wx/unix/gsockunx.h"
a324a7bc 20
483249fc
GRG
21
22void _GSocket_GDK_Input(gpointer data,
23 gint source,
24 GdkInputCondition condition)
a324a7bc
GL
25{
26 GSocket *socket = (GSocket *)data;
27
aa8fb7a0 28 if (condition & GDK_INPUT_READ)
a324a7bc 29 _GSocket_Detected_Read(socket);
aa8fb7a0 30 if (condition & GDK_INPUT_WRITE)
a324a7bc 31 _GSocket_Detected_Write(socket);
a324a7bc
GL
32}
33
34void _GSocket_GUI_Init(GSocket *socket)
35{
36 int i;
37 gint *m_id;
38
483249fc 39 socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
a324a7bc
GL
40 m_id = (gint *)(socket->m_gui_dependent);
41
483249fc
GRG
42 m_id[0] = -1;
43 m_id[1] = -1;
a324a7bc
GL
44}
45
46void _GSocket_GUI_Destroy(GSocket *socket)
47{
a324a7bc
GL
48 free(socket->m_gui_dependent);
49}
50
39b91eca 51void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 52{
483249fc 53 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 54 int c;
a324a7bc 55
483249fc
GRG
56 if (socket->m_fd == -1)
57 return;
a324a7bc 58
483249fc
GRG
59 switch (event)
60 {
61 case GSOCK_LOST: /* fall-through */
62 case GSOCK_INPUT: c = 0; break;
63 case GSOCK_OUTPUT: c = 1; break;
64 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
65 default: return;
a324a7bc
GL
66 }
67
68 if (m_id[c] != -1)
69 gdk_input_remove(m_id[c]);
70
483249fc
GRG
71 m_id[c] = gdk_input_add(socket->m_fd,
72 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
73 _GSocket_GDK_Input,
74 (gpointer)socket);
a324a7bc
GL
75}
76
39b91eca 77void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 78{
483249fc 79 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 80 int c;
a324a7bc 81
483249fc
GRG
82 switch (event)
83 {
84 case GSOCK_LOST: /* fall-through */
85 case GSOCK_INPUT: c = 0; break;
86 case GSOCK_OUTPUT: c = 1; break;
87 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
88 default: return;
a324a7bc
GL
89 }
90
91 if (m_id[c] != -1)
92 gdk_input_remove(m_id[c]);
93
94 m_id[c] = -1;
95}
96
483249fc 97void _GSocket_Enable_Events(GSocket *socket)
a324a7bc 98{
483249fc
GRG
99 _GSocket_Install_Callback(socket, GSOCK_INPUT);
100 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
a324a7bc
GL
101}
102
483249fc 103void _GSocket_Disable_Events(GSocket *socket)
a324a7bc 104{
483249fc
GRG
105 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
106 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
a324a7bc 107}
3646fd68
VZ
108
109#endif /* wxUSE_SOCKETS */