remove assert looking for new compatibilityMode DOCX
[LibreOffice.git] / sd / source / ui / dlg / PhotoAlbumDialog.cxx
blob870c6d64f56a7ba72a9ff4cd3133417fcac624f7
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/graphic/GraphicProvider.hpp>
15 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
16 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
18 #include <sfx2/filedlghelper.hxx>
19 #include <tools/urlobj.hxx>
21 #include <unotools/ucbstreamhelper.hxx>
22 #include <vcl/graphicfilter.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/weld.hxx>
25 #include <svx/xfillit0.hxx>
26 #include <svx/xfltrit.hxx>
27 #include <svx/xflclit.hxx>
28 #include <comphelper/diagnose_ex.hxx>
29 #include <xmloff/autolayout.hxx>
31 #include "PhotoAlbumDialog.hxx"
32 #include <strings.hrc>
33 #include <sdresid.hxx>
34 #include <drawdoc.hxx>
35 #include <sdpage.hxx>
36 #include <unomodel.hxx>
38 namespace sd
41 SdPhotoAlbumDialog::SdPhotoAlbumDialog(weld::Window* pWindow, SdDrawDocument* pActDoc)
42 : GenericDialogController(pWindow, u"modules/simpress/ui/photoalbum.ui"_ustr, u"PhotoAlbumCreatorDialog"_ustr)
43 , m_pDoc(pActDoc)
44 , m_aImg(m_xDialog.get())
45 , m_xCancelBtn(m_xBuilder->weld_button(u"cancel"_ustr))
46 , m_xCreateBtn(m_xBuilder->weld_button(u"ok"_ustr))
47 , m_xAddBtn(m_xBuilder->weld_button(u"add_btn"_ustr))
48 , m_xUpBtn(m_xBuilder->weld_button(u"up_btn"_ustr))
49 , m_xDownBtn(m_xBuilder->weld_button(u"down_btn"_ustr))
50 , m_xRemoveBtn(m_xBuilder->weld_button(u"rem_btn"_ustr))
51 , m_xImagesLst(m_xBuilder->weld_tree_view(u"images_tree"_ustr))
52 , m_xImg(new weld::CustomWeld(*m_xBuilder, u"preview_img"_ustr, m_aImg))
53 , m_xInsTypeCombo(m_xBuilder->weld_combo_box(u"opt_combo"_ustr))
54 , m_xASRCheck(m_xBuilder->weld_check_button(u"asr_check"_ustr))
55 , m_xASRCheckCrop(m_xBuilder->weld_check_button(u"asr_check_crop"_ustr))
56 , m_xCapCheck(m_xBuilder->weld_check_button(u"cap_check"_ustr))
57 , m_xInsertAsLinkCheck(m_xBuilder->weld_check_button(u"insert_as_link_check"_ustr))
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_selection_changed(LINK(this, SdPhotoAlbumDialog, SelectHdl));
70 m_xInsTypeCombo->connect_changed(LINK(this, SdPhotoAlbumDialog, TypeSelectHdl));
72 m_pGraphicFilter = std::make_unique<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 rtl::Reference< SdXImpressDocument > xDPS( m_pDoc->getUnoModel() );
97 Reference< drawing::XDrawPages > xDrawPages = xDPS->getDrawPages();
98 rtl::Reference< SdXImpressDocument > xShapeFactory( m_pDoc->getUnoModel() );
100 const 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(u"com.sun.star.drawing.GraphicObjectShape"_ustr),
130 uno::UNO_QUERY);
132 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
133 xProps->setPropertyValue(u"Graphic"_ustr, ::uno::Any(xGraphic));
135 ::awt::Size aPageSize;
137 xSlideProps->getPropertyValue(
138 u"Width"_ustr) >>= aPageSize.Width;
139 xSlideProps->getPropertyValue(
140 u"Height"_ustr) >>= 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&)
167 TOOLS_WARN_EXCEPTION( "sd", "" );
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 u"Width"_ustr) >>= aPageSize.Width;
183 xSlideProps->getPropertyValue(
184 u"Height"_ustr) >>= 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(u"com.sun.star.drawing.GraphicObjectShape"_ustr),
203 uno::UNO_QUERY);
205 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
206 xProps->setPropertyValue(u"Graphic"_ustr, ::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&)
231 TOOLS_WARN_EXCEPTION( "sd", "" );
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(u"com.sun.star.drawing.GraphicObjectShape"_ustr),
247 uno::UNO_QUERY);
249 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
250 xProps->setPropertyValue(u"Graphic"_ustr, ::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&)
278 TOOLS_WARN_EXCEPTION( "sd", "" );
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 u"Width"_ustr) >>= aPageSize.Width;
295 xSlideProps->getPropertyValue(
296 u"Height"_ustr) >>= 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(u"com.sun.star.drawing.GraphicObjectShape"_ustr),
322 uno::UNO_QUERY);
324 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
325 xProps->setPropertyValue(u"Graphic"_ustr, ::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&)
350 TOOLS_WARN_EXCEPTION( "sd", "" );
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(u"com.sun.star.drawing.GraphicObjectShape"_ustr),
365 uno::UNO_QUERY);
367 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
368 xProps->setPropertyValue(u"Graphic"_ustr, ::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&)
393 TOOLS_WARN_EXCEPTION( "sd", "" );
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(u"com.sun.star.drawing.GraphicObjectShape"_ustr),
408 uno::UNO_QUERY);
410 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
411 xProps->setPropertyValue(u"Graphic"_ustr, ::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&)
436 TOOLS_WARN_EXCEPTION( "sd", "" );
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(u"com.sun.star.drawing.GraphicObjectShape"_ustr),
451 uno::UNO_QUERY);
453 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
454 xProps->setPropertyValue(u"Graphic"_ustr, ::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&)
481 TOOLS_WARN_EXCEPTION( "sd", "" );
486 else
488 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(),
489 VclMessageType::Info, VclButtonsType::Ok,
490 u"Function is not implemented!"_ustr));
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 aDlg.SetContext(sfx2::FileDialogHelper::ImpressPhotoDialog);
504 if ( aDlg.Execute() == ERRCODE_NONE )
506 const Sequence< OUString > aFilesArr = aDlg.GetSelectedFiles();
507 for ( const auto& rFile : aFilesArr )
509 // Store full path, show filename only. Use INetURLObject to display spaces in filename correctly
510 INetURLObject aUrl(rFile);
511 m_xImagesLst->append(aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE), aUrl.GetLastName(INetURLObject::DecodeMechanism::WithCharset), u""_ustr);
514 EnableDisableButtons();
517 IMPL_LINK_NOARG(SdPhotoAlbumDialog, UpHdl, weld::Button&, void)
519 const int nActPos = m_xImagesLst->get_selected_index();
520 if (nActPos != -1 && nActPos != 0)
522 OUString sActEntry(m_xImagesLst->get_text(nActPos));
523 // actual data
524 OUString sAct(m_xImagesLst->get_id(nActPos));
526 OUString sUpperEntry(m_xImagesLst->get_text(nActPos - 1));
527 // upper data
528 OUString sUpper(m_xImagesLst->get_id(nActPos - 1));
530 m_xImagesLst->remove_text(sActEntry);
531 m_xImagesLst->remove_text(sUpperEntry);
533 m_xImagesLst->insert(nActPos - 1, sActEntry, &sAct, nullptr, nullptr);
534 m_xImagesLst->insert(nActPos, sUpperEntry, &sUpper, nullptr, nullptr);
536 m_xImagesLst->select(nActPos - 1);
539 EnableDisableButtons();
542 IMPL_LINK_NOARG(SdPhotoAlbumDialog, DownHdl, weld::Button&, void)
544 const int nActPos = m_xImagesLst->get_selected_index();
545 if (!m_xImagesLst->get_text(nActPos + 1).isEmpty())
547 OUString sActEntry(m_xImagesLst->get_selected_text());
548 OUString sAct(m_xImagesLst->get_selected_id());
550 OUString sDownEntry(m_xImagesLst->get_text(nActPos + 1));
551 OUString sDown(m_xImagesLst->get_id(nActPos + 1));
553 m_xImagesLst->remove_text(sActEntry);
554 m_xImagesLst->remove_text(sDownEntry);
556 m_xImagesLst->insert(nActPos, sDownEntry, &sDown, nullptr, nullptr);
557 m_xImagesLst->insert(nActPos + 1, sActEntry, &sAct, nullptr, nullptr);
559 m_xImagesLst->select(nActPos + 1);
561 EnableDisableButtons();
564 IMPL_LINK_NOARG(SdPhotoAlbumDialog, RemoveHdl, weld::Button&, void)
566 m_xImagesLst->remove(m_xImagesLst->get_selected_index());
567 m_aImg.SetGraphic(Graphic());
569 EnableDisableButtons();
572 IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl, weld::TreeView&, void)
574 OUString sImgUrl = m_xImagesLst->get_selected_id();
576 if (sImgUrl != SdResId(STR_PHOTO_ALBUM_TEXTBOX))
578 Graphic aGraphic;
579 INetURLObject aURLObj( sImgUrl );
581 sal_uInt16 nFilter = GRFILTER_FORMAT_DONTKNOW;
583 if ( aURLObj.HasError() || INetProtocol::NotValid == aURLObj.GetProtocol() )
585 aURLObj.SetSmartProtocol( INetProtocol::File );
586 aURLObj.SetSmartURL( sImgUrl );
589 GraphicFilterImportFlags nFilterImportFlags = GraphicFilterImportFlags::SetLogsizeForJpeg;
590 // remote?
591 if ( INetProtocol::File != aURLObj.GetProtocol() )
593 std::unique_ptr<SvStream> pStream = ::utl::UcbStreamHelper::CreateStream( sImgUrl, StreamMode::READ );
595 if( pStream )
596 m_pGraphicFilter->ImportGraphic( aGraphic, sImgUrl, *pStream, nFilter, nullptr, nFilterImportFlags );
597 else
598 m_pGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, nullptr, nFilterImportFlags );
600 else
602 m_pGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, nullptr, nFilterImportFlags );
605 BitmapEx aBmp = aGraphic.GetBitmapEx();
606 sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
607 sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
609 double nXRatio = double(200) / nBmpWidth;
610 double nYRatio = double(150) / nBmpHeight;
611 if ( nXRatio < nYRatio )
612 aBmp.Scale( nXRatio, nXRatio );
613 else
614 aBmp.Scale( nYRatio, nYRatio );
616 aBmp.Convert( BmpConversion::N24Bit );
617 m_aImg.SetGraphic(Graphic(aBmp));
619 else
621 m_aImg.SetGraphic(Graphic());
623 EnableDisableButtons();
626 IMPL_LINK_NOARG(SdPhotoAlbumDialog, TypeSelectHdl, weld::ComboBox&, void)
628 // Enable "Fill Slide" only for one image
629 // If we want to have it for other images too, we need to implement the actual cropping.
630 bool const bEnable = m_xInsTypeCombo->get_active() == ONE_IMAGE;
631 m_xASRCheckCrop->set_sensitive(bEnable);
632 if (!bEnable)
633 m_xASRCheckCrop->set_active(false);
636 Reference< drawing::XDrawPage > SdPhotoAlbumDialog::appendNewSlide(AutoLayout aLayout,
637 const Reference< drawing::XDrawPages >& xDrawPages
640 // Create the slide
641 Reference< drawing::XDrawPage > xSlide = xDrawPages->insertNewByIndex( xDrawPages->getCount() );
642 SdPage* pSlide = m_pDoc->GetSdPage( m_pDoc->GetSdPageCount(PageKind::Standard)-1, PageKind::Standard);
643 pSlide->SetAutoLayout(aLayout, true); // Set the layout here
644 return xSlide;
647 awt::Size SdPhotoAlbumDialog::createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize)
649 double resizeWidth = aPicSize.Width;
650 double resizeHeight = aPicSize.Height;
651 double aspect = resizeWidth/resizeHeight;
653 if( resizeWidth > aMaxSize.Width )
655 resizeWidth = aMaxSize.Width;
656 resizeHeight = resizeWidth / aspect;
659 if( resizeHeight > aMaxSize.Height )
661 aspect = resizeWidth/resizeHeight;
662 resizeHeight = aMaxSize.Height;
663 resizeWidth = resizeHeight * aspect;
665 return awt::Size(resizeWidth, resizeHeight);
668 awt::Size SdPhotoAlbumDialog::createASRSizeCrop(const awt::Size& aPicSize, const awt::Size& aMaxSize)
670 double resizeWidth = aPicSize.Width;
671 double resizeHeight = aPicSize.Height;
672 double imgAspect = resizeWidth / resizeHeight;
673 double windowAspectRatio = static_cast<double>(aMaxSize.Width) / aMaxSize.Height ;
676 //When both sides of an image are bigger than canvas size, image would be downscaled.
677 if( resizeWidth > aMaxSize.Width && resizeHeight > aMaxSize.Height )
679 if( imgAspect > windowAspectRatio )
681 resizeHeight = aMaxSize.Height;
682 resizeWidth = aMaxSize.Height * imgAspect;
684 else
686 resizeHeight = aMaxSize.Width / imgAspect;
687 resizeWidth = aMaxSize.Width;
691 //In all other cases image is upscaled
692 else
694 if( imgAspect > windowAspectRatio )
696 resizeHeight = aMaxSize.Height;
697 resizeWidth = aMaxSize.Height * imgAspect;
699 else
701 resizeWidth = aMaxSize.Width;
702 resizeHeight = aMaxSize.Width / imgAspect;
705 return awt::Size(resizeWidth, resizeHeight);
708 void SdPhotoAlbumDialog::createCaption(const awt::Size& aPageSize )
710 Point CapPos;
711 Size CapSize;
713 CapSize.setWidth( aPageSize.Width );
714 CapSize.setHeight( aPageSize.Height/6 );
715 CapPos.setX( 0 );
716 CapPos.setY( aPageSize.Height - CapSize.Height() );
717 SdPage* pSlide = m_pDoc->GetSdPage( m_pDoc->GetSdPageCount(PageKind::Standard)-1, PageKind::Standard );
719 // try to get existing PresObj
720 const ::tools::Rectangle rRect(CapPos,CapSize);
721 SdrObject* pSdrObj = pSlide->GetPresObj(PresObjKind::Title);
723 if(!pSdrObj)
725 // if not exists, create. Beware: It is already inserted to the SdPage
726 pSdrObj = pSlide->CreatePresObj(PresObjKind::Title,false,rRect);
728 else
730 // if exists, bring to front and position it
731 const size_t nObjNum(pSlide->GetObjCount());
733 if(nObjNum)
735 pSlide->SetObjectOrdNum(pSdrObj->GetOrdNum(), nObjNum - 1);
738 pSdrObj->SetSnapRect(rRect);
741 if(pSdrObj)
743 // set color, style and some transparency
744 SfxItemSet aSet(m_pDoc->GetItemPool() );
746 aSet.Put( XFillStyleItem(drawing::FillStyle_SOLID) );
747 aSet.Put( XFillColorItem( u""_ustr, COL_BLACK ) );
748 aSet.Put( XFillTransparenceItem( 20 ) );
749 pSdrObj->SetMergedItemSetAndBroadcast(aSet);
753 Reference< graphic::XGraphic> SdPhotoAlbumDialog::createXGraphicFromUrl(const OUString& sUrl,
754 const Reference< graphic::XGraphicProvider>& xProvider
757 // The same as above, except this returns an XGraphic from the image URL
758 ::comphelper::NamedValueCollection aMediaProperties;
759 aMediaProperties.put( u"URL"_ustr, sUrl );
760 Reference< graphic::XGraphic> xGraphic =
761 xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
762 return xGraphic;
765 void SdPhotoAlbumDialog::EnableDisableButtons()
767 m_xRemoveBtn->set_sensitive(m_xImagesLst->count_selected_rows() > 0);
768 m_xUpBtn->set_sensitive(m_xImagesLst->count_selected_rows() > 0 &&
769 m_xImagesLst->get_selected_index() != 0);
770 m_xDownBtn->set_sensitive(m_xImagesLst->count_selected_rows() > 0 &&
771 m_xImagesLst->get_selected_index() < m_xImagesLst->n_children() - 1);
774 } // end of namespace sd
776 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */