From f4cdb3064631719ea51d9fb8345137f20c15c8bb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 17 Jun 2022 01:59:06 +0200 Subject: [PATCH] Make wxSashWindow resizing work with wxGTK3 with X11 Apply similar changes as to wxSplitterWindow to make the existing wxINVERT-based code work at least in this case, i.e. 1. Don't use wxScreenDC with wxGTK3 (although this is more involved in this case, as we can't just use wxClientDC for this window itself). 2. Use white brush so that wxCOMPOSITION_DIFF works as wxINVERT. --- src/generic/sashwin.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/generic/sashwin.cpp b/src/generic/sashwin.cpp index dc0dff3c07..85f0b3936f 100644 --- a/src/generic/sashwin.cpp +++ b/src/generic/sashwin.cpp @@ -545,7 +545,6 @@ void wxSashWindow::DrawSashTracker(wxSashEdgePosition edge, int x, int y) int w, h; GetClientSize(&w, &h); - wxScreenDC screenDC; int x1, y1; int x2, y2; @@ -583,18 +582,34 @@ void wxSashWindow::DrawSashTracker(wxSashEdgePosition edge, int x, int y) ClientToScreen(&x1, &y1); ClientToScreen(&x2, &y2); +#ifdef __WXGTK3__ + // We need to draw over the parent window, not this one, as we want to + // allow the sash go outside of this window. + wxWindow* const parent = wxGetTopLevelParent(this); + if ( !parent ) + return; + + wxClientDC dc(parent); + parent->ScreenToClient(&x1, &y1); + parent->ScreenToClient(&x2, &y2); + + // In the ports with wxGraphicsContext-based wxDC, wxINVERT only works for + // inverting the background when using white foreground (note that this + // code is not going to work anyhow with wxOSX nor with wxGTK when using + // Wayland, as drawing using wxClientDC doesn't work at all there), but + // this at least makes it work with wxGTK with X11. + wxPen sashTrackerPen(*wxWHITE, 2, wxPENSTYLE_SOLID); +#else + wxScreenDC dc; + wxPen sashTrackerPen(*wxBLACK, 2, wxPENSTYLE_SOLID); +#endif - screenDC.SetLogicalFunction(wxINVERT); - screenDC.SetPen(sashTrackerPen); - screenDC.SetBrush(*wxTRANSPARENT_BRUSH); + dc.SetLogicalFunction(wxINVERT); + dc.SetPen(sashTrackerPen); + dc.SetBrush(*wxTRANSPARENT_BRUSH); - screenDC.DrawLine(x1, y1, x2, y2); - - screenDC.SetLogicalFunction(wxCOPY); - - screenDC.SetPen(wxNullPen); - screenDC.SetBrush(wxNullBrush); + dc.DrawLine(x1, y1, x2, y2); } // Position and size subwindows.