1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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 <sal/log.hxx>
22 #include <unotools/pathoptions.hxx>
23 #include <unotools/ucbstreamhelper.hxx>
24 #include <officecfg/Office/Impress.hxx>
25 #include <vcl/graphicfilter.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/weld.hxx>
28 #include <svx/xfltrit.hxx>
29 #include <svx/xflclit.hxx>
30 #include <tools/diagnose_ex.h>
31 #include <xmloff/autolayout.hxx>
33 #include "PhotoAlbumDialog.hxx"
34 #include <strings.hrc>
35 #include <sdresid.hxx>
36 #include <drawdoc.hxx>
42 SdPhotoAlbumDialog::SdPhotoAlbumDialog(weld::Window
* pWindow
, SdDrawDocument
* pActDoc
)
43 : GenericDialogController(pWindow
, "modules/simpress/ui/photoalbum.ui", "PhotoAlbumCreatorDialog")
45 , m_aImg(m_xDialog
.get())
46 , m_xCancelBtn(m_xBuilder
->weld_button("cancel"))
47 , m_xCreateBtn(m_xBuilder
->weld_button("ok"))
48 , m_xAddBtn(m_xBuilder
->weld_button("add_btn"))
49 , m_xUpBtn(m_xBuilder
->weld_button("up_btn"))
50 , m_xDownBtn(m_xBuilder
->weld_button("down_btn"))
51 , m_xRemoveBtn(m_xBuilder
->weld_button("rem_btn"))
52 , m_xImagesLst(m_xBuilder
->weld_tree_view("images_tree"))
53 , m_xImg(new weld::CustomWeld(*m_xBuilder
, "preview_img", m_aImg
))
54 , m_xInsTypeCombo(m_xBuilder
->weld_combo_box("opt_combo"))
55 , m_xASRCheck(m_xBuilder
->weld_check_button("asr_check"))
56 , m_xASRCheckCrop(m_xBuilder
->weld_check_button("asr_check_crop"))
57 , m_xCapCheck(m_xBuilder
->weld_check_button("cap_check"))
58 , m_xInsertAsLinkCheck(m_xBuilder
->weld_check_button("insert_as_link_check"))
60 m_xCancelBtn
->connect_clicked(LINK(this, SdPhotoAlbumDialog
, CancelHdl
));
61 m_xCreateBtn
->connect_clicked(LINK(this, SdPhotoAlbumDialog
, CreateHdl
));
63 m_xAddBtn
->connect_clicked(LINK(this, SdPhotoAlbumDialog
, FileHdl
));
64 m_xUpBtn
->connect_clicked(LINK(this, SdPhotoAlbumDialog
, UpHdl
));
65 m_xUpBtn
->set_sensitive(false);
66 m_xDownBtn
->connect_clicked(LINK(this, SdPhotoAlbumDialog
, DownHdl
));
67 m_xDownBtn
->set_sensitive(false);
68 m_xRemoveBtn
->connect_clicked(LINK(this, SdPhotoAlbumDialog
, RemoveHdl
));
69 m_xRemoveBtn
->set_sensitive(false);
70 m_xImagesLst
->connect_changed(LINK(this, SdPhotoAlbumDialog
, SelectHdl
));
71 m_xInsTypeCombo
->connect_changed(LINK(this, SdPhotoAlbumDialog
, TypeSelectHdl
));
73 m_pGraphicFilter
= new GraphicFilter
;
74 m_xAddBtn
->grab_focus();
77 SdPhotoAlbumDialog::~SdPhotoAlbumDialog()
81 IMPL_LINK_NOARG(SdPhotoAlbumDialog
, CancelHdl
, weld::Button
&, void)
83 m_xDialog
->response(RET_CANCEL
);
86 IMPL_LINK_NOARG(SdPhotoAlbumDialog
, CreateHdl
, weld::Button
&, void)
88 if (m_xImagesLst
->n_children() == 0)
90 std::unique_ptr
<weld::MessageDialog
> xWarn(Application::CreateMessageDialog(m_xDialog
.get(),
91 VclMessageType::Warning
, VclButtonsType::Ok
,
92 SdResId(STR_PHOTO_ALBUM_EMPTY_WARNING
)));
97 Reference
< drawing::XDrawPagesSupplier
> xDPS( m_pDoc
->getUnoModel(), uno::UNO_QUERY
);
98 Reference
< drawing::XDrawPages
> xDrawPages( xDPS
->getDrawPages(), uno::UNO_QUERY
);
99 Reference
< lang::XMultiServiceFactory
> xShapeFactory( m_pDoc
->getUnoModel(), uno::UNO_QUERY
);
101 Reference
< XComponentContext
> xContext(::comphelper::getProcessComponentContext());
102 Reference
< graphic::XGraphicProvider
> xProvider(graphic::GraphicProvider::create(xContext
));
104 // determine if to use Captions (use TitleObject) and choose the correct AutoLayout
105 // from the beginning
106 const bool bCreateCaptions(m_xCapCheck
->get_active());
107 const bool bInsertAsLink(m_xInsertAsLinkCheck
->get_active());
108 const AutoLayout
aAutoLayout(bCreateCaptions
? AUTOLAYOUT_TITLE_ONLY
: AUTOLAYOUT_NONE
);
111 const int nOpt
= m_xInsTypeCombo
->get_active();
112 if (nOpt
== ONE_IMAGE
)
114 for( sal_Int32 i
= 0; i
< m_xImagesLst
->n_children(); ++i
)
116 OUString sUrl
= m_xImagesLst
->get_id(i
);
118 Reference
< drawing::XDrawPage
> xSlide
= appendNewSlide(aAutoLayout
, xDrawPages
);
119 Reference
< beans::XPropertySet
> xSlideProps( xSlide
, uno::UNO_QUERY
);
120 Reference
< graphic::XGraphic
> xGraphic
= createXGraphicFromUrl(sUrl
, xProvider
);
122 Graphic
aGraphic(xGraphic
);
124 aGraphic
.setOriginURL(sUrl
);
126 // Save the original size, multiplied with 100
127 ::awt::Size
aPicSize(aGraphic
.GetSizePixel().Width()*100, aGraphic
.GetSizePixel().Height()*100);
129 Reference
< drawing::XShape
> xShape(
130 xShapeFactory
->createInstance("com.sun.star.drawing.GraphicObjectShape"),
133 Reference
< beans::XPropertySet
> xProps( xShape
, uno::UNO_QUERY
);
134 xProps
->setPropertyValue("Graphic", ::uno::Any(xGraphic
));
136 ::awt::Size aPageSize
;
138 xSlideProps
->getPropertyValue(
139 "Width") >>= aPageSize
.Width
;
140 xSlideProps
->getPropertyValue(
141 "Height") >>= aPageSize
.Height
;
143 ::awt::Point aPicPos
;
145 if (m_xASRCheck
->get_active() && !m_xASRCheckCrop
->get_active())
147 // Resize the image, with keeping ASR
148 aPicSize
= createASRSize(aPicSize
, aPageSize
);
150 else if (m_xASRCheckCrop
->get_active())
152 aPicSize
= createASRSizeCrop(aPicSize
, aPageSize
);
155 xShape
->setSize(aPicSize
);
156 aPicPos
.X
= (aPageSize
.Width
- aPicSize
.Width
)/2;
157 aPicPos
.Y
= (aPageSize
.Height
- aPicSize
.Height
)/2;
159 xShape
->setPosition(aPicPos
);
164 createCaption( aPageSize
);
166 catch (const css::uno::Exception
&)
168 css::uno::Any
ex( cppu::getCaughtException() );
169 SAL_WARN( "sd", exceptionToString(ex
) );
173 else if( nOpt
== TWO_IMAGES
)
175 for( sal_Int32 i
= 0; i
< m_xImagesLst
->n_children(); i
+=2 )
178 Reference
< drawing::XDrawPage
> xSlide
= appendNewSlide(aAutoLayout
, xDrawPages
);
179 Reference
< beans::XPropertySet
> xSlideProps( xSlide
, uno::UNO_QUERY
);
181 ::awt::Size aPageSize
;
183 xSlideProps
->getPropertyValue(
184 "Width") >>= aPageSize
.Width
;
185 xSlideProps
->getPropertyValue(
186 "Height") >>= aPageSize
.Height
;
189 OUString sUrl1
= m_xImagesLst
->get_id(i
);
190 // grab the right one
191 OUString sUrl2
= m_xImagesLst
->get_id(i
+1);
193 if( !sUrl1
.isEmpty() )
195 Reference
< graphic::XGraphic
> xGraphic
= createXGraphicFromUrl(sUrl1
, xProvider
);
197 Graphic
aGraphic(xGraphic
);
199 aGraphic
.setOriginURL(sUrl1
);
200 // Save the original size, multiplied with 100
201 ::awt::Size
aPicSize(aGraphic
.GetSizePixel().Width()*100, aGraphic
.GetSizePixel().Height()*100);
203 Reference
< drawing::XShape
> xShape(
204 xShapeFactory
->createInstance("com.sun.star.drawing.GraphicObjectShape"),
207 Reference
< beans::XPropertySet
> xProps( xShape
, uno::UNO_QUERY
);
208 xProps
->setPropertyValue("Graphic", ::uno::Any(xGraphic
));
210 ::awt::Point aPicPos
;
212 if (m_xASRCheck
->get_active())
214 // Resize the image, with keeping ASR
215 aPicSize
= createASRSize(aPicSize
, ::awt::Size(aPageSize
.Width
/2 - 100, aPageSize
.Height
/2 - 100));
219 aPicSize
.Width
= aPageSize
.Width
/2 - 100;
220 aPicSize
.Height
= aPageSize
.Height
/2 - 100;
222 xShape
->setSize(aPicSize
);
223 aPicPos
.X
= (aPageSize
.Width
/4 - aPicSize
.Width
/2);
224 aPicPos
.Y
= aPageSize
.Height
/2 - aPicSize
.Height
/2;
226 xShape
->setPosition(aPicPos
);
231 catch (const css::uno::Exception
&)
233 css::uno::Any
ex( cppu::getCaughtException() );
234 SAL_WARN( "sd", exceptionToString(ex
) );
238 if( !sUrl2
.isEmpty() )
240 Reference
< graphic::XGraphic
> xGraphic
= createXGraphicFromUrl(sUrl2
, xProvider
);
242 Graphic
aGraphic(xGraphic
);
244 aGraphic
.setOriginURL(sUrl2
);
245 // Save the original size, multiplied with 100
246 ::awt::Size
aPicSize(aGraphic
.GetSizePixel().Width()*100, aGraphic
.GetSizePixel().Height()*100);
248 Reference
< drawing::XShape
> xShape(
249 xShapeFactory
->createInstance("com.sun.star.drawing.GraphicObjectShape"),
252 Reference
< beans::XPropertySet
> xProps( xShape
, uno::UNO_QUERY
);
253 xProps
->setPropertyValue("Graphic", ::uno::Any(xGraphic
));
255 ::awt::Point aPicPos
;
257 if (m_xASRCheck
->get_active())
259 // Resize the image, with keeping ASR
260 aPicSize
= createASRSize(aPicSize
, ::awt::Size(aPageSize
.Width
/2 - 100, aPageSize
.Height
/2 - 100));
264 aPicSize
.Width
= aPageSize
.Width
/2 - 100;
265 aPicSize
.Height
= aPageSize
.Height
/2 - 100;
267 xShape
->setSize(aPicSize
);
268 aPicPos
.X
= (aPageSize
.Width
/4 - aPicSize
.Width
/2) + aPageSize
.Width
/2;
269 aPicPos
.Y
= aPageSize
.Height
/2 - aPicSize
.Height
/2;
271 xShape
->setPosition(aPicPos
);
277 createCaption( aPageSize
);
279 catch (const css::uno::Exception
&)
281 css::uno::Any
ex( cppu::getCaughtException() );
282 SAL_WARN( "sd", exceptionToString(ex
) );
287 else if( nOpt
== FOUR_IMAGES
)
289 for( sal_Int32 i
= 0; i
< m_xImagesLst
->n_children(); i
+=4 )
292 Reference
< drawing::XDrawPage
> xSlide
= appendNewSlide(aAutoLayout
, xDrawPages
);
293 Reference
< beans::XPropertySet
> xSlideProps( xSlide
, uno::UNO_QUERY
);
295 ::awt::Size aPageSize
;
297 xSlideProps
->getPropertyValue(
298 "Width") >>= aPageSize
.Width
;
299 xSlideProps
->getPropertyValue(
300 "Height") >>= aPageSize
.Height
;
302 // grab the upper left one
303 OUString sUrl1
= m_xImagesLst
->get_id(i
);
305 // grab the upper right one
306 OUString sUrl2
= m_xImagesLst
->get_id(i
+1);
308 // grab the lower left one
309 OUString sUrl3
= m_xImagesLst
->get_id(i
+2);
311 // grab the lower right one
312 OUString sUrl4
= m_xImagesLst
->get_id(i
+3);
314 if( !sUrl1
.isEmpty() )
316 Reference
< graphic::XGraphic
> xGraphic
= createXGraphicFromUrl(sUrl1
, xProvider
);
318 Graphic
aGraphic(xGraphic
);
320 aGraphic
.setOriginURL(sUrl1
);
321 // Save the original size, multiplied with 100
322 ::awt::Size
aPicSize(aGraphic
.GetSizePixel().Width()*100, aGraphic
.GetSizePixel().Height()*100);
324 Reference
< drawing::XShape
> xShape(
325 xShapeFactory
->createInstance("com.sun.star.drawing.GraphicObjectShape"),
328 Reference
< beans::XPropertySet
> xProps( xShape
, uno::UNO_QUERY
);
329 xProps
->setPropertyValue("Graphic", ::uno::Any(xGraphic
));
331 ::awt::Point aPicPos
;
333 if (m_xASRCheck
->get_active())
335 // Resize the image, with keeping ASR
336 aPicSize
= createASRSize(aPicSize
, ::awt::Size(aPageSize
.Width
/2 - 100, aPageSize
.Height
/2 - 100));
340 aPicSize
.Width
= aPageSize
.Width
/2 - 100;
341 aPicSize
.Height
= aPageSize
.Height
/2 - 100;
343 xShape
->setSize(aPicSize
);
344 aPicPos
.X
= (aPageSize
.Width
/4 - aPicSize
.Width
/2);
345 aPicPos
.Y
= aPageSize
.Height
/4 - aPicSize
.Height
/2;
347 xShape
->setPosition(aPicPos
);
352 catch (const css::uno::Exception
&)
354 css::uno::Any
ex( cppu::getCaughtException() );
355 SAL_WARN( "sd", exceptionToString(ex
) );
358 if( !sUrl2
.isEmpty() )
360 Reference
< graphic::XGraphic
> xGraphic
= createXGraphicFromUrl(sUrl2
, xProvider
);
362 Graphic
aGraphic(xGraphic
);
364 aGraphic
.setOriginURL(sUrl2
);
365 // Save the original size, multiplied with 100
366 ::awt::Size
aPicSize(aGraphic
.GetSizePixel().Width()*100, aGraphic
.GetSizePixel().Height()*100);
368 Reference
< drawing::XShape
> xShape(
369 xShapeFactory
->createInstance("com.sun.star.drawing.GraphicObjectShape"),
372 Reference
< beans::XPropertySet
> xProps( xShape
, uno::UNO_QUERY
);
373 xProps
->setPropertyValue("Graphic", ::uno::Any(xGraphic
));
375 ::awt::Point aPicPos
;
377 if (m_xASRCheck
->get_active())
379 // Resize the image, with keeping ASR
380 aPicSize
= createASRSize(aPicSize
, ::awt::Size(aPageSize
.Width
/2 - 100, aPageSize
.Height
/2 - 100));
384 aPicSize
.Width
= aPageSize
.Width
/2 - 100;
385 aPicSize
.Height
= aPageSize
.Height
/2 - 100;
387 xShape
->setSize(aPicSize
);
388 aPicPos
.X
= (aPageSize
.Width
/4 - aPicSize
.Width
/2) + aPageSize
.Width
/2;
389 aPicPos
.Y
= aPageSize
.Height
/4 - aPicSize
.Height
/2;
391 xShape
->setPosition(aPicPos
);
396 catch (const css::uno::Exception
&)
398 css::uno::Any
ex( cppu::getCaughtException() );
399 SAL_WARN( "sd", exceptionToString(ex
) );
402 if( !sUrl3
.isEmpty() )
404 Reference
< graphic::XGraphic
> xGraphic
= createXGraphicFromUrl(sUrl3
, xProvider
);
406 Graphic
aGraphic(xGraphic
);
408 aGraphic
.setOriginURL(sUrl3
);
409 // Save the original size, multiplied with 100
410 ::awt::Size
aPicSize(aGraphic
.GetSizePixel().Width()*100, aGraphic
.GetSizePixel().Height()*100);
412 Reference
< drawing::XShape
> xShape(
413 xShapeFactory
->createInstance("com.sun.star.drawing.GraphicObjectShape"),
416 Reference
< beans::XPropertySet
> xProps( xShape
, uno::UNO_QUERY
);
417 xProps
->setPropertyValue("Graphic", ::uno::Any(xGraphic
));
419 ::awt::Point aPicPos
;
421 if (m_xASRCheck
->get_active())
423 // Resize the image, with keeping ASR
424 aPicSize
= createASRSize(aPicSize
, ::awt::Size(aPageSize
.Width
/2 - 100, aPageSize
.Height
/2 - 100));
428 aPicSize
.Width
= aPageSize
.Width
/2 - 100;
429 aPicSize
.Height
= aPageSize
.Height
/2 - 100;
431 xShape
->setSize(aPicSize
);
432 aPicPos
.X
= (aPageSize
.Width
/4 - aPicSize
.Width
/2);
433 aPicPos
.Y
= aPageSize
.Height
/4 - aPicSize
.Height
/2 + aPageSize
.Height
/2;
435 xShape
->setPosition(aPicPos
);
440 catch (const css::uno::Exception
&)
442 css::uno::Any
ex( cppu::getCaughtException() );
443 SAL_WARN( "sd", exceptionToString(ex
) );
446 if( !sUrl4
.isEmpty() )
448 Reference
< graphic::XGraphic
> xGraphic
= createXGraphicFromUrl(sUrl4
, xProvider
);
450 Graphic
aGraphic(xGraphic
);
452 aGraphic
.setOriginURL(sUrl4
);
453 // Save the original size, multiplied with 100
454 ::awt::Size
aPicSize(aGraphic
.GetSizePixel().Width()*100, aGraphic
.GetSizePixel().Height()*100);
456 Reference
< drawing::XShape
> xShape(
457 xShapeFactory
->createInstance("com.sun.star.drawing.GraphicObjectShape"),
460 Reference
< beans::XPropertySet
> xProps( xShape
, uno::UNO_QUERY
);
461 xProps
->setPropertyValue("Graphic", ::uno::Any(xGraphic
));
463 ::awt::Point aPicPos
;
465 if (m_xASRCheck
->get_active())
467 // Resize the image, with keeping ASR
468 aPicSize
= createASRSize(aPicSize
, ::awt::Size(aPageSize
.Width
/2 - 100, aPageSize
.Height
/2 - 100));
472 aPicSize
.Width
= aPageSize
.Width
/2 - 100;
473 aPicSize
.Height
= aPageSize
.Height
/2 - 100;
475 xShape
->setSize(aPicSize
);
476 aPicPos
.X
= (aPageSize
.Width
/4 - aPicSize
.Width
/2) + aPageSize
.Width
/2;
477 aPicPos
.Y
= aPageSize
.Height
/4 - aPicSize
.Height
/2 + aPageSize
.Height
/2;
479 xShape
->setPosition(aPicPos
);
484 createCaption( aPageSize
);
486 catch (const css::uno::Exception
&)
488 css::uno::Any
ex( cppu::getCaughtException() );
489 SAL_WARN( "sd", exceptionToString(ex
) );
496 std::unique_ptr
<weld::MessageDialog
> xInfoBox(Application::CreateMessageDialog(m_xDialog
.get(),
497 VclMessageType::Info
, VclButtonsType::Ok
,
498 "Function is not implemented!"));
501 m_xDialog
->response(RET_OK
);
505 IMPL_LINK_NOARG(SdPhotoAlbumDialog
, FileHdl
, weld::Button
&, void)
507 ::sfx2::FileDialogHelper
aDlg(
508 css::ui::dialogs::TemplateDescription::FILEOPEN_PREVIEW
,
509 FileDialogFlags::Graphic
| FileDialogFlags::MultiSelection
, m_xDialog
.get());
510 // Read configuration
511 OUString
sUrl(officecfg::Office::Impress::Pictures::Path::get());
513 INetURLObject
aFile( SvtPathOptions().GetUserConfigPath() );
515 aDlg
.SetDisplayDirectory(sUrl
);
517 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
519 if ( aDlg
.Execute() == ERRCODE_NONE
)
521 Sequence
< OUString
> aFilesArr
= aDlg
.GetSelectedFiles();
522 if( aFilesArr
.hasElements() )
524 sUrl
= aDlg
.GetDisplayDirectory();
525 // Write out configuration
527 std::shared_ptr
< comphelper::ConfigurationChanges
> batch(
528 comphelper::ConfigurationChanges::create());
529 officecfg::Office::Impress::Pictures::Path::set(sUrl
, batch
);
533 for ( sal_Int32 i
= 0; i
< aFilesArr
.getLength(); i
++ )
535 // Store full path, show filename only. Use INetURLObject to display spaces in filename correctly
536 INetURLObject
aUrl(aFilesArr
[i
]);
537 m_xImagesLst
->append(aUrl
.GetMainURL(INetURLObject::DecodeMechanism::NONE
), aUrl
.GetLastName(INetURLObject::DecodeMechanism::WithCharset
), "");
541 EnableDisableButtons();
544 IMPL_LINK_NOARG(SdPhotoAlbumDialog
, UpHdl
, weld::Button
&, void)
546 const int nActPos
= m_xImagesLst
->get_selected_index();
547 if (nActPos
!= -1 && nActPos
!= 0)
549 OUString
sActEntry(m_xImagesLst
->get_text(nActPos
));
551 OUString
sAct(m_xImagesLst
->get_id(nActPos
));
553 OUString
sUpperEntry(m_xImagesLst
->get_text(nActPos
- 1));
555 OUString
sUpper(m_xImagesLst
->get_id(nActPos
- 1));
557 m_xImagesLst
->remove_text(sActEntry
);
558 m_xImagesLst
->remove_text(sUpperEntry
);
560 m_xImagesLst
->insert(nActPos
- 1, sActEntry
, &sAct
, nullptr, nullptr);
561 m_xImagesLst
->insert(nActPos
, sUpperEntry
, &sUpper
, nullptr, nullptr);
563 m_xImagesLst
->select(nActPos
- 1);
566 EnableDisableButtons();
569 IMPL_LINK_NOARG(SdPhotoAlbumDialog
, DownHdl
, weld::Button
&, void)
571 const int nActPos
= m_xImagesLst
->get_selected_index();
572 if (!m_xImagesLst
->get_text(nActPos
+ 1).isEmpty())
574 OUString
sActEntry(m_xImagesLst
->get_selected_text());
575 OUString
sAct(m_xImagesLst
->get_selected_id());
577 OUString
sDownEntry(m_xImagesLst
->get_text(nActPos
+ 1));
578 OUString
sDown(m_xImagesLst
->get_id(nActPos
+ 1));
580 m_xImagesLst
->remove_text(sActEntry
);
581 m_xImagesLst
->remove_text(sDownEntry
);
583 m_xImagesLst
->insert(nActPos
, sDownEntry
, &sDown
, nullptr, nullptr);
584 m_xImagesLst
->insert(nActPos
+ 1, sActEntry
, &sAct
, nullptr, nullptr);
586 m_xImagesLst
->select(nActPos
+ 1);
588 EnableDisableButtons();
591 IMPL_LINK_NOARG(SdPhotoAlbumDialog
, RemoveHdl
, weld::Button
&, void)
593 m_xImagesLst
->remove(m_xImagesLst
->get_selected_index());
594 m_aImg
.SetGraphic(Graphic());
596 EnableDisableButtons();
599 IMPL_LINK_NOARG(SdPhotoAlbumDialog
, SelectHdl
, weld::TreeView
&, void)
601 OUString sImgUrl
= m_xImagesLst
->get_selected_id();
603 if (sImgUrl
!= SdResId(STR_PHOTO_ALBUM_TEXTBOX
))
605 GraphicFilter aCurFilter
;
607 INetURLObject
aURLObj( sImgUrl
);
609 sal_uInt16 nFilter
= GRFILTER_FORMAT_DONTKNOW
;
611 if ( aURLObj
.HasError() || INetProtocol::NotValid
== aURLObj
.GetProtocol() )
613 aURLObj
.SetSmartProtocol( INetProtocol::File
);
614 aURLObj
.SetSmartURL( sImgUrl
);
617 GraphicFilterImportFlags nFilterImportFlags
= GraphicFilterImportFlags::SetLogsizeForJpeg
;
619 if ( INetProtocol::File
!= aURLObj
.GetProtocol() )
621 std::unique_ptr
<SvStream
> pStream
= ::utl::UcbStreamHelper::CreateStream( sImgUrl
, StreamMode::READ
);
624 m_pGraphicFilter
->ImportGraphic( aGraphic
, sImgUrl
, *pStream
, nFilter
, nullptr, nFilterImportFlags
);
626 m_pGraphicFilter
->ImportGraphic( aGraphic
, aURLObj
, nFilter
, nullptr, nFilterImportFlags
);
630 m_pGraphicFilter
->ImportGraphic( aGraphic
, aURLObj
, nFilter
, nullptr, nFilterImportFlags
);
633 BitmapEx aBmp
= aGraphic
.GetBitmapEx();
634 sal_Int32 nBmpWidth
= aBmp
.GetSizePixel().Width();
635 sal_Int32 nBmpHeight
= aBmp
.GetSizePixel().Height();
637 double nXRatio
= double(200) / nBmpWidth
;
638 double nYRatio
= double(150) / nBmpHeight
;
639 if ( nXRatio
< nYRatio
)
640 aBmp
.Scale( nXRatio
, nXRatio
);
642 aBmp
.Scale( nYRatio
, nYRatio
);
644 aBmp
.Convert( BmpConversion::N24Bit
);
645 m_aImg
.SetGraphic(Graphic(aBmp
));
649 m_aImg
.SetGraphic(Graphic());
651 EnableDisableButtons();
654 IMPL_LINK_NOARG(SdPhotoAlbumDialog
, TypeSelectHdl
, weld::ComboBox
&, void)
656 // Enable "Fill Slide" only for one image
657 // If we want to have it for other images too, we need to implement the actual cropping.
658 bool const bEnable
= m_xInsTypeCombo
->get_active() == ONE_IMAGE
;
659 m_xASRCheckCrop
->set_sensitive(bEnable
);
661 m_xASRCheckCrop
->set_active(false);
664 Reference
< drawing::XDrawPage
> SdPhotoAlbumDialog::appendNewSlide(AutoLayout aLayout
,
665 const Reference
< drawing::XDrawPages
>& xDrawPages
668 Reference
< drawing::XDrawPage
> xSlide
; // Create the slide
669 Reference
< container::XIndexAccess
> xIndexAccess( xDrawPages
, uno::UNO_QUERY
);
670 xSlide
= xDrawPages
->insertNewByIndex( xIndexAccess
->getCount() );
671 SdPage
* pSlide
= m_pDoc
->GetSdPage( m_pDoc
->GetSdPageCount(PageKind::Standard
)-1, PageKind::Standard
);
672 pSlide
->SetAutoLayout(aLayout
, true); // Set the layout here
676 awt::Size
SdPhotoAlbumDialog::createASRSize(const awt::Size
& aPicSize
, const awt::Size
& aMaxSize
)
678 double resizeWidth
= aPicSize
.Width
;
679 double resizeHeight
= aPicSize
.Height
;
680 double aspect
= resizeWidth
/resizeHeight
;
682 if( resizeWidth
> aMaxSize
.Width
)
684 resizeWidth
= aMaxSize
.Width
;
685 resizeHeight
= resizeWidth
/ aspect
;
688 if( resizeHeight
> aMaxSize
.Height
)
690 aspect
= resizeWidth
/resizeHeight
;
691 resizeHeight
= aMaxSize
.Height
;
692 resizeWidth
= resizeHeight
* aspect
;
694 return awt::Size(resizeWidth
, resizeHeight
);
697 awt::Size
SdPhotoAlbumDialog::createASRSizeCrop(const awt::Size
& aPicSize
, const awt::Size
& aMaxSize
)
699 double resizeWidth
= aPicSize
.Width
;
700 double resizeHeight
= aPicSize
.Height
;
701 double imgAspect
= resizeWidth
/ resizeHeight
;
702 double windowAspectRatio
= static_cast<double>(aMaxSize
.Width
) / aMaxSize
.Height
;
705 //When both sides of an image are bigger than canvas size, image would be downscaled.
706 if( resizeWidth
> aMaxSize
.Width
&& resizeHeight
> aMaxSize
.Height
)
708 if( imgAspect
> windowAspectRatio
)
710 resizeHeight
= aMaxSize
.Height
;
711 resizeWidth
= aMaxSize
.Height
* imgAspect
;
715 resizeHeight
= aMaxSize
.Width
/ imgAspect
;
716 resizeWidth
= aMaxSize
.Width
;
720 //In all other cases image is upscaled
723 if( imgAspect
> windowAspectRatio
)
725 resizeHeight
= aMaxSize
.Height
;
726 resizeWidth
= aMaxSize
.Height
* imgAspect
;
730 resizeWidth
= aMaxSize
.Width
;
731 resizeHeight
= aMaxSize
.Width
/ imgAspect
;
734 return awt::Size(resizeWidth
, resizeHeight
);
737 void SdPhotoAlbumDialog::createCaption(const awt::Size
& aPageSize
)
742 CapSize
.setWidth( aPageSize
.Width
);
743 CapSize
.setHeight( aPageSize
.Height
/6 );
745 CapPos
.setY( aPageSize
.Height
- CapSize
.Height() );
746 SdPage
* pSlide
= m_pDoc
->GetSdPage( m_pDoc
->GetSdPageCount(PageKind::Standard
)-1, PageKind::Standard
);
748 // try to get existing PresObj
749 const ::tools::Rectangle
rRect(CapPos
,CapSize
);
750 SdrObject
* pSdrObj
= pSlide
->GetPresObj(PRESOBJ_TITLE
);
754 // if not exists, create. Beware: It is already inserted to the SdPage
755 pSdrObj
= pSlide
->CreatePresObj(PRESOBJ_TITLE
,false,rRect
);
759 // if exists, bring to front and position it
760 const size_t nObjNum(pSlide
->GetObjCount());
764 pSlide
->SetObjectOrdNum(pSdrObj
->GetOrdNum(), nObjNum
- 1);
767 pSdrObj
->SetSnapRect(rRect
);
772 // set color, style and some transparency
773 SfxItemSet
aSet(m_pDoc
->GetItemPool() );
775 aSet
.Put( XFillStyleItem(drawing::FillStyle_SOLID
) );
776 aSet
.Put( XFillColorItem( "", COL_BLACK
) );
777 aSet
.Put( XFillTransparenceItem( 20 ) );
778 pSdrObj
->SetMergedItemSetAndBroadcast(aSet
);
782 Reference
< graphic::XGraphic
> SdPhotoAlbumDialog::createXGraphicFromUrl(const OUString
& sUrl
,
783 const Reference
< graphic::XGraphicProvider
>& xProvider
786 // The same as above, except this returns an XGraphic from the image URL
787 ::comphelper::NamedValueCollection aMediaProperties
;
788 aMediaProperties
.put( "URL", sUrl
);
789 Reference
< graphic::XGraphic
> xGraphic
=
790 xProvider
->queryGraphic( aMediaProperties
.getPropertyValues() );
794 void SdPhotoAlbumDialog::EnableDisableButtons()
796 m_xRemoveBtn
->set_sensitive(m_xImagesLst
->count_selected_rows() > 0);
797 m_xUpBtn
->set_sensitive(m_xImagesLst
->count_selected_rows() > 0 &&
798 m_xImagesLst
->get_selected_index() != 0);
799 m_xDownBtn
->set_sensitive(m_xImagesLst
->count_selected_rows() > 0 &&
800 m_xImagesLst
->get_selected_index() < m_xImagesLst
->n_children() - 1);
803 } // end of namespace sd
805 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */