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_dbaccess.hxx" 30 #ifndef DBAUI_COLUMNPEER_HXX 31 #include "ColumnPeer.hxx" 32 #endif 33 #ifndef DBAUI_COLUMNCONTROLWINDOW_HXX 34 #include "ColumnControlWindow.hxx" 35 #endif 36 #ifndef _SV_SVAPP_HXX 37 #include <vcl/svapp.hxx> 38 #endif 39 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC 40 #include "dbustrings.hrc" 41 #endif 42 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX 43 #include "FieldDescriptions.hxx" 44 #endif 45 46 //......................................................................... 47 namespace dbaui 48 { 49 //......................................................................... 50 using namespace ::com::sun::star::awt; 51 using namespace ::com::sun::star::uno; 52 using namespace ::com::sun::star::beans; 53 using namespace ::com::sun::star::lang; 54 using namespace ::com::sun::star::sdbc; 55 56 OColumnPeer::OColumnPeer(Window* _pParent,const Reference<XMultiServiceFactory>& _rxFactory) 57 :m_xORB(_rxFactory) 58 ,m_pActFieldDescr(NULL) 59 { 60 osl_incrementInterlockedCount( &m_refCount ); 61 { 62 OColumnControlWindow* pFieldControl = new OColumnControlWindow(_pParent,m_xORB); 63 pFieldControl->SetComponentInterface(this); 64 pFieldControl->Show(); 65 } 66 osl_decrementInterlockedCount( &m_refCount ); 67 } 68 // ----------------------------------------------------------------------------- 69 void OColumnPeer::setEditWidth(sal_Int32 _nWidth) 70 { 71 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 72 73 OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() ); 74 if ( pFieldControl ) 75 { 76 pFieldControl->setEditWidth(_nWidth); 77 } 78 } 79 // ----------------------------------------------------------------------------- 80 void OColumnPeer::setColumn(const Reference< XPropertySet>& _xColumn) 81 { 82 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 83 84 OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() ); 85 if ( pFieldControl ) 86 { 87 if ( m_pActFieldDescr ) 88 { 89 delete m_pActFieldDescr; 90 m_pActFieldDescr = NULL; 91 } 92 if ( _xColumn.is() ) 93 { 94 sal_Int32 nType = 0; 95 sal_Int32 nScale = 0; 96 sal_Int32 nPrecision = 0; 97 sal_Bool bAutoIncrement = sal_False; 98 ::rtl::OUString sTypeName; 99 100 try 101 { 102 // get the properties from the column 103 _xColumn->getPropertyValue(PROPERTY_TYPENAME) >>= sTypeName; 104 _xColumn->getPropertyValue(PROPERTY_TYPE) >>= nType; 105 _xColumn->getPropertyValue(PROPERTY_SCALE) >>= nScale; 106 _xColumn->getPropertyValue(PROPERTY_PRECISION) >>= nPrecision; 107 _xColumn->getPropertyValue(PROPERTY_ISAUTOINCREMENT) >>= bAutoIncrement; 108 } 109 catch(Exception) 110 { 111 } 112 113 m_pActFieldDescr = new OFieldDescription(_xColumn,sal_True); 114 // search for type 115 ::rtl::OUString sCreateParam(RTL_CONSTASCII_USTRINGPARAM("x")); 116 sal_Bool bForce; 117 TOTypeInfoSP pTypeInfo = ::dbaui::getTypeInfoFromType(*pFieldControl->getTypeInfo(),nType,sTypeName,sCreateParam,nPrecision,nScale,bAutoIncrement,bForce); 118 if ( !pTypeInfo.get() ) 119 pTypeInfo = pFieldControl->getDefaultTyp(); 120 121 m_pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False); 122 m_xColumn = _xColumn; 123 } 124 pFieldControl->DisplayData(m_pActFieldDescr); 125 } 126 } 127 // ----------------------------------------------------------------------------- 128 void OColumnPeer::setConnection(const Reference< XConnection>& _xCon) 129 { 130 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 131 OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() ); 132 if ( pFieldControl ) 133 pFieldControl->setConnection(_xCon); 134 } 135 //------------------------------------------------------------------------------ 136 void OColumnPeer::setProperty( const ::rtl::OUString& _rPropertyName, const Any& Value) throw( RuntimeException ) 137 { 138 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 139 140 if ( 0 == _rPropertyName.compareToAscii( PROPERTY_COLUMN ) ) 141 { 142 Reference<XPropertySet> xProp(Value,UNO_QUERY); 143 setColumn(xProp); 144 } 145 else if ( 0 == _rPropertyName.compareToAscii( PROPERTY_ACTIVE_CONNECTION ) ) 146 { 147 Reference<XConnection> xCon(Value,UNO_QUERY); 148 setConnection(xCon); 149 } 150 else 151 VCLXWindow::setProperty(_rPropertyName,Value); 152 } 153 // ----------------------------------------------------------------------------- 154 Any OColumnPeer::getProperty( const ::rtl::OUString& _rPropertyName ) throw( RuntimeException ) 155 { 156 Any aProp; 157 OFieldDescControl* pFieldControl = static_cast<OFieldDescControl*>( GetWindow() ); 158 if ( pFieldControl && 0 == _rPropertyName.compareToAscii( PROPERTY_COLUMN ) ) 159 { 160 aProp <<= m_xColumn; 161 } 162 else if ( pFieldControl && 0 == _rPropertyName.compareToAscii( PROPERTY_ACTIVE_CONNECTION ) ) 163 { 164 aProp <<= pFieldControl->getConnection(); 165 } 166 else 167 aProp = VCLXWindow::getProperty(_rPropertyName); 168 return aProp; 169 } 170 //......................................................................... 171 } // namespace dbaui 172 //......................................................................... 173