LCOV - code coverage report
Current view: top level - sd/source/ui/docshell - docshell.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 93 180 51.7 %
Date: 2014-11-03 Functions: 24 34 70.6 %
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 "DrawDocShell.hxx"
      21             : #include <vcl/svapp.hxx>
      22             : 
      23             : #include <sfx2/docfac.hxx>
      24             : #include <sfx2/objface.hxx>
      25             : #include <sfx2/request.hxx>
      26             : #include <svx/svxids.hrc>
      27             : #include <svl/srchitem.hxx>
      28             : #include <svx/srchdlg.hxx>
      29             : #include <editeng/flstitem.hxx>
      30             : #include <svl/eitem.hxx>
      31             : #include <svl/intitem.hxx>
      32             : #include <sfx2/printer.hxx>
      33             : #include <sfx2/docfile.hxx>
      34             : #include <svx/drawitem.hxx>
      35             : #include <sfx2/dispatch.hxx>
      36             : #include <svl/whiter.hxx>
      37             : #include <svl/itempool.hxx>
      38             : #include <svtools/ctrltool.hxx>
      39             : #include <vcl/graphicfilter.hxx>
      40             : #include <comphelper/classids.hxx>
      41             : #include <svl/cjkoptions.hxx>
      42             : #include <svl/visitem.hxx>
      43             : 
      44             : #include <svx/svdoutl.hxx>
      45             : 
      46             : #include <sfx2/fcontnr.hxx>
      47             : 
      48             : #include "app.hrc"
      49             : #include "sdmod.hxx"
      50             : #include "strmname.h"
      51             : #include "stlpool.hxx"
      52             : #include "strings.hrc"
      53             : #include "View.hxx"
      54             : #include "drawdoc.hxx"
      55             : #include "sdpage.hxx"
      56             : #include "glob.hrc"
      57             : #include "res_bmp.hrc"
      58             : #include "fupoor.hxx"
      59             : #include "fusearch.hxx"
      60             : #include "ViewShell.hxx"
      61             : #include "sdresid.hxx"
      62             : #include "slideshow.hxx"
      63             : #include "drawview.hxx"
      64             : #include "FrameView.hxx"
      65             : #include "unomodel.hxx"
      66             : #include "undo/undomanager.hxx"
      67             : #include "undo/undofactory.hxx"
      68             : #include "OutlineView.hxx"
      69             : #include "ViewShellBase.hxx"
      70             : 
      71             : using namespace sd;
      72             : #define DrawDocShell
      73             : #include "sdslots.hxx"
      74             : 
      75        1688 : SFX_IMPL_INTERFACE(DrawDocShell, SfxObjectShell, SdResId(0))
      76             : 
      77          36 : void DrawDocShell::InitInterface_Impl()
      78             : {
      79          36 :     GetStaticInterface()->RegisterChildWindow(SvxSearchDialogWrapper::GetChildWindowId());
      80          36 : }
      81             : 
      82             : namespace sd {
      83             : 
      84             : /**
      85             :  * slotmaps and definitions of SFX
      86             :  */
      87       12500 : TYPEINIT1( DrawDocShell, SfxObjectShell );
      88             : 
      89       17470 : SFX_IMPL_OBJECTFACTORY(
      90             :     DrawDocShell,
      91             :     SvGlobalName(SO3_SIMPRESS_CLASSID),
      92             :     SFXOBJECTSHELL_STD_NORMAL,
      93             :     "simpress" )
      94             : 
      95         438 : void DrawDocShell::Construct( bool bClipboard )
      96             : {
      97         438 :     mbInDestruction = false;
      98         438 :     SetSlotFilter();     // setzt Filter zurueck
      99             : 
     100         438 :     mbOwnDocument = mpDoc == 0;
     101         438 :     if( mbOwnDocument )
     102         438 :         mpDoc = new SdDrawDocument(meDocType, this);
     103             : 
     104             :     // The document has been created so we can call UpdateRefDevice() to set
     105             :     // the document's ref device.
     106         438 :     UpdateRefDevice();
     107             : 
     108         438 :     SetBaseModel( new SdXImpressDocument( this, bClipboard ) );
     109         438 :     SetPool( &mpDoc->GetItemPool() );
     110         438 :     mpUndoManager = new sd::UndoManager;
     111         438 :     mpDoc->SetSdrUndoManager( mpUndoManager );
     112         438 :     mpDoc->SetSdrUndoFactory( new sd::UndoFactory );
     113         438 :     UpdateTablePointers();
     114         438 :     SetStyleFamily(5);       //CL: actually SFX_STYLE_FAMILY_PSEUDO
     115         438 : }
     116             : 
     117         138 : DrawDocShell::DrawDocShell(SfxObjectCreateMode eMode,
     118             :                                bool bDataObject,
     119             :                                DocumentType eDocumentType) :
     120             :     SfxObjectShell( eMode == SFX_CREATE_MODE_INTERNAL ?  SFX_CREATE_MODE_EMBEDDED : eMode),
     121             :     mpDoc(NULL),
     122             :     mpUndoManager(NULL),
     123             :     mpPrinter(NULL),
     124             :     mpViewShell(NULL),
     125             :     mpFontList(NULL),
     126             :     meDocType(eDocumentType),
     127             :     mpFilterSIDs(0),
     128             :     mbSdDataObj(bDataObject),
     129             :     mbOwnPrinter(false),
     130         138 :     mbNewDocument( true )
     131             : {
     132         138 :     Construct( eMode == SFX_CREATE_MODE_INTERNAL );
     133         138 : }
     134             : 
     135         300 : DrawDocShell::DrawDocShell( const sal_uInt64 nModelCreationFlags, bool bDataObject, DocumentType eDocumentType ) :
     136             :     SfxObjectShell( nModelCreationFlags ),
     137             :     mpDoc(NULL),
     138             :     mpUndoManager(NULL),
     139             :     mpPrinter(NULL),
     140             :     mpViewShell(NULL),
     141             :     mpFontList(NULL),
     142             :     meDocType(eDocumentType),
     143             :     mpFilterSIDs(0),
     144             :     mbSdDataObj(bDataObject),
     145             :     mbOwnPrinter(false),
     146         300 :     mbNewDocument( true )
     147             : {
     148         300 :     Construct( false );
     149         300 : }
     150             : 
     151           0 : DrawDocShell::DrawDocShell(SdDrawDocument* pDoc, SfxObjectCreateMode eMode,
     152             :                                bool bDataObject,
     153             :                                DocumentType eDocumentType) :
     154             :     SfxObjectShell(eMode == SFX_CREATE_MODE_INTERNAL ?  SFX_CREATE_MODE_EMBEDDED : eMode),
     155             :     mpDoc(pDoc),
     156             :     mpUndoManager(NULL),
     157             :     mpPrinter(NULL),
     158             :     mpViewShell(NULL),
     159             :     mpFontList(NULL),
     160             :     meDocType(eDocumentType),
     161             :     mpFilterSIDs(0),
     162             :     mbSdDataObj(bDataObject),
     163             :     mbOwnPrinter(false),
     164           0 :     mbNewDocument( true )
     165             : {
     166           0 :     Construct( eMode == SFX_CREATE_MODE_INTERNAL );
     167           0 : }
     168             : 
     169        1144 : DrawDocShell::~DrawDocShell()
     170             : {
     171             :     // Tell all listeners that the doc shell is about to be
     172             :     // destroyed.  This has been introduced for the PreviewRenderer to
     173             :     // free its view (that uses the item poll of the doc shell) but
     174             :     // may be useful in other places as well.
     175         438 :     Broadcast(SfxSimpleHint(SFX_HINT_DYING));
     176             : 
     177         438 :     mbInDestruction = true;
     178             : 
     179         438 :     SetDocShellFunction(0);
     180             : 
     181         438 :     delete mpFontList;
     182             : 
     183         438 :     if( mpDoc )
     184         438 :         mpDoc->SetSdrUndoManager( 0 );
     185         438 :     delete mpUndoManager;
     186             : 
     187         438 :     if (mbOwnPrinter)
     188           8 :         delete mpPrinter;
     189             : 
     190         438 :     if( mbOwnDocument )
     191         438 :         delete mpDoc;
     192             : 
     193             :     // that the navigator get informed about the disappearance of the document
     194         438 :     SfxBoolItem     aItem(SID_NAVIGATOR_INIT, true);
     195         438 :     SfxViewFrame*   pFrame = mpViewShell ? mpViewShell->GetFrame() : GetFrame();
     196             : 
     197         438 :     if( !pFrame )
     198         438 :         pFrame = SfxViewFrame::GetFirst( this );
     199             : 
     200         438 :     if( pFrame )
     201             :         pFrame->GetDispatcher()->Execute(
     202           0 :             SID_NAVIGATOR_INIT, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, &aItem, 0L);
     203         706 : }
     204             : 
     205           0 : void DrawDocShell::GetState(SfxItemSet &rSet)
     206             : {
     207             : 
     208           0 :     SfxWhichIter aIter( rSet );
     209           0 :     sal_uInt16 nWhich = aIter.FirstWhich();
     210             : 
     211           0 :     while ( nWhich )
     212             :     {
     213           0 :         sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
     214           0 :             ? GetPool().GetSlotId(nWhich)
     215           0 :             : nWhich;
     216             : 
     217           0 :         switch ( nSlotId )
     218             :         {
     219             :             case SID_SEARCH_ITEM:
     220             :             {
     221           0 :                 rSet.Put( *SD_MOD()->GetSearchItem() );
     222             :             }
     223           0 :             break;
     224             : 
     225             :             case SID_CLOSEDOC:
     226           0 :                 GetSlotState(SID_CLOSEDOC, SfxObjectShell::GetInterface(), &rSet);
     227           0 :             break;
     228             : 
     229             :             case SID_SEARCH_OPTIONS:
     230             :             {
     231             :                 sal_uInt16 nOpt = SEARCH_OPTIONS_SEARCH      |
     232             :                               SEARCH_OPTIONS_WHOLE_WORDS |
     233             :                               SEARCH_OPTIONS_BACKWARDS   |
     234             :                               SEARCH_OPTIONS_REG_EXP     |
     235             :                               SEARCH_OPTIONS_EXACT       |
     236             :                               SEARCH_OPTIONS_SIMILARITY  |
     237           0 :                               SEARCH_OPTIONS_SELECTION;
     238             : 
     239           0 :                 if (!IsReadOnly())
     240             :                 {
     241           0 :                     nOpt |= SEARCH_OPTIONS_REPLACE;
     242           0 :                     nOpt |= SEARCH_OPTIONS_REPLACE_ALL;
     243             :                 }
     244             : 
     245           0 :                 rSet.Put(SfxUInt16Item(nWhich, nOpt));
     246             :             }
     247           0 :             break;
     248             : 
     249             :             case SID_VERSION:
     250             :             {
     251           0 :                 GetSlotState( SID_VERSION, SfxObjectShell::GetInterface(), &rSet );
     252             :             }
     253           0 :             break;
     254             : 
     255             :             case SID_CHINESE_CONVERSION:
     256             :             case SID_HANGUL_HANJA_CONVERSION:
     257             :             {
     258           0 :                 rSet.Put(SfxVisibilityItem(nWhich, SvtCJKOptions().IsAnyEnabled()));
     259             :             }
     260           0 :             break;
     261             :             case SID_LANGUAGE_STATUS:
     262             :             {
     263             :                 // Keeping this enabled for the time being
     264           0 :                 rSet.Put(SfxVisibilityItem(nWhich, true));
     265             :             }
     266           0 :             break;
     267             : 
     268             :             default:
     269           0 :             break;
     270             :         }
     271           0 :         nWhich = aIter.NextWhich();
     272             :     }
     273             : 
     274           0 :     SfxViewFrame* pFrame = SfxViewFrame::Current();
     275             : 
     276           0 :     if (pFrame)
     277             :     {
     278           0 :         if (rSet.GetItemState(SID_RELOAD) != SfxItemState::UNKNOWN)
     279             :         {
     280             :             pFrame->GetSlotState(SID_RELOAD,
     281           0 :                                  pFrame->GetInterface(), &rSet);
     282             :         }
     283           0 :     }
     284           0 : }
     285             : 
     286           0 : void DrawDocShell::InPlaceActivate( bool bActive )
     287             : {
     288           0 :     SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
     289           0 :     std::vector<FrameView*> &rViews = mpDoc->GetFrameViewList();
     290             : 
     291           0 :     if( !bActive )
     292             :     {
     293           0 :         std::vector<FrameView*>::iterator pIter;
     294           0 :         for ( pIter = rViews.begin(); pIter != rViews.end(); ++pIter )
     295           0 :             delete *pIter;
     296             : 
     297           0 :         rViews.clear();
     298             : 
     299           0 :         while (pSfxViewFrame)
     300             :         {
     301             :             // determine the number of FrameViews
     302           0 :             SfxViewShell* pSfxViewSh = pSfxViewFrame->GetViewShell();
     303             :             // FIXME this used to be a PTR_CAST, but when I updated the macro, I discovered that SfxViewShell is not statically castable to sd::ViewShell
     304           0 :             ViewShell* pViewSh = (pSfxViewSh && pSfxViewSh->IsA( TYPE(ViewShell) )) ? dynamic_cast<ViewShell*>(pSfxViewSh) : 0;
     305             : 
     306           0 :             if ( pViewSh && pViewSh->GetFrameView() )
     307             :             {
     308           0 :                 pViewSh->WriteFrameViewData();
     309           0 :                 rViews.push_back( new FrameView( mpDoc, pViewSh->GetFrameView() ) );
     310             :             }
     311             : 
     312           0 :             pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
     313             :         }
     314             :     }
     315             : 
     316           0 :     SfxObjectShell::InPlaceActivate( bActive );
     317             : 
     318           0 :     if( bActive )
     319             :     {
     320           0 :         for( sal_uInt32 i = 0; pSfxViewFrame && (i < rViews.size()); i++ )
     321             :         {
     322             :             // determine the number of FrameViews
     323           0 :             SfxViewShell* pSfxViewSh = pSfxViewFrame->GetViewShell();
     324             :             // FIXME this used to be a PTR_CAST, but when I updated the macro, I discovered that SfxViewShell is not statically castable to sd::ViewShell
     325           0 :             ViewShell* pViewSh = (pSfxViewSh && pSfxViewSh->IsA( TYPE(ViewShell) )) ? dynamic_cast<ViewShell*>(pSfxViewSh) : 0;
     326             : 
     327           0 :             if ( pViewSh )
     328             :             {
     329           0 :                 pViewSh->ReadFrameViewData( rViews[ i ] );
     330             :             }
     331             : 
     332           0 :             pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
     333             :         }
     334             :     }
     335           0 : }
     336             : 
     337         212 : void DrawDocShell::Activate( bool bMDI)
     338             : {
     339         212 :     if (bMDI)
     340             :     {
     341         212 :         ApplySlotFilter();
     342         212 :         mpDoc->StartOnlineSpelling();
     343             :     }
     344         212 : }
     345             : 
     346         212 : void DrawDocShell::Deactivate( bool )
     347             : {
     348         212 : }
     349             : 
     350       16244 : ::svl::IUndoManager* DrawDocShell::GetUndoManager()
     351             : {
     352       16244 :     return mpUndoManager;
     353             : }
     354             : 
     355         470 : void DrawDocShell::UpdateTablePointers()
     356             : {
     357         470 :     PutItem( SvxColorListItem( mpDoc->GetColorList(), SID_COLOR_TABLE ) );
     358         470 :     PutItem( SvxGradientListItem( mpDoc->GetGradientList(), SID_GRADIENT_LIST ) );
     359         470 :     PutItem( SvxHatchListItem( mpDoc->GetHatchList(), SID_HATCH_LIST ) );
     360         470 :     PutItem( SvxBitmapListItem( mpDoc->GetBitmapList(), SID_BITMAP_LIST ) );
     361         470 :     PutItem( SvxDashListItem( mpDoc->GetDashList(), SID_DASH_LIST ) );
     362         470 :     PutItem( SvxLineEndListItem( mpDoc->GetLineEndList(), SID_LINEEND_LIST ) );
     363             : 
     364         470 :     UpdateFontList();
     365         470 : }
     366             : 
     367           0 : void DrawDocShell::CancelSearching()
     368             : {
     369           0 :     if( dynamic_cast<FuSearch*>( mxDocShellFunction.get() ) )
     370             :     {
     371           0 :         SetDocShellFunction(0);
     372             :     }
     373           0 : }
     374             : 
     375             : /**
     376             :  * apply configured slot filters
     377             :  */
     378         212 : void DrawDocShell::ApplySlotFilter() const
     379             : {
     380         212 :     SfxViewShell* pTestViewShell = SfxViewShell::GetFirst();
     381             : 
     382         644 :     while( pTestViewShell )
     383             :     {
     384         440 :         if( pTestViewShell->GetObjectShell()
     385         220 :             == const_cast<DrawDocShell*>( this )
     386         212 :             && pTestViewShell->GetViewFrame()
     387         432 :             && pTestViewShell->GetViewFrame()->GetDispatcher() )
     388             :         {
     389         212 :             SfxDispatcher* pDispatcher = pTestViewShell->GetViewFrame()->GetDispatcher();
     390             : 
     391         212 :             if( mpFilterSIDs )
     392           0 :                 pDispatcher->SetSlotFilter( mbFilterEnable ? SFX_SLOT_FILTER_ENABLED : SFX_SLOT_FILTER_DISABLED, mnFilterCount, mpFilterSIDs );
     393             :             else
     394         212 :                 pDispatcher->SetSlotFilter();
     395             : 
     396         212 :             if( pDispatcher->GetBindings() )
     397         212 :                 pDispatcher->GetBindings()->InvalidateAll( true );
     398             :         }
     399             : 
     400         220 :         pTestViewShell = SfxViewShell::GetNext( *pTestViewShell );
     401             :     }
     402         212 : }
     403             : 
     404       86644 : void DrawDocShell::SetModified( bool bSet /* = true */ )
     405             : {
     406       86644 :     SfxObjectShell::SetModified( bSet );
     407             : 
     408             :     // change model state, too
     409             :     // only set the changed state if modification is enabled
     410       86644 :     if( IsEnableSetModified() )
     411             :     {
     412       86142 :         if ( mpDoc )
     413       86142 :             mpDoc->NbcSetChanged( bSet );
     414             : 
     415       86142 :         Broadcast( SfxSimpleHint( SFX_HINT_DOCCHANGED ) );
     416             :     }
     417       86644 : }
     418             : 
     419             : /**
     420             :  * Callback for ExecuteSpellPopup()
     421             :  */
     422             : // ExecuteSpellPopup now handled by DrawDocShell. This is necessary
     423             : // to get hands on the outliner and the text object.
     424           0 : IMPL_LINK(DrawDocShell, OnlineSpellCallback, SpellCallbackInfo*, pInfo)
     425             : {
     426           0 :     SdrObject* pObj = NULL;
     427           0 :     SdrOutliner* pOutl = NULL;
     428             : 
     429           0 :     if(GetViewShell())
     430             :     {
     431           0 :         pOutl = GetViewShell()->GetView()->GetTextEditOutliner();
     432           0 :         pObj = GetViewShell()->GetView()->GetTextEditObject();
     433             :     }
     434             : 
     435           0 :     mpDoc->ImpOnlineSpellCallback(pInfo, pObj, pOutl);
     436           0 :     return(0);
     437             : }
     438             : 
     439          36 : void DrawDocShell::ClearUndoBuffer()
     440             : {
     441             :     // clear possible undo buffers of outliners
     442          36 :     SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
     443          72 :     while(pSfxViewFrame)
     444             :     {
     445           0 :         ViewShellBase* pViewShellBase = dynamic_cast< ViewShellBase* >( pSfxViewFrame->GetViewShell() );
     446           0 :         if( pViewShellBase )
     447             :         {
     448           0 :             ::boost::shared_ptr<ViewShell> pViewSh( pViewShellBase->GetMainViewShell() );
     449           0 :             if( pViewSh.get() )
     450             :             {
     451           0 :                 ::sd::View* pView = pViewSh->GetView();
     452           0 :                 if( pView )
     453             :                 {
     454           0 :                     pView->SdrEndTextEdit();
     455           0 :                     sd::OutlineView* pOutlView = dynamic_cast< sd::OutlineView* >( pView );
     456           0 :                     if( pOutlView )
     457             :                     {
     458           0 :                         pOutlView->GetOutliner().GetUndoManager().Clear();
     459             :                     }
     460             :                 }
     461           0 :             }
     462             :         }
     463           0 :         pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
     464             :     }
     465             : 
     466          36 :     ::svl::IUndoManager* pUndoManager = GetUndoManager();
     467          36 :     if(pUndoManager && pUndoManager->GetUndoActionCount())
     468           0 :         pUndoManager->Clear();
     469          36 : }
     470             : 
     471         114 : } // end of namespace sd
     472             : 
     473             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10