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