Line data Source code
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 <svl/stritem.hxx>
21 : #include <svl/eitem.hxx>
22 : #include <svl/whiter.hxx>
23 : #include <vcl/msgbox.hxx>
24 : #include <vcl/toolbox.hxx>
25 : #include <svl/intitem.hxx>
26 : #include <svtools/sfxecode.hxx>
27 : #include <svtools/ehdl.hxx>
28 : #include <com/sun/star/frame/XLayoutManager.hpp>
29 : #include <com/sun/star/frame/ModuleManager.hpp>
30 : #include <com/sun/star/beans/XPropertySet.hpp>
31 : #include <com/sun/star/embed/EmbedStates.hpp>
32 : #include <com/sun/star/embed/EmbedMisc.hpp>
33 : #include <com/sun/star/container/XContainerQuery.hpp>
34 : #include <com/sun/star/frame/XStorable.hpp>
35 : #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
36 : #include <com/sun/star/frame/UICommandDescription.hpp>
37 : #include <cppuhelper/implbase1.hxx>
38 :
39 : #include <osl/file.hxx>
40 : #include <osl/mutex.hxx>
41 : #include <tools/urlobj.hxx>
42 : #include <unotools/tempfile.hxx>
43 : #include <unotools/pathoptions.hxx>
44 : #include <svtools/miscopt.hxx>
45 : #include <svtools/soerr.hxx>
46 : #include <unotools/internaloptions.hxx>
47 :
48 : #include <basic/basmgr.hxx>
49 : #include <basic/sbuno.hxx>
50 : #include <framework/actiontriggerhelper.hxx>
51 : #include <comphelper/processfactory.hxx>
52 : #include <comphelper/sequenceashashmap.hxx>
53 : #include <toolkit/unohlp.hxx>
54 :
55 :
56 : #include <sfx2/app.hxx>
57 : #include "view.hrc"
58 : #include <sfx2/viewsh.hxx>
59 : #include "viewimp.hxx"
60 : #include "sfx2/sfxresid.hxx"
61 : #include <sfx2/request.hxx>
62 : #include <sfx2/templdlg.hxx>
63 : #include <sfx2/printer.hxx>
64 : #include <sfx2/docfile.hxx>
65 : #include <sfx2/dispatch.hxx>
66 : #include "arrdecl.hxx"
67 : #include <sfx2/docfac.hxx>
68 : #include "sfxlocal.hrc"
69 : #include <sfx2/sfxbasecontroller.hxx>
70 : #include "sfx2/mailmodelapi.hxx"
71 : #include "bluthsndapi.hxx"
72 : #include <sfx2/viewfrm.hxx>
73 : #include <sfx2/event.hxx>
74 : #include <sfx2/fcontnr.hxx>
75 : #include <sfx2/ipclient.hxx>
76 : #include "workwin.hxx"
77 : #include <sfx2/objface.hxx>
78 : #include <sfx2/docfilt.hxx>
79 : #include "openuriexternally.hxx"
80 :
81 : using namespace ::com::sun::star;
82 : using namespace ::com::sun::star::uno;
83 : using namespace ::com::sun::star::frame;
84 : using namespace ::com::sun::star::beans;
85 : using namespace ::com::sun::star::util;
86 : using namespace ::cppu;
87 :
88 : //=========================================================================
89 : DBG_NAME(SfxViewShell)
90 :
91 : #define SfxViewShell
92 : #include "sfxslots.hxx"
93 :
94 : //=========================================================================
95 :
96 : class SfxClipboardChangeListener : public ::cppu::WeakImplHelper1<
97 : datatransfer::clipboard::XClipboardListener >
98 : {
99 : public:
100 : SfxClipboardChangeListener( SfxViewShell* pView, const uno::Reference< datatransfer::clipboard::XClipboardNotifier >& xClpbrdNtfr );
101 : virtual ~SfxClipboardChangeListener();
102 :
103 : // XEventListener
104 : virtual void SAL_CALL disposing( const lang::EventObject& rEventObject )
105 : throw ( uno::RuntimeException );
106 :
107 : // XClipboardListener
108 : virtual void SAL_CALL changedContents( const datatransfer::clipboard::ClipboardEvent& rEventObject )
109 : throw ( uno::RuntimeException );
110 :
111 160 : void DisconnectViewShell() { m_pViewShell = NULL; }
112 : void ChangedContents();
113 :
114 : enum AsyncExecuteCmd
115 : {
116 : ASYNCEXECUTE_CMD_DISPOSING,
117 : ASYNCEXECUTE_CMD_CHANGEDCONTENTS
118 : };
119 :
120 54 : struct AsyncExecuteInfo
121 : {
122 98 : AsyncExecuteInfo( AsyncExecuteCmd eCmd, uno::Reference< datatransfer::clipboard::XClipboardListener > xThis, SfxClipboardChangeListener* pListener ) :
123 98 : m_eCmd( eCmd ), m_xThis( xThis ), m_pListener( pListener ) {}
124 :
125 : AsyncExecuteCmd m_eCmd;
126 : uno::Reference< datatransfer::clipboard::XClipboardListener > m_xThis;
127 : SfxClipboardChangeListener* m_pListener;
128 : };
129 :
130 : private:
131 : SfxViewShell* m_pViewShell;
132 : uno::Reference< datatransfer::clipboard::XClipboardNotifier > m_xClpbrdNtfr;
133 : uno::Reference< lang::XComponent > m_xCtrl;
134 :
135 : DECL_STATIC_LINK( SfxClipboardChangeListener, AsyncExecuteHdl_Impl, AsyncExecuteInfo* );
136 : };
137 :
138 524 : SfxClipboardChangeListener::SfxClipboardChangeListener( SfxViewShell* pView, const uno::Reference< datatransfer::clipboard::XClipboardNotifier >& xClpbrdNtfr )
139 524 : : m_pViewShell( 0 ), m_xClpbrdNtfr( xClpbrdNtfr )
140 : {
141 524 : m_xCtrl = uno::Reference < lang::XComponent >( pView->GetController(), uno::UNO_QUERY );
142 524 : if ( m_xCtrl.is() )
143 : {
144 524 : m_xCtrl->addEventListener( uno::Reference < lang::XEventListener > ( static_cast < lang::XEventListener* >( this ) ) );
145 524 : m_pViewShell = pView;
146 : }
147 524 : if ( m_xClpbrdNtfr.is() )
148 : {
149 2 : m_xClpbrdNtfr->addClipboardListener( uno::Reference< datatransfer::clipboard::XClipboardListener >(
150 2 : static_cast< datatransfer::clipboard::XClipboardListener* >( this )));
151 : }
152 524 : }
153 :
154 108 : SfxClipboardChangeListener::~SfxClipboardChangeListener()
155 : {
156 108 : }
157 :
158 0 : void SfxClipboardChangeListener::ChangedContents()
159 : {
160 0 : const SolarMutexGuard aGuard;
161 0 : if( m_pViewShell )
162 : {
163 0 : SfxBindings& rBind = m_pViewShell->GetViewFrame()->GetBindings();
164 0 : rBind.Invalidate( SID_PASTE );
165 0 : rBind.Invalidate( SID_PASTE_SPECIAL );
166 0 : rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
167 0 : }
168 0 : }
169 :
170 54 : IMPL_STATIC_LINK_NOINSTANCE( SfxClipboardChangeListener, AsyncExecuteHdl_Impl, AsyncExecuteInfo*, pAsyncExecuteInfo )
171 : {
172 54 : if ( pAsyncExecuteInfo )
173 : {
174 54 : uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( pAsyncExecuteInfo->m_xThis );
175 54 : if ( pAsyncExecuteInfo->m_pListener )
176 : {
177 54 : if ( pAsyncExecuteInfo->m_eCmd == ASYNCEXECUTE_CMD_DISPOSING )
178 54 : pAsyncExecuteInfo->m_pListener->DisconnectViewShell();
179 0 : else if ( pAsyncExecuteInfo->m_eCmd == ASYNCEXECUTE_CMD_CHANGEDCONTENTS )
180 0 : pAsyncExecuteInfo->m_pListener->ChangedContents();
181 54 : }
182 : }
183 54 : delete pAsyncExecuteInfo;
184 :
185 54 : return 0;
186 : }
187 :
188 98 : void SAL_CALL SfxClipboardChangeListener::disposing( const lang::EventObject& /*rEventObject*/ )
189 : throw ( uno::RuntimeException )
190 : {
191 : // Either clipboard or ViewShell is going to be destroyed -> no interest in listening anymore
192 98 : uno::Reference< lang::XComponent > xCtrl( m_xCtrl );
193 98 : uno::Reference< datatransfer::clipboard::XClipboardNotifier > xNotify( m_xClpbrdNtfr );
194 :
195 98 : uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( static_cast< datatransfer::clipboard::XClipboardListener* >( this ));
196 98 : if ( xCtrl.is() )
197 98 : xCtrl->removeEventListener( uno::Reference < lang::XEventListener > ( static_cast < lang::XEventListener* >( this )));
198 98 : if ( xNotify.is() )
199 2 : xNotify->removeClipboardListener( xThis );
200 :
201 : // Make asynchronous call to avoid locking SolarMutex which is the
202 : // root for many deadlocks, especially in conjuction with the "Windows"
203 : // based single thread apartment clipboard code!
204 98 : AsyncExecuteInfo* pInfo = new AsyncExecuteInfo( ASYNCEXECUTE_CMD_DISPOSING, xThis, this );
205 98 : Application::PostUserEvent( STATIC_LINK( 0, SfxClipboardChangeListener, AsyncExecuteHdl_Impl ), pInfo );
206 98 : }
207 :
208 0 : void SAL_CALL SfxClipboardChangeListener::changedContents( const datatransfer::clipboard::ClipboardEvent& )
209 : throw ( RuntimeException )
210 : {
211 : // Make asynchronous call to avoid locking SolarMutex which is the
212 : // root for many deadlocks, especially in conjuction with the "Windows"
213 : // based single thread apartment clipboard code!
214 0 : uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( static_cast< datatransfer::clipboard::XClipboardListener* >( this ));
215 0 : AsyncExecuteInfo* pInfo = new AsyncExecuteInfo( ASYNCEXECUTE_CMD_CHANGEDCONTENTS, xThis, this );
216 0 : Application::PostUserEvent( STATIC_LINK( 0, SfxClipboardChangeListener, AsyncExecuteHdl_Impl ), pInfo );
217 0 : }
218 :
219 : //=========================================================================
220 :
221 7 : static ::rtl::OUString RetrieveLabelFromCommand(
222 : const ::rtl::OUString& rCommandURL,
223 : const css::uno::Reference< css::frame::XFrame >& rFrame )
224 : {
225 7 : static css::uno::WeakReference< frame::XModuleManager2 > s_xModuleManager;
226 7 : static css::uno::WeakReference< container::XNameAccess > s_xNameAccess;
227 :
228 7 : ::rtl::OUString aLabel;
229 7 : css::uno::Reference< css::frame::XModuleManager2 > xModuleManager( s_xModuleManager );
230 7 : css::uno::Reference< css::container::XNameAccess > xNameAccess( s_xNameAccess );
231 : css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR(
232 7 : ::comphelper::getProcessServiceFactory(), css::uno::UNO_QUERY_THROW);
233 : css::uno::Reference< css::uno::XComponentContext > xContext(
234 7 : ::comphelper::getProcessComponentContext(), css::uno::UNO_QUERY_THROW);
235 :
236 : try
237 : {
238 7 : if ( !xModuleManager.is() )
239 : {
240 7 : xModuleManager = css::frame::ModuleManager::create(xContext);
241 7 : s_xModuleManager = xModuleManager;
242 : }
243 :
244 7 : ::rtl::OUString aModuleIdentifier = xModuleManager->identify( rFrame );
245 :
246 7 : if ( !xNameAccess.is() )
247 : {
248 : xNameAccess = css::uno::Reference< css::container::XNameAccess >(
249 : css::frame::UICommandDescription::create(
250 : comphelper::getComponentContext(xSMGR)),
251 2 : css::uno::UNO_QUERY_THROW );
252 2 : s_xNameAccess = xNameAccess;
253 : }
254 :
255 7 : css::uno::Any a = xNameAccess->getByName( aModuleIdentifier );
256 7 : css::uno::Reference< css::container::XNameAccess > xUICommands;
257 7 : a >>= xUICommands;
258 :
259 7 : rtl::OUString aStr;
260 7 : css::uno::Sequence< css::beans::PropertyValue > aPropSeq;
261 :
262 7 : a = xUICommands->getByName( rCommandURL );
263 7 : if ( a >>= aPropSeq )
264 : {
265 7 : for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
266 : {
267 7 : if ( aPropSeq[i].Name == "Label" )
268 : {
269 7 : aPropSeq[i].Value >>= aStr;
270 7 : break;
271 : }
272 : }
273 7 : aLabel = aStr;
274 7 : }
275 : }
276 0 : catch (const css::uno::Exception&)
277 : {
278 : }
279 :
280 7 : return aLabel;
281 : }
282 :
283 : //=========================================================================
284 516 : SfxViewShell_Impl::SfxViewShell_Impl(sal_uInt16 const nFlags)
285 : : aInterceptorContainer( aMutex )
286 : , m_bControllerSet(false)
287 : , m_nPrinterLocks(0)
288 : , m_bCanPrint(SFX_VIEW_CAN_PRINT == (nFlags & SFX_VIEW_CAN_PRINT))
289 : , m_bHasPrintOptions(
290 : SFX_VIEW_HAS_PRINTOPTIONS == (nFlags & SFX_VIEW_HAS_PRINTOPTIONS))
291 : , m_bPlugInsActive(true)
292 : , m_bIsShowView(SFX_VIEW_NO_SHOW != (nFlags & SFX_VIEW_NO_SHOW))
293 : , m_bGotOwnership(false)
294 : , m_bGotFrameOwnership(false)
295 : , m_nFamily(0xFFFF) // undefined, default set by TemplateDialog
296 : , m_pController(0)
297 516 : , m_pAccExec(0)
298 516 : {}
299 :
300 : //=========================================================================
301 454 : SFX_IMPL_INTERFACE(SfxViewShell,SfxShell,SfxResId(0))
302 : {
303 72 : SFX_CHILDWINDOW_REGISTRATION( SID_MAIL_CHILDWIN );
304 72 : }
305 :
306 13964 : TYPEINIT2(SfxViewShell,SfxShell,SfxListener);
307 :
308 : //--------------------------------------------------------------------
309 : /** search for a filter name dependent on type and module
310 : */
311 :
312 0 : static ::rtl::OUString impl_retrieveFilterNameFromTypeAndModule(
313 : const css::uno::Reference< css::container::XContainerQuery >& rContainerQuery,
314 : const ::rtl::OUString& rType,
315 : const ::rtl::OUString& rModuleIdentifier,
316 : const sal_Int32 nFlags )
317 : {
318 : // Retrieve filter from type
319 0 : css::uno::Sequence< css::beans::NamedValue > aQuery( 2 );
320 0 : aQuery[0].Name = rtl::OUString( "Type" );
321 0 : aQuery[0].Value = css::uno::makeAny( rType );
322 0 : aQuery[1].Name = rtl::OUString( "DocumentService" );
323 0 : aQuery[1].Value = css::uno::makeAny( rModuleIdentifier );
324 :
325 : css::uno::Reference< css::container::XEnumeration > xEnumeration =
326 0 : rContainerQuery->createSubSetEnumerationByProperties( aQuery );
327 :
328 0 : ::rtl::OUString aFoundFilterName;
329 0 : while ( xEnumeration->hasMoreElements() )
330 : {
331 0 : ::comphelper::SequenceAsHashMap aFilterPropsHM( xEnumeration->nextElement() );
332 : ::rtl::OUString aFilterName = aFilterPropsHM.getUnpackedValueOrDefault(
333 : ::rtl::OUString("Name"),
334 0 : ::rtl::OUString() );
335 :
336 : sal_Int32 nFilterFlags = aFilterPropsHM.getUnpackedValueOrDefault(
337 : ::rtl::OUString("Flags"),
338 0 : sal_Int32( 0 ) );
339 :
340 0 : if ( nFilterFlags & nFlags )
341 : {
342 0 : aFoundFilterName = aFilterName;
343 : break;
344 : }
345 0 : }
346 :
347 0 : return aFoundFilterName;
348 : }
349 :
350 : //--------------------------------------------------------------------
351 : /** search for an internal typename, which map to the current app module
352 : and map also to a "family" of file formats as e.g. PDF/MS Doc/OOo Doc.
353 : */
354 : enum ETypeFamily
355 : {
356 : E_MS_DOC,
357 : E_OOO_DOC
358 : };
359 :
360 0 : ::rtl::OUString impl_searchFormatTypeForApp(const css::uno::Reference< css::frame::XFrame >& xFrame ,
361 : ETypeFamily eTypeFamily)
362 : {
363 : try
364 : {
365 0 : css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR (::comphelper::getProcessServiceFactory() , css::uno::UNO_QUERY_THROW);
366 0 : css::uno::Reference< css::uno::XComponentContext > xContext (::comphelper::getProcessComponentContext() , css::uno::UNO_QUERY_THROW);
367 0 : css::uno::Reference< css::frame::XModuleManager2 > xModuleManager(css::frame::ModuleManager::create(xContext));
368 :
369 0 : ::rtl::OUString sModule = xModuleManager->identify(xFrame);
370 0 : ::rtl::OUString sType ;
371 :
372 0 : switch(eTypeFamily)
373 : {
374 : case E_MS_DOC:
375 : {
376 0 : if ( sModule == "com.sun.star.text.TextDocument" )
377 0 : sType = ::rtl::OUString( "writer_MS_Word_97" );
378 : else
379 0 : if ( sModule == "com.sun.star.sheet.SpreadsheetDocument" )
380 0 : sType = ::rtl::OUString( "calc_MS_Excel_97" );
381 : else
382 0 : if ( sModule == "com.sun.star.drawing.DrawingDocument" )
383 0 : sType = ::rtl::OUString( "impress_MS_PowerPoint_97" );
384 : else
385 0 : if ( sModule == "com.sun.star.presentation.PresentationDocument" )
386 0 : sType = ::rtl::OUString( "impress_MS_PowerPoint_97" );
387 : }
388 0 : break;
389 :
390 : case E_OOO_DOC:
391 : {
392 0 : if ( sModule == "com.sun.star.text.TextDocument" )
393 0 : sType = ::rtl::OUString( "writer8" );
394 : else
395 0 : if ( sModule == "com.sun.star.sheet.SpreadsheetDocument" )
396 0 : sType = ::rtl::OUString( "calc8" );
397 : else
398 0 : if ( sModule == "com.sun.star.drawing.DrawingDocument" )
399 0 : sType = ::rtl::OUString( "draw8" );
400 : else
401 0 : if ( sModule == "com.sun.star.presentation.PresentationDocument" )
402 0 : sType = ::rtl::OUString( "impress8" );
403 : }
404 0 : break;
405 : }
406 :
407 0 : return sType;
408 : }
409 0 : catch (const css::uno::RuntimeException&)
410 : {
411 0 : throw;
412 : }
413 0 : catch (const css::uno::Exception&)
414 : {
415 : }
416 :
417 0 : return ::rtl::OUString();
418 : }
419 :
420 : //--------------------------------------------------------------------
421 :
422 0 : SAL_DLLPRIVATE void SfxViewShell::IPClientGone_Impl( SfxInPlaceClient *pIPClient )
423 : {
424 0 : SfxInPlaceClientList* pClientList = GetIPClientList_Impl(sal_True);
425 :
426 0 : for( SfxInPlaceClientList::iterator it = pClientList->begin(); it != pClientList->end(); ++it )
427 : {
428 0 : if ( *it == pIPClient )
429 : {
430 0 : pClientList->erase( it );
431 0 : break;
432 : }
433 : }
434 0 : }
435 :
436 :
437 :
438 : //--------------------------------------------------------------------
439 :
440 0 : void SfxViewShell::ExecMisc_Impl( SfxRequest &rReq )
441 : {
442 0 : const sal_uInt16 nId = rReq.GetSlot();
443 0 : switch( nId )
444 : {
445 : case SID_STYLE_FAMILY :
446 : {
447 0 : SFX_REQUEST_ARG(rReq, pItem, SfxUInt16Item, nId, sal_False);
448 0 : if (pItem)
449 : {
450 0 : pImp->m_nFamily = pItem->GetValue();
451 : }
452 0 : break;
453 : }
454 : case SID_STYLE_CATALOG:
455 : {
456 : SfxTemplateCatalog aCatalog(
457 0 : SFX_APP()->GetTopWindow(), &GetViewFrame()->GetBindings());
458 0 : aCatalog.Execute();
459 0 : rReq.Ignore();
460 0 : break;
461 : }
462 : case SID_ACTIVATE_STYLE_APPLY:
463 : {
464 : com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
465 0 : GetViewFrame()->GetFrame().GetFrameInterface(),
466 0 : com::sun::star::uno::UNO_QUERY);
467 :
468 0 : Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
469 0 : Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
470 0 : if ( xPropSet.is() )
471 : {
472 : try
473 : {
474 0 : Any aValue = xPropSet->getPropertyValue( rtl::OUString( "LayoutManager" ));
475 0 : aValue >>= xLayoutManager;
476 0 : if ( xLayoutManager.is() )
477 : {
478 0 : rtl::OUString aTextResString( "private:resource/toolbar/textobjectbar" );
479 0 : uno::Reference< ui::XUIElement > xElement = xLayoutManager->getElement( aTextResString );
480 0 : if(!xElement.is())
481 : {
482 0 : rtl::OUString aFrameResString( "private:resource/toolbar/frameobjectbar" );
483 0 : xElement = xLayoutManager->getElement( aFrameResString );
484 : }
485 0 : if(!xElement.is())
486 : {
487 0 : rtl::OUString aOleResString( "private:resource/toolbar/oleobjectbar" );
488 0 : xElement = xLayoutManager->getElement( aOleResString );
489 : }
490 0 : if(xElement.is())
491 : {
492 0 : uno::Reference< awt::XWindow > xWin( xElement->getRealInterface(), uno::UNO_QUERY_THROW );
493 0 : Window* pWin = VCLUnoHelper::GetWindow( xWin );
494 0 : ToolBox* pTextToolbox = dynamic_cast< ToolBox* >( pWin );
495 0 : if( pTextToolbox )
496 : {
497 0 : sal_uInt16 nItemCount = pTextToolbox->GetItemCount();
498 0 : for( sal_uInt16 nItem = 0; nItem < nItemCount; ++nItem )
499 : {
500 0 : sal_uInt16 nItemId = pTextToolbox->GetItemId( nItem );
501 0 : const OUString& rCommand = pTextToolbox->GetItemCommand( nItemId );
502 0 : if (rCommand == ".uno:StyleApply")
503 : {
504 0 : Window* pItemWin = pTextToolbox->GetItemWindow( nItemId );
505 0 : if( pItemWin )
506 0 : pItemWin->GrabFocus();
507 : break;
508 : }
509 0 : }
510 0 : }
511 0 : }
512 0 : }
513 : }
514 0 : catch (const Exception&)
515 : {
516 : }
517 : }
518 0 : rReq.Done();
519 : }
520 0 : break;
521 : // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
522 :
523 : case SID_MAIL_SENDDOCASMS:
524 : case SID_MAIL_SENDDOCASOOO:
525 : case SID_MAIL_SENDDOCASPDF:
526 : case SID_MAIL_SENDDOC:
527 : case SID_MAIL_SENDDOCASFORMAT:
528 : {
529 0 : SfxObjectShell* pDoc = GetObjectShell();
530 0 : if ( pDoc && pDoc->QueryHiddenInformation(
531 0 : WhenSaving, &GetViewFrame()->GetWindow() ) != RET_YES )
532 0 : break;
533 :
534 0 : if ( SvtInternalOptions().MailUIEnabled() )
535 : {
536 0 : GetViewFrame()->SetChildWindow( SID_MAIL_CHILDWIN, sal_True );
537 : }
538 : else
539 : {
540 0 : SfxMailModel aModel;
541 0 : rtl::OUString aDocType;
542 :
543 0 : SFX_REQUEST_ARG(rReq, pMailSubject, SfxStringItem, SID_MAIL_SUBJECT, sal_False );
544 0 : if ( pMailSubject )
545 0 : aModel.SetSubject( pMailSubject->GetValue() );
546 :
547 0 : SFX_REQUEST_ARG(rReq, pMailRecipient, SfxStringItem, SID_MAIL_RECIPIENT, sal_False );
548 0 : if ( pMailRecipient )
549 : {
550 0 : String aRecipient( pMailRecipient->GetValue() );
551 0 : String aMailToStr(rtl::OUString("mailto:"));
552 :
553 0 : if ( aRecipient.Search( aMailToStr ) == 0 )
554 0 : aRecipient = aRecipient.Erase( 0, aMailToStr.Len() );
555 0 : aModel.AddAddress( aRecipient, SfxMailModel::ROLE_TO );
556 : }
557 0 : SFX_REQUEST_ARG(rReq, pMailDocType, SfxStringItem, SID_TYPE_NAME, sal_False );
558 0 : if ( pMailDocType )
559 0 : aDocType = pMailDocType->GetValue();
560 :
561 0 : uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() );
562 0 : SfxMailModel::SendMailResult eResult = SfxMailModel::SEND_MAIL_ERROR;
563 :
564 0 : if ( nId == SID_MAIL_SENDDOC )
565 0 : eResult = aModel.SaveAndSend( xFrame, rtl::OUString() );
566 : else
567 0 : if ( nId == SID_MAIL_SENDDOCASPDF )
568 0 : eResult = aModel.SaveAndSend( xFrame, rtl::OUString( "pdf_Portable_Document_Format" ));
569 : else
570 0 : if ( nId == SID_MAIL_SENDDOCASMS )
571 : {
572 0 : aDocType = impl_searchFormatTypeForApp(xFrame, E_MS_DOC);
573 0 : if (!aDocType.isEmpty())
574 0 : eResult = aModel.SaveAndSend( xFrame, aDocType );
575 : }
576 : else
577 0 : if ( nId == SID_MAIL_SENDDOCASOOO )
578 : {
579 0 : aDocType = impl_searchFormatTypeForApp(xFrame, E_OOO_DOC);
580 0 : if (!aDocType.isEmpty())
581 0 : eResult = aModel.SaveAndSend( xFrame, aDocType );
582 : }
583 :
584 0 : if ( eResult == SfxMailModel::SEND_MAIL_ERROR )
585 : {
586 0 : InfoBox aBox( SFX_APP()->GetTopWindow(), SfxResId( MSG_ERROR_SEND_MAIL ));
587 0 : aBox.Execute();
588 0 : rReq.Ignore();
589 : }
590 : else
591 0 : rReq.Done();
592 : }
593 :
594 0 : break;
595 : }
596 :
597 : case SID_BLUETOOTH_SENDDOC:
598 : {
599 0 : SfxBluetoothModel aModel;
600 0 : SfxObjectShell* pDoc = GetObjectShell();
601 0 : if ( pDoc && pDoc->QueryHiddenInformation(
602 0 : WhenSaving, &GetViewFrame()->GetWindow() ) != RET_YES )
603 : break;
604 0 : uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() );
605 0 : SfxMailModel::SendMailResult eResult = aModel.SaveAndSend( xFrame, rtl::OUString() );
606 0 : if( eResult == SfxMailModel::SEND_MAIL_ERROR )
607 : {
608 0 : InfoBox aBox( SFX_APP()->GetTopWindow(), SfxResId( MSG_ERROR_SEND_MAIL ));
609 0 : aBox.Execute();
610 0 : rReq.Ignore();
611 : }
612 : else
613 0 : rReq.Done();
614 : }
615 0 : break;
616 :
617 : // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
618 : case SID_WEBHTML:
619 : {
620 : static const char HTML_DOCUMENT_TYPE[] = "generic_HTML";
621 : static const char HTML_GRAPHIC_TYPE[] = "graphic_HTML";
622 0 : const sal_Int32 FILTERFLAG_EXPORT = 0x00000002;
623 :
624 0 : css::uno::Reference< lang::XMultiServiceFactory > xSMGR(::comphelper::getProcessServiceFactory(), css::uno::UNO_QUERY_THROW);
625 0 : css::uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext(), css::uno::UNO_QUERY_THROW);
626 0 : css::uno::Reference< css::frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() );
627 0 : css::uno::Reference< css::frame::XModel > xModel;
628 :
629 0 : css::uno::Reference< css::frame::XModuleManager2 > xModuleManager( css::frame::ModuleManager::create(xContext) );
630 :
631 0 : rtl::OUString aModule;
632 : try
633 : {
634 0 : aModule = xModuleManager->identify( xFrame );
635 : }
636 0 : catch (const css::uno::RuntimeException&)
637 : {
638 0 : throw;
639 : }
640 0 : catch (const css::uno::Exception&)
641 : {
642 : }
643 :
644 0 : if ( xFrame.is() )
645 : {
646 0 : css::uno::Reference< css::frame::XController > xController = xFrame->getController();
647 0 : if ( xController.is() )
648 0 : xModel = xController->getModel();
649 : }
650 :
651 : // We need at least a valid module name and model reference
652 0 : css::uno::Reference< css::frame::XStorable > xStorable( xModel, css::uno::UNO_QUERY );
653 0 : if ( xModel.is() && xStorable.is() )
654 : {
655 0 : rtl::OUString aFilterName;
656 0 : rtl::OUString aTypeName( HTML_DOCUMENT_TYPE );
657 0 : rtl::OUString aFileName;
658 0 : rtl::OUString aExtension( "htm" );
659 :
660 0 : rtl::OUString aLocation = xStorable->getLocation();
661 0 : INetURLObject aFileObj( aLocation );
662 :
663 0 : bool bPrivateProtocol = ( aFileObj.GetProtocol() == INET_PROT_PRIV_SOFFICE );
664 0 : bool bHasLocation = !aLocation.isEmpty() && !bPrivateProtocol;
665 :
666 : css::uno::Reference< css::container::XContainerQuery > xContainerQuery(
667 0 : xSMGR->createInstance( rtl::OUString(
668 0 : "com.sun.star.document.FilterFactory" )),
669 0 : css::uno::UNO_QUERY_THROW );
670 :
671 : // Retrieve filter from type
672 0 : sal_Int32 nFilterFlags = FILTERFLAG_EXPORT;
673 0 : aFilterName = impl_retrieveFilterNameFromTypeAndModule( xContainerQuery, aTypeName, aModule, nFilterFlags );
674 0 : if ( aFilterName.isEmpty() )
675 : {
676 : // Draw/Impress uses a different type. 2nd chance try to use alternative type name
677 : aFilterName = impl_retrieveFilterNameFromTypeAndModule(
678 0 : xContainerQuery, ::rtl::OUString( HTML_GRAPHIC_TYPE ), aModule, nFilterFlags );
679 : }
680 :
681 : // No filter found => error
682 : // No type and no location => error
683 0 : if ( aFilterName.isEmpty() || aTypeName.isEmpty())
684 : {
685 0 : rReq.Done(sal_False);
686 : return;
687 : }
688 :
689 : // Use provided save file name. If empty determine file name
690 0 : if ( !bHasLocation )
691 : {
692 : // Create a default file name with the correct extension
693 0 : const rtl::OUString aPreviewFileName( "webpreview" );
694 0 : aFileName = aPreviewFileName;
695 : }
696 : else
697 : {
698 : // Determine file name from model
699 0 : INetURLObject aFObj( xStorable->getLocation() );
700 0 : aFileName = aFObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::NO_DECODE );
701 : }
702 :
703 : OSL_ASSERT( !aFilterName.isEmpty() );
704 : OSL_ASSERT( !aFileName.isEmpty() );
705 :
706 : // Creates a temporary directory to store our predefined file into it.
707 0 : ::utl::TempFile aTempDir( NULL, sal_True );
708 :
709 0 : INetURLObject aFilePathObj( aTempDir.GetURL() );
710 0 : aFilePathObj.insertName( aFileName );
711 0 : aFilePathObj.setExtension( aExtension );
712 :
713 0 : rtl::OUString aFileURL = aFilePathObj.GetMainURL( INetURLObject::NO_DECODE );
714 :
715 0 : css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
716 0 : aArgs[0].Name = rtl::OUString( "FilterName" );
717 0 : aArgs[0].Value = css::uno::makeAny( aFilterName );
718 :
719 : // Store document in the html format
720 : try
721 : {
722 0 : xStorable->storeToURL( aFileURL, aArgs );
723 : }
724 0 : catch (const com::sun::star::io::IOException&)
725 : {
726 0 : rReq.Done(sal_False);
727 : return;
728 : }
729 :
730 0 : rReq.Done(sfx2::openUriExternally(aFileURL, true));
731 0 : break;
732 : }
733 : else
734 : {
735 0 : rReq.Done(sal_False);
736 : return;
737 0 : }
738 : }
739 :
740 : // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
741 : case SID_PLUGINS_ACTIVE:
742 : {
743 0 : SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nId, sal_False);
744 : bool const bActive = (pShowItem)
745 0 : ? pShowItem->GetValue()
746 0 : : !pImp->m_bPlugInsActive;
747 : // ggf. recorden
748 0 : if ( !rReq.IsAPI() )
749 0 : rReq.AppendItem( SfxBoolItem( nId, bActive ) );
750 :
751 : // Jetzt schon DONE aufrufen, da die Argumente evtl. einen Pool
752 : // benutzen, der demn"achst weg ist
753 0 : rReq.Done(sal_True);
754 :
755 : // ausfuehren
756 0 : if (!pShowItem || (bActive != pImp->m_bPlugInsActive))
757 : {
758 0 : SfxFrame* pTopFrame = &GetFrame()->GetTopFrame();
759 0 : if ( pTopFrame != &GetFrame()->GetFrame() )
760 : {
761 : // FramesetDocument
762 0 : SfxViewShell *pShell = pTopFrame->GetCurrentViewFrame()->GetViewShell();
763 0 : if ( pShell->GetInterface()->GetSlot( nId ) )
764 0 : pShell->ExecuteSlot( rReq );
765 : break;
766 : }
767 :
768 0 : SfxFrameIterator aIter( *pTopFrame );
769 0 : while ( pTopFrame )
770 : {
771 0 : if ( pTopFrame->GetCurrentViewFrame() )
772 : {
773 0 : SfxViewShell *pView = pTopFrame->GetCurrentViewFrame()->GetViewShell();
774 0 : if ( pView )
775 : {
776 0 : pView->pImp->m_bPlugInsActive = bActive;
777 0 : Rectangle aVisArea = GetObjectShell()->GetVisArea();
778 0 : VisAreaChanged(aVisArea);
779 :
780 : // the plugins might need change in their state
781 0 : SfxInPlaceClientList *pClients = pView->GetIPClientList_Impl(sal_False);
782 0 : if ( pClients )
783 : {
784 0 : for ( size_t n = 0; n < pClients->size(); n++)
785 : {
786 0 : SfxInPlaceClient* pIPClient = pClients->at( n );
787 0 : if ( pIPClient )
788 0 : pView->CheckIPClient_Impl( pIPClient, aVisArea );
789 : }
790 : }
791 : }
792 : }
793 :
794 0 : if ( !pTopFrame->GetParentFrame() )
795 0 : pTopFrame = aIter.FirstFrame();
796 : else
797 0 : pTopFrame = aIter.NextFrame( *pTopFrame );
798 : }
799 : }
800 :
801 0 : break;
802 : }
803 : }
804 : }
805 :
806 : //--------------------------------------------------------------------
807 :
808 14 : void SfxViewShell::GetState_Impl( SfxItemSet &rSet )
809 : {
810 : DBG_CHKTHIS(SfxViewShell, 0);
811 :
812 14 : SfxWhichIter aIter( rSet );
813 28 : for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
814 : {
815 14 : switch ( nSID )
816 : {
817 : case SID_STYLE_CATALOG:
818 : {
819 0 : if ( !GetViewFrame()->KnowsChildWindow( SID_STYLE_DESIGNER ) )
820 0 : rSet.DisableItem( nSID );
821 0 : break;
822 : }
823 :
824 : // Printer functions
825 : case SID_PRINTDOC:
826 : case SID_PRINTDOCDIRECT:
827 : case SID_SETUPPRINTER:
828 : case SID_PRINTER_NAME:
829 : {
830 7 : bool bEnabled = pImp->m_bCanPrint && !pImp->m_nPrinterLocks;
831 7 : bEnabled = bEnabled && !Application::GetSettings().GetMiscSettings().GetDisablePrinting();
832 7 : if ( bEnabled )
833 : {
834 7 : SfxPrinter *pPrinter = GetPrinter(sal_False);
835 :
836 7 : if ( SID_PRINTDOCDIRECT == nSID )
837 : {
838 7 : rtl::OUString aPrinterName;
839 7 : if ( pPrinter != NULL )
840 0 : aPrinterName = pPrinter->GetName();
841 : else
842 7 : aPrinterName = Printer::GetDefaultPrinterName();
843 7 : if ( !aPrinterName.isEmpty() )
844 : {
845 7 : uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() );
846 :
847 7 : ::rtl::OUStringBuffer aBuffer( 60 );
848 : aBuffer.append( RetrieveLabelFromCommand(
849 : ::rtl::OUString( ".uno:PrintDefault" ),
850 7 : xFrame ));
851 7 : aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
852 7 : aBuffer.append( aPrinterName );
853 7 : aBuffer.append(')');
854 :
855 7 : rSet.Put( SfxStringItem( SID_PRINTDOCDIRECT, aBuffer.makeStringAndClear() ) );
856 7 : }
857 : }
858 7 : bEnabled = !pPrinter || !pPrinter->IsPrinting();
859 : }
860 7 : break;
861 : }
862 :
863 : // Mail functions
864 : case SID_MAIL_SENDDOCASPDF:
865 : case SID_MAIL_SENDDOC:
866 : case SID_MAIL_SENDDOCASFORMAT:
867 : {
868 7 : sal_Bool bEnable = !GetViewFrame()->HasChildWindow( SID_MAIL_CHILDWIN );
869 7 : if ( !bEnable )
870 0 : rSet.DisableItem( nSID );
871 7 : break;
872 : }
873 :
874 : // PlugIns running
875 : case SID_PLUGINS_ACTIVE:
876 : {
877 0 : rSet.Put( SfxBoolItem( SID_PLUGINS_ACTIVE, !pImp->m_bPlugInsActive) );
878 0 : break;
879 : }
880 : case SID_STYLE_FAMILY :
881 : {
882 0 : rSet.Put( SfxUInt16Item( SID_STYLE_FAMILY, pImp->m_nFamily ) );
883 0 : break;
884 : }
885 : }
886 14 : }
887 14 : }
888 :
889 : //--------------------------------------------------------------------
890 :
891 0 : void SfxViewShell::SetZoomFactor( const Fraction &rZoomX,
892 : const Fraction &rZoomY )
893 : {
894 : DBG_ASSERT( GetWindow(), "no window" );
895 0 : MapMode aMap( GetWindow()->GetMapMode() );
896 0 : aMap.SetScaleX( rZoomX );
897 0 : aMap.SetScaleY( rZoomY );
898 0 : GetWindow()->SetMapMode( aMap );
899 0 : }
900 :
901 : //--------------------------------------------------------------------
902 0 : ErrCode SfxViewShell::DoVerb(long /*nVerb*/)
903 :
904 : /* [Description]
905 :
906 : Virtual Method used to perform a Verb on a selected Object.
907 : Since this Object is just known by the derived classes, DoVerb
908 : must be overloaded.
909 : */
910 :
911 : {
912 0 : return ERRCODE_SO_NOVERBS;
913 : }
914 :
915 : //--------------------------------------------------------------------
916 :
917 0 : void SfxViewShell::OutplaceActivated( sal_Bool bActive, SfxInPlaceClient* /*pClient*/ )
918 : {
919 0 : if ( !bActive )
920 0 : GetFrame()->GetFrame().Appear();
921 0 : }
922 :
923 : //--------------------------------------------------------------------
924 :
925 0 : void SfxViewShell::InplaceActivating( SfxInPlaceClient* /*pClient*/ )
926 : {
927 : // TODO/LATER: painting of the bitmap can be stopped, it is required if CLIPCHILDREN problem #i25788# is not solved,
928 : // but may be the bug will not affect the real office vcl windows, then it is not required
929 0 : }
930 :
931 : //--------------------------------------------------------------------
932 :
933 0 : void SfxViewShell::InplaceDeactivated( SfxInPlaceClient* /*pClient*/ )
934 : {
935 : // TODO/LATER: paint the replacement image in normal way if the painting was stopped
936 0 : }
937 :
938 : //--------------------------------------------------------------------
939 :
940 0 : void SfxViewShell::UIActivating( SfxInPlaceClient* /*pClient*/ )
941 : {
942 0 : uno::Reference < frame::XFrame > xOwnFrame( pFrame->GetFrame().GetFrameInterface() );
943 0 : uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
944 0 : if ( xParentFrame.is() )
945 0 : xParentFrame->setActiveFrame( xOwnFrame );
946 :
947 0 : pFrame->GetBindings().HidePopups(sal_True);
948 0 : pFrame->GetDispatcher()->Update_Impl( sal_True );
949 0 : }
950 :
951 : //--------------------------------------------------------------------
952 :
953 0 : void SfxViewShell::UIDeactivated( SfxInPlaceClient* /*pClient*/ )
954 : {
955 0 : if ( !pFrame->GetFrame().IsClosing_Impl() || SfxViewFrame::Current() != pFrame )
956 0 : pFrame->GetDispatcher()->Update_Impl( sal_True );
957 0 : pFrame->GetBindings().HidePopups(sal_False);
958 :
959 0 : }
960 :
961 : //--------------------------------------------------------------------
962 :
963 572 : SfxInPlaceClient* SfxViewShell::FindIPClient
964 : (
965 : const uno::Reference < embed::XEmbeddedObject >& xObj,
966 : Window* pObjParentWin
967 : ) const
968 : {
969 572 : SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
970 572 : if ( !pClients )
971 572 : return 0;
972 :
973 0 : if( !pObjParentWin )
974 0 : pObjParentWin = GetWindow();
975 0 : for ( size_t n = 0; n < pClients->size(); n++)
976 : {
977 0 : SfxInPlaceClient *pIPClient = (SfxInPlaceClient*) pClients->at( n );
978 0 : if ( pIPClient->GetObject() == xObj && pIPClient->GetEditWin() == pObjParentWin )
979 0 : return pIPClient;
980 : }
981 :
982 0 : return 0;
983 : }
984 :
985 : //--------------------------------------------------------------------
986 :
987 2936 : SfxInPlaceClient* SfxViewShell::GetIPClient() const
988 : {
989 2936 : return GetUIActiveClient();
990 : }
991 :
992 : //--------------------------------------------------------------------
993 :
994 1526 : SfxInPlaceClient* SfxViewShell::GetUIActiveIPClient_Impl() const
995 : {
996 : // this method is needed as long as SFX still manages the border space for ChildWindows (see SfxFrame::Resize)
997 1526 : SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
998 1526 : if ( !pClients )
999 1526 : return 0;
1000 :
1001 0 : for ( size_t n = 0; n < pClients->size(); n++)
1002 : {
1003 0 : SfxInPlaceClient* pIPClient = pClients->at( n );
1004 0 : if ( pIPClient->IsUIActive() )
1005 0 : return pIPClient;
1006 : }
1007 :
1008 0 : return NULL;
1009 : }
1010 :
1011 9558 : SfxInPlaceClient* SfxViewShell::GetUIActiveClient() const
1012 : {
1013 9558 : SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1014 9558 : if ( !pClients )
1015 9558 : return 0;
1016 :
1017 0 : for ( size_t n = 0; n < pClients->size(); n++)
1018 : {
1019 0 : SfxInPlaceClient* pIPClient = pClients->at( n );
1020 0 : if ( pIPClient->IsObjectUIActive() )
1021 0 : return pIPClient;
1022 : }
1023 :
1024 0 : return NULL;
1025 : }
1026 :
1027 : //--------------------------------------------------------------------
1028 :
1029 508 : void SfxViewShell::Activate( sal_Bool bMDI )
1030 : {
1031 : DBG_CHKTHIS(SfxViewShell, 0);
1032 508 : if ( bMDI )
1033 : {
1034 508 : SfxObjectShell *pSh = GetViewFrame()->GetObjectShell();
1035 508 : if ( pSh->GetModel().is() )
1036 508 : pSh->GetModel()->setCurrentController( GetViewFrame()->GetFrame().GetController() );
1037 :
1038 508 : SetCurrentDocument();
1039 : }
1040 508 : }
1041 :
1042 : //--------------------------------------------------------------------
1043 :
1044 504 : void SfxViewShell::Deactivate(sal_Bool /*bMDI*/)
1045 : {
1046 : DBG_CHKTHIS(SfxViewShell, 0);
1047 504 : }
1048 :
1049 : //--------------------------------------------------------------------
1050 :
1051 0 : void SfxViewShell::AdjustPosSizePixel
1052 : (
1053 : const Point& /*rToolOffset*/,// Upper left corner Tools in Frame-Window
1054 : const Size& /*rSize*/ // All available sizes.
1055 : )
1056 :
1057 : {
1058 : DBG_CHKTHIS(SfxViewShell, 0);
1059 0 : }
1060 :
1061 : //--------------------------------------------------------------------
1062 :
1063 0 : void SfxViewShell::Move()
1064 :
1065 : /* [Description]
1066 :
1067 : This virtual Method is called when the window displayed in the
1068 : SfxViewShell gets a StarView-Move() notification.
1069 :
1070 : This base implementation does not have to be called. .
1071 :
1072 : [Note]
1073 :
1074 : This Method can be used to cancel a selection, in order to catch the
1075 : mouse movement which is due to moving a window.
1076 :
1077 : For now the notification does not work In-Place.
1078 : */
1079 :
1080 : {
1081 0 : }
1082 :
1083 : //--------------------------------------------------------------------
1084 :
1085 0 : void SfxViewShell::OuterResizePixel
1086 : (
1087 : const Point& /*rToolOffset*/,// Upper left corner Tools in Frame-Window
1088 : const Size& /*rSize*/ // All available sizes.
1089 : )
1090 :
1091 : /* [Description]
1092 :
1093 : This Method has to be overloaded to be able to react to the size-change of
1094 : the View. Thus the View is defined as the Edit window and also the
1095 : attached Tools are defined (for example the ruler).
1096 :
1097 : The Edit window must not be changed either in size or position.
1098 :
1099 : The Vis-Area of SfxObjectShell, its scale and position can be changed
1100 : here. The mainuse is to change the size of the Vis-Area.
1101 :
1102 : If the Border is changed due to the new calculation then this has to be set
1103 : by <SfxViewShell::SetBorderPixel(const SvBorder&)>. The Postioning of Tools
1104 : is only allowed after the calling of 'SetBorderPixel'.
1105 :
1106 : [Example]
1107 :
1108 : void AppViewSh::OuterViewResizePixel( const Point &rOfs, const Size &rSz )
1109 : {
1110 : // Calculate Tool position and size externally, do not set!
1111 : // (due to the following Border calculation)
1112 : Point aHLinPos...; Size aHLinSz...;
1113 : ...
1114 :
1115 : // Calculate and Set a Border of Tools which matches rSize.
1116 : SvBorder aBorder...
1117 : SetBorderPixel( aBorder ); // Allow Positioning from here on.
1118 :
1119 : // Arrange Tools
1120 : pHLin->SetPosSizePixel( aHLinPos, aHLinSz );
1121 : ...
1122 : }
1123 :
1124 : [Cross-reference]
1125 :
1126 : <SfxViewShell::InnerResizePixel(const Point&,const Size& rSize)>
1127 : */
1128 :
1129 : {
1130 : DBG_CHKTHIS(SfxViewShell, 0);
1131 0 : SetBorderPixel( SvBorder() );
1132 0 : }
1133 :
1134 : //--------------------------------------------------------------------
1135 :
1136 0 : void SfxViewShell::InnerResizePixel
1137 : (
1138 : const Point& /*rToolOffset*/,// Upper left corner Tools in Frame-Window
1139 : const Size& /*rSize*/ // All available sizes.
1140 : )
1141 :
1142 : /* [Description]
1143 :
1144 : This Method has to be overloaded to be able to react to the size-change of
1145 : the Edit window.
1146 :
1147 : The Edit window must not be changed either in size or position.
1148 : Neither the Vis-Area of SfxObjectShell nor its scale or position are
1149 : allowed to be changed
1150 :
1151 : If the Border is changed due to the new calculation then is has to be set
1152 : by <SfxViewShell::SetBorderPixel(const SvBorder&)>.
1153 : The Postioning of Tools is only allowed after the calling of
1154 : 'SetBorderPixel'.
1155 :
1156 :
1157 : [Note]
1158 :
1159 : void AppViewSh::InnerViewResizePixel( const Point &rOfs, const Size &rSz )
1160 : {
1161 : // Calculate Tool position and size internally, do not set!
1162 : // (due to the following Border calculation)
1163 : Point aHLinPos...; Size aHLinSz...;
1164 : ...
1165 :
1166 : // Calculate and Set a Border of Tools which matches rSize.
1167 : SvBorder aBorder...
1168 : SetBorderPixel( aBorder ); // Allow Positioning from here on.
1169 :
1170 : // Arrange Tools
1171 : pHLin->SetPosSizePixel( aHLinPos, aHLinSz );
1172 : ...
1173 : }
1174 :
1175 : [Cross-reference]
1176 :
1177 : <SfxViewShell::OuterResizePixel(const Point&,const Size& rSize)>
1178 : */
1179 :
1180 : {
1181 : DBG_CHKTHIS(SfxViewShell, 0);
1182 0 : SetBorderPixel( SvBorder() );
1183 0 : }
1184 :
1185 : //--------------------------------------------------------------------
1186 :
1187 1434 : void SfxViewShell::InvalidateBorder()
1188 : {
1189 : DBG_CHKTHIS(SfxViewShell, 0);
1190 : DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
1191 :
1192 1434 : GetViewFrame()->InvalidateBorderImpl( this );
1193 1434 : if (pImp->m_pController.is())
1194 : {
1195 1434 : pImp->m_pController->BorderWidthsChanged_Impl();
1196 : }
1197 1434 : }
1198 :
1199 : //--------------------------------------------------------------------
1200 :
1201 1443 : void SfxViewShell::SetBorderPixel( const SvBorder &rBorder )
1202 : {
1203 : DBG_CHKTHIS(SfxViewShell, 0);
1204 : DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
1205 :
1206 1443 : GetViewFrame()->SetBorderPixelImpl( this, rBorder );
1207 :
1208 : // notify related controller that border size is changed
1209 1443 : if (pImp->m_pController.is())
1210 : {
1211 1413 : pImp->m_pController->BorderWidthsChanged_Impl();
1212 : }
1213 1443 : }
1214 :
1215 : //--------------------------------------------------------------------
1216 :
1217 0 : const SvBorder& SfxViewShell::GetBorderPixel() const
1218 : {
1219 : DBG_CHKTHIS(SfxViewShell, 0);
1220 : DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
1221 :
1222 0 : return GetViewFrame()->GetBorderPixelImpl( this );
1223 : }
1224 :
1225 : //--------------------------------------------------------------------
1226 :
1227 614 : void SfxViewShell::SetWindow
1228 : (
1229 : Window* pViewPort // For example Null pointer in the Destructor.
1230 : )
1231 :
1232 : /* [Description]
1233 :
1234 : With this method the SfxViewShell is set in the data window. This is
1235 : needed for the in-place container and for restoring the proper focus.
1236 :
1237 : Even in-place-active the conversion of the ViewPort Windows is forbidden.
1238 : */
1239 :
1240 : {
1241 614 : if( pWindow == pViewPort )
1242 614 : return;
1243 :
1244 : // Disconnect existing IP-Clients if possible
1245 614 : DisconnectAllClients();
1246 :
1247 : //TODO: should we have a "ReconnectAllClients" method?
1248 614 : DiscardClients_Impl();
1249 :
1250 : // Switch View-Port
1251 614 : sal_Bool bHadFocus = pWindow ? pWindow->HasChildPathFocus( sal_True ) : sal_False;
1252 614 : pWindow = pViewPort;
1253 :
1254 614 : if( pWindow )
1255 : {
1256 : // Disable automatic GUI mirroring (right-to-left) for document windows
1257 516 : pWindow->EnableRTL( sal_False );
1258 : }
1259 :
1260 614 : if ( bHadFocus && pWindow )
1261 0 : pWindow->GrabFocus();
1262 : //TODO/CLEANUP
1263 : //Do we still need this Method?!
1264 : //SFX_APP()->GrabFocus( pWindow );
1265 : }
1266 :
1267 : //--------------------------------------------------------------------
1268 :
1269 0 : Size SfxViewShell::GetOptimalSizePixel() const
1270 : {
1271 : OSL_FAIL( "Useless call!" );
1272 0 : return Size();
1273 : }
1274 :
1275 : //------------------------------------------------------------------------
1276 :
1277 516 : SfxViewShell::SfxViewShell
1278 : (
1279 : SfxViewFrame* pViewFrame, /* <SfxViewFrame>, which will be
1280 : displayed in this View */
1281 : sal_uInt16 nFlags /* See <SfxViewShell-Flags> */
1282 : )
1283 :
1284 : : SfxShell(this)
1285 516 : , pImp( new SfxViewShell_Impl(nFlags) )
1286 : , pIPClientList( 0 )
1287 : , pFrame(pViewFrame)
1288 : , pSubShell(0)
1289 : , pWindow(0)
1290 1032 : , bNoNewWindow( 0 != (nFlags & SFX_VIEW_NO_NEWWINDOW) )
1291 : {
1292 : DBG_CTOR(SfxViewShell, 0);
1293 :
1294 516 : if ( pViewFrame->GetParentViewFrame() )
1295 : {
1296 0 : pImp->m_bPlugInsActive = pViewFrame->GetParentViewFrame()
1297 0 : ->GetViewShell()->pImp->m_bPlugInsActive;
1298 : }
1299 516 : SetMargin( pViewFrame->GetMargin_Impl() );
1300 :
1301 516 : SetPool( &pViewFrame->GetObjectShell()->GetPool() );
1302 516 : StartListening(*pViewFrame->GetObjectShell());
1303 :
1304 : // Insert into list
1305 516 : SfxViewShellArr_Impl &rViewArr = SFX_APP()->GetViewShells_Impl();
1306 516 : rViewArr.push_back(this);
1307 516 : }
1308 :
1309 : //--------------------------------------------------------------------
1310 :
1311 196 : SfxViewShell::~SfxViewShell()
1312 : {
1313 : DBG_DTOR(SfxViewShell, 0);
1314 :
1315 : // Remove from list
1316 98 : const SfxViewShell *pThis = this;
1317 98 : SfxViewShellArr_Impl &rViewArr = SFX_APP()->GetViewShells_Impl();
1318 98 : SfxViewShellArr_Impl::iterator it = std::find( rViewArr.begin(), rViewArr.end(), pThis );
1319 98 : rViewArr.erase( it );
1320 :
1321 98 : if ( pImp->xClipboardListener.is() )
1322 : {
1323 98 : pImp->xClipboardListener->DisconnectViewShell();
1324 98 : pImp->xClipboardListener = NULL;
1325 : }
1326 :
1327 98 : if (pImp->m_pController.is())
1328 : {
1329 98 : pImp->m_pController->ReleaseShell_Impl();
1330 98 : pImp->m_pController.clear();
1331 : }
1332 :
1333 98 : DELETEZ( pImp );
1334 98 : DELETEZ( pIPClientList );
1335 98 : }
1336 :
1337 : //--------------------------------------------------------------------
1338 :
1339 196 : sal_uInt16 SfxViewShell::PrepareClose
1340 : (
1341 : sal_Bool bUI, // TRUE: Allow Dialog and so on, FALSE: silent-mode
1342 : sal_Bool /*bForBrowsing*/
1343 : )
1344 : {
1345 196 : SfxPrinter *pPrinter = GetPrinter();
1346 196 : if ( pPrinter && pPrinter->IsPrinting() )
1347 : {
1348 0 : if ( bUI )
1349 : {
1350 0 : InfoBox aInfoBox( &GetViewFrame()->GetWindow(), SfxResId( MSG_CANT_CLOSE ) );
1351 0 : aInfoBox.Execute();
1352 : }
1353 :
1354 0 : return sal_False;
1355 : }
1356 :
1357 196 : if( GetViewFrame()->IsInModalMode() )
1358 0 : return sal_False;
1359 :
1360 196 : if( bUI && GetViewFrame()->GetDispatcher()->IsLocked() )
1361 0 : return sal_False;
1362 :
1363 196 : return sal_True;
1364 : }
1365 :
1366 : //--------------------------------------------------------------------
1367 :
1368 15526 : SfxViewShell* SfxViewShell::Current()
1369 : {
1370 15526 : SfxViewFrame *pCurrent = SfxViewFrame::Current();
1371 15526 : return pCurrent ? pCurrent->GetViewShell() : NULL;
1372 : }
1373 :
1374 : //--------------------------------------------------------------------
1375 :
1376 524 : SfxViewShell* SfxViewShell::Get( const Reference< XController>& i_rController )
1377 : {
1378 524 : if ( !i_rController.is() )
1379 516 : return NULL;
1380 :
1381 20 : for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst( NULL, sal_False );
1382 : pViewShell;
1383 : pViewShell = SfxViewShell::GetNext( *pViewShell, NULL, sal_False )
1384 : )
1385 : {
1386 20 : if ( pViewShell->GetController() == i_rController )
1387 8 : return pViewShell;
1388 : }
1389 0 : return NULL;
1390 : }
1391 :
1392 : //--------------------------------------------------------------------
1393 :
1394 0 : SdrView* SfxViewShell::GetDrawView() const
1395 :
1396 : /* [Description]
1397 :
1398 : This virtual Method has to be overloded by the sub classes, to be able
1399 : make the Property-Editor available.
1400 :
1401 : The default implementation does always return zero.
1402 : */
1403 :
1404 : {
1405 0 : return 0;
1406 : }
1407 :
1408 : //--------------------------------------------------------------------
1409 :
1410 0 : String SfxViewShell::GetSelectionText
1411 : (
1412 : sal_Bool /*bCompleteWords*/ /* FALSE (default)
1413 : Only the actual selected text is returned.
1414 :
1415 : TRUE
1416 : The selected text is expanded so that only
1417 : whole words are returned. As word separators
1418 : these are used: white spaces and punctuation
1419 : ".,;" and single and double quotes.
1420 : */
1421 : )
1422 :
1423 : /* [Description]
1424 :
1425 : This Method can be overloaded by the programmers to return a text that
1426 : is included in the current selection. This is for example used when
1427 : sending emails.
1428 :
1429 : When called with "CompleteWords == TRUE", it is for example sufficent
1430 : with having the Cursor positioned somewhere within an URL in-order
1431 : to have the entire URL returned.
1432 : */
1433 :
1434 : {
1435 0 : return String();
1436 : }
1437 :
1438 : //--------------------------------------------------------------------
1439 :
1440 0 : sal_Bool SfxViewShell::HasSelection( sal_Bool ) const
1441 :
1442 : /* [Description]
1443 :
1444 : With this virtual Method can a for example a Dialog be queried, to
1445 : check if something is selected in the current view. If the Parameter
1446 : is <BOOL> TRUE then it is checked whether some text is selected.
1447 : */
1448 :
1449 : {
1450 0 : return sal_False;
1451 : }
1452 :
1453 66 : void SfxViewShell::AddSubShell( SfxShell& rShell )
1454 : {
1455 66 : pImp->aArr.push_back(&rShell);
1456 66 : SfxDispatcher *pDisp = pFrame->GetDispatcher();
1457 66 : if ( pDisp->IsActive(*this) )
1458 : {
1459 6 : pDisp->Push(rShell);
1460 6 : pDisp->Flush();
1461 : }
1462 66 : }
1463 :
1464 28 : void SfxViewShell::RemoveSubShell( SfxShell* pShell )
1465 : {
1466 28 : SfxDispatcher *pDisp = pFrame->GetDispatcher();
1467 28 : if ( !pShell )
1468 : {
1469 28 : size_t nCount = pImp->aArr.size();
1470 28 : if ( pDisp->IsActive(*this) )
1471 : {
1472 6 : for(size_t n = nCount; n > 0; --n)
1473 4 : pDisp->Pop(*pImp->aArr[n - 1]);
1474 2 : pDisp->Flush();
1475 : }
1476 28 : pImp->aArr.clear();
1477 : }
1478 : else
1479 : {
1480 0 : SfxShellArr_Impl::iterator i = std::find(pImp->aArr.begin(), pImp->aArr.end(), pShell);
1481 0 : if(i != pImp->aArr.end())
1482 : {
1483 0 : pImp->aArr.erase(i);
1484 0 : if(pDisp->IsActive(*this))
1485 : {
1486 0 : pDisp->RemoveShell_Impl(*pShell);
1487 0 : pDisp->Flush();
1488 : }
1489 : }
1490 : }
1491 28 : }
1492 :
1493 0 : SfxShell* SfxViewShell::GetSubShell( sal_uInt16 nNo )
1494 : {
1495 0 : sal_uInt16 nCount = pImp->aArr.size();
1496 0 : if(nNo < nCount)
1497 0 : return pImp->aArr[nCount - nNo - 1];
1498 0 : return NULL;
1499 : }
1500 :
1501 614 : void SfxViewShell::PushSubShells_Impl( sal_Bool bPush )
1502 : {
1503 614 : SfxDispatcher *pDisp = pFrame->GetDispatcher();
1504 614 : if ( bPush )
1505 : {
1506 576 : for(SfxShellArr_Impl::const_iterator i = pImp->aArr.begin(); i != pImp->aArr.end(); ++i)
1507 60 : pDisp->Push(**i);
1508 : }
1509 98 : else if(!pImp->aArr.empty())
1510 : {
1511 26 : SfxShell& rPopUntil = *pImp->aArr[0];
1512 26 : if ( pDisp->GetShellLevel( rPopUntil ) != USHRT_MAX )
1513 26 : pDisp->Pop( rPopUntil, SFX_SHELL_POP_UNTIL );
1514 : }
1515 :
1516 614 : pDisp->Flush();
1517 614 : }
1518 :
1519 : //--------------------------------------------------------------------
1520 :
1521 0 : void SfxViewShell::WriteUserData( String&, sal_Bool )
1522 : {
1523 0 : }
1524 :
1525 : //--------------------------------------------------------------------
1526 :
1527 0 : void SfxViewShell::ReadUserData(const String&, sal_Bool )
1528 : {
1529 0 : }
1530 :
1531 0 : void SfxViewShell::ReadUserDataSequence ( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool )
1532 : {
1533 0 : }
1534 :
1535 0 : void SfxViewShell::WriteUserDataSequence ( ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool )
1536 : {
1537 0 : }
1538 :
1539 :
1540 : //--------------------------------------------------------------------
1541 : // returns the first shell of spec. type viewing the specified doc.
1542 :
1543 66 : SfxViewShell* SfxViewShell::GetFirst
1544 : (
1545 : const TypeId* pType,
1546 : sal_Bool bOnlyVisible
1547 : )
1548 : {
1549 : // search for a SfxViewShell of the specified type
1550 66 : SfxViewShellArr_Impl &rShells = SFX_APP()->GetViewShells_Impl();
1551 66 : SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl();
1552 66 : for ( sal_uInt16 nPos = 0; nPos < rShells.size(); ++nPos )
1553 : {
1554 64 : SfxViewShell *pShell = rShells[nPos];
1555 64 : if ( pShell )
1556 : {
1557 : // sometimes dangling SfxViewShells exist that point to a dead SfxViewFrame
1558 : // these ViewShells shouldn't be accessible anymore
1559 : // a destroyed ViewFrame is not in the ViewFrame array anymore, so checking this array helps
1560 64 : for ( sal_uInt16 n=0; n<rFrames.size(); ++n )
1561 : {
1562 64 : SfxViewFrame *pFrame = rFrames[n];
1563 64 : if ( pFrame == pShell->GetViewFrame() )
1564 : {
1565 : // only ViewShells with a valid ViewFrame will be returned
1566 64 : if ( ( !bOnlyVisible || pFrame->IsVisible() ) && ( !pType || pShell->IsA(*pType) ) )
1567 64 : return pShell;
1568 0 : break;
1569 : }
1570 : }
1571 : }
1572 : }
1573 :
1574 2 : return 0;
1575 : }
1576 :
1577 : //--------------------------------------------------------------------
1578 : // returns the next shell of spec. type viewing the specified doc.
1579 :
1580 80 : SfxViewShell* SfxViewShell::GetNext
1581 : (
1582 : const SfxViewShell& rPrev,
1583 : const TypeId* pType,
1584 : sal_Bool bOnlyVisible
1585 : )
1586 : {
1587 80 : SfxViewShellArr_Impl &rShells = SFX_APP()->GetViewShells_Impl();
1588 80 : SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl();
1589 : sal_uInt16 nPos;
1590 336 : for ( nPos = 0; nPos < rShells.size(); ++nPos )
1591 336 : if ( rShells[nPos] == &rPrev )
1592 80 : break;
1593 :
1594 80 : for ( ++nPos; nPos < rShells.size(); ++nPos )
1595 : {
1596 50 : SfxViewShell *pShell = rShells[nPos];
1597 50 : if ( pShell )
1598 : {
1599 : // sometimes dangling SfxViewShells exist that point to a dead SfxViewFrame
1600 : // these ViewShells shouldn't be accessible anymore
1601 : // a destroyed ViewFrame is not in the ViewFrame array anymore, so checking this array helps
1602 320 : for ( sal_uInt16 n=0; n<rFrames.size(); ++n )
1603 : {
1604 320 : SfxViewFrame *pFrame = rFrames[n];
1605 320 : if ( pFrame == pShell->GetViewFrame() )
1606 : {
1607 : // only ViewShells with a valid ViewFrame will be returned
1608 50 : if ( ( !bOnlyVisible || pFrame->IsVisible() ) && ( !pType || pShell->IsA(*pType) ) )
1609 50 : return pShell;
1610 0 : break;
1611 : }
1612 : }
1613 : }
1614 : }
1615 :
1616 30 : return 0;
1617 : }
1618 :
1619 : //--------------------------------------------------------------------
1620 :
1621 4757 : void SfxViewShell::Notify( SfxBroadcaster& rBC,
1622 : const SfxHint& rHint )
1623 : {
1624 4757 : if ( rHint.IsA(TYPE(SfxEventHint)) )
1625 : {
1626 2752 : switch ( ((SfxEventHint&)rHint).GetEventId() )
1627 : {
1628 : case SFX_EVENT_LOADFINISHED:
1629 : {
1630 2 : if ( GetController().is() )
1631 : {
1632 : // avoid access to dangling ViewShells
1633 2 : SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl();
1634 4 : for ( sal_uInt16 n=0; n<rFrames.size(); ++n )
1635 : {
1636 2 : SfxViewFrame *frame = rFrames[n];
1637 2 : if ( frame == GetViewFrame() && &rBC == GetObjectShell() )
1638 : {
1639 0 : SfxItemSet* pSet = GetObjectShell()->GetMedium()->GetItemSet();
1640 0 : SFX_ITEMSET_ARG( pSet, pItem, SfxUnoAnyItem, SID_VIEW_DATA, sal_False );
1641 0 : if ( pItem )
1642 : {
1643 0 : pImp->m_pController->restoreViewData( pItem->GetValue() );
1644 0 : pSet->ClearItem( SID_VIEW_DATA );
1645 : }
1646 :
1647 0 : break;
1648 : }
1649 : }
1650 : }
1651 :
1652 2 : break;
1653 : }
1654 : }
1655 : }
1656 4757 : }
1657 :
1658 : //--------------------------------------------------------------------
1659 :
1660 0 : sal_Bool SfxViewShell::ExecKey_Impl(const KeyEvent& aKey)
1661 : {
1662 0 : if (!pImp->m_pAccExec.get())
1663 : {
1664 : pImp->m_pAccExec.reset(
1665 0 : ::svt::AcceleratorExecute::createAcceleratorHelper() );
1666 0 : pImp->m_pAccExec->init(::comphelper::getProcessServiceFactory(),
1667 0 : pFrame->GetFrame().GetFrameInterface());
1668 : }
1669 :
1670 0 : return pImp->m_pAccExec->execute(aKey.GetKeyCode());
1671 : }
1672 :
1673 : //--------------------------------------------------------------------
1674 :
1675 0 : bool SfxViewShell::KeyInput( const KeyEvent &rKeyEvent )
1676 :
1677 : /* [Description]
1678 :
1679 : This Method executes the KeyEvent 'rKeyEvent' of the Keys (Accelerator)
1680 : configured either direct or indirect (for example by the Application)
1681 : in the SfxViewShell.
1682 :
1683 : [Return value]
1684 :
1685 : bool TRUE
1686 : The Key (Accelerator) is configured and the
1687 : the associated Handler was called
1688 :
1689 : FALSE
1690 : The Key (Accelerator) is not configured and
1691 : subsequently no Handler was called
1692 :
1693 : [Cross-reference]
1694 :
1695 : <SfxApplication::KeyInput(const KeyEvent&)>
1696 : */
1697 : {
1698 0 : return ExecKey_Impl(rKeyEvent);
1699 : }
1700 :
1701 0 : bool SfxViewShell::GlobalKeyInput_Impl( const KeyEvent &rKeyEvent )
1702 : {
1703 0 : return ExecKey_Impl(rKeyEvent);
1704 : }
1705 :
1706 : //--------------------------------------------------------------------
1707 :
1708 0 : void SfxViewShell::ShowCursor( bool /*bOn*/ )
1709 :
1710 : /* [Description]
1711 :
1712 : This Method has to be overloaded by the subclasses so that SFx from
1713 : the Cursor can be switched on and off. This happes for example with
1714 : with the running <SfxProgress>.
1715 : */
1716 :
1717 : {
1718 0 : }
1719 :
1720 : //--------------------------------------------------------------------
1721 :
1722 26 : void SfxViewShell::GotFocus() const
1723 :
1724 : /* [Description]
1725 :
1726 : This Method has to be called by the programmer, when the
1727 : Edit window has received the focus. This gives for example the SFx
1728 : the power to turn on the accelerator.
1729 :
1730 : [Note]
1731 :
1732 : <StarView> does sadly enough not provide the possibillity to attach
1733 : such "side-way" events.
1734 : */
1735 :
1736 : {
1737 26 : }
1738 :
1739 : //--------------------------------------------------------------------
1740 0 : void SfxViewShell::ResetAllClients_Impl( SfxInPlaceClient *pIP )
1741 : {
1742 :
1743 0 : SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1744 0 : if ( !pClients )
1745 0 : return;
1746 :
1747 0 : for ( size_t n = 0; n < pClients->size(); n++ )
1748 : {
1749 0 : SfxInPlaceClient* pIPClient = pClients->at( n );
1750 0 : if( pIPClient != pIP )
1751 0 : pIPClient->ResetObject();
1752 : }
1753 : }
1754 :
1755 : //--------------------------------------------------------------------
1756 :
1757 750 : void SfxViewShell::DisconnectAllClients()
1758 : {
1759 750 : SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1760 750 : if ( !pClients )
1761 1500 : return;
1762 :
1763 0 : for ( size_t n = 0; n < pClients->size(); )
1764 : // clients will remove themselves from the list
1765 0 : delete pClients->at( n );
1766 : }
1767 :
1768 : //--------------------------------------------------------------------
1769 :
1770 0 : void SfxViewShell::QueryObjAreaPixel( Rectangle& ) const
1771 : {
1772 0 : }
1773 :
1774 : //--------------------------------------------------------------------
1775 :
1776 1218 : void SfxViewShell::VisAreaChanged(const Rectangle& /*rVisArea*/)
1777 : {
1778 1218 : SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1779 1218 : if ( !pClients )
1780 2436 : return;
1781 :
1782 0 : for ( size_t n = 0; n < pClients->size(); n++)
1783 : {
1784 0 : SfxInPlaceClient* pIPClient = pClients->at( n );
1785 0 : if ( pIPClient->IsObjectInPlaceActive() )
1786 : // client is active, notify client that the VisArea might have changed
1787 0 : pIPClient->VisAreaChanged();
1788 : }
1789 : }
1790 :
1791 : //--------------------------------------------------------------------
1792 0 : void SfxViewShell::CheckIPClient_Impl( SfxInPlaceClient *pIPClient, const Rectangle& rVisArea )
1793 : {
1794 0 : if ( GetObjectShell()->IsInClose() )
1795 0 : return;
1796 :
1797 : sal_Bool bAlwaysActive =
1798 0 : ( ( pIPClient->GetObjectMiscStatus() & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) != 0 );
1799 : sal_Bool bActiveWhenVisible =
1800 0 : ( ( pIPClient->GetObjectMiscStatus() & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE ) != 0 );
1801 :
1802 : // this method is called when either a client is created or the "Edit/Plugins" checkbox is checked
1803 0 : if ( !pIPClient->IsObjectInPlaceActive() && pImp->m_bPlugInsActive )
1804 : {
1805 : // object in client is currently not active
1806 : // check if the object wants to be activated always or when it becomes at least partially visible
1807 : // TODO/LATER: maybe we should use the scaled area instead of the ObjArea?!
1808 0 : if ( bAlwaysActive || (bActiveWhenVisible && rVisArea.IsOver(pIPClient->GetObjArea())) )
1809 : {
1810 : try
1811 : {
1812 0 : pIPClient->GetObject()->changeState( embed::EmbedStates::INPLACE_ACTIVE );
1813 : }
1814 0 : catch (const uno::Exception&)
1815 : {
1816 : }
1817 : }
1818 : }
1819 0 : else if (!pImp->m_bPlugInsActive)
1820 : {
1821 : // object in client is currently active and "Edit/Plugins" checkbox is selected
1822 : // check if the object wants to be activated always or when it becomes at least partially visible
1823 : // in this case selecting of the "Edit/Plugin" checkbox should let such objects deactivate
1824 0 : if ( bAlwaysActive || bActiveWhenVisible )
1825 0 : pIPClient->GetObject()->changeState( embed::EmbedStates::RUNNING );
1826 : }
1827 : }
1828 :
1829 : //--------------------------------------------------------------------
1830 810 : void SfxViewShell::DiscardClients_Impl()
1831 :
1832 : /* [Description]
1833 :
1834 : The purpose of this Method is to prevent the saving of Objects when closing
1835 : the Document, if the user has chosen to close without saving.
1836 : */
1837 :
1838 : {
1839 810 : SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1840 810 : if ( !pClients )
1841 1620 : return;
1842 :
1843 0 : for ( size_t n = 0; n < pClients->size(); )
1844 0 : delete pClients->at( n );
1845 : }
1846 :
1847 : //--------------------------------------------------------------------
1848 :
1849 89969 : SfxObjectShell* SfxViewShell::GetObjectShell()
1850 : {
1851 89969 : return pFrame ? pFrame->GetObjectShell() : NULL;
1852 : }
1853 :
1854 : //--------------------------------------------------------------------
1855 :
1856 1336 : Reference< XModel > SfxViewShell::GetCurrentDocument() const
1857 : {
1858 1336 : Reference< XModel > xDocument;
1859 :
1860 1336 : const SfxObjectShell* pDocShell( const_cast< SfxViewShell* >( this )->GetObjectShell() );
1861 : OSL_ENSURE( pDocShell, "SfxViewFrame::GetCurrentDocument: no DocShell!?" );
1862 1336 : if ( pDocShell )
1863 1336 : xDocument = pDocShell->GetModel();
1864 1336 : return xDocument;
1865 : }
1866 :
1867 : //--------------------------------------------------------------------
1868 :
1869 1336 : void SfxViewShell::SetCurrentDocument() const
1870 : {
1871 1336 : uno::Reference< frame::XModel > xDocument( GetCurrentDocument() );
1872 1336 : if ( xDocument.is() )
1873 1336 : SfxObjectShell::SetCurrentComponent( xDocument );
1874 1336 : }
1875 :
1876 : //--------------------------------------------------------------------
1877 :
1878 478 : const Size& SfxViewShell::GetMargin() const
1879 : {
1880 478 : return pImp->aMargin;
1881 : }
1882 :
1883 : //--------------------------------------------------------------------
1884 :
1885 516 : void SfxViewShell::SetMargin( const Size& rSize )
1886 : {
1887 : // the default margin was verified using www.apple.com !!
1888 516 : Size aMargin = rSize;
1889 516 : if ( aMargin.Width() == -1 )
1890 516 : aMargin.Width() = DEFAULT_MARGIN_WIDTH;
1891 516 : if ( aMargin.Height() == -1 )
1892 516 : aMargin.Height() = DEFAULT_MARGIN_HEIGHT;
1893 :
1894 516 : if ( aMargin != pImp->aMargin )
1895 : {
1896 516 : pImp->aMargin = aMargin;
1897 516 : MarginChanged();
1898 : }
1899 516 : }
1900 :
1901 : //--------------------------------------------------------------------
1902 :
1903 516 : void SfxViewShell::MarginChanged()
1904 : {
1905 516 : }
1906 :
1907 : //--------------------------------------------------------------------
1908 :
1909 516 : sal_Bool SfxViewShell::IsShowView_Impl() const
1910 : {
1911 516 : return pImp->m_bIsShowView;
1912 : }
1913 :
1914 : //--------------------------------------------------------------------
1915 :
1916 0 : SfxFrame* SfxViewShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ )
1917 : {
1918 0 : return pSelf;
1919 : }
1920 :
1921 : //------------------------------------------------------------------------
1922 :
1923 0 : void SfxViewShell::JumpToMark( const String& rMark )
1924 : {
1925 0 : SfxStringItem aMarkItem( SID_JUMPTOMARK, rMark );
1926 : GetViewFrame()->GetDispatcher()->Execute(
1927 : SID_JUMPTOMARK,
1928 : SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
1929 0 : &aMarkItem, 0L );
1930 0 : }
1931 :
1932 : //------------------------------------------------------------------------
1933 :
1934 14434 : SfxInPlaceClientList* SfxViewShell::GetIPClientList_Impl( sal_Bool bCreate ) const
1935 : {
1936 14434 : if ( !pIPClientList && bCreate )
1937 0 : ( (SfxViewShell*) this )->pIPClientList = new SfxInPlaceClientList;
1938 14434 : return pIPClientList;
1939 : }
1940 :
1941 524 : void SfxViewShell::SetController( SfxBaseController* pController )
1942 : {
1943 524 : pImp->m_pController = pController;
1944 524 : pImp->m_bControllerSet = true;
1945 :
1946 : // there should be no old listener, but if there is one, it should be disconnected
1947 524 : if ( pImp->xClipboardListener.is() )
1948 8 : pImp->xClipboardListener->DisconnectViewShell();
1949 :
1950 524 : pImp->xClipboardListener = new SfxClipboardChangeListener( this, GetClipboardNotifier() );
1951 524 : }
1952 :
1953 3788 : Reference < XController > SfxViewShell::GetController()
1954 : {
1955 3788 : return pImp->m_pController.get();
1956 : }
1957 :
1958 516 : SfxBaseController* SfxViewShell::GetBaseController_Impl() const
1959 : {
1960 516 : return pImp->m_pController.get();
1961 : }
1962 :
1963 0 : void SfxViewShell::AddContextMenuInterceptor_Impl( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor )
1964 : {
1965 0 : pImp->aInterceptorContainer.addInterface( xInterceptor );
1966 0 : }
1967 :
1968 0 : void SfxViewShell::RemoveContextMenuInterceptor_Impl( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor )
1969 : {
1970 0 : pImp->aInterceptorContainer.removeInterface( xInterceptor );
1971 0 : }
1972 :
1973 0 : void Change( Menu* pMenu, SfxViewShell* pView )
1974 : {
1975 0 : SfxDispatcher *pDisp = pView->GetViewFrame()->GetDispatcher();
1976 0 : sal_uInt16 nCount = pMenu->GetItemCount();
1977 0 : for ( sal_uInt16 nPos=0; nPos<nCount; ++nPos )
1978 : {
1979 0 : sal_uInt16 nId = pMenu->GetItemId(nPos);
1980 0 : String aCmd = pMenu->GetItemCommand(nId);
1981 0 : PopupMenu* pPopup = pMenu->GetPopupMenu(nId);
1982 0 : if ( pPopup )
1983 : {
1984 0 : Change( pPopup, pView );
1985 : }
1986 0 : else if ( nId < 5000 )
1987 : {
1988 0 : if ( aCmd.CompareToAscii(".uno:", 5) == 0 )
1989 : {
1990 0 : for (sal_uInt16 nIdx=0;;)
1991 : {
1992 0 : SfxShell *pShell=pDisp->GetShell(nIdx++);
1993 0 : if (pShell == NULL)
1994 0 : break;
1995 0 : const SfxInterface *pIFace = pShell->GetInterface();
1996 0 : const SfxSlot* pSlot = pIFace->GetSlot( aCmd );
1997 0 : if ( pSlot )
1998 : {
1999 0 : pMenu->InsertItem( pSlot->GetSlotId(), pMenu->GetItemText( nId ), pMenu->GetItemBits( nId ), nPos );
2000 0 : pMenu->SetItemCommand( pSlot->GetSlotId(), aCmd );
2001 0 : pMenu->RemoveItem( nPos+1 );
2002 0 : break;
2003 : }
2004 : }
2005 : }
2006 : }
2007 0 : }
2008 0 : }
2009 :
2010 :
2011 0 : sal_Bool SfxViewShell::TryContextMenuInterception( Menu& rIn, const ::rtl::OUString& rMenuIdentifier, Menu*& rpOut, ui::ContextMenuExecuteEvent aEvent )
2012 : {
2013 0 : rpOut = NULL;
2014 0 : sal_Bool bModified = sal_False;
2015 :
2016 : // create container from menu
2017 : aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu(
2018 0 : ::comphelper::getProcessServiceFactory(), &rIn, &rMenuIdentifier );
2019 :
2020 : // get selection from controller
2021 0 : aEvent.Selection = uno::Reference < view::XSelectionSupplier > ( GetController(), uno::UNO_QUERY );
2022 :
2023 : // call interceptors
2024 0 : ::cppu::OInterfaceIteratorHelper aIt( pImp->aInterceptorContainer );
2025 0 : while( aIt.hasMoreElements() )
2026 : {
2027 : try
2028 : {
2029 : ui::ContextMenuInterceptorAction eAction =
2030 0 : ((ui::XContextMenuInterceptor*)aIt.next())->notifyContextMenuExecute( aEvent );
2031 0 : switch ( eAction )
2032 : {
2033 : case ui::ContextMenuInterceptorAction_CANCELLED :
2034 : // interceptor does not want execution
2035 0 : return sal_False;
2036 : case ui::ContextMenuInterceptorAction_EXECUTE_MODIFIED :
2037 : // interceptor wants his modified menu to be executed
2038 0 : bModified = sal_True;
2039 0 : break;
2040 : case ui::ContextMenuInterceptorAction_CONTINUE_MODIFIED :
2041 : // interceptor has modified menu, but allows for calling other interceptors
2042 0 : bModified = sal_True;
2043 0 : continue;
2044 : case ui::ContextMenuInterceptorAction_IGNORED :
2045 : // interceptor is indifferent
2046 0 : continue;
2047 : default:
2048 : OSL_FAIL("Wrong return value of ContextMenuInterceptor!");
2049 0 : continue;
2050 : }
2051 : }
2052 0 : catch (...)
2053 : {
2054 0 : aIt.remove();
2055 : }
2056 :
2057 0 : break;
2058 : }
2059 :
2060 0 : if ( bModified )
2061 : {
2062 : // container was modified, create a new window out of it
2063 0 : rpOut = new PopupMenu;
2064 0 : ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer( rpOut, aEvent.ActionTriggerContainer );
2065 :
2066 0 : Change( rpOut, this );
2067 : }
2068 :
2069 0 : return sal_True;
2070 : }
2071 :
2072 0 : void SfxViewShell::TakeOwnerShip_Impl()
2073 : {
2074 : // currently there is only one reason to take OwnerShip: a hidden frame is printed
2075 : // so the ViewShell will check this on EndPrint (->prnmon.cxx)
2076 0 : pImp->m_bGotOwnership = true;
2077 0 : }
2078 :
2079 0 : void SfxViewShell::TakeFrameOwnerShip_Impl()
2080 : {
2081 : // currently there is only one reason to take OwnerShip: a hidden frame is printed
2082 : // so the ViewShell will check this on EndPrint (->prnmon.cxx)
2083 0 : pImp->m_bGotFrameOwnership = true;
2084 0 : }
2085 :
2086 0 : long SfxViewShell::HandleNotifyEvent_Impl( NotifyEvent& rEvent )
2087 : {
2088 0 : if (pImp->m_pController.is())
2089 0 : return pImp->m_pController->HandleEvent_Impl( rEvent );
2090 0 : return 0;
2091 : }
2092 :
2093 0 : sal_Bool SfxViewShell::HasKeyListeners_Impl()
2094 : {
2095 0 : return (pImp->m_pController.is())
2096 0 : ? pImp->m_pController->HasKeyListeners_Impl() : sal_False;
2097 : }
2098 :
2099 0 : sal_Bool SfxViewShell::HasMouseClickListeners_Impl()
2100 : {
2101 0 : return (pImp->m_pController.is())
2102 0 : ? pImp->m_pController->HasMouseClickListeners_Impl() : sal_False;
2103 : }
2104 :
2105 0 : sal_Bool SfxViewShell::Escape()
2106 : {
2107 0 : return GetViewFrame()->GetBindings().Execute( SID_TERMINATE_INPLACEACTIVATION );
2108 : }
2109 :
2110 0 : Reference< view::XRenderable > SfxViewShell::GetRenderable()
2111 : {
2112 0 : Reference< view::XRenderable >xRender;
2113 0 : SfxObjectShell* pObj = GetObjectShell();
2114 0 : if( pObj )
2115 : {
2116 0 : Reference< frame::XModel > xModel( pObj->GetModel() );
2117 0 : if( xModel.is() )
2118 0 : xRender = Reference< view::XRenderable >( xModel, UNO_QUERY );
2119 : }
2120 0 : return xRender;
2121 : }
2122 :
2123 524 : uno::Reference< datatransfer::clipboard::XClipboardNotifier > SfxViewShell::GetClipboardNotifier()
2124 : {
2125 524 : uno::Reference< datatransfer::clipboard::XClipboardNotifier > xClipboardNotifier;
2126 524 : if ( GetViewFrame() )
2127 : xClipboardNotifier = uno::Reference< datatransfer::clipboard::XClipboardNotifier >(
2128 524 : GetViewFrame()->GetWindow().GetClipboard(), uno::UNO_QUERY );
2129 :
2130 524 : return xClipboardNotifier;
2131 : }
2132 :
2133 4 : void SfxViewShell::AddRemoveClipboardListener( const uno::Reference < datatransfer::clipboard::XClipboardListener >& rClp, sal_Bool bAdd )
2134 : {
2135 : try
2136 : {
2137 4 : if ( GetViewFrame() )
2138 : {
2139 4 : uno::Reference< datatransfer::clipboard::XClipboard > xClipboard( GetViewFrame()->GetWindow().GetClipboard() );
2140 4 : if( xClipboard.is() )
2141 : {
2142 4 : uno::Reference< datatransfer::clipboard::XClipboardNotifier > xClpbrdNtfr( xClipboard, uno::UNO_QUERY );
2143 4 : if( xClpbrdNtfr.is() )
2144 : {
2145 4 : if( bAdd )
2146 2 : xClpbrdNtfr->addClipboardListener( rClp );
2147 : else
2148 2 : xClpbrdNtfr->removeClipboardListener( rClp );
2149 4 : }
2150 4 : }
2151 : }
2152 : }
2153 0 : catch (const uno::Exception&)
2154 : {
2155 : }
2156 4 : }
2157 :
2158 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|