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