update credits
[LibreOffice.git] / dbaccess / source / ui / control / ColumnControlWindow.cxx
blob0e0f60960e52d29d0e4e222cce8846e4381ec922
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>
30 using namespace ::dbaui;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::beans;
33 using namespace ::com::sun::star::container;
34 using namespace ::com::sun::star::util;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::lang;
38 //========================================================================
39 // OColumnControlWindow
40 DBG_NAME(OColumnControlWindow)
41 //========================================================================
42 OColumnControlWindow::OColumnControlWindow(Window* pParent
43 ,const Reference<XComponentContext>& _rxContext)
44 : OFieldDescControl(pParent,NULL)
45 , m_xContext(_rxContext)
46 , m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES))
47 , m_bAutoIncrementEnabled(sal_True)
49 DBG_CTOR(OColumnControlWindow,NULL);
51 setRightAligned();
52 m_aLocale = SvtSysLocale().GetLanguageTag().getLocale();
54 // -----------------------------------------------------------------------------
55 OColumnControlWindow::~OColumnControlWindow()
58 DBG_DTOR(OColumnControlWindow,NULL);
60 // -----------------------------------------------------------------------
61 void OColumnControlWindow::ActivateAggregate( EControlType eType )
63 switch(eType )
65 case tpFormat:
66 case tpDefault:
67 case tpColumnName:
68 break;
69 default:
70 OFieldDescControl::ActivateAggregate( eType );
73 // -----------------------------------------------------------------------
74 void OColumnControlWindow::DeactivateAggregate( EControlType eType )
76 switch(eType )
78 case tpFormat:
79 case tpDefault:
80 case tpColumnName:
81 break;
82 default:
83 OFieldDescControl::DeactivateAggregate( eType );
86 // -----------------------------------------------------------------------------
87 void OColumnControlWindow::CellModified(long /*nRow*/, sal_uInt16 /*nColId*/ )
89 saveCurrentFieldDescData();
91 // -----------------------------------------------------------------------------
92 ::com::sun::star::lang::Locale OColumnControlWindow::GetLocale() const
94 return m_aLocale;
96 // -----------------------------------------------------------------------------
97 Reference< XNumberFormatter > OColumnControlWindow::GetFormatter() const
99 if ( !m_xFormatter.is() )
102 Reference< XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(m_xConnection, sal_True, m_xContext));
104 if ( xSupplier.is() )
106 // create a new formatter
107 m_xFormatter.set( NumberFormatter::create(m_xContext), UNO_QUERY_THROW);
108 m_xFormatter->attachNumberFormatsSupplier(xSupplier);
111 catch(Exception&)
114 return m_xFormatter;
116 // -----------------------------------------------------------------------------
117 TOTypeInfoSP OColumnControlWindow::getTypeInfo(sal_Int32 _nPos)
119 return ( _nPos >= 0 && _nPos < static_cast<sal_Int32>(m_aDestTypeInfoIndex.size())) ? m_aDestTypeInfoIndex[_nPos]->second : TOTypeInfoSP();
121 // -----------------------------------------------------------------------------
122 const OTypeInfoMap* OColumnControlWindow::getTypeInfo() const
124 return &m_aDestTypeInfo;
126 // -----------------------------------------------------------------------------
127 Reference< XDatabaseMetaData> OColumnControlWindow::getMetaData()
129 if ( m_xConnection.is() )
130 return m_xConnection->getMetaData();
131 return Reference< XDatabaseMetaData>();
133 // -----------------------------------------------------------------------------
134 Reference< XConnection> OColumnControlWindow::getConnection()
136 return m_xConnection;
138 // -----------------------------------------------------------------------------
139 void OColumnControlWindow::setConnection(const Reference< XConnection>& _xCon)
141 m_xConnection = _xCon;
142 m_xFormatter = NULL;
143 m_aDestTypeInfoIndex.clear();
144 m_aDestTypeInfo.clear();
146 if ( m_xConnection.is() )
148 Init();
150 ::dbaui::fillTypeInfo(m_xConnection,m_sTypeNames,m_aDestTypeInfo,m_aDestTypeInfoIndex);
151 // read autoincrement value set in the datasource
152 ::dbaui::fillAutoIncrementValue(m_xConnection,m_bAutoIncrementEnabled,m_sAutoIncrementValue);
155 // -----------------------------------------------------------------------------
156 sal_Bool OColumnControlWindow::isAutoIncrementValueEnabled() const
158 return m_bAutoIncrementEnabled;
160 // -----------------------------------------------------------------------------
161 OUString OColumnControlWindow::getAutoIncrementValue() const
163 return m_sAutoIncrementValue;
165 // -----------------------------------------------------------------------------
166 TOTypeInfoSP OColumnControlWindow::getDefaultTyp() const
168 if ( !m_pTypeInfo.get() )
170 m_pTypeInfo = TOTypeInfoSP(new OTypeInfo());
171 m_pTypeInfo->aUIName = m_sTypeNames.GetToken(TYPE_OTHER);
173 return m_pTypeInfo;
175 // -----------------------------------------------------------------------------
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */