diff options
author | Caolán McNamara <caolanm@redhat.com> | 2010-10-22 16:07:22 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2010-10-22 16:07:22 +0100 |
commit | 28a124c47d4be01c93803aa85266454a74d9f6ac (patch) | |
tree | dbc26e3fbbfb66ccf85d5c7a4fa44ee9cea11f03 /svx/source/unogallery/unogaltheme.cxx | |
parent | 40d88ad961b36d72f562402eac7388004ff377af (diff) |
#i80184# Allow adding drawing documents to gallery via API
Diffstat (limited to 'svx/source/unogallery/unogaltheme.cxx')
-rw-r--r-- | svx/source/unogallery/unogaltheme.cxx | 35 |
1 files changed, 35 insertions, 0 deletions
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 <svx/fmmodel.hxx> +#include <svx/svdpage.hxx> +#include <svx/unopage.hxx> +#include <svl/itempool.hxx> #include <rtl/uuid.h> #include <vos/mutex.hxx> #include <vcl/svapp.hxx> @@ -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; |