LCOV - code coverage report
Current view: top level - sd/source/ui/dlg - sdpreslt.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 126 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 13 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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <svl/itemset.hxx>
      21             : #include <sfx2/new.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : 
      24             : #include "strings.hrc"
      25             : #include "res_bmp.hrc"
      26             : #include "sdpreslt.hxx"
      27             : #include "sdattr.hxx"
      28             : #include "sdresid.hxx"
      29             : #include "drawdoc.hxx"
      30             : #include "sdpage.hxx"
      31             : #include "DrawDocShell.hxx"
      32             : #include <boost/scoped_ptr.hpp>
      33             : 
      34           0 : SdPresLayoutDlg::SdPresLayoutDlg(::sd::DrawDocShell* pDocShell,
      35             :     vcl::Window* pWindow, const SfxItemSet& rInAttrs)
      36             :     : ModalDialog(pWindow, "SlideDesignDialog",
      37             :         "modules/simpress/ui/slidedesigndialog.ui")
      38             :     , mpDocSh(pDocShell)
      39             :     , mrOutAttrs(rInAttrs)
      40           0 :     , maStrNone(SD_RESSTR(STR_NULL))
      41             : {
      42           0 :     get(m_pVS, "select");
      43           0 :     Size aPref(LogicToPixel(Size(144 , 141), MAP_APPFONT));
      44           0 :     m_pVS->set_width_request(aPref.Width());
      45           0 :     m_pVS->set_height_request(aPref.Height());
      46           0 :     get(m_pCbxMasterPage, "masterpage");
      47           0 :     get(m_pCbxCheckMasters, "checkmasters");
      48           0 :     get(m_pBtnLoad, "load");
      49             : 
      50           0 :     m_pVS->SetDoubleClickHdl(LINK(this, SdPresLayoutDlg, ClickLayoutHdl));
      51           0 :     m_pBtnLoad->SetClickHdl(LINK(this, SdPresLayoutDlg, ClickLoadHdl));
      52             : 
      53           0 :     Reset();
      54           0 : }
      55             : 
      56           0 : SdPresLayoutDlg::~SdPresLayoutDlg()
      57             : {
      58           0 :     disposeOnce();
      59           0 : }
      60             : 
      61           0 : void SdPresLayoutDlg::dispose()
      62             : {
      63           0 :     m_pVS.clear();
      64           0 :     m_pCbxMasterPage.clear();
      65           0 :     m_pCbxCheckMasters.clear();
      66           0 :     m_pBtnLoad.clear();
      67           0 :     ModalDialog::dispose();
      68           0 : }
      69             : 
      70             : /**
      71             :  *    Initialize
      72             :  */
      73           0 : void SdPresLayoutDlg::Reset()
      74             : {
      75           0 :     const SfxPoolItem *pPoolItem = NULL;
      76             :     long nName;
      77             : 
      78             :     // replace master page
      79           0 :     if( mrOutAttrs.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE, false, &pPoolItem ) == SfxItemState::SET )
      80             :     {
      81           0 :         bool bMasterPage = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
      82           0 :         m_pCbxMasterPage->Enable( !bMasterPage );
      83           0 :         m_pCbxMasterPage->Check( bMasterPage );
      84             :     }
      85             : 
      86             :     // remove not used master pages
      87           0 :     m_pCbxCheckMasters->Check(false);
      88             : 
      89           0 :     if(mrOutAttrs.GetItemState(ATTR_PRESLAYOUT_NAME, true, &pPoolItem) == SfxItemState::SET)
      90           0 :         maName = static_cast<const SfxStringItem*>(pPoolItem)->GetValue();
      91             :     else
      92           0 :         maName.clear();
      93             : 
      94           0 :     FillValueSet();
      95             : 
      96           0 :     mnLayoutCount = maLayoutNames.size();
      97           0 :     for( nName = 0; nName < mnLayoutCount; nName++ )
      98             :     {
      99           0 :         if (maLayoutNames[nName] == maName)
     100           0 :             break;
     101             :     }
     102             :     DBG_ASSERT(nName < mnLayoutCount, "Layout not found");
     103             : 
     104           0 :     m_pVS->SelectItem((sal_uInt16)nName + 1);  // Indices of the ValueSets start at 1
     105             : 
     106           0 : }
     107             : 
     108             : /**
     109             :  * Fills the provided Item-Set with dialog box attributes
     110             :  */
     111           0 : void SdPresLayoutDlg::GetAttr(SfxItemSet& rOutAttrs)
     112             : {
     113           0 :     short nId = m_pVS->GetSelectItemId();
     114           0 :     bool bLoad = nId > mnLayoutCount;
     115           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad ) );
     116             : 
     117           0 :     OUString aLayoutName;
     118             : 
     119           0 :     if( bLoad )
     120             :     {
     121           0 :         aLayoutName = maName + "#" + maLayoutNames[ nId - 1 ];
     122             :     }
     123             :     else
     124             :     {
     125           0 :         aLayoutName = maLayoutNames[ nId - 1 ];
     126           0 :         if( aLayoutName == maStrNone )
     127           0 :             aLayoutName.clear(); // that way we encode "- nothing -" (see below)
     128             :     }
     129             : 
     130           0 :     rOutAttrs.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aLayoutName ) );
     131           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, m_pCbxMasterPage->IsChecked() ) );
     132           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, m_pCbxCheckMasters->IsChecked() ) );
     133           0 : }
     134             : 
     135             : /**
     136             :  * Fills ValueSet with bitmaps
     137             :  */
     138           0 : void SdPresLayoutDlg::FillValueSet()
     139             : {
     140           0 :     m_pVS->SetStyle(m_pVS->GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER
     141           0 :                                       | WB_VSCROLL | WB_NAMEFIELD);
     142             : 
     143           0 :     m_pVS->SetColCount(2);
     144           0 :     m_pVS->SetLineCount(2);
     145           0 :     m_pVS->SetExtraSpacing(2);
     146             : 
     147           0 :     SdDrawDocument* pDoc = mpDocSh->GetDoc();
     148             : 
     149           0 :     sal_uInt16 nCount = pDoc->GetMasterPageCount();
     150             : 
     151           0 :     for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
     152             :     {
     153           0 :         SdPage* pMaster = static_cast<SdPage*>(pDoc->GetMasterPage(nLayout));
     154           0 :         if (pMaster->GetPageKind() == PK_STANDARD)
     155             :         {
     156           0 :             OUString aLayoutName(pMaster->GetLayoutName());
     157           0 :             aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
     158           0 :             maLayoutNames.push_back(aLayoutName);
     159             : 
     160           0 :             Image aBitmap(Bitmap(mpDocSh->GetPagePreviewBitmap(pMaster, 90)));
     161           0 :             m_pVS->InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
     162             :         }
     163             :     }
     164             : 
     165           0 :     m_pVS->Show();
     166           0 : }
     167             : 
     168             : /**
     169             :  * DoubleClick handler
     170             :  */
     171           0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLayoutHdl)
     172             : {
     173           0 :     EndDialog(RET_OK);
     174           0 :     return 0;
     175             : }
     176             : 
     177             : /**
     178             :  * Click handler for load button
     179             :  */
     180           0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLoadHdl)
     181             : {
     182           0 :     VclPtrInstance< SfxNewFileDialog > pDlg(this, SFXWB_PREVIEW);
     183           0 :     pDlg->SetText(SD_RESSTR(STR_LOAD_PRESENTATION_LAYOUT));
     184             : 
     185           0 :     if(!IsReallyVisible())
     186           0 :         return 0;
     187             : 
     188           0 :     sal_uInt16 nResult = pDlg->Execute();
     189             :     // Inserted update to force repaint
     190           0 :     Update();
     191             : 
     192           0 :     bool   bCancel = false;
     193             : 
     194           0 :     switch (nResult)
     195             :     {
     196             :         case RET_OK:
     197             :         {
     198           0 :             if (pDlg->IsTemplate())
     199             :             {
     200           0 :                 maName = pDlg->GetTemplateFileName();
     201             :             }
     202             :             else
     203             :             {
     204             :                 // that way we encode "- nothing -"
     205           0 :                 maName.clear();
     206             :             }
     207             :         }
     208           0 :         break;
     209             : 
     210             :         default:
     211           0 :             bCancel = true;
     212             :     }
     213           0 :     pDlg.reset();
     214             : 
     215           0 :     if( !bCancel )
     216             :     {
     217             :         // check if template already exists
     218           0 :         bool bExists = false;
     219           0 :         OUString aCompareStr(maName);
     220           0 :         if (aCompareStr.isEmpty())
     221           0 :             aCompareStr = maStrNone;
     222             : 
     223           0 :         sal_uInt16 aPos = 0;
     224           0 :         for (std::vector<OUString>::iterator it = maLayoutNames.begin();
     225           0 :                   it != maLayoutNames.end() && !bExists; ++it, ++aPos)
     226             :         {
     227           0 :             if( aCompareStr == *it )
     228             :             {
     229           0 :                 bExists = true;
     230             :                 // select template
     231           0 :                 m_pVS->SelectItem( aPos + 1 );
     232             :             }
     233             :         }
     234             : 
     235           0 :         if( !bExists )
     236             :         {
     237             :             // load document in order to determine preview bitmap (if template is selected)
     238           0 :             if (!maName.isEmpty())
     239             :             {
     240             :                 // determine document in order to call OpenBookmarkDoc
     241           0 :                 SdDrawDocument* pDoc = mpDocSh->GetDoc();
     242           0 :                 SdDrawDocument* pTemplDoc  = pDoc->OpenBookmarkDoc( maName );
     243             : 
     244           0 :                 if (pTemplDoc)
     245             :                 {
     246           0 :                     ::sd::DrawDocShell*  pTemplDocSh= pTemplDoc->GetDocSh();
     247             : 
     248           0 :                     sal_uInt16 nCount = pTemplDoc->GetMasterPageCount();
     249             : 
     250           0 :                     for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
     251             :                     {
     252           0 :                         SdPage* pMaster = static_cast<SdPage*>( pTemplDoc->GetMasterPage(nLayout) );
     253           0 :                         if (pMaster->GetPageKind() == PK_STANDARD)
     254             :                         {
     255           0 :                             OUString aLayoutName(pMaster->GetLayoutName());
     256           0 :                             aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
     257           0 :                             maLayoutNames.push_back(aLayoutName);
     258             : 
     259           0 :                             Image aBitmap(Bitmap(pTemplDocSh->GetPagePreviewBitmap(pMaster, 90)));
     260           0 :                             m_pVS->InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
     261             :                         }
     262             :                     }
     263             :                 }
     264             :                 else
     265             :                 {
     266           0 :                     bCancel = true;
     267             :                 }
     268             : 
     269           0 :                 pDoc->CloseBookmarkDoc();
     270             :             }
     271             :             else
     272             :             {
     273             :                 // empty layout
     274           0 :                 maLayoutNames.push_back(maStrNone);
     275           0 :                 m_pVS->InsertItem( (sal_uInt16) maLayoutNames.size(),
     276           0 :                         Image(Bitmap(SdResId(BMP_FOIL_NONE))), maStrNone );
     277             :             }
     278             : 
     279           0 :             if (!bCancel)
     280             :             {
     281             :                 // select template
     282           0 :                 m_pVS->SelectItem( (sal_uInt16) maLayoutNames.size() );
     283             :             }
     284           0 :         }
     285             :     }
     286             : 
     287           0 :     return 0;
     288           0 : }
     289             : 
     290             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11