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