// Created: 10.07.01
// RCS-ID: $Id$
// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
-// License: wxWindows licence
+// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
#endif
#include "wx/evtloop.h"
+#include "wx/evtloopsrc.h"
#ifndef WX_PRECOMP
#include "wx/app.h"
// wxEventLoop adding & removing sources
// ----------------------------------------------------------------------------
+#if wxUSE_EVENTLOOP_SOURCE
+
extern "C"
{
static gboolean wx_on_channel_event(GIOChannel *channel,
- GIOCondition condition, gpointer data)
+ GIOCondition condition,
+ gpointer data)
{
- wxLogTrace(wxTRACE_EVT_SOURCE, "wx_on_channel_event, gtk_source_id=%d",
- g_io_channel_unix_get_fd(channel));
+ wxUnusedVar(channel); // Unused if !wxUSE_LOG || !wxDEBUG_LEVEL
+
+ wxLogTrace(wxTRACE_EVT_SOURCE,
+ "wx_on_channel_event, fd=%d, condition=%08x",
+ g_io_channel_unix_get_fd(channel), condition);
- wxEventLoopSourceHandler* handler =
- static_cast<wxEventLoopSourceHandler*>(data);
+ wxEventLoopSourceHandler * const
+ handler = static_cast<wxEventLoopSourceHandler *>(data);
if (condition & G_IO_IN || condition & G_IO_PRI)
- {
handler->OnReadWaiting();
- }
- else if (condition & G_IO_OUT)
- {
+ if (condition & G_IO_OUT)
handler->OnWriteWaiting();
- }
else if (condition & G_IO_ERR || condition & G_IO_NVAL)
- {
handler->OnExceptionWaiting();
- }
- else
- {
- wxFAIL_MSG(wxString::Format("Inavlid condition=%d", condition));
- }
// we never want to remove source here, so always return true
return TRUE;
}
}
-bool wxGUIEventLoop::DoAddSource(wxAbstractEventLoopSource* src)
+wxEventLoopSource *
+wxGUIEventLoop::AddSourceForFD(int fd,
+ wxEventLoopSourceHandler *handler,
+ int flags)
{
- Source* source = dynamic_cast<Source*>(src);
- wxCHECK_MSG( source, false, "Invalid source type" );
+ wxCHECK_MSG( fd != -1, NULL, "can't monitor invalid fd" );
- wxLogTrace(wxTRACE_EVT_SOURCE,
- "wxGUIEventLoop::DoAddSource() source=%d",
- source->GetResource());
-
- int flags = source->GetFlags();
int condition = 0;
if (flags & wxEVENT_SOURCE_INPUT)
condition |= G_IO_IN | G_IO_PRI;
if (flags & wxEVENT_SOURCE_EXCEPTION)
condition |= G_IO_ERR | G_IO_HUP | G_IO_NVAL;
- GIOChannel* channel = g_io_channel_unix_new(source->GetResource());
- int gtk_id = g_io_add_watch(channel, (GIOCondition)condition,
- &wx_on_channel_event, source->GetHandler());
+ GIOChannel* channel = g_io_channel_unix_new(fd);
+ const unsigned sourceId = g_io_add_watch
+ (
+ channel,
+ (GIOCondition)condition,
+ &wx_on_channel_event,
+ handler
+ );
+ // it was ref'd by g_io_add_watch() so we can unref it here
g_io_channel_unref(channel);
- wxEventLoopSourceIdMap::value_type val(source, gtk_id);
- return m_sourceIdMap.insert(val).second;
+ if ( !sourceId )
+ return NULL;
+
+ wxLogTrace(wxTRACE_EVT_SOURCE,
+ "Adding event loop source for fd=%d with GTK id=%u",
+ fd, sourceId);
+
+
+ return new wxGTKEventLoopSource(sourceId, handler, flags);
}
-bool wxGUIEventLoop::DoRemoveSource(wxAbstractEventLoopSource* src)
+wxGTKEventLoopSource::~wxGTKEventLoopSource()
{
- Source* source = dynamic_cast<Source*>(src);
- wxCHECK_MSG( source, false, "Invalid source type" );
-
wxLogTrace(wxTRACE_EVT_SOURCE,
- "wxGUIEventLoop::DoRemoveSource() source=%d",
- source->GetResource());
-
- wxEventLoopSourceIdMap::iterator it = m_sourceIdMap.find(source);
- wxCHECK_MSG( it != m_sourceIdMap.end(), false, "Source not on the list" );
+ "Removing event loop source with GTK id=%u", m_sourceId);
- int gtk_id = it->second;
- m_sourceIdMap.erase(it);
- return g_source_remove(gtk_id);
+ g_source_remove(m_sourceId);
}
+#endif // wxUSE_EVENTLOOP_SOURCE
+
// ----------------------------------------------------------------------------
// wxEventLoop message processing dispatching
// ----------------------------------------------------------------------------
// new event types (since new event types are always added in GDK with non
// conflicting values for ABI compatibility).
- wxEventCategory cat = wxEVT_CATEGORY_UNKNOWN;
+ // Some events (currently only a single one) may be used for more than one
+ // category, so we need 2 variables. The second one will remain "unknown"
+ // in most cases.
+ wxEventCategory cat = wxEVT_CATEGORY_UNKNOWN,
+ cat2 = wxEVT_CATEGORY_UNKNOWN;
switch (event->type)
{
case GDK_SELECTION_REQUEST:
case GDK_SELECTION_NOTIFY:
case GDK_SELECTION_CLEAR:
-#if GTK_CHECK_VERSION(2,6,0)
case GDK_OWNER_CHANGE:
-#endif
cat = wxEVT_CATEGORY_CLIPBOARD;
break;
cat = wxEVT_CATEGORY_USER_INPUT;
break;
+ case GDK_PROPERTY_NOTIFY:
+ // This one is special: it can be used for UI purposes but also for
+ // clipboard operations, so allow it in both cases (we probably could
+ // examine the event itself to distinguish between the two cases but
+ // this would be unnecessarily complicated).
+ cat2 = wxEVT_CATEGORY_CLIPBOARD;
+ // Fall through.
+
case GDK_PROXIMITY_IN:
case GDK_PROXIMITY_OUT:
case GDK_ENTER_NOTIFY:
case GDK_LEAVE_NOTIFY:
case GDK_VISIBILITY_NOTIFY:
- case GDK_PROPERTY_NOTIFY:
case GDK_FOCUS_CHANGE:
case GDK_CONFIGURE:
case GDK_DESTROY:
case GDK_EXPOSE:
+#ifndef __WXGTK3__
case GDK_NO_EXPOSE:
+#endif
case GDK_MAP:
case GDK_UNMAP:
wxGUIEventLoop* evtloop = static_cast<wxGUIEventLoop*>(data);
// is this event allowed now?
- if (evtloop->IsEventAllowedInsideYield(cat))
- gtk_main_do_event(event); // process it now
+ if (evtloop->IsEventAllowedInsideYield(cat) ||
+ (cat2 != wxEVT_CATEGORY_UNKNOWN &&
+ evtloop->IsEventAllowedInsideYield(cat2)))
+ {
+ // process it now
+ gtk_main_do_event(event);
+ }
else if (event->type != GDK_NOTHING)
+ {
+ // process it later (but make a copy; the caller will free the event
+ // pointer)
evtloop->StoreGdkEventForLaterProcessing(gdk_event_copy(event));
- // process it later (but make a copy; the caller will free the event pointer)
+ }
}
}