1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewsh.cxx,v $
10 * $Revision: 1.82.98.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <svtools/stritem.hxx>
34 #include <svtools/eitem.hxx>
35 #include <svtools/whiter.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <vcl/toolbox.hxx>
38 #include <svtools/intitem.hxx>
39 #include <svtools/sfxecode.hxx>
40 #include <svtools/ehdl.hxx>
41 #include <com/sun/star/frame/XLayoutManager.hpp>
42 #include <com/sun/star/frame/XModuleManager.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/embed/EmbedStates.hpp>
45 #include <com/sun/star/embed/EmbedMisc.hpp>
46 #include <com/sun/star/system/XSystemShellExecute.hpp>
47 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
48 #include <com/sun/star/container/XContainerQuery.hpp>
49 #include <com/sun/star/frame/XStorable.hpp>
51 #include <osl/file.hxx>
52 #include <vos/mutex.hxx>
53 #include <tools/urlobj.hxx>
54 #include <unotools/tempfile.hxx>
55 #include <svtools/pathoptions.hxx>
56 #include <svtools/miscopt.hxx>
57 #include <svtools/soerr.hxx>
58 #include <svtools/internaloptions.hxx>
60 #include <svtools/javaoptions.hxx>
61 #include <basic/basmgr.hxx>
62 #include <basic/sbuno.hxx>
63 #include <framework/actiontriggerhelper.hxx>
64 #include <comphelper/processfactory.hxx>
65 #include <comphelper/sequenceashashmap.hxx>
66 #include <toolkit/unohlp.hxx>
69 #include <sfx2/app.hxx>
71 #include <sfx2/viewsh.hxx>
72 #include "viewimp.hxx"
73 #include "sfxresid.hxx"
74 #include <sfx2/request.hxx>
75 #include <sfx2/templdlg.hxx>
76 #include <sfx2/printer.hxx>
77 #include <sfx2/docfile.hxx>
78 #include <sfx2/dispatch.hxx>
79 #include "arrdecl.hxx"
80 #include <sfx2/docfac.hxx>
82 #include "sfxlocal.hrc"
83 #include <sfx2/sfxbasecontroller.hxx>
84 #include <sfx2/topfrm.hxx>
85 #include "mailmodelapi.hxx"
86 #include <sfx2/event.hxx>
87 #include <sfx2/fcontnr.hxx>
88 #include <sfx2/ipclient.hxx>
89 #include "workwin.hxx"
90 #include <sfx2/objface.hxx>
91 #include <sfx2/docfilt.hxx>
94 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
95 #include <comphelper/processfactory.hxx>
98 using namespace ::com::sun::star
;
99 using namespace ::com::sun::star::uno
;
100 using namespace ::com::sun::star::frame
;
101 using namespace ::com::sun::star::beans
;
102 using namespace ::com::sun::star::util
;
103 using namespace ::com::sun::star::system
;
104 using namespace ::cppu
;
105 namespace css
= ::com::sun::star
;
107 //=========================================================================
108 DBG_NAME(SfxViewShell
)
111 #include "sfxslots.hxx"
113 //=========================================================================
115 static ::rtl::OUString
RetrieveLabelFromCommand(
116 const ::rtl::OUString
& rCommandURL
,
117 const css::uno::Reference
< css::frame::XFrame
>& rFrame
)
119 static css::uno::WeakReference
< frame::XModuleManager
> s_xModuleManager
;
120 static css::uno::WeakReference
< container::XNameAccess
> s_xNameAccess
;
122 ::rtl::OUString aLabel
;
123 css::uno::Reference
< css::frame::XModuleManager
> xModuleManager( s_xModuleManager
);
124 css::uno::Reference
< css::container::XNameAccess
> xNameAccess( s_xNameAccess
);
125 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR(
126 ::comphelper::getProcessServiceFactory(), css::uno::UNO_QUERY_THROW
);
130 if ( !xModuleManager
.is() )
132 xModuleManager
= css::uno::Reference
< css::frame::XModuleManager
>(
133 xSMGR
->createInstance(
134 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ))),
135 css::uno::UNO_QUERY_THROW
);
136 s_xModuleManager
= xModuleManager
;
139 ::rtl::OUString aModuleIdentifier
= xModuleManager
->identify( rFrame
);
141 if ( !xNameAccess
.is() )
143 xNameAccess
= css::uno::Reference
< css::container::XNameAccess
>(
144 xSMGR
->createInstance(
145 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.UICommandDescription" ))),
146 css::uno::UNO_QUERY_THROW
);
147 s_xNameAccess
= xNameAccess
;
150 css::uno::Any a
= xNameAccess
->getByName( aModuleIdentifier
);
151 css::uno::Reference
< css::container::XNameAccess
> xUICommands
;
155 css::uno::Sequence
< css::beans::PropertyValue
> aPropSeq
;
157 a
= xUICommands
->getByName( rCommandURL
);
158 if ( a
>>= aPropSeq
)
160 for ( sal_Int32 i
= 0; i
< aPropSeq
.getLength(); i
++ )
162 if ( aPropSeq
[i
].Name
.equalsAscii( "Label" ))
164 aPropSeq
[i
].Value
>>= aStr
;
171 catch ( css::uno::Exception
& )
178 //=========================================================================
180 SFX_IMPL_INTERFACE(SfxViewShell
,SfxShell
,SfxResId(0))
182 SFX_CHILDWINDOW_REGISTRATION( SID_MAIL_CHILDWIN
);
185 TYPEINIT2(SfxViewShell
,SfxShell
,SfxListener
);
187 //--------------------------------------------------------------------
188 /** search for a filter name dependent on type and module
191 static ::rtl::OUString
impl_retrieveFilterNameFromTypeAndModule(
192 const css::uno::Reference
< css::container::XContainerQuery
>& rContainerQuery
,
193 const ::rtl::OUString
& rType
,
194 const ::rtl::OUString
& rModuleIdentifier
,
195 const sal_Int32 nFlags
)
197 // Retrieve filter from type
198 css::uno::Sequence
< css::beans::NamedValue
> aQuery( 2 );
199 aQuery
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ));
200 aQuery
[0].Value
= css::uno::makeAny( rType
);
201 aQuery
[1].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" ));
202 aQuery
[1].Value
= css::uno::makeAny( rModuleIdentifier
);
204 css::uno::Reference
< css::container::XEnumeration
> xEnumeration
=
205 rContainerQuery
->createSubSetEnumerationByProperties( aQuery
);
207 ::rtl::OUString aFoundFilterName
;
208 while ( xEnumeration
->hasMoreElements() )
210 ::comphelper::SequenceAsHashMap
aFilterPropsHM( xEnumeration
->nextElement() );
211 ::rtl::OUString aFilterName
= aFilterPropsHM
.getUnpackedValueOrDefault(
212 ::rtl::OUString::createFromAscii( "Name" ),
215 sal_Int32 nFilterFlags
= aFilterPropsHM
.getUnpackedValueOrDefault(
216 ::rtl::OUString::createFromAscii( "Flags" ),
219 if ( nFilterFlags
& nFlags
)
221 aFoundFilterName
= aFilterName
;
226 return aFoundFilterName
;
229 //--------------------------------------------------------------------
230 /** search for an internal typename, which map to the current app module
231 and map also to a "family" of file formats as e.g. PDF/MS Doc/OOo Doc.
239 ::rtl::OUString
impl_searchFormatTypeForApp(const css::uno::Reference
< css::frame::XFrame
>& xFrame
,
240 ETypeFamily eTypeFamily
)
242 static ::rtl::OUString SERVICENAME_MODULEMANAGER
= ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
246 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR (::comphelper::getProcessServiceFactory() , css::uno::UNO_QUERY_THROW
);
247 css::uno::Reference
< css::frame::XModuleManager
> xModuleManager(xSMGR
->createInstance(SERVICENAME_MODULEMANAGER
), css::uno::UNO_QUERY_THROW
);
249 ::rtl::OUString sModule
= xModuleManager
->identify(xFrame
);
250 ::rtl::OUString sType
;
256 if (sModule
.equalsAscii( "com.sun.star.text.TextDocument" ))
257 sType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "writer_MS_Word_97" ));
259 if (sModule
.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ))
260 sType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calc_MS_Excel_97" ));
262 if (sModule
.equalsAscii( "com.sun.star.drawing.DrawingDocument" ))
263 sType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress_MS_PowerPoint_97" ));
265 if (sModule
.equalsAscii( "com.sun.star.presentation.PresentationDocument" ))
266 sType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress_MS_PowerPoint_97" ));
272 if (sModule
.equalsAscii( "com.sun.star.text.TextDocument" ))
273 sType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "writer8" ));
275 if (sModule
.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ))
276 sType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calc8" ));
278 if (sModule
.equalsAscii( "com.sun.star.drawing.DrawingDocument" ))
279 sType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "draw8" ));
281 if (sModule
.equalsAscii( "com.sun.star.presentation.PresentationDocument" ))
282 sType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress8" ));
289 catch(const css::uno::RuntimeException
& exRun
)
291 catch(const css::uno::Exception
&)
294 return ::rtl::OUString();
297 //--------------------------------------------------------------------
299 void SfxViewShell::ExecMisc_Impl( SfxRequest
&rReq
)
301 const USHORT nId
= rReq
.GetSlot();
304 case SID_STYLE_FAMILY
:
306 SFX_REQUEST_ARG(rReq
, pItem
, SfxUInt16Item
, nId
, FALSE
);
308 pImp
->nFamily
= pItem
->GetValue();
312 case SID_STYLE_CATALOG
:
314 SfxTemplateCatalog
aCatalog(
315 SFX_APP()->GetTopWindow(), &GetViewFrame()->GetBindings());
320 case SID_ACTIVATE_STYLE_APPLY
:
322 com::sun::star::uno::Reference
< com::sun::star::frame::XFrame
> xFrame(
323 GetViewFrame()->GetFrame()->GetFrameInterface(),
324 com::sun::star::uno::UNO_QUERY
);
326 Reference
< com::sun::star::beans::XPropertySet
> xPropSet( xFrame
, UNO_QUERY
);
327 Reference
< ::com::sun::star::frame::XLayoutManager
> xLayoutManager
;
332 Any aValue
= xPropSet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
333 aValue
>>= xLayoutManager
;
334 if ( xLayoutManager
.is() )
336 rtl::OUString
aTextResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/textobjectbar" ));
337 uno::Reference
< ui::XUIElement
> xElement
= xLayoutManager
->getElement( aTextResString
);
340 rtl::OUString
aFrameResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/frameobjectbar" ));
341 xElement
= xLayoutManager
->getElement( aFrameResString
);
345 rtl::OUString
aOleResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/oleobjectbar" ));
346 xElement
= xLayoutManager
->getElement( aOleResString
);
350 uno::Reference
< awt::XWindow
> xWin( xElement
->getRealInterface(), uno::UNO_QUERY_THROW
);
351 Window
* pWin
= VCLUnoHelper::GetWindow( xWin
);
352 ToolBox
* pTextToolbox
= dynamic_cast< ToolBox
* >( pWin
);
355 USHORT nItemCount
= pTextToolbox
->GetItemCount();
356 for( USHORT nItem
= 0; nItem
< nItemCount
; ++nItem
)
358 USHORT nItemId
= pTextToolbox
->GetItemId( nItem
);
359 const XubString
& rCommand
= pTextToolbox
->GetItemCommand( nItemId
);
360 if( rCommand
.EqualsAscii( ".uno:StyleApply" ) )
362 Window
* pItemWin
= pTextToolbox
->GetItemWindow( nItemId
);
364 pItemWin
->GrabFocus();
379 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
381 case SID_MAIL_SENDDOCASMS
:
382 case SID_MAIL_SENDDOCASOOO
:
383 case SID_MAIL_SENDDOCASPDF
:
384 case SID_MAIL_SENDDOC
:
385 case SID_MAIL_SENDDOCASFORMAT
:
387 SfxObjectShell
* pDoc
= GetObjectShell();
388 if ( pDoc
&& pDoc
->QueryHiddenInformation(
389 WhenSaving
, &GetViewFrame()->GetWindow() ) != RET_YES
)
392 if ( SvtInternalOptions().MailUIEnabled() )
394 GetViewFrame()->SetChildWindow( SID_MAIL_CHILDWIN
, TRUE
);
399 rtl::OUString aDocType
;
401 SFX_REQUEST_ARG(rReq
, pMailSubject
, SfxStringItem
, SID_MAIL_SUBJECT
, FALSE
);
403 aModel
.SetSubject( pMailSubject
->GetValue() );
405 SFX_REQUEST_ARG(rReq
, pMailRecipient
, SfxStringItem
, SID_MAIL_RECIPIENT
, FALSE
);
406 if ( pMailRecipient
)
408 String
aRecipient( pMailRecipient
->GetValue() );
409 String
aMailToStr( String::CreateFromAscii( "mailto:" ));
411 if ( aRecipient
.Search( aMailToStr
) == 0 )
412 aRecipient
= aRecipient
.Erase( 0, aMailToStr
.Len() );
413 aModel
.AddAddress( aRecipient
, SfxMailModel::ROLE_TO
);
415 SFX_REQUEST_ARG(rReq
, pMailDocType
, SfxStringItem
, SID_TYPE_NAME
, FALSE
);
417 aDocType
= pMailDocType
->GetValue();
419 uno::Reference
< frame::XFrame
> xFrame( pFrame
->GetFrame()->GetFrameInterface() );
420 SfxMailModel::SendMailResult eResult
= SfxMailModel::SEND_MAIL_ERROR
;
422 if ( nId
== SID_MAIL_SENDDOC
)
423 eResult
= aModel
.SaveAndSend( xFrame
, rtl::OUString() );
425 if ( nId
== SID_MAIL_SENDDOCASPDF
)
426 eResult
= aModel
.SaveAndSend( xFrame
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "pdf_Portable_Document_Format" )));
428 if ( nId
== SID_MAIL_SENDDOCASMS
)
430 aDocType
= impl_searchFormatTypeForApp(xFrame
, E_MS_DOC
);
431 if (aDocType
.getLength() > 0)
432 eResult
= aModel
.SaveAndSend( xFrame
, aDocType
);
435 if ( nId
== SID_MAIL_SENDDOCASOOO
)
437 aDocType
= impl_searchFormatTypeForApp(xFrame
, E_OOO_DOC
);
438 if (aDocType
.getLength() > 0)
439 eResult
= aModel
.SaveAndSend( xFrame
, aDocType
);
442 if ( eResult
== SfxMailModel::SEND_MAIL_ERROR
)
444 InfoBox
aBox( SFX_APP()->GetTopWindow(), SfxResId( MSG_ERROR_SEND_MAIL
));
455 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
458 static const char HTML_DOCUMENT_TYPE
[] = "writer_web_HTML";
459 static const char HTML_GRAPHIC_TYPE
[] = "graphic_HTML";
460 const sal_Int32 FILTERFLAG_EXPORT
= 0x00000002;
462 css::uno::Reference
< lang::XMultiServiceFactory
> xSMGR(::comphelper::getProcessServiceFactory(), css::uno::UNO_QUERY_THROW
);
463 css::uno::Reference
< css::frame::XFrame
> xFrame( pFrame
->GetFrame()->GetFrameInterface() );
464 css::uno::Reference
< css::frame::XModel
> xModel
;
466 const rtl::OUString
aModuleManager( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ));
467 css::uno::Reference
< css::frame::XModuleManager
> xModuleManager( xSMGR
->createInstance( aModuleManager
), css::uno::UNO_QUERY_THROW
);
468 if ( !xModuleManager
.is() )
474 rtl::OUString aModule
;
477 aModule
= xModuleManager
->identify( xFrame
);
479 catch ( css::uno::RuntimeException
& )
483 catch ( css::uno::Exception
& )
489 css::uno::Reference
< css::frame::XController
> xController
= xFrame
->getController();
490 if ( xController
.is() )
491 xModel
= xController
->getModel();
494 // We need at least a valid module name and model reference
495 css::uno::Reference
< css::frame::XStorable
> xStorable( xModel
, css::uno::UNO_QUERY
);
496 if ( xModel
.is() && xStorable
.is() )
498 rtl::OUString aFilterName
;
499 rtl::OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM( HTML_DOCUMENT_TYPE
));
500 rtl::OUString aFileName
;
501 rtl::OUString
aExtension( RTL_CONSTASCII_USTRINGPARAM( "htm" ));
503 rtl::OUString aLocation
= xStorable
->getLocation();
504 INetURLObject
aFileObj( aLocation
);
506 bool bPrivateProtocol
= ( aFileObj
.GetProtocol() == INET_PROT_PRIV_SOFFICE
);
507 bool bHasLocation
= ( aLocation
.getLength() > 0 ) && !bPrivateProtocol
;
509 css::uno::Reference
< css::container::XContainerQuery
> xContainerQuery(
510 xSMGR
->createInstance( rtl::OUString(
511 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ))),
512 css::uno::UNO_QUERY_THROW
);
514 // Retrieve filter from type
515 sal_Int32 nFilterFlags
= FILTERFLAG_EXPORT
;
516 aFilterName
= impl_retrieveFilterNameFromTypeAndModule( xContainerQuery
, aTypeName
, aModule
, nFilterFlags
);
517 if ( aFilterName
.getLength() == 0 )
519 // Draw/Impress uses a different type. 2nd chance try to use alternative type name
520 aFilterName
= impl_retrieveFilterNameFromTypeAndModule(
521 xContainerQuery
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( HTML_GRAPHIC_TYPE
)), aModule
, nFilterFlags
);
524 // No filter found => error
525 // No type and no location => error
526 if (( aFilterName
.getLength() == 0 ) || ( aTypeName
.getLength() == 0 ))
532 // Use provided save file name. If empty determine file name
535 // Create a default file name with the correct extension
536 const rtl::OUString
aPreviewFileName( RTL_CONSTASCII_USTRINGPARAM( "webpreview" ));
537 aFileName
= aPreviewFileName
;
541 // Determine file name from model
542 INetURLObject
aFObj( xStorable
->getLocation() );
543 aFileName
= aFObj
.getName( INetURLObject::LAST_SEGMENT
, true, INetURLObject::NO_DECODE
);
546 OSL_ASSERT( aFilterName
.getLength() > 0 );
547 OSL_ASSERT( aFileName
.getLength() > 0 );
549 // Creates a temporary directory to store our predefined file into it.
550 ::utl::TempFile
aTempDir( NULL
, sal_True
);
552 INetURLObject
aFilePathObj( aTempDir
.GetURL() );
553 aFilePathObj
.insertName( aFileName
);
554 aFilePathObj
.setExtension( aExtension
);
556 rtl::OUString aFileURL
= aFilePathObj
.GetMainURL( INetURLObject::NO_DECODE
);
558 css::uno::Sequence
< css::beans::PropertyValue
> aArgs( 1 );
559 aArgs
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
560 aArgs
[0].Value
= css::uno::makeAny( aFilterName
);
562 // Store document in the html format
565 xStorable
->storeToURL( aFileURL
, aArgs
);
567 catch ( com::sun::star::io::IOException
& )
573 ::com::sun::star::uno::Reference
< XSystemShellExecute
> xSystemShellExecute( xSMGR
->createInstance(
574 ::rtl::OUString::createFromAscii( "com.sun.star.system.SystemShellExecute" )),
575 css::uno::UNO_QUERY
);
578 if ( xSystemShellExecute
.is() )
582 xSystemShellExecute
->execute(
583 aFileURL
, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS
);
585 catch ( uno::Exception
& )
587 vos::OGuard
aGuard( Application::GetSolarMutex() );
588 Window
*pParent
= SFX_APP()->GetTopWindow();
589 ErrorBox( pParent
, SfxResId( MSG_ERROR_NO_WEBBROWSER_FOUND
)).Execute();
604 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
605 case SID_PLUGINS_ACTIVE
:
607 SFX_REQUEST_ARG(rReq
, pShowItem
, SfxBoolItem
, nId
, FALSE
);
608 BOOL bActive
= pShowItem
? pShowItem
->GetValue() : !pImp
->bPlugInsActive
;
611 rReq
.AppendItem( SfxBoolItem( nId
, bActive
) );
613 // Jetzt schon DONE aufrufen, da die Argumente evtl. einen Pool
614 // benutzen, der demn"achst weg ist
618 if ( !pShowItem
|| bActive
!= pImp
->bPlugInsActive
)
620 SfxFrame
* pTopFrame
= GetFrame()->GetTopFrame();
621 if ( pTopFrame
!= GetFrame()->GetFrame() )
624 SfxViewShell
*pShell
= pTopFrame
->GetCurrentViewFrame()->GetViewShell();
625 if ( pShell
->GetInterface()->GetSlot( nId
) )
626 pShell
->ExecuteSlot( rReq
);
630 SfxFrameIterator
aIter( *pTopFrame
);
633 if ( pTopFrame
->GetCurrentViewFrame() )
635 SfxViewShell
*pView
= pTopFrame
->GetCurrentViewFrame()->GetViewShell();
638 pView
->pImp
->bPlugInsActive
= bActive
;
639 Rectangle aVisArea
= GetObjectShell()->GetVisArea();
640 VisAreaChanged(aVisArea
);
642 // the plugins might need change in their state
643 SfxInPlaceClientList
*pClients
= pView
->GetIPClientList_Impl(FALSE
);
646 for (USHORT n
=0; n
< pClients
->Count(); n
++)
648 SfxInPlaceClient
* pIPClient
= pClients
->GetObject(n
);
650 pView
->CheckIPClient_Impl( pIPClient
, aVisArea
);
656 if ( !pTopFrame
->GetParentFrame() )
657 pTopFrame
= aIter
.FirstFrame();
659 pTopFrame
= aIter
.NextFrame( *pTopFrame
);
668 //--------------------------------------------------------------------
670 void SfxViewShell::GetState_Impl( SfxItemSet
&rSet
)
672 DBG_CHKTHIS(SfxViewShell
, 0);
674 SfxWhichIter
aIter( rSet
);
675 for ( USHORT nSID
= aIter
.FirstWhich(); nSID
; nSID
= aIter
.NextWhich() )
679 case SID_STYLE_CATALOG
:
681 if ( !GetViewFrame()->KnowsChildWindow( SID_STYLE_DESIGNER
) )
682 rSet
.DisableItem( nSID
);
686 // Printer-Funktionen
688 case SID_PRINTDOCDIRECT
:
689 case SID_SETUPPRINTER
:
691 BOOL bEnabled
= pImp
->bCanPrint
&& !pImp
->nPrinterLocks
;
692 bEnabled
= bEnabled
&& !Application::GetSettings().GetMiscSettings().GetDisablePrinting();
695 SfxPrinter
*pPrinter
= GetPrinter(FALSE
);
697 if ( SID_PRINTDOCDIRECT
== nSID
)
699 rtl::OUString aPrinterName
;
700 if ( pPrinter
!= NULL
)
701 aPrinterName
= pPrinter
->GetName();
703 aPrinterName
= Printer::GetDefaultPrinterName();
704 if ( aPrinterName
.getLength() > 0 )
706 uno::Reference
< frame::XFrame
> xFrame( pFrame
->GetFrame()->GetFrameInterface() );
708 ::rtl::OUStringBuffer
aBuffer( 60 );
709 aBuffer
.append( RetrieveLabelFromCommand(
710 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PrintDefault" )),
712 aBuffer
.appendAscii( " (" );
713 aBuffer
.append( aPrinterName
);
714 aBuffer
.appendAscii( ")" );
716 rSet
.Put( SfxStringItem( SID_PRINTDOCDIRECT
, aBuffer
.makeStringAndClear() ) );
719 bEnabled
= !pPrinter
|| !pPrinter
->IsPrinting();
723 rSet
.DisableItem( SID_PRINTDOC
);
724 rSet
.DisableItem( SID_PRINTDOCDIRECT
);
725 rSet
.DisableItem( SID_SETUPPRINTER
);
731 case SID_MAIL_SENDDOCASPDF
:
732 case SID_MAIL_SENDDOC
:
733 case SID_MAIL_SENDDOCASFORMAT
:
735 BOOL bEnable
= !GetViewFrame()->HasChildWindow( SID_MAIL_CHILDWIN
);
737 rSet
.DisableItem( nSID
);
742 case SID_PLUGINS_ACTIVE
:
744 rSet
.Put( SfxBoolItem( SID_PLUGINS_ACTIVE
, !pImp
->bPlugInsActive
) );
749 case SID_SELECTION_TEXT:
751 rSet.Put( SfxStringItem( SID_SELECTION_TEXT, GetSelectionText() ) );
756 case SID_SELECTION_TEXT_EXT:
758 rSet.Put( SfxStringItem( SID_SELECTION_TEXT_EXT, GetSelectionText(TRUE) ) );
762 case SID_STYLE_FAMILY
:
764 rSet
.Put( SfxUInt16Item( SID_STYLE_FAMILY
, pImp
->nFamily
) );
771 //--------------------------------------------------------------------
773 void SfxViewShell::SetZoomFactor( const Fraction
&rZoomX
,
774 const Fraction
&rZoomY
)
776 DBG_ASSERT( GetWindow(), "no window" );
777 MapMode
aMap( GetWindow()->GetMapMode() );
778 aMap
.SetScaleX( rZoomX
);
779 aMap
.SetScaleY( rZoomY
);
780 GetWindow()->SetMapMode( aMap
);
783 //--------------------------------------------------------------------
784 ErrCode
SfxViewShell::DoVerb(long /*nVerb*/)
788 Virtuelle Methode, um am selektierten Objekt ein Verb auszuf"uhren.
789 Da dieses Objekt nur den abgeleiteten Klassen bekannt ist, muss DoVerb
790 dort "uberschrieben werden.
795 return ERRCODE_SO_NOVERBS
;
798 //--------------------------------------------------------------------
800 void SfxViewShell::OutplaceActivated( sal_Bool bActive
, SfxInPlaceClient
* /*pClient*/ )
803 GetFrame()->GetFrame()->Appear();
806 //--------------------------------------------------------------------
808 void SfxViewShell::InplaceActivating( SfxInPlaceClient
* /*pClient*/ )
810 // TODO/LATER: painting of the bitmap can be stopped, it is required if CLIPCHILDREN problem #i25788# is not solved,
811 // but may be the bug will not affect the real office vcl windows, then it is not required
814 //--------------------------------------------------------------------
816 void SfxViewShell::InplaceDeactivated( SfxInPlaceClient
* /*pClient*/ )
818 // TODO/LATER: paint the replacement image in normal way if the painting was stopped
821 //--------------------------------------------------------------------
823 void SfxViewShell::UIActivating( SfxInPlaceClient
* /*pClient*/ )
825 uno::Reference
< frame::XFrame
> xOwnFrame( pFrame
->GetFrame()->GetFrameInterface() );
826 uno::Reference
< frame::XFramesSupplier
> xParentFrame( xOwnFrame
->getCreator(), uno::UNO_QUERY
);
827 if ( xParentFrame
.is() )
828 xParentFrame
->setActiveFrame( xOwnFrame
);
830 pFrame
->GetBindings().HidePopups(TRUE
);
831 pFrame
->GetDispatcher()->Update_Impl( TRUE
);
834 //--------------------------------------------------------------------
836 void SfxViewShell::UIDeactivated( SfxInPlaceClient
* /*pClient*/ )
838 if ( !pFrame
->GetFrame()->IsClosing_Impl() ||
839 SfxViewFrame::Current() != pFrame
)
840 pFrame
->GetDispatcher()->Update_Impl( TRUE
);
841 pFrame
->GetBindings().HidePopups(FALSE
);
843 // uno::Reference < frame::XFrame > xOwnFrame( pFrame->GetFrame()->GetFrameInterface() );
844 // uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
845 // if ( xParentFrame.is() )
846 // xParentFrame->setActiveFrame( uno::Reference < frame::XFrame >() );
849 //--------------------------------------------------------------------
851 SfxInPlaceClient
* SfxViewShell::FindIPClient
853 const uno::Reference
< embed::XEmbeddedObject
>& xObj
,
854 Window
* pObjParentWin
857 SfxInPlaceClientList
*pClients
= GetIPClientList_Impl(FALSE
);
862 pObjParentWin
= GetWindow();
863 for (USHORT n
=0; n
< pClients
->Count(); n
++)
865 SfxInPlaceClient
*pIPClient
= (SfxInPlaceClient
*) pClients
->GetObject(n
);
866 if ( pIPClient
->GetObject() == xObj
&& pIPClient
->GetEditWin() == pObjParentWin
)
873 //--------------------------------------------------------------------
875 SfxInPlaceClient
* SfxViewShell::GetIPClient() const
877 return GetUIActiveClient();
880 //--------------------------------------------------------------------
882 SfxInPlaceClient
* SfxViewShell::GetUIActiveIPClient_Impl() const
884 // this method is needed as long as SFX still manages the border space for ChildWindows (see SfxFrame::Resize)
885 SfxInPlaceClientList
*pClients
= GetIPClientList_Impl(FALSE
);
889 for (USHORT n
=0; n
< pClients
->Count(); n
++)
891 SfxInPlaceClient
* pIPClient
= pClients
->GetObject(n
);
892 if ( pIPClient
->IsUIActive() )
899 SfxInPlaceClient
* SfxViewShell::GetUIActiveClient() const
901 SfxInPlaceClientList
*pClients
= GetIPClientList_Impl(FALSE
);
905 for (USHORT n
=0; n
< pClients
->Count(); n
++)
907 SfxInPlaceClient
* pIPClient
= pClients
->GetObject(n
);
908 if ( pIPClient
->IsObjectUIActive() )
915 //--------------------------------------------------------------------
917 void SfxViewShell::Activate( BOOL bMDI
)
919 DBG_CHKTHIS(SfxViewShell
, 0);
922 SfxObjectShell
*pSh
= GetViewFrame()->GetObjectShell();
923 if ( pSh
->GetModel().is() )
924 pSh
->GetModel()->setCurrentController( GetViewFrame()->GetFrame()->GetController() );
926 SetCurrentDocument();
930 //--------------------------------------------------------------------
932 void SfxViewShell::Deactivate(BOOL
/*bMDI*/)
934 DBG_CHKTHIS(SfxViewShell
, 0);
937 //--------------------------------------------------------------------
939 void SfxViewShell::AdjustPosSizePixel
941 const Point
& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window
942 const Size
& /*rSize*/ // gesamte zur Verf"ugung stehende Gr"o\se
946 DBG_CHKTHIS(SfxViewShell
, 0);
949 //--------------------------------------------------------------------
951 void SfxViewShell::Move()
955 Diese virtuelle Methode wird gerufen, wenn das Fenster, in dem die
956 SfxViewShell dargestellt wird eine StarView-Move() Nachricht erh"alt.
958 Die Basisimplementierung braucht nicht gerufen zu werden.
963 Diese Methode kann dazu verwendet werden, eine Selektion abzubrechen,
964 um durch das Moven des Fensters erzeugte Maus-Bewegungen anzufangen.
966 Zur Zeit funktioniert die Benachrichtigung nicht In-Place.
972 //--------------------------------------------------------------------
974 void SfxViewShell::OuterResizePixel
976 const Point
& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window
977 const Size
& /*rSize*/ // gesamte zur Verf"ugung stehende Gr"o\se
982 Diese Methode muss ueberladen werden, um auf "Anderungen der Groesse
983 der View zu reagieren. Dabei definieren wir die View als das Edit-Window
984 zuz"uglich der um das Edit-Window angeordnenten Tools (z.B. Lineale).
986 Das Edit-Window darf weder in Gr"o\se noch Position ver"andert werden.
988 Die Vis-Area der SfxObjectShell, dessen Skalierung und Position
989 d"urfen hier ver"andert werden. Der Hauptanwendungsfall ist dabei,
990 das Ver"andern der Gr"o\se der Vis-Area.
992 "Andert sich durch die neue Berechnung der Border, so mu\s dieser
993 mit <SfxViewShell::SetBorderPixel(const SvBorder&)> gesetzt werden.
994 Erst nach Aufruf von 'SetBorderPixel' ist das Positionieren von
1000 void AppViewSh::OuterViewResizePixel( const Point &rOfs, const Size &rSz )
1002 // Tool-Positionen und Gr"o\sen von au\sen berechnen, NICHT setzen!
1003 // (wegen folgender Border-Berechnung)
1004 Point aHLinPos...; Size aHLinSz...;
1007 // Border f"ur Tools passend zu rSize berechnen und setzen
1009 SetBorderPixel( aBorder ); // ab jetzt sind Positionierungen erlaubt
1012 pHLin->SetPosSizePixel( aHLinPos, aHLinSz );
1019 <SfxViewShell::InnerResizePixel(const Point&,const Size& rSize)>
1023 DBG_CHKTHIS(SfxViewShell
, 0);
1024 SetBorderPixel( SvBorder() );
1027 //--------------------------------------------------------------------
1029 void SfxViewShell::InnerResizePixel
1031 const Point
& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window
1032 const Size
& /*rSize*/ // dem Edit-Win zur Verf"ugung stehende Gr"o\se
1037 Diese Methode muss ueberladen werden, um auf "Anderungen der Groesse
1038 des Edit-Windows zu reagieren.
1040 Das Edit-Window darf weder in Gr"o\se noch Position ver"andert werden.
1041 Weder die Vis-Area der SfxObjectShell noch dessen Skalierung oder
1042 Position d"urfen ver"andert werden.
1044 "Andert sich durch die neue Berechnung der Border, so mu\s dieser
1045 mit <SfxViewShell::SetBorderPixel(const SvBorder&)> gesetzt werden.
1046 Erst nach Aufruf von 'SetBorderPixel' ist das Positionieren von
1052 void AppViewSh::InnerViewResizePixel( const Point &rOfs, const Size &rSz )
1054 // Tool-Positionen und Gr"o\sen von innen berechnen, NICHT setzen!
1055 // (wegen folgender Border-Berechnung)
1056 Point aHLinPos...; Size aHLinSz...;
1059 // Border f"ur Tools passend zu rSz berechnen und setzen
1061 SetBorderPixel( aBorder ); // ab jetzt sind Positionierungen erlaubt
1064 pHLin->SetPosSizePixel( aHLinPos, aHLinSz );
1071 <SfxViewShell::OuterResizePixel(const Point&,const Size& rSize)>
1075 DBG_CHKTHIS(SfxViewShell
, 0);
1076 SetBorderPixel( SvBorder() );
1079 //--------------------------------------------------------------------
1081 void SfxViewShell::InvalidateBorder()
1083 DBG_CHKTHIS(SfxViewShell
, 0);
1084 DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
1086 GetViewFrame()->InvalidateBorderImpl( this );
1087 if ( pImp
->pController
)
1088 pImp
->pController
->BorderWidthsChanged_Impl();
1091 //--------------------------------------------------------------------
1093 void SfxViewShell::SetBorderPixel( const SvBorder
&rBorder
)
1095 DBG_CHKTHIS(SfxViewShell
, 0);
1096 DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
1098 //if ( rBorder != GetBorderPixel())
1100 GetViewFrame()->SetBorderPixelImpl( this, rBorder
);
1102 // notify related controller that border size is changed
1103 if ( pImp
->pController
)
1104 pImp
->pController
->BorderWidthsChanged_Impl();
1108 //--------------------------------------------------------------------
1110 const SvBorder
& SfxViewShell::GetBorderPixel() const
1112 DBG_CHKTHIS(SfxViewShell
, 0);
1113 DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
1115 return GetViewFrame()->GetBorderPixelImpl( this );
1118 //--------------------------------------------------------------------
1120 void SfxViewShell::SetWindow
1122 Window
* pViewPort
// Pointer auf das Datenfenster bzw. 0 im Destruktor
1127 Mit dieser Methode wird der SfxViewShell das Datenfenster mitgeteilt.
1128 Dieses wird f"ur den In-Place-Container und f"ur das korrekte
1129 Wiederherstellen des Focus ben"otigt.
1131 Selbst In-Place-aktiv ist das Umsetzen des ViewPort-Windows verboten.
1135 if( pWindow
== pViewPort
)
1138 // ggf. vorhandene IP-Clients disconnecten
1139 DisconnectAllClients();
1141 //TODO: should we have a "ReconnectAllClients" method?
1142 DiscardClients_Impl();
1144 // View-Port austauschen
1145 BOOL bHadFocus
= pWindow
? pWindow
->HasChildPathFocus( TRUE
) : FALSE
;
1146 pWindow
= pViewPort
;
1150 // Disable automatic GUI mirroring (right-to-left) for document windows
1151 pWindow
->EnableRTL( FALSE
);
1154 if ( bHadFocus
&& pWindow
)
1155 pWindow
->GrabFocus();
1157 //brauchen wir die Methode doch noch?!
1158 //SFX_APP()->GrabFocus( pWindow );
1161 //--------------------------------------------------------------------
1163 Size
SfxViewShell::GetOptimalSizePixel() const
1165 DBG_ERROR( "Useless call!" );
1169 //------------------------------------------------------------------------
1171 SfxViewShell::SfxViewShell
1173 SfxViewFrame
* pViewFrame
, /* <SfxViewFrame>, in dem diese View
1175 USHORT nFlags
/* siehe <SfxViewShell-Flags> */
1179 ,pImp( new SfxViewShell_Impl
)
1184 ,bMaximizeFirst( 0 != (nFlags
& SFX_VIEW_MAXIMIZE_FIRST
) )
1185 ,bOptimizeEach(0 != (nFlags
& SFX_VIEW_OPTIMIZE_EACH
))
1186 ,bNoNewWindow( 0 != (nFlags
& SFX_VIEW_NO_NEWWINDOW
) )
1188 DBG_CTOR(SfxViewShell
, 0);
1190 pImp
->pController
= 0;
1192 !(SFX_VIEW_NO_SHOW
== (nFlags
& SFX_VIEW_NO_SHOW
));
1194 pImp
->bUseObjectSize
= FALSE
;
1195 // SFX_CREATE_MODE_EMBEDDED==pFrame->GetObjectShell()->GetCreateMode() &&
1196 // SFX_VIEW_OBJECTSIZE_EMBEDDED == (nFlags & SFX_VIEW_OBJECTSIZE_EMBEDDED);
1197 pImp
->bCanPrint
= SFX_VIEW_CAN_PRINT
== (nFlags
& SFX_VIEW_CAN_PRINT
);
1198 pImp
->bFrameSetImpl
= (nFlags
& SFX_VIEW_IMPLEMENTED_AS_FRAMESET
) != 0;
1199 pImp
->bHasPrintOptions
=
1200 SFX_VIEW_HAS_PRINTOPTIONS
== (nFlags
& SFX_VIEW_HAS_PRINTOPTIONS
);
1201 pImp
->bPlugInsActive
= TRUE
;
1202 pImp
->bGotOwnerShip
= FALSE
;
1203 pImp
->bGotFrameOwnerShip
= FALSE
;
1204 if ( pViewFrame
->GetParentViewFrame() )
1205 pImp
->bPlugInsActive
= pViewFrame
->GetParentViewFrame()->GetViewShell()->pImp
->bPlugInsActive
;
1206 pImp
->eScroll
= SCROLLING_DEFAULT
;
1207 pImp
->nPrinterLocks
= 0;
1208 pImp
->bControllerSet
= FALSE
;
1209 pImp
->nFamily
= 0xFFFF; // undefined, default set by TemplateDialog
1210 SetMargin( pViewFrame
->GetMargin_Impl() );
1212 SetPool( &pViewFrame
->GetObjectShell()->GetPool() );
1213 StartListening(*pViewFrame
->GetObjectShell());
1215 // in Liste eintragen
1216 const SfxViewShell
*pThis
= this; // wegen der kranken Array-Syntax
1217 SfxViewShellArr_Impl
&rViewArr
= SFX_APP()->GetViewShells_Impl();
1218 rViewArr
.Insert(pThis
, rViewArr
.Count() );
1221 //--------------------------------------------------------------------
1223 SfxViewShell::~SfxViewShell()
1225 DBG_DTOR(SfxViewShell
, 0);
1227 // aus Liste austragen
1228 const SfxViewShell
*pThis
= this;
1229 SfxViewShellArr_Impl
&rViewArr
= SFX_APP()->GetViewShells_Impl();
1230 rViewArr
.Remove( rViewArr
.GetPos(pThis
) );
1232 if ( pImp
->pController
)
1234 pImp
->pController
->ReleaseShell_Impl();
1235 pImp
->pController
->release();
1240 delete pImp
->pAccExec
;
1244 delete pIPClientList
;
1247 //--------------------------------------------------------------------
1249 USHORT
SfxViewShell::PrepareClose
1251 BOOL bUI
, // TRUE: Dialoge etc. erlaubt, FALSE: silent-mode
1252 BOOL
/*bForBrowsing*/
1255 SfxPrinter
*pPrinter
= GetPrinter();
1256 if ( pPrinter
&& pPrinter
->IsPrinting() )
1260 InfoBox
aInfoBox( &GetViewFrame()->GetWindow(), SfxResId( MSG_CANT_CLOSE
) );
1267 if( GetViewFrame()->IsInModalMode() )
1270 if( bUI
&& GetViewFrame()->GetDispatcher()->IsLocked() )
1276 //--------------------------------------------------------------------
1278 SfxViewShell
* SfxViewShell::Current()
1280 SfxViewFrame
*pCurrent
= SfxViewFrame::Current();
1281 return pCurrent
? pCurrent
->GetViewShell() : NULL
;
1284 //--------------------------------------------------------------------
1286 SdrView
* SfxViewShell::GetDrawView() const
1290 Diese virtuelle Methode mu\s von den Subklassen "uberladen werden, wenn
1291 der Property-Editor zur Verf"ugung stehen soll.
1293 Die Default-Implementierung liefert immer 0.
1300 //--------------------------------------------------------------------
1302 String
SfxViewShell::GetSelectionText
1304 BOOL
/*bCompleteWords*/ /* FALSE (default)
1305 Nur der tats"achlich selektierte Text wird
1309 Der selektierte Text wird soweit erweitert,
1310 da\s nur ganze W"orter zur"uckgegeben werden.
1311 Als Worttrenner gelten White-Spaces und die
1312 Satzzeichen ".,;" sowie einfache und doppelte
1319 Diese Methode kann von Anwendungsprogrammierer "uberladen werden,
1320 um einen Text zur"uckzuliefern, der in der aktuellen Selektion
1321 steht. Dieser wird z.B. beim Versenden (email) verwendet.
1323 Mit "CompleteWords == TRUE" ger"ufen, reicht z.B. auch der Cursor,
1324 der in einer URL steht, um die gesamte URL zu liefern.
1331 //--------------------------------------------------------------------
1333 BOOL
SfxViewShell::HasSelection( BOOL
) const
1337 Mit dieser virtuellen Methode kann z.B. ein Dialog abfragen, ob in der
1338 aktuellen View etwas selektiert ist. Wenn der Parameter <BOOL> TRUE ist,
1339 wird abgefragt, ob Text selektiert ist.
1346 //--------------------------------------------------------------------
1348 void SfxViewShell::SetSubShell( SfxShell
*pShell
)
1352 Mit dieser Methode kann eine Selektions- oder Cursor-Shell angemeldet
1353 werden, die automatisch unmittelbar nach der SfxViewShell auf den
1354 SfxDispatcher gepusht wird, und automatisch umittelbar vor ihr
1357 Ist die SfxViewShell-Instanz bereits gepusht, dann wird pShell
1358 sofort ebenfalls gepusht. Wird mit SetSubShell eine andere SfxShell
1359 Instanz angemeldet, als vorher angemeldet war, wird die zuvor angemeldete
1360 ggf. automatisch gepoppt. Mit pShell==0 kann daher die aktuelle
1361 Sub-Shell abgemeldet werden.
1365 // ist diese ViewShell "uberhaupt aktiv?
1366 SfxDispatcher
*pDisp
= pFrame
->GetDispatcher();
1367 if ( pDisp
->IsActive(*this) )
1369 // Dispatcher updaten
1371 pDisp
->Pop(*pSubShell
);
1373 pDisp
->Push(*pShell
);
1380 void SfxViewShell::AddSubShell( SfxShell
& rShell
)
1382 pImp
->aArr
.Insert( &rShell
, pImp
->aArr
.Count() );
1383 SfxDispatcher
*pDisp
= pFrame
->GetDispatcher();
1384 if ( pDisp
->IsActive(*this) )
1386 pDisp
->Push(rShell
);
1391 void SfxViewShell::RemoveSubShell( SfxShell
* pShell
)
1393 SfxDispatcher
*pDisp
= pFrame
->GetDispatcher();
1396 USHORT nCount
= pImp
->aArr
.Count();
1397 if ( pDisp
->IsActive(*this) )
1399 for ( USHORT n
=nCount
; n
>0; n
-- )
1400 pDisp
->Pop( *pImp
->aArr
[n
-1] );
1404 pImp
->aArr
.Remove(0, nCount
);
1408 USHORT nPos
= pImp
->aArr
.GetPos( pShell
);
1409 if ( nPos
!= 0xFFFF )
1411 pImp
->aArr
.Remove( nPos
);
1412 if ( pDisp
->IsActive(*this) )
1414 pDisp
->RemoveShell_Impl( *pShell
);
1421 SfxShell
* SfxViewShell::GetSubShell( USHORT nNo
)
1423 USHORT nCount
= pImp
->aArr
.Count();
1425 return pImp
->aArr
[nCount
-nNo
-1];
1429 void SfxViewShell::PushSubShells_Impl( BOOL bPush
)
1431 USHORT nCount
= pImp
->aArr
.Count();
1432 SfxDispatcher
*pDisp
= pFrame
->GetDispatcher();
1435 for ( USHORT n
=0; n
<nCount
; n
++ )
1436 pDisp
->Push( *pImp
->aArr
[n
] );
1438 // HACK(evtl. PushSubShells fuer SW virtuell machen oder im SW umbauen)
1439 // Notify( *this, SfxSimpleHint( SFX_HINT_RESERVED4 ) );
1443 pDisp
->Pop( *pImp
->aArr
[0], SFX_SHELL_POP_UNTIL
);
1445 // HACK(evtl. PushSubShells fuer SW virtuell machen oder im SW umbauen)
1446 // Notify( *this, SfxSimpleHint( SFX_HINT_RESERVED3 ) );
1452 //--------------------------------------------------------------------
1454 void SfxViewShell::WriteUserData( String
&, BOOL
)
1458 //--------------------------------------------------------------------
1460 void SfxViewShell::ReadUserData(const String
&, BOOL
)
1464 void SfxViewShell::ReadUserDataSequence ( const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>&, sal_Bool
)
1467 void SfxViewShell::WriteUserDataSequence ( ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>&, sal_Bool
)
1472 //--------------------------------------------------------------------
1473 // returns the first shell of spec. type viewing the specified doc.
1475 SfxViewShell
* SfxViewShell::GetFirst
1477 const TypeId
* pType
,
1481 // search for a SfxViewShell of the specified type
1482 SfxViewShellArr_Impl
&rShells
= SFX_APP()->GetViewShells_Impl();
1483 SfxViewFrameArr_Impl
&rFrames
= SFX_APP()->GetViewFrames_Impl();
1484 for ( USHORT nPos
= 0; nPos
< rShells
.Count(); ++nPos
)
1486 SfxViewShell
*pShell
= rShells
.GetObject(nPos
);
1489 // sometimes dangling SfxViewShells exist that point to a dead SfxViewFrame
1490 // these ViewShells shouldn't be accessible anymore
1491 // a destroyed ViewFrame is not in the ViewFrame array anymore, so checking this array helps
1492 for ( sal_uInt16 n
=0; n
<rFrames
.Count(); ++n
)
1494 SfxViewFrame
*pFrame
= rFrames
.GetObject(n
);
1495 if ( pFrame
== pShell
->GetViewFrame() )
1497 // only ViewShells with a valid ViewFrame will be returned
1498 if ( ( !bOnlyVisible
|| pFrame
->IsVisible_Impl() ) && ( !pType
|| pShell
->IsA(*pType
) ) )
1509 //--------------------------------------------------------------------
1510 // returns the next shell of spec. type viewing the specified doc.
1512 SfxViewShell
* SfxViewShell::GetNext
1514 const SfxViewShell
& rPrev
,
1515 const TypeId
* pType
,
1519 SfxViewShellArr_Impl
&rShells
= SFX_APP()->GetViewShells_Impl();
1520 SfxViewFrameArr_Impl
&rFrames
= SFX_APP()->GetViewFrames_Impl();
1522 for ( nPos
= 0; nPos
< rShells
.Count(); ++nPos
)
1523 if ( rShells
.GetObject(nPos
) == &rPrev
)
1526 for ( ++nPos
; nPos
< rShells
.Count(); ++nPos
)
1528 SfxViewShell
*pShell
= rShells
.GetObject(nPos
);
1531 // sometimes dangling SfxViewShells exist that point to a dead SfxViewFrame
1532 // these ViewShells shouldn't be accessible anymore
1533 // a destroyed ViewFrame is not in the ViewFrame array anymore, so checking this array helps
1534 for ( sal_uInt16 n
=0; n
<rFrames
.Count(); ++n
)
1536 SfxViewFrame
*pFrame
= rFrames
.GetObject(n
);
1537 if ( pFrame
== pShell
->GetViewFrame() )
1539 // only ViewShells with a valid ViewFrame will be returned
1540 if ( ( !bOnlyVisible
|| pFrame
->IsVisible_Impl() ) && ( !pType
|| pShell
->IsA(*pType
) ) )
1551 //--------------------------------------------------------------------
1553 void SfxViewShell::Notify( SfxBroadcaster
& rBC
,
1554 const SfxHint
& rHint
)
1556 if ( rHint
.IsA(TYPE(SfxEventHint
)) )
1558 switch ( ((SfxEventHint
&)rHint
).GetEventId() )
1560 case SFX_EVENT_LOADFINISHED
:
1562 if ( GetController().is() )
1564 // avoid access to dangling ViewShells
1565 SfxViewFrameArr_Impl
&rFrames
= SFX_APP()->GetViewFrames_Impl();
1566 for ( sal_uInt16 n
=0; n
<rFrames
.Count(); ++n
)
1568 SfxViewFrame
*frame
= rFrames
.GetObject(n
);
1569 if ( frame
== GetViewFrame() && &rBC
== GetObjectShell() )
1571 SfxItemSet
* pSet
= GetObjectShell()->GetMedium()->GetItemSet();
1572 SFX_ITEMSET_ARG( pSet
, pItem
, SfxUnoAnyItem
, SID_VIEW_DATA
, sal_False
);
1575 pImp
->pController
->restoreViewData( pItem
->GetValue() );
1576 pSet
->ClearItem( SID_VIEW_DATA
);
1590 //--------------------------------------------------------------------
1592 BOOL
SfxViewShell::ExecKey_Impl(const KeyEvent
& aKey
)
1594 if (!pImp
->pAccExec
)
1596 pImp
->pAccExec
= ::svt::AcceleratorExecute::createAcceleratorHelper();
1597 pImp
->pAccExec
->init(::comphelper::getProcessServiceFactory(), pFrame
->GetFrame()->GetFrameInterface());
1600 return pImp
->pAccExec
->execute(aKey
.GetKeyCode());
1603 //--------------------------------------------------------------------
1605 FASTBOOL
SfxViewShell::KeyInput( const KeyEvent
&rKeyEvent
)
1609 Diese Methode f"uhrt das KeyEvent 'rKeyEvent' "uber die an dieser
1610 SfxViewShell direkt oder indirekt (z.B. via Applikation) konfigurierten
1611 Tasten (Accelerator) aus.
1617 die Taste ist konfiguriert, der betreffende
1618 Handler wurde gerufen
1621 die Taste ist nicht konfiguriert, es konnte
1622 also kein Handler gerufen werden
1626 <SfxApplication::KeyInput(const KeyEvent&)>
1629 return ExecKey_Impl(rKeyEvent
);
1632 FASTBOOL
SfxViewShell::GlobalKeyInput_Impl( const KeyEvent
&rKeyEvent
)
1634 return ExecKey_Impl(rKeyEvent
);
1637 //--------------------------------------------------------------------
1639 void SfxViewShell::ShowCursor( FASTBOOL
/*bOn*/ )
1643 Diese Methode mu\s von Subklassen "uberladen werden, damit vom SFx
1644 aus der Cursor ein- und ausgeschaltet werden kann. Dies geschieht
1645 z.B. bei laufendem <SfxProgress>.
1651 //--------------------------------------------------------------------
1653 void SfxViewShell::GotFocus() const
1657 Diese Methode mu\s vom Applikationsentwickler gerufen werden, wenn
1658 das Edit-Window den Focus erhalten hat. Der SFx hat so z.B. die
1659 M"oglichkeit, den Accelerator einzuschalten.
1664 <StarView> liefert leider keine M"oglichkeit, solche Events
1665 'von der Seite' einzuh"angen.
1671 //--------------------------------------------------------------------
1672 void SfxViewShell::ResetAllClients_Impl( SfxInPlaceClient
*pIP
)
1675 SfxInPlaceClientList
*pClients
= GetIPClientList_Impl(FALSE
);
1679 for ( USHORT n
=0; n
< pClients
->Count(); n
++ )
1681 SfxInPlaceClient
* pIPClient
= pClients
->GetObject(n
);
1682 if( pIPClient
!= pIP
)
1683 pIPClient
->ResetObject();
1687 //--------------------------------------------------------------------
1689 void SfxViewShell::DisconnectAllClients()
1691 SfxInPlaceClientList
*pClients
= GetIPClientList_Impl(FALSE
);
1695 for ( USHORT n
=0; n
<pClients
->Count(); )
1696 // clients will remove themselves from the list
1697 delete pClients
->GetObject(n
);
1700 //--------------------------------------------------------------------
1702 BOOL
SfxViewShell::UseObjectSize() const
1704 return pImp
->bUseObjectSize
;
1707 //--------------------------------------------------------------------
1709 void SfxViewShell::QueryObjAreaPixel( Rectangle
& ) const
1713 //--------------------------------------------------------------------
1715 void SfxViewShell::AdjustVisArea(const Rectangle
& rRect
)
1717 DBG_ASSERT (pFrame
, "Kein Frame?");
1718 if ( UseObjectSize() )
1720 Point aPos
= rRect
.TopLeft();
1721 Size aSize
= GetObjectShell()->GetVisArea().GetSize();
1722 GetObjectShell()->SetVisArea( Rectangle(aPos
, aSize
) );
1725 GetObjectShell()->SetVisArea( rRect
);
1728 //--------------------------------------------------------------------
1730 void SfxViewShell::VisAreaChanged(const Rectangle
& /*rVisArea*/)
1732 SfxInPlaceClientList
*pClients
= GetIPClientList_Impl(FALSE
);
1736 for (USHORT n
=0; n
< pClients
->Count(); n
++)
1738 SfxInPlaceClient
* pIPClient
= pClients
->GetObject(n
);
1739 if ( pIPClient
->IsObjectInPlaceActive() )
1740 // client is active, notify client that the VisArea might have changed
1741 pIPClient
->VisAreaChanged();
1745 //--------------------------------------------------------------------
1746 void SfxViewShell::CheckIPClient_Impl( SfxInPlaceClient
*pIPClient
, const Rectangle
& rVisArea
)
1748 if ( GetObjectShell()->IsInClose() )
1751 sal_Bool bAlwaysActive
=
1752 ( ( pIPClient
->GetObjectMiscStatus() & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY
) != 0 );
1753 sal_Bool bActiveWhenVisible
=
1754 ( ( pIPClient
->GetObjectMiscStatus() & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE
) != 0 );
1756 // this method is called when either a client is created or the "Edit/Plugins" checkbox is checked
1757 if ( !pIPClient
->IsObjectInPlaceActive() && pImp
->bPlugInsActive
)
1759 // object in client is currently not active
1760 // check if the object wants to be activated always or when it becomes at least partially visible
1761 // TODO/LATER: maybe we should use the scaled area instead of the ObjArea?!
1762 if ( bAlwaysActive
|| (bActiveWhenVisible
&& rVisArea
.IsOver(pIPClient
->GetObjArea())) )
1766 pIPClient
->GetObject()->changeState( embed::EmbedStates::INPLACE_ACTIVE
);
1768 catch ( uno::Exception
& )
1773 else if ( !pImp
->bPlugInsActive
)
1775 // object in client is currently active and "Edit/Plugins" checkbox is selected
1776 // check if the object wants to be activated always or when it becomes at least partially visible
1777 // in this case selecting of the "Edit/Plugin" checkbox should let such objects deactivate
1778 if ( bAlwaysActive
|| bActiveWhenVisible
)
1779 pIPClient
->GetObject()->changeState( embed::EmbedStates::RUNNING
);
1783 //--------------------------------------------------------------------
1785 BOOL
SfxViewShell::PlugInsActive() const
1787 return pImp
->bPlugInsActive
;
1790 //--------------------------------------------------------------------
1791 void SfxViewShell::DiscardClients_Impl()
1795 Diese Methode dient dazu, vor dem Schlie\sen eines Dokuments das
1796 Speichern der Objekte zu verhindern, wenn der Benutzer Schlie\en ohne
1797 Speichern gew"ahlt hatte.
1801 SfxInPlaceClientList
*pClients
= GetIPClientList_Impl(FALSE
);
1805 for (USHORT n
=0; n
< pClients
->Count(); )
1806 delete pClients
->GetObject(n
);
1809 //--------------------------------------------------------------------
1811 SfxScrollingMode
SfxViewShell::GetScrollingMode() const
1813 return pImp
->eScroll
;
1816 //--------------------------------------------------------------------
1818 void SfxViewShell::SetScrollingMode( SfxScrollingMode eMode
)
1820 pImp
->eScroll
= eMode
;
1823 //--------------------------------------------------------------------
1825 SfxObjectShell
* SfxViewShell::GetObjectShell()
1827 return pFrame
? pFrame
->GetObjectShell() : NULL
;
1830 //--------------------------------------------------------------------
1832 Reference
< XModel
> SfxViewShell::GetCurrentDocument() const
1834 Reference
< XModel
> xDocument
;
1836 const SfxObjectShell
* pDocShell( const_cast< SfxViewShell
* >( this )->GetObjectShell() );
1837 OSL_ENSURE( pDocShell
, "SfxViewFrame::GetCurrentDocument: no DocShell!?" );
1839 xDocument
= pDocShell
->GetModel();
1843 //--------------------------------------------------------------------
1845 void SfxViewShell::SetCurrentDocument() const
1847 uno::Reference
< frame::XModel
> xDocument( GetCurrentDocument() );
1848 if ( xDocument
.is() )
1849 SfxObjectShell::SetCurrentComponent( xDocument
);
1852 //--------------------------------------------------------------------
1854 const Size
& SfxViewShell::GetMargin() const
1856 return pImp
->aMargin
;
1859 //--------------------------------------------------------------------
1861 void SfxViewShell::SetMargin( const Size
& rSize
)
1863 // Der default-Margin wurde "geeicht" mit www.apple.com !!
1864 Size aMargin
= rSize
;
1865 if ( aMargin
.Width() == -1 )
1866 aMargin
.Width() = DEFAULT_MARGIN_WIDTH
;
1867 if ( aMargin
.Height() == -1 )
1868 aMargin
.Height() = DEFAULT_MARGIN_HEIGHT
;
1870 if ( aMargin
!= pImp
->aMargin
)
1872 pImp
->aMargin
= aMargin
;
1877 //--------------------------------------------------------------------
1879 void SfxViewShell::MarginChanged()
1883 //--------------------------------------------------------------------
1885 BOOL
SfxViewShell::IsShowView_Impl() const
1887 return pImp
->bIsShowView
;
1890 //--------------------------------------------------------------------
1892 SfxFrame
* SfxViewShell::GetSmartSelf( SfxFrame
* pSelf
, SfxMedium
& /*rMedium*/ )
1897 //--------------------------------------------------------------------
1899 BOOL
SfxViewShell::IsImplementedAsFrameset_Impl( ) const
1901 return pImp
->bFrameSetImpl
;
1904 //------------------------------------------------------------------------
1906 void SfxViewShell::JumpToMark( const String
& rMark
)
1908 SfxStringItem
aMarkItem( SID_JUMPTOMARK
, rMark
);
1909 GetViewFrame()->GetDispatcher()->Execute(
1911 SFX_CALLMODE_SYNCHRON
|SFX_CALLMODE_RECORD
,
1915 //------------------------------------------------------------------------
1917 SfxInPlaceClientList
* SfxViewShell::GetIPClientList_Impl( BOOL bCreate
) const
1919 if ( !pIPClientList
&& bCreate
)
1920 ( (SfxViewShell
*) this )->pIPClientList
= new SfxInPlaceClientList
;
1921 return pIPClientList
;
1924 void SfxViewShell::SetController( SfxBaseController
* pController
)
1926 pImp
->pController
= pController
;
1927 pImp
->pController
->acquire();
1928 pImp
->bControllerSet
= TRUE
;
1931 Reference
< XController
> SfxViewShell::GetController()
1933 return pImp
->pController
;
1936 void SfxViewShell::AddContextMenuInterceptor_Impl( const REFERENCE
< XCONTEXTMENUINTERCEPTOR
>& xInterceptor
)
1938 pImp
->aInterceptorContainer
.addInterface( xInterceptor
);
1941 void SfxViewShell::RemoveContextMenuInterceptor_Impl( const REFERENCE
< XCONTEXTMENUINTERCEPTOR
>& xInterceptor
)
1943 pImp
->aInterceptorContainer
.removeInterface( xInterceptor
);
1946 ::cppu::OInterfaceContainerHelper
& SfxViewShell::GetContextMenuInterceptors() const
1948 return pImp
->aInterceptorContainer
;
1951 void Change( Menu
* pMenu
, SfxViewShell
* pView
)
1953 SfxDispatcher
*pDisp
= pView
->GetViewFrame()->GetDispatcher();
1954 USHORT nCount
= pMenu
->GetItemCount();
1955 for ( USHORT nPos
=0; nPos
<nCount
; ++nPos
)
1957 USHORT nId
= pMenu
->GetItemId(nPos
);
1958 String aCmd
= pMenu
->GetItemCommand(nId
);
1959 PopupMenu
* pPopup
= pMenu
->GetPopupMenu(nId
);
1962 Change( pPopup
, pView
);
1964 else if ( nId
< 5000 )
1966 if ( aCmd
.CompareToAscii(".uno:", 5) == 0 )
1968 for (USHORT nIdx
=0;;)
1970 SfxShell
*pShell
=pDisp
->GetShell(nIdx
++);
1973 const SfxInterface
*pIFace
= pShell
->GetInterface();
1974 const SfxSlot
* pSlot
= pIFace
->GetSlot( aCmd
);
1977 pMenu
->InsertItem( pSlot
->GetSlotId(), pMenu
->GetItemText( nId
), pMenu
->GetItemBits( nId
), nPos
);
1978 pMenu
->RemoveItem( nPos
+1 );
1988 BOOL
SfxViewShell::TryContextMenuInterception( Menu
& rIn
, const ::rtl::OUString
& rMenuIdentifier
, Menu
*& rpOut
, ::com::sun::star::ui::ContextMenuExecuteEvent aEvent
)
1991 BOOL bModified
= FALSE
;
1993 // create container from menu
1995 // aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu( &rIn );
1996 aEvent
.ActionTriggerContainer
= ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu(
1997 ::comphelper::getProcessServiceFactory(), &rIn
, &rMenuIdentifier
);
1999 // get selection from controller
2000 aEvent
.Selection
= ::com::sun::star::uno::Reference
< ::com::sun::star::view::XSelectionSupplier
> ( GetController(), ::com::sun::star::uno::UNO_QUERY
);
2002 // call interceptors
2003 ::cppu::OInterfaceIteratorHelper
aIt( pImp
->aInterceptorContainer
);
2004 while( aIt
.hasMoreElements() )
2008 ::com::sun::star::ui::ContextMenuInterceptorAction eAction
=
2009 ((::com::sun::star::ui::XContextMenuInterceptor
*)aIt
.next())->notifyContextMenuExecute( aEvent
);
2012 case ::com::sun::star::ui::ContextMenuInterceptorAction_CANCELLED
:
2013 // interceptor does not want execution
2015 case ::com::sun::star::ui::ContextMenuInterceptorAction_EXECUTE_MODIFIED
:
2016 // interceptor wants his modified menu to be executed
2019 case ::com::sun::star::ui::ContextMenuInterceptorAction_CONTINUE_MODIFIED
:
2020 // interceptor has modified menu, but allows for calling other interceptors
2023 case ::com::sun::star::ui::ContextMenuInterceptorAction_IGNORED
:
2024 // interceptor is indifferent
2027 DBG_ERROR("Wrong return value of ContextMenuInterceptor!");
2031 catch( ::com::sun::star::uno::RuntimeException
& )
2041 // container was modified, create a new window out of it
2042 rpOut
= new PopupMenu
;
2043 ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer( rpOut
, aEvent
.ActionTriggerContainer
);
2045 Change( rpOut
, this );
2051 void SfxViewShell::TakeOwnerShip_Impl()
2053 // currently there is only one reason to take OwnerShip: a hidden frame is printed
2054 // so the ViewShell will check this on EndPrint (->prnmon.cxx)
2055 pImp
->bGotOwnerShip
= TRUE
;
2058 void SfxViewShell::TakeFrameOwnerShip_Impl()
2060 // currently there is only one reason to take OwnerShip: a hidden frame is printed
2061 // so the ViewShell will check this on EndPrint (->prnmon.cxx)
2062 pImp
->bGotFrameOwnerShip
= TRUE
;
2065 void SfxViewShell::CheckOwnerShip_Impl()
2067 BOOL bSuccess
= FALSE
;
2068 if( pImp
->bGotOwnerShip
)
2070 com::sun::star::uno::Reference
< com::sun::star::util::XCloseable
> xModel(
2071 GetObjectShell()->GetModel(), com::sun::star::uno::UNO_QUERY
);
2076 // this call will destroy this object in case of success!
2077 xModel
->close( sal_True
);
2080 catch ( com::sun::star::util::CloseVetoException
& )
2086 if( !bSuccess
&& pImp
->bGotFrameOwnerShip
)
2088 // document couldn't be closed or it shouldn't, now try at least to close the frame
2089 com::sun::star::uno::Reference
< com::sun::star::util::XCloseable
> xFrame(
2090 GetViewFrame()->GetFrame()->GetFrameInterface(), com::sun::star::uno::UNO_QUERY
);
2095 xFrame
->close( sal_True
);
2097 catch ( com::sun::star::util::CloseVetoException
& )
2104 long SfxViewShell::HandleNotifyEvent_Impl( NotifyEvent
& rEvent
)
2106 if ( pImp
->pController
)
2107 return pImp
->pController
->HandleEvent_Impl( rEvent
);
2111 BOOL
SfxViewShell::HasKeyListeners_Impl()
2113 return pImp
->pController
? pImp
->pController
->HasKeyListeners_Impl() : FALSE
;
2116 BOOL
SfxViewShell::HasMouseClickListeners_Impl()
2118 return pImp
->pController
? pImp
->pController
->HasMouseClickListeners_Impl() : FALSE
;
2121 void SfxViewShell::SetAdditionalPrintOptions( const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>& rOpts
)
2123 pImp
->aPrintOpts
= rOpts
;
2124 GetObjectShell()->Broadcast( SfxPrintingHint( -3, NULL
, NULL
, rOpts
) );
2127 BOOL
SfxViewShell::Escape()
2129 return GetViewFrame()->GetBindings().Execute( SID_TERMINATE_INPLACEACTIVATION
);