LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/dlg - PhotoAlbumDialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 380 0.0 %
Date: 2013-07-09 Functions: 0 25 0.0 %
Legend: Lines: hit not hit

          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             : #include <comphelper/configurationhelper.hxx>
      13             : 
      14             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      15             : #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
      16             : #include <com/sun/star/container/XNameAccess.hpp>
      17             : 
      18             : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
      19             : #include <com/sun/star/text/XText.hpp>
      20             : 
      21             : #include <sfx2/filedlghelper.hxx>
      22             : #include <tools/urlobj.hxx>
      23             : 
      24             : #include <unotools/pathoptions.hxx>
      25             : #include <unotools/useroptions.hxx>
      26             : #include <unotools/ucbstreamhelper.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(".");
     458           0 :     Reference< XInterface > xCfg;
     459             :     try
     460             :     {
     461           0 :         xCfg = ::comphelper::ConfigurationHelper::openConfig(
     462             :             ::comphelper::getProcessComponentContext(),
     463             :             OUString("/org.openoffice.Office.Impress/"),
     464           0 :             ::comphelper::ConfigurationHelper::E_READONLY);
     465             : 
     466             :         ::comphelper::ConfigurationHelper::readRelativeKey(
     467             :             xCfg,
     468             :             OUString("Pictures"),
     469           0 :             OUString("Path")) >>= sUrl;
     470             :     }
     471           0 :     catch(const Exception&)
     472             :     {
     473             :         OSL_FAIL("Could not find config for Create Photo Album function");
     474             :     }
     475             : 
     476             : 
     477           0 :     INetURLObject aFile( SvtPathOptions().GetPalettePath() );
     478           0 :     if (sUrl != "")
     479           0 :         aDlg.SetDisplayDirectory(sUrl);
     480             :     else
     481           0 :         aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
     482             : 
     483           0 :     if ( aDlg.Execute() == ERRCODE_NONE )
     484             :     {
     485           0 :         Sequence< OUString > aFilesArr = aDlg.GetSelectedFiles();
     486           0 :         if( aFilesArr.getLength() )
     487             :         {
     488           0 :             sUrl = aDlg.GetDisplayDirectory();
     489             :             // Write out configuration
     490             :             try
     491             :             {
     492           0 :                 xCfg = ::comphelper::ConfigurationHelper::openConfig(
     493             :                     ::comphelper::getProcessComponentContext(),
     494             :                     OUString("/org.openoffice.Office.Impress/"),
     495           0 :                     ::comphelper::ConfigurationHelper::E_STANDARD);
     496             : 
     497             :                 ::comphelper::ConfigurationHelper::writeRelativeKey(
     498             :                     xCfg,
     499             :                     OUString("Pictures"),
     500             :                     OUString("Path"),
     501           0 :                     uno::makeAny(sUrl));
     502             : 
     503           0 :                 ::comphelper::ConfigurationHelper::flush(xCfg);
     504             :             }
     505           0 :             catch(const Exception&)
     506             :             {
     507             :                 OSL_FAIL("Could not find config for Create Photo Album function");
     508             :             }
     509             : 
     510           0 :             for ( sal_Int32 i = 0; i < aFilesArr.getLength(); i++ )
     511             :             {
     512             :                 // Store full path, show filename only. Use INetURLObject to display spaces in filename correctly
     513           0 :                 INetURLObject aUrl = INetURLObject(aFilesArr[i]);
     514           0 :                 sal_Int16 nPos = pImagesLst->InsertEntry( aUrl.GetLastName(INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8) );
     515           0 :                 pImagesLst->SetEntryData(nPos, (OUString*) new OUString(aUrl.GetMainURL(INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8)));
     516           0 :             }
     517           0 :         }
     518             :     }
     519           0 :     EnableDisableButtons();
     520           0 :     return 0;
     521             : }
     522             : 
     523           0 : IMPL_LINK_NOARG(SdPhotoAlbumDialog, UpHdl)
     524             : {
     525           0 :     if (pImagesLst->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
     526           0 :         && pImagesLst->GetSelectEntryPos() != 0)
     527             :     {
     528           0 :         sal_uInt16 nActPos = pImagesLst->GetSelectEntryPos();
     529           0 :         OUString sActEntry( pImagesLst->GetEntry(nActPos) );
     530             :         // actual data
     531           0 :         OUString* pActData = (OUString*) pImagesLst->GetEntryData(nActPos);
     532           0 :         OUString sAct(*pActData);
     533             : 
     534           0 :         OUString sUpperEntry( pImagesLst->GetEntry(nActPos - 1) );
     535             :         // upper data
     536           0 :         OUString* pUpperData = (OUString*) pImagesLst->GetEntryData(nActPos - 1);
     537           0 :         OUString sUpper(*pUpperData);
     538             : 
     539           0 :         pImagesLst->RemoveEntry( sActEntry );
     540           0 :         pImagesLst->RemoveEntry( sUpperEntry );
     541             : 
     542           0 :         pImagesLst->InsertEntry( sActEntry, nActPos - 1 );
     543           0 :         pImagesLst->SetEntryData( nActPos - 1, (void*) new OUString(sAct));
     544             : 
     545           0 :         pImagesLst->InsertEntry( sUpperEntry, nActPos );
     546           0 :         pImagesLst->SetEntryData( nActPos, (void*) new OUString(sUpper));
     547             : 
     548           0 :         pImagesLst->SelectEntryPos(nActPos - 1);
     549             :     }
     550             : 
     551           0 :     EnableDisableButtons();
     552           0 :     return 0;
     553             : }
     554             : 
     555           0 : IMPL_LINK_NOARG(SdPhotoAlbumDialog, DownHdl)
     556             : {
     557           0 :     sal_uInt16 nActPos = pImagesLst->GetSelectEntryPos();
     558           0 :     if (pImagesLst->GetEntry(nActPos + 1) != OUString("") )
     559             :     {
     560           0 :         OUString sActEntry( pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos()) );
     561           0 :         OUString* pActData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos());
     562           0 :         OUString sAct(*pActData);
     563             : 
     564           0 :         OUString sDownEntry( pImagesLst->GetEntry(nActPos + 1) );
     565           0 :         OUString* pDownData = (OUString*) pImagesLst->GetEntryData(nActPos + 1);
     566           0 :         OUString sDown(*pDownData);
     567             : 
     568           0 :         pImagesLst->RemoveEntry( sActEntry );
     569           0 :         pImagesLst->RemoveEntry( sDownEntry );
     570             : 
     571           0 :         pImagesLst->InsertEntry( sDownEntry, nActPos );
     572           0 :         pImagesLst->SetEntryData( nActPos, (void*) new OUString(sDown));
     573             : 
     574           0 :         pImagesLst->InsertEntry( sActEntry, nActPos + 1 );
     575           0 :         pImagesLst->SetEntryData( nActPos + 1, (void*) new OUString(sAct));
     576             : 
     577           0 :         pImagesLst->SelectEntryPos(nActPos + 1);
     578             : 
     579             :     }
     580           0 :     EnableDisableButtons();
     581           0 :     return 0;
     582             : }
     583             : 
     584           0 : IMPL_LINK_NOARG(SdPhotoAlbumDialog, RemoveHdl)
     585             : {
     586           0 :     pImagesLst->RemoveEntry( pImagesLst->GetSelectEntryPos() );
     587           0 :     pImg->SetImage(Image());
     588             : 
     589           0 :     EnableDisableButtons();
     590           0 :     return 0;
     591             : }
     592             : 
     593           0 : IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl)
     594             : {
     595           0 :     OUString* pData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos());
     596           0 :     OUString sImgUrl = pData ? OUString(*pData) : "";
     597             : 
     598           0 :     if (sImgUrl != SD_RESSTR(STR_PHOTO_ALBUM_TEXTBOX))
     599             :     {
     600           0 :         GraphicFilter aCurFilter;
     601           0 :         Graphic aGraphic;
     602           0 :         INetURLObject aURLObj( sImgUrl );
     603             : 
     604           0 :         sal_uInt16 nFilter = GRFILTER_FORMAT_DONTKNOW;
     605             : 
     606           0 :         if ( aURLObj.HasError() || INET_PROT_NOT_VALID == aURLObj.GetProtocol() )
     607             :         {
     608           0 :             aURLObj.SetSmartProtocol( INET_PROT_FILE );
     609           0 :             aURLObj.SetSmartURL( sImgUrl );
     610             :         }
     611             : 
     612           0 :         sal_uInt32 nFilterImportFlags = GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG;
     613             :         // remote?
     614           0 :         if ( INET_PROT_FILE != aURLObj.GetProtocol() )
     615             :         {
     616           0 :             SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( sImgUrl, STREAM_READ );
     617             : 
     618           0 :             if( pStream )
     619           0 :                 mpGraphicFilter->ImportGraphic( aGraphic, sImgUrl, *pStream, nFilter, NULL, nFilterImportFlags );
     620             :             else
     621           0 :                 mpGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
     622           0 :             delete pStream;
     623             :         }
     624             :         else
     625             :         {
     626           0 :             mpGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
     627             :         }
     628             : 
     629           0 :         Bitmap aBmp = aGraphic.GetBitmap();
     630           0 :         sal_Int32 nBmpWidth  = aBmp.GetSizePixel().Width();
     631           0 :         sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
     632           0 :         sal_Int32 nPrevWidth = 200;
     633           0 :         sal_Int32 nPrewHeight = 150;
     634             : 
     635           0 :         double nXRatio = (double) nPrevWidth / nBmpWidth;
     636           0 :         double nYRatio = (double) nPrewHeight / nBmpHeight;
     637           0 :         if ( nXRatio < nYRatio )
     638           0 :             aBmp.Scale( nXRatio, nXRatio );
     639             :         else
     640           0 :             aBmp.Scale( nYRatio, nYRatio );
     641             : 
     642           0 :         aBmp.Convert( BMP_CONVERSION_24BIT );
     643           0 :         pImg->SetImage( aBmp );
     644             :     }
     645             :     else
     646             :     {
     647           0 :         pImg->SetImage(Image());
     648             :     }
     649           0 :     EnableDisableButtons();
     650           0 :     return 0;
     651             : }
     652             : 
     653           0 : Reference< drawing::XDrawPage > SdPhotoAlbumDialog::appendNewSlide(AutoLayout aLayout,
     654             :     Reference< drawing::XDrawPages > xDrawPages
     655             : )
     656             : {
     657           0 :     Reference< drawing::XDrawPage > xSlide; // Create the slide
     658           0 :     Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY );
     659           0 :     xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() );
     660           0 :     SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD);
     661           0 :     pSlide->SetAutoLayout(aLayout, sal_True); // Set the layout here
     662           0 :     return xSlide;
     663             : }
     664             : 
     665           0 : awt::Size SdPhotoAlbumDialog::createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize)
     666             : {
     667           0 :     double resizeWidth = aPicSize.Width;
     668           0 :     double resizeHeight = aPicSize.Height;
     669           0 :     double aspect = resizeWidth/resizeHeight;
     670             : 
     671           0 :     if( resizeWidth > aMaxSize.Width )
     672             :     {
     673           0 :         resizeWidth = aMaxSize.Width;
     674           0 :         resizeHeight = resizeWidth / aspect;
     675             :     }
     676             : 
     677           0 :     if( resizeHeight > aMaxSize.Height )
     678             :     {
     679           0 :         aspect = resizeWidth/resizeHeight;
     680           0 :         resizeHeight = aMaxSize.Height;
     681           0 :         resizeWidth = resizeHeight * aspect;
     682             :     }
     683           0 :     return awt::Size(resizeWidth, resizeHeight);
     684             : }
     685             : 
     686           0 : Reference< drawing::XShape > SdPhotoAlbumDialog::createXShapeFromUrl(const OUString& sUrl,
     687             :     Reference< lang::XMultiServiceFactory > xShapeFactory,
     688             :     Reference< graphic::XGraphicProvider> xProvider
     689             : )
     690             : {
     691             :     //First, we create an XGraphic
     692           0 :     ::comphelper::NamedValueCollection aMediaProperties;
     693           0 :     aMediaProperties.put( "URL", OUString( sUrl ) );
     694             :     Reference< graphic::XGraphic> xGraphic =
     695           0 :         xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
     696             :     //And then, we can create the XShape from the XGraphic
     697             :     Reference< drawing::XShape > xShape(
     698           0 :         xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
     699             :         uno::UNO_QUERY
     700           0 :     );
     701             : 
     702           0 :     Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
     703           0 :     xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
     704             : 
     705           0 :     return xShape; // Image loaded into XShape
     706             : }
     707             : 
     708           0 : Reference< graphic::XGraphic> SdPhotoAlbumDialog::createXGraphicFromUrl(const OUString& sUrl,
     709             :     Reference< graphic::XGraphicProvider> xProvider
     710             : )
     711             : {
     712             :     // The same as above, except this returns an XGraphic from the image URL
     713           0 :     ::comphelper::NamedValueCollection aMediaProperties;
     714           0 :     aMediaProperties.put( "URL", OUString( sUrl ) );
     715             :     Reference< graphic::XGraphic> xGraphic =
     716           0 :         xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
     717           0 :     return xGraphic;
     718             : }
     719             : 
     720           0 : short SdPhotoAlbumDialog::Execute()
     721             : {
     722           0 :     return ModalDialog::Execute();
     723             : }
     724             : 
     725           0 : void SdPhotoAlbumDialog::EnableDisableButtons()
     726             : {
     727           0 :     pRemoveBtn->Enable(pImagesLst->GetSelectEntryCount() > 0);
     728           0 :     pUpBtn->Enable(pImagesLst->GetSelectEntryCount() > 0 &&
     729           0 :                    pImagesLst->GetSelectEntryPos() != 0);
     730           0 :     pDownBtn->Enable(pImagesLst->GetSelectEntryCount() > 0 &&
     731           0 :                      pImagesLst->GetSelectEntryPos() < pImagesLst->GetEntryCount()-1);
     732           0 : }
     733             : 
     734             : 
     735           0 : } // end of namespace sd
     736             : 
     737             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10