summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorArmin Le Grand <Armin.Le.Grand@cib.de (CIB)>2018-03-15 11:32:00 +0100
committerArmin Le Grand <Armin.Le.Grand@cib.de (CIB)>2018-03-17 23:15:49 +0100
commit86c4672f4600daf19238ef25377406f445d9453a (patch)
treef00afc0f3f77760b8aaad9801c6ee01917c48f28 /cui
parentd1027af3c74529827d53e8cf7b0d42a0ee47d1ba (diff)
OperationSmiley: Secured quite some places using CustomShape
Changed quite some places of SdrObjCustomShape usage to use references instead of pointers, thus forcing to more secure handling. Changed some test and change methods, even found a memory leak by doing so. Change-Id: Iba76037a3c54af50bb05e6bd63d7ad04624665a7
Diffstat (limited to 'cui')
-rw-r--r--cui/source/tabpages/transfrm.cxx216
1 files changed, 141 insertions, 75 deletions
diff --git a/cui/source/tabpages/transfrm.cxx b/cui/source/tabpages/transfrm.cxx
index 7ce63c79aa0d..bb95a7ca5153 100644
--- a/cui/source/tabpages/transfrm.cxx
+++ b/cui/source/tabpages/transfrm.cxx
@@ -24,6 +24,7 @@
#include <svx/svdobj.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svdotext.hxx>
+#include <svx/svdoashp.hxx>
#include <svx/sderitm.hxx>
#include <svx/dialogs.hrc>
#include <svx/transfrmhelper.hxx>
@@ -530,42 +531,80 @@ bool SvxSlantTabPage::FillItemSet(SfxItemSet* rAttrs)
if (!bControlPointsChanged)
return bModified;
- SdrObject* pObj = pView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
- SdrModel* pModel = pObj->GetModel();
- SdrUndoAction* pUndo = pModel->IsUndoEnabled() ?
- pModel->GetSdrUndoFactory().CreateUndoAttrObject(*pObj) :
- nullptr;
+ bool bSelectionIsSdrObjCustomShape(false);
- if (pUndo)
- pModel->BegUndo(pUndo->GetComment());
+ while(true)
+ {
+ if(nullptr == pView)
+ {
+ break;
+ }
+
+ if(0 == pView->GetMarkedObjectList().GetMarkCount())
+ {
+ break;
+ }
- EnhancedCustomShape2d aShape(pObj);
- ::tools::Rectangle aLogicRect = aShape.GetLogicRect();
+ SdrObject* pCandidate(pView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj());
- for (int i = 0; i < 2; ++i)
+ if(nullptr == pCandidate)
+ {
+ break;
+ }
+
+ if(nullptr == dynamic_cast< SdrObjCustomShape* >(pCandidate))
+ {
+ break;
+ }
+
+ bSelectionIsSdrObjCustomShape = true;
+ break;
+ }
+
+ if(bSelectionIsSdrObjCustomShape)
{
- if (m_aControlX[i]->IsValueChangedFromSaved() || m_aControlY[i]->IsValueChangedFromSaved())
+ SdrObjCustomShape& rSdrObjCustomShape(
+ static_cast< SdrObjCustomShape& >(
+ *pView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj()));
+ SdrModel* pModel(rSdrObjCustomShape.GetModel());
+ SdrUndoAction* pUndo(
+ pModel->IsUndoEnabled()
+ ? pModel->GetSdrUndoFactory().CreateUndoAttrObject(rSdrObjCustomShape)
+ : nullptr);
+
+ if(pUndo)
{
- Point aNewPosition(GetCoreValue(*m_aControlX[i], ePoolUnit),
- GetCoreValue(*m_aControlY[i], ePoolUnit));
- aNewPosition.Move(aLogicRect.Left(), aLogicRect.Top());
+ pModel->BegUndo(pUndo->GetComment());
+ }
- css::awt::Point aPosition;
- aPosition.X = aNewPosition.X();
- aPosition.Y = aNewPosition.Y();
+ EnhancedCustomShape2d aShape(rSdrObjCustomShape);
+ ::tools::Rectangle aLogicRect = aShape.GetLogicRect();
- aShape.SetHandleControllerPosition(i, aPosition);
+ for (int i = 0; i < 2; ++i)
+ {
+ if (m_aControlX[i]->IsValueChangedFromSaved() || m_aControlY[i]->IsValueChangedFromSaved())
+ {
+ Point aNewPosition(GetCoreValue(*m_aControlX[i], ePoolUnit),
+ GetCoreValue(*m_aControlY[i], ePoolUnit));
+ aNewPosition.Move(aLogicRect.Left(), aLogicRect.Top());
+
+ css::awt::Point aPosition;
+ aPosition.X = aNewPosition.X();
+ aPosition.Y = aNewPosition.Y();
+
+ aShape.SetHandleControllerPosition(i, aPosition);
+ }
}
- }
- pObj->SetChanged();
- pObj->BroadcastObjectChange();
- bModified = true;
+ rSdrObjCustomShape.SetChanged();
+ rSdrObjCustomShape.BroadcastObjectChange();
+ bModified = true;
- if (pUndo)
- {
- pModel->AddUndo(pUndo);
- pModel->EndUndo();
+ if (pUndo)
+ {
+ pModel->AddUndo(pUndo);
+ pModel->EndUndo();
+ }
}
return bModified;
@@ -622,67 +661,94 @@ void SvxSlantTabPage::Reset(const SfxItemSet* rAttrs)
m_pMtrAngle->SaveValue();
- const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
- if (rMarkList.GetMarkCount() == 1)
+ bool bSelectionIsSdrObjCustomShape(false);
+
+ while(true)
{
- SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
- SdrObjKind eKind = static_cast<SdrObjKind>(pObj->GetObjIdentifier());
- if (eKind == OBJ_CUSTOMSHAPE)
+ if(nullptr == pView)
+ {
+ break;
+ }
+
+ if(1 != pView->GetMarkedObjectList().GetMarkCount())
{
- //save geometry
- SdrCustomShapeGeometryItem aInitialGeometry =
- pObj->GetMergedItem(SDRATTR_CUSTOMSHAPE_GEOMETRY);
+ break;
+ }
- EnhancedCustomShape2d aShape(pObj);
+ SdrObject* pCandidate(pView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj());
- for (int i = 0; i < 2; ++i)
- {
- Point aInitialPosition;
- if (!aShape.GetHandlePosition(i, aInitialPosition))
- break;
- m_aControlGroups[i]->Enable();
- css::awt::Point aPosition;
+ if(nullptr == pCandidate)
+ {
+ break;
+ }
- aPosition.X = SAL_MAX_INT32/2;
- aPosition.Y = SAL_MAX_INT32/2;
- aShape.SetHandleControllerPosition(i, aPosition);
- Point aMaxPosition;
- aShape.GetHandlePosition(i, aMaxPosition);
+ if(nullptr == dynamic_cast< SdrObjCustomShape* >(pCandidate))
+ {
+ break;
+ }
- aPosition.X = SAL_MIN_INT32/2;
- aPosition.Y = SAL_MIN_INT32/2;
- aShape.SetHandleControllerPosition(i, aPosition);
- Point aMinPosition;
- aShape.GetHandlePosition(i, aMinPosition);
+ bSelectionIsSdrObjCustomShape = true;
+ break;
+ }
- ::tools::Rectangle aLogicRect = aShape.GetLogicRect();
- aInitialPosition.Move(-aLogicRect.Left(), -aLogicRect.Top());
- aMaxPosition.Move(-aLogicRect.Left(), -aLogicRect.Top());
- aMinPosition.Move(-aLogicRect.Left(), -aLogicRect.Top());
+ if(bSelectionIsSdrObjCustomShape)
+ {
+ SdrObjCustomShape& rSdrObjCustomShape(
+ static_cast< SdrObjCustomShape& >(
+ *pView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj()));
- SetMetricValue(*m_aControlX[i], aInitialPosition.X(), ePoolUnit);
- SetMetricValue(*m_aControlY[i], aInitialPosition.Y(), ePoolUnit);
+ //save geometry
+ SdrCustomShapeGeometryItem aInitialGeometry(rSdrObjCustomShape.GetMergedItem(SDRATTR_CUSTOMSHAPE_GEOMETRY));
+ EnhancedCustomShape2d aShape(rSdrObjCustomShape);
- if (aMaxPosition.X() == aMinPosition.X())
- m_aControlGroupX[i]->Disable();
- else
- {
- m_aControlX[i]->SetMin(aMinPosition.X(), FUNIT_MM);
- m_aControlX[i]->SetMax(aMaxPosition.X(), FUNIT_MM);
- }
- if (aMaxPosition.Y() == aMinPosition.Y())
- m_aControlGroupY[i]->Disable();
- else
- {
- m_aControlY[i]->SetMin(aMinPosition.Y(), FUNIT_MM);
- m_aControlY[i]->SetMax(aMaxPosition.Y(), FUNIT_MM);
- }
- }
+ for (int i = 0; i < 2; ++i)
+ {
+ Point aInitialPosition;
+ if (!aShape.GetHandlePosition(i, aInitialPosition))
+ break;
+ m_aControlGroups[i]->Enable();
+ css::awt::Point aPosition;
+
+ aPosition.X = SAL_MAX_INT32/2;
+ aPosition.Y = SAL_MAX_INT32/2;
+ aShape.SetHandleControllerPosition(i, aPosition);
+ Point aMaxPosition;
+ aShape.GetHandlePosition(i, aMaxPosition);
+
+ aPosition.X = SAL_MIN_INT32/2;
+ aPosition.Y = SAL_MIN_INT32/2;
+ aShape.SetHandleControllerPosition(i, aPosition);
+ Point aMinPosition;
+ aShape.GetHandlePosition(i, aMinPosition);
+
+ ::tools::Rectangle aLogicRect = aShape.GetLogicRect();
+ aInitialPosition.Move(-aLogicRect.Left(), -aLogicRect.Top());
+ aMaxPosition.Move(-aLogicRect.Left(), -aLogicRect.Top());
+ aMinPosition.Move(-aLogicRect.Left(), -aLogicRect.Top());
- //restore geometry
- pObj->SetMergedItem(aInitialGeometry);
+ SetMetricValue(*m_aControlX[i], aInitialPosition.X(), ePoolUnit);
+ SetMetricValue(*m_aControlY[i], aInitialPosition.Y(), ePoolUnit);
+
+ if (aMaxPosition.X() == aMinPosition.X())
+ m_aControlGroupX[i]->Disable();
+ else
+ {
+ m_aControlX[i]->SetMin(aMinPosition.X(), FUNIT_MM);
+ m_aControlX[i]->SetMax(aMaxPosition.X(), FUNIT_MM);
+ }
+ if (aMaxPosition.Y() == aMinPosition.Y())
+ m_aControlGroupY[i]->Disable();
+ else
+ {
+ m_aControlY[i]->SetMin(aMinPosition.Y(), FUNIT_MM);
+ m_aControlY[i]->SetMax(aMaxPosition.Y(), FUNIT_MM);
+ }
}
+
+ //restore geometry
+ rSdrObjCustomShape.SetMergedItem(aInitialGeometry);
}
+
for (int i = 0; i < 2; ++i)
{
m_aControlX[i]->SaveValue();