]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/gsockgtk.cpp
compile w/o tooltips
[wxWidgets.git] / src / gtk1 / gsockgtk.cpp
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockgtk.c
4 * Purpose: GSocket: GTK part
5 * Licence: The wxWindows licence
6 * CVSID: $Id$
7 * -------------------------------------------------------------------------
8 */
9 #include "wx/setup.h"
10
11 #if wxUSE_SOCKETS
12
13 #include <assert.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16
17 #include <gdk/gdk.h>
18 #include <glib.h>
19
20 #include "wx/gsocket.h"
21 #include "wx/unix/gsockunx.h"
22
23
24 void _GSocket_GDK_Input(gpointer data,
25 gint source,
26 GdkInputCondition condition)
27 {
28 GSocket *socket = (GSocket *)data;
29
30 if (condition & GDK_INPUT_READ)
31 socket->Detected_Read();
32 if (condition & GDK_INPUT_WRITE)
33 socket->Detected_Write();
34 }
35
36 bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
37 { return true; }
38
39 bool GSocketGUIFunctionsTableConcrete::OnInit(void)
40 {
41 return 1;
42 }
43
44 void GSocketGUIFunctionsTableConcrete::OnExit(void)
45 {
46 }
47
48 bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
49 {
50 gint *m_id;
51
52 socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
53 m_id = (gint *)(socket->m_gui_dependent);
54
55 m_id[0] = -1;
56 m_id[1] = -1;
57
58 return TRUE;
59 }
60
61 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
62 {
63 free(socket->m_gui_dependent);
64 }
65
66 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
67 {
68 gint *m_id = (gint *)(socket->m_gui_dependent);
69 int c;
70
71 if (socket->m_fd == -1)
72 return;
73
74 switch (event)
75 {
76 case GSOCK_LOST: /* fall-through */
77 case GSOCK_INPUT: c = 0; break;
78 case GSOCK_OUTPUT: c = 1; break;
79 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
80 default: return;
81 }
82
83 if (m_id[c] != -1)
84 gdk_input_remove(m_id[c]);
85
86 m_id[c] = gdk_input_add(socket->m_fd,
87 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
88 _GSocket_GDK_Input,
89 (gpointer)socket);
90 }
91
92 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
93 {
94 gint *m_id = (gint *)(socket->m_gui_dependent);
95 int c;
96
97 assert( m_id != NULL );
98
99 switch (event)
100 {
101 case GSOCK_LOST: /* fall-through */
102 case GSOCK_INPUT: c = 0; break;
103 case GSOCK_OUTPUT: c = 1; break;
104 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
105 default: return;
106 }
107
108 if (m_id[c] != -1)
109 gdk_input_remove(m_id[c]);
110
111 m_id[c] = -1;
112 }
113
114 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
115 {
116 Install_Callback(socket, GSOCK_INPUT);
117 Install_Callback(socket, GSOCK_OUTPUT);
118 }
119
120 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
121 {
122 Uninstall_Callback(socket, GSOCK_INPUT);
123 Uninstall_Callback(socket, GSOCK_OUTPUT);
124 }
125
126 #else /* !wxUSE_SOCKETS */
127
128 /* some compilers don't like having empty source files */
129 static int wxDummyGsockVar = 0;
130
131 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */