Line data Source code
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 :
20 :
21 : #include <FormattedFieldBeautifier.hxx>
22 :
23 : #include <com/sun/star/report/XFormattedField.hpp>
24 : #include <com/sun/star/report/XImageControl.hpp>
25 : #include <com/sun/star/awt/XVclWindowPeer.hpp>
26 : #include <com/sun/star/awt/InvalidateStyle.hpp>
27 :
28 : #include <RptObject.hxx>
29 : #include <RptModel.hxx>
30 : #include <RptPage.hxx>
31 : #include <ViewsWindow.hxx>
32 : #include <ReportSection.hxx>
33 : #include <ReportController.hxx>
34 : #include <uistrings.hrc>
35 : #include <reportformula.hxx>
36 : #include <toolkit/helper/property.hxx>
37 :
38 : #include <svtools/extcolorcfg.hxx>
39 : #include <unotools/confignode.hxx>
40 :
41 : // DBG_*
42 : #include <tools/debug.hxx>
43 : // DBG_UNHANDLED_EXCEPTION
44 : #include <tools/diagnose_ex.h>
45 :
46 : namespace rptui
47 : {
48 : using namespace ::com::sun::star;
49 :
50 : DBG_NAME(rpt_FormattedFieldBeautifier)
51 :
52 : //--------------------------------------------------------------------
53 0 : FormattedFieldBeautifier::FormattedFieldBeautifier(const OReportController& _aController)
54 : :m_rReportController(_aController)
55 0 : ,m_nTextColor(-1)
56 : {
57 : DBG_CTOR(rpt_FormattedFieldBeautifier, NULL);
58 0 : }
59 :
60 : //--------------------------------------------------------------------
61 0 : sal_Int32 FormattedFieldBeautifier::getTextColor()
62 : {
63 0 : if (m_nTextColor == -1)
64 : {
65 0 : svtools::ExtendedColorConfig aConfig;
66 0 : m_nTextColor = aConfig.GetColorValue(CFG_REPORTDESIGNER, DBTEXTBOXBOUNDCONTENT).getColor();
67 : }
68 0 : return m_nTextColor;
69 : }
70 :
71 : //--------------------------------------------------------------------
72 0 : FormattedFieldBeautifier::~FormattedFieldBeautifier()
73 : {
74 : DBG_DTOR(rpt_FormattedFieldBeautifier,NULL);
75 0 : }
76 :
77 : // -----------------------------------------------------------------------------
78 0 : void FormattedFieldBeautifier::setPlaceholderText( const uno::Reference< uno::XInterface >& _rxComponent )
79 : {
80 0 : ::rtl::OUString sDataField;
81 :
82 : try
83 : {
84 0 : uno::Reference< report::XFormattedField > xControlModel( _rxComponent, uno::UNO_QUERY );
85 0 : if ( xControlModel.is() )
86 : {
87 0 : sDataField = xControlModel->getDataField();
88 :
89 0 : if ( !sDataField.isEmpty() )
90 : {
91 0 : ReportFormula aFormula( sDataField );
92 0 : bool bSet = true;
93 0 : if ( aFormula.getType() == ReportFormula::Field )
94 : {
95 0 : const ::rtl::OUString sColumnName = aFormula.getFieldName();
96 0 : ::rtl::OUString sLabel = m_rReportController.getColumnLabel_throw(sColumnName);
97 0 : if ( !sLabel.isEmpty() )
98 : {
99 0 : ::rtl::OUStringBuffer aBuffer;
100 0 : aBuffer.appendAscii( "=" );
101 0 : aBuffer.append( sLabel );
102 0 : sDataField = aBuffer.makeStringAndClear();
103 0 : bSet = false;
104 0 : }
105 : }
106 0 : if ( bSet )
107 0 : sDataField = aFormula.getEqualUndecoratedContent();
108 : }
109 : }
110 :
111 0 : if ( xControlModel.is() )
112 0 : setPlaceholderText( getVclWindowPeer( xControlModel.get() ), sDataField );
113 : }
114 0 : catch (const uno::Exception &)
115 : {
116 : DBG_UNHANDLED_EXCEPTION();
117 0 : }
118 0 : }
119 :
120 : // -----------------------------------------------------------------------------
121 0 : void FormattedFieldBeautifier::setPlaceholderText( const uno::Reference< awt::XVclWindowPeer >& _xVclWindowPeer, const ::rtl::OUString& _rText )
122 : {
123 : OSL_ENSURE( _xVclWindowPeer.is(), "FormattedFieldBeautifier::setPlaceholderText: invalid peer!" );
124 0 : if ( !_xVclWindowPeer.is() )
125 0 : throw uno::RuntimeException();
126 :
127 : // the actual text
128 0 : _xVclWindowPeer->setProperty(PROPERTY_TEXT, uno::makeAny(_rText));
129 : // the text color
130 0 : _xVclWindowPeer->setProperty(PROPERTY_TEXTCOLOR, uno::makeAny(getTextColor()));
131 : // font->italic
132 0 : uno::Any aFontDescriptor = _xVclWindowPeer->getProperty(PROPERTY_FONTDESCRIPTOR);
133 0 : awt::FontDescriptor aFontDescriptorStructure;
134 0 : aFontDescriptor >>= aFontDescriptorStructure;
135 0 : aFontDescriptorStructure.Slant = ::com::sun::star::awt::FontSlant_ITALIC;
136 0 : _xVclWindowPeer->setProperty(PROPERTY_FONTDESCRIPTOR, uno::makeAny(aFontDescriptorStructure));
137 0 : }
138 :
139 : // -----------------------------------------------------------------------------
140 0 : void FormattedFieldBeautifier::notifyPropertyChange( const beans::PropertyChangeEvent& _rEvent )
141 : {
142 0 : if ( _rEvent.PropertyName != "DataField" )
143 : // not interested in
144 0 : return;
145 :
146 0 : setPlaceholderText( _rEvent.Source );
147 : }
148 :
149 : // -----------------------------------------------------------------------------
150 0 : void FormattedFieldBeautifier::handle( const uno::Reference< uno::XInterface >& _rxElement )
151 : {
152 0 : setPlaceholderText( _rxElement );
153 0 : }
154 :
155 : // -----------------------------------------------------------------------------
156 0 : void FormattedFieldBeautifier::notifyElementInserted( const uno::Reference< uno::XInterface >& _rxElement )
157 : {
158 0 : handle( _rxElement );
159 0 : }
160 :
161 : // -----------------------------------------------------------------------------
162 0 : uno::Reference<awt::XVclWindowPeer> FormattedFieldBeautifier::getVclWindowPeer(const uno::Reference< report::XReportComponent >& _xComponent) throw(uno::RuntimeException)
163 : {
164 0 : uno::Reference<awt::XVclWindowPeer> xVclWindowPeer;
165 :
166 0 : ::boost::shared_ptr<OReportModel> pModel = const_cast< OReportController& >( m_rReportController ).getSdrModel();
167 :
168 0 : uno::Reference<report::XSection> xSection(_xComponent->getSection());
169 0 : if ( xSection.is() )
170 : {
171 0 : OReportPage *pPage = pModel->getPage(xSection);
172 0 : sal_uLong nIndex = pPage->getIndexOf(_xComponent);
173 0 : if (nIndex < pPage->GetObjCount() )
174 : {
175 0 : SdrObject *pObject = pPage->GetObj(nIndex);
176 0 : OUnoObject* pUnoObj = dynamic_cast<OUnoObject*>(pObject);
177 0 : if ( pUnoObj ) // this doesn't need to be done for shapes
178 : {
179 0 : ::boost::shared_ptr<OSectionWindow> pSectionWindow = m_rReportController.getSectionWindow(xSection);
180 0 : if (pSectionWindow != NULL)
181 : {
182 0 : OReportSection& aOutputDevice = pSectionWindow->getReportSection(); // OutputDevice
183 0 : OSectionView& aSdrView = aOutputDevice.getSectionView(); // SdrView
184 0 : uno::Reference<awt::XControl> xControl = pUnoObj->GetUnoControl(aSdrView, aOutputDevice);
185 0 : xVclWindowPeer = uno::Reference<awt::XVclWindowPeer>( xControl->getPeer(), uno::UNO_QUERY);
186 0 : }
187 : }
188 : }
189 : }
190 0 : return xVclWindowPeer;
191 : }
192 : }
193 :
194 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|