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{
66 mxXTextView->Invalidate();
67 mxXTextView.clear();
68 if( mxScanEvtLstnr.is() )
69 mxScanEvtLstnr->ViewDestroyed();
70 if( mxClipEvtLstnr.is() )
71 {
72 mxClipEvtLstnr->AddRemoveListener( false );
73 mxClipEvtLstnr->ViewDestroyed();
74 }
75#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
76 m_xConfigItem.reset();
77#endif
78 m_pDocInserter.reset();
79 m_pRequest.reset();
80}
81
83{
84 m_eShellMode = eSet;
85}
86
87view::XSelectionSupplier* SwView_Impl::GetUNOObject()
88{
89 return mxXTextView.get();
90}
91
93{
94 return mxXTextView.get();
95}
96
98{
99 switch(rReq.GetSlot())
100 {
101 case SID_TWAIN_SELECT:
102 {
103 bool bDone = false;
104 Reference< XScannerManager2 > xScanMgr = SW_MOD()->GetScannerManager();
105
106 if( xScanMgr.is() )
107 {
108 try
109 {
111 const Sequence< ScannerContext >
112 aContexts( xScanMgr->getAvailableScanners() );
113
114 if( aContexts.hasElements() )
115 {
116 Reference< XEventListener > xLstner = &rListener;
117 ScannerContext aContext( aContexts.getConstArray()[ 0 ] );
118
119 Reference<lang::XInitialization> xInit(xScanMgr, UNO_QUERY);
120 if (xInit.is())
121 {
122 // initialize dialog
123 weld::Window* pWindow = rReq.GetFrameWeld();
124 uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
125 {
126 {"ParentWindow", pWindow ? uno::Any(pWindow->GetXWindow()) : uno::Any(Reference<awt::XWindow>())}
127 }));
128 xInit->initialize( aSeq );
129 }
130
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(rReq.GetFrameWeld(),
174 VclMessageType::Info, VclButtonsType::Ok,
175 SwResId(STR_SCAN_NOSOURCE)));
176 xBox->run();
177 rReq.Ignore();
178 }
179 else
180 {
181 rReq.Done();
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 rtl::Reference<SwTransferable> pTransferable = xTransferable.get();
213 if(pTransferable)
214 pTransferable->Invalidate();
215 }
216}
217
219{
220 //prevent removing of the non-referenced SwTransferable
221 osl_atomic_increment(&rTransferable.m_refCount);
222 {
223 // Remove previously added, but no longer existing weak references.
224 mxTransferables.erase(std::remove_if(mxTransferables.begin(), mxTransferables.end(),
225 [](const unotools::WeakReference<SwTransferable>& rTunnel) {
226 return !rTunnel.get();
227 }), mxTransferables.end());
228
229 mxTransferables.emplace_back(&rTransferable);
230 }
231 osl_atomic_decrement(&rTransferable.m_refCount);
232}
233
235 const OUString& rFactory,
236 const Link<sfx2::FileDialogHelper*,void>& rEndDialogHdl,
237 const sal_uInt16 nSlotId
238)
239{
241 switch( nSlotId )
242 {
243 case SID_DOCUMENT_MERGE:
245 break;
246 case SID_DOCUMENT_COMPARE:
248 break;
249 default:
250 break;
251 }
252
253 m_pDocInserter.reset(new ::sfx2::DocumentInserter(m_pView->GetFrameWeld(), rFactory, mode));
254 m_pDocInserter->StartExecuteModal( rEndDialogHdl );
255}
256
257std::unique_ptr<SfxMedium> SwView_Impl::CreateMedium()
258{
259 return m_pDocInserter->CreateMedium();
260}
261
263{
264 m_pRequest.reset(new SfxRequest( rRequest ));
265}
266
268{
269}
270
271void SAL_CALL SwScannerEventListener::disposing( const EventObject& /*rEventObject*/)
272{
273#if defined(_WIN32) || defined UNX
274 SolarMutexGuard aGuard;
275 if( m_pView )
277#endif
278}
279
281{
282}
283
284void SAL_CALL SwClipboardChangeListener::disposing( const EventObject& /*rEventObject*/ )
285{
286 SolarMutexGuard aGuard;
287 m_pView = nullptr; // so we don't touch the view if changedContents somehow fires afterwards
288}
289
290void SAL_CALL SwClipboardChangeListener::changedContents( const css::datatransfer::clipboard::ClipboardEvent& rEventObject )
291
292{
293 const SolarMutexGuard aGuard;
294 if( !m_pView )
295 return;
296
297 {
298 TransferableDataHelper aDataHelper( rEventObject.Contents );
300
302 m_pView->m_bPasteState = aDataHelper.GetXTransferable().is() &&
303 SwTransferable::IsPaste( rSh, aDataHelper );
304
305 m_pView->m_bPasteSpecialState = aDataHelper.GetXTransferable().is() &&
306 SwTransferable::IsPasteSpecial( rSh, aDataHelper );
307 }
308
310 rBind.Invalidate( SID_PASTE );
311 rBind.Invalidate( SID_PASTE_SPECIAL );
312 rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
313}
314
316{
317 m_pView->AddRemoveClipboardListener( Reference< XClipboardListener >( this ), bAdd );
318}
319
320/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
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:280
virtual void SAL_CALL disposing(const css::lang::EventObject &rEventObject) override
Definition: uivwimp.cxx:284
virtual void SAL_CALL changedContents(const css::datatransfer::clipboard::ClipboardEvent &rEventObject) override
Definition: uivwimp.cxx:290
void AddRemoveListener(bool bAdd)
Definition: uivwimp.cxx:315
virtual ~SwScannerEventListener() override
Definition: uivwimp.cxx:267
virtual void SAL_CALL disposing(const css::lang::EventObject &rEventObject) override
Definition: uivwimp.cxx:271
static bool IsPasteSpecial(const SwWrtShell &rWrtShell, const TransferableDataHelper &)
Definition: swdtflvr.cxx:3383
static SotExchangeDest GetSotDestination(const SwWrtShell &rSh)
Definition: swdtflvr.cxx:2100
static bool IsPaste(const SwWrtShell &, const TransferableDataHelper &)
Definition: swdtflvr.cxx:1367
ShellMode m_eShellMode
Definition: uivwimp.hxx:102
~SwView_Impl()
Definition: uivwimp.cxx:62
rtl::Reference< SwScannerEventListener > mxScanEvtLstnr
Definition: uivwimp.hxx:99
void SetShellMode(ShellMode eSet)
Definition: uivwimp.cxx:82
std::unique_ptr< SfxRequest > m_pRequest
Definition: uivwimp.hxx:108
rtl::Reference< SwXTextView > mxXTextView
Definition: uivwimp.hxx:90
rtl::Reference< SwXDispatchProviderInterceptor > m_xDispatchProviderInterceptor
Definition: uivwimp.hxx:89
std::vector< unotools::WeakReference< SwTransferable > > mxTransferables
Definition: uivwimp.hxx:91
css::view::XSelectionSupplier * GetUNOObject()
Definition: uivwimp.cxx:87
SwView * m_pView
Definition: uivwimp.hxx:97
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:234
void AddTransferable(SwTransferable &rTransferable)
Definition: uivwimp.cxx:218
void AddClipboardListener()
Definition: uivwimp.cxx:198
SwXTextView * GetUNOObject_Impl()
Definition: uivwimp.cxx:92
std::unique_ptr< sfx2::DocumentInserter > m_pDocInserter
Definition: uivwimp.hxx:107
void InitRequest(const SfxRequest &rRequest)
Definition: uivwimp.cxx:262
SwScannerEventListener & GetScannerEventListener()
Definition: uivwimp.cxx:191
void ExecuteScan(SfxRequest &rReq)
Definition: uivwimp.cxx:97
std::unique_ptr< SfxMedium > CreateMedium()
Definition: uivwimp.cxx:257
std::shared_ptr< SwMailMergeConfigItem > m_xConfigItem
Definition: uivwimp.hxx:105
rtl::Reference< SwClipboardChangeListener > mxClipEvtLstnr
Definition: uivwimp.hxx:101
void Invalidate()
Definition: uivwimp.cxx:207
Definition: view.hxx:146
void ScannerEventHdl()
Definition: view.cxx:1806
SotExchangeDest m_nLastPasteDestination
Definition: view.hxx:229
bool m_bPasteState
Definition: view.hxx:255
SwWrtShell & GetWrtShell() const
Definition: view.hxx:423
bool m_bPasteSpecialState
Definition: view.hxx:256
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
void Invalidate()
Definition: unotxvw.cxx:101
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:168
#define SW_MOD()
Definition: swmodule.hxx:254
ShellMode
Definition: view.hxx:87