X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/521bf4ff3ef47059265beff5d53c9e1162beb122..2f36b4d22beeb7f4f0cedf922c0c26d037f54477:/src/x11/utils.cpp diff --git a/src/x11/utils.cpp b/src/x11/utils.cpp index 501b9fcaeb..69750e035f 100644 --- a/src/x11/utils.cpp +++ b/src/x11/utils.cpp @@ -4,8 +4,8 @@ // Author: Julian Smart // Modified by: // Created: 17/09/98 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart +// (c) 2013 Rob Bresalier // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -13,9 +13,11 @@ #include "wx/wxprec.h" #if defined(__BORLANDC__) -#pragma hdrstop + #pragma hdrstop #endif +#include "wx/private/eventloopsourcesmanager.h" + // ============================================================================ // declarations // ============================================================================ @@ -25,11 +27,17 @@ // ---------------------------------------------------------------------------- #include "wx/utils.h" -#include "wx/app.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/window.h" // for wxTopLevelWindows + #include "wx/cursor.h" + #include "wx/msgdlg.h" +#endif + #include "wx/apptrait.h" -#include "wx/msgdlg.h" -#include "wx/cursor.h" -#include "wx/window.h" // for wxTopLevelWindows +#include "wx/generic/private/timer.h" +#include "wx/evtloop.h" #include #include @@ -52,8 +60,6 @@ #pragma message disable nosimpint #endif -#include "wx/unix/execute.h" - #include "wx/x11/private.h" #include "X11/Xutil.h" @@ -77,20 +83,10 @@ void wxFlushEvents() // ?? } -bool wxCheckForInterrupt(wxWindow *wnd) -{ - wxASSERT_MSG(FALSE, wxT("wxCheckForInterrupt not yet implemented.")); - return FALSE; -} - -// ---------------------------------------------------------------------------- -// wxExecute stuff -// ---------------------------------------------------------------------------- - -int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) +bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd)) { - // TODO - return 0; + wxFAIL_MSG(wxT("wxCheckForInterrupt not yet implemented.")); + return false; } // ---------------------------------------------------------------------------- @@ -98,24 +94,30 @@ int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) // ---------------------------------------------------------------------------- // 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 -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { - static wxToolkitInfo info; - info.shortName = _T("x11univ"); - info.name = _T("wxX11"); - info.versionMajor = 0; - info.versionMinor = 0; - info.os = wxX11; - return info; + // get X protocol version + Display *display = wxGlobalDisplay(); + if (display) + { + if ( verMaj ) + *verMaj = ProtocolVersion (display); + if ( verMin ) + *verMin = ProtocolRevision (display); + } + + return wxPORT_X11; +} + +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() +{ + return new wxEventLoop; } // ---------------------------------------------------------------------------- @@ -142,7 +144,7 @@ void wxGetMousePosition( int* x, int* y ) #endif }; -// Return TRUE if we have a colour display +// Return true if we have a colour display bool wxColourDisplay() { return wxDisplayDepth() > 1; @@ -177,51 +179,57 @@ void wxDisplaySizeMM(int *width, int *height) *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() @@ -229,10 +237,20 @@ 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 @@ -344,12 +362,11 @@ void wxAllocColor(Display *d,Colormap cmp,XColor *xc) { 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 @@ -357,7 +374,7 @@ wxString wxGetXEventName(XEvent& event) 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 @@ -374,12 +391,28 @@ wxString wxGetXEventName(XEvent& event) 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 (wa.map_state == IsViewable); + return NULL; + } +}; + +wxEventLoopSourcesManagerBase* wxGUIAppTraits::GetEventLoopSourcesManager() +{ + static wxX11EventLoopSourcesManager s_eventLoopSourcesManager; + + return &s_eventLoopSourcesManager; } + +#endif // wxUSE_EVENTLOOP_SOURCE