From 4cdd3001c249f3426e9ae720bff9d15242a9d4ae Mon Sep 17 00:00:00 2001 From: Teodor Petrov Date: Sun, 1 Apr 2018 17:15:41 +0300 Subject: [PATCH] Keep wxSTC call tips inside the current display Make it harder for the calltip to be invisible * This required changes to the Window::SetPositionRelative. * Use the Qt version as a base. * The idea is to confine the window to the boundaries of the display the scintilla control is at the moment of the call. Closes #18115. --- src/stc/PlatWX.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 303bfbf9d6..ecca096883 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -1852,8 +1852,35 @@ void Window::SetPosition(PRectangle rc) { GETWIN(wid)->SetSize(r); } -void Window::SetPositionRelative(PRectangle rc, Window) { - SetPosition(rc); // ???? +void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { + wxWindow *relativeWin = GETWIN(relativeTo.wid); + + wxPoint position = relativeWin->GetScreenPosition(); + position.x = wxRound(position.x + rc.left); + position.y = wxRound(position.y + rc.top); + + const int currentDisplay = wxDisplay::GetFromWindow(relativeWin); + const wxRect displayRect = wxDisplay(currentDisplay).GetClientArea(); + + if (position.x < displayRect.GetLeft()) + position.x = displayRect.GetLeft(); + + const int width = rc.Width(); + if (width > displayRect.GetWidth()) + { + // We want to show at least the beginning of the window. + position.x = displayRect.GetLeft(); + } + else if (position.x + width > displayRect.GetRight()) + position.x = displayRect.GetRight() - width; + + const int height = rc.Height(); + if (position.y + height > displayRect.GetBottom()) + position.y = displayRect.GetBottom() - height; + + position = relativeWin->ScreenToClient(position); + wxWindow *window = GETWIN(wid); + window->SetSize(position.x, position.y, width, height); } PRectangle Window::GetClientPosition() {