Bump version to 6.4-15
[LibreOffice.git] / svx / source / sdr / properties / properties.cxx
blobc76ecba49c8a89943b1939780c5844247f329bfc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <libxml/xmlwriter.h>
22 #include <svx/sdr/properties/properties.hxx>
23 #include <sdr/properties/itemsettools.hxx>
24 #include <svl/itemset.hxx>
25 #include <svx/svdogrp.hxx>
26 #include <svx/svditer.hxx>
27 #include <svx/xdef.hxx>
28 #include <svx/xfillit0.hxx>
29 #include <vcl/outdev.hxx>
30 #include <svx/svdmodel.hxx>
32 using namespace com::sun::star;
34 namespace sdr
36 namespace properties
38 BaseProperties::BaseProperties(SdrObject& rObj)
39 : mrObject(rObj)
43 BaseProperties::~BaseProperties()
47 void BaseProperties::applyDefaultStyleSheetFromSdrModel()
49 SfxStyleSheet* pDefaultStyleSheet(GetSdrObject().getSdrModelFromSdrObject().GetDefaultStyleSheet());
51 // tdf#118139 Only do this when StyleSheet really differs. It may e.g.
52 // be the case that nullptr == pDefaultStyleSheet and there is none set yet,
53 // so indeed no need to set it (needed for some strange old MSWord2003
54 // documents with CustomShape-'Group' and added Text-Frames, see task description)
55 if(pDefaultStyleSheet != GetStyleSheet())
57 // do not delete hard attributes when setting dsefault Style
58 SetStyleSheet(pDefaultStyleSheet, true);
62 const SdrObject& BaseProperties::GetSdrObject() const
64 return mrObject;
67 SdrObject& BaseProperties::GetSdrObject()
69 return mrObject;
72 const SfxItemSet& BaseProperties::GetMergedItemSet() const
74 // default implementation falls back to GetObjectItemSet()
75 return GetObjectItemSet();
78 void BaseProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems)
80 // clear items if requested
81 if(bClearAllItems)
83 ClearObjectItem();
86 // default implementation falls back to SetObjectItemSet()
87 SetObjectItemSet(rSet);
90 void BaseProperties::SetMergedItem(const SfxPoolItem& rItem)
92 // default implementation falls back to SetObjectItem()
93 SetObjectItem(rItem);
96 void BaseProperties::ClearMergedItem(const sal_uInt16 nWhich)
98 // default implementation falls back to ClearObjectItem()
99 ClearObjectItem(nWhich);
102 void BaseProperties::ForceStyleToHardAttributes()
104 // force all attributes which come from styles to hard attributes
105 // to be able to live without the style. Default implementation does nothing.
106 // Override where an ItemSet is implemented.
109 void BaseProperties::SetMergedItemSetAndBroadcast(const SfxItemSet& rSet, bool bClearAllItems)
111 ItemChangeBroadcaster aC(GetSdrObject());
113 if(bClearAllItems)
115 ClearObjectItem();
118 SetMergedItemSet(rSet);
119 BroadcastItemChange(aC);
122 const SfxPoolItem& BaseProperties::GetItem(const sal_uInt16 nWhich) const
124 return GetObjectItemSet().Get(nWhich);
127 void BaseProperties::BroadcastItemChange(const ItemChangeBroadcaster& rChange)
129 const sal_uInt32 nCount(rChange.GetRectangleCount());
131 // invalidate all new rectangles
132 if(dynamic_cast<const SdrObjGroup*>( &GetSdrObject() ) != nullptr)
134 SdrObjListIter aIter(static_cast<SdrObjGroup&>(GetSdrObject()), SdrIterMode::DeepNoGroups);
136 while(aIter.IsMore())
138 SdrObject* pObj = aIter.Next();
139 pObj->BroadcastObjectChange();
142 else
144 GetSdrObject().BroadcastObjectChange();
147 // also send the user calls
148 for(sal_uInt32 a(0); a < nCount; a++)
150 GetSdrObject().SendUserCall(SdrUserCallType::ChangeAttr, rChange.GetRectangle(a));
154 sal_uInt32 BaseProperties::getVersion() const
156 return 0;
159 void BaseProperties::dumpAsXml(xmlTextWriterPtr pWriter) const
161 xmlTextWriterStartElement(pWriter, BAD_CAST("BaseProperties"));
162 xmlTextWriterEndElement(pWriter);
165 void CleanupFillProperties( SfxItemSet& rItemSet )
167 const bool bFillBitmap = rItemSet.GetItemState(XATTR_FILLBITMAP, false) == SfxItemState::SET;
168 const bool bFillGradient = rItemSet.GetItemState(XATTR_FILLGRADIENT, false) == SfxItemState::SET;
169 const bool bFillHatch = rItemSet.GetItemState(XATTR_FILLHATCH, false) == SfxItemState::SET;
170 if( bFillBitmap || bFillGradient || bFillHatch )
172 const XFillStyleItem* pFillStyleItem = rItemSet.GetItem(XATTR_FILLSTYLE);
173 if( pFillStyleItem )
175 if( bFillBitmap && (pFillStyleItem->GetValue() != drawing::FillStyle_BITMAP) )
177 rItemSet.ClearItem( XATTR_FILLBITMAP );
180 if( bFillGradient && (pFillStyleItem->GetValue() != drawing::FillStyle_GRADIENT) )
182 rItemSet.ClearItem( XATTR_FILLGRADIENT );
185 if( bFillHatch && (pFillStyleItem->GetValue() != drawing::FillStyle_HATCH) )
187 rItemSet.ClearItem( XATTR_FILLHATCH );
193 } // end of namespace properties
194 } // end of namespace sdr
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */