LibreOffice Module reportdesign (master) 1
FixedTextColor.cxx
Go to the documentation of this file.
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 <ReportSection.hxx>
29#include <ReportController.hxx>
30#include <strings.hxx>
31
32#include <tools/color.hxx>
33
34// DBG_UNHANDLED_EXCEPTION
36
37#include <vcl/svapp.hxx>
38#include <vcl/settings.hxx>
39
40namespace rptui
41{
42 using namespace ::com::sun::star;
43
44
46 :m_rReportController(_aController)
47 {
48 }
49
50
52 {
53 }
54
55
56 void FixedTextColor::notifyPropertyChange( const beans::PropertyChangeEvent& _rEvent )
57 {
58 uno::Reference< report::XFixedText > xFixedText( _rEvent.Source, uno::UNO_QUERY );
59 if ( ! xFixedText.is() )
60 {
61 return;
62 }
63
64 try
65 {
66 uno::Reference< lang::XComponent > xComponent( xFixedText, uno::UNO_QUERY_THROW );
67 handle(xComponent);
68 }
69 catch (uno::Exception const&)
70 {
71 DBG_UNHANDLED_EXCEPTION("reportdesign");
72 }
73 }
74
75
76 void FixedTextColor::setPropertyTextColor(const uno::Reference< awt::XVclWindowPeer >& _xVclWindowPeer, Color _nTextColor)
77 {
78 _xVclWindowPeer->setProperty(PROPERTY_TEXTCOLOR, uno::Any(_nTextColor));
79 }
80
81
82 void FixedTextColor::notifyElementInserted( const uno::Reference< uno::XInterface >& _rxElement )
83 {
84 handle(_rxElement);
85 }
86
87
88 void FixedTextColor::handle( const uno::Reference< uno::XInterface >& _rxElement )
89 {
90 uno::Reference< report::XFixedText > xFixedText( _rxElement, uno::UNO_QUERY );
91 if ( ! xFixedText.is() )
92 {
93 return;
94 }
95
96 try
97 {
98 bool bIsDark = false;
99 const Color nBackColor( ColorTransparency, xFixedText->getControlBackground() );
100 if (nBackColor == COL_TRANSPARENT)
101 {
102 uno::Reference <report::XSection> xSection(xFixedText->getParent(), uno::UNO_QUERY_THROW);
103
104 bool bSectionBackColorIsTransparent = xSection->getBackTransparent();
105 if (bSectionBackColorIsTransparent)
106 {
107 // Label Transparent, Section Transparent set LabelTextColor
108 const StyleSettings& aStyleSettings = Application::GetSettings().GetStyleSettings();
109 Color aWindowColor = aStyleSettings.GetWindowColor();
110 bIsDark = aWindowColor.IsDark();
111 }
112 else
113 {
114 css::util::Color aColor2 = xSection->getBackColor();
115 Color aBackColor(ColorTransparency, aColor2);
116 bIsDark = aBackColor.IsDark();
117 }
118 }
119 else
120 {
121 Color aLabelBackColor(nBackColor);
122 bIsDark = aLabelBackColor.IsDark();
123 }
124
125 uno::Reference<awt::XVclWindowPeer> xVclWindowPeer = getVclWindowPeer(xFixedText);
126 if (bIsDark)
127 {
128 const StyleSettings& aStyleSettings = Application::GetSettings().GetStyleSettings();
129 Color aLabelTextColor = aStyleSettings.GetLabelTextColor();
130 setPropertyTextColor(xVclWindowPeer, aLabelTextColor);
131 }
132 else
133 {
134 util::Color aLabelColor = xFixedText->getCharColor();
135 setPropertyTextColor(xVclWindowPeer, ::Color(ColorTransparency, aLabelColor));
136 }
137
138 }
139 catch( const uno::Exception& )
140 {
141 DBG_UNHANDLED_EXCEPTION("reportdesign");
142 }
143 }
144
145
146 // XPropertyChangeListener
147 uno::Reference<awt::XControl> FixedTextColor::getXControl(const uno::Reference< report::XFixedText >& _xFixedText)
148 {
149
150 uno::Reference<awt::XControl> xControl;
151 OReportController *pController = const_cast<OReportController *>(&m_rReportController);
152
153 std::shared_ptr<OReportModel> pModel = pController->getSdrModel();
154
155 uno::Reference<report::XSection> xSection(_xFixedText->getSection());
156 if ( xSection.is() )
157 {
158 OReportPage *pPage = pModel->getPage(xSection);
159 const size_t nIndex = pPage->getIndexOf(_xFixedText);
160 if (nIndex < pPage->GetObjCount() )
161 {
162 SdrObject *pObject = pPage->GetObj(nIndex);
163 OUnoObject* pUnoObj = dynamic_cast<OUnoObject*>(pObject);
164 if ( pUnoObj ) // this doesn't need to be done for shapes
165 {
166 OSectionWindow* pSectionWindow = pController->getSectionWindow(xSection);
167 if (pSectionWindow != nullptr)
168 {
169 OReportSection& aOutputDevice = pSectionWindow->getReportSection(); // OutputDevice
170 OSectionView& aSdrView = aOutputDevice.getSectionView(); // SdrView
171 xControl = pUnoObj->GetUnoControl(aSdrView, *aOutputDevice.GetOutDev());
172 }
173 }
174 }
175 }
176 return xControl;
177 }
178
179
180 uno::Reference<awt::XVclWindowPeer> FixedTextColor::getVclWindowPeer(const uno::Reference< report::XFixedText >& _xComponent)
181 {
182 uno::Reference<awt::XVclWindowPeer> xVclWindowPeer;
183 uno::Reference<awt::XControl> xControl = getXControl(_xComponent);
184
185 xVclWindowPeer.set( xControl->getPeer(), uno::UNO_QUERY);
186
187 return xVclWindowPeer;
188 }
189
190
191}
192
193/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
bool IsDark() const
SdrObject * GetObj(size_t nNum) const
css::uno::Reference< css::awt::XControl > GetUnoControl(const SdrView &_rView, const OutputDevice &_rOut) const
const Color & GetWindowColor() const
const Color & GetLabelTextColor() const
void notifyPropertyChange(const css::beans::PropertyChangeEvent &_rEvent) override
const OReportController & m_rReportController
void notifyElementInserted(const css::uno::Reference< css::uno::XInterface > &_rxElement) override
static void setPropertyTextColor(const css::uno::Reference< css::awt::XVclWindowPeer > &_xVclWindowPeer, Color _nFormatKey)
css::uno::Reference< css::awt::XVclWindowPeer > getVclWindowPeer(const css::uno::Reference< css::report::XFixedText > &_xComponent)
void handle(const css::uno::Reference< css::uno::XInterface > &_rxElement) override
css::uno::Reference< css::awt::XControl > getXControl(const css::uno::Reference< css::report::XFixedText > &_xFixedText)
virtual ~FixedTextColor() override
FixedTextColor(const OReportController &_aObserver)
OSectionWindow * getSectionWindow(const css::uno::Reference< css::report::XSection > &_xSection) const
const std::shared_ptr< rptui::OReportModel > & getSdrModel() const
return the SdrModel of the real model
size_t getIndexOf(const css::uno::Reference< css::report::XReportComponent > &_xObject)
returns the index inside the object list which belongs to the report component.
Definition: RptPage.cxx:56
OSectionView & getSectionView() const
OReportSection & getReportSection()
::OutputDevice const * GetOutDev() const
ColorTransparency
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
#define DBG_UNHANDLED_EXCEPTION(...)
EmbeddedObjectRef * pObject
sal_Int32 nIndex
constexpr OUStringLiteral PROPERTY_TEXTCOLOR
Definition: strings.hxx:196