LibreOffice Module sw (master)  1
uivwimp.cxx
Go to the documentation of this file.
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 #include <config_features.h>
21 
22 #include <cmdid.h>
23 #include <globals.hrc>
24 
25 #include <com/sun/star/scanner/XScannerManager2.hpp>
26 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
28 #include <vcl/weld.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/wrkwin.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/docfile.hxx>
34 
35 #include <sfx2/docinsert.hxx>
36 #include <sfx2/request.hxx>
37 #include <svx/svxids.hrc>
38 #include <uivwimp.hxx>
39 #include <wview.hxx>
40 #include <unotxvw.hxx>
41 #include <unodispatch.hxx>
42 #include <swmodule.hxx>
43 #include <swdtflvr.hxx>
44 #include <edtwin.hxx>
45 #include <mmconfigitem.hxx>
46 
47 #include <strings.hrc>
48 
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::scanner;
52 using namespace ::com::sun::star::lang;
54 
56  : mxXTextView()
57  , pView(pShell)
58  , eShellMode(ShellMode::Text)
59  , m_nParam(0)
60  , m_bSelectObject(false)
61  , m_bEditingPositionSet(false)
62 {
65 }
66 
68 {
69  Reference<XUnoTunnel> xDispTunnel(xDisProvInterceptor, UNO_QUERY);
70  SwXDispatchProviderInterceptor* pInterceptor = nullptr;
71  if(xDispTunnel.is() &&
72  nullptr != (pInterceptor = reinterpret_cast< SwXDispatchProviderInterceptor * >(
73  sal::static_int_cast< sal_IntPtr >(
74  xDispTunnel->getSomething(SwXDispatchProviderInterceptor::getUnoTunnelId())))))
75  {
76  pInterceptor->Invalidate();
77  }
78  view::XSelectionSupplier* pTextView = mxXTextView.get();
79  static_cast<SwXTextView*>(pTextView)->Invalidate();
80  mxXTextView.clear();
81  if( mxScanEvtLstnr.is() )
82  mxScanEvtLstnr->ViewDestroyed();
83  if( mxClipEvtLstnr.is() )
84  {
85  mxClipEvtLstnr->AddRemoveListener( false );
86  mxClipEvtLstnr->ViewDestroyed();
87  }
88 #if HAVE_FEATURE_DBCONNECTIVITY
89  xConfigItem.reset();
90 #endif
91  m_pDocInserter.reset();
92  m_pRequest.reset();
93 }
94 
96 {
97  eShellMode = eSet;
98 }
99 
100 view::XSelectionSupplier* SwView_Impl::GetUNOObject()
101 {
102  return mxXTextView.get();
103 }
104 
106 {
107  view::XSelectionSupplier* pTextView = mxXTextView.get();
108  return static_cast<SwXTextView*>(pTextView);
109 }
110 
112 {
113  switch(rReq.GetSlot())
114  {
115  case SID_TWAIN_SELECT:
116  {
117  bool bDone = false;
118  Reference< XScannerManager2 > xScanMgr = SW_MOD()->GetScannerManager();
119 
120  if( xScanMgr.is() )
121  {
122  try
123  {
125  const Sequence< ScannerContext >
126  aContexts( xScanMgr->getAvailableScanners() );
127 
128  if( aContexts.hasElements() )
129  {
130  Reference< XEventListener > xLstner = &rListener;
131  ScannerContext aContext( aContexts.getConstArray()[ 0 ] );
132 
133  Reference<lang::XInitialization> xInit(xScanMgr, UNO_QUERY);
134  if (xInit.is())
135  {
136  // initialize dialog
137  weld::Window* pWindow = rReq.GetFrameWeld();
138  uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
139  {
140  {"ParentWindow", pWindow ? uno::Any(pWindow->GetXWindow()) : uno::Any(Reference<awt::XWindow>())}
141  }));
142  xInit->initialize( aSeq );
143  }
144 
145  bDone = xScanMgr->configureScannerAndScan( aContext, xLstner );
146  }
147  }
148  catch(...)
149  {
150  }
151 
152  }
153  if( bDone )
154  rReq.Done();
155  else
156  {
157  rReq.Ignore();
158  }
159  }
160  break;
161 
162  case SID_TWAIN_TRANSFER:
163  {
164  bool bDone = false;
165 
166  Reference< XScannerManager2 > xScanMgr = SW_MOD()->GetScannerManager();
167  if( xScanMgr.is() )
168  {
170  try
171  {
172  const Sequence< scanner::ScannerContext >aContexts( xScanMgr->getAvailableScanners() );
173  if( aContexts.hasElements() )
174  {
175  Reference< XEventListener > xLstner = &rListener;
176  xScanMgr->startScan( aContexts.getConstArray()[ 0 ], xLstner );
177  bDone = true;
178  }
179  }
180  catch(...)
181  {
182  }
183  }
184 
185  if( !bDone )
186  {
187  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(rReq.GetFrameWeld(),
188  VclMessageType::Info, VclButtonsType::Ok,
189  SwResId(STR_SCAN_NOSOURCE)));
190  xBox->run();
191  rReq.Ignore();
192  }
193  else
194  {
195  rReq.Done();
196  SfxBindings& rBind = pView->GetViewFrame()->GetBindings();
197  rBind.Invalidate( SID_TWAIN_SELECT );
198  rBind.Invalidate( SID_TWAIN_TRANSFER );
199  }
200  }
201  break;
202  }
203 }
204 
206 {
207  if(!mxScanEvtLstnr.is())
209  return *mxScanEvtLstnr;
210 }
211 
213 {
214  if(!mxClipEvtLstnr.is())
215  {
217  mxClipEvtLstnr->AddRemoveListener( true );
218  }
219 }
220 
222 {
224  for (const auto& xTransferable: mxTransferables)
225  {
226  Reference< XUnoTunnel > xTunnel(xTransferable.get(), UNO_QUERY);
227  if(xTunnel.is())
228 
229  {
230  SwTransferable* pTransferable = reinterpret_cast< SwTransferable * >(
231  sal::static_int_cast< sal_IntPtr >(
232  xTunnel->getSomething(SwTransferable::getUnoTunnelId())));
233  if(pTransferable)
234  pTransferable->Invalidate();
235  }
236  }
237 }
238 
240 {
241  //prevent removing of the non-referenced SwTransferable
242  osl_atomic_increment(&rTransferable.m_refCount);
243  {
244  // Remove previously added, but no longer existing weak references.
245  mxTransferables.erase(std::remove_if(mxTransferables.begin(), mxTransferables.end(),
246  [](const css::uno::WeakReference<css::lang::XUnoTunnel>& rTunnel) {
247  uno::Reference<lang::XUnoTunnel> xTunnel(rTunnel.get(), uno::UNO_QUERY);
248  return !xTunnel.is();
249  }), mxTransferables.end());
250 
251  mxTransferables.emplace_back(uno::Reference<lang::XUnoTunnel>(&rTransferable));
252  }
253  osl_atomic_decrement(&rTransferable.m_refCount);
254 }
255 
257  const OUString& rFactory,
258  const Link<sfx2::FileDialogHelper*,void>& rEndDialogHdl,
259  const sal_uInt16 nSlotId
260 )
261 {
263  switch( nSlotId )
264  {
265  case SID_DOCUMENT_MERGE:
267  break;
268  case SID_DOCUMENT_COMPARE:
270  break;
271  default:
272  break;
273  }
274 
275  m_pDocInserter.reset(new ::sfx2::DocumentInserter(pView->GetFrameWeld(), rFactory, mode));
276  m_pDocInserter->StartExecuteModal( rEndDialogHdl );
277 }
278 
279 std::unique_ptr<SfxMedium> SwView_Impl::CreateMedium()
280 {
281  return m_pDocInserter->CreateMedium();
282 }
283 
284 void SwView_Impl::InitRequest( const SfxRequest& rRequest )
285 {
286  m_pRequest.reset(new SfxRequest( rRequest ));
287 }
288 
290 {
291 }
292 
293 void SAL_CALL SwScannerEventListener::disposing( const EventObject& /*rEventObject*/)
294 {
295 #if defined(_WIN32) || defined UNX
296  SolarMutexGuard aGuard;
297  if( pView )
299 #endif
300 }
301 
303 {
304 }
305 
306 void SAL_CALL SwClipboardChangeListener::disposing( const EventObject& /*rEventObject*/ )
307 {
308 }
309 
310 void SAL_CALL SwClipboardChangeListener::changedContents( const css::datatransfer::clipboard::ClipboardEvent& rEventObject )
311 
312 {
313  const SolarMutexGuard aGuard;
314  if( pView )
315  {
316  {
317  TransferableDataHelper aDataHelper( rEventObject.Contents );
318  SwWrtShell& rSh = pView->GetWrtShell();
319 
321  pView->m_bPasteState = aDataHelper.GetXTransferable().is() &&
322  SwTransferable::IsPaste( rSh, aDataHelper );
323 
324  pView->m_bPasteSpecialState = aDataHelper.GetXTransferable().is() &&
325  SwTransferable::IsPasteSpecial( rSh, aDataHelper );
326  }
327 
328  SfxBindings& rBind = pView->GetViewFrame()->GetBindings();
329  rBind.Invalidate( SID_PASTE );
330  rBind.Invalidate( SID_PASTE_SPECIAL );
331  rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
332  }
333 }
334 
336 {
337  pView->AddRemoveClipboardListener( Reference< XClipboardListener >( this ), bAdd );
338 }
339 
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
virtual ~SwScannerEventListener() override
Definition: uivwimp.cxx:289
SwXTextView * GetUNOObject_Impl()
Definition: uivwimp.cxx:105
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
void AddRemoveClipboardListener(const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > &, bool)
void InitRequest(const SfxRequest &rRequest)
Definition: uivwimp.cxx:284
void ExecuteScan(SfxRequest &rReq)
Definition: uivwimp.cxx:111
std::vector< css::uno::WeakReference< css::lang::XUnoTunnel > > mxTransferables
Definition: uivwimp.hxx:89
std::shared_ptr< SwMailMergeConfigItem > xConfigItem
Definition: uivwimp.hxx:103
static bool IsPaste(const SwWrtShell &, const TransferableDataHelper &)
Definition: swdtflvr.cxx:1270
void AddRemoveListener(bool bAdd)
Definition: uivwimp.cxx:335
void Done(bool bRemove=false)
void Invalidate(sal_uInt16 nId)
std::unique_ptr< sfx2::DocumentInserter > m_pDocInserter
Definition: uivwimp.hxx:105
void AddTransferable(SwTransferable &rTransferable)
Definition: uivwimp.cxx:239
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
void StartDocumentInserter(const OUString &rFactory, const Link< sfx2::FileDialogHelper *, void > &rEndDialogHdl, const sal_uInt16 nSlotId)
Definition: uivwimp.cxx:256
rtl::Reference< SwClipboardChangeListener > mxClipEvtLstnr
Definition: uivwimp.hxx:99
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
Used by the UI to modify the document model.
Definition: wrtsh.hxx:88
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: swdtflvr.cxx:3869
rtl::Reference< SwScannerEventListener > mxScanEvtLstnr
Definition: uivwimp.hxx:97
bool m_bPasteState
Definition: view.hxx:229
css::uno::Reference< css::frame::XDispatchProviderInterceptor > xDisProvInterceptor
Definition: uivwimp.hxx:87
static SotExchangeDest GetSotDestination(const SwWrtShell &rSh)
Definition: swdtflvr.cxx:1807
ShellMode
Definition: view.hxx:87
virtual void SAL_CALL disposing(const css::lang::EventObject &rEventObject) override
Definition: uivwimp.cxx:293
SotExchangeDest m_nLastPasteDestination
Definition: view.hxx:219
void SetShellMode(ShellMode eSet)
Definition: uivwimp.cxx:95
#define SW_MOD()
Definition: swmodule.hxx:256
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::uno::Reference< css::datatransfer::XTransferable > GetXTransferable() const
std::unique_ptr< SfxRequest > m_pRequest
Definition: uivwimp.hxx:106
virtual ~SwClipboardChangeListener() override
Definition: uivwimp.cxx:302
SfxBindings & GetBindings()
virtual void SAL_CALL disposing(const css::lang::EventObject &rEventObject) override
Definition: uivwimp.cxx:306
virtual void SAL_CALL changedContents(const css::datatransfer::clipboard::ClipboardEvent &rEventObject) override
Definition: uivwimp.cxx:310
static bool IsPasteSpecial(const SwWrtShell &rWrtShell, const TransferableDataHelper &)
Definition: swdtflvr.cxx:3070
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
void Invalidate()
Definition: unotxvw.cxx:108
void AddClipboardListener()
Definition: uivwimp.cxx:212
weld::Window * GetFrameWeld() const
css::uno::Reference< css::view::XSelectionSupplier > mxXTextView
Definition: uivwimp.hxx:88
sal_uInt16 GetSlot() const
void Invalidate()
Definition: swdtflvr.hxx:224
weld::Window * GetFrameWeld() const
bool m_bPasteSpecialState
Definition: view.hxx:229
css::view::XSelectionSupplier * GetUNOObject()
Definition: uivwimp.cxx:100
void Invalidate()
Definition: uivwimp.cxx:221
SwScannerEventListener & GetScannerEventListener()
Definition: uivwimp.cxx:205
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
SwView_Impl(SwView *pShell)
Definition: uivwimp.cxx:55
void ScannerEventHdl()
Definition: view.cxx:1727
ShellMode eShellMode
Definition: uivwimp.hxx:100
std::unique_ptr< SfxMedium > CreateMedium()
Definition: uivwimp.cxx:279
~SwView_Impl()
Definition: uivwimp.cxx:67
void Ignore()
SwView * pView
Definition: uivwimp.hxx:95
Definition: view.hxx:146