1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ColumnPeer.hxx"
21 #include <ColumnControlWindow.hxx>
22 #include <vcl/svapp.hxx>
23 #include <strings.hxx>
24 #include <FieldDescriptions.hxx>
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::beans
;
30 using namespace ::com::sun::star::sdbc
;
32 OColumnPeer::OColumnPeer(vcl::Window
* _pParent
,const Reference
<XComponentContext
>& _rxContext
)
33 :m_pActFieldDescr(nullptr)
35 osl_atomic_increment( &m_refCount
);
37 VclPtrInstance
<OColumnControlTopLevel
> pFieldControl(_pParent
, _rxContext
);
38 pFieldControl
->SetComponentInterface(this);
39 pFieldControl
->Show();
41 osl_atomic_decrement( &m_refCount
);
44 void OColumnPeer::setEditWidth(sal_Int32 _nWidth
)
46 SolarMutexGuard aGuard
;
47 VclPtr
<OColumnControlTopLevel
> pFieldControl
= GetAs
<OColumnControlTopLevel
>();
49 pFieldControl
->GetControl().setEditWidth(_nWidth
);
52 void OColumnPeer::setColumn(const Reference
< XPropertySet
>& _xColumn
)
54 SolarMutexGuard aGuard
;
56 VclPtr
<OColumnControlTopLevel
> pFieldControl
= GetAs
<OColumnControlTopLevel
>();
60 OColumnControlWindow
& rControl
= pFieldControl
->GetControl();
62 if ( m_pActFieldDescr
)
64 delete m_pActFieldDescr
;
65 m_pActFieldDescr
= nullptr;
71 sal_Int32 nPrecision
= 0;
72 bool bAutoIncrement
= false;
77 // get the properties from the column
78 _xColumn
->getPropertyValue(PROPERTY_TYPENAME
) >>= sTypeName
;
79 _xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nType
;
80 _xColumn
->getPropertyValue(PROPERTY_SCALE
) >>= nScale
;
81 _xColumn
->getPropertyValue(PROPERTY_PRECISION
) >>= nPrecision
;
82 _xColumn
->getPropertyValue(PROPERTY_ISAUTOINCREMENT
) >>= bAutoIncrement
;
84 catch(const Exception
&)
88 m_pActFieldDescr
= new OFieldDescription(_xColumn
,true);
91 TOTypeInfoSP pTypeInfo
= ::dbaui::getTypeInfoFromType(*rControl
.getTypeInfo(),nType
,sTypeName
,u
"x"_ustr
,nPrecision
,nScale
,bAutoIncrement
,bForce
);
93 pTypeInfo
= rControl
.getDefaultTyp();
95 m_pActFieldDescr
->FillFromTypeInfo(pTypeInfo
,true,false);
98 rControl
.DisplayData(m_pActFieldDescr
);
101 void OColumnPeer::setConnection(const Reference
< XConnection
>& _xCon
)
103 SolarMutexGuard aGuard
;
104 VclPtr
<OColumnControlTopLevel
> pFieldControl
= GetAs
<OColumnControlTopLevel
>();
106 pFieldControl
->GetControl().setConnection(_xCon
);
109 void OColumnPeer::setProperty( const OUString
& _rPropertyName
, const Any
& Value
)
111 SolarMutexGuard aGuard
;
113 if (_rPropertyName
== PROPERTY_COLUMN
)
115 Reference
<XPropertySet
> xProp(Value
,UNO_QUERY
);
118 else if (_rPropertyName
== PROPERTY_ACTIVE_CONNECTION
)
120 Reference
<XConnection
> xCon(Value
,UNO_QUERY
);
124 VCLXWindow::setProperty(_rPropertyName
,Value
);
127 Any
OColumnPeer::getProperty( const OUString
& _rPropertyName
)
130 VclPtr
<OColumnControlTopLevel
> pFieldControl
= GetAs
<OColumnControlTopLevel
>();
131 if (pFieldControl
&& _rPropertyName
== PROPERTY_COLUMN
)
135 else if (pFieldControl
&& _rPropertyName
== PROPERTY_ACTIVE_CONNECTION
)
137 aProp
<<= pFieldControl
->GetControl().getConnection();
140 aProp
= VCLXWindow::getProperty(_rPropertyName
);
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */