1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 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> 36 37 //............................................................................ 38 namespace pcr 39 { 40 //............................................................................ 41 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 === **/ 50 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 ) 61 { 62 DBG_ASSERT( m_pControlWindow != NULL, "ControlHelper::ControlHelper: invalid window!" ); 63 } 64 65 //------------------------------------------------------------------ 66 ControlHelper::~ControlHelper() 67 { 68 } 69 70 //-------------------------------------------------------------------- 71 ::sal_Int16 SAL_CALL ControlHelper::getControlType() throw (RuntimeException) 72 { 73 return m_nControlType; 74 } 75 76 //-------------------------------------------------------------------- 77 Reference< XPropertyControlContext > SAL_CALL ControlHelper::getControlContext() throw (RuntimeException) 78 { 79 return m_xContext; 80 } 81 82 //-------------------------------------------------------------------- 83 void SAL_CALL ControlHelper::setControlContext( const Reference< XPropertyControlContext >& _controlcontext ) throw (RuntimeException) 84 { 85 m_xContext = _controlcontext; 86 } 87 88 //-------------------------------------------------------------------- 89 Reference< XWindow > SAL_CALL ControlHelper::getControlWindow() throw (RuntimeException) 90 { 91 return VCLUnoHelper::GetInterface( m_pControlWindow ); 92 } 93 94 //-------------------------------------------------------------------- 95 ::sal_Bool SAL_CALL ControlHelper::isModified( ) throw (RuntimeException) 96 { 97 return m_bModified; 98 } 99 100 //-------------------------------------------------------------------- 101 void SAL_CALL ControlHelper::notifyModifiedValue( ) throw (RuntimeException) 102 { 103 if ( isModified() && m_xContext.is() ) 104 { 105 try 106 { 107 m_xContext->valueChanged( &m_rAntiImpl ); 108 m_bModified = sal_False; 109 } 110 catch( const Exception& ) 111 { 112 DBG_UNHANDLED_EXCEPTION(); 113 } 114 } 115 } 116 117 //------------------------------------------------------------------ 118 void SAL_CALL ControlHelper::dispose() 119 { 120 DELETEZ( m_pControlWindow ); 121 } 122 123 //------------------------------------------------------------------ 124 void ControlHelper::autoSizeWindow() 125 { 126 OSL_PRECOND( m_pControlWindow, "ControlHelper::autoSizeWindow: no window!" ); 127 if ( !m_pControlWindow ) 128 return; 129 130 ComboBox aComboBox(m_pControlWindow, WB_DROPDOWN); 131 aComboBox.SetPosSizePixel(Point(0,0), Size(100,100)); 132 m_pControlWindow->SetSizePixel(aComboBox.GetSizePixel()); 133 134 // TODO/UNOize: why do the controls this themselves? Shouldn't this be the task 135 // of the the browser listbox/line? 136 } 137 138 //------------------------------------------------------------------ 139 void ControlHelper::impl_activateNextControl_nothrow() const 140 { 141 try 142 { 143 if ( m_xContext.is() ) 144 m_xContext->activateNextControl( const_cast< XPropertyControl* >( &m_rAntiImpl ) ); 145 } 146 catch( const Exception& ) 147 { 148 DBG_UNHANDLED_EXCEPTION(); 149 } 150 } 151 152 //------------------------------------------------------------------ 153 bool ControlHelper::handlePreNotify(NotifyEvent& rNEvt) 154 { 155 if (EVENT_KEYINPUT == rNEvt.GetType()) 156 { 157 const KeyCode& aKeyCode = rNEvt.GetKeyEvent()->GetKeyCode(); 158 sal_uInt16 nKey = aKeyCode.GetCode(); 159 160 if (nKey == KEY_RETURN && !aKeyCode.IsShift()) 161 { 162 LoseFocusHdl(m_pControlWindow); 163 impl_activateNextControl_nothrow(); 164 return true; 165 } 166 } 167 return false; 168 } 169 170 //------------------------------------------------------------------ 171 IMPL_LINK( ControlHelper, ModifiedHdl, Window*, /*_pWin*/ ) 172 { 173 if ( m_pModifyListener ) 174 m_pModifyListener->modified(); 175 return 0; 176 } 177 178 //------------------------------------------------------------------ 179 IMPL_LINK( ControlHelper, GetFocusHdl, Window*, /*_pWin*/ ) 180 { 181 try 182 { 183 if ( m_xContext.is() ) 184 m_xContext->focusGained( &m_rAntiImpl ); 185 } 186 catch( const Exception& ) 187 { 188 DBG_UNHANDLED_EXCEPTION(); 189 } 190 return 0; 191 } 192 193 //------------------------------------------------------------------ 194 IMPL_LINK( ControlHelper, LoseFocusHdl, Window*, /*_pWin*/ ) 195 { 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; 201 } 202 203 //............................................................................ 204 } // namespace pcr 205 //............................................................................ 206 207