diff options
author | Gergő Mocsi <gmocsi91@gmail.com> | 2013-04-02 12:57:59 +0200 |
---|---|---|
committer | Andras Timar <atimar@suse.com> | 2013-04-10 15:00:25 +0000 |
commit | 3a56257e858c6793156a78b387451802593455e0 (patch) | |
tree | 2e766f7b5dbb9a223f61731851e07e5655635b7e /sd/source/ui/dlg | |
parent | 857adeada9cc3276e79ceb828959a3ffe2d7409b (diff) |
Create Photo Album implementation
Added a checkbox to enable/diable Keep Aspect ratio.
Options 2 images/slide, 4 images/slide implemented.
UI tweaks: dialog window remembers last used directory (via config),
buttons get enabled/disabled according to the content of the ListBox.
ListBox show filename only, full path is shown lower in a label.
Dialog window reopens again, if slide preview is not in focus.
Added a title slide: author, title.
Conflicts:
officecfg/registry/data/org/openoffice/Office/UI/DrawImpressCommands.xcu
sd/uiconfig/simpress/ui/photoalbum.ui
Change-Id: I68d2a3e00f8c55b909fe4d98aa3958188653390e
Reviewed-on: https://gerrit.libreoffice.org/3169
Reviewed-by: Andras Timar <atimar@suse.com>
Tested-by: Andras Timar <atimar@suse.com>
Diffstat (limited to 'sd/source/ui/dlg')
-rw-r--r-- | sd/source/ui/dlg/PhotoAlbumDialog.cxx | 701 | ||||
-rw-r--r-- | sd/source/ui/dlg/PhotoAlbumDialog.hxx | 35 |
2 files changed, 650 insertions, 86 deletions
diff --git a/sd/source/ui/dlg/PhotoAlbumDialog.cxx b/sd/source/ui/dlg/PhotoAlbumDialog.cxx index bd87f341ae2f..5bbd5cf2a4e7 100644 --- a/sd/source/ui/dlg/PhotoAlbumDialog.cxx +++ b/sd/source/ui/dlg/PhotoAlbumDialog.cxx @@ -9,17 +9,17 @@ #include "PhotoAlbumDialog.hxx" -#include <com/sun/star/graphic/GraphicProvider.hpp> -#include <com/sun/star/graphic/XGraphicProvider.hpp> #include <comphelper/namedvaluecollection.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/componentcontext.hxx> +#include <comphelper/configurationhelper.hxx> #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> #include <com/sun/star/drawing/XMasterPagesSupplier.hpp> -#include <com/sun/star/drawing/XDrawPages.hpp> -#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/container/XNameAccess.hpp> + #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/text/XText.hpp> #include <sfx2/filedlghelper.hxx> #include <tools/urlobj.hxx> @@ -29,17 +29,13 @@ #include <unotools/ucbstreamhelper.hxx> #include <vcl/msgbox.hxx> - - - - -using namespace ::com::sun::star; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::presentation; +#include <svx/unoshape.hxx> namespace sd { +OUString SdPhotoAlbumDialog::sDirUrl; + SdPhotoAlbumDialog::SdPhotoAlbumDialog(Window* pWindow, SdDrawDocument* pActDoc) : ModalDialog(pWindow, "PhotoAlbumCreatorDialog", "modules/simpress/ui/photoalbum.ui"), pDoc(pActDoc) @@ -58,18 +54,26 @@ SdPhotoAlbumDialog::SdPhotoAlbumDialog(Window* pWindow, SdDrawDocument* pActDoc) get(pInsTypeCombo, "opt_combo"); + get(pASRCheck, "asr_check"); + get(pFilenameLab, "filename_lab"); + pCancelBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CancelHdl)); pCreateBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CreateHdl)); pFileBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, FileHdl)); pTextBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, TextHdl)); pUpBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, UpHdl)); + pUpBtn->Disable(); pDownBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, DownHdl)); + pDownBtn->Disable(); pRemoveBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, RemoveHdl)); - + pRemoveBtn->Disable(); pImagesLst->SetSelectHdl(LINK(this, SdPhotoAlbumDialog, SelectHdl)); - mpGraphicFilter = new GraphicFilter; + mpGraphicFilter = new GraphicFilter; + sDirUrl = ""; + pFileBtn->GrabFocus(); + pImagesLst->Clear(); } SdPhotoAlbumDialog::~SdPhotoAlbumDialog() @@ -78,7 +82,7 @@ SdPhotoAlbumDialog::~SdPhotoAlbumDialog() IMPL_LINK_NOARG(SdPhotoAlbumDialog, CancelHdl) { - EndDialog(0); + Close(); return 0; } @@ -95,9 +99,20 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, CreateHdl) Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_QUERY ); Reference< lang::XMultiServiceFactory > xShapeFactory( pDoc->getUnoModel(), uno::UNO_QUERY ); - // insert text to the first slide + // Create the title slide + Reference< drawing::XDrawPage > xTitleSlide = appendNewSlide(AUTOLAYOUT_TITLE, xDrawPages); + SdPage* pFirstSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD); - pFirstSlide->SetAutoLayout(AUTOLAYOUT_TITLE, sal_True); + SvtUserOptions aUserOptions; + SdrObject* pTitleObj = pFirstSlide->GetPresObj(PRESOBJ_TITLE, 0); + SvxShapeText* pTitleText = new SvxShapeText(pTitleObj); + pTitleText->SetShapeType("com.sun.star.presentation.TitleTextShape"); + pTitleText->setString(OUString("Photoalbum\n")); + + SdrObject* pTextObj = pFirstSlide->GetPresObj(PRESOBJ_TEXT, 0); + SvxShapeText* pTextShape = new SvxShapeText(pTextObj); + pTextShape->SetShapeType("com.sun.star.presentation.TextShape"); + pTextShape->setString(OUString("Author: ") + aUserOptions.GetFullName()); Reference< XComponentContext > xContext(::comphelper::getProcessComponentContext()); Reference< graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(xContext)); @@ -106,98 +121,87 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, CreateHdl) OUString sOpt = pInsTypeCombo->GetEntry(pInsTypeCombo->GetSelectEntryPos()); if ( sOpt == "Fit to slide") { - setFirstSlide(pFirstSlide); + OUString sUrl; + OUString* pData; for( sal_Int16 i = 0; i < pImagesLst->GetEntryCount(); ++i ) { - OUString sUrl = pImagesLst->GetEntry( i ); + pData = (OUString*) pImagesLst->GetEntryData(i); + sUrl = *pData; if (sUrl != "Text Box") { - ::comphelper::NamedValueCollection aMediaProperties; - aMediaProperties.put( "URL", OUString( sUrl ) ); - - Reference< graphic::XGraphic> xGraphic = - xProvider->queryGraphic( aMediaProperties.getPropertyValues() ); + Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE, xDrawPages); + Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY ); - Reference< drawing::XDrawPage > xSlide; - Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY ); - xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() ); - SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD); - pSlide->SetAutoLayout(AUTOLAYOUT_NONE, sal_True); + Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl, xProvider); - Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY ); + Image aImg(xGraphic); + // Save the original size, multiplied with 100 + ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100); Reference< drawing::XShape > xShape( xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), - uno::UNO_QUERY - ); + uno::UNO_QUERY); Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY ); xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic)); - ::awt::Size aPicSize = xShape->getSize(); + ::awt::Size aPageSize; xSlideProps->getPropertyValue( OUString("Width")) >>= aPageSize.Width; xSlideProps->getPropertyValue( OUString("Height")) >>= aPageSize.Height; - aPicSize.Width = aPageSize.Width; - aPicSize.Height = aPageSize.Height; + ::awt::Point aPicPos; + if(pASRCheck->IsChecked()) + { + // Resize the image, with keeping ASR + aPicSize = createASRSize(aPicSize, aPageSize); + } + else + { + aPicSize.Width = aPageSize.Width; + aPicSize.Height = aPageSize.Height; + } + xShape->setSize(aPicSize); aPicPos.X = (aPageSize.Width - aPicSize.Width)/2; aPicPos.Y = (aPageSize.Height - aPicSize.Height)/2; - xShape->setSize(aPicSize); + xShape->setPosition(aPicPos); xSlide->add(xShape); } else // insert an empty slide, with centered text box { - Reference< drawing::XDrawPage > xSlide; - Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY ); - xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() ); - SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD); - pSlide->SetAutoLayout(AUTOLAYOUT_ONLY_TEXT, sal_True); + appendNewSlide(AUTOLAYOUT_ONLY_TEXT, xDrawPages); } } + delete pData; } else if( sOpt == "1 image with title" ) { - setFirstSlide(pFirstSlide); + OUString sUrl; + OUString* pData; for( sal_Int16 i = 0; i < pImagesLst->GetEntryCount(); ++i ) { - OUString sUrl = pImagesLst->GetEntry( i ); + pData = (OUString*) pImagesLst->GetEntryData(i); + sUrl = *pData; if ( sUrl != "Text Box" ) { - ::comphelper::NamedValueCollection aMediaProperties; - aMediaProperties.put( "URL", OUString( sUrl ) ); - - Reference< graphic::XGraphic> xGraphic = - xProvider->queryGraphic( aMediaProperties.getPropertyValues() ); - - Reference< drawing::XDrawPage > xSlide; - Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY ); - xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() ); + Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE, xDrawPages); Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY ); + Reference< drawing::XShape > xShape = createXShapeFromUrl(sUrl, xShapeFactory, xProvider); - Reference< drawing::XShape > xShape( - xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), - uno::UNO_QUERY - ); - - Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY ); - xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic)); - - ::awt::Size aPicSize = xShape->getSize(); + ::awt::Size aPicSize(xShape->getSize()); ::awt::Size aPageSize; xSlideProps->getPropertyValue( OUString("Width")) >>= aPageSize.Width; xSlideProps->getPropertyValue( OUString("Height")) >>= aPageSize.Height; - aPicSize.Width = aPageSize.Width/2; - aPicSize.Height = aPageSize.Height/2; + ::awt::Point aPicPos; aPicPos.X = (aPageSize.Width - aPicSize.Width)/2; @@ -212,20 +216,336 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, CreateHdl) } else // insert an empty slide, with centered text box { - Reference< drawing::XDrawPage > xSlide; - Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY ); - xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() ); + appendNewSlide(AUTOLAYOUT_ONLY_TEXT, xDrawPages); + } + } + delete pData; + } + else if( sOpt == "2 images" ) + { + OUString sUrl1(""); + OUString sUrl2(""); + OUString* pData; + + for( sal_Int32 i = 0; i < pImagesLst->GetEntryCount(); i+=2 ) + { + // create the slide + Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE, xDrawPages); + Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY ); + //Slide dimensions + ::awt::Size aPageSize; + + xSlideProps->getPropertyValue( + OUString("Width")) >>= aPageSize.Width; + xSlideProps->getPropertyValue( + OUString("Height")) >>= aPageSize.Height; + + // grab the left one + pData = (OUString*) pImagesLst->GetEntryData(i); + sUrl1 = pData ? OUString(*pData) : ""; + // grab the right one + pData = (OUString*) pImagesLst->GetEntryData(i+1); + sUrl2 = pData ? OUString(*pData) : ""; + + if( sUrl1 == "Text Box" ) // create a Text Box + { + SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD); + pSlide->CreatePresObj(PRESOBJ_TEXT, sal_False, Rectangle(Point(100,100), Point(aPageSize.Width/2-100, aPageSize.Height-100)), sal_True); + } + else if( sUrl1.isEmpty()){} // nothing to do + else + { + + Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider); + + Image aImg(xGraphic); + // Save the original size, multiplied with 100 + ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100); + + Reference< drawing::XShape > xShape( + xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), + uno::UNO_QUERY); + + Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY ); + xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic)); + + ::awt::Point aPicPos; + + if(pASRCheck->IsChecked()) + { + // Resize the image, with keeping ASR + aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100)); + } + else + { + aPicSize.Width = aPageSize.Width/2 - 100; + aPicSize.Height = aPageSize.Height/2 - 100; + } + xShape->setSize(aPicSize); + aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2); + aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2; + + xShape->setPosition(aPicPos); + xSlide->add(xShape); + } + + if( sUrl2 == "Text Box" ) // create a Text Box + { SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD); - pSlide->SetAutoLayout(AUTOLAYOUT_ONLY_TEXT, sal_True); + pSlide->CreatePresObj(PRESOBJ_TEXT, sal_False, Rectangle(Point(aPageSize.Width/2 + 100,100), Point(aPageSize.Width-100, aPageSize.Height-100)), sal_True); } + else if( sUrl2.isEmpty()){} // nothing to do + else + { + Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider); + + Image aImg(xGraphic); + // Save the original size, multiplied with 100 + ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100); + + Reference< drawing::XShape > xShape( + xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), + uno::UNO_QUERY); + + Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY ); + xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic)); + + ::awt::Point aPicPos; + + if(pASRCheck->IsChecked()) + { + // Resize the image, with keeping ASR + aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100)); + } + else + { + aPicSize.Width = aPageSize.Width/2 - 100; + aPicSize.Height = aPageSize.Height/2 - 100; + } + xShape->setSize(aPicSize); + aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2; + aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2; + + xShape->setPosition(aPicPos); + xSlide->add(xShape); + } + } + delete pData; + } + else if( sOpt == "4 images" ) + { + OUString sUrl1(""); + OUString sUrl2(""); + OUString sUrl3(""); + OUString sUrl4(""); + OUString* pData; + + for( sal_Int32 i = 0; i < pImagesLst->GetEntryCount(); i+=4 ) + { + // create the slide + Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE, xDrawPages); + Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY ); + //Slide dimensions + ::awt::Size aPageSize; + + xSlideProps->getPropertyValue( + OUString("Width")) >>= aPageSize.Width; + xSlideProps->getPropertyValue( + OUString("Height")) >>= aPageSize.Height; + + // grab the upper left one + pData = (OUString*) pImagesLst->GetEntryData(i); + sUrl1 = pData ? OUString(*pData) : ""; + + // grab the upper right one + pData = (OUString*) pImagesLst->GetEntryData(i+1); + sUrl2 = pData ? OUString(*pData) : ""; + + // grab the lower left one + pData = (OUString*) pImagesLst->GetEntryData(i+2); + sUrl3 = pData ? OUString(*pData) : ""; + + // grab the lower right one + pData = (OUString*) pImagesLst->GetEntryData(i+3); + sUrl4 = pData ? OUString(*pData) : ""; + + if( sUrl1 == "Text Box" ) // create a Text Box + { + SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD); + pSlide->CreatePresObj(PRESOBJ_TEXT, sal_False, Rectangle(Point(100,100), Point(aPageSize.Width/2-100, aPageSize.Height/2-100)), sal_True); + } + else if( sUrl1.isEmpty()){} // nothing to do + else + { + + Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider); + + Image aImg(xGraphic); + // Save the original size, multiplied with 100 + ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100); + + Reference< drawing::XShape > xShape( + xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), + uno::UNO_QUERY); + + Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY ); + xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic)); + + ::awt::Point aPicPos; + + if(pASRCheck->IsChecked()) + { + // Resize the image, with keeping ASR + aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100)); + } + else + { + aPicSize.Width = aPageSize.Width/2 - 100; + aPicSize.Height = aPageSize.Height/2 - 100; + } + xShape->setSize(aPicSize); + aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2); + aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2; + + xShape->setPosition(aPicPos); + xSlide->add(xShape); + } + + if( sUrl2 == "Text Box" ) // create a Text Box + { + SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD); + pSlide->CreatePresObj(PRESOBJ_TEXT, sal_False, Rectangle(Point(aPageSize.Width/2 + 100,100), Point(aPageSize.Width-100, aPageSize.Height/2-100)), sal_True); + } + else if( sUrl2.isEmpty()){} // nothing to do + else + { + Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider); + + Image aImg(xGraphic); + // Save the original size, multiplied with 100 + ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100); + + Reference< drawing::XShape > xShape( + xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), + uno::UNO_QUERY); + + Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY ); + xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic)); + + ::awt::Point aPicPos; + + if(pASRCheck->IsChecked()) + { + // Resize the image, with keeping ASR + aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100)); + } + else + { + aPicSize.Width = aPageSize.Width/2 - 100; + aPicSize.Height = aPageSize.Height/2 - 100; + } + xShape->setSize(aPicSize); + aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2; + aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2; + + xShape->setPosition(aPicPos); + xSlide->add(xShape); + } + + if( sUrl3 == "Text Box" ) // create a Text Box + { + SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD); + pSlide->CreatePresObj(PRESOBJ_TEXT, sal_False, Rectangle(Point(100,aPageSize.Height/2-100), Point(aPageSize.Width/2-100, aPageSize.Height-100)), sal_True); + } + else if( sUrl3.isEmpty()){} // nothing to do + else + { + + Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl3, xProvider); + + Image aImg(xGraphic); + // Save the original size, multiplied with 100 + ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100); + + Reference< drawing::XShape > xShape( + xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), + uno::UNO_QUERY); + + Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY ); + xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic)); + + ::awt::Point aPicPos; + + if(pASRCheck->IsChecked()) + { + // Resize the image, with keeping ASR + aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100)); + } + else + { + aPicSize.Width = aPageSize.Width/2 - 100; + aPicSize.Height = aPageSize.Height/2 - 100; + } + xShape->setSize(aPicSize); + aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2); + aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2; + + + xShape->setPosition(aPicPos); + xSlide->add(xShape); + } + + if( sUrl4 == "Text Box" ) // create a Text Box + { + SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD); + pSlide->CreatePresObj(PRESOBJ_TEXT, sal_False, Rectangle(Point(aPageSize.Width/2 + 100,aPageSize.Height/2 - 100), Point(aPageSize.Width-100, aPageSize.Height-100)), sal_True); + } + else if( sUrl4.isEmpty()){} // nothing to do + else + { + Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl4, xProvider); + + Image aImg(xGraphic); + // Save the original size, multiplied with 100 + ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100); + + Reference< drawing::XShape > xShape( + xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), + uno::UNO_QUERY); + + Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY ); + xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic)); + + ::awt::Point aPicPos; + + if(pASRCheck->IsChecked()) + { + // Resize the image, with keeping ASR + aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100)); + } + else + { + aPicSize.Width = aPageSize.Width/2 - 100; + aPicSize.Height = aPageSize.Height/2 - 100; + } + xShape->setSize(aPicSize); + aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2; + aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2; + + xShape->setPosition(aPicPos); + xSlide->add(xShape); + } + } + delete pData; } else { InfoBox aInfo(this, OUString("Function is not implemented!")); aInfo.Execute(); } - EndDialog(0); + EndDialog(); + return 0; } return 0; } @@ -236,18 +556,79 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, FileHdl) css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW, SFXWB_GRAPHIC | SFXWB_MULTISELECTION ); + // Read configuration + OUString sUrl("."); + Reference< XInterface > xCfg; + try + { + xCfg = ::comphelper::ConfigurationHelper::openConfig( + ::comphelper::getProcessComponentContext(), + OUString("/org.openoffice.Office.Impress/"), + ::comphelper::ConfigurationHelper::E_READONLY); + + ::comphelper::ConfigurationHelper::readRelativeKey( + xCfg, + OUString("Pictures"), + OUString("Path")) >>= sUrl; + } + catch(const Exception&) + { + OSL_FAIL("Could not find config for Create Photo Album function"); + } + INetURLObject aFile( SvtPathOptions().GetPalettePath() ); - aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) ); + if (sUrl != "") + aDlg.SetDisplayDirectory(sUrl); + else + aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) ); if ( aDlg.Execute() == ERRCODE_NONE ) { Sequence< OUString > aFilesArr = aDlg.GetSelectedFiles(); if( aFilesArr.getLength() ) { - for ( sal_Int32 i = 0; i < aFilesArr.getLength(); ++i ) + sUrl = aDlg.GetDisplayDirectory(); + // Write out configuration + try + { + Reference< XInterface > xCfg = ::comphelper::ConfigurationHelper::openConfig( + ::comphelper::getProcessComponentContext(), + OUString("/org.openoffice.Office.Impress/"), + ::comphelper::ConfigurationHelper::E_STANDARD); + + ::comphelper::ConfigurationHelper::writeRelativeKey( + xCfg, + OUString("Pictures"), + OUString("Path"), + uno::makeAny(sUrl)); + + ::comphelper::ConfigurationHelper::flush(xCfg); + } + catch(const Exception&) + { + OSL_FAIL("Could not find config for Create Photo Album function"); + } + + if( aFilesArr.getLength() == 1) { - pImagesLst->InsertEntry( aFilesArr[i] ); + pRemoveBtn->Enable(); + pUpBtn->Disable(); + pDownBtn->Disable(); + } + else + { + pRemoveBtn->Enable(); + pUpBtn->Enable(); + pDownBtn->Enable(); + } + + for ( sal_Int32 i = 0; i < aFilesArr.getLength(); i++ ) + { + // Store full path, show filename only + OUString sFileName = aFilesArr[i].copy(aFilesArr[i].lastIndexOf("/")).replaceAll("/",""); + sal_Int16 nPos = pImagesLst->InsertEntry( sFileName ); + pImagesLst->SetEntryData(nPos, (void*)new OUString(aFilesArr[i])); } } } @@ -256,8 +637,22 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, FileHdl) IMPL_LINK_NOARG(SdPhotoAlbumDialog, TextHdl) { - sal_uInt16 nInsertPos = pImagesLst->GetSelectEntryPos() + 1; - pImagesLst->InsertEntry( OUString("Text Box"), nInsertPos); + sal_Int16 nPos; + sal_Int16 nInsertPos = pImagesLst->GetSelectEntryPos(); + if (nInsertPos < 0) + nPos = pImagesLst->InsertEntry( OUString("Text Box")); + else + nPos = pImagesLst->InsertEntry( OUString("Text Box"), nInsertPos); + + OUString sStr("Text Box"); + pImagesLst->SetEntryData(nPos, (void*)new OUString(sStr)); + + if(pImagesLst->GetEntryCount() >= 1) + { + pRemoveBtn->Enable(); + pUpBtn->Disable(); + pDownBtn->Disable(); + } return 0; } @@ -267,15 +662,35 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, UpHdl) && pImagesLst->GetSelectEntryPos() != 0) { OUString sActEntry( pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos()) ); + // actual data + OUString* pActData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos()); + OUString sAct(*pActData); + sal_uInt16 nActPos = pImagesLst->GetSelectEntryPos(); OUString sUpperEntry( pImagesLst->GetEntry(nActPos - 1) ); + // upper data + OUString* pUpperData = (OUString*) pImagesLst->GetEntryData(nActPos - 1); + OUString sUpper(*pUpperData); pImagesLst->RemoveEntry( sActEntry ); pImagesLst->RemoveEntry( sUpperEntry ); pImagesLst->InsertEntry( sActEntry, nActPos - 1 ); + pImagesLst->SetEntryData( nActPos - 1, (void*) new OUString(sAct)); + pImagesLst->InsertEntry( sUpperEntry, nActPos ); + pImagesLst->SetEntryData( nActPos, (void*) new OUString(sUpper)); + pImagesLst->SelectEntryPos(nActPos - 1); + + pDownBtn->Enable(); + + } + + if(pImagesLst->GetSelectEntryPos() == 0) + { + pDownBtn->Enable(); + pUpBtn->Disable(); } return 0; } @@ -286,15 +701,34 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, DownHdl) if (pImagesLst->GetEntry(nActPos + 1) != OUString("") ) { OUString sActEntry( pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos()) ); + OUString* pActData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos()); + OUString sAct(*pActData); + OUString sDownEntry( pImagesLst->GetEntry(nActPos + 1) ); + OUString* pDownData = (OUString*) pImagesLst->GetEntryData(nActPos + 1); + OUString sDown(*pDownData); pImagesLst->RemoveEntry( sActEntry ); pImagesLst->RemoveEntry( sDownEntry ); pImagesLst->InsertEntry( sDownEntry, nActPos ); + pImagesLst->SetEntryData( nActPos, (void*) new OUString(sAct)); + pImagesLst->InsertEntry( sActEntry, nActPos + 1 ); + pImagesLst->SetEntryData( nActPos + 1, (void*) new OUString(sDown)); pImagesLst->SelectEntryPos(nActPos + 1); + + } + + if(pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos() + 1) != OUString("")) + { + pDownBtn->Enable(); + pUpBtn->Enable(); + } + else + { + pDownBtn->Disable(); } return 0; } @@ -302,17 +736,56 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, DownHdl) IMPL_LINK_NOARG(SdPhotoAlbumDialog, RemoveHdl) { pImagesLst->RemoveEntry( pImagesLst->GetSelectEntryPos() ); + pImg->SetImage(Image()); + pFilenameLab->SetText(""); + + if(pImagesLst->GetEntryCount() >= 1) + { + pRemoveBtn->Enable(); + pUpBtn->Disable(); + pDownBtn->Disable(); + } + else + { + pRemoveBtn->Disable(); + pUpBtn->Disable(); + pDownBtn->Disable(); + } return 0; } IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl) { - OUString sImgUrl( pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos()) ); - if (sImgUrl != OUString("Text Box") ) + OUString* pData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos()); + OUString sImgUrl = pData ? OUString(*pData) : ""; + // Some UI functionality: if you select the first/last item in the list, + // the Up/Down button gets enabled/diabled (meaning: you cannot move up/down the item) + // disable/enable moving up + if(pImagesLst->GetSelectEntryPos() == 0) + { + pUpBtn->Disable(); + } + else + { + pUpBtn->Enable(); + } + + // disable/enable moving down + if(pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos() + 1) == OUString("")) + { + pDownBtn->Disable(); + } + else + { + pDownBtn->Enable(); + } + + if (sImgUrl != "Text Box") { GraphicFilter aCurFilter; Graphic aGraphic; INetURLObject aURLObj( sImgUrl ); + pFilenameLab->SetText(sImgUrl); sal_uInt16 nFilter = GRFILTER_FORMAT_DONTKNOW; @@ -342,7 +815,7 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl) Bitmap aBmp = aGraphic.GetBitmap(); sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width(); sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height(); - sal_Int32 nPrevWidth = 150; + sal_Int32 nPrevWidth = 200; sal_Int32 nPrewHeight = 150; double nXRatio = (double) nPrevWidth / nBmpWidth; @@ -358,22 +831,84 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl) else { pImg->SetImage(Image()); + pFilenameLab->SetText(""); } + return 0; } -void SdPhotoAlbumDialog::setFirstSlide(SdPage* pFirstSlide) +Reference< drawing::XDrawPage > SdPhotoAlbumDialog::appendNewSlide(AutoLayout aLayout, + Reference< drawing::XDrawPages > xDrawPages +) +{ + Reference< drawing::XDrawPage > xSlide; // Create the slide + Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY ); + xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() ); + SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD); + pSlide->SetAutoLayout(aLayout, sal_True); // Set the layout here + return xSlide; +} + +awt::Size SdPhotoAlbumDialog::createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize) +{ + double resizeWidth = aPicSize.Width; + double resizeHeight = aPicSize.Height; + double aspect = resizeWidth/resizeHeight; + + if( resizeWidth > aMaxSize.Width ) + { + resizeWidth = aMaxSize.Width; + resizeHeight = resizeWidth / aspect; + } + + if( resizeHeight > aMaxSize.Height ) + { + aspect = resizeWidth/resizeHeight; + resizeHeight = aMaxSize.Height; + resizeWidth = resizeHeight * aspect; + } + return awt::Size(resizeWidth, resizeHeight); +} + +Reference< drawing::XShape > SdPhotoAlbumDialog::createXShapeFromUrl(const OUString& sUrl, + Reference< lang::XMultiServiceFactory > xShapeFactory, + Reference< graphic::XGraphicProvider> xProvider +) { - SdrTextObj* pTitleObj; // title - pTitleObj = dynamic_cast< SdrTextObj* >(pFirstSlide->GetPresObj(PRESOBJ_TITLE)); - pFirstSlide->SetObjText(pTitleObj, NULL, PRESOBJ_TITLE, OUString("Photoalbum")); + //First, we create an XGraphic + ::comphelper::NamedValueCollection aMediaProperties; + aMediaProperties.put( "URL", OUString( sUrl ) ); + Reference< graphic::XGraphic> xGraphic = + xProvider->queryGraphic( aMediaProperties.getPropertyValues() ); + //And then, we can create the XShape from the XGraphic + Reference< drawing::XShape > xShape( + xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), + uno::UNO_QUERY + ); - SdrTextObj* pAuthorObj; // author's full name - pAuthorObj = dynamic_cast< SdrTextObj* >(pFirstSlide->GetPresObj(PRESOBJ_TEXT)); + Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY ); + xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic)); - SvtUserOptions aUserOptions; - pFirstSlide->SetObjText(pAuthorObj, NULL, PRESOBJ_TEXT, OUString("Author: ") + aUserOptions.GetFullName()); + return xShape; // Image loaded into XShape } +Reference< graphic::XGraphic> SdPhotoAlbumDialog::createXGraphicFromUrl(const OUString& sUrl, + Reference< graphic::XGraphicProvider> xProvider +) +{ + ::comphelper::NamedValueCollection aMediaProperties; + aMediaProperties.put( "URL", OUString( sUrl ) ); + Reference< graphic::XGraphic> xGraphic = + xProvider->queryGraphic( aMediaProperties.getPropertyValues() ); + return xGraphic; +} + +short SdPhotoAlbumDialog::Execute() +{ + return ModalDialog::Execute(); } + + +} // end of namespace sd + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/dlg/PhotoAlbumDialog.hxx b/sd/source/ui/dlg/PhotoAlbumDialog.hxx index cf70fc803c4b..98eb458d0c8f 100644 --- a/sd/source/ui/dlg/PhotoAlbumDialog.hxx +++ b/sd/source/ui/dlg/PhotoAlbumDialog.hxx @@ -22,11 +22,22 @@ #include <vcl/field.hxx> #include <vcl/graphicfilter.hxx> #include <svx/svdotext.hxx> +#include <svx/svdobj.hxx> + +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/graphic/GraphicProvider.hpp> +#include <com/sun/star/graphic/XGraphicProvider.hpp> +#include <com/sun/star/configuration/theDefaultProvider.hpp> class SdrTextObj; class SdDrawDocument; class SdPage; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::presentation; + namespace sd { @@ -36,7 +47,10 @@ public: SdPhotoAlbumDialog(Window* pWindow, SdDrawDocument* pActDoc); ~SdPhotoAlbumDialog(); + virtual short Execute(); + private: + static OUString sDirUrl; CancelButton* pCancelBtn; PushButton* pCreateBtn; @@ -49,7 +63,11 @@ private: ListBox* pImagesLst; FixedImage* pImg; - ListBox* pInsTypeCombo; + ListBox* pInsTypeCombo; + + CheckBox* pASRCheck; + + FixedText* pFilenameLab; SdDrawDocument* pDoc; GraphicFilter* mpGraphicFilter; @@ -65,10 +83,21 @@ private: DECL_LINK(SelectHdl, void*); - void setFirstSlide(SdPage* pFirstSlide); + Reference< drawing::XDrawPage > appendNewSlide(AutoLayout aLayout, + Reference< drawing::XDrawPages > xDrawPages); + + awt::Size createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize); + + Reference< drawing::XShape > createXShapeFromUrl(const OUString& sUrl, + Reference< lang::XMultiServiceFactory > xShapeFactory, + Reference< graphic::XGraphicProvider> xProvider); + + Reference< graphic::XGraphic> createXGraphicFromUrl(const OUString& sUrl, + Reference< graphic::XGraphicProvider> xProvider); + }; -} +} // end of namespace sd #endif // _SD_PHOTOALBUMDIALOG_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |