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#include <config_fuzzers.h>
22
23#include <cmdid.h>
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 <uivwimp.hxx>
38#include <unotxvw.hxx>
39#include <unodispatch.hxx>
40#include <swmodule.hxx>
41#include <swdtflvr.hxx>
42
43#include <strings.hrc>
44
45using namespace ::com::sun::star;
46using namespace ::com::sun::star::uno;
47using namespace ::com::sun::star::scanner;
48using namespace ::com::sun::star::lang;
50
52 : m_pView(pShell)
53 , m_eShellMode(ShellMode::Text)
54 , m_nParam(0)
55 , m_bSelectObject(false)
56 , m_bEditingPositionSet(false)
57{
60}
61
63{
64 auto pInterceptor = comphelper::getFromUnoTunnel<SwXDispatchProviderInterceptor>(m_xDispatchProviderInterceptor);
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 && !ENABLE_FUZZERS
78 m_xConfigItem.reset();
79#endif
80 m_pDocInserter.reset();
81 m_pRequest.reset();
82}
83
85{
86 m_eShellMode = eSet;
87}
88
89view::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();
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::getFromUnoTunnel<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(&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(m_pView->GetFrameWeld(), rFactory, mode));
258 m_pDocInserter->StartExecuteModal( rEndDialogHdl );
259}
260
261std::unique_ptr<SfxMedium> SwView_Impl::CreateMedium()
262{
263 return m_pDocInserter->CreateMedium();
264}
265
267{
268 m_pRequest.reset(new SfxRequest( rRequest ));
269}
270
272{
273}
274
275void SAL_CALL SwScannerEventListener::disposing( const EventObject& /*rEventObject*/)
276{
277#if defined(_WIN32) || defined UNX
278 SolarMutexGuard aGuard;
279 if( m_pView )
281#endif
282}
283
285{
286}
287
288void SAL_CALL SwClipboardChangeListener::disposing( const EventObject& /*rEventObject*/ )
289{
290 SolarMutexGuard aGuard;
291 m_pView = nullptr; // so we don't touch the view if changedContents somehow fires afterwards
292}
293
294void SAL_CALL SwClipboardChangeListener::changedContents( const css::datatransfer::clipboard::ClipboardEvent& rEventObject )
295
296{
297 const SolarMutexGuard aGuard;
298 if( !m_pView )
299 return;
300
301 {
302 TransferableDataHelper aDataHelper( rEventObject.Contents );
304
306 m_pView->m_bPasteState = aDataHelper.GetXTransferable().is() &&
307 SwTransferable::IsPaste( rSh, aDataHelper );
308
309 m_pView->m_bPasteSpecialState = aDataHelper.GetXTransferable().is() &&
310 SwTransferable::IsPasteSpecial( rSh, aDataHelper );
311 }
312
314 rBind.Invalidate( SID_PASTE );
315 rBind.Invalidate( SID_PASTE_SPECIAL );
316 rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
317}
318
320{
321 m_pView->AddRemoveClipboardListener( Reference< XClipboardListener >( this ), bAdd );
322}
323
324/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
void Invalidate(sal_uInt16 nId)
sal_uInt16 GetSlot() const
void Ignore()
weld::Window * GetFrameWeld() const
void Done(bool bRemove=false)
SfxBindings & GetBindings()
weld::Window * GetFrameWeld() const
SfxViewFrame * GetViewFrame() const
void AddRemoveClipboardListener(const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > &, bool)
virtual ~SwClipboardChangeListener() override
Definition: uivwimp.cxx:284
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:294
void AddRemoveListener(bool bAdd)
Definition: uivwimp.cxx:319
virtual ~SwScannerEventListener() override
Definition: uivwimp.cxx:271
virtual void SAL_CALL disposing(const css::lang::EventObject &rEventObject) override
Definition: uivwimp.cxx:275
static bool IsPasteSpecial(const SwWrtShell &rWrtShell, const TransferableDataHelper &)
Definition: swdtflvr.cxx:3366
static SotExchangeDest GetSotDestination(const SwWrtShell &rSh)
Definition: swdtflvr.cxx:2083
static bool IsPaste(const SwWrtShell &, const TransferableDataHelper &)
Definition: swdtflvr.cxx:1374
ShellMode m_eShellMode
Definition: uivwimp.hxx:100
~SwView_Impl()
Definition: uivwimp.cxx:62
rtl::Reference< SwScannerEventListener > mxScanEvtLstnr
Definition: uivwimp.hxx:97
void SetShellMode(ShellMode eSet)
Definition: uivwimp.cxx:84
std::unique_ptr< SfxRequest > m_pRequest
Definition: uivwimp.hxx:106
css::view::XSelectionSupplier * GetUNOObject()
Definition: uivwimp.cxx:89
SwView * m_pView
Definition: uivwimp.hxx:95
SwView_Impl(SwView *pShell)
Definition: uivwimp.cxx:51
void StartDocumentInserter(const OUString &rFactory, const Link< sfx2::FileDialogHelper *, void > &rEndDialogHdl, const sal_uInt16 nSlotId)
Definition: uivwimp.cxx:238
void AddTransferable(SwTransferable &rTransferable)
Definition: uivwimp.cxx:221
void AddClipboardListener()
Definition: uivwimp.cxx:201
std::vector< css::uno::WeakReference< css::lang::XUnoTunnel > > mxTransferables
Definition: uivwimp.hxx:89
SwXTextView * GetUNOObject_Impl()
Definition: uivwimp.cxx:94
std::unique_ptr< sfx2::DocumentInserter > m_pDocInserter
Definition: uivwimp.hxx:105
void InitRequest(const SfxRequest &rRequest)
Definition: uivwimp.cxx:266
SwScannerEventListener & GetScannerEventListener()
Definition: uivwimp.cxx:194
void ExecuteScan(SfxRequest &rReq)
Definition: uivwimp.cxx:100
css::uno::Reference< css::view::XSelectionSupplier > mxXTextView
Definition: uivwimp.hxx:88
css::uno::Reference< css::frame::XDispatchProviderInterceptor > m_xDispatchProviderInterceptor
Definition: uivwimp.hxx:87
std::unique_ptr< SfxMedium > CreateMedium()
Definition: uivwimp.cxx:261
std::shared_ptr< SwMailMergeConfigItem > m_xConfigItem
Definition: uivwimp.hxx:103
rtl::Reference< SwClipboardChangeListener > mxClipEvtLstnr
Definition: uivwimp.hxx:99
void Invalidate()
Definition: uivwimp.cxx:210
Definition: view.hxx:145
void ScannerEventHdl()
Definition: view.cxx:1782
SotExchangeDest m_nLastPasteDestination
Definition: view.hxx:230
bool m_bPasteState
Definition: view.hxx:254
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
bool m_bPasteSpecialState
Definition: view.hxx:255
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
void Invalidate()
Definition: unotxvw.cxx:100
css::uno::Reference< css::datatransfer::XTransferable > GetXTransferable() const
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
Sequence< sal_Int8 > aSeq
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
ConversionMode mode
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
#define SW_MOD()
Definition: swmodule.hxx:256
ShellMode
Definition: view.hxx:86