1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include "globals.hrc"
24 #include <tools/shl.hxx>
25 #include <com/sun/star/scanner/XScannerManager2.hpp>
26 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
27 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <comphelper/processfactory.hxx>
30 #include <osl/mutex.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/wrkwin.hxx>
33 #include <vcl/msgbox.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/bindings.hxx>
37 #include <sfx2/docinsert.hxx>
38 #include <sfx2/request.hxx>
39 #include <uivwimp.hxx>
41 #include <unotxvw.hxx>
42 #include <unodispatch.hxx>
43 #include <swmodule.hxx>
44 #include <swdtflvr.hxx>
46 #include <mmconfigitem.hxx>
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::scanner
;
53 using namespace ::com::sun::star::lang
;
54 using namespace ::com::sun::star::datatransfer::clipboard
;
56 SwView_Impl::SwView_Impl(SwView
* pShell
) :
57 pxXTextView(new uno::Reference
<view::XSelectionSupplier
>),
59 eShellMode(SHELL_MODE_TEXT
),
61 nMailMergeRestartPage(0),
62 bMailMergeSourceView(sal_True
),
65 m_bSelectObject(false),
66 m_bEditingPositionSet(false)
68 *pxXTextView
= new SwXTextView(pView
);
69 xDisProvInterceptor
= new SwXDispatchProviderInterceptor(*pView
);
72 SwView_Impl::~SwView_Impl()
74 Reference
<XUnoTunnel
> xDispTunnel(xDisProvInterceptor
, UNO_QUERY
);
75 SwXDispatchProviderInterceptor
* pInterceptor
= 0;
76 if(xDispTunnel
.is() &&
77 0 != (pInterceptor
= reinterpret_cast< SwXDispatchProviderInterceptor
* >(
78 sal::static_int_cast
< sal_IntPtr
>(
79 xDispTunnel
->getSomething(SwXDispatchProviderInterceptor::getUnoTunnelId())))))
81 pInterceptor
->Invalidate();
83 view::XSelectionSupplier
* pTextView
= pxXTextView
->get();
84 ((SwXTextView
*)pTextView
)->Invalidate();
86 if( xScanEvtLstnr
.is() )
87 pScanEvtLstnr
->ViewDestroyed();
88 if( xClipEvtLstnr
.is() )
90 pClipEvtLstnr
->AddRemoveListener( sal_False
);
91 pClipEvtLstnr
->ViewDestroyed();
95 delete m_pDocInserter
;
99 void SwView_Impl::SetShellMode(ShellModes eSet
)
104 view::XSelectionSupplier
* SwView_Impl::GetUNOObject()
106 return pxXTextView
->get();
109 SwXTextView
* SwView_Impl::GetUNOObject_Impl()
111 view::XSelectionSupplier
* pTextView
= pxXTextView
->get();
112 return ((SwXTextView
*)pTextView
);
115 void SwView_Impl::ExecuteScan( SfxRequest
& rReq
)
117 sal_uInt16 nSlot
= rReq
.GetSlot();
120 case SID_TWAIN_SELECT
:
122 sal_Bool bDone
= sal_False
;
123 Reference
< XScannerManager2
> xScanMgr
= SW_MOD()->GetScannerManager();
129 SwScannerEventListener
& rListener
= GetScannerEventListener();
130 const Sequence
< ScannerContext
>
131 aContexts( xScanMgr
->getAvailableScanners() );
133 if( aContexts
.getLength() )
135 Reference
< XEventListener
> xLstner
= &rListener
;
136 ScannerContext
aContext( aContexts
.getConstArray()[ 0 ] );
137 bDone
= xScanMgr
->configureScannerAndScan( aContext
, xLstner
);
154 case SID_TWAIN_TRANSFER
:
158 Reference
< XScannerManager2
> xScanMgr
= SW_MOD()->GetScannerManager();
161 SwScannerEventListener
& rListener
= GetScannerEventListener();
164 const Sequence
< scanner::ScannerContext
>aContexts( xScanMgr
->getAvailableScanners() );
165 if( aContexts
.getLength() )
167 Reference
< XEventListener
> xLstner
= &rListener
;
168 xScanMgr
->startScan( aContexts
.getConstArray()[ 0 ], xLstner
);
179 InfoBox( 0, SW_RES(MSG_SCAN_NOSOURCE
) ).Execute();
185 SfxBindings
& rBind
= pView
->GetViewFrame()->GetBindings();
186 rBind
.Invalidate( SID_TWAIN_SELECT
);
187 rBind
.Invalidate( SID_TWAIN_TRANSFER
);
194 SwScannerEventListener
& SwView_Impl::GetScannerEventListener()
196 if(!xScanEvtLstnr
.is())
197 xScanEvtLstnr
= pScanEvtLstnr
= new SwScannerEventListener(*pView
);
198 return *pScanEvtLstnr
;
201 void SwView_Impl::AddClipboardListener()
203 if(!xClipEvtLstnr
.is())
205 xClipEvtLstnr
= pClipEvtLstnr
= new SwClipboardChangeListener( *pView
);
206 pClipEvtLstnr
->AddRemoveListener( sal_True
);
210 void SwView_Impl::Invalidate()
212 GetUNOObject_Impl()->Invalidate();
213 Reference
< XUnoTunnel
> xTunnel(xTransferable
.get(), UNO_QUERY
);
217 SwTransferable
* pTransferable
= reinterpret_cast< SwTransferable
* >(
218 sal::static_int_cast
< sal_IntPtr
>(
219 xTunnel
->getSomething(SwTransferable::getUnoTunnelId())));
221 pTransferable
->Invalidate();
225 void SwView_Impl::AddTransferable(SwTransferable
& rTransferable
)
227 //prevent removing of the non-referenced SwTransferable
228 rTransferable
.m_refCount
++;
230 xTransferable
= Reference
<XUnoTunnel
> (&rTransferable
);
232 rTransferable
.m_refCount
--;
235 void SwView_Impl::StartDocumentInserter( const String
& rFactory
, const Link
& rEndDialogHdl
)
237 delete m_pDocInserter
;
238 m_pDocInserter
= new ::sfx2::DocumentInserter( rFactory
);
239 m_pDocInserter
->StartExecuteModal( rEndDialogHdl
);
242 SfxMedium
* SwView_Impl::CreateMedium()
244 return m_pDocInserter
->CreateMedium();
247 void SwView_Impl::InitRequest( const SfxRequest
& rRequest
)
250 m_pRequest
= new SfxRequest( rRequest
);
253 SwScannerEventListener::~SwScannerEventListener()
257 void SAL_CALL
SwScannerEventListener::disposing( const EventObject
& rEventObject
) throw(uno::RuntimeException
)
259 #if defined WNT || defined UNX
260 SolarMutexGuard aGuard
;
262 pView
->ScannerEventHdl( rEventObject
);
266 SwClipboardChangeListener::~SwClipboardChangeListener()
270 void SAL_CALL
SwClipboardChangeListener::disposing( const EventObject
& /*rEventObject*/ )
271 throw ( RuntimeException
)
275 void SAL_CALL
SwClipboardChangeListener::changedContents( const ::com::sun::star::datatransfer::clipboard::ClipboardEvent
& rEventObject
)
276 throw ( RuntimeException
)
279 const SolarMutexGuard aGuard
;
283 TransferableDataHelper
aDataHelper( rEventObject
.Contents
);
284 SwWrtShell
& rSh
= pView
->GetWrtShell();
286 pView
->m_nLastPasteDestination
= SwTransferable::GetSotDestination( rSh
);
287 pView
->m_bPasteState
= aDataHelper
.GetXTransferable().is() &&
288 SwTransferable::IsPaste( rSh
, aDataHelper
);
290 pView
->m_bPasteSpecialState
= aDataHelper
.GetXTransferable().is() &&
291 SwTransferable::IsPasteSpecial( rSh
, aDataHelper
);
294 SfxBindings
& rBind
= pView
->GetViewFrame()->GetBindings();
295 rBind
.Invalidate( SID_PASTE
);
296 rBind
.Invalidate( SID_PASTE_SPECIAL
);
297 rBind
.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS
);
301 void SwClipboardChangeListener::AddRemoveListener( sal_Bool bAdd
)
303 pView
->AddRemoveClipboardListener( Reference
< XClipboardListener
>( this ), bAdd
);
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */