diff options
author | Noel Power <noel.power@novell.com> | 2012-06-26 18:19:21 +0100 |
---|---|---|
committer | Noel Power <noel.power@novell.com> | 2012-06-26 18:24:37 +0100 |
commit | baf87aacce6d75f9b01156ce085ef4487d46a406 (patch) | |
tree | 7e96feb0099e1f11c53c6fb5436a62cbd05aea14 /sc | |
parent | ff62d9c4be26096c7f5ea06e4dee2b16d40aa16b (diff) |
fix for fdo#51040 preview crash
Change-Id: I13d3cfa99294bdce8c9f5133f49e91114feb4baa
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/inc/prevwsh.hxx | 3 | ||||
-rw-r--r-- | sc/source/ui/view/preview.cxx | 5 | ||||
-rw-r--r-- | sc/source/ui/view/prevwsh.cxx | 100 |
3 files changed, 61 insertions, 47 deletions
diff --git a/sc/source/ui/inc/prevwsh.hxx b/sc/source/ui/inc/prevwsh.hxx index f62165f0390a..1da34f3e3c03 100644 --- a/sc/source/ui/inc/prevwsh.hxx +++ b/sc/source/ui/inc/prevwsh.hxx @@ -50,7 +50,6 @@ class CommandEvent; class ScPreviewShell: public SfxViewShell { -friend class ScPreview; // allow access to AdjustPosSizePixel ScDocShell* pDocShell; SystemWindow* mpFrameWindow; @@ -66,7 +65,6 @@ friend class ScPreview; // allow access to AdjustPosSizePixel SfxBroadcaster* pAccessibilityBroadcaster; bool GetPageSize( Size& aPageSize ); - void UpdateNeededScrollBars(); private: void Construct( Window* pParent ); DECL_LINK(ScrollHandler, ScrollBar* ); @@ -106,6 +104,7 @@ public: void InitStartTable(SCTAB nTab); void UpdateScrollBars(); + void UpdateNeededScrollBars(bool bFromZoom = false); sal_Bool ScrollCommand( const CommandEvent& rCEvt ); void Execute( SfxRequest& rReq ); diff --git a/sc/source/ui/view/preview.cxx b/sc/source/ui/view/preview.cxx index ae233ffa1b84..8007e0efaf6a 100644 --- a/sc/source/ui/view/preview.cxx +++ b/sc/source/ui/view/preview.cxx @@ -701,10 +701,7 @@ void ScPreview::SetZoom(sal_uInt16 nNewZoom) SetMapMode( aMMMode ); bInSetZoom = true; // don't scroll during SetYOffset in UpdateScrollBars - if ( Window* pWin = ( pViewShell->GetViewFrame() ? &pViewShell->GetViewFrame()->GetWindow() : NULL ) ) - pViewShell->AdjustPosSizePixel( pWin->GetPosPixel(), pWin->GetSizePixel() ); - else - pViewShell->UpdateScrollBars(); + pViewShell->UpdateNeededScrollBars(true); bInSetZoom = false; bStateValid = false; diff --git a/sc/source/ui/view/prevwsh.cxx b/sc/source/ui/view/prevwsh.cxx index 77f633ddfc91..43f97948c419 100644 --- a/sc/source/ui/view/prevwsh.cxx +++ b/sc/source/ui/view/prevwsh.cxx @@ -297,16 +297,9 @@ bool ScPreviewShell::GetPageSize( Size& aPageSize ) return true; } -void ScPreviewShell::UpdateNeededScrollBars() +void ScPreviewShell::UpdateNeededScrollBars( bool bFromZoom ) { - bool bVert = pVerScroll ? pVerScroll->IsVisible() : false; - bool bHori = pHorScroll ? pHorScroll->IsVisible() : false; - Size aPageSize; - if ( !GetPageSize( aPageSize ) ) - return; - - Size aWindowSize = pPreview->GetOutputSize(); OutputDevice* pDevice = Application::GetDefaultDevice(); long nBarW = GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetScrollBarSize(); @@ -315,49 +308,74 @@ void ScPreviewShell::UpdateNeededScrollBars() long aHeightOffSet = pDevice ? pDevice->PixelToLogic( Size( nBarW, nBarH ), pPreview->GetMapMode() ).Height() : 0; long aWidthOffSet = aHeightOffSet; - if( pHorScroll ) + + if (!GetPageSize( aPageSize )) + return; + + // for centering, page size without the shadow is used + bool bVert = pVerScroll ? pVerScroll->IsVisible() : false; + bool bHori = pHorScroll ? pHorScroll->IsVisible() : false; + Size aWindowSize = pPreview->GetOutputSize(); + Point aPos = pPreview->GetPosPixel(); + Size aWindowPixelSize = pPreview->GetOutputSizePixel(); + + // if we are called from Zoom then we need to compensate for whatever + // scrollbars were displayed before the zoom was called + if ( bFromZoom ) { - long nMaxPos = aPageSize.Width() - aWindowSize.Width() + aWidthOffSet; - if ( nMaxPos<0 ) - bHori = false; - else - bHori = true; - pHorScroll->Show( bHori ); + if ( bVert ) + { + aWindowPixelSize.Width() += nBarH; + aWindowSize.Width() += aHeightOffSet; + } + if ( bHori ) + { + aWindowPixelSize.Height() += nBarW; + aWindowSize.Height() += aWidthOffSet; + } } + // recalculate any needed scrollbars + bHori = false; + bVert = false; - if( pVerScroll ) - { - nMaxVertPos = aPageSize.Height() - aWindowSize.Height() + aHeightOffSet; + long nMaxWidthPos = aPageSize.Width() - aWindowSize.Width(); + if ( nMaxWidthPos<0 ) + bHori = false; + else + bHori = true; - if ( nMaxVertPos < 0 ) - bVert = false; - else + long nMaxHeightPos = aPageSize.Height() - aWindowSize.Height(); + + if ( nMaxHeightPos < 0 ) + bVert = false; + else + bVert = true; + + // see if having a scroll bar requires the other + if ( bVert != bHori && ( bVert || bHori ) ) + { + if ( bVert && ( (nMaxWidthPos + aWidthOffSet ) > 0 ) ) + bHori = true; + else if ( (nMaxHeightPos + aHeightOffSet ) > 0 ) bVert = true; - pVerScroll->Show( bVert ); } + pHorScroll->Show( bHori ); + pVerScroll->Show( bVert ); - Size aOutSize = pPreview->GetSizePixel(); - Size aNewSize = aOutSize; - Point aPos = pPreview->GetPosPixel(); - + // make room for needed scrollbars ( and reduce the size + // of the preview appropriately ) if ( bHori ) - aNewSize.Height() -= nBarH; + aWindowPixelSize.Height() -= nBarW; if ( bVert ) - aNewSize.Width() -= nBarW; - - pPreview->SetPosSizePixel( aPos, aNewSize ); - - pHorScroll->SetPosSizePixel( Point( aPos.X(), aPos.Y() + aNewSize.Height() ), - Size( aNewSize.Width(), nBarH ) ); - pVerScroll->SetPosSizePixel( Point( aPos.X() + aNewSize.Width(), aPos.Y() ), - Size( nBarW, aNewSize.Height() ) ); - pCorner->SetPosSizePixel( Point( aPos.X() + aNewSize.Width(), aPos.Y() + aNewSize.Height() ), + aWindowPixelSize.Width() -= nBarH; + + pPreview->SetSizePixel( aWindowPixelSize ); + pHorScroll->SetPosSizePixel( Point( aPos.X(), aPos.Y() + aWindowPixelSize.Height() ), + Size( aWindowPixelSize.Width(), nBarH ) ); + pVerScroll->SetPosSizePixel( Point( aPos.X() + aWindowPixelSize.Width(), aPos.Y() ), + Size( nBarW, aWindowPixelSize.Height() ) ); + pCorner->SetPosSizePixel( Point( aPos.X() + aWindowPixelSize.Width(), aPos.Y() + aWindowPixelSize.Height() ), Size( nBarW, nBarH ) ); - - if ( SVX_ZOOM_WHOLEPAGE == eZoom ) - pPreview->SetZoom( pPreview->GetOptimalZoom( sal_False ) ); - else if ( SVX_ZOOM_PAGEWIDTH == eZoom ) - pPreview->SetZoom( pPreview->GetOptimalZoom( sal_True ) ); UpdateScrollBars(); } |