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>
41 : GenericDialogController(pWindow,
"modules/simpress/ui/photoalbum.ui",
"PhotoAlbumCreatorDialog")
44 , m_xCancelBtn(m_xBuilder->weld_button(
"cancel"))
45 , m_xCreateBtn(m_xBuilder->weld_button(
"ok"))
46 , m_xAddBtn(m_xBuilder->weld_button(
"add_btn"))
47 , m_xUpBtn(m_xBuilder->weld_button(
"up_btn"))
48 , m_xDownBtn(m_xBuilder->weld_button(
"down_btn"))
49 , m_xRemoveBtn(m_xBuilder->weld_button(
"rem_btn"))
50 , m_xImagesLst(m_xBuilder->weld_tree_view(
"images_tree"))
51 , m_xImg(new
weld::CustomWeld(*m_xBuilder,
"preview_img", m_aImg))
52 , m_xInsTypeCombo(m_xBuilder->weld_combo_box(
"opt_combo"))
53 , m_xASRCheck(m_xBuilder->weld_check_button(
"asr_check"))
54 , m_xASRCheckCrop(m_xBuilder->weld_check_button(
"asr_check_crop"))
55 , m_xCapCheck(m_xBuilder->weld_check_button(
"cap_check"))
56 , m_xInsertAsLinkCheck(m_xBuilder->weld_check_button(
"insert_as_link_check"))
86 if (m_xImagesLst->n_children() == 0)
89 VclMessageType::Warning, VclButtonsType::Ok,
90 SdResId(STR_PHOTO_ALBUM_EMPTY_WARNING)));
95 Reference< drawing::XDrawPagesSupplier > xDPS( m_pDoc->getUnoModel(), uno::UNO_QUERY );
96 Reference< drawing::XDrawPages > xDrawPages = xDPS->getDrawPages();
97 Reference< lang::XMultiServiceFactory > xShapeFactory( m_pDoc->getUnoModel(), uno::UNO_QUERY );
99 Reference< XComponentContext > xContext(::comphelper::getProcessComponentContext());
100 Reference< graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(xContext));
104 const bool bCreateCaptions(m_xCapCheck->get_active());
105 const bool bInsertAsLink(m_xInsertAsLinkCheck->get_active());
109 const int nOpt = m_xInsTypeCombo->get_active();
110 if (nOpt == ONE_IMAGE)
112 for( sal_Int32
i = 0;
i < m_xImagesLst->n_children(); ++
i )
114 OUString sUrl = m_xImagesLst->get_id(
i);
116 Reference< drawing::XDrawPage > xSlide = appendNewSlide(aAutoLayout, xDrawPages);
117 Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
118 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl, xProvider);
127 Reference< drawing::XShape > xShape(
128 xShapeFactory->createInstance(
"com.sun.star.drawing.GraphicObjectShape"),
131 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
132 xProps->setPropertyValue(
"Graphic",
::uno::Any(xGraphic));
134 ::awt::Size aPageSize;
136 xSlideProps->getPropertyValue(
137 "Width") >>= aPageSize.Width;
138 xSlideProps->getPropertyValue(
139 "Height") >>= aPageSize.Height;
141 ::awt::Point aPicPos;
143 if (m_xASRCheck->get_active() && !m_xASRCheckCrop->get_active())
146 aPicSize = createASRSize(aPicSize, aPageSize);
148 else if (m_xASRCheckCrop->get_active())
150 aPicSize = createASRSizeCrop(aPicSize, aPageSize);
153 xShape->setSize(aPicSize);
154 aPicPos.X = (aPageSize.Width - aPicSize.Width)/2;
155 aPicPos.Y = (aPageSize.Height - aPicSize.Height)/2;
157 xShape->setPosition(aPicPos);
162 createCaption( aPageSize );
164 catch (
const css::uno::Exception&)
170 else if( nOpt == TWO_IMAGES )
172 for( sal_Int32
i = 0;
i < m_xImagesLst->n_children();
i+=2 )
175 Reference< drawing::XDrawPage > xSlide = appendNewSlide(aAutoLayout, xDrawPages);
176 Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
178 ::awt::Size aPageSize;
180 xSlideProps->getPropertyValue(
181 "Width") >>= aPageSize.Width;
182 xSlideProps->getPropertyValue(
183 "Height") >>= aPageSize.Height;
186 OUString sUrl1 = m_xImagesLst->get_id(
i);
188 OUString sUrl2 = m_xImagesLst->get_id(
i+1);
190 if( !sUrl1.isEmpty() )
192 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
200 Reference< drawing::XShape > xShape(
201 xShapeFactory->createInstance(
"com.sun.star.drawing.GraphicObjectShape"),
204 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
205 xProps->setPropertyValue(
"Graphic",
::uno::Any(xGraphic));
207 ::awt::Point aPicPos;
209 if (m_xASRCheck->get_active())
212 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
216 aPicSize.Width = aPageSize.Width/2 - 100;
217 aPicSize.Height = aPageSize.Height/2 - 100;
219 xShape->setSize(aPicSize);
220 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
221 aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
223 xShape->setPosition(aPicPos);
228 catch (
const css::uno::Exception&)
234 if( !sUrl2.isEmpty() )
236 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
244 Reference< drawing::XShape > xShape(
245 xShapeFactory->createInstance(
"com.sun.star.drawing.GraphicObjectShape"),
248 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
249 xProps->setPropertyValue(
"Graphic",
::uno::Any(xGraphic));
251 ::awt::Point aPicPos;
253 if (m_xASRCheck->get_active())
256 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
260 aPicSize.Width = aPageSize.Width/2 - 100;
261 aPicSize.Height = aPageSize.Height/2 - 100;
263 xShape->setSize(aPicSize);
264 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
265 aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
267 xShape->setPosition(aPicPos);
273 createCaption( aPageSize );
275 catch (
const css::uno::Exception&)
282 else if( nOpt == FOUR_IMAGES )
284 for( sal_Int32
i = 0;
i < m_xImagesLst->n_children();
i+=4 )
287 Reference< drawing::XDrawPage > xSlide = appendNewSlide(aAutoLayout, xDrawPages);
288 Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
290 ::awt::Size aPageSize;
292 xSlideProps->getPropertyValue(
293 "Width") >>= aPageSize.Width;
294 xSlideProps->getPropertyValue(
295 "Height") >>= aPageSize.Height;
298 OUString sUrl1 = m_xImagesLst->get_id(
i);
301 OUString sUrl2 = m_xImagesLst->get_id(
i+1);
304 OUString sUrl3 = m_xImagesLst->get_id(
i+2);
307 OUString sUrl4 = m_xImagesLst->get_id(
i+3);
309 if( !sUrl1.isEmpty() )
311 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
319 Reference< drawing::XShape > xShape(
320 xShapeFactory->createInstance(
"com.sun.star.drawing.GraphicObjectShape"),
323 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
324 xProps->setPropertyValue(
"Graphic",
::uno::Any(xGraphic));
326 ::awt::Point aPicPos;
328 if (m_xASRCheck->get_active())
331 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
335 aPicSize.Width = aPageSize.Width/2 - 100;
336 aPicSize.Height = aPageSize.Height/2 - 100;
338 xShape->setSize(aPicSize);
339 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
340 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
342 xShape->setPosition(aPicPos);
347 catch (
const css::uno::Exception&)
352 if( !sUrl2.isEmpty() )
354 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
362 Reference< drawing::XShape > xShape(
363 xShapeFactory->createInstance(
"com.sun.star.drawing.GraphicObjectShape"),
366 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
367 xProps->setPropertyValue(
"Graphic",
::uno::Any(xGraphic));
369 ::awt::Point aPicPos;
371 if (m_xASRCheck->get_active())
374 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
378 aPicSize.Width = aPageSize.Width/2 - 100;
379 aPicSize.Height = aPageSize.Height/2 - 100;
381 xShape->setSize(aPicSize);
382 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
383 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
385 xShape->setPosition(aPicPos);
390 catch (
const css::uno::Exception&)
395 if( !sUrl3.isEmpty() )
397 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl3, xProvider);
405 Reference< drawing::XShape > xShape(
406 xShapeFactory->createInstance(
"com.sun.star.drawing.GraphicObjectShape"),
409 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
410 xProps->setPropertyValue(
"Graphic",
::uno::Any(xGraphic));
412 ::awt::Point aPicPos;
414 if (m_xASRCheck->get_active())
417 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
421 aPicSize.Width = aPageSize.Width/2 - 100;
422 aPicSize.Height = aPageSize.Height/2 - 100;
424 xShape->setSize(aPicSize);
425 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
426 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
428 xShape->setPosition(aPicPos);
433 catch (
const css::uno::Exception&)
438 if( !sUrl4.isEmpty() )
440 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl4, xProvider);
448 Reference< drawing::XShape > xShape(
449 xShapeFactory->createInstance(
"com.sun.star.drawing.GraphicObjectShape"),
452 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
453 xProps->setPropertyValue(
"Graphic",
::uno::Any(xGraphic));
455 ::awt::Point aPicPos;
457 if (m_xASRCheck->get_active())
460 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
464 aPicSize.Width = aPageSize.Width/2 - 100;
465 aPicSize.Height = aPageSize.Height/2 - 100;
467 xShape->setSize(aPicSize);
468 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
469 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
471 xShape->setPosition(aPicPos);
476 createCaption( aPageSize );
478 catch (
const css::uno::Exception&)
488 VclMessageType::Info, VclButtonsType::Ok,
489 "Function is not implemented!"));
499 css::ui::dialogs::TemplateDescription::FILEOPEN_PREVIEW,
500 FileDialogFlags::Graphic | FileDialogFlags::MultiSelection,
m_xDialog.get());
506 for (
const auto& rFile : aFilesArr )
513 EnableDisableButtons();
518 const int nActPos = m_xImagesLst->get_selected_index();
519 if (nActPos != -1 && nActPos != 0)
521 OUString sActEntry(m_xImagesLst->get_text(nActPos));
523 OUString sAct(m_xImagesLst->get_id(nActPos));
525 OUString sUpperEntry(m_xImagesLst->get_text(nActPos - 1));
527 OUString sUpper(m_xImagesLst->get_id(nActPos - 1));
529 m_xImagesLst->remove_text(sActEntry);
530 m_xImagesLst->remove_text(sUpperEntry);
532 m_xImagesLst->insert(nActPos - 1, sActEntry, &sAct,
nullptr,
nullptr);
533 m_xImagesLst->insert(nActPos, sUpperEntry, &sUpper,
nullptr,
nullptr);
535 m_xImagesLst->select(nActPos - 1);
538 EnableDisableButtons();
543 const int nActPos = m_xImagesLst->get_selected_index();
544 if (!m_xImagesLst->get_text(nActPos + 1).isEmpty())
546 OUString sActEntry(m_xImagesLst->get_selected_text());
547 OUString sAct(m_xImagesLst->get_selected_id());
549 OUString sDownEntry(m_xImagesLst->get_text(nActPos + 1));
550 OUString sDown(m_xImagesLst->get_id(nActPos + 1));
552 m_xImagesLst->remove_text(sActEntry);
553 m_xImagesLst->remove_text(sDownEntry);
555 m_xImagesLst->insert(nActPos, sDownEntry, &sDown,
nullptr,
nullptr);
556 m_xImagesLst->insert(nActPos + 1, sActEntry, &sAct,
nullptr,
nullptr);
558 m_xImagesLst->select(nActPos + 1);
560 EnableDisableButtons();
565 m_xImagesLst->remove(m_xImagesLst->get_selected_index());
568 EnableDisableButtons();
573 OUString sImgUrl = m_xImagesLst->get_selected_id();
575 if (sImgUrl !=
SdResId(STR_PHOTO_ALBUM_TEXTBOX))
595 m_pGraphicFilter->ImportGraphic( aGraphic, sImgUrl, *pStream, nFilter,
nullptr, nFilterImportFlags );
597 m_pGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter,
nullptr, nFilterImportFlags );
601 m_pGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter,
nullptr, nFilterImportFlags );
608 double nXRatio = double(200) / nBmpWidth;
609 double nYRatio = double(150) / nBmpHeight;
610 if ( nXRatio < nYRatio )
611 aBmp.
Scale( nXRatio, nXRatio );
613 aBmp.
Scale( nYRatio, nYRatio );
615 aBmp.
Convert( BmpConversion::N24Bit );
616 m_aImg.SetGraphic(
Graphic(aBmp));
622 EnableDisableButtons();
629 bool const bEnable = m_xInsTypeCombo->get_active() == ONE_IMAGE;
630 m_xASRCheckCrop->set_sensitive(bEnable);
632 m_xASRCheckCrop->set_active(
false);
636 const Reference< drawing::XDrawPages >& xDrawPages
640 Reference< drawing::XDrawPage > xSlide = xDrawPages->insertNewByIndex( xDrawPages->getCount() );
648 double resizeWidth = aPicSize.Width;
649 double resizeHeight = aPicSize.Height;
650 double aspect = resizeWidth/resizeHeight;
652 if( resizeWidth > aMaxSize.Width )
654 resizeWidth = aMaxSize.Width;
655 resizeHeight = resizeWidth / aspect;
658 if( resizeHeight > aMaxSize.Height )
660 aspect = resizeWidth/resizeHeight;
661 resizeHeight = aMaxSize.Height;
662 resizeWidth = resizeHeight * aspect;
664 return awt::Size(resizeWidth, resizeHeight);
669 double resizeWidth = aPicSize.Width;
670 double resizeHeight = aPicSize.Height;
671 double imgAspect = resizeWidth / resizeHeight;
672 double windowAspectRatio =
static_cast<double>(aMaxSize.Width) / aMaxSize.Height ;
676 if( resizeWidth > aMaxSize.Width && resizeHeight > aMaxSize.Height )
678 if( imgAspect > windowAspectRatio )
680 resizeHeight = aMaxSize.Height;
681 resizeWidth = aMaxSize.Height * imgAspect;
685 resizeHeight = aMaxSize.Width / imgAspect;
686 resizeWidth = aMaxSize.Width;
693 if( imgAspect > windowAspectRatio )
695 resizeHeight = aMaxSize.Height;
696 resizeWidth = aMaxSize.Height * imgAspect;
700 resizeWidth = aMaxSize.Width;
701 resizeHeight = aMaxSize.Width / imgAspect;
704 return awt::Size(resizeWidth, resizeHeight);
712 CapSize.
setWidth( aPageSize.Width );
715 CapPos.
setY( aPageSize.Height - CapSize.
Height() );
719 const ::tools::Rectangle rRect(CapPos,CapSize);
753 const Reference< graphic::XGraphicProvider>& xProvider
758 aMediaProperties.
put(
"URL", sUrl );
759 Reference< graphic::XGraphic> xGraphic =
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
bool Convert(BmpConversion eConversion)
const Size & GetSizePixel() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
void setOriginURL(OUString const &rOriginURL)
void SetSmartProtocol(INetProtocol eTheSmartScheme)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool SetSmartURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
OUString GetLastName(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
void setX(tools::Long nX)
void setY(tools::Long nY)
SdPage * GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
sal_uInt16 GetSdPageCount(PageKind ePgKind) const
SdrObject * GetPresObj(PresObjKind eObjKind, int nIndex=1, bool bFuzzySearch=false)
returns the nIndex'th object from the given PresObjKind, index starts with 1
SdrObject * CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::tools::Rectangle &rRect)
creates a presentation object with the given PresObjKind on this page.
void SetAutoLayout(AutoLayout eLayout, bool bInit=false, bool bCreate=false)
const SfxItemPool & GetItemPool() const
virtual SdrObject * SetObjectOrdNum(size_t nOldObjNum, size_t nNewObjNum)
size_t GetObjCount() const
sal_uInt32 GetOrdNum() const
void SetMergedItemSetAndBroadcast(const SfxItemSet &rSet, bool bClearAllItems=false)
virtual void SetSnapRect(const tools::Rectangle &rRect)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
void EnableDisableButtons()
std::unique_ptr< weld::Button > m_xCancelBtn
static awt::Size createASRSize(const awt::Size &aPicSize, const awt::Size &aMaxSize)
GraphicFilter * m_pGraphicFilter
std::unique_ptr< weld::Button > m_xRemoveBtn
std::unique_ptr< weld::Button > m_xAddBtn
std::unique_ptr< weld::ComboBox > m_xInsTypeCombo
void createCaption(const awt::Size &aPageSize)
std::unique_ptr< weld::Button > m_xCreateBtn
SdPhotoAlbumDialog(weld::Window *pWindow, SdDrawDocument *pActDoc)
std::unique_ptr< weld::TreeView > m_xImagesLst
std::unique_ptr< weld::Button > m_xUpBtn
virtual ~SdPhotoAlbumDialog() override
std::unique_ptr< weld::Button > m_xDownBtn
static awt::Size createASRSizeCrop(const awt::Size &aPicSize, const awt::Size &aMaxSize)
Reference< drawing::XDrawPage > appendNewSlide(AutoLayout aLayout, const Reference< drawing::XDrawPages > &xDrawPages)
static Reference< graphic::XGraphic > createXGraphicFromUrl(const OUString &sUrl, const Reference< graphic::XGraphicProvider > &xProvider)
css::uno::Sequence< OUString > GetSelectedFiles() const
void SetContext(Context _eNewContext)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define GRFILTER_FORMAT_DONTKNOW
#define LINK(Instance, Class, Member)
IMPL_LINK_NOARG(MainSequence, onTimerHdl, Timer *, void)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
OUString SdResId(TranslateId aId)