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