Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / control / ColumnControlWindow.cxx
blob36aff78e2f964b94f21834feec52ef4115777ca3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "ColumnControlWindow.hxx"
21 #include "FieldControls.hxx"
22 #include <unotools/syslocale.hxx>
23 #include <connectivity/dbtools.hxx>
24 #include "UITools.hxx"
25 #include "dbu_resource.hrc"
26 #include <comphelper/processfactory.hxx>
27 #include <com/sun/star/util/NumberFormatter.hpp>
29 using namespace ::dbaui;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::beans;
32 using namespace ::com::sun::star::container;
33 using namespace ::com::sun::star::util;
34 using namespace ::com::sun::star::sdbc;
35 using namespace ::com::sun::star::lang;
37 // OColumnControlWindow
38 OColumnControlWindow::OColumnControlWindow(vcl::Window* pParent
39 ,const Reference<XComponentContext>& _rxContext)
40 : OFieldDescControl(pParent,NULL)
41 , m_xContext(_rxContext)
42 , m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES))
43 , m_bAutoIncrementEnabled(true)
46 setRightAligned();
47 m_aLocale = SvtSysLocale().GetLanguageTag().getLocale();
50 void OColumnControlWindow::ActivateAggregate( EControlType eType )
52 switch(eType )
54 case tpFormat:
55 case tpDefault:
56 case tpColumnName:
57 break;
58 default:
59 OFieldDescControl::ActivateAggregate( eType );
63 void OColumnControlWindow::DeactivateAggregate( EControlType eType )
65 switch(eType )
67 case tpFormat:
68 case tpDefault:
69 case tpColumnName:
70 break;
71 default:
72 OFieldDescControl::DeactivateAggregate( eType );
76 void OColumnControlWindow::CellModified(long /*nRow*/, sal_uInt16 /*nColId*/ )
78 saveCurrentFieldDescData();
81 ::com::sun::star::lang::Locale OColumnControlWindow::GetLocale() const
83 return m_aLocale;
86 Reference< XNumberFormatter > OColumnControlWindow::GetFormatter() const
88 if ( !m_xFormatter.is() )
89 try
91 Reference< XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(m_xConnection, true, m_xContext));
93 if ( xSupplier.is() )
95 // create a new formatter
96 m_xFormatter.set( NumberFormatter::create(m_xContext), UNO_QUERY_THROW);
97 m_xFormatter->attachNumberFormatsSupplier(xSupplier);
100 catch(Exception&)
103 return m_xFormatter;
106 TOTypeInfoSP OColumnControlWindow::getTypeInfo(sal_Int32 _nPos)
108 return ( _nPos >= 0 && _nPos < static_cast<sal_Int32>(m_aDestTypeInfoIndex.size())) ? m_aDestTypeInfoIndex[_nPos]->second : TOTypeInfoSP();
111 const OTypeInfoMap* OColumnControlWindow::getTypeInfo() const
113 return &m_aDestTypeInfo;
116 Reference< XDatabaseMetaData> OColumnControlWindow::getMetaData()
118 if ( m_xConnection.is() )
119 return m_xConnection->getMetaData();
120 return Reference< XDatabaseMetaData>();
123 Reference< XConnection> OColumnControlWindow::getConnection()
125 return m_xConnection;
128 void OColumnControlWindow::setConnection(const Reference< XConnection>& _xCon)
130 m_xConnection = _xCon;
131 m_xFormatter = NULL;
132 m_aDestTypeInfoIndex.clear();
133 m_aDestTypeInfo.clear();
135 if ( m_xConnection.is() )
137 Init();
139 ::dbaui::fillTypeInfo(m_xConnection,m_sTypeNames,m_aDestTypeInfo,m_aDestTypeInfoIndex);
140 // read autoincrement value set in the datasource
141 ::dbaui::fillAutoIncrementValue(m_xConnection,m_bAutoIncrementEnabled,m_sAutoIncrementValue);
145 bool OColumnControlWindow::isAutoIncrementValueEnabled() const
147 return m_bAutoIncrementEnabled;
150 OUString OColumnControlWindow::getAutoIncrementValue() const
152 return m_sAutoIncrementValue;
155 TOTypeInfoSP OColumnControlWindow::getDefaultTyp() const
157 if ( !m_pTypeInfo.get() )
159 m_pTypeInfo = TOTypeInfoSP(new OTypeInfo());
160 m_pTypeInfo->aUIName = m_sTypeNames.getToken(TYPE_OTHER, ';');
162 return m_pTypeInfo;
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */