1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_reportdesign.hxx"
26 
27 #include <FixedTextColor.hxx>
28 #include <com/sun/star/report/XFixedText.hpp>
29 #include <com/sun/star/awt/XVclWindowPeer.hpp>
30 #include <com/sun/star/awt/InvalidateStyle.hpp>
31 
32 #include <RptObject.hxx>
33 #include <RptModel.hxx>
34 #include <RptPage.hxx>
35 #include <ViewsWindow.hxx>
36 #include <ReportSection.hxx>
37 #include <ReportController.hxx>
38 #include <uistrings.hrc>
39 #include <reportformula.hxx>
40 #include <toolkit/helper/property.hxx>
41 
42 #include <tools/color.hxx> // COL_TRANSPARENT
43 #include <svtools/extcolorcfg.hxx>
44 #include <unotools/confignode.hxx>
45 
46 // DBG_*
47 #include <tools/debug.hxx>
48 // DBG_UNHANDLED_EXCEPTION
49 #include <tools/diagnose_ex.h>
50 
51 #include <vcl/svapp.hxx>
52 #include <vcl/settings.hxx>
53 
54 namespace rptui
55 {
56 	using namespace ::com::sun::star;
57 
DBG_NAME(rpt_FixedTextColor)58     DBG_NAME(rpt_FixedTextColor)
59 
60     FixedTextColor::FixedTextColor(const OReportController& _aController)
61             :m_rReportController(_aController)
62     {
63         DBG_CTOR(rpt_FixedTextColor, NULL);
64     }
65 
66 	//--------------------------------------------------------------------
67     // sal_Int32 FixedTextColor::getTextColor()
68     // {
69     //     const StyleSettings& aStyleSettings = Application::GetSettings().GetStyleSettings();
70     //     sal_Bool bHighContrast = aStyleSettings.GetHighContrastMode();
71     //
72     //     Color aGetFaceColor = aStyleSettings.GetFaceColor();
73     //     Color aGetCheckedColor = aStyleSettings.GetCheckedColor();
74     //     Color aGetLightColor = aStyleSettings.GetLightColor();
75     //     Color aGetLightBorderColor = aStyleSettings.GetLightBorderColor();
76     //     Color aGetShadowColor = aStyleSettings.GetShadowColor();
77     //     Color aGetDarkShadowColor = aStyleSettings.GetDarkShadowColor();
78     //     Color aGetButtonTextColor = aStyleSettings.GetButtonTextColor();
79     //     Color aGetButtonRolloverTextColor = aStyleSettings.GetButtonRolloverTextColor();
80     //     Color aGetRadioCheckTextColor = aStyleSettings.GetRadioCheckTextColor();
81     //     Color aGetGroupTextColor = aStyleSettings.GetGroupTextColor();
82     //     Color aGetLabelTextColor = aStyleSettings.GetLabelTextColor();
83     //     Color aGetInfoTextColor = aStyleSettings.GetInfoTextColor();
84     //     Color aGetWindowColor = aStyleSettings.GetWindowColor();
85     //     Color aGetWindowTextColor = aStyleSettings.GetWindowTextColor();
86     //     Color aGetDialogColor = aStyleSettings.GetDialogColor();
87     //     Color aGetDialogTextColor = aStyleSettings.GetDialogTextColor();
88     //     Color aGetWorkspaceColor = aStyleSettings.GetWorkspaceColor();
89     //     Color aGetFieldColor = aStyleSettings.GetFieldColor();
90     //     Color aGetFieldTextColor = aStyleSettings.GetFieldTextColor();
91     //     Color aGetFieldRolloverTextColor = aStyleSettings.GetFieldRolloverTextColor();
92     //     Color aGetActiveColor = aStyleSettings.GetActiveColor();
93     //     Color aGetActiveColor2 = aStyleSettings.GetActiveColor2();
94     //     Color aGetActiveTextColor = aStyleSettings.GetActiveTextColor();
95     //     Color aGetActiveBorderColor = aStyleSettings.GetActiveBorderColor();
96     //     Color aGetDeactiveColor = aStyleSettings.GetDeactiveColor();
97     //     Color aGetDeactiveColor2 = aStyleSettings.GetDeactiveColor2();
98     //     Color aGetDeactiveTextColor = aStyleSettings.GetDeactiveTextColor();
99     //     Color aGetDeactiveBorderColor = aStyleSettings.GetDeactiveBorderColor();
100     //     Color aGetHighlightColor = aStyleSettings.GetHighlightColor();
101     //     Color aGetHighlightTextColor = aStyleSettings.GetHighlightTextColor();
102     //     Color aGetDisableColor = aStyleSettings.GetDisableColor();
103     //     Color aGetHelpColor = aStyleSettings.GetHelpColor();
104     //     Color aGetHelpTextColor = aStyleSettings.GetHelpTextColor();
105     //     Color aGetMenuColor = aStyleSettings.GetMenuColor();
106     //     Color aGetMenuBarColor = aStyleSettings.GetMenuBarColor();
107     //     Color aGetMenuBorderColor = aStyleSettings.GetMenuBorderColor();
108     //     Color aGetMenuTextColor = aStyleSettings.GetMenuTextColor();
109     //     Color aGetMenuHighlightColor = aStyleSettings.GetMenuHighlightColor();
110     //     Color aGetMenuHighlightTextColor = aStyleSettings.GetMenuHighlightTextColor();
111     //     Color aGetLinkColor = aStyleSettings.GetLinkColor();
112     //     Color aGetVisitedLinkColor = aStyleSettings.GetVisitedLinkColor();
113     //     Color aGetHighlightLinkColor = aStyleSettings.GetHighlightLinkColor();
114     //     Color aGetMonoColor = aStyleSettings.GetMonoColor();
115     //     Color aGetActiveTabColor = aStyleSettings.GetActiveTabColor();
116     //     Color aGetInactiveTabColor = aStyleSettings.GetInactiveTabColor();
117     //
118     //     Color aWindowColor = aStyleSettings.GetWindowColor();
119     //     Color aLabelColor  = aStyleSettings.GetLabelTextColor();
120     //
121     //     // if (m_nTextColor == -1)
122     //     // {
123     //     //    svtools::ExtendedColorConfig aConfig;
124     //     //    m_nTextColor = aConfig.GetColorValue(CFG_REPORTDESIGNER, DBTEXTBOXBOUNDCONTENT).getColor();
125     //     // }
126     //     return aLabelColor.GetColor();
127     // }
128 
129 	//--------------------------------------------------------------------
~FixedTextColor()130     FixedTextColor::~FixedTextColor()
131     {
132         DBG_DTOR(rpt_FixedTextColor,NULL);
133     }
134     // -----------------------------------------------------------------------------
135 
notifyPropertyChange(const beans::PropertyChangeEvent & _rEvent)136     void FixedTextColor::notifyPropertyChange( const beans::PropertyChangeEvent& _rEvent )
137     {
138         // (void)_rEvent;
139         uno::Reference< report::XFixedText > xFixedText( _rEvent.Source, uno::UNO_QUERY );
140         if ( ! xFixedText.is() )
141         {
142             return;
143         }
144 
145         try
146         {
147             uno::Reference< lang::XComponent > xComponent( xFixedText, uno::UNO_QUERY_THROW );
148             handle(xComponent);
149             // uno::Reference<awt::XVclWindowPeer> xVclWindowPeer = getVclWindowPeer(xComponent);
150 
151             //     setPropertyTextColor(xVclWindowPeer, getTextColor());
152         }
153         catch (uno::Exception e)
154         {
155     	    DBG_UNHANDLED_EXCEPTION();
156         }
157     }
158 
159     // -----------------------------------------------------------------------------
setPropertyTextColor(const uno::Reference<awt::XVclWindowPeer> & _xVclWindowPeer,sal_Int32 _nTextColor)160     void FixedTextColor::setPropertyTextColor(const uno::Reference< awt::XVclWindowPeer >& _xVclWindowPeer, sal_Int32 _nTextColor)
161     {
162         _xVclWindowPeer->setProperty(PROPERTY_TEXTCOLOR, uno::makeAny(sal_Int32(_nTextColor)));
163     }
164 
165     // -----------------------------------------------------------------------------
notifyElementInserted(const uno::Reference<uno::XInterface> & _rxElement)166     void FixedTextColor::notifyElementInserted( const uno::Reference< uno::XInterface >& _rxElement )
167     {
168         handle(_rxElement);
169     }
170 
171 // -----------------------------------------------------------------------------
handle(const uno::Reference<uno::XInterface> & _rxElement)172     void FixedTextColor::handle( const uno::Reference< uno::XInterface >& _rxElement )
173     {
174         // (void) _rxElement;
175         uno::Reference< report::XFixedText > xFixedText( _rxElement, uno::UNO_QUERY );
176         if ( ! xFixedText.is() )
177         {
178             return;
179         }
180 
181         try
182         {
183             sal_Bool bIsDark = sal_False;
184             const sal_Int32 nBackColor( xFixedText->getControlBackground() );
185             if ((sal_uInt32)nBackColor == COL_TRANSPARENT)
186             {
187                 uno::Reference <report::XSection> xSection(xFixedText->getParent(), uno::UNO_QUERY_THROW);
188 
189                 sal_Bool bSectionBackColorIsTransparent = xSection->getBackTransparent();
190                 if (bSectionBackColorIsTransparent)
191                 {
192                     // Label Transparent, Section Transparent set LabelTextColor
193                     const StyleSettings& aStyleSettings = Application::GetSettings().GetStyleSettings();
194                     Color aWindowColor  = aStyleSettings.GetWindowColor();
195                     bIsDark = aWindowColor.IsDark();
196                 }
197                 else
198                 {
199                     com::sun::star::util::Color aColor2 = xSection->getBackColor();
200                     Color aBackColor(aColor2);
201                     bIsDark = aBackColor.IsDark();
202                 }
203             }
204             else
205             {
206                 Color aLabelBackColor(nBackColor);
207                 bIsDark = aLabelBackColor.IsDark();
208             }
209 
210             uno::Reference<awt::XVclWindowPeer> xVclWindowPeer = getVclWindowPeer(xFixedText);
211             if (bIsDark)
212             {
213                 const StyleSettings& aStyleSettings = Application::GetSettings().GetStyleSettings();
214                 Color aLabelTextColor  = aStyleSettings.GetLabelTextColor();
215                 setPropertyTextColor(xVclWindowPeer, aLabelTextColor.GetColor());
216             }
217             else
218             {
219                 util::Color aLabelColor = xFixedText->getCharColor();
220                 setPropertyTextColor(xVclWindowPeer, aLabelColor);
221             }
222 
223         }
224         catch( const uno::Exception& )
225         {
226         	DBG_UNHANDLED_EXCEPTION();
227         }
228     }
229 
230 
231 // -----------------------------------------------------------------------------
232     // XPropertyChangeListener
getXControl(const uno::Reference<report::XFixedText> & _xFixedText)233     uno::Reference<awt::XControl> FixedTextColor::getXControl(const uno::Reference< report::XFixedText >& _xFixedText) throw(uno::RuntimeException)
234     {
235 
236         uno::Reference<awt::XControl> xControl;
237         OReportController *pController = (OReportController *)&m_rReportController;
238 
239         ::boost::shared_ptr<OReportModel> pModel = pController->getSdrModel();
240 
241             uno::Reference<report::XSection> xSection(_xFixedText->getSection());
242             if ( xSection.is() )
243             {
244                 OReportPage *pPage = pModel->getPage(xSection);
245                 sal_uLong nIndex = pPage->getIndexOf(_xFixedText.get());
246                 if (nIndex < pPage->GetObjCount() )
247                 {
248                     SdrObject *pObject = pPage->GetObj(nIndex);
249                     OUnoObject* pUnoObj = dynamic_cast<OUnoObject*>(pObject);
250                     if ( pUnoObj ) // this doesn't need to be done for shapes
251                     {
252                         ::boost::shared_ptr<OSectionWindow> pSectionWindow = pController->getSectionWindow(xSection);
253                         if( bool(pSectionWindow) )
254                         {
255                             OReportSection& aOutputDevice = pSectionWindow->getReportSection(); // OutputDevice
256                             OSectionView& aSdrView = aOutputDevice.getSectionView(); // SdrView
257                             xControl = pUnoObj->GetUnoControl(aSdrView, aOutputDevice);
258                         }
259                     }
260                 }
261             }
262         return xControl;
263     }
264 
265 // -----------------------------------------------------------------------------
getVclWindowPeer(const uno::Reference<report::XFixedText> & _xComponent)266     uno::Reference<awt::XVclWindowPeer> FixedTextColor::getVclWindowPeer(const uno::Reference< report::XFixedText >& _xComponent) throw(uno::RuntimeException)
267     {
268         uno::Reference<awt::XVclWindowPeer> xVclWindowPeer;
269         uno::Reference<awt::XControl> xControl = getXControl(_xComponent);
270 
271         xVclWindowPeer = uno::Reference<awt::XVclWindowPeer>( xControl->getPeer(), uno::UNO_QUERY);
272 
273         return xVclWindowPeer;
274     }
275 
276 
277 
278 
279 }
280