1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "vbamultipage.hxx"
20 #include <ooo/vba/XCollection.hpp>
21 #include "vbapages.hxx"
22 #include <com/sun/star/container/XNameContainer.hpp>
23 #include <cppuhelper/implbase.hxx>
25 using namespace com::sun::star
;
26 using namespace ooo::vba
;
28 constexpr OUStringLiteral
SVALUE( u
"MultiPageValue" );
32 class PagesImpl
: public cppu::WeakImplHelper
< container::XIndexAccess
>
36 explicit PagesImpl( sal_Int32 nPages
) : mnPages( nPages
) {}
37 virtual ::sal_Int32 SAL_CALL
getCount() override
{ return mnPages
; }
38 virtual uno::Any SAL_CALL
getByIndex( ::sal_Int32 Index
) override
40 if ( Index
< 0 || Index
> mnPages
)
41 throw lang::IndexOutOfBoundsException();
42 return uno::makeAny( uno::Reference
< uno::XInterface
>() );
45 virtual uno::Type SAL_CALL
getElementType() override
47 // no Pages object yet #FIXME
48 //return cppu::UnoType<msforms::XPage>::get();
49 return cppu::UnoType
<uno::XInterface
>::get();
51 virtual sal_Bool SAL_CALL
hasElements( ) override
53 return ( mnPages
> 0 );
59 ScVbaMultiPage::ScVbaMultiPage(
60 const uno::Reference
< ov::XHelperInterface
>& xParent
,
61 const uno::Reference
< uno::XComponentContext
>& xContext
,
62 const uno::Reference
< uno::XInterface
>& xControl
,
63 const uno::Reference
< frame::XModel
>& xModel
,
64 std::unique_ptr
<ov::AbstractGeometryAttributes
> pGeomHelper
) :
65 MultiPageImpl_BASE( xParent
, xContext
, xControl
, xModel
, std::move(pGeomHelper
) )
71 ScVbaMultiPage::getValue()
74 m_xProps
->getPropertyValue( SVALUE
) >>= nValue
;
75 // VBA 0 based tab index
80 ScVbaMultiPage::setValue( const sal_Int32 _value
)
82 // Openoffice 1 based tab index
83 sal_Int32 nVal
= _value
+ 1;
84 sal_Int32 nOldVal
= getValue();
85 m_xProps
->setPropertyValue( SVALUE
, uno::makeAny( nVal
) );
86 if ( nVal
!= nOldVal
)
91 ScVbaMultiPage::getServiceImplName()
93 return "ScVbaMultiPage";
97 ScVbaMultiPage::Pages( const uno::Any
& index
)
99 // get the container model
100 uno::Reference
< container::XNameContainer
> xContainer( m_xProps
, uno::UNO_QUERY_THROW
);
101 uno::Reference
< XCollection
> xColl( new ScVbaPages( this, mxContext
, new PagesImpl( xContainer
->getElementNames().getLength() ) ) );
102 if ( !index
.hasValue() )
103 return uno::makeAny( xColl
);
104 return xColl
->Item( index
, uno::Any() );
107 uno::Sequence
< OUString
>
108 ScVbaMultiPage::getServiceNames()
110 static uno::Sequence
< OUString
> const aServiceNames
112 "ooo.vba.msforms.MultiPage"
114 return aServiceNames
;
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */