docthemes: Save themes def. to a file when added to ColorSets
[LibreOffice.git] / sw / source / uibase / uiview / uivwimp.cxx
blob01dc4f856c068a90e58d31301fde0a29f35928db
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <config_features.h>
21 #include <config_fuzzers.h>
23 #include <cmdid.h>
25 #include <com/sun/star/scanner/XScannerManager2.hpp>
26 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
27 #include <comphelper/propertysequence.hxx>
28 #include <comphelper/servicehelper.hxx>
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>
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>
43 #include <strings.hrc>
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::scanner;
48 using namespace ::com::sun::star::lang;
49 using namespace ::com::sun::star::datatransfer::clipboard;
51 SwView_Impl::SwView_Impl(SwView* pShell)
52 : m_pView(pShell)
53 , m_eShellMode(ShellMode::Text)
54 , m_nParam(0)
55 , m_bSelectObject(false)
56 , m_bEditingPositionSet(false)
58 mxXTextView = new SwXTextView(m_pView);
59 m_xDispatchProviderInterceptor = new SwXDispatchProviderInterceptor(*m_pView);
62 SwView_Impl::~SwView_Impl()
64 if(m_xDispatchProviderInterceptor)
65 m_xDispatchProviderInterceptor->Invalidate();
66 mxXTextView->Invalidate();
67 mxXTextView.clear();
69 if( mxScanEvtLstnr.is() )
70 mxScanEvtLstnr->ViewDestroyed();
71 if( mxClipEvtLstnr.is() )
73 mxClipEvtLstnr->AddRemoveListener( false );
74 mxClipEvtLstnr->ViewDestroyed();
76 DisconnectTransferableDDE();
78 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
79 m_xConfigItem.reset();
80 #endif
81 m_pDocInserter.reset();
82 m_pRequest.reset();
85 void SwView_Impl::SetShellMode(ShellMode eSet)
87 m_eShellMode = eSet;
90 view::XSelectionSupplier* SwView_Impl::GetUNOObject()
92 return mxXTextView.get();
95 SwXTextView* SwView_Impl::GetUNOObject_Impl()
97 return mxXTextView.get();
100 void SwView_Impl::ExecuteScan( SfxRequest& rReq )
102 switch(rReq.GetSlot())
104 case SID_TWAIN_SELECT:
106 bool bDone = false;
107 Reference<XScannerManager2> xScanMgr = SwModule::get()->GetScannerManager();
109 if( xScanMgr.is() )
113 SwScannerEventListener& rListener = GetScannerEventListener();
114 const Sequence< ScannerContext >
115 aContexts( xScanMgr->getAvailableScanners() );
117 if( aContexts.hasElements() )
119 Reference< XEventListener > xLstner = &rListener;
120 ScannerContext aContext( aContexts.getConstArray()[ 0 ] );
122 Reference<lang::XInitialization> xInit(xScanMgr, UNO_QUERY);
123 if (xInit.is())
125 // initialize dialog
126 weld::Window* pWindow = rReq.GetFrameWeld();
127 uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
129 {"ParentWindow", pWindow ? uno::Any(pWindow->GetXWindow()) : uno::Any(Reference<awt::XWindow>())}
130 }));
131 xInit->initialize( aSeq );
134 bDone = xScanMgr->configureScannerAndScan( aContext, xLstner );
137 catch(...)
142 if( bDone )
143 rReq.Done();
144 else
146 rReq.Ignore();
149 break;
151 case SID_TWAIN_TRANSFER:
153 bool bDone = false;
155 Reference<XScannerManager2> xScanMgr = SwModule::get()->GetScannerManager();
156 if( xScanMgr.is() )
158 SwScannerEventListener& rListener = GetScannerEventListener();
161 const Sequence< scanner::ScannerContext >aContexts( xScanMgr->getAvailableScanners() );
162 if( aContexts.hasElements() )
164 Reference< XEventListener > xLstner = &rListener;
165 xScanMgr->startScan( aContexts.getConstArray()[ 0 ], xLstner );
166 bDone = true;
169 catch(...)
174 if( !bDone )
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();
182 else
184 rReq.Done();
185 SfxBindings& rBind = m_pView->GetViewFrame().GetBindings();
186 rBind.Invalidate( SID_TWAIN_SELECT );
187 rBind.Invalidate( SID_TWAIN_TRANSFER );
190 break;
194 SwScannerEventListener& SwView_Impl::GetScannerEventListener()
196 if(!mxScanEvtLstnr.is())
197 mxScanEvtLstnr = new SwScannerEventListener(*m_pView);
198 return *mxScanEvtLstnr;
201 void SwView_Impl::AddClipboardListener()
203 if(!mxClipEvtLstnr.is())
205 mxClipEvtLstnr = new SwClipboardChangeListener( *m_pView );
206 mxClipEvtLstnr->AddRemoveListener( true );
210 void SwView_Impl::Invalidate()
212 GetUNOObject_Impl()->Invalidate();
213 for (const auto& xTransferable: mxTransferables)
215 rtl::Reference<SwTransferable> pTransferable = xTransferable.get();
216 if(pTransferable)
217 pTransferable->Invalidate();
221 void SwView_Impl::DisconnectTransferableDDE()
223 for (const auto& xTransferable: mxTransferables)
225 rtl::Reference<SwTransferable> pTransferable = xTransferable.get();
226 if(pTransferable)
227 pTransferable->DisconnectDDE();
231 void SwView_Impl::AddTransferable(SwTransferable& rTransferable)
233 //prevent removing of the non-referenced SwTransferable
234 osl_atomic_increment(&rTransferable.m_refCount);
236 // Remove previously added, but no longer existing weak references.
237 std::erase_if(mxTransferables,
238 [](const unotools::WeakReference<SwTransferable>& rTunnel) {
239 return !rTunnel.get();
242 mxTransferables.emplace_back(&rTransferable);
244 osl_atomic_decrement(&rTransferable.m_refCount);
247 void SwView_Impl::StartDocumentInserter(
248 const OUString& rFactory,
249 const Link<sfx2::FileDialogHelper*,void>& rEndDialogHdl,
250 const sal_uInt16 nSlotId
253 sfx2::DocumentInserter::Mode mode {sfx2::DocumentInserter::Mode::Insert};
254 switch( nSlotId )
256 case SID_DOCUMENT_MERGE:
257 mode = sfx2::DocumentInserter::Mode::Merge;
258 break;
259 case SID_DOCUMENT_COMPARE:
260 mode = sfx2::DocumentInserter::Mode::Compare;
261 break;
262 default:
263 break;
266 m_pDocInserter.reset(new ::sfx2::DocumentInserter(m_pView->GetFrameWeld(), rFactory, mode));
267 m_pDocInserter->StartExecuteModal( rEndDialogHdl );
270 std::unique_ptr<SfxMedium> SwView_Impl::CreateMedium()
272 return m_pDocInserter->CreateMedium();
275 void SwView_Impl::InitRequest( const SfxRequest& rRequest )
277 m_pRequest.reset(new SfxRequest( rRequest ));
280 SwScannerEventListener::~SwScannerEventListener()
284 void SAL_CALL SwScannerEventListener::disposing( const EventObject& /*rEventObject*/)
286 #if defined(_WIN32) || defined UNX
287 SolarMutexGuard aGuard;
288 if( m_pView )
289 m_pView->ScannerEventHdl();
290 #endif
293 SwClipboardChangeListener::~SwClipboardChangeListener()
297 void SAL_CALL SwClipboardChangeListener::disposing( const EventObject& /*rEventObject*/ )
299 SolarMutexGuard aGuard;
300 m_pView = nullptr; // so we don't touch the view if changedContents somehow fires afterwards
303 void SAL_CALL SwClipboardChangeListener::changedContents( const css::datatransfer::clipboard::ClipboardEvent& rEventObject )
306 const SolarMutexGuard aGuard;
307 if( !m_pView )
308 return;
311 TransferableDataHelper aDataHelper( rEventObject.Contents );
312 SwWrtShell& rSh = m_pView->GetWrtShell();
314 m_pView->m_nLastPasteDestination = SwTransferable::GetSotDestination( rSh );
315 m_pView->m_bPasteState = aDataHelper.GetXTransferable().is() &&
316 SwTransferable::IsPaste( rSh, aDataHelper );
318 m_pView->m_bPasteSpecialState = aDataHelper.GetXTransferable().is() &&
319 SwTransferable::IsPasteSpecial( rSh, aDataHelper );
322 SfxBindings& rBind = m_pView->GetViewFrame().GetBindings();
323 rBind.Invalidate( SID_PASTE );
324 rBind.Invalidate( SID_PASTE_SPECIAL );
325 rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
328 void SwClipboardChangeListener::AddRemoveListener( bool bAdd )
330 m_pView->AddRemoveClipboardListener( Reference< XClipboardListener >( this ), bAdd );
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */