X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f84fb4ad9ec61894dba6f08c67a4e5079aee8537..cf2227623a889dd0a5f36288d346fc6bf64b55fa:/src/x11/window.cpp diff --git a/src/x11/window.cpp b/src/x11/window.cpp index 6cae3175d7..fcd2ee3dea 100644 --- a/src/x11/window.cpp +++ b/src/x11/window.cpp @@ -56,6 +56,8 @@ #include "wx/dnd.h" #endif +#include "wx/unix/utilsx11.h" + #include "wx/x11/private.h" #include "X11/Xutil.h" @@ -148,7 +150,7 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, if (parent->GetInsertIntoMain()) { // wxLogDebug( "Inserted into main: %s", GetName().c_str() ); - xparent = (Window) parent->GetMainWindow(); + xparent = (Window) parent->X11GetMainWindow(); } // Size (not including the border) must be nonzero (or a Value error results)! @@ -350,8 +352,6 @@ wxWindowX11::~wxWindowX11() if (g_captureWindow == this) g_captureWindow = NULL; - m_isBeingDeleted = true; - DestroyChildren(); if (m_clientWindow != m_mainWindow) @@ -397,9 +397,12 @@ void wxWindowX11::SetFocus() } #endif - if (wxWindowIsVisible(xwindow)) + XWindowAttributes wa; + XGetWindowAttributes(wxGlobalDisplay(), xwindow, &wa); + + if (wa.map_state == IsViewable) { - wxLogTrace( _T("focus"), _T("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName()); + wxLogTrace( wxT("focus"), wxT("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName()); // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime ); XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToNone, CurrentTime ); m_needsInputFocus = false; @@ -524,7 +527,9 @@ void wxWindowX11::DoCaptureMouse() msg.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName()); wxLogDebug(msg); if (res == GrabNotViewable) + { wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") ); + } g_captureWindow = NULL; return; @@ -577,7 +582,7 @@ bool wxWindowX11::SetCursor(const wxCursor& cursor) wxCHECK_MSG( xwindow, false, wxT("invalid window") ); wxCursor cursorToUse; - if (m_cursor.Ok()) + if (m_cursor.IsOk()) cursorToUse = m_cursor; else cursorToUse = *wxSTANDARD_CURSOR; @@ -1026,7 +1031,7 @@ void wxWindowX11::DoSetSizeHints(int minW, int minH, int maxW, int maxH, int inc int wxWindowX11::GetCharHeight() const { wxFont font(GetFont()); - wxCHECK_MSG( font.Ok(), 0, wxT("valid window font needed") ); + wxCHECK_MSG( font.IsOk(), 0, wxT("valid window font needed") ); #if wxUSE_UNICODE // There should be an easier way. @@ -1054,7 +1059,7 @@ int wxWindowX11::GetCharHeight() const int wxWindowX11::GetCharWidth() const { wxFont font(GetFont()); - wxCHECK_MSG( font.Ok(), 0, wxT("valid window font needed") ); + wxCHECK_MSG( font.IsOk(), 0, wxT("valid window font needed") ); #if wxUSE_UNICODE // There should be an easier way. @@ -1078,15 +1083,16 @@ int wxWindowX11::GetCharWidth() const #endif } -void wxWindowX11::GetTextExtent(const wxString& string, - int *x, int *y, - int *descent, int *externalLeading, - const wxFont *theFont) const +void wxWindowX11::DoGetTextExtent(const wxString& string, + int *x, int *y, + int *descent, + int *externalLeading, + const wxFont *theFont) const { wxFont fontToUse = GetFont(); if (theFont) fontToUse = *theFont; - wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") ); + wxCHECK_RET( fontToUse.IsOk(), wxT("invalid font") ); if (string.empty()) { @@ -1101,7 +1107,7 @@ void wxWindowX11::GetTextExtent(const wxString& string, PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description; pango_layout_set_font_description(layout, desc); - const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); + const wxCharBuffer data = wxConvUTF8.cWC2MB( string.wc_str() ); pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data; @@ -1266,7 +1272,7 @@ void wxWindowX11::SendNcPaintEvents() x = sb->GetPosition().x; Display *xdisplay = wxGlobalDisplay(); - Window xwindow = (Window) GetMainWindow(); + Window xwindow = (Window) X11GetMainWindow(); Colormap cm = (Colormap) wxTheApp->GetMainColormap( wxGetDisplay() ); wxColour colour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); colour.CalcPixel( (WXColormap) cm ); @@ -1315,10 +1321,7 @@ void wxWindowX11::OnInternalIdle() // Update invalidated regions. Update(); - // This calls the UI-update mechanism (querying windows for - // menu/toolbar/control state information) - if (wxUpdateUIEvent::CanUpdate((wxWindow*) this) && IsShownOnScreen()) - UpdateWindowUI(wxUPDATE_UI_FROMIDLE); + wxWindowBase::OnInternalIdle(); // Set the input focus if couldn't do it before if (m_needsInputFocus) @@ -1407,7 +1410,7 @@ void wxDeleteClientWindowFromTable(Window w) // X11-specific accessors // ---------------------------------------------------------------------------- -WXWindow wxWindowX11::GetMainWindow() const +WXWindow wxWindowX11::X11GetMainWindow() const { return m_mainWindow; } @@ -1640,9 +1643,7 @@ bool wxWindowX11::SetForegroundColour(const wxColour& col) wxWindow *wxGetActiveWindow() { - // TODO - wxFAIL_MSG(wxT("Not implemented")); - return NULL; + return wxGetTopLevelParent(wxWindow::FindFocus()); } /* static */ @@ -1731,7 +1732,7 @@ public: wxWinModule() { // we must be cleaned up before the display is closed - AddDependency(wxClassInfo::FindClass(_T("wxX11DisplayModule"))); + AddDependency(wxClassInfo::FindClass(wxT("wxX11DisplayModule"))); } virtual bool OnInit(); @@ -1746,6 +1747,15 @@ IMPLEMENT_DYNAMIC_CLASS(wxWinModule, wxModule) bool wxWinModule::OnInit() { Display *xdisplay = wxGlobalDisplay(); + if ( !xdisplay ) + { + // This module may be linked into a console program when using + // monolithic library and in this case it's perfectly normal not to + // have a display, so just return without doing anything and avoid + // crashing below. + return true; + } + int xscreen = DefaultScreen( xdisplay ); Window xroot = RootWindow( xdisplay, xscreen ); g_eraseGC = XCreateGC( xdisplay, xroot, 0, NULL );