LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/dlg - sdpreslt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 115 0.0 %
Date: 2013-07-09 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 "sdpreslt.hrc"
      28             : #include "sdattr.hxx"
      29             : #include "sdresid.hxx"
      30             : #include "drawdoc.hxx"
      31             : #include "sdpage.hxx"
      32             : #include "DrawDocShell.hxx"
      33             : 
      34             : #define DOCUMENT_TOKEN (sal_Unicode('#'))
      35             : 
      36           0 : SdPresLayoutDlg::SdPresLayoutDlg(
      37             :     ::sd::DrawDocShell* pDocShell,
      38             :     ::Window* pWindow,
      39             :     const SfxItemSet& rInAttrs ):
      40             :                 ModalDialog         (pWindow, SdResId(DLG_PRESLT)),
      41             :                 mpDocSh              ( pDocShell ),
      42             :                 maFtLayout           (this, SdResId(FT_LAYOUT)),
      43             :                 maVS                 (this, SdResId(VS_LAYOUT)),
      44             :                 maBtnOK              (this, SdResId(BTN_OK)),
      45             :                 maBtnCancel          (this, SdResId(BTN_CANCEL)),
      46             :                 maBtnHelp            (this, SdResId(BTN_HELP)),
      47             :                 maCbxMasterPage     (this, SdResId(CBX_MASTER_PAGE)),
      48             :                 maCbxCheckMasters   (this, SdResId(CBX_CHECK_MASTERS)),
      49             :                 maBtnLoad            (this, SdResId(BTN_LOAD)),
      50             :                 mrOutAttrs           (rInAttrs),
      51           0 :                 maStrNone           ( SdResId( STR_NULL ) )
      52             : {
      53           0 :     FreeResource();
      54             : 
      55           0 :     maVS.SetDoubleClickHdl(LINK(this, SdPresLayoutDlg, ClickLayoutHdl));
      56           0 :     maBtnLoad.SetClickHdl(LINK(this, SdPresLayoutDlg, ClickLoadHdl));
      57             : 
      58           0 :     Reset();
      59           0 : }
      60             : 
      61           0 : SdPresLayoutDlg::~SdPresLayoutDlg()
      62             : {
      63           0 : }
      64             : 
      65             : /**
      66             :  *    Initialize
      67             :  */
      68           0 : void SdPresLayoutDlg::Reset()
      69             : {
      70           0 :     const SfxPoolItem *pPoolItem = NULL;
      71             :     long nName;
      72             : 
      73             :     // replace master page
      74           0 :     if( mrOutAttrs.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE, sal_False, &pPoolItem ) == SFX_ITEM_SET )
      75             :     {
      76           0 :         sal_Bool bMasterPage = ( (const SfxBoolItem*) pPoolItem)->GetValue();
      77           0 :         maCbxMasterPage.Enable( !bMasterPage );
      78           0 :         maCbxMasterPage.Check( bMasterPage );
      79             :     }
      80             : 
      81             :     // remove not used master pages
      82           0 :     maCbxCheckMasters.Check(sal_False);
      83             : 
      84           0 :     if(mrOutAttrs.GetItemState(ATTR_PRESLAYOUT_NAME, sal_True, &pPoolItem) == SFX_ITEM_SET)
      85           0 :         maName = ((const SfxStringItem*)pPoolItem)->GetValue();
      86             :     else
      87           0 :         maName.Erase();
      88             : 
      89           0 :     FillValueSet();
      90             : 
      91           0 :     mnLayoutCount = maLayoutNames.size();
      92           0 :     for( nName = 0; nName < mnLayoutCount; nName++ )
      93             :     {
      94           0 :         if (maLayoutNames[nName] == maName)
      95           0 :             break;
      96             :     }
      97             :     DBG_ASSERT(nName < mnLayoutCount, "Layout not found");
      98             : 
      99           0 :     maVS.SelectItem((sal_uInt16)nName + 1);  // Indices of the ValueSets start at 1
     100             : 
     101           0 : }
     102             : 
     103             : /**
     104             :  * Fills the provided Item-Set with dialog box attributes
     105             :  */
     106           0 : void SdPresLayoutDlg::GetAttr(SfxItemSet& rOutAttrs)
     107             : {
     108           0 :     short nId = maVS.GetSelectItemId();
     109           0 :     sal_Bool bLoad = nId > mnLayoutCount;
     110           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad ) );
     111             : 
     112           0 :     String aLayoutName;
     113             : 
     114           0 :     if( bLoad )
     115             :     {
     116           0 :         aLayoutName = maName;
     117           0 :         aLayoutName.Append( DOCUMENT_TOKEN );
     118           0 :         aLayoutName.Append( maLayoutNames[ nId - 1 ] );
     119             :     }
     120             :     else
     121             :     {
     122           0 :         aLayoutName = maLayoutNames[ nId - 1 ];
     123           0 :         if( aLayoutName == maStrNone )
     124           0 :             aLayoutName.Erase(); // that way we encode "- nothing -" (see below)
     125             :     }
     126             : 
     127           0 :     rOutAttrs.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aLayoutName ) );
     128           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, maCbxMasterPage.IsChecked() ) );
     129           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, maCbxCheckMasters.IsChecked() ) );
     130           0 : }
     131             : 
     132             : 
     133             : /**
     134             :  * Fills ValueSet with bitmaps
     135             :  */
     136           0 : void SdPresLayoutDlg::FillValueSet()
     137             : {
     138           0 :     maVS.SetStyle(maVS.GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER
     139           0 :                                       | WB_VSCROLL | WB_NAMEFIELD);
     140             : 
     141           0 :     maVS.SetColCount(2);
     142           0 :     maVS.SetLineCount(2);
     143           0 :     maVS.SetExtraSpacing(2);
     144             : 
     145           0 :     SdDrawDocument* pDoc = mpDocSh->GetDoc();
     146             : 
     147           0 :     sal_uInt16 nCount = pDoc->GetMasterPageCount();
     148             : 
     149           0 :     for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
     150             :     {
     151           0 :         SdPage* pMaster = (SdPage*)pDoc->GetMasterPage(nLayout);
     152           0 :         if (pMaster->GetPageKind() == PK_STANDARD)
     153             :         {
     154           0 :             String aLayoutName(pMaster->GetLayoutName());
     155           0 :             aLayoutName.Erase( aLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
     156           0 :             maLayoutNames.push_back(new String(aLayoutName));
     157             : 
     158           0 :             Bitmap aBitmap(mpDocSh->GetPagePreviewBitmap(pMaster, 90));
     159           0 :             maVS.InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
     160             :         }
     161             :     }
     162             : 
     163           0 :     maVS.Show();
     164           0 : }
     165             : 
     166             : 
     167             : /**
     168             :  * DoubleClick handler
     169             :  */
     170           0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLayoutHdl)
     171             : {
     172           0 :     EndDialog(RET_OK);
     173           0 :     return 0;
     174             : }
     175             : 
     176             : /**
     177             :  * Click handler for load button
     178             :  */
     179           0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLoadHdl)
     180             : {
     181           0 :     SfxNewFileDialog* pDlg = new SfxNewFileDialog(this, SFXWB_PREVIEW);
     182           0 :     pDlg->SetText(String(SdResId(STR_LOAD_PRESENTATION_LAYOUT)));
     183             : 
     184           0 :     if(!IsReallyVisible())
     185             :     {
     186           0 :         delete pDlg;
     187           0 :         return 0;
     188             :     }
     189             : 
     190           0 :     sal_uInt16 nResult = pDlg->Execute();
     191             :     // Inserted update to force repaint
     192           0 :     Update();
     193             : 
     194           0 :     sal_Bool   bCancel = sal_False;
     195             : 
     196           0 :     switch (nResult)
     197             :     {
     198             :         case RET_OK:
     199             :         {
     200           0 :             if (pDlg->IsTemplate())
     201             :             {
     202           0 :                 maName = pDlg->GetTemplateFileName();
     203             :             }
     204             :             else
     205             :             {
     206             :                 // that way we encode "- nothing -"
     207           0 :                 maName.Erase();
     208             :             }
     209             :         }
     210           0 :         break;
     211             : 
     212             :         default:
     213           0 :             bCancel = sal_True;
     214             :     }
     215           0 :     delete pDlg;
     216             : 
     217           0 :     if( !bCancel )
     218             :     {
     219             :         // check if template already ecists
     220           0 :         sal_Bool bExists = sal_False;
     221           0 :         String aCompareStr( maName );
     222           0 :         if( maName.Len() == 0 )
     223           0 :             aCompareStr = maStrNone;
     224             : 
     225           0 :         sal_uInt16 aPos = 0;
     226           0 :         for (boost::ptr_vector<String>::iterator it = maLayoutNames.begin();
     227           0 :                   it != maLayoutNames.end() && !bExists; ++it, ++aPos)
     228             :         {
     229           0 :             if( aCompareStr == *it )
     230             :             {
     231           0 :                 bExists = sal_True;
     232             :                 // select template
     233           0 :                 maVS.SelectItem( aPos + 1 );
     234             :             }
     235             :         }
     236             : 
     237           0 :         if( !bExists )
     238             :         {
     239             :             // load document in order to determine preview bitmap (if template is selected)
     240           0 :             if( maName.Len() )
     241             :             {
     242             :                 // determine document in order to call OpenBookmarkDoc
     243           0 :                 SdDrawDocument* pDoc = mpDocSh->GetDoc();
     244           0 :                 SdDrawDocument* pTemplDoc  = pDoc->OpenBookmarkDoc( maName );
     245             : 
     246           0 :                 if (pTemplDoc)
     247             :                 {
     248           0 :                     ::sd::DrawDocShell*  pTemplDocSh= pTemplDoc->GetDocSh();
     249             : 
     250           0 :                     sal_uInt16 nCount = pTemplDoc->GetMasterPageCount();
     251             : 
     252           0 :                     for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
     253             :                     {
     254           0 :                         SdPage* pMaster = (SdPage*) pTemplDoc->GetMasterPage(nLayout);
     255           0 :                         if (pMaster->GetPageKind() == PK_STANDARD)
     256             :                         {
     257           0 :                             String aLayoutName(pMaster->GetLayoutName());
     258           0 :                             aLayoutName.Erase( aLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
     259           0 :                             maLayoutNames.push_back(new String(aLayoutName));
     260             : 
     261           0 :                             Bitmap aBitmap(pTemplDocSh->GetPagePreviewBitmap(pMaster, 90));
     262           0 :                             maVS.InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
     263             :                         }
     264             :                     }
     265             :                 }
     266             :                 else
     267             :                 {
     268           0 :                     bCancel = sal_True;
     269             :                 }
     270             : 
     271           0 :                 pDoc->CloseBookmarkDoc();
     272             :             }
     273             :             else
     274             :             {
     275             :                 // empty layout
     276           0 :                 maLayoutNames.push_back( new String( maStrNone ) );
     277           0 :                 maVS.InsertItem( (sal_uInt16) maLayoutNames.size(),
     278           0 :                         Bitmap( SdResId( BMP_FOIL_NONE ) ), maStrNone );
     279             :             }
     280             : 
     281           0 :             if (!bCancel)
     282             :             {
     283             :                 // select template
     284           0 :                 maVS.SelectItem( (sal_uInt16) maLayoutNames.size() );
     285             :             }
     286           0 :         }
     287             :     }
     288             : 
     289           0 :     return( 0 );
     290           0 : }
     291             : 
     292             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10