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

Generated by: LCOV version 1.10