LCOV - code coverage report
Current view: top level - sd/source/ui/view - ViewShellImplementation.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 31 150 20.7 %
Date: 2015-06-13 12:38:46 Functions: 10 15 66.7 %
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 <config_features.h>
      21             : 
      22             : #include "ViewShellImplementation.hxx"
      23             : 
      24             : #include "sdpage.hxx"
      25             : #include "drawdoc.hxx"
      26             : #include "sdresid.hxx"
      27             : #include "glob.hrc"
      28             : #include "app.hrc"
      29             : #include "strings.hrc"
      30             : #include "helpids.h"
      31             : #include "sdattr.hxx"
      32             : #include "sdabstdlg.hxx"
      33             : #include "unmodpg.hxx"
      34             : #include "Window.hxx"
      35             : #include "optsitem.hxx"
      36             : #include "DrawDocShell.hxx"
      37             : #include "DrawController.hxx"
      38             : #include "FactoryIds.hxx"
      39             : #include "slideshow.hxx"
      40             : #include "ViewShellBase.hxx"
      41             : #include "FrameView.hxx"
      42             : #include "DrawViewShell.hxx"
      43             : #include "ViewShellHint.hxx"
      44             : #include "SidebarPanelId.hxx"
      45             : #include "framework/FrameworkHelper.hxx"
      46             : 
      47             : #include <sfx2/bindings.hxx>
      48             : #include <sfx2/dispatch.hxx>
      49             : #include <sfx2/request.hxx>
      50             : #include <sfx2/sidebar/Sidebar.hxx>
      51             : #include <svl/aeitem.hxx>
      52             : #include <svx/imapdlg.hxx>
      53             : #include <vcl/msgbox.hxx>
      54             : #include <basic/sbstar.hxx>
      55             : #include "undo/undoobjects.hxx"
      56             : 
      57             : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
      58             : 
      59             : using namespace ::com::sun::star::uno;
      60             : using namespace ::com::sun::star::drawing::framework;
      61             : using ::sd::framework::FrameworkHelper;
      62             : 
      63             : namespace sd {
      64             : 
      65         197 : ViewShell::Implementation::Implementation (ViewShell& rViewShell)
      66             :     : mbIsShowingUIControls(false),
      67             :       mbIsMainViewShell(false),
      68             :       mbIsInitialized(false),
      69             :       mbArrangeActive(false),
      70             :       mpSubShellFactory(),
      71             :       mpUpdateLockForMouse(),
      72         197 :       mrViewShell(rViewShell)
      73             : {
      74         197 : }
      75             : 
      76         394 : ViewShell::Implementation::~Implementation()
      77             : {
      78         197 :     if ( ! mpUpdateLockForMouse.expired())
      79             :     {
      80           0 :         ::boost::shared_ptr<ToolBarManagerLock> pLock(mpUpdateLockForMouse);
      81           0 :         if (pLock.get() != NULL)
      82             :         {
      83             :             // Force the ToolBarManagerLock to be released even when the
      84             :             // IsUICaptured() returns <TRUE/>.
      85           0 :             pLock->Release(true);
      86           0 :         }
      87             :     }
      88         197 : }
      89             : 
      90           0 : void ViewShell::Implementation::ProcessModifyPageSlot (
      91             :     SfxRequest& rRequest,
      92             :     SdPage* pCurrentPage,
      93             :     PageKind ePageKind)
      94             : {
      95           0 :     SdDrawDocument* pDocument = mrViewShell.GetDoc();
      96           0 :     SdrLayerAdmin& rLayerAdmin = pDocument->GetLayerAdmin();
      97           0 :     sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND), false);
      98           0 :     sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ), false);
      99           0 :     SetOfByte aVisibleLayers;
     100           0 :     bool bHandoutMode = false;
     101           0 :     SdPage* pHandoutMPage = NULL;
     102           0 :     OUString aNewName;
     103             : 
     104             :     AutoLayout aNewAutoLayout;
     105             : 
     106             :     bool bBVisible;
     107             :     bool bBObjsVisible;
     108           0 :     const SfxItemSet* pArgs = rRequest.GetArgs();
     109             : 
     110           0 :     if (pCurrentPage != NULL && pCurrentPage->TRG_HasMasterPage())
     111           0 :         aVisibleLayers = pCurrentPage->TRG_GetMasterPageVisibleLayers();
     112             :     else
     113           0 :         aVisibleLayers.SetAll();
     114             : 
     115             :     do
     116             :     {
     117           0 :         if (pCurrentPage == NULL)
     118           0 :             break;
     119             : 
     120           0 :         if (!pArgs || pArgs->Count() == 1 || pArgs->Count() == 2 )
     121             :         {
     122             : 
     123             :             // Make the layout menu visible in the tool pane.
     124             :             sfx2::sidebar::Sidebar::ShowPanel(
     125             :                 OUString("ImpressLayoutsPanel"),
     126           0 :                 mrViewShell.GetViewFrame()->GetFrame().GetFrameInterface());
     127           0 :             break;
     128             :         }
     129           0 :         else if (pArgs->Count() == 4)
     130             :         {
     131           0 :             SFX_REQUEST_ARG (rRequest, pNewName, SfxStringItem, ID_VAL_PAGENAME, false);
     132           0 :             SFX_REQUEST_ARG (rRequest, pNewAutoLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, false);
     133           0 :             SFX_REQUEST_ARG (rRequest, pBVisible, SfxBoolItem, ID_VAL_ISPAGEBACK, false);
     134           0 :             SFX_REQUEST_ARG (rRequest, pBObjsVisible, SfxBoolItem, ID_VAL_ISPAGEOBJ, false);
     135           0 :             AutoLayout aLayout ((AutoLayout)pNewAutoLayout->GetValue ());
     136           0 :             if (aLayout >= AUTOLAYOUT__START
     137           0 :                 && aLayout < AUTOLAYOUT__END)
     138             :             {
     139           0 :                 aNewName        = pNewName->GetValue ();
     140           0 :                 aNewAutoLayout = (AutoLayout) pNewAutoLayout->GetValue ();
     141           0 :                 bBVisible       = pBVisible->GetValue ();
     142           0 :                 bBObjsVisible   = pBObjsVisible->GetValue ();
     143             :             }
     144             :             else
     145             :             {
     146             : #if HAVE_FEATURE_SCRIPTING
     147           0 :                 StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
     148             : #endif
     149           0 :                 rRequest.Ignore ();
     150           0 :                 break;
     151             :             }
     152           0 :             if (ePageKind == PK_HANDOUT)
     153             :             {
     154           0 :                 bHandoutMode = true;
     155           0 :                 pHandoutMPage = pDocument->GetMasterSdPage(0, PK_HANDOUT);
     156             :             }
     157             :         }
     158             :         else
     159             :         {
     160             : #if HAVE_FEATURE_SCRIPTING
     161           0 :             StarBASIC::FatalError (SbERR_WRONG_ARGS);
     162             : #endif
     163           0 :             rRequest.Ignore ();
     164           0 :             break;
     165             :         }
     166             : 
     167             :         SdPage* pUndoPage =
     168           0 :             bHandoutMode ? pHandoutMPage : pCurrentPage;
     169             : 
     170           0 :         ::svl::IUndoManager* pUndoManager = mrViewShell.GetDocSh()->GetUndoManager();
     171             :         DBG_ASSERT(pUndoManager, "No UNDO MANAGER ?!?");
     172             : 
     173           0 :         if( pUndoManager )
     174             :         {
     175           0 :             OUString aComment( SdResId(STR_UNDO_MODIFY_PAGE) );
     176           0 :             pUndoManager->EnterListAction(aComment, aComment);
     177             :             ModifyPageUndoAction* pAction = new ModifyPageUndoAction(
     178           0 :                 pDocument, pUndoPage, aNewName, aNewAutoLayout, bBVisible, bBObjsVisible);
     179           0 :             pUndoManager->AddUndoAction(pAction);
     180             : 
     181             :             // Clear the selection because the selected object may be removed as
     182             :             // a result of the assignment of the layout.
     183           0 :             mrViewShell.GetDrawView()->UnmarkAll();
     184             : 
     185           0 :             if (!bHandoutMode)
     186             :             {
     187           0 :                 if (pCurrentPage->GetName() != aNewName)
     188             :                 {
     189           0 :                     pCurrentPage->SetName(aNewName);
     190             : 
     191           0 :                     if (ePageKind == PK_STANDARD)
     192             :                     {
     193           0 :                         sal_uInt16 nPage = (pCurrentPage->GetPageNum()-1) / 2;
     194           0 :                         SdPage* pNotesPage = pDocument->GetSdPage(nPage, PK_NOTES);
     195           0 :                         if (pNotesPage != NULL)
     196           0 :                             pNotesPage->SetName(aNewName);
     197             :                     }
     198             :                 }
     199             : 
     200           0 :                 pCurrentPage->SetAutoLayout(aNewAutoLayout, true);
     201             : 
     202           0 :                 aBckgrnd = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND), false);
     203           0 :                 aBckgrndObj = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ), false);
     204           0 :                 aVisibleLayers.Set(aBckgrnd, bBVisible);
     205           0 :                 aVisibleLayers.Set(aBckgrndObj, bBObjsVisible);
     206           0 :                 pCurrentPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
     207             :             }
     208             :             else
     209             :             {
     210           0 :                 pHandoutMPage->SetAutoLayout(aNewAutoLayout, true);
     211             :             }
     212             : 
     213             :             mrViewShell.GetViewFrame()->GetDispatcher()->Execute(SID_SWITCHPAGE,
     214           0 :                 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
     215             : 
     216           0 :             bool bSetModified = true;
     217             : 
     218           0 :             if (pArgs && pArgs->Count() == 1)
     219             :             {
     220           0 :                 bSetModified = static_cast<const SfxBoolItem&>(pArgs->Get(SID_MODIFYPAGE)).GetValue();
     221             :             }
     222             : 
     223           0 :             pUndoManager->AddUndoAction( new UndoAutoLayoutPosAndSize( *pUndoPage ) );
     224           0 :             pUndoManager->LeaveListAction();
     225             : 
     226           0 :             pDocument->SetChanged(bSetModified);
     227             :         }
     228             :     }
     229             :     while (false);
     230             : 
     231           0 :     mrViewShell.Cancel();
     232           0 :     rRequest.Done ();
     233           0 : }
     234             : 
     235           0 : void ViewShell::Implementation::AssignLayout ( SfxRequest& rRequest, PageKind ePageKind )
     236             : {
     237           0 :     const SfxUInt32Item* pWhatPage = static_cast< const SfxUInt32Item*  > ( rRequest.GetArg( ID_VAL_WHATPAGE, false, TYPE(SfxUInt32Item) ) );
     238           0 :     const SfxUInt32Item* pWhatLayout = static_cast< const SfxUInt32Item*  > ( rRequest.GetArg( ID_VAL_WHATLAYOUT, false, TYPE(SfxUInt32Item) ) );
     239             : 
     240           0 :     SdDrawDocument* pDocument = mrViewShell.GetDoc();
     241           0 :     if( !pDocument )
     242           0 :         return;
     243             : 
     244           0 :     SdPage* pPage = 0;
     245           0 :     if( pWhatPage )
     246             :     {
     247           0 :         pPage = pDocument->GetSdPage(static_cast<sal_uInt16>(pWhatPage->GetValue()), ePageKind);
     248             :     }
     249             : 
     250           0 :     if( pPage == 0 )
     251           0 :         pPage = mrViewShell.getCurrentPage();
     252             : 
     253           0 :     if( pPage )
     254             :     {
     255           0 :         AutoLayout eLayout = pPage->GetAutoLayout();
     256             : 
     257           0 :         if( pWhatLayout )
     258           0 :             eLayout = static_cast< AutoLayout >( pWhatLayout->GetValue() );
     259             : 
     260             :         // Transform the given request into the four argument form that is
     261             :         // understood by ProcessModifyPageSlot().
     262           0 :         SdrLayerAdmin& rLayerAdmin (mrViewShell.GetViewShellBase().GetDocument()->GetLayerAdmin());
     263           0 :         sal_uInt8 aBackground (rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND), false));
     264           0 :         sal_uInt8 aBackgroundObject (rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ), false));
     265             : 
     266           0 :         SetOfByte aVisibleLayers;
     267             : 
     268           0 :         if( pPage->GetPageKind() == PK_HANDOUT )
     269           0 :             aVisibleLayers.SetAll();
     270             :         else
     271           0 :             aVisibleLayers = pPage->TRG_GetMasterPageVisibleLayers();
     272             : 
     273           0 :         SfxRequest aRequest (mrViewShell.GetViewShellBase().GetViewFrame(), SID_MODIFYPAGE);
     274           0 :         aRequest.AppendItem(SfxStringItem (ID_VAL_PAGENAME, pPage->GetName()));
     275           0 :         aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, eLayout));
     276           0 :         aRequest.AppendItem(SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
     277           0 :         aRequest.AppendItem(SfxBoolItem(ID_VAL_ISPAGEOBJ, aVisibleLayers.IsSet(aBackgroundObject)));
     278             : 
     279             :         // Forward the call with the new arguments.
     280           0 :         ProcessModifyPageSlot( aRequest, pPage, pPage->GetPageKind());
     281             :     }
     282             : }
     283             : 
     284         112 : sal_uInt16 ViewShell::Implementation::GetViewId()
     285             : {
     286         112 :     switch (mrViewShell.GetShellType())
     287             :     {
     288             :         case ViewShell::ST_IMPRESS:
     289             :         case ViewShell::ST_NOTES:
     290             :         case ViewShell::ST_HANDOUT:
     291          25 :             return IMPRESS_FACTORY_ID;
     292             : 
     293             :         case ViewShell::ST_DRAW:
     294          87 :             return DRAW_FACTORY_ID;
     295             : 
     296             :         case ViewShell::ST_OUTLINE:
     297           0 :             return OUTLINE_FACTORY_ID;
     298             : 
     299             :         case ViewShell::ST_SLIDE_SORTER:
     300           0 :             return SLIDE_SORTER_FACTORY_ID;
     301             : 
     302             :         case ViewShell::ST_PRESENTATION:
     303           0 :             return PRESENTATION_FACTORY_ID;
     304             : 
     305             :         // Since we have to return a view id for every possible shell type
     306             :         // and there is not (yet) a proper ViewShellBase sub class for the
     307             :         // remaining types we chose the Impress factory as a fall back.
     308             :         case ViewShell::ST_SIDEBAR:
     309             :         case ViewShell::ST_NONE:
     310             :         default:
     311           0 :             return IMPRESS_FACTORY_ID;
     312             :     }
     313             : }
     314             : 
     315           0 : SvxIMapDlg* ViewShell::Implementation::GetImageMapDialog()
     316             : {
     317           0 :     SvxIMapDlg* pDialog = NULL;
     318             :     SfxChildWindow* pChildWindow = SfxViewFrame::Current()->GetChildWindow(
     319           0 :         SvxIMapDlgChildWindow::GetChildWindowId());
     320           0 :     if (pChildWindow != NULL)
     321           0 :         pDialog = dynamic_cast<SvxIMapDlg*>(pChildWindow->GetWindow());
     322           0 :     return pDialog;
     323             : }
     324             : 
     325             : //===== ToolBarManagerLock ====================================================
     326             : 
     327             : class ViewShell::Implementation::ToolBarManagerLock::Deleter { public:
     328           2 :     void operator() (ToolBarManagerLock* pObject) { delete pObject; }
     329             : };
     330             : 
     331             : ::boost::shared_ptr<ViewShell::Implementation::ToolBarManagerLock>
     332           2 :     ViewShell::Implementation::ToolBarManagerLock::Create (
     333             :         const ::boost::shared_ptr<ToolBarManager>& rpManager)
     334             : {
     335             :     ::boost::shared_ptr<ToolBarManagerLock> pLock (
     336           2 :         new ViewShell::Implementation::ToolBarManagerLock(rpManager),
     337           4 :         ViewShell::Implementation::ToolBarManagerLock::Deleter());
     338           2 :     pLock->mpSelf = pLock;
     339           2 :     return pLock;
     340             : }
     341             : 
     342           2 : ViewShell::Implementation::ToolBarManagerLock::ToolBarManagerLock (
     343             :     const ::boost::shared_ptr<ToolBarManager>& rpManager)
     344           2 :     : mpLock(new ToolBarManager::UpdateLock(rpManager)),
     345           4 :       maTimer()
     346             : {
     347             :     // Start a timer that will unlock the ToolBarManager update lock when
     348             :     // that is not done explicitly by calling Release().
     349           2 :     maTimer.SetTimeoutHdl(LINK(this,ToolBarManagerLock,TimeoutCallback));
     350           2 :     maTimer.SetTimeout(100);
     351           2 :     maTimer.Start();
     352           2 : }
     353             : 
     354           0 : IMPL_LINK_NOARG_TYPED(ViewShell::Implementation::ToolBarManagerLock, TimeoutCallback, Timer *, void)
     355             : {
     356             :     // If possible then release the lock now.  Otherwise start the timer
     357             :     // and try again later.
     358           0 :     if (Application::IsUICaptured())
     359             :     {
     360           0 :         maTimer.Start();
     361             :     }
     362             :     else
     363             :     {
     364           0 :         mpSelf.reset();
     365             :     }
     366           0 : }
     367             : 
     368           2 : void ViewShell::Implementation::ToolBarManagerLock::Release (bool bForce)
     369             : {
     370             :     // If possible then release the lock now.  Otherwise try again when the
     371             :     // timer expires.
     372           2 :     if (bForce || ! Application::IsUICaptured())
     373             :     {
     374           2 :         mpSelf.reset();
     375             :     }
     376           2 : }
     377             : 
     378           4 : ViewShell::Implementation::ToolBarManagerLock::~ToolBarManagerLock()
     379             : {
     380           2 :     mpLock.reset();
     381           2 : }
     382             : 
     383          66 : } // end of namespace sd
     384             : 
     385             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11