LCOV - code coverage report
Current view: top level - sd/source/ui/func - fuprlout.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 99 1.0 %
Date: 2015-06-13 12:38:46 Functions: 2 10 20.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 "fuprlout.hxx"
      21             : #include <vcl/wrkwin.hxx>
      22             : #include <sfx2/dispatch.hxx>
      23             : #include <svl/smplhint.hxx>
      24             : #include <svl/itempool.hxx>
      25             : #include <sot/storage.hxx>
      26             : #include <vcl/msgbox.hxx>
      27             : #include <svx/svdundo.hxx>
      28             : 
      29             : #include <sfx2/viewfrm.hxx>
      30             : #include <sfx2/request.hxx>
      31             : 
      32             : #include "drawdoc.hxx"
      33             : #include "sdpage.hxx"
      34             : #include "pres.hxx"
      35             : #include "DrawViewShell.hxx"
      36             : #include "FrameView.hxx"
      37             : #include "stlpool.hxx"
      38             : #include "View.hxx"
      39             : #include "glob.hrc"
      40             : #include "glob.hxx"
      41             : #include "strings.hrc"
      42             : #include "strmname.h"
      43             : #include "app.hrc"
      44             : #include "DrawDocShell.hxx"
      45             : #include "unprlout.hxx"
      46             : #include "unchss.hxx"
      47             : #include "unmovss.hxx"
      48             : #include "sdattr.hxx"
      49             : #include "sdresid.hxx"
      50             : #include "drawview.hxx"
      51             : #include <editeng/outliner.hxx>
      52             : #include <editeng/editdata.hxx>
      53             : #include "sdabstdlg.hxx"
      54             : #include <boost/scoped_ptr.hpp>
      55             : 
      56             : namespace sd
      57             : {
      58             : 
      59           0 : TYPEINIT1( FuPresentationLayout, FuPoor );
      60             : 
      61             : #define DOCUMENT_TOKEN '#'
      62             : 
      63           0 : FuPresentationLayout::FuPresentationLayout (
      64             :     ViewShell* pViewSh,
      65             :     ::sd::Window* pWin,
      66             :     ::sd::View* pView,
      67             :     SdDrawDocument* pDoc,
      68             :     SfxRequest& rReq)
      69           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
      70             : {
      71           0 : }
      72             : 
      73           0 : rtl::Reference<FuPoor> FuPresentationLayout::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
      74             : {
      75           0 :     rtl::Reference<FuPoor> xFunc( new FuPresentationLayout( pViewSh, pWin, pView, pDoc, rReq ) );
      76           0 :     xFunc->DoExecute(rReq);
      77           0 :     return xFunc;
      78             : }
      79             : 
      80           0 : void FuPresentationLayout::DoExecute( SfxRequest& rReq )
      81             : {
      82             :     // prevent selected objects or objects which are under editing from disappearing
      83           0 :     mpView->SdrEndTextEdit();
      84             : 
      85           0 :     if(mpView->GetSdrPageView())
      86             :     {
      87           0 :         mpView->UnmarkAll();
      88             :     }
      89             : 
      90           0 :     bool bError = false;
      91             : 
      92             :     // determine the active page
      93           0 :     sal_uInt16 nSelectedPage = SDRPAGE_NOTFOUND;
      94           0 :     for (sal_uInt16 nPage = 0; nPage < mpDoc->GetSdPageCount(PK_STANDARD); nPage++)
      95             :     {
      96           0 :         if (mpDoc->GetSdPage(nPage, PK_STANDARD)->IsSelected())
      97             :         {
      98           0 :             nSelectedPage = nPage;
      99           0 :             break;
     100             :         }
     101             :     }
     102             : 
     103             :     DBG_ASSERT(nSelectedPage != SDRPAGE_NOTFOUND, "no selected page");
     104           0 :     SdPage* pSelectedPage = mpDoc->GetSdPage(nSelectedPage, PK_STANDARD);
     105           0 :     OUString aOldLayoutName(pSelectedPage->GetLayoutName());
     106           0 :     sal_Int32 nPos = aOldLayoutName.indexOf(SD_LT_SEPARATOR);
     107           0 :     if (nPos != -1)
     108           0 :         aOldLayoutName = aOldLayoutName.copy(0, nPos);
     109             : 
     110             :     /* if we are on a master page, the changes apply for all pages and notes-
     111             :        pages who are using the relevant layout */
     112           0 :     bool bOnMaster = false;
     113           0 :     if( mpViewShell && mpViewShell->ISA(DrawViewShell))
     114             :     {
     115             :         EditMode eEditMode =
     116           0 :             static_cast<DrawViewShell*>(mpViewShell)->GetEditMode();
     117           0 :         if (eEditMode == EM_MASTERPAGE)
     118           0 :             bOnMaster = true;
     119             :     }
     120           0 :     bool bMasterPage = bOnMaster;
     121           0 :     bool bCheckMasters = false;
     122             : 
     123             :     // call dialog
     124           0 :     bool   bLoad = false;           // appear the new master pages?
     125           0 :     OUString aFile;
     126             : 
     127           0 :     SfxItemSet aSet(mpDoc->GetPool(), ATTR_PRESLAYOUT_START, ATTR_PRESLAYOUT_END);
     128             : 
     129           0 :     aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad));
     130           0 :     aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, bMasterPage ) );
     131           0 :     aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, bCheckMasters ) );
     132           0 :     aSet.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aOldLayoutName));
     133             : 
     134           0 :     const SfxItemSet *pArgs = rReq.GetArgs ();
     135             : 
     136           0 :     if (pArgs)
     137             :     {
     138           0 :         if (pArgs->GetItemState(ATTR_PRESLAYOUT_LOAD) == SfxItemState::SET)
     139           0 :             bLoad = static_cast<const SfxBoolItem&>(pArgs->Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
     140           0 :         if( pArgs->GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SfxItemState::SET )
     141           0 :             bMasterPage = static_cast<const SfxBoolItem&>( pArgs->Get( ATTR_PRESLAYOUT_MASTER_PAGE ) ).GetValue();
     142           0 :         if( pArgs->GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SfxItemState::SET )
     143           0 :             bCheckMasters = static_cast<const SfxBoolItem&>( pArgs->Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
     144           0 :         if (pArgs->GetItemState(ATTR_PRESLAYOUT_NAME) == SfxItemState::SET)
     145           0 :             aFile = static_cast<const SfxStringItem&>(pArgs->Get(ATTR_PRESLAYOUT_NAME)).GetValue();
     146             :     }
     147             :     else
     148             :     {
     149           0 :         SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
     150           0 :         boost::scoped_ptr<AbstractSdPresLayoutDlg> pDlg(pFact ? pFact->CreateSdPresLayoutDlg(mpDocSh, NULL, aSet ) : 0);
     151             : 
     152           0 :         sal_uInt16 nResult = pDlg ? pDlg->Execute() : static_cast<short>(RET_CANCEL);
     153             : 
     154           0 :         switch (nResult)
     155             :         {
     156             :             case RET_OK:
     157             :             {
     158           0 :                 pDlg->GetAttr(aSet);
     159           0 :                 if (aSet.GetItemState(ATTR_PRESLAYOUT_LOAD) == SfxItemState::SET)
     160           0 :                     bLoad = static_cast<const SfxBoolItem&>(aSet.Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
     161           0 :                 if( aSet.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SfxItemState::SET )
     162           0 :                     bMasterPage = static_cast<const SfxBoolItem&>(aSet.Get( ATTR_PRESLAYOUT_MASTER_PAGE ) ).GetValue();
     163           0 :                 if( aSet.GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SfxItemState::SET )
     164           0 :                     bCheckMasters = static_cast<const SfxBoolItem&>(aSet.Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
     165           0 :                 if (aSet.GetItemState(ATTR_PRESLAYOUT_NAME) == SfxItemState::SET)
     166           0 :                     aFile = static_cast<const SfxStringItem&>(aSet.Get(ATTR_PRESLAYOUT_NAME)).GetValue();
     167             :             }
     168           0 :             break;
     169             : 
     170             :             default:
     171           0 :                 bError = true;
     172           0 :         }
     173             :     }
     174             : 
     175           0 :     if (!bError)
     176             :     {
     177           0 :         mpDocSh->SetWaitCursor( true );
     178             : 
     179             :         /* Here, we only exchange masterpages, therefore the current page
     180             :            remains the current page. To prevent calling PageOrderChangedHint
     181             :            during insertion and extraction of the masterpages, we block. */
     182             :         /* That isn't quitely right. If the masterpageview is active and you are
     183             :            removing a masterpage, it's possible that you are removing the
     184             :            current masterpage. So you have to call ResetActualPage ! */
     185           0 :         if( mpViewShell->ISA(DrawViewShell) && !bCheckMasters )
     186           0 :             static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(true);
     187             : 
     188           0 :         if (bLoad)
     189             :         {
     190           0 :             OUString aFileName = aFile.getToken(0, DOCUMENT_TOKEN);
     191           0 :             SdDrawDocument* pTempDoc = mpDoc->OpenBookmarkDoc( aFileName );
     192             : 
     193             :             // #69581: If I chosed the standard-template I got no filename and so I get no
     194             :             //         SdDrawDocument-Pointer. But the method SetMasterPage is able to handle
     195             :             //         a NULL-pointer as a Standard-template ( look at SdDrawDocument::SetMasterPage )
     196           0 :             OUString aLayoutName;
     197           0 :             if( pTempDoc )
     198           0 :                 aLayoutName = aFile.getToken(1, DOCUMENT_TOKEN);
     199             : 
     200           0 :             mpDoc->SetMasterPage(nSelectedPage, aLayoutName, pTempDoc, bMasterPage, bCheckMasters);
     201           0 :             mpDoc->CloseBookmarkDoc();
     202             :         }
     203             :         else
     204             :         {
     205             :             // use master page with the layout name aFile from current Doc
     206           0 :             mpDoc->SetMasterPage(nSelectedPage, aFile, mpDoc, bMasterPage, bCheckMasters);
     207             :         }
     208             : 
     209             :         // remove blocking
     210           0 :         if (mpViewShell->ISA(DrawViewShell) && !bCheckMasters )
     211           0 :             static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(false);
     212             : 
     213             :         // if the master page was visible, show it again
     214           0 :         if (!bError && nSelectedPage != SDRPAGE_NOTFOUND)
     215             :         {
     216           0 :             if (bOnMaster)
     217             :             {
     218           0 :                 if (mpViewShell->ISA(DrawViewShell))
     219             :                 {
     220             :                     ::sd::View* pView =
     221           0 :                           static_cast<DrawViewShell*>(mpViewShell)->GetView();
     222           0 :                     sal_uInt16 nPgNum = pSelectedPage->TRG_GetMasterPage().GetPageNum();
     223             : 
     224           0 :                     if (static_cast<DrawViewShell*>(mpViewShell)->GetPageKind() == PK_NOTES)
     225           0 :                         nPgNum++;
     226             : 
     227           0 :                     pView->HideSdrPage();
     228           0 :                     pView->ShowSdrPage(pView->GetModel()->GetMasterPage(nPgNum));
     229             :                 }
     230             : 
     231             :                 // force update of TabBar
     232           0 :                 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_MASTERPAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
     233             :             }
     234             :             else
     235             :             {
     236           0 :                 pSelectedPage->SetAutoLayout(pSelectedPage->GetAutoLayout());
     237             :             }
     238             :         }
     239             : 
     240             :         // fake a mode change to repaint the page tab bar
     241           0 :         if( mpViewShell && mpViewShell->ISA( DrawViewShell ) )
     242             :         {
     243             :             DrawViewShell* pDrawViewSh =
     244           0 :                 static_cast<DrawViewShell*>(mpViewShell);
     245           0 :             EditMode eMode = pDrawViewSh->GetEditMode();
     246           0 :             bool bLayer = pDrawViewSh->IsLayerModeActive();
     247           0 :             pDrawViewSh->ChangeEditMode( eMode, !bLayer );
     248           0 :             pDrawViewSh->ChangeEditMode( eMode, bLayer );
     249             :         }
     250             : 
     251           0 :         mpDocSh->SetWaitCursor( false );
     252           0 :     }
     253           0 : }
     254             : 
     255          66 : } // end of namespace sd
     256             : 
     257             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11