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