diff options
author | Noel Power <noel.power@suse.com> | 2013-04-17 17:08:59 +0100 |
---|---|---|
committer | Noel Power <noel.power@suse.com> | 2013-04-17 17:10:31 +0100 |
commit | a43cc9ec8dde4f311bcf8ff96e6a26d56b2abdcf (patch) | |
tree | d33f375d48027afd6e910154a7e8bf0162b9f8ee /oox/source/ole | |
parent | 2bbdf5c72254a70c43894eb907f23f78557f709a (diff) |
implement MultiPage, Page & TabStrip import for oox
Change-Id: I1912c9550c12a971fcc7fdbc8bd623f18ccc40b8
Diffstat (limited to 'oox/source/ole')
-rw-r--r-- | oox/source/ole/axbinaryreader.cxx | 11 | ||||
-rw-r--r-- | oox/source/ole/axcontrol.cxx | 115 | ||||
-rw-r--r-- | oox/source/ole/vbacontrol.cxx | 63 |
3 files changed, 184 insertions, 5 deletions
diff --git a/oox/source/ole/axbinaryreader.cxx b/oox/source/ole/axbinaryreader.cxx index 1e4c626d1224..b78f428794fd 100644 --- a/oox/source/ole/axbinaryreader.cxx +++ b/oox/source/ole/axbinaryreader.cxx @@ -144,7 +144,7 @@ bool AxBinaryPropertyReader::StringProperty::readProperty( AxAlignedInputStream& return lclReadString( rInStrm, mrValue, mnSize, false ); } -bool AxBinaryPropertyReader::StringArrayProperty::readProperty( AxAlignedInputStream& rInStrm ) +bool AxBinaryPropertyReader::ArrayStringProperty::readProperty( AxAlignedInputStream& rInStrm ) { sal_Int64 nEndPos = rInStrm.tell() + mnSize; while( rInStrm.tell() < nEndPos ) @@ -214,6 +214,15 @@ void AxBinaryPropertyReader::readStringProperty( OUString& orValue ) } } +void AxBinaryPropertyReader::readArrayStringProperty( std::vector<OUString>& orValue ) +{ + if( startNextProperty() ) + { + sal_uInt32 nSize = maInStrm.readAligned< sal_uInt32 >(); + maLargeProps.push_back( ComplexPropVector::value_type( new ArrayStringProperty( orValue, nSize ) ) ); + } +} + void AxBinaryPropertyReader::readGuidProperty( OUString& orGuid ) { if( startNextProperty() ) diff --git a/oox/source/ole/axcontrol.cxx b/oox/source/ole/axcontrol.cxx index bbb8a5f249a7..38b959e7c9f5 100644 --- a/oox/source/ole/axcontrol.cxx +++ b/oox/source/ole/axcontrol.cxx @@ -1351,6 +1351,53 @@ void AxImageModel::convertProperties( PropertyMap& rPropMap, const ControlConver // ============================================================================ +AxTabStripModel::AxTabStripModel() : + mnListIndex( 0 ), + mnTabStyle( 0 ), + mnTabData( 0 ), + mnVariousPropertyBits( 0 ) +{ +} + +bool AxTabStripModel::importBinaryModel( BinaryInputStream& rInStrm ) +{ + // not worth reading much here, basically we are interested + // in whether we have tabs, the width, the height and the + // captions, everything else we can pretty much discard ( for now ) + AxBinaryPropertyReader aReader( rInStrm ); + aReader.readIntProperty< sal_uInt32 >( mnListIndex ); // ListIndex + aReader.skipIntProperty< sal_uInt32 >(); // Backcolor + aReader.skipIntProperty< sal_uInt32 >(); // ForeColor + aReader.skipUndefinedProperty(); + aReader.readPairProperty( maSize ); + aReader.readArrayStringProperty( maItems ); + aReader.skipIntProperty< sal_uInt8 >(); // MousePointer + aReader.skipUndefinedProperty(); + aReader.skipIntProperty< sal_uInt32 >(); // TabOrientation + aReader.readIntProperty< sal_uInt32 >(mnTabStyle); // TabStyle + aReader.skipBoolProperty(); // MultiRow + aReader.skipIntProperty< sal_uInt32 >(); // TabFixedWidth + aReader.skipIntProperty< sal_uInt32 >(); // TabFixedHeight + aReader.skipBoolProperty(); // ToolTips + aReader.skipUndefinedProperty(); + aReader.skipArrayStringProperty(); // ToolTip strings + aReader.skipUndefinedProperty(); + aReader.readArrayStringProperty( maTabNames ); // Tab names + aReader.readIntProperty< sal_uInt32 >(mnVariousPropertyBits); // VariousPropertyBits + aReader.skipBoolProperty();// NewVersion + aReader.skipIntProperty< sal_uInt32 >(); // TabsAllocated + aReader.skipArrayStringProperty(); // Tags + aReader.readIntProperty<sal_uInt32 >(mnTabData); // TabData + aReader.skipArrayStringProperty(); // Accelerators + aReader.skipPictureProperty(); // Mouse Icon + return aReader.finalizeImport() && AxFontDataModel::importBinaryModel( rInStrm ); +} + +ApiControlType AxTabStripModel::getControlType() const +{ + return API_CONTROL_TABSTRIP; +} + AxMorphDataModelBase::AxMorphDataModelBase() : mnTextColor( AX_SYSCOLOR_WINDOWTEXT ), mnBackColor( AX_SYSCOLOR_WINDOWBACK ), @@ -2385,6 +2432,74 @@ void AxFrameModel::convertProperties( PropertyMap& rPropMap, const ControlConver AxContainerModelBase::convertProperties( rPropMap, rConv ); } +AxPageModel::AxPageModel() +{ +} + +ApiControlType AxPageModel::getControlType() const +{ + return API_CONTROL_PAGE; +} + +void AxPageModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const +{ + rPropMap.setProperty( PROP_Title, maCaption ); + rConv.convertColor( rPropMap, PROP_BackgroundColor, mnBackColor ); + rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_CONTAINER_ENABLED ) ); + AxContainerModelBase::convertProperties( rPropMap, rConv ); +} + +AxMultiPageModel::AxMultiPageModel() : + mnActiveTab( 0 ), + mnTabStyle( AX_TABSTRIP_TABS ) +{ +} + +ApiControlType AxMultiPageModel::getControlType() const +{ + return API_CONTROL_MULTIPAGE; +} + + +bool AxMultiPageModel::importPageAndMultiPageProperties( BinaryInputStream& rInStrm, sal_Int32 nPages ) +{ + // PageProperties + for ( sal_Int32 nPage = 0; nPage < nPages; ++nPage ) + { + AxBinaryPropertyReader aReader( rInStrm ); + aReader.skipUndefinedProperty(); + aReader.skipIntProperty< sal_uInt32 >(); // TransistionEffect + aReader.skipIntProperty< sal_uInt32 >(); // TransitionPeriod + } + // MultiPageProperties + AxBinaryPropertyReader aReader( rInStrm ); + sal_uInt32 nPageCount = 0; + aReader.skipUndefinedProperty(); + aReader.readIntProperty< sal_uInt32 >(nPageCount); // PageCount + aReader.skipIntProperty< sal_uInt32 >(); //ID + + // IDs + for ( sal_uInt32 count = 0; count < nPageCount; ++count ) + { + sal_Int32 nID = 0; + rInStrm >> nID; + mnIDs.push_back( nID ); + } + return true; +} + +void AxMultiPageModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const +{ + rPropMap.setProperty( PROP_Title, maCaption ); + rPropMap.setProperty( PROP_MultiPageValue, mnActiveTab + 1); + rConv.convertColor( rPropMap, PROP_BackgroundColor, mnBackColor ); + rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_CONTAINER_ENABLED ) ); + rPropMap.setProperty( PROP_Decoration, mnTabStyle != AX_TABSTRIP_NONE ); + + AxContainerModelBase::convertProperties( rPropMap, rConv ); +} + + // ============================================================================ AxUserFormModel::AxUserFormModel() diff --git a/oox/source/ole/vbacontrol.cxx b/oox/source/ole/vbacontrol.cxx index ad6eaf5b438a..073f64e676a5 100644 --- a/oox/source/ole/vbacontrol.cxx +++ b/oox/source/ole/vbacontrol.cxx @@ -36,6 +36,7 @@ #include "oox/helper/storagebase.hxx" #include "oox/helper/textinputstream.hxx" #include "oox/ole/vbahelper.hxx" +#include <boost/unordered_map.hpp> namespace oox { namespace ole { @@ -259,10 +260,13 @@ ControlModelRef VbaSiteModel::createControlModel( const AxClassTable& rClassTabl case VBA_SITE_COMBOBOX: xCtrlModel.reset( new AxComboBoxModel ); break; case VBA_SITE_SPINBUTTON: xCtrlModel.reset( new AxSpinButtonModel ); break; case VBA_SITE_SCROLLBAR: xCtrlModel.reset( new AxScrollBarModel ); break; - case VBA_SITE_TABSTRIP: break; + case VBA_SITE_TABSTRIP: xCtrlModel.reset( new AxTabStripModel ); + break; case VBA_SITE_FRAME: xCtrlModel.reset( new AxFrameModel ); break; - case VBA_SITE_MULTIPAGE: break; - case VBA_SITE_FORM: break; + case VBA_SITE_MULTIPAGE: xCtrlModel.reset( new AxMultiPageModel ); + break; + case VBA_SITE_FORM: xCtrlModel.reset( new AxPageModel ); + break; default: OSL_FAIL( "VbaSiteModel::createControlModel - unknown type index" ); } } @@ -405,7 +409,6 @@ void VbaFormControl::importStorage( StorageBase& rStrg, const AxClassTable& rCla maControls vector). Ignore failure of importSiteModels() but try to import as much controls as possible. */ importEmbeddedSiteModels( aFStrm ); - /* Open the 'o' stream containing models of embedded simple controls. Stream may be empty or missing, if this control contains no controls or only container controls. */ @@ -417,6 +420,58 @@ void VbaFormControl::importStorage( StorageBase& rStrg, const AxClassTable& rCla maControls.forEachMem( &VbaFormControl::importModelOrStorage, ::boost::ref( aOStrm ), ::boost::ref( rStrg ), ::boost::cref( maClassTable ) ); + // Special handling for multi-page which has non-standard + // containment and additionally needs to re-order Page children + if ( pContainerModel->getControlType() == API_CONTROL_MULTIPAGE ) + { + AxMultiPageModel* pMultiPage = dynamic_cast< AxMultiPageModel* >( pContainerModel ); + if ( pMultiPage ) + { + BinaryXInputStream aXStrm( rStrg.openInputStream( "x" ), true ); + pMultiPage->importPageAndMultiPageProperties( aXStrm, maControls.size() ); + } + typedef boost::unordered_map< sal_uInt32, ::boost::shared_ptr< VbaFormControl > > IdToPageMap; + IdToPageMap idToPage; + VbaFormControlVector::iterator it = maControls.begin(); + VbaFormControlVector::iterator it_end = maControls.end(); + typedef std::vector< sal_uInt32 > UInt32Array; + AxArrayString sCaptions; + + for ( ; it != it_end; ++it ) + { + if ( (*it)->mxCtrlModel->getControlType() == API_CONTROL_PAGE ) + { + VbaSiteModelRef xPageSiteRef = (*it)->mxSiteModel; + if ( xPageSiteRef.get() ) + idToPage[ xPageSiteRef->getId() ] = (*it); + } + else + { + AxTabStripModel* pTabStrip = static_cast<AxTabStripModel*> ( (*it)->mxCtrlModel.get() ); + sCaptions = pTabStrip->maItems; + pMultiPage->mnActiveTab = pTabStrip->mnListIndex; + pMultiPage->mnTabStyle = pTabStrip->mnTabStyle; + } + } + // apply caption/titles to pages + UInt32Array::iterator itCtrlId = pMultiPage->mnIDs.begin(); + UInt32Array::iterator itCtrlId_end = pMultiPage->mnIDs.end(); + AxArrayString::iterator itCaption = sCaptions.begin(); + + maControls.clear(); + // need to sort the controls according to the order of the ids + for ( sal_Int32 index = 1 ; ( sCaptions.size() == idToPage.size() ) && itCtrlId != itCtrlId_end; ++itCtrlId, ++itCaption, ++index ) + { + IdToPageMap::iterator iter = idToPage.find( *itCtrlId ); + if ( iter != idToPage.end() ) + { + AxPageModel* pPage = static_cast<AxPageModel*> ( iter->second->mxCtrlModel.get() ); + + pPage->importProperty( XML_Caption, *itCaption ); + maControls.push_back( iter->second ); + } + } + } /* Reorder the controls (sorts all option buttons of an option group together), and move all children of all embedded frames (group boxes) to this control (UNO group boxes cannot contain |