]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/gsockgtk.cpp
Applied patch [ 1382329 ] [msw] SetScrollbar: Set thumbsize before triggering events
[wxWidgets.git] / src / gtk / 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 extern "C" {
25 static
26 void _GSocket_GDK_Input(gpointer data,
27 gint source,
28 GdkInputCondition condition)
29 {
30 GSocket *socket = (GSocket *)data;
31
32 if (condition & GDK_INPUT_READ)
33 socket->Detected_Read();
34 if (condition & GDK_INPUT_WRITE)
35 socket->Detected_Write();
36 }
37 }
38
39 bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
40 { return true; }
41
42 bool GSocketGUIFunctionsTableConcrete::OnInit(void)
43 {
44 return 1;
45 }
46
47 void GSocketGUIFunctionsTableConcrete::OnExit(void)
48 {
49 }
50
51 bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
52 {
53 gint *m_id;
54
55 socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
56 m_id = (gint *)(socket->m_gui_dependent);
57
58 m_id[0] = -1;
59 m_id[1] = -1;
60
61 return TRUE;
62 }
63
64 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
65 {
66 free(socket->m_gui_dependent);
67 }
68
69 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
70 {
71 gint *m_id = (gint *)(socket->m_gui_dependent);
72 int c;
73
74 if (socket->m_fd == -1)
75 return;
76
77 switch (event)
78 {
79 case GSOCK_LOST: /* fall-through */
80 case GSOCK_INPUT: c = 0; break;
81 case GSOCK_OUTPUT: c = 1; break;
82 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
83 default: return;
84 }
85
86 if (m_id[c] != -1)
87 gdk_input_remove(m_id[c]);
88
89 m_id[c] = gdk_input_add(socket->m_fd,
90 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
91 _GSocket_GDK_Input,
92 (gpointer)socket);
93 }
94
95 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
96 {
97 gint *m_id = (gint *)(socket->m_gui_dependent);
98 int c;
99
100 assert( m_id != NULL );
101
102 switch (event)
103 {
104 case GSOCK_LOST: /* fall-through */
105 case GSOCK_INPUT: c = 0; break;
106 case GSOCK_OUTPUT: c = 1; break;
107 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
108 default: return;
109 }
110
111 if (m_id[c] != -1)
112 {
113 gdk_input_remove(m_id[c]);
114 m_id[c] = -1;
115 }
116 }
117
118 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
119 {
120 Install_Callback(socket, GSOCK_INPUT);
121 Install_Callback(socket, GSOCK_OUTPUT);
122 }
123
124 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
125 {
126 Uninstall_Callback(socket, GSOCK_INPUT);
127 Uninstall_Callback(socket, GSOCK_OUTPUT);
128 }
129
130 #else /* !wxUSE_SOCKETS */
131
132 /* some compilers don't like having empty source files */
133 static int wxDummyGsockVar = 0;
134
135 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */