lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / reportdesign / source / core / api / FixedLine.cxx
blob2d80b075a1df45184ce4930b02d7e71d27fa1562
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 .
19 #include <FixedLine.hxx>
20 #include <com/sun/star/beans/PropertyAttribute.hpp>
21 #include <strings.hxx>
22 #include <strings.hrc>
23 #include <core_resource.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <Tools.hxx>
26 #include <FormatCondition.hxx>
27 #include <com/sun/star/beans/XPropertyState.hpp>
28 #include <com/sun/star/text/ParagraphVertAlign.hpp>
29 #include <ReportHelperImpl.hxx>
31 #define MIN_WIDTH 80
32 #define MIN_HEIGHT 20
34 namespace reportdesign
37 using namespace com::sun::star;
38 static uno::Sequence< OUString > lcl_getLineOptionals()
40 OUString pProps[] = {
41 OUString(PROPERTY_DATAFIELD)
42 ,OUString(PROPERTY_DEFAULTCONTROL)
43 ,OUString(PROPERTY_CONTROLBORDER)
44 ,OUString(PROPERTY_CONTROLBORDERCOLOR)
45 ,OUString(PROPERTY_CHARCOLOR)
46 ,OUString(PROPERTY_CHAREMPHASIS)
47 ,OUString(PROPERTY_CHARFONTCHARSET)
48 ,OUString(PROPERTY_CHARFONTFAMILY)
49 ,OUString(PROPERTY_CHARFONTNAME)
50 ,OUString(PROPERTY_CHARFONTPITCH)
51 ,OUString(PROPERTY_CHARFONTSTYLENAME)
52 ,OUString(PROPERTY_CHARHEIGHT)
53 ,OUString(PROPERTY_CHARPOSTURE)
54 ,OUString(PROPERTY_CHARRELIEF)
55 ,OUString(PROPERTY_FONTDESCRIPTOR)
56 ,OUString(PROPERTY_FONTDESCRIPTORASIAN)
57 ,OUString(PROPERTY_FONTDESCRIPTORCOMPLEX)
58 ,OUString(PROPERTY_CONTROLTEXTEMPHASISMARK)
59 ,OUString(PROPERTY_CHARROTATION)
60 ,OUString(PROPERTY_CHARSCALEWIDTH)
61 ,OUString(PROPERTY_CHARSTRIKEOUT)
62 ,OUString(PROPERTY_CHARUNDERLINECOLOR)
63 ,OUString(PROPERTY_CHARUNDERLINE)
64 ,OUString(PROPERTY_CHARWEIGHT)
65 ,OUString(PROPERTY_CHARWORDMODE)
66 ,OUString(PROPERTY_CONTROLBACKGROUND)
67 ,OUString(PROPERTY_CONTROLBACKGROUNDTRANSPARENT)
68 ,OUString(PROPERTY_CHARFLASH)
69 ,OUString(PROPERTY_CHARAUTOKERNING)
70 ,OUString(PROPERTY_CHARESCAPEMENTHEIGHT)
71 ,OUString(PROPERTY_CHARLOCALE)
72 ,OUString(PROPERTY_CHARESCAPEMENT)
73 ,OUString(PROPERTY_CHARCASEMAP)
74 ,OUString(PROPERTY_CHARCOMBINEISON)
75 ,OUString(PROPERTY_CHARCOMBINEPREFIX)
76 ,OUString(PROPERTY_CHARCOMBINESUFFIX)
77 ,OUString(PROPERTY_CHARHIDDEN)
78 ,OUString(PROPERTY_CHARSHADOWED)
79 ,OUString(PROPERTY_CHARCONTOURED)
80 ,OUString(PROPERTY_HYPERLINKURL)
81 ,OUString(PROPERTY_HYPERLINKTARGET)
82 ,OUString(PROPERTY_HYPERLINKNAME)
83 ,OUString(PROPERTY_VISITEDCHARSTYLENAME)
84 ,OUString(PROPERTY_UNVISITEDCHARSTYLENAME)
85 ,OUString(PROPERTY_CHARKERNING)
86 ,OUString(PROPERTY_PRINTREPEATEDVALUES)
87 ,OUString(PROPERTY_CONDITIONALPRINTEXPRESSION)
88 ,OUString(PROPERTY_PRINTWHENGROUPCHANGE)
89 ,OUString(PROPERTY_MASTERFIELDS)
90 ,OUString(PROPERTY_DETAILFIELDS)
91 ,OUString(PROPERTY_PARAADJUST)
93 , OUString(PROPERTY_CHAREMPHASISASIAN)
94 , OUString(PROPERTY_CHARFONTNAMEASIAN)
95 , OUString(PROPERTY_CHARFONTSTYLENAMEASIAN)
96 , OUString(PROPERTY_CHARFONTFAMILYASIAN)
97 , OUString(PROPERTY_CHARFONTCHARSETASIAN)
98 , OUString(PROPERTY_CHARFONTPITCHASIAN)
99 , OUString(PROPERTY_CHARHEIGHTASIAN)
100 , OUString(PROPERTY_CHARUNDERLINEASIAN)
101 , OUString(PROPERTY_CHARWEIGHTASIAN)
102 , OUString(PROPERTY_CHARPOSTUREASIAN)
103 , OUString(PROPERTY_CHARWORDMODEASIAN)
104 , OUString(PROPERTY_CHARROTATIONASIAN)
105 , OUString(PROPERTY_CHARSCALEWIDTHASIAN)
106 , OUString(PROPERTY_CHARLOCALEASIAN)
107 , OUString(PROPERTY_CHAREMPHASISCOMPLEX)
108 , OUString(PROPERTY_CHARFONTNAMECOMPLEX)
109 , OUString(PROPERTY_CHARFONTSTYLENAMECOMPLEX)
110 , OUString(PROPERTY_CHARFONTFAMILYCOMPLEX)
111 , OUString(PROPERTY_CHARFONTCHARSETCOMPLEX)
112 , OUString(PROPERTY_CHARFONTPITCHCOMPLEX)
113 , OUString(PROPERTY_CHARHEIGHTCOMPLEX)
114 , OUString(PROPERTY_CHARUNDERLINECOMPLEX)
115 , OUString(PROPERTY_CHARWEIGHTCOMPLEX)
116 , OUString(PROPERTY_CHARPOSTURECOMPLEX)
117 , OUString(PROPERTY_CHARWORDMODECOMPLEX)
118 , OUString(PROPERTY_CHARROTATIONCOMPLEX)
119 , OUString(PROPERTY_CHARSCALEWIDTHCOMPLEX)
120 , OUString(PROPERTY_CHARLOCALECOMPLEX)
124 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
127 OFixedLine::OFixedLine(uno::Reference< uno::XComponentContext > const & _xContext)
128 :FixedLineBase(m_aMutex)
129 ,FixedLinePropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getLineOptionals())
130 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
131 ,m_LineStyle( drawing::LineStyle_NONE )
132 ,m_nOrientation(1)
133 ,m_LineColor(0)
134 ,m_LineTransparence(0)
135 ,m_LineWidth(0)
137 m_aProps.aComponent.m_sName = RptResId(RID_STR_FIXEDLINE);
138 m_aProps.aComponent.m_nWidth = MIN_WIDTH;
141 OFixedLine::OFixedLine(uno::Reference< uno::XComponentContext > const & _xContext
142 ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
143 ,uno::Reference< drawing::XShape >& _xShape
144 ,sal_Int32 _nOrientation)
145 :FixedLineBase(m_aMutex)
146 ,FixedLinePropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getLineOptionals())
147 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
148 ,m_LineStyle( drawing::LineStyle_NONE )
149 ,m_nOrientation(_nOrientation)
150 ,m_LineColor(0)
151 ,m_LineTransparence(0)
152 ,m_LineWidth(0)
154 m_aProps.aComponent.m_sName = RptResId(RID_STR_FIXEDLINE);
155 m_aProps.aComponent.m_xFactory = _xFactory;
156 osl_atomic_increment( &m_refCount );
159 awt::Size aSize = _xShape->getSize();
160 if ( m_nOrientation == 1 )
162 if ( aSize.Width < MIN_WIDTH )
164 aSize.Width = MIN_WIDTH;
165 _xShape->setSize(aSize);
168 else if ( MIN_HEIGHT > aSize.Height )
170 aSize.Height = MIN_HEIGHT;
171 _xShape->setSize(aSize);
173 m_aProps.aComponent.setShape(_xShape,this,m_refCount);
175 catch(uno::Exception&)
177 OSL_FAIL("OFixedLine::OFixedLine: Exception caught!");
179 osl_atomic_decrement( &m_refCount );
182 OFixedLine::~OFixedLine()
186 IMPLEMENT_FORWARD_REFCOUNT( OFixedLine, FixedLineBase )
188 uno::Any SAL_CALL OFixedLine::queryInterface( const uno::Type& _rType )
190 uno::Any aReturn = FixedLineBase::queryInterface(_rType);
191 if ( !aReturn.hasValue() )
192 aReturn = FixedLinePropertySet::queryInterface(_rType);
193 if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
194 return aReturn;
196 return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
199 void SAL_CALL OFixedLine::dispose()
201 FixedLinePropertySet::dispose();
202 cppu::WeakComponentImplHelperBase::dispose();
205 OUString OFixedLine::getImplementationName_Static( )
207 return OUString("com.sun.star.comp.report.OFixedLine");
211 OUString SAL_CALL OFixedLine::getImplementationName( )
213 return getImplementationName_Static();
216 uno::Sequence< OUString > OFixedLine::getSupportedServiceNames_Static( )
218 uno::Sequence< OUString > aServices { SERVICE_FIXEDLINE };
220 return aServices;
223 uno::Reference< uno::XInterface > OFixedLine::create(uno::Reference< uno::XComponentContext > const & xContext)
225 return *(new OFixedLine(xContext));
229 uno::Sequence< OUString > SAL_CALL OFixedLine::getSupportedServiceNames( )
231 return getSupportedServiceNames_Static();
234 sal_Bool SAL_CALL OFixedLine::supportsService(const OUString& ServiceName)
236 return cppu::supportsService(this, ServiceName);
239 // XReportComponent
240 REPORTCOMPONENT_IMPL3(OFixedLine,m_aProps.aComponent)
241 REPORTCOMPONENT_NOMASTERDETAIL(OFixedLine)
243 ::sal_Int16 SAL_CALL OFixedLine::getControlBorder( )
245 throw beans::UnknownPropertyException();
248 void SAL_CALL OFixedLine::setControlBorder( ::sal_Int16 /*_border*/ )
250 throw beans::UnknownPropertyException();
253 ::sal_Int32 SAL_CALL OFixedLine::getControlBorderColor()
255 throw beans::UnknownPropertyException();
258 void SAL_CALL OFixedLine::setControlBorderColor( ::sal_Int32 /*_bordercolor*/ )
260 throw beans::UnknownPropertyException();
263 uno::Reference< beans::XPropertySetInfo > SAL_CALL OFixedLine::getPropertySetInfo( )
265 return FixedLinePropertySet::getPropertySetInfo();
268 void SAL_CALL OFixedLine::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
270 FixedLinePropertySet::setPropertyValue( aPropertyName, aValue );
273 uno::Any SAL_CALL OFixedLine::getPropertyValue( const OUString& PropertyName )
275 return FixedLinePropertySet::getPropertyValue( PropertyName);
278 void SAL_CALL OFixedLine::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
280 FixedLinePropertySet::addPropertyChangeListener( aPropertyName, xListener );
283 void SAL_CALL OFixedLine::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
285 FixedLinePropertySet::removePropertyChangeListener( aPropertyName, aListener );
288 void SAL_CALL OFixedLine::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
290 FixedLinePropertySet::addVetoableChangeListener( PropertyName, aListener );
293 void SAL_CALL OFixedLine::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
295 FixedLinePropertySet::removeVetoableChangeListener( PropertyName, aListener );
298 // XReportControlModel
299 OUString SAL_CALL OFixedLine::getDataField()
301 throw beans::UnknownPropertyException();
304 void SAL_CALL OFixedLine::setDataField( const OUString& /*_datafield*/ )
306 throw beans::UnknownPropertyException();
309 ::sal_Int32 SAL_CALL OFixedLine::getControlBackground()
311 throw beans::UnknownPropertyException();
314 void SAL_CALL OFixedLine::setControlBackground( ::sal_Int32 /*_backgroundcolor*/ )
316 throw beans::UnknownPropertyException();
319 sal_Bool SAL_CALL OFixedLine::getControlBackgroundTransparent()
321 throw beans::UnknownPropertyException();
324 void SAL_CALL OFixedLine::setControlBackgroundTransparent( sal_Bool /*_controlbackgroundtransparent*/ )
326 throw beans::UnknownPropertyException();
329 sal_Bool SAL_CALL OFixedLine::getPrintWhenGroupChange()
331 throw beans::UnknownPropertyException();
334 void SAL_CALL OFixedLine::setPrintWhenGroupChange( sal_Bool /*_printwhengroupchange*/ )
336 throw beans::UnknownPropertyException();
339 OUString SAL_CALL OFixedLine::getConditionalPrintExpression()
341 throw beans::UnknownPropertyException();
344 void SAL_CALL OFixedLine::setConditionalPrintExpression( const OUString& /*_conditionalprintexpression*/ )
346 throw beans::UnknownPropertyException();
349 // XCloneable
350 uno::Reference< util::XCloneable > SAL_CALL OFixedLine::createClone( )
352 uno::Reference< report::XReportComponent> xSource = this;
353 uno::Reference< report::XFixedLine> xSet(cloneObject(xSource,m_aProps.aComponent.m_xFactory,SERVICE_FIXEDLINE),uno::UNO_QUERY_THROW);
354 return xSet.get();
358 // XFixedLine
360 ::sal_Int32 SAL_CALL OFixedLine::getOrientation()
362 ::osl::MutexGuard aGuard(m_aMutex);
363 return m_nOrientation;
366 void SAL_CALL OFixedLine::setOrientation( ::sal_Int32 _orientation )
368 set(PROPERTY_ORIENTATION,_orientation,m_nOrientation);
371 drawing::LineStyle SAL_CALL OFixedLine::getLineStyle()
373 ::osl::MutexGuard aGuard(m_aMutex);
374 return m_LineStyle;
377 void SAL_CALL OFixedLine::setLineStyle( drawing::LineStyle _linestyle )
379 set(PROPERTY_LINESTYLE,_linestyle,m_LineStyle);
382 drawing::LineDash SAL_CALL OFixedLine::getLineDash()
384 ::osl::MutexGuard aGuard(m_aMutex);
385 return m_LineDash;
388 void SAL_CALL OFixedLine::setLineDash( const drawing::LineDash& _linedash )
390 set(PROPERTY_LINEDASH,_linedash,m_LineDash);
393 ::sal_Int32 SAL_CALL OFixedLine::getLineColor()
395 ::osl::MutexGuard aGuard(m_aMutex);
396 return m_LineColor;
399 void SAL_CALL OFixedLine::setLineColor( ::sal_Int32 _linecolor )
401 set(PROPERTY_LINECOLOR,_linecolor,m_LineColor);
404 ::sal_Int16 SAL_CALL OFixedLine::getLineTransparence()
406 ::osl::MutexGuard aGuard(m_aMutex);
407 return m_LineTransparence;
410 void SAL_CALL OFixedLine::setLineTransparence( ::sal_Int16 _linetransparence )
412 set(PROPERTY_LINETRANSPARENCE,_linetransparence,m_LineTransparence);
415 ::sal_Int32 SAL_CALL OFixedLine::getLineWidth()
417 ::osl::MutexGuard aGuard(m_aMutex);
418 return m_LineWidth;
421 void SAL_CALL OFixedLine::setLineWidth( ::sal_Int32 _linewidth )
423 set(PROPERTY_LINEWIDTH,_linewidth,m_LineWidth);
427 // XChild
428 uno::Reference< uno::XInterface > SAL_CALL OFixedLine::getParent( )
430 return OShapeHelper::getParent(this);
433 void SAL_CALL OFixedLine::setParent( const uno::Reference< uno::XInterface >& Parent )
435 OShapeHelper::setParent(Parent,this);
438 uno::Reference< report::XFormatCondition > SAL_CALL OFixedLine::createFormatCondition( )
440 return new OFormatCondition(m_aProps.aComponent.m_xContext);
443 // XContainer
444 void SAL_CALL OFixedLine::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
446 m_aProps.addContainerListener(xListener);
449 void SAL_CALL OFixedLine::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
451 m_aProps.removeContainerListener(xListener);
454 // XElementAccess
455 uno::Type SAL_CALL OFixedLine::getElementType( )
457 return cppu::UnoType<report::XFormatCondition>::get();
460 sal_Bool SAL_CALL OFixedLine::hasElements( )
462 return m_aProps.hasElements();
465 // XIndexContainer
466 void SAL_CALL OFixedLine::insertByIndex( ::sal_Int32 Index, const uno::Any& Element )
468 m_aProps.insertByIndex(Index,Element);
471 void SAL_CALL OFixedLine::removeByIndex( ::sal_Int32 Index )
473 m_aProps.removeByIndex(Index);
476 // XIndexReplace
477 void SAL_CALL OFixedLine::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
479 m_aProps.replaceByIndex(Index,Element);
482 // XIndexAccess
483 ::sal_Int32 SAL_CALL OFixedLine::getCount( )
485 return m_aProps.getCount();
488 uno::Any SAL_CALL OFixedLine::getByIndex( ::sal_Int32 Index )
490 return m_aProps.getByIndex( Index );
493 // XShape
494 awt::Point SAL_CALL OFixedLine::getPosition( )
496 return OShapeHelper::getPosition(this);
499 void SAL_CALL OFixedLine::setPosition( const awt::Point& aPosition )
501 OShapeHelper::setPosition(aPosition,this);
504 awt::Size SAL_CALL OFixedLine::getSize( )
506 return OShapeHelper::getSize(this);
509 void SAL_CALL OFixedLine::setSize( const awt::Size& aSize )
511 if ( aSize.Width < MIN_WIDTH && m_nOrientation == 1 )
512 throw beans::PropertyVetoException("Too small width for FixedLine; minimum is " + OUString::number(MIN_WIDTH) + "0 micrometer", static_cast<cppu::OWeakObject*>(this));
513 else if ( aSize.Height < MIN_HEIGHT && m_nOrientation == 0 )
514 throw beans::PropertyVetoException("Too small height for FixedLine; minimum is " + OUString::number(MIN_HEIGHT) + "0 micrometer", static_cast<cppu::OWeakObject*>(this));
515 OShapeHelper::setSize(aSize,this);
518 // XShapeDescriptor
519 OUString SAL_CALL OFixedLine::getShapeType( )
521 ::osl::MutexGuard aGuard(m_aMutex);
522 if ( m_aProps.aComponent.m_xShape.is() )
523 return m_aProps.aComponent.m_xShape->getShapeType();
524 return OUString("com.sun.star.drawing.ControlShape");
527 OUString SAL_CALL OFixedLine::getHyperLinkURL()
529 throw beans::UnknownPropertyException();
531 void SAL_CALL OFixedLine::setHyperLinkURL(const OUString & /*the_value*/)
533 throw beans::UnknownPropertyException();
535 OUString SAL_CALL OFixedLine::getHyperLinkTarget()
537 throw beans::UnknownPropertyException();
539 void SAL_CALL OFixedLine::setHyperLinkTarget(const OUString & /*the_value*/)
541 throw beans::UnknownPropertyException();
543 OUString SAL_CALL OFixedLine::getHyperLinkName()
545 throw beans::UnknownPropertyException();
547 void SAL_CALL OFixedLine::setHyperLinkName(const OUString & /*the_value*/)
549 throw beans::UnknownPropertyException();
552 NO_REPORTCONTROLFORMAT_IMPL(OFixedLine)
554 sal_Bool SAL_CALL OFixedLine::getPrintRepeatedValues()
556 throw beans::UnknownPropertyException();
558 void SAL_CALL OFixedLine::setPrintRepeatedValues( sal_Bool /*_printrepeatedvalues*/ )
560 throw beans::UnknownPropertyException();
564 } // namespace reportdesign
567 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */