1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir #ifndef DBAUI_COLUMNPEER_HXX
27cdf0e10cSrcweir #include "ColumnPeer.hxx"
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #ifndef DBAUI_COLUMNCONTROLWINDOW_HXX
30cdf0e10cSrcweir #include "ColumnControlWindow.hxx"
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX
33cdf0e10cSrcweir #include <vcl/svapp.hxx>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
36cdf0e10cSrcweir #include "dbustrings.hrc"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
39cdf0e10cSrcweir #include "FieldDescriptions.hxx"
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //.........................................................................
43cdf0e10cSrcweir namespace dbaui
44cdf0e10cSrcweir {
45cdf0e10cSrcweir //.........................................................................
46cdf0e10cSrcweir using namespace ::com::sun::star::awt;
47cdf0e10cSrcweir using namespace ::com::sun::star::uno;
48cdf0e10cSrcweir using namespace ::com::sun::star::beans;
49cdf0e10cSrcweir using namespace ::com::sun::star::lang;
50cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
51cdf0e10cSrcweir 
OColumnPeer(Window * _pParent,const Reference<XMultiServiceFactory> & _rxFactory)52cdf0e10cSrcweir OColumnPeer::OColumnPeer(Window* _pParent,const Reference<XMultiServiceFactory>& _rxFactory)
53cdf0e10cSrcweir     :m_xORB(_rxFactory)
54cdf0e10cSrcweir     ,m_pActFieldDescr(NULL)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir 	osl_incrementInterlockedCount( &m_refCount );
57cdf0e10cSrcweir 	{
58cdf0e10cSrcweir 		OColumnControlWindow* pFieldControl = new OColumnControlWindow(_pParent,m_xORB);
59cdf0e10cSrcweir 		pFieldControl->SetComponentInterface(this);
60cdf0e10cSrcweir 		pFieldControl->Show();
61cdf0e10cSrcweir 	}
62cdf0e10cSrcweir 	osl_decrementInterlockedCount( &m_refCount );
63cdf0e10cSrcweir }
64cdf0e10cSrcweir // -----------------------------------------------------------------------------
setEditWidth(sal_Int32 _nWidth)65cdf0e10cSrcweir void OColumnPeer::setEditWidth(sal_Int32 _nWidth)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
70cdf0e10cSrcweir 	if ( pFieldControl )
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir 		pFieldControl->setEditWidth(_nWidth);
73cdf0e10cSrcweir 	}
74cdf0e10cSrcweir }
75cdf0e10cSrcweir // -----------------------------------------------------------------------------
setColumn(const Reference<XPropertySet> & _xColumn)76cdf0e10cSrcweir void OColumnPeer::setColumn(const Reference< XPropertySet>& _xColumn)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
81cdf0e10cSrcweir 	if ( pFieldControl )
82cdf0e10cSrcweir 	{
83cdf0e10cSrcweir 		if ( m_pActFieldDescr )
84cdf0e10cSrcweir 		{
85cdf0e10cSrcweir 			delete m_pActFieldDescr;
86cdf0e10cSrcweir 			m_pActFieldDescr = NULL;
87cdf0e10cSrcweir 		}
88cdf0e10cSrcweir 		if ( _xColumn.is() )
89cdf0e10cSrcweir 		{
90cdf0e10cSrcweir 			sal_Int32 nType			= 0;
91cdf0e10cSrcweir 			sal_Int32 nScale		= 0;
92cdf0e10cSrcweir 			sal_Int32 nPrecision	= 0;
93cdf0e10cSrcweir 			sal_Bool bAutoIncrement = sal_False;
94cdf0e10cSrcweir 			::rtl::OUString sTypeName;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 			try
97cdf0e10cSrcweir 			{
98cdf0e10cSrcweir 				// get the properties from the column
99cdf0e10cSrcweir 				_xColumn->getPropertyValue(PROPERTY_TYPENAME)		>>= sTypeName;
100cdf0e10cSrcweir 				_xColumn->getPropertyValue(PROPERTY_TYPE)			>>= nType;
101cdf0e10cSrcweir 				_xColumn->getPropertyValue(PROPERTY_SCALE)			>>= nScale;
102cdf0e10cSrcweir 				_xColumn->getPropertyValue(PROPERTY_PRECISION)		>>= nPrecision;
103cdf0e10cSrcweir 				_xColumn->getPropertyValue(PROPERTY_ISAUTOINCREMENT)	>>= bAutoIncrement;
104cdf0e10cSrcweir 			}
105cdf0e10cSrcweir 			catch(Exception)
106cdf0e10cSrcweir 			{
107cdf0e10cSrcweir 			}
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 			m_pActFieldDescr = new OFieldDescription(_xColumn,sal_True);
110cdf0e10cSrcweir 			// search for type
111cdf0e10cSrcweir 			::rtl::OUString sCreateParam(RTL_CONSTASCII_USTRINGPARAM("x"));
112cdf0e10cSrcweir 			sal_Bool bForce;
113cdf0e10cSrcweir 			TOTypeInfoSP pTypeInfo = ::dbaui::getTypeInfoFromType(*pFieldControl->getTypeInfo(),nType,sTypeName,sCreateParam,nPrecision,nScale,bAutoIncrement,bForce);
114cdf0e10cSrcweir 			if ( !pTypeInfo.get() )
115cdf0e10cSrcweir 				pTypeInfo = pFieldControl->getDefaultTyp();
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 			m_pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False);
118cdf0e10cSrcweir 			m_xColumn = _xColumn;
119cdf0e10cSrcweir 		}
120cdf0e10cSrcweir 		pFieldControl->DisplayData(m_pActFieldDescr);
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir }
123cdf0e10cSrcweir // -----------------------------------------------------------------------------
setConnection(const Reference<XConnection> & _xCon)124cdf0e10cSrcweir void OColumnPeer::setConnection(const Reference< XConnection>& _xCon)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
127cdf0e10cSrcweir 	OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
128cdf0e10cSrcweir 	if ( pFieldControl )
129cdf0e10cSrcweir 		pFieldControl->setConnection(_xCon);
130cdf0e10cSrcweir }
131cdf0e10cSrcweir //------------------------------------------------------------------------------
setProperty(const::rtl::OUString & _rPropertyName,const Any & Value)132cdf0e10cSrcweir void OColumnPeer::setProperty( const ::rtl::OUString& _rPropertyName, const Any& Value) throw( RuntimeException )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	if ( 0 == _rPropertyName.compareToAscii( PROPERTY_COLUMN ) )
137cdf0e10cSrcweir 	{
138cdf0e10cSrcweir 		Reference<XPropertySet> xProp(Value,UNO_QUERY);
139cdf0e10cSrcweir 		setColumn(xProp);
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir 	else if ( 0 == _rPropertyName.compareToAscii( PROPERTY_ACTIVE_CONNECTION ) )
142cdf0e10cSrcweir 	{
143cdf0e10cSrcweir 		Reference<XConnection> xCon(Value,UNO_QUERY);
144cdf0e10cSrcweir 		setConnection(xCon);
145cdf0e10cSrcweir 	}
146cdf0e10cSrcweir 	else
147cdf0e10cSrcweir 		VCLXWindow::setProperty(_rPropertyName,Value);
148cdf0e10cSrcweir }
149cdf0e10cSrcweir // -----------------------------------------------------------------------------
getProperty(const::rtl::OUString & _rPropertyName)150cdf0e10cSrcweir Any OColumnPeer::getProperty( const ::rtl::OUString& _rPropertyName ) throw( RuntimeException )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	Any aProp;
153cdf0e10cSrcweir 	OFieldDescControl* pFieldControl = static_cast<OFieldDescControl*>( GetWindow() );
154cdf0e10cSrcweir 	if ( pFieldControl && 0 == _rPropertyName.compareToAscii( PROPERTY_COLUMN ) )
155cdf0e10cSrcweir 	{
156cdf0e10cSrcweir 		aProp <<= m_xColumn;
157cdf0e10cSrcweir 	}
158cdf0e10cSrcweir 	else if ( pFieldControl && 0 == _rPropertyName.compareToAscii( PROPERTY_ACTIVE_CONNECTION ) )
159cdf0e10cSrcweir 	{
160cdf0e10cSrcweir 		aProp <<= pFieldControl->getConnection();
161cdf0e10cSrcweir 	}
162cdf0e10cSrcweir 	else
163cdf0e10cSrcweir 		aProp = VCLXWindow::getProperty(_rPropertyName);
164cdf0e10cSrcweir 	return aProp;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir //.........................................................................
167cdf0e10cSrcweir }	// namespace dbaui
168cdf0e10cSrcweir //.........................................................................
169