diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2003-06-30 14:59:33 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2003-06-30 14:59:33 +0000 |
commit | 1b33680dde8e07068da07f32973d608c35c8718f (patch) | |
tree | 2fa954a972f3672a6f3b8d95cab4d335ef63e3de /xmloff | |
parent | 2051ddeca0783a80abf7429f323e25d4719df202 (diff) |
INTEGRATION: CWS aig04 (1.45.28); FILE MERGED
2003/06/17 09:54:50 dvo 1.45.28.2: #108791# load/save name property of drop down text field
2003/06/13 12:39:41 dvo 1.45.28.1: #108791# added load/save of drop down field (preliminary)
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/text/txtfldi.cxx | 133 |
1 files changed, 130 insertions, 3 deletions
diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx index 9d562b07c580..69642f96b205 100644 --- a/xmloff/source/text/txtfldi.cxx +++ b/xmloff/source/text/txtfldi.cxx @@ -2,9 +2,9 @@ * * $RCSfile: txtfldi.cxx,v $ * - * $Revision: 1.45 $ + * $Revision: 1.46 $ * - * last change: $Author: vg $ $Date: 2003-04-17 13:16:53 $ + * last change: $Author: hr $ $Date: 2003-06-30 15:59:33 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -299,6 +299,8 @@ const sal_Char sAPI_bibliography[] = "Bibliography"; const sal_Char sAPI_annotation[] = "Annotation"; const sal_Char sAPI_script[] = "Script"; const sal_Char sAPI_measure[] = "Measure"; +const sal_Char sAPI_drop_down[] = "DropDown"; + // property names const sal_Char sAPI_is_fixed[] = "IsFixed"; @@ -811,6 +813,10 @@ XMLTextFieldImportContext::CreateTextFieldImportContext( pContext = new XMLTableFormulaImportContext( rImport, rHlp, nPrefix, rName ); break; + case XML_TOK_TEXT_DROPDOWN: + pContext = new XMLDropDownFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; default: // ignore! May not even be a textfield. @@ -3314,7 +3320,7 @@ void XMLDdeFieldDeclImportContext::StartElement( } // else: ignore } - catch (Exception & aException) + catch ( const Exception& ) { //ignore } @@ -3961,3 +3967,124 @@ void XMLMeasureFieldImportContext::PrepareField( aAny <<= mnKind; xPropertySet->setPropertyValue(OUString::createFromAscii("Kind"), aAny); } + + + +// +// dropdown field +// + + +TYPEINIT1( XMLDropDownFieldImportContext, XMLTextFieldImportContext ); + +XMLDropDownFieldImportContext::XMLDropDownFieldImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const ::rtl::OUString& sLocalName) : + XMLTextFieldImportContext( rImport, rHlp, sAPI_drop_down, + nPrfx, sLocalName ), + aLabels(), + sName(), + nSelected( -1 ), + bNameOK( false ), + sPropertyItems( RTL_CONSTASCII_USTRINGPARAM( "Items" ) ), + sPropertySelectedItem( RTL_CONSTASCII_USTRINGPARAM( "SelectedItem" ) ), + sPropertyName( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ) +{ + bValid = sal_True; +} + +bool lcl_ProcessLabel( const SvXMLImport& rImport, + const Reference<XAttributeList>& xAttrList, + OUString& rLabel, + bool& rIsSelected ) +{ + bool bValid = false; + sal_Int16 nLength = xAttrList->getLength(); + for( sal_Int16 n = 0; n < nLength; n++ ) + { + OUString sLocalName; + sal_uInt16 nPrefix = rImport.GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(n), &sLocalName ); + OUString sValue = xAttrList->getValueByIndex(n); + + if( nPrefix == XML_NAMESPACE_TEXT ) + { + if( IsXMLToken( sLocalName, XML_VALUE ) ) + { + rLabel = sValue; + bValid = true; + } + else if( IsXMLToken( sLocalName, XML_CURRENT_SELECTED ) ) + { + sal_Bool bTmp; + if( SvXMLUnitConverter::convertBool( bTmp, sValue ) ) + rIsSelected = bTmp; + } + } + } + return bValid; +} + +SvXMLImportContext* XMLDropDownFieldImportContext::CreateChildContext( + USHORT nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList>& xAttrList ) +{ + if( nPrefix == XML_NAMESPACE_TEXT && + IsXMLToken( rLocalName, XML_LABEL ) ) + { + OUString sLabel; + bool bIsSelected; + if( lcl_ProcessLabel( GetImport(), xAttrList, sLabel, bIsSelected ) ) + { + if( bIsSelected ) + nSelected = static_cast<sal_Int32>( aLabels.size() ); + aLabels.push_back( sLabel ); + } + } + return new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); +} + +void XMLDropDownFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const ::rtl::OUString& sAttrValue ) +{ + if( nAttrToken == XML_TOK_TEXTFIELD_NAME ) + { + sName = sAttrValue; + bNameOK = true; + } +} + + +void XMLDropDownFieldImportContext::PrepareField( + const Reference<XPropertySet>& xPropertySet) +{ + // create sequence + sal_Int32 nLength = static_cast<sal_Int32>( aLabels.size() ); + Sequence<OUString> aSequence( nLength ); + OUString* pSequence = aSequence.getArray(); + for( sal_Int32 n = 0; n < nLength; n++ ) + pSequence[n] = aLabels[n]; + + // now set values: + Any aAny; + + aAny <<= aSequence; + xPropertySet->setPropertyValue( sPropertyItems, aAny ); + + if( nSelected >= 0 && nSelected < nLength ) + { + aAny <<= pSequence[nSelected]; + xPropertySet->setPropertyValue( sPropertySelectedItem, aAny ); + } + + // set name + if( bNameOK ) + { + aAny <<= sName; + xPropertySet->setPropertyValue( sPropertyName, aAny ); + } +} |