]> git.saurik.com Git - wxWidgets.git/blob - src/unix/fdiounix.cpp
Do not allow multiple selection when dragging in the 'value' column
[wxWidgets.git] / src / unix / fdiounix.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/fdiounix.cpp
3 // Purpose: wxFDIOManager implementation for console Unix applications
4 // Author: Vadim Zeitlin
5 // Created: 2009-08-17
6 // RCS-ID: $Id: wxhead.cpp,v 1.10 2009-06-29 10:23:04 zeitlin Exp $
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #include "wx/apptrait.h"
27 #include "wx/log.h"
28 #include "wx/private/fdiodispatcher.h"
29 #include "wx/unix/private/fdiounix.h"
30
31 // ============================================================================
32 // wxFDIOManagerUnix implementation
33 // ============================================================================
34
35 int wxFDIOManagerUnix::AddInput(wxFDIOHandler *handler, int fd, Direction d)
36 {
37 wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
38 wxCHECK_MSG( dispatcher, -1, "can't monitor FDs without FD IO dispatcher" );
39
40 // translate our direction to dispatcher flags
41 const int flag = d == INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT;
42
43 // we need to either register this FD with the dispatcher or update an
44 // existing registration depending on whether it had been previously
45 // registered for anything or not
46 bool ok;
47 const int regmask = handler->GetRegisteredEvents();
48 if ( !regmask )
49 {
50 ok = dispatcher->RegisterFD(fd, handler, flag);
51 }
52 else
53 {
54 ok = dispatcher->ModifyFD(fd, handler, regmask | flag);
55 }
56
57 if ( !ok )
58 return -1;
59
60 // update the stored mask of registered events
61 handler->SetRegisteredEvent(flag);
62
63 return fd;
64 }
65
66 void wxFDIOManagerUnix::RemoveInput(wxFDIOHandler *handler, int fd, Direction d)
67 {
68 wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
69 if ( !dispatcher )
70 return;
71
72 const int flag = d == INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT;
73
74 // just as in AddInput() above we may need to either just modify the FD or
75 // remove it completely if we don't need to monitor it any more
76 bool ok;
77 const int regmask = handler->GetRegisteredEvents();
78 if ( regmask == flag )
79 {
80 ok = dispatcher->UnregisterFD(fd);
81 }
82 else
83 {
84 ok = dispatcher->ModifyFD(fd, handler, regmask & ~flag);
85 }
86
87 if ( !ok )
88 {
89 wxLogDebug("Failed to unregister %d in direction %d", fd, d);
90 }
91
92 // do this even after a failure to unregister it, we still tried...
93 handler->ClearRegisteredEvent(flag);
94 }
95
96 wxFDIOManager *wxAppTraits::GetFDIOManager()
97 {
98 static wxFDIOManagerUnix s_manager;
99 return &s_manager;
100 }
101