]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/sockgtk.cpp
Update the sample to show how to block navigation and new window events
[wxWidgets.git] / src / gtk / sockgtk.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/sockgtk.cpp
3 // Purpose: implementation of wxGTK-specific socket event handling
4 // Author: Guilhem Lavaux, Vadim Zeitlin
5 // Created: 1999
6 // RCS-ID: $Id$
7 // Copyright: (c) 1999, 2007 wxWidgets dev team
8 // (c) 2009 Vadim Zeitlin
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #if wxUSE_SOCKETS
16
17 #include "wx/apptrait.h"
18 #include "wx/private/fdiomanager.h"
19
20 #include <glib.h>
21
22 extern "C" {
23 static gboolean wxSocket_Input(GIOChannel*, GIOCondition condition, gpointer data)
24 {
25 wxFDIOHandler * const handler = static_cast<wxFDIOHandler *>(data);
26
27 if (condition & G_IO_IN)
28 {
29 handler->OnReadWaiting();
30
31 // we could have lost connection while reading in which case we
32 // shouldn't call OnWriteWaiting() as the socket is now closed and it
33 // would assert
34 if ( !handler->IsOk() )
35 return true;
36 }
37
38 if (condition & G_IO_OUT)
39 handler->OnWriteWaiting();
40
41 return true;
42 }
43 }
44
45 class GTKFDIOManager : public wxFDIOManager
46 {
47 public:
48 virtual int AddInput(wxFDIOHandler *handler, int fd, Direction d)
49 {
50 return g_io_add_watch(
51 g_io_channel_unix_new(fd),
52 d == OUTPUT ? G_IO_OUT : G_IO_IN,
53 wxSocket_Input,
54 handler);
55 }
56
57 virtual void
58 RemoveInput(wxFDIOHandler* WXUNUSED(handler), int fd, Direction WXUNUSED(d))
59 {
60 g_source_remove(fd);
61 }
62 };
63
64 wxFDIOManager *wxGUIAppTraits::GetFDIOManager()
65 {
66 static GTKFDIOManager s_manager;
67 return &s_manager;
68 }
69
70 #endif // wxUSE_SOCKETS