X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/af1a6227cc5b17afeded61658fb7a7dc3e862d8a..2f36b4d22beeb7f4f0cedf922c0c26d037f54477:/src/x11/window.cpp diff --git a/src/x11/window.cpp b/src/x11/window.cpp index dcd3dffb80..89a218afef 100644 --- a/src/x11/window.cpp +++ b/src/x11/window.cpp @@ -4,7 +4,6 @@ // Author: Julian Smart // Modified by: // Created: 17/09/98 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -45,10 +44,10 @@ #include "wx/listbox.h" #include "wx/scrolwin.h" #include "wx/layout.h" + #include "wx/menuitem.h" + #include "wx/module.h" #endif -#include "wx/module.h" -#include "wx/menuitem.h" #include "wx/fontutil.h" #include "wx/univ/renderer.h" @@ -56,6 +55,8 @@ #include "wx/dnd.h" #endif +#include "wx/unix/utilsx11.h" + #include "wx/x11/private.h" #include "X11/Xutil.h" @@ -122,6 +123,11 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, { wxCHECK_MSG( parent, false, wxT("can't create wxWindow without parent") ); + // Get default border + wxBorder border = GetBorder(style); + style &= ~wxBORDER_MASK; + style |= border; + CreateBase(parent, id, pos, size, style, wxDefaultValidator, name); parent->AddChild(this); @@ -143,7 +149,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)! @@ -160,9 +166,11 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, if (pos2.y == wxDefaultCoord) pos2.y = 0; + AdjustForParentClientOrigin(pos2.x, pos2.y); + #if wxUSE_TWO_WINDOWS bool need_two_windows = - ((( wxSUNKEN_BORDER | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0); + ((( wxSUNKEN_BORDER | wxBORDER_THEME | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0); #else bool need_two_windows = false; #endif @@ -228,7 +236,7 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, } #endif - if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER)) + if (HasFlag(wxSUNKEN_BORDER) || HasFlag(wxRAISED_BORDER) || HasFlag(wxBORDER_THEME)) { pos2.x = 2; pos2.y = 2; @@ -343,8 +351,6 @@ wxWindowX11::~wxWindowX11() if (g_captureWindow == this) g_captureWindow = NULL; - m_isBeingDeleted = true; - DestroyChildren(); if (m_clientWindow != m_mainWindow) @@ -357,10 +363,13 @@ wxWindowX11::~wxWindowX11() } // Destroy the window - Window xwindow = (Window) m_mainWindow; - wxDeleteWindowFromTable( xwindow ); - XDestroyWindow( wxGlobalDisplay(), xwindow ); - m_mainWindow = NULL; + if ( m_mainWindow ) + { + Window xwindow = (Window) m_mainWindow; + wxDeleteWindowFromTable( xwindow ); + XDestroyWindow( wxGlobalDisplay(), xwindow ); + m_mainWindow = NULL; + } } // --------------------------------------------------------------------------- @@ -387,9 +396,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; @@ -514,7 +526,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; @@ -567,7 +581,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; @@ -671,8 +685,8 @@ void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect) if (dx < 0) s_x += -dx; if (dy < 0) s_y += -dy; - if (dx > 0) d_x = dx + offset.x; - if (dy > 0) d_y = dy + offset.y; + if (dx > 0) d_x += dx + offset.x; + if (dy > 0) d_y += dy + offset.y; XCopyArea( xdisplay, xwindow, xwindow, xgc, s_x, s_y, w, h, d_x, d_y ); @@ -802,9 +816,11 @@ void wxWindowX11::DoScreenToClient(int *x, int *y) const Window thisWindow = (Window) m_clientWindow; Window childWindow; - int xx = *x; - int yy = *y; - XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow); + int xx = x ? *x : 0; + int yy = y ? *y : 0; + XTranslateCoordinates(display, rootWindow, thisWindow, + xx, yy, x ? x : &xx, y ? y : &yy, + &childWindow); } void wxWindowX11::DoClientToScreen(int *x, int *y) const @@ -814,9 +830,11 @@ void wxWindowX11::DoClientToScreen(int *x, int *y) const Window thisWindow = (Window) m_clientWindow; Window childWindow; - int xx = *x; - int yy = *y; - XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow); + int xx = x ? *x : 0; + int yy = y ? *y : 0; + XTranslateCoordinates(display, thisWindow, rootWindow, + xx, yy, x ? x : &xx, y ? y : &yy, + &childWindow); } @@ -1012,7 +1030,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. @@ -1040,7 +1058,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. @@ -1064,15 +1082,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()) { @@ -1087,7 +1106,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; @@ -1113,7 +1132,7 @@ void wxWindowX11::GetTextExtent(const wxString& string, XCharStruct overall; int slen = string.length(); - XTextExtents((XFontStruct*) pFontStruct, (char*) string.c_str(), slen, + XTextExtents((XFontStruct*) pFontStruct, (const char*) string.c_str(), slen, &direction, &ascent, &descent2, &overall); if ( x ) @@ -1192,12 +1211,12 @@ void wxWindowX11::SendEraseEvents() if (m_clearRegion.IsEmpty()) return; wxClientDC dc( (wxWindow*)this ); - dc.SetClippingRegion( m_clearRegion ); + dc.SetDeviceClippingRegion( m_clearRegion ); wxEraseEvent erase_event( GetId(), &dc ); erase_event.SetEventObject( this ); - if (!GetEventHandler()->ProcessEvent(erase_event) ) + if (!HandleWindowEvent(erase_event) ) { Display *xdisplay = wxGlobalDisplay(); Window xwindow = (Window) GetClientAreaWindow(); @@ -1223,7 +1242,7 @@ void wxWindowX11::SendPaintEvents() wxPaintEvent paint_event( GetId() ); paint_event.SetEventObject( this ); - GetEventHandler()->ProcessEvent( paint_event ); + HandleWindowEvent( paint_event ); m_updateRegion.Clear(); @@ -1252,7 +1271,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 ); @@ -1265,7 +1284,7 @@ void wxWindowX11::SendNcPaintEvents() wxNcPaintEvent nc_paint_event( GetId() ); nc_paint_event.SetEventObject( this ); - GetEventHandler()->ProcessEvent( nc_paint_event ); + HandleWindowEvent( nc_paint_event ); m_updateNcArea = false; } @@ -1286,7 +1305,7 @@ void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event) { wxSysColourChangedEvent event2; event.SetEventObject(win); - win->GetEventHandler()->ProcessEvent(event2); + win->HandleWindowEvent(event2); } node = node->GetNext(); @@ -1301,10 +1320,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)) - UpdateWindowUI(wxUPDATE_UI_FROMIDLE); + wxWindowBase::OnInternalIdle(); // Set the input focus if couldn't do it before if (m_needsInputFocus) @@ -1393,7 +1409,7 @@ void wxDeleteClientWindowFromTable(Window w) // X11-specific accessors // ---------------------------------------------------------------------------- -WXWindow wxWindowX11::GetMainWindow() const +WXWindow wxWindowX11::X11GetMainWindow() const { return m_mainWindow; } @@ -1407,7 +1423,10 @@ WXWindow wxWindowX11::GetClientAreaWindow() const // TranslateXXXEvent() functions // ---------------------------------------------------------------------------- -bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Window window, XEvent *xevent) +bool wxTranslateMouseEvent(wxMouseEvent& wxevent, + wxWindow *win, + Window WXUNUSED(window), + XEvent *xevent) { switch (XEventGetType(xevent)) { @@ -1456,6 +1475,23 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Window window, eventType = wxEVT_RIGHT_DOWN; button = 3; } + else if ( xevent->xbutton.button == Button4 || + xevent->xbutton.button == Button5 ) + { + // this is the same value as used under wxMSW + static const int WHEEL_DELTA = 120; + + eventType = wxEVT_MOUSEWHEEL; + button = xevent->xbutton.button; + + wxevent.m_linesPerAction = 3; + wxevent.m_columnsPerAction = 3; + wxevent.m_wheelDelta = WHEEL_DELTA; + + // Button 4 means mousewheel up, 5 means down + wxevent.m_wheelRotation = button == Button4 ? WHEEL_DELTA + : -WHEEL_DELTA; + } // check for a double click // TODO: where can we get this value from? @@ -1607,9 +1643,7 @@ bool wxWindowX11::SetForegroundColour(const wxColour& col) wxWindow *wxGetActiveWindow() { - // TODO - wxFAIL_MSG(wxT("Not implemented")); - return NULL; + return wxGetTopLevelParent(wxWindow::FindFocus()); } /* static */ @@ -1623,7 +1657,8 @@ wxWindow *wxWindowBase::GetCapture() // position. wxWindow* wxFindWindowAtPointer(wxPoint& pt) { - return wxFindWindowAtPoint(wxGetMousePosition()); + pt = wxGetMousePosition(); + return wxFindWindowAtPoint(pt); } void wxGetMouseState(int& rootX, int& rootY, unsigned& maskReturn) @@ -1694,8 +1729,14 @@ int wxNoOptimize::ms_count = 0; class wxWinModule : public wxModule { public: - bool OnInit(); - void OnExit(); + wxWinModule() + { + // we must be cleaned up before the display is closed + AddDependency(wxClassInfo::FindClass(wxT("wxX11DisplayModule"))); + } + + virtual bool OnInit(); + virtual void OnExit(); private: DECLARE_DYNAMIC_CLASS(wxWinModule) @@ -1706,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 );