summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Power <noel.power@novell.com>2012-06-26 18:19:21 +0100
committerNoel Power <noel.power@novell.com>2012-06-26 18:19:21 +0100
commit4a5e8fc26e2bbd37779505c40f470b3b3be9a5db (patch)
tree39ece8144ebe2fb9cc1d99ba3f6b0f782a1a87e0
parentbe92126c633f13589628068d523939c60f905894 (diff)
fix for fdo#51040 preview crash
Change-Id: I13d3cfa99294bdce8c9f5133f49e91114feb4baa
-rw-r--r--sc/source/ui/inc/prevwsh.hxx3
-rw-r--r--sc/source/ui/view/preview.cxx5
-rw-r--r--sc/source/ui/view/prevwsh.cxx100
3 files changed, 61 insertions, 47 deletions
diff --git a/sc/source/ui/inc/prevwsh.hxx b/sc/source/ui/inc/prevwsh.hxx
index 0f89fc7745d9..020c2110022f 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 da05322957b5..c45135b2e3e8 100644
--- a/sc/source/ui/view/preview.cxx
+++ b/sc/source/ui/view/preview.cxx
@@ -705,10 +705,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 a69cb795e2ef..02bf4e153536 100644
--- a/sc/source/ui/view/prevwsh.cxx
+++ b/sc/source/ui/view/prevwsh.cxx
@@ -302,16 +302,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();
@@ -320,49 +313,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();
}