X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d02cb44ecf4991eb6dd480d24852f5ef238a5317..fbfb3fb3c73c8cc70159a191c204424a37591334:/src/x11/window.cpp?ds=sidebyside diff --git a/src/x11/window.cpp b/src/x11/window.cpp index 28993a5310..75c41eb94c 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() // ============================================================================ @@ -100,12 +93,10 @@ void wxWindowX11::Init() // X11-specific m_mainWidget = (WXWindow) 0; - m_winCaptured = FALSE; - + m_needsInputFocus = FALSE; m_isShown = TRUE; m_isBeingDeleted = FALSE; - m_lastTS = 0; m_lastButton = 0; } @@ -121,26 +112,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,40 +123,63 @@ 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_foregroundColour = *wxBLACK; + m_foregroundColour.CalcPixel( (WXColormap) cm ); - Window window = XCreateSimpleWindow(wxGlobalDisplay(), parentWindow, - x, y, w, h, 0, - m_backgroundColour.AllocColour(wxGlobalDisplay()), - m_foregroundColour.AllocColour(wxGlobalDisplay())); + Window parentWindow = (Window) parent->GetMainWindow(); + + wxSize size2(size); + if (size2.x == -1) + size2.x = 100; + if (size2.y == -1) + size2.y = 100; + + wxPoint pos2(pos); + if (pos2.x == -1) + pos2.x = 100; + if (pos2.y == -1) + pos2.y = 100; + + Window xwindow = XCreateSimpleWindow( + xdisplay, parentWindow, + pos2.x, pos2.y, size2.x, size2.y, 0, + m_backgroundColour.GetPixel(), + m_backgroundColour.GetPixel() ); + + m_mainWidget = (WXWindow) xwindow; // Select event types wanted - XSelectInput(wxGlobalDisplay(), window, + XSelectInput( xdisplay, xwindow, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | PropertyChangeMask); - wxAddWindowToTable(window, (wxWindow*) this); + wxAddWindowToTable( xwindow, (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( xdisplay, xwindow ); // Without this, the cursor may not be restored properly (e.g. in splitter // sample). SetCursor(*wxSTANDARD_CURSOR); SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); - SetSize(pos.x, pos.y, size.x, size.y); + + // Set background to None which will prevent X11 from clearing the + // background comletely. + XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); + + // Don't call this, it can have nasty repercussions for composite controls, + // for example + // SetSize(pos.x, pos.y, size.x, size.y); return TRUE; } @@ -226,35 +221,31 @@ wxWindowX11::~wxWindowX11() void wxWindowX11::SetFocus() { -#if 0 - Window wMain = (Window) GetMainWidget(); - if (wMain) + Window xwindow = (Window) GetMainWindow(); + + wxCHECK_RET( xwindow, wxT("invalid window") ); + + if (wxWindowIsVisible(xwindow)) { - XSetInputFocus(wxGlobalDisplay(), wMain, RevertToParent, CurrentTime); - - XWMHints wmhints; - wmhints.flags = InputHint; - wmhints.input = True; - XSetWMHints(wxGlobalDisplay(), wMain, &wmhints) + XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime ); + m_needsInputFocus = FALSE; + } + else + { + m_needsInputFocus = TRUE; } -#endif } // Get the window with the focus wxWindow *wxWindowBase::FindFocus() { - Window wFocus = (Window) 0; + Window xfocus = (Window) 0; int revert = 0; - XGetInputFocus(wxGlobalDisplay(), & wFocus, & revert); - if (wFocus) + XGetInputFocus( wxGlobalDisplay(), &xfocus, &revert); + if (xfocus) { - wxWindow *win = NULL; - do - { - win = wxGetWindowFromTable(wFocus); - wFocus = wxGetWindowParent(wFocus); - } while (wFocus && !win); + wxWindow *win = wxGetWindowFromTable( xfocus ); return win; } @@ -274,17 +265,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,40 +304,109 @@ void wxWindowX11::Lower() void wxWindowX11::DoCaptureMouse() { - g_captureWindow = (wxWindow*) this; - if ( m_winCaptured ) + 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? - if (GetMainWindow()) + Window xwindow = (Window) GetMainWindow(); + + wxCHECK_RET( xwindow, wxT("invalid window") ); + + g_captureWindow = (wxWindow*) this; + + if (xwindow) { - int res = XGrabPointer(wxGlobalDisplay(), (Window) GetMainWindow(), + int res = XGrabPointer(wxGlobalDisplay(), xwindow, FALSE, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, /* cursor */ // TODO: This may need to be set to the cursor of this window + CurrentTime ); + + if (res != GrabSuccess) + { + 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(), + ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask, + FALSE, + GrabModeAsync, + GrabModeAsync, CurrentTime); - if (res == GrabSuccess) + if (res != GrabSuccess) { - m_winCaptured = TRUE; + wxLogDebug("Failed to grab keyboard."); + XUngrabPointer(wxGlobalDisplay(), CurrentTime); + XUngrabButton(wxGlobalDisplay(), AnyButton, AnyModifier, + (Window) GetMainWindow()); + return; } +#endif + + m_winCaptured = TRUE; } } void wxWindowX11::DoReleaseMouse() { g_captureWindow = NULL; + if ( !m_winCaptured ) return; - Window wMain = (Window)GetMainWindow(); + Window xwindow = (Window) GetMainWindow(); - // TODO: should we also call XUngrabButton, XUngrabKeyboard? - if ( wMain ) - XUngrabPointer(wxGlobalDisplay(), wMain); + if (xwindow) + { + XUngrabPointer( wxGlobalDisplay(), CurrentTime ); +#if 0 + XUngrabButton( wxGlobalDisplay(), AnyButton, AnyModifier, xwindow); + XUngrabKeyboard( wxGlobalDisplay(), CurrentTime ); +#endif + } + wxLogDebug("Ungrabbed pointer"); m_winCaptured = FALSE; } @@ -364,17 +430,19 @@ bool wxWindowX11::SetCursor(const wxCursor& cursor) return FALSE; } - wxCursor* cursor2 = NULL; + Window xwindow = (Window) GetMainWindow(); + + wxCHECK_MSG( xwindow, FALSE, wxT("invalid window") ); + + wxCursor cursorToUse; if (m_cursor.Ok()) - cursor2 = & m_cursor; + cursorToUse = m_cursor; else - cursor2 = wxSTANDARD_CURSOR; + cursorToUse = *wxSTANDARD_CURSOR; - WXDisplay *dpy = GetXDisplay(); - WXCursor x_cursor = cursor2->GetXCursor(dpy); + Cursor xcursor = (Cursor) cursorToUse.GetCursor(); - Window win = (Window) GetMainWindow(); - XDefineCursor((Display*) dpy, win, (Cursor) x_cursor); + XDefineCursor( (Display*) wxGlobalDisplay(), xwindow, xcursor ); return TRUE; } @@ -382,213 +450,59 @@ bool wxWindowX11::SetCursor(const wxCursor& cursor) // Coordinates relative to the window void wxWindowX11::WarpPointer (int x, int y) { - if (m_mainWidget) - XWarpPointer( wxGlobalDisplay(), None, (Window) m_mainWidget, 0, 0, 0, 0, x, y); -} - -// --------------------------------------------------------------------------- -// scrolling stuff -// --------------------------------------------------------------------------- + Window xwindow = (Window) GetMainWindow(); -int wxWindowX11::GetScrollPos(int orient) const -{ - return 0; + wxCHECK_RET( xwindow, wxT("invalid window") ); + + XWarpPointer( wxGlobalDisplay(), None, xwindow, 0, 0, 0, 0, x, y); } -// This now returns the whole range, not just the number of positions that we -// can scroll. -int wxWindowX11::GetScrollRange(int WXUNUSED(orient)) const +// Does a physical scroll +void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect) { - return 0; -} + Window xwindow = (Window) GetMainWindow(); -int wxWindowX11::GetScrollThumb(int orient) const -{ - // TODO - return 0; -} + wxCHECK_RET( xwindow, wxT("invalid window") ); -void wxWindowX11::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) -{ - // TODO -} + Display *xdisplay = wxGlobalDisplay(); -// 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 -} + GC xgc = XCreateGC( xdisplay, xwindow, 0, NULL ); + XSetGraphicsExposures( xdisplay, xgc, True ); -// Does a physical scroll -void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect) -{ - int x, y, w, h; - if (rect) + int cw = 0; + int ch = 0; + GetClientSize( &cw, &ch ); + int w = cw - abs(dx); + int h = ch - abs(dy); + + if ((h < 0) || (w < 0)) { - // Use specified rectangle - x = rect->x; y = rect->y; w = rect->width; h = rect->height; + Refresh(); } else { - // Use whole client area - x = 0; y = 0; - GetClientSize(& w, & h); - } - - wxNode *cnode = m_children.First(); - while (cnode) - { - wxWindow *child = (wxWindow*) cnode->Data(); - int sx = 0; - int sy = 0; - child->GetSize( &sx, &sy ); - wxPoint pos( child->GetPosition() ); - child->SetSize( pos.x + dx, pos.y + dy, sx, sy, wxSIZE_ALLOW_MINUS_ONE ); - cnode = cnode->Next(); - } - - int x1 = (dx >= 0) ? x : x - dx; - int y1 = (dy >= 0) ? y : y - dy; - int w1 = w - abs(dx); - int h1 = h - abs(dy); - int x2 = (dx >= 0) ? x + dx : x; - int y2 = (dy >= 0) ? y + dy : y; - - wxClientDC dc((wxWindow*) this); - - dc.SetLogicalFunction (wxCOPY); - - Window window = (Window) GetMainWindow(); - Display* display = wxGlobalDisplay(); - - XCopyArea(display, window, window, (GC) dc.GetGC(), - x1, y1, w1, h1, x2, y2); - - dc.SetAutoSetting(TRUE); - wxBrush brush(GetBackgroundColour(), wxSOLID); - dc.SetBrush(brush); // FIXME: needed? - - // We'll add rectangles to the list of update rectangles according to which - // bits we've exposed. - wxList updateRects; - - if (dx > 0) - { - wxRect *rect = new wxRect; - rect->x = x; - rect->y = y; - rect->width = dx; - rect->height = h; - - XFillRectangle(display, window, - (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); - - rect->x = rect->x; - rect->y = rect->y; - rect->width = rect->width; - rect->height = rect->height; - - updateRects.Append((wxObject*) rect); - } - else if (dx < 0) - { - wxRect *rect = new wxRect; - - rect->x = x + w + dx; - rect->y = y; - rect->width = -dx; - rect->height = h; - - XFillRectangle(display, window, - (GC) dc.GetGC(), rect->x, rect->y, rect->width, - rect->height); - - rect->x = rect->x; - rect->y = rect->y; - rect->width = rect->width; - rect->height = rect->height; - - updateRects.Append((wxObject*) rect); - } - if (dy > 0) - { - wxRect *rect = new wxRect; - - rect->x = x; - rect->y = y; - rect->width = w; - rect->height = dy; - - XFillRectangle(display, window, - (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); - - rect->x = rect->x; - rect->y = rect->y; - rect->width = rect->width; - rect->height = rect->height; - - updateRects.Append((wxObject*) rect); - } - else if (dy < 0) - { - wxRect *rect = new wxRect; - - rect->x = x; - rect->y = y + h + dy; - rect->width = w; - rect->height = -dy; - - XFillRectangle(display, window, - (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); - - rect->x = rect->x; - rect->y = rect->y; - rect->width = rect->width; - rect->height = rect->height; - - updateRects.Append((wxObject*) rect); - } - dc.SetBrush(wxNullBrush); - - // Now send expose events - - wxNode* node = updateRects.First(); - while (node) - { - wxRect* rect = (wxRect*) node->Data(); - XExposeEvent event; - - event.type = Expose; - event.display = display; - event.send_event = True; - event.window = window; - - event.x = rect->x; - event.y = rect->y; - event.width = rect->width; - event.height = rect->height; - - event.count = 0; - - XSendEvent(display, window, False, ExposureMask, (XEvent *)&event); - - node = node->Next(); - - } - - // Delete the update rects - node = updateRects.First(); - while (node) - { - wxRect* rect = (wxRect*) node->Data(); - delete rect; - node = node->Next(); + int s_x = 0; + int s_y = 0; + if (dx < 0) s_x = -dx; + if (dy < 0) s_y = -dy; + int d_x = 0; + int d_y = 0; + if (dx > 0) d_x = dx; + if (dy > 0) d_y = dy; + + XCopyArea( xdisplay, xwindow, xwindow, xgc, s_x, s_y, w, h, d_x, d_y ); + + wxRect rect; + if (dx < 0) rect.x = cw+dx; else rect.x = 0; + if (dy < 0) rect.y = ch+dy; else rect.y = 0; + if (dy != 0) rect.width = cw; else rect.width = abs(dx); + if (dx != 0) rect.height = ch; else rect.height = abs(dy); + + m_updateRegion.Union( rect ); + m_clearRegion.Union( rect ); } - // TODO - - // XmUpdateDisplay((Widget) GetMainWidget()); + XFreeGC( xdisplay, xgc ); } // --------------------------------------------------------------------------- @@ -635,18 +549,19 @@ bool wxWindowX11::PreResize() // Get total size void wxWindowX11::DoGetSize(int *x, int *y) const { - Window window = (Window) m_mainWidget; - if (window) - { - XWindowAttributes attr; - Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); - wxASSERT(status); + Window xwindow = (Window) GetMainWindow(); + + wxCHECK_RET( xwindow, wxT("invalid window") ); + + XSync(wxGlobalDisplay(), False); + XWindowAttributes attr; + Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); + wxASSERT(status); - if (status) - { - *x = attr.width /* + 2*m_borderSize */ ; - *y = attr.height /* + 2*m_borderSize */ ; - } + if (status) + { + *x = attr.width /* + 2*m_borderSize */ ; + *y = attr.height /* + 2*m_borderSize */ ; } } @@ -655,6 +570,7 @@ void wxWindowX11::DoGetPosition(int *x, int *y) const Window window = (Window) m_mainWidget; if (window) { + XSync(wxGlobalDisplay(), False); XWindowAttributes attr; Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); wxASSERT(status); @@ -708,8 +624,9 @@ void wxWindowX11::DoGetClientSize(int *x, int *y) const if (window) { + XSync(wxGlobalDisplay(), False); XWindowAttributes attr; - Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); + Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr ); wxASSERT(status); if (status) @@ -726,32 +643,45 @@ void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) return; XWindowChanges windowChanges; + windowChanges.x = 0; + windowChanges.y = 0; + windowChanges.width = 0; + windowChanges.height = 0; + windowChanges.stack_mode = 0; int valueMask = 0; 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; } if (width != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) { windowChanges.width = width /* - m_borderSize*2 */; + if (windowChanges.width == 0) + windowChanges.width = 1; valueMask |= CWWidth; } if (height != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) { windowChanges.height = height /* -m_borderSize*2*/; + if (windowChanges.height == 0) + windowChanges.height = 1; valueMask |= CWHeight; } - AdjustForParentClientOrigin( x, y, sizeFlags); XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(), valueMask, & windowChanges); + XSync(wxGlobalDisplay(), False); } void wxWindowX11::DoSetClientSize(int width, int height) @@ -774,6 +704,7 @@ void wxWindowX11::DoSetClientSize(int width, int height) } XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(), valueMask, & windowChanges); + XSync(wxGlobalDisplay(), False); } // For implementation purposes - sometimes decorations make the client area @@ -869,13 +800,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 +817,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,22 +862,20 @@ 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() { if (!m_updateRegion.IsEmpty()) { + // Actually send erase and paint events. X11SendPaintEvents(); } } @@ -974,10 +902,17 @@ void wxWindowX11::X11SendPaintEvents() if (!GetEventHandler()->ProcessEvent(erase_event)) { + printf( "Hallo!\n" ); + Window xwindow = (Window) GetMainWindow(); + Display *xdisplay = wxGlobalDisplay(); + GC xgc = XCreateGC( xdisplay, xwindow, 0, NULL ); + XSetFillStyle( xdisplay, xgc, FillSolid ); + XSetForeground( xdisplay, xgc, m_backgroundColour.GetPixel() ); wxRegionIterator upd( m_clearRegion ); while (upd) { - // XClearArea( ... , upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() ); + XFillRectangle( xdisplay, xwindow, xgc, + upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() ); upd ++; } } @@ -992,6 +927,8 @@ void wxWindowX11::X11SendPaintEvents() paint_event.SetEventObject( this ); GetEventHandler()->ProcessEvent( paint_event ); + m_updateRegion.Clear(); + m_clipPaintRegion = FALSE; } @@ -1018,11 +955,18 @@ 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(); + + // Set the input focus if couldn't do it before + if (m_needsInputFocus) + SetFocus(); } // ---------------------------------------------------------------------------- @@ -1082,79 +1026,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 // ---------------------------------------------------------------------------- @@ -1328,73 +1199,28 @@ bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Window WXUNUSED(win // Colour stuff // ---------------------------------------------------------------------------- -#if 0 - -#define YAllocColor XAllocColor -XColor g_itemColors[5]; -int wxComputeColours (Display *display, wxColour * back, wxColour * fore) +bool wxWindowX11::SetBackgroundColour(const wxColour& col) { - int result; - static XmColorProc colorProc; + wxWindowBase::SetBackgroundColour(col); - result = wxNO_COLORS; - - if (back) - { - g_itemColors[0].red = (((long) back->Red ()) << 8); - g_itemColors[0].green = (((long) back->Green ()) << 8); - g_itemColors[0].blue = (((long) back->Blue ()) << 8); - g_itemColors[0].flags = DoRed | DoGreen | DoBlue; - if (colorProc == (XmColorProc) NULL) - { - // Get a ptr to the actual function - colorProc = XmSetColorCalculation ((XmColorProc) NULL); - // And set it back to motif. - XmSetColorCalculation (colorProc); - } - (*colorProc) (&g_itemColors[wxBACK_INDEX], - &g_itemColors[wxFORE_INDEX], - &g_itemColors[wxSELE_INDEX], - &g_itemColors[wxTOPS_INDEX], - &g_itemColors[wxBOTS_INDEX]); - result = wxBACK_COLORS; - } - if (fore) - { - g_itemColors[wxFORE_INDEX].red = (((long) fore->Red ()) << 8); - g_itemColors[wxFORE_INDEX].green = (((long) fore->Green ()) << 8); - g_itemColors[wxFORE_INDEX].blue = (((long) fore->Blue ()) << 8); - g_itemColors[wxFORE_INDEX].flags = DoRed | DoGreen | DoBlue; - if (result == wxNO_COLORS) - result = wxFORE_COLORS; - } + Display *xdisplay = (Display*) wxGlobalDisplay(); + int xscreen = DefaultScreen( xdisplay ); + Colormap cm = DefaultColormap( xdisplay, xscreen ); - Display *dpy = display; - Colormap cmap = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dpy); - - if (back) - { - /* 5 Colours to allocate */ - for (int i = 0; i < 5; i++) - if (!YAllocColor (dpy, cmap, &g_itemColors[i])) - result = wxNO_COLORS; - } - else if (fore) - { - /* Only 1 colour to allocate */ - if (!YAllocColor (dpy, cmap, &g_itemColors[wxFORE_INDEX])) - result = wxNO_COLORS; - } - - return (result); + m_backgroundColour.CalcPixel( (WXColormap) cm ); + + if (!GetMainWindow()) + return FALSE; -} -#endif +/* + XSetWindowAttributes attrib; + attrib.background_pixel = colour.GetPixel(); -bool wxWindowX11::SetBackgroundColour(const wxColour& col) -{ - if ( !wxWindowBase::SetBackgroundColour(col) ) - return FALSE; + XChangeWindowAttributes(wxGlobalDisplay(), + (Window) GetMainWindow(), + CWBackPixel, + & attrib); +*/ return TRUE; }