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"
21 #include <ColumnControlWindow.hxx>
22 #include <vcl/svapp.hxx>
23 #include <stringconstants.hxx>
24 #include <strings.hxx>
25 #include <FieldDescriptions.hxx>
26 
27 namespace dbaui
28 {
29 using namespace ::com::sun::star::awt;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::beans;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::sdbc;
34 
OColumnPeer(vcl::Window * _pParent,const Reference<XComponentContext> & _rxContext)35 OColumnPeer::OColumnPeer(vcl::Window* _pParent,const Reference<XComponentContext>& _rxContext)
36     :m_pActFieldDescr(nullptr)
37 {
38     osl_atomic_increment( &m_refCount );
39     {
40         VclPtrInstance<OColumnControlWindow> pFieldControl(_pParent, _rxContext);
41         pFieldControl->SetComponentInterface(this);
42         pFieldControl->Show();
43     }
44     osl_atomic_decrement( &m_refCount );
45 }
46 
setEditWidth(sal_Int32 _nWidth)47 void OColumnPeer::setEditWidth(sal_Int32 _nWidth)
48 {
49     SolarMutexGuard aGuard;
50     VclPtr<OColumnControlWindow> pFieldControl = GetAs<OColumnControlWindow>();
51     if ( pFieldControl )
52         pFieldControl->setEditWidth(_nWidth);
53 }
54 
setColumn(const Reference<XPropertySet> & _xColumn)55 void OColumnPeer::setColumn(const Reference< XPropertySet>& _xColumn)
56 {
57     SolarMutexGuard aGuard;
58 
59     VclPtr<OColumnControlWindow> pFieldControl = GetAs<OColumnControlWindow>();
60     if ( pFieldControl )
61     {
62         if ( m_pActFieldDescr )
63         {
64             delete m_pActFieldDescr;
65             m_pActFieldDescr = nullptr;
66         }
67         if ( _xColumn.is() )
68         {
69             sal_Int32 nType         = 0;
70             sal_Int32 nScale        = 0;
71             sal_Int32 nPrecision    = 0;
72             bool bAutoIncrement = false;
73             OUString sTypeName;
74 
75             try
76             {
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;
83             }
84             catch(const Exception&)
85             {
86             }
87 
88             m_pActFieldDescr = new OFieldDescription(_xColumn,true);
89             // search for type
90             OUString const sCreateParam("x");
91             bool bForce;
92             TOTypeInfoSP pTypeInfo = ::dbaui::getTypeInfoFromType(*pFieldControl->getTypeInfo(),nType,sTypeName,sCreateParam,nPrecision,nScale,bAutoIncrement,bForce);
93             if ( !pTypeInfo.get() )
94                 pTypeInfo = pFieldControl->getDefaultTyp();
95 
96             m_pActFieldDescr->FillFromTypeInfo(pTypeInfo,true,false);
97             m_xColumn = _xColumn;
98         }
99         pFieldControl->DisplayData(m_pActFieldDescr);
100     }
101 }
102 
setConnection(const Reference<XConnection> & _xCon)103 void OColumnPeer::setConnection(const Reference< XConnection>& _xCon)
104 {
105     SolarMutexGuard aGuard;
106     VclPtr<OColumnControlWindow> pFieldControl = GetAs<OColumnControlWindow>();
107     if ( pFieldControl )
108         pFieldControl->setConnection(_xCon);
109 }
110 
setProperty(const OUString & _rPropertyName,const Any & Value)111 void 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 
getProperty(const OUString & _rPropertyName)129 Any OColumnPeer::getProperty( const OUString& _rPropertyName )
130 {
131     Any aProp;
132     VclPtr< OFieldDescControl > pFieldControl = GetAs< OFieldDescControl >();
133     if (pFieldControl && _rPropertyName == PROPERTY_COLUMN)
134     {
135         aProp <<= m_xColumn;
136     }
137     else if (pFieldControl && _rPropertyName == PROPERTY_ACTIVE_CONNECTION)
138     {
139         aProp <<= pFieldControl->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: */
149