LibreOffice Module svx (master)  1
EnhancedCustomShapeHandle.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
22 #include <svx/unoapi.hxx>
23 #include <svx/svdoashp.hxx>
24 
25 
26 EnhancedCustomShapeHandle::EnhancedCustomShapeHandle( css::uno::Reference< css::drawing::XShape > const & xCustomShape, sal_uInt32 nIndex ) :
27  mnIndex ( nIndex ),
28  mxCustomShape ( xCustomShape )
29 {
30 }
31 
32 
34 {
35 }
36 
37 
38 void SAL_CALL EnhancedCustomShapeHandle::acquire() throw()
39 {
40  OWeakObject::acquire();
41 }
42 
43 
44 void SAL_CALL EnhancedCustomShapeHandle::release() throw()
45 {
46  OWeakObject::release();
47 }
48 
49 // XCustomShapeHandle
50 css::awt::Point SAL_CALL EnhancedCustomShapeHandle::getPosition()
51 {
52  const bool bIsSdrObjCustomShape(nullptr != dynamic_cast< SdrObjCustomShape* >(GetSdrObjectFromXShape(mxCustomShape)));
53 
54  if(!bIsSdrObjCustomShape)
55  {
56  throw css::uno::RuntimeException();
57  }
58 
59  SdrObjCustomShape& rSdrObjCustomShape(static_cast< SdrObjCustomShape& >(*GetSdrObjectFromXShape(mxCustomShape)));
60  Point aPosition;
61  EnhancedCustomShape2d aCustomShape2d(rSdrObjCustomShape);
62 
63  if(!aCustomShape2d.GetHandlePosition(mnIndex, aPosition))
64  {
65  throw css::uno::RuntimeException();
66  }
67 
68  return css::awt::Point( aPosition.X(), aPosition.Y() );
69 }
70 
71 void SAL_CALL EnhancedCustomShapeHandle::setControllerPosition( const css::awt::Point& aPnt )
72 {
73  const bool bIsSdrObjCustomShape(nullptr != dynamic_cast< SdrObjCustomShape* >(GetSdrObjectFromXShape(mxCustomShape)));
74 
75  if(!bIsSdrObjCustomShape)
76  {
77  throw css::uno::RuntimeException();
78  }
79 
80  SdrObjCustomShape& rSdrObjCustomShape(static_cast< SdrObjCustomShape& >(*GetSdrObjectFromXShape(mxCustomShape)));
81  EnhancedCustomShape2d aCustomShape2d(rSdrObjCustomShape);
82 
83  if(!aCustomShape2d.SetHandleControllerPosition(mnIndex, aPnt))
84  {
85  throw css::uno::RuntimeException();
86  }
87 }
88 
89 // XInitialization
90 void SAL_CALL EnhancedCustomShapeHandle::initialize( const css::uno::Sequence< css::uno::Any >& /* aArguments */ )
91 {
92 }
93 
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool GetHandlePosition(const sal_uInt32 nIndex, Point &rReturnPosition) const
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
bool SetHandleControllerPosition(const sal_uInt32 nIndex, const css::awt::Point &rPosition)
EnhancedCustomShapeHandle(css::uno::Reference< css::drawing::XShape > const &xCustomShape, sal_uInt32 nIndex)
virtual void SAL_CALL acquire() override
virtual void SAL_CALL release() override
virtual ~EnhancedCustomShapeHandle() override
virtual void SAL_CALL setControllerPosition(const css::awt::Point &) override
virtual css::awt::Point SAL_CALL getPosition() override
css::uno::Reference< css::drawing::XShape > mxCustomShape
int mnIndex
SdrObject * GetSdrObjectFromXShape(const uno::Reference< drawing::XShape > &xShape)
returns the SdrObject from the given StarOffice API wrapper
Definition: unoshape.cxx:3986