LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/dlg - sdpreslt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 115 0.0 %
Date: 2012-12-17 Functions: 0 10 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             : 
      21             : #ifdef SD_DLLIMPLEMENTATION
      22             : #undef SD_DLLIMPLEMENTATION
      23             : #endif
      24             : 
      25             : 
      26             : #include <svl/itemset.hxx>
      27             : #include <sfx2/new.hxx>
      28             : #include <vcl/msgbox.hxx>
      29             : 
      30             : #include "strings.hrc"
      31             : #include "res_bmp.hrc"
      32             : #include "sdpreslt.hxx"
      33             : #include "sdpreslt.hrc"
      34             : #include "sdattr.hxx"
      35             : #include "sdresid.hxx"
      36             : #include "drawdoc.hxx"
      37             : #include "sdpage.hxx"
      38             : #include "DrawDocShell.hxx"
      39             : 
      40             : #define DOCUMENT_TOKEN (sal_Unicode('#'))
      41             : 
      42             : /*************************************************************************
      43             : |*
      44             : |* Konstruktor
      45             : |*
      46             : \************************************************************************/
      47             : 
      48           0 : SdPresLayoutDlg::SdPresLayoutDlg(
      49             :     ::sd::DrawDocShell* pDocShell,
      50             :     ::Window* pWindow,
      51             :     const SfxItemSet& rInAttrs ):
      52             :                 ModalDialog         (pWindow, SdResId(DLG_PRESLT)),
      53             :                 mpDocSh              ( pDocShell ),
      54             :                 maFtLayout           (this, SdResId(FT_LAYOUT)),
      55             :                 maVS                 (this, SdResId(VS_LAYOUT)),
      56             :                 maBtnOK              (this, SdResId(BTN_OK)),
      57             :                 maBtnCancel          (this, SdResId(BTN_CANCEL)),
      58             :                 maBtnHelp            (this, SdResId(BTN_HELP)),
      59             :                 maCbxMasterPage     (this, SdResId(CBX_MASTER_PAGE)),
      60             :                 maCbxCheckMasters   (this, SdResId(CBX_CHECK_MASTERS)),
      61             :                 maBtnLoad            (this, SdResId(BTN_LOAD)),
      62             :                 mrOutAttrs           (rInAttrs),
      63           0 :                 maStrNone           ( SdResId( STR_NULL ) )
      64             : {
      65           0 :     FreeResource();
      66             : 
      67           0 :     maVS.SetDoubleClickHdl(LINK(this, SdPresLayoutDlg, ClickLayoutHdl));
      68           0 :     maBtnLoad.SetClickHdl(LINK(this, SdPresLayoutDlg, ClickLoadHdl));
      69             : 
      70           0 :     Reset();
      71           0 : }
      72             : 
      73             : /*************************************************************************
      74             : |*
      75             : |*  Dtor
      76             : |*
      77             : *************************************************************************/
      78             : 
      79           0 : SdPresLayoutDlg::~SdPresLayoutDlg()
      80             : {
      81           0 : }
      82             : 
      83             : /*************************************************************************
      84             : |*
      85             : |*    Initialisierung
      86             : |*
      87             : *************************************************************************/
      88             : 
      89           0 : void SdPresLayoutDlg::Reset()
      90             : {
      91           0 :     const SfxPoolItem *pPoolItem = NULL;
      92             :     long nName;
      93             : 
      94             :     // MasterPage austauschen
      95           0 :     if( mrOutAttrs.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE, sal_False, &pPoolItem ) == SFX_ITEM_SET )
      96             :     {
      97           0 :         sal_Bool bMasterPage = ( (const SfxBoolItem*) pPoolItem)->GetValue();
      98           0 :         maCbxMasterPage.Enable( !bMasterPage );
      99           0 :         maCbxMasterPage.Check( bMasterPage );
     100             :     }
     101             : 
     102             :     // Nicht verwendete MasterPages entfernen
     103           0 :     maCbxCheckMasters.Check(sal_False);
     104             : 
     105           0 :     if(mrOutAttrs.GetItemState(ATTR_PRESLAYOUT_NAME, sal_True, &pPoolItem) == SFX_ITEM_SET)
     106           0 :         maName = ((const SfxStringItem*)pPoolItem)->GetValue();
     107             :     else
     108           0 :         maName.Erase();
     109             : 
     110           0 :     FillValueSet();
     111             : 
     112           0 :     mnLayoutCount = maLayoutNames.size();
     113           0 :     for( nName = 0; nName < mnLayoutCount; nName++ )
     114             :     {
     115           0 :         if (maLayoutNames[nName] == maName)
     116           0 :             break;
     117             :     }
     118             :     DBG_ASSERT(nName < mnLayoutCount, "Layout nicht gefunden");
     119             : 
     120           0 :     maVS.SelectItem((sal_uInt16)nName + 1);  // Inizes des ValueSets beginnen bei 1
     121             : 
     122           0 : }
     123             : 
     124             : /*************************************************************************
     125             : |*
     126             : |*    Fuellt uebergebenen Item-Set mit Dialogbox-Attributen
     127             : |*
     128             : *************************************************************************/
     129             : 
     130           0 : void SdPresLayoutDlg::GetAttr(SfxItemSet& rOutAttrs)
     131             : {
     132           0 :     short nId = maVS.GetSelectItemId();
     133           0 :     sal_Bool bLoad = nId > mnLayoutCount;
     134           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad ) );
     135             : 
     136           0 :     String aLayoutName;
     137             : 
     138           0 :     if( bLoad )
     139             :     {
     140           0 :         aLayoutName = maName;
     141           0 :         aLayoutName.Append( DOCUMENT_TOKEN );
     142           0 :         aLayoutName.Append( maLayoutNames[ nId - 1 ] );
     143             :     }
     144             :     else
     145             :     {
     146           0 :         aLayoutName = maLayoutNames[ nId - 1 ];
     147           0 :         if( aLayoutName == maStrNone )
     148           0 :             aLayoutName.Erase(); //  so wird "- keine -" codiert (s.u.)
     149             :     }
     150             : 
     151           0 :     rOutAttrs.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aLayoutName ) );
     152           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, maCbxMasterPage.IsChecked() ) );
     153           0 :     rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, maCbxCheckMasters.IsChecked() ) );
     154           0 : }
     155             : 
     156             : 
     157             : /*************************************************************************
     158             : |*
     159             : |* Fuellt das ValueSet mit Bitmaps
     160             : |*
     161             : \************************************************************************/
     162             : 
     163           0 : void SdPresLayoutDlg::FillValueSet()
     164             : {
     165           0 :     maVS.SetStyle(maVS.GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER
     166           0 :                                       | WB_VSCROLL | WB_NAMEFIELD);
     167             : 
     168           0 :     maVS.SetColCount(2);
     169           0 :     maVS.SetLineCount(2);
     170           0 :     maVS.SetExtraSpacing(2);
     171             : 
     172           0 :     SdDrawDocument* pDoc = mpDocSh->GetDoc();
     173             : 
     174           0 :     sal_uInt16 nCount = pDoc->GetMasterPageCount();
     175             : 
     176           0 :     for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
     177             :     {
     178           0 :         SdPage* pMaster = (SdPage*)pDoc->GetMasterPage(nLayout);
     179           0 :         if (pMaster->GetPageKind() == PK_STANDARD)
     180             :         {
     181           0 :             String aLayoutName(pMaster->GetLayoutName());
     182           0 :             aLayoutName.Erase( aLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
     183           0 :             maLayoutNames.push_back(new String(aLayoutName));
     184             : 
     185           0 :             Bitmap aBitmap(mpDocSh->GetPagePreviewBitmap(pMaster, 90));
     186           0 :             maVS.InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
     187             :         }
     188             :     }
     189             : 
     190           0 :     maVS.Show();
     191           0 : }
     192             : 
     193             : 
     194             : /*************************************************************************
     195             : |*
     196             : |* Doppelklick-Handler
     197             : |*
     198             : \************************************************************************/
     199             : 
     200           0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLayoutHdl)
     201             : {
     202           0 :     EndDialog(RET_OK);
     203           0 :     return 0;
     204             : }
     205             : 
     206             : /*************************************************************************
     207             : |*
     208             : |* Klick-Handler fuer Laden-Button
     209             : |*
     210             : \************************************************************************/
     211             : 
     212           0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLoadHdl)
     213             : {
     214           0 :     SfxNewFileDialog* pDlg = new SfxNewFileDialog(this, SFXWB_PREVIEW);
     215           0 :     pDlg->SetText(String(SdResId(STR_LOAD_PRESENTATION_LAYOUT)));
     216             : 
     217           0 :     if(!IsReallyVisible())
     218             :     {
     219           0 :         delete pDlg;
     220           0 :         return 0;
     221             :     }
     222             : 
     223           0 :     sal_uInt16 nResult = pDlg->Execute();
     224             :     // Inserted update to force repaint
     225           0 :     Update();
     226             : 
     227           0 :     String aFile;
     228           0 :     sal_Bool   bCancel = sal_False;
     229             : 
     230           0 :     switch (nResult)
     231             :     {
     232             :         case RET_OK:
     233             :         {
     234           0 :             if (pDlg->IsTemplate())
     235             :             {
     236           0 :                 maName = pDlg->GetTemplateFileName();
     237             :             }
     238             :             else
     239             :             {
     240             :                 // so wird "- keine -" codiert
     241           0 :                 maName.Erase();
     242             :             }
     243             :         }
     244           0 :         break;
     245             : 
     246             :         default:
     247           0 :             bCancel = sal_True;
     248             :     }
     249           0 :     delete pDlg;
     250             : 
     251           0 :     if( !bCancel )
     252             :     {
     253             :         // Pruefen, ob Vorlage schon vorhanden
     254           0 :         sal_Bool bExists = sal_False;
     255           0 :         String aCompareStr( maName );
     256           0 :         if( maName.Len() == 0 )
     257           0 :             aCompareStr = maStrNone;
     258             : 
     259           0 :         sal_uInt16 aPos = 0;
     260           0 :         for (boost::ptr_vector<String>::iterator it = maLayoutNames.begin();
     261           0 :                   it != maLayoutNames.end() && !bExists; ++it, ++aPos)
     262             :         {
     263           0 :             if( aCompareStr == *it )
     264             :             {
     265           0 :                 bExists = sal_True;
     266             :                 // Vorlage selektieren
     267           0 :                 maVS.SelectItem( aPos + 1 );
     268             :             }
     269             :         }
     270             : 
     271           0 :         if( !bExists )
     272             :         {
     273             :             // Dokument laden um Preview-Bitmap zu ermitteln (wenn Vorlage ausgewaehlt)
     274           0 :             if( maName.Len() )
     275             :             {
     276             :                 // Dokument ermitteln, um OpenBookmarkDoc rufen zu koennen
     277           0 :                 SdDrawDocument* pDoc = mpDocSh->GetDoc();
     278           0 :                 SdDrawDocument* pTemplDoc  = pDoc->OpenBookmarkDoc( maName );
     279             : 
     280           0 :                 if (pTemplDoc)
     281             :                 {
     282           0 :                     ::sd::DrawDocShell*  pTemplDocSh= pTemplDoc->GetDocSh();
     283             : 
     284           0 :                     sal_uInt16 nCount = pTemplDoc->GetMasterPageCount();
     285             : 
     286           0 :                     for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
     287             :                     {
     288           0 :                         SdPage* pMaster = (SdPage*) pTemplDoc->GetMasterPage(nLayout);
     289           0 :                         if (pMaster->GetPageKind() == PK_STANDARD)
     290             :                         {
     291           0 :                             String aLayoutName(pMaster->GetLayoutName());
     292           0 :                             aLayoutName.Erase( aLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
     293           0 :                             maLayoutNames.push_back(new String(aLayoutName));
     294             : 
     295           0 :                             Bitmap aBitmap(pTemplDocSh->GetPagePreviewBitmap(pMaster, 90));
     296           0 :                             maVS.InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
     297             :                         }
     298             :                     }
     299             :                 }
     300             :                 else
     301             :                 {
     302           0 :                     bCancel = sal_True;
     303             :                 }
     304             : 
     305           0 :                 pDoc->CloseBookmarkDoc();
     306             :             }
     307             :             else
     308             :             {
     309             :                 // leeres Layout
     310           0 :                 maLayoutNames.push_back( new String( maStrNone ) );
     311           0 :                 maVS.InsertItem( (sal_uInt16) maLayoutNames.size(),
     312           0 :                         Bitmap( SdResId( BMP_FOIL_NONE ) ), maStrNone );
     313             :             }
     314             : 
     315           0 :             if (!bCancel)
     316             :             {
     317             :                 // Vorlage selektieren
     318           0 :                 maVS.SelectItem( (sal_uInt16) maLayoutNames.size() );
     319             :             }
     320           0 :         }
     321             :     }
     322             : 
     323           0 :     return( 0 );
     324             : }
     325             : 
     326             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10