LibreOffice Module reportdesign (master) 1
Tools.hxx
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#ifndef INCLUDED_REPORTDESIGN_SOURCE_CORE_INC_TOOLS_HXX
20#define INCLUDED_REPORTDESIGN_SOURCE_CORE_INC_TOOLS_HXX
21
22#include <com/sun/star/report/XSection.hpp>
23#include <com/sun/star/awt/Point.hpp>
24#include <com/sun/star/awt/Size.hpp>
25#include <com/sun/star/container/XChild.hpp>
26#include <com/sun/star/lang/XMultiServiceFactory.hpp>
27
28
29#include <strings.hxx>
30#include <osl/diagnose.h>
31#include <comphelper/uno3.hxx>
32
33namespace reportdesign
34{
40 css::uno::Reference< css::report::XSection> lcl_getSection(const css::uno::Reference< css::uno::XInterface>& _xReportComponent);
41
48 void throwIllegallArgumentException(std::u16string_view _sTypeName
49 ,const css::uno::Reference< css::uno::XInterface >& ExceptionContext_
50 ,sal_Int16 ArgumentPosition_);
51
59 css::uno::Reference< css::util::XCloneable > cloneObject(
60 const css::uno::Reference< css::report::XReportComponent>& _xReportComponent
61 ,const css::uno::Reference< css::lang::XMultiServiceFactory>& _xFactory
62 ,const OUString& _sServiceName);
63
65 {
66 public:
67 template<typename T> static void setSize(const css::awt::Size& aSize,T* _pShape)
68 {
69 OSL_ENSURE(aSize.Width >= 0 && aSize.Height >= 0,"Illegal width or height!");
70
71 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
72 if ( _pShape->m_aProps.aComponent.m_xShape.is() )
73 {
74 css::awt::Size aOldSize = _pShape->m_aProps.aComponent.m_xShape->getSize();
75 if ( aOldSize.Height != aSize.Height || aOldSize.Width != aSize.Width )
76 {
77 _pShape->m_aProps.aComponent.m_nWidth = aOldSize.Width;
78 _pShape->m_aProps.aComponent.m_nHeight = aOldSize.Height;
79 _pShape->m_aProps.aComponent.m_xShape->setSize(aSize);
80 }
81 }
82 _pShape->set(PROPERTY_WIDTH,aSize.Width,_pShape->m_aProps.aComponent.m_nWidth);
83 _pShape->set(PROPERTY_HEIGHT,aSize.Height,_pShape->m_aProps.aComponent.m_nHeight);
84 }
85 template<typename T> static css::awt::Size getSize( T* _pShape )
86 {
87 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
88 if ( _pShape->m_aProps.aComponent.m_xShape.is() )
89 {
90 css::awt::Size aSize = _pShape->m_aProps.aComponent.m_xShape->getSize();
91 OSL_ENSURE(aSize.Width >= 0 && aSize.Height >= 0,"Illegal width or height!");
92 return aSize;
93 }
94 return css::awt::Size(_pShape->m_aProps.aComponent.m_nWidth,_pShape->m_aProps.aComponent.m_nHeight);
95 }
96
97 template<typename T> static void setPosition( const css::awt::Point& _aPosition ,T* _pShape)
98 {
99 // we know it is not allowed that the position in smaller 0, but in NbcMove() it will handled right.
100 // only at 'Undo' it is possible to short set the position smaller 0
101 // OSL_ENSURE(_aPosition.X >= 0 && _aPosition.Y >= 0,"set to Illegal position!");
102 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
103 css::awt::Point aOldPos;
104 aOldPos.X = _pShape->m_aProps.aComponent.m_nPosX;
105 aOldPos.Y = _pShape->m_aProps.aComponent.m_nPosY;
106
107 css::awt::Point aPosition(_aPosition);
108 if ( _pShape->m_aProps.aComponent.m_xShape.is() )
109 {
110 aOldPos = _pShape->m_aProps.aComponent.m_xShape->getPosition();
111 if ( aOldPos.X != aPosition.X || aOldPos.Y != aPosition.Y )
112 {
113 _pShape->m_aProps.aComponent.m_nPosX = aOldPos.X;
114 _pShape->m_aProps.aComponent.m_nPosY = aOldPos.Y;
115 _pShape->m_aProps.aComponent.m_xShape->setPosition(aPosition);
116 }
117 }
118 _pShape->set(PROPERTY_POSITIONX,aPosition.X,aOldPos.X);
119 _pShape->set(PROPERTY_POSITIONY,aPosition.Y,aOldPos.Y);
120 }
121 template<typename T> static css::awt::Point getPosition(T* _pShape)
122 {
123 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
124 if ( _pShape->m_aProps.aComponent.m_xShape.is() )
125 {
126 css::awt::Point aPosition = _pShape->m_aProps.aComponent.m_xShape->getPosition();
127 return aPosition;
128 }
129 return css::awt::Point(_pShape->m_aProps.aComponent.m_nPosX,_pShape->m_aProps.aComponent.m_nPosY);
130 }
131 template<typename T> static void setParent( const css::uno::Reference< css::uno::XInterface >& Parent, T* _pShape)
132 {
133 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
134 _pShape->m_aProps.aComponent.m_xParent = css::uno::Reference< css::container::XChild >(Parent,css::uno::UNO_QUERY);
135 css::uno::Reference< css::container::XChild > xChild;
136 comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild);
137 if ( xChild.is() )
138 xChild->setParent(Parent);
139 }
140 template<typename T> static css::uno::Reference< css::uno::XInterface > getParent( T* _pShape )
141 {
142 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
143 css::uno::Reference< css::container::XChild > xChild;
144 comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild);
145 if ( xChild.is() )
146 return xChild->getParent();
147 return _pShape->m_aProps.aComponent.m_xParent;
148 }
149 };
150
151} // namespace reportdesign
152
153#endif // INCLUDED_REPORTDESIGN_SOURCE_CORE_INC_TOOLS_HXX
154
155/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void setSize(const css::awt::Size &aSize, T *_pShape)
Definition: Tools.hxx:67
static css::awt::Size getSize(T *_pShape)
Definition: Tools.hxx:85
static void setPosition(const css::awt::Point &_aPosition, T *_pShape)
Definition: Tools.hxx:97
static css::awt::Point getPosition(T *_pShape)
Definition: Tools.hxx:121
static css::uno::Reference< css::uno::XInterface > getParent(T *_pShape)
Definition: Tools.hxx:140
static void setParent(const css::uno::Reference< css::uno::XInterface > &Parent, T *_pShape)
Definition: Tools.hxx:131
bool query_aggregation(const css::uno::Reference< css::uno::XAggregation > &_rxAggregate, css::uno::Reference< iface > &_rxOut)
uno::Reference< report::XSection > lcl_getSection(const uno::Reference< uno::XInterface > &_xReportComponent)
Definition: Tools.cxx:30
void throwIllegallArgumentException(std::u16string_view _sTypeName, const uno::Reference< uno::XInterface > &ExceptionContext_, sal_Int16 ArgumentPosition_)
Definition: Tools.cxx:43
uno::Reference< util::XCloneable > cloneObject(const uno::Reference< report::XReportComponent > &_xReportComponent, const uno::Reference< lang::XMultiServiceFactory > &_xFactory, const OUString &_sServiceName)
Definition: Tools.cxx:53
constexpr OUStringLiteral PROPERTY_HEIGHT
Definition: strings.hxx:37
constexpr OUStringLiteral PROPERTY_POSITIONX
Definition: strings.hxx:74
constexpr OUStringLiteral PROPERTY_POSITIONY
Definition: strings.hxx:75
constexpr OUStringLiteral PROPERTY_WIDTH
Definition: strings.hxx:73