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