From ef13436f1fa16fbf8d0a71726db581376054435d Mon Sep 17 00:00:00 2001 From: Ryan Leavengood Date: Tue, 29 Apr 2008 03:37:41 +0000 Subject: [PATCH] Fix for #676, an oldie (from 2 years ago): if the MediaPlayer window is moved off the screen at all, it will be moved back on when the window is activated. I almost think this might be a reasonable default implementation for WindowActivated in BWindow :) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25234 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/MainWin.cpp | 30 ++++++++++++++++++++++++++++++ src/apps/mediaplayer/MainWin.h | 1 + 2 files changed, 31 insertions(+) diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index 3b8c1bb6d8..5c3626effe 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -656,6 +656,36 @@ MainWin::MessageReceived(BMessage *msg) } +void +MainWin::WindowActivated(bool active) +{ + if (active) { + BScreen screen; + BRect screenFrame = screen.Frame(); + BRect frame = Frame(); + float diffX = 0.0; + float diffY = 0.0; + + // If the frame if off the edge of the screen at all + // we will move it so all the window is on the screen. + if (frame.left < screenFrame.left) + // Move right + diffX = screenFrame.left - frame.left; + if (frame.top < screenFrame.top) + // Move down + diffY = screenFrame.top - frame.top; + if (frame.right > screenFrame.right) + // Move left + diffX = screenFrame.right - frame.right; + if (frame.bottom > screenFrame.bottom) + // Move up + diffY = screenFrame.bottom - frame.bottom; + + MoveBy(diffX, diffY); + } +} + + bool MainWin::QuitRequested() { diff --git a/src/apps/mediaplayer/MainWin.h b/src/apps/mediaplayer/MainWin.h index 6cadb333ae..1e73dce3d6 100644 --- a/src/apps/mediaplayer/MainWin.h +++ b/src/apps/mediaplayer/MainWin.h @@ -48,6 +48,7 @@ public: virtual void DispatchMessage(BMessage* message, BHandler* handler); virtual void MessageReceived(BMessage* message); + virtual void WindowActivated(bool active); virtual bool QuitRequested(); void OpenFile(const entry_ref& ref);