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