]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/gsockgtk.c
initial attempts to get raw bitmaps working under Mac
[wxWidgets.git] / src / gtk / gsockgtk.c
CommitLineData
dbd300df
GL
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockgtk.c
4 * Purpose: GSocket: GTK part
84969af7 5 * Licence: The wxWindows licence
dbd300df
GL
6 * CVSID: $Id$
7 * -------------------------------------------------------------------------
8 */
3646fd68
VZ
9#include "wx/setup.h"
10
11#if wxUSE_SOCKETS
12
007c77ab 13#include <assert.h>
a324a7bc 14#include <stdlib.h>
483249fc 15#include <stdio.h>
16c1f79c
RR
16
17#include <gdk/gdk.h>
18#include <glib.h>
19
d422d01e 20#include "wx/gsocket.h"
1a9469d7 21#include "wx/unix/gsockunx.h"
a324a7bc 22
483249fc
GRG
23
24void _GSocket_GDK_Input(gpointer data,
25 gint source,
26 GdkInputCondition condition)
a324a7bc
GL
27{
28 GSocket *socket = (GSocket *)data;
29
aa8fb7a0 30 if (condition & GDK_INPUT_READ)
a324a7bc 31 _GSocket_Detected_Read(socket);
aa8fb7a0 32 if (condition & GDK_INPUT_WRITE)
a324a7bc 33 _GSocket_Detected_Write(socket);
a324a7bc
GL
34}
35
27a97d02 36int _GSocket_GUI_Init(GSocket *socket)
a324a7bc 37{
a324a7bc
GL
38 gint *m_id;
39
483249fc 40 socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
a324a7bc
GL
41 m_id = (gint *)(socket->m_gui_dependent);
42
483249fc
GRG
43 m_id[0] = -1;
44 m_id[1] = -1;
5ff86996
GRG
45
46 return TRUE;
a324a7bc
GL
47}
48
49void _GSocket_GUI_Destroy(GSocket *socket)
50{
a324a7bc
GL
51 free(socket->m_gui_dependent);
52}
53
39b91eca 54void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 55{
483249fc 56 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 57 int c;
a324a7bc 58
483249fc
GRG
59 if (socket->m_fd == -1)
60 return;
a324a7bc 61
483249fc
GRG
62 switch (event)
63 {
64 case GSOCK_LOST: /* fall-through */
06b466c7 65 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
66 case GSOCK_OUTPUT: c = 1; break;
67 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
68 default: return;
a324a7bc
GL
69 }
70
71 if (m_id[c] != -1)
72 gdk_input_remove(m_id[c]);
73
483249fc
GRG
74 m_id[c] = gdk_input_add(socket->m_fd,
75 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
76 _GSocket_GDK_Input,
77 (gpointer)socket);
a324a7bc
GL
78}
79
39b91eca 80void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 81{
483249fc 82 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 83 int c;
a324a7bc 84
007c77ab
RL
85 assert( m_id != NULL );
86
483249fc
GRG
87 switch (event)
88 {
89 case GSOCK_LOST: /* fall-through */
06b466c7 90 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
91 case GSOCK_OUTPUT: c = 1; break;
92 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
93 default: return;
a324a7bc
GL
94 }
95
96 if (m_id[c] != -1)
97 gdk_input_remove(m_id[c]);
98
99 m_id[c] = -1;
100}
101
483249fc 102void _GSocket_Enable_Events(GSocket *socket)
a324a7bc 103{
483249fc
GRG
104 _GSocket_Install_Callback(socket, GSOCK_INPUT);
105 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
a324a7bc
GL
106}
107
483249fc 108void _GSocket_Disable_Events(GSocket *socket)
a324a7bc 109{
483249fc
GRG
110 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
111 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
a324a7bc 112}
3646fd68 113
06b466c7
VZ
114#else /* !wxUSE_SOCKETS */
115
116/* some compilers don't like having empty source files */
117static int wxDummyGsockVar = 0;
118
119#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */