1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: commoncontrol.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "commoncontrol.hxx"
34 #include "pcrcommon.hxx"
35 #include <tools/debug.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <vcl/combobox.hxx>
38 #include <toolkit/helper/vclunohelper.hxx>
40 //............................................................................
43 //............................................................................
45 /** === begin UNO using === **/
46 using ::com::sun::star::uno::RuntimeException
;
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::inspection::XPropertyControlContext
;
49 using ::com::sun::star::awt::XWindow
;
50 using ::com::sun::star::uno::Exception
;
51 using ::com::sun::star::inspection::XPropertyControl
;
52 /** === end UNO using === **/
54 //==================================================================
56 //==================================================================
57 //------------------------------------------------------------------
58 ControlHelper::ControlHelper( Window
* _pControlWindow
, sal_Int16 _nControlType
, XPropertyControl
& _rAntiImpl
, IModifyListener
* _pModifyListener
)
59 :m_pControlWindow( _pControlWindow
)
60 ,m_nControlType( _nControlType
)
61 ,m_rAntiImpl( _rAntiImpl
)
62 ,m_pModifyListener( _pModifyListener
)
63 ,m_bModified( sal_False
)
65 DBG_ASSERT( m_pControlWindow
!= NULL
, "ControlHelper::ControlHelper: invalid window!" );
68 //------------------------------------------------------------------
69 ControlHelper::~ControlHelper()
73 //--------------------------------------------------------------------
74 ::sal_Int16 SAL_CALL
ControlHelper::getControlType() throw (RuntimeException
)
76 return m_nControlType
;
79 //--------------------------------------------------------------------
80 Reference
< XPropertyControlContext
> SAL_CALL
ControlHelper::getControlContext() throw (RuntimeException
)
85 //--------------------------------------------------------------------
86 void SAL_CALL
ControlHelper::setControlContext( const Reference
< XPropertyControlContext
>& _controlcontext
) throw (RuntimeException
)
88 m_xContext
= _controlcontext
;
91 //--------------------------------------------------------------------
92 Reference
< XWindow
> SAL_CALL
ControlHelper::getControlWindow() throw (RuntimeException
)
94 return VCLUnoHelper::GetInterface( m_pControlWindow
);
97 //--------------------------------------------------------------------
98 ::sal_Bool SAL_CALL
ControlHelper::isModified( ) throw (RuntimeException
)
103 //--------------------------------------------------------------------
104 void SAL_CALL
ControlHelper::notifyModifiedValue( ) throw (RuntimeException
)
106 if ( isModified() && m_xContext
.is() )
110 m_xContext
->valueChanged( &m_rAntiImpl
);
111 m_bModified
= sal_False
;
113 catch( const Exception
& )
115 DBG_UNHANDLED_EXCEPTION();
120 //------------------------------------------------------------------
121 void SAL_CALL
ControlHelper::dispose()
123 DELETEZ( m_pControlWindow
);
126 //------------------------------------------------------------------
127 void ControlHelper::autoSizeWindow()
129 OSL_PRECOND( m_pControlWindow
, "ControlHelper::autoSizeWindow: no window!" );
130 if ( !m_pControlWindow
)
133 ComboBox
aComboBox(m_pControlWindow
, WB_DROPDOWN
);
134 aComboBox
.SetPosSizePixel(Point(0,0), Size(100,100));
135 m_pControlWindow
->SetSizePixel(aComboBox
.GetSizePixel());
137 // TODO/UNOize: why do the controls this themselves? Shouldn't this be the task
138 // of the the browser listbox/line?
141 //------------------------------------------------------------------
142 void ControlHelper::impl_activateNextControl_nothrow() const
146 if ( m_xContext
.is() )
147 m_xContext
->activateNextControl( const_cast< XPropertyControl
* >( &m_rAntiImpl
) );
149 catch( const Exception
& )
151 DBG_UNHANDLED_EXCEPTION();
155 //------------------------------------------------------------------
156 bool ControlHelper::handlePreNotify(NotifyEvent
& rNEvt
)
158 if (EVENT_KEYINPUT
== rNEvt
.GetType())
160 const KeyCode
& aKeyCode
= rNEvt
.GetKeyEvent()->GetKeyCode();
161 sal_uInt16 nKey
= aKeyCode
.GetCode();
163 if (nKey
== KEY_RETURN
&& !aKeyCode
.IsShift())
165 LoseFocusHdl(m_pControlWindow
);
166 impl_activateNextControl_nothrow();
173 //------------------------------------------------------------------
174 IMPL_LINK( ControlHelper
, ModifiedHdl
, Window
*, /*_pWin*/ )
176 if ( m_pModifyListener
)
177 m_pModifyListener
->modified();
181 //------------------------------------------------------------------
182 IMPL_LINK( ControlHelper
, GetFocusHdl
, Window
*, /*_pWin*/ )
186 if ( m_xContext
.is() )
187 m_xContext
->focusGained( &m_rAntiImpl
);
189 catch( const Exception
& )
191 DBG_UNHANDLED_EXCEPTION();
196 //------------------------------------------------------------------
197 IMPL_LINK( ControlHelper
, LoseFocusHdl
, Window
*, /*_pWin*/ )
199 // TODO/UNOize: should this be outside the default control's implementations? If somebody
200 // has an own control implementation, which does *not* do this - would this be allowed?
201 // If not, then we must move this logic out of here.
202 notifyModifiedValue();
206 //............................................................................
208 //............................................................................