LCOV - code coverage report
Current view: top level - reportdesign/source/ui/report - FixedTextColor.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 4 72 5.6 %
Date: 2015-06-13 12:38:46 Functions: 3 11 27.3 %
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 <FixedTextColor.hxx>
      22             : #include <com/sun/star/report/XFixedText.hpp>
      23             : #include <com/sun/star/awt/XVclWindowPeer.hpp>
      24             : 
      25             : #include <RptObject.hxx>
      26             : #include <RptModel.hxx>
      27             : #include <RptPage.hxx>
      28             : #include <ViewsWindow.hxx>
      29             : #include <ReportSection.hxx>
      30             : #include <ReportController.hxx>
      31             : #include <uistrings.hrc>
      32             : #include <reportformula.hxx>
      33             : #include <toolkit/helper/property.hxx>
      34             : 
      35             : #include <tools/color.hxx>
      36             : #include <svtools/extcolorcfg.hxx>
      37             : #include <unotools/confignode.hxx>
      38             : 
      39             : // DBG_*
      40             : #include <tools/debug.hxx>
      41             : // DBG_UNHANDLED_EXCEPTION
      42             : #include <tools/diagnose_ex.h>
      43             : 
      44             : #include <vcl/svapp.hxx>
      45             : #include <vcl/settings.hxx>
      46             : 
      47             : namespace rptui
      48             : {
      49             :     using namespace ::com::sun::star;
      50             : 
      51             : 
      52           1 :     FixedTextColor::FixedTextColor(const OReportController& _aController)
      53           1 :             :m_rReportController(_aController)
      54             :     {
      55           1 :     }
      56             : 
      57             : 
      58           0 :     FixedTextColor::~FixedTextColor()
      59             :     {
      60           0 :     }
      61             : 
      62             : 
      63           0 :     void FixedTextColor::notifyPropertyChange( const beans::PropertyChangeEvent& _rEvent )
      64             :     {
      65           0 :         uno::Reference< report::XFixedText > xFixedText( _rEvent.Source, uno::UNO_QUERY );
      66           0 :         if ( ! xFixedText.is() )
      67             :         {
      68           0 :             return;
      69             :         }
      70             : 
      71             :         try
      72             :         {
      73           0 :             uno::Reference< lang::XComponent > xComponent( xFixedText, uno::UNO_QUERY_THROW );
      74           0 :             handle(xComponent);
      75             :         }
      76           0 :         catch (uno::Exception const&)
      77             :         {
      78             :             DBG_UNHANDLED_EXCEPTION();
      79           0 :         }
      80             :     }
      81             : 
      82             : 
      83           0 :     void FixedTextColor::setPropertyTextColor(const uno::Reference< awt::XVclWindowPeer >& _xVclWindowPeer, sal_Int32 _nTextColor)
      84             :     {
      85           0 :         _xVclWindowPeer->setProperty(PROPERTY_TEXTCOLOR, uno::makeAny(sal_Int32(_nTextColor)));
      86           0 :     }
      87             : 
      88             : 
      89           0 :     void FixedTextColor::notifyElementInserted( const uno::Reference< uno::XInterface >& _rxElement )
      90             :     {
      91           0 :         handle(_rxElement);
      92           0 :     }
      93             : 
      94             : 
      95           0 :     void FixedTextColor::handle( const uno::Reference< uno::XInterface >& _rxElement )
      96             :     {
      97           0 :         uno::Reference< report::XFixedText > xFixedText( _rxElement, uno::UNO_QUERY );
      98           0 :         if ( ! xFixedText.is() )
      99             :         {
     100           0 :             return;
     101             :         }
     102             : 
     103             :         try
     104             :         {
     105           0 :             bool bIsDark = false;
     106           0 :             const sal_Int32 nBackColor( xFixedText->getControlBackground() );
     107           0 :             if ((sal_uInt32)nBackColor == COL_TRANSPARENT)
     108             :             {
     109           0 :                 uno::Reference <report::XSection> xSection(xFixedText->getParent(), uno::UNO_QUERY_THROW);
     110             : 
     111           0 :                 bool bSectionBackColorIsTransparent = xSection->getBackTransparent();
     112           0 :                 if (bSectionBackColorIsTransparent)
     113             :                 {
     114             :                     // Label Transparent, Section Transparent set LabelTextColor
     115           0 :                     const StyleSettings& aStyleSettings = Application::GetSettings().GetStyleSettings();
     116           0 :                     Color aWindowColor  = aStyleSettings.GetWindowColor();
     117           0 :                     bIsDark = aWindowColor.IsDark();
     118             :                 }
     119             :                 else
     120             :                 {
     121           0 :                     com::sun::star::util::Color aColor2 = xSection->getBackColor();
     122           0 :                     Color aBackColor(aColor2);
     123           0 :                     bIsDark = aBackColor.IsDark();
     124           0 :                 }
     125             :             }
     126             :             else
     127             :             {
     128           0 :                 Color aLabelBackColor(nBackColor);
     129           0 :                 bIsDark = aLabelBackColor.IsDark();
     130             :             }
     131             : 
     132           0 :             uno::Reference<awt::XVclWindowPeer> xVclWindowPeer = getVclWindowPeer(xFixedText);
     133           0 :             if (bIsDark)
     134             :             {
     135           0 :                 const StyleSettings& aStyleSettings = Application::GetSettings().GetStyleSettings();
     136           0 :                 Color aLabelTextColor  = aStyleSettings.GetLabelTextColor();
     137           0 :                 setPropertyTextColor(xVclWindowPeer, aLabelTextColor.GetColor());
     138             :             }
     139             :             else
     140             :             {
     141           0 :                 util::Color aLabelColor = xFixedText->getCharColor();
     142           0 :                 setPropertyTextColor(xVclWindowPeer, aLabelColor);
     143           0 :             }
     144             : 
     145             :         }
     146           0 :         catch( const uno::Exception& )
     147             :         {
     148             :             DBG_UNHANDLED_EXCEPTION();
     149           0 :         }
     150             :     }
     151             : 
     152             : 
     153             : 
     154             :     // XPropertyChangeListener
     155           0 :     uno::Reference<awt::XControl> FixedTextColor::getXControl(const uno::Reference< report::XFixedText >& _xFixedText) throw(uno::RuntimeException)
     156             :     {
     157             : 
     158           0 :         uno::Reference<awt::XControl> xControl;
     159           0 :         OReportController *pController = const_cast<OReportController *>(&m_rReportController);
     160             : 
     161           0 :         ::boost::shared_ptr<OReportModel> pModel = pController->getSdrModel();
     162             : 
     163           0 :             uno::Reference<report::XSection> xSection(_xFixedText->getSection());
     164           0 :             if ( xSection.is() )
     165             :             {
     166           0 :                 OReportPage *pPage = pModel->getPage(xSection);
     167           0 :                 const size_t nIndex = pPage->getIndexOf(_xFixedText.get());
     168           0 :                 if (nIndex < pPage->GetObjCount() )
     169             :                 {
     170           0 :                     SdrObject *pObject = pPage->GetObj(nIndex);
     171           0 :                     OUnoObject* pUnoObj = dynamic_cast<OUnoObject*>(pObject);
     172           0 :                     if ( pUnoObj ) // this doesn't need to be done for shapes
     173             :                     {
     174           0 :                         OSectionWindow* pSectionWindow = pController->getSectionWindow(xSection);
     175           0 :                         if (pSectionWindow != 0)
     176             :                         {
     177           0 :                             OReportSection& aOutputDevice = pSectionWindow->getReportSection(); // OutputDevice
     178           0 :                             OSectionView& aSdrView = aOutputDevice.getSectionView(); // SdrView
     179           0 :                             xControl = pUnoObj->GetUnoControl(aSdrView, aOutputDevice);
     180             :                         }
     181             :                     }
     182             :                 }
     183             :             }
     184           0 :         return xControl;
     185             :     }
     186             : 
     187             : 
     188           0 :     uno::Reference<awt::XVclWindowPeer> FixedTextColor::getVclWindowPeer(const uno::Reference< report::XFixedText >& _xComponent) throw(uno::RuntimeException)
     189             :     {
     190           0 :         uno::Reference<awt::XVclWindowPeer> xVclWindowPeer;
     191           0 :         uno::Reference<awt::XControl> xControl = getXControl(_xComponent);
     192             : 
     193           0 :         xVclWindowPeer = uno::Reference<awt::XVclWindowPeer>( xControl->getPeer(), uno::UNO_QUERY);
     194             : 
     195           0 :         return xVclWindowPeer;
     196             :     }
     197             : 
     198             : 
     199             : 
     200             : 
     201           3 : }
     202             : 
     203             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11