]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/socketiohandler.cpp
implement button support for pre-XP systems (or with themes disabled); using only...
[wxWidgets.git] / src / common / socketiohandler.cpp
index baa797a74e85c173e26376adde21f989bd37558d..3b1504a3291ffe3be6ee68e58a63d8d335148db9 100644 (file)
 // for compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
 #if wxUSE_SOCKETS && wxUSE_SELECT_DISPATCHER
 
 #include "wx/apptrait.h"
-#include "wx/unix/private.h"
-#include "wx/private/socketiohandler.h"
+#include "wx/private/socket.h"
+#include "wx/link.h"
 
 // ============================================================================
 // implementation
 // ============================================================================
 
 // ----------------------------------------------------------------------------
-// wxSocketImplFDIO
+// wxSocketFDIOManager: socket manager using wxFDIODispatcher
 // ----------------------------------------------------------------------------
 
-class wxSocketImplFDIO : public wxSocketImplUnix
+class wxSocketFDIOManager : public wxSocketFDBasedManager
 {
 public:
-    wxSocketImplFDIO(wxSocketBase& wxsocket)
-        : wxSocketImplUnix(wxsocket)
-    {
-        m_handler = NULL;
-    }
-
-    virtual ~wxSocketImplFDIO()
-    {
-        delete m_handler;
-    }
-
-    wxSocketIOHandler *m_handler;
-};
-
-// ----------------------------------------------------------------------------
-// wxSocketSelectManager
-// ----------------------------------------------------------------------------
-
-class wxSocketSelectManager : public wxSocketFDBasedManager
-{
-public:
-    virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket)
-    {
-        return new wxSocketImplFDIO(wxsocket);
-    }
-
     virtual void Install_Callback(wxSocketImpl *socket, wxSocketNotify event);
     virtual void Uninstall_Callback(wxSocketImpl *socket, wxSocketNotify event);
 };
 
-void wxSocketSelectManager::Install_Callback(wxSocketImpl *socket_,
+void wxSocketFDIOManager::Install_Callback(wxSocketImpl *socket_,
                                              wxSocketNotify event)
 {
-    wxSocketImplFDIO * const socket = static_cast<wxSocketImplFDIO *>(socket_);
+    wxSocketImplUnix * const socket = static_cast<wxSocketImplUnix *>(socket_);
 
     const int fd = socket->m_fd;
 
@@ -83,40 +61,24 @@ void wxSocketSelectManager::Install_Callback(wxSocketImpl *socket_,
     if ( !dispatcher )
         return;
 
-    wxSocketIOHandler *& handler = socket->m_handler;
+    FD(socket, d) = fd;
 
-    // we should register the new handlers but modify the existing ones in place
-    bool registerHandler;
-    if ( handler )
-    {
-        registerHandler = false;
-    }
-    else // no existing handler
-    {
-        registerHandler = true;
-        handler = new wxSocketIOHandler(socket);
-    }
+    // register it when it's used for the first time, update it if it had been
+    // previously registered
+    const bool alreadyRegistered = socket->HasAnyEnabledCallbacks();
 
-    FD(socket, d) = fd;
-    if (d == FD_INPUT)
-    {
-        handler->AddFlag(wxFDIO_INPUT);
-    }
-    else
-    {
-        handler->AddFlag(wxFDIO_OUTPUT);
-    }
+    socket->EnableCallback(d == FD_INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT);
 
-    if ( registerHandler )
-        dispatcher->RegisterFD(fd, handler, handler->GetFlags());
+    if ( alreadyRegistered )
+        dispatcher->ModifyFD(fd, socket, socket->GetEnabledCallbacks());
     else
-        dispatcher->ModifyFD(fd, handler, handler->GetFlags());
+        dispatcher->RegisterFD(fd, socket, socket->GetEnabledCallbacks());
 }
 
-void wxSocketSelectManager::Uninstall_Callback(wxSocketImpl *socket_,
+void wxSocketFDIOManager::Uninstall_Callback(wxSocketImpl *socket_,
                                                wxSocketNotify event)
 {
-    wxSocketImplFDIO * const socket = static_cast<wxSocketImplFDIO *>(socket_);
+    wxSocketImplUnix * const socket = static_cast<wxSocketImplUnix *>(socket_);
 
     const SocketDir d = GetDirForEvent(socket, event);
 
@@ -133,26 +95,12 @@ void wxSocketSelectManager::Uninstall_Callback(wxSocketImpl *socket_,
     if ( !dispatcher )
         return;
 
-    wxSocketIOHandler *& handler = socket->m_handler;
-    if ( handler )
-    {
-        handler->RemoveFlag(flag);
-
-        if ( !handler->GetFlags() )
-        {
-            dispatcher->UnregisterFD(fd);
-            delete handler;
-            socket->m_handler = NULL;
-        }
-        else
-        {
-            dispatcher->ModifyFD(fd, handler, handler->GetFlags());
-        }
-    }
-    else
-    {
+    socket->DisableCallback(flag);
+
+    if ( !socket->HasAnyEnabledCallbacks() )
         dispatcher->UnregisterFD(fd);
-    }
+    else
+        dispatcher->ModifyFD(fd, socket, socket->GetEnabledCallbacks());
 }
 
 // set the wxBase variable to point to our wxSocketManager implementation
@@ -163,9 +111,13 @@ static struct ManagerSetter
 {
     ManagerSetter()
     {
-        static wxSocketSelectManager s_manager;
+        static wxSocketFDIOManager s_manager;
         wxAppTraits::SetDefaultSocketManager(&s_manager);
     }
 } gs_managerSetter;
 
+
+// see the relative linker macro in socket.cpp
+wxFORCE_LINK_THIS_MODULE( socketiohandler );
+
 #endif // wxUSE_SOCKETS