1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
38 BaseProperties::BaseProperties(SdrObject
& 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
67 SdrObject
& BaseProperties::GetSdrObject()
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
86 // default implementation falls back to SetObjectItemSet()
87 SetObjectItemSet(rSet
);
90 void BaseProperties::SetMergedItem(const SfxPoolItem
& rItem
)
92 // default implementation falls back to SetObjectItem()
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());
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();
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
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
);
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: */