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