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>
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 ControlHelper::ControlHelper( vcl::Window
* _pControlWindow
, sal_Int16 _nControlType
, XPropertyControl
& _rAntiImpl
, IModifyListener
* _pModifyListener
)
40 :m_pControlWindow( _pControlWindow
)
41 ,m_nControlType( _nControlType
)
42 ,m_rAntiImpl( _rAntiImpl
)
43 ,m_pModifyListener( _pModifyListener
)
46 DBG_ASSERT( m_pControlWindow
!= nullptr, "ControlHelper::ControlHelper: invalid window!" );
50 ControlHelper::~ControlHelper()
54 void SAL_CALL
ControlHelper::setControlContext( const Reference
< XPropertyControlContext
>& _controlcontext
) throw (RuntimeException
)
56 m_xContext
= _controlcontext
;
60 Reference
< XWindow
> SAL_CALL
ControlHelper::getControlWindow() throw (RuntimeException
)
62 return VCLUnoHelper::GetInterface( m_pControlWindow
);
68 void SAL_CALL
ControlHelper::notifyModifiedValue( ) throw (RuntimeException
)
70 if ( isModified() && m_xContext
.is() )
74 m_xContext
->valueChanged( &m_rAntiImpl
);
77 catch( const Exception
& )
79 DBG_UNHANDLED_EXCEPTION();
85 void SAL_CALL
ControlHelper::dispose()
87 m_pControlWindow
.disposeAndClear();
91 void ControlHelper::autoSizeWindow()
93 OSL_PRECOND( m_pControlWindow
, "ControlHelper::autoSizeWindow: no window!" );
94 if ( !m_pControlWindow
)
97 ScopedVclPtrInstance
< ComboBox
> aComboBox(m_pControlWindow
, WB_DROPDOWN
);
98 aComboBox
->SetPosSizePixel(Point(0,0), Size(100,100));
99 m_pControlWindow
->SetSizePixel(aComboBox
->GetSizePixel());
101 // TODO/UNOize: why do the controls this themselves? Shouldn't this be the task
102 // of the browser listbox/line?
106 void ControlHelper::impl_activateNextControl_nothrow() const
110 if ( m_xContext
.is() )
111 m_xContext
->activateNextControl( const_cast< XPropertyControl
* >( &m_rAntiImpl
) );
113 catch( const Exception
& )
115 DBG_UNHANDLED_EXCEPTION();
120 bool ControlHelper::handlePreNotify(NotifyEvent
& rNEvt
)
122 if (MouseNotifyEvent::KEYINPUT
== rNEvt
.GetType())
124 const vcl::KeyCode
& aKeyCode
= rNEvt
.GetKeyEvent()->GetKeyCode();
125 sal_uInt16 nKey
= aKeyCode
.GetCode();
127 if (nKey
== KEY_RETURN
&& !aKeyCode
.IsShift())
129 LoseFocusHdl(m_pControlWindow
);
130 impl_activateNextControl_nothrow();
138 IMPL_LINK( ControlHelper
, ModifiedHdl
, vcl::Window
*, /*_pWin*/ )
140 if ( m_pModifyListener
)
141 m_pModifyListener
->modified();
146 IMPL_LINK( ControlHelper
, GetFocusHdl
, vcl::Window
*, /*_pWin*/ )
150 if ( m_xContext
.is() )
151 m_xContext
->focusGained( &m_rAntiImpl
);
153 catch( const Exception
& )
155 DBG_UNHANDLED_EXCEPTION();
161 IMPL_LINK( ControlHelper
, LoseFocusHdl
, vcl::Window
*, /*_pWin*/ )
163 // TODO/UNOize: should this be outside the default control's implementations? If somebody
164 // has an own control implementation, which does *not* do this - would this be allowed?
165 // If not, then we must move this logic out of here.
166 notifyModifiedValue();
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */