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

Generated by: LCOV version 1.10