Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / control / ColumnControlWindow.cxx
blobc17d0952215b9794384f1f2b24afc4f0c0318443
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 <unotools/syslocale.hxx>
22 #include <i18nlangtag/languagetag.hxx>
23 #include <connectivity/dbtools.hxx>
24 #include <o3tl/safeint.hxx>
25 #include <UITools.hxx>
26 #include <core_resource.hxx>
27 #include <strings.hrc>
28 #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 OColumnControlTopLevel::OColumnControlTopLevel(vcl::Window* pParent,
39 const Reference<XComponentContext>& _rxContext)
40 : InterimItemWindow(pParent, u"dbaccess/ui/colcontrolbox.ui"_ustr, u"ColControlBox"_ustr)
41 , m_xControl(new OColumnControlWindow(m_xContainer.get(), _rxContext))
45 void OColumnControlTopLevel::dispose()
47 m_xControl.reset();
48 InterimItemWindow::dispose();
51 void OColumnControlTopLevel::GetFocus()
53 m_xControl->GrabFocus();
56 // OColumnControlWindow
57 OColumnControlWindow::OColumnControlWindow(weld::Container* pParent,
58 const Reference<XComponentContext>& _rxContext)
59 : OFieldDescControl(pParent, nullptr)
60 , m_xContext(_rxContext)
61 , m_sTypeNames(DBA_RES(STR_TABLEDESIGN_DBFIELDTYPES))
62 , m_bAutoIncrementEnabled(true)
64 m_aLocale = SvtSysLocale().GetLanguageTag().getLocale();
67 void OColumnControlWindow::ActivateAggregate( EControlType eType )
69 switch(eType )
71 case tpFormat:
72 case tpDefault:
73 case tpColumnName:
74 break;
75 default:
76 OFieldDescControl::ActivateAggregate( eType );
80 void OColumnControlWindow::DeactivateAggregate( EControlType eType )
82 switch(eType )
84 case tpFormat:
85 case tpDefault:
86 case tpColumnName:
87 break;
88 default:
89 OFieldDescControl::DeactivateAggregate( eType );
93 void OColumnControlWindow::CellModified(sal_Int32 /*nRow*/, sal_uInt16 /*nColId*/ )
95 saveCurrentFieldDescData();
98 css::lang::Locale OColumnControlWindow::GetLocale() const
100 return m_aLocale;
103 Reference< XNumberFormatter > OColumnControlWindow::GetFormatter() const
105 if ( !m_xFormatter.is() )
108 Reference< XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(m_xConnection, true, m_xContext));
110 if ( xSupplier.is() )
112 // create a new formatter
113 m_xFormatter.set( NumberFormatter::create(m_xContext), UNO_QUERY_THROW);
114 m_xFormatter->attachNumberFormatsSupplier(xSupplier);
117 catch(Exception&)
120 return m_xFormatter;
123 TOTypeInfoSP OColumnControlWindow::getTypeInfo(sal_Int32 _nPos)
125 return ( _nPos >= 0 && o3tl::make_unsigned(_nPos) < m_aDestTypeInfoIndex.size()) ? m_aDestTypeInfoIndex[_nPos]->second : TOTypeInfoSP();
128 const OTypeInfoMap* OColumnControlWindow::getTypeInfo() const
130 return &m_aDestTypeInfo;
133 Reference< XDatabaseMetaData> OColumnControlWindow::getMetaData()
135 if ( m_xConnection.is() )
136 return m_xConnection->getMetaData();
137 return Reference< XDatabaseMetaData>();
140 Reference< XConnection> OColumnControlWindow::getConnection()
142 return m_xConnection;
145 void OColumnControlWindow::setConnection(const Reference< XConnection>& _xCon)
147 m_xConnection = _xCon;
148 m_xFormatter = nullptr;
149 m_aDestTypeInfoIndex.clear();
150 m_aDestTypeInfo.clear();
152 if ( m_xConnection.is() )
154 Init();
156 ::dbaui::fillTypeInfo(m_xConnection,m_sTypeNames,m_aDestTypeInfo,m_aDestTypeInfoIndex);
157 // read autoincrement value set in the datasource
158 ::dbaui::fillAutoIncrementValue(m_xConnection,m_bAutoIncrementEnabled,m_sAutoIncrementValue);
162 bool OColumnControlWindow::isAutoIncrementValueEnabled() const
164 return m_bAutoIncrementEnabled;
167 OUString OColumnControlWindow::getAutoIncrementValue() const
169 return m_sAutoIncrementValue;
172 TOTypeInfoSP const & OColumnControlWindow::getDefaultTyp() const
174 if ( !m_pTypeInfo )
176 m_pTypeInfo = std::make_shared<OTypeInfo>();
177 m_pTypeInfo->aUIName = m_sTypeNames.getToken(TYPE_OTHER, ';');
179 return m_pTypeInfo;
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */