1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ColumnPeer.cxx,v $
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"
36 #ifndef DBAUI_COLUMNCONTROLWINDOW_HXX
37 #include "ColumnControlWindow.hxx"
40 #include <vcl/svapp.hxx>
42 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
43 #include "dbustrings.hrc"
45 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
46 #include "FieldDescriptions.hxx"
49 //.........................................................................
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
)
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() );
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() );
90 if ( m_pActFieldDescr
)
92 delete m_pActFieldDescr
;
93 m_pActFieldDescr
= NULL
;
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
;
116 m_pActFieldDescr
= new OFieldDescription(_xColumn
,sal_True
);
118 ::rtl::OUString
sCreateParam(RTL_CONSTASCII_USTRINGPARAM("x"));
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() );
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
);
148 else if ( 0 == _rPropertyName
.compareToAscii( PROPERTY_ACTIVE_CONNECTION
) )
150 Reference
<XConnection
> xCon(Value
,UNO_QUERY
);
154 VCLXWindow::setProperty(_rPropertyName
,Value
);
156 // -----------------------------------------------------------------------------
157 Any
OColumnPeer::getProperty( const ::rtl::OUString
& _rPropertyName
) throw( RuntimeException
)
160 OFieldDescControl
* pFieldControl
= static_cast<OFieldDescControl
*>( GetWindow() );
161 if ( pFieldControl
&& 0 == _rPropertyName
.compareToAscii( PROPERTY_COLUMN
) )
165 else if ( pFieldControl
&& 0 == _rPropertyName
.compareToAscii( PROPERTY_ACTIVE_CONNECTION
) )
167 aProp
<<= pFieldControl
->getConnection();
170 aProp
= VCLXWindow::getProperty(_rPropertyName
);
173 //.........................................................................
175 //.........................................................................