1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/processfactory.hxx>
#include <svl/itemset.hxx>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <com/sun/star/text/XText.hpp>
#include <sfx2/filedlghelper.hxx>
#include <tools/urlobj.hxx>
#include <unotools/pathoptions.hxx>
#include <unotools/useroptions.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <officecfg/Office/Impress.hxx>
#include <svx/svdview.hxx>
#include <vcl/msgbox.hxx>
#include <svx/unoshape.hxx>
#include <svx/xfltrit.hxx>
#include <svx/xfillit.hxx>
#include "PhotoAlbumDialog.hxx"
#include "strings.hrc"
#include "sdresid.hxx"
namespace sd
{
SdPhotoAlbumDialog::SdPhotoAlbumDialog(vcl::Window* pWindow, SdDrawDocument* pActDoc)
: ModalDialog(pWindow, "PhotoAlbumCreatorDialog", "modules/simpress/ui/photoalbum.ui"),
pDoc(pActDoc)
{
get(pCancelBtn, "cancel_btn");
get(pCreateBtn, "create_btn");
get(pAddBtn, "add_btn");
get(pUpBtn, "up_btn");
get(pDownBtn, "down_btn");
get(pRemoveBtn, "rem_btn");
get(pImagesLst, "images_tree");
get(pImg, "preview_img");
get(pInsTypeCombo, "opt_combo");
get(pASRCheck, "asr_check");
get(pASRCheckCrop, "asr_check_crop");
get(pCapCheck, "cap_check");
get(pInsertAsLinkCheck, "insert_as_link_check");
pCancelBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CancelHdl));
pCreateBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CreateHdl));
pAddBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, FileHdl));
pUpBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, UpHdl));
pUpBtn->Disable();
pDownBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, DownHdl));
pDownBtn->Disable();
pRemoveBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, RemoveHdl));
pRemoveBtn->Disable();
pImagesLst->SetSelectHdl(LINK(this, SdPhotoAlbumDialog, SelectHdl));
pInsTypeCombo->SetSelectHdl(LINK(this, SdPhotoAlbumDialog, TypeSelectHdl));
mpGraphicFilter = new GraphicFilter;
pAddBtn->GrabFocus();
pImagesLst->Clear();
}
SdPhotoAlbumDialog::~SdPhotoAlbumDialog()
{
disposeOnce();
}
void SdPhotoAlbumDialog::dispose()
{
pCancelBtn.clear();
pCreateBtn.clear();
pAddBtn.clear();
pUpBtn.clear();
pDownBtn.clear();
pRemoveBtn.clear();
pImagesLst.clear();
pImg.clear();
pInsTypeCombo.clear();
pASRCheck.clear();
pASRCheckCrop.clear();
pCapCheck.clear();
pInsertAsLinkCheck.clear();
ModalDialog::dispose();
}
IMPL_LINK_NOARG(SdPhotoAlbumDialog, CancelHdl, Button*, void)
{
Close();
}
IMPL_LINK_NOARG(SdPhotoAlbumDialog, CreateHdl, Button*, void)
{
if (pImagesLst->GetEntryCount() == 0)
{
ScopedVclPtrInstance< WarningBox > aWarning(this, WB_OK, SD_RESSTR(STR_PHOTO_ALBUM_EMPTY_WARNING));
aWarning->Execute();
}
else
{
Reference< drawing::XDrawPagesSupplier > xDPS( pDoc->getUnoModel(), uno::UNO_QUERY );
Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_QUERY );
Reference< lang::XMultiServiceFactory > xShapeFactory( pDoc->getUnoModel(), uno::UNO_QUERY );
Reference< XComponentContext > xContext(::comphelper::getProcessComponentContext());
Reference< graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(xContext));
// determine if to use Captions (use TitleObject) and choose the correct AutoLayout
// from the beginning
const bool bCreateCaptions(pCapCheck->IsChecked());
const bool bInsertAsLink(pInsertAsLinkCheck->IsChecked());
const AutoLayout aAutoLayout(bCreateCaptions ? AUTOLAYOUT_TITLE_ONLY : AUTOLAYOUT_NONE);
// get the option
const sal_Int32 nOpt = pInsTypeCombo->GetSelectEntryPos();
if ( nOpt == ONE_IMAGE )
{
OUString sUrl;
for( sal_Int32 i = 0; i < pImagesLst->GetEntryCount(); ++i )
{
OUString const * pData = static_cast<OUString const *>(pImagesLst->GetEntryData(i));
sUrl = *pData;
Reference< drawing::XDrawPage > xSlide = appendNewSlide(aAutoLayout, xDrawPages);
Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl, xProvider);
Graphic aImg(xGraphic);
// Save the original size, multiplied with 100
::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
Reference< drawing::XShape > xShape(
xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
uno::UNO_QUERY);
Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
if (bInsertAsLink)
xProps->setPropertyValue("GraphicURL", ::uno::Any(sUrl));
else
xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
::awt::Size aPageSize;
xSlideProps->getPropertyValue(
"Width") >>= aPageSize.Width;
xSlideProps->getPropertyValue(
"Height") >>= aPageSize.Height;
::awt::Point aPicPos;
if(pASRCheck->IsChecked() && !pASRCheckCrop->IsChecked())
{
// Resize the image, with keeping ASR
aPicSize = createASRSize(aPicSize, aPageSize);
}
else if(pASRCheckCrop->IsChecked())
{
aPicSize = createASRSizeCrop(aPicSize, aPageSize);
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width - aPicSize.Width)/2;
aPicPos.Y = (aPageSize.Height - aPicSize.Height)/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
if(bCreateCaptions)
createCaption( aPageSize );
}
}
else if( nOpt == TWO_IMAGES )
{
OUString sUrl1("");
OUString sUrl2("");
for( sal_Int32 i = 0; i < pImagesLst->GetEntryCount(); i+=2 )
{
OUString const * pData = nullptr;
// create the slide
Reference< drawing::XDrawPage > xSlide = appendNewSlide(aAutoLayout, xDrawPages);
Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
//Slide dimensions
::awt::Size aPageSize;
xSlideProps->getPropertyValue(
"Width") >>= aPageSize.Width;
xSlideProps->getPropertyValue(
"Height") >>= aPageSize.Height;
// grab the left one
void* pD1 = pImagesLst->GetEntryData(i);
pData = static_cast<OUString const *>(pD1);
sUrl1 = pData ? OUString(*pData) : "";
// grab the right one
void* pD2 = pImagesLst->GetEntryData(i+1);
pData = static_cast<OUString const *>(pD2);
sUrl2 = pData ? OUString(*pData) : "";
if( !sUrl1.isEmpty() )
{
Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
Graphic aImg(xGraphic);
// Save the original size, multiplied with 100
::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
Reference< drawing::XShape > xShape(
xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
uno::UNO_QUERY);
Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
if (bInsertAsLink)
xProps->setPropertyValue("GraphicURL", ::uno::Any(sUrl1));
else
xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
::awt::Point aPicPos;
if(pASRCheck->IsChecked())
{
// Resize the image, with keeping ASR
aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
}
if( !sUrl2.isEmpty() )
{
Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
Graphic aImg(xGraphic);
// Save the original size, multiplied with 100
::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
Reference< drawing::XShape > xShape(
xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
uno::UNO_QUERY);
Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
if (bInsertAsLink)
xProps->setPropertyValue("GraphicURL", ::uno::Any(sUrl2));
else
xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
::awt::Point aPicPos;
if(pASRCheck->IsChecked())
{
// Resize the image, with keeping ASR
aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
if(bCreateCaptions)
createCaption( aPageSize );
}
}
}
else if( nOpt == FOUR_IMAGES )
{
OUString sUrl1("");
OUString sUrl2("");
OUString sUrl3("");
OUString sUrl4("");
for( sal_Int32 i = 0; i < pImagesLst->GetEntryCount(); i+=4 )
{
OUString* pData = nullptr;
// create the slide
Reference< drawing::XDrawPage > xSlide = appendNewSlide(aAutoLayout, xDrawPages);
Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
//Slide dimensions
::awt::Size aPageSize;
xSlideProps->getPropertyValue(
"Width") >>= aPageSize.Width;
xSlideProps->getPropertyValue(
"Height") >>= aPageSize.Height;
// grab the upper left one
void* pD1 = pImagesLst->GetEntryData(i);
pData = static_cast<OUString*>(pD1);
sUrl1 = pData ? OUString(*pData) : "";
// grab the upper right one
void* pD2 = pImagesLst->GetEntryData(i+1);
pData = static_cast<OUString *>(pD2);
sUrl2 = pData ? OUString(*pData) : "";
// grab the lower left one
void* pD3 = pImagesLst->GetEntryData(i+2);
pData = static_cast<OUString*>(pD3);
sUrl3 = pData ? OUString(*pData) : "";
// grab the lower right one
void* pD4 = pImagesLst->GetEntryData(i+3);
pData = static_cast<OUString*>(pD4);
sUrl4 = pData ? OUString(*pData) : "";
if( !sUrl1.isEmpty() )
{
Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1, xProvider);
Graphic aImg(xGraphic);
// Save the original size, multiplied with 100
::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
Reference< drawing::XShape > xShape(
xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
uno::UNO_QUERY);
Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
if (bInsertAsLink)
xProps->setPropertyValue("GraphicURL", ::uno::Any(sUrl1));
else
xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
::awt::Point aPicPos;
if(pASRCheck->IsChecked())
{
// Resize the image, with keeping ASR
aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
}
if( !sUrl2.isEmpty() )
{
Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2, xProvider);
Graphic aImg(xGraphic);
// Save the original size, multiplied with 100
::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
Reference< drawing::XShape > xShape(
xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
uno::UNO_QUERY);
Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
if (bInsertAsLink)
xProps->setPropertyValue("GraphicURL", ::uno::Any(sUrl2));
else
xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
::awt::Point aPicPos;
if(pASRCheck->IsChecked())
{
// Resize the image, with keeping ASR
aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
}
if( !sUrl3.isEmpty() )
{
Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl3, xProvider);
Graphic aImg(xGraphic);
// Save the original size, multiplied with 100
::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
Reference< drawing::XShape > xShape(
xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
uno::UNO_QUERY);
Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
if (bInsertAsLink)
xProps->setPropertyValue("GraphicURL", ::uno::Any(sUrl3));
else
xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
::awt::Point aPicPos;
if(pASRCheck->IsChecked())
{
// Resize the image, with keeping ASR
aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
}
if( !sUrl4.isEmpty() )
{
Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl4, xProvider);
Graphic aImg(xGraphic);
// Save the original size, multiplied with 100
::awt::Size aPicSize(aImg.GetSizePixel().Width()*100, aImg.GetSizePixel().Height()*100);
Reference< drawing::XShape > xShape(
xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
uno::UNO_QUERY);
Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
if (bInsertAsLink)
xProps->setPropertyValue("GraphicURL", ::uno::Any(sUrl4));
else
xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
::awt::Point aPicPos;
if(pASRCheck->IsChecked())
{
// Resize the image, with keeping ASR
aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
if(bCreateCaptions)
createCaption( aPageSize );
}
}
}
else
{
ScopedVclPtrInstance< InfoBox > aInfo(this, OUString("Function is not implemented!"));
aInfo->Execute();
}
EndDialog();
}
}
IMPL_LINK_NOARG(SdPhotoAlbumDialog, FileHdl, Button*, void)
{
::sfx2::FileDialogHelper aDlg(
css::ui::dialogs::TemplateDescription::FILEOPEN_PREVIEW,
FileDialogFlags::Graphic | FileDialogFlags::MultiSelection
);
// Read configuration
OUString sUrl(officecfg::Office::Impress::Pictures::Path::get());
INetURLObject aFile( SvtPathOptions().GetUserConfigPath() );
if (!sUrl.isEmpty())
aDlg.SetDisplayDirectory(sUrl);
else
aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
if ( aDlg.Execute() == ERRCODE_NONE )
{
Sequence< OUString > aFilesArr = aDlg.GetSelectedFiles();
if( aFilesArr.getLength() )
{
sUrl = aDlg.GetDisplayDirectory();
// Write out configuration
{
std::shared_ptr< comphelper::ConfigurationChanges > batch(
comphelper::ConfigurationChanges::create());
officecfg::Office::Impress::Pictures::Path::set(sUrl, batch);
batch->commit();
}
for ( sal_Int32 i = 0; i < aFilesArr.getLength(); i++ )
{
// Store full path, show filename only. Use INetURLObject to display spaces in filename correctly
INetURLObject aUrl = INetURLObject(aFilesArr[i]);
sal_Int16 nPos = pImagesLst->InsertEntry( aUrl.GetLastName(INetURLObject::DecodeMechanism::WithCharset) );
pImagesLst->SetEntryData(nPos, new OUString(aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)));
}
}
}
EnableDisableButtons();
}
IMPL_LINK_NOARG(SdPhotoAlbumDialog, UpHdl, Button*, void)
{
if (pImagesLst->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
&& pImagesLst->GetSelectEntryPos() != 0)
{
const sal_Int32 nActPos = pImagesLst->GetSelectEntryPos();
OUString sActEntry( pImagesLst->GetEntry(nActPos) );
// actual data
OUString* pActData = static_cast<OUString*>(pImagesLst->GetEntryData(nActPos));
OUString sAct(*pActData);
OUString sUpperEntry( pImagesLst->GetEntry(nActPos - 1) );
// upper data
OUString* pUpperData = static_cast<OUString*>(pImagesLst->GetEntryData(nActPos - 1));
OUString sUpper(*pUpperData);
pImagesLst->RemoveEntry( sActEntry );
pImagesLst->RemoveEntry( sUpperEntry );
pImagesLst->InsertEntry( sActEntry, nActPos - 1 );
pImagesLst->SetEntryData( nActPos - 1, new OUString(sAct));
pImagesLst->InsertEntry( sUpperEntry, nActPos );
pImagesLst->SetEntryData( nActPos, new OUString(sUpper));
pImagesLst->SelectEntryPos(nActPos - 1);
}
EnableDisableButtons();
}
IMPL_LINK_NOARG(SdPhotoAlbumDialog, DownHdl, Button*, void)
{
const sal_Int32 nActPos = pImagesLst->GetSelectEntryPos();
if (!pImagesLst->GetEntry(nActPos + 1).isEmpty())
{
OUString sActEntry( pImagesLst->GetSelectEntry() );
OUString* pActData = static_cast<OUString*>(pImagesLst->GetSelectEntryData());
OUString sAct(*pActData);
OUString sDownEntry( pImagesLst->GetEntry(nActPos + 1) );
OUString* pDownData = static_cast<OUString*>(pImagesLst->GetEntryData(nActPos + 1));
OUString sDown(*pDownData);
pImagesLst->RemoveEntry( sActEntry );
pImagesLst->RemoveEntry( sDownEntry );
pImagesLst->InsertEntry( sDownEntry, nActPos );
pImagesLst->SetEntryData( nActPos, new OUString(sDown));
pImagesLst->InsertEntry( sActEntry, nActPos + 1 );
pImagesLst->SetEntryData( nActPos + 1, new OUString(sAct));
pImagesLst->SelectEntryPos(nActPos + 1);
}
EnableDisableButtons();
}
IMPL_LINK_NOARG(SdPhotoAlbumDialog, RemoveHdl, Button*, void)
{
pImagesLst->RemoveEntry( pImagesLst->GetSelectEntryPos() );
pImg->SetImage(Image());
EnableDisableButtons();
}
IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl, ListBox&, void)
{
OUString* pData = static_cast<OUString*>(pImagesLst->GetSelectEntryData());
OUString sImgUrl = pData ? OUString(*pData) : "";
if (sImgUrl != SD_RESSTR(STR_PHOTO_ALBUM_TEXTBOX))
{
GraphicFilter aCurFilter;
Graphic aGraphic;
INetURLObject aURLObj( sImgUrl );
sal_uInt16 nFilter = GRFILTER_FORMAT_DONTKNOW;
if ( aURLObj.HasError() || INetProtocol::NotValid == aURLObj.GetProtocol() )
{
aURLObj.SetSmartProtocol( INetProtocol::File );
aURLObj.SetSmartURL( sImgUrl );
}
GraphicFilterImportFlags nFilterImportFlags = GraphicFilterImportFlags::SetLogsizeForJpeg;
// remote?
if ( INetProtocol::File != aURLObj.GetProtocol() )
{
SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( sImgUrl, StreamMode::READ );
if( pStream )
mpGraphicFilter->ImportGraphic( aGraphic, sImgUrl, *pStream, nFilter, nullptr, nFilterImportFlags );
else
mpGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, nullptr, nFilterImportFlags );
delete pStream;
}
else
{
mpGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, nullptr, nFilterImportFlags );
}
Bitmap aBmp = aGraphic.GetBitmap();
sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
sal_Int32 nPrevWidth = 200;
sal_Int32 nPrewHeight = 150;
double nXRatio = (double) nPrevWidth / nBmpWidth;
double nYRatio = (double) nPrewHeight / nBmpHeight;
if ( nXRatio < nYRatio )
aBmp.Scale( nXRatio, nXRatio );
else
aBmp.Scale( nYRatio, nYRatio );
aBmp.Convert( BMP_CONVERSION_24BIT );
pImg->SetImage(Image(aBmp));
}
else
{
pImg->SetImage(Image());
}
EnableDisableButtons();
}
IMPL_LINK_NOARG(SdPhotoAlbumDialog, TypeSelectHdl, ListBox&, void)
{
// Enable "Fill Slide" only for one image
// If we want to have it for other images too, we need to implement the actual cropping.
bool const bEnable = pInsTypeCombo->GetSelectEntryPos() == ONE_IMAGE;
pASRCheckCrop->Enable(bEnable);
if (!bEnable)
pASRCheckCrop->Check(false);
}
Reference< drawing::XDrawPage > SdPhotoAlbumDialog::appendNewSlide(AutoLayout aLayout,
const Reference< drawing::XDrawPages >& xDrawPages
)
{
Reference< drawing::XDrawPage > xSlide; // Create the slide
Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY );
xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() );
SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PageKind::Standard)-1, PageKind::Standard);
pSlide->SetAutoLayout(aLayout, true); // Set the layout here
return xSlide;
}
awt::Size SdPhotoAlbumDialog::createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize)
{
double resizeWidth = aPicSize.Width;
double resizeHeight = aPicSize.Height;
double aspect = resizeWidth/resizeHeight;
if( resizeWidth > aMaxSize.Width )
{
resizeWidth = aMaxSize.Width;
resizeHeight = resizeWidth / aspect;
}
if( resizeHeight > aMaxSize.Height )
{
aspect = resizeWidth/resizeHeight;
resizeHeight = aMaxSize.Height;
resizeWidth = resizeHeight * aspect;
}
return awt::Size(resizeWidth, resizeHeight);
}
awt::Size SdPhotoAlbumDialog::createASRSizeCrop(const awt::Size& aPicSize, const awt::Size& aMaxSize)
{
double resizeWidth = aPicSize.Width;
double resizeHeight = aPicSize.Height;
double imgAspect = resizeWidth / resizeHeight;
double windowAspectRatio = static_cast<double>(aMaxSize.Width) / aMaxSize.Height ;
//When both sides of an image are bigger than canvas size, image would be downscaled.
if( resizeWidth > aMaxSize.Width && resizeHeight > aMaxSize.Height )
{
if( imgAspect > windowAspectRatio )
{
resizeHeight = aMaxSize.Height;
resizeWidth = aMaxSize.Height * imgAspect;
}
else
{
resizeHeight = aMaxSize.Width / imgAspect;
resizeWidth = aMaxSize.Width;
}
}
//In all other cases image is upscaled
else
{
if( imgAspect > windowAspectRatio )
{
resizeHeight = aMaxSize.Height;
resizeWidth = aMaxSize.Height * imgAspect;
}
else
{
resizeWidth = aMaxSize.Width;
resizeHeight = aMaxSize.Width / imgAspect;
}
}
return awt::Size(resizeWidth, resizeHeight);
}
void SdPhotoAlbumDialog::createCaption(const awt::Size& aPageSize )
{
Point CapPos;
Size CapSize;
CapSize.Width() = aPageSize.Width;
CapSize.Height() = aPageSize.Height/6;
CapPos.X() = 0;
CapPos.Y() = aPageSize.Height - CapSize.Height();
SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PageKind::Standard)-1, PageKind::Standard );
// try to get existing PresObj
const Rectangle rRect(CapPos,CapSize);
SdrObject* pSdrObj = pSlide->GetPresObj(PRESOBJ_TITLE);
if(!pSdrObj)
{
// if not exists, create. Beware: It is already inserted to the SdPage
pSdrObj = pSlide->CreatePresObj(PRESOBJ_TITLE,false,rRect);
}
else
{
// if exists, bring to front and position it
const size_t nObjNum(pSlide->GetObjCount());
if(nObjNum)
{
pSlide->SetObjectOrdNum(pSdrObj->GetOrdNum(), nObjNum - 1);
}
pSdrObj->SetSnapRect(rRect);
}
if(pSdrObj)
{
// set color, style and some transparency
SfxItemSet aSet(pDoc->GetItemPool() );
aSet.Put( XFillStyleItem(drawing::FillStyle_SOLID) );
aSet.Put( XFillColorItem( "", Color(COL_BLACK) ) );
aSet.Put( XFillTransparenceItem( 20 ) );
pSdrObj->SetMergedItemSetAndBroadcast(aSet);
}
}
Reference< graphic::XGraphic> SdPhotoAlbumDialog::createXGraphicFromUrl(const OUString& sUrl,
const Reference< graphic::XGraphicProvider>& xProvider
)
{
// The same as above, except this returns an XGraphic from the image URL
::comphelper::NamedValueCollection aMediaProperties;
aMediaProperties.put( "URL", OUString( sUrl ) );
Reference< graphic::XGraphic> xGraphic =
xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
return xGraphic;
}
void SdPhotoAlbumDialog::EnableDisableButtons()
{
pRemoveBtn->Enable(pImagesLst->GetSelectEntryCount() > 0);
pUpBtn->Enable(pImagesLst->GetSelectEntryCount() > 0 &&
pImagesLst->GetSelectEntryPos() != 0);
pDownBtn->Enable(pImagesLst->GetSelectEntryCount() > 0 &&
pImagesLst->GetSelectEntryPos() < pImagesLst->GetEntryCount()-1);
}
} // end of namespace sd
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|