LCOV - code coverage report
Current view: top level - reportdesign/source/ui/report - FormattedFieldBeautifier.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 4 75 5.3 %
Date: 2015-06-13 12:38:46 Functions: 3 12 25.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11