LCOV - code coverage report
Current view: top level - reportdesign/source/ui/report - FormattedFieldBeautifier.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 75 0.0 %
Date: 2012-08-25 Functions: 0 10 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <FormattedFieldBeautifier.hxx>
      31                 :            : 
      32                 :            : #include <com/sun/star/report/XFormattedField.hpp>
      33                 :            : #include <com/sun/star/report/XImageControl.hpp>
      34                 :            : #include <com/sun/star/awt/XVclWindowPeer.hpp>
      35                 :            : #include <com/sun/star/awt/InvalidateStyle.hpp>
      36                 :            : 
      37                 :            : #include <RptObject.hxx>
      38                 :            : #include <RptModel.hxx>
      39                 :            : #include <RptPage.hxx>
      40                 :            : #include <ViewsWindow.hxx>
      41                 :            : #include <ReportSection.hxx>
      42                 :            : #include <ReportController.hxx>
      43                 :            : #include <uistrings.hrc>
      44                 :            : #include <reportformula.hxx>
      45                 :            : #include <toolkit/helper/property.hxx>
      46                 :            : 
      47                 :            : #include <svtools/extcolorcfg.hxx>
      48                 :            : #include <unotools/confignode.hxx>
      49                 :            : 
      50                 :            : // DBG_*
      51                 :            : #include <tools/debug.hxx>
      52                 :            : // DBG_UNHANDLED_EXCEPTION
      53                 :            : #include <tools/diagnose_ex.h>
      54                 :            : 
      55                 :            : namespace rptui
      56                 :            : {
      57                 :            :     using namespace ::com::sun::star;
      58                 :            : 
      59                 :            :     DBG_NAME(rpt_FormattedFieldBeautifier)
      60                 :            : 
      61                 :            :     //--------------------------------------------------------------------
      62                 :          0 :     FormattedFieldBeautifier::FormattedFieldBeautifier(const OReportController& _aController)
      63                 :            :         :m_rReportController(_aController)
      64                 :          0 :         ,m_nTextColor(-1)
      65                 :            :     {
      66                 :            :         DBG_CTOR(rpt_FormattedFieldBeautifier, NULL);
      67                 :          0 :     }
      68                 :            : 
      69                 :            :     //--------------------------------------------------------------------
      70                 :          0 :     sal_Int32 FormattedFieldBeautifier::getTextColor()
      71                 :            :     {
      72                 :          0 :         if (m_nTextColor == -1)
      73                 :            :         {
      74                 :          0 :             svtools::ExtendedColorConfig aConfig;
      75                 :          0 :             m_nTextColor = aConfig.GetColorValue(CFG_REPORTDESIGNER, DBTEXTBOXBOUNDCONTENT).getColor();
      76                 :            :         }
      77                 :          0 :         return m_nTextColor;
      78                 :            :     }
      79                 :            : 
      80                 :            :     //--------------------------------------------------------------------
      81                 :          0 :     FormattedFieldBeautifier::~FormattedFieldBeautifier()
      82                 :            :     {
      83                 :            :         DBG_DTOR(rpt_FormattedFieldBeautifier,NULL);
      84                 :          0 :     }
      85                 :            : 
      86                 :            :     // -----------------------------------------------------------------------------
      87                 :          0 :     void FormattedFieldBeautifier::setPlaceholderText( const uno::Reference< uno::XInterface >& _rxComponent )
      88                 :            :     {
      89                 :          0 :         ::rtl::OUString sDataField;
      90                 :            : 
      91                 :            :         try
      92                 :            :         {
      93                 :          0 :             uno::Reference< report::XFormattedField > xControlModel( _rxComponent, uno::UNO_QUERY );
      94                 :          0 :             if ( xControlModel.is() )
      95                 :            :             {
      96                 :          0 :                 sDataField = xControlModel->getDataField();
      97                 :            : 
      98                 :          0 :                 if ( !sDataField.isEmpty() )
      99                 :            :                 {
     100                 :          0 :                     ReportFormula aFormula( sDataField );
     101                 :          0 :                     bool bSet = true;
     102                 :          0 :                     if ( aFormula.getType() == ReportFormula::Field )
     103                 :            :                     {
     104                 :          0 :                         const ::rtl::OUString sColumnName = aFormula.getFieldName();
     105                 :          0 :                         ::rtl::OUString sLabel = m_rReportController.getColumnLabel_throw(sColumnName);
     106                 :          0 :                         if ( !sLabel.isEmpty() )
     107                 :            :                         {
     108                 :          0 :                             ::rtl::OUStringBuffer aBuffer;
     109                 :          0 :                             aBuffer.appendAscii( "=" );
     110                 :          0 :                             aBuffer.append( sLabel );
     111                 :          0 :                             sDataField = aBuffer.makeStringAndClear();
     112                 :          0 :                             bSet = false;
     113                 :          0 :                         }
     114                 :            :                     }
     115                 :          0 :                     if ( bSet )
     116                 :          0 :                         sDataField = aFormula.getEqualUndecoratedContent();
     117                 :            :                 }
     118                 :            :             }
     119                 :            : 
     120                 :          0 :             if ( xControlModel.is() )
     121                 :          0 :                 setPlaceholderText( getVclWindowPeer( xControlModel.get() ), sDataField );
     122                 :            :         }
     123                 :          0 :         catch (const uno::Exception &)
     124                 :            :         {
     125                 :            :             DBG_UNHANDLED_EXCEPTION();
     126                 :          0 :         }
     127                 :          0 :     }
     128                 :            : 
     129                 :            :     // -----------------------------------------------------------------------------
     130                 :          0 :     void FormattedFieldBeautifier::setPlaceholderText( const uno::Reference< awt::XVclWindowPeer >& _xVclWindowPeer, const ::rtl::OUString& _rText )
     131                 :            :     {
     132                 :            :         OSL_ENSURE( _xVclWindowPeer.is(), "FormattedFieldBeautifier::setPlaceholderText: invalid peer!" );
     133                 :          0 :         if ( !_xVclWindowPeer.is() )
     134                 :          0 :             throw uno::RuntimeException();
     135                 :            : 
     136                 :            :         // the actual text
     137                 :          0 :         _xVclWindowPeer->setProperty(PROPERTY_TEXT, uno::makeAny(_rText));
     138                 :            :         // the text color
     139                 :          0 :         _xVclWindowPeer->setProperty(PROPERTY_TEXTCOLOR, uno::makeAny(getTextColor()));
     140                 :            :         // font->italic
     141                 :          0 :         uno::Any aFontDescriptor = _xVclWindowPeer->getProperty(PROPERTY_FONTDESCRIPTOR);
     142                 :          0 :         awt::FontDescriptor aFontDescriptorStructure;
     143                 :          0 :         aFontDescriptor >>= aFontDescriptorStructure;
     144                 :          0 :         aFontDescriptorStructure.Slant = ::com::sun::star::awt::FontSlant_ITALIC;
     145                 :          0 :         _xVclWindowPeer->setProperty(PROPERTY_FONTDESCRIPTOR, uno::makeAny(aFontDescriptorStructure));
     146                 :          0 :     }
     147                 :            : 
     148                 :            :     // -----------------------------------------------------------------------------
     149                 :          0 :     void FormattedFieldBeautifier::notifyPropertyChange( const beans::PropertyChangeEvent& _rEvent )
     150                 :            :     {
     151                 :          0 :         if  ( _rEvent.PropertyName != "DataField" )
     152                 :            :             // not interested in
     153                 :          0 :             return;
     154                 :            : 
     155                 :          0 :         setPlaceholderText( _rEvent.Source );
     156                 :            :     }
     157                 :            : 
     158                 :            :     // -----------------------------------------------------------------------------
     159                 :          0 :     void FormattedFieldBeautifier::handle( const uno::Reference< uno::XInterface >& _rxElement )
     160                 :            :     {
     161                 :          0 :         setPlaceholderText( _rxElement );
     162                 :          0 :     }
     163                 :            : 
     164                 :            :     // -----------------------------------------------------------------------------
     165                 :          0 :     void FormattedFieldBeautifier::notifyElementInserted( const uno::Reference< uno::XInterface >& _rxElement )
     166                 :            :     {
     167                 :          0 :         handle( _rxElement );
     168                 :          0 :     }
     169                 :            : 
     170                 :            :     // -----------------------------------------------------------------------------
     171                 :          0 :     uno::Reference<awt::XVclWindowPeer> FormattedFieldBeautifier::getVclWindowPeer(const uno::Reference< report::XReportComponent >& _xComponent) throw(uno::RuntimeException)
     172                 :            :     {
     173                 :          0 :         uno::Reference<awt::XVclWindowPeer> xVclWindowPeer;
     174                 :            : 
     175                 :          0 :         ::boost::shared_ptr<OReportModel> pModel = const_cast< OReportController& >( m_rReportController ).getSdrModel();
     176                 :            : 
     177                 :          0 :         uno::Reference<report::XSection> xSection(_xComponent->getSection());
     178                 :          0 :         if ( xSection.is() )
     179                 :            :         {
     180                 :          0 :             OReportPage *pPage = pModel->getPage(xSection);
     181                 :          0 :             sal_uLong nIndex = pPage->getIndexOf(_xComponent);
     182                 :          0 :             if (nIndex < pPage->GetObjCount() )
     183                 :            :             {
     184                 :          0 :                 SdrObject *pObject = pPage->GetObj(nIndex);
     185                 :          0 :                 OUnoObject* pUnoObj = dynamic_cast<OUnoObject*>(pObject);
     186                 :          0 :                 if ( pUnoObj ) // this doesn't need to be done for shapes
     187                 :            :                 {
     188                 :          0 :                     ::boost::shared_ptr<OSectionWindow> pSectionWindow = m_rReportController.getSectionWindow(xSection);
     189                 :          0 :                     if (pSectionWindow != NULL)
     190                 :            :                     {
     191                 :          0 :                         OReportSection& aOutputDevice = pSectionWindow->getReportSection(); // OutputDevice
     192                 :          0 :                         OSectionView& aSdrView = aOutputDevice.getSectionView();            // SdrView
     193                 :          0 :                         uno::Reference<awt::XControl> xControl = pUnoObj->GetUnoControl(aSdrView, aOutputDevice);
     194                 :          0 :                         xVclWindowPeer = uno::Reference<awt::XVclWindowPeer>( xControl->getPeer(), uno::UNO_QUERY);
     195                 :          0 :                     }
     196                 :            :                 }
     197                 :            :             }
     198                 :            :         }
     199                 :          0 :         return xVclWindowPeer;
     200                 :            :     }
     201                 :            : }
     202                 :            : 
     203                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10