Commits

Anonymous committed f0dfe79

sdk321: #i111636# Look up style before falling back to default.

Comments (0)

Files changed (1)

svx/source/sdr/properties/attributeproperties.cxx

 
 		void AttributeProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
 		{
+            OSL_ASSERT(pNewModel!=NULL);
+
 			if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
 			{
 				if(mpItemSet)
                         }
                         else
                         {
-                            // StyleSheet is NOT from the correct pool; use default
-    						ImpAddStyleSheet(pNewModel->GetDefaultStyleSheet(), sal_True);
+                            // StyleSheet is NOT from the correct pool.
+                            // Look one up in the right pool with the same
+                            // name or use the default.
+
+                            // Look up the style in the new document.
+                            OSL_ASSERT(pNewModel->GetStyleSheetPool() != NULL);
+                            SfxStyleSheet* pNewStyleSheet = dynamic_cast<SfxStyleSheet*>(
+                                pNewModel->GetStyleSheetPool()->Find(
+                                    pStySheet->GetName(),
+                                    SFX_STYLE_FAMILY_ALL));
+                            if (pNewStyleSheet == NULL
+                                || &pNewStyleSheet->GetPool().GetPool() != pDestPool)
+                            {
+                                // There is no copy of the style in the new
+                                // document.  Use the default as a fallback.
+                                pNewStyleSheet = pNewModel->GetDefaultStyleSheet();
+                            }
+    						ImpAddStyleSheet(pNewStyleSheet, sal_True);
                         }
 					}