1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ColumnControlWindow.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_COLUMNCONTROLWINDOW_HXX
34 #include "ColumnControlWindow.hxx"
36 #ifndef DBAUI_FIELDCONTROLS_HXX
37 #include "FieldControls.hxx"
39 #ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX
40 #include <svtools/syslocale.hxx>
42 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
43 #include <connectivity/dbtools.hxx>
45 #ifndef DBAUI_TOOLS_HXX
46 #include "UITools.hxx"
48 #ifndef _DBU_RESOURCE_HRC_
49 #include "dbu_resource.hrc"
53 using namespace ::dbaui
;
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::beans
;
56 using namespace ::com::sun::star::container
;
57 using namespace ::com::sun::star::util
;
58 using namespace ::com::sun::star::sdbc
;
59 using namespace ::com::sun::star::lang
;
61 //========================================================================
62 // OColumnControlWindow
63 DBG_NAME(OColumnControlWindow
)
64 //========================================================================
65 OColumnControlWindow::OColumnControlWindow(Window
* pParent
66 ,const Reference
<XMultiServiceFactory
>& _rxFactory
)
67 : OFieldDescControl(pParent
,NULL
)
69 , m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES
))
70 , m_bAutoIncrementEnabled(sal_True
)
72 DBG_CTOR(OColumnControlWindow
,NULL
);
75 m_aLocale
= SvtSysLocale().GetLocaleData().getLocale();
77 // -----------------------------------------------------------------------------
78 OColumnControlWindow::~OColumnControlWindow()
81 DBG_DTOR(OColumnControlWindow
,NULL
);
83 // -----------------------------------------------------------------------
84 void OColumnControlWindow::ActivateAggregate( EControlType eType
)
90 // case tpAutoIncrement:
94 OFieldDescControl::ActivateAggregate( eType
);
97 // -----------------------------------------------------------------------
98 void OColumnControlWindow::DeactivateAggregate( EControlType eType
)
104 // case tpAutoIncrement:
108 OFieldDescControl::DeactivateAggregate( eType
);
111 // -----------------------------------------------------------------------------
112 void OColumnControlWindow::CellModified(long /*nRow*/, USHORT
/*nColId*/ )
114 saveCurrentFieldDescData();
116 // -----------------------------------------------------------------------------
117 ::com::sun::star::lang::Locale
OColumnControlWindow::GetLocale() const
121 // -----------------------------------------------------------------------------
122 Reference
< XNumberFormatter
> OColumnControlWindow::GetFormatter() const
124 if ( !m_xFormatter
.is() )
127 Reference
< XNumberFormatsSupplier
> xSupplier(::dbtools::getNumberFormats(m_xConnection
, sal_True
,m_xORB
));
129 if ( xSupplier
.is() )
131 // create a new formatter
132 m_xFormatter
.set( m_xORB
->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter"))), UNO_QUERY
);
133 if (m_xFormatter
.is())
134 m_xFormatter
->attachNumberFormatsSupplier(xSupplier
);
142 // -----------------------------------------------------------------------------
143 TOTypeInfoSP
OColumnControlWindow::getTypeInfo(sal_Int32 _nPos
)
145 return ( _nPos
>= 0 && _nPos
< static_cast<sal_Int32
>(m_aDestTypeInfoIndex
.size())) ? m_aDestTypeInfoIndex
[_nPos
]->second
: TOTypeInfoSP();
147 // -----------------------------------------------------------------------------
148 const OTypeInfoMap
* OColumnControlWindow::getTypeInfo() const
150 return &m_aDestTypeInfo
;
152 // -----------------------------------------------------------------------------
153 Reference
< XDatabaseMetaData
> OColumnControlWindow::getMetaData()
155 if ( m_xConnection
.is() )
156 return m_xConnection
->getMetaData();
157 return Reference
< XDatabaseMetaData
>();
159 // -----------------------------------------------------------------------------
160 Reference
< XConnection
> OColumnControlWindow::getConnection()
162 return m_xConnection
;
164 // -----------------------------------------------------------------------------
165 void OColumnControlWindow::setConnection(const Reference
< XConnection
>& _xCon
)
167 m_xConnection
= _xCon
;
169 m_aDestTypeInfoIndex
.clear();
170 m_aDestTypeInfo
.clear();
172 if ( m_xConnection
.is() )
176 ::dbaui::fillTypeInfo(m_xConnection
,m_sTypeNames
,m_aDestTypeInfo
,m_aDestTypeInfoIndex
);
177 // read autoincrement value set in the datasource
178 ::dbaui::fillAutoIncrementValue(m_xConnection
,m_bAutoIncrementEnabled
,m_sAutoIncrementValue
);
181 // -----------------------------------------------------------------------------
182 sal_Bool
OColumnControlWindow::isAutoIncrementValueEnabled() const
184 return m_bAutoIncrementEnabled
;
186 // -----------------------------------------------------------------------------
187 ::rtl::OUString
OColumnControlWindow::getAutoIncrementValue() const
189 return m_sAutoIncrementValue
;
191 // -----------------------------------------------------------------------------
192 TOTypeInfoSP
OColumnControlWindow::getDefaultTyp() const
194 if ( !m_pTypeInfo
.get() )
196 m_pTypeInfo
= TOTypeInfoSP(new OTypeInfo());
197 m_pTypeInfo
->aUIName
= m_sTypeNames
.GetToken(TYPE_OTHER
);
201 // -----------------------------------------------------------------------------