tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / svx / source / sdr / properties / e3dsceneproperties.cxx
blobbf1d4cd6f55d6316cc506758a41d6535b86e3721
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 <sdr/properties/e3dsceneproperties.hxx>
21 #include <svl/itemset.hxx>
22 #include <svl/whiter.hxx>
23 #include <svx/svddef.hxx>
24 #include <svx/scene3d.hxx>
25 #include <osl/diagnose.h>
26 #include <memory>
29 namespace sdr::properties
31 E3dSceneProperties::E3dSceneProperties(SdrObject& rObj)
32 : E3dProperties(rObj)
36 E3dSceneProperties::E3dSceneProperties(const E3dSceneProperties& rProps, SdrObject& rObj)
37 : E3dProperties(rProps, rObj)
41 E3dSceneProperties::~E3dSceneProperties()
45 std::unique_ptr<BaseProperties> E3dSceneProperties::Clone(SdrObject& rObj) const
47 return std::unique_ptr<BaseProperties>(new E3dSceneProperties(*this, rObj));
50 const SfxItemSet& E3dSceneProperties::GetMergedItemSet() const
52 // prepare ItemSet
53 if(moItemSet)
55 // filter for SDRATTR_3DSCENE_ items, only keep those items
56 SfxItemSetFixed<SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST> aNew(*moItemSet->GetPool());
57 aNew.Put(*moItemSet);
58 moItemSet->ClearItem();
59 moItemSet->Put(aNew);
61 else
63 // No ItemSet yet, force local ItemSet
64 GetObjectItemSet();
67 // collect all ItemSets of contained 3d objects
68 const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
69 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
71 if (pSub)
72 for (const rtl::Reference<SdrObject>& pObj : *pSub)
74 if(dynamic_cast<const E3dCompoundObject* >(pObj.get()))
76 const SfxItemSet& rSet = pObj->GetMergedItemSet();
77 SfxWhichIter aIter(rSet);
78 sal_uInt16 nWhich(aIter.FirstWhich());
80 while(nWhich)
82 // Leave out the SDRATTR_3DSCENE_ range, this would only be double
83 // and always equal.
84 if(nWhich <= SDRATTR_3DSCENE_FIRST || nWhich >= SDRATTR_3DSCENE_LAST)
86 if(SfxItemState::INVALID == aIter.GetItemState(false))
88 moItemSet->InvalidateItem(nWhich);
90 else
92 moItemSet->MergeValue(rSet.Get(nWhich));
96 nWhich = aIter.NextWhich();
101 // call parent
102 return E3dProperties::GetMergedItemSet();
105 void E3dSceneProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems, bool bAdjustTextFrameWidthAndHeight)
107 // Set SDRATTR_3DOBJ_ range at contained objects.
108 const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
109 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
110 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
112 if(nCount)
114 // Generate filtered ItemSet which contains all but the SDRATTR_3DSCENE items.
115 // #i50808# Leak fix, Clone produces a new instance and we get ownership here
116 std::unique_ptr<SfxItemSet> xNewSet(rSet.Clone());
118 for(sal_uInt16 b(SDRATTR_3DSCENE_FIRST); b <= SDRATTR_3DSCENE_LAST; b++)
120 xNewSet->ClearItem(b);
123 if(xNewSet->Count())
125 for (const rtl::Reference<SdrObject>& pObj : *pSub)
127 if(dynamic_cast<const E3dCompoundObject* >(pObj.get()))
129 // set merged ItemSet at contained 3d object.
130 pObj->SetMergedItemSet(*xNewSet, bClearAllItems, bAdjustTextFrameWidthAndHeight);
136 // call parent. This will set items on local object, too.
137 E3dProperties::SetMergedItemSet(rSet, bClearAllItems, bAdjustTextFrameWidthAndHeight);
140 void E3dSceneProperties::SetMergedItem(const SfxPoolItem& rItem)
142 const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
143 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
144 if (pSub)
145 for (const rtl::Reference<SdrObject>& pObj : *pSub)
146 pObj->SetMergedItem(rItem);
148 // #i43809# call parent. This will set items on local object, too.
149 E3dProperties::SetMergedItem(rItem);
152 void E3dSceneProperties::ClearMergedItem(const sal_uInt16 nWhich)
154 const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
155 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
156 if (pSub)
157 for (const rtl::Reference<SdrObject>& pObj : *pSub)
158 pObj->ClearMergedItem(nWhich);
160 // #i43809# call parent. This will clear items on local object, too.
161 E3dProperties::ClearMergedItem(nWhich);
164 void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich)
166 // call parent
167 E3dProperties::PostItemChange(nWhich);
169 // local changes
170 E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
171 rObj.StructureChanged();
173 switch(nWhich)
175 case SDRATTR_3DSCENE_PERSPECTIVE :
176 case SDRATTR_3DSCENE_DISTANCE :
177 case SDRATTR_3DSCENE_FOCAL_LENGTH :
179 // #83387#, #83391#
180 // one common function for the camera attributes
181 // since SetCamera() sets all three back to the ItemSet
182 Camera3D aSceneCam(rObj.GetCamera());
183 bool bChange(false);
185 // for SDRATTR_3DSCENE_PERSPECTIVE:
186 if(aSceneCam.GetProjection() != rObj.GetPerspective())
188 aSceneCam.SetProjection(rObj.GetPerspective());
189 bChange = true;
192 // for SDRATTR_3DSCENE_DISTANCE:
193 basegfx::B3DPoint aActualPosition(aSceneCam.GetPosition());
194 double fNew = rObj.GetDistance();
196 if(fNew != aActualPosition.getZ())
198 aSceneCam.SetPosition(basegfx::B3DPoint(aActualPosition.getX(), aActualPosition.getY(), fNew));
199 bChange = true;
202 // for SDRATTR_3DSCENE_FOCAL_LENGTH:
203 fNew = rObj.GetFocalLength() / 100.0;
205 if(aSceneCam.GetFocalLength() != fNew)
207 aSceneCam.SetFocalLength(fNew);
208 bChange = true;
211 // for all
212 if(bChange)
214 rObj.SetCamera(aSceneCam);
217 break;
222 void E3dSceneProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr,
223 bool bBroadcast, bool bAdjustTextFrameWidthAndHeight)
225 const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
226 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
227 if (!pSub)
228 return;
229 for (const rtl::Reference<SdrObject>& pObj : *pSub)
231 if(bBroadcast)
232 pObj->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
233 else
234 pObj->NbcSetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr, bAdjustTextFrameWidthAndHeight);
238 SfxStyleSheet* E3dSceneProperties::GetStyleSheet() const
240 SfxStyleSheet* pRetval = nullptr;
242 const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
243 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
244 if (!pSub)
245 return pRetval;
246 for (const rtl::Reference<SdrObject>& pObj : *pSub)
248 SfxStyleSheet* pCandidate = pObj->GetStyleSheet();
250 if(pRetval)
252 if(pCandidate != pRetval)
254 // different StyleSheelts, return none
255 return nullptr;
258 else
260 pRetval = pCandidate;
264 return pRetval;
267 void E3dSceneProperties::SetSceneItemsFromCamera()
269 // force ItemSet
270 GetObjectItemSet();
272 E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
273 const Camera3D& aSceneCam(rObj.GetCamera());
275 // ProjectionType
276 moItemSet->Put(Svx3DPerspectiveItem(aSceneCam.GetProjection()));
278 // CamPos
279 moItemSet->Put(makeSvx3DDistanceItem(static_cast<sal_uInt32>(aSceneCam.GetPosition().getZ() + 0.5)));
281 // FocalLength
282 moItemSet->Put(makeSvx3DFocalLengthItem(static_cast<sal_uInt32>((aSceneCam.GetFocalLength() * 100.0) + 0.5)));
284 } // end of namespace
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */