LibreOffice Module vbahelper (master) 1
vbamultipage.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include "vbamultipage.hxx"
20#include <ooo/vba/XCollection.hpp>
21#include "vbapages.hxx"
22#include <com/sun/star/container/XNameContainer.hpp>
24
25using namespace com::sun::star;
26using namespace ooo::vba;
27
28constexpr OUStringLiteral SVALUE( u"MultiPageValue" );
29
30namespace {
31
32class PagesImpl : public cppu::WeakImplHelper< container::XIndexAccess >
33{
34 sal_Int32 mnPages;
35public:
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
39 {
40 if ( Index < 0 || Index > mnPages )
41 throw lang::IndexOutOfBoundsException();
42 return uno::Any( uno::Reference< uno::XInterface >() );
43 }
44 // XElementAccess
45 virtual uno::Type SAL_CALL getElementType() override
46 {
47 // no Pages object yet #FIXME
48 //return cppu::UnoType<msforms::XPage>::get();
50 }
51 virtual sal_Bool SAL_CALL hasElements( ) override
52 {
53 return ( mnPages > 0 );
54 }
55};
56
57}
58
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) )
66{
67}
68
69// Attributes
70sal_Int32 SAL_CALL
72{
73 sal_Int32 nValue = 0;
74 m_xProps->getPropertyValue( SVALUE ) >>= nValue;
75 // VBA 0 based tab index
76 return nValue - 1;
77}
78
79void SAL_CALL
80ScVbaMultiPage::setValue( const sal_Int32 _value )
81{
82 // Openoffice 1 based tab index
83 sal_Int32 nVal = _value + 1;
84 sal_Int32 nOldVal = getValue();
85 m_xProps->setPropertyValue( SVALUE, uno::Any( nVal ) );
86 if ( nVal != nOldVal )
87 fireChangeEvent();
88}
89
90OUString
92{
93 return "ScVbaMultiPage";
94}
95
96uno::Any SAL_CALL
98{
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::Any( xColl );
104 return xColl->Item( index, uno::Any() );
105}
106
107uno::Sequence< OUString >
109{
110 static uno::Sequence< OUString > const aServiceNames
111 {
112 "ooo.vba.msforms.MultiPage"
113 };
114 return aServiceNames;
115}
116
117/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
Reference< XPropertySet > m_xProps
virtual void SAL_CALL setValue(sal_Int32 _value) override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Any SAL_CALL Pages(const css::uno::Any &index) override
virtual sal_Int32 SAL_CALL getValue() override
virtual OUString getServiceImplName() override
ScVbaMultiPage(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::uno::XInterface > &xControl, const css::uno::Reference< css::frame::XModel > &xModel, std::unique_ptr< ov::AbstractGeometryAttributes > pGeomHelper)
css::uno::Type const & get()
uno::Reference< uno::XComponentContext > mxContext
Sequence< OUString > aServiceNames
sal_Int16 nValue
index
Reference< XModel > xModel
unsigned char sal_Bool
constexpr OUStringLiteral SVALUE(u"MultiPageValue")
cppu::ImplInheritanceHelper< ScVbaControl, ov::msforms::XMultiPage > MultiPageImpl_BASE