LibreOffice Module sd (master) 1
PhotoAlbumDialog.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3* This file is part of the LibreOffice project.
4*
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*/
9
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>
17
19#include <tools/urlobj.hxx>
20
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>
29#include <xmloff/autolayout.hxx>
30
31#include "PhotoAlbumDialog.hxx"
32#include <strings.hrc>
33#include <sdresid.hxx>
34#include <drawdoc.hxx>
35#include <sdpage.hxx>
36
37namespace sd
38{
39
41 : GenericDialogController(pWindow, "modules/simpress/ui/photoalbum.ui", "PhotoAlbumCreatorDialog")
42 , m_pDoc(pActDoc)
43 , m_aImg(m_xDialog.get())
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"))
57{
58 m_xCancelBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, CancelHdl));
59 m_xCreateBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, CreateHdl));
60
61 m_xAddBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, FileHdl));
62 m_xUpBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, UpHdl));
63 m_xUpBtn->set_sensitive(false);
64 m_xDownBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, DownHdl));
65 m_xDownBtn->set_sensitive(false);
66 m_xRemoveBtn->connect_clicked(LINK(this, SdPhotoAlbumDialog, RemoveHdl));
67 m_xRemoveBtn->set_sensitive(false);
68 m_xImagesLst->connect_changed(LINK(this, SdPhotoAlbumDialog, SelectHdl));
69 m_xInsTypeCombo->connect_changed(LINK(this, SdPhotoAlbumDialog, TypeSelectHdl));
70
72 m_xAddBtn->grab_focus();
73}
74
76{
77}
78
80{
81 m_xDialog->response(RET_CANCEL);
82}
83
85{
86 if (m_xImagesLst->n_children() == 0)
87 {
88 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(m_xDialog.get(),
89 VclMessageType::Warning, VclButtonsType::Ok,
90 SdResId(STR_PHOTO_ALBUM_EMPTY_WARNING)));
91 xWarn->run();
92 }
93 else
94 {
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 );
98
99 Reference< XComponentContext > xContext(::comphelper::getProcessComponentContext());
100 Reference< graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(xContext));
101
102 // determine if to use Captions (use TitleObject) and choose the correct AutoLayout
103 // from the beginning
104 const bool bCreateCaptions(m_xCapCheck->get_active());
105 const bool bInsertAsLink(m_xInsertAsLinkCheck->get_active());
106 const AutoLayout aAutoLayout(bCreateCaptions ? AUTOLAYOUT_TITLE_ONLY : AUTOLAYOUT_NONE);
107
108 // get the option
109 const int nOpt = m_xInsTypeCombo->get_active();
110 if (nOpt == ONE_IMAGE)
111 {
112 for( sal_Int32 i = 0; i < m_xImagesLst->n_children(); ++i )
113 {
114 OUString sUrl = m_xImagesLst->get_id(i);
115
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);
119
120 Graphic aGraphic(xGraphic);
121 if (bInsertAsLink)
122 aGraphic.setOriginURL(sUrl);
123
124 // Save the original size, multiplied with 100
125 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
126
127 Reference< drawing::XShape > xShape(
128 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
129 uno::UNO_QUERY);
130
131 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
132 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
133
134 ::awt::Size aPageSize;
135
136 xSlideProps->getPropertyValue(
137 "Width") >>= aPageSize.Width;
138 xSlideProps->getPropertyValue(
139 "Height") >>= aPageSize.Height;
140
141 ::awt::Point aPicPos;
142
143 if (m_xASRCheck->get_active() && !m_xASRCheckCrop->get_active())
144 {
145 // Resize the image, with keeping ASR
146 aPicSize = createASRSize(aPicSize, aPageSize);
147 }
148 else if (m_xASRCheckCrop->get_active())
149 {
150 aPicSize = createASRSizeCrop(aPicSize, aPageSize);
151 }
152
153 xShape->setSize(aPicSize);
154 aPicPos.X = (aPageSize.Width - aPicSize.Width)/2;
155 aPicPos.Y = (aPageSize.Height - aPicSize.Height)/2;
156
157 xShape->setPosition(aPicPos);
158 try
159 {
160 xSlide->add(xShape);
161 if (bCreateCaptions)
162 createCaption( aPageSize );
163 }
164 catch (const css::uno::Exception&)
165 {
166 TOOLS_WARN_EXCEPTION( "sd", "" );
167 }
168 }
169 }
170 else if( nOpt == TWO_IMAGES )
171 {
172 for( sal_Int32 i = 0; i < m_xImagesLst->n_children(); i+=2 )
173 {
174 // create the slide
175 Reference< drawing::XDrawPage > xSlide = appendNewSlide(aAutoLayout, xDrawPages);
176 Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
177 //Slide dimensions
178 ::awt::Size aPageSize;
179
180 xSlideProps->getPropertyValue(
181 "Width") >>= aPageSize.Width;
182 xSlideProps->getPropertyValue(
183 "Height") >>= aPageSize.Height;
184
185 // grab the left one
186 OUString sUrl1 = m_xImagesLst->get_id(i);
187 // grab the right one
188 OUString sUrl2 = m_xImagesLst->get_id(i+1);
189
190 if( !sUrl1.isEmpty() )
191 {
192 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
193
194 Graphic aGraphic(xGraphic);
195 if (bInsertAsLink)
196 aGraphic.setOriginURL(sUrl1);
197 // Save the original size, multiplied with 100
198 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
199
200 Reference< drawing::XShape > xShape(
201 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
202 uno::UNO_QUERY);
203
204 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
205 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
206
207 ::awt::Point aPicPos;
208
209 if (m_xASRCheck->get_active())
210 {
211 // Resize the image, with keeping ASR
212 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
213 }
214 else
215 {
216 aPicSize.Width = aPageSize.Width/2 - 100;
217 aPicSize.Height = aPageSize.Height/2 - 100;
218 }
219 xShape->setSize(aPicSize);
220 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
221 aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
222
223 xShape->setPosition(aPicPos);
224 try
225 {
226 xSlide->add(xShape);
227 }
228 catch (const css::uno::Exception&)
229 {
230 TOOLS_WARN_EXCEPTION( "sd", "" );
231 }
232 }
233
234 if( !sUrl2.isEmpty() )
235 {
236 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
237
238 Graphic aGraphic(xGraphic);
239 if (bInsertAsLink)
240 aGraphic.setOriginURL(sUrl2);
241 // Save the original size, multiplied with 100
242 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
243
244 Reference< drawing::XShape > xShape(
245 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
246 uno::UNO_QUERY);
247
248 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
249 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
250
251 ::awt::Point aPicPos;
252
253 if (m_xASRCheck->get_active())
254 {
255 // Resize the image, with keeping ASR
256 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
257 }
258 else
259 {
260 aPicSize.Width = aPageSize.Width/2 - 100;
261 aPicSize.Height = aPageSize.Height/2 - 100;
262 }
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;
266
267 xShape->setPosition(aPicPos);
268
269 try
270 {
271 xSlide->add(xShape);
272 if(bCreateCaptions)
273 createCaption( aPageSize );
274 }
275 catch (const css::uno::Exception&)
276 {
277 TOOLS_WARN_EXCEPTION( "sd", "" );
278 }
279 }
280 }
281 }
282 else if( nOpt == FOUR_IMAGES )
283 {
284 for( sal_Int32 i = 0; i < m_xImagesLst->n_children(); i+=4 )
285 {
286 // create the slide
287 Reference< drawing::XDrawPage > xSlide = appendNewSlide(aAutoLayout, xDrawPages);
288 Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
289 //Slide dimensions
290 ::awt::Size aPageSize;
291
292 xSlideProps->getPropertyValue(
293 "Width") >>= aPageSize.Width;
294 xSlideProps->getPropertyValue(
295 "Height") >>= aPageSize.Height;
296
297 // grab the upper left one
298 OUString sUrl1 = m_xImagesLst->get_id(i);
299
300 // grab the upper right one
301 OUString sUrl2 = m_xImagesLst->get_id(i+1);
302
303 // grab the lower left one
304 OUString sUrl3 = m_xImagesLst->get_id(i+2);
305
306 // grab the lower right one
307 OUString sUrl4 = m_xImagesLst->get_id(i+3);
308
309 if( !sUrl1.isEmpty() )
310 {
311 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
312
313 Graphic aGraphic(xGraphic);
314 if (bInsertAsLink)
315 aGraphic.setOriginURL(sUrl1);
316 // Save the original size, multiplied with 100
317 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
318
319 Reference< drawing::XShape > xShape(
320 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
321 uno::UNO_QUERY);
322
323 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
324 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
325
326 ::awt::Point aPicPos;
327
328 if (m_xASRCheck->get_active())
329 {
330 // Resize the image, with keeping ASR
331 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
332 }
333 else
334 {
335 aPicSize.Width = aPageSize.Width/2 - 100;
336 aPicSize.Height = aPageSize.Height/2 - 100;
337 }
338 xShape->setSize(aPicSize);
339 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
340 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
341
342 xShape->setPosition(aPicPos);
343 try
344 {
345 xSlide->add(xShape);
346 }
347 catch (const css::uno::Exception&)
348 {
349 TOOLS_WARN_EXCEPTION( "sd", "" );
350 }
351 }
352 if( !sUrl2.isEmpty() )
353 {
354 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
355
356 Graphic aGraphic(xGraphic);
357 if (bInsertAsLink)
358 aGraphic.setOriginURL(sUrl2);
359 // Save the original size, multiplied with 100
360 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
361
362 Reference< drawing::XShape > xShape(
363 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
364 uno::UNO_QUERY);
365
366 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
367 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
368
369 ::awt::Point aPicPos;
370
371 if (m_xASRCheck->get_active())
372 {
373 // Resize the image, with keeping ASR
374 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
375 }
376 else
377 {
378 aPicSize.Width = aPageSize.Width/2 - 100;
379 aPicSize.Height = aPageSize.Height/2 - 100;
380 }
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;
384
385 xShape->setPosition(aPicPos);
386 try
387 {
388 xSlide->add(xShape);
389 }
390 catch (const css::uno::Exception&)
391 {
392 TOOLS_WARN_EXCEPTION( "sd", "" );
393 }
394 }
395 if( !sUrl3.isEmpty() )
396 {
397 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl3, xProvider);
398
399 Graphic aGraphic(xGraphic);
400 if (bInsertAsLink)
401 aGraphic.setOriginURL(sUrl3);
402 // Save the original size, multiplied with 100
403 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
404
405 Reference< drawing::XShape > xShape(
406 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
407 uno::UNO_QUERY);
408
409 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
410 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
411
412 ::awt::Point aPicPos;
413
414 if (m_xASRCheck->get_active())
415 {
416 // Resize the image, with keeping ASR
417 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
418 }
419 else
420 {
421 aPicSize.Width = aPageSize.Width/2 - 100;
422 aPicSize.Height = aPageSize.Height/2 - 100;
423 }
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;
427
428 xShape->setPosition(aPicPos);
429 try
430 {
431 xSlide->add(xShape);
432 }
433 catch (const css::uno::Exception&)
434 {
435 TOOLS_WARN_EXCEPTION( "sd", "" );
436 }
437 }
438 if( !sUrl4.isEmpty() )
439 {
440 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl4, xProvider);
441
442 Graphic aGraphic(xGraphic);
443 if (bInsertAsLink)
444 aGraphic.setOriginURL(sUrl4);
445 // Save the original size, multiplied with 100
446 ::awt::Size aPicSize(aGraphic.GetSizePixel().Width()*100, aGraphic.GetSizePixel().Height()*100);
447
448 Reference< drawing::XShape > xShape(
449 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
450 uno::UNO_QUERY);
451
452 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
453 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
454
455 ::awt::Point aPicPos;
456
457 if (m_xASRCheck->get_active())
458 {
459 // Resize the image, with keeping ASR
460 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
461 }
462 else
463 {
464 aPicSize.Width = aPageSize.Width/2 - 100;
465 aPicSize.Height = aPageSize.Height/2 - 100;
466 }
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;
470
471 xShape->setPosition(aPicPos);
472 try
473 {
474 xSlide->add(xShape);
475 if(bCreateCaptions)
476 createCaption( aPageSize );
477 }
478 catch (const css::uno::Exception&)
479 {
480 TOOLS_WARN_EXCEPTION( "sd", "" );
481 }
482 }
483 }
484 }
485 else
486 {
487 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(),
488 VclMessageType::Info, VclButtonsType::Ok,
489 "Function is not implemented!"));
490 xInfoBox->run();
491 }
492 m_xDialog->response(RET_OK);
493 }
494}
495
497{
499 css::ui::dialogs::TemplateDescription::FILEOPEN_PREVIEW,
500 FileDialogFlags::Graphic | FileDialogFlags::MultiSelection, m_xDialog.get());
502
503 if ( aDlg.Execute() == ERRCODE_NONE )
504 {
505 const Sequence< OUString > aFilesArr = aDlg.GetSelectedFiles();
506 for ( const auto& rFile : aFilesArr )
507 {
508 // Store full path, show filename only. Use INetURLObject to display spaces in filename correctly
509 INetURLObject aUrl(rFile);
511 }
512 }
513 EnableDisableButtons();
514}
515
517{
518 const int nActPos = m_xImagesLst->get_selected_index();
519 if (nActPos != -1 && nActPos != 0)
520 {
521 OUString sActEntry(m_xImagesLst->get_text(nActPos));
522 // actual data
523 OUString sAct(m_xImagesLst->get_id(nActPos));
524
525 OUString sUpperEntry(m_xImagesLst->get_text(nActPos - 1));
526 // upper data
527 OUString sUpper(m_xImagesLst->get_id(nActPos - 1));
528
529 m_xImagesLst->remove_text(sActEntry);
530 m_xImagesLst->remove_text(sUpperEntry);
531
532 m_xImagesLst->insert(nActPos - 1, sActEntry, &sAct, nullptr, nullptr);
533 m_xImagesLst->insert(nActPos, sUpperEntry, &sUpper, nullptr, nullptr);
534
535 m_xImagesLst->select(nActPos - 1);
536 }
537
538 EnableDisableButtons();
539}
540
542{
543 const int nActPos = m_xImagesLst->get_selected_index();
544 if (!m_xImagesLst->get_text(nActPos + 1).isEmpty())
545 {
546 OUString sActEntry(m_xImagesLst->get_selected_text());
547 OUString sAct(m_xImagesLst->get_selected_id());
548
549 OUString sDownEntry(m_xImagesLst->get_text(nActPos + 1));
550 OUString sDown(m_xImagesLst->get_id(nActPos + 1));
551
552 m_xImagesLst->remove_text(sActEntry);
553 m_xImagesLst->remove_text(sDownEntry);
554
555 m_xImagesLst->insert(nActPos, sDownEntry, &sDown, nullptr, nullptr);
556 m_xImagesLst->insert(nActPos + 1, sActEntry, &sAct, nullptr, nullptr);
557
558 m_xImagesLst->select(nActPos + 1);
559 }
560 EnableDisableButtons();
561}
562
564{
565 m_xImagesLst->remove(m_xImagesLst->get_selected_index());
566 m_aImg.SetGraphic(Graphic());
567
568 EnableDisableButtons();
569}
570
572{
573 OUString sImgUrl = m_xImagesLst->get_selected_id();
574
575 if (sImgUrl != SdResId(STR_PHOTO_ALBUM_TEXTBOX))
576 {
577 Graphic aGraphic;
578 INetURLObject aURLObj( sImgUrl );
579
580 sal_uInt16 nFilter = GRFILTER_FORMAT_DONTKNOW;
581
582 if ( aURLObj.HasError() || INetProtocol::NotValid == aURLObj.GetProtocol() )
583 {
584 aURLObj.SetSmartProtocol( INetProtocol::File );
585 aURLObj.SetSmartURL( sImgUrl );
586 }
587
588 GraphicFilterImportFlags nFilterImportFlags = GraphicFilterImportFlags::SetLogsizeForJpeg;
589 // remote?
590 if ( INetProtocol::File != aURLObj.GetProtocol() )
591 {
592 std::unique_ptr<SvStream> pStream = ::utl::UcbStreamHelper::CreateStream( sImgUrl, StreamMode::READ );
593
594 if( pStream )
595 m_pGraphicFilter->ImportGraphic( aGraphic, sImgUrl, *pStream, nFilter, nullptr, nFilterImportFlags );
596 else
597 m_pGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, nullptr, nFilterImportFlags );
598 }
599 else
600 {
601 m_pGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, nullptr, nFilterImportFlags );
602 }
603
604 BitmapEx aBmp = aGraphic.GetBitmapEx();
605 sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
606 sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
607
608 double nXRatio = double(200) / nBmpWidth;
609 double nYRatio = double(150) / nBmpHeight;
610 if ( nXRatio < nYRatio )
611 aBmp.Scale( nXRatio, nXRatio );
612 else
613 aBmp.Scale( nYRatio, nYRatio );
614
615 aBmp.Convert( BmpConversion::N24Bit );
616 m_aImg.SetGraphic(Graphic(aBmp));
617 }
618 else
619 {
620 m_aImg.SetGraphic(Graphic());
621 }
622 EnableDisableButtons();
623}
624
626{
627 // Enable "Fill Slide" only for one image
628 // If we want to have it for other images too, we need to implement the actual cropping.
629 bool const bEnable = m_xInsTypeCombo->get_active() == ONE_IMAGE;
630 m_xASRCheckCrop->set_sensitive(bEnable);
631 if (!bEnable)
632 m_xASRCheckCrop->set_active(false);
633}
634
635Reference< drawing::XDrawPage > SdPhotoAlbumDialog::appendNewSlide(AutoLayout aLayout,
636 const Reference< drawing::XDrawPages >& xDrawPages
637)
638{
639 // Create the slide
640 Reference< drawing::XDrawPage > xSlide = xDrawPages->insertNewByIndex( xDrawPages->getCount() );
642 pSlide->SetAutoLayout(aLayout, true); // Set the layout here
643 return xSlide;
644}
645
646awt::Size SdPhotoAlbumDialog::createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize)
647{
648 double resizeWidth = aPicSize.Width;
649 double resizeHeight = aPicSize.Height;
650 double aspect = resizeWidth/resizeHeight;
651
652 if( resizeWidth > aMaxSize.Width )
653 {
654 resizeWidth = aMaxSize.Width;
655 resizeHeight = resizeWidth / aspect;
656 }
657
658 if( resizeHeight > aMaxSize.Height )
659 {
660 aspect = resizeWidth/resizeHeight;
661 resizeHeight = aMaxSize.Height;
662 resizeWidth = resizeHeight * aspect;
663 }
664 return awt::Size(resizeWidth, resizeHeight);
665}
666
667awt::Size SdPhotoAlbumDialog::createASRSizeCrop(const awt::Size& aPicSize, const awt::Size& aMaxSize)
668{
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 ;
673
674
675 //When both sides of an image are bigger than canvas size, image would be downscaled.
676 if( resizeWidth > aMaxSize.Width && resizeHeight > aMaxSize.Height )
677 {
678 if( imgAspect > windowAspectRatio )
679 {
680 resizeHeight = aMaxSize.Height;
681 resizeWidth = aMaxSize.Height * imgAspect;
682 }
683 else
684 {
685 resizeHeight = aMaxSize.Width / imgAspect;
686 resizeWidth = aMaxSize.Width;
687 }
688
689 }
690 //In all other cases image is upscaled
691 else
692 {
693 if( imgAspect > windowAspectRatio )
694 {
695 resizeHeight = aMaxSize.Height;
696 resizeWidth = aMaxSize.Height * imgAspect;
697 }
698 else
699 {
700 resizeWidth = aMaxSize.Width;
701 resizeHeight = aMaxSize.Width / imgAspect;
702 }
703 }
704 return awt::Size(resizeWidth, resizeHeight);
705}
706
707void SdPhotoAlbumDialog::createCaption(const awt::Size& aPageSize )
708{
709 Point CapPos;
710 Size CapSize;
711
712 CapSize.setWidth( aPageSize.Width );
713 CapSize.setHeight( aPageSize.Height/6 );
714 CapPos.setX( 0 );
715 CapPos.setY( aPageSize.Height - CapSize.Height() );
717
718 // try to get existing PresObj
719 const ::tools::Rectangle rRect(CapPos,CapSize);
720 SdrObject* pSdrObj = pSlide->GetPresObj(PresObjKind::Title);
721
722 if(!pSdrObj)
723 {
724 // if not exists, create. Beware: It is already inserted to the SdPage
725 pSdrObj = pSlide->CreatePresObj(PresObjKind::Title,false,rRect);
726 }
727 else
728 {
729 // if exists, bring to front and position it
730 const size_t nObjNum(pSlide->GetObjCount());
731
732 if(nObjNum)
733 {
734 pSlide->SetObjectOrdNum(pSdrObj->GetOrdNum(), nObjNum - 1);
735 }
736
737 pSdrObj->SetSnapRect(rRect);
738 }
739
740 if(pSdrObj)
741 {
742 // set color, style and some transparency
743 SfxItemSet aSet(m_pDoc->GetItemPool() );
744
745 aSet.Put( XFillStyleItem(drawing::FillStyle_SOLID) );
746 aSet.Put( XFillColorItem( "", COL_BLACK ) );
747 aSet.Put( XFillTransparenceItem( 20 ) );
748 pSdrObj->SetMergedItemSetAndBroadcast(aSet);
749 }
750}
751
752Reference< graphic::XGraphic> SdPhotoAlbumDialog::createXGraphicFromUrl(const OUString& sUrl,
753 const Reference< graphic::XGraphicProvider>& xProvider
754)
755{
756 // The same as above, except this returns an XGraphic from the image URL
757 ::comphelper::NamedValueCollection aMediaProperties;
758 aMediaProperties.put( "URL", sUrl );
759 Reference< graphic::XGraphic> xGraphic =
760 xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
761 return xGraphic;
762}
763
765{
766 m_xRemoveBtn->set_sensitive(m_xImagesLst->count_selected_rows() > 0);
767 m_xUpBtn->set_sensitive(m_xImagesLst->count_selected_rows() > 0 &&
768 m_xImagesLst->get_selected_index() != 0);
769 m_xDownBtn->set_sensitive(m_xImagesLst->count_selected_rows() > 0 &&
770 m_xImagesLst->get_selected_index() < m_xImagesLst->n_children() - 1);
771}
772
773} // end of namespace sd
774
775/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
AutoLayout
AUTOLAYOUT_TITLE_ONLY
AUTOLAYOUT_NONE
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 HasError() 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
Definition: drawdoc2.cxx:207
sal_uInt16 GetSdPageCount(PageKind ePgKind) const
Definition: drawdoc2.cxx:212
SdrObject * GetPresObj(PresObjKind eObjKind, int nIndex=1, bool bFuzzySearch=false)
returns the nIndex'th object from the given PresObjKind, index starts with 1
Definition: sdpage.cxx:203
SdrObject * CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::tools::Rectangle &rRect)
creates a presentation object with the given PresObjKind on this page.
Definition: sdpage.cxx:284
void SetAutoLayout(AutoLayout eLayout, bool bInit=false, bool bCreate=false)
Definition: sdpage.cxx:1610
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
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 ERRCODE_NONE
#define GRFILTER_FORMAT_DONTKNOW
GraphicFilterImportFlags
int i
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)
Definition: sdmod.cxx:83
RET_OK
RET_CANCEL