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