merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / uno / ColumnPeer.cxx
blob48960e78ad5f31cfb3a1fc2a6ac1e8cc2dd5a18c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ColumnPeer.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_COLUMNPEER_HXX
34 #include "ColumnPeer.hxx"
35 #endif
36 #ifndef DBAUI_COLUMNCONTROLWINDOW_HXX
37 #include "ColumnControlWindow.hxx"
38 #endif
39 #ifndef _SV_SVAPP_HXX
40 #include <vcl/svapp.hxx>
41 #endif
42 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
43 #include "dbustrings.hrc"
44 #endif
45 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
46 #include "FieldDescriptions.hxx"
47 #endif
49 //.........................................................................
50 namespace dbaui
52 //.........................................................................
53 using namespace ::com::sun::star::awt;
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::beans;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::sdbc;
59 OColumnPeer::OColumnPeer(Window* _pParent,const Reference<XMultiServiceFactory>& _rxFactory)
60 :m_xORB(_rxFactory)
61 ,m_pActFieldDescr(NULL)
63 osl_incrementInterlockedCount( &m_refCount );
65 OColumnControlWindow* pFieldControl = new OColumnControlWindow(_pParent,m_xORB);
66 pFieldControl->SetComponentInterface(this);
67 pFieldControl->Show();
69 osl_decrementInterlockedCount( &m_refCount );
71 // -----------------------------------------------------------------------------
72 void OColumnPeer::setEditWidth(sal_Int32 _nWidth)
74 ::vos::OGuard aGuard( Application::GetSolarMutex() );
76 OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
77 if ( pFieldControl )
79 pFieldControl->setEditWidth(_nWidth);
82 // -----------------------------------------------------------------------------
83 void OColumnPeer::setColumn(const Reference< XPropertySet>& _xColumn)
85 ::vos::OGuard aGuard( Application::GetSolarMutex() );
87 OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
88 if ( pFieldControl )
90 if ( m_pActFieldDescr )
92 delete m_pActFieldDescr;
93 m_pActFieldDescr = NULL;
95 if ( _xColumn.is() )
97 sal_Int32 nType = 0;
98 sal_Int32 nScale = 0;
99 sal_Int32 nPrecision = 0;
100 sal_Bool bAutoIncrement = sal_False;
101 ::rtl::OUString sTypeName;
105 // get the properties from the column
106 _xColumn->getPropertyValue(PROPERTY_TYPENAME) >>= sTypeName;
107 _xColumn->getPropertyValue(PROPERTY_TYPE) >>= nType;
108 _xColumn->getPropertyValue(PROPERTY_SCALE) >>= nScale;
109 _xColumn->getPropertyValue(PROPERTY_PRECISION) >>= nPrecision;
110 _xColumn->getPropertyValue(PROPERTY_ISAUTOINCREMENT) >>= bAutoIncrement;
112 catch(Exception)
116 m_pActFieldDescr = new OFieldDescription(_xColumn,sal_True);
117 // search for type
118 ::rtl::OUString sCreateParam(RTL_CONSTASCII_USTRINGPARAM("x"));
119 sal_Bool bForce;
120 TOTypeInfoSP pTypeInfo = ::dbaui::getTypeInfoFromType(*pFieldControl->getTypeInfo(),nType,sTypeName,sCreateParam,nPrecision,nScale,bAutoIncrement,bForce);
121 if ( !pTypeInfo.get() )
122 pTypeInfo = pFieldControl->getDefaultTyp();
124 m_pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False);
125 m_xColumn = _xColumn;
127 pFieldControl->DisplayData(m_pActFieldDescr);
130 // -----------------------------------------------------------------------------
131 void OColumnPeer::setConnection(const Reference< XConnection>& _xCon)
133 ::vos::OGuard aGuard( Application::GetSolarMutex() );
134 OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
135 if ( pFieldControl )
136 pFieldControl->setConnection(_xCon);
138 //------------------------------------------------------------------------------
139 void OColumnPeer::setProperty( const ::rtl::OUString& _rPropertyName, const Any& Value) throw( RuntimeException )
141 ::vos::OGuard aGuard( Application::GetSolarMutex() );
143 if ( 0 == _rPropertyName.compareToAscii( PROPERTY_COLUMN ) )
145 Reference<XPropertySet> xProp(Value,UNO_QUERY);
146 setColumn(xProp);
148 else if ( 0 == _rPropertyName.compareToAscii( PROPERTY_ACTIVE_CONNECTION ) )
150 Reference<XConnection> xCon(Value,UNO_QUERY);
151 setConnection(xCon);
153 else
154 VCLXWindow::setProperty(_rPropertyName,Value);
156 // -----------------------------------------------------------------------------
157 Any OColumnPeer::getProperty( const ::rtl::OUString& _rPropertyName ) throw( RuntimeException )
159 Any aProp;
160 OFieldDescControl* pFieldControl = static_cast<OFieldDescControl*>( GetWindow() );
161 if ( pFieldControl && 0 == _rPropertyName.compareToAscii( PROPERTY_COLUMN ) )
163 aProp <<= m_xColumn;
165 else if ( pFieldControl && 0 == _rPropertyName.compareToAscii( PROPERTY_ACTIVE_CONNECTION ) )
167 aProp <<= pFieldControl->getConnection();
169 else
170 aProp = VCLXWindow::getProperty(_rPropertyName);
171 return aProp;
173 //.........................................................................
174 } // namespace dbaui
175 //.........................................................................