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

Generated by: LCOV version 1.10