fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / dlg / PhotoAlbumDialog.cxx
blob2c49e36dcfc57266b74de119eaf8837845b10f2b
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 <comphelper/componentcontext.hxx>
13 #include <comphelper/configurationhelper.hxx>
15 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
16 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
17 #include <com/sun/star/container/XNameAccess.hpp>
19 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
20 #include <com/sun/star/text/XText.hpp>
22 #include <sfx2/filedlghelper.hxx>
23 #include <tools/urlobj.hxx>
25 #include <unotools/pathoptions.hxx>
26 #include <unotools/useroptions.hxx>
27 #include <unotools/ucbstreamhelper.hxx>
29 #include <vcl/msgbox.hxx>
30 #include <svx/unoshape.hxx>
32 #include "PhotoAlbumDialog.hxx"
33 #include "strings.hrc"
34 #include "sdresid.hxx"
36 namespace sd
39 OUString SdPhotoAlbumDialog::sDirUrl;
41 SdPhotoAlbumDialog::SdPhotoAlbumDialog(Window* pWindow, SdDrawDocument* pActDoc)
42 : ModalDialog(pWindow, "PhotoAlbumCreatorDialog", "modules/simpress/ui/photoalbum.ui"),
43 pDoc(pActDoc)
45 get(pCancelBtn, "cancel_btn");
46 get(pCreateBtn, "create_btn");
48 get(pAddBtn, "add_btn");
49 get(pUpBtn, "up_btn");
50 get(pDownBtn, "down_btn");
51 get(pRemoveBtn, "rem_btn");
53 get(pImagesLst, "images_tree");
54 get(pImg, "preview_img");
56 get(pInsTypeCombo, "opt_combo");
57 get(pASRCheck, "asr_check");
59 pCancelBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CancelHdl));
60 pCreateBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CreateHdl));
62 pAddBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, FileHdl));
63 pUpBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, UpHdl));
64 pUpBtn->Disable();
65 pDownBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, DownHdl));
66 pDownBtn->Disable();
67 pRemoveBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, RemoveHdl));
68 pRemoveBtn->Disable();
69 pImagesLst->SetSelectHdl(LINK(this, SdPhotoAlbumDialog, SelectHdl));
71 mpGraphicFilter = new GraphicFilter;
72 sDirUrl = "";
73 pAddBtn->GrabFocus();
74 pImagesLst->Clear();
77 SdPhotoAlbumDialog::~SdPhotoAlbumDialog()
81 IMPL_LINK_NOARG(SdPhotoAlbumDialog, CancelHdl)
83 Close();
84 return 0;
87 IMPL_LINK_NOARG(SdPhotoAlbumDialog, CreateHdl)
89 if (pImagesLst->GetEntryCount() == 0)
91 WarningBox aWarning(this, WB_OK, SD_RESSTR(STR_PHOTO_ALBUM_EMPTY_WARNING));
92 aWarning.Execute();
94 else
96 Reference< drawing::XDrawPagesSupplier > xDPS( pDoc->getUnoModel(), uno::UNO_QUERY );
97 Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_QUERY );
98 Reference< lang::XMultiServiceFactory > xShapeFactory( pDoc->getUnoModel(), uno::UNO_QUERY );
100 Reference< XComponentContext > xContext(::comphelper::getProcessComponentContext());
101 Reference< graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(xContext));
103 // get the option
104 sal_uInt16 nOpt = pInsTypeCombo->GetSelectEntryPos();
105 if ( nOpt == ONE_IMAGE )
107 OUString sUrl;
108 for( sal_Int16 i = 0; i < pImagesLst->GetEntryCount(); ++i )
110 OUString* pData = (OUString*) pImagesLst->GetEntryData(i);
111 sUrl = *pData;
113 Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE, xDrawPages);
114 Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
116 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl, xProvider);
118 Image aImg(xGraphic);
119 // Save the original size, multiplied with 100
120 ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
122 Reference< drawing::XShape > xShape(
123 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
124 uno::UNO_QUERY);
126 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
127 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
130 ::awt::Size aPageSize;
132 xSlideProps->getPropertyValue(
133 OUString("Width")) >>= aPageSize.Width;
134 xSlideProps->getPropertyValue(
135 OUString("Height")) >>= aPageSize.Height;
137 ::awt::Point aPicPos;
139 if(pASRCheck->IsChecked())
141 // Resize the image, with keeping ASR
142 aPicSize = createASRSize(aPicSize, aPageSize);
144 else
146 aPicSize.Width = aPageSize.Width;
147 aPicSize.Height = aPageSize.Height;
150 xShape->setSize(aPicSize);
151 aPicPos.X = (aPageSize.Width - aPicSize.Width)/2;
152 aPicPos.Y = (aPageSize.Height - aPicSize.Height)/2;
154 xShape->setPosition(aPicPos);
155 xSlide->add(xShape);
158 else if( nOpt == TWO_IMAGES )
160 OUString sUrl1("");
161 OUString sUrl2("");
163 for( sal_Int32 i = 0; i < pImagesLst->GetEntryCount(); i+=2 )
165 OUString* pData = NULL;
167 // create the slide
168 Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE, xDrawPages);
169 Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
170 //Slide dimensions
171 ::awt::Size aPageSize;
173 xSlideProps->getPropertyValue(
174 OUString("Width")) >>= aPageSize.Width;
175 xSlideProps->getPropertyValue(
176 OUString("Height")) >>= aPageSize.Height;
178 // grab the left one
179 void* pD1 = pImagesLst->GetEntryData(i);
180 pData = (OUString*) pD1;
181 sUrl1 = pData ? OUString(*pData) : "";
182 // grab the right one
183 void* pD2 = pImagesLst->GetEntryData(i+1);
184 pData = (OUString*) pD2;
185 sUrl2 = pData ? OUString(*pData) : "";
187 if( !sUrl1.isEmpty() )
190 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
192 Image aImg(xGraphic);
193 // Save the original size, multiplied with 100
194 ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
196 Reference< drawing::XShape > xShape(
197 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
198 uno::UNO_QUERY);
200 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
201 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
203 ::awt::Point aPicPos;
205 if(pASRCheck->IsChecked())
207 // Resize the image, with keeping ASR
208 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
210 else
212 aPicSize.Width = aPageSize.Width/2 - 100;
213 aPicSize.Height = aPageSize.Height/2 - 100;
215 xShape->setSize(aPicSize);
216 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
217 aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
219 xShape->setPosition(aPicPos);
220 xSlide->add(xShape);
223 if( !sUrl2.isEmpty() )
225 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
227 Image aImg(xGraphic);
228 // Save the original size, multiplied with 100
229 ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
231 Reference< drawing::XShape > xShape(
232 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
233 uno::UNO_QUERY);
235 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
236 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
238 ::awt::Point aPicPos;
240 if(pASRCheck->IsChecked())
242 // Resize the image, with keeping ASR
243 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
245 else
247 aPicSize.Width = aPageSize.Width/2 - 100;
248 aPicSize.Height = aPageSize.Height/2 - 100;
250 xShape->setSize(aPicSize);
251 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
252 aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
254 xShape->setPosition(aPicPos);
255 xSlide->add(xShape);
259 else if( nOpt == FOUR_IMAGES )
261 OUString sUrl1("");
262 OUString sUrl2("");
263 OUString sUrl3("");
264 OUString sUrl4("");
266 for( sal_Int32 i = 0; i < pImagesLst->GetEntryCount(); i+=4 )
268 OUString* pData = NULL;
269 // create the slide
270 Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE, xDrawPages);
271 Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
272 //Slide dimensions
273 ::awt::Size aPageSize;
275 xSlideProps->getPropertyValue(
276 OUString("Width")) >>= aPageSize.Width;
277 xSlideProps->getPropertyValue(
278 OUString("Height")) >>= aPageSize.Height;
280 // grab the upper left one
281 void* pD1 = pImagesLst->GetEntryData(i);
282 pData = (OUString*) pD1;
283 sUrl1 = pData ? OUString(*pData) : "";
285 // grab the upper right one
286 void* pD2 = pImagesLst->GetEntryData(i+1);
287 pData = (OUString*) pD2;
288 sUrl2 = pData ? OUString(*pData) : "";
290 // grab the lower left one
291 void* pD3 = pImagesLst->GetEntryData(i+2);
292 pData = (OUString*) pD3;
293 sUrl3 = pData ? OUString(*pData) : "";
295 // grab the lower right one
296 void* pD4 = pImagesLst->GetEntryData(i+3);
297 pData = (OUString*) pD4;
298 sUrl4 = pData ? OUString(*pData) : "";
300 if( !sUrl1.isEmpty() )
302 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
304 Image aImg(xGraphic);
305 // Save the original size, multiplied with 100
306 ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
308 Reference< drawing::XShape > xShape(
309 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
310 uno::UNO_QUERY);
312 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
313 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
315 ::awt::Point aPicPos;
317 if(pASRCheck->IsChecked())
319 // Resize the image, with keeping ASR
320 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
322 else
324 aPicSize.Width = aPageSize.Width/2 - 100;
325 aPicSize.Height = aPageSize.Height/2 - 100;
327 xShape->setSize(aPicSize);
328 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
329 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
331 xShape->setPosition(aPicPos);
332 xSlide->add(xShape);
334 if( !sUrl2.isEmpty() )
336 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
338 Image aImg(xGraphic);
339 // Save the original size, multiplied with 100
340 ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
342 Reference< drawing::XShape > xShape(
343 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
344 uno::UNO_QUERY);
346 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
347 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
349 ::awt::Point aPicPos;
351 if(pASRCheck->IsChecked())
353 // Resize the image, with keeping ASR
354 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
356 else
358 aPicSize.Width = aPageSize.Width/2 - 100;
359 aPicSize.Height = aPageSize.Height/2 - 100;
361 xShape->setSize(aPicSize);
362 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
363 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
365 xShape->setPosition(aPicPos);
366 xSlide->add(xShape);
368 if( !sUrl3.isEmpty() )
371 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl3, xProvider);
373 Image aImg(xGraphic);
374 // Save the original size, multiplied with 100
375 ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
377 Reference< drawing::XShape > xShape(
378 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
379 uno::UNO_QUERY);
381 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
382 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
384 ::awt::Point aPicPos;
386 if(pASRCheck->IsChecked())
388 // Resize the image, with keeping ASR
389 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
391 else
393 aPicSize.Width = aPageSize.Width/2 - 100;
394 aPicSize.Height = aPageSize.Height/2 - 100;
396 xShape->setSize(aPicSize);
397 aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
398 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
401 xShape->setPosition(aPicPos);
402 xSlide->add(xShape);
404 if( !sUrl4.isEmpty() )
406 Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl4, xProvider);
408 Image aImg(xGraphic);
409 // Save the original size, multiplied with 100
410 ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
412 Reference< drawing::XShape > xShape(
413 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
414 uno::UNO_QUERY);
416 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
417 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
419 ::awt::Point aPicPos;
421 if(pASRCheck->IsChecked())
423 // Resize the image, with keeping ASR
424 aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
426 else
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) + aPageSize.Width/2;
433 aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
435 xShape->setPosition(aPicPos);
436 xSlide->add(xShape);
440 else
442 InfoBox aInfo(this, OUString("Function is not implemented!"));
443 aInfo.Execute();
445 EndDialog();
446 return 0;
448 return 0;
451 IMPL_LINK_NOARG(SdPhotoAlbumDialog, FileHdl)
453 ::sfx2::FileDialogHelper aDlg(
454 css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW,
455 SFXWB_GRAPHIC | SFXWB_MULTISELECTION
457 // Read configuration
458 OUString sUrl(".");
459 Reference< XInterface > xCfg;
462 xCfg = ::comphelper::ConfigurationHelper::openConfig(
463 ::comphelper::getProcessComponentContext(),
464 OUString("/org.openoffice.Office.Impress/"),
465 ::comphelper::ConfigurationHelper::E_READONLY);
467 ::comphelper::ConfigurationHelper::readRelativeKey(
468 xCfg,
469 OUString("Pictures"),
470 OUString("Path")) >>= sUrl;
472 catch(const Exception&)
474 OSL_FAIL("Could not find config for Create Photo Album function");
478 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
479 if (sUrl != "")
480 aDlg.SetDisplayDirectory(sUrl);
481 else
482 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
484 if ( aDlg.Execute() == ERRCODE_NONE )
486 Sequence< OUString > aFilesArr = aDlg.GetSelectedFiles();
487 if( aFilesArr.getLength() )
489 sUrl = aDlg.GetDisplayDirectory();
490 // Write out configuration
493 xCfg = ::comphelper::ConfigurationHelper::openConfig(
494 ::comphelper::getProcessComponentContext(),
495 OUString("/org.openoffice.Office.Impress/"),
496 ::comphelper::ConfigurationHelper::E_STANDARD);
498 ::comphelper::ConfigurationHelper::writeRelativeKey(
499 xCfg,
500 OUString("Pictures"),
501 OUString("Path"),
502 uno::makeAny(sUrl));
504 ::comphelper::ConfigurationHelper::flush(xCfg);
506 catch(const Exception&)
508 OSL_FAIL("Could not find config for Create Photo Album function");
511 for ( sal_Int32 i = 0; i < aFilesArr.getLength(); i++ )
513 // Store full path, show filename only. Use INetURLObject to display spaces in filename correctly
514 INetURLObject aUrl = INetURLObject(aFilesArr[i]);
515 sal_Int16 nPos = pImagesLst->InsertEntry( aUrl.GetLastName(INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8) );
516 pImagesLst->SetEntryData(nPos, (OUString*) new OUString(aUrl.GetMainURL(INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8)));
520 EnableDisableButtons();
521 return 0;
524 IMPL_LINK_NOARG(SdPhotoAlbumDialog, UpHdl)
526 if (pImagesLst->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
527 && pImagesLst->GetSelectEntryPos() != 0)
529 sal_uInt16 nActPos = pImagesLst->GetSelectEntryPos();
530 OUString sActEntry( pImagesLst->GetEntry(nActPos) );
531 // actual data
532 OUString* pActData = (OUString*) pImagesLst->GetEntryData(nActPos);
533 OUString sAct(*pActData);
535 OUString sUpperEntry( pImagesLst->GetEntry(nActPos - 1) );
536 // upper data
537 OUString* pUpperData = (OUString*) pImagesLst->GetEntryData(nActPos - 1);
538 OUString sUpper(*pUpperData);
540 pImagesLst->RemoveEntry( sActEntry );
541 pImagesLst->RemoveEntry( sUpperEntry );
543 pImagesLst->InsertEntry( sActEntry, nActPos - 1 );
544 pImagesLst->SetEntryData( nActPos - 1, (void*) new OUString(sAct));
546 pImagesLst->InsertEntry( sUpperEntry, nActPos );
547 pImagesLst->SetEntryData( nActPos, (void*) new OUString(sUpper));
549 pImagesLst->SelectEntryPos(nActPos - 1);
552 EnableDisableButtons();
553 return 0;
556 IMPL_LINK_NOARG(SdPhotoAlbumDialog, DownHdl)
558 sal_uInt16 nActPos = pImagesLst->GetSelectEntryPos();
559 if (pImagesLst->GetEntry(nActPos + 1) != OUString("") )
561 OUString sActEntry( pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos()) );
562 OUString* pActData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos());
563 OUString sAct(*pActData);
565 OUString sDownEntry( pImagesLst->GetEntry(nActPos + 1) );
566 OUString* pDownData = (OUString*) pImagesLst->GetEntryData(nActPos + 1);
567 OUString sDown(*pDownData);
569 pImagesLst->RemoveEntry( sActEntry );
570 pImagesLst->RemoveEntry( sDownEntry );
572 pImagesLst->InsertEntry( sDownEntry, nActPos );
573 pImagesLst->SetEntryData( nActPos, (void*) new OUString(sDown));
575 pImagesLst->InsertEntry( sActEntry, nActPos + 1 );
576 pImagesLst->SetEntryData( nActPos + 1, (void*) new OUString(sAct));
578 pImagesLst->SelectEntryPos(nActPos + 1);
581 EnableDisableButtons();
582 return 0;
585 IMPL_LINK_NOARG(SdPhotoAlbumDialog, RemoveHdl)
587 pImagesLst->RemoveEntry( pImagesLst->GetSelectEntryPos() );
588 pImg->SetImage(Image());
590 EnableDisableButtons();
591 return 0;
594 IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl)
596 OUString* pData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos());
597 OUString sImgUrl = pData ? OUString(*pData) : "";
599 if (sImgUrl != SD_RESSTR(STR_PHOTO_ALBUM_TEXTBOX))
601 GraphicFilter aCurFilter;
602 Graphic aGraphic;
603 INetURLObject aURLObj( sImgUrl );
605 sal_uInt16 nFilter = GRFILTER_FORMAT_DONTKNOW;
607 if ( aURLObj.HasError() || INET_PROT_NOT_VALID == aURLObj.GetProtocol() )
609 aURLObj.SetSmartProtocol( INET_PROT_FILE );
610 aURLObj.SetSmartURL( sImgUrl );
613 sal_uInt32 nFilterImportFlags = GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG;
614 // remote?
615 if ( INET_PROT_FILE != aURLObj.GetProtocol() )
617 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( sImgUrl, STREAM_READ );
619 if( pStream )
620 mpGraphicFilter->ImportGraphic( aGraphic, sImgUrl, *pStream, nFilter, NULL, nFilterImportFlags );
621 else
622 mpGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
623 delete pStream;
625 else
627 mpGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
630 Bitmap aBmp = aGraphic.GetBitmap();
631 sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
632 sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
633 sal_Int32 nPrevWidth = 200;
634 sal_Int32 nPrewHeight = 150;
636 double nXRatio = (double) nPrevWidth / nBmpWidth;
637 double nYRatio = (double) nPrewHeight / nBmpHeight;
638 if ( nXRatio < nYRatio )
639 aBmp.Scale( nXRatio, nXRatio );
640 else
641 aBmp.Scale( nYRatio, nYRatio );
643 aBmp.Convert( BMP_CONVERSION_24BIT );
644 pImg->SetImage( aBmp );
646 else
648 pImg->SetImage(Image());
650 EnableDisableButtons();
651 return 0;
654 Reference< drawing::XDrawPage > SdPhotoAlbumDialog::appendNewSlide(AutoLayout aLayout,
655 Reference< drawing::XDrawPages > xDrawPages
658 Reference< drawing::XDrawPage > xSlide; // Create the slide
659 Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY );
660 xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() );
661 SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD);
662 pSlide->SetAutoLayout(aLayout, sal_True); // Set the layout here
663 return xSlide;
666 awt::Size SdPhotoAlbumDialog::createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize)
668 double resizeWidth = aPicSize.Width;
669 double resizeHeight = aPicSize.Height;
670 double aspect = resizeWidth/resizeHeight;
672 if( resizeWidth > aMaxSize.Width )
674 resizeWidth = aMaxSize.Width;
675 resizeHeight = resizeWidth / aspect;
678 if( resizeHeight > aMaxSize.Height )
680 aspect = resizeWidth/resizeHeight;
681 resizeHeight = aMaxSize.Height;
682 resizeWidth = resizeHeight * aspect;
684 return awt::Size(resizeWidth, resizeHeight);
687 Reference< drawing::XShape > SdPhotoAlbumDialog::createXShapeFromUrl(const OUString& sUrl,
688 Reference< lang::XMultiServiceFactory > xShapeFactory,
689 Reference< graphic::XGraphicProvider> xProvider
692 //First, we create an XGraphic
693 ::comphelper::NamedValueCollection aMediaProperties;
694 aMediaProperties.put( "URL", OUString( sUrl ) );
695 Reference< graphic::XGraphic> xGraphic =
696 xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
697 //And then, we can create the XShape from the XGraphic
698 Reference< drawing::XShape > xShape(
699 xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
700 uno::UNO_QUERY
703 Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
704 xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
706 return xShape; // Image loaded into XShape
709 Reference< graphic::XGraphic> SdPhotoAlbumDialog::createXGraphicFromUrl(const OUString& sUrl,
710 Reference< graphic::XGraphicProvider> xProvider
713 // The same as above, except this returns an XGraphic from the image URL
714 ::comphelper::NamedValueCollection aMediaProperties;
715 aMediaProperties.put( "URL", OUString( sUrl ) );
716 Reference< graphic::XGraphic> xGraphic =
717 xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
718 return xGraphic;
721 short SdPhotoAlbumDialog::Execute()
723 return ModalDialog::Execute();
726 void SdPhotoAlbumDialog::EnableDisableButtons()
728 pRemoveBtn->Enable(pImagesLst->GetSelectEntryCount() > 0);
729 pUpBtn->Enable(pImagesLst->GetSelectEntryCount() > 0 &&
730 pImagesLst->GetSelectEntryPos() != 0);
731 pDownBtn->Enable(pImagesLst->GetSelectEntryCount() > 0 &&
732 pImagesLst->GetSelectEntryPos() < pImagesLst->GetEntryCount()-1);
736 } // end of namespace sd
738 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */