xref: /AOO41X/main/svx/source/form/fmcontrolbordermanager.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef SVX_SOURCE_FORM_FMCONTROLBORDERMANAGER_HXX
32*cdf0e10cSrcweir #include "fmcontrolbordermanager.hxx"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #ifndef _SVX_FMPROP_HRC
36*cdf0e10cSrcweir #include "fmprop.hrc"
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir /** === begin UNO includes === **/
40*cdf0e10cSrcweir #include <com/sun/star/form/validation/XValidatableFormComponent.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/awt/XTextComponent.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/awt/XListBox.hpp>
43*cdf0e10cSrcweir /** === end UNO includes === **/
44*cdf0e10cSrcweir #include <tools/debug.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir //........................................................................
47*cdf0e10cSrcweir namespace svxform
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir //........................................................................
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
52*cdf0e10cSrcweir     using namespace ::com::sun::star::awt;
53*cdf0e10cSrcweir     using namespace ::com::sun::star::form::validation;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir     //====================================================================
56*cdf0e10cSrcweir 	//= helper
57*cdf0e10cSrcweir 	//====================================================================
58*cdf0e10cSrcweir 	//--------------------------------------------------------------------
59*cdf0e10cSrcweir     static void setUnderline( const Reference< XVclWindowPeer >& _rxPeer, const UnderlineDescriptor& _rUnderline )
60*cdf0e10cSrcweir     {
61*cdf0e10cSrcweir         OSL_ENSURE( _rxPeer.is(), "setUnderline: invalid peer!" );
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir         // the underline type is an aspect of the font
64*cdf0e10cSrcweir         FontDescriptor aFont;
65*cdf0e10cSrcweir         OSL_VERIFY( _rxPeer->getProperty( FM_PROP_FONT ) >>= aFont );
66*cdf0e10cSrcweir         aFont.Underline = _rUnderline.nUnderlineType;
67*cdf0e10cSrcweir         _rxPeer->setProperty( FM_PROP_FONT, makeAny( aFont ) );
68*cdf0e10cSrcweir         // the underline color is a separate property
69*cdf0e10cSrcweir         _rxPeer->setProperty( FM_PROP_TEXTLINECOLOR, makeAny( _rUnderline.nUnderlineColor ) );
70*cdf0e10cSrcweir     }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	//--------------------------------------------------------------------
73*cdf0e10cSrcweir     static void getUnderline( const Reference< XVclWindowPeer >& _rxPeer, UnderlineDescriptor& _rUnderline )
74*cdf0e10cSrcweir     {
75*cdf0e10cSrcweir         OSL_ENSURE( _rxPeer.is(), "getUnderline: invalid peer!" );
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir         FontDescriptor aFont;
78*cdf0e10cSrcweir         OSL_VERIFY( _rxPeer->getProperty( FM_PROP_FONT ) >>= aFont );
79*cdf0e10cSrcweir         _rUnderline.nUnderlineType = aFont.Underline;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir         OSL_VERIFY( _rxPeer->getProperty( FM_PROP_TEXTLINECOLOR ) >>= _rUnderline.nUnderlineColor );
82*cdf0e10cSrcweir     }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	//--------------------------------------------------------------------
85*cdf0e10cSrcweir     static void getBorder( const Reference< XVclWindowPeer >& _rxPeer, BorderDescriptor& _rBoder )
86*cdf0e10cSrcweir     {
87*cdf0e10cSrcweir         OSL_ENSURE( _rxPeer.is(), "getBorder: invalid peer!" );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir         OSL_VERIFY( _rxPeer->getProperty( FM_PROP_BORDER ) >>= _rBoder.nBorderType );
90*cdf0e10cSrcweir         OSL_VERIFY( _rxPeer->getProperty( FM_PROP_BORDERCOLOR ) >>= _rBoder.nBorderColor );
91*cdf0e10cSrcweir     }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	//--------------------------------------------------------------------
94*cdf0e10cSrcweir     static void setBorder( const Reference< XVclWindowPeer >& _rxPeer, const BorderDescriptor& _rBoder )
95*cdf0e10cSrcweir     {
96*cdf0e10cSrcweir         OSL_ENSURE( _rxPeer.is(), "setBorder: invalid peer!" );
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir         _rxPeer->setProperty( FM_PROP_BORDER, makeAny( _rBoder.nBorderType ) );
99*cdf0e10cSrcweir         _rxPeer->setProperty( FM_PROP_BORDERCOLOR, makeAny( _rBoder.nBorderColor ) );
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     //====================================================================
103*cdf0e10cSrcweir 	//= ControlBorderManager
104*cdf0e10cSrcweir 	//====================================================================
105*cdf0e10cSrcweir 	//--------------------------------------------------------------------
106*cdf0e10cSrcweir     ControlBorderManager::ControlBorderManager()
107*cdf0e10cSrcweir         :m_nFocusColor    ( 0x000000FF )
108*cdf0e10cSrcweir         ,m_nMouseHoveColor( 0x007098BE )
109*cdf0e10cSrcweir         ,m_nInvalidColor  ( 0x00FF0000 )
110*cdf0e10cSrcweir         ,m_bDynamicBorderColors( false )
111*cdf0e10cSrcweir     {
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 	//--------------------------------------------------------------------
115*cdf0e10cSrcweir     ControlBorderManager::~ControlBorderManager()
116*cdf0e10cSrcweir     {
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	//--------------------------------------------------------------------
120*cdf0e10cSrcweir     bool ControlBorderManager::canColorBorder( const Reference< XVclWindowPeer >& _rxPeer )
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         OSL_PRECOND( _rxPeer.is(), "ControlBorderManager::canColorBorder: invalid peer!" );
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir         PeerBag::const_iterator aPos = m_aColorableControls.find( _rxPeer );
125*cdf0e10cSrcweir         if ( aPos != m_aColorableControls.end() )
126*cdf0e10cSrcweir             return true;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         aPos = m_aNonColorableControls.find( _rxPeer );
129*cdf0e10cSrcweir         if ( aPos != m_aNonColorableControls.end() )
130*cdf0e10cSrcweir             return false;
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir         // this peer is not yet known
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir         // no border coloring for controls which are not for text input
135*cdf0e10cSrcweir         // #i37434# / 2004-11-19 / frank.schoenheit@sun.com
136*cdf0e10cSrcweir         Reference< XTextComponent > xText( _rxPeer, UNO_QUERY );
137*cdf0e10cSrcweir         Reference< XListBox > xListBox( _rxPeer, UNO_QUERY );
138*cdf0e10cSrcweir         if ( xText.is() || xListBox.is() )
139*cdf0e10cSrcweir         {
140*cdf0e10cSrcweir             sal_Int16 nBorderStyle = VisualEffect::NONE;
141*cdf0e10cSrcweir             OSL_VERIFY( _rxPeer->getProperty( FM_PROP_BORDER ) >>= nBorderStyle );
142*cdf0e10cSrcweir             if ( nBorderStyle == VisualEffect::FLAT )
143*cdf0e10cSrcweir             	// if you change this to also accept LOOK3D, then this would also work, but look ugly
144*cdf0e10cSrcweir             {
145*cdf0e10cSrcweir                 m_aColorableControls.insert( _rxPeer );
146*cdf0e10cSrcweir                 return true;
147*cdf0e10cSrcweir             }
148*cdf0e10cSrcweir         }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir         m_aNonColorableControls.insert( _rxPeer );
151*cdf0e10cSrcweir         return false;
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 	//--------------------------------------------------------------------
155*cdf0e10cSrcweir     ControlStatus ControlBorderManager::getControlStatus( const Reference< XControl >& _rxControl ) SAL_THROW(())
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir         ControlStatus nStatus = CONTROL_STATUS_NONE;
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir         if ( _rxControl.get() == m_aFocusControl.xControl.get() )
160*cdf0e10cSrcweir             nStatus |= CONTROL_STATUS_FOCUSED;
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir         if ( _rxControl.get() == m_aMouseHoverControl.xControl.get() )
163*cdf0e10cSrcweir             nStatus |= CONTROL_STATUS_MOUSE_HOVER;
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir         if ( m_aInvalidControls.find( ControlData( _rxControl ) ) != m_aInvalidControls.end() )
166*cdf0e10cSrcweir             nStatus |= CONTROL_STATUS_INVALID;
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir         return nStatus;
169*cdf0e10cSrcweir     }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 	//--------------------------------------------------------------------
172*cdf0e10cSrcweir     sal_Int32 ControlBorderManager::getControlColorByStatus( ControlStatus _nStatus )
173*cdf0e10cSrcweir     {
174*cdf0e10cSrcweir         // "invalid" is ranked highest
175*cdf0e10cSrcweir         if ( _nStatus & CONTROL_STATUS_INVALID )
176*cdf0e10cSrcweir             return m_nInvalidColor;
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir         // then, "focused" is more important than ...
179*cdf0e10cSrcweir         if ( _nStatus & CONTROL_STATUS_FOCUSED )
180*cdf0e10cSrcweir             return m_nFocusColor;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir         // ... "mouse over"
183*cdf0e10cSrcweir         if ( _nStatus & CONTROL_STATUS_MOUSE_HOVER )
184*cdf0e10cSrcweir             return m_nMouseHoveColor;
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir         OSL_ENSURE( sal_False, "ControlBorderManager::getControlColorByStatus: invalid status!" );
187*cdf0e10cSrcweir         return 0x00000000;
188*cdf0e10cSrcweir     }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	//--------------------------------------------------------------------
191*cdf0e10cSrcweir     void ControlBorderManager::updateBorderStyle( const Reference< XControl >& _rxControl, const Reference< XVclWindowPeer >& _rxPeer, const BorderDescriptor& _rFallback ) SAL_THROW(())
192*cdf0e10cSrcweir     {
193*cdf0e10cSrcweir         OSL_PRECOND( _rxControl.is() && _rxPeer.is(), "ControlBorderManager::updateBorderStyle: invalid parameters!" );
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir         ControlStatus nStatus = getControlStatus( _rxControl );
196*cdf0e10cSrcweir         BorderDescriptor aBorder;
197*cdf0e10cSrcweir         aBorder.nBorderType =   ( nStatus == CONTROL_STATUS_NONE )
198*cdf0e10cSrcweir                             ?   _rFallback.nBorderType
199*cdf0e10cSrcweir                             :   VisualEffect::FLAT;
200*cdf0e10cSrcweir         aBorder.nBorderColor =   ( nStatus == CONTROL_STATUS_NONE )
201*cdf0e10cSrcweir                              ?   _rFallback.nBorderColor
202*cdf0e10cSrcweir                              :   getControlColorByStatus( nStatus );
203*cdf0e10cSrcweir         setBorder( _rxPeer, aBorder );
204*cdf0e10cSrcweir     }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 	//--------------------------------------------------------------------
207*cdf0e10cSrcweir     void ControlBorderManager::determineOriginalBorderStyle( const Reference< XControl >& _rxControl, BorderDescriptor& _rData ) const
208*cdf0e10cSrcweir     {
209*cdf0e10cSrcweir         _rData = ControlData();
210*cdf0e10cSrcweir         if ( m_aFocusControl.xControl.get() == _rxControl.get() )
211*cdf0e10cSrcweir         {
212*cdf0e10cSrcweir             _rData = m_aFocusControl;
213*cdf0e10cSrcweir         }
214*cdf0e10cSrcweir         else if ( m_aMouseHoverControl.xControl.get() == _rxControl.get() )
215*cdf0e10cSrcweir         {
216*cdf0e10cSrcweir             _rData = m_aMouseHoverControl;
217*cdf0e10cSrcweir         }
218*cdf0e10cSrcweir         else
219*cdf0e10cSrcweir         {
220*cdf0e10cSrcweir             ControlBag::const_iterator aPos = m_aInvalidControls.find( _rxControl );
221*cdf0e10cSrcweir             if ( aPos != m_aInvalidControls.end() )
222*cdf0e10cSrcweir             {
223*cdf0e10cSrcweir                 _rData = *aPos;
224*cdf0e10cSrcweir             }
225*cdf0e10cSrcweir             else
226*cdf0e10cSrcweir             {
227*cdf0e10cSrcweir                 Reference< XVclWindowPeer > xPeer( _rxControl->getPeer(), UNO_QUERY );
228*cdf0e10cSrcweir                 getBorder( xPeer, _rData );
229*cdf0e10cSrcweir             }
230*cdf0e10cSrcweir         }
231*cdf0e10cSrcweir     }
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 	//--------------------------------------------------------------------
234*cdf0e10cSrcweir     void ControlBorderManager::controlStatusGained( const Reference< XInterface >& _rxControl, ControlData& _rControlData ) SAL_THROW(())
235*cdf0e10cSrcweir     {
236*cdf0e10cSrcweir         if ( _rxControl == _rControlData.xControl )
237*cdf0e10cSrcweir             // nothing to do - though suspicious
238*cdf0e10cSrcweir             return;
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir         Reference< XControl > xAsControl( _rxControl, UNO_QUERY );
241*cdf0e10cSrcweir         DBG_ASSERT( xAsControl.is(), "ControlBorderManager::controlStatusGained: invalid control!" );
242*cdf0e10cSrcweir         if ( !xAsControl.is() )
243*cdf0e10cSrcweir             return;
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir         try
246*cdf0e10cSrcweir         {
247*cdf0e10cSrcweir             Reference< XVclWindowPeer > xPeer( xAsControl->getPeer(), UNO_QUERY );
248*cdf0e10cSrcweir             if ( xPeer.is() && canColorBorder( xPeer ) )
249*cdf0e10cSrcweir             {
250*cdf0e10cSrcweir                 // remember the control and it's current border color
251*cdf0e10cSrcweir                 _rControlData.xControl.clear(); // so determineOriginalBorderStyle doesn't get confused
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir                 determineOriginalBorderStyle( xAsControl, _rControlData );
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir                 _rControlData.xControl = xAsControl;
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir                 updateBorderStyle( xAsControl, xPeer, _rControlData );
258*cdf0e10cSrcweir             }
259*cdf0e10cSrcweir         }
260*cdf0e10cSrcweir         catch( const Exception& )
261*cdf0e10cSrcweir         {
262*cdf0e10cSrcweir         	OSL_ENSURE( sal_False, "ControlBorderManager::controlStatusGained: caught an exception!" );
263*cdf0e10cSrcweir         }
264*cdf0e10cSrcweir     }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 	//--------------------------------------------------------------------
267*cdf0e10cSrcweir     void ControlBorderManager::controlStatusLost( const Reference< XInterface >& _rxControl, ControlData& _rControlData ) SAL_THROW(())
268*cdf0e10cSrcweir     {
269*cdf0e10cSrcweir         if ( _rxControl != _rControlData.xControl )
270*cdf0e10cSrcweir             // nothing to do
271*cdf0e10cSrcweir             return;
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir         OSL_PRECOND( _rControlData.xControl.is(), "ControlBorderManager::controlStatusLost: invalid control data - this will crash!" );
274*cdf0e10cSrcweir         try
275*cdf0e10cSrcweir         {
276*cdf0e10cSrcweir             Reference< XVclWindowPeer > xPeer( _rControlData.xControl->getPeer(), UNO_QUERY );
277*cdf0e10cSrcweir             if ( xPeer.is() && canColorBorder( xPeer ) )
278*cdf0e10cSrcweir             {
279*cdf0e10cSrcweir                 ControlData aPreviousStatus( _rControlData );
280*cdf0e10cSrcweir                 _rControlData = ControlData();
281*cdf0e10cSrcweir                 updateBorderStyle( aPreviousStatus.xControl, xPeer, aPreviousStatus );
282*cdf0e10cSrcweir             }
283*cdf0e10cSrcweir         }
284*cdf0e10cSrcweir         catch( const Exception& )
285*cdf0e10cSrcweir         {
286*cdf0e10cSrcweir         	OSL_ENSURE( sal_False, "ControlBorderManager::controlStatusLost: caught an exception!" );
287*cdf0e10cSrcweir         }
288*cdf0e10cSrcweir     }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir     //--------------------------------------------------------------------
291*cdf0e10cSrcweir     void ControlBorderManager::enableDynamicBorderColor( )
292*cdf0e10cSrcweir     {
293*cdf0e10cSrcweir         m_bDynamicBorderColors = true;
294*cdf0e10cSrcweir     }
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     //--------------------------------------------------------------------
297*cdf0e10cSrcweir     void ControlBorderManager::disableDynamicBorderColor( )
298*cdf0e10cSrcweir     {
299*cdf0e10cSrcweir         m_bDynamicBorderColors = false;
300*cdf0e10cSrcweir         restoreAll();
301*cdf0e10cSrcweir     }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 	//--------------------------------------------------------------------
304*cdf0e10cSrcweir     void ControlBorderManager::setStatusColor( ControlStatus _nStatus, sal_Int32 _nColor )
305*cdf0e10cSrcweir     {
306*cdf0e10cSrcweir         switch ( _nStatus )
307*cdf0e10cSrcweir         {
308*cdf0e10cSrcweir         case CONTROL_STATUS_FOCUSED:
309*cdf0e10cSrcweir             m_nFocusColor = _nColor;
310*cdf0e10cSrcweir             break;
311*cdf0e10cSrcweir         case CONTROL_STATUS_MOUSE_HOVER:
312*cdf0e10cSrcweir             m_nMouseHoveColor = _nColor;
313*cdf0e10cSrcweir             break;
314*cdf0e10cSrcweir         case CONTROL_STATUS_INVALID:
315*cdf0e10cSrcweir             m_nInvalidColor = _nColor;
316*cdf0e10cSrcweir             break;
317*cdf0e10cSrcweir         default:
318*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "ControlBorderManager::setStatusColor: invalid status!" );
319*cdf0e10cSrcweir         }
320*cdf0e10cSrcweir     }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir     //--------------------------------------------------------------------
323*cdf0e10cSrcweir     void ControlBorderManager::restoreAll()
324*cdf0e10cSrcweir     {
325*cdf0e10cSrcweir         if ( m_aFocusControl.xControl.is() )
326*cdf0e10cSrcweir             controlStatusLost( m_aFocusControl.xControl, m_aFocusControl );
327*cdf0e10cSrcweir         if ( m_aMouseHoverControl.xControl.is() )
328*cdf0e10cSrcweir             controlStatusLost( m_aMouseHoverControl.xControl, m_aMouseHoverControl );
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir         ControlBag aInvalidControls;
331*cdf0e10cSrcweir         m_aInvalidControls.swap( aInvalidControls );
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir         for ( ControlBag::const_iterator loop = aInvalidControls.begin();
334*cdf0e10cSrcweir               loop != aInvalidControls.end();
335*cdf0e10cSrcweir               ++loop
336*cdf0e10cSrcweir             )
337*cdf0e10cSrcweir         {
338*cdf0e10cSrcweir             Reference< XVclWindowPeer > xPeer( loop->xControl->getPeer(), UNO_QUERY );
339*cdf0e10cSrcweir             if ( xPeer.is() )
340*cdf0e10cSrcweir             {
341*cdf0e10cSrcweir                 updateBorderStyle( loop->xControl, xPeer, *loop );
342*cdf0e10cSrcweir                 xPeer->setProperty( FM_PROP_HELPTEXT, makeAny( loop->sOriginalHelpText ) );
343*cdf0e10cSrcweir                 setUnderline( xPeer, *loop );
344*cdf0e10cSrcweir             }
345*cdf0e10cSrcweir         }
346*cdf0e10cSrcweir     }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir 	//--------------------------------------------------------------------
349*cdf0e10cSrcweir     void ControlBorderManager::focusGained( const Reference< XInterface >& _rxControl ) SAL_THROW(())
350*cdf0e10cSrcweir     {
351*cdf0e10cSrcweir         if ( m_bDynamicBorderColors )
352*cdf0e10cSrcweir             controlStatusGained( _rxControl, m_aFocusControl );
353*cdf0e10cSrcweir     }
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 	//--------------------------------------------------------------------
356*cdf0e10cSrcweir     void ControlBorderManager::focusLost( const Reference< XInterface >& _rxControl ) SAL_THROW(())
357*cdf0e10cSrcweir     {
358*cdf0e10cSrcweir         if ( m_bDynamicBorderColors )
359*cdf0e10cSrcweir             controlStatusLost( _rxControl, m_aFocusControl );
360*cdf0e10cSrcweir     }
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir 	//--------------------------------------------------------------------
363*cdf0e10cSrcweir     void ControlBorderManager::mouseEntered( const Reference< XInterface >& _rxControl ) SAL_THROW(())
364*cdf0e10cSrcweir     {
365*cdf0e10cSrcweir         if ( m_bDynamicBorderColors )
366*cdf0e10cSrcweir             controlStatusGained( _rxControl, m_aMouseHoverControl );
367*cdf0e10cSrcweir     }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 	//--------------------------------------------------------------------
370*cdf0e10cSrcweir     void ControlBorderManager::mouseExited( const Reference< XInterface >& _rxControl ) SAL_THROW(())
371*cdf0e10cSrcweir     {
372*cdf0e10cSrcweir         if ( m_bDynamicBorderColors )
373*cdf0e10cSrcweir             controlStatusLost( _rxControl, m_aMouseHoverControl );
374*cdf0e10cSrcweir     }
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 	//--------------------------------------------------------------------
377*cdf0e10cSrcweir     void ControlBorderManager::validityChanged( const Reference< XControl >& _rxControl, const Reference< XValidatableFormComponent >& _rxValidatable ) SAL_THROW(())
378*cdf0e10cSrcweir     {
379*cdf0e10cSrcweir         try
380*cdf0e10cSrcweir         {
381*cdf0e10cSrcweir             OSL_ENSURE( _rxControl.is(), "ControlBorderManager::validityChanged: invalid control!" );
382*cdf0e10cSrcweir             OSL_ENSURE( _rxValidatable.is(), "ControlBorderManager::validityChanged: invalid validatable!" );
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir             Reference< XVclWindowPeer > xPeer( _rxControl.is() ? _rxControl->getPeer() : Reference< XWindowPeer >(), UNO_QUERY );
385*cdf0e10cSrcweir             if ( !xPeer.is() || !_rxValidatable.is() )
386*cdf0e10cSrcweir                 return;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir             ControlData aData( _rxControl );
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir             if ( _rxValidatable->isValid() )
391*cdf0e10cSrcweir             {
392*cdf0e10cSrcweir                 ControlBag::iterator aPos = m_aInvalidControls.find( aData );
393*cdf0e10cSrcweir                 if ( aPos != m_aInvalidControls.end() )
394*cdf0e10cSrcweir                 {   // invalid before, valid now
395*cdf0e10cSrcweir                     ControlData aOriginalLayout( *aPos );
396*cdf0e10cSrcweir                     m_aInvalidControls.erase( aPos );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir                     // restore all the things we used to indicate invalidity
399*cdf0e10cSrcweir                     if ( m_bDynamicBorderColors )
400*cdf0e10cSrcweir                         updateBorderStyle( _rxControl, xPeer, aOriginalLayout );
401*cdf0e10cSrcweir                     xPeer->setProperty( FM_PROP_HELPTEXT, makeAny( aOriginalLayout.sOriginalHelpText ) );
402*cdf0e10cSrcweir                     setUnderline( xPeer, aOriginalLayout );
403*cdf0e10cSrcweir                 }
404*cdf0e10cSrcweir                 return;
405*cdf0e10cSrcweir             }
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir             // we're here in the INVALID case
408*cdf0e10cSrcweir             if ( m_aInvalidControls.find( _rxControl ) == m_aInvalidControls.end() )
409*cdf0e10cSrcweir             {   // valid before, invalid now
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir                 // remember the current border
412*cdf0e10cSrcweir                 determineOriginalBorderStyle( _rxControl, aData );
413*cdf0e10cSrcweir                 // and tool tip
414*cdf0e10cSrcweir                 xPeer->getProperty( FM_PROP_HELPTEXT ) >>= aData.sOriginalHelpText;
415*cdf0e10cSrcweir                 // and font
416*cdf0e10cSrcweir                 getUnderline( xPeer, aData );
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir                 m_aInvalidControls.insert( aData );
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir                 // update the border to the new invalidity
421*cdf0e10cSrcweir                 if ( m_bDynamicBorderColors && canColorBorder( xPeer ) )
422*cdf0e10cSrcweir                     updateBorderStyle( _rxControl, xPeer, aData );
423*cdf0e10cSrcweir                 else
424*cdf0e10cSrcweir                 {
425*cdf0e10cSrcweir                     // and also the new font
426*cdf0e10cSrcweir                     setUnderline( xPeer, UnderlineDescriptor( com::sun::star::awt::FontUnderline::WAVE, m_nInvalidColor ) );
427*cdf0e10cSrcweir                 }
428*cdf0e10cSrcweir             }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir             // update the explanation for invalidity (this is always done, even if the validity did not change)
431*cdf0e10cSrcweir             Reference< XValidator > xValidator = _rxValidatable->getValidator();
432*cdf0e10cSrcweir             OSL_ENSURE( xValidator.is(), "ControlBorderManager::validityChanged: invalid, but no validator?" );
433*cdf0e10cSrcweir             ::rtl::OUString sExplainInvalidity = xValidator.is() ? xValidator->explainInvalid( _rxValidatable->getCurrentValue() ) : ::rtl::OUString();
434*cdf0e10cSrcweir             xPeer->setProperty( FM_PROP_HELPTEXT, makeAny( sExplainInvalidity ) );
435*cdf0e10cSrcweir         }
436*cdf0e10cSrcweir         catch( const Exception& )
437*cdf0e10cSrcweir         {
438*cdf0e10cSrcweir         	OSL_ENSURE( sal_False, "ControlBorderManager::validityChanged: caught an exception!" );
439*cdf0e10cSrcweir         }
440*cdf0e10cSrcweir     }
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir //........................................................................
443*cdf0e10cSrcweir } // namespace svxform
444*cdf0e10cSrcweir //........................................................................
445*cdf0e10cSrcweir 
446