1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_dbaccess.hxx" 26 #ifndef DBAUI_COLUMNCONTROLWINDOW_HXX 27 #include "ColumnControlWindow.hxx" 28 #endif 29 #ifndef DBAUI_FIELDCONTROLS_HXX 30 #include "FieldControls.hxx" 31 #endif 32 #ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX 33 #include <unotools/syslocale.hxx> 34 #endif 35 #ifndef _CONNECTIVITY_DBTOOLS_HXX_ 36 #include <connectivity/dbtools.hxx> 37 #endif 38 #ifndef DBAUI_TOOLS_HXX 39 #include "UITools.hxx" 40 #endif 41 #ifndef _DBU_RESOURCE_HRC_ 42 #include "dbu_resource.hrc" 43 #endif 44 45 46 using namespace ::dbaui; 47 using namespace ::com::sun::star::uno; 48 using namespace ::com::sun::star::beans; 49 using namespace ::com::sun::star::container; 50 using namespace ::com::sun::star::util; 51 using namespace ::com::sun::star::sdbc; 52 using namespace ::com::sun::star::lang; 53 54 //======================================================================== 55 // OColumnControlWindow 56 DBG_NAME(OColumnControlWindow) 57 //======================================================================== 58 OColumnControlWindow::OColumnControlWindow(Window* pParent 59 ,const Reference<XMultiServiceFactory>& _rxFactory) 60 : OFieldDescControl(pParent,NULL) 61 , m_xORB(_rxFactory) 62 , m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES)) 63 , m_bAutoIncrementEnabled(sal_True) 64 { 65 DBG_CTOR(OColumnControlWindow,NULL); 66 67 setRightAligned(); 68 m_aLocale = SvtSysLocale().GetLocaleData().getLocale(); 69 } 70 // ----------------------------------------------------------------------------- 71 OColumnControlWindow::~OColumnControlWindow() 72 { 73 74 DBG_DTOR(OColumnControlWindow,NULL); 75 } 76 // ----------------------------------------------------------------------- 77 void OColumnControlWindow::ActivateAggregate( EControlType eType ) 78 { 79 switch(eType ) 80 { 81 case tpFormat: 82 case tpDefault: 83 // case tpAutoIncrement: 84 case tpColumnName: 85 break; 86 default: 87 OFieldDescControl::ActivateAggregate( eType ); 88 } 89 } 90 // ----------------------------------------------------------------------- 91 void OColumnControlWindow::DeactivateAggregate( EControlType eType ) 92 { 93 switch(eType ) 94 { 95 case tpFormat: 96 case tpDefault: 97 // case tpAutoIncrement: 98 case tpColumnName: 99 break; 100 default: 101 OFieldDescControl::DeactivateAggregate( eType ); 102 } 103 } 104 // ----------------------------------------------------------------------------- 105 void OColumnControlWindow::CellModified(long /*nRow*/, sal_uInt16 /*nColId*/ ) 106 { 107 saveCurrentFieldDescData(); 108 } 109 // ----------------------------------------------------------------------------- 110 ::com::sun::star::lang::Locale OColumnControlWindow::GetLocale() const 111 { 112 return m_aLocale; 113 } 114 // ----------------------------------------------------------------------------- 115 Reference< XNumberFormatter > OColumnControlWindow::GetFormatter() const 116 { 117 if ( !m_xFormatter.is() ) 118 try 119 { 120 Reference< XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(m_xConnection, sal_True,m_xORB)); 121 122 if ( xSupplier.is() ) 123 { 124 // create a new formatter 125 m_xFormatter.set( m_xORB->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter"))), UNO_QUERY); 126 if (m_xFormatter.is()) 127 m_xFormatter->attachNumberFormatsSupplier(xSupplier); 128 } 129 } 130 catch(Exception&) 131 { 132 } 133 return m_xFormatter; 134 } 135 // ----------------------------------------------------------------------------- 136 TOTypeInfoSP OColumnControlWindow::getTypeInfo(sal_Int32 _nPos) 137 { 138 return ( _nPos >= 0 && _nPos < static_cast<sal_Int32>(m_aDestTypeInfoIndex.size())) ? m_aDestTypeInfoIndex[_nPos]->second : TOTypeInfoSP(); 139 } 140 // ----------------------------------------------------------------------------- 141 const OTypeInfoMap* OColumnControlWindow::getTypeInfo() const 142 { 143 return &m_aDestTypeInfo; 144 } 145 // ----------------------------------------------------------------------------- 146 Reference< XDatabaseMetaData> OColumnControlWindow::getMetaData() 147 { 148 if ( m_xConnection.is() ) 149 return m_xConnection->getMetaData(); 150 return Reference< XDatabaseMetaData>(); 151 } 152 // ----------------------------------------------------------------------------- 153 Reference< XConnection> OColumnControlWindow::getConnection() 154 { 155 return m_xConnection; 156 } 157 // ----------------------------------------------------------------------------- 158 void OColumnControlWindow::setConnection(const Reference< XConnection>& _xCon) 159 { 160 m_xConnection = _xCon; 161 m_xFormatter = NULL; 162 m_aDestTypeInfoIndex.clear(); 163 m_aDestTypeInfo.clear(); 164 165 if ( m_xConnection.is() ) 166 { 167 Init(); 168 169 ::dbaui::fillTypeInfo(m_xConnection,m_sTypeNames,m_aDestTypeInfo,m_aDestTypeInfoIndex); 170 // read autoincrement value set in the datasource 171 ::dbaui::fillAutoIncrementValue(m_xConnection,m_bAutoIncrementEnabled,m_sAutoIncrementValue); 172 } 173 } 174 // ----------------------------------------------------------------------------- 175 sal_Bool OColumnControlWindow::isAutoIncrementValueEnabled() const 176 { 177 return m_bAutoIncrementEnabled; 178 } 179 // ----------------------------------------------------------------------------- 180 ::rtl::OUString OColumnControlWindow::getAutoIncrementValue() const 181 { 182 return m_sAutoIncrementValue; 183 } 184 // ----------------------------------------------------------------------------- 185 TOTypeInfoSP OColumnControlWindow::getDefaultTyp() const 186 { 187 if ( !m_pTypeInfo.get() ) 188 { 189 m_pTypeInfo = TOTypeInfoSP(new OTypeInfo()); 190 m_pTypeInfo->aUIName = m_sTypeNames.GetToken(TYPE_OTHER); 191 } 192 return m_pTypeInfo; 193 } 194 // ----------------------------------------------------------------------------- 195