Line data Source code
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 :
10 : #include <comphelper/namedvaluecollection.hxx>
11 : #include <comphelper/processfactory.hxx>
12 :
13 : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
14 : #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
15 : #include <com/sun/star/container/XNameAccess.hpp>
16 :
17 : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
18 : #include <com/sun/star/text/XText.hpp>
19 :
20 : #include <sfx2/filedlghelper.hxx>
21 : #include <tools/urlobj.hxx>
22 :
23 : #include <unotools/pathoptions.hxx>
24 : #include <unotools/useroptions.hxx>
25 : #include <unotools/ucbstreamhelper.hxx>
26 : #include <officecfg/Office/Impress.hxx>
27 :
28 : #include <vcl/msgbox.hxx>
29 : #include <svx/unoshape.hxx>
30 :
31 : #include "PhotoAlbumDialog.hxx"
32 : #include "strings.hrc"
33 : #include "sdresid.hxx"
34 :
35 : namespace sd
36 : {
37 :
38 0 : OUString SdPhotoAlbumDialog::sDirUrl;
39 :
40 0 : SdPhotoAlbumDialog::SdPhotoAlbumDialog(Window* pWindow, SdDrawDocument* pActDoc)
41 : : ModalDialog(pWindow, "PhotoAlbumCreatorDialog", "modules/simpress/ui/photoalbum.ui"),
42 0 : pDoc(pActDoc)
43 : {
44 0 : get(pCancelBtn, "cancel_btn");
45 0 : get(pCreateBtn, "create_btn");
46 :
47 0 : get(pAddBtn, "add_btn");
48 0 : get(pUpBtn, "up_btn");
49 0 : get(pDownBtn, "down_btn");
50 0 : get(pRemoveBtn, "rem_btn");
51 :
52 0 : get(pImagesLst, "images_tree");
53 0 : get(pImg, "preview_img");
54 :
55 0 : get(pInsTypeCombo, "opt_combo");
56 0 : get(pASRCheck, "asr_check");
57 :
58 0 : pCancelBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CancelHdl));
59 0 : pCreateBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CreateHdl));
60 :
61 0 : pAddBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, FileHdl));
62 0 : pUpBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, UpHdl));
63 0 : pUpBtn->Disable();
64 0 : pDownBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, DownHdl));
65 0 : pDownBtn->Disable();
66 0 : pRemoveBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, RemoveHdl));
67 0 : pRemoveBtn->Disable();
68 0 : pImagesLst->SetSelectHdl(LINK(this, SdPhotoAlbumDialog, SelectHdl));
69 :
70 0 : mpGraphicFilter = new GraphicFilter;
71 0 : sDirUrl = "";
72 0 : pAddBtn->GrabFocus();
73 0 : pImagesLst->Clear();
74 0 : }
75 :
76 0 : SdPhotoAlbumDialog::~SdPhotoAlbumDialog()
77 : {
78 0 : }
79 :
80 0 : IMPL_LINK_NOARG(SdPhotoAlbumDialog, CancelHdl)
81 : {
82 0 : Close();
83 0 : return 0;
84 : }
85 :
86 0 : IMPL_LINK_NOARG(SdPhotoAlbumDialog, CreateHdl)
87 : {
88 0 : if (pImagesLst->GetEntryCount() == 0)
89 : {
90 0 : WarningBox aWarning(this, WB_OK, SD_RESSTR(STR_PHOTO_ALBUM_EMPTY_WARNING));
91 0 : aWarning.Execute();
92 : }
93 : else
94 : {
95 0 : Reference< drawing::XDrawPagesSupplier > xDPS( pDoc->getUnoModel(), uno::UNO_QUERY );
96 0 : Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_QUERY );
97 0 : Reference< lang::XMultiServiceFactory > xShapeFactory( pDoc->getUnoModel(), uno::UNO_QUERY );
98 :
99 0 : Reference< XComponentContext > xContext(::comphelper::getProcessComponentContext());
100 0 : Reference< graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(xContext));
101 :
102 : // get the option
103 0 : sal_uInt16 nOpt = pInsTypeCombo->GetSelectEntryPos();
104 0 : if ( nOpt == ONE_IMAGE )
105 : {
106 0 : OUString sUrl;
107 0 : for( sal_Int16 i = 0; i < pImagesLst->GetEntryCount(); ++i )
108 : {
109 0 : OUString* pData = (OUString*) pImagesLst->GetEntryData(i);
110 0 : sUrl = *pData;
111 :
112 0 : Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE, xDrawPages);
113 0 : Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
114 :
115 0 : Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl, xProvider);
116 :
117 0 : Image aImg(xGraphic);
118 : // Save the original size, multiplied with 100
119 0 : ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
120 :
121 : Reference< drawing::XShape > xShape(
122 0 : xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
123 0 : uno::UNO_QUERY);
124 :
125 0 : Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
126 0 : xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
127 :
128 :
129 0 : ::awt::Size aPageSize;
130 :
131 0 : xSlideProps->getPropertyValue(
132 0 : OUString("Width")) >>= aPageSize.Width;
133 0 : xSlideProps->getPropertyValue(
134 0 : OUString("Height")) >>= aPageSize.Height;
135 :
136 0 : ::awt::Point aPicPos;
137 :
138 0 : if(pASRCheck->IsChecked())
139 : {
140 : // Resize the image, with keeping ASR
141 0 : aPicSize = createASRSize(aPicSize, aPageSize);
142 : }
143 : else
144 : {
145 0 : aPicSize.Width = aPageSize.Width;
146 0 : aPicSize.Height = aPageSize.Height;
147 : }
148 :
149 0 : xShape->setSize(aPicSize);
150 0 : aPicPos.X = (aPageSize.Width - aPicSize.Width)/2;
151 0 : aPicPos.Y = (aPageSize.Height - aPicSize.Height)/2;
152 :
153 0 : xShape->setPosition(aPicPos);
154 0 : xSlide->add(xShape);
155 0 : }
156 : }
157 0 : else if( nOpt == TWO_IMAGES )
158 : {
159 0 : OUString sUrl1("");
160 0 : OUString sUrl2("");
161 :
162 0 : for( sal_Int32 i = 0; i < pImagesLst->GetEntryCount(); i+=2 )
163 : {
164 0 : OUString* pData = NULL;
165 :
166 : // create the slide
167 0 : Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE, xDrawPages);
168 0 : Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
169 : //Slide dimensions
170 0 : ::awt::Size aPageSize;
171 :
172 0 : xSlideProps->getPropertyValue(
173 0 : OUString("Width")) >>= aPageSize.Width;
174 0 : xSlideProps->getPropertyValue(
175 0 : OUString("Height")) >>= aPageSize.Height;
176 :
177 : // grab the left one
178 0 : void* pD1 = pImagesLst->GetEntryData(i);
179 0 : pData = (OUString*) pD1;
180 0 : sUrl1 = pData ? OUString(*pData) : "";
181 : // grab the right one
182 0 : void* pD2 = pImagesLst->GetEntryData(i+1);
183 0 : pData = (OUString*) pD2;
184 0 : sUrl2 = pData ? OUString(*pData) : "";
185 :
186 0 : if( !sUrl1.isEmpty() )
187 : {
188 :
189 0 : Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
190 :
191 0 : Image aImg(xGraphic);
192 : // Save the original size, multiplied with 100
193 0 : ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
194 :
195 : Reference< drawing::XShape > xShape(
196 0 : xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
197 0 : uno::UNO_QUERY);
198 :
199 0 : Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
200 0 : xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
201 :
202 0 : ::awt::Point aPicPos;
203 :
204 0 : if(pASRCheck->IsChecked())
205 : {
206 : // Resize the image, with keeping ASR
207 0 : aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
208 : }
209 : else
210 : {
211 0 : aPicSize.Width = aPageSize.Width/2 - 100;
212 0 : aPicSize.Height = aPageSize.Height/2 - 100;
213 : }
214 0 : xShape->setSize(aPicSize);
215 0 : aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
216 0 : aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
217 :
218 0 : xShape->setPosition(aPicPos);
219 0 : xSlide->add(xShape);
220 : }
221 :
222 0 : if( !sUrl2.isEmpty() )
223 : {
224 0 : Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
225 :
226 0 : Image aImg(xGraphic);
227 : // Save the original size, multiplied with 100
228 0 : ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
229 :
230 : Reference< drawing::XShape > xShape(
231 0 : xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
232 0 : uno::UNO_QUERY);
233 :
234 0 : Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
235 0 : xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
236 :
237 0 : ::awt::Point aPicPos;
238 :
239 0 : if(pASRCheck->IsChecked())
240 : {
241 : // Resize the image, with keeping ASR
242 0 : aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
243 : }
244 : else
245 : {
246 0 : aPicSize.Width = aPageSize.Width/2 - 100;
247 0 : aPicSize.Height = aPageSize.Height/2 - 100;
248 : }
249 0 : xShape->setSize(aPicSize);
250 0 : aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
251 0 : aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
252 :
253 0 : xShape->setPosition(aPicPos);
254 0 : xSlide->add(xShape);
255 : }
256 0 : }
257 : }
258 0 : else if( nOpt == FOUR_IMAGES )
259 : {
260 0 : OUString sUrl1("");
261 0 : OUString sUrl2("");
262 0 : OUString sUrl3("");
263 0 : OUString sUrl4("");
264 :
265 0 : for( sal_Int32 i = 0; i < pImagesLst->GetEntryCount(); i+=4 )
266 : {
267 0 : OUString* pData = NULL;
268 : // create the slide
269 0 : Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE, xDrawPages);
270 0 : Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
271 : //Slide dimensions
272 0 : ::awt::Size aPageSize;
273 :
274 0 : xSlideProps->getPropertyValue(
275 0 : OUString("Width")) >>= aPageSize.Width;
276 0 : xSlideProps->getPropertyValue(
277 0 : OUString("Height")) >>= aPageSize.Height;
278 :
279 : // grab the upper left one
280 0 : void* pD1 = pImagesLst->GetEntryData(i);
281 0 : pData = (OUString*) pD1;
282 0 : sUrl1 = pData ? OUString(*pData) : "";
283 :
284 : // grab the upper right one
285 0 : void* pD2 = pImagesLst->GetEntryData(i+1);
286 0 : pData = (OUString*) pD2;
287 0 : sUrl2 = pData ? OUString(*pData) : "";
288 :
289 : // grab the lower left one
290 0 : void* pD3 = pImagesLst->GetEntryData(i+2);
291 0 : pData = (OUString*) pD3;
292 0 : sUrl3 = pData ? OUString(*pData) : "";
293 :
294 : // grab the lower right one
295 0 : void* pD4 = pImagesLst->GetEntryData(i+3);
296 0 : pData = (OUString*) pD4;
297 0 : sUrl4 = pData ? OUString(*pData) : "";
298 :
299 0 : if( !sUrl1.isEmpty() )
300 : {
301 0 : Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
302 :
303 0 : Image aImg(xGraphic);
304 : // Save the original size, multiplied with 100
305 0 : ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
306 :
307 : Reference< drawing::XShape > xShape(
308 0 : xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
309 0 : uno::UNO_QUERY);
310 :
311 0 : Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
312 0 : xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
313 :
314 0 : ::awt::Point aPicPos;
315 :
316 0 : if(pASRCheck->IsChecked())
317 : {
318 : // Resize the image, with keeping ASR
319 0 : aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
320 : }
321 : else
322 : {
323 0 : aPicSize.Width = aPageSize.Width/2 - 100;
324 0 : aPicSize.Height = aPageSize.Height/2 - 100;
325 : }
326 0 : xShape->setSize(aPicSize);
327 0 : aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
328 0 : aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
329 :
330 0 : xShape->setPosition(aPicPos);
331 0 : xSlide->add(xShape);
332 : }
333 0 : if( !sUrl2.isEmpty() )
334 : {
335 0 : Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
336 :
337 0 : Image aImg(xGraphic);
338 : // Save the original size, multiplied with 100
339 0 : ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
340 :
341 : Reference< drawing::XShape > xShape(
342 0 : xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
343 0 : uno::UNO_QUERY);
344 :
345 0 : Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
346 0 : xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
347 :
348 0 : ::awt::Point aPicPos;
349 :
350 0 : if(pASRCheck->IsChecked())
351 : {
352 : // Resize the image, with keeping ASR
353 0 : aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
354 : }
355 : else
356 : {
357 0 : aPicSize.Width = aPageSize.Width/2 - 100;
358 0 : aPicSize.Height = aPageSize.Height/2 - 100;
359 : }
360 0 : xShape->setSize(aPicSize);
361 0 : aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
362 0 : aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
363 :
364 0 : xShape->setPosition(aPicPos);
365 0 : xSlide->add(xShape);
366 : }
367 0 : if( !sUrl3.isEmpty() )
368 : {
369 :
370 0 : Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl3, xProvider);
371 :
372 0 : Image aImg(xGraphic);
373 : // Save the original size, multiplied with 100
374 0 : ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
375 :
376 : Reference< drawing::XShape > xShape(
377 0 : xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
378 0 : uno::UNO_QUERY);
379 :
380 0 : Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
381 0 : xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
382 :
383 0 : ::awt::Point aPicPos;
384 :
385 0 : if(pASRCheck->IsChecked())
386 : {
387 : // Resize the image, with keeping ASR
388 0 : aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
389 : }
390 : else
391 : {
392 0 : aPicSize.Width = aPageSize.Width/2 - 100;
393 0 : aPicSize.Height = aPageSize.Height/2 - 100;
394 : }
395 0 : xShape->setSize(aPicSize);
396 0 : aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
397 0 : aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
398 :
399 :
400 0 : xShape->setPosition(aPicPos);
401 0 : xSlide->add(xShape);
402 : }
403 0 : if( !sUrl4.isEmpty() )
404 : {
405 0 : Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl4, xProvider);
406 :
407 0 : Image aImg(xGraphic);
408 : // Save the original size, multiplied with 100
409 0 : ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
410 :
411 : Reference< drawing::XShape > xShape(
412 0 : xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
413 0 : uno::UNO_QUERY);
414 :
415 0 : Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
416 0 : xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
417 :
418 0 : ::awt::Point aPicPos;
419 :
420 0 : if(pASRCheck->IsChecked())
421 : {
422 : // Resize the image, with keeping ASR
423 0 : aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
424 : }
425 : else
426 : {
427 0 : aPicSize.Width = aPageSize.Width/2 - 100;
428 0 : aPicSize.Height = aPageSize.Height/2 - 100;
429 : }
430 0 : xShape->setSize(aPicSize);
431 0 : aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
432 0 : aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
433 :
434 0 : xShape->setPosition(aPicPos);
435 0 : xSlide->add(xShape);
436 : }
437 0 : }
438 : }
439 : else
440 : {
441 0 : InfoBox aInfo(this, OUString("Function is not implemented!"));
442 0 : aInfo.Execute();
443 : }
444 0 : EndDialog();
445 0 : return 0;
446 : }
447 0 : return 0;
448 : }
449 :
450 0 : IMPL_LINK_NOARG(SdPhotoAlbumDialog, FileHdl)
451 : {
452 : ::sfx2::FileDialogHelper aDlg(
453 : css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW,
454 : SFXWB_GRAPHIC | SFXWB_MULTISELECTION
455 0 : );
456 : // Read configuration
457 0 : OUString sUrl(officecfg::Office::Impress::Pictures::Path::get());
458 :
459 0 : INetURLObject aFile( SvtPathOptions().GetPalettePath() );
460 0 : if (sUrl != "")
461 0 : aDlg.SetDisplayDirectory(sUrl);
462 : else
463 0 : aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
464 :
465 0 : if ( aDlg.Execute() == ERRCODE_NONE )
466 : {
467 0 : Sequence< OUString > aFilesArr = aDlg.GetSelectedFiles();
468 0 : if( aFilesArr.getLength() )
469 : {
470 0 : sUrl = aDlg.GetDisplayDirectory();
471 : // Write out configuration
472 : {
473 : boost::shared_ptr< comphelper::ConfigurationChanges > batch(
474 0 : comphelper::ConfigurationChanges::create());
475 0 : officecfg::Office::Impress::Pictures::Path::set(sUrl, batch);
476 0 : batch->commit();
477 : }
478 :
479 0 : for ( sal_Int32 i = 0; i < aFilesArr.getLength(); i++ )
480 : {
481 : // Store full path, show filename only. Use INetURLObject to display spaces in filename correctly
482 0 : INetURLObject aUrl = INetURLObject(aFilesArr[i]);
483 0 : sal_Int16 nPos = pImagesLst->InsertEntry( aUrl.GetLastName(INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8) );
484 0 : pImagesLst->SetEntryData(nPos, new OUString(aUrl.GetMainURL(INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8)));
485 0 : }
486 0 : }
487 : }
488 0 : EnableDisableButtons();
489 0 : return 0;
490 : }
491 :
492 0 : IMPL_LINK_NOARG(SdPhotoAlbumDialog, UpHdl)
493 : {
494 0 : if (pImagesLst->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
495 0 : && pImagesLst->GetSelectEntryPos() != 0)
496 : {
497 0 : sal_uInt16 nActPos = pImagesLst->GetSelectEntryPos();
498 0 : OUString sActEntry( pImagesLst->GetEntry(nActPos) );
499 : // actual data
500 0 : OUString* pActData = (OUString*) pImagesLst->GetEntryData(nActPos);
501 0 : OUString sAct(*pActData);
502 :
503 0 : OUString sUpperEntry( pImagesLst->GetEntry(nActPos - 1) );
504 : // upper data
505 0 : OUString* pUpperData = (OUString*) pImagesLst->GetEntryData(nActPos - 1);
506 0 : OUString sUpper(*pUpperData);
507 :
508 0 : pImagesLst->RemoveEntry( sActEntry );
509 0 : pImagesLst->RemoveEntry( sUpperEntry );
510 :
511 0 : pImagesLst->InsertEntry( sActEntry, nActPos - 1 );
512 0 : pImagesLst->SetEntryData( nActPos - 1, new OUString(sAct));
513 :
514 0 : pImagesLst->InsertEntry( sUpperEntry, nActPos );
515 0 : pImagesLst->SetEntryData( nActPos, new OUString(sUpper));
516 :
517 0 : pImagesLst->SelectEntryPos(nActPos - 1);
518 : }
519 :
520 0 : EnableDisableButtons();
521 0 : return 0;
522 : }
523 :
524 0 : IMPL_LINK_NOARG(SdPhotoAlbumDialog, DownHdl)
525 : {
526 0 : sal_uInt16 nActPos = pImagesLst->GetSelectEntryPos();
527 0 : if (pImagesLst->GetEntry(nActPos + 1) != OUString("") )
528 : {
529 0 : OUString sActEntry( pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos()) );
530 0 : OUString* pActData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos());
531 0 : OUString sAct(*pActData);
532 :
533 0 : OUString sDownEntry( pImagesLst->GetEntry(nActPos + 1) );
534 0 : OUString* pDownData = (OUString*) pImagesLst->GetEntryData(nActPos + 1);
535 0 : OUString sDown(*pDownData);
536 :
537 0 : pImagesLst->RemoveEntry( sActEntry );
538 0 : pImagesLst->RemoveEntry( sDownEntry );
539 :
540 0 : pImagesLst->InsertEntry( sDownEntry, nActPos );
541 0 : pImagesLst->SetEntryData( nActPos, new OUString(sDown));
542 :
543 0 : pImagesLst->InsertEntry( sActEntry, nActPos + 1 );
544 0 : pImagesLst->SetEntryData( nActPos + 1, new OUString(sAct));
545 :
546 0 : pImagesLst->SelectEntryPos(nActPos + 1);
547 :
548 : }
549 0 : EnableDisableButtons();
550 0 : return 0;
551 : }
552 :
553 0 : IMPL_LINK_NOARG(SdPhotoAlbumDialog, RemoveHdl)
554 : {
555 0 : pImagesLst->RemoveEntry( pImagesLst->GetSelectEntryPos() );
556 0 : pImg->SetImage(Image());
557 :
558 0 : EnableDisableButtons();
559 0 : return 0;
560 : }
561 :
562 0 : IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl)
563 : {
564 0 : OUString* pData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos());
565 0 : OUString sImgUrl = pData ? OUString(*pData) : "";
566 :
567 0 : if (sImgUrl != SD_RESSTR(STR_PHOTO_ALBUM_TEXTBOX))
568 : {
569 0 : GraphicFilter aCurFilter;
570 0 : Graphic aGraphic;
571 0 : INetURLObject aURLObj( sImgUrl );
572 :
573 0 : sal_uInt16 nFilter = GRFILTER_FORMAT_DONTKNOW;
574 :
575 0 : if ( aURLObj.HasError() || INET_PROT_NOT_VALID == aURLObj.GetProtocol() )
576 : {
577 0 : aURLObj.SetSmartProtocol( INET_PROT_FILE );
578 0 : aURLObj.SetSmartURL( sImgUrl );
579 : }
580 :
581 0 : sal_uInt32 nFilterImportFlags = GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG;
582 : // remote?
583 0 : if ( INET_PROT_FILE != aURLObj.GetProtocol() )
584 : {
585 0 : SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( sImgUrl, STREAM_READ );
586 :
587 0 : if( pStream )
588 0 : mpGraphicFilter->ImportGraphic( aGraphic, sImgUrl, *pStream, nFilter, NULL, nFilterImportFlags );
589 : else
590 0 : mpGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
591 0 : delete pStream;
592 : }
593 : else
594 : {
595 0 : mpGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
596 : }
597 :
598 0 : Bitmap aBmp = aGraphic.GetBitmap();
599 0 : sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
600 0 : sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
601 0 : sal_Int32 nPrevWidth = 200;
602 0 : sal_Int32 nPrewHeight = 150;
603 :
604 0 : double nXRatio = (double) nPrevWidth / nBmpWidth;
605 0 : double nYRatio = (double) nPrewHeight / nBmpHeight;
606 0 : if ( nXRatio < nYRatio )
607 0 : aBmp.Scale( nXRatio, nXRatio );
608 : else
609 0 : aBmp.Scale( nYRatio, nYRatio );
610 :
611 0 : aBmp.Convert( BMP_CONVERSION_24BIT );
612 0 : pImg->SetImage(Image(aBmp));
613 : }
614 : else
615 : {
616 0 : pImg->SetImage(Image());
617 : }
618 0 : EnableDisableButtons();
619 0 : return 0;
620 : }
621 :
622 0 : Reference< drawing::XDrawPage > SdPhotoAlbumDialog::appendNewSlide(AutoLayout aLayout,
623 : Reference< drawing::XDrawPages > xDrawPages
624 : )
625 : {
626 0 : Reference< drawing::XDrawPage > xSlide; // Create the slide
627 0 : Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY );
628 0 : xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() );
629 0 : SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD);
630 0 : pSlide->SetAutoLayout(aLayout, sal_True); // Set the layout here
631 0 : return xSlide;
632 : }
633 :
634 0 : awt::Size SdPhotoAlbumDialog::createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize)
635 : {
636 0 : double resizeWidth = aPicSize.Width;
637 0 : double resizeHeight = aPicSize.Height;
638 0 : double aspect = resizeWidth/resizeHeight;
639 :
640 0 : if( resizeWidth > aMaxSize.Width )
641 : {
642 0 : resizeWidth = aMaxSize.Width;
643 0 : resizeHeight = resizeWidth / aspect;
644 : }
645 :
646 0 : if( resizeHeight > aMaxSize.Height )
647 : {
648 0 : aspect = resizeWidth/resizeHeight;
649 0 : resizeHeight = aMaxSize.Height;
650 0 : resizeWidth = resizeHeight * aspect;
651 : }
652 0 : return awt::Size(resizeWidth, resizeHeight);
653 : }
654 :
655 0 : Reference< graphic::XGraphic> SdPhotoAlbumDialog::createXGraphicFromUrl(const OUString& sUrl,
656 : Reference< graphic::XGraphicProvider> xProvider
657 : )
658 : {
659 : // The same as above, except this returns an XGraphic from the image URL
660 0 : ::comphelper::NamedValueCollection aMediaProperties;
661 0 : aMediaProperties.put( "URL", OUString( sUrl ) );
662 : Reference< graphic::XGraphic> xGraphic =
663 0 : xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
664 0 : return xGraphic;
665 : }
666 :
667 0 : short SdPhotoAlbumDialog::Execute()
668 : {
669 0 : return ModalDialog::Execute();
670 : }
671 :
672 0 : void SdPhotoAlbumDialog::EnableDisableButtons()
673 : {
674 0 : pRemoveBtn->Enable(pImagesLst->GetSelectEntryCount() > 0);
675 0 : pUpBtn->Enable(pImagesLst->GetSelectEntryCount() > 0 &&
676 0 : pImagesLst->GetSelectEntryPos() != 0);
677 0 : pDownBtn->Enable(pImagesLst->GetSelectEntryCount() > 0 &&
678 0 : pImagesLst->GetSelectEntryPos() < pImagesLst->GetEntryCount()-1);
679 0 : }
680 :
681 :
682 0 : } // end of namespace sd
683 :
684 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|