1*2a97ec55SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2a97ec55SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2a97ec55SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2a97ec55SAndrew Rist * distributed with this work for additional information 6*2a97ec55SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2a97ec55SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2a97ec55SAndrew Rist * "License"); you may not use this file except in compliance 9*2a97ec55SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2a97ec55SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2a97ec55SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2a97ec55SAndrew Rist * software distributed under the License is distributed on an 15*2a97ec55SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2a97ec55SAndrew Rist * KIND, either express or implied. See the License for the 17*2a97ec55SAndrew Rist * specific language governing permissions and limitations 18*2a97ec55SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2a97ec55SAndrew Rist *************************************************************/ 21*2a97ec55SAndrew Rist 22*2a97ec55SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_extensions.hxx" 26cdf0e10cSrcweir #include "commoncontrol.hxx" 27cdf0e10cSrcweir #include "pcrcommon.hxx" 28cdf0e10cSrcweir #include <tools/debug.hxx> 29cdf0e10cSrcweir #include <tools/diagnose_ex.h> 30cdf0e10cSrcweir #include <vcl/combobox.hxx> 31cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir //............................................................................ 34cdf0e10cSrcweir namespace pcr 35cdf0e10cSrcweir { 36cdf0e10cSrcweir //............................................................................ 37cdf0e10cSrcweir 38cdf0e10cSrcweir /** === begin UNO using === **/ 39cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 40cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 41cdf0e10cSrcweir using ::com::sun::star::inspection::XPropertyControlContext; 42cdf0e10cSrcweir using ::com::sun::star::awt::XWindow; 43cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 44cdf0e10cSrcweir using ::com::sun::star::inspection::XPropertyControl; 45cdf0e10cSrcweir /** === end UNO using === **/ 46cdf0e10cSrcweir 47cdf0e10cSrcweir //================================================================== 48cdf0e10cSrcweir //= ControlHelper 49cdf0e10cSrcweir //================================================================== 50cdf0e10cSrcweir //------------------------------------------------------------------ ControlHelper(Window * _pControlWindow,sal_Int16 _nControlType,XPropertyControl & _rAntiImpl,IModifyListener * _pModifyListener)51cdf0e10cSrcweir ControlHelper::ControlHelper( Window* _pControlWindow, sal_Int16 _nControlType, XPropertyControl& _rAntiImpl, IModifyListener* _pModifyListener ) 52cdf0e10cSrcweir :m_pControlWindow( _pControlWindow ) 53cdf0e10cSrcweir ,m_nControlType( _nControlType ) 54cdf0e10cSrcweir ,m_rAntiImpl( _rAntiImpl ) 55cdf0e10cSrcweir ,m_pModifyListener( _pModifyListener ) 56cdf0e10cSrcweir ,m_bModified( sal_False ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir DBG_ASSERT( m_pControlWindow != NULL, "ControlHelper::ControlHelper: invalid window!" ); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir //------------------------------------------------------------------ ~ControlHelper()62cdf0e10cSrcweir ControlHelper::~ControlHelper() 63cdf0e10cSrcweir { 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir //-------------------------------------------------------------------- getControlType()67cdf0e10cSrcweir ::sal_Int16 SAL_CALL ControlHelper::getControlType() throw (RuntimeException) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir return m_nControlType; 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir //-------------------------------------------------------------------- getControlContext()73cdf0e10cSrcweir Reference< XPropertyControlContext > SAL_CALL ControlHelper::getControlContext() throw (RuntimeException) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir return m_xContext; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir //-------------------------------------------------------------------- setControlContext(const Reference<XPropertyControlContext> & _controlcontext)79cdf0e10cSrcweir void SAL_CALL ControlHelper::setControlContext( const Reference< XPropertyControlContext >& _controlcontext ) throw (RuntimeException) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir m_xContext = _controlcontext; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir //-------------------------------------------------------------------- getControlWindow()85cdf0e10cSrcweir Reference< XWindow > SAL_CALL ControlHelper::getControlWindow() throw (RuntimeException) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir return VCLUnoHelper::GetInterface( m_pControlWindow ); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir //-------------------------------------------------------------------- isModified()91cdf0e10cSrcweir ::sal_Bool SAL_CALL ControlHelper::isModified( ) throw (RuntimeException) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir return m_bModified; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir //-------------------------------------------------------------------- notifyModifiedValue()97cdf0e10cSrcweir void SAL_CALL ControlHelper::notifyModifiedValue( ) throw (RuntimeException) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir if ( isModified() && m_xContext.is() ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir try 102cdf0e10cSrcweir { 103cdf0e10cSrcweir m_xContext->valueChanged( &m_rAntiImpl ); 104cdf0e10cSrcweir m_bModified = sal_False; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir catch( const Exception& ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir } 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir //------------------------------------------------------------------ dispose()114cdf0e10cSrcweir void SAL_CALL ControlHelper::dispose() 115cdf0e10cSrcweir { 116cdf0e10cSrcweir DELETEZ( m_pControlWindow ); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir //------------------------------------------------------------------ autoSizeWindow()120cdf0e10cSrcweir void ControlHelper::autoSizeWindow() 121cdf0e10cSrcweir { 122cdf0e10cSrcweir OSL_PRECOND( m_pControlWindow, "ControlHelper::autoSizeWindow: no window!" ); 123cdf0e10cSrcweir if ( !m_pControlWindow ) 124cdf0e10cSrcweir return; 125cdf0e10cSrcweir 126cdf0e10cSrcweir ComboBox aComboBox(m_pControlWindow, WB_DROPDOWN); 127cdf0e10cSrcweir aComboBox.SetPosSizePixel(Point(0,0), Size(100,100)); 128cdf0e10cSrcweir m_pControlWindow->SetSizePixel(aComboBox.GetSizePixel()); 129cdf0e10cSrcweir 130cdf0e10cSrcweir // TODO/UNOize: why do the controls this themselves? Shouldn't this be the task 131cdf0e10cSrcweir // of the the browser listbox/line? 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir //------------------------------------------------------------------ impl_activateNextControl_nothrow() const135cdf0e10cSrcweir void ControlHelper::impl_activateNextControl_nothrow() const 136cdf0e10cSrcweir { 137cdf0e10cSrcweir try 138cdf0e10cSrcweir { 139cdf0e10cSrcweir if ( m_xContext.is() ) 140cdf0e10cSrcweir m_xContext->activateNextControl( const_cast< XPropertyControl* >( &m_rAntiImpl ) ); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir catch( const Exception& ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir //------------------------------------------------------------------ handlePreNotify(NotifyEvent & rNEvt)149cdf0e10cSrcweir bool ControlHelper::handlePreNotify(NotifyEvent& rNEvt) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir if (EVENT_KEYINPUT == rNEvt.GetType()) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir const KeyCode& aKeyCode = rNEvt.GetKeyEvent()->GetKeyCode(); 154cdf0e10cSrcweir sal_uInt16 nKey = aKeyCode.GetCode(); 155cdf0e10cSrcweir 156cdf0e10cSrcweir if (nKey == KEY_RETURN && !aKeyCode.IsShift()) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir LoseFocusHdl(m_pControlWindow); 159cdf0e10cSrcweir impl_activateNextControl_nothrow(); 160cdf0e10cSrcweir return true; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir } 163cdf0e10cSrcweir return false; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir //------------------------------------------------------------------ 167cdf0e10cSrcweir IMPL_LINK( ControlHelper, ModifiedHdl, Window*, /*_pWin*/ ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir if ( m_pModifyListener ) 170cdf0e10cSrcweir m_pModifyListener->modified(); 171cdf0e10cSrcweir return 0; 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir //------------------------------------------------------------------ 175cdf0e10cSrcweir IMPL_LINK( ControlHelper, GetFocusHdl, Window*, /*_pWin*/ ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir try 178cdf0e10cSrcweir { 179cdf0e10cSrcweir if ( m_xContext.is() ) 180cdf0e10cSrcweir m_xContext->focusGained( &m_rAntiImpl ); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir catch( const Exception& ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir return 0; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir //------------------------------------------------------------------ 190cdf0e10cSrcweir IMPL_LINK( ControlHelper, LoseFocusHdl, Window*, /*_pWin*/ ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir // TODO/UNOize: should this be outside the default control's implementations? If somebody 193cdf0e10cSrcweir // has an own control implementation, which does *not* do this - would this be allowed? 194cdf0e10cSrcweir // If not, then we must move this logic out of here. 195cdf0e10cSrcweir notifyModifiedValue(); 196cdf0e10cSrcweir return 0; 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir //............................................................................ 200cdf0e10cSrcweir } // namespace pcr 201cdf0e10cSrcweir //............................................................................ 202cdf0e10cSrcweir 203