Line data Source code
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 "dbustrings.hrc"
24 : #include "FieldDescriptions.hxx"
25 :
26 : namespace dbaui
27 : {
28 : using namespace ::com::sun::star::awt;
29 : using namespace ::com::sun::star::uno;
30 : using namespace ::com::sun::star::beans;
31 : using namespace ::com::sun::star::lang;
32 : using namespace ::com::sun::star::sdbc;
33 :
34 0 : OColumnPeer::OColumnPeer(Window* _pParent,const Reference<XComponentContext>& _rxContext)
35 0 : :m_pActFieldDescr(NULL)
36 : {
37 0 : osl_atomic_increment( &m_refCount );
38 : {
39 0 : OColumnControlWindow* pFieldControl = new OColumnControlWindow(_pParent, _rxContext);
40 0 : pFieldControl->SetComponentInterface(this);
41 0 : pFieldControl->Show();
42 : }
43 0 : osl_atomic_decrement( &m_refCount );
44 0 : }
45 :
46 0 : void OColumnPeer::setEditWidth(sal_Int32 _nWidth)
47 : {
48 0 : SolarMutexGuard aGuard;
49 :
50 0 : OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
51 0 : if ( pFieldControl )
52 : {
53 0 : pFieldControl->setEditWidth(_nWidth);
54 0 : }
55 0 : }
56 :
57 0 : void OColumnPeer::setColumn(const Reference< XPropertySet>& _xColumn)
58 : {
59 0 : SolarMutexGuard aGuard;
60 :
61 0 : OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
62 0 : if ( pFieldControl )
63 : {
64 0 : if ( m_pActFieldDescr )
65 : {
66 0 : delete m_pActFieldDescr;
67 0 : m_pActFieldDescr = NULL;
68 : }
69 0 : if ( _xColumn.is() )
70 : {
71 0 : sal_Int32 nType = 0;
72 0 : sal_Int32 nScale = 0;
73 0 : sal_Int32 nPrecision = 0;
74 0 : sal_Bool bAutoIncrement = sal_False;
75 0 : OUString sTypeName;
76 :
77 : try
78 : {
79 : // get the properties from the column
80 0 : _xColumn->getPropertyValue(PROPERTY_TYPENAME) >>= sTypeName;
81 0 : _xColumn->getPropertyValue(PROPERTY_TYPE) >>= nType;
82 0 : _xColumn->getPropertyValue(PROPERTY_SCALE) >>= nScale;
83 0 : _xColumn->getPropertyValue(PROPERTY_PRECISION) >>= nPrecision;
84 0 : _xColumn->getPropertyValue(PROPERTY_ISAUTOINCREMENT) >>= bAutoIncrement;
85 : }
86 0 : catch(const Exception&)
87 : {
88 : }
89 :
90 0 : m_pActFieldDescr = new OFieldDescription(_xColumn,sal_True);
91 : // search for type
92 0 : OUString sCreateParam("x");
93 : sal_Bool bForce;
94 0 : TOTypeInfoSP pTypeInfo = ::dbaui::getTypeInfoFromType(*pFieldControl->getTypeInfo(),nType,sTypeName,sCreateParam,nPrecision,nScale,bAutoIncrement,bForce);
95 0 : if ( !pTypeInfo.get() )
96 0 : pTypeInfo = pFieldControl->getDefaultTyp();
97 :
98 0 : m_pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False);
99 0 : m_xColumn = _xColumn;
100 : }
101 0 : pFieldControl->DisplayData(m_pActFieldDescr);
102 0 : }
103 0 : }
104 :
105 0 : void OColumnPeer::setConnection(const Reference< XConnection>& _xCon)
106 : {
107 0 : SolarMutexGuard aGuard;
108 0 : OColumnControlWindow* pFieldControl = static_cast<OColumnControlWindow*>( GetWindow() );
109 0 : if ( pFieldControl )
110 0 : pFieldControl->setConnection(_xCon);
111 0 : }
112 :
113 0 : void OColumnPeer::setProperty( const OUString& _rPropertyName, const Any& Value) throw( RuntimeException, std::exception )
114 : {
115 0 : SolarMutexGuard aGuard;
116 :
117 0 : if (_rPropertyName == PROPERTY_COLUMN)
118 : {
119 0 : Reference<XPropertySet> xProp(Value,UNO_QUERY);
120 0 : setColumn(xProp);
121 : }
122 0 : else if (_rPropertyName == PROPERTY_ACTIVE_CONNECTION)
123 : {
124 0 : Reference<XConnection> xCon(Value,UNO_QUERY);
125 0 : setConnection(xCon);
126 : }
127 : else
128 0 : VCLXWindow::setProperty(_rPropertyName,Value);
129 0 : }
130 :
131 0 : Any OColumnPeer::getProperty( const OUString& _rPropertyName ) throw( RuntimeException, std::exception )
132 : {
133 0 : Any aProp;
134 0 : OFieldDescControl* pFieldControl = static_cast<OFieldDescControl*>( GetWindow() );
135 0 : if (pFieldControl && _rPropertyName == PROPERTY_COLUMN)
136 : {
137 0 : aProp <<= m_xColumn;
138 : }
139 0 : else if (pFieldControl && _rPropertyName == PROPERTY_ACTIVE_CONNECTION)
140 : {
141 0 : aProp <<= pFieldControl->getConnection();
142 : }
143 : else
144 0 : aProp = VCLXWindow::getProperty(_rPropertyName);
145 0 : return aProp;
146 : }
147 :
148 : } // namespace dbaui
149 :
150 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|