1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "commoncontrol.hxx"
21 #include "pcrcommon.hxx"
22 #include <tools/debug.hxx>
23 #include <tools/diagnose_ex.h>
24 #include <vcl/combobox.hxx>
25 #include <toolkit/helper/vclunohelper.hxx>
27 //............................................................................
30 //............................................................................
32 using ::com::sun::star::uno::RuntimeException
;
33 using ::com::sun::star::uno::Reference
;
34 using ::com::sun::star::inspection::XPropertyControlContext
;
35 using ::com::sun::star::awt::XWindow
;
36 using ::com::sun::star::uno::Exception
;
37 using ::com::sun::star::inspection::XPropertyControl
;
39 //==================================================================
41 //==================================================================
42 //------------------------------------------------------------------
43 ControlHelper::ControlHelper( Window
* _pControlWindow
, sal_Int16 _nControlType
, XPropertyControl
& _rAntiImpl
, IModifyListener
* _pModifyListener
)
44 :m_pControlWindow( _pControlWindow
)
45 ,m_nControlType( _nControlType
)
46 ,m_rAntiImpl( _rAntiImpl
)
47 ,m_pModifyListener( _pModifyListener
)
48 ,m_bModified( sal_False
)
50 DBG_ASSERT( m_pControlWindow
!= NULL
, "ControlHelper::ControlHelper: invalid window!" );
53 //------------------------------------------------------------------
54 ControlHelper::~ControlHelper()
58 //--------------------------------------------------------------------
59 ::sal_Int16 SAL_CALL
ControlHelper::getControlType() throw (RuntimeException
)
61 return m_nControlType
;
64 //--------------------------------------------------------------------
65 Reference
< XPropertyControlContext
> SAL_CALL
ControlHelper::getControlContext() throw (RuntimeException
)
70 //--------------------------------------------------------------------
71 void SAL_CALL
ControlHelper::setControlContext( const Reference
< XPropertyControlContext
>& _controlcontext
) throw (RuntimeException
)
73 m_xContext
= _controlcontext
;
76 //--------------------------------------------------------------------
77 Reference
< XWindow
> SAL_CALL
ControlHelper::getControlWindow() throw (RuntimeException
)
79 return VCLUnoHelper::GetInterface( m_pControlWindow
);
82 //--------------------------------------------------------------------
83 ::sal_Bool SAL_CALL
ControlHelper::isModified( ) throw (RuntimeException
)
88 //--------------------------------------------------------------------
89 void SAL_CALL
ControlHelper::notifyModifiedValue( ) throw (RuntimeException
)
91 if ( isModified() && m_xContext
.is() )
95 m_xContext
->valueChanged( &m_rAntiImpl
);
96 m_bModified
= sal_False
;
98 catch( const Exception
& )
100 DBG_UNHANDLED_EXCEPTION();
105 //------------------------------------------------------------------
106 void SAL_CALL
ControlHelper::dispose()
108 DELETEZ( m_pControlWindow
);
111 //------------------------------------------------------------------
112 void ControlHelper::autoSizeWindow()
114 OSL_PRECOND( m_pControlWindow
, "ControlHelper::autoSizeWindow: no window!" );
115 if ( !m_pControlWindow
)
118 ComboBox
aComboBox(m_pControlWindow
, WB_DROPDOWN
);
119 aComboBox
.SetPosSizePixel(Point(0,0), Size(100,100));
120 m_pControlWindow
->SetSizePixel(aComboBox
.GetSizePixel());
122 // TODO/UNOize: why do the controls this themselves? Shouldn't this be the task
123 // of the browser listbox/line?
126 //------------------------------------------------------------------
127 void ControlHelper::impl_activateNextControl_nothrow() const
131 if ( m_xContext
.is() )
132 m_xContext
->activateNextControl( const_cast< XPropertyControl
* >( &m_rAntiImpl
) );
134 catch( const Exception
& )
136 DBG_UNHANDLED_EXCEPTION();
140 //------------------------------------------------------------------
141 bool ControlHelper::handlePreNotify(NotifyEvent
& rNEvt
)
143 if (EVENT_KEYINPUT
== rNEvt
.GetType())
145 const KeyCode
& aKeyCode
= rNEvt
.GetKeyEvent()->GetKeyCode();
146 sal_uInt16 nKey
= aKeyCode
.GetCode();
148 if (nKey
== KEY_RETURN
&& !aKeyCode
.IsShift())
150 LoseFocusHdl(m_pControlWindow
);
151 impl_activateNextControl_nothrow();
158 //------------------------------------------------------------------
159 IMPL_LINK( ControlHelper
, ModifiedHdl
, Window
*, /*_pWin*/ )
161 if ( m_pModifyListener
)
162 m_pModifyListener
->modified();
166 //------------------------------------------------------------------
167 IMPL_LINK( ControlHelper
, GetFocusHdl
, Window
*, /*_pWin*/ )
171 if ( m_xContext
.is() )
172 m_xContext
->focusGained( &m_rAntiImpl
);
174 catch( const Exception
& )
176 DBG_UNHANDLED_EXCEPTION();
181 //------------------------------------------------------------------
182 IMPL_LINK( ControlHelper
, LoseFocusHdl
, Window
*, /*_pWin*/ )
184 // TODO/UNOize: should this be outside the default control's implementations? If somebody
185 // has an own control implementation, which does *not* do this - would this be allowed?
186 // If not, then we must move this logic out of here.
187 notifyModifiedValue();
191 //............................................................................
193 //............................................................................
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */