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 <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"
39 OUString
SdPhotoAlbumDialog::sDirUrl
;
41 SdPhotoAlbumDialog::SdPhotoAlbumDialog(Window
* pWindow
, SdDrawDocument
* pActDoc
)
42 : ModalDialog(pWindow
, "PhotoAlbumCreatorDialog", "modules/simpress/ui/photoalbum.ui"),
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
));
65 pDownBtn
->SetClickHdl(LINK(this, SdPhotoAlbumDialog
, DownHdl
));
67 pRemoveBtn
->SetClickHdl(LINK(this, SdPhotoAlbumDialog
, RemoveHdl
));
68 pRemoveBtn
->Disable();
69 pImagesLst
->SetSelectHdl(LINK(this, SdPhotoAlbumDialog
, SelectHdl
));
71 mpGraphicFilter
= new GraphicFilter
;
77 SdPhotoAlbumDialog::~SdPhotoAlbumDialog()
81 IMPL_LINK_NOARG(SdPhotoAlbumDialog
, CancelHdl
)
87 IMPL_LINK_NOARG(SdPhotoAlbumDialog
, CreateHdl
)
89 if (pImagesLst
->GetEntryCount() == 0)
91 WarningBox
aWarning(this, WB_OK
, SD_RESSTR(STR_PHOTO_ALBUM_EMPTY_WARNING
));
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
));
104 sal_uInt16 nOpt
= pInsTypeCombo
->GetSelectEntryPos();
105 if ( nOpt
== ONE_IMAGE
)
108 for( sal_Int16 i
= 0; i
< pImagesLst
->GetEntryCount(); ++i
)
110 OUString
* pData
= (OUString
*) pImagesLst
->GetEntryData(i
);
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"),
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
);
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
);
158 else if( nOpt
== TWO_IMAGES
)
163 for( sal_Int32 i
= 0; i
< pImagesLst
->GetEntryCount(); i
+=2 )
165 OUString
* pData
= NULL
;
168 Reference
< drawing::XDrawPage
> xSlide
= appendNewSlide(AUTOLAYOUT_NONE
, xDrawPages
);
169 Reference
< beans::XPropertySet
> xSlideProps( xSlide
, uno::UNO_QUERY
);
171 ::awt::Size aPageSize
;
173 xSlideProps
->getPropertyValue(
174 OUString("Width")) >>= aPageSize
.Width
;
175 xSlideProps
->getPropertyValue(
176 OUString("Height")) >>= aPageSize
.Height
;
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"),
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));
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
);
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"),
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));
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
);
259 else if( nOpt
== FOUR_IMAGES
)
266 for( sal_Int32 i
= 0; i
< pImagesLst
->GetEntryCount(); i
+=4 )
268 OUString
* pData
= NULL
;
270 Reference
< drawing::XDrawPage
> xSlide
= appendNewSlide(AUTOLAYOUT_NONE
, xDrawPages
);
271 Reference
< beans::XPropertySet
> xSlideProps( xSlide
, uno::UNO_QUERY
);
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"),
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));
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
);
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"),
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));
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
);
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"),
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));
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
);
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"),
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));
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
);
442 InfoBox
aInfo(this, OUString("Function is not implemented!"));
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
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(
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() );
480 aDlg
.SetDisplayDirectory(sUrl
);
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(
500 OUString("Pictures"),
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();
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
) );
532 OUString
* pActData
= (OUString
*) pImagesLst
->GetEntryData(nActPos
);
533 OUString
sAct(*pActData
);
535 OUString
sUpperEntry( pImagesLst
->GetEntry(nActPos
- 1) );
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();
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();
585 IMPL_LINK_NOARG(SdPhotoAlbumDialog
, RemoveHdl
)
587 pImagesLst
->RemoveEntry( pImagesLst
->GetSelectEntryPos() );
588 pImg
->SetImage(Image());
590 EnableDisableButtons();
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
;
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
;
615 if ( INET_PROT_FILE
!= aURLObj
.GetProtocol() )
617 SvStream
* pStream
= ::utl::UcbStreamHelper::CreateStream( sImgUrl
, STREAM_READ
);
620 mpGraphicFilter
->ImportGraphic( aGraphic
, sImgUrl
, *pStream
, nFilter
, NULL
, nFilterImportFlags
);
622 mpGraphicFilter
->ImportGraphic( aGraphic
, aURLObj
, nFilter
, NULL
, nFilterImportFlags
);
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
);
641 aBmp
.Scale( nYRatio
, nYRatio
);
643 aBmp
.Convert( BMP_CONVERSION_24BIT
);
644 pImg
->SetImage( aBmp
);
648 pImg
->SetImage(Image());
650 EnableDisableButtons();
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
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"),
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() );
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: */