From 28a124c47d4be01c93803aa85266454a74d9f6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Fri, 22 Oct 2010 16:07:22 +0100 Subject: [PATCH] #i80184# Allow adding drawing documents to gallery via API --- svx/source/unogallery/unogaltheme.cxx | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/svx/source/unogallery/unogaltheme.cxx b/svx/source/unogallery/unogaltheme.cxx index 3edebcda7c06..03ba21743499 100644 --- a/svx/source/unogallery/unogaltheme.cxx +++ b/svx/source/unogallery/unogaltheme.cxx @@ -37,6 +37,9 @@ #include "svx/gallery1.hxx" #include "svx/galmisc.hxx" #include +#include +#include +#include #include #include #include @@ -321,11 +324,43 @@ void SAL_CALL GalleryTheme::update( ) if( pModel && pModel->GetDoc() && pModel->GetDoc()->ISA( FmFormModel ) ) { + //Here we're inserting something that's already a gallery theme drawing + nIndex = ::std::max( ::std::min( nIndex, getCount() ), sal_Int32( 0 ) ); if( mpTheme->InsertModel( *static_cast< FmFormModel* >( pModel->GetDoc() ), nIndex ) ) nRet = nIndex; } + else if (!pModel) + { + //#i80184# Try to do the right thing and make a Gallery drawing out of an ordinary + //Drawing if possible. + try + { + uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSupplier( Drawing, uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( 0 ), uno::UNO_QUERY_THROW ); + SvxDrawPage* pUnoPage = xPage.is() ? SvxDrawPage::getImplementation( xPage ) : NULL; + SdrModel* pOrigModel = pUnoPage ? pUnoPage->GetSdrPage()->GetModel() : NULL; + SdrPage* pOrigPage = pUnoPage ? pUnoPage->GetSdrPage() : NULL; + + if (pOrigPage && pOrigModel) + { + FmFormModel* pTmpModel = new FmFormModel(&pOrigModel->GetItemPool()); + SdrPage* pNewPage = pOrigPage->Clone(); + pTmpModel->InsertPage(pNewPage, 0); + + uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pTmpModel ) ); + pTmpModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) ); + + nRet = insertDrawingByIndex( xDrawing, nIndex ); + return nRet; + } + } + catch (...) + { + } + } } return nRet;