1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 #include <svl/stritem.hxx>
27 #include <svl/eitem.hxx>
28 #include <svl/whiter.hxx>
29 #include <vcl/msgbox.hxx>
30 #include <vcl/toolbox.hxx>
31 #include <svl/intitem.hxx>
32 #include <svtools/sfxecode.hxx>
33 #include <svtools/ehdl.hxx>
34 #include <com/sun/star/frame/XLayoutManager.hpp>
35 #include <com/sun/star/frame/XModuleManager.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/embed/EmbedStates.hpp>
38 #include <com/sun/star/embed/EmbedMisc.hpp>
39 #include <com/sun/star/system/SystemShellExecute.hpp>
40 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
41 #include <com/sun/star/container/XContainerQuery.hpp>
42 #include <com/sun/star/frame/XStorable.hpp>
43 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
44 #include <cppuhelper/implbase1.hxx>
45
46 #include <osl/file.hxx>
47 #include <vos/mutex.hxx>
48 #include <tools/urlobj.hxx>
49 #include <unotools/tempfile.hxx>
50 #include <unotools/pathoptions.hxx>
51 #include <svtools/miscopt.hxx>
52 #include <svtools/soerr.hxx>
53 #include <unotools/internaloptions.hxx>
54
55 #include <unotools/javaoptions.hxx>
56 #include <basic/basmgr.hxx>
57 #include <basic/sbuno.hxx>
58 #include <framework/actiontriggerhelper.hxx>
59 #include <comphelper/processfactory.hxx>
60 #include <comphelper/sequenceashashmap.hxx>
61 #include <toolkit/helper/vclunohelper.hxx>
62
63
64 #include <sfx2/app.hxx>
65 #include "view.hrc"
66 #include <sfx2/viewsh.hxx>
67 #include "viewimp.hxx"
68 #include "sfx2/sfxresid.hxx"
69 #include <sfx2/request.hxx>
70 #include <sfx2/templdlg.hxx>
71 #include <sfx2/printer.hxx>
72 #include <sfx2/docfile.hxx>
73 #include <sfx2/dispatch.hxx>
74 #include "arrdecl.hxx"
75 #include <sfx2/docfac.hxx>
76 #include "view.hrc"
77 #include "sfxlocal.hrc"
78 #include <sfx2/sfxbasecontroller.hxx>
79 #include "sfx2/mailmodelapi.hxx"
80 #include <sfx2/viewfrm.hxx>
81 #include <sfx2/event.hxx>
82 #include <sfx2/fcontnr.hxx>
83 #include <sfx2/ipclient.hxx>
84 #include "workwin.hxx"
85 #include <sfx2/objface.hxx>
86 #include <sfx2/docfilt.hxx>
87
88 // #110897#
89 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
90 #include <comphelper/processfactory.hxx>
91 #endif
92
93 using namespace ::com::sun::star;
94 using namespace ::com::sun::star::uno;
95 using namespace ::com::sun::star::frame;
96 using namespace ::com::sun::star::beans;
97 using namespace ::com::sun::star::util;
98 using namespace ::com::sun::star::system;
99 using namespace ::cppu;
100 namespace css = ::com::sun::star;
101
102 //=========================================================================
103 DBG_NAME(SfxViewShell)
104
105 #define SfxViewShell
106 #include "sfxslots.hxx"
107
108 //=========================================================================
109
110 class SfxClipboardChangeListener : public ::cppu::WeakImplHelper1<
111 datatransfer::clipboard::XClipboardListener >
112 {
113 public:
114 SfxClipboardChangeListener( SfxViewShell* pView, const uno::Reference< datatransfer::clipboard::XClipboardNotifier >& xClpbrdNtfr );
115 virtual ~SfxClipboardChangeListener();
116
117 // XEventListener
118 virtual void SAL_CALL disposing( const lang::EventObject& rEventObject )
119 throw ( uno::RuntimeException );
120
121 // XClipboardListener
122 virtual void SAL_CALL changedContents( const datatransfer::clipboard::ClipboardEvent& rEventObject )
123 throw ( uno::RuntimeException );
124
DisconnectViewShell()125 void DisconnectViewShell() { m_pViewShell = NULL; }
126 void ChangedContents();
127
128 enum AsyncExecuteCmd
129 {
130 ASYNCEXECUTE_CMD_DISPOSING,
131 ASYNCEXECUTE_CMD_CHANGEDCONTENTS
132 };
133
134 struct AsyncExecuteInfo
135 {
AsyncExecuteInfoSfxClipboardChangeListener::AsyncExecuteInfo136 AsyncExecuteInfo( AsyncExecuteCmd eCmd, uno::Reference< datatransfer::clipboard::XClipboardListener > xThis, SfxClipboardChangeListener* pListener ) :
137 m_eCmd( eCmd ), m_xThis( xThis ), m_pListener( pListener ) {}
138
139 AsyncExecuteCmd m_eCmd;
140 uno::Reference< datatransfer::clipboard::XClipboardListener > m_xThis;
141 SfxClipboardChangeListener* m_pListener;
142 };
143
144 private:
145 SfxViewShell* m_pViewShell;
146 uno::Reference< datatransfer::clipboard::XClipboardNotifier > m_xClpbrdNtfr;
147 uno::Reference< lang::XComponent > m_xCtrl;
148
149 DECL_STATIC_LINK( SfxClipboardChangeListener, AsyncExecuteHdl_Impl, AsyncExecuteInfo* );
150 };
151
SfxClipboardChangeListener(SfxViewShell * pView,const uno::Reference<datatransfer::clipboard::XClipboardNotifier> & xClpbrdNtfr)152 SfxClipboardChangeListener::SfxClipboardChangeListener( SfxViewShell* pView, const uno::Reference< datatransfer::clipboard::XClipboardNotifier >& xClpbrdNtfr )
153 : m_pViewShell( 0 ), m_xClpbrdNtfr( xClpbrdNtfr )
154 {
155 m_xCtrl = uno::Reference < lang::XComponent >( pView->GetController(), uno::UNO_QUERY );
156 if ( m_xCtrl.is() )
157 {
158 m_xCtrl->addEventListener( uno::Reference < lang::XEventListener > ( static_cast < lang::XEventListener* >( this ) ) );
159 m_pViewShell = pView;
160 }
161 if ( m_xClpbrdNtfr.is() )
162 {
163 m_xClpbrdNtfr->addClipboardListener( uno::Reference< datatransfer::clipboard::XClipboardListener >(
164 static_cast< datatransfer::clipboard::XClipboardListener* >( this )));
165 }
166 }
167
~SfxClipboardChangeListener()168 SfxClipboardChangeListener::~SfxClipboardChangeListener()
169 {
170 }
171
ChangedContents()172 void SfxClipboardChangeListener::ChangedContents()
173 {
174 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
175 if( m_pViewShell )
176 {
177 SfxBindings& rBind = m_pViewShell->GetViewFrame()->GetBindings();
178 rBind.Invalidate( SID_PASTE );
179 rBind.Invalidate( SID_PASTE_SPECIAL );
180 rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
181 }
182 }
183
IMPL_STATIC_LINK_NOINSTANCE(SfxClipboardChangeListener,AsyncExecuteHdl_Impl,AsyncExecuteInfo *,pAsyncExecuteInfo)184 IMPL_STATIC_LINK_NOINSTANCE( SfxClipboardChangeListener, AsyncExecuteHdl_Impl, AsyncExecuteInfo*, pAsyncExecuteInfo )
185 {
186 if ( pAsyncExecuteInfo )
187 {
188 uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( pAsyncExecuteInfo->m_xThis );
189 if ( pAsyncExecuteInfo->m_pListener )
190 {
191 if ( pAsyncExecuteInfo->m_eCmd == ASYNCEXECUTE_CMD_DISPOSING )
192 pAsyncExecuteInfo->m_pListener->DisconnectViewShell();
193 else if ( pAsyncExecuteInfo->m_eCmd == ASYNCEXECUTE_CMD_CHANGEDCONTENTS )
194 pAsyncExecuteInfo->m_pListener->ChangedContents();
195 }
196 }
197 delete pAsyncExecuteInfo;
198
199 return 0;
200 }
201
disposing(const lang::EventObject &)202 void SAL_CALL SfxClipboardChangeListener::disposing( const lang::EventObject& /*rEventObject*/ )
203 throw ( uno::RuntimeException )
204 {
205 // Either clipboard or ViewShell is going to be destroyed -> no interest in listening anymore
206 uno::Reference< lang::XComponent > xCtrl( m_xCtrl );
207 uno::Reference< datatransfer::clipboard::XClipboardNotifier > xNotify( m_xClpbrdNtfr );
208
209 uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( static_cast< datatransfer::clipboard::XClipboardListener* >( this ));
210 if ( xCtrl.is() )
211 xCtrl->removeEventListener( uno::Reference < lang::XEventListener > ( static_cast < lang::XEventListener* >( this )));
212 if ( xNotify.is() )
213 xNotify->removeClipboardListener( xThis );
214
215 // Make asynchronous call to avoid locking SolarMutex which is the
216 // root for many deadlocks, especially in conjunction with the "Windows"
217 // based single thread apartment clipboard code!
218 AsyncExecuteInfo* pInfo = new AsyncExecuteInfo( ASYNCEXECUTE_CMD_DISPOSING, xThis, this );
219 Application::PostUserEvent( STATIC_LINK( 0, SfxClipboardChangeListener, AsyncExecuteHdl_Impl ), pInfo );
220 }
221
changedContents(const datatransfer::clipboard::ClipboardEvent &)222 void SAL_CALL SfxClipboardChangeListener::changedContents( const datatransfer::clipboard::ClipboardEvent& )
223 throw ( RuntimeException )
224 {
225 // Make asynchronous call to avoid locking SolarMutex which is the
226 // root for many deadlocks, especially in conjunction with the "Windows"
227 // based single thread apartment clipboard code!
228 uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( static_cast< datatransfer::clipboard::XClipboardListener* >( this ));
229 AsyncExecuteInfo* pInfo = new AsyncExecuteInfo( ASYNCEXECUTE_CMD_CHANGEDCONTENTS, xThis, this );
230 Application::PostUserEvent( STATIC_LINK( 0, SfxClipboardChangeListener, AsyncExecuteHdl_Impl ), pInfo );
231 }
232
233 //=========================================================================
234
RetrieveLabelFromCommand(const::rtl::OUString & rCommandURL,const css::uno::Reference<css::frame::XFrame> & rFrame)235 static ::rtl::OUString RetrieveLabelFromCommand(
236 const ::rtl::OUString& rCommandURL,
237 const css::uno::Reference< css::frame::XFrame >& rFrame )
238 {
239 static css::uno::WeakReference< frame::XModuleManager > s_xModuleManager;
240 static css::uno::WeakReference< container::XNameAccess > s_xNameAccess;
241
242 ::rtl::OUString aLabel;
243 css::uno::Reference< css::frame::XModuleManager > xModuleManager( s_xModuleManager );
244 css::uno::Reference< css::container::XNameAccess > xNameAccess( s_xNameAccess );
245 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR(
246 ::comphelper::getProcessServiceFactory(), css::uno::UNO_QUERY_THROW);
247
248 try
249 {
250 if ( !xModuleManager.is() )
251 {
252 xModuleManager = css::uno::Reference< css::frame::XModuleManager >(
253 xSMGR->createInstance(
254 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ))),
255 css::uno::UNO_QUERY_THROW );
256 s_xModuleManager = xModuleManager;
257 }
258
259 ::rtl::OUString aModuleIdentifier = xModuleManager->identify( rFrame );
260
261 if ( !xNameAccess.is() )
262 {
263 xNameAccess = css::uno::Reference< css::container::XNameAccess >(
264 xSMGR->createInstance(
265 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.UICommandDescription" ))),
266 css::uno::UNO_QUERY_THROW );
267 s_xNameAccess = xNameAccess;
268 }
269
270 css::uno::Any a = xNameAccess->getByName( aModuleIdentifier );
271 css::uno::Reference< css::container::XNameAccess > xUICommands;
272 a >>= xUICommands;
273
274 rtl::OUString aStr;
275 css::uno::Sequence< css::beans::PropertyValue > aPropSeq;
276
277 a = xUICommands->getByName( rCommandURL );
278 if ( a >>= aPropSeq )
279 {
280 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
281 {
282 if ( aPropSeq[i].Name.equalsAscii( "Label" ))
283 {
284 aPropSeq[i].Value >>= aStr;
285 break;
286 }
287 }
288 aLabel = aStr;
289 }
290 }
291 catch ( css::uno::Exception& )
292 {
293 }
294
295 return aLabel;
296 }
297
298 //=========================================================================
SfxViewShell_Impl(sal_uInt16 const nFlags)299 SfxViewShell_Impl::SfxViewShell_Impl(sal_uInt16 const nFlags)
300 : aInterceptorContainer( aMutex )
301 , m_bControllerSet(false)
302 , m_nPrinterLocks(0)
303 , m_bCanPrint(SFX_VIEW_CAN_PRINT == (nFlags & SFX_VIEW_CAN_PRINT))
304 , m_bHasPrintOptions(
305 SFX_VIEW_HAS_PRINTOPTIONS == (nFlags & SFX_VIEW_HAS_PRINTOPTIONS))
306 , m_bPlugInsActive(true)
307 , m_bIsShowView(SFX_VIEW_NO_SHOW != (nFlags & SFX_VIEW_NO_SHOW))
308 , m_bGotOwnership(false)
309 , m_bGotFrameOwnership(false)
310 , m_eScroll(SCROLLING_DEFAULT)
311 , m_nFamily(0xFFFF) // undefined, default set by TemplateDialog
312 , m_pController(0)
313 , m_pAccExec(0)
314 {}
315
316 //=========================================================================
317 SFX_IMPL_INTERFACE(SfxViewShell,SfxShell,SfxResId(0))
318 {
319 SFX_CHILDWINDOW_REGISTRATION( SID_MAIL_CHILDWIN );
320 }
321
322 TYPEINIT2(SfxViewShell,SfxShell,SfxListener);
323
324 //--------------------------------------------------------------------
325 /** search for a filter name dependent on type and module
326 */
327
impl_retrieveFilterNameFromTypeAndModule(const css::uno::Reference<css::container::XContainerQuery> & rContainerQuery,const::rtl::OUString & rType,const::rtl::OUString & rModuleIdentifier,const sal_Int32 nFlags)328 static ::rtl::OUString impl_retrieveFilterNameFromTypeAndModule(
329 const css::uno::Reference< css::container::XContainerQuery >& rContainerQuery,
330 const ::rtl::OUString& rType,
331 const ::rtl::OUString& rModuleIdentifier,
332 const sal_Int32 nFlags )
333 {
334 // Retrieve filter from type
335 css::uno::Sequence< css::beans::NamedValue > aQuery( 2 );
336 aQuery[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ));
337 aQuery[0].Value = css::uno::makeAny( rType );
338 aQuery[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" ));
339 aQuery[1].Value = css::uno::makeAny( rModuleIdentifier );
340
341 css::uno::Reference< css::container::XEnumeration > xEnumeration =
342 rContainerQuery->createSubSetEnumerationByProperties( aQuery );
343
344 ::rtl::OUString aFoundFilterName;
345 while ( xEnumeration->hasMoreElements() )
346 {
347 ::comphelper::SequenceAsHashMap aFilterPropsHM( xEnumeration->nextElement() );
348 ::rtl::OUString aFilterName = aFilterPropsHM.getUnpackedValueOrDefault(
349 ::rtl::OUString::createFromAscii( "Name" ),
350 ::rtl::OUString() );
351
352 sal_Int32 nFilterFlags = aFilterPropsHM.getUnpackedValueOrDefault(
353 ::rtl::OUString::createFromAscii( "Flags" ),
354 sal_Int32( 0 ) );
355
356 if ( nFilterFlags & nFlags )
357 {
358 aFoundFilterName = aFilterName;
359 break;
360 }
361 }
362
363 return aFoundFilterName;
364 }
365
366 //--------------------------------------------------------------------
367 /** search for an internal typename, which map to the current app module
368 and map also to a "family" of file formats as e.g. PDF/MS Doc/OOo Doc.
369 */
370 enum ETypeFamily
371 {
372 E_MS_DOC,
373 E_OOO_DOC
374 };
375
impl_searchFormatTypeForApp(const css::uno::Reference<css::frame::XFrame> & xFrame,ETypeFamily eTypeFamily)376 ::rtl::OUString impl_searchFormatTypeForApp(const css::uno::Reference< css::frame::XFrame >& xFrame ,
377 ETypeFamily eTypeFamily)
378 {
379 static ::rtl::OUString SERVICENAME_MODULEMANAGER = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
380
381 try
382 {
383 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR (::comphelper::getProcessServiceFactory() , css::uno::UNO_QUERY_THROW);
384 css::uno::Reference< css::frame::XModuleManager > xModuleManager(xSMGR->createInstance(SERVICENAME_MODULEMANAGER), css::uno::UNO_QUERY_THROW);
385
386 ::rtl::OUString sModule = xModuleManager->identify(xFrame);
387 ::rtl::OUString sType ;
388
389 switch(eTypeFamily)
390 {
391 case E_MS_DOC:
392 {
393 if (sModule.equalsAscii( "com.sun.star.text.TextDocument" ))
394 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "writer_MS_Word_97" ));
395 else
396 if (sModule.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ))
397 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calc_MS_Excel_97" ));
398 else
399 if (sModule.equalsAscii( "com.sun.star.drawing.DrawingDocument" ))
400 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress_MS_PowerPoint_97" ));
401 else
402 if (sModule.equalsAscii( "com.sun.star.presentation.PresentationDocument" ))
403 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress_MS_PowerPoint_97" ));
404 }
405 break;
406
407 case E_OOO_DOC:
408 {
409 if (sModule.equalsAscii( "com.sun.star.text.TextDocument" ))
410 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "writer8" ));
411 else
412 if (sModule.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ))
413 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calc8" ));
414 else
415 if (sModule.equalsAscii( "com.sun.star.drawing.DrawingDocument" ))
416 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "draw8" ));
417 else
418 if (sModule.equalsAscii( "com.sun.star.presentation.PresentationDocument" ))
419 sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress8" ));
420 }
421 break;
422 }
423
424 return sType;
425 }
426 catch(const css::uno::RuntimeException& exRun)
427 { throw exRun; }
428 catch(const css::uno::Exception&)
429 {}
430
431 return ::rtl::OUString();
432 }
433
434 //--------------------------------------------------------------------
435
ExecMisc_Impl(SfxRequest & rReq)436 void SfxViewShell::ExecMisc_Impl( SfxRequest &rReq )
437 {
438 const sal_uInt16 nId = rReq.GetSlot();
439 switch( nId )
440 {
441 case SID_STYLE_FAMILY :
442 {
443 SFX_REQUEST_ARG(rReq, pItem, SfxUInt16Item, nId, sal_False);
444 if (pItem)
445 {
446 pImp->m_nFamily = pItem->GetValue();
447 }
448 break;
449 }
450
451 case SID_STYLE_CATALOG:
452 {
453 SfxTemplateCatalog aCatalog(
454 SFX_APP()->GetTopWindow(), &GetViewFrame()->GetBindings());
455 aCatalog.Execute();
456 rReq.Ignore();
457 break;
458 }
459 case SID_ACTIVATE_STYLE_APPLY:
460 {
461 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
462 GetViewFrame()->GetFrame().GetFrameInterface(),
463 com::sun::star::uno::UNO_QUERY);
464
465 Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
466 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
467 if ( xPropSet.is() )
468 {
469 try
470 {
471 Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
472 aValue >>= xLayoutManager;
473 if ( xLayoutManager.is() )
474 {
475 rtl::OUString aTextResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/textobjectbar" ));
476 uno::Reference< ui::XUIElement > xElement = xLayoutManager->getElement( aTextResString );
477 if(!xElement.is())
478 {
479 rtl::OUString aFrameResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/frameobjectbar" ));
480 xElement = xLayoutManager->getElement( aFrameResString );
481 }
482 if(!xElement.is())
483 {
484 rtl::OUString aOleResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/oleobjectbar" ));
485 xElement = xLayoutManager->getElement( aOleResString );
486 }
487 if(xElement.is())
488 {
489 uno::Reference< awt::XWindow > xWin( xElement->getRealInterface(), uno::UNO_QUERY_THROW );
490 Window* pWin = VCLUnoHelper::GetWindow( xWin );
491 ToolBox* pTextToolbox = dynamic_cast< ToolBox* >( pWin );
492 if( pTextToolbox )
493 {
494 sal_uInt16 nItemCount = pTextToolbox->GetItemCount();
495 for( sal_uInt16 nItem = 0; nItem < nItemCount; ++nItem )
496 {
497 sal_uInt16 nItemId = pTextToolbox->GetItemId( nItem );
498 const XubString& rCommand = pTextToolbox->GetItemCommand( nItemId );
499 if( rCommand.EqualsAscii( ".uno:StyleApply" ) )
500 {
501 Window* pItemWin = pTextToolbox->GetItemWindow( nItemId );
502 if( pItemWin )
503 pItemWin->GrabFocus();
504 break;
505 }
506 }
507 }
508 }
509 }
510 }
511 catch ( Exception& )
512 {
513 }
514 }
515 rReq.Done();
516 }
517 break;
518 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
519
520 case SID_MAIL_SENDDOCASMS:
521 case SID_MAIL_SENDDOCASOOO:
522 case SID_MAIL_SENDDOCASPDF:
523 case SID_MAIL_SENDDOC:
524 case SID_MAIL_SENDDOCASFORMAT:
525 {
526 SfxObjectShell* pDoc = GetObjectShell();
527 if ( pDoc && pDoc->QueryHiddenInformation(
528 WhenSaving, &GetViewFrame()->GetWindow() ) != RET_YES )
529 break;
530
531 if ( SvtInternalOptions().MailUIEnabled() )
532 {
533 GetViewFrame()->SetChildWindow( SID_MAIL_CHILDWIN, sal_True );
534 }
535 else
536 {
537 SfxMailModel aModel;
538 rtl::OUString aDocType;
539
540 SFX_REQUEST_ARG(rReq, pMailSubject, SfxStringItem, SID_MAIL_SUBJECT, sal_False );
541 if ( pMailSubject )
542 aModel.SetSubject( pMailSubject->GetValue() );
543
544 SFX_REQUEST_ARG(rReq, pMailRecipient, SfxStringItem, SID_MAIL_RECIPIENT, sal_False );
545 if ( pMailRecipient )
546 {
547 String aRecipient( pMailRecipient->GetValue() );
548 String aMailToStr( String::CreateFromAscii( "mailto:" ));
549
550 if ( aRecipient.Search( aMailToStr ) == 0 )
551 aRecipient = aRecipient.Erase( 0, aMailToStr.Len() );
552 aModel.AddAddress( aRecipient, SfxMailModel::ROLE_TO );
553 }
554 SFX_REQUEST_ARG(rReq, pMailDocType, SfxStringItem, SID_TYPE_NAME, sal_False );
555 if ( pMailDocType )
556 aDocType = pMailDocType->GetValue();
557
558 uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() );
559 SfxMailModel::SendMailResult eResult = SfxMailModel::SEND_MAIL_ERROR;
560
561 if ( nId == SID_MAIL_SENDDOC )
562 eResult = aModel.SaveAndSend( xFrame, rtl::OUString() );
563 else
564 if ( nId == SID_MAIL_SENDDOCASPDF )
565 eResult = aModel.SaveAndSend( xFrame, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "pdf_Portable_Document_Format" )));
566 else
567 if ( nId == SID_MAIL_SENDDOCASMS )
568 {
569 aDocType = impl_searchFormatTypeForApp(xFrame, E_MS_DOC);
570 if (aDocType.getLength() > 0)
571 eResult = aModel.SaveAndSend( xFrame, aDocType );
572 }
573 else
574 if ( nId == SID_MAIL_SENDDOCASOOO )
575 {
576 aDocType = impl_searchFormatTypeForApp(xFrame, E_OOO_DOC);
577 if (aDocType.getLength() > 0)
578 eResult = aModel.SaveAndSend( xFrame, aDocType );
579 }
580
581 if ( eResult == SfxMailModel::SEND_MAIL_ERROR )
582 {
583 InfoBox aBox( SFX_APP()->GetTopWindow(), SfxResId( MSG_ERROR_SEND_MAIL ));
584 aBox.Execute();
585 rReq.Ignore();
586 }
587 else
588 rReq.Done();
589 }
590
591 break;
592 }
593
594 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
595 case SID_WEBHTML:
596 {
597 static const char HTML_DOCUMENT_TYPE[] = "writer_web_HTML";
598 static const char HTML_GRAPHIC_TYPE[] = "graphic_HTML";
599 const sal_Int32 FILTERFLAG_EXPORT = 0x00000002;
600
601 css::uno::Reference< lang::XMultiServiceFactory > xSMGR(::comphelper::getProcessServiceFactory(), css::uno::UNO_QUERY_THROW);
602 css::uno::Reference < css::frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() );
603 css::uno::Reference< css::frame::XModel > xModel;
604
605 const rtl::OUString aModuleManager( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ));
606 css::uno::Reference< css::frame::XModuleManager > xModuleManager( xSMGR->createInstance( aModuleManager ), css::uno::UNO_QUERY_THROW );
607 if ( !xModuleManager.is() )
608 {
609 rReq.Done(sal_False);
610 return;
611 }
612
613 rtl::OUString aModule;
614 try
615 {
616 aModule = xModuleManager->identify( xFrame );
617 }
618 catch ( css::uno::RuntimeException& )
619 {
620 throw;
621 }
622 catch ( css::uno::Exception& )
623 {
624 }
625
626 if ( xFrame.is() )
627 {
628 css::uno::Reference< css::frame::XController > xController = xFrame->getController();
629 if ( xController.is() )
630 xModel = xController->getModel();
631 }
632
633 // We need at least a valid module name and model reference
634 css::uno::Reference< css::frame::XStorable > xStorable( xModel, css::uno::UNO_QUERY );
635 if ( xModel.is() && xStorable.is() )
636 {
637 rtl::OUString aFilterName;
638 rtl::OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM( HTML_DOCUMENT_TYPE ));
639 rtl::OUString aFileName;
640 rtl::OUString aExtension( RTL_CONSTASCII_USTRINGPARAM( "htm" ));
641
642 rtl::OUString aLocation = xStorable->getLocation();
643 INetURLObject aFileObj( aLocation );
644
645 bool bPrivateProtocol = ( aFileObj.GetProtocol() == INET_PROT_PRIV_SOFFICE );
646 bool bHasLocation = ( aLocation.getLength() > 0 ) && !bPrivateProtocol;
647
648 css::uno::Reference< css::container::XContainerQuery > xContainerQuery(
649 xSMGR->createInstance( rtl::OUString(
650 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ))),
651 css::uno::UNO_QUERY_THROW );
652
653 // Retrieve filter from type
654 sal_Int32 nFilterFlags = FILTERFLAG_EXPORT;
655 aFilterName = impl_retrieveFilterNameFromTypeAndModule( xContainerQuery, aTypeName, aModule, nFilterFlags );
656 if ( aFilterName.getLength() == 0 )
657 {
658 // Draw/Impress uses a different type. 2nd chance try to use alternative type name
659 aFilterName = impl_retrieveFilterNameFromTypeAndModule(
660 xContainerQuery, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( HTML_GRAPHIC_TYPE )), aModule, nFilterFlags );
661 }
662
663 // No filter found => error
664 // No type and no location => error
665 if (( aFilterName.getLength() == 0 ) || ( aTypeName.getLength() == 0 ))
666 {
667 rReq.Done(sal_False);
668 return;
669 }
670
671 // Use provided save file name. If empty determine file name
672 if ( !bHasLocation )
673 {
674 // Create a default file name with the correct extension
675 const rtl::OUString aPreviewFileName( RTL_CONSTASCII_USTRINGPARAM( "webpreview" ));
676 aFileName = aPreviewFileName;
677 }
678 else
679 {
680 // Determine file name from model
681 INetURLObject aFObj( xStorable->getLocation() );
682 aFileName = aFObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::NO_DECODE );
683 }
684
685 OSL_ASSERT( aFilterName.getLength() > 0 );
686 OSL_ASSERT( aFileName.getLength() > 0 );
687
688 // Creates a temporary directory to store our predefined file into it.
689 ::utl::TempFile aTempDir( NULL, sal_True );
690
691 INetURLObject aFilePathObj( aTempDir.GetURL() );
692 aFilePathObj.insertName( aFileName );
693 aFilePathObj.setExtension( aExtension );
694
695 rtl::OUString aFileURL = aFilePathObj.GetMainURL( INetURLObject::NO_DECODE );
696
697 css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
698 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
699 aArgs[0].Value = css::uno::makeAny( aFilterName );
700
701 // Store document in the html format
702 try
703 {
704 xStorable->storeToURL( aFileURL, aArgs );
705 }
706 catch ( com::sun::star::io::IOException& )
707 {
708 rReq.Done(sal_False);
709 return;
710 }
711
712 ::com::sun::star::uno::Reference< XSystemShellExecute > xSystemShellExecute(
713 com::sun::star::system::SystemShellExecute::create(
714 ::comphelper::getProcessComponentContext() ) );
715
716 sal_Bool bRet( sal_True );
717 if ( xSystemShellExecute.is() )
718 {
719 try
720 {
721 xSystemShellExecute->execute(
722 aFileURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
723 }
724 catch ( uno::Exception& )
725 {
726 vos::OGuard aGuard( Application::GetSolarMutex() );
727 Window *pParent = SFX_APP()->GetTopWindow();
728 ErrorBox( pParent, SfxResId( MSG_ERROR_NO_WEBBROWSER_FOUND )).Execute();
729 bRet = sal_False;
730 }
731 }
732
733 rReq.Done(bRet);
734 break;
735 }
736 else
737 {
738 rReq.Done(sal_False);
739 return;
740 }
741 }
742
743 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
744 case SID_PLUGINS_ACTIVE:
745 {
746 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nId, sal_False);
747 bool const bActive = (pShowItem)
748 ? pShowItem->GetValue()
749 : !pImp->m_bPlugInsActive;
750 // ggf. recorden
751 if ( !rReq.IsAPI() )
752 rReq.AppendItem( SfxBoolItem( nId, bActive ) );
753
754 // Jetzt schon DONE aufrufen, da die Argumente evtl. einen Pool
755 // benutzen, der demn"achst weg ist
756 rReq.Done(sal_True);
757
758 // ausfuehren
759 if (!pShowItem || (bActive != pImp->m_bPlugInsActive))
760 {
761 SfxFrame* pTopFrame = &GetFrame()->GetTopFrame();
762 if ( pTopFrame != &GetFrame()->GetFrame() )
763 {
764 // FramesetDocument
765 SfxViewShell *pShell = pTopFrame->GetCurrentViewFrame()->GetViewShell();
766 if ( pShell->GetInterface()->GetSlot( nId ) )
767 pShell->ExecuteSlot( rReq );
768 break;
769 }
770
771 SfxFrameIterator aIter( *pTopFrame );
772 while ( pTopFrame )
773 {
774 if ( pTopFrame->GetCurrentViewFrame() )
775 {
776 SfxViewShell *pView = pTopFrame->GetCurrentViewFrame()->GetViewShell();
777 if ( pView )
778 {
779 pView->pImp->m_bPlugInsActive = bActive;
780 Rectangle aVisArea = GetObjectShell()->GetVisArea();
781 VisAreaChanged(aVisArea);
782
783 // the plugins might need change in their state
784 SfxInPlaceClientList *pClients = pView->GetIPClientList_Impl(sal_False);
785 if ( pClients )
786 {
787 for (sal_uInt16 n=0; n < pClients->Count(); n++)
788 {
789 SfxInPlaceClient* pIPClient = pClients->GetObject(n);
790 if ( pIPClient )
791 pView->CheckIPClient_Impl( pIPClient, aVisArea );
792 }
793 }
794 }
795 }
796
797 if ( !pTopFrame->GetParentFrame() )
798 pTopFrame = aIter.FirstFrame();
799 else
800 pTopFrame = aIter.NextFrame( *pTopFrame );
801 }
802 }
803
804 break;
805 }
806 }
807 }
808
809 //--------------------------------------------------------------------
810
GetState_Impl(SfxItemSet & rSet)811 void SfxViewShell::GetState_Impl( SfxItemSet &rSet )
812 {
813 DBG_CHKTHIS(SfxViewShell, 0);
814
815 SfxWhichIter aIter( rSet );
816 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
817 {
818 switch ( nSID )
819 {
820 case SID_STYLE_CATALOG:
821 {
822 if ( !GetViewFrame()->KnowsChildWindow( SID_STYLE_DESIGNER ) )
823 rSet.DisableItem( nSID );
824 break;
825 }
826
827 // Printer-Funktionen
828 case SID_PRINTDOC:
829 case SID_PRINTDOCDIRECT:
830 case SID_SETUPPRINTER:
831 case SID_PRINTER_NAME:
832 {
833 bool bEnabled = pImp->m_bCanPrint && !pImp->m_nPrinterLocks;
834 bEnabled = bEnabled && !Application::GetSettings().GetMiscSettings().GetDisablePrinting();
835 if ( bEnabled )
836 {
837 SfxPrinter *pPrinter = GetPrinter(sal_False);
838
839 if ( SID_PRINTDOCDIRECT == nSID )
840 {
841 rtl::OUString aPrinterName;
842 if ( pPrinter != NULL )
843 aPrinterName = pPrinter->GetName();
844 else
845 aPrinterName = Printer::GetDefaultPrinterName();
846 if ( aPrinterName.getLength() > 0 )
847 {
848 uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() );
849
850 ::rtl::OUStringBuffer aBuffer( 60 );
851 aBuffer.append( RetrieveLabelFromCommand(
852 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PrintDefault" )),
853 xFrame ));
854 aBuffer.appendAscii( " (" );
855 aBuffer.append( aPrinterName );
856 aBuffer.appendAscii( ")" );
857
858 rSet.Put( SfxStringItem( SID_PRINTDOCDIRECT, aBuffer.makeStringAndClear() ) );
859 }
860 }
861 bEnabled = !pPrinter || !pPrinter->IsPrinting();
862 }
863 if ( !bEnabled )
864 {
865 // will now be handled by requeing the request
866 /* rSet.DisableItem( SID_PRINTDOC );
867 rSet.DisableItem( SID_PRINTDOCDIRECT );
868 rSet.DisableItem( SID_SETUPPRINTER ); */
869 }
870 break;
871 }
872
873 // Mail-Funktionen
874 case SID_MAIL_SENDDOCASPDF:
875 case SID_MAIL_SENDDOC:
876 case SID_MAIL_SENDDOCASFORMAT:
877 {
878 sal_Bool bEnable = !GetViewFrame()->HasChildWindow( SID_MAIL_CHILDWIN );
879 if ( !bEnable )
880 rSet.DisableItem( nSID );
881 break;
882 }
883
884 // PlugIns running
885 case SID_PLUGINS_ACTIVE:
886 {
887 rSet.Put( SfxBoolItem( SID_PLUGINS_ACTIVE,
888 !pImp->m_bPlugInsActive) );
889 break;
890 }
891 /*
892 // SelectionText
893 case SID_SELECTION_TEXT:
894 {
895 rSet.Put( SfxStringItem( SID_SELECTION_TEXT, GetSelectionText() ) );
896 break;
897 }
898
899 // SelectionTextExt
900 case SID_SELECTION_TEXT_EXT:
901 {
902 rSet.Put( SfxStringItem( SID_SELECTION_TEXT_EXT, GetSelectionText(sal_True) ) );
903 break;
904 }
905 */
906 case SID_STYLE_FAMILY :
907 {
908 rSet.Put( SfxUInt16Item( SID_STYLE_FAMILY, pImp->m_nFamily ) );
909 break;
910 }
911 }
912 }
913 }
914
915 //--------------------------------------------------------------------
916
SetZoomFactor(const Fraction & rZoomX,const Fraction & rZoomY)917 void SfxViewShell::SetZoomFactor( const Fraction &rZoomX,
918 const Fraction &rZoomY )
919 {
920 DBG_ASSERT( GetWindow(), "no window" );
921 MapMode aMap( GetWindow()->GetMapMode() );
922 aMap.SetScaleX( rZoomX );
923 aMap.SetScaleY( rZoomY );
924 GetWindow()->SetMapMode( aMap );
925 }
926
927 //--------------------------------------------------------------------
DoVerb(long)928 ErrCode SfxViewShell::DoVerb(long /*nVerb*/)
929
930 /* [Beschreibung]
931
932 Virtuelle Methode, um am selektierten Objekt ein Verb auszuf"uhren.
933 Da dieses Objekt nur den abgeleiteten Klassen bekannt ist, muss DoVerb
934 dort "uberschrieben werden.
935
936 */
937
938 {
939 return ERRCODE_SO_NOVERBS;
940 }
941
942 //--------------------------------------------------------------------
943
OutplaceActivated(sal_Bool bActive,SfxInPlaceClient *)944 void SfxViewShell::OutplaceActivated( sal_Bool bActive, SfxInPlaceClient* /*pClient*/ )
945 {
946 if ( !bActive )
947 GetFrame()->GetFrame().Appear();
948 }
949
950 //--------------------------------------------------------------------
951
InplaceActivating(SfxInPlaceClient *)952 void SfxViewShell::InplaceActivating( SfxInPlaceClient* /*pClient*/ )
953 {
954 // TODO/LATER: painting of the bitmap can be stopped, it is required if CLIPCHILDREN problem #i25788# is not solved,
955 // but may be the bug will not affect the real office vcl windows, then it is not required
956 }
957
958 //--------------------------------------------------------------------
959
InplaceDeactivated(SfxInPlaceClient *)960 void SfxViewShell::InplaceDeactivated( SfxInPlaceClient* /*pClient*/ )
961 {
962 // TODO/LATER: paint the replacement image in normal way if the painting was stopped
963 }
964
965 //--------------------------------------------------------------------
966
UIActivating(SfxInPlaceClient *)967 void SfxViewShell::UIActivating( SfxInPlaceClient* /*pClient*/ )
968 {
969 uno::Reference < frame::XFrame > xOwnFrame( pFrame->GetFrame().GetFrameInterface() );
970 uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
971 if ( xParentFrame.is() )
972 xParentFrame->setActiveFrame( xOwnFrame );
973
974 pFrame->GetBindings().HidePopups(sal_True);
975 pFrame->GetDispatcher()->Update_Impl( sal_True );
976 }
977
978 //--------------------------------------------------------------------
979
UIDeactivated(SfxInPlaceClient *)980 void SfxViewShell::UIDeactivated( SfxInPlaceClient* /*pClient*/ )
981 {
982 if ( !pFrame->GetFrame().IsClosing_Impl() ||
983 SfxViewFrame::Current() != pFrame )
984 pFrame->GetDispatcher()->Update_Impl( sal_True );
985 pFrame->GetBindings().HidePopups(sal_False);
986
987 // uno::Reference < frame::XFrame > xOwnFrame( pFrame->GetFrame().GetFrameInterface() );
988 // uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
989 // if ( xParentFrame.is() )
990 // xParentFrame->setActiveFrame( uno::Reference < frame::XFrame >() );
991
992 // Make sure that slot servers are initialized or updated after
993 // an OLE object is deactivated.
994 pFrame->GetBindings().InvalidateAll(sal_True);
995 }
996
997 //--------------------------------------------------------------------
998
FindIPClient(const uno::Reference<embed::XEmbeddedObject> & xObj,Window * pObjParentWin) const999 SfxInPlaceClient* SfxViewShell::FindIPClient
1000 (
1001 const uno::Reference < embed::XEmbeddedObject >& xObj,
1002 Window* pObjParentWin
1003 ) const
1004 {
1005 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1006 if ( !pClients )
1007 return 0;
1008
1009 if( !pObjParentWin )
1010 pObjParentWin = GetWindow();
1011 for (sal_uInt16 n=0; n < pClients->Count(); n++)
1012 {
1013 SfxInPlaceClient *pIPClient = (SfxInPlaceClient*) pClients->GetObject(n);
1014 if ( pIPClient->GetObject() == xObj && pIPClient->GetEditWin() == pObjParentWin )
1015 return pIPClient;
1016 }
1017
1018 return 0;
1019 }
1020
1021 //--------------------------------------------------------------------
1022
GetIPClient() const1023 SfxInPlaceClient* SfxViewShell::GetIPClient() const
1024 {
1025 return GetUIActiveClient();
1026 }
1027
1028 //--------------------------------------------------------------------
1029
GetUIActiveIPClient_Impl() const1030 SfxInPlaceClient* SfxViewShell::GetUIActiveIPClient_Impl() const
1031 {
1032 // this method is needed as long as SFX still manages the border space for ChildWindows (see SfxFrame::Resize)
1033 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1034 if ( !pClients )
1035 return 0;
1036
1037 for (sal_uInt16 n=0; n < pClients->Count(); n++)
1038 {
1039 SfxInPlaceClient* pIPClient = pClients->GetObject(n);
1040 if ( pIPClient->IsUIActive() )
1041 return pIPClient;
1042 }
1043
1044 return NULL;
1045 }
1046
GetUIActiveClient() const1047 SfxInPlaceClient* SfxViewShell::GetUIActiveClient() const
1048 {
1049 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1050 if ( !pClients )
1051 return 0;
1052
1053 for (sal_uInt16 n=0; n < pClients->Count(); n++)
1054 {
1055 SfxInPlaceClient* pIPClient = pClients->GetObject(n);
1056 if ( pIPClient->IsObjectUIActive() )
1057 return pIPClient;
1058 }
1059
1060 return NULL;
1061 }
1062
1063 //--------------------------------------------------------------------
1064
Activate(sal_Bool bMDI)1065 void SfxViewShell::Activate( sal_Bool bMDI )
1066 {
1067 DBG_CHKTHIS(SfxViewShell, 0);
1068 if ( bMDI )
1069 {
1070 SfxObjectShell *pSh = GetViewFrame()->GetObjectShell();
1071 if ( pSh->GetModel().is() )
1072 pSh->GetModel()->setCurrentController( GetViewFrame()->GetFrame().GetController() );
1073
1074 SetCurrentDocument();
1075 }
1076 }
1077
1078 //--------------------------------------------------------------------
1079
Deactivate(sal_Bool)1080 void SfxViewShell::Deactivate(sal_Bool /*bMDI*/)
1081 {
1082 DBG_CHKTHIS(SfxViewShell, 0);
1083 }
1084
1085 //--------------------------------------------------------------------
1086
AdjustPosSizePixel(const Point &,const Size &)1087 void SfxViewShell::AdjustPosSizePixel
1088 (
1089 const Point& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window
1090 const Size& /*rSize*/ // gesamte zur Verf"ugung stehende Gr"o\se
1091 )
1092
1093 {
1094 DBG_CHKTHIS(SfxViewShell, 0);
1095 }
1096
1097 //--------------------------------------------------------------------
1098
Move()1099 void SfxViewShell::Move()
1100
1101 /* [Beschreibung]
1102
1103 Diese virtuelle Methode wird gerufen, wenn das Fenster, in dem die
1104 SfxViewShell dargestellt wird eine StarView-Move() Nachricht erh"alt.
1105
1106 Die Basisimplementierung braucht nicht gerufen zu werden.
1107
1108
1109 [Anmerkung]
1110
1111 Diese Methode kann dazu verwendet werden, eine Selektion abzubrechen,
1112 um durch das Moven des Fensters erzeugte Maus-Bewegungen anzufangen.
1113
1114 Zur Zeit funktioniert die Benachrichtigung nicht In-Place.
1115 */
1116
1117 {
1118 }
1119
1120 //--------------------------------------------------------------------
1121
OuterResizePixel(const Point &,const Size &)1122 void SfxViewShell::OuterResizePixel
1123 (
1124 const Point& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window
1125 const Size& /*rSize*/ // gesamte zur Verf"ugung stehende Gr"o\se
1126 )
1127
1128 /* [Beschreibung]
1129
1130 Diese Methode muss ueberladen werden, um auf "Anderungen der Groesse
1131 der View zu reagieren. Dabei definieren wir die View als das Edit-Window
1132 zuz"uglich der um das Edit-Window angeordnenten Tools (z.B. Lineale).
1133
1134 Das Edit-Window darf weder in Gr"o\se noch Position ver"andert werden.
1135
1136 Die Vis-Area der SfxObjectShell, dessen Skalierung und Position
1137 d"urfen hier ver"andert werden. Der Hauptanwendungsfall ist dabei,
1138 das Ver"andern der Gr"o\se der Vis-Area.
1139
1140 "Andert sich durch die neue Berechnung der Border, so mu\s dieser
1141 mit <SfxViewShell::SetBorderPixel(const SvBorder&)> gesetzt werden.
1142 Erst nach Aufruf von 'SetBorderPixel' ist das Positionieren von
1143 Tools erlaubt.
1144
1145
1146 [Beispiel]
1147
1148 void AppViewSh::OuterViewResizePixel( const Point &rOfs, const Size &rSz )
1149 {
1150 // Tool-Positionen und Gr"o\sen von au\sen berechnen, NICHT setzen!
1151 // (wegen folgender Border-Berechnung)
1152 Point aHLinPos...; Size aHLinSz...;
1153 ...
1154
1155 // Border f"ur Tools passend zu rSize berechnen und setzen
1156 SvBorder aBorder...
1157 SetBorderPixel( aBorder ); // ab jetzt sind Positionierungen erlaubt
1158
1159 // Tools anordnen
1160 pHLin->SetPosSizePixel( aHLinPos, aHLinSz );
1161 ...
1162 }
1163
1164
1165 [Querverweise]
1166
1167 <SfxViewShell::InnerResizePixel(const Point&,const Size& rSize)>
1168 */
1169
1170 {
1171 DBG_CHKTHIS(SfxViewShell, 0);
1172 SetBorderPixel( SvBorder() );
1173 }
1174
1175 //--------------------------------------------------------------------
1176
InnerResizePixel(const Point &,const Size &)1177 void SfxViewShell::InnerResizePixel
1178 (
1179 const Point& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window
1180 const Size& /*rSize*/ // dem Edit-Win zur Verf"ugung stehende Gr"o\se
1181 )
1182
1183 /* [Beschreibung]
1184
1185 Diese Methode muss ueberladen werden, um auf "Anderungen der Groesse
1186 des Edit-Windows zu reagieren.
1187
1188 Das Edit-Window darf weder in Gr"o\se noch Position ver"andert werden.
1189 Weder die Vis-Area der SfxObjectShell noch dessen Skalierung oder
1190 Position d"urfen ver"andert werden.
1191
1192 "Andert sich durch die neue Berechnung der Border, so mu\s dieser
1193 mit <SfxViewShell::SetBorderPixel(const SvBorder&)> gesetzt werden.
1194 Erst nach Aufruf von 'SetBorderPixel' ist das Positionieren von
1195 Tools erlaubt.
1196
1197
1198 [Beispiel]
1199
1200 void AppViewSh::InnerViewResizePixel( const Point &rOfs, const Size &rSz )
1201 {
1202 // Tool-Positionen und Gr"o\sen von innen berechnen, NICHT setzen!
1203 // (wegen folgender Border-Berechnung)
1204 Point aHLinPos...; Size aHLinSz...;
1205 ...
1206
1207 // Border f"ur Tools passend zu rSz berechnen und setzen
1208 SvBorder aBorder...
1209 SetBorderPixel( aBorder ); // ab jetzt sind Positionierungen erlaubt
1210
1211 // Tools anordnen
1212 pHLin->SetPosSizePixel( aHLinPos, aHLinSz );
1213 ...
1214 }
1215
1216
1217 [Querverweise]
1218
1219 <SfxViewShell::OuterResizePixel(const Point&,const Size& rSize)>
1220 */
1221
1222 {
1223 DBG_CHKTHIS(SfxViewShell, 0);
1224 SetBorderPixel( SvBorder() );
1225 }
1226
1227 //--------------------------------------------------------------------
1228
InvalidateBorder()1229 void SfxViewShell::InvalidateBorder()
1230 {
1231 DBG_CHKTHIS(SfxViewShell, 0);
1232 DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
1233
1234 GetViewFrame()->InvalidateBorderImpl( this );
1235 if (pImp->m_pController.is())
1236 {
1237 pImp->m_pController->BorderWidthsChanged_Impl();
1238 }
1239 }
1240
1241 //--------------------------------------------------------------------
1242
SetBorderPixel(const SvBorder & rBorder)1243 void SfxViewShell::SetBorderPixel( const SvBorder &rBorder )
1244 {
1245 DBG_CHKTHIS(SfxViewShell, 0);
1246 DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
1247
1248 //if ( rBorder != GetBorderPixel())
1249 {
1250 GetViewFrame()->SetBorderPixelImpl( this, rBorder );
1251
1252 // notify related controller that border size is changed
1253 if (pImp->m_pController.is())
1254 {
1255 pImp->m_pController->BorderWidthsChanged_Impl();
1256 }
1257 }
1258 }
1259
1260 //--------------------------------------------------------------------
1261
GetBorderPixel() const1262 const SvBorder& SfxViewShell::GetBorderPixel() const
1263 {
1264 DBG_CHKTHIS(SfxViewShell, 0);
1265 DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
1266
1267 return GetViewFrame()->GetBorderPixelImpl( this );
1268 }
1269
1270 //--------------------------------------------------------------------
1271
SetWindow(Window * pViewPort)1272 void SfxViewShell::SetWindow
1273 (
1274 Window* pViewPort // Pointer auf das Datenfenster bzw. 0 im Destruktor
1275 )
1276
1277 /* [Beschreibung]
1278
1279 Mit dieser Methode wird der SfxViewShell das Datenfenster mitgeteilt.
1280 Dieses wird f"ur den In-Place-Container und f"ur das korrekte
1281 Wiederherstellen des Focus ben"otigt.
1282
1283 Selbst In-Place-aktiv ist das Umsetzen des ViewPort-Windows verboten.
1284 */
1285
1286 {
1287 if( pWindow == pViewPort )
1288 return;
1289
1290 // ggf. vorhandene IP-Clients disconnecten
1291 DisconnectAllClients();
1292
1293 //TODO: should we have a "ReconnectAllClients" method?
1294 DiscardClients_Impl();
1295
1296 // View-Port austauschen
1297 sal_Bool bHadFocus = pWindow ? pWindow->HasChildPathFocus( sal_True ) : sal_False;
1298 pWindow = pViewPort;
1299
1300 if( pWindow )
1301 {
1302 // Disable automatic GUI mirroring (right-to-left) for document windows
1303 pWindow->EnableRTL( sal_False );
1304 }
1305
1306 if ( bHadFocus && pWindow )
1307 pWindow->GrabFocus();
1308 //TODO/CLEANUP
1309 //brauchen wir die Methode doch noch?!
1310 //SFX_APP()->GrabFocus( pWindow );
1311 }
1312
1313 //--------------------------------------------------------------------
1314
GetOptimalSizePixel() const1315 Size SfxViewShell::GetOptimalSizePixel() const
1316 {
1317 DBG_ERROR( "Useless call!" );
1318 return Size();
1319 }
1320
1321 //------------------------------------------------------------------------
1322
SfxViewShell(SfxViewFrame * pViewFrame,sal_uInt16 nFlags)1323 SfxViewShell::SfxViewShell
1324 (
1325 SfxViewFrame* pViewFrame, /* <SfxViewFrame>, in dem diese View dargestellt wird */
1326 sal_uInt16 nFlags /* siehe <SfxViewShell-Flags> */
1327 )
1328
1329 : SfxShell(this)
1330 , pImp( new SfxViewShell_Impl(nFlags) )
1331 ,pIPClientList( 0 )
1332 ,pFrame(pViewFrame)
1333 ,pSubShell(0)
1334 ,pWindow(0)
1335 ,bNoNewWindow( 0 != (nFlags & SFX_VIEW_NO_NEWWINDOW) )
1336 {
1337 DBG_CTOR(SfxViewShell, 0);
1338
1339 //pImp->pPrinterCommandQueue = new SfxAsyncPrintExec_Impl( this );
1340
1341 if ( pViewFrame->GetParentViewFrame() )
1342 {
1343 pImp->m_bPlugInsActive = pViewFrame->GetParentViewFrame()
1344 ->GetViewShell()->pImp->m_bPlugInsActive;
1345 }
1346 SetMargin( pViewFrame->GetMargin_Impl() );
1347
1348 SetPool( &pViewFrame->GetObjectShell()->GetPool() );
1349 StartListening(*pViewFrame->GetObjectShell());
1350
1351 // in Liste eintragen
1352 const SfxViewShell *pThis = this; // wegen der kranken Array-Syntax
1353 SfxViewShellArr_Impl &rViewArr = SFX_APP()->GetViewShells_Impl();
1354 rViewArr.Insert(pThis, rViewArr.Count() );
1355 }
1356
1357 //--------------------------------------------------------------------
1358
~SfxViewShell()1359 SfxViewShell::~SfxViewShell()
1360 {
1361 DBG_DTOR(SfxViewShell, 0);
1362
1363 // aus Liste austragen
1364 const SfxViewShell *pThis = this;
1365 SfxViewShellArr_Impl &rViewArr = SFX_APP()->GetViewShells_Impl();
1366 rViewArr.Remove( rViewArr.GetPos(pThis) );
1367
1368 if ( pImp->xClipboardListener.is() )
1369 {
1370 pImp->xClipboardListener->DisconnectViewShell();
1371 pImp->xClipboardListener = NULL;
1372 }
1373
1374 if (pImp->m_pController.is())
1375 {
1376 pImp->m_pController->ReleaseShell_Impl();
1377 pImp->m_pController.clear();
1378 }
1379
1380 //DELETEZ( pImp->pPrinterCommandQueue );
1381 DELETEZ( pImp );
1382 DELETEZ( pIPClientList );
1383 }
1384
1385 //--------------------------------------------------------------------
1386
PrepareClose(sal_Bool bUI,sal_Bool)1387 sal_uInt16 SfxViewShell::PrepareClose
1388 (
1389 sal_Bool bUI, // sal_True: Dialoge etc. erlaubt, sal_False: silent-mode
1390 sal_Bool /*bForBrowsing*/
1391 )
1392 {
1393 SfxPrinter *pPrinter = GetPrinter();
1394 if ( pPrinter && pPrinter->IsPrinting() )
1395 {
1396 if ( bUI )
1397 {
1398 InfoBox aInfoBox( &GetViewFrame()->GetWindow(), SfxResId( MSG_CANT_CLOSE ) );
1399 aInfoBox.Execute();
1400 }
1401
1402 return sal_False;
1403 }
1404
1405 if( GetViewFrame()->IsInModalMode() )
1406 return sal_False;
1407
1408 if( bUI && GetViewFrame()->GetDispatcher()->IsLocked() )
1409 return sal_False;
1410
1411 return sal_True;
1412 }
1413
1414 //--------------------------------------------------------------------
1415
Current()1416 SfxViewShell* SfxViewShell::Current()
1417 {
1418 SfxViewFrame *pCurrent = SfxViewFrame::Current();
1419 return pCurrent ? pCurrent->GetViewShell() : NULL;
1420 }
1421
1422 //--------------------------------------------------------------------
1423
Get(const Reference<XController> & i_rController)1424 SfxViewShell* SfxViewShell::Get( const Reference< XController>& i_rController )
1425 {
1426 if ( !i_rController.is() )
1427 return NULL;
1428
1429 for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst( NULL, sal_False );
1430 pViewShell;
1431 pViewShell = SfxViewShell::GetNext( *pViewShell, NULL, sal_False )
1432 )
1433 {
1434 if ( pViewShell->GetController() == i_rController )
1435 return pViewShell;
1436 }
1437 return NULL;
1438 }
1439
1440 //--------------------------------------------------------------------
1441
GetDrawView() const1442 SdrView* SfxViewShell::GetDrawView() const
1443
1444 /* [Beschreibung]
1445
1446 Diese virtuelle Methode mu\s von den Subklassen "uberladen werden, wenn
1447 der Property-Editor zur Verf"ugung stehen soll.
1448
1449 Die Default-Implementierung liefert immer 0.
1450 */
1451
1452 {
1453 return 0;
1454 }
1455
1456 //--------------------------------------------------------------------
1457
GetSelectionText(sal_Bool)1458 String SfxViewShell::GetSelectionText
1459 (
1460 sal_Bool /*bCompleteWords*/ /* sal_False (default)
1461 Nur der tats"achlich selektierte Text wird
1462 zur"uckgegeben.
1463
1464 TRUE
1465 Der selektierte Text wird soweit erweitert,
1466 da\s nur ganze W"orter zur"uckgegeben werden.
1467 Als Worttrenner gelten White-Spaces und die
1468 Satzzeichen ".,;" sowie einfache und doppelte
1469 Anf"uhrungszeichen.
1470 */
1471 )
1472
1473 /* [Beschreibung]
1474
1475 Diese Methode kann von Anwendungsprogrammierer "uberladen werden,
1476 um einen Text zur"uckzuliefern, der in der aktuellen Selektion
1477 steht. Dieser wird z.B. beim Versenden (email) verwendet.
1478
1479 Mit "CompleteWords == TRUE" ger"ufen, reicht z.B. auch der Cursor,
1480 der in einer URL steht, um die gesamte URL zu liefern.
1481 */
1482
1483 {
1484 return String();
1485 }
1486
1487 //--------------------------------------------------------------------
1488
HasSelection(sal_Bool) const1489 sal_Bool SfxViewShell::HasSelection( sal_Bool ) const
1490
1491 /* [Beschreibung]
1492
1493 Mit dieser virtuellen Methode kann z.B. ein Dialog abfragen, ob in der
1494 aktuellen View etwas selektiert ist. Wenn der Parameter <sal_Bool> sal_True ist,
1495 wird abgefragt, ob Text selektiert ist.
1496 */
1497
1498 {
1499 return sal_False;
1500 }
1501
1502 //--------------------------------------------------------------------
1503
SetSubShell(SfxShell * pShell)1504 void SfxViewShell::SetSubShell( SfxShell *pShell )
1505
1506 /* [Beschreibung]
1507
1508 Mit dieser Methode kann eine Selektions- oder Cursor-Shell angemeldet
1509 werden, die automatisch unmittelbar nach der SfxViewShell auf den
1510 SfxDispatcher gepusht wird, und automatisch umittelbar vor ihr
1511 gepoppt wird.
1512
1513 Ist die SfxViewShell-Instanz bereits gepusht, dann wird pShell
1514 sofort ebenfalls gepusht. Wird mit SetSubShell eine andere SfxShell
1515 Instanz angemeldet, als vorher angemeldet war, wird die zuvor angemeldete
1516 ggf. automatisch gepoppt. Mit pShell==0 kann daher die aktuelle
1517 Sub-Shell abgemeldet werden.
1518 */
1519
1520 {
1521 // ist diese ViewShell "uberhaupt aktiv?
1522 SfxDispatcher *pDisp = pFrame->GetDispatcher();
1523 if ( pDisp->IsActive(*this) )
1524 {
1525 // Dispatcher updaten
1526 if ( pSubShell )
1527 pDisp->Pop(*pSubShell);
1528 if ( pShell )
1529 pDisp->Push(*pShell);
1530 pDisp->Flush();
1531 }
1532
1533 pSubShell = pShell;
1534 }
1535
AddSubShell(SfxShell & rShell)1536 void SfxViewShell::AddSubShell( SfxShell& rShell )
1537 {
1538 pImp->aArr.Insert( &rShell, pImp->aArr.Count() );
1539 SfxDispatcher *pDisp = pFrame->GetDispatcher();
1540 if ( pDisp->IsActive(*this) )
1541 {
1542 pDisp->Push(rShell);
1543 pDisp->Flush();
1544 }
1545 }
1546
RemoveSubShell(SfxShell * pShell)1547 void SfxViewShell::RemoveSubShell( SfxShell* pShell )
1548 {
1549 SfxDispatcher *pDisp = pFrame->GetDispatcher();
1550 if ( !pShell )
1551 {
1552 sal_uInt16 nCount = pImp->aArr.Count();
1553 if ( pDisp->IsActive(*this) )
1554 {
1555 for ( sal_uInt16 n=nCount; n>0; n-- )
1556 pDisp->Pop( *pImp->aArr[n-1] );
1557 pDisp->Flush();
1558 }
1559
1560 pImp->aArr.Remove(0, nCount);
1561 }
1562 else
1563 {
1564 sal_uInt16 nPos = pImp->aArr.GetPos( pShell );
1565 if ( nPos != 0xFFFF )
1566 {
1567 pImp->aArr.Remove( nPos );
1568 if ( pDisp->IsActive(*this) )
1569 {
1570 pDisp->RemoveShell_Impl( *pShell );
1571 pDisp->Flush();
1572 }
1573 }
1574 }
1575 }
1576
GetSubShell(sal_uInt16 nNo)1577 SfxShell* SfxViewShell::GetSubShell( sal_uInt16 nNo )
1578 {
1579 sal_uInt16 nCount = pImp->aArr.Count();
1580 if ( nNo<nCount )
1581 return pImp->aArr[nCount-nNo-1];
1582 return NULL;
1583 }
1584
PushSubShells_Impl(sal_Bool bPush)1585 void SfxViewShell::PushSubShells_Impl( sal_Bool bPush )
1586 {
1587 sal_uInt16 nCount = pImp->aArr.Count();
1588 SfxDispatcher *pDisp = pFrame->GetDispatcher();
1589 if ( bPush )
1590 {
1591 for ( sal_uInt16 n=0; n<nCount; n++ )
1592 pDisp->Push( *pImp->aArr[n] );
1593 }
1594 else if ( nCount )
1595 {
1596 SfxShell& rPopUntil = *pImp->aArr[0];
1597 if ( pDisp->GetShellLevel( rPopUntil ) != USHRT_MAX )
1598 pDisp->Pop( rPopUntil, SFX_SHELL_POP_UNTIL );
1599 }
1600
1601 pDisp->Flush();
1602 }
1603
1604 //--------------------------------------------------------------------
1605
WriteUserData(String &,sal_Bool)1606 void SfxViewShell::WriteUserData( String&, sal_Bool )
1607 {
1608 }
1609
1610 //--------------------------------------------------------------------
1611
ReadUserData(const String &,sal_Bool)1612 void SfxViewShell::ReadUserData(const String&, sal_Bool )
1613 {
1614 }
1615
ReadUserDataSequence(const::com::sun::star::uno::Sequence<::com::sun::star::beans::PropertyValue> &,sal_Bool)1616 void SfxViewShell::ReadUserDataSequence ( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool )
1617 {
1618 }
1619
WriteUserDataSequence(::com::sun::star::uno::Sequence<::com::sun::star::beans::PropertyValue> &,sal_Bool)1620 void SfxViewShell::WriteUserDataSequence ( ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool )
1621 {
1622 }
1623
1624
1625 //--------------------------------------------------------------------
1626 // returns the first shell of spec. type viewing the specified doc.
1627
GetFirst(const TypeId * pType,sal_Bool bOnlyVisible)1628 SfxViewShell* SfxViewShell::GetFirst
1629 (
1630 const TypeId* pType,
1631 sal_Bool bOnlyVisible
1632 )
1633 {
1634 // search for a SfxViewShell of the specified type
1635 SfxViewShellArr_Impl &rShells = SFX_APP()->GetViewShells_Impl();
1636 SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl();
1637 for ( sal_uInt16 nPos = 0; nPos < rShells.Count(); ++nPos )
1638 {
1639 SfxViewShell *pShell = rShells.GetObject(nPos);
1640 if ( pShell )
1641 {
1642 // sometimes dangling SfxViewShells exist that point to a dead SfxViewFrame
1643 // these ViewShells shouldn't be accessible anymore
1644 // a destroyed ViewFrame is not in the ViewFrame array anymore, so checking this array helps
1645 for ( sal_uInt16 n=0; n<rFrames.Count(); ++n )
1646 {
1647 SfxViewFrame *pFrame = rFrames.GetObject(n);
1648 if ( pFrame == pShell->GetViewFrame() )
1649 {
1650 // only ViewShells with a valid ViewFrame will be returned
1651 if ( ( !bOnlyVisible || pFrame->IsVisible() ) && ( !pType || pShell->IsA(*pType) ) )
1652 return pShell;
1653 break;
1654 }
1655 }
1656 }
1657 }
1658
1659 return 0;
1660 }
1661
1662 //--------------------------------------------------------------------
1663 // returns the next shell of spec. type viewing the specified doc.
1664
GetNext(const SfxViewShell & rPrev,const TypeId * pType,sal_Bool bOnlyVisible)1665 SfxViewShell* SfxViewShell::GetNext
1666 (
1667 const SfxViewShell& rPrev,
1668 const TypeId* pType,
1669 sal_Bool bOnlyVisible
1670 )
1671 {
1672 SfxViewShellArr_Impl &rShells = SFX_APP()->GetViewShells_Impl();
1673 SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl();
1674 sal_uInt16 nPos;
1675 for ( nPos = 0; nPos < rShells.Count(); ++nPos )
1676 if ( rShells.GetObject(nPos) == &rPrev )
1677 break;
1678
1679 for ( ++nPos; nPos < rShells.Count(); ++nPos )
1680 {
1681 SfxViewShell *pShell = rShells.GetObject(nPos);
1682 if ( pShell )
1683 {
1684 // sometimes dangling SfxViewShells exist that point to a dead SfxViewFrame
1685 // these ViewShells shouldn't be accessible anymore
1686 // a destroyed ViewFrame is not in the ViewFrame array anymore, so checking this array helps
1687 for ( sal_uInt16 n=0; n<rFrames.Count(); ++n )
1688 {
1689 SfxViewFrame *pFrame = rFrames.GetObject(n);
1690 if ( pFrame == pShell->GetViewFrame() )
1691 {
1692 // only ViewShells with a valid ViewFrame will be returned
1693 if ( ( !bOnlyVisible || pFrame->IsVisible() ) && ( !pType || pShell->IsA(*pType) ) )
1694 return pShell;
1695 break;
1696 }
1697 }
1698 }
1699 }
1700
1701 return 0;
1702 }
1703
1704 //--------------------------------------------------------------------
1705
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)1706 void SfxViewShell::Notify( SfxBroadcaster& rBC,
1707 const SfxHint& rHint )
1708 {
1709 if ( rHint.IsA(TYPE(SfxEventHint)) )
1710 {
1711 switch ( ((SfxEventHint&)rHint).GetEventId() )
1712 {
1713 case SFX_EVENT_LOADFINISHED:
1714 {
1715 if ( GetController().is() )
1716 {
1717 // avoid access to dangling ViewShells
1718 SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl();
1719 for ( sal_uInt16 n=0; n<rFrames.Count(); ++n )
1720 {
1721 SfxViewFrame *frame = rFrames.GetObject(n);
1722 if ( frame == GetViewFrame() && &rBC == GetObjectShell() )
1723 {
1724 SfxItemSet* pSet = GetObjectShell()->GetMedium()->GetItemSet();
1725 SFX_ITEMSET_ARG( pSet, pItem, SfxUnoAnyItem, SID_VIEW_DATA, sal_False );
1726 if ( pItem )
1727 {
1728 pImp->m_pController->restoreViewData(
1729 pItem->GetValue() );
1730 pSet->ClearItem( SID_VIEW_DATA );
1731 }
1732
1733 break;
1734 }
1735 }
1736 }
1737
1738 break;
1739 }
1740 }
1741 }
1742 }
1743
1744 //--------------------------------------------------------------------
1745
ExecKey_Impl(const KeyEvent & aKey)1746 sal_Bool SfxViewShell::ExecKey_Impl(const KeyEvent& aKey)
1747 {
1748 if (!pImp->m_pAccExec.get())
1749 {
1750 pImp->m_pAccExec.reset(
1751 ::svt::AcceleratorExecute::createAcceleratorHelper() );
1752 pImp->m_pAccExec->init(::comphelper::getProcessServiceFactory(),
1753 pFrame->GetFrame().GetFrameInterface());
1754 }
1755
1756 return pImp->m_pAccExec->execute(aKey.GetKeyCode());
1757 }
1758
1759 //--------------------------------------------------------------------
1760
KeyInput(const KeyEvent & rKeyEvent)1761 FASTBOOL SfxViewShell::KeyInput( const KeyEvent &rKeyEvent )
1762
1763 /* [Beschreibung]
1764
1765 Diese Methode f"uhrt das KeyEvent 'rKeyEvent' "uber die an dieser
1766 SfxViewShell direkt oder indirekt (z.B. via Applikation) konfigurierten
1767 Tasten (Accelerator) aus.
1768
1769
1770 [R"uckgabewert]
1771
1772 FASTBOOL sal_True
1773 die Taste ist konfiguriert, der betreffende
1774 Handler wurde gerufen
1775
1776 FALSE
1777 die Taste ist nicht konfiguriert, es konnte
1778 also kein Handler gerufen werden
1779
1780
1781 [Querverweise]
1782 <SfxApplication::KeyInput(const KeyEvent&)>
1783 */
1784 {
1785 return ExecKey_Impl(rKeyEvent);
1786 }
1787
GlobalKeyInput_Impl(const KeyEvent & rKeyEvent)1788 bool SfxViewShell::GlobalKeyInput_Impl( const KeyEvent &rKeyEvent )
1789 {
1790 return ExecKey_Impl(rKeyEvent);
1791 }
1792
1793 //--------------------------------------------------------------------
1794
ShowCursor(FASTBOOL)1795 void SfxViewShell::ShowCursor( FASTBOOL /*bOn*/ )
1796
1797 /* [Beschreibung]
1798
1799 Diese Methode mu\s von Subklassen "uberladen werden, damit vom SFx
1800 aus der Cursor ein- und ausgeschaltet werden kann. Dies geschieht
1801 z.B. bei laufendem <SfxProgress>.
1802 */
1803
1804 {
1805 }
1806
1807 //--------------------------------------------------------------------
1808
GotFocus() const1809 void SfxViewShell::GotFocus() const
1810
1811 /* [Beschreibung]
1812
1813 Diese Methode mu\s vom Applikationsentwickler gerufen werden, wenn
1814 das Edit-Window den Focus erhalten hat. Der SFx hat so z.B. die
1815 M"oglichkeit, den Accelerator einzuschalten.
1816
1817
1818 [Anmerkung]
1819
1820 <StarView> liefert leider keine M"oglichkeit, solche Events
1821 'von der Seite' einzuh"angen.
1822 */
1823
1824 {
1825 }
1826
1827 //--------------------------------------------------------------------
ResetAllClients_Impl(SfxInPlaceClient * pIP)1828 void SfxViewShell::ResetAllClients_Impl( SfxInPlaceClient *pIP )
1829 {
1830
1831 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1832 if ( !pClients )
1833 return;
1834
1835 for ( sal_uInt16 n=0; n < pClients->Count(); n++ )
1836 {
1837 SfxInPlaceClient* pIPClient = pClients->GetObject(n);
1838 if( pIPClient != pIP )
1839 pIPClient->ResetObject();
1840 }
1841 }
1842
1843 //--------------------------------------------------------------------
1844
DisconnectAllClients()1845 void SfxViewShell::DisconnectAllClients()
1846 {
1847 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1848 if ( !pClients )
1849 return;
1850
1851 for ( sal_uInt16 n=0; n<pClients->Count(); )
1852 // clients will remove themselves from the list
1853 delete pClients->GetObject(n);
1854 }
1855
1856 //--------------------------------------------------------------------
1857
QueryObjAreaPixel(Rectangle &) const1858 void SfxViewShell::QueryObjAreaPixel( Rectangle& ) const
1859 {
1860 }
1861
1862 //--------------------------------------------------------------------
1863
AdjustVisArea(const Rectangle & rRect)1864 void SfxViewShell::AdjustVisArea(const Rectangle& rRect)
1865 {
1866 DBG_ASSERT (pFrame, "Kein Frame?");
1867 GetObjectShell()->SetVisArea( rRect );
1868 }
1869
1870 //--------------------------------------------------------------------
1871
VisAreaChanged(const Rectangle &)1872 void SfxViewShell::VisAreaChanged(const Rectangle& /*rVisArea*/)
1873 {
1874 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1875 if ( !pClients )
1876 return;
1877
1878 for (sal_uInt16 n=0; n < pClients->Count(); n++)
1879 {
1880 SfxInPlaceClient* pIPClient = pClients->GetObject(n);
1881 if ( pIPClient->IsObjectInPlaceActive() )
1882 // client is active, notify client that the VisArea might have changed
1883 pIPClient->VisAreaChanged();
1884 }
1885 }
1886
1887 //--------------------------------------------------------------------
CheckIPClient_Impl(SfxInPlaceClient * pIPClient,const Rectangle & rVisArea)1888 void SfxViewShell::CheckIPClient_Impl( SfxInPlaceClient *pIPClient, const Rectangle& rVisArea )
1889 {
1890 if ( GetObjectShell()->IsInClose() )
1891 return;
1892
1893 sal_Bool bAlwaysActive =
1894 ( ( pIPClient->GetObjectMiscStatus() & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) != 0 );
1895 sal_Bool bActiveWhenVisible =
1896 ( ( pIPClient->GetObjectMiscStatus() & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE ) != 0 );
1897
1898 // this method is called when either a client is created or the "Edit/Plugins" checkbox is checked
1899 if ( !pIPClient->IsObjectInPlaceActive() && pImp->m_bPlugInsActive )
1900 {
1901 // object in client is currently not active
1902 // check if the object wants to be activated always or when it becomes at least partially visible
1903 // TODO/LATER: maybe we should use the scaled area instead of the ObjArea?!
1904 if ( bAlwaysActive || (bActiveWhenVisible && rVisArea.IsOver(pIPClient->GetObjArea())) )
1905 {
1906 try
1907 {
1908 pIPClient->GetObject()->changeState( embed::EmbedStates::INPLACE_ACTIVE );
1909 }
1910 catch ( uno::Exception& )
1911 {
1912 }
1913 }
1914 }
1915 else if (!pImp->m_bPlugInsActive)
1916 {
1917 // object in client is currently active and "Edit/Plugins" checkbox is selected
1918 // check if the object wants to be activated always or when it becomes at least partially visible
1919 // in this case selecting of the "Edit/Plugin" checkbox should let such objects deactivate
1920 if ( bAlwaysActive || bActiveWhenVisible )
1921 pIPClient->GetObject()->changeState( embed::EmbedStates::RUNNING );
1922 }
1923 }
1924
1925 //--------------------------------------------------------------------
1926
PlugInsActive() const1927 sal_Bool SfxViewShell::PlugInsActive() const
1928 {
1929 return pImp->m_bPlugInsActive;
1930 }
1931
1932 //--------------------------------------------------------------------
DiscardClients_Impl()1933 void SfxViewShell::DiscardClients_Impl()
1934
1935 /* [Beschreibung]
1936
1937 Diese Methode dient dazu, vor dem Schlie\sen eines Dokuments das
1938 Speichern der Objekte zu verhindern, wenn der Benutzer Schlie\en ohne
1939 Speichern gew"ahlt hatte.
1940 */
1941
1942 {
1943 SfxInPlaceClientList *pClients = GetIPClientList_Impl(sal_False);
1944 if ( !pClients )
1945 return;
1946
1947 for (sal_uInt16 n=0; n < pClients->Count(); )
1948 delete pClients->GetObject(n);
1949 }
1950
1951 //--------------------------------------------------------------------
1952
GetScrollingMode() const1953 SfxScrollingMode SfxViewShell::GetScrollingMode() const
1954 {
1955 return pImp->m_eScroll;
1956 }
1957
1958 //--------------------------------------------------------------------
1959
SetScrollingMode(SfxScrollingMode eMode)1960 void SfxViewShell::SetScrollingMode( SfxScrollingMode eMode )
1961 {
1962 pImp->m_eScroll = eMode;
1963 }
1964
1965 //--------------------------------------------------------------------
1966
GetObjectShell()1967 SfxObjectShell* SfxViewShell::GetObjectShell()
1968 {
1969 return pFrame ? pFrame->GetObjectShell() : NULL;
1970 }
1971
1972 //--------------------------------------------------------------------
1973
GetCurrentDocument() const1974 Reference< XModel > SfxViewShell::GetCurrentDocument() const
1975 {
1976 Reference< XModel > xDocument;
1977
1978 const SfxObjectShell* pDocShell( const_cast< SfxViewShell* >( this )->GetObjectShell() );
1979 OSL_ENSURE( pDocShell, "SfxViewFrame::GetCurrentDocument: no DocShell!?" );
1980 if ( pDocShell )
1981 xDocument = pDocShell->GetModel();
1982 return xDocument;
1983 }
1984
1985 //--------------------------------------------------------------------
1986
SetCurrentDocument() const1987 void SfxViewShell::SetCurrentDocument() const
1988 {
1989 uno::Reference< frame::XModel > xDocument( GetCurrentDocument() );
1990 if ( xDocument.is() )
1991 SfxObjectShell::SetCurrentComponent( xDocument );
1992 }
1993
1994 //--------------------------------------------------------------------
1995
GetMargin() const1996 const Size& SfxViewShell::GetMargin() const
1997 {
1998 return pImp->aMargin;
1999 }
2000
2001 //--------------------------------------------------------------------
2002
SetMargin(const Size & rSize)2003 void SfxViewShell::SetMargin( const Size& rSize )
2004 {
2005 // Der default-Margin wurde "geeicht" mit www.apple.com !!
2006 Size aMargin = rSize;
2007 if ( aMargin.Width() == -1 )
2008 aMargin.Width() = DEFAULT_MARGIN_WIDTH;
2009 if ( aMargin.Height() == -1 )
2010 aMargin.Height() = DEFAULT_MARGIN_HEIGHT;
2011
2012 if ( aMargin != pImp->aMargin )
2013 {
2014 pImp->aMargin = aMargin;
2015 MarginChanged();
2016 }
2017 }
2018
2019 //--------------------------------------------------------------------
2020
MarginChanged()2021 void SfxViewShell::MarginChanged()
2022 {
2023 }
2024
2025 //--------------------------------------------------------------------
2026
IsShowView_Impl() const2027 sal_Bool SfxViewShell::IsShowView_Impl() const
2028 {
2029 return pImp->m_bIsShowView;
2030 }
2031
2032 //--------------------------------------------------------------------
2033
GetSmartSelf(SfxFrame * pSelf,SfxMedium &)2034 SfxFrame* SfxViewShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ )
2035 {
2036 return pSelf;
2037 }
2038
2039 //------------------------------------------------------------------------
2040
JumpToMark(const String & rMark)2041 void SfxViewShell::JumpToMark( const String& rMark )
2042 {
2043 SfxStringItem aMarkItem( SID_JUMPTOMARK, rMark );
2044 GetViewFrame()->GetDispatcher()->Execute(
2045 SID_JUMPTOMARK,
2046 SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
2047 &aMarkItem, 0L );
2048 }
2049
2050 //------------------------------------------------------------------------
2051
GetIPClientList_Impl(sal_Bool bCreate) const2052 SfxInPlaceClientList* SfxViewShell::GetIPClientList_Impl( sal_Bool bCreate ) const
2053 {
2054 if ( !pIPClientList && bCreate )
2055 ( (SfxViewShell*) this )->pIPClientList = new SfxInPlaceClientList;
2056 return pIPClientList;
2057 }
2058
SetController(SfxBaseController * pController)2059 void SfxViewShell::SetController( SfxBaseController* pController )
2060 {
2061 pImp->m_pController = pController;
2062 pImp->m_bControllerSet = true;
2063
2064 // there should be no old listener, but if there is one, it should be disconnected
2065 if ( pImp->xClipboardListener.is() )
2066 pImp->xClipboardListener->DisconnectViewShell();
2067
2068 pImp->xClipboardListener = new SfxClipboardChangeListener( this, GetClipboardNotifier() );
2069 }
2070
GetController()2071 Reference < XController > SfxViewShell::GetController()
2072 {
2073 return pImp->m_pController.get();
2074 }
2075
GetBaseController_Impl() const2076 SfxBaseController* SfxViewShell::GetBaseController_Impl() const
2077 {
2078 return pImp->m_pController.get();
2079 }
2080
AddContextMenuInterceptor_Impl(const REFERENCE<XCONTEXTMENUINTERCEPTOR> & xInterceptor)2081 void SfxViewShell::AddContextMenuInterceptor_Impl( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor )
2082 {
2083 pImp->aInterceptorContainer.addInterface( xInterceptor );
2084 }
2085
RemoveContextMenuInterceptor_Impl(const REFERENCE<XCONTEXTMENUINTERCEPTOR> & xInterceptor)2086 void SfxViewShell::RemoveContextMenuInterceptor_Impl( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor )
2087 {
2088 pImp->aInterceptorContainer.removeInterface( xInterceptor );
2089 }
2090
GetContextMenuInterceptors() const2091 ::cppu::OInterfaceContainerHelper& SfxViewShell::GetContextMenuInterceptors() const
2092 {
2093 return pImp->aInterceptorContainer;
2094 }
2095
Change(Menu * pMenu,SfxViewShell * pView)2096 void Change( Menu* pMenu, SfxViewShell* pView )
2097 {
2098 SfxDispatcher *pDisp = pView->GetViewFrame()->GetDispatcher();
2099 sal_uInt16 nCount = pMenu->GetItemCount();
2100 for ( sal_uInt16 nPos=0; nPos<nCount; ++nPos )
2101 {
2102 sal_uInt16 nId = pMenu->GetItemId(nPos);
2103 String aCmd = pMenu->GetItemCommand(nId);
2104 PopupMenu* pPopup = pMenu->GetPopupMenu(nId);
2105 if ( pPopup )
2106 {
2107 Change( pPopup, pView );
2108 }
2109 else if ( nId < 5000 )
2110 {
2111 if ( aCmd.CompareToAscii(".uno:", 5) == 0 )
2112 {
2113 for (sal_uInt16 nIdx=0;;)
2114 {
2115 SfxShell *pShell=pDisp->GetShell(nIdx++);
2116 if (pShell == NULL)
2117 break;
2118 const SfxInterface *pIFace = pShell->GetInterface();
2119 const SfxSlot* pSlot = pIFace->GetSlot( aCmd );
2120 if ( pSlot )
2121 {
2122 pMenu->InsertItem( pSlot->GetSlotId(), pMenu->GetItemText( nId ), pMenu->GetItemBits( nId ), nPos );
2123 pMenu->SetItemCommand( pSlot->GetSlotId(), aCmd );
2124 pMenu->RemoveItem( nPos+1 );
2125 break;
2126 }
2127 }
2128 }
2129 }
2130 }
2131 }
2132
2133
TryContextMenuInterception(Menu & rIn,const::rtl::OUString & rMenuIdentifier,Menu * & rpOut,ui::ContextMenuExecuteEvent aEvent)2134 sal_Bool SfxViewShell::TryContextMenuInterception( Menu& rIn, const ::rtl::OUString& rMenuIdentifier, Menu*& rpOut, ui::ContextMenuExecuteEvent aEvent )
2135 {
2136 rpOut = NULL;
2137 sal_Bool bModified = sal_False;
2138
2139 // create container from menu
2140 // #110897#
2141 // aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu( &rIn );
2142 aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu(
2143 ::comphelper::getProcessServiceFactory(), &rIn, &rMenuIdentifier );
2144
2145 // get selection from controller
2146 aEvent.Selection = uno::Reference < view::XSelectionSupplier > ( GetController(), uno::UNO_QUERY );
2147
2148 // call interceptors
2149 ::cppu::OInterfaceIteratorHelper aIt( pImp->aInterceptorContainer );
2150 while( aIt.hasMoreElements() )
2151 {
2152 try
2153 {
2154 ui::ContextMenuInterceptorAction eAction =
2155 ((ui::XContextMenuInterceptor*)aIt.next())->notifyContextMenuExecute( aEvent );
2156 switch ( eAction )
2157 {
2158 case ui::ContextMenuInterceptorAction_CANCELLED :
2159 // interceptor does not want execution
2160 return sal_False;
2161 case ui::ContextMenuInterceptorAction_EXECUTE_MODIFIED :
2162 // interceptor wants his modified menu to be executed
2163 bModified = sal_True;
2164 break;
2165 case ui::ContextMenuInterceptorAction_CONTINUE_MODIFIED :
2166 // interceptor has modified menu, but allows for calling other interceptors
2167 bModified = sal_True;
2168 continue;
2169 case ui::ContextMenuInterceptorAction_IGNORED :
2170 // interceptor is indifferent
2171 continue;
2172 default:
2173 DBG_ERROR("Wrong return value of ContextMenuInterceptor!");
2174 continue;
2175 }
2176 }
2177 catch( uno::RuntimeException& )
2178 {
2179 aIt.remove();
2180 }
2181
2182 break;
2183 }
2184
2185 if ( bModified )
2186 {
2187 // container was modified, create a new window out of it
2188 rpOut = new PopupMenu;
2189 ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer( rpOut, aEvent.ActionTriggerContainer );
2190
2191 Change( rpOut, this );
2192 }
2193
2194 return sal_True;
2195 }
2196
TakeOwnerShip_Impl()2197 void SfxViewShell::TakeOwnerShip_Impl()
2198 {
2199 // currently there is only one reason to take OwnerShip: a hidden frame is printed
2200 // so the ViewShell will check this on EndPrint (->prnmon.cxx)
2201 pImp->m_bGotOwnership = true;
2202 }
2203
TakeFrameOwnerShip_Impl()2204 void SfxViewShell::TakeFrameOwnerShip_Impl()
2205 {
2206 // currently there is only one reason to take OwnerShip: a hidden frame is printed
2207 // so the ViewShell will check this on EndPrint (->prnmon.cxx)
2208 pImp->m_bGotFrameOwnership = true;
2209 }
2210
CheckOwnerShip_Impl()2211 void SfxViewShell::CheckOwnerShip_Impl()
2212 {
2213 sal_Bool bSuccess = sal_False;
2214 if (pImp->m_bGotOwnership)
2215 {
2216 uno::Reference < util::XCloseable > xModel(
2217 GetObjectShell()->GetModel(), uno::UNO_QUERY );
2218 if ( xModel.is() )
2219 {
2220 try
2221 {
2222 // this call will destroy this object in case of success!
2223 xModel->close( sal_True );
2224 bSuccess = sal_True;
2225 }
2226 catch ( util::CloseVetoException& )
2227 {
2228 }
2229 }
2230 }
2231
2232 if (!bSuccess && pImp->m_bGotFrameOwnership)
2233 {
2234 // document couldn't be closed or it shouldn't, now try at least to close the frame
2235 uno::Reference < util::XCloseable > xFrame(
2236 GetViewFrame()->GetFrame().GetFrameInterface(), com::sun::star::uno::UNO_QUERY );
2237 if ( xFrame.is() )
2238 {
2239 try
2240 {
2241 xFrame->close( sal_True );
2242 }
2243 catch ( util::CloseVetoException& )
2244 {
2245 }
2246 }
2247 }
2248 }
2249
HandleNotifyEvent_Impl(NotifyEvent & rEvent)2250 long SfxViewShell::HandleNotifyEvent_Impl( NotifyEvent& rEvent )
2251 {
2252 if (pImp->m_pController.is())
2253 return pImp->m_pController->HandleEvent_Impl( rEvent );
2254 return 0;
2255 }
2256
HasKeyListeners_Impl()2257 sal_Bool SfxViewShell::HasKeyListeners_Impl()
2258 {
2259 return (pImp->m_pController.is())
2260 ? pImp->m_pController->HasKeyListeners_Impl() : sal_False;
2261 }
2262
HasMouseClickListeners_Impl()2263 sal_Bool SfxViewShell::HasMouseClickListeners_Impl()
2264 {
2265 return (pImp->m_pController.is())
2266 ? pImp->m_pController->HasMouseClickListeners_Impl() : sal_False;
2267 }
2268
SetAdditionalPrintOptions(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> & rOpts)2269 void SfxViewShell::SetAdditionalPrintOptions( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& rOpts )
2270 {
2271 pImp->aPrintOpts = rOpts;
2272 // GetObjectShell()->Broadcast( SfxPrintingHint( -3, NULL, NULL, rOpts ) );
2273 }
2274
Escape()2275 sal_Bool SfxViewShell::Escape()
2276 {
2277 return GetViewFrame()->GetBindings().Execute( SID_TERMINATE_INPLACEACTIVATION );
2278 }
2279
GetRenderable()2280 Reference< view::XRenderable > SfxViewShell::GetRenderable()
2281 {
2282 Reference< view::XRenderable >xRender;
2283 SfxObjectShell* pObj = GetObjectShell();
2284 if( pObj )
2285 {
2286 Reference< frame::XModel > xModel( pObj->GetModel() );
2287 if( xModel.is() )
2288 xRender = Reference< view::XRenderable >( xModel, UNO_QUERY );
2289 }
2290 return xRender;
2291 }
2292
GetClipboardNotifier()2293 uno::Reference< datatransfer::clipboard::XClipboardNotifier > SfxViewShell::GetClipboardNotifier()
2294 {
2295 uno::Reference< datatransfer::clipboard::XClipboardNotifier > xClipboardNotifier;
2296 if ( GetViewFrame() )
2297 xClipboardNotifier = uno::Reference< datatransfer::clipboard::XClipboardNotifier >( GetViewFrame()->GetWindow().GetClipboard(), uno::UNO_QUERY );
2298
2299 return xClipboardNotifier;
2300 }
2301
AddRemoveClipboardListener(const uno::Reference<datatransfer::clipboard::XClipboardListener> & rClp,sal_Bool bAdd)2302 void SfxViewShell::AddRemoveClipboardListener( const uno::Reference < datatransfer::clipboard::XClipboardListener >& rClp, sal_Bool bAdd )
2303 {
2304 try
2305 {
2306 if ( GetViewFrame() )
2307 {
2308 uno::Reference< datatransfer::clipboard::XClipboard > xClipboard( GetViewFrame()->GetWindow().GetClipboard() );
2309 if( xClipboard.is() )
2310 {
2311 uno::Reference< datatransfer::clipboard::XClipboardNotifier > xClpbrdNtfr( xClipboard, uno::UNO_QUERY );
2312 if( xClpbrdNtfr.is() )
2313 {
2314 if( bAdd )
2315 xClpbrdNtfr->addClipboardListener( rClp );
2316 else
2317 xClpbrdNtfr->removeClipboardListener( rClp );
2318 }
2319 }
2320 }
2321 }
2322 catch( const uno::Exception& )
2323 {
2324 }
2325 }
2326
2327