update dev300-m58
[ooovba.git] / sw / source / ui / uiview / uivwimp.cxx
blobf6feb0ec0d584749126803ed78bc2ab4bb656bd1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: uivwimp.cxx,v $
10 * $Revision: 1.25 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <cmdid.h>
36 #include "globals.hrc"
38 #include <tools/shl.hxx>
39 #include <com/sun/star/scanner/XScannerManager.hpp>
40 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
41 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
42 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 #include <comphelper/processfactory.hxx>
44 #include <vos/mutex.hxx>
45 #include <vcl/svapp.hxx>
46 #include <vcl/wrkwin.hxx>
47 #include <vcl/msgbox.hxx>
48 #include <sfx2/viewfrm.hxx>
49 #include <sfx2/bindings.hxx>
51 #include <sfx2/docinsert.hxx>
52 #include <sfx2/request.hxx>
53 #include <uivwimp.hxx>
54 #include <wview.hxx>
55 #include <unotxvw.hxx>
56 #include <unodispatch.hxx>
57 #include <swmodule.hxx>
58 #include <swdtflvr.hxx>
59 #include <edtwin.hxx>
60 #include <mmconfigitem.hxx>
62 #include <view.hrc>
65 using namespace ::com::sun::star;
66 using namespace ::com::sun::star::uno;
67 using namespace ::com::sun::star::scanner;
68 using namespace ::com::sun::star::lang;
69 using namespace ::com::sun::star::datatransfer::clipboard;
71 /* -----------------02.06.98 15:31-------------------
73 * --------------------------------------------------*/
74 SwView_Impl::SwView_Impl(SwView* pShell) :
75 pxXTextView(new uno::Reference<view::XSelectionSupplier>),
76 pView(pShell),
77 eShellMode(SHELL_MODE_TEXT),
78 pConfigItem(0),
79 nMailMergeRestartPage(0),
80 bMailMergeSourceView(sal_True),
81 m_pDocInserter(NULL),
82 m_pRequest(NULL),
83 m_bSelectObject(false),
84 m_bEditingPositionSet(false)
86 *pxXTextView = new SwXTextView(pView);
87 xDisProvInterceptor = new SwXDispatchProviderInterceptor(*pView);
90 /*-----------------13.12.97 09:51-------------------
92 --------------------------------------------------*/
93 SwView_Impl::~SwView_Impl()
95 Reference<XUnoTunnel> xDispTunnel(xDisProvInterceptor, UNO_QUERY);
96 SwXDispatchProviderInterceptor* pInterceptor = 0;
97 if(xDispTunnel.is() &&
98 0 != (pInterceptor = reinterpret_cast< SwXDispatchProviderInterceptor * >(
99 sal::static_int_cast< sal_IntPtr >(
100 xDispTunnel->getSomething(SwXDispatchProviderInterceptor::getUnoTunnelId())))))
102 pInterceptor->Invalidate();
104 view::XSelectionSupplier* pTextView = pxXTextView->get();
105 ((SwXTextView*)pTextView)->Invalidate();
106 delete pxXTextView;
107 if( xScanEvtLstnr.is() )
108 pScanEvtLstnr->ViewDestroyed();
109 if( xClipEvtLstnr.is() )
111 pClipEvtLstnr->AddRemoveListener( FALSE );
112 pClipEvtLstnr->ViewDestroyed();
114 delete pConfigItem;
116 delete m_pDocInserter;
117 delete m_pRequest;
120 /*-----------------13.12.97 09:54-------------------
122 --------------------------------------------------*/
123 void SwView_Impl::SetShellMode(ShellModes eSet)
125 eShellMode = eSet;
127 /*-----------------13.12.97 09:59-------------------
129 --------------------------------------------------*/
130 view::XSelectionSupplier* SwView_Impl::GetUNOObject()
132 return pxXTextView->get();
134 /* -----------------02.06.98 15:29-------------------
136 * --------------------------------------------------*/
137 SwXTextView* SwView_Impl::GetUNOObject_Impl()
139 view::XSelectionSupplier* pTextView = pxXTextView->get();
140 return ((SwXTextView*)pTextView);
142 /* -----------------------------29.05.00 09:04--------------------------------
144 ---------------------------------------------------------------------------*/
145 void SwView_Impl::ExecuteScan( SfxRequest& rReq )
147 USHORT nSlot = rReq.GetSlot();
148 switch(nSlot)
150 case SID_TWAIN_SELECT:
152 BOOL bDone = FALSE;
153 Reference< XScannerManager > xScanMgr = SW_MOD()->GetScannerManager();
155 if( xScanMgr.is() )
159 const Sequence< ScannerContext >
160 aContexts( xScanMgr->getAvailableScanners() );
162 if( aContexts.getLength() )
164 ScannerContext aContext( aContexts.getConstArray()[ 0 ] );
165 bDone = xScanMgr->configureScanner( aContext );
168 catch(...)
173 if( bDone )
174 rReq.Done();
175 else
177 rReq.Ignore();
178 // KA 04.07.2002
179 // InfoBox( 0, SW_RES(MSG_SCAN_NOSOURCE) ).Execute();
182 break;
184 case SID_TWAIN_TRANSFER:
186 BOOL bDone = FALSE;
188 Reference< XScannerManager > xScanMgr = SW_MOD()->GetScannerManager();
189 if( xScanMgr.is() )
191 SwScannerEventListener& rListener = GetScannerEventListener();
194 const Sequence< scanner::ScannerContext >aContexts( xScanMgr->getAvailableScanners() );
195 if( aContexts.getLength() )
197 Reference< XEventListener > xLstner = &rListener;
198 xScanMgr->startScan( aContexts.getConstArray()[ 0 ], xLstner );
199 bDone = TRUE;
202 catch(...)
207 if( !bDone )
209 InfoBox( 0, SW_RES(MSG_SCAN_NOSOURCE) ).Execute();
210 rReq.Ignore();
212 else
214 rReq.Done();
215 SfxBindings& rBind = pView->GetViewFrame()->GetBindings();
216 rBind.Invalidate( SID_TWAIN_SELECT );
217 rBind.Invalidate( SID_TWAIN_TRANSFER );
220 break;
224 /* -----------------------------29.05.00 08:26--------------------------------
226 ---------------------------------------------------------------------------*/
227 SwScannerEventListener& SwView_Impl::GetScannerEventListener()
229 if(!xScanEvtLstnr.is())
230 xScanEvtLstnr = pScanEvtLstnr = new SwScannerEventListener(*pView);
231 return *pScanEvtLstnr;
235 void SwView_Impl::AddClipboardListener()
237 if(!xClipEvtLstnr.is())
239 xClipEvtLstnr = pClipEvtLstnr = new SwClipboardChangeListener( *pView );
240 pClipEvtLstnr->AddRemoveListener( TRUE );
243 /* -----------------3/31/2003 11:42AM----------------
245 --------------------------------------------------*/
246 void SwView_Impl::Invalidate()
248 GetUNOObject_Impl()->Invalidate();
249 Reference< XUnoTunnel > xTunnel(xTransferable.get(), UNO_QUERY);
250 if(xTunnel.is())
253 SwTransferable* pTransferable = reinterpret_cast< SwTransferable * >(
254 sal::static_int_cast< sal_IntPtr >(
255 xTunnel->getSomething(SwTransferable::getUnoTunnelId())));
256 if(pTransferable)
257 pTransferable->Invalidate();
260 /* -----------------3/31/2003 12:40PM----------------
262 --------------------------------------------------*/
263 void SwView_Impl::AddTransferable(SwTransferable& rTransferable)
265 //prevent removing of the non-referenced SwTransferable
266 rTransferable.m_refCount++;;
268 xTransferable = Reference<XUnoTunnel> (&rTransferable);
270 rTransferable.m_refCount--;
273 void SwView_Impl::StartDocumentInserter( const String& rFactory, const Link& rEndDialogHdl )
275 delete m_pDocInserter;
276 m_pDocInserter = new ::sfx2::DocumentInserter( 0, rFactory );
277 m_pDocInserter->StartExecuteModal( rEndDialogHdl );
280 SfxMedium* SwView_Impl::CreateMedium()
282 return m_pDocInserter->CreateMedium();
285 void SwView_Impl::InitRequest( const SfxRequest& rRequest )
287 delete m_pRequest;
288 m_pRequest = new SfxRequest( rRequest );
291 // ------------------------- SwScannerEventListener ---------------------
293 SwScannerEventListener::~SwScannerEventListener()
297 void SAL_CALL SwScannerEventListener::disposing( const EventObject& rEventObject) throw(uno::RuntimeException)
299 vos::OGuard aGuard(Application::GetSolarMutex());
300 #if defined WIN || defined WNT || defined UNX
301 if( pView )
302 pView->ScannerEventHdl( rEventObject );
303 #endif
306 // ------------------------- SwClipboardChangeListener ---------------------
308 SwClipboardChangeListener::~SwClipboardChangeListener()
312 void SAL_CALL SwClipboardChangeListener::disposing( const EventObject& /*rEventObject*/ )
313 throw ( RuntimeException )
317 void SAL_CALL SwClipboardChangeListener::changedContents( const CLIP_NMSPC::ClipboardEvent& rEventObject )
318 throw ( RuntimeException )
321 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
322 if( pView )
325 TransferableDataHelper aDataHelper( rEventObject.Contents );
326 SwWrtShell& rSh = pView->GetWrtShell();
328 pView->nLastPasteDestination = SwTransferable::GetSotDestination( rSh );
329 pView->bPasteState = aDataHelper.GetXTransferable().is() &&
330 SwTransferable::IsPaste( rSh, aDataHelper );
332 pView->bPasteSpecialState = aDataHelper.GetXTransferable().is() &&
333 SwTransferable::IsPasteSpecial( rSh, aDataHelper );
336 SfxBindings& rBind = pView->GetViewFrame()->GetBindings();
337 rBind.Invalidate( SID_PASTE );
338 rBind.Invalidate( FN_PASTESPECIAL );
339 rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
343 void SwClipboardChangeListener::AddRemoveListener( BOOL bAdd )
347 do {
349 #ifdef _DONT_WORD_FOR_WEBTOP_
350 JP 4.7.2001: change for WebTop - get Clipboard from the Window.
351 Reference< XMultiServiceFactory > xFact(
352 ::comphelper::getProcessServiceFactory() );
353 if( !xFact.is() )
354 break;
355 Reference< XClipboard > xClipboard( xFact->createInstance(
356 ::rtl::OUString::createFromAscii(
357 "com.sun.star.datatransfer.clipboard.SystemClipboard" )),
358 UNO_QUERY );
359 #else
360 Reference< XClipboard > xClipboard(
361 pView->GetEditWin().GetClipboard() );
362 #endif
363 if( !xClipboard.is() )
364 break;
366 Reference< XClipboardNotifier > xClpbrdNtfr( xClipboard, UNO_QUERY );
367 if( xClpbrdNtfr.is() )
369 Reference< XClipboardListener > xClipEvtLstnr( this );
370 if( bAdd )
371 xClpbrdNtfr->addClipboardListener( xClipEvtLstnr );
372 else
373 xClpbrdNtfr->removeClipboardListener( xClipEvtLstnr );
375 } while ( FALSE );
377 catch( const uno::Exception& )