diff --git a/include/svtools/DocumentToGraphicRenderer.hxx b/include/svtools/DocumentToGraphicRenderer.hxx index 450672ebe7ad..2240b160d79b 100644 --- a/include/svtools/DocumentToGraphicRenderer.hxx +++ b/include/svtools/DocumentToGraphicRenderer.hxx @@ -38,8 +38,14 @@ class SVT_DLLPUBLIC DocumentToGraphicRenderer css::uno::Reference mxController; css::uno::Reference mxRenderable; css::uno::Reference mxToolkit; + css::uno::Any maSelection; bool mbSelectionOnly; + bool hasSelection() const; + + /** Always something even if hasSelection() is false (in which case the + selection is mxDocument). + */ css::uno::Any getSelection() const; sal_Int32 getCurrentPageWriter(); diff --git a/svtools/source/filter/DocumentToGraphicRenderer.cxx b/svtools/source/filter/DocumentToGraphicRenderer.cxx index 459bfb925174..8cf4e0e53a77 100644 --- a/svtools/source/filter/DocumentToGraphicRenderer.cxx +++ b/svtools/source/filter/DocumentToGraphicRenderer.cxx @@ -46,6 +46,22 @@ DocumentToGraphicRenderer::DocumentToGraphicRenderer( const Reference xSelSup( mxController, uno::UNO_QUERY); + if (xSelSup.is()) + { + uno::Any aViewSelection( xSelSup->getSelection()); + if (aViewSelection.hasValue()) + maSelection = aViewSelection; + } + } + catch (const uno::Exception&) + { + } + } } DocumentToGraphicRenderer::~DocumentToGraphicRenderer() @@ -58,26 +74,18 @@ Size DocumentToGraphicRenderer::getDocumentSizeInPixels(sal_Int32 nCurrentPage) return Application::GetDefaultDevice()->LogicToPixel( aSize100mm, MapUnit::Map100thMM ); } +bool DocumentToGraphicRenderer::hasSelection() const +{ + return maSelection.hasValue(); +} + uno::Any DocumentToGraphicRenderer::getSelection() const { uno::Any aSelection; - aSelection <<= mxDocument; // default: render whole document - if (mbSelectionOnly && mxController.is()) - { - try - { - uno::Reference< view::XSelectionSupplier > xSelSup( mxController, uno::UNO_QUERY); - if (xSelSup.is()) - { - uno::Any aViewSelection( xSelSup->getSelection()); - if (aViewSelection.hasValue()) - aSelection = aViewSelection; - } - } - catch (const uno::Exception&) - { - } - } + if (hasSelection()) + aSelection <<= maSelection; + else + aSelection <<= mxDocument; // default: render whole document return aSelection; }