1*efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*efeef26fSAndrew Rist * distributed with this work for additional information 6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*efeef26fSAndrew Rist * software distributed under the License is distributed on an 15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17*efeef26fSAndrew Rist * specific language governing permissions and limitations 18*efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*efeef26fSAndrew Rist *************************************************************/ 21*efeef26fSAndrew Rist 22*efeef26fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sw.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <cmdid.h> 29cdf0e10cSrcweir #include "globals.hrc" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <tools/shl.hxx> 32cdf0e10cSrcweir #include <com/sun/star/scanner/XScannerManager.hpp> 33cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp> 34cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> 35cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 36cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 37cdf0e10cSrcweir #include <vos/mutex.hxx> 38cdf0e10cSrcweir #include <vcl/svapp.hxx> 39cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 40cdf0e10cSrcweir #include <vcl/msgbox.hxx> 41cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 42cdf0e10cSrcweir #include <sfx2/bindings.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <sfx2/docinsert.hxx> 45cdf0e10cSrcweir #include <sfx2/request.hxx> 46cdf0e10cSrcweir #include <uivwimp.hxx> 47cdf0e10cSrcweir #include <wview.hxx> 48cdf0e10cSrcweir #include <unotxvw.hxx> 49cdf0e10cSrcweir #include <unodispatch.hxx> 50cdf0e10cSrcweir #include <swmodule.hxx> 51cdf0e10cSrcweir #include <swdtflvr.hxx> 52cdf0e10cSrcweir #include <edtwin.hxx> 53cdf0e10cSrcweir #include <mmconfigitem.hxx> 54cdf0e10cSrcweir 55cdf0e10cSrcweir #include <view.hrc> 56cdf0e10cSrcweir 57cdf0e10cSrcweir 58cdf0e10cSrcweir using namespace ::com::sun::star; 59cdf0e10cSrcweir using namespace ::com::sun::star::uno; 60cdf0e10cSrcweir using namespace ::com::sun::star::scanner; 61cdf0e10cSrcweir using namespace ::com::sun::star::lang; 62cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::clipboard; 63cdf0e10cSrcweir 64cdf0e10cSrcweir /* -----------------02.06.98 15:31------------------- 65cdf0e10cSrcweir * 66cdf0e10cSrcweir * --------------------------------------------------*/ 67cdf0e10cSrcweir SwView_Impl::SwView_Impl(SwView* pShell) : 68cdf0e10cSrcweir pxXTextView(new uno::Reference<view::XSelectionSupplier>), 69cdf0e10cSrcweir pView(pShell), 70cdf0e10cSrcweir eShellMode(SHELL_MODE_TEXT), 71cdf0e10cSrcweir pConfigItem(0), 72cdf0e10cSrcweir nMailMergeRestartPage(0), 73cdf0e10cSrcweir bMailMergeSourceView(sal_True), 74cdf0e10cSrcweir m_pDocInserter(NULL), 75cdf0e10cSrcweir m_pRequest(NULL), 76cdf0e10cSrcweir m_bSelectObject(false), 77cdf0e10cSrcweir m_bEditingPositionSet(false) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir *pxXTextView = new SwXTextView(pView); 80cdf0e10cSrcweir xDisProvInterceptor = new SwXDispatchProviderInterceptor(*pView); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir /*-----------------13.12.97 09:51------------------- 84cdf0e10cSrcweir 85cdf0e10cSrcweir --------------------------------------------------*/ 86cdf0e10cSrcweir SwView_Impl::~SwView_Impl() 87cdf0e10cSrcweir { 88cdf0e10cSrcweir Reference<XUnoTunnel> xDispTunnel(xDisProvInterceptor, UNO_QUERY); 89cdf0e10cSrcweir SwXDispatchProviderInterceptor* pInterceptor = 0; 90cdf0e10cSrcweir if(xDispTunnel.is() && 91cdf0e10cSrcweir 0 != (pInterceptor = reinterpret_cast< SwXDispatchProviderInterceptor * >( 92cdf0e10cSrcweir sal::static_int_cast< sal_IntPtr >( 93cdf0e10cSrcweir xDispTunnel->getSomething(SwXDispatchProviderInterceptor::getUnoTunnelId()))))) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir pInterceptor->Invalidate(); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir view::XSelectionSupplier* pTextView = pxXTextView->get(); 98cdf0e10cSrcweir ((SwXTextView*)pTextView)->Invalidate(); 99cdf0e10cSrcweir delete pxXTextView; 100cdf0e10cSrcweir if( xScanEvtLstnr.is() ) 101cdf0e10cSrcweir pScanEvtLstnr->ViewDestroyed(); 102cdf0e10cSrcweir if( xClipEvtLstnr.is() ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir pClipEvtLstnr->AddRemoveListener( sal_False ); 105cdf0e10cSrcweir pClipEvtLstnr->ViewDestroyed(); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir delete pConfigItem; 108cdf0e10cSrcweir 109cdf0e10cSrcweir delete m_pDocInserter; 110cdf0e10cSrcweir delete m_pRequest; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir /*-----------------13.12.97 09:54------------------- 114cdf0e10cSrcweir 115cdf0e10cSrcweir --------------------------------------------------*/ 116cdf0e10cSrcweir void SwView_Impl::SetShellMode(ShellModes eSet) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir eShellMode = eSet; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir /*-----------------13.12.97 09:59------------------- 121cdf0e10cSrcweir 122cdf0e10cSrcweir --------------------------------------------------*/ 123cdf0e10cSrcweir view::XSelectionSupplier* SwView_Impl::GetUNOObject() 124cdf0e10cSrcweir { 125cdf0e10cSrcweir return pxXTextView->get(); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir /* -----------------02.06.98 15:29------------------- 128cdf0e10cSrcweir * 129cdf0e10cSrcweir * --------------------------------------------------*/ 130cdf0e10cSrcweir SwXTextView* SwView_Impl::GetUNOObject_Impl() 131cdf0e10cSrcweir { 132cdf0e10cSrcweir view::XSelectionSupplier* pTextView = pxXTextView->get(); 133cdf0e10cSrcweir return ((SwXTextView*)pTextView); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir /* -----------------------------29.05.00 09:04-------------------------------- 136cdf0e10cSrcweir 137cdf0e10cSrcweir ---------------------------------------------------------------------------*/ 138cdf0e10cSrcweir void SwView_Impl::ExecuteScan( SfxRequest& rReq ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir sal_uInt16 nSlot = rReq.GetSlot(); 141cdf0e10cSrcweir switch(nSlot) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir case SID_TWAIN_SELECT: 144cdf0e10cSrcweir { 145cdf0e10cSrcweir sal_Bool bDone = sal_False; 146cdf0e10cSrcweir Reference< XScannerManager > xScanMgr = SW_MOD()->GetScannerManager(); 147cdf0e10cSrcweir 148cdf0e10cSrcweir if( xScanMgr.is() ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir try 151cdf0e10cSrcweir { 152cdf0e10cSrcweir const Sequence< ScannerContext > 153cdf0e10cSrcweir aContexts( xScanMgr->getAvailableScanners() ); 154cdf0e10cSrcweir 155cdf0e10cSrcweir if( aContexts.getLength() ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir ScannerContext aContext( aContexts.getConstArray()[ 0 ] ); 158cdf0e10cSrcweir bDone = xScanMgr->configureScanner( aContext ); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir } 161cdf0e10cSrcweir catch(...) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir } 166cdf0e10cSrcweir if( bDone ) 167cdf0e10cSrcweir rReq.Done(); 168cdf0e10cSrcweir else 169cdf0e10cSrcweir { 170cdf0e10cSrcweir rReq.Ignore(); 171cdf0e10cSrcweir // KA 04.07.2002 172cdf0e10cSrcweir // InfoBox( 0, SW_RES(MSG_SCAN_NOSOURCE) ).Execute(); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir } 175cdf0e10cSrcweir break; 176cdf0e10cSrcweir 177cdf0e10cSrcweir case SID_TWAIN_TRANSFER: 178cdf0e10cSrcweir { 179cdf0e10cSrcweir sal_Bool bDone = sal_False; 180cdf0e10cSrcweir 181cdf0e10cSrcweir Reference< XScannerManager > xScanMgr = SW_MOD()->GetScannerManager(); 182cdf0e10cSrcweir if( xScanMgr.is() ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir SwScannerEventListener& rListener = GetScannerEventListener(); 185cdf0e10cSrcweir try 186cdf0e10cSrcweir { 187cdf0e10cSrcweir const Sequence< scanner::ScannerContext >aContexts( xScanMgr->getAvailableScanners() ); 188cdf0e10cSrcweir if( aContexts.getLength() ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir Reference< XEventListener > xLstner = &rListener; 191cdf0e10cSrcweir xScanMgr->startScan( aContexts.getConstArray()[ 0 ], xLstner ); 192cdf0e10cSrcweir bDone = sal_True; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir } 195cdf0e10cSrcweir catch(...) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir } 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir if( !bDone ) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir InfoBox( 0, SW_RES(MSG_SCAN_NOSOURCE) ).Execute(); 203cdf0e10cSrcweir rReq.Ignore(); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir else 206cdf0e10cSrcweir { 207cdf0e10cSrcweir rReq.Done(); 208cdf0e10cSrcweir SfxBindings& rBind = pView->GetViewFrame()->GetBindings(); 209cdf0e10cSrcweir rBind.Invalidate( SID_TWAIN_SELECT ); 210cdf0e10cSrcweir rBind.Invalidate( SID_TWAIN_TRANSFER ); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir } 213cdf0e10cSrcweir break; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir /* -----------------------------29.05.00 08:26-------------------------------- 218cdf0e10cSrcweir 219cdf0e10cSrcweir ---------------------------------------------------------------------------*/ 220cdf0e10cSrcweir SwScannerEventListener& SwView_Impl::GetScannerEventListener() 221cdf0e10cSrcweir { 222cdf0e10cSrcweir if(!xScanEvtLstnr.is()) 223cdf0e10cSrcweir xScanEvtLstnr = pScanEvtLstnr = new SwScannerEventListener(*pView); 224cdf0e10cSrcweir return *pScanEvtLstnr; 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir 228cdf0e10cSrcweir void SwView_Impl::AddClipboardListener() 229cdf0e10cSrcweir { 230cdf0e10cSrcweir if(!xClipEvtLstnr.is()) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir xClipEvtLstnr = pClipEvtLstnr = new SwClipboardChangeListener( *pView ); 233cdf0e10cSrcweir pClipEvtLstnr->AddRemoveListener( sal_True ); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir } 236cdf0e10cSrcweir /* -----------------3/31/2003 11:42AM---------------- 237cdf0e10cSrcweir 238cdf0e10cSrcweir --------------------------------------------------*/ 239cdf0e10cSrcweir void SwView_Impl::Invalidate() 240cdf0e10cSrcweir { 241cdf0e10cSrcweir GetUNOObject_Impl()->Invalidate(); 242cdf0e10cSrcweir Reference< XUnoTunnel > xTunnel(xTransferable.get(), UNO_QUERY); 243cdf0e10cSrcweir if(xTunnel.is()) 244cdf0e10cSrcweir 245cdf0e10cSrcweir { 246cdf0e10cSrcweir SwTransferable* pTransferable = reinterpret_cast< SwTransferable * >( 247cdf0e10cSrcweir sal::static_int_cast< sal_IntPtr >( 248cdf0e10cSrcweir xTunnel->getSomething(SwTransferable::getUnoTunnelId()))); 249cdf0e10cSrcweir if(pTransferable) 250cdf0e10cSrcweir pTransferable->Invalidate(); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir } 253cdf0e10cSrcweir /* -----------------3/31/2003 12:40PM---------------- 254cdf0e10cSrcweir 255cdf0e10cSrcweir --------------------------------------------------*/ 256cdf0e10cSrcweir void SwView_Impl::AddTransferable(SwTransferable& rTransferable) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir //prevent removing of the non-referenced SwTransferable 259cdf0e10cSrcweir rTransferable.m_refCount++;; 260cdf0e10cSrcweir { 261cdf0e10cSrcweir xTransferable = Reference<XUnoTunnel> (&rTransferable); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir rTransferable.m_refCount--; 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir void SwView_Impl::StartDocumentInserter( const String& rFactory, const Link& rEndDialogHdl ) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir delete m_pDocInserter; 269cdf0e10cSrcweir m_pDocInserter = new ::sfx2::DocumentInserter( 0, rFactory ); 270cdf0e10cSrcweir m_pDocInserter->StartExecuteModal( rEndDialogHdl ); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273cdf0e10cSrcweir SfxMedium* SwView_Impl::CreateMedium() 274cdf0e10cSrcweir { 275cdf0e10cSrcweir return m_pDocInserter->CreateMedium(); 276cdf0e10cSrcweir } 277cdf0e10cSrcweir 278cdf0e10cSrcweir void SwView_Impl::InitRequest( const SfxRequest& rRequest ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir delete m_pRequest; 281cdf0e10cSrcweir m_pRequest = new SfxRequest( rRequest ); 282cdf0e10cSrcweir } 283cdf0e10cSrcweir 284cdf0e10cSrcweir // ------------------------- SwScannerEventListener --------------------- 285cdf0e10cSrcweir 286cdf0e10cSrcweir SwScannerEventListener::~SwScannerEventListener() 287cdf0e10cSrcweir { 288cdf0e10cSrcweir } 289cdf0e10cSrcweir 290cdf0e10cSrcweir void SAL_CALL SwScannerEventListener::disposing( const EventObject& rEventObject) throw(uno::RuntimeException) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir vos::OGuard aGuard(Application::GetSolarMutex()); 293cdf0e10cSrcweir #if defined WNT || defined UNX 294cdf0e10cSrcweir if( pView ) 295cdf0e10cSrcweir pView->ScannerEventHdl( rEventObject ); 296cdf0e10cSrcweir #endif 297cdf0e10cSrcweir } 298cdf0e10cSrcweir 299cdf0e10cSrcweir // ------------------------- SwClipboardChangeListener --------------------- 300cdf0e10cSrcweir 301cdf0e10cSrcweir SwClipboardChangeListener::~SwClipboardChangeListener() 302cdf0e10cSrcweir { 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir void SAL_CALL SwClipboardChangeListener::disposing( const EventObject& /*rEventObject*/ ) 306cdf0e10cSrcweir throw ( RuntimeException ) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir void SAL_CALL SwClipboardChangeListener::changedContents( const CLIP_NMSPC::ClipboardEvent& rEventObject ) 311cdf0e10cSrcweir throw ( RuntimeException ) 312cdf0e10cSrcweir 313cdf0e10cSrcweir { 314cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 315cdf0e10cSrcweir if( pView ) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir { 318cdf0e10cSrcweir TransferableDataHelper aDataHelper( rEventObject.Contents ); 319cdf0e10cSrcweir SwWrtShell& rSh = pView->GetWrtShell(); 320cdf0e10cSrcweir 321cdf0e10cSrcweir pView->nLastPasteDestination = SwTransferable::GetSotDestination( rSh ); 322cdf0e10cSrcweir pView->bPasteState = aDataHelper.GetXTransferable().is() && 323cdf0e10cSrcweir SwTransferable::IsPaste( rSh, aDataHelper ); 324cdf0e10cSrcweir 325cdf0e10cSrcweir pView->bPasteSpecialState = aDataHelper.GetXTransferable().is() && 326cdf0e10cSrcweir SwTransferable::IsPasteSpecial( rSh, aDataHelper ); 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir SfxBindings& rBind = pView->GetViewFrame()->GetBindings(); 330cdf0e10cSrcweir rBind.Invalidate( SID_PASTE ); 331cdf0e10cSrcweir rBind.Invalidate( SID_PASTE_SPECIAL ); 332cdf0e10cSrcweir rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS ); 333cdf0e10cSrcweir } 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir void SwClipboardChangeListener::AddRemoveListener( sal_Bool bAdd ) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir pView->AddRemoveClipboardListener( Reference< XClipboardListener >( this ), bAdd ); 339cdf0e10cSrcweir } 340cdf0e10cSrcweir 341cdf0e10cSrcweir 342