diff options
author | obo <obo@openoffice.org> | 2010-06-18 12:27:33 +0200 |
---|---|---|
committer | obo <obo@openoffice.org> | 2010-06-18 12:27:33 +0200 |
commit | 9827d16734c9e1984a0fd7aab43209df07d992ff (patch) | |
tree | 43d59d83a98a0c3cc26815704edd5688372af295 /sfx2 | |
parent | b71f8795d5e9e2e3ec4810d50b4cd7d43d682852 (diff) | |
parent | 3d2a51111ac8e45f6eae9d1fd9e52ee8c4cb35d0 (diff) |
CWS-TOOLING: integrate CWS tl78v3
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/sfx2/objsh.hxx | 4 | ||||
-rw-r--r-- | sfx2/inc/sfx2/sfxsids.hrc | 2 | ||||
-rw-r--r-- | sfx2/sdi/sfx.sdi | 29 | ||||
-rwxr-xr-x | sfx2/source/appl/appuno.cxx | 17 | ||||
-rw-r--r-- | sfx2/source/dialog/filedlghelper.cxx | 5797 | ||||
-rw-r--r-- | sfx2/source/doc/objcont.cxx | 36 | ||||
-rwxr-xr-x | sfx2/source/doc/objmisc.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 20 | ||||
-rw-r--r-- | sfx2/source/inc/objshimp.hxx | 2 | ||||
-rw-r--r-- | sfx2/source/view/viewfrm.cxx | 7012 |
10 files changed, 6484 insertions, 6437 deletions
diff --git a/sfx2/inc/sfx2/objsh.hxx b/sfx2/inc/sfx2/objsh.hxx index 95e8f21c8d86..6d2b6611991e 100644 --- a/sfx2/inc/sfx2/objsh.hxx +++ b/sfx2/inc/sfx2/objsh.hxx @@ -439,9 +439,13 @@ public: void SetSaveVersionOnClose( sal_Bool bSet ); void ResetFromTemplate( const String& rTemplateName, const String& rFileName ); + // TODO/LATER: the following two methods should be replaced by Get/SetModifPasswordInfo in future sal_uInt32 GetModifyPasswordHash() const; sal_Bool SetModifyPasswordHash( sal_uInt32 nHash ); + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > GetModifyPasswordInfo() const; + sal_Bool SetModifyPasswordInfo( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aInfo ); + static sal_uInt32 HandleFilter( SfxMedium* pMedium, SfxObjectShell* pDoc ); virtual void ViewAssigned(); diff --git a/sfx2/inc/sfx2/sfxsids.hrc b/sfx2/inc/sfx2/sfxsids.hrc index 109a60207894..b5782b5d4f19 100644 --- a/sfx2/inc/sfx2/sfxsids.hrc +++ b/sfx2/inc/sfx2/sfxsids.hrc @@ -306,7 +306,7 @@ #define SID_ACTIVATE_STYLE_APPLY (SID_SFX_START + 1715) #define SID_FONT_NAME (SID_SFX_START + 1716) #define SID_DEFAULTFILENAME (SID_SFX_START + 1717) -#define SID_MODIFYPASSWORDHASH (SID_SFX_START + 1718) +#define SID_MODIFYPASSWORDINFO (SID_SFX_START + 1718) #define SID_RECOMMENDREADONLY (SID_SFX_START + 1719) #define SID_SFX_free_START (SID_SFX_START + 1720) #define SID_SFX_free_END (SID_SFX_START + 3999) diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi index 967c5ad7dd18..8ca8645a05ff 100644 --- a/sfx2/sdi/sfx.sdi +++ b/sfx2/sdi/sfx.sdi @@ -3594,33 +3594,6 @@ SfxVoidItem MacroOrganizer SID_MACROORGANIZER ] //-------------------------------------------------------------------------- -SfxInt32Item PasswordToModifyHash SID_MODIFYPASSWORDHASH - -[ - /* flags: */ - AutoUpdate = FALSE, - Cachable = Cachable, - FastCall = FALSE, - HasCoreId = FALSE, - HasDialog = FALSE, - ReadOnlyDoc = TRUE, - Toggle = FALSE, - Container = TRUE, - RecordAbsolute = FALSE, - RecordPerSet; - Synchron; - - Readonly = TRUE, - - /* config: */ - AccelConfig = FALSE, - MenuConfig = FALSE, - StatusBarConfig = FALSE, - ToolBoxConfig = FALSE, - GroupId = ; -] - -//-------------------------------------------------------------------------- SfxBoolItem ReccomendReadonly SID_RECOMMENDREADONLY [ @@ -5344,7 +5317,7 @@ SfxBoolItem SaveAll SID_SAVEDOCS //-------------------------------------------------------------------------- SfxBoolItem SaveAs SID_SAVEASDOC -(SfxStringItem URL SID_FILE_NAME,SfxStringItem FilterName SID_FILTER_NAME,SfxStringItem Password SID_PASSWORD,SfxStringItem FilterOptions SID_FILE_FILTEROPTIONS,SfxStringItem VersionComment SID_DOCINFO_COMMENTS,SfxStringItem VersionAuthor SID_DOCINFO_AUTHOR,SfxBoolItem Overwrite SID_OVERWRITE,SfxBoolItem Unpacked SID_UNPACK,SfxBoolItem SaveTo SID_SAVETO,SfxInt32Item ModifyPasswordHash SID_MODIFYPASSWORDHASH) +(SfxStringItem URL SID_FILE_NAME,SfxStringItem FilterName SID_FILTER_NAME,SfxStringItem Password SID_PASSWORD,SfxStringItem FilterOptions SID_FILE_FILTEROPTIONS,SfxStringItem VersionComment SID_DOCINFO_COMMENTS,SfxStringItem VersionAuthor SID_DOCINFO_AUTHOR,SfxBoolItem Overwrite SID_OVERWRITE,SfxBoolItem Unpacked SID_UNPACK,SfxBoolItem SaveTo SID_SAVETO) [ /* flags: */ AutoUpdate = FALSE, diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index 66452f10bbfb..6f9d3b258745 100755 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -191,6 +191,7 @@ static char const sFolderName[] = "FolderName"; static char const sUseSystemDialog[] = "UseSystemDialog"; static char const sStandardDir[] = "StandardDir"; static char const sBlackList[] = "BlackList"; +static char const sModifyPasswordInfo[] = "ModifyPasswordInfo"; void TransformParameters( sal_uInt16 nSlotId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rArgs, SfxAllItemSet& rSet, const SfxSlot* pSlot ) { @@ -846,6 +847,10 @@ void TransformParameters( sal_uInt16 nSlotId, const ::com::sun::star::uno::Seque if (bOK) rSet.Put( SfxBoolItem( SID_NOAUTOSAVE, bVal ) ); } + else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sModifyPasswordInfo)) ) + { + rSet.Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, rProp.Value ) ); + } #ifdef DBG_UTIL else --nFoundArgs; @@ -1058,6 +1063,8 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, ::com::sun::sta nAdditional++; if ( rSet.GetItemState( SID_NOAUTOSAVE ) == SFX_ITEM_SET ) nAdditional++; + if ( rSet.GetItemState( SID_MODIFYPASSWORDINFO ) == SFX_ITEM_SET ) + nAdditional++; // consider additional arguments nProps += nAdditional; @@ -1197,7 +1204,9 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, ::com::sun::sta // used only internally if ( nId == SID_SAVETO ) continue; - } + if ( nId == SID_MODIFYPASSWORDINFO ) + continue; + } ByteString aDbg( "Unknown item detected: "); aDbg += ByteString::CreateFromInt32( nId ); @@ -1555,7 +1564,11 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, ::com::sun::sta pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sNoAutoSave)); pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() ); } - + if ( rSet.GetItemState( SID_MODIFYPASSWORDINFO, sal_False, &pItem ) == SFX_ITEM_SET ) + { + pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sModifyPasswordInfo)); + pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() ); + } } } diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index 545e77e56c91..b0890a3ee781 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -1,2893 +1,2904 @@ -/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_sfx2.hxx"
-#include <sfx2/filedlghelper.hxx>
-#include <sal/types.h>
-#include <com/sun/star/lang/XInitialization.hpp>
-#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
-#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
-#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
-#include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
-#include <com/sun/star/ui/dialogs/ControlActions.hpp>
-#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
-#include <com/sun/star/ui/dialogs/XControlInformation.hpp>
-#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
-#include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
-#include <com/sun/star/ui/dialogs/XFilePreview.hpp>
-#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
-#include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
-#include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
-#include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
-#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
-#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <com/sun/star/beans/XPropertySet.hpp>
-#include <com/sun/star/beans/NamedValue.hpp>
-#include <com/sun/star/embed/ElementModes.hpp>
-#include <com/sun/star/container/XEnumeration.hpp>
-#include <com/sun/star/container/XContainerQuery.hpp>
-#include <com/sun/star/task/XInteractionRequest.hpp>
-#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
-
-#include <comphelper/processfactory.hxx>
-#include <comphelper/types.hxx>
-#include <comphelper/sequenceashashmap.hxx>
-#include <comphelper/stillreadwriteinteraction.hxx>
-#include <tools/urlobj.hxx>
-#include <vcl/help.hxx>
-#include <unotools/ucbstreamhelper.hxx>
-#include <unotools/ucbhelper.hxx>
-#include <unotools/localfilehelper.hxx>
-#include <vos/thread.hxx>
-#include <vos/mutex.hxx>
-#include <vos/security.hxx>
-#include <vcl/cvtgrf.hxx>
-#include <vcl/msgbox.hxx>
-#include <vcl/mnemonic.hxx>
-#include <unotools/pathoptions.hxx>
-#include <unotools/securityoptions.hxx>
-#include <svl/itemset.hxx>
-#include <svl/eitem.hxx>
-#include <svl/intitem.hxx>
-#include <svl/stritem.hxx>
-#include <svtools/filter.hxx>
-#include <unotools/viewoptions.hxx>
-#include <unotools/moduleoptions.hxx>
-#include <svtools/helpid.hrc>
-#include <svl/pickerhelper.hxx>
-#include <comphelper/docpasswordrequest.hxx>
-#include <ucbhelper/content.hxx>
-#include <ucbhelper/commandenvironment.hxx>
-#include <comphelper/storagehelper.hxx>
-#include <toolkit/helper/vclunohelper.hxx>
-#include <sfx2/app.hxx>
-#include <sfx2/docfile.hxx>
-#include <sfx2/docfac.hxx>
-#include "openflag.hxx"
-#include <sfx2/passwd.hxx>
-#include "sfxresid.hxx"
-#include <sfx2/sfxsids.hrc>
-#include "filedlghelper.hrc"
-#include "filtergrouping.hxx"
-#include <sfx2/request.hxx>
-#include "filedlgimpl.hxx"
-
-#include <sfxlocal.hrc>
-
-//-----------------------------------------------------------------------------
-
-using namespace ::com::sun::star;
-using namespace ::com::sun::star::container;
-using namespace ::com::sun::star::lang;
-using namespace ::com::sun::star::ui::dialogs;
-using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::beans;
-using namespace ::rtl;
-using namespace ::cppu;
-
-//-----------------------------------------------------------------------------
-
-#define IODLG_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Save"))
-#define IMPGRF_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Graph"))
-#define USERITEM_NAME ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "UserItem" ))
-
-//-----------------------------------------------------------------------------
-
-namespace sfx2
-{
-
-const OUString* GetLastFilterConfigId( FileDialogHelper::Context _eContext )
-{
- static const OUString aSD_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SdExportLastFilter" ) );
- static const OUString aSI_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SiExportLastFilter" ) );
- static const OUString aSW_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SwExportLastFilter" ) );
-
- const OUString* pRet = NULL;
-
- switch( _eContext )
- {
- case FileDialogHelper::SD_EXPORT: pRet = &aSD_EXPORT_IDENTIFIER; break;
- case FileDialogHelper::SI_EXPORT: pRet = &aSI_EXPORT_IDENTIFIER; break;
- case FileDialogHelper::SW_EXPORT: pRet = &aSW_EXPORT_IDENTIFIER; break;
- default: break;
- }
-
- return pRet;
-}
-
-String EncodeSpaces_Impl( const String& rSource );
-String DecodeSpaces_Impl( const String& rSource );
-
-// ------------------------------------------------------------------------
-// ----------- FileDialogHelper_Impl ---------------------------
-// ------------------------------------------------------------------------
-
-// ------------------------------------------------------------------------
-// XFilePickerListener Methods
-// ------------------------------------------------------------------------
-void SAL_CALL FileDialogHelper_Impl::fileSelectionChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
-{
- ::vos::OGuard aGuard( Application::GetSolarMutex() );
- mpAntiImpl->FileSelectionChanged( aEvent );
-}
-
-// ------------------------------------------------------------------------
-void SAL_CALL FileDialogHelper_Impl::directoryChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
-{
- ::vos::OGuard aGuard( Application::GetSolarMutex() );
- mpAntiImpl->DirectoryChanged( aEvent );
-}
-
-// ------------------------------------------------------------------------
-OUString SAL_CALL FileDialogHelper_Impl::helpRequested( const FilePickerEvent& aEvent ) throw ( RuntimeException )
-{
- ::vos::OGuard aGuard( Application::GetSolarMutex() );
- return mpAntiImpl->HelpRequested( aEvent );
-}
-
-// ------------------------------------------------------------------------
-void SAL_CALL FileDialogHelper_Impl::controlStateChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
-{
- ::vos::OGuard aGuard( Application::GetSolarMutex() );
- mpAntiImpl->ControlStateChanged( aEvent );
-}
-
-// ------------------------------------------------------------------------
-void SAL_CALL FileDialogHelper_Impl::dialogSizeChanged() throw ( RuntimeException )
-{
- ::vos::OGuard aGuard( Application::GetSolarMutex() );
- mpAntiImpl->DialogSizeChanged();
-}
-
-// ------------------------------------------------------------------------
-// XDialogClosedListener Methods
-// ------------------------------------------------------------------------
-void SAL_CALL FileDialogHelper_Impl::dialogClosed( const DialogClosedEvent& _rEvent ) throw ( RuntimeException )
-{
- ::vos::OGuard aGuard( Application::GetSolarMutex() );
- mpAntiImpl->DialogClosed( _rEvent );
- postExecute( _rEvent.DialogResult );
-}
-
-// ------------------------------------------------------------------------
-// handle XFilePickerListener events
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::handleFileSelectionChanged( const FilePickerEvent& )
-{
- if ( mbHasVersions )
- updateVersions();
-
- if ( mbShowPreview )
- maPreViewTimer.Start();
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::handleDirectoryChanged( const FilePickerEvent& )
-{
- if ( mbShowPreview )
- TimeOutHdl_Impl( NULL );
-}
-
-// ------------------------------------------------------------------------
-OUString FileDialogHelper_Impl::handleHelpRequested( const FilePickerEvent& aEvent )
-{
- //!!! todo: cache the help strings (here or TRA)
-
- ULONG nHelpId = 0;
- // mapping from element id -> help id
- switch ( aEvent.ElementId )
- {
- case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION :
- nHelpId = HID_FILESAVE_AUTOEXTENSION;
- break;
-
- case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD :
- nHelpId = HID_FILESAVE_SAVEWITHPASSWORD;
- break;
-
- case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS :
- nHelpId = HID_FILESAVE_CUSTOMIZEFILTER;
- break;
-
- case ExtendedFilePickerElementIds::CHECKBOX_READONLY :
- nHelpId = HID_FILEOPEN_READONLY;
- break;
-
- case ExtendedFilePickerElementIds::CHECKBOX_LINK :
- nHelpId = HID_FILEDLG_LINK_CB;
- break;
-
- case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW :
- nHelpId = HID_FILEDLG_PREVIEW_CB;
- break;
-
- case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY :
- nHelpId = HID_FILESAVE_DOPLAY;
- break;
-
- case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL :
- case ExtendedFilePickerElementIds::LISTBOX_VERSION :
- nHelpId = HID_FILEOPEN_VERSION;
- break;
-
- case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL :
- case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE :
- nHelpId = HID_FILESAVE_TEMPLATE;
- break;
-
- case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL :
- case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE :
- nHelpId = HID_FILEOPEN_IMAGE_TEMPLATE;
- break;
-
- case ExtendedFilePickerElementIds::CHECKBOX_SELECTION :
- nHelpId = HID_FILESAVE_SELECTION;
- break;
-
- default:
- DBG_ERRORFILE( "invalid element id" );
- }
-
- OUString aHelpText;
- Help* pHelp = Application::GetHelp();
- if ( pHelp )
- aHelpText = String( pHelp->GetHelpText( nHelpId, NULL ) );
- return aHelpText;
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::handleControlStateChanged( const FilePickerEvent& aEvent )
-{
- switch ( aEvent.ElementId )
- {
- case CommonFilePickerElementIds::LISTBOX_FILTER:
- updateFilterOptionsBox();
- enablePasswordBox( sal_False );
- updateSelectionBox();
- // only use it for export and with our own dialog
- if ( mbExport && !mbSystemPicker )
- updateExportButton();
- break;
-
- case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
- updatePreviewState();
- break;
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::handleDialogSizeChanged()
-{
- if ( mbShowPreview )
- TimeOutHdl_Impl( NULL );
-}
-
-// ------------------------------------------------------------------------
-// XEventListener Methods
-// ------------------------------------------------------------------------
-void SAL_CALL FileDialogHelper_Impl::disposing( const EventObject& ) throw ( RuntimeException )
-{
- ::vos::OGuard aGuard( Application::GetSolarMutex() );
- dispose();
-}
-
-// ------------------------------------------------------------------------
-// ------------------------------------------------------------------------
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::dispose()
-{
- if ( mxFileDlg.is() )
- {
- // remove the event listener
- uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
- if ( xNotifier.is() )
- xNotifier->removeFilePickerListener( this );
-
- ::comphelper::disposeComponent( mxFileDlg );
- mxFileDlg.clear();
- }
-}
-
-// ------------------------------------------------------------------------
-String FileDialogHelper_Impl::getCurrentFilterUIName() const
-{
- String aFilterName;
- uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
-
- if( xFltMgr.is() )
- {
- aFilterName = xFltMgr->getCurrentFilter();
-
- if ( aFilterName.Len() && isShowFilterExtensionEnabled() )
- aFilterName = getFilterName( aFilterName );
- }
-
- return aFilterName;
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::LoadLastUsedFilter( const OUString& _rContextIdentifier )
-{
- SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
-
- if( aDlgOpt.Exists() )
- {
- OUString aLastFilter;
- if( aDlgOpt.GetUserItem( _rContextIdentifier ) >>= aLastFilter )
- setFilter( aLastFilter );
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::SaveLastUsedFilter( const OUString& _rContextIdentifier )
-{
- SvtViewOptions( E_DIALOG, IODLG_CONFIGNAME ).SetUserItem( _rContextIdentifier,
- makeAny( getFilterWithExtension( getFilter() ) ) );
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::SaveLastUsedFilter( void )
-{
- const OUString* pConfigId = GetLastFilterConfigId( meContext );
- if( pConfigId )
- SaveLastUsedFilter( *pConfigId );
-}
-
-// ------------------------------------------------------------------------
-const SfxFilter* FileDialogHelper_Impl::getCurentSfxFilter()
-{
- String aFilterName = getCurrentFilterUIName();
-
- const SfxFilter* pFilter = NULL;
- if ( mpMatcher && aFilterName.Len() )
- pFilter = mpMatcher->GetFilter4UIName( aFilterName, m_nMustFlags, m_nDontFlags );
-
- return pFilter;
-}
-
-// ------------------------------------------------------------------------
-sal_Bool FileDialogHelper_Impl::updateExtendedControl( sal_Int16 _nExtendedControlId, sal_Bool _bEnable )
-{
- sal_Bool bIsEnabled = sal_False;
-
- uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
- if ( xCtrlAccess.is() )
- {
- try
- {
- xCtrlAccess->enableControl( _nExtendedControlId, _bEnable );
- bIsEnabled = _bEnable;
- }
- catch( const IllegalArgumentException& )
- {
- DBG_ERROR( "FileDialogHelper_Impl::updateExtendedControl: caught an exception!" );
- }
- }
- return bIsEnabled;
-}
-
-// ------------------------------------------------------------------------
-sal_Bool FileDialogHelper_Impl::CheckFilterOptionsCapability( const SfxFilter* _pFilter )
-{
- sal_Bool bResult = sal_False;
-
- if( mxFilterCFG.is() && _pFilter )
- {
- try {
- Sequence < PropertyValue > aProps;
- Any aAny = mxFilterCFG->getByName( _pFilter->GetName() );
- if ( aAny >>= aProps )
- {
- ::rtl::OUString aServiceName;
- sal_Int32 nPropertyCount = aProps.getLength();
- for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
- {
- if( aProps[nProperty].Name.equals( DEFINE_CONST_OUSTRING( "UIComponent") ) )
- {
- aProps[nProperty].Value >>= aServiceName;
- if( aServiceName.getLength() )
- bResult = sal_True;
- }
- }
- }
- }
- catch( Exception& )
- {
- }
- }
-
- return bResult;
-}
-
-// ------------------------------------------------------------------------
-sal_Bool FileDialogHelper_Impl::isInOpenMode() const
-{
- sal_Bool bRet = sal_False;
-
- switch ( m_nDialogType )
- {
- case FILEOPEN_SIMPLE:
- case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
- case FILEOPEN_PLAY:
- case FILEOPEN_READONLY_VERSION:
- case FILEOPEN_LINK_PREVIEW:
- bRet = sal_True;
- }
-
- return bRet;
-}
-
-// ------------------------------------------------------------------------
-
-void FileDialogHelper_Impl::updateFilterOptionsBox()
-{
- if ( !m_bHaveFilterOptions )
- return;
-
- updateExtendedControl(
- ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS,
- CheckFilterOptionsCapability( getCurentSfxFilter() )
- );
-}
-
-// ------------------------------------------------------------------------
-
-void FileDialogHelper_Impl::updateExportButton()
-{
- uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
- if ( xCtrlAccess.is() )
- {
- OUString sEllipses( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
- OUString sOldLabel( xCtrlAccess->getLabel( CommonFilePickerElementIds::PUSHBUTTON_OK ) );
-
- // initialize button label; we need the label with the mnemonic char
- if ( !maButtonLabel.getLength() || maButtonLabel.indexOf( MNEMONIC_CHAR ) == -1 )
- {
- // cut the ellipses, if necessary
- sal_Int32 nIndex = sOldLabel.indexOf( sEllipses );
- if ( -1 == nIndex )
- nIndex = sOldLabel.getLength();
- maButtonLabel = sOldLabel.copy( 0, nIndex );
- }
-
- OUString sLabel = maButtonLabel;
- // filter with options -> append ellipses on export button label
- if ( CheckFilterOptionsCapability( getCurentSfxFilter() ) )
- sLabel += OUString( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
-
- if ( sOldLabel != sLabel )
- {
- try
- {
- xCtrlAccess->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK, sLabel );
- }
- catch( const IllegalArgumentException& )
- {
- DBG_ERRORFILE( "FileDialogHelper_Impl::updateExportButton: caught an exception!" );
- }
- }
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::updateSelectionBox()
-{
- if ( !mbHasSelectionBox )
- return;
-
- // Does the selection box exist?
- sal_Bool bSelectionBoxFound = sal_False;
- uno::Reference< XControlInformation > xCtrlInfo( mxFileDlg, UNO_QUERY );
- if ( xCtrlInfo.is() )
- {
- Sequence< ::rtl::OUString > aCtrlList = xCtrlInfo->getSupportedControls();
- sal_uInt32 nCount = aCtrlList.getLength();
- for ( sal_uInt32 nCtrl = 0; nCtrl < nCount; ++nCtrl )
- if ( aCtrlList[ nCtrl ].equalsAscii("SelectionBox") )
- {
- bSelectionBoxFound = sal_False;
- break;
- }
- }
-
- if ( bSelectionBoxFound )
- {
- const SfxFilter* pFilter = getCurentSfxFilter();
- mbSelectionFltrEnabled = updateExtendedControl(
- ExtendedFilePickerElementIds::CHECKBOX_SELECTION,
- ( mbSelectionEnabled && pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_SUPPORTSSELECTION ) != 0 ) );
- uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
- xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, makeAny( (sal_Bool)mbSelection ) );
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::enablePasswordBox( sal_Bool bInit )
-{
- if ( ! mbHasPassword )
- return;
-
- sal_Bool bWasEnabled = mbIsPwdEnabled;
-
- const SfxFilter* pCurrentFilter = getCurentSfxFilter();
- mbIsPwdEnabled = updateExtendedControl(
- ExtendedFilePickerElementIds::CHECKBOX_PASSWORD,
- pCurrentFilter && ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_ENCRYPTION )
- );
-
- if( bInit )
- {
- // in case of inintialization previous state is not interesting
- if( mbIsPwdEnabled )
- {
- uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
- if( mbPwdCheckBoxState )
- xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
- }
- }
- else if( !bWasEnabled && mbIsPwdEnabled )
- {
- uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
- if( mbPwdCheckBoxState )
- xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
- }
- else if( bWasEnabled && !mbIsPwdEnabled )
- {
- // remember user settings until checkbox is enabled
- uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
- Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
- sal_Bool bPassWord = sal_False;
- mbPwdCheckBoxState = ( aValue >>= bPassWord ) && bPassWord;
- xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_False ) );
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::updatePreviewState( sal_Bool _bUpdatePreviewWindow )
-{
- if ( mbHasPreview )
- {
- uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
-
- // check, wether or not we have to display a preview
- if ( xCtrlAccess.is() )
- {
- try
- {
- Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
- sal_Bool bShowPreview = sal_False;
-
- if ( aValue >>= bShowPreview )
- {
- mbShowPreview = bShowPreview;
-
- // #97633
- // setShowState has currently no effect for the
- // OpenOffice FilePicker (see svtools/source/filepicker/iodlg.cxx)
- uno::Reference< XFilePreview > xFilePreview( mxFileDlg, UNO_QUERY );
- if ( xFilePreview.is() )
- xFilePreview->setShowState( mbShowPreview );
-
- if ( _bUpdatePreviewWindow )
- TimeOutHdl_Impl( NULL );
- }
- }
- catch( Exception )
- {
- DBG_ERRORFILE( "FileDialogHelper_Impl::updatePreviewState: caught an exception!" );
- }
- }
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::updateVersions()
-{
- Sequence < OUString > aEntries;
- Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
-
- if ( aPathSeq.getLength() == 1 )
- {
- INetURLObject aObj( aPathSeq[0] );
-
- if ( ( aObj.GetProtocol() == INET_PROT_FILE ) &&
- ( utl::UCBContentHelper::IsDocument( aObj.GetMainURL( INetURLObject::NO_DECODE ) ) ) )
- {
- try
- {
- uno::Reference< embed::XStorage > xStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
- aObj.GetMainURL( INetURLObject::NO_DECODE ),
- embed::ElementModes::READ );
-
- DBG_ASSERT( xStorage.is(), "The method must return the storage or throw an exception!" );
- if ( !xStorage.is() )
- throw uno::RuntimeException();
-
- uno::Sequence < util::RevisionTag > xVersions = SfxMedium::GetVersionList( xStorage );
-
- aEntries.realloc( xVersions.getLength() + 1 );
- aEntries[0] = OUString( String ( SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ) ) );
-
- for ( sal_Int32 i=0; i<xVersions.getLength(); i++ )
- aEntries[ i + 1 ] = xVersions[i].Identifier;
-
- // TODO/LATER: not sure that this information must be shown in future ( binfilter? )
-//REMOVE else
-//REMOVE {
-//REMOVE SfxFilterFlags nMust = SFX_FILTER_IMPORT | SFX_FILTER_OWN;
-//REMOVE SfxFilterFlags nDont = SFX_FILTER_NOTINSTALLED | SFX_FILTER_STARONEFILTER;
-//REMOVE if ( SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( pStor->GetFormat(), nMust, nDont ) )
-//REMOVE {
-//REMOVE aEntries.realloc( 1 );
-//REMOVE aEntries[0] = OUString( String ( SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ) ) );
-//REMOVE }
-//REMOVE }
- }
- catch( uno::Exception& )
- {
- }
- }
- }
-
- uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
- Any aValue;
-
- try
- {
- xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
- ControlActions::DELETE_ITEMS, aValue );
- }
- catch( IllegalArgumentException ){}
-
- sal_Int32 nCount = aEntries.getLength();
-
- if ( nCount )
- {
- try
- {
- aValue <<= aEntries;
- xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
- ControlActions::ADD_ITEMS, aValue );
-
- Any aPos;
- aPos <<= (sal_Int32) 0;
- xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
- ControlActions::SET_SELECT_ITEM, aPos );
- }
- catch( IllegalArgumentException ){}
- }
-}
-
-// -----------------------------------------------------------------------
-class OReleaseSolarMutex
-{
-private:
- const sal_Int32 m_nAquireCount;
-public:
- OReleaseSolarMutex( )
- :m_nAquireCount( Application::ReleaseSolarMutex() )
- {
- }
- ~OReleaseSolarMutex( )
- {
- Application::AcquireSolarMutex( m_nAquireCount );
- }
-};
-
-// -----------------------------------------------------------------------
-IMPL_LINK( FileDialogHelper_Impl, TimeOutHdl_Impl, Timer*, EMPTYARG )
-{
- if ( !mbHasPreview )
- return 0;
-
- maGraphic.Clear();
-
- Any aAny;
- uno::Reference < XFilePreview > xFilePicker( mxFileDlg, UNO_QUERY );
-
- if ( ! xFilePicker.is() )
- return 0;
-
- Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
-
- if ( mbShowPreview && ( aPathSeq.getLength() == 1 ) )
- {
- OUString aURL = aPathSeq[0];
-
- if ( ERRCODE_NONE == getGraphic( aURL, maGraphic ) )
- {
- // #89491
- // changed the code slightly;
- // before: the bitmap was scaled and
- // surrounded a white frame
- // now: the bitmap will only be scaled
- // and the filepicker implementation
- // is responsible for placing it at its
- // proper position and painting a frame
-
- Bitmap aBmp = maGraphic.GetBitmap();
-
- // scale the bitmap to the correct size
- sal_Int32 nOutWidth = xFilePicker->getAvailableWidth();
- sal_Int32 nOutHeight = xFilePicker->getAvailableHeight();
- sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
- sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
-
- double nXRatio = (double) nOutWidth / nBmpWidth;
- double nYRatio = (double) nOutHeight / nBmpHeight;
-
- if ( nXRatio < nYRatio )
- aBmp.Scale( nXRatio, nXRatio );
- else
- aBmp.Scale( nYRatio, nYRatio );
-
- // #94505# Convert to true color, to allow CopyPixel
- aBmp.Convert( BMP_CONVERSION_24BIT );
-
- // and copy it into the Any
- SvMemoryStream aData;
-
- aData << aBmp;
-
- const Sequence < sal_Int8 > aBuffer(
- static_cast< const sal_Int8* >(aData.GetData()),
- aData.GetEndOfData() );
-
- aAny <<= aBuffer;
- }
- }
-
- try
- {
- OReleaseSolarMutex aReleaseForCallback;
- // clear the preview window
- xFilePicker->setImage( FilePreviewImageFormats::BITMAP, aAny );
- }
- catch( IllegalArgumentException )
- {
- }
-
- return 0;
-}
-
-// ------------------------------------------------------------------------
-ErrCode FileDialogHelper_Impl::getGraphic( const OUString& rURL,
- Graphic& rGraphic ) const
-{
- if ( utl::UCBContentHelper::IsFolder( rURL ) )
- return ERRCODE_IO_NOTAFILE;
-
- if ( !mpGraphicFilter )
- return ERRCODE_IO_NOTSUPPORTED;
-
- // select graphic filter from dialog filter selection
- OUString aCurFilter( getFilter() );
-
- sal_uInt16 nFilter = aCurFilter.getLength() && mpGraphicFilter->GetImportFormatCount()
- ? mpGraphicFilter->GetImportFormatNumber( aCurFilter )
- : GRFILTER_FORMAT_DONTKNOW;
-
- INetURLObject aURLObj( rURL );
-
- if ( aURLObj.HasError() || INET_PROT_NOT_VALID == aURLObj.GetProtocol() )
- {
- aURLObj.SetSmartProtocol( INET_PROT_FILE );
- aURLObj.SetSmartURL( rURL );
- }
-
- ErrCode nRet = ERRCODE_NONE;
-
- sal_uInt32 nFilterImportFlags = GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG;
- // non-local?
- if ( INET_PROT_FILE != aURLObj.GetProtocol() )
- {
- SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( rURL, STREAM_READ );
-
- if( pStream )
- nRet = mpGraphicFilter->ImportGraphic( rGraphic, rURL, *pStream, nFilter, NULL, nFilterImportFlags );
- else
- nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
- delete pStream;
- }
- else
- {
- nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
- }
-
- return nRet;
-}
-
-// ------------------------------------------------------------------------
-ErrCode FileDialogHelper_Impl::getGraphic( Graphic& rGraphic ) const
-{
- ErrCode nRet = ERRCODE_NONE;
-
- if ( ! maGraphic )
- {
- OUString aPath;;
- Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
-
- if ( aPathSeq.getLength() == 1 )
- {
- aPath = aPathSeq[0];
- }
-
- if ( aPath.getLength() )
- nRet = getGraphic( aPath, rGraphic );
- else
- nRet = ERRCODE_IO_GENERAL;
- }
- else
- rGraphic = maGraphic;
-
- return nRet;
-}
-
-// ------------------------------------------------------------------------
-sal_Bool lcl_isSystemFilePicker( const uno::Reference< XFilePicker >& _rxFP )
-{
- try
- {
- uno::Reference< XServiceInfo > xSI( _rxFP, UNO_QUERY );
- if ( xSI.is() && xSI->supportsService( DEFINE_CONST_OUSTRING( "com.sun.star.ui.dialogs.SystemFilePicker" ) ) )
- return sal_True;
- }
- catch( const Exception& )
- {
- }
- return sal_False;
-}
-
-
-// ------------------------------------------------------------------------
-// ----------- FileDialogHelper_Impl ---------------------------
-// ------------------------------------------------------------------------
-
-FileDialogHelper_Impl::FileDialogHelper_Impl(
- FileDialogHelper* _pAntiImpl,
- sal_Int16 nDialogType,
- sal_Int64 nFlags,
- sal_Int16 nDialog,
- Window* _pPreferredParentWindow,
- const String& sStandardDir,
- const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList
- )
- :m_nDialogType ( nDialogType )
- ,meContext ( FileDialogHelper::UNKNOWN_CONTEXT )
-{
- const char* pServiceName=0;
- if ( nDialog == SFX2_IMPL_DIALOG_SYSTEM )
- pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
- else if ( nDialog == SFX2_IMPL_DIALOG_OOO )
- pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
- else
- pServiceName = FILE_OPEN_SERVICE_NAME;
- OUString aService = ::rtl::OUString::createFromAscii( pServiceName );
-
- uno::Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
-
- // create the file open dialog
- // the flags can be SFXWB_INSERT or SFXWB_MULTISELECTION
-
- mpPreferredParentWindow = _pPreferredParentWindow;
- mpAntiImpl = _pAntiImpl;
- mnError = ERRCODE_NONE;
- mbHasAutoExt = sal_False;
- mbHasPassword = sal_False;
- m_bHaveFilterOptions = sal_False;
- mbIsPwdEnabled = sal_True;
- mbHasVersions = sal_False;
- mbHasPreview = sal_False;
- mbShowPreview = sal_False;
- mbHasLink = sal_False;
- mbDeleteMatcher = sal_False;
- mbInsert = SFXWB_INSERT == ( nFlags & SFXWB_INSERT );
- mbExport = SFXWB_EXPORT == ( nFlags & SFXWB_EXPORT );
- mbIsSaveDlg = sal_False;
- mbPwdCheckBoxState = sal_False;
- mbSelection = sal_False;
- mbSelectionEnabled = sal_True;
- mbHasSelectionBox = sal_False;
- mbSelectionFltrEnabled = sal_False;
-
- // default settings
- m_nDontFlags = SFX_FILTER_INTERNAL | SFX_FILTER_NOTINFILEDLG | SFX_FILTER_NOTINSTALLED;
- if( WB_OPEN == ( nFlags & WB_OPEN ) )
- m_nMustFlags = SFX_FILTER_IMPORT;
- else
- m_nMustFlags = SFX_FILTER_EXPORT;
-
-
- mpMatcher = NULL;
- mpGraphicFilter = NULL;
- mnPostUserEventId = 0;
-
- // create the picker component
- mxFileDlg = mxFileDlg.query( xFactory->createInstance( aService ) );
- mbSystemPicker = lcl_isSystemFilePicker( mxFileDlg );
-
- uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
- uno::Reference< XInitialization > xInit( mxFileDlg, UNO_QUERY );
-
- if ( ! mxFileDlg.is() || ! xNotifier.is() )
- {
- mnError = ERRCODE_ABORT;
- return;
- }
-
-
- if ( xInit.is() )
- {
- sal_Int16 nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
-
- switch ( m_nDialogType )
- {
- case FILEOPEN_SIMPLE:
- nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
- break;
-
- case FILESAVE_SIMPLE:
- nTemplateDescription = TemplateDescription::FILESAVE_SIMPLE;
- mbIsSaveDlg = sal_True;
- break;
-
- case FILESAVE_AUTOEXTENSION_PASSWORD:
- nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
- mbHasPassword = sal_True;
- mbHasAutoExt = sal_True;
- mbIsSaveDlg = sal_True;
- break;
-
- case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
- nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS;
- mbHasPassword = sal_True;
-
- m_bHaveFilterOptions = sal_True;
- if( xFactory.is() )
- {
- mxFilterCFG = uno::Reference< XNameAccess >(
- xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
- UNO_QUERY );
- }
-
- mbHasAutoExt = sal_True;
- mbIsSaveDlg = sal_True;
- break;
-
- case FILESAVE_AUTOEXTENSION_SELECTION:
- nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION;
- mbHasAutoExt = sal_True;
- mbIsSaveDlg = sal_True;
- mbHasSelectionBox = sal_True;
- if ( mbExport && !mxFilterCFG.is() && xFactory.is() )
- {
- mxFilterCFG = uno::Reference< XNameAccess >(
- xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
- UNO_QUERY );
- }
- break;
-
- case FILESAVE_AUTOEXTENSION_TEMPLATE:
- nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE;
- mbHasAutoExt = sal_True;
- mbIsSaveDlg = sal_True;
- break;
-
- case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
- nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE;
- mbHasPreview = sal_True;
- mbHasLink = sal_True;
-
- // aPreviewTimer
- maPreViewTimer.SetTimeout( 500 );
- maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
- break;
-
- case FILEOPEN_PLAY:
- nTemplateDescription = TemplateDescription::FILEOPEN_PLAY;
- break;
-
- case FILEOPEN_READONLY_VERSION:
- nTemplateDescription = TemplateDescription::FILEOPEN_READONLY_VERSION;
- mbHasVersions = sal_True;
- break;
-
- case FILEOPEN_LINK_PREVIEW:
- nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW;
- mbHasPreview = sal_True;
- mbHasLink = sal_True;
- // aPreviewTimer
- maPreViewTimer.SetTimeout( 500 );
- maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
- break;
-
- case FILESAVE_AUTOEXTENSION:
- nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION;
- mbHasAutoExt = sal_True;
- mbIsSaveDlg = sal_True;
- break;
-
- default:
- DBG_ERRORFILE( "FileDialogHelper::ctor with unknown type" );
- break;
- }
-
-
-
- //Sequence < Any > aInitArguments( mbSystemPicker || !mpPreferredParentWindow ? 1 : 3 );
- Sequence < Any > aInitArguments( !mpPreferredParentWindow ? 3 : 4 );
-
- // This is a hack. We currently know that the internal file picker implementation
- // supports the extended arguments as specified below.
- // TODO:
- // a) adjust the service description so that it includes the TemplateDescription and ParentWindow args
- // b) adjust the implementation of the system file picker to that it recognizes it
- if ( mbSystemPicker )
- {
- aInitArguments[0] <<= nTemplateDescription;
- }
- else
- {
- aInitArguments[0] <<= NamedValue(
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TemplateDescription" ) ),
- makeAny( nTemplateDescription )
- );
-
- ::rtl::OUString sStandardDirTemp = ::rtl::OUString( sStandardDir );
-
- aInitArguments[1] <<= NamedValue(
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StandardDir" ) ),
- makeAny( sStandardDirTemp )
- );
-
- aInitArguments[2] <<= NamedValue(
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BlackList" ) ),
- makeAny( rBlackList )
- );
-
-
- if ( mpPreferredParentWindow )
- aInitArguments[3] <<= NamedValue(
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ) ),
- makeAny( VCLUnoHelper::GetInterface( mpPreferredParentWindow ) )
- );
-
-
- }
-
- try
- {
- xInit->initialize( aInitArguments );
- }
- catch( const Exception& )
- {
- DBG_ERROR( "FileDialogHelper_Impl::FileDialogHelper_Impl: could not initialize the picker!" );
- }
- }
-
-
- // set multiselection mode
- if ( nFlags & SFXWB_MULTISELECTION )
- mxFileDlg->setMultiSelectionMode( sal_True );
-
- if ( mbHasLink ) // generate graphic filter only on demand
- addGraphicFilter();
-
- // Export dialog
- if ( mbExport )
- {
- mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_EXPORT ) ) ) );
- try {
- com::sun::star::uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY_THROW );
- xCtrlAccess->enableControl( ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, sal_True );
- }
- catch( const Exception & ) { }
- }
-
- // the "insert file" dialog needs another title
- if ( mbInsert )
- {
- mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_INSERT ) ) ) );
- uno::Reference < XFilePickerControlAccess > xExtDlg( mxFileDlg, UNO_QUERY );
- if ( xExtDlg.is() )
- {
- try
- {
- xExtDlg->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK,
- OUString( String( SfxResId( STR_SFX_EXPLORERFILE_BUTTONINSERT ) ) ) );
- }
- catch( IllegalArgumentException ){}
- }
- }
-
- // add the event listener
- xNotifier->addFilePickerListener( this );
-}
-
-// ------------------------------------------------------------------------
-FileDialogHelper_Impl::~FileDialogHelper_Impl()
-{
- // Remove user event if we haven't received it yet
- if ( mnPostUserEventId )
- Application::RemoveUserEvent( mnPostUserEventId );
- mnPostUserEventId = 0;
-
- delete mpGraphicFilter;
-
- if ( mbDeleteMatcher )
- delete mpMatcher;
-
- maPreViewTimer.SetTimeoutHdl( Link() );
-
- ::comphelper::disposeComponent( mxFileDlg );
-}
-
-#define nMagic -1
-
-class PickerThread_Impl : public ::vos::OThread
-{
- uno::Reference < XFilePicker > mxPicker;
- ::vos::OMutex maMutex;
- virtual void SAL_CALL run();
- sal_Int16 mnRet;
-public:
- PickerThread_Impl( const uno::Reference < XFilePicker >& rPicker )
- : mxPicker( rPicker ), mnRet(nMagic) {}
-
- sal_Int16 GetReturnValue()
- { ::vos::OGuard aGuard( maMutex ); return mnRet; }
-
- void SetReturnValue( sal_Int16 aRetValue )
- { ::vos::OGuard aGuard( maMutex ); mnRet = aRetValue; }
-};
-
-void SAL_CALL PickerThread_Impl::run()
-{
- try
- {
- sal_Int16 n = mxPicker->execute();
- SetReturnValue( n );
- }
- catch( RuntimeException& )
- {
- SetReturnValue( ExecutableDialogResults::CANCEL );
- DBG_ERRORFILE( "RuntimeException caught" );
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::setControlHelpIds( const sal_Int16* _pControlId, const sal_Int32* _pHelpId )
-{
- DBG_ASSERT( _pControlId && _pHelpId, "FileDialogHelper_Impl::setControlHelpIds: invalid array pointers!" );
- if ( !_pControlId || !_pHelpId )
- return;
-
- // forward these ids to the file picker
- try
- {
- const ::rtl::OUString sHelpIdPrefix( RTL_CONSTASCII_USTRINGPARAM( "HID:" ) );
- // the ids for the single controls
- uno::Reference< XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
- if ( xControlAccess.is() )
- {
- while ( *_pControlId )
- {
- // calc the help id of the element
- ::rtl::OUString sId( sHelpIdPrefix );
- sId += ::rtl::OUString::valueOf( *_pHelpId );
- // set the help id
- xControlAccess->setValue( *_pControlId, ControlActions::SET_HELP_URL, makeAny( sId ) );
-
- ++_pControlId; ++_pHelpId;
- }
- }
- }
- catch( const Exception& )
- {
- DBG_ERROR( "FileDialogHelper_Impl::setControlHelpIds: caught an exception while setting the help ids!" );
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::setDialogHelpId( const sal_Int32 _nHelpId )
-{
- svt::SetDialogHelpId( mxFileDlg, _nHelpId );
-}
-
-// ------------------------------------------------------------------------
-IMPL_LINK( FileDialogHelper_Impl, InitControls, void*, NOTINTERESTEDIN )
-{
- (void)NOTINTERESTEDIN;
- mnPostUserEventId = 0;
- enablePasswordBox( sal_True );
- updateFilterOptionsBox( );
- updateSelectionBox( );
-
- return 0L;
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::preExecute()
-{
- loadConfig( );
- setDefaultValues( );
- updatePreviewState( sal_False );
-
- implInitializeFileName( );
- // #106079# / 2002-12-09 / fs@openoffice.org
-
-#if !(defined(MACOSX) && defined(QUARTZ)) && !defined(WNT)
- // allow for dialog implementations which need to be executed before they return valid values for
- // current filter and such
-
- // On Vista (at least SP1) it's the same as on MacOSX, the modal dialog won't let message pass
- // through before it returns from execution
- mnPostUserEventId = Application::PostUserEvent( LINK( this, FileDialogHelper_Impl, InitControls ) );
-#else
- // However, the Mac OS X implementation's pickers run modally in execute and so the event doesn't
- // get through in time... so we call the methods directly
- enablePasswordBox( sal_True );
- updateFilterOptionsBox( );
- updateSelectionBox( );
-#endif
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::postExecute( sal_Int16 _nResult )
-{
- if ( ExecutableDialogResults::CANCEL != _nResult )
- saveConfig();
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::implInitializeFileName( )
-{
- if ( maFileName.getLength() )
- {
- INetURLObject aObj( maPath );
- aObj.Append( maFileName );
-
- // in case we're operating as save dialog, and "auto extension" is checked,
- // cut the extension from the name
- // #106079# / 2002-12-09 / fs@openoffice.org
- if ( mbIsSaveDlg && mbHasAutoExt )
- {
- try
- {
- sal_Bool bAutoExtChecked = sal_False;
-
- uno::Reference < XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
- if ( xControlAccess.is()
- && ( xControlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 )
- >>= bAutoExtChecked
- )
- )
- {
- if ( bAutoExtChecked )
- { // cut the extension
- aObj.removeExtension( );
- mxFileDlg->setDefaultName( aObj.GetName( INetURLObject::DECODE_WITH_CHARSET ) );
- }
- }
- }
- catch( const Exception& )
- {
- DBG_ERROR( "FileDialogHelper_Impl::implInitializeFileName: could not ask for the auto-extension current-value!" );
- }
- }
- }
-}
-
-// ------------------------------------------------------------------------
-sal_Int16 FileDialogHelper_Impl::implDoExecute()
-{
- preExecute();
-
- sal_Int16 nRet = ExecutableDialogResults::CANCEL;
-
-//On MacOSX the native file picker has to run in the primordial thread because of drawing issues
-//On Linux the native gtk file picker, when backed by gnome-vfs2, needs to be run in the same
-//primordial thread as the ucb gnome-vfs2 provider was initialized in.
-/*
-#ifdef WNT
- if ( mbSystemPicker )
- {
- PickerThread_Impl* pThread = new PickerThread_Impl( mxFileDlg );
- pThread->create();
- while ( pThread->GetReturnValue() == nMagic )
- Application::Yield();
- pThread->join();
- nRet = pThread->GetReturnValue();
- delete pThread;
- }
- else
-#endif
-*/
- {
- try
- {
-#ifdef WNT
- if ( mbSystemPicker )
- {
- OReleaseSolarMutex aSolarMutex;
- nRet = mxFileDlg->execute();
- }
- else
-#endif
- nRet = mxFileDlg->execute();
- }
- catch( const Exception& )
- {
- DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
- }
- }
-
- postExecute( nRet );
-
- return nRet;
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::implStartExecute()
-{
- DBG_ASSERT( mxFileDlg.is(), "invalid file dialog" );
-
- preExecute();
-
- if ( mbSystemPicker )
- {
- }
- else
- {
- try
- {
- uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( mxFileDlg, UNO_QUERY );
- if ( xAsyncDlg.is() )
- xAsyncDlg->startExecuteModal( this );
- }
- catch( const Exception& )
- {
- DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
- }
- }
-}
-
-// ------------------------------------------------------------------------
-String FileDialogHelper_Impl::implEnsureURLExtension(const String& sURL,
- const String& /*sExtension*/)
-{
- return sURL;
- /*
- // This feature must be active for file save/export only !
- if (
- (! mbIsSaveDlg) &&
- (! mbExport )
- )
- return sURL;
-
- // no extension available (because "ALL *.*" was selected) ?
- // Nod idea what else should happen here .-)
- if (sExtension.Len() < 1)
- return sURL;
-
- // Some FilePicker implementations already add the right extension ...
- // or might be the user used the right one already ...
- // Dont create duplicate extension.
- INetURLObject aURL(sURL);
- if (aURL.getExtension().equals(sExtension))
- return sURL;
-
- // Ignore any other extension set by the user.
- // Make sure suitable extension is used always.
- // e.g. "test.bla.odt" for "ODT"
- ::rtl::OUStringBuffer sNewURL(256);
- sNewURL.append (sURL );
- sNewURL.appendAscii("." );
- sNewURL.append (sExtension);
- return sNewURL.makeStringAndClear();
- */
-}
-
-// ------------------------------------------------------------------------
-void lcl_saveLastURLs(SvStringsDtor*& rpURLList ,
- ::comphelper::SequenceAsVector< ::rtl::OUString >& lLastURLs )
-{
- lLastURLs.clear();
- USHORT c = rpURLList->Count();
- USHORT i = 0;
- for (i=0; i<c; ++i)
- lLastURLs.push_back(*(rpURLList->GetObject(i)));
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::implGetAndCacheFiles(const uno::Reference< XInterface >& xPicker ,
- SvStringsDtor*& rpURLList,
- const SfxFilter* pFilter )
-{
- rpURLList = NULL;
-
- String sExtension;
- if (pFilter)
- {
- sExtension = pFilter->GetDefaultExtension ();
- sExtension.EraseAllChars( '*' );
- sExtension.EraseAllChars( '.' );
- }
-
- // a) the new way (optional!)
- uno::Reference< XFilePicker2 > xPickNew(xPicker, UNO_QUERY);
- if (xPickNew.is())
- {
- rpURLList = new SvStringsDtor;
- Sequence< OUString > lFiles = xPickNew->getSelectedFiles();
- ::sal_Int32 nFiles = lFiles.getLength();
- for (::sal_Int32 i = 0; i < nFiles; i++)
- {
- String* pURL = new String(implEnsureURLExtension(lFiles[i], sExtension));
- rpURLList->Insert( pURL, rpURLList->Count() );
- }
- }
-
- // b) the olde way ... non optional.
- else
- {
- uno::Reference< XFilePicker > xPickOld(xPicker, UNO_QUERY_THROW);
- Sequence< OUString > lFiles = xPickOld->getFiles();
- ::sal_Int32 nFiles = lFiles.getLength();
- if ( nFiles == 1 )
- {
- rpURLList = new SvStringsDtor;
- String* pURL = new String(implEnsureURLExtension(lFiles[0], sExtension));
- rpURLList->Insert( pURL, 0 );
- }
- else
- if ( nFiles > 1 )
- {
- rpURLList = new SvStringsDtor;
-
- INetURLObject aPath( lFiles[0] );
- aPath.setFinalSlash();
-
- for (::sal_Int32 i = 1; i < nFiles; i++)
- {
- if (i == 1)
- aPath.Append( lFiles[i] );
- else
- aPath.setName( lFiles[i] );
-
- String* pURL = new String(implEnsureURLExtension(aPath.GetMainURL( INetURLObject::NO_DECODE ), sExtension) );
- rpURLList->Insert( pURL, rpURLList->Count() );
- }
- }
- }
-
- lcl_saveLastURLs(rpURLList, mlLastURLs);
-}
-
-// ------------------------------------------------------------------------
-ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
- SfxItemSet *& rpSet,
- String& rFilter )
-{
- // rFilter is a pure output parameter, it shouldn't be used for anything else
- // changing this would surely break code
- // rpSet is in/out parameter, usually just a media-descriptor that can be changed by dialog
-
- uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
-
- // retrieves parameters from rpSet
- // for now only Password is used
- if ( rpSet )
- {
- // check password checkbox if the document had password before
- if( mbHasPassword )
- {
- SFX_ITEMSET_ARG( rpSet, pPassItem, SfxStringItem, SID_PASSWORD, FALSE );
- mbPwdCheckBoxState = ( pPassItem != NULL );
-
- // in case the document has password to modify, the dialog should be shown
- SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxInt32Item, SID_MODIFYPASSWORDHASH, FALSE );
- mbPwdCheckBoxState |= ( pPassToModifyItem && pPassToModifyItem->GetValue() );
- }
-
- SFX_ITEMSET_ARG( rpSet, pSelectItem, SfxBoolItem, SID_SELECTION, FALSE );
- if ( pSelectItem )
- mbSelection = pSelectItem->GetValue();
- else
- mbSelectionEnabled = sal_False;
-
- // the password will be set in case user decide so
- rpSet->ClearItem( SID_PASSWORD );
- rpSet->ClearItem( SID_RECOMMENDREADONLY );
- rpSet->ClearItem( SID_MODIFYPASSWORDHASH );
-
- }
-
- if ( mbHasPassword && !mbPwdCheckBoxState )
- {
- SvtSecurityOptions aSecOpt;
- mbPwdCheckBoxState = (
- aSecOpt.IsOptionSet( SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD ) );
- }
-
- rpURLList = NULL;
-
- if ( ! mxFileDlg.is() )
- return ERRCODE_ABORT;
-
- if ( ExecutableDialogResults::CANCEL != implDoExecute() )
- {
- // create an itemset if there is no
- if( !rpSet )
- rpSet = new SfxAllItemSet( SFX_APP()->GetPool() );
-
- // the item should remain only if it was set by the dialog
- rpSet->ClearItem( SID_SELECTION );
-
- if( mbExport )
- {
- try
- {
- Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
- sal_Bool bSelection = sal_False;
- if ( aValue >>= bSelection )
- rpSet->Put( SfxBoolItem( SID_SELECTION, bSelection ) );
- }
- catch( IllegalArgumentException )
- {
- DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
- }
- }
-
-
- // set the read-only flag. When inserting a file, this flag is always set
- if ( mbInsert )
- rpSet->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
- else
- {
- if ( ( FILEOPEN_READONLY_VERSION == m_nDialogType ) && xCtrlAccess.is() )
- {
- try
- {
- Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY, 0 );
- sal_Bool bReadOnly = sal_False;
- if ( ( aValue >>= bReadOnly ) && bReadOnly )
- rpSet->Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
- }
- catch( IllegalArgumentException )
- {
- DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
- }
- }
- }
- if ( mbHasVersions && xCtrlAccess.is() )
- {
- try
- {
- Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
- ControlActions::GET_SELECTED_ITEM_INDEX );
- sal_Int32 nVersion = 0;
- if ( ( aValue >>= nVersion ) && nVersion > 0 )
- // open a special version; 0 == current version
- rpSet->Put( SfxInt16Item( SID_VERSION, (short)nVersion ) );
- }
- catch( IllegalArgumentException ){}
- }
-
- // set the filter
- getRealFilter( rFilter );
-
- const SfxFilter* pCurrentFilter = getCurentSfxFilter();
-
- // fill the rpURLList
- implGetAndCacheFiles( mxFileDlg, rpURLList, pCurrentFilter );
- if ( rpURLList == NULL || rpURLList->GetObject(0) == NULL )
- return ERRCODE_ABORT;
-
- // check, wether or not we have to display a password box
- if ( pCurrentFilter && mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() )
- {
- try
- {
- Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
- sal_Bool bPassWord = sal_False;
- if ( ( aValue >>= bPassWord ) && bPassWord )
- {
- // ask for a password
- uno::Reference < ::com::sun::star::task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY );
-
- if( xInteractionHandler.is() )
- {
- // TODO: need a save way to distinguish MS filters from other filters
- // for now MS-filters are the only alien filters that support encryption
- sal_Bool bMSType = !pCurrentFilter->IsOwnFormat();
- ::comphelper::DocPasswordRequestType eType = bMSType ?
- ::comphelper::DocPasswordRequestType_MS :
- ::comphelper::DocPasswordRequestType_STANDARD;
-
- ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new ::comphelper::DocPasswordRequest( eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)), ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ) != 0 ) );
-
- uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
- xInteractionHandler->handle( rRequest );
- if ( pPasswordRequest->isPassword() )
- {
- if ( pPasswordRequest->getPassword().getLength() )
- rpSet->Put( SfxStringItem( SID_PASSWORD, pPasswordRequest->getPassword() ) );
-
- if ( pPasswordRequest->getRecommendReadOnly() )
- rpSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) );
-
- // the empty password has 0 as Hash
- sal_Int32 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pCurrentFilter->GetServiceName() ) );
- if ( nHash )
- rpSet->Put( SfxInt32Item( SID_MODIFYPASSWORDHASH, nHash ) );
- }
- else
- return ERRCODE_ABORT;
- }
- }
- }
- catch( IllegalArgumentException ){}
- }
-
- SaveLastUsedFilter();
- return ERRCODE_NONE;
- }
- else
- return ERRCODE_ABORT;
-}
-
-// ------------------------------------------------------------------------
-ErrCode FileDialogHelper_Impl::execute()
-{
- if ( ! mxFileDlg.is() )
- return ERRCODE_ABORT;
-
- sal_Int16 nRet = implDoExecute();
-
- maPath = mxFileDlg->getDisplayDirectory();
-
- if ( ExecutableDialogResults::CANCEL == nRet )
- return ERRCODE_ABORT;
- else
- {
- return ERRCODE_NONE;
- }
-}
-
-// ------------------------------------------------------------------------
-OUString FileDialogHelper_Impl::getPath() const
-{
- OUString aPath;
-
- if ( mxFileDlg.is() )
- aPath = mxFileDlg->getDisplayDirectory();
-
- if ( !aPath.getLength() )
- aPath = maPath;
-
- return aPath;
-}
-
-// ------------------------------------------------------------------------
-OUString FileDialogHelper_Impl::getFilter() const
-{
- String aFilter = getCurrentFilterUIName();
-
- if( !aFilter.Len() )
- aFilter = maCurFilter;
-
- return aFilter;
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::getRealFilter( String& _rFilter ) const
-{
- _rFilter = getCurrentFilterUIName();
-
- if ( !_rFilter.Len() )
- _rFilter = maCurFilter;
-
- if ( _rFilter.Len() && mpMatcher )
- {
- const SfxFilter* pFilter =
- mpMatcher->GetFilter4UIName( _rFilter, m_nMustFlags, m_nDontFlags );
- _rFilter = pFilter ? pFilter->GetFilterName() : _rFilter.Erase();
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::displayFolder( const ::rtl::OUString& _rPath )
-{
- if ( ! _rPath.getLength() )
- // nothing to do
- return;
-
- /*
- if ( !::utl::UCBContentHelper::IsFolder( _rPath ) )
- // only valid folders accepted here
- return;
- */
-
- maPath = _rPath;
- if ( mxFileDlg.is() )
- {
- try
- {
- mxFileDlg->setDisplayDirectory( maPath );
- }
- catch( const IllegalArgumentException& )
- {
- DBG_ERROR( "FileDialogHelper_Impl::displayFolder: caught an exception!" );
- }
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::setFileName( const ::rtl::OUString& _rFile )
-{
- maFileName = _rFile;
- if ( mxFileDlg.is() )
- {
- try
- {
- mxFileDlg->setDefaultName( maFileName );
- }
- catch( const IllegalArgumentException& )
- {
- DBG_ERROR( "FileDialogHelper_Impl::setFileName: caught an exception!" );
- }
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::setFilter( const OUString& rFilter )
-{
- DBG_ASSERT( rFilter.indexOf(':') == -1, "Old filter name used!");
-
- maCurFilter = rFilter;
-
- if ( rFilter.getLength() && mpMatcher )
- {
- const SfxFilter* pFilter = mpMatcher->GetFilter4FilterName(
- rFilter, m_nMustFlags, m_nDontFlags );
- if ( pFilter )
- maCurFilter = pFilter->GetUIName();
- }
-
- uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
-
- if ( maCurFilter.getLength() && xFltMgr.is() )
- {
- try
- {
- xFltMgr->setCurrentFilter( maCurFilter );
- }
- catch( IllegalArgumentException ){}
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::createMatcher( const String& rFactory )
-{
- mpMatcher = new SfxFilterMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
- mbDeleteMatcher = sal_True;
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::addFilters( sal_Int64 nFlags,
- const String& rFactory,
- SfxFilterFlags nMust,
- SfxFilterFlags nDont )
-{
- uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
-
- if ( ! xFltMgr.is() )
- return;
-
- // we still need a matcher to convert UI names to filter names
- if ( !rFactory.Len() )
- {
- SfxApplication *pSfxApp = SFX_APP();
- mpMatcher = &pSfxApp->GetFilterMatcher();
- mbDeleteMatcher = sal_False;
- }
- else
- {
- mpMatcher = new SfxFilterMatcher( rFactory );
- mbDeleteMatcher = sal_True;
- }
-
- uno::Reference< XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
- uno::Reference< XContainerQuery > xFilterCont(
- xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.FilterFactory")),
- UNO_QUERY);
- if ( ! xFilterCont.is() )
- return;
-
- m_nMustFlags |= nMust;
- m_nDontFlags |= nDont;
-
- // create the list of filters
- ::rtl::OUStringBuffer sQuery(256);
- sQuery.appendAscii("getSortedFilterList()");
- sQuery.appendAscii(":module=" );
- sQuery.append (rFactory ); // use long name here !
- sQuery.appendAscii(":iflags=" );
- sQuery.append (::rtl::OUString::valueOf((sal_Int32)m_nMustFlags));
- sQuery.appendAscii(":eflags=" );
- sQuery.append (::rtl::OUString::valueOf((sal_Int32)m_nDontFlags));
-
- uno::Reference< XEnumeration > xResult = xFilterCont->createSubSetEnumerationByQuery(sQuery.makeStringAndClear());
- TSortedFilterList aIter (xResult);
-
- // no matcher any longer used ...
- mbDeleteMatcher = sal_False;
-
- // append the filters
- ::rtl::OUString sFirstFilter;
- if ( WB_OPEN == ( nFlags & WB_OPEN ) )
- ::sfx2::appendFiltersForOpen( aIter, xFltMgr, sFirstFilter, *this );
- else if ( mbExport )
- ::sfx2::appendExportFilters( aIter, xFltMgr, sFirstFilter, *this );
- else
- ::sfx2::appendFiltersForSave( aIter, xFltMgr, sFirstFilter, *this, rFactory );
-
- // set our initial selected filter (if we do not already have one)
- if ( !maSelectFilter.getLength() )
- maSelectFilter = sFirstFilter;
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::addFilter( const OUString& rFilterName,
- const OUString& rExtension )
-{
- uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
-
- if ( ! xFltMgr.is() )
- return;
-
- try
- {
- xFltMgr->appendFilter( rFilterName, rExtension );
-
- if ( !maSelectFilter.getLength() )
- maSelectFilter = rFilterName;
- }
- catch( IllegalArgumentException )
- {
-#ifdef DBG_UTIL
- ByteString aMsg( "Could not append Filter" );
- aMsg += ByteString( String( rFilterName ), RTL_TEXTENCODING_UTF8 );
- DBG_ERRORFILE( aMsg.GetBuffer() );
-#endif
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::addGraphicFilter()
-{
- uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
-
- if ( ! xFltMgr.is() )
- return;
-
- // create the list of filters
- mpGraphicFilter = new GraphicFilter;
- USHORT i, j, nCount = mpGraphicFilter->GetImportFormatCount();
-
- // compute the extension string for all known import filters
- String aExtensions;
-
- for ( i = 0; i < nCount; i++ )
- {
- j = 0;
- String sWildcard;
- while( TRUE )
- {
- sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
- if ( !sWildcard.Len() )
- break;
- if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
- {
- if ( aExtensions.Len() )
- aExtensions += sal_Unicode(';');
- aExtensions += sWildcard;
- }
- }
- }
-
-#if defined(WIN) || defined(WNT)
- if ( aExtensions.Len() > 240 )
- aExtensions = DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL );
-#endif
- sal_Bool bIsInOpenMode = isInOpenMode();
-
- try
- {
- OUString aAllFilterName = String( SfxResId( STR_SFX_IMPORT_ALL ) );
- aAllFilterName = ::sfx2::addExtension( aAllFilterName, aExtensions, bIsInOpenMode, *this );
-
- xFltMgr->appendFilter( aAllFilterName, aExtensions );
- maSelectFilter = aAllFilterName;
- }
- catch( IllegalArgumentException )
- {
- DBG_ERRORFILE( "Could not append Filter" );
- }
-
- // Now add the filter
- for ( i = 0; i < nCount; i++ )
- {
- String aName = mpGraphicFilter->GetImportFormatName( i );
- String aExt;
- j = 0;
- String sWildcard;
- while( TRUE )
- {
- sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
- if ( !sWildcard.Len() )
- break;
- if ( aExt.Search( sWildcard ) == STRING_NOTFOUND )
- {
- if ( aExt.Len() )
- aExt += sal_Unicode(';');
- aExt += sWildcard;
- }
- }
- aName = ::sfx2::addExtension( aName, aExt, bIsInOpenMode, *this );
- try
- {
- xFltMgr->appendFilter( aName, aExt );
- }
- catch( IllegalArgumentException )
- {
- DBG_ERRORFILE( "Could not append Filter" );
- }
- }
-}
-
-// ------------------------------------------------------------------------
-#define GRF_CONFIG_STR " "
-#define STD_CONFIG_STR "1 "
-
-void FileDialogHelper_Impl::saveConfig()
-{
- uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
- Any aValue;
-
- if ( ! xDlg.is() )
- return;
-
- if ( mbHasPreview )
- {
- SvtViewOptions aDlgOpt( E_DIALOG, IMPGRF_CONFIGNAME );
- String aUserData = DEFINE_CONST_UNICODE( GRF_CONFIG_STR );
-
- try
- {
- aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0 );
- sal_Bool bValue = sal_False;
- aValue >>= bValue;
- aUserData.SetToken( 0, ' ', String::CreateFromInt32( (sal_Int32) bValue ) );
-
- aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
- bValue = sal_False;
- aValue >>= bValue;
- aUserData.SetToken( 1, ' ', String::CreateFromInt32( (sal_Int32) bValue ) );
-
- INetURLObject aObj( getPath() );
-
- if ( aObj.GetProtocol() == INET_PROT_FILE )
- aUserData.SetToken( 2, ' ', aObj.GetMainURL( INetURLObject::NO_DECODE ) );
-
- String aFilter = getFilter();
- aFilter = EncodeSpaces_Impl( aFilter );
- aUserData.SetToken( 3, ' ', aFilter );
-
- aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
- }
- catch( IllegalArgumentException ){}
- }
- else
- {
- sal_Bool bWriteConfig = sal_False;
- SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
- String aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
-
- if ( aDlgOpt.Exists() )
- {
- Any aUserItem = aDlgOpt.GetUserItem( USERITEM_NAME );
- OUString aTemp;
- if ( aUserItem >>= aTemp )
- aUserData = String( aTemp );
- }
-
- if ( mbHasAutoExt )
- {
- try
- {
- aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 );
- sal_Bool bAutoExt = sal_True;
- aValue >>= bAutoExt;
- aUserData.SetToken( 0, ' ', String::CreateFromInt32( (sal_Int32) bAutoExt ) );
- bWriteConfig = sal_True;
- }
- catch( IllegalArgumentException ){}
- }
-
- if ( ! mbIsSaveDlg )
- {
- OUString aPath = getPath();
- if ( aPath.getLength() &&
- utl::LocalFileHelper::IsLocalFile( aPath ) )
- {
- aUserData.SetToken( 1, ' ', aPath );
- bWriteConfig = sal_True;
- }
- }
-
- if( mbHasSelectionBox && mbSelectionFltrEnabled )
- {
- try
- {
- aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
- sal_Bool bSelection = sal_True;
- aValue >>= bSelection;
- if ( aUserData.GetTokenCount(' ') < 3 )
- aUserData.Append(' ');
- aUserData.SetToken( 2, ' ', String::CreateFromInt32( (sal_Int32) bSelection ) );
- bWriteConfig = sal_True;
- }
- catch( IllegalArgumentException ){}
- }
-
- if ( bWriteConfig )
- aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
- }
-
- SfxApplication *pSfxApp = SFX_APP();
- pSfxApp->SetLastDir_Impl( getPath() );
-}
-
-// ------------------------------------------------------------------------
-namespace
-{
- static ::rtl::OUString getInitPath( const String& _rFallback, const xub_StrLen _nFallbackToken )
- {
- SfxApplication *pSfxApp = SFX_APP();
- String sPath = pSfxApp->GetLastDir_Impl();
-
- if ( !sPath.Len() )
- sPath = _rFallback.GetToken( _nFallbackToken, ' ' );
-
- // check if the path points to a valid (accessible) directory
- sal_Bool bValid = sal_False;
- if ( sPath.Len() )
- {
- String sPathCheck( sPath );
- if ( sPathCheck.GetBuffer()[ sPathCheck.Len() - 1 ] != '/' )
- sPathCheck += '/';
- sPathCheck += '.';
- try
- {
- ::ucbhelper::Content aContent( sPathCheck, uno::Reference< ucb::XCommandEnvironment >() );
- bValid = aContent.isFolder();
- }
- catch( Exception& ) {}
- }
-
- if ( !bValid )
- sPath.Erase();
-
- return sPath;
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::loadConfig()
-{
- uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
- Any aValue;
-
- if ( ! xDlg.is() )
- return;
-
- if ( mbHasPreview )
- {
- SvtViewOptions aViewOpt( E_DIALOG, IMPGRF_CONFIGNAME );
- String aUserData;
-
- if ( aViewOpt.Exists() )
- {
- Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
- OUString aTemp;
- if ( aUserItem >>= aTemp )
- aUserData = String( aTemp );
- }
-
- if ( aUserData.Len() > 0 )
- {
- try
- {
- // respect the last "insert as link" state
- sal_Bool bLink = (sal_Bool) aUserData.GetToken( 0, ' ' ).ToInt32();
- if ( !xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0 ).hasValue() )
- {
- aValue <<= bLink;
- xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, aValue );
- }
-
- // respect the last "show preview" state
- sal_Bool bShowPreview = (sal_Bool) aUserData.GetToken( 1, ' ' ).ToInt32();
- if ( !xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 ).hasValue() )
- {
- aValue <<= bShowPreview;
- xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, aValue );
- }
-
- if ( !maPath.getLength() )
- displayFolder( getInitPath( aUserData, 2 ) );
-
- if ( ! maCurFilter.getLength() )
- {
- String aFilter = aUserData.GetToken( 3, ' ' );
- aFilter = DecodeSpaces_Impl( aFilter );
- setFilter( aFilter );
- }
-
- // set the member so we know that we have to show the preview
- mbShowPreview = bShowPreview;
- }
- catch( IllegalArgumentException ){}
- }
-
- if ( !maPath.getLength() )
- displayFolder( SvtPathOptions().GetGraphicPath() );
- }
- else
- {
- SvtViewOptions aViewOpt( E_DIALOG, IODLG_CONFIGNAME );
- String aUserData;
-
- if ( aViewOpt.Exists() )
- {
- Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
- OUString aTemp;
- if ( aUserItem >>= aTemp )
- aUserData = String( aTemp );
- }
-
- if ( ! aUserData.Len() )
- aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
-
- if ( ! maPath.getLength() )
- displayFolder( getInitPath( aUserData, 1 ) );
-
- if ( mbHasAutoExt )
- {
- sal_Int32 nFlag = aUserData.GetToken( 0, ' ' ).ToInt32();
- aValue <<= (sal_Bool) nFlag;
- try
- {
- xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue );
- }
- catch( IllegalArgumentException ){}
- }
-
- if( mbHasSelectionBox )
- {
- sal_Int32 nFlag = aUserData.GetToken( 2, ' ' ).ToInt32();
- aValue <<= (sal_Bool) nFlag;
- try
- {
- xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, aValue );
- }
- catch( IllegalArgumentException ){}
- }
-
- if ( !maPath.getLength() )
- displayFolder( SvtPathOptions().GetWorkPath() );
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper_Impl::setDefaultValues()
-{
- // when no filter is set, we set the curentFilter to <all>
- if ( !maCurFilter.getLength() && maSelectFilter.getLength() )
- {
- uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
- try
- {
- xFltMgr->setCurrentFilter( maSelectFilter );
- }
- catch( IllegalArgumentException )
- {}
- }
-
- // when no path is set, we use the standard 'work' folder
- if ( ! maPath.getLength() )
- {
- OUString aWorkFolder = SvtPathOptions().GetWorkPath();
- try
- {
- mxFileDlg->setDisplayDirectory( aWorkFolder );
- }
- catch( const Exception& )
- {
- DBG_ERROR( "FileDialogHelper_Impl::setDefaultValues: caught an exception while setting the display directory!" );
- }
-
- // INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
- //SetStandardDir( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE ) );
- }
-}
-
-sal_Bool FileDialogHelper_Impl::isShowFilterExtensionEnabled() const
-{
- return !maFilters.empty();
-}
-
-void FileDialogHelper_Impl::addFilterPair( const OUString& rFilter,
- const OUString& rFilterWithExtension )
-{
- maFilters.push_back( FilterPair( rFilter, rFilterWithExtension ) );
-
-}
-
-OUString FileDialogHelper_Impl::getFilterName( const OUString& rFilterWithExtension ) const
-{
- OUString sRet;
- for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
- {
- if ( (*pIter).Second == rFilterWithExtension )
- {
- sRet = (*pIter).First;
- break;
- }
- }
- return sRet;
-}
-
-OUString FileDialogHelper_Impl::getFilterWithExtension( const OUString& rFilter ) const
-{
- OUString sRet;
- for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
- {
- if ( (*pIter).First == rFilter )
- {
- sRet = (*pIter).Second;
- break;
- }
- }
- return sRet;
-}
-
-void FileDialogHelper_Impl::SetContext( FileDialogHelper::Context _eNewContext )
-{
- meContext = _eNewContext;
-
- sal_Int32 nNewHelpId = 0;
- OUString aConfigId;
-
- switch( _eNewContext )
- {
-// #104952# dependency to SVX not allowed! When used again, another solution has to be found
-// case FileDialogHelper::SW_INSERT_GRAPHIC:
-// case FileDialogHelper::SC_INSERT_GRAPHIC:
-// case FileDialogHelper::SD_INSERT_GRAPHIC: nNewHelpId = SID_INSERT_GRAPHIC; break;
- case FileDialogHelper::SW_INSERT_SOUND:
- case FileDialogHelper::SC_INSERT_SOUND:
- case FileDialogHelper::SD_INSERT_SOUND: nNewHelpId = SID_INSERT_SOUND; break;
- case FileDialogHelper::SW_INSERT_VIDEO:
- case FileDialogHelper::SC_INSERT_VIDEO:
- case FileDialogHelper::SD_INSERT_VIDEO: nNewHelpId = SID_INSERT_VIDEO; break;
- default: break;
- }
-
- const OUString* pConfigId = GetLastFilterConfigId( _eNewContext );
- if( pConfigId )
- LoadLastUsedFilter( *pConfigId );
-
-// if( nNewHelpId )
-// this->setDialogHelpId( nNewHelpId );
-}
-
-// ------------------------------------------------------------------------
-// ----------- FileDialogHelper ---------------------------
-// ------------------------------------------------------------------------
-
-FileDialogHelper::FileDialogHelper(
- sal_Int64 nFlags,
- const String& rFact,
- SfxFilterFlags nMust,
- SfxFilterFlags nDont )
-{
- mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags );
- mxImp = mpImp;
-
- // create the list of filters
- mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
-}
-
-FileDialogHelper::FileDialogHelper(
- sal_Int64 nFlags,
- const String& rFact,
- sal_Int16 nDialog,
- SfxFilterFlags nMust,
- SfxFilterFlags nDont,
- const String& rStandardDir,
- const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
-{
- mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags, nDialog, NULL , rStandardDir, rBlackList );
- mxImp = mpImp;
-
- // create the list of filters
- mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
-}
-
-FileDialogHelper::FileDialogHelper(
- sal_Int64 nFlags,
- const String& rFact,
- sal_Int16 nDialog,
- SfxFilterFlags nMust,
- SfxFilterFlags nDont )
-{
- mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags, nDialog );
- mxImp = mpImp;
-
- // create the list of filters
- mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
-}
-
-// ------------------------------------------------------------------------
-FileDialogHelper::FileDialogHelper( sal_Int64 nFlags )
-{
- sal_Int16 nDialogType = getDialogType( nFlags );
-
- mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags );
- mxImp = mpImp;
-}
-
-// ------------------------------------------------------------------------
-FileDialogHelper::FileDialogHelper(
- sal_Int16 nDialogType,
- sal_Int64 nFlags,
- const String& rFact,
- SfxFilterFlags nMust,
- SfxFilterFlags nDont )
-{
- mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags );
- mxImp = mpImp;
-
- // create the list of filters
- mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
-}
-
-// ------------------------------------------------------------------------
-FileDialogHelper::FileDialogHelper(
- sal_Int16 nDialogType,
- sal_Int64 nFlags,
- const String& rFact,
- sal_Int16 nDialog,
- SfxFilterFlags nMust,
- SfxFilterFlags nDont,
- const String& rStandardDir,
- const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
-{
- mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, nDialog, NULL, rStandardDir, rBlackList );
- mxImp = mpImp;
-
- // create the list of filters
- mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
-}
-
-// ------------------------------------------------------------------------
-FileDialogHelper::FileDialogHelper(
- sal_Int16 nDialogType,
- sal_Int64 nFlags,
- Window* _pPreferredParent )
-{
- mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent );
- mxImp = mpImp;
-}
-
-// ------------------------------------------------------------------------
-FileDialogHelper::FileDialogHelper(
- sal_Int16 nDialogType,
- sal_Int64 nFlags,
- const ::rtl::OUString& aFilterUIName,
- const ::rtl::OUString& aExtName,
- const ::rtl::OUString& rStandardDir,
- const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList,
- Window* _pPreferredParent )
-{
- mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent,rStandardDir, rBlackList );
- mxImp = mpImp;
-
- // the wildcard here is expected in form "*.extension"
- ::rtl::OUString aWildcard;
- if ( aExtName.indexOf( (sal_Unicode)'*' ) != 0 )
- {
- if ( aExtName.getLength() && aExtName.indexOf( (sal_Unicode)'.' ) != 0 )
- aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*." ) );
- else
- aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*" ) );
- }
-
- aWildcard += aExtName;
-
- ::rtl::OUString aUIString =
- ::sfx2::addExtension( aFilterUIName, aWildcard, ( WB_OPEN == ( nFlags & WB_OPEN ) ), *mpImp );
- AddFilter( aUIString, aWildcard );
-}
-
-// ------------------------------------------------------------------------
-FileDialogHelper::~FileDialogHelper()
-{
- mpImp->dispose();
- mxImp.clear();
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper::CreateMatcher( const String& rFactory )
-{
- mpImp->createMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper::SetControlHelpIds( const sal_Int16* _pControlId, const sal_Int32* _pHelpId )
-{
- mpImp->setControlHelpIds( _pControlId, _pHelpId );
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper::SetDialogHelpId( const sal_Int32 _nHelpId )
-{
- mpImp->setDialogHelpId( _nHelpId );
-}
-
-void FileDialogHelper::SetContext( Context _eNewContext )
-{
- mpImp->SetContext( _eNewContext );
-}
-
-// ------------------------------------------------------------------------
-IMPL_LINK( FileDialogHelper, ExecuteSystemFilePicker, void*, EMPTYARG )
-{
- m_nError = mpImp->execute();
- if ( m_aDialogClosedLink.IsSet() )
- m_aDialogClosedLink.Call( this );
-
- return 0L;
-}
-
-// ------------------------------------------------------------------------
-// rDirPath has to be a directory
-ErrCode FileDialogHelper::Execute( SvStringsDtor*& rpURLList,
- SfxItemSet *& rpSet,
- String& rFilter,
- const String& rDirPath )
-{
- SetDisplayFolder( rDirPath );
- return mpImp->execute( rpURLList, rpSet, rFilter );
-}
-
-
-// ------------------------------------------------------------------------
-ErrCode FileDialogHelper::Execute()
-{
- return mpImp->execute();
-}
-
-// ------------------------------------------------------------------------
-ErrCode FileDialogHelper::Execute( SfxItemSet *& rpSet,
- String& rFilter )
-{
- ErrCode nRet;
- SvStringsDtor* pURLList;
-
- nRet = mpImp->execute( pURLList, rpSet, rFilter );
-
- delete pURLList;
-
- return nRet;
-}
-
-void FileDialogHelper::StartExecuteModal( const Link& rEndDialogHdl )
-{
- m_aDialogClosedLink = rEndDialogHdl;
- m_nError = ERRCODE_NONE;
- if ( mpImp->isSystemFilePicker() )
- Application::PostUserEvent( LINK( this, FileDialogHelper, ExecuteSystemFilePicker ) );
- else
- mpImp->implStartExecute();
-}
-
-// ------------------------------------------------------------------------
-
-short FileDialogHelper::GetDialogType() const
-{
- return mpImp ? mpImp->m_nDialogType : 0;
-}
-
-// ------------------------------------------------------------------------
-
-sal_Bool FileDialogHelper::IsPasswordEnabled() const
-{
- return mpImp ? mpImp->isPasswordEnabled() : sal_False;
-}
-
-// ------------------------------------------------------------------------
-
-String FileDialogHelper::GetRealFilter() const
-{
- String sFilter;
- if ( mpImp )
- mpImp->getRealFilter( sFilter );
- return sFilter;
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper::SetTitle( const String& rNewTitle )
-{
- if ( mpImp->mxFileDlg.is() )
- mpImp->mxFileDlg->setTitle( rNewTitle );
-}
-
-// ------------------------------------------------------------------------
-String FileDialogHelper::GetPath() const
-{
- OUString aPath;
-
- if ( mpImp->mlLastURLs.size() > 0)
- return mpImp->mlLastURLs[0];
-
- if ( mpImp->mxFileDlg.is() )
- {
- Sequence < OUString > aPathSeq = mpImp->mxFileDlg->getFiles();
-
- if ( aPathSeq.getLength() == 1 )
- {
- aPath = aPathSeq[0];
- }
- }
-
- return aPath;
-}
-
-// ------------------------------------------------------------------------
-Sequence < OUString > FileDialogHelper::GetMPath() const
-{
- if ( mpImp->mlLastURLs.size() > 0)
- return mpImp->mlLastURLs.getAsConstList();
-
- if ( mpImp->mxFileDlg.is() )
- return mpImp->mxFileDlg->getFiles();
- else
- {
- Sequence < OUString > aEmpty;
- return aEmpty;
- }
-}
-
-// ------------------------------------------------------------------------
-Sequence< ::rtl::OUString > FileDialogHelper::GetSelectedFiles() const
-{
- // a) the new way (optional!)
- uno::Sequence< ::rtl::OUString > aResultSeq;
- uno::Reference< XFilePicker2 > xPickNew(mpImp->mxFileDlg, UNO_QUERY);
- if (xPickNew.is())
- {
- aResultSeq = xPickNew->getSelectedFiles();
- }
- // b) the olde way ... non optional.
- else
- {
- uno::Reference< XFilePicker > xPickOld(mpImp->mxFileDlg, UNO_QUERY_THROW);
- Sequence< OUString > lFiles = xPickOld->getFiles();
- ::sal_Int32 nFiles = lFiles.getLength();
- if ( nFiles > 1 )
- {
- aResultSeq = Sequence< ::rtl::OUString >( nFiles-1 );
-
- INetURLObject aPath( lFiles[0] );
- aPath.setFinalSlash();
-
- for (::sal_Int32 i = 1; i < nFiles; i++)
- {
- if (i == 1)
- aPath.Append( lFiles[i] );
- else
- aPath.setName( lFiles[i] );
-
- aResultSeq[i-1] = ::rtl::OUString(aPath.GetMainURL( INetURLObject::NO_DECODE ));
- }
- }
- else
- aResultSeq = lFiles;
- }
-
- return aResultSeq;
-}
-
-// ------------------------------------------------------------------------
-String FileDialogHelper::GetDisplayDirectory() const
-{
- return mpImp->getPath();
-}
-
-// ------------------------------------------------------------------------
-String FileDialogHelper::GetCurrentFilter() const
-{
- return mpImp->getFilter();
-}
-
-// ------------------------------------------------------------------------
-ErrCode FileDialogHelper::GetGraphic( Graphic& rGraphic ) const
-{
- return mpImp->getGraphic( rGraphic );
-}
-
-// ------------------------------------------------------------------------
-static int impl_isFolder( const OUString& rPath )
-{
- uno::Reference< task::XInteractionHandler > xHandler;
- try
- {
- uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
- xHandler.set( xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.task.InteractionHandler" ) ),
- uno::UNO_QUERY_THROW );
- }
- catch ( Exception const & )
- {
- }
-
- ::rtl::Reference< ::comphelper::StillReadWriteInteraction > aHandler = new ::comphelper::StillReadWriteInteraction( xHandler );
-
- try
- {
- ::ucbhelper::Content aContent(
- rPath, new ::ucbhelper::CommandEnvironment( static_cast< task::XInteractionHandler* > ( aHandler.get() ), uno::Reference< ucb::XProgressHandler >() ) );
- if ( aContent.isFolder() )
- return 1;
-
- return 0;
- }
- catch ( Exception const & )
- {
- }
-
- return -1;
-}
-
-void FileDialogHelper::SetDisplayDirectory( const String& _rPath )
-{
- if ( !_rPath.Len() )
- return;
-
- // if the given path isn't a folder, we cut off the last part
- // and take it as filename and the rest of the path should be
- // the folder
-
- INetURLObject aObj( _rPath );
-
- ::rtl::OUString sFileName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET );
- aObj.removeSegment();
- ::rtl::OUString sPath = aObj.GetMainURL( INetURLObject::NO_DECODE );
-
- int nIsFolder = impl_isFolder( _rPath );
- if ( nIsFolder == 0 ||
- ( nIsFolder == -1 && impl_isFolder( sPath ) == 1 ) )
- {
- mpImp->setFileName( sFileName );
- mpImp->displayFolder( sPath );
- }
- else
- {
- INetURLObject aObjPathName( _rPath );
- ::rtl::OUString sFolder( aObjPathName.GetMainURL( INetURLObject::NO_DECODE ) );
- if ( sFolder.getLength() == 0 )
- {
- // _rPath is not a valid path -> fallback to home directory
- NAMESPACE_VOS( OSecurity ) aSecurity;
- aSecurity.getHomeDir( sFolder );
- }
- mpImp->displayFolder( sFolder );
- }
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper::SetDisplayFolder( const String& _rURL )
-{
- mpImp->displayFolder( _rURL );
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper::SetFileName( const String& _rFileName )
-{
- mpImp->setFileName( _rFileName );
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper::AddFilter( const String& rFilterName,
- const String& rExtension )
-{
- mpImp->addFilter( rFilterName, rExtension );
-}
-
-// ------------------------------------------------------------------------
-void FileDialogHelper::SetCurrentFilter( const String& rFilter )
-{
- String sFilter( rFilter );
- if ( mpImp->isShowFilterExtensionEnabled() )
- sFilter = mpImp->getFilterWithExtension( rFilter );
- mpImp->setFilter( sFilter );
-}
-
-// ------------------------------------------------------------------------
-uno::Reference < XFilePicker > FileDialogHelper::GetFilePicker() const
-{
- return mpImp->mxFileDlg;
-}
-
-// ------------------------------------------------------------------------
-sal_Int16 FileDialogHelper::getDialogType( sal_Int64 nFlags ) const
-{
- sal_Int16 nDialogType = FILEOPEN_SIMPLE;
-
- if ( nFlags & WB_SAVEAS )
- {
- if ( nFlags & SFXWB_PASSWORD )
- nDialogType = FILESAVE_AUTOEXTENSION_PASSWORD;
- else
- nDialogType = FILESAVE_SIMPLE;
- }
- else if ( nFlags & SFXWB_GRAPHIC )
- {
- if ( nFlags & SFXWB_SHOWSTYLES )
- nDialogType = FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE;
- else
- nDialogType = FILEOPEN_LINK_PREVIEW;
- }
- else if ( SFXWB_INSERT != ( nFlags & SFXWB_INSERT ) )
- nDialogType = FILEOPEN_READONLY_VERSION;
-
- return nDialogType;
-}
-
-// ------------------------------------------------------------------------
-// XFilePickerListener Methods
-// ------------------------------------------------------------------------
-void SAL_CALL FileDialogHelper::FileSelectionChanged( const FilePickerEvent& aEvent )
-{
- mpImp->handleFileSelectionChanged( aEvent );
-}
-
-// ------------------------------------------------------------------------
-void SAL_CALL FileDialogHelper::DirectoryChanged( const FilePickerEvent& aEvent )
-{
- mpImp->handleDirectoryChanged( aEvent );
-}
-
-// ------------------------------------------------------------------------
-OUString SAL_CALL FileDialogHelper::HelpRequested( const FilePickerEvent& aEvent )
-{
- return mpImp->handleHelpRequested( aEvent );
-}
-
-// ------------------------------------------------------------------------
-void SAL_CALL FileDialogHelper::ControlStateChanged( const FilePickerEvent& aEvent )
-{
- mpImp->handleControlStateChanged( aEvent );
-}
-
-// ------------------------------------------------------------------------
-void SAL_CALL FileDialogHelper::DialogSizeChanged()
-{
- mpImp->handleDialogSizeChanged();
-}
-
-// ------------------------------------------------------------------------
-void SAL_CALL FileDialogHelper::DialogClosed( const DialogClosedEvent& _rEvent )
-{
- m_nError = ( RET_OK == _rEvent.DialogResult ) ? ERRCODE_NONE : ERRCODE_ABORT;
- if ( m_aDialogClosedLink.IsSet() )
- m_aDialogClosedLink.Call( this );
-}
-
-// ------------------------------------------------------------------------
-// ------------------------------------------------------------------------
-// ------------------------------------------------------------------------
-
-ErrCode FileOpenDialog_Impl( sal_Int64 nFlags,
- const String& rFact,
- SvStringsDtor *& rpURLList,
- String& rFilter,
- SfxItemSet *& rpSet,
- const String* pPath,
- sal_Int16 nDialog,
- const String& rStandardDir,
- const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList )
-{
- ErrCode nRet;
- FileDialogHelper aDialog( nFlags, rFact, nDialog, 0, 0, rStandardDir, rBlackList );
-
- String aPath;
- if ( pPath )
- aPath = *pPath;
-
- nRet = aDialog.Execute( rpURLList, rpSet, rFilter, aPath );
- DBG_ASSERT( rFilter.SearchAscii(": ") == STRING_NOTFOUND, "Old filter name used!");
-
- return nRet;
-}
-
-
-// ------------------------------------------------------------------------
-String EncodeSpaces_Impl( const String& rSource )
-{
- String sRet( rSource );
- sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( " " ), DEFINE_CONST_UNICODE( "%20" ) );
- return sRet;
-}
-
-// ------------------------------------------------------------------------
-String DecodeSpaces_Impl( const String& rSource )
-{
- String sRet( rSource );
- sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( "%20" ), DEFINE_CONST_UNICODE( " " ) );
- return sRet;
-}
-
-// ------------------------------------------------------------------------
-
-} // end of namespace sfx2
-
+/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" +#include <sfx2/filedlghelper.hxx> +#include <sal/types.h> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> +#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> +#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> +#include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp> +#include <com/sun/star/ui/dialogs/ControlActions.hpp> +#include <com/sun/star/ui/dialogs/TemplateDescription.hpp> +#include <com/sun/star/ui/dialogs/XControlInformation.hpp> +#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> +#include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp> +#include <com/sun/star/ui/dialogs/XFilePreview.hpp> +#include <com/sun/star/ui/dialogs/XFilterManager.hpp> +#include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp> +#include <com/sun/star/ui/dialogs/XFolderPicker.hpp> +#include <com/sun/star/ui/dialogs/XFilePicker2.hpp> +#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/container/XContainerQuery.hpp> +#include <com/sun/star/task/XInteractionRequest.hpp> +#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp> + +#include <comphelper/processfactory.hxx> +#include <comphelper/types.hxx> +#include <comphelper/sequenceashashmap.hxx> +#include <comphelper/stillreadwriteinteraction.hxx> +#include <tools/urlobj.hxx> +#include <vcl/help.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <unotools/ucbhelper.hxx> +#include <unotools/localfilehelper.hxx> +#include <vos/thread.hxx> +#include <vos/mutex.hxx> +#include <vos/security.hxx> +#include <vcl/cvtgrf.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/mnemonic.hxx> +#include <unotools/pathoptions.hxx> +#include <unotools/securityoptions.hxx> +#include <svl/itemset.hxx> +#include <svl/eitem.hxx> +#include <svl/intitem.hxx> +#include <svl/stritem.hxx> +#include <svtools/filter.hxx> +#include <unotools/viewoptions.hxx> +#include <unotools/moduleoptions.hxx> +#include <svtools/helpid.hrc> +#include <svl/pickerhelper.hxx> +#include <comphelper/docpasswordrequest.hxx> +#include <comphelper/docpasswordhelper.hxx> +#include <ucbhelper/content.hxx> +#include <ucbhelper/commandenvironment.hxx> +#include <comphelper/storagehelper.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <sfx2/app.hxx> +#include <sfx2/frame.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/docfac.hxx> +#include "openflag.hxx" +#include <sfx2/passwd.hxx> +#include "sfxresid.hxx" +#include <sfx2/sfxsids.hrc> +#include "filedlghelper.hrc" +#include "filtergrouping.hxx" +#include <sfx2/request.hxx> +#include "filedlgimpl.hxx" + +#include <sfxlocal.hrc> + +//----------------------------------------------------------------------------- + +using namespace ::com::sun::star; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::ui::dialogs; +using namespace ::com::sun::star::ui::dialogs::TemplateDescription; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::rtl; +using namespace ::cppu; + +//----------------------------------------------------------------------------- + +#define IODLG_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Save")) +#define IMPGRF_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Graph")) +#define USERITEM_NAME ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "UserItem" )) + +//----------------------------------------------------------------------------- + +namespace sfx2 +{ + +const OUString* GetLastFilterConfigId( FileDialogHelper::Context _eContext ) +{ + static const OUString aSD_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SdExportLastFilter" ) ); + static const OUString aSI_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SiExportLastFilter" ) ); + static const OUString aSW_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SwExportLastFilter" ) ); + + const OUString* pRet = NULL; + + switch( _eContext ) + { + case FileDialogHelper::SD_EXPORT: pRet = &aSD_EXPORT_IDENTIFIER; break; + case FileDialogHelper::SI_EXPORT: pRet = &aSI_EXPORT_IDENTIFIER; break; + case FileDialogHelper::SW_EXPORT: pRet = &aSW_EXPORT_IDENTIFIER; break; + default: break; + } + + return pRet; +} + +String EncodeSpaces_Impl( const String& rSource ); +String DecodeSpaces_Impl( const String& rSource ); + +// ------------------------------------------------------------------------ +// ----------- FileDialogHelper_Impl --------------------------- +// ------------------------------------------------------------------------ + +// ------------------------------------------------------------------------ +// XFilePickerListener Methods +// ------------------------------------------------------------------------ +void SAL_CALL FileDialogHelper_Impl::fileSelectionChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException ) +{ + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + mpAntiImpl->FileSelectionChanged( aEvent ); +} + +// ------------------------------------------------------------------------ +void SAL_CALL FileDialogHelper_Impl::directoryChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException ) +{ + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + mpAntiImpl->DirectoryChanged( aEvent ); +} + +// ------------------------------------------------------------------------ +OUString SAL_CALL FileDialogHelper_Impl::helpRequested( const FilePickerEvent& aEvent ) throw ( RuntimeException ) +{ + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + return mpAntiImpl->HelpRequested( aEvent ); +} + +// ------------------------------------------------------------------------ +void SAL_CALL FileDialogHelper_Impl::controlStateChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException ) +{ + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + mpAntiImpl->ControlStateChanged( aEvent ); +} + +// ------------------------------------------------------------------------ +void SAL_CALL FileDialogHelper_Impl::dialogSizeChanged() throw ( RuntimeException ) +{ + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + mpAntiImpl->DialogSizeChanged(); +} + +// ------------------------------------------------------------------------ +// XDialogClosedListener Methods +// ------------------------------------------------------------------------ +void SAL_CALL FileDialogHelper_Impl::dialogClosed( const DialogClosedEvent& _rEvent ) throw ( RuntimeException ) +{ + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + mpAntiImpl->DialogClosed( _rEvent ); + postExecute( _rEvent.DialogResult ); +} + +// ------------------------------------------------------------------------ +// handle XFilePickerListener events +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::handleFileSelectionChanged( const FilePickerEvent& ) +{ + if ( mbHasVersions ) + updateVersions(); + + if ( mbShowPreview ) + maPreViewTimer.Start(); +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::handleDirectoryChanged( const FilePickerEvent& ) +{ + if ( mbShowPreview ) + TimeOutHdl_Impl( NULL ); +} + +// ------------------------------------------------------------------------ +OUString FileDialogHelper_Impl::handleHelpRequested( const FilePickerEvent& aEvent ) +{ + //!!! todo: cache the help strings (here or TRA) + + ULONG nHelpId = 0; + // mapping from element id -> help id + switch ( aEvent.ElementId ) + { + case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION : + nHelpId = HID_FILESAVE_AUTOEXTENSION; + break; + + case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD : + nHelpId = HID_FILESAVE_SAVEWITHPASSWORD; + break; + + case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS : + nHelpId = HID_FILESAVE_CUSTOMIZEFILTER; + break; + + case ExtendedFilePickerElementIds::CHECKBOX_READONLY : + nHelpId = HID_FILEOPEN_READONLY; + break; + + case ExtendedFilePickerElementIds::CHECKBOX_LINK : + nHelpId = HID_FILEDLG_LINK_CB; + break; + + case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW : + nHelpId = HID_FILEDLG_PREVIEW_CB; + break; + + case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY : + nHelpId = HID_FILESAVE_DOPLAY; + break; + + case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL : + case ExtendedFilePickerElementIds::LISTBOX_VERSION : + nHelpId = HID_FILEOPEN_VERSION; + break; + + case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL : + case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE : + nHelpId = HID_FILESAVE_TEMPLATE; + break; + + case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL : + case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE : + nHelpId = HID_FILEOPEN_IMAGE_TEMPLATE; + break; + + case ExtendedFilePickerElementIds::CHECKBOX_SELECTION : + nHelpId = HID_FILESAVE_SELECTION; + break; + + default: + DBG_ERRORFILE( "invalid element id" ); + } + + OUString aHelpText; + Help* pHelp = Application::GetHelp(); + if ( pHelp ) + aHelpText = String( pHelp->GetHelpText( nHelpId, NULL ) ); + return aHelpText; +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::handleControlStateChanged( const FilePickerEvent& aEvent ) +{ + switch ( aEvent.ElementId ) + { + case CommonFilePickerElementIds::LISTBOX_FILTER: + updateFilterOptionsBox(); + enablePasswordBox( sal_False ); + updateSelectionBox(); + // only use it for export and with our own dialog + if ( mbExport && !mbSystemPicker ) + updateExportButton(); + break; + + case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW: + updatePreviewState(); + break; + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::handleDialogSizeChanged() +{ + if ( mbShowPreview ) + TimeOutHdl_Impl( NULL ); +} + +// ------------------------------------------------------------------------ +// XEventListener Methods +// ------------------------------------------------------------------------ +void SAL_CALL FileDialogHelper_Impl::disposing( const EventObject& ) throw ( RuntimeException ) +{ + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + dispose(); +} + +// ------------------------------------------------------------------------ +// ------------------------------------------------------------------------ +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::dispose() +{ + if ( mxFileDlg.is() ) + { + // remove the event listener + uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY ); + if ( xNotifier.is() ) + xNotifier->removeFilePickerListener( this ); + + ::comphelper::disposeComponent( mxFileDlg ); + mxFileDlg.clear(); + } +} + +// ------------------------------------------------------------------------ +String FileDialogHelper_Impl::getCurrentFilterUIName() const +{ + String aFilterName; + uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY ); + + if( xFltMgr.is() ) + { + aFilterName = xFltMgr->getCurrentFilter(); + + if ( aFilterName.Len() && isShowFilterExtensionEnabled() ) + aFilterName = getFilterName( aFilterName ); + } + + return aFilterName; +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::LoadLastUsedFilter( const OUString& _rContextIdentifier ) +{ + SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME ); + + if( aDlgOpt.Exists() ) + { + OUString aLastFilter; + if( aDlgOpt.GetUserItem( _rContextIdentifier ) >>= aLastFilter ) + setFilter( aLastFilter ); + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::SaveLastUsedFilter( const OUString& _rContextIdentifier ) +{ + SvtViewOptions( E_DIALOG, IODLG_CONFIGNAME ).SetUserItem( _rContextIdentifier, + makeAny( getFilterWithExtension( getFilter() ) ) ); +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::SaveLastUsedFilter( void ) +{ + const OUString* pConfigId = GetLastFilterConfigId( meContext ); + if( pConfigId ) + SaveLastUsedFilter( *pConfigId ); +} + +// ------------------------------------------------------------------------ +const SfxFilter* FileDialogHelper_Impl::getCurentSfxFilter() +{ + String aFilterName = getCurrentFilterUIName(); + + const SfxFilter* pFilter = NULL; + if ( mpMatcher && aFilterName.Len() ) + pFilter = mpMatcher->GetFilter4UIName( aFilterName, m_nMustFlags, m_nDontFlags ); + + return pFilter; +} + +// ------------------------------------------------------------------------ +sal_Bool FileDialogHelper_Impl::updateExtendedControl( sal_Int16 _nExtendedControlId, sal_Bool _bEnable ) +{ + sal_Bool bIsEnabled = sal_False; + + uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); + if ( xCtrlAccess.is() ) + { + try + { + xCtrlAccess->enableControl( _nExtendedControlId, _bEnable ); + bIsEnabled = _bEnable; + } + catch( const IllegalArgumentException& ) + { + DBG_ERROR( "FileDialogHelper_Impl::updateExtendedControl: caught an exception!" ); + } + } + return bIsEnabled; +} + +// ------------------------------------------------------------------------ +sal_Bool FileDialogHelper_Impl::CheckFilterOptionsCapability( const SfxFilter* _pFilter ) +{ + sal_Bool bResult = sal_False; + + if( mxFilterCFG.is() && _pFilter ) + { + try { + Sequence < PropertyValue > aProps; + Any aAny = mxFilterCFG->getByName( _pFilter->GetName() ); + if ( aAny >>= aProps ) + { + ::rtl::OUString aServiceName; + sal_Int32 nPropertyCount = aProps.getLength(); + for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty ) + { + if( aProps[nProperty].Name.equals( DEFINE_CONST_OUSTRING( "UIComponent") ) ) + { + aProps[nProperty].Value >>= aServiceName; + if( aServiceName.getLength() ) + bResult = sal_True; + } + } + } + } + catch( Exception& ) + { + } + } + + return bResult; +} + +// ------------------------------------------------------------------------ +sal_Bool FileDialogHelper_Impl::isInOpenMode() const +{ + sal_Bool bRet = sal_False; + + switch ( m_nDialogType ) + { + case FILEOPEN_SIMPLE: + case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE: + case FILEOPEN_PLAY: + case FILEOPEN_READONLY_VERSION: + case FILEOPEN_LINK_PREVIEW: + bRet = sal_True; + } + + return bRet; +} + +// ------------------------------------------------------------------------ + +void FileDialogHelper_Impl::updateFilterOptionsBox() +{ + if ( !m_bHaveFilterOptions ) + return; + + updateExtendedControl( + ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS, + CheckFilterOptionsCapability( getCurentSfxFilter() ) + ); +} + +// ------------------------------------------------------------------------ + +void FileDialogHelper_Impl::updateExportButton() +{ + uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); + if ( xCtrlAccess.is() ) + { + OUString sEllipses( RTL_CONSTASCII_USTRINGPARAM( "..." ) ); + OUString sOldLabel( xCtrlAccess->getLabel( CommonFilePickerElementIds::PUSHBUTTON_OK ) ); + + // initialize button label; we need the label with the mnemonic char + if ( !maButtonLabel.getLength() || maButtonLabel.indexOf( MNEMONIC_CHAR ) == -1 ) + { + // cut the ellipses, if necessary + sal_Int32 nIndex = sOldLabel.indexOf( sEllipses ); + if ( -1 == nIndex ) + nIndex = sOldLabel.getLength(); + maButtonLabel = sOldLabel.copy( 0, nIndex ); + } + + OUString sLabel = maButtonLabel; + // filter with options -> append ellipses on export button label + if ( CheckFilterOptionsCapability( getCurentSfxFilter() ) ) + sLabel += OUString( RTL_CONSTASCII_USTRINGPARAM( "..." ) ); + + if ( sOldLabel != sLabel ) + { + try + { + xCtrlAccess->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK, sLabel ); + } + catch( const IllegalArgumentException& ) + { + DBG_ERRORFILE( "FileDialogHelper_Impl::updateExportButton: caught an exception!" ); + } + } + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::updateSelectionBox() +{ + if ( !mbHasSelectionBox ) + return; + + // Does the selection box exist? + sal_Bool bSelectionBoxFound = sal_False; + uno::Reference< XControlInformation > xCtrlInfo( mxFileDlg, UNO_QUERY ); + if ( xCtrlInfo.is() ) + { + Sequence< ::rtl::OUString > aCtrlList = xCtrlInfo->getSupportedControls(); + sal_uInt32 nCount = aCtrlList.getLength(); + for ( sal_uInt32 nCtrl = 0; nCtrl < nCount; ++nCtrl ) + if ( aCtrlList[ nCtrl ].equalsAscii("SelectionBox") ) + { + bSelectionBoxFound = sal_False; + break; + } + } + + if ( bSelectionBoxFound ) + { + const SfxFilter* pFilter = getCurentSfxFilter(); + mbSelectionFltrEnabled = updateExtendedControl( + ExtendedFilePickerElementIds::CHECKBOX_SELECTION, + ( mbSelectionEnabled && pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_SUPPORTSSELECTION ) != 0 ) ); + uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); + xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, makeAny( (sal_Bool)mbSelection ) ); + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::enablePasswordBox( sal_Bool bInit ) +{ + if ( ! mbHasPassword ) + return; + + sal_Bool bWasEnabled = mbIsPwdEnabled; + + const SfxFilter* pCurrentFilter = getCurentSfxFilter(); + mbIsPwdEnabled = updateExtendedControl( + ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, + pCurrentFilter && ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_ENCRYPTION ) + ); + + if( bInit ) + { + // in case of inintialization previous state is not interesting + if( mbIsPwdEnabled ) + { + uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); + if( mbPwdCheckBoxState ) + xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) ); + } + } + else if( !bWasEnabled && mbIsPwdEnabled ) + { + uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); + if( mbPwdCheckBoxState ) + xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) ); + } + else if( bWasEnabled && !mbIsPwdEnabled ) + { + // remember user settings until checkbox is enabled + uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); + Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 ); + sal_Bool bPassWord = sal_False; + mbPwdCheckBoxState = ( aValue >>= bPassWord ) && bPassWord; + xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_False ) ); + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::updatePreviewState( sal_Bool _bUpdatePreviewWindow ) +{ + if ( mbHasPreview ) + { + uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); + + // check, wether or not we have to display a preview + if ( xCtrlAccess.is() ) + { + try + { + Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 ); + sal_Bool bShowPreview = sal_False; + + if ( aValue >>= bShowPreview ) + { + mbShowPreview = bShowPreview; + + // #97633 + // setShowState has currently no effect for the + // OpenOffice FilePicker (see svtools/source/filepicker/iodlg.cxx) + uno::Reference< XFilePreview > xFilePreview( mxFileDlg, UNO_QUERY ); + if ( xFilePreview.is() ) + xFilePreview->setShowState( mbShowPreview ); + + if ( _bUpdatePreviewWindow ) + TimeOutHdl_Impl( NULL ); + } + } + catch( Exception ) + { + DBG_ERRORFILE( "FileDialogHelper_Impl::updatePreviewState: caught an exception!" ); + } + } + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::updateVersions() +{ + Sequence < OUString > aEntries; + Sequence < OUString > aPathSeq = mxFileDlg->getFiles(); + + if ( aPathSeq.getLength() == 1 ) + { + INetURLObject aObj( aPathSeq[0] ); + + if ( ( aObj.GetProtocol() == INET_PROT_FILE ) && + ( utl::UCBContentHelper::IsDocument( aObj.GetMainURL( INetURLObject::NO_DECODE ) ) ) ) + { + try + { + uno::Reference< embed::XStorage > xStorage = ::comphelper::OStorageHelper::GetStorageFromURL( + aObj.GetMainURL( INetURLObject::NO_DECODE ), + embed::ElementModes::READ ); + + DBG_ASSERT( xStorage.is(), "The method must return the storage or throw an exception!" ); + if ( !xStorage.is() ) + throw uno::RuntimeException(); + + uno::Sequence < util::RevisionTag > xVersions = SfxMedium::GetVersionList( xStorage ); + + aEntries.realloc( xVersions.getLength() + 1 ); + aEntries[0] = OUString( String ( SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ) ) ); + + for ( sal_Int32 i=0; i<xVersions.getLength(); i++ ) + aEntries[ i + 1 ] = xVersions[i].Identifier; + + // TODO/LATER: not sure that this information must be shown in future ( binfilter? ) +//REMOVE else +//REMOVE { +//REMOVE SfxFilterFlags nMust = SFX_FILTER_IMPORT | SFX_FILTER_OWN; +//REMOVE SfxFilterFlags nDont = SFX_FILTER_NOTINSTALLED | SFX_FILTER_STARONEFILTER; +//REMOVE if ( SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( pStor->GetFormat(), nMust, nDont ) ) +//REMOVE { +//REMOVE aEntries.realloc( 1 ); +//REMOVE aEntries[0] = OUString( String ( SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ) ) ); +//REMOVE } +//REMOVE } + } + catch( uno::Exception& ) + { + } + } + } + + uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY ); + Any aValue; + + try + { + xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION, + ControlActions::DELETE_ITEMS, aValue ); + } + catch( IllegalArgumentException ){} + + sal_Int32 nCount = aEntries.getLength(); + + if ( nCount ) + { + try + { + aValue <<= aEntries; + xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION, + ControlActions::ADD_ITEMS, aValue ); + + Any aPos; + aPos <<= (sal_Int32) 0; + xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION, + ControlActions::SET_SELECT_ITEM, aPos ); + } + catch( IllegalArgumentException ){} + } +} + +// ----------------------------------------------------------------------- +class OReleaseSolarMutex +{ +private: + const sal_Int32 m_nAquireCount; +public: + OReleaseSolarMutex( ) + :m_nAquireCount( Application::ReleaseSolarMutex() ) + { + } + ~OReleaseSolarMutex( ) + { + Application::AcquireSolarMutex( m_nAquireCount ); + } +}; + +// ----------------------------------------------------------------------- +IMPL_LINK( FileDialogHelper_Impl, TimeOutHdl_Impl, Timer*, EMPTYARG ) +{ + if ( !mbHasPreview ) + return 0; + + maGraphic.Clear(); + + Any aAny; + uno::Reference < XFilePreview > xFilePicker( mxFileDlg, UNO_QUERY ); + + if ( ! xFilePicker.is() ) + return 0; + + Sequence < OUString > aPathSeq = mxFileDlg->getFiles(); + + if ( mbShowPreview && ( aPathSeq.getLength() == 1 ) ) + { + OUString aURL = aPathSeq[0]; + + if ( ERRCODE_NONE == getGraphic( aURL, maGraphic ) ) + { + // #89491 + // changed the code slightly; + // before: the bitmap was scaled and + // surrounded a white frame + // now: the bitmap will only be scaled + // and the filepicker implementation + // is responsible for placing it at its + // proper position and painting a frame + + Bitmap aBmp = maGraphic.GetBitmap(); + + // scale the bitmap to the correct size + sal_Int32 nOutWidth = xFilePicker->getAvailableWidth(); + sal_Int32 nOutHeight = xFilePicker->getAvailableHeight(); + sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width(); + sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height(); + + double nXRatio = (double) nOutWidth / nBmpWidth; + double nYRatio = (double) nOutHeight / nBmpHeight; + + if ( nXRatio < nYRatio ) + aBmp.Scale( nXRatio, nXRatio ); + else + aBmp.Scale( nYRatio, nYRatio ); + + // #94505# Convert to true color, to allow CopyPixel + aBmp.Convert( BMP_CONVERSION_24BIT ); + + // and copy it into the Any + SvMemoryStream aData; + + aData << aBmp; + + const Sequence < sal_Int8 > aBuffer( + static_cast< const sal_Int8* >(aData.GetData()), + aData.GetEndOfData() ); + + aAny <<= aBuffer; + } + } + + try + { + OReleaseSolarMutex aReleaseForCallback; + // clear the preview window + xFilePicker->setImage( FilePreviewImageFormats::BITMAP, aAny ); + } + catch( IllegalArgumentException ) + { + } + + return 0; +} + +// ------------------------------------------------------------------------ +ErrCode FileDialogHelper_Impl::getGraphic( const OUString& rURL, + Graphic& rGraphic ) const +{ + if ( utl::UCBContentHelper::IsFolder( rURL ) ) + return ERRCODE_IO_NOTAFILE; + + if ( !mpGraphicFilter ) + return ERRCODE_IO_NOTSUPPORTED; + + // select graphic filter from dialog filter selection + OUString aCurFilter( getFilter() ); + + sal_uInt16 nFilter = aCurFilter.getLength() && mpGraphicFilter->GetImportFormatCount() + ? mpGraphicFilter->GetImportFormatNumber( aCurFilter ) + : GRFILTER_FORMAT_DONTKNOW; + + INetURLObject aURLObj( rURL ); + + if ( aURLObj.HasError() || INET_PROT_NOT_VALID == aURLObj.GetProtocol() ) + { + aURLObj.SetSmartProtocol( INET_PROT_FILE ); + aURLObj.SetSmartURL( rURL ); + } + + ErrCode nRet = ERRCODE_NONE; + + sal_uInt32 nFilterImportFlags = GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG; + // non-local? + if ( INET_PROT_FILE != aURLObj.GetProtocol() ) + { + SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( rURL, STREAM_READ ); + + if( pStream ) + nRet = mpGraphicFilter->ImportGraphic( rGraphic, rURL, *pStream, nFilter, NULL, nFilterImportFlags ); + else + nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags ); + delete pStream; + } + else + { + nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags ); + } + + return nRet; +} + +// ------------------------------------------------------------------------ +ErrCode FileDialogHelper_Impl::getGraphic( Graphic& rGraphic ) const +{ + ErrCode nRet = ERRCODE_NONE; + + if ( ! maGraphic ) + { + OUString aPath;; + Sequence < OUString > aPathSeq = mxFileDlg->getFiles(); + + if ( aPathSeq.getLength() == 1 ) + { + aPath = aPathSeq[0]; + } + + if ( aPath.getLength() ) + nRet = getGraphic( aPath, rGraphic ); + else + nRet = ERRCODE_IO_GENERAL; + } + else + rGraphic = maGraphic; + + return nRet; +} + +// ------------------------------------------------------------------------ +sal_Bool lcl_isSystemFilePicker( const uno::Reference< XFilePicker >& _rxFP ) +{ + try + { + uno::Reference< XServiceInfo > xSI( _rxFP, UNO_QUERY ); + if ( xSI.is() && xSI->supportsService( DEFINE_CONST_OUSTRING( "com.sun.star.ui.dialogs.SystemFilePicker" ) ) ) + return sal_True; + } + catch( const Exception& ) + { + } + return sal_False; +} + + +// ------------------------------------------------------------------------ +// ----------- FileDialogHelper_Impl --------------------------- +// ------------------------------------------------------------------------ + +FileDialogHelper_Impl::FileDialogHelper_Impl( + FileDialogHelper* _pAntiImpl, + sal_Int16 nDialogType, + sal_Int64 nFlags, + sal_Int16 nDialog, + Window* _pPreferredParentWindow, + const String& sStandardDir, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList + ) + :m_nDialogType ( nDialogType ) + ,meContext ( FileDialogHelper::UNKNOWN_CONTEXT ) +{ + const char* pServiceName=0; + if ( nDialog == SFX2_IMPL_DIALOG_SYSTEM ) + pServiceName = FILE_OPEN_SERVICE_NAME_OOO; + else if ( nDialog == SFX2_IMPL_DIALOG_OOO ) + pServiceName = FILE_OPEN_SERVICE_NAME_OOO; + else + pServiceName = FILE_OPEN_SERVICE_NAME; + OUString aService = ::rtl::OUString::createFromAscii( pServiceName ); + + uno::Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); + + // create the file open dialog + // the flags can be SFXWB_INSERT or SFXWB_MULTISELECTION + + mpPreferredParentWindow = _pPreferredParentWindow; + mpAntiImpl = _pAntiImpl; + mnError = ERRCODE_NONE; + mbHasAutoExt = sal_False; + mbHasPassword = sal_False; + m_bHaveFilterOptions = sal_False; + mbIsPwdEnabled = sal_True; + mbHasVersions = sal_False; + mbHasPreview = sal_False; + mbShowPreview = sal_False; + mbHasLink = sal_False; + mbDeleteMatcher = sal_False; + mbInsert = SFXWB_INSERT == ( nFlags & SFXWB_INSERT ); + mbExport = SFXWB_EXPORT == ( nFlags & SFXWB_EXPORT ); + mbIsSaveDlg = sal_False; + mbPwdCheckBoxState = sal_False; + mbSelection = sal_False; + mbSelectionEnabled = sal_True; + mbHasSelectionBox = sal_False; + mbSelectionFltrEnabled = sal_False; + + // default settings + m_nDontFlags = SFX_FILTER_INTERNAL | SFX_FILTER_NOTINFILEDLG | SFX_FILTER_NOTINSTALLED; + if( WB_OPEN == ( nFlags & WB_OPEN ) ) + m_nMustFlags = SFX_FILTER_IMPORT; + else + m_nMustFlags = SFX_FILTER_EXPORT; + + + mpMatcher = NULL; + mpGraphicFilter = NULL; + mnPostUserEventId = 0; + + // create the picker component + mxFileDlg = mxFileDlg.query( xFactory->createInstance( aService ) ); + mbSystemPicker = lcl_isSystemFilePicker( mxFileDlg ); + + uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY ); + uno::Reference< XInitialization > xInit( mxFileDlg, UNO_QUERY ); + + if ( ! mxFileDlg.is() || ! xNotifier.is() ) + { + mnError = ERRCODE_ABORT; + return; + } + + + if ( xInit.is() ) + { + sal_Int16 nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE; + + switch ( m_nDialogType ) + { + case FILEOPEN_SIMPLE: + nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE; + break; + + case FILESAVE_SIMPLE: + nTemplateDescription = TemplateDescription::FILESAVE_SIMPLE; + mbIsSaveDlg = sal_True; + break; + + case FILESAVE_AUTOEXTENSION_PASSWORD: + nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD; + mbHasPassword = sal_True; + mbHasAutoExt = sal_True; + mbIsSaveDlg = sal_True; + break; + + case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS: + nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS; + mbHasPassword = sal_True; + + m_bHaveFilterOptions = sal_True; + if( xFactory.is() ) + { + mxFilterCFG = uno::Reference< XNameAccess >( + xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ), + UNO_QUERY ); + } + + mbHasAutoExt = sal_True; + mbIsSaveDlg = sal_True; + break; + + case FILESAVE_AUTOEXTENSION_SELECTION: + nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION; + mbHasAutoExt = sal_True; + mbIsSaveDlg = sal_True; + mbHasSelectionBox = sal_True; + if ( mbExport && !mxFilterCFG.is() && xFactory.is() ) + { + mxFilterCFG = uno::Reference< XNameAccess >( + xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ), + UNO_QUERY ); + } + break; + + case FILESAVE_AUTOEXTENSION_TEMPLATE: + nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE; + mbHasAutoExt = sal_True; + mbIsSaveDlg = sal_True; + break; + + case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE: + nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE; + mbHasPreview = sal_True; + mbHasLink = sal_True; + + // aPreviewTimer + maPreViewTimer.SetTimeout( 500 ); + maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) ); + break; + + case FILEOPEN_PLAY: + nTemplateDescription = TemplateDescription::FILEOPEN_PLAY; + break; + + case FILEOPEN_READONLY_VERSION: + nTemplateDescription = TemplateDescription::FILEOPEN_READONLY_VERSION; + mbHasVersions = sal_True; + break; + + case FILEOPEN_LINK_PREVIEW: + nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW; + mbHasPreview = sal_True; + mbHasLink = sal_True; + // aPreviewTimer + maPreViewTimer.SetTimeout( 500 ); + maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) ); + break; + + case FILESAVE_AUTOEXTENSION: + nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION; + mbHasAutoExt = sal_True; + mbIsSaveDlg = sal_True; + break; + + default: + DBG_ERRORFILE( "FileDialogHelper::ctor with unknown type" ); + break; + } + + + + //Sequence < Any > aInitArguments( mbSystemPicker || !mpPreferredParentWindow ? 1 : 3 ); + Sequence < Any > aInitArguments( !mpPreferredParentWindow ? 3 : 4 ); + + // This is a hack. We currently know that the internal file picker implementation + // supports the extended arguments as specified below. + // TODO: + // a) adjust the service description so that it includes the TemplateDescription and ParentWindow args + // b) adjust the implementation of the system file picker to that it recognizes it + if ( mbSystemPicker ) + { + aInitArguments[0] <<= nTemplateDescription; + } + else + { + aInitArguments[0] <<= NamedValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TemplateDescription" ) ), + makeAny( nTemplateDescription ) + ); + + ::rtl::OUString sStandardDirTemp = ::rtl::OUString( sStandardDir ); + + aInitArguments[1] <<= NamedValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StandardDir" ) ), + makeAny( sStandardDirTemp ) + ); + + aInitArguments[2] <<= NamedValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BlackList" ) ), + makeAny( rBlackList ) + ); + + + if ( mpPreferredParentWindow ) + aInitArguments[3] <<= NamedValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ) ), + makeAny( VCLUnoHelper::GetInterface( mpPreferredParentWindow ) ) + ); + + + } + + try + { + xInit->initialize( aInitArguments ); + } + catch( const Exception& ) + { + DBG_ERROR( "FileDialogHelper_Impl::FileDialogHelper_Impl: could not initialize the picker!" ); + } + } + + + // set multiselection mode + if ( nFlags & SFXWB_MULTISELECTION ) + mxFileDlg->setMultiSelectionMode( sal_True ); + + if ( mbHasLink ) // generate graphic filter only on demand + addGraphicFilter(); + + // Export dialog + if ( mbExport ) + { + mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_EXPORT ) ) ) ); + try { + com::sun::star::uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY_THROW ); + xCtrlAccess->enableControl( ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, sal_True ); + } + catch( const Exception & ) { } + } + + // the "insert file" dialog needs another title + if ( mbInsert ) + { + mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_INSERT ) ) ) ); + uno::Reference < XFilePickerControlAccess > xExtDlg( mxFileDlg, UNO_QUERY ); + if ( xExtDlg.is() ) + { + try + { + xExtDlg->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK, + OUString( String( SfxResId( STR_SFX_EXPLORERFILE_BUTTONINSERT ) ) ) ); + } + catch( IllegalArgumentException ){} + } + } + + // add the event listener + xNotifier->addFilePickerListener( this ); +} + +// ------------------------------------------------------------------------ +FileDialogHelper_Impl::~FileDialogHelper_Impl() +{ + // Remove user event if we haven't received it yet + if ( mnPostUserEventId ) + Application::RemoveUserEvent( mnPostUserEventId ); + mnPostUserEventId = 0; + + delete mpGraphicFilter; + + if ( mbDeleteMatcher ) + delete mpMatcher; + + maPreViewTimer.SetTimeoutHdl( Link() ); + + ::comphelper::disposeComponent( mxFileDlg ); +} + +#define nMagic -1 + +class PickerThread_Impl : public ::vos::OThread +{ + uno::Reference < XFilePicker > mxPicker; + ::vos::OMutex maMutex; + virtual void SAL_CALL run(); + sal_Int16 mnRet; +public: + PickerThread_Impl( const uno::Reference < XFilePicker >& rPicker ) + : mxPicker( rPicker ), mnRet(nMagic) {} + + sal_Int16 GetReturnValue() + { ::vos::OGuard aGuard( maMutex ); return mnRet; } + + void SetReturnValue( sal_Int16 aRetValue ) + { ::vos::OGuard aGuard( maMutex ); mnRet = aRetValue; } +}; + +void SAL_CALL PickerThread_Impl::run() +{ + try + { + sal_Int16 n = mxPicker->execute(); + SetReturnValue( n ); + } + catch( RuntimeException& ) + { + SetReturnValue( ExecutableDialogResults::CANCEL ); + DBG_ERRORFILE( "RuntimeException caught" ); + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::setControlHelpIds( const sal_Int16* _pControlId, const sal_Int32* _pHelpId ) +{ + DBG_ASSERT( _pControlId && _pHelpId, "FileDialogHelper_Impl::setControlHelpIds: invalid array pointers!" ); + if ( !_pControlId || !_pHelpId ) + return; + + // forward these ids to the file picker + try + { + const ::rtl::OUString sHelpIdPrefix( RTL_CONSTASCII_USTRINGPARAM( "HID:" ) ); + // the ids for the single controls + uno::Reference< XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY ); + if ( xControlAccess.is() ) + { + while ( *_pControlId ) + { + // calc the help id of the element + ::rtl::OUString sId( sHelpIdPrefix ); + sId += ::rtl::OUString::valueOf( *_pHelpId ); + // set the help id + xControlAccess->setValue( *_pControlId, ControlActions::SET_HELP_URL, makeAny( sId ) ); + + ++_pControlId; ++_pHelpId; + } + } + } + catch( const Exception& ) + { + DBG_ERROR( "FileDialogHelper_Impl::setControlHelpIds: caught an exception while setting the help ids!" ); + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::setDialogHelpId( const sal_Int32 _nHelpId ) +{ + svt::SetDialogHelpId( mxFileDlg, _nHelpId ); +} + +// ------------------------------------------------------------------------ +IMPL_LINK( FileDialogHelper_Impl, InitControls, void*, NOTINTERESTEDIN ) +{ + (void)NOTINTERESTEDIN; + mnPostUserEventId = 0; + enablePasswordBox( sal_True ); + updateFilterOptionsBox( ); + updateSelectionBox( ); + + return 0L; +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::preExecute() +{ + loadConfig( ); + setDefaultValues( ); + updatePreviewState( sal_False ); + + implInitializeFileName( ); + // #106079# / 2002-12-09 / fs@openoffice.org + +#if !(defined(MACOSX) && defined(QUARTZ)) && !defined(WNT) + // allow for dialog implementations which need to be executed before they return valid values for + // current filter and such + + // On Vista (at least SP1) it's the same as on MacOSX, the modal dialog won't let message pass + // through before it returns from execution + mnPostUserEventId = Application::PostUserEvent( LINK( this, FileDialogHelper_Impl, InitControls ) ); +#else + // However, the Mac OS X implementation's pickers run modally in execute and so the event doesn't + // get through in time... so we call the methods directly + enablePasswordBox( sal_True ); + updateFilterOptionsBox( ); + updateSelectionBox( ); +#endif +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::postExecute( sal_Int16 _nResult ) +{ + if ( ExecutableDialogResults::CANCEL != _nResult ) + saveConfig(); +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::implInitializeFileName( ) +{ + if ( maFileName.getLength() ) + { + INetURLObject aObj( maPath ); + aObj.Append( maFileName ); + + // in case we're operating as save dialog, and "auto extension" is checked, + // cut the extension from the name + // #106079# / 2002-12-09 / fs@openoffice.org + if ( mbIsSaveDlg && mbHasAutoExt ) + { + try + { + sal_Bool bAutoExtChecked = sal_False; + + uno::Reference < XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY ); + if ( xControlAccess.is() + && ( xControlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 ) + >>= bAutoExtChecked + ) + ) + { + if ( bAutoExtChecked ) + { // cut the extension + aObj.removeExtension( ); + mxFileDlg->setDefaultName( aObj.GetName( INetURLObject::DECODE_WITH_CHARSET ) ); + } + } + } + catch( const Exception& ) + { + DBG_ERROR( "FileDialogHelper_Impl::implInitializeFileName: could not ask for the auto-extension current-value!" ); + } + } + } +} + +// ------------------------------------------------------------------------ +sal_Int16 FileDialogHelper_Impl::implDoExecute() +{ + preExecute(); + + sal_Int16 nRet = ExecutableDialogResults::CANCEL; + +//On MacOSX the native file picker has to run in the primordial thread because of drawing issues +//On Linux the native gtk file picker, when backed by gnome-vfs2, needs to be run in the same +//primordial thread as the ucb gnome-vfs2 provider was initialized in. +/* +#ifdef WNT + if ( mbSystemPicker ) + { + PickerThread_Impl* pThread = new PickerThread_Impl( mxFileDlg ); + pThread->create(); + while ( pThread->GetReturnValue() == nMagic ) + Application::Yield(); + pThread->join(); + nRet = pThread->GetReturnValue(); + delete pThread; + } + else +#endif +*/ + { + try + { +#ifdef WNT + if ( mbSystemPicker ) + { + OReleaseSolarMutex aSolarMutex; + nRet = mxFileDlg->execute(); + } + else +#endif + nRet = mxFileDlg->execute(); + } + catch( const Exception& ) + { + DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" ); + } + } + + postExecute( nRet ); + + return nRet; +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::implStartExecute() +{ + DBG_ASSERT( mxFileDlg.is(), "invalid file dialog" ); + + preExecute(); + + if ( mbSystemPicker ) + { + } + else + { + try + { + uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( mxFileDlg, UNO_QUERY ); + if ( xAsyncDlg.is() ) + xAsyncDlg->startExecuteModal( this ); + } + catch( const Exception& ) + { + DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" ); + } + } +} + +// ------------------------------------------------------------------------ +String FileDialogHelper_Impl::implEnsureURLExtension(const String& sURL, + const String& /*sExtension*/) +{ + return sURL; + /* + // This feature must be active for file save/export only ! + if ( + (! mbIsSaveDlg) && + (! mbExport ) + ) + return sURL; + + // no extension available (because "ALL *.*" was selected) ? + // Nod idea what else should happen here .-) + if (sExtension.Len() < 1) + return sURL; + + // Some FilePicker implementations already add the right extension ... + // or might be the user used the right one already ... + // Dont create duplicate extension. + INetURLObject aURL(sURL); + if (aURL.getExtension().equals(sExtension)) + return sURL; + + // Ignore any other extension set by the user. + // Make sure suitable extension is used always. + // e.g. "test.bla.odt" for "ODT" + ::rtl::OUStringBuffer sNewURL(256); + sNewURL.append (sURL ); + sNewURL.appendAscii("." ); + sNewURL.append (sExtension); + return sNewURL.makeStringAndClear(); + */ +} + +// ------------------------------------------------------------------------ +void lcl_saveLastURLs(SvStringsDtor*& rpURLList , + ::comphelper::SequenceAsVector< ::rtl::OUString >& lLastURLs ) +{ + lLastURLs.clear(); + USHORT c = rpURLList->Count(); + USHORT i = 0; + for (i=0; i<c; ++i) + lLastURLs.push_back(*(rpURLList->GetObject(i))); +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::implGetAndCacheFiles(const uno::Reference< XInterface >& xPicker , + SvStringsDtor*& rpURLList, + const SfxFilter* pFilter ) +{ + rpURLList = NULL; + + String sExtension; + if (pFilter) + { + sExtension = pFilter->GetDefaultExtension (); + sExtension.EraseAllChars( '*' ); + sExtension.EraseAllChars( '.' ); + } + + // a) the new way (optional!) + uno::Reference< XFilePicker2 > xPickNew(xPicker, UNO_QUERY); + if (xPickNew.is()) + { + rpURLList = new SvStringsDtor; + Sequence< OUString > lFiles = xPickNew->getSelectedFiles(); + ::sal_Int32 nFiles = lFiles.getLength(); + for (::sal_Int32 i = 0; i < nFiles; i++) + { + String* pURL = new String(implEnsureURLExtension(lFiles[i], sExtension)); + rpURLList->Insert( pURL, rpURLList->Count() ); + } + } + + // b) the olde way ... non optional. + else + { + uno::Reference< XFilePicker > xPickOld(xPicker, UNO_QUERY_THROW); + Sequence< OUString > lFiles = xPickOld->getFiles(); + ::sal_Int32 nFiles = lFiles.getLength(); + if ( nFiles == 1 ) + { + rpURLList = new SvStringsDtor; + String* pURL = new String(implEnsureURLExtension(lFiles[0], sExtension)); + rpURLList->Insert( pURL, 0 ); + } + else + if ( nFiles > 1 ) + { + rpURLList = new SvStringsDtor; + + INetURLObject aPath( lFiles[0] ); + aPath.setFinalSlash(); + + for (::sal_Int32 i = 1; i < nFiles; i++) + { + if (i == 1) + aPath.Append( lFiles[i] ); + else + aPath.setName( lFiles[i] ); + + String* pURL = new String(implEnsureURLExtension(aPath.GetMainURL( INetURLObject::NO_DECODE ), sExtension) ); + rpURLList->Insert( pURL, rpURLList->Count() ); + } + } + } + + lcl_saveLastURLs(rpURLList, mlLastURLs); +} + +// ------------------------------------------------------------------------ +ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, + SfxItemSet *& rpSet, + String& rFilter ) +{ + // rFilter is a pure output parameter, it shouldn't be used for anything else + // changing this would surely break code + // rpSet is in/out parameter, usually just a media-descriptor that can be changed by dialog + + uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); + + // retrieves parameters from rpSet + // for now only Password is used + if ( rpSet ) + { + // check password checkbox if the document had password before + if( mbHasPassword ) + { + SFX_ITEMSET_ARG( rpSet, pPassItem, SfxStringItem, SID_PASSWORD, FALSE ); + mbPwdCheckBoxState = ( pPassItem != NULL ); + + // in case the document has password to modify, the dialog should be shown + SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, FALSE ); + mbPwdCheckBoxState |= ( pPassToModifyItem && pPassToModifyItem->GetValue().hasValue() ); + } + + SFX_ITEMSET_ARG( rpSet, pSelectItem, SfxBoolItem, SID_SELECTION, FALSE ); + if ( pSelectItem ) + mbSelection = pSelectItem->GetValue(); + else + mbSelectionEnabled = sal_False; + + // the password will be set in case user decide so + rpSet->ClearItem( SID_PASSWORD ); + rpSet->ClearItem( SID_RECOMMENDREADONLY ); + rpSet->ClearItem( SID_MODIFYPASSWORDINFO ); + + } + + if ( mbHasPassword && !mbPwdCheckBoxState ) + { + SvtSecurityOptions aSecOpt; + mbPwdCheckBoxState = ( + aSecOpt.IsOptionSet( SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD ) ); + } + + rpURLList = NULL; + + if ( ! mxFileDlg.is() ) + return ERRCODE_ABORT; + + if ( ExecutableDialogResults::CANCEL != implDoExecute() ) + { + // create an itemset if there is no + if( !rpSet ) + rpSet = new SfxAllItemSet( SFX_APP()->GetPool() ); + + // the item should remain only if it was set by the dialog + rpSet->ClearItem( SID_SELECTION ); + + if( mbExport ) + { + try + { + Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 ); + sal_Bool bSelection = sal_False; + if ( aValue >>= bSelection ) + rpSet->Put( SfxBoolItem( SID_SELECTION, bSelection ) ); + } + catch( IllegalArgumentException ) + { + DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" ); + } + } + + + // set the read-only flag. When inserting a file, this flag is always set + if ( mbInsert ) + rpSet->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); + else + { + if ( ( FILEOPEN_READONLY_VERSION == m_nDialogType ) && xCtrlAccess.is() ) + { + try + { + Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY, 0 ); + sal_Bool bReadOnly = sal_False; + if ( ( aValue >>= bReadOnly ) && bReadOnly ) + rpSet->Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) ); + } + catch( IllegalArgumentException ) + { + DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" ); + } + } + } + if ( mbHasVersions && xCtrlAccess.is() ) + { + try + { + Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION, + ControlActions::GET_SELECTED_ITEM_INDEX ); + sal_Int32 nVersion = 0; + if ( ( aValue >>= nVersion ) && nVersion > 0 ) + // open a special version; 0 == current version + rpSet->Put( SfxInt16Item( SID_VERSION, (short)nVersion ) ); + } + catch( IllegalArgumentException ){} + } + + // set the filter + getRealFilter( rFilter ); + + const SfxFilter* pCurrentFilter = getCurentSfxFilter(); + + // fill the rpURLList + implGetAndCacheFiles( mxFileDlg, rpURLList, pCurrentFilter ); + if ( rpURLList == NULL || rpURLList->GetObject(0) == NULL ) + return ERRCODE_ABORT; + + // check, wether or not we have to display a password box + if ( pCurrentFilter && mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() ) + { + try + { + Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 ); + sal_Bool bPassWord = sal_False; + if ( ( aValue >>= bPassWord ) && bPassWord ) + { + // ask for a password + uno::Reference < ::com::sun::star::task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY ); + + if( xInteractionHandler.is() ) + { + // TODO: need a save way to distinguish MS filters from other filters + // for now MS-filters are the only alien filters that support encryption + sal_Bool bMSType = !pCurrentFilter->IsOwnFormat(); + ::comphelper::DocPasswordRequestType eType = bMSType ? + ::comphelper::DocPasswordRequestType_MS : + ::comphelper::DocPasswordRequestType_STANDARD; + + ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new ::comphelper::DocPasswordRequest( eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)), ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ) != 0 ) ); + + uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() ); + xInteractionHandler->handle( rRequest ); + if ( pPasswordRequest->isPassword() ) + { + if ( pPasswordRequest->getPassword().getLength() ) + rpSet->Put( SfxStringItem( SID_PASSWORD, pPasswordRequest->getPassword() ) ); + + if ( pPasswordRequest->getRecommendReadOnly() ) + rpSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) ); + + if ( bMSType ) + { + // the empty password has 0 as Hash + sal_Int32 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pCurrentFilter->GetServiceName() ) ); + if ( nHash ) + rpSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( nHash ) ) ); + } + else + { + uno::Sequence< beans::PropertyValue > aModifyPasswordInfo = ::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfo( pPasswordRequest->getPasswordToModify() ); + if ( aModifyPasswordInfo.getLength() ) + rpSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( aModifyPasswordInfo ) ) ); + } + } + else + return ERRCODE_ABORT; + } + } + } + catch( IllegalArgumentException ){} + } + + SaveLastUsedFilter(); + return ERRCODE_NONE; + } + else + return ERRCODE_ABORT; +} + +// ------------------------------------------------------------------------ +ErrCode FileDialogHelper_Impl::execute() +{ + if ( ! mxFileDlg.is() ) + return ERRCODE_ABORT; + + sal_Int16 nRet = implDoExecute(); + + maPath = mxFileDlg->getDisplayDirectory(); + + if ( ExecutableDialogResults::CANCEL == nRet ) + return ERRCODE_ABORT; + else + { + return ERRCODE_NONE; + } +} + +// ------------------------------------------------------------------------ +OUString FileDialogHelper_Impl::getPath() const +{ + OUString aPath; + + if ( mxFileDlg.is() ) + aPath = mxFileDlg->getDisplayDirectory(); + + if ( !aPath.getLength() ) + aPath = maPath; + + return aPath; +} + +// ------------------------------------------------------------------------ +OUString FileDialogHelper_Impl::getFilter() const +{ + String aFilter = getCurrentFilterUIName(); + + if( !aFilter.Len() ) + aFilter = maCurFilter; + + return aFilter; +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::getRealFilter( String& _rFilter ) const +{ + _rFilter = getCurrentFilterUIName(); + + if ( !_rFilter.Len() ) + _rFilter = maCurFilter; + + if ( _rFilter.Len() && mpMatcher ) + { + const SfxFilter* pFilter = + mpMatcher->GetFilter4UIName( _rFilter, m_nMustFlags, m_nDontFlags ); + _rFilter = pFilter ? pFilter->GetFilterName() : _rFilter.Erase(); + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::displayFolder( const ::rtl::OUString& _rPath ) +{ + if ( ! _rPath.getLength() ) + // nothing to do + return; + + /* + if ( !::utl::UCBContentHelper::IsFolder( _rPath ) ) + // only valid folders accepted here + return; + */ + + maPath = _rPath; + if ( mxFileDlg.is() ) + { + try + { + mxFileDlg->setDisplayDirectory( maPath ); + } + catch( const IllegalArgumentException& ) + { + DBG_ERROR( "FileDialogHelper_Impl::displayFolder: caught an exception!" ); + } + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::setFileName( const ::rtl::OUString& _rFile ) +{ + maFileName = _rFile; + if ( mxFileDlg.is() ) + { + try + { + mxFileDlg->setDefaultName( maFileName ); + } + catch( const IllegalArgumentException& ) + { + DBG_ERROR( "FileDialogHelper_Impl::setFileName: caught an exception!" ); + } + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::setFilter( const OUString& rFilter ) +{ + DBG_ASSERT( rFilter.indexOf(':') == -1, "Old filter name used!"); + + maCurFilter = rFilter; + + if ( rFilter.getLength() && mpMatcher ) + { + const SfxFilter* pFilter = mpMatcher->GetFilter4FilterName( + rFilter, m_nMustFlags, m_nDontFlags ); + if ( pFilter ) + maCurFilter = pFilter->GetUIName(); + } + + uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY ); + + if ( maCurFilter.getLength() && xFltMgr.is() ) + { + try + { + xFltMgr->setCurrentFilter( maCurFilter ); + } + catch( IllegalArgumentException ){} + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::createMatcher( const String& rFactory ) +{ + mpMatcher = new SfxFilterMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) ); + mbDeleteMatcher = sal_True; +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::addFilters( sal_Int64 nFlags, + const String& rFactory, + SfxFilterFlags nMust, + SfxFilterFlags nDont ) +{ + uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY ); + + if ( ! xFltMgr.is() ) + return; + + // we still need a matcher to convert UI names to filter names + if ( !rFactory.Len() ) + { + SfxApplication *pSfxApp = SFX_APP(); + mpMatcher = &pSfxApp->GetFilterMatcher(); + mbDeleteMatcher = sal_False; + } + else + { + mpMatcher = new SfxFilterMatcher( rFactory ); + mbDeleteMatcher = sal_True; + } + + uno::Reference< XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); + uno::Reference< XContainerQuery > xFilterCont( + xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.FilterFactory")), + UNO_QUERY); + if ( ! xFilterCont.is() ) + return; + + m_nMustFlags |= nMust; + m_nDontFlags |= nDont; + + // create the list of filters + ::rtl::OUStringBuffer sQuery(256); + sQuery.appendAscii("getSortedFilterList()"); + sQuery.appendAscii(":module=" ); + sQuery.append (rFactory ); // use long name here ! + sQuery.appendAscii(":iflags=" ); + sQuery.append (::rtl::OUString::valueOf((sal_Int32)m_nMustFlags)); + sQuery.appendAscii(":eflags=" ); + sQuery.append (::rtl::OUString::valueOf((sal_Int32)m_nDontFlags)); + + uno::Reference< XEnumeration > xResult = xFilterCont->createSubSetEnumerationByQuery(sQuery.makeStringAndClear()); + TSortedFilterList aIter (xResult); + + // no matcher any longer used ... + mbDeleteMatcher = sal_False; + + // append the filters + ::rtl::OUString sFirstFilter; + if ( WB_OPEN == ( nFlags & WB_OPEN ) ) + ::sfx2::appendFiltersForOpen( aIter, xFltMgr, sFirstFilter, *this ); + else if ( mbExport ) + ::sfx2::appendExportFilters( aIter, xFltMgr, sFirstFilter, *this ); + else + ::sfx2::appendFiltersForSave( aIter, xFltMgr, sFirstFilter, *this, rFactory ); + + // set our initial selected filter (if we do not already have one) + if ( !maSelectFilter.getLength() ) + maSelectFilter = sFirstFilter; +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::addFilter( const OUString& rFilterName, + const OUString& rExtension ) +{ + uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY ); + + if ( ! xFltMgr.is() ) + return; + + try + { + xFltMgr->appendFilter( rFilterName, rExtension ); + + if ( !maSelectFilter.getLength() ) + maSelectFilter = rFilterName; + } + catch( IllegalArgumentException ) + { +#ifdef DBG_UTIL + ByteString aMsg( "Could not append Filter" ); + aMsg += ByteString( String( rFilterName ), RTL_TEXTENCODING_UTF8 ); + DBG_ERRORFILE( aMsg.GetBuffer() ); +#endif + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::addGraphicFilter() +{ + uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY ); + + if ( ! xFltMgr.is() ) + return; + + // create the list of filters + mpGraphicFilter = new GraphicFilter; + USHORT i, j, nCount = mpGraphicFilter->GetImportFormatCount(); + + // compute the extension string for all known import filters + String aExtensions; + + for ( i = 0; i < nCount; i++ ) + { + j = 0; + String sWildcard; + while( TRUE ) + { + sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ ); + if ( !sWildcard.Len() ) + break; + if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND ) + { + if ( aExtensions.Len() ) + aExtensions += sal_Unicode(';'); + aExtensions += sWildcard; + } + } + } + +#if defined(WIN) || defined(WNT) + if ( aExtensions.Len() > 240 ) + aExtensions = DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL ); +#endif + sal_Bool bIsInOpenMode = isInOpenMode(); + + try + { + OUString aAllFilterName = String( SfxResId( STR_SFX_IMPORT_ALL ) ); + aAllFilterName = ::sfx2::addExtension( aAllFilterName, aExtensions, bIsInOpenMode, *this ); + + xFltMgr->appendFilter( aAllFilterName, aExtensions ); + maSelectFilter = aAllFilterName; + } + catch( IllegalArgumentException ) + { + DBG_ERRORFILE( "Could not append Filter" ); + } + + // Now add the filter + for ( i = 0; i < nCount; i++ ) + { + String aName = mpGraphicFilter->GetImportFormatName( i ); + String aExt; + j = 0; + String sWildcard; + while( TRUE ) + { + sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ ); + if ( !sWildcard.Len() ) + break; + if ( aExt.Search( sWildcard ) == STRING_NOTFOUND ) + { + if ( aExt.Len() ) + aExt += sal_Unicode(';'); + aExt += sWildcard; + } + } + aName = ::sfx2::addExtension( aName, aExt, bIsInOpenMode, *this ); + try + { + xFltMgr->appendFilter( aName, aExt ); + } + catch( IllegalArgumentException ) + { + DBG_ERRORFILE( "Could not append Filter" ); + } + } +} + +// ------------------------------------------------------------------------ +#define GRF_CONFIG_STR " " +#define STD_CONFIG_STR "1 " + +void FileDialogHelper_Impl::saveConfig() +{ + uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY ); + Any aValue; + + if ( ! xDlg.is() ) + return; + + if ( mbHasPreview ) + { + SvtViewOptions aDlgOpt( E_DIALOG, IMPGRF_CONFIGNAME ); + String aUserData = DEFINE_CONST_UNICODE( GRF_CONFIG_STR ); + + try + { + aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0 ); + sal_Bool bValue = sal_False; + aValue >>= bValue; + aUserData.SetToken( 0, ' ', String::CreateFromInt32( (sal_Int32) bValue ) ); + + aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 ); + bValue = sal_False; + aValue >>= bValue; + aUserData.SetToken( 1, ' ', String::CreateFromInt32( (sal_Int32) bValue ) ); + + INetURLObject aObj( getPath() ); + + if ( aObj.GetProtocol() == INET_PROT_FILE ) + aUserData.SetToken( 2, ' ', aObj.GetMainURL( INetURLObject::NO_DECODE ) ); + + String aFilter = getFilter(); + aFilter = EncodeSpaces_Impl( aFilter ); + aUserData.SetToken( 3, ' ', aFilter ); + + aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) ); + } + catch( IllegalArgumentException ){} + } + else + { + sal_Bool bWriteConfig = sal_False; + SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME ); + String aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR ); + + if ( aDlgOpt.Exists() ) + { + Any aUserItem = aDlgOpt.GetUserItem( USERITEM_NAME ); + OUString aTemp; + if ( aUserItem >>= aTemp ) + aUserData = String( aTemp ); + } + + if ( mbHasAutoExt ) + { + try + { + aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 ); + sal_Bool bAutoExt = sal_True; + aValue >>= bAutoExt; + aUserData.SetToken( 0, ' ', String::CreateFromInt32( (sal_Int32) bAutoExt ) ); + bWriteConfig = sal_True; + } + catch( IllegalArgumentException ){} + } + + if ( ! mbIsSaveDlg ) + { + OUString aPath = getPath(); + if ( aPath.getLength() && + utl::LocalFileHelper::IsLocalFile( aPath ) ) + { + aUserData.SetToken( 1, ' ', aPath ); + bWriteConfig = sal_True; + } + } + + if( mbHasSelectionBox && mbSelectionFltrEnabled ) + { + try + { + aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 ); + sal_Bool bSelection = sal_True; + aValue >>= bSelection; + if ( aUserData.GetTokenCount(' ') < 3 ) + aUserData.Append(' '); + aUserData.SetToken( 2, ' ', String::CreateFromInt32( (sal_Int32) bSelection ) ); + bWriteConfig = sal_True; + } + catch( IllegalArgumentException ){} + } + + if ( bWriteConfig ) + aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) ); + } + + SfxApplication *pSfxApp = SFX_APP(); + pSfxApp->SetLastDir_Impl( getPath() ); +} + +// ------------------------------------------------------------------------ +namespace +{ + static ::rtl::OUString getInitPath( const String& _rFallback, const xub_StrLen _nFallbackToken ) + { + SfxApplication *pSfxApp = SFX_APP(); + String sPath = pSfxApp->GetLastDir_Impl(); + + if ( !sPath.Len() ) + sPath = _rFallback.GetToken( _nFallbackToken, ' ' ); + + // check if the path points to a valid (accessible) directory + sal_Bool bValid = sal_False; + if ( sPath.Len() ) + { + String sPathCheck( sPath ); + if ( sPathCheck.GetBuffer()[ sPathCheck.Len() - 1 ] != '/' ) + sPathCheck += '/'; + sPathCheck += '.'; + try + { + ::ucbhelper::Content aContent( sPathCheck, uno::Reference< ucb::XCommandEnvironment >() ); + bValid = aContent.isFolder(); + } + catch( Exception& ) {} + } + + if ( !bValid ) + sPath.Erase(); + + return sPath; + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::loadConfig() +{ + uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY ); + Any aValue; + + if ( ! xDlg.is() ) + return; + + if ( mbHasPreview ) + { + SvtViewOptions aViewOpt( E_DIALOG, IMPGRF_CONFIGNAME ); + String aUserData; + + if ( aViewOpt.Exists() ) + { + Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME ); + OUString aTemp; + if ( aUserItem >>= aTemp ) + aUserData = String( aTemp ); + } + + if ( aUserData.Len() > 0 ) + { + try + { + // respect the last "insert as link" state + sal_Bool bLink = (sal_Bool) aUserData.GetToken( 0, ' ' ).ToInt32(); + if ( !xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0 ).hasValue() ) + { + aValue <<= bLink; + xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, aValue ); + } + + // respect the last "show preview" state + sal_Bool bShowPreview = (sal_Bool) aUserData.GetToken( 1, ' ' ).ToInt32(); + if ( !xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 ).hasValue() ) + { + aValue <<= bShowPreview; + xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, aValue ); + } + + if ( !maPath.getLength() ) + displayFolder( getInitPath( aUserData, 2 ) ); + + if ( ! maCurFilter.getLength() ) + { + String aFilter = aUserData.GetToken( 3, ' ' ); + aFilter = DecodeSpaces_Impl( aFilter ); + setFilter( aFilter ); + } + + // set the member so we know that we have to show the preview + mbShowPreview = bShowPreview; + } + catch( IllegalArgumentException ){} + } + + if ( !maPath.getLength() ) + displayFolder( SvtPathOptions().GetGraphicPath() ); + } + else + { + SvtViewOptions aViewOpt( E_DIALOG, IODLG_CONFIGNAME ); + String aUserData; + + if ( aViewOpt.Exists() ) + { + Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME ); + OUString aTemp; + if ( aUserItem >>= aTemp ) + aUserData = String( aTemp ); + } + + if ( ! aUserData.Len() ) + aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR ); + + if ( ! maPath.getLength() ) + displayFolder( getInitPath( aUserData, 1 ) ); + + if ( mbHasAutoExt ) + { + sal_Int32 nFlag = aUserData.GetToken( 0, ' ' ).ToInt32(); + aValue <<= (sal_Bool) nFlag; + try + { + xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue ); + } + catch( IllegalArgumentException ){} + } + + if( mbHasSelectionBox ) + { + sal_Int32 nFlag = aUserData.GetToken( 2, ' ' ).ToInt32(); + aValue <<= (sal_Bool) nFlag; + try + { + xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, aValue ); + } + catch( IllegalArgumentException ){} + } + + if ( !maPath.getLength() ) + displayFolder( SvtPathOptions().GetWorkPath() ); + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper_Impl::setDefaultValues() +{ + // when no filter is set, we set the curentFilter to <all> + if ( !maCurFilter.getLength() && maSelectFilter.getLength() ) + { + uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY ); + try + { + xFltMgr->setCurrentFilter( maSelectFilter ); + } + catch( IllegalArgumentException ) + {} + } + + // when no path is set, we use the standard 'work' folder + if ( ! maPath.getLength() ) + { + OUString aWorkFolder = SvtPathOptions().GetWorkPath(); + try + { + mxFileDlg->setDisplayDirectory( aWorkFolder ); + } + catch( const Exception& ) + { + DBG_ERROR( "FileDialogHelper_Impl::setDefaultValues: caught an exception while setting the display directory!" ); + } + + // INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() ); + //SetStandardDir( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE ) ); + } +} + +sal_Bool FileDialogHelper_Impl::isShowFilterExtensionEnabled() const +{ + return !maFilters.empty(); +} + +void FileDialogHelper_Impl::addFilterPair( const OUString& rFilter, + const OUString& rFilterWithExtension ) +{ + maFilters.push_back( FilterPair( rFilter, rFilterWithExtension ) ); + +} + +OUString FileDialogHelper_Impl::getFilterName( const OUString& rFilterWithExtension ) const +{ + OUString sRet; + for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter ) + { + if ( (*pIter).Second == rFilterWithExtension ) + { + sRet = (*pIter).First; + break; + } + } + return sRet; +} + +OUString FileDialogHelper_Impl::getFilterWithExtension( const OUString& rFilter ) const +{ + OUString sRet; + for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter ) + { + if ( (*pIter).First == rFilter ) + { + sRet = (*pIter).Second; + break; + } + } + return sRet; +} + +void FileDialogHelper_Impl::SetContext( FileDialogHelper::Context _eNewContext ) +{ + meContext = _eNewContext; + + sal_Int32 nNewHelpId = 0; + OUString aConfigId; + + switch( _eNewContext ) + { +// #104952# dependency to SVX not allowed! When used again, another solution has to be found +// case FileDialogHelper::SW_INSERT_GRAPHIC: +// case FileDialogHelper::SC_INSERT_GRAPHIC: +// case FileDialogHelper::SD_INSERT_GRAPHIC: nNewHelpId = SID_INSERT_GRAPHIC; break; + case FileDialogHelper::SW_INSERT_SOUND: + case FileDialogHelper::SC_INSERT_SOUND: + case FileDialogHelper::SD_INSERT_SOUND: nNewHelpId = SID_INSERT_SOUND; break; + case FileDialogHelper::SW_INSERT_VIDEO: + case FileDialogHelper::SC_INSERT_VIDEO: + case FileDialogHelper::SD_INSERT_VIDEO: nNewHelpId = SID_INSERT_VIDEO; break; + default: break; + } + + const OUString* pConfigId = GetLastFilterConfigId( _eNewContext ); + if( pConfigId ) + LoadLastUsedFilter( *pConfigId ); + +// if( nNewHelpId ) +// this->setDialogHelpId( nNewHelpId ); +} + +// ------------------------------------------------------------------------ +// ----------- FileDialogHelper --------------------------- +// ------------------------------------------------------------------------ + +FileDialogHelper::FileDialogHelper( + sal_Int64 nFlags, + const String& rFact, + SfxFilterFlags nMust, + SfxFilterFlags nDont ) +{ + mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags ); + mxImp = mpImp; + + // create the list of filters + mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont ); +} + +FileDialogHelper::FileDialogHelper( + sal_Int64 nFlags, + const String& rFact, + sal_Int16 nDialog, + SfxFilterFlags nMust, + SfxFilterFlags nDont, + const String& rStandardDir, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList) +{ + mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags, nDialog, NULL , rStandardDir, rBlackList ); + mxImp = mpImp; + + // create the list of filters + mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont ); +} + +FileDialogHelper::FileDialogHelper( + sal_Int64 nFlags, + const String& rFact, + sal_Int16 nDialog, + SfxFilterFlags nMust, + SfxFilterFlags nDont ) +{ + mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags, nDialog ); + mxImp = mpImp; + + // create the list of filters + mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont ); +} + +// ------------------------------------------------------------------------ +FileDialogHelper::FileDialogHelper( sal_Int64 nFlags ) +{ + sal_Int16 nDialogType = getDialogType( nFlags ); + + mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags ); + mxImp = mpImp; +} + +// ------------------------------------------------------------------------ +FileDialogHelper::FileDialogHelper( + sal_Int16 nDialogType, + sal_Int64 nFlags, + const String& rFact, + SfxFilterFlags nMust, + SfxFilterFlags nDont ) +{ + mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags ); + mxImp = mpImp; + + // create the list of filters + mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont ); +} + +// ------------------------------------------------------------------------ +FileDialogHelper::FileDialogHelper( + sal_Int16 nDialogType, + sal_Int64 nFlags, + const String& rFact, + sal_Int16 nDialog, + SfxFilterFlags nMust, + SfxFilterFlags nDont, + const String& rStandardDir, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList) +{ + mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, nDialog, NULL, rStandardDir, rBlackList ); + mxImp = mpImp; + + // create the list of filters + mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont ); +} + +// ------------------------------------------------------------------------ +FileDialogHelper::FileDialogHelper( + sal_Int16 nDialogType, + sal_Int64 nFlags, + Window* _pPreferredParent ) +{ + mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent ); + mxImp = mpImp; +} + +// ------------------------------------------------------------------------ +FileDialogHelper::FileDialogHelper( + sal_Int16 nDialogType, + sal_Int64 nFlags, + const ::rtl::OUString& aFilterUIName, + const ::rtl::OUString& aExtName, + const ::rtl::OUString& rStandardDir, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList, + Window* _pPreferredParent ) +{ + mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent,rStandardDir, rBlackList ); + mxImp = mpImp; + + // the wildcard here is expected in form "*.extension" + ::rtl::OUString aWildcard; + if ( aExtName.indexOf( (sal_Unicode)'*' ) != 0 ) + { + if ( aExtName.getLength() && aExtName.indexOf( (sal_Unicode)'.' ) != 0 ) + aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*." ) ); + else + aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*" ) ); + } + + aWildcard += aExtName; + + ::rtl::OUString aUIString = + ::sfx2::addExtension( aFilterUIName, aWildcard, ( WB_OPEN == ( nFlags & WB_OPEN ) ), *mpImp ); + AddFilter( aUIString, aWildcard ); +} + +// ------------------------------------------------------------------------ +FileDialogHelper::~FileDialogHelper() +{ + mpImp->dispose(); + mxImp.clear(); +} + +// ------------------------------------------------------------------------ +void FileDialogHelper::CreateMatcher( const String& rFactory ) +{ + mpImp->createMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) ); +} + +// ------------------------------------------------------------------------ +void FileDialogHelper::SetControlHelpIds( const sal_Int16* _pControlId, const sal_Int32* _pHelpId ) +{ + mpImp->setControlHelpIds( _pControlId, _pHelpId ); +} + +// ------------------------------------------------------------------------ +void FileDialogHelper::SetDialogHelpId( const sal_Int32 _nHelpId ) +{ + mpImp->setDialogHelpId( _nHelpId ); +} + +void FileDialogHelper::SetContext( Context _eNewContext ) +{ + mpImp->SetContext( _eNewContext ); +} + +// ------------------------------------------------------------------------ +IMPL_LINK( FileDialogHelper, ExecuteSystemFilePicker, void*, EMPTYARG ) +{ + m_nError = mpImp->execute(); + if ( m_aDialogClosedLink.IsSet() ) + m_aDialogClosedLink.Call( this ); + + return 0L; +} + +// ------------------------------------------------------------------------ +// rDirPath has to be a directory +ErrCode FileDialogHelper::Execute( SvStringsDtor*& rpURLList, + SfxItemSet *& rpSet, + String& rFilter, + const String& rDirPath ) +{ + SetDisplayFolder( rDirPath ); + return mpImp->execute( rpURLList, rpSet, rFilter ); +} + + +// ------------------------------------------------------------------------ +ErrCode FileDialogHelper::Execute() +{ + return mpImp->execute(); +} + +// ------------------------------------------------------------------------ +ErrCode FileDialogHelper::Execute( SfxItemSet *& rpSet, + String& rFilter ) +{ + ErrCode nRet; + SvStringsDtor* pURLList; + + nRet = mpImp->execute( pURLList, rpSet, rFilter ); + + delete pURLList; + + return nRet; +} + +void FileDialogHelper::StartExecuteModal( const Link& rEndDialogHdl ) +{ + m_aDialogClosedLink = rEndDialogHdl; + m_nError = ERRCODE_NONE; + if ( mpImp->isSystemFilePicker() ) + Application::PostUserEvent( LINK( this, FileDialogHelper, ExecuteSystemFilePicker ) ); + else + mpImp->implStartExecute(); +} + +// ------------------------------------------------------------------------ + +short FileDialogHelper::GetDialogType() const +{ + return mpImp ? mpImp->m_nDialogType : 0; +} + +// ------------------------------------------------------------------------ + +sal_Bool FileDialogHelper::IsPasswordEnabled() const +{ + return mpImp ? mpImp->isPasswordEnabled() : sal_False; +} + +// ------------------------------------------------------------------------ + +String FileDialogHelper::GetRealFilter() const +{ + String sFilter; + if ( mpImp ) + mpImp->getRealFilter( sFilter ); + return sFilter; +} + +// ------------------------------------------------------------------------ +void FileDialogHelper::SetTitle( const String& rNewTitle ) +{ + if ( mpImp->mxFileDlg.is() ) + mpImp->mxFileDlg->setTitle( rNewTitle ); +} + +// ------------------------------------------------------------------------ +String FileDialogHelper::GetPath() const +{ + OUString aPath; + + if ( mpImp->mlLastURLs.size() > 0) + return mpImp->mlLastURLs[0]; + + if ( mpImp->mxFileDlg.is() ) + { + Sequence < OUString > aPathSeq = mpImp->mxFileDlg->getFiles(); + + if ( aPathSeq.getLength() == 1 ) + { + aPath = aPathSeq[0]; + } + } + + return aPath; +} + +// ------------------------------------------------------------------------ +Sequence < OUString > FileDialogHelper::GetMPath() const +{ + if ( mpImp->mlLastURLs.size() > 0) + return mpImp->mlLastURLs.getAsConstList(); + + if ( mpImp->mxFileDlg.is() ) + return mpImp->mxFileDlg->getFiles(); + else + { + Sequence < OUString > aEmpty; + return aEmpty; + } +} + +// ------------------------------------------------------------------------ +Sequence< ::rtl::OUString > FileDialogHelper::GetSelectedFiles() const +{ + // a) the new way (optional!) + uno::Sequence< ::rtl::OUString > aResultSeq; + uno::Reference< XFilePicker2 > xPickNew(mpImp->mxFileDlg, UNO_QUERY); + if (xPickNew.is()) + { + aResultSeq = xPickNew->getSelectedFiles(); + } + // b) the olde way ... non optional. + else + { + uno::Reference< XFilePicker > xPickOld(mpImp->mxFileDlg, UNO_QUERY_THROW); + Sequence< OUString > lFiles = xPickOld->getFiles(); + ::sal_Int32 nFiles = lFiles.getLength(); + if ( nFiles > 1 ) + { + aResultSeq = Sequence< ::rtl::OUString >( nFiles-1 ); + + INetURLObject aPath( lFiles[0] ); + aPath.setFinalSlash(); + + for (::sal_Int32 i = 1; i < nFiles; i++) + { + if (i == 1) + aPath.Append( lFiles[i] ); + else + aPath.setName( lFiles[i] ); + + aResultSeq[i-1] = ::rtl::OUString(aPath.GetMainURL( INetURLObject::NO_DECODE )); + } + } + else + aResultSeq = lFiles; + } + + return aResultSeq; +} + +// ------------------------------------------------------------------------ +String FileDialogHelper::GetDisplayDirectory() const +{ + return mpImp->getPath(); +} + +// ------------------------------------------------------------------------ +String FileDialogHelper::GetCurrentFilter() const +{ + return mpImp->getFilter(); +} + +// ------------------------------------------------------------------------ +ErrCode FileDialogHelper::GetGraphic( Graphic& rGraphic ) const +{ + return mpImp->getGraphic( rGraphic ); +} + +// ------------------------------------------------------------------------ +static int impl_isFolder( const OUString& rPath ) +{ + uno::Reference< task::XInteractionHandler > xHandler; + try + { + uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + xHandler.set( xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.task.InteractionHandler" ) ), + uno::UNO_QUERY_THROW ); + } + catch ( Exception const & ) + { + } + + ::rtl::Reference< ::comphelper::StillReadWriteInteraction > aHandler = new ::comphelper::StillReadWriteInteraction( xHandler ); + + try + { + ::ucbhelper::Content aContent( + rPath, new ::ucbhelper::CommandEnvironment( static_cast< task::XInteractionHandler* > ( aHandler.get() ), uno::Reference< ucb::XProgressHandler >() ) ); + if ( aContent.isFolder() ) + return 1; + + return 0; + } + catch ( Exception const & ) + { + } + + return -1; +} + +void FileDialogHelper::SetDisplayDirectory( const String& _rPath ) +{ + if ( !_rPath.Len() ) + return; + + // if the given path isn't a folder, we cut off the last part + // and take it as filename and the rest of the path should be + // the folder + + INetURLObject aObj( _rPath ); + + ::rtl::OUString sFileName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET ); + aObj.removeSegment(); + ::rtl::OUString sPath = aObj.GetMainURL( INetURLObject::NO_DECODE ); + + int nIsFolder = impl_isFolder( _rPath ); + if ( nIsFolder == 0 || + ( nIsFolder == -1 && impl_isFolder( sPath ) == 1 ) ) + { + mpImp->setFileName( sFileName ); + mpImp->displayFolder( sPath ); + } + else + { + INetURLObject aObjPathName( _rPath ); + ::rtl::OUString sFolder( aObjPathName.GetMainURL( INetURLObject::NO_DECODE ) ); + if ( sFolder.getLength() == 0 ) + { + // _rPath is not a valid path -> fallback to home directory + NAMESPACE_VOS( OSecurity ) aSecurity; + aSecurity.getHomeDir( sFolder ); + } + mpImp->displayFolder( sFolder ); + } +} + +// ------------------------------------------------------------------------ +void FileDialogHelper::SetDisplayFolder( const String& _rURL ) +{ + mpImp->displayFolder( _rURL ); +} + +// ------------------------------------------------------------------------ +void FileDialogHelper::SetFileName( const String& _rFileName ) +{ + mpImp->setFileName( _rFileName ); +} + +// ------------------------------------------------------------------------ +void FileDialogHelper::AddFilter( const String& rFilterName, + const String& rExtension ) +{ + mpImp->addFilter( rFilterName, rExtension ); +} + +// ------------------------------------------------------------------------ +void FileDialogHelper::SetCurrentFilter( const String& rFilter ) +{ + String sFilter( rFilter ); + if ( mpImp->isShowFilterExtensionEnabled() ) + sFilter = mpImp->getFilterWithExtension( rFilter ); + mpImp->setFilter( sFilter ); +} + +// ------------------------------------------------------------------------ +uno::Reference < XFilePicker > FileDialogHelper::GetFilePicker() const +{ + return mpImp->mxFileDlg; +} + +// ------------------------------------------------------------------------ +sal_Int16 FileDialogHelper::getDialogType( sal_Int64 nFlags ) const +{ + sal_Int16 nDialogType = FILEOPEN_SIMPLE; + + if ( nFlags & WB_SAVEAS ) + { + if ( nFlags & SFXWB_PASSWORD ) + nDialogType = FILESAVE_AUTOEXTENSION_PASSWORD; + else + nDialogType = FILESAVE_SIMPLE; + } + else if ( nFlags & SFXWB_GRAPHIC ) + { + if ( nFlags & SFXWB_SHOWSTYLES ) + nDialogType = FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE; + else + nDialogType = FILEOPEN_LINK_PREVIEW; + } + else if ( SFXWB_INSERT != ( nFlags & SFXWB_INSERT ) ) + nDialogType = FILEOPEN_READONLY_VERSION; + + return nDialogType; +} + +// ------------------------------------------------------------------------ +// XFilePickerListener Methods +// ------------------------------------------------------------------------ +void SAL_CALL FileDialogHelper::FileSelectionChanged( const FilePickerEvent& aEvent ) +{ + mpImp->handleFileSelectionChanged( aEvent ); +} + +// ------------------------------------------------------------------------ +void SAL_CALL FileDialogHelper::DirectoryChanged( const FilePickerEvent& aEvent ) +{ + mpImp->handleDirectoryChanged( aEvent ); +} + +// ------------------------------------------------------------------------ +OUString SAL_CALL FileDialogHelper::HelpRequested( const FilePickerEvent& aEvent ) +{ + return mpImp->handleHelpRequested( aEvent ); +} + +// ------------------------------------------------------------------------ +void SAL_CALL FileDialogHelper::ControlStateChanged( const FilePickerEvent& aEvent ) +{ + mpImp->handleControlStateChanged( aEvent ); +} + +// ------------------------------------------------------------------------ +void SAL_CALL FileDialogHelper::DialogSizeChanged() +{ + mpImp->handleDialogSizeChanged(); +} + +// ------------------------------------------------------------------------ +void SAL_CALL FileDialogHelper::DialogClosed( const DialogClosedEvent& _rEvent ) +{ + m_nError = ( RET_OK == _rEvent.DialogResult ) ? ERRCODE_NONE : ERRCODE_ABORT; + if ( m_aDialogClosedLink.IsSet() ) + m_aDialogClosedLink.Call( this ); +} + +// ------------------------------------------------------------------------ +// ------------------------------------------------------------------------ +// ------------------------------------------------------------------------ + +ErrCode FileOpenDialog_Impl( sal_Int64 nFlags, + const String& rFact, + SvStringsDtor *& rpURLList, + String& rFilter, + SfxItemSet *& rpSet, + const String* pPath, + sal_Int16 nDialog, + const String& rStandardDir, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList ) +{ + ErrCode nRet; + FileDialogHelper aDialog( nFlags, rFact, nDialog, 0, 0, rStandardDir, rBlackList ); + + String aPath; + if ( pPath ) + aPath = *pPath; + + nRet = aDialog.Execute( rpURLList, rpSet, rFilter, aPath ); + DBG_ASSERT( rFilter.SearchAscii(": ") == STRING_NOTFOUND, "Old filter name used!"); + + return nRet; +} + + +// ------------------------------------------------------------------------ +String EncodeSpaces_Impl( const String& rSource ) +{ + String sRet( rSource ); + sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( " " ), DEFINE_CONST_UNICODE( "%20" ) ); + return sRet; +} + +// ------------------------------------------------------------------------ +String DecodeSpaces_Impl( const String& rSource ) +{ + String sRet( rSource ); + sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( "%20" ), DEFINE_CONST_UNICODE( " " ) ); + return sRet; +} + +// ------------------------------------------------------------------------ + +} // end of namespace sfx2 + diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx index 547198f60ace..451e33084c07 100644 --- a/sfx2/source/doc/objcont.cxx +++ b/sfx2/source/doc/objcont.cxx @@ -1249,17 +1249,35 @@ sal_uInt32 SfxObjectShell::GetModifyPasswordHash() const sal_Bool SfxObjectShell::SetModifyPasswordHash( sal_uInt32 nHash ) { -// Commented out before the solution for Saving process is found -// if ( ( !IsReadOnly() && !IsReadOnlyUI() ) -// || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) ) -// { -// // the hash can be changed only in editable documents, -// // or during loading of document + if ( ( !IsReadOnly() && !IsReadOnlyUI() ) + || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) ) + { + // the hash can be changed only in editable documents, + // or during loading of document pImp->m_nModifyPasswordHash = nHash; return sal_True; -// } -// -// return sal_False; + } + + return sal_False; +} + +uno::Sequence< beans::PropertyValue > SfxObjectShell::GetModifyPasswordInfo() const +{ + return pImp->m_aModifyPasswordInfo; +} + +sal_Bool SfxObjectShell::SetModifyPasswordInfo( const uno::Sequence< beans::PropertyValue >& aInfo ) +{ + if ( ( !IsReadOnly() && !IsReadOnlyUI() ) + || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) ) + { + // the hash can be changed only in editable documents, + // or during loading of document + pImp->m_aModifyPasswordInfo = aInfo; + return sal_True; + } + + return sal_False; } void SfxObjectShell::SetModifyPasswordEntered( sal_Bool bEntered ) diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index afcaa1614f2c..addb648ef2e9 100755 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -1389,7 +1389,7 @@ void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags ) if( !IsAbortingImport() ) PositionView_Impl(); - if ( GetModifyPasswordHash() && !IsModifyPasswordEntered() ) + if ( ( GetModifyPasswordHash() || GetModifyPasswordInfo().getLength() ) && !IsModifyPasswordEntered() ) SetReadOnly(); // Salvage diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index d3707636d5ea..b5a9536b12c5 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -2732,11 +2732,23 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL uno::Reference< uno::XInterface >() ); } - SFX_ITEMSET_ARG( aParams, pModifyPasswordHashItem, SfxInt32Item, SID_MODIFYPASSWORDHASH, sal_False ); - sal_uInt32 nModifyPasswordHash = pModifyPasswordHashItem ? pModifyPasswordHashItem->GetValue() : 0; - aParams->ClearItem( SID_MODIFYPASSWORDHASH ); + sal_uInt32 nModifyPasswordHash = 0; + uno::Sequence< beans::PropertyValue > aModifyPasswordInfo; + SFX_ITEMSET_ARG( aParams, pModifyPasswordInfoItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, sal_False ); + if ( pModifyPasswordInfoItem ) + { + // it contains either a simple hash or a set of PropertyValues + // TODO/LATER: the sequence of PropertyValue should replace the hash completely in future + sal_Int32 nMPHTmp = 0; + pModifyPasswordInfoItem->GetValue() >>= nMPHTmp; + nModifyPasswordHash = (sal_uInt32)nMPHTmp; + pModifyPasswordInfoItem->GetValue() >>= aModifyPasswordInfo; + } + aParams->ClearItem( SID_MODIFYPASSWORDINFO ); sal_uInt32 nOldModifyPasswordHash = m_pData->m_pObjectShell->GetModifyPasswordHash(); m_pData->m_pObjectShell->SetModifyPasswordHash( nModifyPasswordHash ); + uno::Sequence< beans::PropertyValue > aOldModifyPasswordInfo = m_pData->m_pObjectShell->GetModifyPasswordInfo(); + m_pData->m_pObjectShell->SetModifyPasswordInfo( aModifyPasswordInfo ); // since saving a document modifies its DocumentInfo, the current // DocumentInfo must be saved on "SaveTo", so it can be restored @@ -2823,6 +2835,7 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL else { m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash ); + m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo ); SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVETODOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVETODOCDONE), m_pData->m_pObjectShell ) ); } @@ -2834,6 +2847,7 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL m_pData->m_pObjectShell->StoreLog(); m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash ); + m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo ); SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOCFAILED : SFX_EVENT_SAVEASDOCFAILED, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOCFAILED : STR_EVENT_SAVEASDOCFAILED), diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx index e170a7c27240..b5087fb46294 100644 --- a/sfx2/source/inc/objshimp.hxx +++ b/sfx2/source/inc/objshimp.hxx @@ -149,7 +149,9 @@ struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess sal_Bool m_bIncomplEncrWarnShown; + // TODO/LATER: m_aModifyPasswordInfo should completely replace m_nModifyPasswordHash in future sal_uInt32 m_nModifyPasswordHash; + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aModifyPasswordInfo; sal_Bool m_bModifyPasswordEntered; SfxObjectShell_Impl( SfxObjectShell& _rDocShell ); diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index f5207d431f27..d00229e8a73c 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1,3500 +1,3512 @@ -/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_sfx2.hxx"
-
-#include <stdio.h>
-
-#include <sfx2/viewfrm.hxx>
-#include <com/sun/star/document/MacroExecMode.hpp>
-#include <com/sun/star/frame/XLoadable.hpp>
-#include <com/sun/star/frame/XLayoutManager.hpp>
-#include <com/sun/star/frame/XComponentLoader.hpp>
-
-#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
-#include <toolkit/unohlp.hxx>
-#endif
-#ifndef _SPLITWIN_HXX //autogen
-#include <vcl/splitwin.hxx>
-#endif
-#include <unotools/moduleoptions.hxx>
-#include <svl/intitem.hxx>
-#include <svl/visitem.hxx>
-#include <svl/stritem.hxx>
-#include <svl/eitem.hxx>
-#include <svl/slstitm.hxx>
-#include <svl/whiter.hxx>
-#include <svl/undo.hxx>
-#ifndef _MSGBOX_HXX //autogen
-#include <vcl/msgbox.hxx>
-#endif
-#include <svtools/sfxecode.hxx>
-#include <svtools/ehdl.hxx>
-#include <tools/diagnose_ex.h>
-#include <com/sun/star/container/XIndexAccess.hpp>
-#include <com/sun/star/frame/XFramesSupplier.hpp>
-#include <com/sun/star/frame/FrameSearchFlag.hpp>
-#include <com/sun/star/frame/XFrame.hpp>
-#include <com/sun/star/frame/XFrames.hpp>
-#include <com/sun/star/frame/XFramesSupplier.hpp>
-#include <com/sun/star/awt/XWindow.hpp>
-#include <com/sun/star/frame/XController.hpp>
-#include <com/sun/star/frame/XModel2.hpp>
-#include <com/sun/star/util/XURLTransformer.hpp>
-#include <com/sun/star/util/XCloseable.hpp>
-#include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
-#include <com/sun/star/document/MacroExecMode.hpp>
-#include <com/sun/star/document/UpdateDocMode.hpp>
-#include <com/sun/star/beans/XPropertySet.hpp>
-#include <com/sun/star/uri/XUriReferenceFactory.hpp>
-#include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
-#include <com/sun/star/embed/XStorage.hpp>
-#include <com/sun/star/embed/EmbedStates.hpp>
-#include <rtl/ustrbuf.hxx>
-
-#include <unotools/localfilehelper.hxx>
-#include <unotools/ucbhelper.hxx>
-#include <comphelper/processfactory.hxx>
-#include <comphelper/componentcontext.hxx>
-#include <comphelper/namedvaluecollection.hxx>
-#include <comphelper/configurationhelper.hxx>
-#include <comphelper/docpasswordrequest.hxx>
-
-#include <com/sun/star/uno/Reference.h>
-#include <com/sun/star/ucb/XContent.hpp>
-
-#include <basic/basmgr.hxx>
-#include <basic/sbmod.hxx>
-#include <basic/sbmeth.hxx>
-#include <basic/sbx.hxx>
-#include <comphelper/storagehelper.hxx>
-#include <svtools/asynclink.hxx>
-#include <svl/sharecontrolfile.hxx>
-
-#include <boost/optional.hpp>
-
-using namespace ::com::sun::star;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::ucb;
-using namespace ::com::sun::star::frame;
-using namespace ::com::sun::star::lang;
-using ::com::sun::star::awt::XWindow;
-using ::com::sun::star::beans::PropertyValue;
-namespace css = ::com::sun::star;
-
-#ifndef GCC
-#endif
-
-// wg. ViewFrame::Current
-#include "appdata.hxx"
-#include <sfx2/taskpane.hxx>
-#include <sfx2/app.hxx>
-#include <sfx2/objface.hxx>
-#include "openflag.hxx"
-#include "objshimp.hxx"
-#include <sfx2/viewsh.hxx>
-#include <sfx2/objsh.hxx>
-#include <sfx2/bindings.hxx>
-#include <sfx2/dispatch.hxx>
-#include "arrdecl.hxx"
-#include "sfxtypes.hxx"
-#include <sfx2/request.hxx>
-#include <sfx2/docfac.hxx>
-#include <sfx2/ipclient.hxx>
-#include "sfxresid.hxx"
-#include "appbas.hxx"
-#include <sfx2/objitem.hxx>
-#include "viewfac.hxx"
-#include <sfx2/event.hxx>
-#include "fltfnc.hxx"
-#include <sfx2/docfile.hxx>
-#include <sfx2/module.hxx>
-#include <sfx2/msgpool.hxx>
-#include <sfx2/viewfrm.hxx>
-#include "viewimp.hxx"
-#include <sfx2/sfxbasecontroller.hxx>
-#include <sfx2/sfx.hrc>
-#include "view.hrc"
-#include <sfx2/frmdescr.hxx>
-#include <sfx2/sfxuno.hxx>
-#include <sfx2/progress.hxx>
-#include "workwin.hxx"
-#include "helper.hxx"
-#include "macro.hxx"
-#include "minfitem.hxx"
-#include "../appl/app.hrc"
-#include "impviewframe.hxx"
-
-//-------------------------------------------------------------------------
-DBG_NAME(SfxViewFrame)
-
-#define SfxViewFrame
-#include "sfxslots.hxx"
-#undef SfxViewFrame
-
-//-------------------------------------------------------------------------
-
-SFX_IMPL_INTERFACE(SfxViewFrame,SfxShell,SfxResId(0))
-{
- SFX_CHILDWINDOW_REGISTRATION( SID_BROWSER );
- SFX_CHILDWINDOW_REGISTRATION( SID_RECORDING_FLOATWINDOW );
-
- SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_FULLSCREEN | SFX_VISIBILITY_FULLSCREEN, SfxResId(RID_FULLSCREENTOOLBOX) );
- SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_STANDARD, SfxResId(RID_ENVTOOLBOX) );
-}
-
-TYPEINIT2(SfxViewFrame,SfxShell,SfxListener);
-TYPEINIT1(SfxViewFrameItem, SfxPoolItem);
-
-//=========================================================================
-
-//-------------------------------------------------------------------------
-namespace
-{
- bool moduleHasToolPanels( SfxViewFrame_Impl& i_rViewFrameImpl )
- {
- if ( !i_rViewFrameImpl.aHasToolPanels )
- {
- i_rViewFrameImpl.aHasToolPanels.reset( ::sfx2::ModuleTaskPane::ModuleHasToolPanels(
- i_rViewFrameImpl.rFrame.GetFrameInterface() ) );
- }
- return *i_rViewFrameImpl.aHasToolPanels;
- }
-}
-
-//-------------------------------------------------------------------------
-static sal_Bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const ::rtl::OUString& aPath, const SfxFilter* pFilter, sal_uInt32 nPasswordHash )
-{
- sal_Bool bResult = !nPasswordHash;
-
- OSL_ENSURE( pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ), "PasswordToModify feature is active for a filter that does not support it!" );
-
- if ( pFilter && xHandler.is() )
- {
- sal_Bool bCancel = sal_False;
- sal_Bool bFirstTime = sal_True;
-
- while ( !bResult && !bCancel )
- {
- sal_Bool bMSType = !pFilter->IsOwnFormat();
-
- ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest(
- new ::comphelper::DocPasswordRequest(
- bMSType ? ::comphelper::DocPasswordRequestType_MS : ::comphelper::DocPasswordRequestType_STANDARD,
- bFirstTime ? ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER : ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER,
- aPath,
- sal_True ) );
-
- uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
- xHandler->handle( rRequest );
-
- if ( pPasswordRequest->isPassword() )
- bResult = ( SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pFilter->GetServiceName() ) ) == nPasswordHash );
- else
- bCancel = sal_True;
-
- bFirstTime = sal_False;
- }
- }
-
- return bResult;
-}
-
-//-------------------------------------------------------------------------
-void SfxViewFrame::SetDowning_Impl()
-{
- pImp->bIsDowning = sal_True;
-}
-
-//-------------------------------------------------------------------------
-sal_Bool SfxViewFrame::IsDowning_Impl() const
-{
- return pImp->bIsDowning;
-}
-
-
-//--------------------------------------------------------------------
-class SfxViewNotificatedFrameList_Impl :
- public SfxListener, public SfxViewFrameArr_Impl
-{
-public:
-
- void InsertViewFrame( SfxViewFrame* pFrame )
- {
- StartListening( *pFrame );
- C40_INSERT( SfxViewFrame, pFrame, Count() );
- }
- void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
-};
-
-//-------------------------------------------------------------------------
-void SfxViewNotificatedFrameList_Impl::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
-{
- if ( rHint.IsA(TYPE(SfxSimpleHint)) )
- {
- switch( ( (SfxSimpleHint&) rHint ).GetId() )
- {
- case SFX_HINT_DYING:
- SfxViewFrame* pFrame = (SfxViewFrame*) &rBC;
- if( pFrame )
- {
- sal_uInt16 nPos = C40_GETPOS( SfxViewFrame, pFrame );
- if( nPos != USHRT_MAX )
- Remove( nPos );
- }
- break;
- }
- }
-}
-
-//-------------------------------------------------------------------------
-
-long ReloadDecouple_Impl( void* pObj, void* pArg )
-{
- ((SfxViewFrame*) pObj)->ExecReload_Impl( *(SfxRequest*)pArg );
- return 0;
-}
-
-void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq, sal_Bool bAsync )
-{
- if( bAsync )
- {
- if( !pImp->pReloader )
- pImp->pReloader = new svtools::AsynchronLink(
- Link( this, ReloadDecouple_Impl ) );
- pImp->pReloader->Call( new SfxRequest( rReq ) );
- }
- else ExecReload_Impl( rReq );
-}
-
-void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
-{
- SfxFrame *pParent = GetFrame().GetParentFrame();
- if ( rReq.GetSlot() == SID_RELOAD )
- {
- // Bei CTRL-Reload den aktiven Frame reloaden
- SfxViewFrame* pActFrame = this;
- while ( pActFrame )
- pActFrame = pActFrame->GetActiveChildFrame_Impl();
-
- if ( pActFrame )
- {
- sal_uInt16 nModifier = rReq.GetModifier();
- if ( nModifier & KEY_MOD1 )
- {
- pActFrame->ExecReload_Impl( rReq );
- return;
- }
- }
-
- // Wenn nur ein Reload der Graphiken eines oder mehrerer ChildFrames
- // gemacht werden soll
- SfxFrame& rFrame = GetFrame();
- if ( pParent == &rFrame && rFrame.GetChildFrameCount() )
- {
- sal_Bool bReloadAvailable = sal_False;
- SfxFrameIterator aIter( rFrame, sal_False );
- SfxFrame *pChild = aIter.FirstFrame();
- while ( pChild )
- {
- SfxFrame *pNext = aIter.NextFrame( *pChild );
- SfxObjectShell *pShell = pChild->GetCurrentDocument();
- if( pShell && pShell->Get_Impl()->bReloadAvailable )
- {
- bReloadAvailable = sal_True;
- pChild->GetCurrentViewFrame()->ExecuteSlot( rReq );
- }
- pChild = pNext;
- }
-
- // Der TopLevel-Frame selbst het keine Graphiken!
- if ( bReloadAvailable )
- return;
- }
- }
- else
- {
- // Bei CTRL-Edit den TopFrame bearbeiten
- sal_uInt16 nModifier = rReq.GetModifier();
-
- if ( ( nModifier & KEY_MOD1 ) && pParent )
- {
- SfxViewFrame *pTop = GetTopViewFrame();
- pTop->ExecReload_Impl( rReq );
- return;
- }
- }
-
- SfxObjectShell* pSh = GetObjectShell();
- switch ( rReq.GetSlot() )
- {
- case SID_EDITDOC:
- {
- if ( GetFrame().HasComponent() )
- break;
-
- // Wg. Doppeltbelegung in Toolboxen (mit/ohne Ctrl) ist es auch
- // m"oglich, da\s der Slot zwar enabled ist, aber Ctrl-Click
- // trotzdem nicht geht!
- if( !pSh || !pSh->HasName() || !(pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ))
- break;
-
- SfxMedium* pMed = pSh->GetMedium();
-
- SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_VIEWONLY, sal_False );
- if ( pItem && pItem->GetValue() )
- {
- SfxApplication* pApp = SFX_APP();
- SfxAllItemSet aSet( pApp->GetPool() );
- aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetURLObject().GetMainURL(INetURLObject::NO_DECODE) ) );
- aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
- aSet.Put( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_blank") ) );
- SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False );
- if ( pReferer )
- aSet.Put( *pReferer );
- SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pVersionItem, SfxInt16Item, SID_VERSION, sal_False );
- if ( pVersionItem )
- aSet.Put( *pVersionItem );
-
- if( pMed->GetFilter() )
- {
- aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
- SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
- if ( pOptions )
- aSet.Put( *pOptions );
- }
-
- GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
- return;
- }
-
- sal_uInt16 nOpenMode;
- sal_Bool bNeedsReload = sal_False;
- if ( !pSh->IsReadOnly() )
- {
- // Speichern und Readonly Reloaden
- if( pSh->IsModified() )
- {
- if ( pSh->PrepareClose() )
- {
- // the storing could let the medium be changed
- pMed = pSh->GetMedium();
- bNeedsReload = sal_True;
- }
- else
- {
- rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) );
- return;
- }
- }
- nOpenMode = SFX_STREAM_READONLY;
- }
- else
- {
- if ( pSh->IsReadOnlyMedium()
- && pSh->GetModifyPasswordHash()
- && !pSh->IsModifyPasswordEntered() )
- {
- ::rtl::OUString aDocumentName = INetURLObject( pMed->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
- if( !AskPasswordToModify_Impl( pMed->GetInteractionHandler(), aDocumentName, pMed->GetOrigFilter(), pSh->GetModifyPasswordHash() ) )
- {
- // this is a read-only document, if it has "Password to modify"
- // the user should enter password before he can edit the document
- rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) );
- return;
- }
-
- pSh->SetModifyPasswordEntered();
- }
-
- nOpenMode = SFX_STREAM_READWRITE;
- pSh->SetReadOnlyUI( sal_False );
-
- // if only the view was in the readonly mode then there is no need to do the reload
- if ( !pSh->IsReadOnly() )
- return;
- }
-
- // Parameter auswerten
- // sal_Bool bReload = sal_True;
- if ( rReq.IsAPI() )
- {
- // per API steuern ob r/w oder r/o
- SFX_REQUEST_ARG(rReq, pEditItem, SfxBoolItem, SID_EDITDOC, sal_False);
- if ( pEditItem )
- nOpenMode = pEditItem->GetValue() ? SFX_STREAM_READWRITE : SFX_STREAM_READONLY;
- }
-
- // doing
-
- String aTemp;
- utl::LocalFileHelper::ConvertPhysicalNameToURL( pMed->GetPhysicalName(), aTemp );
- INetURLObject aPhysObj( aTemp );
- SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(),
- pVersionItem, SfxInt16Item, SID_VERSION, sal_False );
-
- INetURLObject aMedObj( pMed->GetName() );
-
- // the logic below is following, if the document seems not to need to be reloaded and the physical name is different
- // to the logical one, then on file system it can be checked that the copy is still newer than the original and no document reload is required
- if ( ( !bNeedsReload && ( (aMedObj.GetProtocol() == INET_PROT_FILE &&
- aMedObj.getFSysPath(INetURLObject::FSYS_DETECT) != aPhysObj.getFSysPath(INetURLObject::FSYS_DETECT) &&
- !::utl::UCBContentHelper::IsYounger( aMedObj.GetMainURL( INetURLObject::NO_DECODE ), aPhysObj.GetMainURL( INetURLObject::NO_DECODE ) ))
- || pMed->IsRemote() ) )
- || pVersionItem )
- {
- sal_Bool bOK = sal_False;
- if ( !pVersionItem )
- {
- sal_Bool bHasStorage = pMed->HasStorage_Impl();
- // switching edit mode could be possible without reload
- if ( bHasStorage && pMed->GetStorage() == pSh->GetStorage() )
- {
- // TODO/LATER: faster creation of copy
- if ( !pSh->ConnectTmpStorage_Impl( pMed->GetStorage(), pMed ) )
- return;
- }
-
- pMed->CloseAndRelease();
- pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) );
- pMed->SetOpenMode( nOpenMode, pMed->IsDirect() );
-
- pMed->CompleteReOpen();
- if ( nOpenMode & STREAM_WRITE )
- pMed->LockOrigFileOnDemand( sal_False, sal_True );
-
- // LockOrigFileOnDemand might set the readonly flag itself, it should be set back
- pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) );
-
- if ( !pMed->GetErrorCode() )
- bOK = sal_True;
- }
-
- if( !bOK )
- {
- ErrCode nErr = pMed->GetErrorCode();
- if ( pVersionItem )
- nErr = ERRCODE_IO_ACCESSDENIED;
- else
- {
- pMed->ResetError();
- pMed->SetOpenMode( SFX_STREAM_READONLY, pMed->IsDirect() );
- pMed->ReOpen();
- pSh->DoSaveCompleted( pMed );
- }
-
- // r/o-Doc kann nicht in Editmode geschaltet werden?
- rReq.Done( sal_False );
-
- if ( nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI() )
- {
- // dem ::com::sun::star::sdbcx::User anbieten, als Vorlage zu oeffnen
- QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) );
- if ( RET_YES == aBox.Execute() )
- {
- SfxApplication* pApp = SFX_APP();
- SfxAllItemSet aSet( pApp->GetPool() );
- aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
- SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False );
- if ( pReferer )
- aSet.Put( *pReferer );
- aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
- if ( pVersionItem )
- aSet.Put( *pVersionItem );
-
- if( pMed->GetFilter() )
- {
- aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
- SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions,
- SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
- if ( pOptions )
- aSet.Put( *pOptions );
- }
-
- GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
- return;
- }
- else
- nErr = 0;
- }
-
- ErrorHandler::HandleError( nErr );
- rReq.SetReturnValue(
- SfxBoolItem( rReq.GetSlot(), sal_False ) );
- return;
- }
- else
- {
- pSh->DoSaveCompleted( pMed );
- pSh->Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
- rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_True ) );
- rReq.Done( sal_True );
- // if( nOpenMode == SFX_STREAM_READONLY )
- // pMed->Close();
- return;
- }
- }
-
- rReq.AppendItem( SfxBoolItem( SID_FORCERELOAD, sal_True) );
- rReq.AppendItem( SfxBoolItem( SID_SILENT, sal_True ));
- }
-
- case SID_RELOAD:
- {
- // Wg. Doppeltbelegung in Toolboxen (mit/ohne Ctrl) ist es auch
- // m"oglich, da\s der Slot zwar enabled ist, aber Ctrl-Click
- // trotzdem nicht geht!
- if ( !pSh || !pSh->CanReload_Impl() )
- break;
- SfxApplication* pApp = SFX_APP();
- SFX_REQUEST_ARG(rReq, pForceReloadItem, SfxBoolItem,
- SID_FORCERELOAD, sal_False);
- if( pForceReloadItem && !pForceReloadItem->GetValue() &&
- !pSh->GetMedium()->IsExpired() )
- return;
- if( pImp->bReloading || pSh->IsInModalMode() )
- return;
-
- // AutoLoad ist ggf. verboten
- SFX_REQUEST_ARG(rReq, pAutoLoadItem, SfxBoolItem, SID_AUTOLOAD, sal_False);
- if ( pAutoLoadItem && pAutoLoadItem->GetValue() &&
- GetFrame().IsAutoLoadLocked_Impl() )
- return;
-
- SfxObjectShellLock xOldObj( pSh );
- pImp->bReloading = sal_True;
- SFX_REQUEST_ARG(rReq, pURLItem, SfxStringItem,
- SID_FILE_NAME, sal_False);
- // editierbar "offnen?
- sal_Bool bForEdit = !pSh->IsReadOnly();
- if ( rReq.GetSlot() == SID_EDITDOC )
- bForEdit = !bForEdit;
-
- // ggf. beim User nachfragen
- sal_Bool bDo = ( GetViewShell()->PrepareClose() != FALSE );
- SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
- if ( bDo && GetFrame().DocIsModified_Impl() &&
- !rReq.IsAPI() && ( !pSilentItem || !pSilentItem->GetValue() ) )
- {
- QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_LASTVERSION) );
- bDo = ( RET_YES == aBox.Execute() );
- }
-
- if ( bDo )
- {
- SfxMedium *pMedium = xOldObj->GetMedium();
-
- // Frameset abziehen, bevor FramesetView evtl. verschwindet
- String aURL = pURLItem ? pURLItem->GetValue() :
- pMedium->GetName();
-
- sal_Bool bHandsOff =
- ( pMedium->GetURLObject().GetProtocol() == INET_PROT_FILE && !xOldObj->IsDocShared() );
-
- // bestehende SfxMDIFrames f"ur dieses Doc leeren
- // eigenes Format oder R/O jetzt editierbar "offnen?
- SfxObjectShellLock xNewObj;
-
- // collect the views of the document
- // TODO: when UNO ViewFactories are available for SFX-based documents, the below code should
- // be UNOized, too
- typedef ::std::pair< Reference< XFrame >, USHORT > ViewDescriptor;
- ::std::list< ViewDescriptor > aViewFrames;
- SfxViewFrame *pView = GetFirst( xOldObj );
- while ( pView )
- {
- Reference< XFrame > xFrame( pView->GetFrame().GetFrameInterface() );
- OSL_ENSURE( xFrame.is(), "SfxViewFrame::ExecReload_Impl: no XFrame?!" );
- aViewFrames.push_back( ViewDescriptor( xFrame, pView->GetCurViewId() ) );
-
- pView = GetNext( *pView, xOldObj );
- }
-
- DELETEZ( xOldObj->Get_Impl()->pReloadTimer );
-
- SfxItemSet* pNewSet = 0;
- const SfxFilter *pFilter = pMedium->GetFilter();
- if( pURLItem )
- {
- pNewSet = new SfxAllItemSet( pApp->GetPool() );
- pNewSet->Put( *pURLItem );
-
- // Filter Detection
- SfxMedium aMedium( pURLItem->GetValue(), SFX_STREAM_READWRITE );
- SfxFilterMatcher().GuessFilter( aMedium, &pFilter );
- if ( pFilter )
- pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
- pNewSet->Put( *aMedium.GetItemSet() );
- }
- else
- {
- pNewSet = new SfxAllItemSet( *pMedium->GetItemSet() );
- pNewSet->ClearItem( SID_VIEW_ID );
- pNewSet->ClearItem( SID_STREAM );
- pNewSet->ClearItem( SID_INPUTSTREAM );
- pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pMedium->GetFilter()->GetName() ) );
-
- // let the current security settings be checked again
- pNewSet->Put( SfxUInt16Item( SID_MACROEXECMODE, document::MacroExecMode::USE_CONFIG ) );
-
- if ( rReq.GetSlot() == SID_EDITDOC || !bForEdit )
- // edit mode is switched or reload of readonly document
- pNewSet->Put( SfxBoolItem( SID_DOC_READONLY, !bForEdit ) );
- else
- // Reload of file opened for writing
- pNewSet->ClearItem( SID_DOC_READONLY );
- }
-
- // Falls eine salvagede Datei vorliegt, nicht nochmals die
- // OrigURL mitschicken, denn die Tempdate ist nach Reload
- // ungueltig
- SFX_ITEMSET_ARG( pNewSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
- if( pSalvageItem )
- {
- aURL = pSalvageItem->GetValue();
- pNewSet->ClearItem( SID_DOC_SALVAGE );
- }
-
- // TODO/LATER: Temporary solution, the SfxMedium must know the original URL as aLogicName
- // SfxMedium::Transfer_Impl() will be vorbidden then.
- if ( xOldObj->IsDocShared() )
- pNewSet->Put( SfxStringItem( SID_FILE_NAME, xOldObj->GetSharedFileURL() ) );
-
- //pNewMedium = new SfxMedium( aURL, nMode, pMedium->IsDirect(), bUseFilter ? pMedium->GetFilter() : 0, pNewSet );
- //pNewSet = pNewMedium->GetItemSet();
- if ( pURLItem )
- pNewSet->Put( SfxStringItem( SID_REFERER, pMedium->GetName() ) );
- else
- pNewSet->Put( SfxStringItem( SID_REFERER, String() ) );
-
- xOldObj->CancelTransfers();
-
- // eigentliches Reload
- //pNewSet->Put( SfxFrameItem ( SID_DOCFRAME, GetFrame() ) );
-
- if ( pSilentItem && pSilentItem->GetValue() )
- pNewSet->Put( SfxBoolItem( SID_SILENT, sal_True ) );
-
- SFX_ITEMSET_ARG(pNewSet, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, FALSE);
- SFX_ITEMSET_ARG(pNewSet, pMacroExecItem , SfxUInt16Item, SID_MACROEXECMODE , FALSE);
- SFX_ITEMSET_ARG(pNewSet, pDocTemplateItem, SfxUInt16Item, SID_UPDATEDOCMODE , FALSE);
-
- if (!pInteractionItem)
- {
- Reference < ::com::sun::star::task::XInteractionHandler > xHdl( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY );
- if (xHdl.is())
- pNewSet->Put( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHdl)) );
- }
-
- if (!pMacroExecItem)
- pNewSet->Put( SfxUInt16Item(SID_MACROEXECMODE,::com::sun::star::document::MacroExecMode::USE_CONFIG) );
- if (!pDocTemplateItem)
- pNewSet->Put( SfxUInt16Item(SID_UPDATEDOCMODE,::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG) );
-
- xOldObj->SetModified( sal_False );
- // Altes Dok nicht cachen! Gilt nicht, wenn anderes
- // Doc geladen wird.
-
- SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False);
- SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedReferer, SfxStringItem, SID_REFERER, sal_False);
-
- sal_Bool bHasStorage = pMedium->HasStorage_Impl();
- if( bHandsOff )
- {
- if ( bHasStorage && pMedium->GetStorage() == xOldObj->GetStorage() )
- {
- // TODO/LATER: faster creation of copy
- if ( !xOldObj->ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
- return;
- }
-
- pMedium->CloseAndRelease();
- }
-
- xNewObj = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_STANDARD );
-
- if ( xOldObj->IsModifyPasswordEntered() )
- xNewObj->SetModifyPasswordEntered();
-
- uno::Sequence < beans::PropertyValue > aLoadArgs;
- TransformItems( SID_OPENDOC, *pNewSet, aLoadArgs );
- try
- {
- uno::Reference < frame::XLoadable > xLoad( xNewObj->GetModel(), uno::UNO_QUERY );
- xLoad->load( aLoadArgs );
- }
- catch ( uno::Exception& )
- {
- xNewObj->DoClose();
- xNewObj = 0;
- }
-
- DELETEZ( pNewSet );
-
- if( !xNewObj.Is() )
- {
- if( bHandsOff )
- {
- // back to old medium
- pMedium->ReOpen();
- pMedium->LockOrigFileOnDemand( sal_False, sal_True );
-
- xOldObj->DoSaveCompleted( pMedium );
- }
-
- // r/o-Doc couldn't be switched to writing mode
- if ( bForEdit && SID_EDITDOC == rReq.GetSlot() )
- {
- // ask user for opening as template
- QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) );
- if ( RET_YES == aBox.Execute() )
- {
- SfxAllItemSet aSet( pApp->GetPool() );
- aSet.Put( SfxStringItem( SID_FILE_NAME, pMedium->GetName() ) );
- aSet.Put( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_blank") ) );
- if ( pSavedOptions )
- aSet.Put( *pSavedOptions );
- if ( pSavedReferer )
- aSet.Put( *pSavedReferer );
- aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
- if( pFilter )
- aSet.Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetFilterName() ) );
- GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
- }
- }
- else
- {
- // an error handling should be done here?!
- // if ( !pSilentItem || !pSilentItem->GetValue() )
- // ErrorHandler::HandleError( nLoadError );
- }
- }
- else
- {
- if ( xNewObj->GetModifyPasswordHash() && xNewObj->GetModifyPasswordHash() != xOldObj->GetModifyPasswordHash() )
- {
- xNewObj->SetModifyPasswordEntered( sal_False );
- xNewObj->SetReadOnly();
- }
-
- if ( xNewObj->IsDocShared() )
- {
- // the file is shared but the closing can change the sharing control file
- xOldObj->DoNotCleanShareControlFile();
- }
-
- // the Reload and Silent items were only temporary, remove them
- xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_RELOAD );
- xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_SILENT );
- TransformItems( SID_OPENDOC, *xNewObj->GetMedium()->GetItemSet(), aLoadArgs );
-
- UpdateDocument_Impl();
-
- try
- {
- while ( !aViewFrames.empty() )
- {
- LoadViewIntoFrame_Impl( *xNewObj, aViewFrames.front().first, aLoadArgs, aViewFrames.front().second, false );
- aViewFrames.pop_front();
- }
- }
- catch( const Exception& )
- {
- // close the remaining frames
- // Don't catch exceptions herein, if this fails, then we're left in an indetermined state, and
- // crashing is better than trying to proceed
- while ( !aViewFrames.empty() )
- {
- Reference< util::XCloseable > xClose( aViewFrames.front().first, UNO_QUERY_THROW );
- xClose->close( sal_True );
- aViewFrames.pop_front();
- }
- }
-
- // Propagate document closure.
- SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ), xOldObj ) );
- }
-
- // als erledigt recorden
- rReq.Done( sal_True );
- rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_True));
- return;
- }
- else
- {
- // als nicht erledigt recorden
- rReq.Done();
- rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_False));
- pImp->bReloading = sal_False;
- return;
- }
- }
- }
-}
-
-//-------------------------------------------------------------------------
-void SfxViewFrame::StateReload_Impl( SfxItemSet& rSet )
-{
- SfxObjectShell* pSh = GetObjectShell();
- if ( !pSh )
- // Ich bin gerade am Reloaden und Yielde so vor mich hin ...
- return;
-
- GetFrame().GetParentFrame();
- SfxWhichIter aIter( rSet );
- for ( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() )
- {
- if ( GetFrame().HasComponent() )
- {
- // Wenn die Komponente es nicht selbst dispatched, dann
- // macht es auch keinen Sinn!
- rSet.DisableItem( nWhich );
- continue;
- }
-
- switch ( nWhich )
- {
- case SID_EDITDOC:
- {
- if ( !pSh || !pSh->HasName() || !( pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
- || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
- rSet.DisableItem( SID_EDITDOC );
- else
- {
- SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, sal_False );
- if ( pItem && !pItem->GetValue() )
- rSet.DisableItem( SID_EDITDOC );
- else
- rSet.Put( SfxBoolItem( nWhich, !pSh->IsReadOnly() ) );
- }
- break;
- }
-
- case SID_RELOAD:
- {
- SfxFrame* pFrame = &GetTopFrame();
-
- if ( !pSh || !pSh->CanReload_Impl() || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
- rSet.DisableItem(nWhich);
- else
- {
- // Wenn irgendein ChildFrame reloadable ist, wird der Slot
- // enabled, damit man CTRL-Reload machen kann
- sal_Bool bReloadAvailable = sal_False;
- SfxFrameIterator aFrameIter( *pFrame, sal_True );
- for( SfxFrame* pNextFrame = aFrameIter.FirstFrame();
- pFrame;
- pNextFrame = pNextFrame ?
- aFrameIter.NextFrame( *pNextFrame ) : 0 )
- {
- SfxObjectShell *pShell = pFrame->GetCurrentDocument();
- if( pShell && pShell->Get_Impl()->bReloadAvailable )
- {
- bReloadAvailable = sal_True;
- break;
- }
- pFrame = pNextFrame;
- }
-
- rSet.Put( SfxBoolItem( nWhich, bReloadAvailable));
- }
-
- break;
- }
- }
- }
-}
-
-
-//--------------------------------------------------------------------
-void SfxViewFrame::ExecHistory_Impl( SfxRequest &rReq )
-{
- // gibt es an der obersten Shell einen Undo-Manager?
- SfxShell *pSh = GetDispatcher()->GetShell(0);
- SfxUndoManager* pShUndoMgr = pSh->GetUndoManager();
- sal_Bool bOK = sal_False;
- if ( pShUndoMgr )
- {
- switch ( rReq.GetSlot() )
- {
- case SID_CLEARHISTORY:
- pShUndoMgr->Clear();
- bOK = sal_True;
- break;
-
- case SID_UNDO:
- pShUndoMgr->Undo(0);
- GetBindings().InvalidateAll(sal_False);
- bOK = sal_True;
- break;
-
- case SID_REDO:
- pShUndoMgr->Redo(0);
- GetBindings().InvalidateAll(sal_False);
- bOK = sal_True;
- break;
-
- case SID_REPEAT:
- if ( pSh->GetRepeatTarget() )
- pShUndoMgr->Repeat( *pSh->GetRepeatTarget(), 0);
- bOK = sal_True;
- break;
- }
- }
- else if ( GetViewShell() )
- {
- // der SW hat eigenes Undo an der View
- const SfxPoolItem *pRet = GetViewShell()->ExecuteSlot( rReq );
- if ( pRet )
- bOK = ((SfxBoolItem*)pRet)->GetValue();
- }
-
- rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bOK ) );
- rReq.Done();
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::StateHistory_Impl( SfxItemSet &rSet )
-{
- // Undo-Manager suchen
- SfxShell *pSh = GetDispatcher()->GetShell(0);
- if ( !pSh )
- // Ich bin gerade am Reloaden und Yielde so vor mich hin ...
- return;
-
- SfxUndoManager *pShUndoMgr = pSh->GetUndoManager();
- if ( !pShUndoMgr )
- {
- // der SW hat eigenes Undo an der View
- SfxWhichIter aIter( rSet );
- SfxViewShell *pViewSh = GetViewShell();
- if( !pViewSh ) return;
- for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
- pViewSh->GetSlotState( nSID, 0, &rSet );
- return;
- }
-
- if ( pShUndoMgr->GetUndoActionCount() == 0 &&
- pShUndoMgr->GetRedoActionCount() == 0 &&
- pShUndoMgr->GetRepeatActionCount() == 0 )
- rSet.DisableItem( SID_CLEARHISTORY );
-
- if ( pShUndoMgr && pShUndoMgr->GetUndoActionCount() )
- {
- String aTmp( SfxResId( STR_UNDO ) );
- aTmp += pShUndoMgr->GetUndoActionComment(0);
- rSet.Put( SfxStringItem( SID_UNDO, aTmp ) );
- }
- else
- rSet.DisableItem( SID_UNDO );
-
- if ( pShUndoMgr && pShUndoMgr->GetRedoActionCount() )
- {
- String aTmp( SfxResId(STR_REDO) );
- aTmp += pShUndoMgr->GetRedoActionComment(0);
- rSet.Put( SfxStringItem( SID_REDO, aTmp ) );
- }
- else
- rSet.DisableItem( SID_REDO );
- SfxRepeatTarget *pTarget = pSh->GetRepeatTarget();
- if ( pShUndoMgr && pTarget && pShUndoMgr->GetRepeatActionCount() &&
- pShUndoMgr->CanRepeat(*pTarget, 0) )
- {
- String aTmp( SfxResId(STR_REPEAT) );
- aTmp += pShUndoMgr->GetRepeatActionComment(*pTarget, 0);
- rSet.Put( SfxStringItem( SID_REPEAT, aTmp ) );
- }
- else
- rSet.DisableItem( SID_REPEAT );
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::PopShellAndSubShells_Impl( SfxViewShell& i_rViewShell )
-{
- i_rViewShell.PopSubShells_Impl();
- sal_uInt16 nLevel = pDispatcher->GetShellLevel( i_rViewShell );
- if ( nLevel != USHRT_MAX )
- {
- if ( nLevel )
- {
- // more sub shells on the stack, which were not affected by PopSubShells_Impl
- SfxShell *pSubShell = pDispatcher->GetShell( nLevel-1 );
- if ( pSubShell == i_rViewShell.GetSubShell() )
- // "real" sub shells will be deleted elsewhere
- pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL );
- else
- pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL | SFX_SHELL_POP_DELETE );
- }
- pDispatcher->Pop( i_rViewShell );
- pDispatcher->Flush();
- }
-
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::ReleaseObjectShell_Impl()
-
-/* [Beschreibung]
-
- Diese Methode entleert den SfxViewFrame, d.h. nimmt die <SfxObjectShell>
- vom Dispatcher und beendet seine <SfxListener>-Beziehung zu dieser
- SfxObjectShell (wodurch sie sich ggf. selbst zerst"ort).
-
- Somit kann durch Aufruf von ReleaseObjectShell() und SetObjectShell()
- die SfxObjectShell ausgetauscht werden.
-
- Zwischen RealeaseObjectShell() und SetObjectShell() darf die Kontrolle
- nicht an das System abgegeben werden.
-
-
- [Querverweise]
-
- <SfxViewFrame::SetObjectShell(SfxObjectShell&)>
-*/
-{
- DBG_CHKTHIS(SfxViewFrame, 0);
- DBG_ASSERT( xObjSh.Is(), "no SfxObjectShell to release!" );
-
- GetFrame().ReleasingComponent_Impl( sal_True );
- if ( GetWindow().HasChildPathFocus( sal_True ) )
- {
- DBG_ASSERT( !GetActiveChildFrame_Impl(), "Wrong active child frame!" );
- GetWindow().GrabFocus();
- }
-
- SfxViewShell *pDyingViewSh = GetViewShell();
- if ( pDyingViewSh )
- {
- PopShellAndSubShells_Impl( *pDyingViewSh );
- pDyingViewSh->DisconnectAllClients();
- SetViewShell_Impl(0);
- delete pDyingViewSh;
- }
-#ifdef DBG_UTIL
- else
- DBG_ERROR("Keine Shell");
-#endif
-
- if ( xObjSh.Is() )
- {
- pImp->aLastType = xObjSh->Type();
- pDispatcher->Pop( *xObjSh );
- SfxModule* pModule = xObjSh->GetModule();
- if( pModule )
- pDispatcher->RemoveShell_Impl( *pModule );
- pDispatcher->Flush();
- EndListening( *xObjSh );
-
- Notify( *xObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) );
- Notify( *xObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) );
-
- if ( 1 == xObjSh->GetOwnerLockCount() && pImp->bObjLocked && xObjSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
- xObjSh->DoClose();
- SfxObjectShellRef xDyingObjSh = xObjSh;
- xObjSh.Clear();
- if( ( GetFrameType() & SFXFRAME_HASTITLE ) && pImp->nDocViewNo )
- xDyingObjSh->GetNoSet_Impl().ReleaseIndex(pImp->nDocViewNo-1);
- if ( pImp->bObjLocked )
- {
- xDyingObjSh->OwnerLock( sal_False );
- pImp->bObjLocked = sal_False;
- }
- }
-
- GetDispatcher()->SetDisableFlags( 0 );
-}
-
-//--------------------------------------------------------------------
-sal_Bool SfxViewFrame::Close()
-{
- DBG_CHKTHIS(SfxViewFrame, 0);
-
- DBG_ASSERT( GetFrame().IsClosing_Impl() || !GetFrame().GetFrameInterface().is(), "ViewFrame closed too early!" );
-
- // Wenn bis jetzt noch nicht gespeichert wurde, sollen eingebettete Objekte
- // auch nicht mehr automatisch gespeichert werden!
- if ( GetViewShell() )
- GetViewShell()->DiscardClients_Impl();
- Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
-
- if (SfxViewFrame::Current() == this)
- SfxViewFrame::SetViewFrame( NULL );
-
- // Da der Dispatcher leer ger"aumt wird, kann man ihn auch nicht mehr
- // vern"unftig verwenden - also besser still legen
- GetDispatcher()->Lock(sal_True);
- delete this;
-
- return sal_True;
-}
-
-//--------------------------------------------------------------------
-
-void SfxViewFrame::DoActivate( sal_Bool bUI, SfxViewFrame* pOldFrame )
-{
- DBG_CHKTHIS(SfxViewFrame, 0);
- SFX_APP();
-
-#ifdef WIN
- pSfxApp->TestFreeResources_Impl();
-#endif
-
- pDispatcher->DoActivate_Impl( bUI, pOldFrame );
-
- // Wenn ich einen parent habe und dieser ist kein parent des alten
- // ViewFrames, erh"alt er ein ParentActivate
- if ( bUI )
- {
-/*
- SfxMedium* pMed = GetObjectShell() ? GetObjectShell()->GetMedium() : NULL;
- if( pMed )
- {
- SFX_ITEMSET_ARG(
- pMed->GetItemSet(), pInterceptorItem, SfxSlotInterceptorItem,
- SID_INTERCEPTOR, sal_False );
- if( pInterceptorItem )
- {
- SfxSlotInterceptor* pInter = pInterceptorItem->GetValue();
- if( !pInter->GetBindings() )
- pInter->SetBindings( &GetBindings() );
- pInter->Activate( sal_True );
- }
- }
- */
- SfxViewFrame *pFrame = GetParentViewFrame();
- while ( pFrame )
- {
- if ( !pOldFrame || !pOldFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
- pFrame->pDispatcher->DoParentActivate_Impl();
- pFrame = pFrame->GetParentViewFrame();
- }
- }
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::DoDeactivate(sal_Bool bUI, SfxViewFrame* pNewFrame )
-{
- DBG_CHKTHIS(SfxViewFrame, 0);
- SFX_APP();
- pDispatcher->DoDeactivate_Impl( bUI, pNewFrame );
-
- // Wenn ich einen parent habe und dieser ist kein parent des neuen
- // ViewFrames, erh"alt er ein ParentDeactivate
- if ( bUI )
- {
-// if ( GetFrame().GetWorkWindow_Impl() )
-// GetFrame().GetWorkWindow_Impl()->SaveStatus_Impl();
-/*
- SfxMedium* pMed = GetObjectShell() ? GetObjectShell()->GetMedium() : NULL;
- if( pMed )
- {
- SFX_ITEMSET_ARG(
- pMed->GetItemSet(), pInterceptorItem, SfxSlotInterceptorItem,
- SID_INTERCEPTOR, sal_False );
- if( pInterceptorItem )
- pInterceptorItem->GetValue()->Activate( sal_False );
- }
-*/
- SfxViewFrame *pFrame = GetParentViewFrame();
- while ( pFrame )
- {
- if ( !pNewFrame || !pNewFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
- pFrame->pDispatcher->DoParentDeactivate_Impl();
- pFrame = pFrame->GetParentViewFrame();
- }
- }
-#ifdef WIN
- pSfxApp->TestFreeResources_Impl();
-#endif
-}
-
-//------------------------------------------------------------------------
-void SfxViewFrame::InvalidateBorderImpl( const SfxViewShell* pSh )
-{
- if( pSh && !nAdjustPosPixelLock )
- {
- if ( GetViewShell() && GetWindow().IsVisible() )
- {
- if ( GetFrame().IsInPlace() )
- {
- /*
- Size aSize( GetViewShell()->GetWindow()->GetSizePixel() );
-
- //Size aBorderSz( pEnv->GetBorderWin()->GetHatchBorderPixel() );
- Point aOfs; //( aBorderSz.Width(), aBorderSz.Height() );
-
- DoAdjustPosSizePixel( GetViewShell(), aOfs, aSize );*/
- return;
- }
-
- DoAdjustPosSizePixel( (SfxViewShell *) GetViewShell(), Point(),
- GetWindow().GetOutputSizePixel() );
- }
- }
-}
-
-//------------------------------------------------------------------------
-sal_Bool SfxViewFrame::SetBorderPixelImpl
-(
- const SfxViewShell* pVSh,
- const SvBorder& rBorder
-)
-
-{
- pImp->aBorder = rBorder;
-
- if ( IsResizeInToOut_Impl() && !GetFrame().IsInPlace() )
- {
- Size aSize = pVSh->GetWindow()->GetOutputSizePixel();
- if ( aSize.Width() && aSize.Height() )
- {
- aSize.Width() += rBorder.Left() + rBorder.Right();
- aSize.Height() += rBorder.Top() + rBorder.Bottom();
-
- Size aOldSize = GetWindow().GetOutputSizePixel();
- GetWindow().SetOutputSizePixel( aSize );
- Window* pParent = &GetWindow();
- while ( pParent->GetParent() )
- pParent = pParent->GetParent();
- Size aOuterSize = pParent->GetOutputSizePixel();
- aOuterSize.Width() += ( aSize.Width() - aOldSize.Width() );
- aOuterSize.Height() += ( aSize.Height() - aOldSize.Height() );
- pParent->SetOutputSizePixel( aOuterSize );
- }
- }
- else
- {
- Point aPoint;
- Rectangle aEditArea( aPoint, GetWindow().GetOutputSizePixel() );
- aEditArea.Left() += rBorder.Left();
- aEditArea.Right() -= rBorder.Right();
- aEditArea.Top() += rBorder.Top();
- aEditArea.Bottom() -= rBorder.Bottom();
- pVSh->GetWindow()->SetPosSizePixel( aEditArea.TopLeft(), aEditArea.GetSize() );
- }
-
- return sal_True;
-}
-
-//------------------------------------------------------------------------
-const SvBorder& SfxViewFrame::GetBorderPixelImpl
-(
- const SfxViewShell* /*pSh*/
-) const
-
-{
- return pImp->aBorder;
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
-{
- {DBG_CHKTHIS(SfxViewFrame, 0);}
-
- if( IsDowning_Impl())
- return;
-
- // we know only SimpleHints
- if ( rHint.IsA(TYPE(SfxSimpleHint)) )
- {
- switch( ( (SfxSimpleHint&) rHint ).GetId() )
- {
- case SFX_HINT_MODECHANGED:
- {
- UpdateTitle();
-
- if ( !xObjSh.Is() )
- break;
-
- // r/o Umschaltung?
- SfxBindings& rBind = GetBindings();
- rBind.Invalidate( SID_RELOAD );
- SfxDispatcher *pDispat = GetDispatcher();
- sal_Bool bWasReadOnly = pDispat->GetReadOnly_Impl();
- sal_Bool bIsReadOnly = xObjSh->IsReadOnly();
- if ( !bWasReadOnly != !bIsReadOnly )
- {
- // Dann auch TITLE_CHANGED
- UpdateTitle();
- rBind.Invalidate( SID_FILE_NAME );
- rBind.Invalidate( SID_DOCINFO_TITLE );
- rBind.Invalidate( SID_EDITDOC );
-
- pDispat->GetBindings()->InvalidateAll(sal_True);
- pDispat->SetReadOnly_Impl( bIsReadOnly );
-
- // Dispatcher-Update nur erzwingen, wenn es nicht sowieso
- // demn"achst kommt, anderenfalls ist Zappelei oder gar
- // GPF m"oglich, da Writer z.B. gerne mal im Resize irgendwelche
- // Aktionen t"atigt, die ein SetReadOnlyUI am Dispatcher zur
- // Folge haben!
- if ( pDispat->IsUpdated_Impl() )
- pDispat->Update_Impl(sal_True);
- }
-
- Enable( !xObjSh->IsInModalMode() );
- break;
- }
-
- case SFX_HINT_TITLECHANGED:
- {
- UpdateTitle();
- SfxBindings& rBind = GetBindings();
- rBind.Invalidate( SID_FILE_NAME );
- rBind.Invalidate( SID_DOCINFO_TITLE );
- rBind.Invalidate( SID_EDITDOC );
- rBind.Invalidate( SID_RELOAD );
- break;
- }
-
- case SFX_HINT_DEINITIALIZING:
- GetFrame().DoClose();
- break;
- case SFX_HINT_DYING:
- // when the Object is being deleted, destroy the view too
- if ( xObjSh.Is() )
- ReleaseObjectShell_Impl();
- else
- GetFrame().DoClose();
- break;
-
- }
- }
- else if ( rHint.IsA(TYPE(SfxEventHint)) )
- {
- // Wenn das Document asynchron geladen wurde, wurde der Dispatcher
- // auf ReadOnly gesetzt, was zur"?ckgenommen werden mu\s, wenn
- // das Document selbst nicht ReadOnly ist und das Laden fertig ist.
- switch ( ((SfxEventHint&)rHint).GetEventId() )
- {
- case SFX_EVENT_MODIFYCHANGED:
- {
- SfxBindings& rBind = GetBindings();
- rBind.Invalidate( SID_DOC_MODIFIED );
- rBind.Invalidate( SID_SAVEDOC );
- rBind.Invalidate( SID_RELOAD );
- rBind.Invalidate( SID_EDITDOC );
- break;
- }
-
- case SFX_EVENT_OPENDOC:
- case SFX_EVENT_CREATEDOC:
- {
- if ( !xObjSh.Is() )
- break;
-
- SfxBindings& rBind = GetBindings();
- rBind.Invalidate( SID_RELOAD );
- rBind.Invalidate( SID_EDITDOC );
- if ( !xObjSh->IsReadOnly() )
- {
- // Im Gegensatz zu oben (TITLE_CHANGED) mu\s das UI nicht
- // upgedated werden, da es nicht gehidet war!
-
- // #i21560# InvalidateAll() causes the assertion
- // 'SfxBindings::Invalidate while in update" when
- // the sfx slot SID_BASICIDE_APPEAR is executed
- // via API from another thread (Java).
- // According to MBA this call is not necessary anymore,
- // because each document has its own SfxBindings.
- //
- //GetDispatcher()->GetBindings()->InvalidateAll(sal_True);
- }
-
- break;
- }
-
- case SFX_EVENT_TOGGLEFULLSCREENMODE:
- {
- if ( GetFrame().OwnsBindings_Impl() )
- GetBindings().GetDispatcher_Impl()->Update_Impl( sal_True );
- break;
- }
- }
- }
-}
-
-//------------------------------------------------------------------------
-void SfxViewFrame::Construct_Impl( SfxObjectShell *pObjSh )
-{
- pImp->bResizeInToOut = sal_True;
- pImp->bDontOverwriteResizeInToOut = sal_False;
- pImp->bObjLocked = sal_False;
- pImp->pFocusWin = 0;
- pImp->pActiveChild = NULL;
- pImp->nCurViewId = 0;
- pImp->bReloading = sal_False;
- pImp->bIsDowning = sal_False;
- pImp->bModal = sal_False;
- pImp->bEnabled = sal_True;
- pImp->nDocViewNo = 0;
- pImp->aMargin = Size( -1, -1 );
- pImp->pWindow = 0;
-
- SetPool( &SFX_APP()->GetPool() );
- pDispatcher = new SfxDispatcher(this);
- if ( !GetBindings().GetDispatcher() )
- GetBindings().SetDispatcher( pDispatcher );
-
- xObjSh = pObjSh;
- if ( xObjSh.Is() && xObjSh->IsPreview() )
- SetQuietMode_Impl( sal_True );
-
- if ( pObjSh )
- {
- pDispatcher->Push( *SFX_APP() );
- SfxModule* pModule = xObjSh->GetModule();
- if( pModule )
- pDispatcher->Push( *pModule );
- pDispatcher->Push( *this );
- pDispatcher->Push( *pObjSh );
- pDispatcher->Flush();
- StartListening( *pObjSh );
- pObjSh->ViewAssigned();
- Notify( *pObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) );
- Notify( *pObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) );
- pDispatcher->SetReadOnly_Impl( pObjSh->IsReadOnly() );
- }
- else
- {
- pDispatcher->Push( *SFX_APP() );
- pDispatcher->Push( *this );
- pDispatcher->Flush();
- }
-
- SfxViewFrame *pThis = this; // wegen der kranken Array-Syntax
- SfxViewFrameArr_Impl &rViewArr = SFX_APP()->GetViewFrames_Impl();
- rViewArr.C40_INSERT(SfxViewFrame, pThis, rViewArr.Count() );
-}
-
-SfxViewFrame::SfxViewFrame
-(
- SfxFrame& rFrame,
- SfxObjectShell* pObjShell
-)
-
-/* [Beschreibung]
-
- Ctor des SfxViewFrame f"ur eine <SfxObjectShell> aus der Ressource.
- Die 'nViewId' der zu erzeugenden <SfxViewShell> kann angegeben werden
- (default ist die zuerst registrierte SfxViewShell-Subklasse).
-*/
-
- : pImp( new SfxViewFrame_Impl( rFrame ) )
- , pDispatcher(0)
- , pBindings( new SfxBindings )
- , nAdjustPosPixelLock( 0 )
-{
- DBG_CTOR( SfxViewFrame, NULL );
-
- rFrame.SetCurrentViewFrame_Impl( this );
- rFrame.SetFrameType_Impl( GetFrameType() | SFXFRAME_HASTITLE );
- Construct_Impl( pObjShell );
-
- pImp->pWindow = new SfxFrameViewWindow_Impl( this, rFrame.GetWindow() );
- pImp->pWindow->SetSizePixel( rFrame.GetWindow().GetOutputSizePixel() );
- rFrame.SetOwnsBindings_Impl( sal_True );
- rFrame.CreateWorkWindow_Impl();
-}
-
-//------------------------------------------------------------------------
-SfxViewFrame::~SfxViewFrame()
-{
- DBG_DTOR(SfxViewFrame, 0);
-
- SetDowning_Impl();
-
- if ( SfxViewFrame::Current() == this )
- SfxViewFrame::SetViewFrame( NULL );
-
- ReleaseObjectShell_Impl();
-
- if ( GetFrame().OwnsBindings_Impl() )
- // Die Bindings l"oscht der Frame!
- KillDispatcher_Impl();
-
- delete pImp->pWindow;
-
- if ( GetFrame().GetCurrentViewFrame() == this )
- GetFrame().SetCurrentViewFrame_Impl( NULL );
-
- // von Frame-Liste abmelden
- SfxApplication *pSfxApp = SFX_APP();
- SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
- const SfxViewFrame *pThis = this;
- rFrames.Remove( rFrames.GetPos(pThis) );
-
- // Member l"oschen
- KillDispatcher_Impl();
-
- delete pImp;
-}
-
-//------------------------------------------------------------------------
-void SfxViewFrame::KillDispatcher_Impl()
-
-// Dispatcher abr"aumen und l"oschen
-
-{
- DBG_CHKTHIS(SfxViewFrame, 0);
-
- SfxModule* pModule = xObjSh.Is() ? xObjSh->GetModule() : 0;
- if ( xObjSh.Is() )
- ReleaseObjectShell_Impl();
- if ( pDispatcher )
- {
- if( pModule )
- pDispatcher->Pop( *pModule, SFX_SHELL_POP_UNTIL );
- else
- pDispatcher->Pop( *this );
- DELETEZ(pDispatcher);
- }
-}
-
-//------------------------------------------------------------------------
-SfxViewFrame* SfxViewFrame::Current()
-{
- return SfxApplication::Is_Impl() ? SFX_APP()->Get_Impl()->pViewFrame : NULL;
-}
-
-//--------------------------------------------------------------------
-sal_uInt16 SfxViewFrame::Count()
-
-/* [Beschreibung]
-
- Liefert die Anzahl der sichtbaren <SfxViewFrame>-Instanzen.
-*/
-
-{
- SfxApplication *pSfxApp = SFX_APP();
- SfxViewFrameArr_Impl& rFrames = pSfxApp->GetViewFrames_Impl();
- const sal_uInt16 nCount = rFrames.Count();
- sal_uInt16 nFound = 0;
- for ( sal_uInt16 i = 0; i < nCount; ++i )
- {
- SfxViewFrame *pFrame = rFrames[i];
- if ( pFrame->IsVisible() )
- ++nFound;
- }
- return nFound;
-}
-
-//--------------------------------------------------------------------
-// returns the first window of spec. type viewing the specified doc.
-SfxViewFrame* SfxViewFrame::GetFirst
-(
- const SfxObjectShell* pDoc,
- sal_Bool bOnlyIfVisible
-)
-{
- SfxApplication *pSfxApp = SFX_APP();
- SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
-
- // search for a SfxDocument of the specified type
- for ( sal_uInt16 nPos = 0; nPos < rFrames.Count(); ++nPos )
- {
- SfxViewFrame *pFrame = rFrames.GetObject(nPos);
- if ( ( !pDoc || pDoc == pFrame->GetObjectShell() )
- && ( !bOnlyIfVisible || pFrame->IsVisible() )
- )
- return pFrame;
- }
-
- return 0;
-}
-//--------------------------------------------------------------------
-
-// returns thenext window of spec. type viewing the specified doc.
-SfxViewFrame* SfxViewFrame::GetNext
-(
- const SfxViewFrame& rPrev,
- const SfxObjectShell* pDoc,
- sal_Bool bOnlyIfVisible
-)
-{
- SfxApplication *pSfxApp = SFX_APP();
- SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
-
- // refind the specified predecessor
- sal_uInt16 nPos;
- for ( nPos = 0; nPos < rFrames.Count(); ++nPos )
- if ( rFrames.GetObject(nPos) == &rPrev )
- break;
-
- // search for a Frame of the specified type
- for ( ++nPos; nPos < rFrames.Count(); ++nPos )
- {
- SfxViewFrame *pFrame = rFrames.GetObject(nPos);
- if ( ( !pDoc || pDoc == pFrame->GetObjectShell() )
- && ( !bOnlyIfVisible || pFrame->IsVisible() )
- )
- return pFrame;
- }
- return 0;
-}
-
-void SfxViewFrame::CloseHiddenFrames_Impl()
-{
- SfxApplication *pSfxApp = SFX_APP();
- SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
- for ( sal_uInt16 nPos=0; nPos<rFrames.Count(); )
- {
- SfxViewFrame *pFrame = rFrames.GetObject(nPos);
- if ( !pFrame->IsVisible() )
- pFrame->DoClose();
- else
- nPos++;
- }
-}
-
-//--------------------------------------------------------------------
-SfxProgress* SfxViewFrame::GetProgress() const
-{
- SfxObjectShell *pObjSh = GetObjectShell();
- return pObjSh ? pObjSh->GetProgress() : 0;
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::ShowStatusText( const String& /*rText*/)
-{
-/* OBSOLETE: If this is used, framework/uielement/progressbarwrapper.[h|c]xx &
- framework/uielement/statusindicatorinterfacewrapper.[h|c]xx must be
- extended to support a new interface to support ShowStatusText/HideStatusText
- SfxWorkWindow* pWorkWin = GetFrame().GetWorkWindow_Impl();
- SfxStatusBarManager *pMgr = pWorkWin->GetStatusBarManager_Impl();
- if ( pMgr )
- {
- pMgr->GetStatusBar()->HideItems();
- pMgr->GetStatusBar()->SetText( rText );
- }
-*/
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::HideStatusText()
-{
-/* OBSOLETE: If this is used, framework/uielement/progressbarwrapper.[h|c]xx &
- framework/uielement/statusindicatorinterfacewrapper.[h|c]xx must be
- extended to support a new interface to support ShowStatusText/HideStatusText
- SfxWorkWindow* pWorkWin = GetFrame().GetWorkWindow_Impl();
- SfxStatusBarManager *pMgr = pWorkWin->GetStatusBarManager_Impl();
- if ( pMgr )
- pMgr->GetStatusBar()->ShowItems();
-*/
-}
-
-
-//--------------------------------------------------------------------
-#ifdef ENABLE_INIMANAGER//MUSTINI
-SfxIniManager* SfxViewFrame::GetIniManager() const
-{
-/* SfxIniManager *pIniMgr = GetObjectShell()
- ? GetObjectShell()->GetFactory().GetIniManager()
- : 0;
- if ( !pIniMgr )*/ //!
- return SFX_APP()->GetAppIniManager();
-// return pIniMgr;
-}
-#endif
-
-//--------------------------------------------------------------------
-void SfxViewFrame::DoAdjustPosSizePixel //! teilen in Inner.../Outer...
-(
- SfxViewShell* pSh,
- const Point& rPos,
- const Size& rSize
-)
-{
- DBG_CHKTHIS(SfxViewFrame, 0);
-
- // Components benutzen diese Methode nicht!
- if( pSh && pSh->GetWindow() && !nAdjustPosPixelLock )
- {
- nAdjustPosPixelLock++;
- if ( pImp->bResizeInToOut )
- pSh->InnerResizePixel( rPos, rSize );
- else
- pSh->OuterResizePixel( rPos, rSize );
- nAdjustPosPixelLock--;
- }
-}
-
-//========================================================================
-
-int SfxViewFrameItem::operator==( const SfxPoolItem &rItem ) const
-{
- return PTR_CAST(SfxViewFrameItem, &rItem)->pFrame== pFrame;
-}
-
-//--------------------------------------------------------------------
-String SfxViewFrameItem::GetValueText() const
-{
- return String();
-}
-
-//--------------------------------------------------------------------
-SfxPoolItem* SfxViewFrameItem::Clone( SfxItemPool *) const
-{
- return new SfxViewFrameItem( pFrame);
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::SetViewShell_Impl( SfxViewShell *pVSh )
-
-/* [Beschreibung]
-
- Interne Methode zum setzen der jeweils aktuellen <SfxViewShell>-Instanz,
- die in diesem SfxViewFrame aktiv ist.
-*/
-
-{
- SfxShell::SetViewShell_Impl( pVSh );
-
- // Hack: InPlaceMode
- if ( pVSh )
- pImp->bResizeInToOut = sal_False;
-}
-
-//--------------------------------------------------------------------
-/*
- Beschreibung:
- Der ParentViewFrame ist der ViewFrame des Containers bei internem InPlace
-*/
-
-//TODO/LATER: is it still necessary? is there a replacement for GetParentViewFrame_Impl?
-SfxViewFrame* SfxViewFrame::GetParentViewFrame_Impl() const
-{
- return NULL;
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::ForceOuterResize_Impl(sal_Bool bOn)
-{
- if ( !pImp->bDontOverwriteResizeInToOut )
- pImp->bResizeInToOut = !bOn;
-}
-
-void SfxViewFrame::ForceInnerResize_Impl(sal_Bool bOn)
-{
- pImp->bDontOverwriteResizeInToOut = bOn;
-}
-
-//--------------------------------------------------------------------
-sal_Bool SfxViewFrame::IsResizeInToOut_Impl() const
-{
- return pImp->bResizeInToOut;
-}
-//--------------------------------------------------------------------
-void SfxViewFrame::DoAdjustPosSize( SfxViewShell *pSh,
- const Point rPos, const Size &rSize )
-{
- DBG_CHKTHIS(SfxViewFrame, 0);
- if( pSh && !nAdjustPosPixelLock )
- {
- Window *pWindow = pSh->GetWindow();
- Point aPos = pWindow->LogicToPixel(rPos);
- Size aSize = pWindow->LogicToPixel(rSize);
- DoAdjustPosSizePixel(pSh, aPos, aSize);
- }
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::GetDocNumber_Impl()
-{
- DBG_ASSERT( GetObjectShell(), "Kein Dokument!" );
- GetObjectShell()->SetNamedVisibility_Impl();
- pImp->nDocViewNo = GetObjectShell()->GetNoSet_Impl().GetFreeIndex()+1;
-}
-
-//--------------------------------------------------------------------
-
-void SfxViewFrame::Enable( sal_Bool bEnable )
-{
- if ( bEnable != pImp->bEnabled )
- {
- pImp->bEnabled = bEnable;
-
- // e.g. InPlace-Frames have a parent...
- SfxViewFrame *pParent = GetParentViewFrame_Impl();
- if ( pParent )
- {
- pParent->Enable( bEnable );
- }
- else
- {
- Window *pWindow = &GetFrame().GetTopFrame().GetWindow();
- if ( !bEnable )
- pImp->bWindowWasEnabled = pWindow->IsInputEnabled();
- if ( !bEnable || pImp->bWindowWasEnabled )
- pWindow->EnableInput( bEnable, TRUE );
- }
-
- // cursor and focus
- SfxViewShell* pViewSh = GetViewShell();
- if ( bEnable )
- {
- // show cursor
- if ( pViewSh )
- pViewSh->ShowCursor();
- }
- else
- {
- // hide cursor
- if ( pViewSh )
- pViewSh->ShowCursor(sal_False);
- }
-/*
- if ( !bEnable )
- GetBindings().ENTERREGISTRATIONS();
- GetDispatcher()->Lock( !bEnable );
- if ( bEnable )
- GetBindings().LEAVEREGISTRATIONS();
-*/
- }
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::Show()
-
-/* [Beschreibung]
-
- Diese Methode macht das Frame-Window sichtbar und ermittelt vorher
- den Fenstername. Au\serdem wird das Dokument festgehalten. Man darf
- i.d.R. nie das Window direkt showen!
-*/
-
-{
- // zuerst locken damit in UpdateTitle() gilt: IsVisible() == sal_True (:#)
- if ( xObjSh.Is() )
- {
- xObjSh->GetMedium()->GetItemSet()->ClearItem( SID_HIDDEN );
- if ( !pImp->bObjLocked )
- LockObjectShell_Impl( sal_True );
-
- // Doc-Shell Titel-Nummer anpassen, get unique view-no
- if ( 0 == pImp->nDocViewNo )
- {
- GetDocNumber_Impl();
- UpdateTitle();
- }
- }
- else
- UpdateTitle();
-
- // Frame-Window anzeigen, aber nur wenn der ViewFrame kein eigenes Window
- // hat oder wenn er keine Component enth"alt
- if ( &GetWindow() == &GetFrame().GetWindow() || !GetFrame().HasComponent() )
- GetWindow().Show();
- GetFrame().GetWindow().Show();
-
-/* SfxViewFrame* pCurrent = SfxViewFrame::Current();
- if ( GetFrame().GetFrameInterface()->isActive() &&
- pCurrent != this &&
- ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) &&
- !GetActiveChildFrame_Impl() )
- MakeActive_Impl( FALSE );*/
- if ( xObjSh.Is() && xObjSh->Get_Impl()->bHiddenLockedByAPI )
- {
- xObjSh->Get_Impl()->bHiddenLockedByAPI = FALSE;
- xObjSh->OwnerLock(FALSE);
- }
-}
-
-//--------------------------------------------------------------------
-sal_Bool SfxViewFrame::IsVisible() const
-{
- return pImp->bObjLocked;
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::Hide()
-{
- GetWindow().Hide();
- if ( pImp->bObjLocked )
- LockObjectShell_Impl( sal_False );
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::LockObjectShell_Impl( sal_Bool bLock )
-{
- DBG_ASSERT( pImp->bObjLocked != bLock, "Falscher Locked-Status!" );
-
- DBG_ASSERT( GetObjectShell(), "Kein Dokument!" );
- GetObjectShell()->OwnerLock(bLock);
- pImp->bObjLocked = bLock;
-}
-
-//--------------------------------------------------------------------
-void SfxViewFrame::MakeActive_Impl( BOOL bGrabFocus )
-{
- if ( GetViewShell() && !GetFrame().IsClosing_Impl() )
- {
- if ( IsVisible() )
- {
- if ( GetViewShell() )
- {
- BOOL bPreview = FALSE;
- if ( GetObjectShell()->IsPreview() )
- {
- bPreview = TRUE;
- }
- else
- {
- SfxViewFrame* pParent = GetParentViewFrame();
- if ( pParent )
- pParent->SetActiveChildFrame_Impl( this );
- }
-
- SfxViewFrame* pCurrent = SfxViewFrame::Current();
- css::uno::Reference< css::frame::XFrame > xFrame = GetFrame().GetFrameInterface();
- if ( !bPreview )
- {
- SetViewFrame( this );
- GetBindings().SetActiveFrame( css::uno::Reference< css::frame::XFrame >() );
- uno::Reference< frame::XFramesSupplier > xSupp( xFrame, uno::UNO_QUERY );
- if ( xSupp.is() )
- xSupp->setActiveFrame( uno::Reference < frame::XFrame >() );
-
- css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow();
- Window* pWindow = VCLUnoHelper::GetWindow(xContainerWindow);
- if (pWindow && pWindow->HasChildPathFocus() && bGrabFocus)
- {
- SfxInPlaceClient *pCli = GetViewShell()->GetUIActiveClient();
- if ( ( !pCli || !pCli->IsObjectUIActive() ) &&
- ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) )
- GetFrame().GrabFocusOnComponent_Impl();
- }
- }
- else
- {
- GetBindings().SetDispatcher( GetDispatcher() );
- GetBindings().SetActiveFrame( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > () );
- GetDispatcher()->Update_Impl( FALSE );
- }
- }
- }
- }
-}
-
-//-------------------------------------------------------------------------
-
-void SfxViewFrame::SetQuietMode_Impl( sal_Bool bOn )
-{
- GetDispatcher()->SetQuietMode_Impl( bOn );
-}
-
-//-------------------------------------------------------------------------
-
-SfxObjectShell* SfxViewFrame::GetObjectShell()
-{
- return xObjSh;
-}
-
-const Size& SfxViewFrame::GetMargin_Impl() const
-{
- return pImp->aMargin;
-}
-
-void SfxViewFrame::SetActiveChildFrame_Impl( SfxViewFrame *pViewFrame )
-{
- if ( pViewFrame != pImp->pActiveChild )
- {
- if ( !pImp->pActiveChild )
- GetDispatcher()->LockUI_Impl( sal_False );
-
- pImp->pActiveChild = pViewFrame;
-
- Reference< XFramesSupplier > xFrame( GetFrame().GetFrameInterface(), UNO_QUERY );
- Reference< XFrame > xActive;
- if ( pViewFrame )
- xActive = pViewFrame->GetFrame().GetFrameInterface();
-
- if ( xFrame.is() ) // PB: #74432# xFrame cann be NULL
- xFrame->setActiveFrame( xActive );
- }
-}
-
-SfxViewFrame* SfxViewFrame::GetActiveChildFrame_Impl() const
-{
- SfxViewFrame *pViewFrame = pImp->pActiveChild;
-/*
- if ( !pViewFrame )
- {
- // Wenn es keinen aktiven ChildFrame gibt, irgendeinen nehmen
- for ( sal_uInt16 n=0; n<GetChildFrameCount(); n++ )
- {
- pViewFrame =
- PTR_CAST( SfxViewFrame, GetChildFrame(n)->GetChildFrame(0) );
- if ( pViewFrame )
- break;
- }
- }
-
- pImp->pActiveChild = pViewFrame;
-*/
- return pViewFrame;
-}
-
-//--------------------------------------------------------------------
-SfxViewFrame* SfxViewFrame::LoadViewIntoFrame_Impl_NoThrow( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
- const USHORT i_nViewId, const bool i_bHidden )
-{
- Reference< XFrame > xFrame( i_rFrame );
- bool bOwnFrame = false;
- SfxViewShell* pSuccessView = NULL;
- try
- {
- if ( !xFrame.is() )
- {
- ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
- Reference < XFrame > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
- xFrame.set( xDesktop->findFrame( DEFINE_CONST_UNICODE("_blank"), 0 ), UNO_SET_THROW );
- bOwnFrame = true;
- }
-
- pSuccessView = LoadViewIntoFrame_Impl(
- i_rDoc,
- xFrame,
- Sequence< PropertyValue >(), // means "reuse existing model's args"
- i_nViewId,
- i_bHidden
- );
-
- if ( bOwnFrame && !i_bHidden )
- {
- // ensure the frame/window is visible
- Reference< XWindow > xContainerWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
- xContainerWindow->setVisible( sal_True );
- }
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
-
- if ( pSuccessView )
- return pSuccessView->GetViewFrame();
-
- if ( bOwnFrame )
- {
- try
- {
- xFrame->dispose();
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- }
-
- return NULL;
-}
-
-//--------------------------------------------------------------------
-SfxViewShell* SfxViewFrame::LoadViewIntoFrame_Impl( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
- const Sequence< PropertyValue >& i_rLoadArgs, const USHORT i_nViewId,
- const bool i_bHidden )
-{
- Reference< XModel > xDocument( i_rDoc.GetModel(), UNO_SET_THROW );
-
- ::comphelper::NamedValueCollection aTransformLoadArgs( i_rLoadArgs.getLength() ? i_rLoadArgs : xDocument->getArgs() );
- aTransformLoadArgs.put( "Model", xDocument );
- if ( i_nViewId )
- aTransformLoadArgs.put( "ViewId", sal_Int16( i_nViewId ) );
- if ( i_bHidden )
- aTransformLoadArgs.put( "Hidden", i_bHidden );
- else
- aTransformLoadArgs.remove( "Hidden" );
-
- ::rtl::OUString sURL( RTL_CONSTASCII_USTRINGPARAM( "private:object" ) );
-
- Reference< XComponentLoader > xLoader( i_rFrame, UNO_QUERY_THROW );
- xLoader->loadComponentFromURL( sURL, ::rtl::OUString::createFromAscii( "_self" ), 0,
- aTransformLoadArgs.getPropertyValues() );
-
- SfxViewShell* pViewShell = SfxViewShell::Get( i_rFrame->getController() );
- ENSURE_OR_THROW( pViewShell,
- "SfxViewFrame::LoadViewIntoFrame_Impl: loading an SFX doc into a frame resulted in a non-SFX view - quite impossible" );
- return pViewShell;
-}
-
-//--------------------------------------------------------------------
-
-SfxViewFrame* SfxViewFrame::LoadHiddenDocument( SfxObjectShell& i_rDoc, const USHORT i_nViewId )
-{
- return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, true );
-}
-
-//--------------------------------------------------------------------
-
-SfxViewFrame* SfxViewFrame::LoadDocument( SfxObjectShell& i_rDoc, const USHORT i_nViewId )
-{
- return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, false );
-}
-
-//--------------------------------------------------------------------
-
-SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rTargetFrame, const USHORT i_nViewId )
-{
- return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_rTargetFrame, i_nViewId, false );
-}
-
-//--------------------------------------------------------------------
-
-SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const SfxFrameItem* i_pFrameItem, const USHORT i_nViewId )
-{
- return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_pFrameItem && i_pFrameItem->GetFrame() ? i_pFrameItem->GetFrame()->GetFrameInterface() : NULL, i_nViewId, false );
-}
-
-//--------------------------------------------------------------------
-SfxViewFrame* SfxViewFrame::DisplayNewDocument( SfxObjectShell& i_rDoc, const SfxRequest& i_rCreateDocRequest, const USHORT i_nViewId )
-{
- SFX_REQUEST_ARG( i_rCreateDocRequest, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, FALSE );
- SFX_REQUEST_ARG( i_rCreateDocRequest, pHiddenItem, SfxBoolItem, SID_HIDDEN, FALSE );
-
- return LoadViewIntoFrame_Impl_NoThrow(
- i_rDoc,
- pFrameItem ? pFrameItem->GetFrame() : NULL,
- i_nViewId,
- pHiddenItem ? pHiddenItem->GetValue() : false
- );
-}
-
-//--------------------------------------------------------------------
-
-SfxViewFrame* SfxViewFrame::Get( const Reference< XController>& i_rController, const SfxObjectShell* i_pDoc )
-{
- if ( !i_rController.is() )
- return NULL;
-
- const SfxObjectShell* pDoc = i_pDoc;
- if ( !pDoc )
- {
- Reference< XModel > xDocument( i_rController->getModel() );
- for ( pDoc = SfxObjectShell::GetFirst( 0, false );
- pDoc;
- pDoc = SfxObjectShell::GetNext( *pDoc, 0, false )
- )
- {
- if ( pDoc->GetModel() == xDocument )
- break;
- }
- }
-
- SfxViewFrame* pViewFrame = NULL;
- for ( pViewFrame = SfxViewFrame::GetFirst( pDoc, FALSE );
- pViewFrame;
- pViewFrame = SfxViewFrame::GetNext( *pViewFrame, pDoc, FALSE )
- )
- {
- if ( pViewFrame->GetViewShell()->GetController() == i_rController )
- break;
- }
-
- return pViewFrame;
-}
-
-//--------------------------------------------------------------------
-
-sal_Bool SfxViewFrame::SwitchToViewShell_Impl
-(
- sal_uInt16 nViewIdOrNo, /* > 0
- Registrierungs-Id der View, auf die umge-
- schaltet werden soll, bzw. die erstmalig
- erzeugt werden soll.
-
- == 0
- Es soll die Default-View verwendet werden. */
-
- sal_Bool bIsIndex /* sal_True
- 'nViewIdOrNo' ist keine Registrations-Id sondern
- ein Index in die f"ur die in diesem
- <SfxViewFrame> dargestellte <SfxObjectShell>.
- */
-)
-
-/* [Beschreibung]
-
- Interne Methode zum Umschalten auf eine andere <SfxViewShell>-Subklasse,
- die in diesem SfxMDIFrame erzeugt werden soll. Existiert noch
- keine SfxViewShell in diesem SfxMDIFrame, so wird erstmalig eine
- erzeugt.
-
-
- [R"uckgabewert]
-
- sal_Bool sal_True
- die angeforderte SfxViewShell wurde erzeugt
- und eine ggf. bestehende gel"oscht
-
- sal_False
- die angeforderte SfxViewShell konnte nicht
- erzeugt werden, die bestehende SfxViewShell
- existiert daher weiterhin
-*/
-
-{
- try
- {
- ENSURE_OR_THROW( GetObjectShell() != NULL, "not possible without a document" );
-
- // if we already have a view shell, remove it
- SfxViewShell* pOldSh = GetViewShell();
- OSL_PRECOND( pOldSh, "SfxViewFrame::SwitchToViewShell_Impl: that's called *switch* (not for *initial-load*) for a reason" );
- if ( pOldSh )
- {
- // ask wether it can be closed
- if ( !pOldSh->PrepareClose( TRUE ) )
- return sal_False;
-
- // remove sub shells from Dispatcher before switching to new ViewShell
- PopShellAndSubShells_Impl( *pOldSh );
- }
-
- GetBindings().ENTERREGISTRATIONS();
- LockAdjustPosSizePixel();
-
- // ID of the new view
- SfxObjectFactory& rDocFact = GetObjectShell()->GetFactory();
- const USHORT nViewId = ( bIsIndex || !nViewIdOrNo ) ? rDocFact.GetViewFactory( nViewIdOrNo ).GetOrdinal() : nViewIdOrNo;
-
- // create and load new ViewShell
- SfxViewShell* pNewSh = LoadViewIntoFrame_Impl(
- *GetObjectShell(),
- GetFrame().GetFrameInterface(),
- Sequence< PropertyValue >(), // means "reuse existing model's args"
- nViewId,
- false
- );
-
- // allow resize events to be processed
- UnlockAdjustPosSizePixel();
-
- if ( GetWindow().IsReallyVisible() )
- DoAdjustPosSizePixel( pNewSh, Point(), GetWindow().GetOutputSizePixel() );
-
- GetBindings().LEAVEREGISTRATIONS();
- delete pOldSh;
- }
- catch ( const com::sun::star::uno::Exception& )
- {
- // the SfxCode is not able to cope with exceptions thrown while creating views
- // the code will crash in the stack unwinding procedure, so we shouldn't let exceptions go through here
- DBG_UNHANDLED_EXCEPTION();
- return sal_False;
- }
-
- DBG_ASSERT( SFX_APP()->GetViewFrames_Impl().Count() == SFX_APP()->GetViewShells_Impl().Count(), "Inconsistent view arrays!" );
- return sal_True;
-}
-
-//-------------------------------------------------------------------------
-void SfxViewFrame::SetCurViewId_Impl( const USHORT i_nID )
-{
- pImp->nCurViewId = i_nID;
-}
-
-//-------------------------------------------------------------------------
-sal_uInt16 SfxViewFrame::GetCurViewId() const
-{
- return pImp->nCurViewId;
-}
-
-//-------------------------------------------------------------------------
-void SfxViewFrame::ExecView_Impl
-(
- SfxRequest& rReq // der auszuf"uhrende <SfxRequest>
-)
-
-/* [Beschreibung]
-
- Interne Methode zum Ausf"uhren der f"ur die <SfxShell> Subklasse
- SfxViewFrame in der <SVIDL> beschriebenen Slots.
-*/
-
-{
- DBG_CHKTHIS(SfxViewFrame, 0);
-
- // Wenn gerade die Shells ausgetauscht werden...
- if ( !GetObjectShell() || !GetViewShell() )
- return;
-
- switch ( rReq.GetSlot() )
- {
- case SID_TERMINATE_INPLACEACTIVATION :
- {
- SfxInPlaceClient* pClient = GetViewShell()->GetUIActiveClient();
- if ( pClient )
- pClient->DeactivateObject();
- break;
- }
-
- case SID_VIEWSHELL:
- {
- const SfxPoolItem *pItem = 0;
- if ( rReq.GetArgs()
- && SFX_ITEM_SET == rReq.GetArgs()->GetItemState( SID_VIEWSHELL, sal_False, &pItem )
- )
- {
- const sal_uInt16 nViewId = static_cast< const SfxUInt16Item* >( pItem )->GetValue();
- BOOL bSuccess = SwitchToViewShell_Impl( nViewId );
- rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
- }
- break;
- }
-
- case SID_VIEWSHELL0:
- case SID_VIEWSHELL1:
- case SID_VIEWSHELL2:
- case SID_VIEWSHELL3:
- case SID_VIEWSHELL4:
- {
- const sal_uInt16 nViewNo = rReq.GetSlot() - SID_VIEWSHELL0;
- BOOL bSuccess = SwitchToViewShell_Impl( nViewNo, sal_True );
- rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
- break;
- }
-
- case SID_NEWWINDOW:
- {
- // Hack. demnaechst virtuelle Funktion
- if ( !GetViewShell()->NewWindowAllowed() )
- {
- OSL_ENSURE( false, "You should have disabled the 'Window/New Window' slot!" );
- return;
- }
-
- // ViewData bei FrameSets rekursiv holen
- GetFrame().GetViewData_Impl();
- SfxMedium* pMed = GetObjectShell()->GetMedium();
-
- // do not open the new window hidden
- pMed->GetItemSet()->ClearItem( SID_HIDDEN );
-
- // the view ID (optional arg. TODO: this is currently not supported in the slot definition ...)
- SFX_REQUEST_ARG( rReq, pViewIdItem, SfxUInt16Item, SID_VIEW_ID, sal_False );
- const USHORT nViewId = pViewIdItem ? pViewIdItem->GetValue() : GetCurViewId();
-
- Reference < XFrame > xFrame;
- // the frame (optional arg. TODO: this is currently not supported in the slot definition ...)
- SFX_REQUEST_ARG( rReq, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
- if ( pFrameItem )
- xFrame = pFrameItem->GetFrame();
-
- LoadViewIntoFrame_Impl_NoThrow( *GetObjectShell(), xFrame, nViewId, false );
-
- rReq.Done();
- break;
- }
-
- case SID_OBJECT:
- {
- SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, SID_OBJECT, sal_False );
-
- SfxViewShell *pViewShell = GetViewShell();
- if ( pViewShell && pItem )
- {
- pViewShell->DoVerb( pItem->GetValue() );
- rReq.Done();
- break;;
- }
- }
- }
-}
-
-//-------------------------------------------------------------------------
-/* TODO as96863:
- This method try to collect informations about the count of currently open documents.
- But the algorithm is implemented very simple ...
- E.g. hidden documents should be ignored here ... but they are counted.
- TODO: export special helper "framework::FrameListAnalyzer" within the framework module
- and use it here.
-*/
-sal_Bool impl_maxOpenDocCountReached()
-{
- static ::rtl::OUString SERVICE_DESKTOP = ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop");
-
- try
- {
- css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
- css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey(
- xSMGR,
- ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/"),
- ::rtl::OUString::createFromAscii("Misc"),
- ::rtl::OUString::createFromAscii("MaxOpenDocuments"),
- ::comphelper::ConfigurationHelper::E_READONLY);
-
- // NIL means: count of allowed documents = infinite !
- if ( ! aVal.hasValue())
- return sal_False;
-
- sal_Int32 nOpenDocs = 0;
- sal_Int32 nMaxDocs = 0;
- aVal >>= nMaxDocs;
-
- css::uno::Reference< css::frame::XFramesSupplier > xDesktop(xSMGR->createInstance(SERVICE_DESKTOP), css::uno::UNO_QUERY_THROW);
- css::uno::Reference< css::container::XIndexAccess > xCont (xDesktop->getFrames() , css::uno::UNO_QUERY_THROW);
-
- sal_Int32 c = xCont->getCount();
- sal_Int32 i = 0;
-
- for (i=0; i<c; ++i)
- {
- try
- {
- css::uno::Reference< css::frame::XFrame > xFrame;
- xCont->getByIndex(i) >>= xFrame;
- if ( ! xFrame.is())
- continue;
-
- // a) do not count the help window
- if (xFrame->getName().equalsAscii("OFFICE_HELP_TASK"))
- continue;
-
- // b) count all other frames
- ++nOpenDocs;
- }
- catch(const css::uno::Exception&)
- // A IndexOutOfBoundException can happen in multithreaded environments,
- // where any other thread can change this container !
- { continue; }
- }
-
- return (nOpenDocs >= nMaxDocs);
- }
- catch(const css::uno::Exception&)
- {}
-
- // Any internal error is no reason to stop opening documents !
- // Limitation of opening documents is a special "nice to have" feature.
- // Otherwhise it can happen, that NO document will be opened ...
- return sal_False;
-}
-
-//-------------------------------------------------------------------------
-void SfxViewFrame::StateView_Impl
-(
- SfxItemSet& rSet /* leeres <SfxItemSet> mit <Which-Ranges>,
- welche die Ids der zu erfragenden
- Slots beschreiben. */
-)
-
-/* [Beschreibung]
-
- Diese interne Methode liefert in 'rSet' die Status der f"ur die
- <SfxShell> Subklasse SfxViewFrame in der <SVIDL> beschriebenen <Slots>.
-
- In 'rSet' sind dabei genau die vom SFx als ung"ultig erkannten
- Slot-Ids als Which-ranges enthalten. Falls der an dieser Shell gesetzte
- <SfxItemPool> f"ur einzelne Slot-Ids ein Mapping hat, werden die
- entsprechenden Which-Ids verwendet, so da\s Items ggf. direkt mit
- einer mit Which-Ids arbeitenden Core-::com::sun::star::script::Engine ausgetauscht werden
- k"onnen.
-*/
-
-{
- DBG_CHKTHIS(SfxViewFrame, 0);
-
- SfxObjectShell *pDocSh = GetObjectShell();
-
- if ( !pDocSh )
- // Ich bin gerade am Reloaden und Yielde so vor mich hin ...
- return;
-
- const sal_uInt16 *pRanges = rSet.GetRanges();
- DBG_ASSERT(pRanges, "Set ohne Bereich");
- while ( *pRanges )
- {
- for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
- {
- switch(nWhich)
- {
- case SID_VIEWSHELL:
- {
- rSet.Put( SfxUInt16Item( nWhich, pImp->nCurViewId ) );
- break;
- }
-
- case SID_VIEWSHELL0:
- case SID_VIEWSHELL1:
- case SID_VIEWSHELL2:
- case SID_VIEWSHELL3:
- case SID_VIEWSHELL4:
- {
- sal_uInt16 nViewNo = nWhich - SID_VIEWSHELL0;
- if ( GetObjectShell()->GetFactory().GetViewFactoryCount() >
- nViewNo && !GetObjectShell()->IsInPlaceActive() )
- {
- SfxViewFactory &rViewFactory =
- GetObjectShell()->GetFactory().GetViewFactory(nViewNo);
- rSet.Put( SfxBoolItem(
- nWhich, pImp->nCurViewId == rViewFactory.GetOrdinal() ) );
- }
- else
- rSet.DisableItem( nWhich );
- break;
- }
- case SID_FRAMETITLE:
- {
- if( GetFrameType() & SFXFRAME_HASTITLE )
- rSet.Put( SfxStringItem(
- SID_FRAMETITLE, pImp->aFrameTitle) );
- else
- rSet.DisableItem( nWhich );
- break;
- }
-
- case SID_NEWWINDOW:
- {
- if ( !GetViewShell()->NewWindowAllowed()
- || impl_maxOpenDocCountReached()
- )
- rSet.DisableItem( nWhich );
- break;
- }
- }
- }
- }
-}
-
-//-------------------------------------------------------------------------
-void SfxViewFrame::ToTop()
-{
- GetFrame().Appear();
-}
-
-//-------------------------------------------------------------------------
-SfxViewFrame* SfxViewFrame::GetParentViewFrame() const
-/*
- Beschreibung:
- Der ParentViewFrame ist der ViewFrame des ParentFrames
-*/
-{
- SfxFrame *pFrame = GetFrame().GetParentFrame();
- return pFrame ? pFrame->GetCurrentViewFrame() : NULL;
-}
-
-//-------------------------------------------------------------------------
-SfxFrame& SfxViewFrame::GetFrame() const
-/*
- Beschreibung:
- GetFrame liefert den Frame, in dem sich der ViewFrame befindet
-*/
-{
- return pImp->rFrame;
-}
-
-//-------------------------------------------------------------------------
-SfxViewFrame* SfxViewFrame::GetTopViewFrame() const
-{
- return GetFrame().GetTopFrame().GetCurrentViewFrame();
-}
-
-Window& SfxViewFrame::GetWindow() const
-{
- return pImp->pWindow ? *pImp->pWindow : GetFrame().GetWindow();
-}
-
-sal_Bool SfxViewFrame::DoClose()
-{
- return GetFrame().DoClose();
-}
-
-String SfxViewFrame::GetActualPresentationURL_Impl() const
-{
- if ( xObjSh.Is() )
- return xObjSh->GetMedium()->GetName();
- return String();
-}
-
-void SfxViewFrame::SetModalMode( sal_Bool bModal )
-{
- pImp->bModal = bModal;
- if ( xObjSh.Is() )
- {
- for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( xObjSh );
- !bModal && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, xObjSh ) )
- bModal = pFrame->pImp->bModal;
- xObjSh->SetModalMode_Impl( bModal );
- }
-}
-
-BOOL SfxViewFrame::IsInModalMode() const
-{
- return pImp->bModal || GetFrame().GetWindow().IsInModalMode();
-}
-
-void SfxViewFrame::Resize( BOOL bForce )
-{
- Size aSize = GetWindow().GetOutputSizePixel();
- if ( bForce || aSize != pImp->aSize )
- {
- pImp->aSize = aSize;
- SfxViewShell *pShell = GetViewShell();
- if ( pShell )
- {
- if ( GetFrame().IsInPlace() )
- {
- Point aPoint = GetWindow().GetPosPixel();
- DoAdjustPosSizePixel( pShell, aPoint, aSize );
- }
- else
- {
- DoAdjustPosSizePixel( pShell, Point(), aSize );
- }
- }
- }
-}
-
-#define LINE_SEP 0x0A
-
-void CutLines( ::rtl::OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, BOOL bEraseTrailingEmptyLines )
-{
- sal_Int32 nStartPos = 0;
- sal_Int32 nEndPos = 0;
- sal_Int32 nLine = 0;
- while ( nLine < nStartLine )
- {
- nStartPos = rStr.indexOf( LINE_SEP, nStartPos );
- if( nStartPos == -1 )
- break;
- nStartPos++; // nicht das \n.
- nLine++;
- }
-
- DBG_ASSERTWARNING( nStartPos != STRING_NOTFOUND, "CutLines: Startzeile nicht gefunden!" );
-
- if ( nStartPos != -1 )
- {
- nEndPos = nStartPos;
- for ( sal_Int32 i = 0; i < nLines; i++ )
- nEndPos = rStr.indexOf( LINE_SEP, nEndPos+1 );
-
- if ( nEndPos == -1 ) // kann bei letzter Zeile passieren
- nEndPos = rStr.getLength();
- else
- nEndPos++;
-
- ::rtl::OUString aEndStr = rStr.copy( nEndPos );
- rStr = rStr.copy( 0, nStartPos );
- rStr += aEndStr;
- }
- if ( bEraseTrailingEmptyLines )
- {
- sal_Int32 n = nStartPos;
- sal_Int32 nLen = rStr.getLength();
- while ( ( n < nLen ) && ( rStr.getStr()[ n ] == LINE_SEP ) )
- n++;
-
- if ( n > nStartPos )
- {
- ::rtl::OUString aEndStr = rStr.copy( n );
- rStr = rStr.copy( 0, nStartPos );
- rStr += aEndStr;
- }
- }
-}
-
-/*
- add new recorded dispatch macro script into the application global basic lib container
- It generates a new unique id for it and insert the macro by using this number as name for
- the modul
- */
-void SfxViewFrame::AddDispatchMacroToBasic_Impl( const ::rtl::OUString& sMacro )
-{
- /*
- // get lib and modul name from dialog
- SfxModule *pMod = GetObjectShell()->GetModule();
- SfxRequest aReq( SID_BASICCHOOSER, SFX_CALLMODE_SYNCHRON, pMod->GetPool() );
- const SfxPoolItem* pRet = pMod->ExecuteSlot( aReq );
- if ( pRet )
- ::rtl::OUString = ((SfxStringItem*)pRet)->GetValue();
- */
- if ( !sMacro.getLength() )
- return;
-
- SfxApplication* pSfxApp = SFX_APP();
- SfxRequest aReq( SID_BASICCHOOSER, SFX_CALLMODE_SYNCHRON, pSfxApp->GetPool() );
- aReq.AppendItem( SfxBoolItem(SID_RECORDMACRO,TRUE) );
- const SfxPoolItem* pRet = SFX_APP()->ExecuteSlot( aReq );
- String aScriptURL;
- if ( pRet )
- aScriptURL = ((SfxStringItem*)pRet)->GetValue();
- if ( aScriptURL.Len() )
- {
- // parse scriptURL
- String aLibName;
- String aModuleName;
- String aMacroName;
- String aLocation;
- Reference< XMultiServiceFactory > xSMgr = ::comphelper::getProcessServiceFactory();
- Reference< com::sun::star::uri::XUriReferenceFactory > xFactory( xSMgr->createInstance(
- ::rtl::OUString::createFromAscii( "com.sun.star.uri.UriReferenceFactory" ) ), UNO_QUERY );
- if ( xFactory.is() )
- {
- Reference< com::sun::star::uri::XVndSunStarScriptUrl > xUrl( xFactory->parse( aScriptURL ), UNO_QUERY );
- if ( xUrl.is() )
- {
- // get name
- ::rtl::OUString aName = xUrl->getName();
- sal_Unicode cTok = '.';
- sal_Int32 nIndex = 0;
- aLibName = aName.getToken( 0, cTok, nIndex );
- if ( nIndex != -1 )
- aModuleName = aName.getToken( 0, cTok, nIndex );
- if ( nIndex != -1 )
- aMacroName = aName.getToken( 0, cTok, nIndex );
-
- // get location
- ::rtl::OUString aLocKey = ::rtl::OUString::createFromAscii( "location" );
- if ( xUrl->hasParameter( aLocKey ) )
- aLocation = xUrl->getParameter( aLocKey );
- }
- }
-
- pSfxApp->EnterBasicCall();
-
- BasicManager* pBasMgr = 0;
- if ( aLocation.EqualsIgnoreCaseAscii( "application" ) )
- {
- // application basic
- pBasMgr = pSfxApp->GetBasicManager();
- }
- else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) )
- {
- pBasMgr = GetObjectShell()->GetBasicManager();
- }
-
- ::rtl::OUString aOUSource;
- if ( pBasMgr)
- {
- StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
- if ( pBasic )
- {
- SbModule* pModule = pBasic->FindModule( aModuleName );
- if ( pModule )
- {
- SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD );
- aOUSource = pModule->GetSource32();
- USHORT nStart, nEnd;
- pMethod->GetLineRange( nStart, nEnd );
- ULONG nlStart = nStart;
- ULONG nlEnd = nEnd;
- CutLines( aOUSource, nlStart-1, nlEnd-nlStart+1, TRUE );
- }
- }
- }
-
- // open lib container and break operation if it couldn't be opened
- com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibCont;
- if ( aLocation.EqualsIgnoreCaseAscii( "application" ) )
- {
- xLibCont = SFX_APP()->GetBasicContainer();
- }
- else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) )
- {
- xLibCont = GetObjectShell()->GetBasicContainer();
- }
-
- if(!xLibCont.is())
- {
- DBG_ERRORFILE("couldn't get access to the basic lib container. Adding of macro isn't possible.");
- return;
- }
-
- // get LibraryContainer
- com::sun::star::uno::Any aTemp;
- com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xRoot(
- xLibCont,
- com::sun::star::uno::UNO_QUERY);
-
- ::rtl::OUString sLib( aLibName );
- com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xLib;
- if(xRoot->hasByName(sLib))
- {
- // library must be loaded
- aTemp = xRoot->getByName(sLib);
- xLibCont->loadLibrary(sLib);
- aTemp >>= xLib;
- }
- else
- {
- xLib = com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >(
- xLibCont->createLibrary(sLib),
- com::sun::star::uno::UNO_QUERY);
- }
-
- // pack the macro as direct usable "sub" routine
- ::rtl::OUString sCode;
- ::rtl::OUStringBuffer sRoutine(10000);
- ::rtl::OUString sMacroName( aMacroName );
- BOOL bReplace = FALSE;
-
- // get module
- ::rtl::OUString sModule( aModuleName );
- if(xLib->hasByName(sModule))
- {
- if ( aOUSource.getLength() )
- {
- sRoutine.append( aOUSource );
- }
- else
- {
- aTemp = xLib->getByName(sModule);
- aTemp >>= sCode;
- sRoutine.append( sCode );
- }
-
- bReplace = TRUE;
- }
-
- // append new method
- sRoutine.appendAscii("\nsub " );
- sRoutine.append (sMacroName );
- sRoutine.appendAscii("\n" );
- sRoutine.append (sMacro );
- sRoutine.appendAscii("\nend sub\n");
-
- // create the modul inside the library and insert the macro routine
- aTemp <<= sRoutine.makeStringAndClear();
- if ( bReplace )
- {
- com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
- xLib,
- com::sun::star::uno::UNO_QUERY);
- xModulCont->replaceByName(sModule,aTemp);
- }
- else
- {
- com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
- xLib,
- com::sun::star::uno::UNO_QUERY);
- xModulCont->insertByName(sModule,aTemp);
- }
-
- // #i17355# update the Basic IDE
- for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst(); pViewShell; pViewShell = SfxViewShell::GetNext( *pViewShell ) )
- {
- if ( pViewShell->GetName().EqualsAscii( "BasicIDE" ) )
- {
- SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
- SfxDispatcher* pDispat = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
- if ( pDispat )
- {
- SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLibName, aModuleName, String(), String() );
- pDispat->Execute( SID_BASICIDE_UPDATEMODULESOURCE, SFX_CALLMODE_SYNCHRON, &aInfoItem, 0L );
- }
- }
- }
-
- pSfxApp->LeaveBasicCall();
- }
- else
- {
- // add code for "session only" macro
- }
-
- /*
- FILE* pFile = fopen( "macro.bas", "a" );
- fprintf( pFile, "%s", ::rtl::OUStringToOString(sBuffer.makeStringAndClear(),RTL_TEXTENCODING_UTF8).getStr() );
- fclose ( pFile );
- */
-}
-
-void SfxViewFrame::MiscExec_Impl( SfxRequest& rReq )
-{
- DBG_MEMTEST();
- FASTBOOL bDone = FALSE;
- switch ( rReq.GetSlot() )
- {
- case SID_STOP_RECORDING :
- case SID_RECORDMACRO :
- {
- // try to find any active recorder on this frame
- ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier");
- com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
- GetFrame().GetFrameInterface(),
- com::sun::star::uno::UNO_QUERY);
-
- com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(xFrame,com::sun::star::uno::UNO_QUERY);
- com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
- com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
- aProp >>= xSupplier;
- com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
- if (xSupplier.is())
- xRecorder = xSupplier->getDispatchRecorder();
-
- BOOL bIsRecording = xRecorder.is();
- SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, SID_RECORDMACRO, sal_False);
- if ( pItem && pItem->GetValue() == bIsRecording )
- return;
-
- if ( xRecorder.is() )
- {
- // disable active recording
- aProp <<= com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >();
- xSet->setPropertyValue(sProperty,aProp);
-
- SFX_REQUEST_ARG( rReq, pRecordItem, SfxBoolItem, FN_PARAM_1, sal_False);
- if ( !pRecordItem || !pRecordItem->GetValue() )
- // insert script into basic library container of application
- AddDispatchMacroToBasic_Impl(xRecorder->getRecordedMacro());
-
- xRecorder->endRecording();
- xRecorder = NULL;
- GetBindings().SetRecorder_Impl( xRecorder );
-
- SetChildWindow( SID_RECORDING_FLOATWINDOW, FALSE );
- if ( rReq.GetSlot() != SID_RECORDMACRO )
- GetBindings().Invalidate( SID_RECORDMACRO );
- }
- else if ( rReq.GetSlot() == SID_RECORDMACRO )
- {
- // enable recording
- com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xFactory(
- ::comphelper::getProcessServiceFactory(),
- com::sun::star::uno::UNO_QUERY);
-
- xRecorder = com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder >(
- xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.frame.DispatchRecorder")),
- com::sun::star::uno::UNO_QUERY);
-
- xSupplier = com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >(
- xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.frame.DispatchRecorderSupplier")),
- com::sun::star::uno::UNO_QUERY);
-
- xSupplier->setDispatchRecorder(xRecorder);
- xRecorder->startRecording(xFrame);
- aProp <<= xSupplier;
- xSet->setPropertyValue(sProperty,aProp);
- GetBindings().SetRecorder_Impl( xRecorder );
- SetChildWindow( SID_RECORDING_FLOATWINDOW, TRUE );
- }
-
- rReq.Done();
- break;
- }
-
- case SID_TOGGLESTATUSBAR:
- {
- com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
- GetFrame().GetFrameInterface(),
- com::sun::star::uno::UNO_QUERY);
-
- Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
- Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
- if ( xPropSet.is() )
- {
- try
- {
- Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
- aValue >>= xLayoutManager;
- }
- catch ( Exception& )
- {
- }
- }
-
- if ( xLayoutManager.is() )
- {
- rtl::OUString aStatusbarResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" ));
- // Parameter auswerten
- SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, rReq.GetSlot(), FALSE);
- BOOL bShow( TRUE );
- if ( !pShowItem )
- bShow = xLayoutManager->isElementVisible( aStatusbarResString );
- else
- bShow = pShowItem->GetValue();
-
- if ( bShow )
- {
- xLayoutManager->createElement( aStatusbarResString );
- xLayoutManager->showElement( aStatusbarResString );
- }
- else
- xLayoutManager->hideElement( aStatusbarResString );
-
- if ( !pShowItem )
- rReq.AppendItem( SfxBoolItem( SID_TOGGLESTATUSBAR, bShow ) );
- }
- rReq.Done();
- break;
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- case SID_WIN_FULLSCREEN:
- {
- SFX_REQUEST_ARG(rReq, pItem, SfxBoolItem, rReq.GetSlot(), FALSE);
- SfxViewFrame *pTop = GetTopViewFrame();
- if ( pTop )
- {
- WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl();
- if ( pWork )
- {
- com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
- GetFrame().GetFrameInterface(),
- com::sun::star::uno::UNO_QUERY);
-
- Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
- Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
- if ( xPropSet.is() )
- {
- try
- {
- Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
- aValue >>= xLayoutManager;
- }
- catch ( Exception& )
- {
- }
- }
-
- BOOL bNewFullScreenMode = pItem ? pItem->GetValue() : !pWork->IsFullScreenMode();
- if ( bNewFullScreenMode != pWork->IsFullScreenMode() )
- {
- Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet( xLayoutManager, UNO_QUERY );
- if ( xLMPropSet.is() )
- {
- try
- {
- xLMPropSet->setPropertyValue(
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HideCurrentUI" )),
- makeAny( bNewFullScreenMode ));
- }
- catch ( ::com::sun::star::beans::UnknownPropertyException& )
- {
- }
- }
- pWork->ShowFullScreenMode( bNewFullScreenMode );
- pWork->SetMenuBarMode( bNewFullScreenMode ? MENUBAR_MODE_HIDE : MENUBAR_MODE_NORMAL );
- GetFrame().GetWorkWindow_Impl()->SetFullScreen_Impl( bNewFullScreenMode );
- if ( !pItem )
- rReq.AppendItem( SfxBoolItem( SID_WIN_FULLSCREEN, bNewFullScreenMode ) );
- rReq.Done();
- }
- else
- rReq.Ignore();
- }
- }
- else
- rReq.Ignore();
-
- GetDispatcher()->Update_Impl( TRUE );
- break;
- }
- }
-
- if ( bDone )
- rReq.Done();
-}
-
-void SfxViewFrame::MiscState_Impl(SfxItemSet &rSet)
-{
- DBG_MEMTEST();
-
- const USHORT *pRanges = rSet.GetRanges();
- DBG_ASSERT(pRanges && *pRanges, "Set ohne Bereich");
- while ( *pRanges )
- {
- for(USHORT nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
- {
- switch(nWhich)
- {
- case SID_CURRENT_URL:
- {
- // Bei internem InPlace den ContainerFrame nehmen
- SfxViewFrame *pFrame = this;
- if ( pFrame->GetParentViewFrame_Impl() )
- pFrame = pFrame->GetParentViewFrame_Impl();
- rSet.Put( SfxStringItem( nWhich, pFrame->GetActualPresentationURL_Impl() ) );
- break;
- }
-
- case SID_RECORDMACRO :
- {
- const char* pName = GetObjectShell()->GetFactory().GetShortName();
- if ( strcmp(pName,"swriter") && strcmp(pName,"scalc") )
- {
- rSet.DisableItem( nWhich );
- break;
- }
-
- ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier");
- com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
- GetFrame().GetFrameInterface(),
- com::sun::star::uno::UNO_QUERY);
-
- com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
- com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
- if ( aProp >>= xSupplier )
- rSet.Put( SfxBoolItem( nWhich, xSupplier.is() ) );
- else
- rSet.DisableItem( nWhich );
- break;
- }
-
- case SID_STOP_RECORDING :
- {
- const char* pName = GetObjectShell()->GetFactory().GetShortName();
- if ( strcmp(pName,"swriter") && strcmp(pName,"scalc") )
- {
- rSet.DisableItem( nWhich );
- break;
- }
-
- ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier");
- com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
- GetFrame().GetFrameInterface(),
- com::sun::star::uno::UNO_QUERY);
-
- com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
- com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
- if ( !(aProp >>= xSupplier) || !xSupplier.is() )
- rSet.DisableItem( nWhich );
- break;
- }
-
- case SID_TOGGLESTATUSBAR:
- {
- com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
- com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
- GetFrame().GetFrameInterface(),
- com::sun::star::uno::UNO_QUERY);
- com::sun::star::uno::Any aProp = xSet->getPropertyValue(
- rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )) );
-
- if ( !( aProp >>= xLayoutManager ))
- rSet.Put( SfxBoolItem( nWhich, FALSE ));
- else
- {
- rtl::OUString aStatusbarResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" ));
- BOOL bShow = xLayoutManager->isElementVisible( aStatusbarResString );
- rSet.Put( SfxBoolItem( nWhich, bShow ));
- }
- break;
- }
-
- case SID_WIN_FULLSCREEN:
- {
- SfxViewFrame* pTop = GetTopViewFrame();
- if ( pTop )
- {
- WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl();
- if ( pWork )
- {
- rSet.Put( SfxBoolItem( nWhich, pWork->IsFullScreenMode() ) );
- break;
- }
- }
-
- rSet.DisableItem( nWhich );
- break;
- }
-
- case SID_FORMATMENUSTATE :
- {
- DBG_ERROR("Outdated slot!");
- rSet.DisableItem( nWhich );
- break;
- }
-
- default:
- //! DBG_ASSERT(FALSE, "Falscher Server fuer GetState");
- break;
- }
- }
-
- ++pRanges;
- }
-}
-
-void SfxViewFrame::ChildWindowExecute( SfxRequest &rReq )
-
-/* [Beschreibung]
-
- Diese Methode kann in der Execute-Methode f"ur das ein- und ausschalten
- von Child-Windows eingesetzt werden, um dieses inkl. API-Anbindung zu
- implementieren.
-
- Einfach in der IDL als 'ExecuteMethod' eintragen.
-*/
-
-{
- // Parameter auswerten
- USHORT nSID = rReq.GetSlot();
-
- SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSID, FALSE);
- if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
- {
- if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE))
- return;
- Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface();
- Reference < XFrame > xBeamer( xFrame->findFrame( DEFINE_CONST_UNICODE("_beamer"), FrameSearchFlag::CHILDREN ) );
- BOOL bShow = FALSE;
- BOOL bHasChild = xBeamer.is();
- bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
- if ( pShowItem )
- {
- if( bShow == bHasChild )
- return;
- }
- else
- rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
-
- if ( !bShow )
- {
- SetChildWindow( SID_BROWSER, FALSE );
- }
- else
- {
- ::com::sun::star::util::URL aTargetURL;
- aTargetURL.Complete = ::rtl::OUString::createFromAscii(".component:DB/DataSourceBrowser");
- Reference < ::com::sun::star::util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
- xTrans->parseStrict( aTargetURL );
-
- Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
- Reference < ::com::sun::star::frame::XDispatch > xDisp;
- if ( xProv.is() )
- xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_beamer"), 31 );
- if ( xDisp.is() )
- {
- Sequence < ::com::sun::star::beans::PropertyValue > aArgs(1);
- ::com::sun::star::beans::PropertyValue* pArg = aArgs.getArray();
- pArg[0].Name = rtl::OUString::createFromAscii("Referer");
- pArg[0].Value <<= ::rtl::OUString::createFromAscii("private:user");
- xDisp->dispatch( aTargetURL, aArgs );
- }
- }
-
- rReq.Done();
- return;
- }
-
- BOOL bShow = FALSE;
- BOOL bHasChild = HasChildWindow(nSID);
- bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
-
- // ausf"uhren
- if ( !pShowItem || bShow != bHasChild )
- ToggleChildWindow( nSID );
-
- GetBindings().Invalidate( nSID );
- GetDispatcher()->Update_Impl( TRUE );
-
- // ggf. recorden
- if ( nSID == SID_HYPERLINK_DIALOG || nSID == SID_SEARCH_DLG )
- {
- rReq.Ignore();
- }
- else
- {
- rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
- rReq.Done();
- }
-}
-
-//--------------------------------------------------------------------
-
-void SfxViewFrame::ChildWindowState( SfxItemSet& rState )
-
-/* [Beschreibung]
-
- Diese Methode kann in der Status-Methode f"ur das Ein- und Ausschalt-
- Zustand von Child-Windows eingesetzt werden, um dieses zu implementieren.
-
- Einfach in der IDL als 'StateMethod' eintragen.
-*/
-
-{
- SfxWhichIter aIter( rState );
- for ( USHORT nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
- {
- if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
- {
- rState.Put( SfxBoolItem( nSID, HasChildWindow( SID_BROWSER ) ) );
- }
- else if ( nSID == SID_HYPERLINK_DIALOG )
- {
- const SfxPoolItem* pDummy = NULL;
- SfxItemState eState = GetDispatcher()->QueryState( SID_HYPERLINK_SETLINK, pDummy );
- if ( SFX_ITEM_DISABLED == eState )
- rState.DisableItem(nSID);
- else
- {
- if ( KnowsChildWindow(nSID) )
- rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID)) );
- else
- rState.DisableItem(nSID);
- }
- }
- else if ( nSID == SID_BROWSER )
- {
- Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface()->
- findFrame( DEFINE_CONST_UNICODE("_beamer"), FrameSearchFlag::CHILDREN );
- if ( !xFrame.is() )
- rState.DisableItem( nSID );
- else if ( KnowsChildWindow(nSID) )
- rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
- }
- else if ( nSID == SID_TASKPANE )
- {
- if ( !KnowsChildWindow( nSID ) )
- {
- OSL_ENSURE( false, "SID_TASKPANE state requested, but no task pane child window exists for this ID!" );
- rState.DisableItem( nSID );
- }
- else if ( !moduleHasToolPanels( *pImp ) )
- {
- rState.Put( SfxVisibilityItem( nSID, sal_False ) );
- }
- else
- {
- rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) );
- }
- }
- else if ( KnowsChildWindow(nSID) )
- rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
- else
- rState.DisableItem(nSID);
- }
-}
-
-//--------------------------------------------------------------------
-SfxWorkWindow* SfxViewFrame::GetWorkWindow_Impl( USHORT /*nId*/ )
-{
- SfxWorkWindow* pWork = 0;
- pWork = GetFrame().GetWorkWindow_Impl();
- return pWork;
-}
-
-/*
-void SfxViewFrame::SetChildWindow(USHORT nId, BOOL bOn)
-{
- SetChildWindow( nId, bOn, TRUE );
-}*/
-
-void SfxViewFrame::SetChildWindow(USHORT nId, BOOL bOn, BOOL bSetFocus )
-{
- SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
- if ( pWork )
- pWork->SetChildWindow_Impl( nId, bOn, bSetFocus );
-}
-
-//--------------------------------------------------------------------
-
-void SfxViewFrame::ToggleChildWindow(USHORT nId)
-{
- SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
- if ( pWork )
- pWork->ToggleChildWindow_Impl( nId, TRUE );
-}
-
-//--------------------------------------------------------------------
-
-BOOL SfxViewFrame::HasChildWindow( USHORT nId )
-{
- SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
- return pWork ? pWork->HasChildWindow_Impl(nId) : FALSE;
-}
-
-//--------------------------------------------------------------------
-
-BOOL SfxViewFrame::KnowsChildWindow( USHORT nId )
-{
- SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
- return pWork ? pWork->KnowsChildWindow_Impl(nId) : FALSE;
-}
-
-//--------------------------------------------------------------------
-
-void SfxViewFrame::ShowChildWindow( USHORT nId, BOOL bVisible )
-{
- SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
- if ( pWork )
- {
- GetDispatcher()->Update_Impl(sal_True);
- pWork->ShowChildWindow_Impl(nId, bVisible, TRUE );
- }
-}
-
-//--------------------------------------------------------------------
-
-SfxChildWindow* SfxViewFrame::GetChildWindow(USHORT nId)
-{
- SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
- return pWork ? pWork->GetChildWindow_Impl(nId) : NULL;
-}
-
-void SfxViewFrame::UpdateDocument_Impl()
-{
- SfxObjectShell* pDoc = GetObjectShell();
- if ( pDoc->IsLoadingFinished() )
- pDoc->CheckSecurityOnLoading_Impl();
-
- // check if document depends on a template
- pDoc->UpdateFromTemplate_Impl();
-}
-
-void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame )
-{
- SFX_APP()->SetViewFrame_Impl( pFrame );
-}
-
-// ---------------------------------------------------------------------------------------------------------------------
-void SfxViewFrame::ActivateToolPanel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame, const ::rtl::OUString& i_rPanelURL )
-{
- ::vos::OGuard aGuard( Application::GetSolarMutex() );
-
- // look up the SfxFrame for the given XFrame
- SfxFrame* pFrame = NULL;
- for ( pFrame = SfxFrame::GetFirst(); pFrame; pFrame = SfxFrame::GetNext( *pFrame ) )
- {
- if ( pFrame->GetFrameInterface() == i_rFrame )
- break;
- }
- SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : NULL;
- ENSURE_OR_RETURN_VOID( pViewFrame != NULL, "SfxViewFrame::ActivateToolPanel: did not find an SfxFrame for the given XFrame!" );
-
- pViewFrame->ActivateToolPanel_Impl( i_rPanelURL );
-}
-
-// ---------------------------------------------------------------------------------------------------------------------
-void SfxViewFrame::ActivateToolPanel_Impl( const ::rtl::OUString& i_rPanelURL )
-{
- // ensure the task pane is visible
- ENSURE_OR_RETURN_VOID( KnowsChildWindow( SID_TASKPANE ), "SfxViewFrame::ActivateToolPanel: this frame/module does not allow for a task pane!" );
- if ( !HasChildWindow( SID_TASKPANE ) )
- ToggleChildWindow( SID_TASKPANE );
-
- SfxChildWindow* pTaskPaneChildWindow = GetChildWindow( SID_TASKPANE );
- ENSURE_OR_RETURN_VOID( pTaskPaneChildWindow, "SfxViewFrame::ActivateToolPanel_Impl: just switched it on, but it is not there!" );
-
- ::sfx2::ITaskPaneToolPanelAccess* pPanelAccess = dynamic_cast< ::sfx2::ITaskPaneToolPanelAccess* >( pTaskPaneChildWindow );
- ENSURE_OR_RETURN_VOID( pPanelAccess, "SfxViewFrame::ActivateToolPanel_Impl: task pane child window does not implement a required interface!" );
- pPanelAccess->ActivateToolPanel( i_rPanelURL );
-}
+/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" + +#include <stdio.h> + +#include <sfx2/viewfrm.hxx> +#include <com/sun/star/document/MacroExecMode.hpp> +#include <com/sun/star/frame/XLoadable.hpp> +#include <com/sun/star/frame/XLayoutManager.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> + +#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ +#include <toolkit/unohlp.hxx> +#endif +#ifndef _SPLITWIN_HXX //autogen +#include <vcl/splitwin.hxx> +#endif +#include <unotools/moduleoptions.hxx> +#include <svl/intitem.hxx> +#include <svl/visitem.hxx> +#include <svl/stritem.hxx> +#include <svl/eitem.hxx> +#include <svl/slstitm.hxx> +#include <svl/whiter.hxx> +#include <svl/undo.hxx> +#ifndef _MSGBOX_HXX //autogen +#include <vcl/msgbox.hxx> +#endif +#include <svtools/sfxecode.hxx> +#include <svtools/ehdl.hxx> +#include <tools/diagnose_ex.h> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/frame/XFramesSupplier.hpp> +#include <com/sun/star/frame/FrameSearchFlag.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XFrames.hpp> +#include <com/sun/star/frame/XFramesSupplier.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/XModel2.hpp> +#include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/frame/XDispatchRecorderSupplier.hpp> +#include <com/sun/star/document/MacroExecMode.hpp> +#include <com/sun/star/document/UpdateDocMode.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uri/XUriReferenceFactory.hpp> +#include <com/sun/star/uri/XVndSunStarScriptUrl.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/embed/EmbedStates.hpp> +#include <rtl/ustrbuf.hxx> + +#include <unotools/localfilehelper.hxx> +#include <unotools/ucbhelper.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/componentcontext.hxx> +#include <comphelper/namedvaluecollection.hxx> +#include <comphelper/configurationhelper.hxx> +#include <comphelper/docpasswordrequest.hxx> +#include <comphelper/docpasswordhelper.hxx> + +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/ucb/XContent.hpp> + +#include <basic/basmgr.hxx> +#include <basic/sbmod.hxx> +#include <basic/sbmeth.hxx> +#include <basic/sbx.hxx> +#include <comphelper/storagehelper.hxx> +#include <svtools/asynclink.hxx> +#include <svl/sharecontrolfile.hxx> + +#include <boost/optional.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::ucb; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::lang; +using ::com::sun::star::awt::XWindow; +using ::com::sun::star::beans::PropertyValue; +namespace css = ::com::sun::star; + +#ifndef GCC +#endif + +// wg. ViewFrame::Current +#include "appdata.hxx" +#include <sfx2/taskpane.hxx> +#include <sfx2/app.hxx> +#include <sfx2/objface.hxx> +#include "openflag.hxx" +#include "objshimp.hxx" +#include <sfx2/viewsh.hxx> +#include <sfx2/objsh.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/dispatch.hxx> +#include "arrdecl.hxx" +#include "sfxtypes.hxx" +#include <sfx2/request.hxx> +#include <sfx2/docfac.hxx> +#include <sfx2/ipclient.hxx> +#include "sfxresid.hxx" +#include "appbas.hxx" +#include <sfx2/objitem.hxx> +#include "viewfac.hxx" +#include <sfx2/event.hxx> +#include "fltfnc.hxx" +#include <sfx2/docfile.hxx> +#include <sfx2/module.hxx> +#include <sfx2/msgpool.hxx> +#include <sfx2/viewfrm.hxx> +#include "viewimp.hxx" +#include <sfx2/sfxbasecontroller.hxx> +#include <sfx2/sfx.hrc> +#include "view.hrc" +#include <sfx2/frmdescr.hxx> +#include <sfx2/sfxuno.hxx> +#include <sfx2/progress.hxx> +#include "workwin.hxx" +#include "helper.hxx" +#include "macro.hxx" +#include "minfitem.hxx" +#include "../appl/app.hrc" +#include "impviewframe.hxx" + +//------------------------------------------------------------------------- +DBG_NAME(SfxViewFrame) + +#define SfxViewFrame +#include "sfxslots.hxx" +#undef SfxViewFrame + +//------------------------------------------------------------------------- + +SFX_IMPL_INTERFACE(SfxViewFrame,SfxShell,SfxResId(0)) +{ + SFX_CHILDWINDOW_REGISTRATION( SID_BROWSER ); + SFX_CHILDWINDOW_REGISTRATION( SID_RECORDING_FLOATWINDOW ); + + SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_FULLSCREEN | SFX_VISIBILITY_FULLSCREEN, SfxResId(RID_FULLSCREENTOOLBOX) ); + SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_STANDARD, SfxResId(RID_ENVTOOLBOX) ); +} + +TYPEINIT2(SfxViewFrame,SfxShell,SfxListener); +TYPEINIT1(SfxViewFrameItem, SfxPoolItem); + +//========================================================================= + +//------------------------------------------------------------------------- +namespace +{ + bool moduleHasToolPanels( SfxViewFrame_Impl& i_rViewFrameImpl ) + { + if ( !i_rViewFrameImpl.aHasToolPanels ) + { + i_rViewFrameImpl.aHasToolPanels.reset( ::sfx2::ModuleTaskPane::ModuleHasToolPanels( + i_rViewFrameImpl.rFrame.GetFrameInterface() ) ); + } + return *i_rViewFrameImpl.aHasToolPanels; + } +} + +//------------------------------------------------------------------------- +static sal_Bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const ::rtl::OUString& aPath, const SfxFilter* pFilter, sal_uInt32 nPasswordHash, const uno::Sequence< beans::PropertyValue > aInfo ) +{ + // TODO/LATER: In future the info should replace the direct hash completely + sal_Bool bResult = ( !nPasswordHash && !aInfo.getLength() ); + + OSL_ENSURE( pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ), "PasswordToModify feature is active for a filter that does not support it!" ); + + if ( pFilter && xHandler.is() ) + { + sal_Bool bCancel = sal_False; + sal_Bool bFirstTime = sal_True; + + while ( !bResult && !bCancel ) + { + sal_Bool bMSType = !pFilter->IsOwnFormat(); + + ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( + new ::comphelper::DocPasswordRequest( + bMSType ? ::comphelper::DocPasswordRequestType_MS : ::comphelper::DocPasswordRequestType_STANDARD, + bFirstTime ? ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER : ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER, + aPath, + sal_True ) ); + + uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() ); + xHandler->handle( rRequest ); + + if ( pPasswordRequest->isPassword() ) + { + if ( aInfo.getLength() ) + { + bResult = ::comphelper::DocPasswordHelper::IsModifyPasswordCorrect( pPasswordRequest->getPasswordToModify(), aInfo ); + } + else + { + // the binary format + bResult = ( SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pFilter->GetServiceName() ) ) == nPasswordHash ); + } + } + else + bCancel = sal_True; + + bFirstTime = sal_False; + } + } + + return bResult; +} + +//------------------------------------------------------------------------- +void SfxViewFrame::SetDowning_Impl() +{ + pImp->bIsDowning = sal_True; +} + +//------------------------------------------------------------------------- +sal_Bool SfxViewFrame::IsDowning_Impl() const +{ + return pImp->bIsDowning; +} + + +//-------------------------------------------------------------------- +class SfxViewNotificatedFrameList_Impl : + public SfxListener, public SfxViewFrameArr_Impl +{ +public: + + void InsertViewFrame( SfxViewFrame* pFrame ) + { + StartListening( *pFrame ); + C40_INSERT( SfxViewFrame, pFrame, Count() ); + } + void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); +}; + +//------------------------------------------------------------------------- +void SfxViewNotificatedFrameList_Impl::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) +{ + if ( rHint.IsA(TYPE(SfxSimpleHint)) ) + { + switch( ( (SfxSimpleHint&) rHint ).GetId() ) + { + case SFX_HINT_DYING: + SfxViewFrame* pFrame = (SfxViewFrame*) &rBC; + if( pFrame ) + { + sal_uInt16 nPos = C40_GETPOS( SfxViewFrame, pFrame ); + if( nPos != USHRT_MAX ) + Remove( nPos ); + } + break; + } + } +} + +//------------------------------------------------------------------------- + +long ReloadDecouple_Impl( void* pObj, void* pArg ) +{ + ((SfxViewFrame*) pObj)->ExecReload_Impl( *(SfxRequest*)pArg ); + return 0; +} + +void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq, sal_Bool bAsync ) +{ + if( bAsync ) + { + if( !pImp->pReloader ) + pImp->pReloader = new svtools::AsynchronLink( + Link( this, ReloadDecouple_Impl ) ); + pImp->pReloader->Call( new SfxRequest( rReq ) ); + } + else ExecReload_Impl( rReq ); +} + +void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) +{ + SfxFrame *pParent = GetFrame().GetParentFrame(); + if ( rReq.GetSlot() == SID_RELOAD ) + { + // Bei CTRL-Reload den aktiven Frame reloaden + SfxViewFrame* pActFrame = this; + while ( pActFrame ) + pActFrame = pActFrame->GetActiveChildFrame_Impl(); + + if ( pActFrame ) + { + sal_uInt16 nModifier = rReq.GetModifier(); + if ( nModifier & KEY_MOD1 ) + { + pActFrame->ExecReload_Impl( rReq ); + return; + } + } + + // Wenn nur ein Reload der Graphiken eines oder mehrerer ChildFrames + // gemacht werden soll + SfxFrame& rFrame = GetFrame(); + if ( pParent == &rFrame && rFrame.GetChildFrameCount() ) + { + sal_Bool bReloadAvailable = sal_False; + SfxFrameIterator aIter( rFrame, sal_False ); + SfxFrame *pChild = aIter.FirstFrame(); + while ( pChild ) + { + SfxFrame *pNext = aIter.NextFrame( *pChild ); + SfxObjectShell *pShell = pChild->GetCurrentDocument(); + if( pShell && pShell->Get_Impl()->bReloadAvailable ) + { + bReloadAvailable = sal_True; + pChild->GetCurrentViewFrame()->ExecuteSlot( rReq ); + } + pChild = pNext; + } + + // Der TopLevel-Frame selbst het keine Graphiken! + if ( bReloadAvailable ) + return; + } + } + else + { + // Bei CTRL-Edit den TopFrame bearbeiten + sal_uInt16 nModifier = rReq.GetModifier(); + + if ( ( nModifier & KEY_MOD1 ) && pParent ) + { + SfxViewFrame *pTop = GetTopViewFrame(); + pTop->ExecReload_Impl( rReq ); + return; + } + } + + SfxObjectShell* pSh = GetObjectShell(); + switch ( rReq.GetSlot() ) + { + case SID_EDITDOC: + { + if ( GetFrame().HasComponent() ) + break; + + // Wg. Doppeltbelegung in Toolboxen (mit/ohne Ctrl) ist es auch + // m"oglich, da\s der Slot zwar enabled ist, aber Ctrl-Click + // trotzdem nicht geht! + if( !pSh || !pSh->HasName() || !(pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )) + break; + + SfxMedium* pMed = pSh->GetMedium(); + + SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_VIEWONLY, sal_False ); + if ( pItem && pItem->GetValue() ) + { + SfxApplication* pApp = SFX_APP(); + SfxAllItemSet aSet( pApp->GetPool() ); + aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetURLObject().GetMainURL(INetURLObject::NO_DECODE) ) ); + aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); + aSet.Put( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_blank") ) ); + SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False ); + if ( pReferer ) + aSet.Put( *pReferer ); + SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pVersionItem, SfxInt16Item, SID_VERSION, sal_False ); + if ( pVersionItem ) + aSet.Put( *pVersionItem ); + + if( pMed->GetFilter() ) + { + aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) ); + SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False ); + if ( pOptions ) + aSet.Put( *pOptions ); + } + + GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet ); + return; + } + + sal_uInt16 nOpenMode; + sal_Bool bNeedsReload = sal_False; + if ( !pSh->IsReadOnly() ) + { + // Speichern und Readonly Reloaden + if( pSh->IsModified() ) + { + if ( pSh->PrepareClose() ) + { + // the storing could let the medium be changed + pMed = pSh->GetMedium(); + bNeedsReload = sal_True; + } + else + { + rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) ); + return; + } + } + nOpenMode = SFX_STREAM_READONLY; + } + else + { + if ( pSh->IsReadOnlyMedium() + && ( pSh->GetModifyPasswordHash() || pSh->GetModifyPasswordInfo().getLength() ) + && !pSh->IsModifyPasswordEntered() ) + { + ::rtl::OUString aDocumentName = INetURLObject( pMed->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET ); + if( !AskPasswordToModify_Impl( pMed->GetInteractionHandler(), aDocumentName, pMed->GetOrigFilter(), pSh->GetModifyPasswordHash(), pSh->GetModifyPasswordInfo() ) ) + { + // this is a read-only document, if it has "Password to modify" + // the user should enter password before he can edit the document + rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) ); + return; + } + + pSh->SetModifyPasswordEntered(); + } + + nOpenMode = SFX_STREAM_READWRITE; + pSh->SetReadOnlyUI( sal_False ); + + // if only the view was in the readonly mode then there is no need to do the reload + if ( !pSh->IsReadOnly() ) + return; + } + + // Parameter auswerten + // sal_Bool bReload = sal_True; + if ( rReq.IsAPI() ) + { + // per API steuern ob r/w oder r/o + SFX_REQUEST_ARG(rReq, pEditItem, SfxBoolItem, SID_EDITDOC, sal_False); + if ( pEditItem ) + nOpenMode = pEditItem->GetValue() ? SFX_STREAM_READWRITE : SFX_STREAM_READONLY; + } + + // doing + + String aTemp; + utl::LocalFileHelper::ConvertPhysicalNameToURL( pMed->GetPhysicalName(), aTemp ); + INetURLObject aPhysObj( aTemp ); + SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), + pVersionItem, SfxInt16Item, SID_VERSION, sal_False ); + + INetURLObject aMedObj( pMed->GetName() ); + + // the logic below is following, if the document seems not to need to be reloaded and the physical name is different + // to the logical one, then on file system it can be checked that the copy is still newer than the original and no document reload is required + if ( ( !bNeedsReload && ( (aMedObj.GetProtocol() == INET_PROT_FILE && + aMedObj.getFSysPath(INetURLObject::FSYS_DETECT) != aPhysObj.getFSysPath(INetURLObject::FSYS_DETECT) && + !::utl::UCBContentHelper::IsYounger( aMedObj.GetMainURL( INetURLObject::NO_DECODE ), aPhysObj.GetMainURL( INetURLObject::NO_DECODE ) )) + || pMed->IsRemote() ) ) + || pVersionItem ) + { + sal_Bool bOK = sal_False; + if ( !pVersionItem ) + { + sal_Bool bHasStorage = pMed->HasStorage_Impl(); + // switching edit mode could be possible without reload + if ( bHasStorage && pMed->GetStorage() == pSh->GetStorage() ) + { + // TODO/LATER: faster creation of copy + if ( !pSh->ConnectTmpStorage_Impl( pMed->GetStorage(), pMed ) ) + return; + } + + pMed->CloseAndRelease(); + pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) ); + pMed->SetOpenMode( nOpenMode, pMed->IsDirect() ); + + pMed->CompleteReOpen(); + if ( nOpenMode & STREAM_WRITE ) + pMed->LockOrigFileOnDemand( sal_False, sal_True ); + + // LockOrigFileOnDemand might set the readonly flag itself, it should be set back + pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) ); + + if ( !pMed->GetErrorCode() ) + bOK = sal_True; + } + + if( !bOK ) + { + ErrCode nErr = pMed->GetErrorCode(); + if ( pVersionItem ) + nErr = ERRCODE_IO_ACCESSDENIED; + else + { + pMed->ResetError(); + pMed->SetOpenMode( SFX_STREAM_READONLY, pMed->IsDirect() ); + pMed->ReOpen(); + pSh->DoSaveCompleted( pMed ); + } + + // r/o-Doc kann nicht in Editmode geschaltet werden? + rReq.Done( sal_False ); + + if ( nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI() ) + { + // dem ::com::sun::star::sdbcx::User anbieten, als Vorlage zu oeffnen + QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) ); + if ( RET_YES == aBox.Execute() ) + { + SfxApplication* pApp = SFX_APP(); + SfxAllItemSet aSet( pApp->GetPool() ); + aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) ); + SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False ); + if ( pReferer ) + aSet.Put( *pReferer ); + aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); + if ( pVersionItem ) + aSet.Put( *pVersionItem ); + + if( pMed->GetFilter() ) + { + aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) ); + SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, + SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False ); + if ( pOptions ) + aSet.Put( *pOptions ); + } + + GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet ); + return; + } + else + nErr = 0; + } + + ErrorHandler::HandleError( nErr ); + rReq.SetReturnValue( + SfxBoolItem( rReq.GetSlot(), sal_False ) ); + return; + } + else + { + pSh->DoSaveCompleted( pMed ); + pSh->Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) ); + rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_True ) ); + rReq.Done( sal_True ); + // if( nOpenMode == SFX_STREAM_READONLY ) + // pMed->Close(); + return; + } + } + + rReq.AppendItem( SfxBoolItem( SID_FORCERELOAD, sal_True) ); + rReq.AppendItem( SfxBoolItem( SID_SILENT, sal_True )); + } + + case SID_RELOAD: + { + // Wg. Doppeltbelegung in Toolboxen (mit/ohne Ctrl) ist es auch + // m"oglich, da\s der Slot zwar enabled ist, aber Ctrl-Click + // trotzdem nicht geht! + if ( !pSh || !pSh->CanReload_Impl() ) + break; + SfxApplication* pApp = SFX_APP(); + SFX_REQUEST_ARG(rReq, pForceReloadItem, SfxBoolItem, + SID_FORCERELOAD, sal_False); + if( pForceReloadItem && !pForceReloadItem->GetValue() && + !pSh->GetMedium()->IsExpired() ) + return; + if( pImp->bReloading || pSh->IsInModalMode() ) + return; + + // AutoLoad ist ggf. verboten + SFX_REQUEST_ARG(rReq, pAutoLoadItem, SfxBoolItem, SID_AUTOLOAD, sal_False); + if ( pAutoLoadItem && pAutoLoadItem->GetValue() && + GetFrame().IsAutoLoadLocked_Impl() ) + return; + + SfxObjectShellLock xOldObj( pSh ); + pImp->bReloading = sal_True; + SFX_REQUEST_ARG(rReq, pURLItem, SfxStringItem, + SID_FILE_NAME, sal_False); + // editierbar "offnen? + sal_Bool bForEdit = !pSh->IsReadOnly(); + if ( rReq.GetSlot() == SID_EDITDOC ) + bForEdit = !bForEdit; + + // ggf. beim User nachfragen + sal_Bool bDo = ( GetViewShell()->PrepareClose() != FALSE ); + SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False); + if ( bDo && GetFrame().DocIsModified_Impl() && + !rReq.IsAPI() && ( !pSilentItem || !pSilentItem->GetValue() ) ) + { + QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_LASTVERSION) ); + bDo = ( RET_YES == aBox.Execute() ); + } + + if ( bDo ) + { + SfxMedium *pMedium = xOldObj->GetMedium(); + + // Frameset abziehen, bevor FramesetView evtl. verschwindet + String aURL = pURLItem ? pURLItem->GetValue() : + pMedium->GetName(); + + sal_Bool bHandsOff = + ( pMedium->GetURLObject().GetProtocol() == INET_PROT_FILE && !xOldObj->IsDocShared() ); + + // bestehende SfxMDIFrames f"ur dieses Doc leeren + // eigenes Format oder R/O jetzt editierbar "offnen? + SfxObjectShellLock xNewObj; + + // collect the views of the document + // TODO: when UNO ViewFactories are available for SFX-based documents, the below code should + // be UNOized, too + typedef ::std::pair< Reference< XFrame >, USHORT > ViewDescriptor; + ::std::list< ViewDescriptor > aViewFrames; + SfxViewFrame *pView = GetFirst( xOldObj ); + while ( pView ) + { + Reference< XFrame > xFrame( pView->GetFrame().GetFrameInterface() ); + OSL_ENSURE( xFrame.is(), "SfxViewFrame::ExecReload_Impl: no XFrame?!" ); + aViewFrames.push_back( ViewDescriptor( xFrame, pView->GetCurViewId() ) ); + + pView = GetNext( *pView, xOldObj ); + } + + DELETEZ( xOldObj->Get_Impl()->pReloadTimer ); + + SfxItemSet* pNewSet = 0; + const SfxFilter *pFilter = pMedium->GetFilter(); + if( pURLItem ) + { + pNewSet = new SfxAllItemSet( pApp->GetPool() ); + pNewSet->Put( *pURLItem ); + + // Filter Detection + SfxMedium aMedium( pURLItem->GetValue(), SFX_STREAM_READWRITE ); + SfxFilterMatcher().GuessFilter( aMedium, &pFilter ); + if ( pFilter ) + pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) ); + pNewSet->Put( *aMedium.GetItemSet() ); + } + else + { + pNewSet = new SfxAllItemSet( *pMedium->GetItemSet() ); + pNewSet->ClearItem( SID_VIEW_ID ); + pNewSet->ClearItem( SID_STREAM ); + pNewSet->ClearItem( SID_INPUTSTREAM ); + pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pMedium->GetFilter()->GetName() ) ); + + // let the current security settings be checked again + pNewSet->Put( SfxUInt16Item( SID_MACROEXECMODE, document::MacroExecMode::USE_CONFIG ) ); + + if ( rReq.GetSlot() == SID_EDITDOC || !bForEdit ) + // edit mode is switched or reload of readonly document + pNewSet->Put( SfxBoolItem( SID_DOC_READONLY, !bForEdit ) ); + else + // Reload of file opened for writing + pNewSet->ClearItem( SID_DOC_READONLY ); + } + + // Falls eine salvagede Datei vorliegt, nicht nochmals die + // OrigURL mitschicken, denn die Tempdate ist nach Reload + // ungueltig + SFX_ITEMSET_ARG( pNewSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False); + if( pSalvageItem ) + { + aURL = pSalvageItem->GetValue(); + pNewSet->ClearItem( SID_DOC_SALVAGE ); + } + + // TODO/LATER: Temporary solution, the SfxMedium must know the original URL as aLogicName + // SfxMedium::Transfer_Impl() will be vorbidden then. + if ( xOldObj->IsDocShared() ) + pNewSet->Put( SfxStringItem( SID_FILE_NAME, xOldObj->GetSharedFileURL() ) ); + + //pNewMedium = new SfxMedium( aURL, nMode, pMedium->IsDirect(), bUseFilter ? pMedium->GetFilter() : 0, pNewSet ); + //pNewSet = pNewMedium->GetItemSet(); + if ( pURLItem ) + pNewSet->Put( SfxStringItem( SID_REFERER, pMedium->GetName() ) ); + else + pNewSet->Put( SfxStringItem( SID_REFERER, String() ) ); + + xOldObj->CancelTransfers(); + + // eigentliches Reload + //pNewSet->Put( SfxFrameItem ( SID_DOCFRAME, GetFrame() ) ); + + if ( pSilentItem && pSilentItem->GetValue() ) + pNewSet->Put( SfxBoolItem( SID_SILENT, sal_True ) ); + + SFX_ITEMSET_ARG(pNewSet, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, FALSE); + SFX_ITEMSET_ARG(pNewSet, pMacroExecItem , SfxUInt16Item, SID_MACROEXECMODE , FALSE); + SFX_ITEMSET_ARG(pNewSet, pDocTemplateItem, SfxUInt16Item, SID_UPDATEDOCMODE , FALSE); + + if (!pInteractionItem) + { + Reference < ::com::sun::star::task::XInteractionHandler > xHdl( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY ); + if (xHdl.is()) + pNewSet->Put( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHdl)) ); + } + + if (!pMacroExecItem) + pNewSet->Put( SfxUInt16Item(SID_MACROEXECMODE,::com::sun::star::document::MacroExecMode::USE_CONFIG) ); + if (!pDocTemplateItem) + pNewSet->Put( SfxUInt16Item(SID_UPDATEDOCMODE,::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG) ); + + xOldObj->SetModified( sal_False ); + // Altes Dok nicht cachen! Gilt nicht, wenn anderes + // Doc geladen wird. + + SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False); + SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedReferer, SfxStringItem, SID_REFERER, sal_False); + + sal_Bool bHasStorage = pMedium->HasStorage_Impl(); + if( bHandsOff ) + { + if ( bHasStorage && pMedium->GetStorage() == xOldObj->GetStorage() ) + { + // TODO/LATER: faster creation of copy + if ( !xOldObj->ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) ) + return; + } + + pMedium->CloseAndRelease(); + } + + xNewObj = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_STANDARD ); + + if ( xOldObj->IsModifyPasswordEntered() ) + xNewObj->SetModifyPasswordEntered(); + + uno::Sequence < beans::PropertyValue > aLoadArgs; + TransformItems( SID_OPENDOC, *pNewSet, aLoadArgs ); + try + { + uno::Reference < frame::XLoadable > xLoad( xNewObj->GetModel(), uno::UNO_QUERY ); + xLoad->load( aLoadArgs ); + } + catch ( uno::Exception& ) + { + xNewObj->DoClose(); + xNewObj = 0; + } + + DELETEZ( pNewSet ); + + if( !xNewObj.Is() ) + { + if( bHandsOff ) + { + // back to old medium + pMedium->ReOpen(); + pMedium->LockOrigFileOnDemand( sal_False, sal_True ); + + xOldObj->DoSaveCompleted( pMedium ); + } + + // r/o-Doc couldn't be switched to writing mode + if ( bForEdit && SID_EDITDOC == rReq.GetSlot() ) + { + // ask user for opening as template + QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) ); + if ( RET_YES == aBox.Execute() ) + { + SfxAllItemSet aSet( pApp->GetPool() ); + aSet.Put( SfxStringItem( SID_FILE_NAME, pMedium->GetName() ) ); + aSet.Put( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_blank") ) ); + if ( pSavedOptions ) + aSet.Put( *pSavedOptions ); + if ( pSavedReferer ) + aSet.Put( *pSavedReferer ); + aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); + if( pFilter ) + aSet.Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetFilterName() ) ); + GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet ); + } + } + else + { + // an error handling should be done here?! + // if ( !pSilentItem || !pSilentItem->GetValue() ) + // ErrorHandler::HandleError( nLoadError ); + } + } + else + { + if ( xNewObj->GetModifyPasswordHash() && xNewObj->GetModifyPasswordHash() != xOldObj->GetModifyPasswordHash() ) + { + xNewObj->SetModifyPasswordEntered( sal_False ); + xNewObj->SetReadOnly(); + } + + if ( xNewObj->IsDocShared() ) + { + // the file is shared but the closing can change the sharing control file + xOldObj->DoNotCleanShareControlFile(); + } + + // the Reload and Silent items were only temporary, remove them + xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_RELOAD ); + xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_SILENT ); + TransformItems( SID_OPENDOC, *xNewObj->GetMedium()->GetItemSet(), aLoadArgs ); + + UpdateDocument_Impl(); + + try + { + while ( !aViewFrames.empty() ) + { + LoadViewIntoFrame_Impl( *xNewObj, aViewFrames.front().first, aLoadArgs, aViewFrames.front().second, false ); + aViewFrames.pop_front(); + } + } + catch( const Exception& ) + { + // close the remaining frames + // Don't catch exceptions herein, if this fails, then we're left in an indetermined state, and + // crashing is better than trying to proceed + while ( !aViewFrames.empty() ) + { + Reference< util::XCloseable > xClose( aViewFrames.front().first, UNO_QUERY_THROW ); + xClose->close( sal_True ); + aViewFrames.pop_front(); + } + } + + // Propagate document closure. + SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ), xOldObj ) ); + } + + // als erledigt recorden + rReq.Done( sal_True ); + rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_True)); + return; + } + else + { + // als nicht erledigt recorden + rReq.Done(); + rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_False)); + pImp->bReloading = sal_False; + return; + } + } + } +} + +//------------------------------------------------------------------------- +void SfxViewFrame::StateReload_Impl( SfxItemSet& rSet ) +{ + SfxObjectShell* pSh = GetObjectShell(); + if ( !pSh ) + // Ich bin gerade am Reloaden und Yielde so vor mich hin ... + return; + + GetFrame().GetParentFrame(); + SfxWhichIter aIter( rSet ); + for ( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() ) + { + if ( GetFrame().HasComponent() ) + { + // Wenn die Komponente es nicht selbst dispatched, dann + // macht es auch keinen Sinn! + rSet.DisableItem( nWhich ); + continue; + } + + switch ( nWhich ) + { + case SID_EDITDOC: + { + if ( !pSh || !pSh->HasName() || !( pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) + || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) + rSet.DisableItem( SID_EDITDOC ); + else + { + SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, sal_False ); + if ( pItem && !pItem->GetValue() ) + rSet.DisableItem( SID_EDITDOC ); + else + rSet.Put( SfxBoolItem( nWhich, !pSh->IsReadOnly() ) ); + } + break; + } + + case SID_RELOAD: + { + SfxFrame* pFrame = &GetTopFrame(); + + if ( !pSh || !pSh->CanReload_Impl() || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) + rSet.DisableItem(nWhich); + else + { + // Wenn irgendein ChildFrame reloadable ist, wird der Slot + // enabled, damit man CTRL-Reload machen kann + sal_Bool bReloadAvailable = sal_False; + SfxFrameIterator aFrameIter( *pFrame, sal_True ); + for( SfxFrame* pNextFrame = aFrameIter.FirstFrame(); + pFrame; + pNextFrame = pNextFrame ? + aFrameIter.NextFrame( *pNextFrame ) : 0 ) + { + SfxObjectShell *pShell = pFrame->GetCurrentDocument(); + if( pShell && pShell->Get_Impl()->bReloadAvailable ) + { + bReloadAvailable = sal_True; + break; + } + pFrame = pNextFrame; + } + + rSet.Put( SfxBoolItem( nWhich, bReloadAvailable)); + } + + break; + } + } + } +} + + +//-------------------------------------------------------------------- +void SfxViewFrame::ExecHistory_Impl( SfxRequest &rReq ) +{ + // gibt es an der obersten Shell einen Undo-Manager? + SfxShell *pSh = GetDispatcher()->GetShell(0); + SfxUndoManager* pShUndoMgr = pSh->GetUndoManager(); + sal_Bool bOK = sal_False; + if ( pShUndoMgr ) + { + switch ( rReq.GetSlot() ) + { + case SID_CLEARHISTORY: + pShUndoMgr->Clear(); + bOK = sal_True; + break; + + case SID_UNDO: + pShUndoMgr->Undo(0); + GetBindings().InvalidateAll(sal_False); + bOK = sal_True; + break; + + case SID_REDO: + pShUndoMgr->Redo(0); + GetBindings().InvalidateAll(sal_False); + bOK = sal_True; + break; + + case SID_REPEAT: + if ( pSh->GetRepeatTarget() ) + pShUndoMgr->Repeat( *pSh->GetRepeatTarget(), 0); + bOK = sal_True; + break; + } + } + else if ( GetViewShell() ) + { + // der SW hat eigenes Undo an der View + const SfxPoolItem *pRet = GetViewShell()->ExecuteSlot( rReq ); + if ( pRet ) + bOK = ((SfxBoolItem*)pRet)->GetValue(); + } + + rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bOK ) ); + rReq.Done(); +} + +//-------------------------------------------------------------------- +void SfxViewFrame::StateHistory_Impl( SfxItemSet &rSet ) +{ + // Undo-Manager suchen + SfxShell *pSh = GetDispatcher()->GetShell(0); + if ( !pSh ) + // Ich bin gerade am Reloaden und Yielde so vor mich hin ... + return; + + SfxUndoManager *pShUndoMgr = pSh->GetUndoManager(); + if ( !pShUndoMgr ) + { + // der SW hat eigenes Undo an der View + SfxWhichIter aIter( rSet ); + SfxViewShell *pViewSh = GetViewShell(); + if( !pViewSh ) return; + for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() ) + pViewSh->GetSlotState( nSID, 0, &rSet ); + return; + } + + if ( pShUndoMgr->GetUndoActionCount() == 0 && + pShUndoMgr->GetRedoActionCount() == 0 && + pShUndoMgr->GetRepeatActionCount() == 0 ) + rSet.DisableItem( SID_CLEARHISTORY ); + + if ( pShUndoMgr && pShUndoMgr->GetUndoActionCount() ) + { + String aTmp( SfxResId( STR_UNDO ) ); + aTmp += pShUndoMgr->GetUndoActionComment(0); + rSet.Put( SfxStringItem( SID_UNDO, aTmp ) ); + } + else + rSet.DisableItem( SID_UNDO ); + + if ( pShUndoMgr && pShUndoMgr->GetRedoActionCount() ) + { + String aTmp( SfxResId(STR_REDO) ); + aTmp += pShUndoMgr->GetRedoActionComment(0); + rSet.Put( SfxStringItem( SID_REDO, aTmp ) ); + } + else + rSet.DisableItem( SID_REDO ); + SfxRepeatTarget *pTarget = pSh->GetRepeatTarget(); + if ( pShUndoMgr && pTarget && pShUndoMgr->GetRepeatActionCount() && + pShUndoMgr->CanRepeat(*pTarget, 0) ) + { + String aTmp( SfxResId(STR_REPEAT) ); + aTmp += pShUndoMgr->GetRepeatActionComment(*pTarget, 0); + rSet.Put( SfxStringItem( SID_REPEAT, aTmp ) ); + } + else + rSet.DisableItem( SID_REPEAT ); +} + +//-------------------------------------------------------------------- +void SfxViewFrame::PopShellAndSubShells_Impl( SfxViewShell& i_rViewShell ) +{ + i_rViewShell.PopSubShells_Impl(); + sal_uInt16 nLevel = pDispatcher->GetShellLevel( i_rViewShell ); + if ( nLevel != USHRT_MAX ) + { + if ( nLevel ) + { + // more sub shells on the stack, which were not affected by PopSubShells_Impl + SfxShell *pSubShell = pDispatcher->GetShell( nLevel-1 ); + if ( pSubShell == i_rViewShell.GetSubShell() ) + // "real" sub shells will be deleted elsewhere + pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL ); + else + pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL | SFX_SHELL_POP_DELETE ); + } + pDispatcher->Pop( i_rViewShell ); + pDispatcher->Flush(); + } + +} + +//-------------------------------------------------------------------- +void SfxViewFrame::ReleaseObjectShell_Impl() + +/* [Beschreibung] + + Diese Methode entleert den SfxViewFrame, d.h. nimmt die <SfxObjectShell> + vom Dispatcher und beendet seine <SfxListener>-Beziehung zu dieser + SfxObjectShell (wodurch sie sich ggf. selbst zerst"ort). + + Somit kann durch Aufruf von ReleaseObjectShell() und SetObjectShell() + die SfxObjectShell ausgetauscht werden. + + Zwischen RealeaseObjectShell() und SetObjectShell() darf die Kontrolle + nicht an das System abgegeben werden. + + + [Querverweise] + + <SfxViewFrame::SetObjectShell(SfxObjectShell&)> +*/ +{ + DBG_CHKTHIS(SfxViewFrame, 0); + DBG_ASSERT( xObjSh.Is(), "no SfxObjectShell to release!" ); + + GetFrame().ReleasingComponent_Impl( sal_True ); + if ( GetWindow().HasChildPathFocus( sal_True ) ) + { + DBG_ASSERT( !GetActiveChildFrame_Impl(), "Wrong active child frame!" ); + GetWindow().GrabFocus(); + } + + SfxViewShell *pDyingViewSh = GetViewShell(); + if ( pDyingViewSh ) + { + PopShellAndSubShells_Impl( *pDyingViewSh ); + pDyingViewSh->DisconnectAllClients(); + SetViewShell_Impl(0); + delete pDyingViewSh; + } +#ifdef DBG_UTIL + else + DBG_ERROR("Keine Shell"); +#endif + + if ( xObjSh.Is() ) + { + pImp->aLastType = xObjSh->Type(); + pDispatcher->Pop( *xObjSh ); + SfxModule* pModule = xObjSh->GetModule(); + if( pModule ) + pDispatcher->RemoveShell_Impl( *pModule ); + pDispatcher->Flush(); + EndListening( *xObjSh ); + + Notify( *xObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) ); + Notify( *xObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) ); + + if ( 1 == xObjSh->GetOwnerLockCount() && pImp->bObjLocked && xObjSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) + xObjSh->DoClose(); + SfxObjectShellRef xDyingObjSh = xObjSh; + xObjSh.Clear(); + if( ( GetFrameType() & SFXFRAME_HASTITLE ) && pImp->nDocViewNo ) + xDyingObjSh->GetNoSet_Impl().ReleaseIndex(pImp->nDocViewNo-1); + if ( pImp->bObjLocked ) + { + xDyingObjSh->OwnerLock( sal_False ); + pImp->bObjLocked = sal_False; + } + } + + GetDispatcher()->SetDisableFlags( 0 ); +} + +//-------------------------------------------------------------------- +sal_Bool SfxViewFrame::Close() +{ + DBG_CHKTHIS(SfxViewFrame, 0); + + DBG_ASSERT( GetFrame().IsClosing_Impl() || !GetFrame().GetFrameInterface().is(), "ViewFrame closed too early!" ); + + // Wenn bis jetzt noch nicht gespeichert wurde, sollen eingebettete Objekte + // auch nicht mehr automatisch gespeichert werden! + if ( GetViewShell() ) + GetViewShell()->DiscardClients_Impl(); + Broadcast( SfxSimpleHint( SFX_HINT_DYING ) ); + + if (SfxViewFrame::Current() == this) + SfxViewFrame::SetViewFrame( NULL ); + + // Da der Dispatcher leer ger"aumt wird, kann man ihn auch nicht mehr + // vern"unftig verwenden - also besser still legen + GetDispatcher()->Lock(sal_True); + delete this; + + return sal_True; +} + +//-------------------------------------------------------------------- + +void SfxViewFrame::DoActivate( sal_Bool bUI, SfxViewFrame* pOldFrame ) +{ + DBG_CHKTHIS(SfxViewFrame, 0); + SFX_APP(); + +#ifdef WIN + pSfxApp->TestFreeResources_Impl(); +#endif + + pDispatcher->DoActivate_Impl( bUI, pOldFrame ); + + // Wenn ich einen parent habe und dieser ist kein parent des alten + // ViewFrames, erh"alt er ein ParentActivate + if ( bUI ) + { +/* + SfxMedium* pMed = GetObjectShell() ? GetObjectShell()->GetMedium() : NULL; + if( pMed ) + { + SFX_ITEMSET_ARG( + pMed->GetItemSet(), pInterceptorItem, SfxSlotInterceptorItem, + SID_INTERCEPTOR, sal_False ); + if( pInterceptorItem ) + { + SfxSlotInterceptor* pInter = pInterceptorItem->GetValue(); + if( !pInter->GetBindings() ) + pInter->SetBindings( &GetBindings() ); + pInter->Activate( sal_True ); + } + } + */ + SfxViewFrame *pFrame = GetParentViewFrame(); + while ( pFrame ) + { + if ( !pOldFrame || !pOldFrame->GetFrame().IsParent( &pFrame->GetFrame() ) ) + pFrame->pDispatcher->DoParentActivate_Impl(); + pFrame = pFrame->GetParentViewFrame(); + } + } +} + +//-------------------------------------------------------------------- +void SfxViewFrame::DoDeactivate(sal_Bool bUI, SfxViewFrame* pNewFrame ) +{ + DBG_CHKTHIS(SfxViewFrame, 0); + SFX_APP(); + pDispatcher->DoDeactivate_Impl( bUI, pNewFrame ); + + // Wenn ich einen parent habe und dieser ist kein parent des neuen + // ViewFrames, erh"alt er ein ParentDeactivate + if ( bUI ) + { +// if ( GetFrame().GetWorkWindow_Impl() ) +// GetFrame().GetWorkWindow_Impl()->SaveStatus_Impl(); +/* + SfxMedium* pMed = GetObjectShell() ? GetObjectShell()->GetMedium() : NULL; + if( pMed ) + { + SFX_ITEMSET_ARG( + pMed->GetItemSet(), pInterceptorItem, SfxSlotInterceptorItem, + SID_INTERCEPTOR, sal_False ); + if( pInterceptorItem ) + pInterceptorItem->GetValue()->Activate( sal_False ); + } +*/ + SfxViewFrame *pFrame = GetParentViewFrame(); + while ( pFrame ) + { + if ( !pNewFrame || !pNewFrame->GetFrame().IsParent( &pFrame->GetFrame() ) ) + pFrame->pDispatcher->DoParentDeactivate_Impl(); + pFrame = pFrame->GetParentViewFrame(); + } + } +#ifdef WIN + pSfxApp->TestFreeResources_Impl(); +#endif +} + +//------------------------------------------------------------------------ +void SfxViewFrame::InvalidateBorderImpl( const SfxViewShell* pSh ) +{ + if( pSh && !nAdjustPosPixelLock ) + { + if ( GetViewShell() && GetWindow().IsVisible() ) + { + if ( GetFrame().IsInPlace() ) + { + /* + Size aSize( GetViewShell()->GetWindow()->GetSizePixel() ); + + //Size aBorderSz( pEnv->GetBorderWin()->GetHatchBorderPixel() ); + Point aOfs; //( aBorderSz.Width(), aBorderSz.Height() ); + + DoAdjustPosSizePixel( GetViewShell(), aOfs, aSize );*/ + return; + } + + DoAdjustPosSizePixel( (SfxViewShell *) GetViewShell(), Point(), + GetWindow().GetOutputSizePixel() ); + } + } +} + +//------------------------------------------------------------------------ +sal_Bool SfxViewFrame::SetBorderPixelImpl +( + const SfxViewShell* pVSh, + const SvBorder& rBorder +) + +{ + pImp->aBorder = rBorder; + + if ( IsResizeInToOut_Impl() && !GetFrame().IsInPlace() ) + { + Size aSize = pVSh->GetWindow()->GetOutputSizePixel(); + if ( aSize.Width() && aSize.Height() ) + { + aSize.Width() += rBorder.Left() + rBorder.Right(); + aSize.Height() += rBorder.Top() + rBorder.Bottom(); + + Size aOldSize = GetWindow().GetOutputSizePixel(); + GetWindow().SetOutputSizePixel( aSize ); + Window* pParent = &GetWindow(); + while ( pParent->GetParent() ) + pParent = pParent->GetParent(); + Size aOuterSize = pParent->GetOutputSizePixel(); + aOuterSize.Width() += ( aSize.Width() - aOldSize.Width() ); + aOuterSize.Height() += ( aSize.Height() - aOldSize.Height() ); + pParent->SetOutputSizePixel( aOuterSize ); + } + } + else + { + Point aPoint; + Rectangle aEditArea( aPoint, GetWindow().GetOutputSizePixel() ); + aEditArea.Left() += rBorder.Left(); + aEditArea.Right() -= rBorder.Right(); + aEditArea.Top() += rBorder.Top(); + aEditArea.Bottom() -= rBorder.Bottom(); + pVSh->GetWindow()->SetPosSizePixel( aEditArea.TopLeft(), aEditArea.GetSize() ); + } + + return sal_True; +} + +//------------------------------------------------------------------------ +const SvBorder& SfxViewFrame::GetBorderPixelImpl +( + const SfxViewShell* /*pSh*/ +) const + +{ + return pImp->aBorder; +} + +//-------------------------------------------------------------------- +void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + {DBG_CHKTHIS(SfxViewFrame, 0);} + + if( IsDowning_Impl()) + return; + + // we know only SimpleHints + if ( rHint.IsA(TYPE(SfxSimpleHint)) ) + { + switch( ( (SfxSimpleHint&) rHint ).GetId() ) + { + case SFX_HINT_MODECHANGED: + { + UpdateTitle(); + + if ( !xObjSh.Is() ) + break; + + // r/o Umschaltung? + SfxBindings& rBind = GetBindings(); + rBind.Invalidate( SID_RELOAD ); + SfxDispatcher *pDispat = GetDispatcher(); + sal_Bool bWasReadOnly = pDispat->GetReadOnly_Impl(); + sal_Bool bIsReadOnly = xObjSh->IsReadOnly(); + if ( !bWasReadOnly != !bIsReadOnly ) + { + // Dann auch TITLE_CHANGED + UpdateTitle(); + rBind.Invalidate( SID_FILE_NAME ); + rBind.Invalidate( SID_DOCINFO_TITLE ); + rBind.Invalidate( SID_EDITDOC ); + + pDispat->GetBindings()->InvalidateAll(sal_True); + pDispat->SetReadOnly_Impl( bIsReadOnly ); + + // Dispatcher-Update nur erzwingen, wenn es nicht sowieso + // demn"achst kommt, anderenfalls ist Zappelei oder gar + // GPF m"oglich, da Writer z.B. gerne mal im Resize irgendwelche + // Aktionen t"atigt, die ein SetReadOnlyUI am Dispatcher zur + // Folge haben! + if ( pDispat->IsUpdated_Impl() ) + pDispat->Update_Impl(sal_True); + } + + Enable( !xObjSh->IsInModalMode() ); + break; + } + + case SFX_HINT_TITLECHANGED: + { + UpdateTitle(); + SfxBindings& rBind = GetBindings(); + rBind.Invalidate( SID_FILE_NAME ); + rBind.Invalidate( SID_DOCINFO_TITLE ); + rBind.Invalidate( SID_EDITDOC ); + rBind.Invalidate( SID_RELOAD ); + break; + } + + case SFX_HINT_DEINITIALIZING: + GetFrame().DoClose(); + break; + case SFX_HINT_DYING: + // when the Object is being deleted, destroy the view too + if ( xObjSh.Is() ) + ReleaseObjectShell_Impl(); + else + GetFrame().DoClose(); + break; + + } + } + else if ( rHint.IsA(TYPE(SfxEventHint)) ) + { + // Wenn das Document asynchron geladen wurde, wurde der Dispatcher + // auf ReadOnly gesetzt, was zur"?ckgenommen werden mu\s, wenn + // das Document selbst nicht ReadOnly ist und das Laden fertig ist. + switch ( ((SfxEventHint&)rHint).GetEventId() ) + { + case SFX_EVENT_MODIFYCHANGED: + { + SfxBindings& rBind = GetBindings(); + rBind.Invalidate( SID_DOC_MODIFIED ); + rBind.Invalidate( SID_SAVEDOC ); + rBind.Invalidate( SID_RELOAD ); + rBind.Invalidate( SID_EDITDOC ); + break; + } + + case SFX_EVENT_OPENDOC: + case SFX_EVENT_CREATEDOC: + { + if ( !xObjSh.Is() ) + break; + + SfxBindings& rBind = GetBindings(); + rBind.Invalidate( SID_RELOAD ); + rBind.Invalidate( SID_EDITDOC ); + if ( !xObjSh->IsReadOnly() ) + { + // Im Gegensatz zu oben (TITLE_CHANGED) mu\s das UI nicht + // upgedated werden, da es nicht gehidet war! + + // #i21560# InvalidateAll() causes the assertion + // 'SfxBindings::Invalidate while in update" when + // the sfx slot SID_BASICIDE_APPEAR is executed + // via API from another thread (Java). + // According to MBA this call is not necessary anymore, + // because each document has its own SfxBindings. + // + //GetDispatcher()->GetBindings()->InvalidateAll(sal_True); + } + + break; + } + + case SFX_EVENT_TOGGLEFULLSCREENMODE: + { + if ( GetFrame().OwnsBindings_Impl() ) + GetBindings().GetDispatcher_Impl()->Update_Impl( sal_True ); + break; + } + } + } +} + +//------------------------------------------------------------------------ +void SfxViewFrame::Construct_Impl( SfxObjectShell *pObjSh ) +{ + pImp->bResizeInToOut = sal_True; + pImp->bDontOverwriteResizeInToOut = sal_False; + pImp->bObjLocked = sal_False; + pImp->pFocusWin = 0; + pImp->pActiveChild = NULL; + pImp->nCurViewId = 0; + pImp->bReloading = sal_False; + pImp->bIsDowning = sal_False; + pImp->bModal = sal_False; + pImp->bEnabled = sal_True; + pImp->nDocViewNo = 0; + pImp->aMargin = Size( -1, -1 ); + pImp->pWindow = 0; + + SetPool( &SFX_APP()->GetPool() ); + pDispatcher = new SfxDispatcher(this); + if ( !GetBindings().GetDispatcher() ) + GetBindings().SetDispatcher( pDispatcher ); + + xObjSh = pObjSh; + if ( xObjSh.Is() && xObjSh->IsPreview() ) + SetQuietMode_Impl( sal_True ); + + if ( pObjSh ) + { + pDispatcher->Push( *SFX_APP() ); + SfxModule* pModule = xObjSh->GetModule(); + if( pModule ) + pDispatcher->Push( *pModule ); + pDispatcher->Push( *this ); + pDispatcher->Push( *pObjSh ); + pDispatcher->Flush(); + StartListening( *pObjSh ); + pObjSh->ViewAssigned(); + Notify( *pObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) ); + Notify( *pObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) ); + pDispatcher->SetReadOnly_Impl( pObjSh->IsReadOnly() ); + } + else + { + pDispatcher->Push( *SFX_APP() ); + pDispatcher->Push( *this ); + pDispatcher->Flush(); + } + + SfxViewFrame *pThis = this; // wegen der kranken Array-Syntax + SfxViewFrameArr_Impl &rViewArr = SFX_APP()->GetViewFrames_Impl(); + rViewArr.C40_INSERT(SfxViewFrame, pThis, rViewArr.Count() ); +} + +SfxViewFrame::SfxViewFrame +( + SfxFrame& rFrame, + SfxObjectShell* pObjShell +) + +/* [Beschreibung] + + Ctor des SfxViewFrame f"ur eine <SfxObjectShell> aus der Ressource. + Die 'nViewId' der zu erzeugenden <SfxViewShell> kann angegeben werden + (default ist die zuerst registrierte SfxViewShell-Subklasse). +*/ + + : pImp( new SfxViewFrame_Impl( rFrame ) ) + , pDispatcher(0) + , pBindings( new SfxBindings ) + , nAdjustPosPixelLock( 0 ) +{ + DBG_CTOR( SfxViewFrame, NULL ); + + rFrame.SetCurrentViewFrame_Impl( this ); + rFrame.SetFrameType_Impl( GetFrameType() | SFXFRAME_HASTITLE ); + Construct_Impl( pObjShell ); + + pImp->pWindow = new SfxFrameViewWindow_Impl( this, rFrame.GetWindow() ); + pImp->pWindow->SetSizePixel( rFrame.GetWindow().GetOutputSizePixel() ); + rFrame.SetOwnsBindings_Impl( sal_True ); + rFrame.CreateWorkWindow_Impl(); +} + +//------------------------------------------------------------------------ +SfxViewFrame::~SfxViewFrame() +{ + DBG_DTOR(SfxViewFrame, 0); + + SetDowning_Impl(); + + if ( SfxViewFrame::Current() == this ) + SfxViewFrame::SetViewFrame( NULL ); + + ReleaseObjectShell_Impl(); + + if ( GetFrame().OwnsBindings_Impl() ) + // Die Bindings l"oscht der Frame! + KillDispatcher_Impl(); + + delete pImp->pWindow; + + if ( GetFrame().GetCurrentViewFrame() == this ) + GetFrame().SetCurrentViewFrame_Impl( NULL ); + + // von Frame-Liste abmelden + SfxApplication *pSfxApp = SFX_APP(); + SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl(); + const SfxViewFrame *pThis = this; + rFrames.Remove( rFrames.GetPos(pThis) ); + + // Member l"oschen + KillDispatcher_Impl(); + + delete pImp; +} + +//------------------------------------------------------------------------ +void SfxViewFrame::KillDispatcher_Impl() + +// Dispatcher abr"aumen und l"oschen + +{ + DBG_CHKTHIS(SfxViewFrame, 0); + + SfxModule* pModule = xObjSh.Is() ? xObjSh->GetModule() : 0; + if ( xObjSh.Is() ) + ReleaseObjectShell_Impl(); + if ( pDispatcher ) + { + if( pModule ) + pDispatcher->Pop( *pModule, SFX_SHELL_POP_UNTIL ); + else + pDispatcher->Pop( *this ); + DELETEZ(pDispatcher); + } +} + +//------------------------------------------------------------------------ +SfxViewFrame* SfxViewFrame::Current() +{ + return SfxApplication::Is_Impl() ? SFX_APP()->Get_Impl()->pViewFrame : NULL; +} + +//-------------------------------------------------------------------- +sal_uInt16 SfxViewFrame::Count() + +/* [Beschreibung] + + Liefert die Anzahl der sichtbaren <SfxViewFrame>-Instanzen. +*/ + +{ + SfxApplication *pSfxApp = SFX_APP(); + SfxViewFrameArr_Impl& rFrames = pSfxApp->GetViewFrames_Impl(); + const sal_uInt16 nCount = rFrames.Count(); + sal_uInt16 nFound = 0; + for ( sal_uInt16 i = 0; i < nCount; ++i ) + { + SfxViewFrame *pFrame = rFrames[i]; + if ( pFrame->IsVisible() ) + ++nFound; + } + return nFound; +} + +//-------------------------------------------------------------------- +// returns the first window of spec. type viewing the specified doc. +SfxViewFrame* SfxViewFrame::GetFirst +( + const SfxObjectShell* pDoc, + sal_Bool bOnlyIfVisible +) +{ + SfxApplication *pSfxApp = SFX_APP(); + SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl(); + + // search for a SfxDocument of the specified type + for ( sal_uInt16 nPos = 0; nPos < rFrames.Count(); ++nPos ) + { + SfxViewFrame *pFrame = rFrames.GetObject(nPos); + if ( ( !pDoc || pDoc == pFrame->GetObjectShell() ) + && ( !bOnlyIfVisible || pFrame->IsVisible() ) + ) + return pFrame; + } + + return 0; +} +//-------------------------------------------------------------------- + +// returns thenext window of spec. type viewing the specified doc. +SfxViewFrame* SfxViewFrame::GetNext +( + const SfxViewFrame& rPrev, + const SfxObjectShell* pDoc, + sal_Bool bOnlyIfVisible +) +{ + SfxApplication *pSfxApp = SFX_APP(); + SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl(); + + // refind the specified predecessor + sal_uInt16 nPos; + for ( nPos = 0; nPos < rFrames.Count(); ++nPos ) + if ( rFrames.GetObject(nPos) == &rPrev ) + break; + + // search for a Frame of the specified type + for ( ++nPos; nPos < rFrames.Count(); ++nPos ) + { + SfxViewFrame *pFrame = rFrames.GetObject(nPos); + if ( ( !pDoc || pDoc == pFrame->GetObjectShell() ) + && ( !bOnlyIfVisible || pFrame->IsVisible() ) + ) + return pFrame; + } + return 0; +} + +void SfxViewFrame::CloseHiddenFrames_Impl() +{ + SfxApplication *pSfxApp = SFX_APP(); + SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl(); + for ( sal_uInt16 nPos=0; nPos<rFrames.Count(); ) + { + SfxViewFrame *pFrame = rFrames.GetObject(nPos); + if ( !pFrame->IsVisible() ) + pFrame->DoClose(); + else + nPos++; + } +} + +//-------------------------------------------------------------------- +SfxProgress* SfxViewFrame::GetProgress() const +{ + SfxObjectShell *pObjSh = GetObjectShell(); + return pObjSh ? pObjSh->GetProgress() : 0; +} + +//-------------------------------------------------------------------- +void SfxViewFrame::ShowStatusText( const String& /*rText*/) +{ +/* OBSOLETE: If this is used, framework/uielement/progressbarwrapper.[h|c]xx & + framework/uielement/statusindicatorinterfacewrapper.[h|c]xx must be + extended to support a new interface to support ShowStatusText/HideStatusText + SfxWorkWindow* pWorkWin = GetFrame().GetWorkWindow_Impl(); + SfxStatusBarManager *pMgr = pWorkWin->GetStatusBarManager_Impl(); + if ( pMgr ) + { + pMgr->GetStatusBar()->HideItems(); + pMgr->GetStatusBar()->SetText( rText ); + } +*/ +} + +//-------------------------------------------------------------------- +void SfxViewFrame::HideStatusText() +{ +/* OBSOLETE: If this is used, framework/uielement/progressbarwrapper.[h|c]xx & + framework/uielement/statusindicatorinterfacewrapper.[h|c]xx must be + extended to support a new interface to support ShowStatusText/HideStatusText + SfxWorkWindow* pWorkWin = GetFrame().GetWorkWindow_Impl(); + SfxStatusBarManager *pMgr = pWorkWin->GetStatusBarManager_Impl(); + if ( pMgr ) + pMgr->GetStatusBar()->ShowItems(); +*/ +} + + +//-------------------------------------------------------------------- +#ifdef ENABLE_INIMANAGER//MUSTINI +SfxIniManager* SfxViewFrame::GetIniManager() const +{ +/* SfxIniManager *pIniMgr = GetObjectShell() + ? GetObjectShell()->GetFactory().GetIniManager() + : 0; + if ( !pIniMgr )*/ //! + return SFX_APP()->GetAppIniManager(); +// return pIniMgr; +} +#endif + +//-------------------------------------------------------------------- +void SfxViewFrame::DoAdjustPosSizePixel //! teilen in Inner.../Outer... +( + SfxViewShell* pSh, + const Point& rPos, + const Size& rSize +) +{ + DBG_CHKTHIS(SfxViewFrame, 0); + + // Components benutzen diese Methode nicht! + if( pSh && pSh->GetWindow() && !nAdjustPosPixelLock ) + { + nAdjustPosPixelLock++; + if ( pImp->bResizeInToOut ) + pSh->InnerResizePixel( rPos, rSize ); + else + pSh->OuterResizePixel( rPos, rSize ); + nAdjustPosPixelLock--; + } +} + +//======================================================================== + +int SfxViewFrameItem::operator==( const SfxPoolItem &rItem ) const +{ + return PTR_CAST(SfxViewFrameItem, &rItem)->pFrame== pFrame; +} + +//-------------------------------------------------------------------- +String SfxViewFrameItem::GetValueText() const +{ + return String(); +} + +//-------------------------------------------------------------------- +SfxPoolItem* SfxViewFrameItem::Clone( SfxItemPool *) const +{ + return new SfxViewFrameItem( pFrame); +} + +//-------------------------------------------------------------------- +void SfxViewFrame::SetViewShell_Impl( SfxViewShell *pVSh ) + +/* [Beschreibung] + + Interne Methode zum setzen der jeweils aktuellen <SfxViewShell>-Instanz, + die in diesem SfxViewFrame aktiv ist. +*/ + +{ + SfxShell::SetViewShell_Impl( pVSh ); + + // Hack: InPlaceMode + if ( pVSh ) + pImp->bResizeInToOut = sal_False; +} + +//-------------------------------------------------------------------- +/* + Beschreibung: + Der ParentViewFrame ist der ViewFrame des Containers bei internem InPlace +*/ + +//TODO/LATER: is it still necessary? is there a replacement for GetParentViewFrame_Impl? +SfxViewFrame* SfxViewFrame::GetParentViewFrame_Impl() const +{ + return NULL; +} + +//-------------------------------------------------------------------- +void SfxViewFrame::ForceOuterResize_Impl(sal_Bool bOn) +{ + if ( !pImp->bDontOverwriteResizeInToOut ) + pImp->bResizeInToOut = !bOn; +} + +void SfxViewFrame::ForceInnerResize_Impl(sal_Bool bOn) +{ + pImp->bDontOverwriteResizeInToOut = bOn; +} + +//-------------------------------------------------------------------- +sal_Bool SfxViewFrame::IsResizeInToOut_Impl() const +{ + return pImp->bResizeInToOut; +} +//-------------------------------------------------------------------- +void SfxViewFrame::DoAdjustPosSize( SfxViewShell *pSh, + const Point rPos, const Size &rSize ) +{ + DBG_CHKTHIS(SfxViewFrame, 0); + if( pSh && !nAdjustPosPixelLock ) + { + Window *pWindow = pSh->GetWindow(); + Point aPos = pWindow->LogicToPixel(rPos); + Size aSize = pWindow->LogicToPixel(rSize); + DoAdjustPosSizePixel(pSh, aPos, aSize); + } +} + +//-------------------------------------------------------------------- +void SfxViewFrame::GetDocNumber_Impl() +{ + DBG_ASSERT( GetObjectShell(), "Kein Dokument!" ); + GetObjectShell()->SetNamedVisibility_Impl(); + pImp->nDocViewNo = GetObjectShell()->GetNoSet_Impl().GetFreeIndex()+1; +} + +//-------------------------------------------------------------------- + +void SfxViewFrame::Enable( sal_Bool bEnable ) +{ + if ( bEnable != pImp->bEnabled ) + { + pImp->bEnabled = bEnable; + + // e.g. InPlace-Frames have a parent... + SfxViewFrame *pParent = GetParentViewFrame_Impl(); + if ( pParent ) + { + pParent->Enable( bEnable ); + } + else + { + Window *pWindow = &GetFrame().GetTopFrame().GetWindow(); + if ( !bEnable ) + pImp->bWindowWasEnabled = pWindow->IsInputEnabled(); + if ( !bEnable || pImp->bWindowWasEnabled ) + pWindow->EnableInput( bEnable, TRUE ); + } + + // cursor and focus + SfxViewShell* pViewSh = GetViewShell(); + if ( bEnable ) + { + // show cursor + if ( pViewSh ) + pViewSh->ShowCursor(); + } + else + { + // hide cursor + if ( pViewSh ) + pViewSh->ShowCursor(sal_False); + } +/* + if ( !bEnable ) + GetBindings().ENTERREGISTRATIONS(); + GetDispatcher()->Lock( !bEnable ); + if ( bEnable ) + GetBindings().LEAVEREGISTRATIONS(); +*/ + } +} + +//-------------------------------------------------------------------- +void SfxViewFrame::Show() + +/* [Beschreibung] + + Diese Methode macht das Frame-Window sichtbar und ermittelt vorher + den Fenstername. Au\serdem wird das Dokument festgehalten. Man darf + i.d.R. nie das Window direkt showen! +*/ + +{ + // zuerst locken damit in UpdateTitle() gilt: IsVisible() == sal_True (:#) + if ( xObjSh.Is() ) + { + xObjSh->GetMedium()->GetItemSet()->ClearItem( SID_HIDDEN ); + if ( !pImp->bObjLocked ) + LockObjectShell_Impl( sal_True ); + + // Doc-Shell Titel-Nummer anpassen, get unique view-no + if ( 0 == pImp->nDocViewNo ) + { + GetDocNumber_Impl(); + UpdateTitle(); + } + } + else + UpdateTitle(); + + // Frame-Window anzeigen, aber nur wenn der ViewFrame kein eigenes Window + // hat oder wenn er keine Component enth"alt + if ( &GetWindow() == &GetFrame().GetWindow() || !GetFrame().HasComponent() ) + GetWindow().Show(); + GetFrame().GetWindow().Show(); + +/* SfxViewFrame* pCurrent = SfxViewFrame::Current(); + if ( GetFrame().GetFrameInterface()->isActive() && + pCurrent != this && + ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) && + !GetActiveChildFrame_Impl() ) + MakeActive_Impl( FALSE );*/ + if ( xObjSh.Is() && xObjSh->Get_Impl()->bHiddenLockedByAPI ) + { + xObjSh->Get_Impl()->bHiddenLockedByAPI = FALSE; + xObjSh->OwnerLock(FALSE); + } +} + +//-------------------------------------------------------------------- +sal_Bool SfxViewFrame::IsVisible() const +{ + return pImp->bObjLocked; +} + +//-------------------------------------------------------------------- +void SfxViewFrame::Hide() +{ + GetWindow().Hide(); + if ( pImp->bObjLocked ) + LockObjectShell_Impl( sal_False ); +} + +//-------------------------------------------------------------------- +void SfxViewFrame::LockObjectShell_Impl( sal_Bool bLock ) +{ + DBG_ASSERT( pImp->bObjLocked != bLock, "Falscher Locked-Status!" ); + + DBG_ASSERT( GetObjectShell(), "Kein Dokument!" ); + GetObjectShell()->OwnerLock(bLock); + pImp->bObjLocked = bLock; +} + +//-------------------------------------------------------------------- +void SfxViewFrame::MakeActive_Impl( BOOL bGrabFocus ) +{ + if ( GetViewShell() && !GetFrame().IsClosing_Impl() ) + { + if ( IsVisible() ) + { + if ( GetViewShell() ) + { + BOOL bPreview = FALSE; + if ( GetObjectShell()->IsPreview() ) + { + bPreview = TRUE; + } + else + { + SfxViewFrame* pParent = GetParentViewFrame(); + if ( pParent ) + pParent->SetActiveChildFrame_Impl( this ); + } + + SfxViewFrame* pCurrent = SfxViewFrame::Current(); + css::uno::Reference< css::frame::XFrame > xFrame = GetFrame().GetFrameInterface(); + if ( !bPreview ) + { + SetViewFrame( this ); + GetBindings().SetActiveFrame( css::uno::Reference< css::frame::XFrame >() ); + uno::Reference< frame::XFramesSupplier > xSupp( xFrame, uno::UNO_QUERY ); + if ( xSupp.is() ) + xSupp->setActiveFrame( uno::Reference < frame::XFrame >() ); + + css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow(); + Window* pWindow = VCLUnoHelper::GetWindow(xContainerWindow); + if (pWindow && pWindow->HasChildPathFocus() && bGrabFocus) + { + SfxInPlaceClient *pCli = GetViewShell()->GetUIActiveClient(); + if ( ( !pCli || !pCli->IsObjectUIActive() ) && + ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) ) + GetFrame().GrabFocusOnComponent_Impl(); + } + } + else + { + GetBindings().SetDispatcher( GetDispatcher() ); + GetBindings().SetActiveFrame( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > () ); + GetDispatcher()->Update_Impl( FALSE ); + } + } + } + } +} + +//------------------------------------------------------------------------- + +void SfxViewFrame::SetQuietMode_Impl( sal_Bool bOn ) +{ + GetDispatcher()->SetQuietMode_Impl( bOn ); +} + +//------------------------------------------------------------------------- + +SfxObjectShell* SfxViewFrame::GetObjectShell() +{ + return xObjSh; +} + +const Size& SfxViewFrame::GetMargin_Impl() const +{ + return pImp->aMargin; +} + +void SfxViewFrame::SetActiveChildFrame_Impl( SfxViewFrame *pViewFrame ) +{ + if ( pViewFrame != pImp->pActiveChild ) + { + if ( !pImp->pActiveChild ) + GetDispatcher()->LockUI_Impl( sal_False ); + + pImp->pActiveChild = pViewFrame; + + Reference< XFramesSupplier > xFrame( GetFrame().GetFrameInterface(), UNO_QUERY ); + Reference< XFrame > xActive; + if ( pViewFrame ) + xActive = pViewFrame->GetFrame().GetFrameInterface(); + + if ( xFrame.is() ) // PB: #74432# xFrame cann be NULL + xFrame->setActiveFrame( xActive ); + } +} + +SfxViewFrame* SfxViewFrame::GetActiveChildFrame_Impl() const +{ + SfxViewFrame *pViewFrame = pImp->pActiveChild; +/* + if ( !pViewFrame ) + { + // Wenn es keinen aktiven ChildFrame gibt, irgendeinen nehmen + for ( sal_uInt16 n=0; n<GetChildFrameCount(); n++ ) + { + pViewFrame = + PTR_CAST( SfxViewFrame, GetChildFrame(n)->GetChildFrame(0) ); + if ( pViewFrame ) + break; + } + } + + pImp->pActiveChild = pViewFrame; +*/ + return pViewFrame; +} + +//-------------------------------------------------------------------- +SfxViewFrame* SfxViewFrame::LoadViewIntoFrame_Impl_NoThrow( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame, + const USHORT i_nViewId, const bool i_bHidden ) +{ + Reference< XFrame > xFrame( i_rFrame ); + bool bOwnFrame = false; + SfxViewShell* pSuccessView = NULL; + try + { + if ( !xFrame.is() ) + { + ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); + Reference < XFrame > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW ); + xFrame.set( xDesktop->findFrame( DEFINE_CONST_UNICODE("_blank"), 0 ), UNO_SET_THROW ); + bOwnFrame = true; + } + + pSuccessView = LoadViewIntoFrame_Impl( + i_rDoc, + xFrame, + Sequence< PropertyValue >(), // means "reuse existing model's args" + i_nViewId, + i_bHidden + ); + + if ( bOwnFrame && !i_bHidden ) + { + // ensure the frame/window is visible + Reference< XWindow > xContainerWindow( xFrame->getContainerWindow(), UNO_SET_THROW ); + xContainerWindow->setVisible( sal_True ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + if ( pSuccessView ) + return pSuccessView->GetViewFrame(); + + if ( bOwnFrame ) + { + try + { + xFrame->dispose(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + return NULL; +} + +//-------------------------------------------------------------------- +SfxViewShell* SfxViewFrame::LoadViewIntoFrame_Impl( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame, + const Sequence< PropertyValue >& i_rLoadArgs, const USHORT i_nViewId, + const bool i_bHidden ) +{ + Reference< XModel > xDocument( i_rDoc.GetModel(), UNO_SET_THROW ); + + ::comphelper::NamedValueCollection aTransformLoadArgs( i_rLoadArgs.getLength() ? i_rLoadArgs : xDocument->getArgs() ); + aTransformLoadArgs.put( "Model", xDocument ); + if ( i_nViewId ) + aTransformLoadArgs.put( "ViewId", sal_Int16( i_nViewId ) ); + if ( i_bHidden ) + aTransformLoadArgs.put( "Hidden", i_bHidden ); + else + aTransformLoadArgs.remove( "Hidden" ); + + ::rtl::OUString sURL( RTL_CONSTASCII_USTRINGPARAM( "private:object" ) ); + + Reference< XComponentLoader > xLoader( i_rFrame, UNO_QUERY_THROW ); + xLoader->loadComponentFromURL( sURL, ::rtl::OUString::createFromAscii( "_self" ), 0, + aTransformLoadArgs.getPropertyValues() ); + + SfxViewShell* pViewShell = SfxViewShell::Get( i_rFrame->getController() ); + ENSURE_OR_THROW( pViewShell, + "SfxViewFrame::LoadViewIntoFrame_Impl: loading an SFX doc into a frame resulted in a non-SFX view - quite impossible" ); + return pViewShell; +} + +//-------------------------------------------------------------------- + +SfxViewFrame* SfxViewFrame::LoadHiddenDocument( SfxObjectShell& i_rDoc, const USHORT i_nViewId ) +{ + return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, true ); +} + +//-------------------------------------------------------------------- + +SfxViewFrame* SfxViewFrame::LoadDocument( SfxObjectShell& i_rDoc, const USHORT i_nViewId ) +{ + return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, false ); +} + +//-------------------------------------------------------------------- + +SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rTargetFrame, const USHORT i_nViewId ) +{ + return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_rTargetFrame, i_nViewId, false ); +} + +//-------------------------------------------------------------------- + +SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const SfxFrameItem* i_pFrameItem, const USHORT i_nViewId ) +{ + return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_pFrameItem && i_pFrameItem->GetFrame() ? i_pFrameItem->GetFrame()->GetFrameInterface() : NULL, i_nViewId, false ); +} + +//-------------------------------------------------------------------- +SfxViewFrame* SfxViewFrame::DisplayNewDocument( SfxObjectShell& i_rDoc, const SfxRequest& i_rCreateDocRequest, const USHORT i_nViewId ) +{ + SFX_REQUEST_ARG( i_rCreateDocRequest, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, FALSE ); + SFX_REQUEST_ARG( i_rCreateDocRequest, pHiddenItem, SfxBoolItem, SID_HIDDEN, FALSE ); + + return LoadViewIntoFrame_Impl_NoThrow( + i_rDoc, + pFrameItem ? pFrameItem->GetFrame() : NULL, + i_nViewId, + pHiddenItem ? pHiddenItem->GetValue() : false + ); +} + +//-------------------------------------------------------------------- + +SfxViewFrame* SfxViewFrame::Get( const Reference< XController>& i_rController, const SfxObjectShell* i_pDoc ) +{ + if ( !i_rController.is() ) + return NULL; + + const SfxObjectShell* pDoc = i_pDoc; + if ( !pDoc ) + { + Reference< XModel > xDocument( i_rController->getModel() ); + for ( pDoc = SfxObjectShell::GetFirst( 0, false ); + pDoc; + pDoc = SfxObjectShell::GetNext( *pDoc, 0, false ) + ) + { + if ( pDoc->GetModel() == xDocument ) + break; + } + } + + SfxViewFrame* pViewFrame = NULL; + for ( pViewFrame = SfxViewFrame::GetFirst( pDoc, FALSE ); + pViewFrame; + pViewFrame = SfxViewFrame::GetNext( *pViewFrame, pDoc, FALSE ) + ) + { + if ( pViewFrame->GetViewShell()->GetController() == i_rController ) + break; + } + + return pViewFrame; +} + +//-------------------------------------------------------------------- + +sal_Bool SfxViewFrame::SwitchToViewShell_Impl +( + sal_uInt16 nViewIdOrNo, /* > 0 + Registrierungs-Id der View, auf die umge- + schaltet werden soll, bzw. die erstmalig + erzeugt werden soll. + + == 0 + Es soll die Default-View verwendet werden. */ + + sal_Bool bIsIndex /* sal_True + 'nViewIdOrNo' ist keine Registrations-Id sondern + ein Index in die f"ur die in diesem + <SfxViewFrame> dargestellte <SfxObjectShell>. + */ +) + +/* [Beschreibung] + + Interne Methode zum Umschalten auf eine andere <SfxViewShell>-Subklasse, + die in diesem SfxMDIFrame erzeugt werden soll. Existiert noch + keine SfxViewShell in diesem SfxMDIFrame, so wird erstmalig eine + erzeugt. + + + [R"uckgabewert] + + sal_Bool sal_True + die angeforderte SfxViewShell wurde erzeugt + und eine ggf. bestehende gel"oscht + + sal_False + die angeforderte SfxViewShell konnte nicht + erzeugt werden, die bestehende SfxViewShell + existiert daher weiterhin +*/ + +{ + try + { + ENSURE_OR_THROW( GetObjectShell() != NULL, "not possible without a document" ); + + // if we already have a view shell, remove it + SfxViewShell* pOldSh = GetViewShell(); + OSL_PRECOND( pOldSh, "SfxViewFrame::SwitchToViewShell_Impl: that's called *switch* (not for *initial-load*) for a reason" ); + if ( pOldSh ) + { + // ask wether it can be closed + if ( !pOldSh->PrepareClose( TRUE ) ) + return sal_False; + + // remove sub shells from Dispatcher before switching to new ViewShell + PopShellAndSubShells_Impl( *pOldSh ); + } + + GetBindings().ENTERREGISTRATIONS(); + LockAdjustPosSizePixel(); + + // ID of the new view + SfxObjectFactory& rDocFact = GetObjectShell()->GetFactory(); + const USHORT nViewId = ( bIsIndex || !nViewIdOrNo ) ? rDocFact.GetViewFactory( nViewIdOrNo ).GetOrdinal() : nViewIdOrNo; + + // create and load new ViewShell + SfxViewShell* pNewSh = LoadViewIntoFrame_Impl( + *GetObjectShell(), + GetFrame().GetFrameInterface(), + Sequence< PropertyValue >(), // means "reuse existing model's args" + nViewId, + false + ); + + // allow resize events to be processed + UnlockAdjustPosSizePixel(); + + if ( GetWindow().IsReallyVisible() ) + DoAdjustPosSizePixel( pNewSh, Point(), GetWindow().GetOutputSizePixel() ); + + GetBindings().LEAVEREGISTRATIONS(); + delete pOldSh; + } + catch ( const com::sun::star::uno::Exception& ) + { + // the SfxCode is not able to cope with exceptions thrown while creating views + // the code will crash in the stack unwinding procedure, so we shouldn't let exceptions go through here + DBG_UNHANDLED_EXCEPTION(); + return sal_False; + } + + DBG_ASSERT( SFX_APP()->GetViewFrames_Impl().Count() == SFX_APP()->GetViewShells_Impl().Count(), "Inconsistent view arrays!" ); + return sal_True; +} + +//------------------------------------------------------------------------- +void SfxViewFrame::SetCurViewId_Impl( const USHORT i_nID ) +{ + pImp->nCurViewId = i_nID; +} + +//------------------------------------------------------------------------- +sal_uInt16 SfxViewFrame::GetCurViewId() const +{ + return pImp->nCurViewId; +} + +//------------------------------------------------------------------------- +void SfxViewFrame::ExecView_Impl +( + SfxRequest& rReq // der auszuf"uhrende <SfxRequest> +) + +/* [Beschreibung] + + Interne Methode zum Ausf"uhren der f"ur die <SfxShell> Subklasse + SfxViewFrame in der <SVIDL> beschriebenen Slots. +*/ + +{ + DBG_CHKTHIS(SfxViewFrame, 0); + + // Wenn gerade die Shells ausgetauscht werden... + if ( !GetObjectShell() || !GetViewShell() ) + return; + + switch ( rReq.GetSlot() ) + { + case SID_TERMINATE_INPLACEACTIVATION : + { + SfxInPlaceClient* pClient = GetViewShell()->GetUIActiveClient(); + if ( pClient ) + pClient->DeactivateObject(); + break; + } + + case SID_VIEWSHELL: + { + const SfxPoolItem *pItem = 0; + if ( rReq.GetArgs() + && SFX_ITEM_SET == rReq.GetArgs()->GetItemState( SID_VIEWSHELL, sal_False, &pItem ) + ) + { + const sal_uInt16 nViewId = static_cast< const SfxUInt16Item* >( pItem )->GetValue(); + BOOL bSuccess = SwitchToViewShell_Impl( nViewId ); + rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) ); + } + break; + } + + case SID_VIEWSHELL0: + case SID_VIEWSHELL1: + case SID_VIEWSHELL2: + case SID_VIEWSHELL3: + case SID_VIEWSHELL4: + { + const sal_uInt16 nViewNo = rReq.GetSlot() - SID_VIEWSHELL0; + BOOL bSuccess = SwitchToViewShell_Impl( nViewNo, sal_True ); + rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) ); + break; + } + + case SID_NEWWINDOW: + { + // Hack. demnaechst virtuelle Funktion + if ( !GetViewShell()->NewWindowAllowed() ) + { + OSL_ENSURE( false, "You should have disabled the 'Window/New Window' slot!" ); + return; + } + + // ViewData bei FrameSets rekursiv holen + GetFrame().GetViewData_Impl(); + SfxMedium* pMed = GetObjectShell()->GetMedium(); + + // do not open the new window hidden + pMed->GetItemSet()->ClearItem( SID_HIDDEN ); + + // the view ID (optional arg. TODO: this is currently not supported in the slot definition ...) + SFX_REQUEST_ARG( rReq, pViewIdItem, SfxUInt16Item, SID_VIEW_ID, sal_False ); + const USHORT nViewId = pViewIdItem ? pViewIdItem->GetValue() : GetCurViewId(); + + Reference < XFrame > xFrame; + // the frame (optional arg. TODO: this is currently not supported in the slot definition ...) + SFX_REQUEST_ARG( rReq, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False ); + if ( pFrameItem ) + xFrame = pFrameItem->GetFrame(); + + LoadViewIntoFrame_Impl_NoThrow( *GetObjectShell(), xFrame, nViewId, false ); + + rReq.Done(); + break; + } + + case SID_OBJECT: + { + SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, SID_OBJECT, sal_False ); + + SfxViewShell *pViewShell = GetViewShell(); + if ( pViewShell && pItem ) + { + pViewShell->DoVerb( pItem->GetValue() ); + rReq.Done(); + break;; + } + } + } +} + +//------------------------------------------------------------------------- +/* TODO as96863: + This method try to collect informations about the count of currently open documents. + But the algorithm is implemented very simple ... + E.g. hidden documents should be ignored here ... but they are counted. + TODO: export special helper "framework::FrameListAnalyzer" within the framework module + and use it here. +*/ +sal_Bool impl_maxOpenDocCountReached() +{ + static ::rtl::OUString SERVICE_DESKTOP = ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"); + + try + { + css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); + css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey( + xSMGR, + ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/"), + ::rtl::OUString::createFromAscii("Misc"), + ::rtl::OUString::createFromAscii("MaxOpenDocuments"), + ::comphelper::ConfigurationHelper::E_READONLY); + + // NIL means: count of allowed documents = infinite ! + if ( ! aVal.hasValue()) + return sal_False; + + sal_Int32 nOpenDocs = 0; + sal_Int32 nMaxDocs = 0; + aVal >>= nMaxDocs; + + css::uno::Reference< css::frame::XFramesSupplier > xDesktop(xSMGR->createInstance(SERVICE_DESKTOP), css::uno::UNO_QUERY_THROW); + css::uno::Reference< css::container::XIndexAccess > xCont (xDesktop->getFrames() , css::uno::UNO_QUERY_THROW); + + sal_Int32 c = xCont->getCount(); + sal_Int32 i = 0; + + for (i=0; i<c; ++i) + { + try + { + css::uno::Reference< css::frame::XFrame > xFrame; + xCont->getByIndex(i) >>= xFrame; + if ( ! xFrame.is()) + continue; + + // a) do not count the help window + if (xFrame->getName().equalsAscii("OFFICE_HELP_TASK")) + continue; + + // b) count all other frames + ++nOpenDocs; + } + catch(const css::uno::Exception&) + // A IndexOutOfBoundException can happen in multithreaded environments, + // where any other thread can change this container ! + { continue; } + } + + return (nOpenDocs >= nMaxDocs); + } + catch(const css::uno::Exception&) + {} + + // Any internal error is no reason to stop opening documents ! + // Limitation of opening documents is a special "nice to have" feature. + // Otherwhise it can happen, that NO document will be opened ... + return sal_False; +} + +//------------------------------------------------------------------------- +void SfxViewFrame::StateView_Impl +( + SfxItemSet& rSet /* leeres <SfxItemSet> mit <Which-Ranges>, + welche die Ids der zu erfragenden + Slots beschreiben. */ +) + +/* [Beschreibung] + + Diese interne Methode liefert in 'rSet' die Status der f"ur die + <SfxShell> Subklasse SfxViewFrame in der <SVIDL> beschriebenen <Slots>. + + In 'rSet' sind dabei genau die vom SFx als ung"ultig erkannten + Slot-Ids als Which-ranges enthalten. Falls der an dieser Shell gesetzte + <SfxItemPool> f"ur einzelne Slot-Ids ein Mapping hat, werden die + entsprechenden Which-Ids verwendet, so da\s Items ggf. direkt mit + einer mit Which-Ids arbeitenden Core-::com::sun::star::script::Engine ausgetauscht werden + k"onnen. +*/ + +{ + DBG_CHKTHIS(SfxViewFrame, 0); + + SfxObjectShell *pDocSh = GetObjectShell(); + + if ( !pDocSh ) + // Ich bin gerade am Reloaden und Yielde so vor mich hin ... + return; + + const sal_uInt16 *pRanges = rSet.GetRanges(); + DBG_ASSERT(pRanges, "Set ohne Bereich"); + while ( *pRanges ) + { + for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich ) + { + switch(nWhich) + { + case SID_VIEWSHELL: + { + rSet.Put( SfxUInt16Item( nWhich, pImp->nCurViewId ) ); + break; + } + + case SID_VIEWSHELL0: + case SID_VIEWSHELL1: + case SID_VIEWSHELL2: + case SID_VIEWSHELL3: + case SID_VIEWSHELL4: + { + sal_uInt16 nViewNo = nWhich - SID_VIEWSHELL0; + if ( GetObjectShell()->GetFactory().GetViewFactoryCount() > + nViewNo && !GetObjectShell()->IsInPlaceActive() ) + { + SfxViewFactory &rViewFactory = + GetObjectShell()->GetFactory().GetViewFactory(nViewNo); + rSet.Put( SfxBoolItem( + nWhich, pImp->nCurViewId == rViewFactory.GetOrdinal() ) ); + } + else + rSet.DisableItem( nWhich ); + break; + } + case SID_FRAMETITLE: + { + if( GetFrameType() & SFXFRAME_HASTITLE ) + rSet.Put( SfxStringItem( + SID_FRAMETITLE, pImp->aFrameTitle) ); + else + rSet.DisableItem( nWhich ); + break; + } + + case SID_NEWWINDOW: + { + if ( !GetViewShell()->NewWindowAllowed() + || impl_maxOpenDocCountReached() + ) + rSet.DisableItem( nWhich ); + break; + } + } + } + } +} + +//------------------------------------------------------------------------- +void SfxViewFrame::ToTop() +{ + GetFrame().Appear(); +} + +//------------------------------------------------------------------------- +SfxViewFrame* SfxViewFrame::GetParentViewFrame() const +/* + Beschreibung: + Der ParentViewFrame ist der ViewFrame des ParentFrames +*/ +{ + SfxFrame *pFrame = GetFrame().GetParentFrame(); + return pFrame ? pFrame->GetCurrentViewFrame() : NULL; +} + +//------------------------------------------------------------------------- +SfxFrame& SfxViewFrame::GetFrame() const +/* + Beschreibung: + GetFrame liefert den Frame, in dem sich der ViewFrame befindet +*/ +{ + return pImp->rFrame; +} + +//------------------------------------------------------------------------- +SfxViewFrame* SfxViewFrame::GetTopViewFrame() const +{ + return GetFrame().GetTopFrame().GetCurrentViewFrame(); +} + +Window& SfxViewFrame::GetWindow() const +{ + return pImp->pWindow ? *pImp->pWindow : GetFrame().GetWindow(); +} + +sal_Bool SfxViewFrame::DoClose() +{ + return GetFrame().DoClose(); +} + +String SfxViewFrame::GetActualPresentationURL_Impl() const +{ + if ( xObjSh.Is() ) + return xObjSh->GetMedium()->GetName(); + return String(); +} + +void SfxViewFrame::SetModalMode( sal_Bool bModal ) +{ + pImp->bModal = bModal; + if ( xObjSh.Is() ) + { + for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( xObjSh ); + !bModal && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, xObjSh ) ) + bModal = pFrame->pImp->bModal; + xObjSh->SetModalMode_Impl( bModal ); + } +} + +BOOL SfxViewFrame::IsInModalMode() const +{ + return pImp->bModal || GetFrame().GetWindow().IsInModalMode(); +} + +void SfxViewFrame::Resize( BOOL bForce ) +{ + Size aSize = GetWindow().GetOutputSizePixel(); + if ( bForce || aSize != pImp->aSize ) + { + pImp->aSize = aSize; + SfxViewShell *pShell = GetViewShell(); + if ( pShell ) + { + if ( GetFrame().IsInPlace() ) + { + Point aPoint = GetWindow().GetPosPixel(); + DoAdjustPosSizePixel( pShell, aPoint, aSize ); + } + else + { + DoAdjustPosSizePixel( pShell, Point(), aSize ); + } + } + } +} + +#define LINE_SEP 0x0A + +void CutLines( ::rtl::OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, BOOL bEraseTrailingEmptyLines ) +{ + sal_Int32 nStartPos = 0; + sal_Int32 nEndPos = 0; + sal_Int32 nLine = 0; + while ( nLine < nStartLine ) + { + nStartPos = rStr.indexOf( LINE_SEP, nStartPos ); + if( nStartPos == -1 ) + break; + nStartPos++; // nicht das \n. + nLine++; + } + + DBG_ASSERTWARNING( nStartPos != STRING_NOTFOUND, "CutLines: Startzeile nicht gefunden!" ); + + if ( nStartPos != -1 ) + { + nEndPos = nStartPos; + for ( sal_Int32 i = 0; i < nLines; i++ ) + nEndPos = rStr.indexOf( LINE_SEP, nEndPos+1 ); + + if ( nEndPos == -1 ) // kann bei letzter Zeile passieren + nEndPos = rStr.getLength(); + else + nEndPos++; + + ::rtl::OUString aEndStr = rStr.copy( nEndPos ); + rStr = rStr.copy( 0, nStartPos ); + rStr += aEndStr; + } + if ( bEraseTrailingEmptyLines ) + { + sal_Int32 n = nStartPos; + sal_Int32 nLen = rStr.getLength(); + while ( ( n < nLen ) && ( rStr.getStr()[ n ] == LINE_SEP ) ) + n++; + + if ( n > nStartPos ) + { + ::rtl::OUString aEndStr = rStr.copy( n ); + rStr = rStr.copy( 0, nStartPos ); + rStr += aEndStr; + } + } +} + +/* + add new recorded dispatch macro script into the application global basic lib container + It generates a new unique id for it and insert the macro by using this number as name for + the modul + */ +void SfxViewFrame::AddDispatchMacroToBasic_Impl( const ::rtl::OUString& sMacro ) +{ + /* + // get lib and modul name from dialog + SfxModule *pMod = GetObjectShell()->GetModule(); + SfxRequest aReq( SID_BASICCHOOSER, SFX_CALLMODE_SYNCHRON, pMod->GetPool() ); + const SfxPoolItem* pRet = pMod->ExecuteSlot( aReq ); + if ( pRet ) + ::rtl::OUString = ((SfxStringItem*)pRet)->GetValue(); + */ + if ( !sMacro.getLength() ) + return; + + SfxApplication* pSfxApp = SFX_APP(); + SfxRequest aReq( SID_BASICCHOOSER, SFX_CALLMODE_SYNCHRON, pSfxApp->GetPool() ); + aReq.AppendItem( SfxBoolItem(SID_RECORDMACRO,TRUE) ); + const SfxPoolItem* pRet = SFX_APP()->ExecuteSlot( aReq ); + String aScriptURL; + if ( pRet ) + aScriptURL = ((SfxStringItem*)pRet)->GetValue(); + if ( aScriptURL.Len() ) + { + // parse scriptURL + String aLibName; + String aModuleName; + String aMacroName; + String aLocation; + Reference< XMultiServiceFactory > xSMgr = ::comphelper::getProcessServiceFactory(); + Reference< com::sun::star::uri::XUriReferenceFactory > xFactory( xSMgr->createInstance( + ::rtl::OUString::createFromAscii( "com.sun.star.uri.UriReferenceFactory" ) ), UNO_QUERY ); + if ( xFactory.is() ) + { + Reference< com::sun::star::uri::XVndSunStarScriptUrl > xUrl( xFactory->parse( aScriptURL ), UNO_QUERY ); + if ( xUrl.is() ) + { + // get name + ::rtl::OUString aName = xUrl->getName(); + sal_Unicode cTok = '.'; + sal_Int32 nIndex = 0; + aLibName = aName.getToken( 0, cTok, nIndex ); + if ( nIndex != -1 ) + aModuleName = aName.getToken( 0, cTok, nIndex ); + if ( nIndex != -1 ) + aMacroName = aName.getToken( 0, cTok, nIndex ); + + // get location + ::rtl::OUString aLocKey = ::rtl::OUString::createFromAscii( "location" ); + if ( xUrl->hasParameter( aLocKey ) ) + aLocation = xUrl->getParameter( aLocKey ); + } + } + + pSfxApp->EnterBasicCall(); + + BasicManager* pBasMgr = 0; + if ( aLocation.EqualsIgnoreCaseAscii( "application" ) ) + { + // application basic + pBasMgr = pSfxApp->GetBasicManager(); + } + else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) ) + { + pBasMgr = GetObjectShell()->GetBasicManager(); + } + + ::rtl::OUString aOUSource; + if ( pBasMgr) + { + StarBASIC* pBasic = pBasMgr->GetLib( aLibName ); + if ( pBasic ) + { + SbModule* pModule = pBasic->FindModule( aModuleName ); + if ( pModule ) + { + SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD ); + aOUSource = pModule->GetSource32(); + USHORT nStart, nEnd; + pMethod->GetLineRange( nStart, nEnd ); + ULONG nlStart = nStart; + ULONG nlEnd = nEnd; + CutLines( aOUSource, nlStart-1, nlEnd-nlStart+1, TRUE ); + } + } + } + + // open lib container and break operation if it couldn't be opened + com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibCont; + if ( aLocation.EqualsIgnoreCaseAscii( "application" ) ) + { + xLibCont = SFX_APP()->GetBasicContainer(); + } + else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) ) + { + xLibCont = GetObjectShell()->GetBasicContainer(); + } + + if(!xLibCont.is()) + { + DBG_ERRORFILE("couldn't get access to the basic lib container. Adding of macro isn't possible."); + return; + } + + // get LibraryContainer + com::sun::star::uno::Any aTemp; + com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xRoot( + xLibCont, + com::sun::star::uno::UNO_QUERY); + + ::rtl::OUString sLib( aLibName ); + com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xLib; + if(xRoot->hasByName(sLib)) + { + // library must be loaded + aTemp = xRoot->getByName(sLib); + xLibCont->loadLibrary(sLib); + aTemp >>= xLib; + } + else + { + xLib = com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >( + xLibCont->createLibrary(sLib), + com::sun::star::uno::UNO_QUERY); + } + + // pack the macro as direct usable "sub" routine + ::rtl::OUString sCode; + ::rtl::OUStringBuffer sRoutine(10000); + ::rtl::OUString sMacroName( aMacroName ); + BOOL bReplace = FALSE; + + // get module + ::rtl::OUString sModule( aModuleName ); + if(xLib->hasByName(sModule)) + { + if ( aOUSource.getLength() ) + { + sRoutine.append( aOUSource ); + } + else + { + aTemp = xLib->getByName(sModule); + aTemp >>= sCode; + sRoutine.append( sCode ); + } + + bReplace = TRUE; + } + + // append new method + sRoutine.appendAscii("\nsub " ); + sRoutine.append (sMacroName ); + sRoutine.appendAscii("\n" ); + sRoutine.append (sMacro ); + sRoutine.appendAscii("\nend sub\n"); + + // create the modul inside the library and insert the macro routine + aTemp <<= sRoutine.makeStringAndClear(); + if ( bReplace ) + { + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont( + xLib, + com::sun::star::uno::UNO_QUERY); + xModulCont->replaceByName(sModule,aTemp); + } + else + { + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont( + xLib, + com::sun::star::uno::UNO_QUERY); + xModulCont->insertByName(sModule,aTemp); + } + + // #i17355# update the Basic IDE + for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst(); pViewShell; pViewShell = SfxViewShell::GetNext( *pViewShell ) ) + { + if ( pViewShell->GetName().EqualsAscii( "BasicIDE" ) ) + { + SfxViewFrame* pViewFrame = pViewShell->GetViewFrame(); + SfxDispatcher* pDispat = pViewFrame ? pViewFrame->GetDispatcher() : NULL; + if ( pDispat ) + { + SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLibName, aModuleName, String(), String() ); + pDispat->Execute( SID_BASICIDE_UPDATEMODULESOURCE, SFX_CALLMODE_SYNCHRON, &aInfoItem, 0L ); + } + } + } + + pSfxApp->LeaveBasicCall(); + } + else + { + // add code for "session only" macro + } + + /* + FILE* pFile = fopen( "macro.bas", "a" ); + fprintf( pFile, "%s", ::rtl::OUStringToOString(sBuffer.makeStringAndClear(),RTL_TEXTENCODING_UTF8).getStr() ); + fclose ( pFile ); + */ +} + +void SfxViewFrame::MiscExec_Impl( SfxRequest& rReq ) +{ + DBG_MEMTEST(); + FASTBOOL bDone = FALSE; + switch ( rReq.GetSlot() ) + { + case SID_STOP_RECORDING : + case SID_RECORDMACRO : + { + // try to find any active recorder on this frame + ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier"); + com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame( + GetFrame().GetFrameInterface(), + com::sun::star::uno::UNO_QUERY); + + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(xFrame,com::sun::star::uno::UNO_QUERY); + com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty); + com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier; + aProp >>= xSupplier; + com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder; + if (xSupplier.is()) + xRecorder = xSupplier->getDispatchRecorder(); + + BOOL bIsRecording = xRecorder.is(); + SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, SID_RECORDMACRO, sal_False); + if ( pItem && pItem->GetValue() == bIsRecording ) + return; + + if ( xRecorder.is() ) + { + // disable active recording + aProp <<= com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >(); + xSet->setPropertyValue(sProperty,aProp); + + SFX_REQUEST_ARG( rReq, pRecordItem, SfxBoolItem, FN_PARAM_1, sal_False); + if ( !pRecordItem || !pRecordItem->GetValue() ) + // insert script into basic library container of application + AddDispatchMacroToBasic_Impl(xRecorder->getRecordedMacro()); + + xRecorder->endRecording(); + xRecorder = NULL; + GetBindings().SetRecorder_Impl( xRecorder ); + + SetChildWindow( SID_RECORDING_FLOATWINDOW, FALSE ); + if ( rReq.GetSlot() != SID_RECORDMACRO ) + GetBindings().Invalidate( SID_RECORDMACRO ); + } + else if ( rReq.GetSlot() == SID_RECORDMACRO ) + { + // enable recording + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xFactory( + ::comphelper::getProcessServiceFactory(), + com::sun::star::uno::UNO_QUERY); + + xRecorder = com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder >( + xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.frame.DispatchRecorder")), + com::sun::star::uno::UNO_QUERY); + + xSupplier = com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >( + xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.frame.DispatchRecorderSupplier")), + com::sun::star::uno::UNO_QUERY); + + xSupplier->setDispatchRecorder(xRecorder); + xRecorder->startRecording(xFrame); + aProp <<= xSupplier; + xSet->setPropertyValue(sProperty,aProp); + GetBindings().SetRecorder_Impl( xRecorder ); + SetChildWindow( SID_RECORDING_FLOATWINDOW, TRUE ); + } + + rReq.Done(); + break; + } + + case SID_TOGGLESTATUSBAR: + { + com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame( + GetFrame().GetFrameInterface(), + com::sun::star::uno::UNO_QUERY); + + Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY ); + Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager; + if ( xPropSet.is() ) + { + try + { + Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))); + aValue >>= xLayoutManager; + } + catch ( Exception& ) + { + } + } + + if ( xLayoutManager.is() ) + { + rtl::OUString aStatusbarResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" )); + // Parameter auswerten + SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, rReq.GetSlot(), FALSE); + BOOL bShow( TRUE ); + if ( !pShowItem ) + bShow = xLayoutManager->isElementVisible( aStatusbarResString ); + else + bShow = pShowItem->GetValue(); + + if ( bShow ) + { + xLayoutManager->createElement( aStatusbarResString ); + xLayoutManager->showElement( aStatusbarResString ); + } + else + xLayoutManager->hideElement( aStatusbarResString ); + + if ( !pShowItem ) + rReq.AppendItem( SfxBoolItem( SID_TOGGLESTATUSBAR, bShow ) ); + } + rReq.Done(); + break; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + case SID_WIN_FULLSCREEN: + { + SFX_REQUEST_ARG(rReq, pItem, SfxBoolItem, rReq.GetSlot(), FALSE); + SfxViewFrame *pTop = GetTopViewFrame(); + if ( pTop ) + { + WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl(); + if ( pWork ) + { + com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame( + GetFrame().GetFrameInterface(), + com::sun::star::uno::UNO_QUERY); + + Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY ); + Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager; + if ( xPropSet.is() ) + { + try + { + Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))); + aValue >>= xLayoutManager; + } + catch ( Exception& ) + { + } + } + + BOOL bNewFullScreenMode = pItem ? pItem->GetValue() : !pWork->IsFullScreenMode(); + if ( bNewFullScreenMode != pWork->IsFullScreenMode() ) + { + Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet( xLayoutManager, UNO_QUERY ); + if ( xLMPropSet.is() ) + { + try + { + xLMPropSet->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HideCurrentUI" )), + makeAny( bNewFullScreenMode )); + } + catch ( ::com::sun::star::beans::UnknownPropertyException& ) + { + } + } + pWork->ShowFullScreenMode( bNewFullScreenMode ); + pWork->SetMenuBarMode( bNewFullScreenMode ? MENUBAR_MODE_HIDE : MENUBAR_MODE_NORMAL ); + GetFrame().GetWorkWindow_Impl()->SetFullScreen_Impl( bNewFullScreenMode ); + if ( !pItem ) + rReq.AppendItem( SfxBoolItem( SID_WIN_FULLSCREEN, bNewFullScreenMode ) ); + rReq.Done(); + } + else + rReq.Ignore(); + } + } + else + rReq.Ignore(); + + GetDispatcher()->Update_Impl( TRUE ); + break; + } + } + + if ( bDone ) + rReq.Done(); +} + +void SfxViewFrame::MiscState_Impl(SfxItemSet &rSet) +{ + DBG_MEMTEST(); + + const USHORT *pRanges = rSet.GetRanges(); + DBG_ASSERT(pRanges && *pRanges, "Set ohne Bereich"); + while ( *pRanges ) + { + for(USHORT nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich) + { + switch(nWhich) + { + case SID_CURRENT_URL: + { + // Bei internem InPlace den ContainerFrame nehmen + SfxViewFrame *pFrame = this; + if ( pFrame->GetParentViewFrame_Impl() ) + pFrame = pFrame->GetParentViewFrame_Impl(); + rSet.Put( SfxStringItem( nWhich, pFrame->GetActualPresentationURL_Impl() ) ); + break; + } + + case SID_RECORDMACRO : + { + const char* pName = GetObjectShell()->GetFactory().GetShortName(); + if ( strcmp(pName,"swriter") && strcmp(pName,"scalc") ) + { + rSet.DisableItem( nWhich ); + break; + } + + ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier"); + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet( + GetFrame().GetFrameInterface(), + com::sun::star::uno::UNO_QUERY); + + com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty); + com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier; + if ( aProp >>= xSupplier ) + rSet.Put( SfxBoolItem( nWhich, xSupplier.is() ) ); + else + rSet.DisableItem( nWhich ); + break; + } + + case SID_STOP_RECORDING : + { + const char* pName = GetObjectShell()->GetFactory().GetShortName(); + if ( strcmp(pName,"swriter") && strcmp(pName,"scalc") ) + { + rSet.DisableItem( nWhich ); + break; + } + + ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier"); + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet( + GetFrame().GetFrameInterface(), + com::sun::star::uno::UNO_QUERY); + + com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty); + com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier; + if ( !(aProp >>= xSupplier) || !xSupplier.is() ) + rSet.DisableItem( nWhich ); + break; + } + + case SID_TOGGLESTATUSBAR: + { + com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager; + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet( + GetFrame().GetFrameInterface(), + com::sun::star::uno::UNO_QUERY); + com::sun::star::uno::Any aProp = xSet->getPropertyValue( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )) ); + + if ( !( aProp >>= xLayoutManager )) + rSet.Put( SfxBoolItem( nWhich, FALSE )); + else + { + rtl::OUString aStatusbarResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" )); + BOOL bShow = xLayoutManager->isElementVisible( aStatusbarResString ); + rSet.Put( SfxBoolItem( nWhich, bShow )); + } + break; + } + + case SID_WIN_FULLSCREEN: + { + SfxViewFrame* pTop = GetTopViewFrame(); + if ( pTop ) + { + WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl(); + if ( pWork ) + { + rSet.Put( SfxBoolItem( nWhich, pWork->IsFullScreenMode() ) ); + break; + } + } + + rSet.DisableItem( nWhich ); + break; + } + + case SID_FORMATMENUSTATE : + { + DBG_ERROR("Outdated slot!"); + rSet.DisableItem( nWhich ); + break; + } + + default: + //! DBG_ASSERT(FALSE, "Falscher Server fuer GetState"); + break; + } + } + + ++pRanges; + } +} + +void SfxViewFrame::ChildWindowExecute( SfxRequest &rReq ) + +/* [Beschreibung] + + Diese Methode kann in der Execute-Methode f"ur das ein- und ausschalten + von Child-Windows eingesetzt werden, um dieses inkl. API-Anbindung zu + implementieren. + + Einfach in der IDL als 'ExecuteMethod' eintragen. +*/ + +{ + // Parameter auswerten + USHORT nSID = rReq.GetSlot(); + + SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSID, FALSE); + if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER ) + { + if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE)) + return; + Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface(); + Reference < XFrame > xBeamer( xFrame->findFrame( DEFINE_CONST_UNICODE("_beamer"), FrameSearchFlag::CHILDREN ) ); + BOOL bShow = FALSE; + BOOL bHasChild = xBeamer.is(); + bShow = pShowItem ? pShowItem->GetValue() : !bHasChild; + if ( pShowItem ) + { + if( bShow == bHasChild ) + return; + } + else + rReq.AppendItem( SfxBoolItem( nSID, bShow ) ); + + if ( !bShow ) + { + SetChildWindow( SID_BROWSER, FALSE ); + } + else + { + ::com::sun::star::util::URL aTargetURL; + aTargetURL.Complete = ::rtl::OUString::createFromAscii(".component:DB/DataSourceBrowser"); + Reference < ::com::sun::star::util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY ); + xTrans->parseStrict( aTargetURL ); + + Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY ); + Reference < ::com::sun::star::frame::XDispatch > xDisp; + if ( xProv.is() ) + xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_beamer"), 31 ); + if ( xDisp.is() ) + { + Sequence < ::com::sun::star::beans::PropertyValue > aArgs(1); + ::com::sun::star::beans::PropertyValue* pArg = aArgs.getArray(); + pArg[0].Name = rtl::OUString::createFromAscii("Referer"); + pArg[0].Value <<= ::rtl::OUString::createFromAscii("private:user"); + xDisp->dispatch( aTargetURL, aArgs ); + } + } + + rReq.Done(); + return; + } + + BOOL bShow = FALSE; + BOOL bHasChild = HasChildWindow(nSID); + bShow = pShowItem ? pShowItem->GetValue() : !bHasChild; + + // ausf"uhren + if ( !pShowItem || bShow != bHasChild ) + ToggleChildWindow( nSID ); + + GetBindings().Invalidate( nSID ); + GetDispatcher()->Update_Impl( TRUE ); + + // ggf. recorden + if ( nSID == SID_HYPERLINK_DIALOG || nSID == SID_SEARCH_DLG ) + { + rReq.Ignore(); + } + else + { + rReq.AppendItem( SfxBoolItem( nSID, bShow ) ); + rReq.Done(); + } +} + +//-------------------------------------------------------------------- + +void SfxViewFrame::ChildWindowState( SfxItemSet& rState ) + +/* [Beschreibung] + + Diese Methode kann in der Status-Methode f"ur das Ein- und Ausschalt- + Zustand von Child-Windows eingesetzt werden, um dieses zu implementieren. + + Einfach in der IDL als 'StateMethod' eintragen. +*/ + +{ + SfxWhichIter aIter( rState ); + for ( USHORT nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() ) + { + if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER ) + { + rState.Put( SfxBoolItem( nSID, HasChildWindow( SID_BROWSER ) ) ); + } + else if ( nSID == SID_HYPERLINK_DIALOG ) + { + const SfxPoolItem* pDummy = NULL; + SfxItemState eState = GetDispatcher()->QueryState( SID_HYPERLINK_SETLINK, pDummy ); + if ( SFX_ITEM_DISABLED == eState ) + rState.DisableItem(nSID); + else + { + if ( KnowsChildWindow(nSID) ) + rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID)) ); + else + rState.DisableItem(nSID); + } + } + else if ( nSID == SID_BROWSER ) + { + Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface()-> + findFrame( DEFINE_CONST_UNICODE("_beamer"), FrameSearchFlag::CHILDREN ); + if ( !xFrame.is() ) + rState.DisableItem( nSID ); + else if ( KnowsChildWindow(nSID) ) + rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) ); + } + else if ( nSID == SID_TASKPANE ) + { + if ( !KnowsChildWindow( nSID ) ) + { + OSL_ENSURE( false, "SID_TASKPANE state requested, but no task pane child window exists for this ID!" ); + rState.DisableItem( nSID ); + } + else if ( !moduleHasToolPanels( *pImp ) ) + { + rState.Put( SfxVisibilityItem( nSID, sal_False ) ); + } + else + { + rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) ); + } + } + else if ( KnowsChildWindow(nSID) ) + rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) ); + else + rState.DisableItem(nSID); + } +} + +//-------------------------------------------------------------------- +SfxWorkWindow* SfxViewFrame::GetWorkWindow_Impl( USHORT /*nId*/ ) +{ + SfxWorkWindow* pWork = 0; + pWork = GetFrame().GetWorkWindow_Impl(); + return pWork; +} + +/* +void SfxViewFrame::SetChildWindow(USHORT nId, BOOL bOn) +{ + SetChildWindow( nId, bOn, TRUE ); +}*/ + +void SfxViewFrame::SetChildWindow(USHORT nId, BOOL bOn, BOOL bSetFocus ) +{ + SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); + if ( pWork ) + pWork->SetChildWindow_Impl( nId, bOn, bSetFocus ); +} + +//-------------------------------------------------------------------- + +void SfxViewFrame::ToggleChildWindow(USHORT nId) +{ + SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); + if ( pWork ) + pWork->ToggleChildWindow_Impl( nId, TRUE ); +} + +//-------------------------------------------------------------------- + +BOOL SfxViewFrame::HasChildWindow( USHORT nId ) +{ + SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); + return pWork ? pWork->HasChildWindow_Impl(nId) : FALSE; +} + +//-------------------------------------------------------------------- + +BOOL SfxViewFrame::KnowsChildWindow( USHORT nId ) +{ + SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); + return pWork ? pWork->KnowsChildWindow_Impl(nId) : FALSE; +} + +//-------------------------------------------------------------------- + +void SfxViewFrame::ShowChildWindow( USHORT nId, BOOL bVisible ) +{ + SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); + if ( pWork ) + { + GetDispatcher()->Update_Impl(sal_True); + pWork->ShowChildWindow_Impl(nId, bVisible, TRUE ); + } +} + +//-------------------------------------------------------------------- + +SfxChildWindow* SfxViewFrame::GetChildWindow(USHORT nId) +{ + SfxWorkWindow* pWork = GetWorkWindow_Impl( nId ); + return pWork ? pWork->GetChildWindow_Impl(nId) : NULL; +} + +void SfxViewFrame::UpdateDocument_Impl() +{ + SfxObjectShell* pDoc = GetObjectShell(); + if ( pDoc->IsLoadingFinished() ) + pDoc->CheckSecurityOnLoading_Impl(); + + // check if document depends on a template + pDoc->UpdateFromTemplate_Impl(); +} + +void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame ) +{ + SFX_APP()->SetViewFrame_Impl( pFrame ); +} + +// --------------------------------------------------------------------------------------------------------------------- +void SfxViewFrame::ActivateToolPanel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame, const ::rtl::OUString& i_rPanelURL ) +{ + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + // look up the SfxFrame for the given XFrame + SfxFrame* pFrame = NULL; + for ( pFrame = SfxFrame::GetFirst(); pFrame; pFrame = SfxFrame::GetNext( *pFrame ) ) + { + if ( pFrame->GetFrameInterface() == i_rFrame ) + break; + } + SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : NULL; + ENSURE_OR_RETURN_VOID( pViewFrame != NULL, "SfxViewFrame::ActivateToolPanel: did not find an SfxFrame for the given XFrame!" ); + + pViewFrame->ActivateToolPanel_Impl( i_rPanelURL ); +} + +// --------------------------------------------------------------------------------------------------------------------- +void SfxViewFrame::ActivateToolPanel_Impl( const ::rtl::OUString& i_rPanelURL ) +{ + // ensure the task pane is visible + ENSURE_OR_RETURN_VOID( KnowsChildWindow( SID_TASKPANE ), "SfxViewFrame::ActivateToolPanel: this frame/module does not allow for a task pane!" ); + if ( !HasChildWindow( SID_TASKPANE ) ) + ToggleChildWindow( SID_TASKPANE ); + + SfxChildWindow* pTaskPaneChildWindow = GetChildWindow( SID_TASKPANE ); + ENSURE_OR_RETURN_VOID( pTaskPaneChildWindow, "SfxViewFrame::ActivateToolPanel_Impl: just switched it on, but it is not there!" ); + + ::sfx2::ITaskPaneToolPanelAccess* pPanelAccess = dynamic_cast< ::sfx2::ITaskPaneToolPanelAccess* >( pTaskPaneChildWindow ); + ENSURE_OR_RETURN_VOID( pPanelAccess, "SfxViewFrame::ActivateToolPanel_Impl: task pane child window does not implement a required interface!" ); + pPanelAccess->ActivateToolPanel( i_rPanelURL ); +} |