]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/gsockgtk.c
generate key events for Space/Enter in addition to the activate events, as wxMSW...
[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
007c77ab 12#include <assert.h>
a324a7bc 13#include <stdlib.h>
483249fc 14#include <stdio.h>
16c1f79c
RR
15
16#include <gdk/gdk.h>
17#include <glib.h>
18
d422d01e 19#include "wx/gsocket.h"
1a9469d7 20#include "wx/unix/gsockunx.h"
a324a7bc 21
483249fc
GRG
22
23void _GSocket_GDK_Input(gpointer data,
24 gint source,
25 GdkInputCondition condition)
a324a7bc
GL
26{
27 GSocket *socket = (GSocket *)data;
28
aa8fb7a0 29 if (condition & GDK_INPUT_READ)
a324a7bc 30 _GSocket_Detected_Read(socket);
aa8fb7a0 31 if (condition & GDK_INPUT_WRITE)
a324a7bc 32 _GSocket_Detected_Write(socket);
a324a7bc
GL
33}
34
27a97d02 35int _GSocket_GUI_Init(GSocket *socket)
a324a7bc 36{
a324a7bc
GL
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;
5ff86996
GRG
44
45 return TRUE;
a324a7bc
GL
46}
47
48void _GSocket_GUI_Destroy(GSocket *socket)
49{
a324a7bc
GL
50 free(socket->m_gui_dependent);
51}
52
39b91eca 53void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 54{
483249fc 55 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 56 int c;
a324a7bc 57
483249fc
GRG
58 if (socket->m_fd == -1)
59 return;
a324a7bc 60
483249fc
GRG
61 switch (event)
62 {
63 case GSOCK_LOST: /* fall-through */
06b466c7 64 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
65 case GSOCK_OUTPUT: c = 1; break;
66 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
67 default: return;
a324a7bc
GL
68 }
69
70 if (m_id[c] != -1)
71 gdk_input_remove(m_id[c]);
72
483249fc
GRG
73 m_id[c] = gdk_input_add(socket->m_fd,
74 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
75 _GSocket_GDK_Input,
76 (gpointer)socket);
a324a7bc
GL
77}
78
39b91eca 79void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 80{
483249fc 81 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 82 int c;
a324a7bc 83
007c77ab
RL
84 assert( m_id != NULL );
85
483249fc
GRG
86 switch (event)
87 {
88 case GSOCK_LOST: /* fall-through */
06b466c7 89 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
90 case GSOCK_OUTPUT: c = 1; break;
91 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
92 default: return;
a324a7bc
GL
93 }
94
95 if (m_id[c] != -1)
96 gdk_input_remove(m_id[c]);
97
98 m_id[c] = -1;
99}
100
483249fc 101void _GSocket_Enable_Events(GSocket *socket)
a324a7bc 102{
483249fc
GRG
103 _GSocket_Install_Callback(socket, GSOCK_INPUT);
104 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
a324a7bc
GL
105}
106
483249fc 107void _GSocket_Disable_Events(GSocket *socket)
a324a7bc 108{
483249fc
GRG
109 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
110 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
a324a7bc 111}
3646fd68 112
06b466c7
VZ
113#else /* !wxUSE_SOCKETS */
114
115/* some compilers don't like having empty source files */
116static int wxDummyGsockVar = 0;
117
118#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */