Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / uno / ColumnPeer.cxx
blob4b583571bcc220eceba29c9c6a96de8d90d5c423
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "ColumnPeer.hxx"
30 #include "ColumnControlWindow.hxx"
31 #include <vcl/svapp.hxx>
32 #include "dbustrings.hrc"
33 #include "FieldDescriptions.hxx"
35 //.........................................................................
36 namespace dbaui
38 //.........................................................................
39 using namespace ::com::sun::star::awt;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::beans;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::sdbc;
45 OColumnPeer::OColumnPeer(Window* _pParent,const Reference<XMultiServiceFactory>& _rxFactory)
46 :m_xORB(_rxFactory)
47 ,m_pActFieldDescr(NULL)
49 osl_incrementInterlockedCount( &m_refCount );
51 OColumnControlWindow* pFieldControl = new OColumnControlWindow(_pParent,m_xORB);
52 pFieldControl->SetComponentInterface(this);
53 pFieldControl->Show();
55 osl_decrementInterlockedCount( &m_refCount );
57 // -----------------------------------------------------------------------------
58 void OColumnPeer::setEditWidth(sal_Int32 _nWidth)
60 SolarMutexGuard aGuard;
62 OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
63 if ( pFieldControl )
65 pFieldControl->setEditWidth(_nWidth);
68 // -----------------------------------------------------------------------------
69 void OColumnPeer::setColumn(const Reference< XPropertySet>& _xColumn)
71 SolarMutexGuard aGuard;
73 OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
74 if ( pFieldControl )
76 if ( m_pActFieldDescr )
78 delete m_pActFieldDescr;
79 m_pActFieldDescr = NULL;
81 if ( _xColumn.is() )
83 sal_Int32 nType = 0;
84 sal_Int32 nScale = 0;
85 sal_Int32 nPrecision = 0;
86 sal_Bool bAutoIncrement = sal_False;
87 ::rtl::OUString sTypeName;
89 try
91 // get the properties from the column
92 _xColumn->getPropertyValue(PROPERTY_TYPENAME) >>= sTypeName;
93 _xColumn->getPropertyValue(PROPERTY_TYPE) >>= nType;
94 _xColumn->getPropertyValue(PROPERTY_SCALE) >>= nScale;
95 _xColumn->getPropertyValue(PROPERTY_PRECISION) >>= nPrecision;
96 _xColumn->getPropertyValue(PROPERTY_ISAUTOINCREMENT) >>= bAutoIncrement;
98 catch(const Exception&)
102 m_pActFieldDescr = new OFieldDescription(_xColumn,sal_True);
103 // search for type
104 ::rtl::OUString sCreateParam(RTL_CONSTASCII_USTRINGPARAM("x"));
105 sal_Bool bForce;
106 TOTypeInfoSP pTypeInfo = ::dbaui::getTypeInfoFromType(*pFieldControl->getTypeInfo(),nType,sTypeName,sCreateParam,nPrecision,nScale,bAutoIncrement,bForce);
107 if ( !pTypeInfo.get() )
108 pTypeInfo = pFieldControl->getDefaultTyp();
110 m_pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False);
111 m_xColumn = _xColumn;
113 pFieldControl->DisplayData(m_pActFieldDescr);
116 // -----------------------------------------------------------------------------
117 void OColumnPeer::setConnection(const Reference< XConnection>& _xCon)
119 SolarMutexGuard aGuard;
120 OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
121 if ( pFieldControl )
122 pFieldControl->setConnection(_xCon);
124 //------------------------------------------------------------------------------
125 void OColumnPeer::setProperty( const ::rtl::OUString& _rPropertyName, const Any& Value) throw( RuntimeException )
127 SolarMutexGuard aGuard;
129 if (_rPropertyName.equalsAsciiL(PROPERTY_COLUMN.ascii, PROPERTY_COLUMN.length) )
131 Reference<XPropertySet> xProp(Value,UNO_QUERY);
132 setColumn(xProp);
134 else if (_rPropertyName.equalsAsciiL(PROPERTY_ACTIVE_CONNECTION.ascii, PROPERTY_ACTIVE_CONNECTION.length) )
136 Reference<XConnection> xCon(Value,UNO_QUERY);
137 setConnection(xCon);
139 else
140 VCLXWindow::setProperty(_rPropertyName,Value);
142 // -----------------------------------------------------------------------------
143 Any OColumnPeer::getProperty( const ::rtl::OUString& _rPropertyName ) throw( RuntimeException )
145 Any aProp;
146 OFieldDescControl* pFieldControl = static_cast<OFieldDescControl*>( GetWindow() );
147 if (pFieldControl && _rPropertyName.equalsAsciiL(PROPERTY_COLUMN.ascii, PROPERTY_COLUMN.length))
149 aProp <<= m_xColumn;
151 else if (pFieldControl && _rPropertyName.equalsAsciiL(PROPERTY_ACTIVE_CONNECTION.ascii, PROPERTY_ACTIVE_CONNECTION.length))
153 aProp <<= pFieldControl->getConnection();
155 else
156 aProp = VCLXWindow::getProperty(_rPropertyName);
157 return aProp;
159 //.........................................................................
160 } // namespace dbaui
161 //.........................................................................
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */