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