From 0d1dff0172e94487c4aa2d830c714f93be73c7ec Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 13 Feb 2002 16:43:18 +0000 Subject: [PATCH] wxX11: INtroduced OnInternalIdle as per wxGTK so that users cannot as easily lill the internals. Fixed pop-up transient window. Removed some #if 0 here and there. Made refresh code work in idle instead of directly. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14176 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/x11/window.h | 11 ++++++++--- src/gtk/app.cpp | 3 ++- src/gtk1/app.cpp | 3 ++- src/x11/app.cpp | 40 ++++++++++++++-------------------------- src/x11/dcclient.cpp | 11 +++-------- src/x11/popupwin.cpp | 7 +++---- src/x11/window.cpp | 34 ++++++++++++++-------------------- 7 files changed, 46 insertions(+), 63 deletions(-) diff --git a/include/wx/x11/window.h b/include/wx/x11/window.h index 6693eaf517..f79d378d50 100644 --- a/include/wx/x11/window.h +++ b/include/wx/x11/window.h @@ -134,10 +134,15 @@ public: // smaller virtual wxPoint GetClientAreaOrigin() const; -protected: - // event handlers (not virtual by design) - void OnIdle(wxIdleEvent& event); + // I don't want users to override what's done in idle so everything that + // has to be done in idle time in order for wxX11 to work is done in + // OnInternalIdle + virtual void OnInternalIdle(); + + // For compatibility across platforms (not in event table) + void OnIdle(wxIdleEvent& WXUNUSED(event)) {} +protected: // Makes an adjustment to the window position (for example, a frame that has // a toolbar that it manages itself). virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags); diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 6b0b5276df..b25fce3b1c 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -515,7 +515,8 @@ bool wxApp::SendIdleEvents( wxWindow* win ) node = node->Next(); } - return needMore ; + + return needMore; } int wxApp::MainLoop() diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp index 6b0b5276df..b25fce3b1c 100644 --- a/src/gtk1/app.cpp +++ b/src/gtk1/app.cpp @@ -515,7 +515,8 @@ bool wxApp::SendIdleEvents( wxWindow* win ) node = node->Next(); } - return needMore ; + + return needMore; } int wxApp::MainLoop() diff --git a/src/x11/app.cpp b/src/x11/app.cpp index 6b85093ad0..62cb336b78 100644 --- a/src/x11/app.cpp +++ b/src/x11/app.cpp @@ -446,12 +446,9 @@ void wxApp::ProcessXEvent(WXEvent* _event) { if (win) { + // Schedule update for later win->GetUpdateRegion().Union( event->xexpose.x, event->xexpose.y, event->xexpose.width, event->xexpose.height); - if (event->xexpose.count == 0) - { - win->X11SendPaintEvents(); // TODO let an idle handler do that - } } return; @@ -547,41 +544,28 @@ void wxApp::HandlePropertyChange(WXEvent *event) void wxApp::OnIdle(wxIdleEvent& event) { - static bool inOnIdle = FALSE; + static bool s_inOnIdle = FALSE; // Avoid recursion (via ProcessEvent default case) - if (inOnIdle) + if (s_inOnIdle) return; - inOnIdle = TRUE; - - // If there are pending events, we must process them: pending events - // are either events to the threads other than main or events posted - // with wxPostEvent() functions - // GRG: I have moved this here so that all pending events are processed - // before starting to delete any objects. This behaves better (in - // particular, wrt wxPostEvent) and is coherent with wxGTK's current - // behaviour. Also removed the '#if wxUSE_THREADS' around it. - // Changed Mar/2000 before 2.1.14 + s_inOnIdle = TRUE; - // Flush pending events. + // Resend in the main thread events which have been prepared in other + // threads ProcessPendingEvents(); - // 'Garbage' collection of windows deleted with Close(). + // 'Garbage' collection of windows deleted with Close() DeletePendingObjects(); - // flush the logged messages if any - wxLog *pLog = wxLog::GetActiveTarget(); - if ( pLog != NULL && pLog->HasPendingMessages() ) - pLog->Flush(); - // Send OnIdle events to all windows bool needMore = SendIdleEvents(); if (needMore) event.RequestMore(TRUE); - inOnIdle = FALSE; + s_inOnIdle = FALSE; } void wxWakeUpIdle() @@ -615,7 +599,10 @@ bool wxApp::SendIdleEvents(wxWindow* win) wxIdleEvent event; event.SetEventObject(win); - win->ProcessEvent(event); + + win->GetEventHandler()->ProcessEvent(event); + + win->OnInternalIdle(); if (event.MoreRequested()) needMore = TRUE; @@ -629,7 +616,8 @@ bool wxApp::SendIdleEvents(wxWindow* win) node = node->Next(); } - return needMore ; + + return needMore; } void wxApp::DeletePendingObjects() diff --git a/src/x11/dcclient.cpp b/src/x11/dcclient.cpp index c00bb29e35..286375fa0e 100644 --- a/src/x11/dcclient.cpp +++ b/src/x11/dcclient.cpp @@ -225,7 +225,6 @@ void wxWindowDC::SetUpDC() m_textGC = (WXGC*) wxGetPoolGC( (Window) m_window, wxTEXT_SCREEN ); m_bgGC = (WXGC*) wxGetPoolGC( (Window) m_window, wxBG_SCREEN ); } -#if 0 else if (m_isMemDC && (((wxMemoryDC*)this)->m_selected.GetDepth() == 1)) { @@ -234,7 +233,6 @@ void wxWindowDC::SetUpDC() m_textGC = (WXGC*) wxGetPoolGC( (Window) m_window, wxTEXT_MONO ); m_bgGC = (WXGC*) wxGetPoolGC( (Window) m_window, wxBG_MONO ); } -#endif else { m_penGC = (WXGC*) wxGetPoolGC( (Window) m_window, wxPEN_COLOUR ); @@ -342,8 +340,6 @@ void wxWindowDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) CalcBoundingBox(x1, y1); CalcBoundingBox(x2, y2); - - wxLogDebug("Drawing line at %d, %d -> %d, %d", XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) ); } } @@ -751,7 +747,6 @@ void wxWindowDC::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord h CalcBoundingBox( x, y ); CalcBoundingBox( x + width, y + height ); - wxLogDebug("Drawing rectangle at %d, %d (%dx%d)", x, y, width, height); } void wxWindowDC::DoDrawRoundedRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius ) @@ -1535,14 +1530,14 @@ void wxWindowDC::SetBrush( const wxBrush &brush ) else { XSetFillStyle( (Display*) m_display, (GC) m_brushGC, FillStippled ); -// XSetStipple( (Display*) m_display, (GC) m_brushGC, (Pixmap) m_brush.GetStipple()->GetBitmap() ); + XSetStipple( (Display*) m_display, (GC) m_brushGC, (Pixmap) m_brush.GetStipple()->GetBitmap() ); } } if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) { XSetFillStyle( (Display*) m_display, (GC) m_textGC, FillOpaqueStippled ); -// XSetStipple( (Display*) m_display, (GC) m_textGC, (Pixmap) m_brush.GetStipple()->GetMask()->GetBitmap() ); + XSetStipple( (Display*) m_display, (GC) m_textGC, (Pixmap) m_brush.GetStipple()->GetMask()->GetBitmap() ); } if (IS_HATCH(m_brush.GetStyle())) @@ -1586,7 +1581,7 @@ void wxWindowDC::SetBackground( const wxBrush &brush ) else { XSetFillStyle( (Display*) m_display, (GC) m_bgGC, FillStippled ); -// XSetStipple( (Display*) m_display, (GC) m_bgGC, (Pixmap) m_backgroundBrush.GetStipple()->GetBitmap() ); + XSetStipple( (Display*) m_display, (GC) m_bgGC, (Pixmap) m_backgroundBrush.GetStipple()->GetBitmap() ); } } diff --git a/src/x11/popupwin.cpp b/src/x11/popupwin.cpp index 4c62f44df5..debfbf577b 100644 --- a/src/x11/popupwin.cpp +++ b/src/x11/popupwin.cpp @@ -62,13 +62,12 @@ bool wxPopupWindow::Create( wxWindow *parent, int style ) long xattributes_mask = CWOverrideRedirect | + CWSaveUnder | CWBorderPixel | CWBackPixel; xattributes.background_pixel = BlackPixel( xdisplay, xscreen ); xattributes.border_pixel = BlackPixel( xdisplay, xscreen ); - - // Trying True in order to stop WM decorating it - //xattributes.override_redirect = False; - xattributes.override_redirect = TRUE; + xattributes.override_redirect = True; + xattributes.save_under = True; Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y, 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); diff --git a/src/x11/window.cpp b/src/x11/window.cpp index 1983d4bb41..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 // ---------------------------------------------------------------------------- @@ -78,7 +72,6 @@ IMPLEMENT_ABSTRACT_CLASS(wxWindowX11, wxWindowBase) BEGIN_EVENT_TABLE(wxWindowX11, wxWindowBase) EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged) - EVT_IDLE(wxWindowX11::OnIdle) END_EVENT_TABLE() // ============================================================================ @@ -895,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; @@ -913,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 ) @@ -958,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() @@ -1019,6 +1008,8 @@ void wxWindowX11::X11SendPaintEvents() paint_event.SetEventObject( this ); GetEventHandler()->ProcessEvent( paint_event ); + m_updateRegion.Clear(); + m_clipPaintRegion = FALSE; } @@ -1045,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(); -- 2.47.2