LCOV - code coverage report
Current view: top level - sd/source/ui/dlg - sdpreslt.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 118 0.0 %
Date: 2014-11-03 Functions: 0 12 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 : }
      59             : 
      60             : /**
      61             :  *    Initialize
      62             :  */
      63           0 : void SdPresLayoutDlg::Reset()
      64             : {
      65           0 :     const SfxPoolItem *pPoolItem = NULL;
      66             :     long nName;
      67             : 
      68             :     // replace master page
      69           0 :     if( mrOutAttrs.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE, false, &pPoolItem ) == SfxItemState::SET )
      70             :     {
      71           0 :         bool bMasterPage = ( (const SfxBoolItem*) pPoolItem)->GetValue();
      72           0 :         m_pCbxMasterPage->Enable( !bMasterPage );
      73           0 :         m_pCbxMasterPage->Check( bMasterPage );
      74             :     }
      75             : 
      76             :     // remove not used master pages
      77           0 :     m_pCbxCheckMasters->Check(false);
      78             : 
      79           0 :     if(mrOutAttrs.GetItemState(ATTR_PRESLAYOUT_NAME, true, &pPoolItem) == SfxItemState::SET)
      80           0 :         maName = ((const SfxStringItem*)pPoolItem)->GetValue();
      81             :     else
      82           0 :         maName = "";
      83             : 
      84           0 :     FillValueSet();
      85             : 
      86           0 :     mnLayoutCount = maLayoutNames.size();
      87           0 :     for( nName = 0; nName < mnLayoutCount; nName++ )
      88             :     {
      89           0 :         if (maLayoutNames[nName] == maName)
      90           0 :             break;
      91             :     }
      92             :     DBG_ASSERT(nName < mnLayoutCount, "Layout not found");
      93             : 
      94           0 :     m_pVS->SelectItem((sal_uInt16)nName + 1);  // Indices of the ValueSets start at 1
      95             : 
      96           0 : }
      97             : 
      98             : /**
      99             :  * Fills the provided Item-Set with dialog box attributes
     100             :  */
     101           0 : void SdPresLayoutDlg::GetAttr(SfxItemSet& rOutAttrs)
     102             : {
     103           0 :     short nId = m_pVS->GetSelectItemId();
     104           0 :     bool bLoad = nId > mnLayoutCount;
     105           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad ) );
     106             : 
     107           0 :     OUString aLayoutName;
     108             : 
     109           0 :     if( bLoad )
     110             :     {
     111           0 :         aLayoutName = maName + "#" + maLayoutNames[ nId - 1 ];
     112             :     }
     113             :     else
     114             :     {
     115           0 :         aLayoutName = maLayoutNames[ nId - 1 ];
     116           0 :         if( aLayoutName == maStrNone )
     117           0 :             aLayoutName = ""; // that way we encode "- nothing -" (see below)
     118             :     }
     119             : 
     120           0 :     rOutAttrs.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aLayoutName ) );
     121           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, m_pCbxMasterPage->IsChecked() ) );
     122           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, m_pCbxCheckMasters->IsChecked() ) );
     123           0 : }
     124             : 
     125             : /**
     126             :  * Fills ValueSet with bitmaps
     127             :  */
     128           0 : void SdPresLayoutDlg::FillValueSet()
     129             : {
     130           0 :     m_pVS->SetStyle(m_pVS->GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER
     131           0 :                                       | WB_VSCROLL | WB_NAMEFIELD);
     132             : 
     133           0 :     m_pVS->SetColCount(2);
     134           0 :     m_pVS->SetLineCount(2);
     135           0 :     m_pVS->SetExtraSpacing(2);
     136             : 
     137           0 :     SdDrawDocument* pDoc = mpDocSh->GetDoc();
     138             : 
     139           0 :     sal_uInt16 nCount = pDoc->GetMasterPageCount();
     140             : 
     141           0 :     for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
     142             :     {
     143           0 :         SdPage* pMaster = (SdPage*)pDoc->GetMasterPage(nLayout);
     144           0 :         if (pMaster->GetPageKind() == PK_STANDARD)
     145             :         {
     146           0 :             OUString aLayoutName(pMaster->GetLayoutName());
     147           0 :             aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
     148           0 :             maLayoutNames.push_back(aLayoutName);
     149             : 
     150           0 :             Image aBitmap(Bitmap(mpDocSh->GetPagePreviewBitmap(pMaster, 90)));
     151           0 :             m_pVS->InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
     152             :         }
     153             :     }
     154             : 
     155           0 :     m_pVS->Show();
     156           0 : }
     157             : 
     158             : /**
     159             :  * DoubleClick handler
     160             :  */
     161           0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLayoutHdl)
     162             : {
     163           0 :     EndDialog(RET_OK);
     164           0 :     return 0;
     165             : }
     166             : 
     167             : /**
     168             :  * Click handler for load button
     169             :  */
     170           0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLoadHdl)
     171             : {
     172           0 :     boost::scoped_ptr<SfxNewFileDialog> pDlg(new SfxNewFileDialog(this, SFXWB_PREVIEW));
     173           0 :     pDlg->SetText(SD_RESSTR(STR_LOAD_PRESENTATION_LAYOUT));
     174             : 
     175           0 :     if(!IsReallyVisible())
     176           0 :         return 0;
     177             : 
     178           0 :     sal_uInt16 nResult = pDlg->Execute();
     179             :     // Inserted update to force repaint
     180           0 :     Update();
     181             : 
     182           0 :     bool   bCancel = false;
     183             : 
     184           0 :     switch (nResult)
     185             :     {
     186             :         case RET_OK:
     187             :         {
     188           0 :             if (pDlg->IsTemplate())
     189             :             {
     190           0 :                 maName = pDlg->GetTemplateFileName();
     191             :             }
     192             :             else
     193             :             {
     194             :                 // that way we encode "- nothing -"
     195           0 :                 maName = "";
     196             :             }
     197             :         }
     198           0 :         break;
     199             : 
     200             :         default:
     201           0 :             bCancel = true;
     202             :     }
     203           0 :     pDlg.reset();
     204             : 
     205           0 :     if( !bCancel )
     206             :     {
     207             :         // check if template already exists
     208           0 :         bool bExists = false;
     209           0 :         OUString aCompareStr(maName);
     210           0 :         if (aCompareStr.isEmpty())
     211           0 :             aCompareStr = maStrNone;
     212             : 
     213           0 :         sal_uInt16 aPos = 0;
     214           0 :         for (std::vector<OUString>::iterator it = maLayoutNames.begin();
     215           0 :                   it != maLayoutNames.end() && !bExists; ++it, ++aPos)
     216             :         {
     217           0 :             if( aCompareStr == *it )
     218             :             {
     219           0 :                 bExists = true;
     220             :                 // select template
     221           0 :                 m_pVS->SelectItem( aPos + 1 );
     222             :             }
     223             :         }
     224             : 
     225           0 :         if( !bExists )
     226             :         {
     227             :             // load document in order to determine preview bitmap (if template is selected)
     228           0 :             if (!maName.isEmpty())
     229             :             {
     230             :                 // determine document in order to call OpenBookmarkDoc
     231           0 :                 SdDrawDocument* pDoc = mpDocSh->GetDoc();
     232           0 :                 SdDrawDocument* pTemplDoc  = pDoc->OpenBookmarkDoc( maName );
     233             : 
     234           0 :                 if (pTemplDoc)
     235             :                 {
     236           0 :                     ::sd::DrawDocShell*  pTemplDocSh= pTemplDoc->GetDocSh();
     237             : 
     238           0 :                     sal_uInt16 nCount = pTemplDoc->GetMasterPageCount();
     239             : 
     240           0 :                     for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
     241             :                     {
     242           0 :                         SdPage* pMaster = (SdPage*) pTemplDoc->GetMasterPage(nLayout);
     243           0 :                         if (pMaster->GetPageKind() == PK_STANDARD)
     244             :                         {
     245           0 :                             OUString aLayoutName(pMaster->GetLayoutName());
     246           0 :                             aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
     247           0 :                             maLayoutNames.push_back(aLayoutName);
     248             : 
     249           0 :                             Image aBitmap(Bitmap(pTemplDocSh->GetPagePreviewBitmap(pMaster, 90)));
     250           0 :                             m_pVS->InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
     251             :                         }
     252             :                     }
     253             :                 }
     254             :                 else
     255             :                 {
     256           0 :                     bCancel = true;
     257             :                 }
     258             : 
     259           0 :                 pDoc->CloseBookmarkDoc();
     260             :             }
     261             :             else
     262             :             {
     263             :                 // empty layout
     264           0 :                 maLayoutNames.push_back(maStrNone);
     265           0 :                 m_pVS->InsertItem( (sal_uInt16) maLayoutNames.size(),
     266           0 :                         Image(Bitmap(SdResId(BMP_FOIL_NONE))), maStrNone );
     267             :             }
     268             : 
     269           0 :             if (!bCancel)
     270             :             {
     271             :                 // select template
     272           0 :                 m_pVS->SelectItem( (sal_uInt16) maLayoutNames.size() );
     273             :             }
     274           0 :         }
     275             :     }
     276             : 
     277           0 :     return( 0 );
     278           0 : }
     279             : 
     280             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10