masterfix DEV300: #i10000# build fix
[LibreOffice.git] / extensions / source / propctrlr / commoncontrol.cxx
blob647b8b92c480a5aa059ed006a8a440e4322132d1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "commoncontrol.hxx"
31 #include "pcrcommon.hxx"
32 #include <tools/debug.hxx>
33 #include <tools/diagnose_ex.h>
34 #include <vcl/combobox.hxx>
35 #include <toolkit/helper/vclunohelper.hxx>
37 //............................................................................
38 namespace pcr
40 //............................................................................
42 /** === begin UNO using === **/
43 using ::com::sun::star::uno::RuntimeException;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::inspection::XPropertyControlContext;
46 using ::com::sun::star::awt::XWindow;
47 using ::com::sun::star::uno::Exception;
48 using ::com::sun::star::inspection::XPropertyControl;
49 /** === end UNO using === **/
51 //==================================================================
52 //= ControlHelper
53 //==================================================================
54 //------------------------------------------------------------------
55 ControlHelper::ControlHelper( Window* _pControlWindow, sal_Int16 _nControlType, XPropertyControl& _rAntiImpl, IModifyListener* _pModifyListener )
56 :m_pControlWindow( _pControlWindow )
57 ,m_nControlType( _nControlType )
58 ,m_rAntiImpl( _rAntiImpl )
59 ,m_pModifyListener( _pModifyListener )
60 ,m_bModified( sal_False )
62 DBG_ASSERT( m_pControlWindow != NULL, "ControlHelper::ControlHelper: invalid window!" );
65 //------------------------------------------------------------------
66 ControlHelper::~ControlHelper()
70 //--------------------------------------------------------------------
71 ::sal_Int16 SAL_CALL ControlHelper::getControlType() throw (RuntimeException)
73 return m_nControlType;
76 //--------------------------------------------------------------------
77 Reference< XPropertyControlContext > SAL_CALL ControlHelper::getControlContext() throw (RuntimeException)
79 return m_xContext;
82 //--------------------------------------------------------------------
83 void SAL_CALL ControlHelper::setControlContext( const Reference< XPropertyControlContext >& _controlcontext ) throw (RuntimeException)
85 m_xContext = _controlcontext;
88 //--------------------------------------------------------------------
89 Reference< XWindow > SAL_CALL ControlHelper::getControlWindow() throw (RuntimeException)
91 return VCLUnoHelper::GetInterface( m_pControlWindow );
94 //--------------------------------------------------------------------
95 ::sal_Bool SAL_CALL ControlHelper::isModified( ) throw (RuntimeException)
97 return m_bModified;
100 //--------------------------------------------------------------------
101 void SAL_CALL ControlHelper::notifyModifiedValue( ) throw (RuntimeException)
103 if ( isModified() && m_xContext.is() )
107 m_xContext->valueChanged( &m_rAntiImpl );
108 m_bModified = sal_False;
110 catch( const Exception& )
112 DBG_UNHANDLED_EXCEPTION();
117 //------------------------------------------------------------------
118 void SAL_CALL ControlHelper::dispose()
120 DELETEZ( m_pControlWindow );
123 //------------------------------------------------------------------
124 void ControlHelper::autoSizeWindow()
126 OSL_PRECOND( m_pControlWindow, "ControlHelper::autoSizeWindow: no window!" );
127 if ( !m_pControlWindow )
128 return;
130 ComboBox aComboBox(m_pControlWindow, WB_DROPDOWN);
131 aComboBox.SetPosSizePixel(Point(0,0), Size(100,100));
132 m_pControlWindow->SetSizePixel(aComboBox.GetSizePixel());
134 // TODO/UNOize: why do the controls this themselves? Shouldn't this be the task
135 // of the the browser listbox/line?
138 //------------------------------------------------------------------
139 void ControlHelper::impl_activateNextControl_nothrow() const
143 if ( m_xContext.is() )
144 m_xContext->activateNextControl( const_cast< XPropertyControl* >( &m_rAntiImpl ) );
146 catch( const Exception& )
148 DBG_UNHANDLED_EXCEPTION();
152 //------------------------------------------------------------------
153 bool ControlHelper::handlePreNotify(NotifyEvent& rNEvt)
155 if (EVENT_KEYINPUT == rNEvt.GetType())
157 const KeyCode& aKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
158 sal_uInt16 nKey = aKeyCode.GetCode();
160 if (nKey == KEY_RETURN && !aKeyCode.IsShift())
162 LoseFocusHdl(m_pControlWindow);
163 impl_activateNextControl_nothrow();
164 return true;
167 return false;
170 //------------------------------------------------------------------
171 IMPL_LINK( ControlHelper, ModifiedHdl, Window*, /*_pWin*/ )
173 if ( m_pModifyListener )
174 m_pModifyListener->modified();
175 return 0;
178 //------------------------------------------------------------------
179 IMPL_LINK( ControlHelper, GetFocusHdl, Window*, /*_pWin*/ )
183 if ( m_xContext.is() )
184 m_xContext->focusGained( &m_rAntiImpl );
186 catch( const Exception& )
188 DBG_UNHANDLED_EXCEPTION();
190 return 0;
193 //------------------------------------------------------------------
194 IMPL_LINK( ControlHelper, LoseFocusHdl, Window*, /*_pWin*/ )
196 // TODO/UNOize: should this be outside the default control's implementations? If somebody
197 // has an own control implementation, which does *not* do this - would this be allowed?
198 // If not, then we must move this logic out of here.
199 notifyModifiedValue();
200 return 0;
203 //............................................................................
204 } // namespace pcr
205 //............................................................................