1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
#include <cmdid.h>
#include "globals.hrc"
#include <tools/shl.hxx>
#include <com/sun/star/scanner/XScannerManager.hpp>
#include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <comphelper/processfactory.hxx>
#include <vos/mutex.hxx>
#include <vcl/svapp.hxx>
#include <vcl/wrkwin.hxx>
#include <vcl/msgbox.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/docinsert.hxx>
#include <sfx2/request.hxx>
#include <uivwimp.hxx>
#include <wview.hxx>
#include <unotxvw.hxx>
#include <unodispatch.hxx>
#include <swmodule.hxx>
#include <swdtflvr.hxx>
#include <edtwin.hxx>
#include <mmconfigitem.hxx>
#include <view.hrc>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::scanner;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::datatransfer::clipboard;
SwView_Impl::SwView_Impl(SwView* pShell) :
pxXTextView(new uno::Reference<view::XSelectionSupplier>),
pView(pShell),
eShellMode(SHELL_MODE_TEXT),
pConfigItem(0),
nMailMergeRestartPage(0),
bMailMergeSourceView(sal_True),
m_pDocInserter(NULL),
m_pRequest(NULL),
m_bSelectObject(false),
m_bEditingPositionSet(false)
{
*pxXTextView = new SwXTextView(pView);
xDisProvInterceptor = new SwXDispatchProviderInterceptor(*pView);
}
SwView_Impl::~SwView_Impl()
{
Reference<XUnoTunnel> xDispTunnel(xDisProvInterceptor, UNO_QUERY);
SwXDispatchProviderInterceptor* pInterceptor = 0;
if(xDispTunnel.is() &&
0 != (pInterceptor = reinterpret_cast< SwXDispatchProviderInterceptor * >(
sal::static_int_cast< sal_IntPtr >(
xDispTunnel->getSomething(SwXDispatchProviderInterceptor::getUnoTunnelId())))))
{
pInterceptor->Invalidate();
}
view::XSelectionSupplier* pTextView = pxXTextView->get();
((SwXTextView*)pTextView)->Invalidate();
delete pxXTextView;
if( xScanEvtLstnr.is() )
pScanEvtLstnr->ViewDestroyed();
if( xClipEvtLstnr.is() )
{
pClipEvtLstnr->AddRemoveListener( FALSE );
pClipEvtLstnr->ViewDestroyed();
}
delete pConfigItem;
delete m_pDocInserter;
delete m_pRequest;
}
void SwView_Impl::SetShellMode(ShellModes eSet)
{
eShellMode = eSet;
}
view::XSelectionSupplier* SwView_Impl::GetUNOObject()
{
return pxXTextView->get();
}
SwXTextView* SwView_Impl::GetUNOObject_Impl()
{
view::XSelectionSupplier* pTextView = pxXTextView->get();
return ((SwXTextView*)pTextView);
}
void SwView_Impl::ExecuteScan( SfxRequest& rReq )
{
USHORT nSlot = rReq.GetSlot();
switch(nSlot)
{
case SID_TWAIN_SELECT:
{
BOOL bDone = FALSE;
Reference< XScannerManager > xScanMgr = SW_MOD()->GetScannerManager();
if( xScanMgr.is() )
{
try
{
const Sequence< ScannerContext >
aContexts( xScanMgr->getAvailableScanners() );
if( aContexts.getLength() )
{
ScannerContext aContext( aContexts.getConstArray()[ 0 ] );
bDone = xScanMgr->configureScanner( aContext );
}
}
catch(...)
{
}
}
if( bDone )
rReq.Done();
else
{
rReq.Ignore();
// KA 04.07.2002
// InfoBox( 0, SW_RES(MSG_SCAN_NOSOURCE) ).Execute();
}
}
break;
case SID_TWAIN_TRANSFER:
{
BOOL bDone = FALSE;
Reference< XScannerManager > xScanMgr = SW_MOD()->GetScannerManager();
if( xScanMgr.is() )
{
SwScannerEventListener& rListener = GetScannerEventListener();
try
{
const Sequence< scanner::ScannerContext >aContexts( xScanMgr->getAvailableScanners() );
if( aContexts.getLength() )
{
Reference< XEventListener > xLstner = &rListener;
xScanMgr->startScan( aContexts.getConstArray()[ 0 ], xLstner );
bDone = TRUE;
}
}
catch(...)
{
}
}
if( !bDone )
{
InfoBox( 0, SW_RES(MSG_SCAN_NOSOURCE) ).Execute();
rReq.Ignore();
}
else
{
rReq.Done();
SfxBindings& rBind = pView->GetViewFrame()->GetBindings();
rBind.Invalidate( SID_TWAIN_SELECT );
rBind.Invalidate( SID_TWAIN_TRANSFER );
}
}
break;
}
}
SwScannerEventListener& SwView_Impl::GetScannerEventListener()
{
if(!xScanEvtLstnr.is())
xScanEvtLstnr = pScanEvtLstnr = new SwScannerEventListener(*pView);
return *pScanEvtLstnr;
}
void SwView_Impl::AddClipboardListener()
{
if(!xClipEvtLstnr.is())
{
xClipEvtLstnr = pClipEvtLstnr = new SwClipboardChangeListener( *pView );
pClipEvtLstnr->AddRemoveListener( TRUE );
}
}
void SwView_Impl::Invalidate()
{
GetUNOObject_Impl()->Invalidate();
Reference< XUnoTunnel > xTunnel(xTransferable.get(), UNO_QUERY);
if(xTunnel.is())
{
SwTransferable* pTransferable = reinterpret_cast< SwTransferable * >(
sal::static_int_cast< sal_IntPtr >(
xTunnel->getSomething(SwTransferable::getUnoTunnelId())));
if(pTransferable)
pTransferable->Invalidate();
}
}
void SwView_Impl::AddTransferable(SwTransferable& rTransferable)
{
//prevent removing of the non-referenced SwTransferable
rTransferable.m_refCount++;;
{
xTransferable = Reference<XUnoTunnel> (&rTransferable);
}
rTransferable.m_refCount--;
}
void SwView_Impl::StartDocumentInserter( const String& rFactory, const Link& rEndDialogHdl )
{
delete m_pDocInserter;
m_pDocInserter = new ::sfx2::DocumentInserter( 0, rFactory );
m_pDocInserter->StartExecuteModal( rEndDialogHdl );
}
SfxMedium* SwView_Impl::CreateMedium()
{
return m_pDocInserter->CreateMedium();
}
void SwView_Impl::InitRequest( const SfxRequest& rRequest )
{
delete m_pRequest;
m_pRequest = new SfxRequest( rRequest );
}
SwScannerEventListener::~SwScannerEventListener()
{
}
void SAL_CALL SwScannerEventListener::disposing( const EventObject& rEventObject) throw(uno::RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
#if defined WIN || defined WNT || defined UNX
if( pView )
pView->ScannerEventHdl( rEventObject );
#endif
}
SwClipboardChangeListener::~SwClipboardChangeListener()
{
}
void SAL_CALL SwClipboardChangeListener::disposing( const EventObject& /*rEventObject*/ )
throw ( RuntimeException )
{
}
void SAL_CALL SwClipboardChangeListener::changedContents( const CLIP_NMSPC::ClipboardEvent& rEventObject )
throw ( RuntimeException )
{
const ::vos::OGuard aGuard( Application::GetSolarMutex() );
if( pView )
{
{
TransferableDataHelper aDataHelper( rEventObject.Contents );
SwWrtShell& rSh = pView->GetWrtShell();
pView->nLastPasteDestination = SwTransferable::GetSotDestination( rSh );
pView->bPasteState = aDataHelper.GetXTransferable().is() &&
SwTransferable::IsPaste( rSh, aDataHelper );
pView->bPasteSpecialState = aDataHelper.GetXTransferable().is() &&
SwTransferable::IsPasteSpecial( rSh, aDataHelper );
}
SfxBindings& rBind = pView->GetViewFrame()->GetBindings();
rBind.Invalidate( SID_PASTE );
rBind.Invalidate( SID_PASTE_SPECIAL );
rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
}
}
void SwClipboardChangeListener::AddRemoveListener( BOOL bAdd )
{
pView->AddRemoveClipboardListener( Reference< XClipboardListener >( this ), bAdd );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|