// Author: Julian Smart
// Modified by:
// Created: 17/09/98
-// RCS-ID: $Id$
// Copyright: (c) Julian Smart
+// (c) 2013 Rob Bresalier
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#pragma hdrstop
#endif
+#include "wx/private/eventloopsourcesmanager.h"
+
// ============================================================================
// declarations
// ============================================================================
#endif
#include "wx/apptrait.h"
+#include "wx/generic/private/timer.h"
+#include "wx/evtloop.h"
#include <ctype.h>
#include <stdarg.h>
#pragma message disable nosimpint
#endif
-#include "wx/unix/execute.h"
-
#include "wx/x11/private.h"
#include "X11/Xutil.h"
// ??
}
-bool wxCheckForInterrupt(wxWindow *wnd)
+bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd))
{
wxFAIL_MSG(wxT("wxCheckForInterrupt not yet implemented."));
return false;
}
-// ----------------------------------------------------------------------------
-// wxExecute stuff
-// ----------------------------------------------------------------------------
-
-WX_DECLARE_HASH_MAP( int, wxEndProcessData*, wxIntegerHash, wxIntegerEqual, wxProcMap );
-
-static wxProcMap *gs_procmap;
-
-int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
-{
- if (!gs_procmap) gs_procmap = new wxProcMap();
- (*gs_procmap)[fd] = proc_data;
- return 1;
-}
-
-void wxCheckForFinishedChildren()
-{
- wxProcMap::iterator it;
- if (!gs_procmap) return;
- if (gs_procmap->size() == 0) {
- // Map empty, delete it.
- delete gs_procmap;
- gs_procmap = NULL;
- }
- for (it = gs_procmap->begin();it != gs_procmap->end(); ++it)
- {
- wxEndProcessData *proc_data = it->second;
- int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
- int status = 0;
- // has the process really terminated?
- int rc = waitpid(pid, &status, WNOHANG);
- if (rc == 0)
- continue; // no, it didn't exit yet, continue waiting
-
- // set exit code to -1 if something bad happened
- proc_data->exitcode = rc != -1 && WIFEXITED(status) ?
- WEXITSTATUS(status) : -1;
-
- // child exited, end waiting
- close(it->first);
-
- // don't call us again!
- gs_procmap->erase(it->first);
-
- wxHandleProcessTermination(proc_data);
-
- // Iterator is invalid. Handle any further children in subsequent
- // calls.
- break;
- }
-}
-
// ----------------------------------------------------------------------------
// misc
// ----------------------------------------------------------------------------
// Emit a beeeeeep
-#ifndef __EMX__
-// on OS/2, we use the wxBell from wxBase library (src/os2/utils.cpp)
void wxBell()
{
// Use current setting for the bell
XBell ((Display*) wxGetDisplay(), 0);
}
-#endif
wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
{
return wxPORT_X11;
}
+wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
+{
+ return new wxEventLoop;
+}
// ----------------------------------------------------------------------------
// display info
*height = DisplayHeightMM(dpy, DefaultScreen (dpy));
}
-void wxClientDisplayRect(int *x, int *y, int *width, int *height)
+wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
{
- // This is supposed to return desktop dimensions minus any window
- // manager panels, menus, taskbars, etc. If there is a way to do that
- // for this platform please fix this function, otherwise it defaults
- // to the entire desktop.
- if (x) *x = 0;
- if (y) *y = 0;
- wxDisplaySize(width, height);
+ return wxGenericFindWindowAtPoint(pt);
}
// Configurable display in wxX11 and wxMotif
-static WXDisplay *gs_currentDisplay = NULL;
+static Display *gs_currentDisplay = NULL;
static wxString gs_displayName;
WXDisplay *wxGetDisplay()
{
- if (gs_currentDisplay)
- return gs_currentDisplay;
- return wxApp::GetDisplay();
+ return (WXDisplay *)gs_currentDisplay;
}
-bool wxSetDisplay(const wxString& display_name)
+// close the current display
+void wxCloseDisplay()
{
- gs_displayName = display_name;
-
- if ( display_name.empty() )
+ if ( gs_currentDisplay )
{
- gs_currentDisplay = NULL;
+ if ( XCloseDisplay(gs_currentDisplay) != 0 )
+ {
+ wxLogWarning(_("Failed to close the display \"%s\""),
+ gs_displayName.c_str());
+ }
- return true;
+ gs_currentDisplay = NULL;
+ gs_displayName.clear();
}
- else
- {
- Display* display = XOpenDisplay((char*) display_name.c_str());
+}
- if (display)
- {
- gs_currentDisplay = (WXDisplay*) display;
- return true;
- }
- else
- return false;
+bool wxSetDisplay(const wxString& displayName)
+{
+ Display *dpy = XOpenDisplay
+ (
+ displayName.empty() ? NULL
+ : (const char *)displayName.mb_str()
+ );
+
+ if ( !dpy )
+ {
+ wxLogError(_("Failed to open display \"%s\"."), displayName.c_str());
+ return false;
}
+
+ wxCloseDisplay();
+
+ gs_currentDisplay = dpy;
+ gs_displayName = displayName;
+
+ return true;
}
wxString wxGetDisplayName()
return gs_displayName;
}
-wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
+#include "wx/module.h"
+
+// the module responsible for closing the X11 display at the program end
+class wxX11DisplayModule : public wxModule
{
- return wxGenericFindWindowAtPoint(pt);
-}
+public:
+ virtual bool OnInit() { return true; }
+ virtual void OnExit() { wxCloseDisplay(); }
+
+private:
+ DECLARE_DYNAMIC_CLASS(wxX11DisplayModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxX11DisplayModule, wxModule)
// ----------------------------------------------------------------------------
// Some colour manipulation routines
{
if (!XAllocColor(d,cmp,xc))
{
- // cout << "wxAllocColor : Warning : Can not allocate color, attempt find nearest !\n";
+ // cout << "wxAllocColor : Warning : Cannot allocate color, attempt find nearest !\n";
wxAllocNearestColor(d,cmp,xc);
}
}
-#ifdef __WXDEBUG__
wxString wxGetXEventName(XEvent& event)
{
#if wxUSE_NANOX
return str;
#else
int type = event.xany.type;
- static char* event_name[] = {
+ static const char* event_name[] = {
"", "unknown(-)", // 0-1
"KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease", // 2-5
"MotionNotify", "EnterNotify", "LeaveNotify", "FocusIn", // 6-9
return wxString::FromAscii(event_name[type]);
#endif
}
-#endif
-bool wxWindowIsVisible(Window win)
+#if wxUSE_EVENTLOOP_SOURCE
+
+class wxX11EventLoopSourcesManager : public wxEventLoopSourcesManagerBase
{
- XWindowAttributes wa;
- XGetWindowAttributes(wxGlobalDisplay(), win, &wa);
+public:
+ wxEventLoopSource *
+ AddSourceForFD(int WXUNUSED(fd),
+ wxEventLoopSourceHandler* WXUNUSED(handler),
+ int WXUNUSED(flags))
+ {
+ wxFAIL_MSG("Monitoring FDs in the main loop is not implemented in wxX11");
+
+ return NULL;
+ }
+};
- return (wa.map_state == IsViewable);
+wxEventLoopSourcesManagerBase* wxGUIAppTraits::GetEventLoopSourcesManager()
+{
+ static wxX11EventLoopSourcesManager s_eventLoopSourcesManager;
+
+ return &s_eventLoopSourcesManager;
}
+
+#endif // wxUSE_EVENTLOOP_SOURCE