1*e6ed5fbcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e6ed5fbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e6ed5fbcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e6ed5fbcSAndrew Rist * distributed with this work for additional information 6*e6ed5fbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e6ed5fbcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e6ed5fbcSAndrew Rist * "License"); you may not use this file except in compliance 9*e6ed5fbcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*e6ed5fbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*e6ed5fbcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e6ed5fbcSAndrew Rist * software distributed under the License is distributed on an 15*e6ed5fbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e6ed5fbcSAndrew Rist * KIND, either express or implied. See the License for the 17*e6ed5fbcSAndrew Rist * specific language governing permissions and limitations 18*e6ed5fbcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*e6ed5fbcSAndrew Rist *************************************************************/ 21*e6ed5fbcSAndrew Rist 22*e6ed5fbcSAndrew Rist 23cdf0e10cSrcweir #include "vbamultipage.hxx" 24cdf0e10cSrcweir #include <ooo/vba/XCollection.hpp> 25cdf0e10cSrcweir #include "vbapages.hxx" 26cdf0e10cSrcweir #include <vector> 27cdf0e10cSrcweir 28cdf0e10cSrcweir using namespace com::sun::star; 29cdf0e10cSrcweir using namespace ooo::vba; 30cdf0e10cSrcweir 31cdf0e10cSrcweir // uno servicename com.sun.star.awt.UnoControlProgressBarMode 32cdf0e10cSrcweir const rtl::OUString SVALUE( RTL_CONSTASCII_USTRINGPARAM("ProgressValue") ); 33cdf0e10cSrcweir const rtl::OUString SVALUEMAX( RTL_CONSTASCII_USTRINGPARAM("ProgressValueMax") ); 34cdf0e10cSrcweir const rtl::OUString SSTEP( RTL_CONSTASCII_USTRINGPARAM("Step") ); 35cdf0e10cSrcweir 36cdf0e10cSrcweir typedef cppu::WeakImplHelper1< container::XIndexAccess > PagesImpl_Base; 37cdf0e10cSrcweir class PagesImpl : public PagesImpl_Base 38cdf0e10cSrcweir { 39cdf0e10cSrcweir sal_Int32 mnPages; 40cdf0e10cSrcweir public: 41cdf0e10cSrcweir PagesImpl( sal_Int32 nPages ) : mnPages( nPages ) {} 42cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException) { return mnPages; } 43cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, ::uno::RuntimeException) 44cdf0e10cSrcweir { 45cdf0e10cSrcweir if ( Index < 0 || Index > mnPages ) 46cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 47cdf0e10cSrcweir return uno::makeAny( uno::Reference< uno::XInterface >() ); 48cdf0e10cSrcweir } 49cdf0e10cSrcweir // XElementAccess 50cdf0e10cSrcweir virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir // no Pages object yet #FIXME 53cdf0e10cSrcweir //return msforms::XPage::static_type(0); 54cdf0e10cSrcweir return uno::XInterface::static_type(0); 55cdf0e10cSrcweir } 56cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir return ( mnPages > 0 ); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir }; 61cdf0e10cSrcweir uno::Reference< container::XIndexAccess > 62cdf0e10cSrcweir ScVbaMultiPage::getPages( sal_Int32 nPages ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir return new PagesImpl( nPages ); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir ScVbaMultiPage::ScVbaMultiPage( 68cdf0e10cSrcweir const uno::Reference< ov::XHelperInterface >& xParent, 69cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& xContext, 70cdf0e10cSrcweir const uno::Reference< uno::XInterface >& xControl, 71cdf0e10cSrcweir const uno::Reference< frame::XModel >& xModel, 72cdf0e10cSrcweir AbstractGeometryAttributes* pGeomHelper, 73cdf0e10cSrcweir const uno::Reference< awt::XControl >& xDialog ) : 74cdf0e10cSrcweir MultiPageImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir mxDialogProps.set( xDialog->getModel(), uno::UNO_QUERY_THROW ); 77cdf0e10cSrcweir // set dialog step to value of multipage pseudo model 78cdf0e10cSrcweir setValue(getValue()); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir // Attributes 82cdf0e10cSrcweir sal_Int32 SAL_CALL 83cdf0e10cSrcweir ScVbaMultiPage::getValue() throw (css::uno::RuntimeException) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir sal_Int32 nValue = 0; 86cdf0e10cSrcweir m_xProps->getPropertyValue( SVALUE ) >>= nValue; 87cdf0e10cSrcweir return nValue; 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir void SAL_CALL 91cdf0e10cSrcweir ScVbaMultiPage::setValue( const sal_Int32 _value ) throw (::com::sun::star::uno::RuntimeException) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir // track change in dialog ( dialog value is 1 based, 0 is a special value ) 94cdf0e10cSrcweir m_xProps->setPropertyValue( SVALUE, uno::makeAny( _value ) ); 95cdf0e10cSrcweir mxDialogProps->setPropertyValue( SSTEP, uno::makeAny( _value + 1) ); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir 99cdf0e10cSrcweir rtl::OUString& 100cdf0e10cSrcweir ScVbaMultiPage::getServiceImplName() 101cdf0e10cSrcweir { 102cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMultiPage") ); 103cdf0e10cSrcweir return sImplName; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir uno::Any SAL_CALL 107cdf0e10cSrcweir ScVbaMultiPage::Pages( const uno::Any& index ) throw (uno::RuntimeException) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir sal_Int32 nValue = 0; 110cdf0e10cSrcweir m_xProps->getPropertyValue( SVALUEMAX ) >>= nValue; 111cdf0e10cSrcweir uno::Reference< XCollection > xColl( new ScVbaPages( this, mxContext, getPages( nValue ) ) ); 112cdf0e10cSrcweir if ( !index.hasValue() ) 113cdf0e10cSrcweir return uno::makeAny( xColl ); 114cdf0e10cSrcweir return xColl->Item( uno::makeAny( index ), uno::Any() ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir uno::Sequence< rtl::OUString > 118cdf0e10cSrcweir ScVbaMultiPage::getServiceNames() 119cdf0e10cSrcweir { 120cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 121cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir aServiceNames.realloc( 1 ); 124cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.MultiPage" ) ); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir return aServiceNames; 127cdf0e10cSrcweir } 128