From 23be3a441f7db8495e6cbb64412a066d3fd63ce2 Mon Sep 17 00:00:00 2001
From: "Daniel Rentz [dr]" <daniel.rentz@oracle.com>
Date: Mon, 30 Aug 2010 14:34:00 +0200
Subject: mib19: #163429# switch off form design mode in new documents created
 with VBA symbol Workbooks.Add

---
 comphelper/inc/comphelper/mediadescriptor.hxx | 26 +++++++++----------
 comphelper/source/misc/mediadescriptor.cxx    | 36 ++++++++++++++++-----------
 2 files changed, 33 insertions(+), 29 deletions(-)

(limited to 'comphelper')

diff --git a/comphelper/inc/comphelper/mediadescriptor.hxx b/comphelper/inc/comphelper/mediadescriptor.hxx
index 7d2333045390..e3d690091327 100644
--- a/comphelper/inc/comphelper/mediadescriptor.hxx
+++ b/comphelper/inc/comphelper/mediadescriptor.hxx
@@ -127,10 +127,6 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap
     //-------------------------------------------
     // interface
     public:
-        /** Value type of the 'ComponentData' property.
-         */
-        typedef ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > ComponentDataSequence;
-
         //---------------------------------------
         /** @short  these ctors do nothing - excepting that they forward
                     the given parameters to the base class ctors.
@@ -204,8 +200,9 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap
         /** Returns a value from the sequence contained in the property
             'ComponentData' of this media descriptor.
 
-            @descr  The property 'ComponentData' should be empty or should
-                contain a value of type ComponentDataSequence (see above).
+            @descr  The property 'ComponentData' should be empty, or should
+                contain a value of type sequence<com.sun.star.beans.NamedValue>
+                or sequence<com.sun.star.beans.PropertyValue>.
 
             @return  The value with the specified name, if existing in the
                 sequence of the 'ComponentData' property, otherwise an empty
@@ -218,10 +215,11 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap
         /** Inserts a value into the sequence contained in the property
             'ComponentData' of the media descriptor.
 
-            @descr  The property 'ComponentData' should be empty or should
-                contain a value of type ComponentDataSequence (see above). The
-                passed value will be inserted into the sequence, or, if already
-                existing, will be overwritten.
+            @descr  The property 'ComponentData' should be empty, or should
+                contain a value of type sequence<com.sun.star.beans.NamedValue>
+                or sequence<com.sun.star.beans.PropertyValue>. The passed value
+                will be inserted into the sequence, or, if already existing,
+                will be overwritten.
 
             @param rName  The name of the value to be inserted into the
                 sequence of the 'ComponentData' property.
@@ -237,10 +235,10 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap
         /** Removes a value from the sequence contained in the property
             'ComponentData' of the media descriptor.
 
-            @descr  The property 'ComponentData' should be empty or should
-                contain a value of type ComponentDataSequence (see above). The
-                value with the passed name will be removed from the sequence,
-                if existing.
+            @descr  The property 'ComponentData' should be empty, or should
+                contain a value of type sequence<com.sun.star.beans.NamedValue>
+                or sequence<com.sun.star.beans.PropertyValue>. The value with
+                the passed name will be removed from the sequence, if existing.
 
             @param rName  The name of the value to be removed from the sequence
                 of the 'ComponentData' property.
diff --git a/comphelper/source/misc/mediadescriptor.cxx b/comphelper/source/misc/mediadescriptor.cxx
index 9e02afe8c56c..468e1e153bff 100644
--- a/comphelper/source/misc/mediadescriptor.cxx
+++ b/comphelper/source/misc/mediadescriptor.cxx
@@ -28,6 +28,7 @@
 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_comphelper.hxx"
 #include <comphelper/mediadescriptor.hxx>
+#include <comphelper/namedvaluecollection.hxx>
 #include <comphelper/stillreadwriteinteraction.hxx>
 
 #include <com/sun/star/ucb/XContent.hpp>
@@ -477,27 +478,30 @@ sal_Bool MediaDescriptor::isStreamReadOnly() const
 
 css::uno::Any MediaDescriptor::getComponentDataEntry( const ::rtl::OUString& rName ) const
 {
-    SequenceAsHashMap aCompDataMap( getUnpackedValueOrDefault( PROP_COMPONENTDATA(), ComponentDataSequence() ) );
-    SequenceAsHashMap::iterator aIt = aCompDataMap.find( rName );
-    return (aIt == aCompDataMap.end()) ? css::uno::Any() : aIt->second;
+    css::uno::Any aEntry;
+    SequenceAsHashMap::const_iterator aPropertyIter = find( PROP_COMPONENTDATA() );
+    if( aPropertyIter != end() )
+        return NamedValueCollection( aPropertyIter->second ).get( rName );
+    return css::uno::Any();
 }
 
 void MediaDescriptor::setComponentDataEntry( const ::rtl::OUString& rName, const css::uno::Any& rValue )
 {
     if( rValue.hasValue() )
     {
-        // get or craete the 'ComponentData' property entry
+        // get or create the 'ComponentData' property entry
         css::uno::Any& rCompDataAny = operator[]( PROP_COMPONENTDATA() );
-        // check type, insert the value
-        OSL_ENSURE( !rCompDataAny.hasValue() || rCompDataAny.has< ComponentDataSequence >(),
-            "MediaDescriptor::setComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
-        if( !rCompDataAny.hasValue() || rCompDataAny.has< ComponentDataSequence >() )
+        // insert the value (retain sequence type, create NamedValue elements by default)
+        bool bHasNamedValues = !rCompDataAny.hasValue() || rCompDataAny.has< css::uno::Sequence< css::beans::NamedValue > >();
+        bool bHasPropValues = rCompDataAny.has< css::uno::Sequence< css::beans::PropertyValue > >();
+        OSL_ENSURE( bHasNamedValues || bHasPropValues, "MediaDescriptor::setComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
+        if( bHasNamedValues || bHasPropValues )
         {
             // insert or overwrite the passed value
             SequenceAsHashMap aCompDataMap( rCompDataAny );
             aCompDataMap[ rName ] = rValue;
-            // write back the sequence (sal_False = use NamedValue instead of PropertyValue)
-            rCompDataAny = aCompDataMap.getAsConstAny( sal_False );
+            // write back the sequence (restore sequence with correct element type)
+            rCompDataAny = aCompDataMap.getAsConstAny( bHasPropValues );
         }
     }
     else
@@ -512,18 +516,20 @@ void MediaDescriptor::clearComponentDataEntry( const ::rtl::OUString& rName )
     SequenceAsHashMap::iterator aPropertyIter = find( PROP_COMPONENTDATA() );
     if( aPropertyIter != end() )
     {
-        OSL_ENSURE( aPropertyIter->second.has< ComponentDataSequence >(),
-            "MediaDescriptor::clearComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
-        if( aPropertyIter->second.has< ComponentDataSequence >() )
+        css::uno::Any& rCompDataAny = aPropertyIter->second;
+        bool bHasNamedValues = rCompDataAny.has< css::uno::Sequence< css::beans::NamedValue > >();
+        bool bHasPropValues = rCompDataAny.has< css::uno::Sequence< css::beans::PropertyValue > >();
+        OSL_ENSURE( bHasNamedValues || bHasPropValues, "MediaDescriptor::clearComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
+        if( bHasNamedValues || bHasPropValues )
         {
             // remove the value with the passed name
-            SequenceAsHashMap aCompDataMap( aPropertyIter->second );
+            SequenceAsHashMap aCompDataMap( rCompDataAny );
             aCompDataMap.erase( rName );
             // write back the sequence, or remove it completely if it is empty
             if( aCompDataMap.empty() )
                 erase( aPropertyIter );
             else
-                aPropertyIter->second = aCompDataMap.getAsConstAny( sal_False );
+                rCompDataAny = aCompDataMap.getAsConstAny( bHasPropValues );
         }
     }
 }
-- 
cgit