Branch data 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 : 1318 : SwView_Impl::SwView_Impl(SwView* pShell) :
57 : 1318 : 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 [ + - ]: 2636 : m_bEditingPositionSet(false)
67 : : {
68 [ + - ][ + - ]: 1318 : *pxXTextView = new SwXTextView(pView);
69 [ + - ][ + - ]: 1318 : xDisProvInterceptor = new SwXDispatchProviderInterceptor(*pView);
[ + - ]
70 : 1318 : }
71 : :
72 [ + - ][ + - ]: 1231 : SwView_Impl::~SwView_Impl()
73 : : {
74 [ + - ]: 1231 : Reference<XUnoTunnel> xDispTunnel(xDisProvInterceptor, UNO_QUERY);
75 : 1231 : SwXDispatchProviderInterceptor* pInterceptor = 0;
76 [ + - + - ]: 2462 : if(xDispTunnel.is() &&
[ + - ]
77 : : 0 != (pInterceptor = reinterpret_cast< SwXDispatchProviderInterceptor * >(
78 : : sal::static_int_cast< sal_IntPtr >(
79 [ + - ][ + - ]: 1231 : xDispTunnel->getSomething(SwXDispatchProviderInterceptor::getUnoTunnelId())))))
[ + - ]
80 : : {
81 [ + - ]: 1231 : pInterceptor->Invalidate();
82 : : }
83 [ + - ]: 1231 : view::XSelectionSupplier* pTextView = pxXTextView->get();
84 [ + - ]: 1231 : ((SwXTextView*)pTextView)->Invalidate();
85 [ + - ]: 1231 : delete pxXTextView;
86 [ - + ]: 1231 : if( xScanEvtLstnr.is() )
87 : 0 : pScanEvtLstnr->ViewDestroyed();
88 [ + + ]: 1231 : if( xClipEvtLstnr.is() )
89 : : {
90 [ + - ]: 747 : pClipEvtLstnr->AddRemoveListener( sal_False );
91 : 747 : pClipEvtLstnr->ViewDestroyed();
92 : : }
93 [ - + ][ # # ]: 1231 : delete pConfigItem;
94 : :
95 [ - + ][ # # ]: 1231 : delete m_pDocInserter;
96 [ - + ][ # # ]: 1231 : delete m_pRequest;
97 : 1231 : }
98 : :
99 : 1314 : void SwView_Impl::SetShellMode(ShellModes eSet)
100 : : {
101 : 1314 : eShellMode = eSet;
102 : 1314 : }
103 : :
104 : 6 : view::XSelectionSupplier* SwView_Impl::GetUNOObject()
105 : : {
106 : 6 : return pxXTextView->get();
107 : : }
108 : :
109 : 22120 : SwXTextView* SwView_Impl::GetUNOObject_Impl()
110 : : {
111 : 22120 : view::XSelectionSupplier* pTextView = pxXTextView->get();
112 : 22120 : 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 : 747 : void SwView_Impl::AddClipboardListener()
202 : : {
203 [ + - ]: 747 : if(!xClipEvtLstnr.is())
204 : : {
205 [ + - ][ + - ]: 747 : xClipEvtLstnr = pClipEvtLstnr = new SwClipboardChangeListener( *pView );
206 : 747 : pClipEvtLstnr->AddRemoveListener( sal_True );
207 : : }
208 : 747 : }
209 : :
210 : 1231 : void SwView_Impl::Invalidate()
211 : : {
212 [ + - ][ + - ]: 1231 : GetUNOObject_Impl()->Invalidate();
213 [ + - ][ + - ]: 1231 : Reference< XUnoTunnel > xTunnel(xTransferable.get(), UNO_QUERY);
214 [ + + ]: 1231 : if(xTunnel.is())
215 : :
216 : : {
217 : : SwTransferable* pTransferable = reinterpret_cast< SwTransferable * >(
218 : : sal::static_int_cast< sal_IntPtr >(
219 [ + - ][ + - ]: 4 : xTunnel->getSomething(SwTransferable::getUnoTunnelId())));
[ + - ]
220 [ + - ]: 4 : if(pTransferable)
221 : 4 : pTransferable->Invalidate();
222 : 1231 : }
223 : 1231 : }
224 : :
225 : 20 : void SwView_Impl::AddTransferable(SwTransferable& rTransferable)
226 : : {
227 : : //prevent removing of the non-referenced SwTransferable
228 : 20 : rTransferable.m_refCount++;
229 : : {
230 [ + - ]: 20 : xTransferable = Reference<XUnoTunnel> (&rTransferable);
231 : : }
232 : 20 : rTransferable.m_refCount--;
233 : 20 : }
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 : 747 : SwClipboardChangeListener::~SwClipboardChangeListener()
267 : : {
268 [ - + ]: 1494 : }
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 : 1494 : void SwClipboardChangeListener::AddRemoveListener( sal_Bool bAdd )
302 : : {
303 [ + - ]: 1494 : pView->AddRemoveClipboardListener( Reference< XClipboardListener >( this ), bAdd );
304 : 1494 : }
305 : :
306 : :
307 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|