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