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