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/report/XImageControl.hpp>
25 #include <com/sun/star/awt/XVclWindowPeer.hpp>
27 #include <RptObject.hxx>
28 #include <RptModel.hxx>
29 #include <RptPage.hxx>
30 #include <ViewsWindow.hxx>
31 #include <ReportSection.hxx>
32 #include <ReportController.hxx>
33 #include <uistrings.hrc>
34 #include <reportformula.hxx>
35 #include <toolkit/helper/property.hxx>
37 #include <svtools/extcolorcfg.hxx>
38 #include <unotools/confignode.hxx>
41 #include <tools/debug.hxx>
42 // DBG_UNHANDLED_EXCEPTION
43 #include <tools/diagnose_ex.h>
47 using namespace ::com::sun::star
;
51 FormattedFieldBeautifier::FormattedFieldBeautifier(const OReportController
& _aController
)
52 :m_rReportController(_aController
)
58 sal_Int32
FormattedFieldBeautifier::getTextColor()
60 if (m_nTextColor
== -1)
62 svtools::ExtendedColorConfig aConfig
;
63 m_nTextColor
= aConfig
.GetColorValue(CFG_REPORTDESIGNER
, DBTEXTBOXBOUNDCONTENT
).getColor();
69 FormattedFieldBeautifier::~FormattedFieldBeautifier()
74 void FormattedFieldBeautifier::setPlaceholderText( const uno::Reference
< uno::XInterface
>& _rxComponent
)
80 uno::Reference
< report::XFormattedField
> xControlModel( _rxComponent
, uno::UNO_QUERY
);
81 if ( xControlModel
.is() )
83 sDataField
= xControlModel
->getDataField();
85 if ( !sDataField
.isEmpty() )
87 ReportFormula
aFormula( sDataField
);
89 if ( aFormula
.getType() == ReportFormula::Field
)
91 const OUString sColumnName
= aFormula
.getFieldName();
92 OUString sLabel
= m_rReportController
.getColumnLabel_throw(sColumnName
);
93 if ( !sLabel
.isEmpty() )
95 OUStringBuffer aBuffer
;
96 aBuffer
.appendAscii( "=" );
97 aBuffer
.append( sLabel
);
98 sDataField
= aBuffer
.makeStringAndClear();
103 sDataField
= aFormula
.getEqualUndecoratedContent();
107 if ( xControlModel
.is() )
108 setPlaceholderText( getVclWindowPeer( xControlModel
.get() ), sDataField
);
110 catch (const uno::Exception
&)
112 DBG_UNHANDLED_EXCEPTION();
117 void FormattedFieldBeautifier::setPlaceholderText( const uno::Reference
< awt::XVclWindowPeer
>& _xVclWindowPeer
, const OUString
& _rText
)
119 OSL_ENSURE( _xVclWindowPeer
.is(), "FormattedFieldBeautifier::setPlaceholderText: invalid peer!" );
120 if ( !_xVclWindowPeer
.is() )
121 throw uno::RuntimeException();
124 _xVclWindowPeer
->setProperty(PROPERTY_TEXT
, uno::makeAny(_rText
));
126 _xVclWindowPeer
->setProperty(PROPERTY_TEXTCOLOR
, uno::makeAny(getTextColor()));
128 uno::Any aFontDescriptor
= _xVclWindowPeer
->getProperty(PROPERTY_FONTDESCRIPTOR
);
129 awt::FontDescriptor aFontDescriptorStructure
;
130 aFontDescriptor
>>= aFontDescriptorStructure
;
131 aFontDescriptorStructure
.Slant
= ::com::sun::star::awt::FontSlant_ITALIC
;
132 _xVclWindowPeer
->setProperty(PROPERTY_FONTDESCRIPTOR
, uno::makeAny(aFontDescriptorStructure
));
136 void FormattedFieldBeautifier::notifyPropertyChange( const beans::PropertyChangeEvent
& _rEvent
)
138 if ( _rEvent
.PropertyName
!= "DataField" )
142 setPlaceholderText( _rEvent
.Source
);
146 void FormattedFieldBeautifier::handle( const uno::Reference
< uno::XInterface
>& _rxElement
)
148 setPlaceholderText( _rxElement
);
152 void FormattedFieldBeautifier::notifyElementInserted( const uno::Reference
< uno::XInterface
>& _rxElement
)
154 handle( _rxElement
);
158 uno::Reference
<awt::XVclWindowPeer
> FormattedFieldBeautifier::getVclWindowPeer(const uno::Reference
< report::XReportComponent
>& _xComponent
) throw(uno::RuntimeException
)
160 uno::Reference
<awt::XVclWindowPeer
> xVclWindowPeer
;
162 ::boost::shared_ptr
<OReportModel
> pModel
= m_rReportController
.getSdrModel();
164 uno::Reference
<report::XSection
> xSection(_xComponent
->getSection());
167 OReportPage
*pPage
= pModel
->getPage(xSection
);
168 const size_t nIndex
= pPage
->getIndexOf(_xComponent
);
169 if (nIndex
< pPage
->GetObjCount() )
171 SdrObject
*pObject
= pPage
->GetObj(nIndex
);
172 OUnoObject
* pUnoObj
= dynamic_cast<OUnoObject
*>(pObject
);
173 if ( pUnoObj
) // this doesn't need to be done for shapes
175 OSectionWindow
* pSectionWindow
= m_rReportController
.getSectionWindow(xSection
);
176 if (pSectionWindow
!= 0)
178 OReportSection
& aOutputDevice
= pSectionWindow
->getReportSection(); // OutputDevice
179 OSectionView
& aSdrView
= aOutputDevice
.getSectionView(); // SdrView
180 uno::Reference
<awt::XControl
> xControl
= pUnoObj
->GetUnoControl(aSdrView
, aOutputDevice
);
181 xVclWindowPeer
= uno::Reference
<awt::XVclWindowPeer
>( xControl
->getPeer(), uno::UNO_QUERY
);
186 return xVclWindowPeer
;
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */