LibreOffice Module dbaccess (master) 1
ColumnPeer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "ColumnPeer.hxx"
22#include <vcl/svapp.hxx>
23#include <strings.hxx>
24#include <FieldDescriptions.hxx>
25
26namespace dbaui
27{
28using namespace ::com::sun::star::awt;
29using namespace ::com::sun::star::uno;
30using namespace ::com::sun::star::beans;
31using namespace ::com::sun::star::lang;
32using namespace ::com::sun::star::sdbc;
33
35 :m_pActFieldDescr(nullptr)
36{
37 osl_atomic_increment( &m_refCount );
38 {
39 VclPtrInstance<OColumnControlTopLevel> pFieldControl(_pParent, _rxContext);
40 pFieldControl->SetComponentInterface(this);
41 pFieldControl->Show();
42 }
43 osl_atomic_decrement( &m_refCount );
44}
45
46void OColumnPeer::setEditWidth(sal_Int32 _nWidth)
47{
48 SolarMutexGuard aGuard;
49 VclPtr<OColumnControlTopLevel> pFieldControl = GetAs<OColumnControlTopLevel>();
50 if ( pFieldControl )
51 pFieldControl->GetControl().setEditWidth(_nWidth);
52}
53
55{
56 SolarMutexGuard aGuard;
57
58 VclPtr<OColumnControlTopLevel> pFieldControl = GetAs<OColumnControlTopLevel>();
59 if ( !pFieldControl )
60 return;
61
62 OColumnControlWindow& rControl = pFieldControl->GetControl();
63
64 if ( m_pActFieldDescr )
65 {
66 delete m_pActFieldDescr;
67 m_pActFieldDescr = nullptr;
68 }
69 if ( _xColumn.is() )
70 {
71 sal_Int32 nType = 0;
72 sal_Int32 nScale = 0;
73 sal_Int32 nPrecision = 0;
74 bool bAutoIncrement = false;
75 OUString sTypeName;
76
77 try
78 {
79 // get the properties from the column
80 _xColumn->getPropertyValue(PROPERTY_TYPENAME) >>= sTypeName;
81 _xColumn->getPropertyValue(PROPERTY_TYPE) >>= nType;
82 _xColumn->getPropertyValue(PROPERTY_SCALE) >>= nScale;
83 _xColumn->getPropertyValue(PROPERTY_PRECISION) >>= nPrecision;
84 _xColumn->getPropertyValue(PROPERTY_ISAUTOINCREMENT) >>= bAutoIncrement;
85 }
86 catch(const Exception&)
87 {
88 }
89
90 m_pActFieldDescr = new OFieldDescription(_xColumn,true);
91 // search for type
92 bool bForce;
93 TOTypeInfoSP pTypeInfo = ::dbaui::getTypeInfoFromType(*rControl.getTypeInfo(),nType,sTypeName,"x",nPrecision,nScale,bAutoIncrement,bForce);
94 if ( !pTypeInfo )
95 pTypeInfo = rControl.getDefaultTyp();
96
97 m_pActFieldDescr->FillFromTypeInfo(pTypeInfo,true,false);
98 m_xColumn = _xColumn;
99 }
101}
102
104{
105 SolarMutexGuard aGuard;
106 VclPtr<OColumnControlTopLevel> pFieldControl = GetAs<OColumnControlTopLevel>();
107 if ( pFieldControl )
108 pFieldControl->GetControl().setConnection(_xCon);
109}
110
111void OColumnPeer::setProperty( const OUString& _rPropertyName, const Any& Value)
112{
113 SolarMutexGuard aGuard;
114
115 if (_rPropertyName == PROPERTY_COLUMN)
116 {
117 Reference<XPropertySet> xProp(Value,UNO_QUERY);
118 setColumn(xProp);
119 }
120 else if (_rPropertyName == PROPERTY_ACTIVE_CONNECTION)
121 {
122 Reference<XConnection> xCon(Value,UNO_QUERY);
123 setConnection(xCon);
124 }
125 else
126 VCLXWindow::setProperty(_rPropertyName,Value);
127}
128
129Any OColumnPeer::getProperty( const OUString& _rPropertyName )
130{
131 Any aProp;
132 VclPtr<OColumnControlTopLevel> pFieldControl = GetAs<OColumnControlTopLevel>();
133 if (pFieldControl && _rPropertyName == PROPERTY_COLUMN)
134 {
135 aProp <<= m_xColumn;
136 }
137 else if (pFieldControl && _rPropertyName == PROPERTY_ACTIVE_CONNECTION)
138 {
139 aProp <<= pFieldControl->GetControl().getConnection();
140 }
141 else
142 aProp = VCLXWindow::getProperty(_rPropertyName);
143 return aProp;
144}
145
146} // namespace dbaui
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Any SAL_CALL getProperty(const OUString &PropertyName) override
void SAL_CALL setProperty(const OUString &PropertyName, const css::uno::Any &Value) override
TOTypeInfoSP const & getDefaultTyp() const
virtual TOTypeInfoSP getTypeInfo(sal_Int32 _nPos) override
void setColumn(const css::uno::Reference< css::beans::XPropertySet > &_xColumn)
Definition: ColumnPeer.cxx:54
OFieldDescription * m_pActFieldDescr
Definition: ColumnPeer.hxx:31
OColumnPeer(vcl::Window *_pParent, const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
Definition: ColumnPeer.cxx:34
css::uno::Reference< css::beans::XPropertySet > m_xColumn
Definition: ColumnPeer.hxx:32
virtual void SAL_CALL setProperty(const OUString &PropertyName, const css::uno::Any &Value) override
Definition: ColumnPeer.cxx:111
void setConnection(const css::uno::Reference< css::sdbc::XConnection > &_xCon)
Definition: ColumnPeer.cxx:103
void setEditWidth(sal_Int32 _nWidth)
Definition: ColumnPeer.cxx:46
virtual css::uno::Any SAL_CALL getProperty(const OUString &PropertyName) override
Definition: ColumnPeer.cxx:129
void DisplayData(OFieldDescription *pFieldDescr)
void FillFromTypeInfo(const TOTypeInfoSP &_pType, bool _bForce, bool _bReset)
ULONG m_refCount
bool bAutoIncrement
@ Exception
TOTypeInfoSP getTypeInfoFromType(const OTypeInfoMap &_rTypeInfo, sal_Int32 _nType, const OUString &_sTypeName, const OUString &_sCreateParams, sal_Int32 _nPrecision, sal_Int32 _nScale, bool _bAutoIncrement, bool &_brForceToType)
return the most suitable typeinfo for a requested type
Definition: UITools.cxx:263
std::shared_ptr< OTypeInfo > TOTypeInfoSP
Definition: TypeInfo.hxx:99
Value
QPRO_FUNC_TYPE nType
constexpr OUStringLiteral PROPERTY_ISAUTOINCREMENT(u"IsAutoIncrement")
constexpr OUStringLiteral PROPERTY_PRECISION(u"Precision")
constexpr OUStringLiteral PROPERTY_TYPENAME(u"TypeName")
constexpr OUStringLiteral PROPERTY_COLUMN(u"Column")
constexpr OUStringLiteral PROPERTY_SCALE(u"Scale")
constexpr OUStringLiteral PROPERTY_ACTIVE_CONNECTION(u"ActiveConnection")
constexpr OUStringLiteral PROPERTY_TYPE(u"Type")