X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d02cb44ecf4991eb6dd480d24852f5ef238a5317..a1de932df0cf2c181d927d7de27d3465719c9b93:/src/x11/window.cpp diff --git a/src/x11/window.cpp b/src/x11/window.cpp index 28993a5310..89ba9d056a 100644 --- a/src/x11/window.cpp +++ b/src/x11/window.cpp @@ -49,12 +49,6 @@ #include -// ---------------------------------------------------------------------------- -// constants -// ---------------------------------------------------------------------------- - -static const int SCROLL_MARGIN = 4; - // ---------------------------------------------------------------------------- // global variables for this module // ---------------------------------------------------------------------------- @@ -74,11 +68,10 @@ static wxWindow* g_captureWindow = NULL; // event tables // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxWindowX11, wxWindowBase) +IMPLEMENT_ABSTRACT_CLASS(wxWindowX11, wxWindowBase) BEGIN_EVENT_TABLE(wxWindowX11, wxWindowBase) EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged) - EVT_IDLE(wxWindowX11::OnIdle) END_EVENT_TABLE() // ============================================================================ @@ -121,26 +114,7 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, CreateBase(parent, id, pos, size, style, wxDefaultValidator, name); - if (parent) - parent->AddChild(this); - - m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); - m_foregroundColour = *wxBLACK; - -#if 0 - // TODO: How to create more interesting borders? - // Will presumably have to create multiple windows. - if (style & wxSIMPLE_BORDER) - { - m_borderSize = 1; - } else if (style & wxSUNKEN_BORDER) - { - m_borderSize = 1; - } else if (style & wxRAISED_BORDER) - { - m_borderSize = 1; - } -#endif + parent->AddChild(this); int w = size.GetWidth(); int h = size.GetHeight(); @@ -151,18 +125,27 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, if (x == -1) x = 0; if (y == -1) y = 0; - int screen = DefaultScreen(wxGlobalDisplay()); + Display *xdisplay = (Display*) wxGlobalDisplay(); + int xscreen = DefaultScreen( xdisplay ); + Colormap cm = DefaultColormap( xdisplay, xscreen ); - Window parentWindow; - if (parent) - parentWindow = (Window) parent->GetMainWindow(); - else - parentWindow = RootWindow(wxGlobalDisplay(), screen); + m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); + m_backgroundColour.CalcPixel( (WXColormap) cm ); + m_hasBgCol = TRUE; + + m_foregroundColour = *wxBLACK; + m_foregroundColour.CalcPixel( (WXColormap) cm ); + + + Window parentWindow = (Window) parent->GetMainWindow(); - Window window = XCreateSimpleWindow(wxGlobalDisplay(), parentWindow, - x, y, w, h, 0, - m_backgroundColour.AllocColour(wxGlobalDisplay()), - m_foregroundColour.AllocColour(wxGlobalDisplay())); + Window window = XCreateSimpleWindow( + xdisplay, parentWindow, + x, y, w, h, 0, + m_backgroundColour.GetPixel(), + m_backgroundColour.GetPixel() ); + + m_mainWidget = (WXWindow) window; // Select event types wanted XSelectInput(wxGlobalDisplay(), window, @@ -173,12 +156,9 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, wxAddWindowToTable(window, (wxWindow*) this); - // If a subwindow, show. -// if (parent && !parent->IsKindOf(CLASSINFO(wxTopLevelWindowX11)) && parent->IsShown()) - { - m_isShown = TRUE; - XMapWindow(wxGlobalDisplay(), window); - } + // Is a subwindow, so map immediately + m_isShown = TRUE; + XMapWindow(wxGlobalDisplay(), window); // Without this, the cursor may not be restored properly (e.g. in splitter // sample). @@ -226,8 +206,7 @@ wxWindowX11::~wxWindowX11() void wxWindowX11::SetFocus() { -#if 0 - Window wMain = (Window) GetMainWidget(); + Window wMain = (Window) GetMainWindow(); if (wMain) { XSetInputFocus(wxGlobalDisplay(), wMain, RevertToParent, CurrentTime); @@ -235,9 +214,8 @@ void wxWindowX11::SetFocus() XWMHints wmhints; wmhints.flags = InputHint; wmhints.input = True; - XSetWMHints(wxGlobalDisplay(), wMain, &wmhints) + XSetWMHints(wxGlobalDisplay(), wMain, &wmhints); } -#endif } // Get the window with the focus @@ -274,17 +252,23 @@ bool wxWindowX11::Enable(bool enable) bool wxWindowX11::Show(bool show) { - if ( !wxWindowBase::Show(show) ) - return FALSE; + wxWindowBase::Show(show); Window xwin = (Window) GetXWindow(); Display *xdisp = (Display*) GetXDisplay(); if (show) { + wxString msg; + msg.Printf("Mapping window of type %s", GetClassInfo()->GetClassName()); + wxLogDebug(msg); XMapWindow(xdisp, xwin); + XSync(xdisp, False); } else { + wxString msg; + msg.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName()); + wxLogDebug(msg); XUnmapWindow(xdisp, xwin); } @@ -307,11 +291,21 @@ void wxWindowX11::Lower() void wxWindowX11::DoCaptureMouse() { - g_captureWindow = (wxWindow*) this; + if ((g_captureWindow != NULL) && (g_captureWindow != this)) + { + wxASSERT_MSG(FALSE, "Trying to capture before mouse released."); + + // Core dump now + int *tmp = NULL; + (*tmp) = 1; + return; + } + if ( m_winCaptured ) return; - // TODO: should we also call XGrabButton, XGrabKeyboard? + g_captureWindow = (wxWindow*) this; + if (GetMainWindow()) { int res = XGrabPointer(wxGlobalDisplay(), (Window) GetMainWindow(), @@ -323,10 +317,62 @@ void wxWindowX11::DoCaptureMouse() None, /* cursor */ // TODO: This may need to be set to the cursor of this window CurrentTime); - if (res == GrabSuccess) + if (res != GrabSuccess) { - m_winCaptured = TRUE; + wxString msg; + msg.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName()); + wxLogDebug(msg); + if (res == GrabNotViewable) + { + wxLogDebug("This is not a viewable window - perhaps not shown yet?"); + } + g_captureWindow = NULL; + return; } + wxLogDebug("Grabbed pointer"); + +#if 0 + res = XGrabButton(wxGlobalDisplay(), AnyButton, AnyModifier, + (Window) GetMainWindow(), + FALSE, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + GrabModeAsync, + GrabModeAsync, + None, + None); + + if (res != GrabSuccess) + { + wxLogDebug("Failed to grab mouse buttons."); + XUngrabPointer(wxGlobalDisplay(), CurrentTime); + return; + } +#endif + +#if 0 + res = XGrabKeyboard(wxGlobalDisplay(), (Window) GetMainWindow(), +#if 0 + ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask, +#else + FALSE, +#endif + GrabModeAsync, + GrabModeAsync, + CurrentTime); + + if (res != GrabSuccess) + { + wxLogDebug("Failed to grab keyboard."); + XUngrabPointer(wxGlobalDisplay(), CurrentTime); +#if 0 + XUngrabButton(wxGlobalDisplay(), AnyButton, AnyModifier, + (Window) GetMainWindow()); +#endif + return; + } +#endif + + m_winCaptured = TRUE; } } @@ -338,9 +384,16 @@ void wxWindowX11::DoReleaseMouse() Window wMain = (Window)GetMainWindow(); - // TODO: should we also call XUngrabButton, XUngrabKeyboard? if ( wMain ) + { XUngrabPointer(wxGlobalDisplay(), wMain); +#if 0 + XUngrabButton(wxGlobalDisplay(), AnyButton, AnyModifier, + wMain); + XUngrabKeyboard(wxGlobalDisplay(), CurrentTime); +#endif + } + wxLogDebug("Ungrabbed pointer"); m_winCaptured = FALSE; } @@ -370,11 +423,10 @@ bool wxWindowX11::SetCursor(const wxCursor& cursor) else cursor2 = wxSTANDARD_CURSOR; - WXDisplay *dpy = GetXDisplay(); - WXCursor x_cursor = cursor2->GetXCursor(dpy); + WXCursor x_cursor = cursor2->GetCursor(); Window win = (Window) GetMainWindow(); - XDefineCursor((Display*) dpy, win, (Cursor) x_cursor); + XDefineCursor((Display*) wxGlobalDisplay(), win, (Cursor) x_cursor); return TRUE; } @@ -386,43 +438,10 @@ void wxWindowX11::WarpPointer (int x, int y) XWarpPointer( wxGlobalDisplay(), None, (Window) m_mainWidget, 0, 0, 0, 0, x, y); } -// --------------------------------------------------------------------------- -// scrolling stuff -// --------------------------------------------------------------------------- - -int wxWindowX11::GetScrollPos(int orient) const -{ - return 0; -} - -// This now returns the whole range, not just the number of positions that we -// can scroll. -int wxWindowX11::GetScrollRange(int WXUNUSED(orient)) const -{ - return 0; -} - -int wxWindowX11::GetScrollThumb(int orient) const -{ - // TODO - return 0; -} - -void wxWindowX11::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) -{ - // TODO -} - -// New function that will replace some of the above. -void wxWindowX11::SetScrollbar(int WXUNUSED(orient), int WXUNUSED(pos), int WXUNUSED(thumbVisible), - int WXUNUSED(range), bool WXUNUSED(refresh)) -{ - // TODO -} - // Does a physical scroll void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect) { +#if 0 int x, y, w, h; if (rect) { @@ -585,10 +604,7 @@ void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect) delete rect; node = node->Next(); } - - // TODO - - // XmUpdateDisplay((Widget) GetMainWidget()); +#endif } // --------------------------------------------------------------------------- @@ -709,7 +725,7 @@ void wxWindowX11::DoGetClientSize(int *x, int *y) const if (window) { XWindowAttributes attr; - Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); + Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr ); wxASSERT(status); if (status) @@ -730,11 +746,15 @@ void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) { + int yy = 0; + AdjustForParentClientOrigin( x, yy, sizeFlags); windowChanges.x = x; valueMask |= CWX; } if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) { + int xx = 0; + AdjustForParentClientOrigin( xx, y, sizeFlags); windowChanges.y = y; valueMask |= CWY; } @@ -748,7 +768,6 @@ void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) windowChanges.height = height /* -m_borderSize*2*/; valueMask |= CWHeight; } - AdjustForParentClientOrigin( x, y, sizeFlags); XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(), valueMask, & windowChanges); @@ -869,13 +888,12 @@ void wxWindowX11::GetTextExtent(const wxString& string, int *descent, int *externalLeading, const wxFont *theFont) const { - wxFont *fontToUse = (wxFont *)theFont; - if (!fontToUse) - fontToUse = (wxFont *) & m_font; + wxFont fontToUse = m_font; + if (theFont) fontToUse = *theFont; - wxCHECK_RET( fontToUse->Ok(), "valid window font needed" ); - - WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay()); + wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") ); + + WXFontStructPtr pFontStruct = fontToUse.GetFontStruct(1.0, GetXDisplay()); int direction, ascent, descent2; XCharStruct overall; @@ -887,7 +905,7 @@ void wxWindowX11::GetTextExtent(const wxString& string, &ascent, &descent2, &overall); #endif - XTextExtents((XFontStruct*) pFontStruct, string, slen, + XTextExtents((XFontStruct*) pFontStruct, string.c_str(), slen, &direction, &ascent, &descent2, &overall); if ( x ) @@ -932,16 +950,13 @@ void wxWindowX11::Refresh(bool eraseBack, const wxRect *rect) } else { - int height,width; - GetSize( &width, &height ); + int height,width; + GetSize( &width, &height ); // Schedule for later Updating in ::Update() or ::OnInternalIdle(). m_updateRegion.Clear(); m_updateRegion.Union( 0, 0, width, height ); } - - // Actually don't schedule yet.. - Update(); } void wxWindowX11::Update() @@ -964,7 +979,7 @@ void wxWindowX11::X11SendPaintEvents() { m_clipPaintRegion = TRUE; - if (!m_clearRegion.IsEmpty()) + // if (!m_clearRegion.IsEmpty()) { wxWindowDC dc( (wxWindow*)this ); dc.SetClippingRegion( m_clearRegion ); @@ -977,7 +992,8 @@ void wxWindowX11::X11SendPaintEvents() wxRegionIterator upd( m_clearRegion ); while (upd) { - // XClearArea( ... , upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() ); + XClearArea( wxGlobalDisplay(), (Window) m_mainWidget, + upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight(), False ); upd ++; } } @@ -992,6 +1008,8 @@ void wxWindowX11::X11SendPaintEvents() paint_event.SetEventObject( this ); GetEventHandler()->ProcessEvent( paint_event ); + m_updateRegion.Clear(); + m_clipPaintRegion = FALSE; } @@ -1018,8 +1036,11 @@ void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event) } } -void wxWindowX11::OnIdle(wxIdleEvent& WXUNUSED(event)) +void wxWindowX11::OnInternalIdle() { + // Update invalidated regions. + Update(); + // This calls the UI-update mechanism (querying windows for // menu/toolbar/control state information) UpdateWindowUI(); @@ -1082,79 +1103,6 @@ WXWindow wxWindowX11::GetMainWindow() const return m_mainWidget; } -// ---------------------------------------------------------------------------- -// callbacks -// ---------------------------------------------------------------------------- - -// TODO: implement wxWindow scrollbar, presumably using wxScrollBar -#if 0 -static void wxScrollBarCallback(Widget scrollbar, - XtPointer clientData, - XmScrollBarCallbackStruct *cbs) -{ - wxWindow *win = wxGetWindowFromTable(scrollbar); - int orientation = (int) clientData; - - wxEventType eventType = wxEVT_NULL; - switch (cbs->reason) - { - case XmCR_INCREMENT: - { - eventType = wxEVT_SCROLLWIN_LINEDOWN; - break; - } - case XmCR_DECREMENT: - { - eventType = wxEVT_SCROLLWIN_LINEUP; - break; - } - case XmCR_DRAG: - { - eventType = wxEVT_SCROLLWIN_THUMBTRACK; - break; - } - case XmCR_VALUE_CHANGED: - { - eventType = wxEVT_SCROLLWIN_THUMBRELEASE; - break; - } - case XmCR_PAGE_INCREMENT: - { - eventType = wxEVT_SCROLLWIN_PAGEDOWN; - break; - } - case XmCR_PAGE_DECREMENT: - { - eventType = wxEVT_SCROLLWIN_PAGEUP; - break; - } - case XmCR_TO_TOP: - { - eventType = wxEVT_SCROLLWIN_TOP; - break; - } - case XmCR_TO_BOTTOM: - { - eventType = wxEVT_SCROLLWIN_BOTTOM; - break; - } - default: - { - // Should never get here - wxFAIL_MSG("Unknown scroll event."); - break; - } - } - - wxScrollWinEvent event(eventType, - cbs->value, - ((orientation == XmHORIZONTAL) ? - wxHORIZONTAL : wxVERTICAL)); - event.SetEventObject( win ); - win->GetEventHandler()->ProcessEvent(event); -} -#endif - // ---------------------------------------------------------------------------- // TranslateXXXEvent() functions // ---------------------------------------------------------------------------- @@ -1393,9 +1341,26 @@ int wxComputeColours (Display *display, wxColour * back, wxColour * fore) bool wxWindowX11::SetBackgroundColour(const wxColour& col) { - if ( !wxWindowBase::SetBackgroundColour(col) ) + wxWindowBase::SetBackgroundColour(col); + + if (!GetMainWindow()) return FALSE; + Display *xdisplay = (Display*) wxGlobalDisplay(); + int xscreen = DefaultScreen( xdisplay ); + Colormap cm = DefaultColormap( xdisplay, xscreen ); + + wxColour colour( col ); + colour.CalcPixel( (WXColormap) cm ); + + XSetWindowAttributes attrib; + attrib.background_pixel = colour.GetPixel(); + + XChangeWindowAttributes(wxGlobalDisplay(), + (Window) GetMainWindow(), + CWBackPixel, + & attrib); + return TRUE; }