1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <FormattedFieldBeautifier.hxx>
23 #include <com/sun/star/report/XFormattedField.hpp>
24 #include <com/sun/star/awt/XVclWindowPeer.hpp>
26 #include <RptObject.hxx>
27 #include <RptModel.hxx>
28 #include <RptPage.hxx>
29 #include <ViewsWindow.hxx>
30 #include <ReportSection.hxx>
31 #include <ReportController.hxx>
32 #include <strings.hxx>
33 #include <reportformula.hxx>
34 #include <toolkit/helper/property.hxx>
36 #include <svtools/extcolorcfg.hxx>
37 #include <unotools/confignode.hxx>
40 #include <tools/debug.hxx>
41 // DBG_UNHANDLED_EXCEPTION
42 #include <tools/diagnose_ex.h>
46 using namespace ::com::sun::star
;
49 FormattedFieldBeautifier::FormattedFieldBeautifier(const OReportController
& _aController
)
50 :m_rReportController(_aController
)
51 ,m_nTextColor(0xffffffff)
56 Color
FormattedFieldBeautifier::getTextColor()
58 if (m_nTextColor
== Color(0xffffffff))
60 svtools::ExtendedColorConfig aConfig
;
61 m_nTextColor
= aConfig
.GetColorValue(CFG_REPORTDESIGNER
, DBTEXTBOXBOUNDCONTENT
).getColor();
67 FormattedFieldBeautifier::~FormattedFieldBeautifier()
72 void FormattedFieldBeautifier::setPlaceholderText( const uno::Reference
< uno::XInterface
>& _rxComponent
)
78 uno::Reference
< report::XFormattedField
> xControlModel( _rxComponent
, uno::UNO_QUERY
);
79 if ( xControlModel
.is() )
81 sDataField
= xControlModel
->getDataField();
83 if ( !sDataField
.isEmpty() )
85 ReportFormula
aFormula( sDataField
);
87 if ( aFormula
.getType() == ReportFormula::Field
)
89 const OUString
& sColumnName
= aFormula
.getFieldName();
90 OUString sLabel
= m_rReportController
.getColumnLabel_throw(sColumnName
);
91 if ( !sLabel
.isEmpty() )
93 OUStringBuffer aBuffer
;
94 aBuffer
.append( "=" );
95 aBuffer
.append( sLabel
);
96 sDataField
= aBuffer
.makeStringAndClear();
101 sDataField
= aFormula
.getEqualUndecoratedContent();
104 setPlaceholderText( getVclWindowPeer( xControlModel
.get() ), sDataField
);
107 catch (const uno::Exception
&)
109 DBG_UNHANDLED_EXCEPTION("reportdesign");
114 void FormattedFieldBeautifier::setPlaceholderText( const uno::Reference
< awt::XVclWindowPeer
>& _xVclWindowPeer
, const OUString
& _rText
)
116 OSL_ENSURE( _xVclWindowPeer
.is(), "FormattedFieldBeautifier::setPlaceholderText: invalid peer!" );
117 if ( !_xVclWindowPeer
.is() )
118 throw uno::RuntimeException();
121 _xVclWindowPeer
->setProperty(PROPERTY_TEXT
, uno::makeAny(_rText
));
123 _xVclWindowPeer
->setProperty(PROPERTY_TEXTCOLOR
, uno::makeAny(getTextColor()));
125 uno::Any aFontDescriptor
= _xVclWindowPeer
->getProperty(PROPERTY_FONTDESCRIPTOR
);
126 awt::FontDescriptor aFontDescriptorStructure
;
127 aFontDescriptor
>>= aFontDescriptorStructure
;
128 aFontDescriptorStructure
.Slant
= css::awt::FontSlant_ITALIC
;
129 _xVclWindowPeer
->setProperty(PROPERTY_FONTDESCRIPTOR
, uno::makeAny(aFontDescriptorStructure
));
133 void FormattedFieldBeautifier::notifyPropertyChange( const beans::PropertyChangeEvent
& _rEvent
)
135 if ( _rEvent
.PropertyName
!= "DataField" )
139 setPlaceholderText( _rEvent
.Source
);
143 void FormattedFieldBeautifier::handle( const uno::Reference
< uno::XInterface
>& _rxElement
)
145 setPlaceholderText( _rxElement
);
149 void FormattedFieldBeautifier::notifyElementInserted( const uno::Reference
< uno::XInterface
>& _rxElement
)
151 handle( _rxElement
);
155 uno::Reference
<awt::XVclWindowPeer
> FormattedFieldBeautifier::getVclWindowPeer(const uno::Reference
< report::XReportComponent
>& _xComponent
)
157 uno::Reference
<awt::XVclWindowPeer
> xVclWindowPeer
;
159 std::shared_ptr
<OReportModel
> pModel
= m_rReportController
.getSdrModel();
161 uno::Reference
<report::XSection
> xSection(_xComponent
->getSection());
164 OReportPage
*pPage
= pModel
->getPage(xSection
);
165 const size_t nIndex
= pPage
->getIndexOf(_xComponent
);
166 if (nIndex
< pPage
->GetObjCount() )
168 SdrObject
*pObject
= pPage
->GetObj(nIndex
);
169 OUnoObject
* pUnoObj
= dynamic_cast<OUnoObject
*>(pObject
);
170 if ( pUnoObj
) // this doesn't need to be done for shapes
172 OSectionWindow
* pSectionWindow
= m_rReportController
.getSectionWindow(xSection
);
173 if (pSectionWindow
!= nullptr)
175 OReportSection
& aOutputDevice
= pSectionWindow
->getReportSection(); // OutputDevice
176 OSectionView
& aSdrView
= aOutputDevice
.getSectionView(); // SdrView
177 uno::Reference
<awt::XControl
> xControl
= pUnoObj
->GetUnoControl(aSdrView
, aOutputDevice
);
178 xVclWindowPeer
.set( xControl
->getPeer(), uno::UNO_QUERY
);
183 return xVclWindowPeer
;
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */