Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / dlg / PhotoAlbumDialog.cxx
blob95b46a89bb690d0c545001839f504c2ba5cc215f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <comphelper/namedvaluecollection.hxx>
11 #include <comphelper/processfactory.hxx>
12 #include <svl/itemset.hxx>
13 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
14 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
15 #include <com/sun/star/container/XNameAccess.hpp>
17 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
18 #include <com/sun/star/text/XText.hpp>
20 #include <sfx2/filedlghelper.hxx>
21 #include <tools/urlobj.hxx>
23 #include <unotools/pathoptions.hxx>
24 #include <unotools/useroptions.hxx>
25 #include <unotools/ucbstreamhelper.hxx>
26 #include <officecfg/Office/Impress.hxx>
27 #include <svx/svdview.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/weld.hxx>
30 #include <svx/unoshape.hxx>
31 #include <svx/xfltrit.hxx>
32 #include <svx/xfillit.hxx>
33 #include <xmloff/autolayout.hxx>
35 #include "PhotoAlbumDialog.hxx"
36 #include <strings.hrc>
37 #include <sdresid.hxx>
39 namespace sd
42 SdPhotoAlbumDialog::SdPhotoAlbumDialog(weld::Window* pWindow, SdDrawDocument* pActDoc)
43 : GenericDialogController(pWindow, "modules/simpress/ui/photoalbum.ui", "PhotoAlbumCreatorDialog")
44 , m_pDoc(pActDoc)
45 , m_xCancelBtn(m_xBuilder->weld_button("cancel"))
46 , m_xCreateBtn(m_xBuilder->weld_button("ok"))
47 , m_xAddBtn(m_xBuilder->weld_button("add_btn"))
48 , m_xUpBtn(m_xBuilder->weld_button("up_btn"))
49 , m_xDownBtn(m_xBuilder->weld_button("down_btn"))
50 , m_xRemoveBtn(m_xBuilder->weld_button("rem_btn"))
51 , m_xImagesLst(m_xBuilder->weld_tree_view("images_tree"))
52 , m_xImg(new weld::CustomWeld(*m_xBuilder, "preview_img", m_aImg))
53 , m_xInsTypeCombo(m_xBuilder->weld_combo_box_text("opt_combo"))
54 , m_xASRCheck(m_xBuilder->weld_check_button("asr_check"))
55 , m_xASRCheckCrop(m_xBuilder->weld_check_button("asr_check_crop"))
56 , m_xCapCheck(m_xBuilder->weld_check_button("cap_check"))
57 , m_xInsertAsLinkCheck(m_xBuilder->weld_check_button("insert_as_link_check"))
59 m_xCancelBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, CancelHdl));
60 m_xCreateBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, CreateHdl));
62 m_xAddBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, FileHdl));
63 m_xUpBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, UpHdl));
64 m_xUpBtn->set_sensitive(false);
65 m_xDownBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, DownHdl));
66 m_xDownBtn->set_sensitive(false);
67 m_xRemoveBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, RemoveHdl));
68 m_xRemoveBtn->set_sensitive(false);
69 m_xImagesLst->connect_changed(LINK(this, SdPhotoAlbumDialog, SelectHdl));
70 m_xInsTypeCombo->connect_changed(LINK(this, SdPhotoAlbumDialog, TypeSelectHdl));
72 m_pGraphicFilter = new GraphicFilter;
73 m_xAddBtn->grab_focus();
76 SdPhotoAlbumDialog::~SdPhotoAlbumDialog()
80 IMPL_LINK_NOARG(SdPhotoAlbumDialog, CancelHdl, weld::Button&, void)
82 m_xDialog->response(RET_CANCEL);
85 IMPL_LINK_NOARG(SdPhotoAlbumDialog, CreateHdl, weld::Button&, void)
87 if (m_xImagesLst->n_children() == 0)
89 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(m_xDialog.get(),
90 VclMessageType::Warning, VclButtonsType::Ok,
91 SdResId(STR_PHOTO_ALBUM_EMPTY_WARNING)));
92 xWarn->run();
94 else
96 Reference< drawing::XDrawPagesSupplier > xDPS( m_pDoc->getUnoModel(), uno::UNO_QUERY );
97 Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_QUERY );
98 Reference< lang::XMultiServiceFactory > xShapeFactory( m_pDoc->getUnoModel(), uno::UNO_QUERY );
100 Reference< XComponentContext > xContext(::comphelper::getProcessComponentContext());
101 Reference< graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(xContext));
103 // determine if to use Captions (use TitleObject) and choose the correct AutoLayout
104 // from the beginning
105 const bool bCreateCaptions(m_xCapCheck->get_active());
106 const bool bInsertAsLink(m_xInsertAsLinkCheck->get_active());
107 const AutoLayout aAutoLayout(bCreateCaptions ? AUTOLAYOUT_TITLE_ONLY : AUTOLAYOUT_NONE);
109 // get the option
110 const int nOpt = m_xInsTypeCombo->get_active();
111 if (nOpt == ONE_IMAGE)
113 for( sal_Int32 i = 0; i < m_xImagesLst->n_children(); ++i )
115 OUString sUrl = m_xImagesLst->get_id(i);
117 Reference< drawing::XDrawPage > xSlide = appendNewSlide(aAutoLayout, xDrawPages);
118 Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
119 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl, xProvider);
121 Graphic aGraphic(xGraphic);
122 if (bInsertAsLink)
123 aGraphic.setOriginURL(sUrl);
125 // Save the original size, multiplied with 100
126 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
128 Reference< drawing::XShape > xShape(
129 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
130 uno::UNO_QUERY);
132 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
133 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
135 ::awt::Size aPageSize;
137 xSlideProps->getPropertyValue(
138 "Width") >>= aPageSize.Width;
139 xSlideProps->getPropertyValue(
140 "Height") >>= aPageSize.Height;
142 ::awt::Point aPicPos;
144 if (m_xASRCheck->get_active() && !m_xASRCheckCrop->get_active())
146 // Resize the image, with keeping ASR
147 aPicSize = createASRSize(aPicSize, aPageSize);
149 else if (m_xASRCheckCrop->get_active())
151 aPicSize = createASRSizeCrop(aPicSize, aPageSize);
154 xShape->setSize(aPicSize);
155 aPicPos.X = (aPageSize.Width - aPicSize.Width)/2;
156 aPicPos.Y = (aPageSize.Height - aPicSize.Height)/2;
158 xShape->setPosition(aPicPos);
161 xSlide->add(xShape);
162 if (bCreateCaptions)
163 createCaption( aPageSize );
165 catch (const css::uno::Exception& exc)
167 SAL_WARN( "sd", exc );
171 else if( nOpt == TWO_IMAGES )
173 for( sal_Int32 i = 0; i < m_xImagesLst->n_children(); i+=2 )
175 // create the slide
176 Reference< drawing::XDrawPage > xSlide = appendNewSlide(aAutoLayout, xDrawPages);
177 Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
178 //Slide dimensions
179 ::awt::Size aPageSize;
181 xSlideProps->getPropertyValue(
182 "Width") >>= aPageSize.Width;
183 xSlideProps->getPropertyValue(
184 "Height") >>= aPageSize.Height;
186 // grab the left one
187 OUString sUrl1 = m_xImagesLst->get_id(i);
188 // grab the right one
189 OUString sUrl2 = m_xImagesLst->get_id(i+1);
191 if( !sUrl1.isEmpty() )
193 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
195 Graphic aGraphic(xGraphic);
196 if (bInsertAsLink)
197 aGraphic.setOriginURL(sUrl1);
198 // Save the original size, multiplied with 100
199 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
201 Reference< drawing::XShape > xShape(
202 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
203 uno::UNO_QUERY);
205 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
206 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
208 ::awt::Point aPicPos;
210 if (m_xASRCheck->get_active())
212 // Resize the image, with keeping ASR
213 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
215 else
217 aPicSize.Width = aPageSize.Width/2 - 100;
218 aPicSize.Height = aPageSize.Height/2 - 100;
220 xShape->setSize(aPicSize);
221 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
222 aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
224 xShape->setPosition(aPicPos);
227 xSlide->add(xShape);
229 catch (const css::uno::Exception& exc)
231 SAL_WARN( "sd", exc );
235 if( !sUrl2.isEmpty() )
237 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
239 Graphic aGraphic(xGraphic);
240 if (bInsertAsLink)
241 aGraphic.setOriginURL(sUrl2);
242 // Save the original size, multiplied with 100
243 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
245 Reference< drawing::XShape > xShape(
246 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
247 uno::UNO_QUERY);
249 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
250 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
252 ::awt::Point aPicPos;
254 if (m_xASRCheck->get_active())
256 // Resize the image, with keeping ASR
257 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
259 else
261 aPicSize.Width = aPageSize.Width/2 - 100;
262 aPicSize.Height = aPageSize.Height/2 - 100;
264 xShape->setSize(aPicSize);
265 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
266 aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
268 xShape->setPosition(aPicPos);
272 xSlide->add(xShape);
273 if(bCreateCaptions)
274 createCaption( aPageSize );
276 catch (const css::uno::Exception& exc)
278 SAL_WARN( "sd", exc );
283 else if( nOpt == FOUR_IMAGES )
285 for( sal_Int32 i = 0; i < m_xImagesLst->n_children(); i+=4 )
287 // create the slide
288 Reference< drawing::XDrawPage > xSlide = appendNewSlide(aAutoLayout, xDrawPages);
289 Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
290 //Slide dimensions
291 ::awt::Size aPageSize;
293 xSlideProps->getPropertyValue(
294 "Width") >>= aPageSize.Width;
295 xSlideProps->getPropertyValue(
296 "Height") >>= aPageSize.Height;
298 // grab the upper left one
299 OUString sUrl1 = m_xImagesLst->get_id(i);
301 // grab the upper right one
302 OUString sUrl2 = m_xImagesLst->get_id(i+1);
304 // grab the lower left one
305 OUString sUrl3 = m_xImagesLst->get_id(i+2);
307 // grab the lower right one
308 OUString sUrl4 = m_xImagesLst->get_id(i+3);
310 if( !sUrl1.isEmpty() )
312 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
314 Graphic aGraphic(xGraphic);
315 if (bInsertAsLink)
316 aGraphic.setOriginURL(sUrl1);
317 // Save the original size, multiplied with 100
318 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
320 Reference< drawing::XShape > xShape(
321 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
322 uno::UNO_QUERY);
324 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
325 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
327 ::awt::Point aPicPos;
329 if (m_xASRCheck->get_active())
331 // Resize the image, with keeping ASR
332 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
334 else
336 aPicSize.Width = aPageSize.Width/2 - 100;
337 aPicSize.Height = aPageSize.Height/2 - 100;
339 xShape->setSize(aPicSize);
340 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
341 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
343 xShape->setPosition(aPicPos);
346 xSlide->add(xShape);
348 catch (const css::uno::Exception& exc)
350 SAL_WARN( "sd", exc );
353 if( !sUrl2.isEmpty() )
355 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
357 Graphic aGraphic(xGraphic);
358 if (bInsertAsLink)
359 aGraphic.setOriginURL(sUrl2);
360 // Save the original size, multiplied with 100
361 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
363 Reference< drawing::XShape > xShape(
364 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
365 uno::UNO_QUERY);
367 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
368 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
370 ::awt::Point aPicPos;
372 if (m_xASRCheck->get_active())
374 // Resize the image, with keeping ASR
375 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
377 else
379 aPicSize.Width = aPageSize.Width/2 - 100;
380 aPicSize.Height = aPageSize.Height/2 - 100;
382 xShape->setSize(aPicSize);
383 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
384 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
386 xShape->setPosition(aPicPos);
389 xSlide->add(xShape);
391 catch (const css::uno::Exception& exc)
393 SAL_WARN( "sd", exc );
396 if( !sUrl3.isEmpty() )
398 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl3, xProvider);
400 Graphic aGraphic(xGraphic);
401 if (bInsertAsLink)
402 aGraphic.setOriginURL(sUrl3);
403 // Save the original size, multiplied with 100
404 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
406 Reference< drawing::XShape > xShape(
407 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
408 uno::UNO_QUERY);
410 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
411 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
413 ::awt::Point aPicPos;
415 if (m_xASRCheck->get_active())
417 // Resize the image, with keeping ASR
418 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
420 else
422 aPicSize.Width = aPageSize.Width/2 - 100;
423 aPicSize.Height = aPageSize.Height/2 - 100;
425 xShape->setSize(aPicSize);
426 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
427 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
429 xShape->setPosition(aPicPos);
432 xSlide->add(xShape);
434 catch (const css::uno::Exception& exc)
436 SAL_WARN( "sd", exc );
439 if( !sUrl4.isEmpty() )
441 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl4, xProvider);
443 Graphic aGraphic(xGraphic);
444 if (bInsertAsLink)
445 aGraphic.setOriginURL(sUrl4);
446 // Save the original size, multiplied with 100
447 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
449 Reference< drawing::XShape > xShape(
450 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
451 uno::UNO_QUERY);
453 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
454 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
456 ::awt::Point aPicPos;
458 if (m_xASRCheck->get_active())
460 // Resize the image, with keeping ASR
461 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
463 else
465 aPicSize.Width = aPageSize.Width/2 - 100;
466 aPicSize.Height = aPageSize.Height/2 - 100;
468 xShape->setSize(aPicSize);
469 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
470 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
472 xShape->setPosition(aPicPos);
475 xSlide->add(xShape);
476 if(bCreateCaptions)
477 createCaption( aPageSize );
479 catch (const css::uno::Exception& exc)
481 SAL_WARN( "sd", exc );
486 else
488 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(),
489 VclMessageType::Info, VclButtonsType::Ok,
490 "Function is not implemented!"));
491 xInfoBox->run();
493 m_xDialog->response(RET_OK);
497 IMPL_LINK_NOARG(SdPhotoAlbumDialog, FileHdl, weld::Button&, void)
499 ::sfx2::FileDialogHelper aDlg(
500 css::ui::dialogs::TemplateDescription::FILEOPEN_PREVIEW,
501 FileDialogFlags::Graphic | FileDialogFlags::MultiSelection, m_xDialog.get());
502 // Read configuration
503 OUString sUrl(officecfg::Office::Impress::Pictures::Path::get());
505 INetURLObject aFile( SvtPathOptions().GetUserConfigPath() );
506 if (!sUrl.isEmpty())
507 aDlg.SetDisplayDirectory(sUrl);
508 else
509 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
511 if ( aDlg.Execute() == ERRCODE_NONE )
513 Sequence< OUString > aFilesArr = aDlg.GetSelectedFiles();
514 if( aFilesArr.getLength() )
516 sUrl = aDlg.GetDisplayDirectory();
517 // Write out configuration
519 std::shared_ptr< comphelper::ConfigurationChanges > batch(
520 comphelper::ConfigurationChanges::create());
521 officecfg::Office::Impress::Pictures::Path::set(sUrl, batch);
522 batch->commit();
525 for ( sal_Int32 i = 0; i < aFilesArr.getLength(); i++ )
527 // Store full path, show filename only. Use INetURLObject to display spaces in filename correctly
528 INetURLObject aUrl = INetURLObject(aFilesArr[i]);
529 m_xImagesLst->append(aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE), aUrl.GetLastName(INetURLObject::DecodeMechanism::WithCharset), "");
533 EnableDisableButtons();
536 IMPL_LINK_NOARG(SdPhotoAlbumDialog, UpHdl, weld::Button&, void)
538 const int nActPos = m_xImagesLst->get_selected_index();
539 if (nActPos != -1 && nActPos != 0)
541 OUString sActEntry(m_xImagesLst->get_text(nActPos));
542 // actual data
543 OUString sAct(m_xImagesLst->get_id(nActPos));
545 OUString sUpperEntry(m_xImagesLst->get_text(nActPos - 1));
546 // upper data
547 OUString sUpper(m_xImagesLst->get_id(nActPos - 1));
549 m_xImagesLst->remove_text(sActEntry);
550 m_xImagesLst->remove_text(sUpperEntry);
552 m_xImagesLst->insert(nActPos - 1, sAct, sActEntry, "");
553 m_xImagesLst->insert(nActPos, sUpper, sUpperEntry, "");
555 m_xImagesLst->select(nActPos - 1);
558 EnableDisableButtons();
561 IMPL_LINK_NOARG(SdPhotoAlbumDialog, DownHdl, weld::Button&, void)
563 const int nActPos = m_xImagesLst->get_selected_index();
564 if (!m_xImagesLst->get_text(nActPos + 1).isEmpty())
566 OUString sActEntry(m_xImagesLst->get_selected_text());
567 OUString sAct(m_xImagesLst->get_selected_id());
569 OUString sDownEntry(m_xImagesLst->get_text(nActPos + 1));
570 OUString sDown(m_xImagesLst->get_id(nActPos + 1));
572 m_xImagesLst->remove_text(sActEntry);
573 m_xImagesLst->remove_text(sDownEntry);
575 m_xImagesLst->insert(nActPos, sDown, sDownEntry, "");
576 m_xImagesLst->insert(nActPos + 1, sAct, sActEntry, "");
578 m_xImagesLst->select(nActPos + 1);
580 EnableDisableButtons();
583 IMPL_LINK_NOARG(SdPhotoAlbumDialog, RemoveHdl, weld::Button&, void)
585 m_xImagesLst->remove(m_xImagesLst->get_selected_index());
586 m_aImg.SetGraphic(Graphic());
588 EnableDisableButtons();
591 IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl, weld::TreeView&, void)
593 OUString sImgUrl = m_xImagesLst->get_selected_id();
595 if (sImgUrl != SdResId(STR_PHOTO_ALBUM_TEXTBOX))
597 GraphicFilter aCurFilter;
598 Graphic aGraphic;
599 INetURLObject aURLObj( sImgUrl );
601 sal_uInt16 nFilter = GRFILTER_FORMAT_DONTKNOW;
603 if ( aURLObj.HasError() || INetProtocol::NotValid == aURLObj.GetProtocol() )
605 aURLObj.SetSmartProtocol( INetProtocol::File );
606 aURLObj.SetSmartURL( sImgUrl );
609 GraphicFilterImportFlags nFilterImportFlags = GraphicFilterImportFlags::SetLogsizeForJpeg;
610 // remote?
611 if ( INetProtocol::File != aURLObj.GetProtocol() )
613 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( sImgUrl, StreamMode::READ );
615 if( pStream )
616 m_pGraphicFilter->ImportGraphic( aGraphic, sImgUrl, *pStream, nFilter, nullptr, nFilterImportFlags );
617 else
618 m_pGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, nullptr, nFilterImportFlags );
619 delete pStream;
621 else
623 m_pGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, nullptr, nFilterImportFlags );
626 Bitmap aBmp = aGraphic.GetBitmap();
627 sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
628 sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
630 double nXRatio = double(200) / nBmpWidth;
631 double nYRatio = double(150) / nBmpHeight;
632 if ( nXRatio < nYRatio )
633 aBmp.Scale( nXRatio, nXRatio );
634 else
635 aBmp.Scale( nYRatio, nYRatio );
637 aBmp.Convert( BmpConversion::N24Bit );
638 m_aImg.SetGraphic(Graphic(aBmp));
640 else
642 m_aImg.SetGraphic(Graphic());
644 EnableDisableButtons();
647 IMPL_LINK_NOARG(SdPhotoAlbumDialog, TypeSelectHdl, weld::ComboBoxText&, void)
649 // Enable "Fill Slide" only for one image
650 // If we want to have it for other images too, we need to implement the actual cropping.
651 bool const bEnable = m_xInsTypeCombo->get_active() == ONE_IMAGE;
652 m_xASRCheckCrop->set_sensitive(bEnable);
653 if (!bEnable)
654 m_xASRCheckCrop->set_active(false);
657 Reference< drawing::XDrawPage > SdPhotoAlbumDialog::appendNewSlide(AutoLayout aLayout,
658 const Reference< drawing::XDrawPages >& xDrawPages
661 Reference< drawing::XDrawPage > xSlide; // Create the slide
662 Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY );
663 xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() );
664 SdPage* pSlide = m_pDoc->GetSdPage( m_pDoc->GetSdPageCount(PageKind::Standard)-1, PageKind::Standard);
665 pSlide->SetAutoLayout(aLayout, true); // Set the layout here
666 return xSlide;
669 awt::Size SdPhotoAlbumDialog::createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize)
671 double resizeWidth = aPicSize.Width;
672 double resizeHeight = aPicSize.Height;
673 double aspect = resizeWidth/resizeHeight;
675 if( resizeWidth > aMaxSize.Width )
677 resizeWidth = aMaxSize.Width;
678 resizeHeight = resizeWidth / aspect;
681 if( resizeHeight > aMaxSize.Height )
683 aspect = resizeWidth/resizeHeight;
684 resizeHeight = aMaxSize.Height;
685 resizeWidth = resizeHeight * aspect;
687 return awt::Size(resizeWidth, resizeHeight);
690 awt::Size SdPhotoAlbumDialog::createASRSizeCrop(const awt::Size& aPicSize, const awt::Size& aMaxSize)
692 double resizeWidth = aPicSize.Width;
693 double resizeHeight = aPicSize.Height;
694 double imgAspect = resizeWidth / resizeHeight;
695 double windowAspectRatio = static_cast<double>(aMaxSize.Width) / aMaxSize.Height ;
698 //When both sides of an image are bigger than canvas size, image would be downscaled.
699 if( resizeWidth > aMaxSize.Width && resizeHeight > aMaxSize.Height )
701 if( imgAspect > windowAspectRatio )
703 resizeHeight = aMaxSize.Height;
704 resizeWidth = aMaxSize.Height * imgAspect;
706 else
708 resizeHeight = aMaxSize.Width / imgAspect;
709 resizeWidth = aMaxSize.Width;
713 //In all other cases image is upscaled
714 else
716 if( imgAspect > windowAspectRatio )
718 resizeHeight = aMaxSize.Height;
719 resizeWidth = aMaxSize.Height * imgAspect;
721 else
723 resizeWidth = aMaxSize.Width;
724 resizeHeight = aMaxSize.Width / imgAspect;
727 return awt::Size(resizeWidth, resizeHeight);
730 void SdPhotoAlbumDialog::createCaption(const awt::Size& aPageSize )
732 Point CapPos;
733 Size CapSize;
735 CapSize.setWidth( aPageSize.Width );
736 CapSize.setHeight( aPageSize.Height/6 );
737 CapPos.setX( 0 );
738 CapPos.setY( aPageSize.Height - CapSize.Height() );
739 SdPage* pSlide = m_pDoc->GetSdPage( m_pDoc->GetSdPageCount(PageKind::Standard)-1, PageKind::Standard );
741 // try to get existing PresObj
742 const ::tools::Rectangle rRect(CapPos,CapSize);
743 SdrObject* pSdrObj = pSlide->GetPresObj(PRESOBJ_TITLE);
745 if(!pSdrObj)
747 // if not exists, create. Beware: It is already inserted to the SdPage
748 pSdrObj = pSlide->CreatePresObj(PRESOBJ_TITLE,false,rRect);
750 else
752 // if exists, bring to front and position it
753 const size_t nObjNum(pSlide->GetObjCount());
755 if(nObjNum)
757 pSlide->SetObjectOrdNum(pSdrObj->GetOrdNum(), nObjNum - 1);
760 pSdrObj->SetSnapRect(rRect);
763 if(pSdrObj)
765 // set color, style and some transparency
766 SfxItemSet aSet(m_pDoc->GetItemPool() );
768 aSet.Put( XFillStyleItem(drawing::FillStyle_SOLID) );
769 aSet.Put( XFillColorItem( "", COL_BLACK ) );
770 aSet.Put( XFillTransparenceItem( 20 ) );
771 pSdrObj->SetMergedItemSetAndBroadcast(aSet);
775 Reference< graphic::XGraphic> SdPhotoAlbumDialog::createXGraphicFromUrl(const OUString& sUrl,
776 const Reference< graphic::XGraphicProvider>& xProvider
779 // The same as above, except this returns an XGraphic from the image URL
780 ::comphelper::NamedValueCollection aMediaProperties;
781 aMediaProperties.put( "URL", sUrl );
782 Reference< graphic::XGraphic> xGraphic =
783 xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
784 return xGraphic;
787 void SdPhotoAlbumDialog::EnableDisableButtons()
789 m_xRemoveBtn->set_sensitive(m_xImagesLst->count_selected_rows() > 0);
790 m_xUpBtn->set_sensitive(m_xImagesLst->count_selected_rows() > 0 &&
791 m_xImagesLst->get_selected_index() != 0);
792 m_xDownBtn->set_sensitive(m_xImagesLst->count_selected_rows() > 0 &&
793 m_xImagesLst->get_selected_index() < m_xImagesLst->n_children() - 1);
796 } // end of namespace sd
798 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */