diff --git a/headers/os/interface/Window.h b/headers/os/interface/Window.h index dbf0431516..37fbf8815f 100644 --- a/headers/os/interface/Window.h +++ b/headers/os/interface/Window.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2011, Haiku, Inc. All rights reserved. + * Copyright 2001-2015, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _WINDOW_H @@ -170,6 +170,7 @@ public: void CenterIn(const BRect& rect); void CenterOnScreen(); void CenterOnScreen(screen_id id); + void MoveOnScreen(); virtual void Show(); virtual void Hide(); diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index 141e4891bc..70cc845447 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2014 Haiku, Inc. All rights reserved + * Copyright 2001-2015 Haiku, Inc. All rights reserved * Distributed under the terms of the MIT License. * * Authors: @@ -2568,6 +2568,47 @@ BWindow::CenterOnScreen(screen_id id) } +void +BWindow::MoveOnScreen() +{ + // Set size limits now if needed + UpdateSizeLimits(); + + BRect screenFrame = BScreen(this).Frame(); + BRect frame = Frame(); + + float borderWidth; + float tabHeight; + _GetDecoratorSize(&borderWidth, &tabHeight); + + frame.InsetBy(-borderWidth, -borderWidth); + frame.top -= tabHeight; + + if (!frame.Intersects(screenFrame)) { + // Off and away + CenterOnScreen(); + return; + } + + // Move such that the upper left corner, and most of the window + // will be visible. + float left = frame.left; + if (left < screenFrame.left) + left = screenFrame.left; + else if (frame.right > screenFrame.right) + left = std::max(0.f, screenFrame.right - frame.Width()); + + float top = frame.top; + if (top < screenFrame.top) + top = screenFrame.top; + else if (frame.bottom > screenFrame.bottom) + top = std::max(0.f, screenFrame.bottom - frame.Height()); + + if (top != frame.top || left != frame.left) + MoveTo(left + borderWidth, top + tabHeight + borderWidth); +} + + void BWindow::Show() {