implement Application.FileDialog attribute
Documentation: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-filedialog-property-excel https://msdn.microsoft.com/VBA/Office-Shared-VBA/articles/filedialog-object-office Using FilePicker and FolderPicker uno services. Change-Id: Ifd3b3fc9c135efb0663d2ef36ecbe2b2fbe6132f Reviewed-on: https://gerrit.libreoffice.org/39806 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tamás Bunth <btomi96@gmail.com>
This commit is contained in:
parent
d6a16aedca
commit
07fb14be7f
@ -233,6 +233,8 @@ $(eval $(call gb_UnoApi_add_idlfiles,oovbaapi,ooo/vba/excel,\
|
|||||||
XDialog \
|
XDialog \
|
||||||
XDialogs \
|
XDialogs \
|
||||||
XDrawings \
|
XDrawings \
|
||||||
|
XFileDialog \
|
||||||
|
XFileDialogSelectedItems \
|
||||||
XFont \
|
XFont \
|
||||||
XFormat \
|
XFormat \
|
||||||
XFormatCondition \
|
XFormatCondition \
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <com/sun/star/script/XInvocation.idl>
|
#include <com/sun/star/script/XInvocation.idl>
|
||||||
#include <ooo/vba/XHelperInterface.idl>
|
#include <ooo/vba/XHelperInterface.idl>
|
||||||
#include <ooo/vba/XAssistant.idl>
|
#include <ooo/vba/XAssistant.idl>
|
||||||
|
#include <ooo/vba/XFileDialog.idl>
|
||||||
|
|
||||||
module ooo { module vba { module excel {
|
module ooo { module vba { module excel {
|
||||||
|
|
||||||
@ -83,6 +84,7 @@ interface XApplication
|
|||||||
any Range( [in] any Cell1, [in] any Cell2 );
|
any Range( [in] any Cell1, [in] any Cell2 );
|
||||||
any Names( [in] any Index );
|
any Names( [in] any Index );
|
||||||
void GoTo( [in] any Reference, [in] any Scroll );
|
void GoTo( [in] any Reference, [in] any Scroll );
|
||||||
|
any FileDialog( [in] any DialogType );
|
||||||
|
|
||||||
void wait( [in] double time );
|
void wait( [in] double time );
|
||||||
void Calculate() raises(com::sun::star::script::BasicErrorException);
|
void Calculate() raises(com::sun::star::script::BasicErrorException);
|
||||||
|
49
oovbaapi/ooo/vba/excel/XFileDialog.idl
Normal file
49
oovbaapi/ooo/vba/excel/XFileDialog.idl
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This file is part of the LibreOffice project.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* This file incorporates work covered by the following license notice:
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed
|
||||||
|
* with this work for additional information regarding copyright
|
||||||
|
* ownership. The ASF licenses this file to you under the Apache
|
||||||
|
* License, Version 2.0 (the "License"); you may not use this file
|
||||||
|
* except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||||
|
*/
|
||||||
|
#ifndef __ooo_vba_excel_XFileDialog_idl__
|
||||||
|
#define __ooo_vba_excel_XFileDialog_idl__
|
||||||
|
|
||||||
|
#include <com/sun/star/uno/XInterface.idl>
|
||||||
|
|
||||||
|
#include <ooo/vba/XFileDialogSelectedItems.idl>
|
||||||
|
|
||||||
|
|
||||||
|
module ooo { module vba { module excel {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
interface XFileDialog
|
||||||
|
{
|
||||||
|
interface ::ooo::vba::XHelperInterface;
|
||||||
|
|
||||||
|
[attribute] any InitialFileName;
|
||||||
|
[attribute] any Title;
|
||||||
|
[attribute, readonly] XFileDialogSelectedItems SelectedItems;
|
||||||
|
|
||||||
|
long Show();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}; }; };
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
42
oovbaapi/ooo/vba/excel/XFileDialogSelectedItems.idl
Normal file
42
oovbaapi/ooo/vba/excel/XFileDialogSelectedItems.idl
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This file is part of the LibreOffice project.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* This file incorporates work covered by the following license notice:
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed
|
||||||
|
* with this work for additional information regarding copyright
|
||||||
|
* ownership. The ASF licenses this file to you under the Apache
|
||||||
|
* License, Version 2.0 (the "License"); you may not use this file
|
||||||
|
* except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||||
|
*/
|
||||||
|
#ifndef __ooo_vba_excel_XFileDialogSelectedItems_idl__
|
||||||
|
#define __ooo_vba_excel_XFileDialogSelectedItems_idl__
|
||||||
|
|
||||||
|
#include <com/sun/star/uno/XInterface.idl>
|
||||||
|
#include <ooo/vba/XCollection.idl>
|
||||||
|
|
||||||
|
|
||||||
|
module ooo { module vba { module excel {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
interface XFileDialogSelectedItems
|
||||||
|
{
|
||||||
|
interface XCollection;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}; }; };
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
@ -74,6 +74,8 @@ $(eval $(call gb_Library_add_exception_objects,vbaobj,\
|
|||||||
sc/source/ui/vba/vbadialog \
|
sc/source/ui/vba/vbadialog \
|
||||||
sc/source/ui/vba/vbadialogs \
|
sc/source/ui/vba/vbadialogs \
|
||||||
sc/source/ui/vba/vbaeventshelper \
|
sc/source/ui/vba/vbaeventshelper \
|
||||||
|
sc/source/ui/vba/vbafiledialog \
|
||||||
|
sc/source/ui/vba/vbafiledialogitems \
|
||||||
sc/source/ui/vba/vbafont \
|
sc/source/ui/vba/vbafont \
|
||||||
sc/source/ui/vba/vbaformat \
|
sc/source/ui/vba/vbaformat \
|
||||||
sc/source/ui/vba/vbaformatcondition \
|
sc/source/ui/vba/vbaformatcondition \
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
#include "sc.hrc"
|
#include "sc.hrc"
|
||||||
#include "macromgr.hxx"
|
#include "macromgr.hxx"
|
||||||
#include "defaultsoptions.hxx"
|
#include "defaultsoptions.hxx"
|
||||||
|
#include "vbafiledialog.hxx"
|
||||||
|
|
||||||
#include <osl/file.hxx>
|
#include <osl/file.hxx>
|
||||||
#include <rtl/instance.hxx>
|
#include <rtl/instance.hxx>
|
||||||
@ -126,7 +127,8 @@ struct ScVbaStaticAppSettings : public ::rtl::Static< ScVbaAppSettings, ScVbaSta
|
|||||||
|
|
||||||
ScVbaApplication::ScVbaApplication( const uno::Reference<uno::XComponentContext >& xContext ) :
|
ScVbaApplication::ScVbaApplication( const uno::Reference<uno::XComponentContext >& xContext ) :
|
||||||
ScVbaApplication_BASE( xContext ),
|
ScVbaApplication_BASE( xContext ),
|
||||||
mrAppSettings( ScVbaStaticAppSettings::get() )
|
mrAppSettings( ScVbaStaticAppSettings::get() ),
|
||||||
|
m_nDialogType(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,6 +314,18 @@ ScVbaApplication::International( sal_Int32 /*Index*/ )
|
|||||||
return aRet;
|
return aRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uno::Any SAL_CALL
|
||||||
|
ScVbaApplication::FileDialog( const uno::Any& DialogType )
|
||||||
|
{
|
||||||
|
sal_Int32 nType = 0;
|
||||||
|
DialogType >>= nType;
|
||||||
|
|
||||||
|
m_nDialogType = nType;
|
||||||
|
if( !m_xFileDialog || nType != m_nDialogType )
|
||||||
|
m_xFileDialog = uno::Reference<excel::XFileDialog> ( new ScVbaFileDialog( this, mxContext, nType ));
|
||||||
|
return uno::Any( m_xFileDialog );
|
||||||
|
}
|
||||||
|
|
||||||
uno::Any SAL_CALL
|
uno::Any SAL_CALL
|
||||||
ScVbaApplication::Workbooks( const uno::Any& aIndex )
|
ScVbaApplication::Workbooks( const uno::Any& aIndex )
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <ooo/vba/excel/XWorksheetFunction.hpp>
|
#include <ooo/vba/excel/XWorksheetFunction.hpp>
|
||||||
#include <ooo/vba/excel/XApplication.hpp>
|
#include <ooo/vba/excel/XApplication.hpp>
|
||||||
|
#include <ooo/vba/excel/XFileDialog.hpp>
|
||||||
#include <com/sun/star/uno/XComponentContext.hpp>
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
||||||
|
|
||||||
#include <vbahelper/vbahelperinterface.hxx>
|
#include <vbahelper/vbahelperinterface.hxx>
|
||||||
@ -37,6 +38,10 @@ private:
|
|||||||
// note: member variables moved to struct "ScVbaAppSettings", see cxx file, to be shared by all application instances
|
// note: member variables moved to struct "ScVbaAppSettings", see cxx file, to be shared by all application instances
|
||||||
ScVbaAppSettings& mrAppSettings;
|
ScVbaAppSettings& mrAppSettings;
|
||||||
|
|
||||||
|
// must be stored in order to get result paths from the same instance
|
||||||
|
css::uno::Reference< ov::excel::XFileDialog > m_xFileDialog;
|
||||||
|
sal_Int32 m_nDialogType;
|
||||||
|
|
||||||
/// @throws css::uno::RuntimeException
|
/// @throws css::uno::RuntimeException
|
||||||
OUString getOfficePath( const OUString& sPath );
|
OUString getOfficePath( const OUString& sPath );
|
||||||
|
|
||||||
@ -85,6 +90,7 @@ public:
|
|||||||
virtual css::uno::Reference< ov::XAssistant > SAL_CALL getAssistant() override;
|
virtual css::uno::Reference< ov::XAssistant > SAL_CALL getAssistant() override;
|
||||||
virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL getThisWorkbook() override;
|
virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL getThisWorkbook() override;
|
||||||
virtual css::uno::Any SAL_CALL International( sal_Int32 Index ) override;
|
virtual css::uno::Any SAL_CALL International( sal_Int32 Index ) override;
|
||||||
|
virtual css::uno::Any SAL_CALL FileDialog( const css::uno::Any& DialogType ) override;
|
||||||
virtual css::uno::Any SAL_CALL Workbooks( const css::uno::Any& aIndex ) override;
|
virtual css::uno::Any SAL_CALL Workbooks( const css::uno::Any& aIndex ) override;
|
||||||
virtual css::uno::Any SAL_CALL Worksheets( const css::uno::Any& aIndex ) override;
|
virtual css::uno::Any SAL_CALL Worksheets( const css::uno::Any& aIndex ) override;
|
||||||
virtual css::uno::Any SAL_CALL WorksheetFunction( ) override;
|
virtual css::uno::Any SAL_CALL WorksheetFunction( ) override;
|
||||||
|
141
sc/source/ui/vba/vbafiledialog.cxx
Normal file
141
sc/source/ui/vba/vbafiledialog.cxx
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This file is part of the LibreOffice project.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* This file incorporates work covered by the following license notice:
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed
|
||||||
|
* with this work for additional information regarding copyright
|
||||||
|
* ownership. The ASF licenses this file to you under the Apache
|
||||||
|
* License, Version 2.0 (the "License"); you may not use this file
|
||||||
|
* except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "vbafiledialog.hxx"
|
||||||
|
|
||||||
|
#include <ooo/vba/office/MsoFileDialogType.hpp>
|
||||||
|
|
||||||
|
#include <com/sun/star/container/XIndexAccess.hpp>
|
||||||
|
#include <com/sun/star/ui/dialogs/FilePicker.hpp>
|
||||||
|
#include <com/sun/star/ui/dialogs/FolderPicker.hpp>
|
||||||
|
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
|
||||||
|
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
|
||||||
|
|
||||||
|
using namespace ::com::sun::star;
|
||||||
|
using namespace ::ooo::vba;
|
||||||
|
|
||||||
|
ScVbaFileDialog::ScVbaFileDialog( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const sal_Int32 nType )
|
||||||
|
: ScVbaFileDialog_BASE( xParent, xContext)
|
||||||
|
, m_nType(nType)
|
||||||
|
, m_sTitle("FileDialog")
|
||||||
|
{}
|
||||||
|
|
||||||
|
uno::Any
|
||||||
|
ScVbaFileDialog::getInitialFileName() { return uno::makeAny( m_sInitialFileName ); }
|
||||||
|
|
||||||
|
void ScVbaFileDialog::setInitialFileName( const css::uno::Any& rName )
|
||||||
|
{
|
||||||
|
rName >>= m_sInitialFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
css::uno::Any ScVbaFileDialog::getTitle() { return uno::makeAny( m_sTitle ); }
|
||||||
|
|
||||||
|
void ScVbaFileDialog::setTitle( const css::uno::Any& rTitle )
|
||||||
|
{
|
||||||
|
rTitle >>= m_sTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
uno::Reference< excel::XFileDialogSelectedItems > SAL_CALL ScVbaFileDialog::getSelectedItems()
|
||||||
|
{
|
||||||
|
// TODO use InitialFileName when m_xItems is empty
|
||||||
|
return m_xItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
sal_Int32 ScVbaFileDialog::Show()
|
||||||
|
{
|
||||||
|
std::vector<OUString> sSelectedPaths;
|
||||||
|
sal_Int32 nRet = -1;
|
||||||
|
|
||||||
|
switch (m_nType)
|
||||||
|
{
|
||||||
|
case office::MsoFileDialogType::msoFileDialogOpen:
|
||||||
|
// TODO implement
|
||||||
|
break;
|
||||||
|
case office::MsoFileDialogType::msoFileDialogSaveAs:
|
||||||
|
// TODO implement
|
||||||
|
break;
|
||||||
|
case office::MsoFileDialogType::msoFileDialogFilePicker:
|
||||||
|
{
|
||||||
|
uno::Reference<ui::dialogs::XFilePicker3> xFilePicker =
|
||||||
|
ui::dialogs::FilePicker::createWithMode(
|
||||||
|
mxContext, ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE );
|
||||||
|
|
||||||
|
// TODO set initial directory
|
||||||
|
|
||||||
|
if( xFilePicker->execute() != ui::dialogs::ExecutableDialogResults::OK)
|
||||||
|
{
|
||||||
|
nRet = 0; // cancel pressed
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for( auto& sPath : xFilePicker->getSelectedFiles() )
|
||||||
|
{
|
||||||
|
sSelectedPaths.push_back(sPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case office::MsoFileDialogType::msoFileDialogFolderPicker:
|
||||||
|
{
|
||||||
|
uno::Reference< ui::dialogs::XFolderPicker2 > xFolderPicker =
|
||||||
|
ui::dialogs::FolderPicker::create(mxContext);
|
||||||
|
|
||||||
|
// TODO set initial directory
|
||||||
|
|
||||||
|
if( xFolderPicker->execute() != ui::dialogs::ExecutableDialogResults::OK)
|
||||||
|
{
|
||||||
|
nRet = 0; // cancel pressed
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
OUString sPath = xFolderPicker->getDirectory();
|
||||||
|
|
||||||
|
if(!sPath.isEmpty())
|
||||||
|
sSelectedPaths.push_back(sPath);
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw uno::RuntimeException();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_xItems = css::uno::Reference< ov::excel::XFileDialogSelectedItems >(
|
||||||
|
new ScVbaFileDialogSelectedItems(this, mxContext, sSelectedPaths) );
|
||||||
|
return nRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
// XHelperInterface
|
||||||
|
OUString
|
||||||
|
ScVbaFileDialog::getServiceImplName()
|
||||||
|
{
|
||||||
|
return OUString("ScVbaFileDialog");
|
||||||
|
}
|
||||||
|
|
||||||
|
uno::Sequence<OUString>
|
||||||
|
ScVbaFileDialog::getServiceNames()
|
||||||
|
{
|
||||||
|
static uno::Sequence< OUString > aServiceNames;
|
||||||
|
if ( aServiceNames.getLength() == 0 )
|
||||||
|
{
|
||||||
|
aServiceNames.realloc( 1 );
|
||||||
|
aServiceNames[ 0 ] = "ooo.vba.FileDialog";
|
||||||
|
}
|
||||||
|
return aServiceNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
56
sc/source/ui/vba/vbafiledialog.hxx
Normal file
56
sc/source/ui/vba/vbafiledialog.hxx
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This file is part of the LibreOffice project.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* This file incorporates work covered by the following license notice:
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed
|
||||||
|
* with this work for additional information regarding copyright
|
||||||
|
* ownership. The ASF licenses this file to you under the Apache
|
||||||
|
* License, Version 2.0 (the "License"); you may not use this file
|
||||||
|
* except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||||
|
*/
|
||||||
|
#ifndef INCLUDED_SC_SOURCE_UI_VBA_VBAFILEDIALOG_HXX
|
||||||
|
#define INCLUDED_SC_SOURCE_UI_VBA_VBAFILEDIALOG_HXX
|
||||||
|
|
||||||
|
#include <ooo/vba/excel/XFileDialog.hpp>
|
||||||
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
||||||
|
#include <vbahelper/vbahelperinterface.hxx>
|
||||||
|
|
||||||
|
#include "vbafiledialogitems.hxx"
|
||||||
|
|
||||||
|
typedef InheritedHelperInterfaceWeakImpl< ov::excel::XFileDialog > ScVbaFileDialog_BASE;
|
||||||
|
|
||||||
|
class ScVbaFileDialog : public ScVbaFileDialog_BASE
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
sal_Int32 m_nType;
|
||||||
|
OUString m_sTitle;
|
||||||
|
OUString m_sInitialFileName;
|
||||||
|
css::uno::Reference< ov::excel::XFileDialogSelectedItems> m_xItems;
|
||||||
|
public:
|
||||||
|
ScVbaFileDialog( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const sal_Int32 nType);
|
||||||
|
|
||||||
|
virtual css::uno::Any SAL_CALL getInitialFileName() override;
|
||||||
|
virtual void SAL_CALL setInitialFileName( const css::uno::Any& rName ) override;
|
||||||
|
virtual css::uno::Any SAL_CALL getTitle() override;
|
||||||
|
virtual void SAL_CALL setTitle( const css::uno::Any& rTitle ) override;
|
||||||
|
virtual css::uno::Reference< ov::excel::XFileDialogSelectedItems > SAL_CALL getSelectedItems() override;
|
||||||
|
|
||||||
|
virtual sal_Int32 SAL_CALL Show() override;
|
||||||
|
|
||||||
|
//XHelperInterface
|
||||||
|
virtual OUString getServiceImplName() override;
|
||||||
|
virtual css::uno::Sequence<OUString> getServiceNames() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
119
sc/source/ui/vba/vbafiledialogitems.cxx
Normal file
119
sc/source/ui/vba/vbafiledialogitems.cxx
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This file is part of the LibreOffice project.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* This file incorporates work covered by the following license notice:
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed
|
||||||
|
* with this work for additional information regarding copyright
|
||||||
|
* ownership. The ASF licenses this file to you under the Apache
|
||||||
|
* License, Version 2.0 (the "License"); you may not use this file
|
||||||
|
* except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||||
|
*/
|
||||||
|
#include "vbafiledialogitems.hxx"
|
||||||
|
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
|
||||||
|
#include <com/sun/star/container/XIndexContainer.hpp>
|
||||||
|
|
||||||
|
using namespace ::com::sun::star;
|
||||||
|
using namespace ::ooo::vba;
|
||||||
|
|
||||||
|
typedef std::vector< OUString > StringVector;
|
||||||
|
|
||||||
|
class FileDialogItemEnumeration : public ::cppu::WeakImplHelper< container::XEnumeration >
|
||||||
|
{
|
||||||
|
StringVector m_sItems;
|
||||||
|
StringVector::iterator mIt;
|
||||||
|
public:
|
||||||
|
explicit FileDialogItemEnumeration( const StringVector& rVector ) : m_sItems( rVector ), mIt( m_sItems.begin() ) {}
|
||||||
|
virtual sal_Bool SAL_CALL hasMoreElements() override
|
||||||
|
{
|
||||||
|
return ( mIt != m_sItems.end() );
|
||||||
|
}
|
||||||
|
virtual uno::Any SAL_CALL nextElement() override
|
||||||
|
{
|
||||||
|
if( !hasMoreElements() )
|
||||||
|
throw container::NoSuchElementException();
|
||||||
|
OUString sPath = *mIt++;
|
||||||
|
return uno::makeAny( sPath );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ScVbaFileDialogSelectedItems::ScVbaFileDialogSelectedItems(
|
||||||
|
const css::uno::Reference< ov::XHelperInterface >& xParent
|
||||||
|
,const css::uno::Reference< css::uno::XComponentContext >& xContext
|
||||||
|
,const StringVector& rItems)
|
||||||
|
: FileDialogSelectedItems_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() )
|
||||||
|
, m_sItems(rItems) {}
|
||||||
|
|
||||||
|
|
||||||
|
// XEnumerationAccess
|
||||||
|
uno::Type SAL_CALL
|
||||||
|
ScVbaFileDialogSelectedItems::getElementType()
|
||||||
|
{
|
||||||
|
return cppu::UnoType<OUString>::get();
|
||||||
|
}
|
||||||
|
|
||||||
|
uno::Reference< container::XEnumeration >
|
||||||
|
ScVbaFileDialogSelectedItems::createEnumeration()
|
||||||
|
{
|
||||||
|
return uno::Reference< container::XEnumeration >( new FileDialogItemEnumeration( m_sItems ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
uno::Any
|
||||||
|
ScVbaFileDialogSelectedItems::createCollectionObject( const uno::Any& aSource )
|
||||||
|
{
|
||||||
|
sal_Int32 nPosition = -1;
|
||||||
|
aSource >>= nPosition;
|
||||||
|
|
||||||
|
OUString sPath = m_sItems[nPosition];
|
||||||
|
return uno::makeAny( sPath );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
uno::Any SAL_CALL
|
||||||
|
ScVbaFileDialogSelectedItems::Item( const uno::Any& aIndex, const uno::Any& /*aIndex*/ )
|
||||||
|
{
|
||||||
|
sal_Int32 nPosition = -1;
|
||||||
|
aIndex >>= nPosition;
|
||||||
|
|
||||||
|
--nPosition; // vba indexing starts with 1
|
||||||
|
|
||||||
|
if( nPosition < 0 || nPosition >= getCount() )
|
||||||
|
{
|
||||||
|
throw uno::RuntimeException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return createCollectionObject( uno::makeAny( nPosition ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
sal_Int32 ScVbaFileDialogSelectedItems::getCount()
|
||||||
|
{
|
||||||
|
return m_sItems.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
// XHelperInterface
|
||||||
|
OUString
|
||||||
|
ScVbaFileDialogSelectedItems::getServiceImplName()
|
||||||
|
{
|
||||||
|
return OUString("ScVbaFileDialogSelectedItems");
|
||||||
|
}
|
||||||
|
|
||||||
|
uno::Sequence<OUString>
|
||||||
|
ScVbaFileDialogSelectedItems::getServiceNames()
|
||||||
|
{
|
||||||
|
static uno::Sequence< OUString > aServiceNames;
|
||||||
|
if ( aServiceNames.getLength() == 0 )
|
||||||
|
{
|
||||||
|
aServiceNames.realloc( 1 );
|
||||||
|
aServiceNames[ 0 ] = "ooo.vba.FileDialogSelectedItems";
|
||||||
|
}
|
||||||
|
return aServiceNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
42
sc/source/ui/vba/vbafiledialogitems.hxx
Normal file
42
sc/source/ui/vba/vbafiledialogitems.hxx
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This file is part of the LibreOffice project.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
#ifndef INCLUDED_SC_SOURCE_UI_VBA_VBAFILEDIALOGSELECTEDITEMS
|
||||||
|
#define INCLUDED_SC_SOURCE_UI_VBA_VBAFILEDIALOGSELECTEDITEMS
|
||||||
|
|
||||||
|
#include <ooo/vba//excel/XFileDialogSelectedItems.hpp>
|
||||||
|
#include <vbahelper/vbahelperinterface.hxx>
|
||||||
|
#include <vbahelper/vbacollectionimpl.hxx>
|
||||||
|
#include <com/sun/star/container/XIndexAccess.hpp>
|
||||||
|
|
||||||
|
typedef CollTestImplHelper< ov::excel::XFileDialogSelectedItems > FileDialogSelectedItems_BASE;
|
||||||
|
|
||||||
|
class ScVbaFileDialogSelectedItems : public FileDialogSelectedItems_BASE
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
const std::vector<OUString> m_sItems;
|
||||||
|
public:
|
||||||
|
ScVbaFileDialogSelectedItems( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const std::vector<OUString>& sItems);
|
||||||
|
|
||||||
|
// XEnumerationAccess
|
||||||
|
virtual css::uno::Type SAL_CALL getElementType() override;
|
||||||
|
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override;
|
||||||
|
virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ) override;
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index, const css::uno::Any& /*Index2*/ ) override;
|
||||||
|
virtual sal_Int32 SAL_CALL getCount() override;
|
||||||
|
|
||||||
|
// XHelperInterface
|
||||||
|
virtual OUString getServiceImplName() override;
|
||||||
|
virtual css::uno::Sequence<OUString> getServiceNames() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // INCLUDED_SC_SOURCE_UI_VBA_VBAFILEDIALOGSELECTEDITEMS
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
Loading…
x
Reference in New Issue
Block a user