LCOV - code coverage report
Current view: top level - sw/source/uibase/uiview - uivwimp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 55 135 40.7 %
Date: 2015-06-13 12:38:46 Functions: 13 23 56.5 %
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 <cmdid.h>
      23             : #include "globals.hrc"
      24             : 
      25             : #include <com/sun/star/scanner/XScannerManager2.hpp>
      26             : #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
      27             : #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
      28             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      29             : #include <comphelper/processfactory.hxx>
      30             : #include <osl/mutex.hxx>
      31             : #include <vcl/layout.hxx>
      32             : #include <vcl/svapp.hxx>
      33             : #include <vcl/wrkwin.hxx>
      34             : #include <vcl/msgbox.hxx>
      35             : #include <sfx2/viewfrm.hxx>
      36             : #include <sfx2/bindings.hxx>
      37             : 
      38             : #include <sfx2/docinsert.hxx>
      39             : #include <sfx2/request.hxx>
      40             : #include <uivwimp.hxx>
      41             : #include <wview.hxx>
      42             : #include <unotxvw.hxx>
      43             : #include <unodispatch.hxx>
      44             : #include <swmodule.hxx>
      45             : #include <swdtflvr.hxx>
      46             : #include <edtwin.hxx>
      47             : #include <mmconfigitem.hxx>
      48             : 
      49             : #include <view.hrc>
      50             : 
      51             : using namespace ::com::sun::star;
      52             : using namespace ::com::sun::star::uno;
      53             : using namespace ::com::sun::star::scanner;
      54             : using namespace ::com::sun::star::lang;
      55             : using namespace ::com::sun::star::datatransfer::clipboard;
      56             : 
      57        2761 : SwView_Impl::SwView_Impl(SwView* pShell)
      58        2761 :     : pxXTextView(new uno::Reference<view::XSelectionSupplier>)
      59             :     , pView(pShell)
      60             :     , pScanEvtLstnr(0)
      61             :     , pClipEvtLstnr(0)
      62             :     , eShellMode(SHELL_MODE_TEXT)
      63             : #if HAVE_FEATURE_DBCONNECTIVITY
      64             :     , pConfigItem(0)
      65             :     , nMailMergeRestartPage(0)
      66             :     , bMailMergeSourceView(true)
      67             : #endif
      68             :     , m_pDocInserter(NULL)
      69             :     , m_pRequest(NULL)
      70             :     , m_nParam(0)
      71             :     , m_bSelectObject(false)
      72        5522 :     , m_bEditingPositionSet(false)
      73             : {
      74        2761 :     *pxXTextView = new SwXTextView(pView);
      75        2761 :     xDisProvInterceptor = new SwXDispatchProviderInterceptor(*pView);
      76        2761 : }
      77             : 
      78        5514 : SwView_Impl::~SwView_Impl()
      79             : {
      80        2757 :     Reference<XUnoTunnel> xDispTunnel(xDisProvInterceptor, UNO_QUERY);
      81        2757 :     SwXDispatchProviderInterceptor* pInterceptor = 0;
      82        5514 :     if(xDispTunnel.is() &&
      83             :         0 != (pInterceptor = reinterpret_cast< SwXDispatchProviderInterceptor * >(
      84             :                     sal::static_int_cast< sal_IntPtr >(
      85        2757 :                     xDispTunnel->getSomething(SwXDispatchProviderInterceptor::getUnoTunnelId())))))
      86             :     {
      87        2757 :         pInterceptor->Invalidate();
      88             :     }
      89        2757 :     view::XSelectionSupplier* pTextView = pxXTextView->get();
      90        2757 :     static_cast<SwXTextView*>(pTextView)->Invalidate();
      91        2757 :     delete pxXTextView;
      92        2757 :     if( xScanEvtLstnr.is() )
      93           0 :            pScanEvtLstnr->ViewDestroyed();
      94        2757 :     if( xClipEvtLstnr.is() )
      95             :     {
      96         338 :         pClipEvtLstnr->AddRemoveListener( false );
      97         338 :         pClipEvtLstnr->ViewDestroyed();
      98             :     }
      99             : #if HAVE_FEATURE_DBCONNECTIVITY
     100        2757 :     delete pConfigItem;
     101             : #endif
     102        2757 :     delete m_pDocInserter;
     103        2757 :     delete m_pRequest;
     104        2757 : }
     105             : 
     106        2778 : void SwView_Impl::SetShellMode(ShellModes eSet)
     107             : {
     108        2778 :     eShellMode = eSet;
     109        2778 : }
     110             : 
     111           2 : view::XSelectionSupplier*   SwView_Impl::GetUNOObject()
     112             : {
     113           2 :     return pxXTextView->get();
     114             : }
     115             : 
     116       17217 : SwXTextView*    SwView_Impl::GetUNOObject_Impl()
     117             : {
     118       17217 :         view::XSelectionSupplier* pTextView = pxXTextView->get();
     119       17217 :         return static_cast<SwXTextView*>(pTextView);
     120             : }
     121             : 
     122           0 : void SwView_Impl::ExecuteScan( SfxRequest& rReq )
     123             : {
     124           0 :     switch(rReq.GetSlot())
     125             :     {
     126             :         case SID_TWAIN_SELECT:
     127             :         {
     128           0 :             bool bDone = false;
     129           0 :             Reference< XScannerManager2 > xScanMgr = SW_MOD()->GetScannerManager();
     130             : 
     131           0 :             if( xScanMgr.is() )
     132             :             {
     133             :                 try
     134             :                 {
     135           0 :                     SwScannerEventListener& rListener = GetScannerEventListener();
     136             :                     const Sequence< ScannerContext >
     137           0 :                         aContexts( xScanMgr->getAvailableScanners() );
     138             : 
     139           0 :                     if( aContexts.getLength() )
     140             :                     {
     141           0 :                         Reference< XEventListener > xLstner = &rListener;
     142           0 :                         ScannerContext aContext( aContexts.getConstArray()[ 0 ] );
     143           0 :                         bDone = xScanMgr->configureScannerAndScan( aContext, xLstner );
     144           0 :                     }
     145             :                 }
     146           0 :                 catch(...)
     147             :                 {
     148             :                 }
     149             : 
     150             :             }
     151           0 :             if( bDone )
     152           0 :                 rReq.Done();
     153             :             else
     154             :             {
     155           0 :                 rReq.Ignore();
     156           0 :             }
     157             :         }
     158           0 :         break;
     159             : 
     160             :         case SID_TWAIN_TRANSFER:
     161             :         {
     162           0 :             bool bDone = false;
     163             : 
     164           0 :             Reference< XScannerManager2 > xScanMgr = SW_MOD()->GetScannerManager();
     165           0 :             if( xScanMgr.is() )
     166             :             {
     167           0 :                 SwScannerEventListener& rListener = GetScannerEventListener();
     168             :                 try
     169             :                 {
     170           0 :                     const Sequence< scanner::ScannerContext >aContexts( xScanMgr->getAvailableScanners() );
     171           0 :                     if( aContexts.getLength() )
     172             :                     {
     173           0 :                         Reference< XEventListener > xLstner = &rListener;
     174           0 :                         xScanMgr->startScan( aContexts.getConstArray()[ 0 ], xLstner );
     175           0 :                         bDone = true;
     176           0 :                     }
     177             :                 }
     178           0 :                 catch(...)
     179             :                 {
     180             :                 }
     181             :             }
     182             : 
     183           0 :             if( !bDone )
     184             :             {
     185           0 :                 ScopedVclPtrInstance<MessageDialog>::Create( nullptr, SW_RES(STR_SCAN_NOSOURCE), VCL_MESSAGE_INFO )->Execute();
     186           0 :                 rReq.Ignore();
     187             :             }
     188             :             else
     189             :             {
     190           0 :                 rReq.Done();
     191           0 :                 SfxBindings& rBind = pView->GetViewFrame()->GetBindings();
     192           0 :                 rBind.Invalidate( SID_TWAIN_SELECT );
     193           0 :                 rBind.Invalidate( SID_TWAIN_TRANSFER );
     194           0 :             }
     195             :         }
     196           0 :         break;
     197             :     }
     198           0 : }
     199             : 
     200           0 : SwScannerEventListener& SwView_Impl::GetScannerEventListener()
     201             : {
     202           0 :     if(!xScanEvtLstnr.is())
     203           0 :         xScanEvtLstnr = pScanEvtLstnr = new SwScannerEventListener(*pView);
     204           0 :     return *pScanEvtLstnr;
     205             : }
     206             : 
     207         338 : void SwView_Impl::AddClipboardListener()
     208             : {
     209         338 :     if(!xClipEvtLstnr.is())
     210             :     {
     211         338 :         xClipEvtLstnr = pClipEvtLstnr = new SwClipboardChangeListener( *pView );
     212         338 :         pClipEvtLstnr->AddRemoveListener( true );
     213             :     }
     214         338 : }
     215             : 
     216        2757 : void SwView_Impl::Invalidate()
     217             : {
     218        2757 :     GetUNOObject_Impl()->Invalidate();
     219        2757 :     Reference< XUnoTunnel > xTunnel(xTransferable.get(), UNO_QUERY);
     220        2757 :     if(xTunnel.is())
     221             : 
     222             :     {
     223             :         SwTransferable* pTransferable = reinterpret_cast< SwTransferable * >(
     224             :                 sal::static_int_cast< sal_IntPtr >(
     225          20 :                 xTunnel->getSomething(SwTransferable::getUnoTunnelId())));
     226          20 :         if(pTransferable)
     227          20 :             pTransferable->Invalidate();
     228        2757 :     }
     229        2757 : }
     230             : 
     231          51 : void SwView_Impl::AddTransferable(SwTransferable& rTransferable)
     232             : {
     233             :     //prevent removing of the non-referenced SwTransferable
     234          51 :     rTransferable.m_refCount++;
     235             :     {
     236          51 :         xTransferable = Reference<XUnoTunnel> (&rTransferable);
     237             :     }
     238          51 :     rTransferable.m_refCount--;
     239          51 : }
     240             : 
     241           0 : void SwView_Impl::StartDocumentInserter( const OUString& rFactory, const Link<>& rEndDialogHdl )
     242             : {
     243           0 :     delete m_pDocInserter;
     244           0 :     m_pDocInserter = new ::sfx2::DocumentInserter( rFactory );
     245           0 :     m_pDocInserter->StartExecuteModal( rEndDialogHdl );
     246           0 : }
     247             : 
     248           0 : SfxMedium* SwView_Impl::CreateMedium()
     249             : {
     250           0 :     return m_pDocInserter->CreateMedium();
     251             : }
     252             : 
     253           0 : void SwView_Impl::InitRequest( const SfxRequest& rRequest )
     254             : {
     255           0 :     delete m_pRequest;
     256           0 :     m_pRequest = new SfxRequest( rRequest );
     257           0 : }
     258             : 
     259           0 : SwScannerEventListener::~SwScannerEventListener()
     260             : {
     261           0 : }
     262             : 
     263           0 : void SAL_CALL SwScannerEventListener::disposing( const EventObject& rEventObject) throw(uno::RuntimeException, std::exception)
     264             : {
     265             : #if defined WNT || defined UNX
     266           0 :     SolarMutexGuard aGuard;
     267           0 :     if( pView )
     268           0 :         pView->ScannerEventHdl( rEventObject );
     269             : #endif
     270           0 : }
     271             : 
     272         676 : SwClipboardChangeListener::~SwClipboardChangeListener()
     273             : {
     274         676 : }
     275             : 
     276           0 : void SAL_CALL SwClipboardChangeListener::disposing( const EventObject& /*rEventObject*/ )
     277             :     throw ( RuntimeException, std::exception )
     278             : {
     279           0 : }
     280             : 
     281           0 : void SAL_CALL SwClipboardChangeListener::changedContents( const ::com::sun::star::datatransfer::clipboard::ClipboardEvent& rEventObject )
     282             :     throw (RuntimeException, std::exception)
     283             : 
     284             : {
     285           0 :     const SolarMutexGuard aGuard;
     286           0 :     if( pView )
     287             :     {
     288             :         {
     289           0 :             TransferableDataHelper aDataHelper( rEventObject.Contents );
     290           0 :             SwWrtShell& rSh = pView->GetWrtShell();
     291             : 
     292           0 :             pView->m_nLastPasteDestination = SwTransferable::GetSotDestination( rSh );
     293           0 :             pView->m_bPasteState = aDataHelper.GetXTransferable().is() &&
     294           0 :                             SwTransferable::IsPaste( rSh, aDataHelper );
     295             : 
     296           0 :             pView->m_bPasteSpecialState = aDataHelper.GetXTransferable().is() &&
     297           0 :                         SwTransferable::IsPasteSpecial( rSh, aDataHelper );
     298             :         }
     299             : 
     300           0 :         SfxBindings& rBind = pView->GetViewFrame()->GetBindings();
     301           0 :         rBind.Invalidate( SID_PASTE );
     302           0 :         rBind.Invalidate( SID_PASTE_SPECIAL );
     303           0 :         rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
     304           0 :     }
     305           0 : }
     306             : 
     307         676 : void SwClipboardChangeListener::AddRemoveListener( bool bAdd )
     308             : {
     309         676 :     pView->AddRemoveClipboardListener( Reference< XClipboardListener >( this ), bAdd );
     310         853 : }
     311             : 
     312             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11