From 92c015e696548862ff3dc8b4592589e38e97ac34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 18 Sep 2009 09:46:09 +0000 Subject: [PATCH] Make sure tool tips are not displayed outside of the screen bounds. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33166 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/ToolTipManager.cpp | 30 ++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/kits/interface/ToolTipManager.cpp b/src/kits/interface/ToolTipManager.cpp index 755a34c2d0..46fa45d87b 100644 --- a/src/kits/interface/ToolTipManager.cpp +++ b/src/kits/interface/ToolTipManager.cpp @@ -1,6 +1,7 @@ /* * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. - * Distributed under the terms of the MIT License. + * Copyright 2009, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. */ @@ -10,6 +11,7 @@ #include #include #include +#include #include #include @@ -113,10 +115,6 @@ ToolTipWindow::ToolTipWindow(BToolTip* tip, BPoint where) kMenuWindowFeel, B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_AVOID_FRONT | B_AVOID_FOCUS) { - MoveTo(where + tip->MouseRelativeLocation()); - - // TODO: take alignment into account! - SetLayout(new BGroupLayout(B_VERTICAL)); BToolTipManager::Lock(); @@ -126,6 +124,28 @@ ToolTipWindow::ToolTipWindow(BToolTip* tip, BPoint where) BSize size = ChildAt(0)->PreferredSize(); ResizeTo(size.width, size.height); //AddChild(BLayoutBuilder::Group<>(B_VERTICAL).Add(new ToolTipView(tip))); + + // figure out location + // TODO: take alignment into account! + where += tip->MouseRelativeLocation(); + + BScreen screen(this); + if (screen.IsValid()) { + BRect screenFrame = screen.Frame().InsetBySelf(5, 5); + BRect frame = Frame().OffsetToSelf(where); + if (!screenFrame.Contains(frame)) { + if (screenFrame.top > frame.top) + where.y -= frame.top - screenFrame.top; + else if (screenFrame.bottom < frame.bottom) + where.y -= frame.bottom - screenFrame.bottom; + if (screenFrame.left > frame.left) + where.x -= frame.left - screenFrame.left; + else if (screenFrame.right < frame.right) + where.x -= frame.right - screenFrame.right; + } + } + + MoveTo(where); }