1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UndoEnv.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_reportdesign.hxx"
34 #include <FormattedFieldBeautifier.hxx>
36 #include <com/sun/star/report/XFormattedField.hpp>
37 #include <com/sun/star/report/XImageControl.hpp>
38 #include <com/sun/star/awt/XVclWindowPeer.hpp>
39 #include <com/sun/star/awt/InvalidateStyle.hpp>
41 #include <RptObject.hxx>
42 #include <RptModel.hxx>
43 #include <RptPage.hxx>
44 #include <ViewsWindow.hxx>
45 #include <ReportSection.hxx>
46 #include <ReportController.hxx>
47 #include <uistrings.hrc>
48 #include <reportformula.hxx>
49 #include <toolkit/helper/property.hxx>
51 #include <svtools/extcolorcfg.hxx>
52 #include <unotools/confignode.hxx>
55 #include <tools/debug.hxx>
56 // DBG_UNHANDLED_EXCEPTION
57 #include <tools/diagnose_ex.h>
61 using namespace ::com::sun::star
;
63 DBG_NAME(rpt_FormattedFieldBeautifier
)
65 //--------------------------------------------------------------------
66 FormattedFieldBeautifier::FormattedFieldBeautifier(const OReportController
& _aController
)
67 :m_rReportController(_aController
)
70 DBG_CTOR(rpt_FormattedFieldBeautifier
, NULL
);
73 //--------------------------------------------------------------------
74 sal_Int32
FormattedFieldBeautifier::getTextColor()
76 if (m_nTextColor
== -1)
78 svtools::ExtendedColorConfig aConfig
;
79 m_nTextColor
= aConfig
.GetColorValue(CFG_REPORTDESIGNER
, DBTEXTBOXBOUNDCONTENT
).getColor();
84 //--------------------------------------------------------------------
85 FormattedFieldBeautifier::~FormattedFieldBeautifier()
87 DBG_DTOR(rpt_FormattedFieldBeautifier
,NULL
);
90 // -----------------------------------------------------------------------------
91 void FormattedFieldBeautifier::setPlaceholderText( const uno::Reference
< uno::XInterface
>& _rxComponent
)
93 ::rtl::OUString sDataField
;
94 uno::Reference
< report::XReportComponent
> xComponent
;
98 // is it a formatted field?
99 uno::Reference
< report::XFormattedField
> xFormattedField( _rxComponent
, uno::UNO_QUERY
);
100 if ( xFormattedField
.is() )
102 sDataField
= xFormattedField
->getDataField();
103 xComponent
.set( xFormattedField
.get() );
107 // perhaps an image control?
108 uno::Reference
< report::XImageControl
> xImageControl( _rxComponent
, uno::UNO_QUERY
);
109 if ( xImageControl
.is() )
111 sDataField
= xImageControl
->getDataField();
112 xComponent
.set( xImageControl
.get() );
115 if ( !xComponent
.is() )
118 if ( sDataField
.getLength() )
120 ReportFormula
aFormula( sDataField
);
121 sDataField
= aFormula
.getEqualUndecoratedContent();
124 setPlaceholderText( getVclWindowPeer( xComponent
), sDataField
);
126 catch (uno::Exception e
)
128 DBG_UNHANDLED_EXCEPTION();
132 // -----------------------------------------------------------------------------
133 void FormattedFieldBeautifier::setPlaceholderText( const uno::Reference
< awt::XVclWindowPeer
>& _xVclWindowPeer
, const ::rtl::OUString
& _rText
)
135 OSL_ENSURE( _xVclWindowPeer
.is(), "FormattedFieldBeautifier::setPlaceholderText: invalid peer!" );
136 if ( !_xVclWindowPeer
.is() )
137 throw uno::RuntimeException();
140 _xVclWindowPeer
->setProperty(PROPERTY_TEXT
, uno::makeAny(_rText
));
142 _xVclWindowPeer
->setProperty(PROPERTY_TEXTCOLOR
, uno::makeAny(getTextColor()));
144 uno::Any aFontDescriptor
= _xVclWindowPeer
->getProperty(PROPERTY_FONTDESCRIPTOR
);
145 awt::FontDescriptor aFontDescriptorStructure
;
146 aFontDescriptor
>>= aFontDescriptorStructure
;
147 aFontDescriptorStructure
.Slant
= ::com::sun::star::awt::FontSlant_ITALIC
;
148 _xVclWindowPeer
->setProperty(PROPERTY_FONTDESCRIPTOR
, uno::makeAny(aFontDescriptorStructure
));
151 // -----------------------------------------------------------------------------
152 void FormattedFieldBeautifier::notifyPropertyChange( const beans::PropertyChangeEvent
& _rEvent
)
154 if ( !_rEvent
.PropertyName
.equalsAscii( "DataField" ) )
158 setPlaceholderText( _rEvent
.Source
);
161 // -----------------------------------------------------------------------------
162 void FormattedFieldBeautifier::handle( const uno::Reference
< uno::XInterface
>& _rxElement
)
164 setPlaceholderText( _rxElement
);
167 // -----------------------------------------------------------------------------
168 void FormattedFieldBeautifier::notifyElementInserted( const uno::Reference
< uno::XInterface
>& _rxElement
)
170 handle( _rxElement
);
173 // -----------------------------------------------------------------------------
174 uno::Reference
<awt::XVclWindowPeer
> FormattedFieldBeautifier::getVclWindowPeer(const uno::Reference
< report::XReportComponent
>& _xComponent
) throw(uno::RuntimeException
)
176 uno::Reference
<awt::XVclWindowPeer
> xVclWindowPeer
;
178 ::boost::shared_ptr
<OReportModel
> pModel
= const_cast< OReportController
& >( m_rReportController
).getSdrModel();
180 uno::Reference
<report::XSection
> xSection(_xComponent
->getSection());
183 OReportPage
*pPage
= pModel
->getPage(xSection
);
184 ULONG nIndex
= pPage
->getIndexOf(_xComponent
);
185 if (nIndex
< pPage
->GetObjCount() )
187 SdrObject
*pObject
= pPage
->GetObj(nIndex
);
188 OUnoObject
* pUnoObj
= dynamic_cast<OUnoObject
*>(pObject
);
189 if ( pUnoObj
) // this doesn't need to be done for shapes
191 // Rectangle aRect = pUnoObj->GetCurrentBoundRect();
192 ::boost::shared_ptr
<OSectionWindow
> pSectionWindow
= m_rReportController
.getSectionWindow(xSection
);
193 if (pSectionWindow
!= NULL
)
195 OReportSection
& aOutputDevice
= pSectionWindow
->getReportSection(); // OutputDevice
196 OSectionView
& aSdrView
= aOutputDevice
.getSectionView(); // SdrView
197 uno::Reference
<awt::XControl
> xControl
= pUnoObj
->GetUnoControl(aSdrView
, aOutputDevice
);
198 xVclWindowPeer
= uno::Reference
<awt::XVclWindowPeer
>( xControl
->getPeer(), uno::UNO_QUERY
);
203 return xVclWindowPeer
;