summaryrefslogtreecommitdiff
path: root/vcl/source/app/svapp.cxx
diff options
context:
space:
mode:
authorRüdiger Timm <rt@openoffice.org>2007-04-26 09:35:36 +0000
committerRüdiger Timm <rt@openoffice.org>2007-04-26 09:35:36 +0000
commit98143181b4b3a8b5bb6dd21a20ee7c4e1fc34b28 (patch)
tree25187b5a21e26322ae3aa1ec457afb6af8617b85 /vcl/source/app/svapp.cxx
parent663ea86280d80b3e38f1611b3c243a99c962a63c (diff)
INTEGRATION: CWS vcl75 (1.74.24); FILE MERGED
2007/03/30 12:08:31 pl 1.74.24.4: #i75332# minor corrections from code review session 2007/03/29 13:42:00 pl 1.74.24.3: #i75332# better algorithm for GetBestScreen 2007/03/28 14:23:57 pl 1.74.24.2: #i75332# better algorithm for GetBestScreen 2007/03/16 11:25:17 pl 1.74.24.1: #i75332# look for non-rectangular multiscreen scnearios when opening popups
Diffstat (limited to 'vcl/source/app/svapp.cxx')
-rw-r--r--vcl/source/app/svapp.cxx61
1 files changed, 59 insertions, 2 deletions
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index 899b8747f597..44e00675b7b0 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: svapp.cxx,v $
*
- * $Revision: 1.75 $
+ * $Revision: 1.76 $
*
- * last change: $Author: rt $ $Date: 2007-04-26 09:26:32 $
+ * last change: $Author: rt $ $Date: 2007-04-26 10:35:36 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -1393,6 +1393,63 @@ Rectangle Application::GetWorkAreaPosSizePixel( unsigned int nScreen )
return pSys ? pSys->GetDisplayWorkAreaPosSizePixel( nScreen ) : Rectangle();
}
+namespace {
+unsigned long calcDistSquare( const Point& i_rPoint, const Rectangle& i_rRect )
+{
+ const Point aRectCenter( (i_rRect.Left() + i_rRect.Right())/2,
+ (i_rRect.Top() + i_rRect.Bottom())/ 2 );
+ const long nDX = aRectCenter.X() - i_rPoint.X();
+ const long nDY = aRectCenter.Y() - i_rPoint.Y();
+ return nDX*nDX + nDY*nDY;
+}
+}
+
+unsigned int Application::GetBestScreen( const Rectangle& i_rRect )
+{
+ if( IsMultiDisplay() )
+ return GetDefaultDisplayNumber();
+
+ const unsigned int nScreens = GetScreenCount();
+ unsigned int nBestMatchScreen = 0;
+ unsigned long nOverlap = 0;
+ for( unsigned int i = 0; i < nScreens; i++ )
+ {
+ const Rectangle aCurScreenRect( GetScreenPosSizePixel( i ) );
+ // if a screen contains the rectangle completely it is obviously the best screen
+ if( aCurScreenRect.IsInside( i_rRect ) )
+ return i;
+ // next the screen which contains most of the area of the rect is the best
+ Rectangle aIntersection( aCurScreenRect.GetIntersection( i_rRect ) );
+ if( ! aIntersection.IsEmpty() )
+ {
+ const unsigned long nCurOverlap( aIntersection.GetWidth() * aIntersection.GetHeight() );
+ if( nCurOverlap > nOverlap )
+ {
+ nOverlap = nCurOverlap;
+ nBestMatchScreen = i;
+ }
+ }
+ }
+ if( nOverlap > 0 )
+ return nBestMatchScreen;
+
+ // finally the screen which center is nearest to the rect is the best
+ const Point aCenter( (i_rRect.Left() + i_rRect.Right())/2,
+ (i_rRect.Top() + i_rRect.Bottom())/2 );
+ unsigned long nDist = ULONG_MAX;
+ for( unsigned int i = 0; i < nScreens; i++ )
+ {
+ const Rectangle aCurScreenRect( GetScreenPosSizePixel( i ) );
+ const unsigned long nCurDist( calcDistSquare( aCenter, aCurScreenRect ) );
+ if( nCurDist < nDist )
+ {
+ nBestMatchScreen = i;
+ nDist = nCurDist;
+ }
+ }
+ return nBestMatchScreen;
+}
+
// -----------------------------------------------------------------------
BOOL Application::InsertAccel( Accelerator* pAccel )