1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_extensions.hxx"
31 #include "commoncontrol.hxx"
32 #include "pcrcommon.hxx"
33 #include <tools/debug.hxx>
34 #include <tools/diagnose_ex.h>
35 #include <vcl/combobox.hxx>
36 #include <toolkit/helper/vclunohelper.hxx>
38 //............................................................................
41 //............................................................................
43 /** === begin UNO using === **/
44 using ::com::sun::star::uno::RuntimeException
;
45 using ::com::sun::star::uno::Reference
;
46 using ::com::sun::star::inspection::XPropertyControlContext
;
47 using ::com::sun::star::awt::XWindow
;
48 using ::com::sun::star::uno::Exception
;
49 using ::com::sun::star::inspection::XPropertyControl
;
50 /** === end UNO using === **/
52 //==================================================================
54 //==================================================================
55 //------------------------------------------------------------------
56 ControlHelper::ControlHelper( Window
* _pControlWindow
, sal_Int16 _nControlType
, XPropertyControl
& _rAntiImpl
, IModifyListener
* _pModifyListener
)
57 :m_pControlWindow( _pControlWindow
)
58 ,m_nControlType( _nControlType
)
59 ,m_rAntiImpl( _rAntiImpl
)
60 ,m_pModifyListener( _pModifyListener
)
61 ,m_bModified( sal_False
)
63 DBG_ASSERT( m_pControlWindow
!= NULL
, "ControlHelper::ControlHelper: invalid window!" );
66 //------------------------------------------------------------------
67 ControlHelper::~ControlHelper()
71 //--------------------------------------------------------------------
72 ::sal_Int16 SAL_CALL
ControlHelper::getControlType() throw (RuntimeException
)
74 return m_nControlType
;
77 //--------------------------------------------------------------------
78 Reference
< XPropertyControlContext
> SAL_CALL
ControlHelper::getControlContext() throw (RuntimeException
)
83 //--------------------------------------------------------------------
84 void SAL_CALL
ControlHelper::setControlContext( const Reference
< XPropertyControlContext
>& _controlcontext
) throw (RuntimeException
)
86 m_xContext
= _controlcontext
;
89 //--------------------------------------------------------------------
90 Reference
< XWindow
> SAL_CALL
ControlHelper::getControlWindow() throw (RuntimeException
)
92 return VCLUnoHelper::GetInterface( m_pControlWindow
);
95 //--------------------------------------------------------------------
96 ::sal_Bool SAL_CALL
ControlHelper::isModified( ) throw (RuntimeException
)
101 //--------------------------------------------------------------------
102 void SAL_CALL
ControlHelper::notifyModifiedValue( ) throw (RuntimeException
)
104 if ( isModified() && m_xContext
.is() )
108 m_xContext
->valueChanged( &m_rAntiImpl
);
109 m_bModified
= sal_False
;
111 catch( const Exception
& )
113 DBG_UNHANDLED_EXCEPTION();
118 //------------------------------------------------------------------
119 void SAL_CALL
ControlHelper::dispose()
121 DELETEZ( m_pControlWindow
);
124 //------------------------------------------------------------------
125 void ControlHelper::autoSizeWindow()
127 OSL_PRECOND( m_pControlWindow
, "ControlHelper::autoSizeWindow: no window!" );
128 if ( !m_pControlWindow
)
131 ComboBox
aComboBox(m_pControlWindow
, WB_DROPDOWN
);
132 aComboBox
.SetPosSizePixel(Point(0,0), Size(100,100));
133 m_pControlWindow
->SetSizePixel(aComboBox
.GetSizePixel());
135 // TODO/UNOize: why do the controls this themselves? Shouldn't this be the task
136 // of the the browser listbox/line?
139 //------------------------------------------------------------------
140 void ControlHelper::impl_activateNextControl_nothrow() const
144 if ( m_xContext
.is() )
145 m_xContext
->activateNextControl( const_cast< XPropertyControl
* >( &m_rAntiImpl
) );
147 catch( const Exception
& )
149 DBG_UNHANDLED_EXCEPTION();
153 //------------------------------------------------------------------
154 bool ControlHelper::handlePreNotify(NotifyEvent
& rNEvt
)
156 if (EVENT_KEYINPUT
== rNEvt
.GetType())
158 const KeyCode
& aKeyCode
= rNEvt
.GetKeyEvent()->GetKeyCode();
159 sal_uInt16 nKey
= aKeyCode
.GetCode();
161 if (nKey
== KEY_RETURN
&& !aKeyCode
.IsShift())
163 LoseFocusHdl(m_pControlWindow
);
164 impl_activateNextControl_nothrow();
171 //------------------------------------------------------------------
172 IMPL_LINK( ControlHelper
, ModifiedHdl
, Window
*, /*_pWin*/ )
174 if ( m_pModifyListener
)
175 m_pModifyListener
->modified();
179 //------------------------------------------------------------------
180 IMPL_LINK( ControlHelper
, GetFocusHdl
, Window
*, /*_pWin*/ )
184 if ( m_xContext
.is() )
185 m_xContext
->focusGained( &m_rAntiImpl
);
187 catch( const Exception
& )
189 DBG_UNHANDLED_EXCEPTION();
194 //------------------------------------------------------------------
195 IMPL_LINK( ControlHelper
, LoseFocusHdl
, Window
*, /*_pWin*/ )
197 // TODO/UNOize: should this be outside the default control's implementations? If somebody
198 // has an own control implementation, which does *not* do this - would this be allowed?
199 // If not, then we must move this logic out of here.
200 notifyModifiedValue();
204 //............................................................................
206 //............................................................................
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */