diff options
author | Michael Stahl <mstahl@redhat.com> | 2012-01-28 20:55:39 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-01-28 20:55:39 +0100 |
commit | 371976860088a3c5c3df9840dcdfd632d9d6f1f5 (patch) | |
tree | 9e9f67205cd5b72f1031721273e1534a3a1e5b0f /svx/source/fmcomp | |
parent | 651568afad1a585c485384ab6d7b65780fb02256 (diff) |
replace obsolete "master" branch with README that points at new repoHEADmaster-deletedmaster
Diffstat (limited to 'svx/source/fmcomp')
-rw-r--r-- | svx/source/fmcomp/dbaexchange.cxx | 730 | ||||
-rw-r--r-- | svx/source/fmcomp/dbaobjectex.cxx | 185 | ||||
-rw-r--r-- | svx/source/fmcomp/fmgridcl.cxx | 2138 | ||||
-rw-r--r-- | svx/source/fmcomp/fmgridif.cxx | 2961 | ||||
-rw-r--r-- | svx/source/fmcomp/gridcell.cxx | 4838 | ||||
-rw-r--r-- | svx/source/fmcomp/gridcols.cxx | 109 | ||||
-rw-r--r-- | svx/source/fmcomp/gridctrl.cxx | 3927 | ||||
-rw-r--r-- | svx/source/fmcomp/gridctrl.src | 259 | ||||
-rw-r--r-- | svx/source/fmcomp/trace.cxx | 116 | ||||
-rw-r--r-- | svx/source/fmcomp/xmlexchg.cxx | 95 |
10 files changed, 0 insertions, 15358 deletions
diff --git a/svx/source/fmcomp/dbaexchange.cxx b/svx/source/fmcomp/dbaexchange.cxx deleted file mode 100644 index fe8faaa163..0000000000 --- a/svx/source/fmcomp/dbaexchange.cxx +++ /dev/null @@ -1,730 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svx.hxx" -#include <svx/dbaexchange.hxx> -#include <osl/diagnose.h> -#include <com/sun/star/sdb/CommandType.hpp> -#include <com/sun/star/sdbcx/XTablesSupplier.hpp> -#include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> -#include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> -#include "fmprop.hrc" -#include <comphelper/extract.hxx> -#include <sot/formats.hxx> -#include <sot/exchange.hxx> -#include <comphelper/propertysetinfo.hxx> -#include "fmprop.hrc" -#include <tools/urlobj.hxx> - -//........................................................................ -namespace svx -{ -//........................................................................ - - using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::beans; - using namespace ::com::sun::star::sdb; - using namespace ::com::sun::star::sdbc; - using namespace ::com::sun::star::lang; - using namespace ::com::sun::star::sdbcx; - using namespace ::com::sun::star::container; - using namespace ::com::sun::star::datatransfer; - using namespace ::comphelper; - - //==================================================================== - //= OColumnTransferable - //==================================================================== - //-------------------------------------------------------------------- - OColumnTransferable::OColumnTransferable(const ::rtl::OUString& _rDatasource - ,const ::rtl::OUString& _rConnectionResource - ,const sal_Int32 _nCommandType - ,const ::rtl::OUString& _rCommand - ,const ::rtl::OUString& _rFieldName - ,sal_Int32 _nFormats) - :m_nFormatFlags(_nFormats) - { - implConstruct(_rDatasource,_rConnectionResource,_nCommandType, _rCommand, _rFieldName); - } - - //-------------------------------------------------------------------- - OColumnTransferable::OColumnTransferable(const ODataAccessDescriptor& _rDescriptor, sal_Int32 _nFormats ) - :m_nFormatFlags(_nFormats) - { - ::rtl::OUString sDataSource, sDatabaseLocation, sConnectionResource, sCommand, sFieldName; - if ( _rDescriptor.has( daDataSource ) ) _rDescriptor[ daDataSource ] >>= sDataSource; - if ( _rDescriptor.has( daDatabaseLocation ) ) _rDescriptor[ daDatabaseLocation ] >>= sDatabaseLocation; - if ( _rDescriptor.has( daConnectionResource ) ) _rDescriptor[ daConnectionResource ] >>= sConnectionResource; - if ( _rDescriptor.has( daCommand ) ) _rDescriptor[ daCommand ] >>= sCommand; - if ( _rDescriptor.has( daColumnName ) ) _rDescriptor[ daColumnName ] >>= sFieldName; - - sal_Int32 nCommandType = CommandType::TABLE; - OSL_VERIFY( _rDescriptor[ daCommandType ] >>= nCommandType ); - - - implConstruct( - sDataSource.getLength() ? sDataSource : sDatabaseLocation, - sConnectionResource, nCommandType, sCommand, sFieldName ); - - if ( m_nFormatFlags & CTF_COLUMN_DESCRIPTOR ) - { - if ( _rDescriptor.has( daConnection ) ) - m_aDescriptor[ daConnection ] = _rDescriptor[ daConnection ]; - if ( _rDescriptor.has( daColumnObject ) ) - m_aDescriptor[ daColumnObject ] = _rDescriptor[ daColumnObject ]; - } - } - - //-------------------------------------------------------------------- - OColumnTransferable::OColumnTransferable(const Reference< XPropertySet >& _rxForm, - const ::rtl::OUString& _rFieldName, const Reference< XPropertySet >& _rxColumn, - const Reference< XConnection >& _rxConnection, sal_Int32 _nFormats) - :m_nFormatFlags(_nFormats) - { - OSL_ENSURE(_rxForm.is(), "OColumnTransferable::OColumnTransferable: invalid form!"); - // collect the necessary information from the form - ::rtl::OUString sCommand; - sal_Int32 nCommandType = CommandType::TABLE; - ::rtl::OUString sDatasource,sURL; - - sal_Bool bTryToParse = sal_True; - try - { - _rxForm->getPropertyValue(FM_PROP_COMMANDTYPE) >>= nCommandType; - _rxForm->getPropertyValue(FM_PROP_COMMAND) >>= sCommand; - _rxForm->getPropertyValue(FM_PROP_DATASOURCE) >>= sDatasource; - _rxForm->getPropertyValue(FM_PROP_URL) >>= sURL; - bTryToParse = ::cppu::any2bool(_rxForm->getPropertyValue(FM_PROP_ESCAPE_PROCESSING)); - } - catch(Exception&) - { - OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !"); - } - - // If the data source is an SQL-statement and simple enough (means "select <field list> from <table> where ....") - // we are able to fake the drag information we are about to create. - if (bTryToParse && (CommandType::COMMAND == nCommandType)) - { - try - { - Reference< XTablesSupplier > xSupTab; - _rxForm->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSupTab; - - if(xSupTab.is()) - { - Reference< XNameAccess > xNames = xSupTab->getTables(); - if (xNames.is()) - { - Sequence< ::rtl::OUString > aTables = xNames->getElementNames(); - if (1 == aTables.getLength()) - { - sCommand = aTables[0]; - nCommandType = CommandType::TABLE; - } - } - } - } - catch(Exception&) - { - OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !"); - } - } - - implConstruct(sDatasource, sURL,nCommandType, sCommand, _rFieldName); - - if ((m_nFormatFlags & CTF_COLUMN_DESCRIPTOR) == CTF_COLUMN_DESCRIPTOR) - { - if (_rxColumn.is()) - m_aDescriptor[daColumnObject] <<= _rxColumn; - if (_rxConnection.is()) - m_aDescriptor[daConnection] <<= _rxConnection; - } - } - - //-------------------------------------------------------------------- - sal_uInt32 OColumnTransferable::getDescriptorFormatId() - { - static sal_uInt32 s_nFormat = (sal_uInt32)-1; - if ((sal_uInt32)-1 == s_nFormat) - { - s_nFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.ColumnDescriptorTransfer\"")); - OSL_ENSURE((sal_uInt32)-1 != s_nFormat, "OColumnTransferable::getDescriptorFormatId: bad exchange id!"); - } - return s_nFormat; - } - - //-------------------------------------------------------------------- - void OColumnTransferable::implConstruct( const ::rtl::OUString& _rDatasource - ,const ::rtl::OUString& _rConnectionResource - ,const sal_Int32 _nCommandType - ,const ::rtl::OUString& _rCommand - , const ::rtl::OUString& _rFieldName) - { - const sal_Unicode cSeparator = sal_Unicode(11); - const ::rtl::OUString sSeparator(&cSeparator, 1); - - m_sCompatibleFormat = ::rtl::OUString(); - m_sCompatibleFormat += _rDatasource; - m_sCompatibleFormat += sSeparator; - m_sCompatibleFormat += _rCommand; - m_sCompatibleFormat += sSeparator; - - sal_Unicode cCommandType; - switch (_nCommandType) - { - case CommandType::TABLE: - cCommandType = '0'; - break; - case CommandType::QUERY: - cCommandType = '1'; - break; - default: - cCommandType = '2'; - break; - } - m_sCompatibleFormat += ::rtl::OUString(&cCommandType, 1); - m_sCompatibleFormat += sSeparator; - m_sCompatibleFormat += _rFieldName; - - m_aDescriptor.clear(); - if ((m_nFormatFlags & CTF_COLUMN_DESCRIPTOR) == CTF_COLUMN_DESCRIPTOR) - { - m_aDescriptor.setDataSource(_rDatasource); - if ( _rConnectionResource.getLength() ) - m_aDescriptor[daConnectionResource] <<= _rConnectionResource; - - m_aDescriptor[daCommand] <<= _rCommand; - m_aDescriptor[daCommandType] <<= _nCommandType; - m_aDescriptor[daColumnName] <<= _rFieldName; - } - } - - //-------------------------------------------------------------------- - void OColumnTransferable::AddSupportedFormats() - { - if (CTF_CONTROL_EXCHANGE & m_nFormatFlags) - AddFormat(SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE); - - if (CTF_FIELD_DESCRIPTOR & m_nFormatFlags) - AddFormat(SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE); - - if (CTF_COLUMN_DESCRIPTOR & m_nFormatFlags) - AddFormat(getDescriptorFormatId()); - } - - //-------------------------------------------------------------------- - sal_Bool OColumnTransferable::GetData( const DataFlavor& _rFlavor ) - { - const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor); - switch (nFormatId) - { - case SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE: - case SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE: - return SetString(m_sCompatibleFormat, _rFlavor); - } - if (nFormatId == getDescriptorFormatId()) - return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor ); - - return sal_False; - } - - //-------------------------------------------------------------------- - sal_Bool OColumnTransferable::canExtractColumnDescriptor(const DataFlavorExVector& _rFlavors, sal_Int32 _nFormats) - { - sal_Bool bFieldFormat = 0 != (_nFormats & CTF_FIELD_DESCRIPTOR); - sal_Bool bControlFormat = 0 != (_nFormats & CTF_CONTROL_EXCHANGE); - sal_Bool bDescriptorFormat = 0 != (_nFormats & CTF_COLUMN_DESCRIPTOR); - for ( DataFlavorExVector::const_iterator aCheck = _rFlavors.begin(); - aCheck != _rFlavors.end(); - ++aCheck - ) - { - if (bFieldFormat && (SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE == aCheck->mnSotId)) - return sal_True; - if (bControlFormat && (SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE == aCheck->mnSotId)) - return sal_True; - if (bDescriptorFormat && (getDescriptorFormatId() == aCheck->mnSotId)) - return sal_True; - } - - return sal_False; - } - - //-------------------------------------------------------------------- - ODataAccessDescriptor OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper& _rData) - { - if (_rData.HasFormat(getDescriptorFormatId())) - { - // the object has a real descriptor object (not just the old compatible format) - - // extract the any from the transferable - DataFlavor aFlavor; -#if OSL_DEBUG_LEVEL > 0 - sal_Bool bSuccess = -#endif - SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor); - OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!"); - - Any aDescriptor = _rData.GetAny(aFlavor); - - // extract the property value sequence - Sequence< PropertyValue > aDescriptorProps; -#if OSL_DEBUG_LEVEL > 0 - bSuccess = -#endif - aDescriptor >>= aDescriptorProps; - OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!"); - - // build the real descriptor - return ODataAccessDescriptor(aDescriptorProps); - } - - // only the old (compatible) format exists -> use the other extract method ... - ::rtl::OUString sDatasource, sCommand, sFieldName,sDatabaseLocation,sConnectionResource; - sal_Int32 nCommandType = CommandType::COMMAND; - - ODataAccessDescriptor aDescriptor; - if (extractColumnDescriptor(_rData, sDatasource, sDatabaseLocation,sConnectionResource,nCommandType, sCommand, sFieldName)) - { - // and build an own descriptor - if ( sDatasource.getLength() ) - aDescriptor[daDataSource] <<= sDatasource; - if ( sDatabaseLocation.getLength() ) - aDescriptor[daDatabaseLocation] <<= sDatabaseLocation; - if ( sConnectionResource.getLength() ) - aDescriptor[daConnectionResource] <<= sConnectionResource; - - aDescriptor[daCommand] <<= sCommand; - aDescriptor[daCommandType] <<= nCommandType; - aDescriptor[daColumnName] <<= sFieldName; - } - return aDescriptor; - } - - //-------------------------------------------------------------------- - sal_Bool OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper& _rData - ,::rtl::OUString& _rDatasource - ,::rtl::OUString& _rDatabaseLocation - ,::rtl::OUString& _rConnectionResource - ,sal_Int32& _nCommandType - ,::rtl::OUString& _rCommand - ,::rtl::OUString& _rFieldName) - { - if ( _rData.HasFormat(getDescriptorFormatId()) ) - { - ODataAccessDescriptor aDescriptor = extractColumnDescriptor(_rData); - if ( aDescriptor.has(daDataSource) ) - aDescriptor[daDataSource] >>= _rDatasource; - if ( aDescriptor.has(daDatabaseLocation) ) - aDescriptor[daDatabaseLocation] >>= _rDatabaseLocation; - if ( aDescriptor.has(daConnectionResource) ) - aDescriptor[daConnectionResource] >>= _rConnectionResource; - - aDescriptor[daCommand] >>= _rCommand; - aDescriptor[daCommandType] >>= _nCommandType; - aDescriptor[daColumnName] >>= _rFieldName; - return sal_True; - } - - // check if we have a (string) format we can use .... - SotFormatStringId nRecognizedFormat = 0; - if (_rData.HasFormat(SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE)) - nRecognizedFormat = SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE; - if (_rData.HasFormat(SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE)) - nRecognizedFormat = SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE; - if (!nRecognizedFormat) - return sal_False; - - String sFieldDescription; - const_cast<TransferableDataHelper&>(_rData).GetString(nRecognizedFormat, sFieldDescription); - - const sal_Unicode cSeparator = sal_Unicode(11); - _rDatasource = sFieldDescription.GetToken(0, cSeparator); - _rCommand = sFieldDescription.GetToken(1, cSeparator); - _nCommandType = sFieldDescription.GetToken(2, cSeparator).ToInt32(); - _rFieldName = sFieldDescription.GetToken(3, cSeparator); - - return sal_True; - } - - //-------------------------------------------------------------------- - void OColumnTransferable::addDataToContainer( TransferDataContainer* _pContainer ) - { - OSL_ENSURE( _pContainer, "OColumnTransferable::addDataToContainer: invalid container!" ); - if ( _pContainer ) - { - if ( m_nFormatFlags & CTF_FIELD_DESCRIPTOR ) - _pContainer->CopyAny( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE, makeAny( m_sCompatibleFormat ) ); - - if ( m_nFormatFlags & CTF_CONTROL_EXCHANGE ) - _pContainer->CopyAny( SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE, makeAny( m_sCompatibleFormat ) ); - - if ( m_nFormatFlags & CTF_COLUMN_DESCRIPTOR ) - { - Any aContent = makeAny( m_aDescriptor.createPropertyValueSequence() ); - _pContainer->CopyAny( - sal::static_int_cast< sal_uInt16 >( getDescriptorFormatId() ), - aContent ); - } - } - } - - //==================================================================== - //= ODataAccessObjectTransferable - //==================================================================== - ODataAccessObjectTransferable::ODataAccessObjectTransferable( - const ::rtl::OUString& _rDatasource - ,const ::rtl::OUString& _rConnectionResource - ,const sal_Int32 _nCommandType - ,const ::rtl::OUString& _rCommand - ) - { - construct(_rDatasource,_rConnectionResource,_nCommandType,_rCommand,NULL,(CommandType::COMMAND == _nCommandType),_rCommand); - } - //-------------------------------------------------------------------- - ODataAccessObjectTransferable::ODataAccessObjectTransferable( - const ::rtl::OUString& _rDatasource - ,const ::rtl::OUString& _rConnectionResource - ,const sal_Int32 _nCommandType - ,const ::rtl::OUString& _rCommand - ,const Reference< XConnection >& _rxConnection) - { - OSL_ENSURE(_rxConnection.is(),"Wrong ctor used.!"); - construct(_rDatasource,_rConnectionResource,_nCommandType,_rCommand,_rxConnection,(CommandType::COMMAND == _nCommandType),_rCommand); - } - - // ----------------------------------------------------------------------------- - ODataAccessObjectTransferable::ODataAccessObjectTransferable(const Reference< XPropertySet >& _rxLivingForm) - { - // collect some properties of the form - ::rtl::OUString sDatasourceName,sConnectionResource; - sal_Int32 nObjectType = CommandType::COMMAND; - ::rtl::OUString sObjectName; - Reference< XConnection > xConnection; - try - { - _rxLivingForm->getPropertyValue(FM_PROP_COMMANDTYPE) >>= nObjectType; - _rxLivingForm->getPropertyValue(FM_PROP_COMMAND) >>= sObjectName; - _rxLivingForm->getPropertyValue(FM_PROP_DATASOURCE) >>= sDatasourceName; - _rxLivingForm->getPropertyValue(FM_PROP_URL) >>= sConnectionResource; - _rxLivingForm->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xConnection; - } - catch(Exception&) - { - OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !"); - return; - } - - String sObjectKind = (CommandType::TABLE == nObjectType) ? String('1') : String('0'); - - // check if the SQL-statement is modified - ::rtl::OUString sCompleteStatement; - try - { - _rxLivingForm->getPropertyValue(FM_PROP_ACTIVECOMMAND) >>= sCompleteStatement; - } - catch(Exception&) - { - OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !"); - return; - } - - construct( sDatasourceName - ,sConnectionResource - ,nObjectType - ,sObjectName,xConnection - ,!((CommandType::QUERY == nObjectType)) - ,sCompleteStatement); - } - - // ----------------------------------------------------------------------------- - void ODataAccessObjectTransferable::AddSupportedFormats() - { - sal_Int32 nObjectType = CommandType::COMMAND; - m_aDescriptor[daCommandType] >>= nObjectType; - switch (nObjectType) - { - case CommandType::TABLE: - AddFormat(SOT_FORMATSTR_ID_DBACCESS_TABLE); - break; - case CommandType::QUERY: - AddFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY); - break; - case CommandType::COMMAND: - AddFormat(SOT_FORMATSTR_ID_DBACCESS_COMMAND); - break; - } - - sal_Int32 nDescriptorLen = m_sCompatibleObjectDescription.getLength(); - if (nDescriptorLen) - { - if (m_sCompatibleObjectDescription.getStr()[nDescriptorLen] == 11) - m_sCompatibleObjectDescription = m_sCompatibleObjectDescription.copy(0, nDescriptorLen - 1); - - if (nDescriptorLen) - AddFormat(SOT_FORMATSTR_ID_SBA_DATAEXCHANGE); - } - } - - // ----------------------------------------------------------------------------- - sal_Bool ODataAccessObjectTransferable::GetData( const DataFlavor& rFlavor ) - { - sal_uIntPtr nFormat = SotExchange::GetFormat(rFlavor); - switch (nFormat) - { - case SOT_FORMATSTR_ID_DBACCESS_TABLE: - case SOT_FORMATSTR_ID_DBACCESS_QUERY: - case SOT_FORMATSTR_ID_DBACCESS_COMMAND: - return SetAny( makeAny(m_aDescriptor.createPropertyValueSequence()), rFlavor ); - - case SOT_FORMATSTR_ID_SBA_DATAEXCHANGE: - return SetString(m_sCompatibleObjectDescription, rFlavor); - } - return sal_False; - } - - // ----------------------------------------------------------------------------- - sal_Bool ODataAccessObjectTransferable::canExtractObjectDescriptor(const DataFlavorExVector& _rFlavors) - { - for ( DataFlavorExVector::const_iterator aCheck = _rFlavors.begin(); - aCheck != _rFlavors.end(); - ++aCheck - ) - { - if (SOT_FORMATSTR_ID_DBACCESS_TABLE == aCheck->mnSotId) - return sal_True; - if (SOT_FORMATSTR_ID_DBACCESS_QUERY == aCheck->mnSotId) - return sal_True; - if (SOT_FORMATSTR_ID_DBACCESS_COMMAND == aCheck->mnSotId) - return sal_True; - } - return sal_False; - } - - // ----------------------------------------------------------------------------- - ODataAccessDescriptor ODataAccessObjectTransferable::extractObjectDescriptor(const TransferableDataHelper& _rData) - { - sal_Int32 nKnownFormatId = 0; - if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_TABLE ) ) - nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_TABLE; - if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_QUERY ) ) - nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_QUERY; - if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_COMMAND ) ) - nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_COMMAND; - - if (0 != nKnownFormatId) - { - // extract the any from the transferable - DataFlavor aFlavor; -#if OSL_DEBUG_LEVEL > 0 - sal_Bool bSuccess = -#endif - SotExchange::GetFormatDataFlavor(nKnownFormatId, aFlavor); - OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!"); - - Any aDescriptor = _rData.GetAny(aFlavor); - - // extract the property value sequence - Sequence< PropertyValue > aDescriptorProps; -#if OSL_DEBUG_LEVEL > 0 - bSuccess = -#endif - aDescriptor >>= aDescriptorProps; - OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!"); - - // build the real descriptor - return ODataAccessDescriptor(aDescriptorProps); - } - - OSL_FAIL( "OColumnTransferable::extractColumnDescriptor: unsupported formats only!" ); - return ODataAccessDescriptor(); - } - - // ----------------------------------------------------------------------------- - void ODataAccessObjectTransferable::addCompatibleSelectionDescription( const Sequence< Any >& _rSelRows ) - { - const sal_Unicode cSeparator(11); - const ::rtl::OUString sSeparator(&cSeparator, 1); - - const Any* pSelRows = _rSelRows.getConstArray(); - const Any* pSelRowsEnd = pSelRows + _rSelRows.getLength(); - for ( ; pSelRows < pSelRowsEnd; ++pSelRows ) - { - sal_Int32 nSelectedRow( 0 ); - OSL_VERIFY( *pSelRows >>= nSelectedRow ); - - m_sCompatibleObjectDescription += ::rtl::OUString::valueOf((sal_Int32)nSelectedRow); - m_sCompatibleObjectDescription += sSeparator; - } - } - - // ----------------------------------------------------------------------------- - void ODataAccessObjectTransferable::ObjectReleased() - { - m_aDescriptor.clear(); - } - // ----------------------------------------------------------------------------- - void ODataAccessObjectTransferable::construct( const ::rtl::OUString& _rDatasource - ,const ::rtl::OUString& _rConnectionResource - ,const sal_Int32 _nCommandType - ,const ::rtl::OUString& _rCommand - ,const Reference< XConnection >& _rxConnection - ,sal_Bool _bAddCommand - ,const ::rtl::OUString& _sActiveCommand) - { - m_aDescriptor.setDataSource(_rDatasource); - // build the descriptor (the property sequence) - if ( _rConnectionResource.getLength() ) - m_aDescriptor[daConnectionResource] <<= _rConnectionResource; - if ( _rxConnection.is() ) - m_aDescriptor[daConnection] <<= _rxConnection; - m_aDescriptor[daCommand] <<= _rCommand; - m_aDescriptor[daCommandType] <<= _nCommandType; - - // extract the single values from the sequence - - ::rtl::OUString sObjectName; - ::rtl::OUString sDatasourceName = _rDatasource; - sObjectName = _rCommand; - - // for compatibility: create a string which can be used for the SOT_FORMATSTR_ID_SBA_DATAEXCHANGE format - - sal_Bool bTreatAsStatement = (CommandType::COMMAND == _nCommandType); - // statements are - in this old and ugly format - described as queries - - const sal_Unicode cSeparator = sal_Unicode(11); - const ::rtl::OUString sSeparator(&cSeparator, 1); - - const sal_Unicode cTableMark = '1'; - const sal_Unicode cQueryMark = '0'; - - // build the descriptor string - m_sCompatibleObjectDescription += sDatasourceName; - m_sCompatibleObjectDescription += sSeparator; - m_sCompatibleObjectDescription += bTreatAsStatement ? ::rtl::OUString() : sObjectName; - m_sCompatibleObjectDescription += sSeparator; - switch (_nCommandType) - { - case CommandType::TABLE: - m_sCompatibleObjectDescription += ::rtl::OUString(&cTableMark, 1); - break; - case CommandType::QUERY: - m_sCompatibleObjectDescription += ::rtl::OUString(&cQueryMark, 1); - break; - case CommandType::COMMAND: - m_sCompatibleObjectDescription += ::rtl::OUString(&cQueryMark, 1); - // think of it as a query - break; - } - m_sCompatibleObjectDescription += sSeparator; - m_sCompatibleObjectDescription += _bAddCommand ? _sActiveCommand : ::rtl::OUString(); - m_sCompatibleObjectDescription += sSeparator; - } - - //-------------------------------------------------------------------- - OMultiColumnTransferable::OMultiColumnTransferable(const Sequence< PropertyValue >& _aDescriptors) : m_aDescriptors(_aDescriptors) - { - } - //-------------------------------------------------------------------- - sal_uInt32 OMultiColumnTransferable::getDescriptorFormatId() - { - static sal_uInt32 s_nFormat = (sal_uInt32)-1; - if ((sal_uInt32)-1 == s_nFormat) - { - s_nFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.MultipleColumnDescriptorTransfer\"")); - OSL_ENSURE((sal_uInt32)-1 != s_nFormat, "OColumnTransferable::getDescriptorFormatId: bad exchange id!"); - } - return s_nFormat; - } - //-------------------------------------------------------------------- - void OMultiColumnTransferable::AddSupportedFormats() - { - AddFormat(getDescriptorFormatId()); - } - //-------------------------------------------------------------------- - void OMultiColumnTransferable::push_back(ODataAccessDescriptor& _aDescriptor) - { - const sal_Int32 nCount = m_aDescriptors.getLength(); - m_aDescriptors.realloc(nCount+1); - m_aDescriptors[nCount].Value <<= _aDescriptor.createPropertyValueSequence(); - } - //-------------------------------------------------------------------- - sal_Bool OMultiColumnTransferable::GetData( const DataFlavor& _rFlavor ) - { - const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor); - if (nFormatId == getDescriptorFormatId()) - { - return SetAny( makeAny( m_aDescriptors ), _rFlavor ); - } - - return sal_False; - } - - //-------------------------------------------------------------------- - sal_Bool OMultiColumnTransferable::canExtractDescriptor(const DataFlavorExVector& _rFlavors) - { - DataFlavorExVector::const_iterator aCheck = _rFlavors.begin(); - for ( ; - aCheck != _rFlavors.end() && getDescriptorFormatId() == aCheck->mnSotId; - ++aCheck - ) - ; - - return aCheck == _rFlavors.end(); - } - - //-------------------------------------------------------------------- - Sequence< PropertyValue > OMultiColumnTransferable::extractDescriptor(const TransferableDataHelper& _rData) - { - Sequence< PropertyValue > aList; - if (_rData.HasFormat(getDescriptorFormatId())) - { - // extract the any from the transferable - DataFlavor aFlavor; -#if OSL_DEBUG_LEVEL > 0 - sal_Bool bSuccess = -#endif - SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor); - OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!"); - - _rData.GetAny(aFlavor) >>= aList; - } // if (_rData.HasFormat(getDescriptorFormatId())) - return aList; - } - // ----------------------------------------------------------------------------- - void OMultiColumnTransferable::ObjectReleased() - { - m_aDescriptors.realloc(0); - } - -//........................................................................ -} // namespace svx -//........................................................................ - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/fmcomp/dbaobjectex.cxx b/svx/source/fmcomp/dbaobjectex.cxx deleted file mode 100644 index 8f50991d31..0000000000 --- a/svx/source/fmcomp/dbaobjectex.cxx +++ /dev/null @@ -1,185 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svx.hxx" -#include <svx/dbaobjectex.hxx> -#include <osl/diagnose.h> -#include <com/sun/star/sdbcx/XTablesSupplier.hpp> -#include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> -#include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> -#include "fmprop.hrc" -#include <comphelper/extract.hxx> -#include <sot/formats.hxx> -#include <sot/exchange.hxx> -#include <comphelper/propertysetinfo.hxx> -#include "fmprop.hrc" - -//........................................................................ -namespace svx -{ -//........................................................................ - - using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::beans; - using namespace ::com::sun::star::sdb; - using namespace ::com::sun::star::sdbc; - using namespace ::com::sun::star::lang; - using namespace ::com::sun::star::ucb; - using namespace ::com::sun::star::sdbcx; - using namespace ::com::sun::star::container; - using namespace ::com::sun::star::datatransfer; - using namespace ::comphelper; - - //==================================================================== - //= OComponentTransferable - //==================================================================== - //-------------------------------------------------------------------- - OComponentTransferable::OComponentTransferable(const ::rtl::OUString& _rDatasourceOrLocation - ,const Reference< XContent>& _xContent) - { - m_aDescriptor.setDataSource(_rDatasourceOrLocation); - m_aDescriptor[daComponent] <<= _xContent; - } - - - //-------------------------------------------------------------------- - sal_uInt32 OComponentTransferable::getDescriptorFormatId(sal_Bool _bExtractForm) - { - static sal_uInt32 s_nReportFormat = (sal_uInt32)-1; - static sal_uInt32 s_nFormFormat = (sal_uInt32)-1; - if ( _bExtractForm && (sal_uInt32)-1 == s_nFormFormat ) - { - s_nFormFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.FormComponentDescriptorTransfer\"" )); - OSL_ENSURE((sal_uInt32)-1 != s_nFormFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!"); - } - else if ( !_bExtractForm && (sal_uInt32)-1 == s_nReportFormat) - { - s_nReportFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.ReportComponentDescriptorTransfer\"")); - OSL_ENSURE((sal_uInt32)-1 != s_nReportFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!"); - } - return _bExtractForm ? s_nFormFormat : s_nReportFormat; - } - - //-------------------------------------------------------------------- - void OComponentTransferable::AddSupportedFormats() - { - sal_Bool bForm = sal_True; - try - { - Reference<XPropertySet> xProp; - m_aDescriptor[daComponent] >>= xProp; - if ( xProp.is() ) - xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm"))) >>= bForm; - } - catch(Exception) - {} - AddFormat(getDescriptorFormatId(bForm)); - } - - //-------------------------------------------------------------------- - sal_Bool OComponentTransferable::GetData( const DataFlavor& _rFlavor ) - { - const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor); - if ( nFormatId == getDescriptorFormatId(sal_True) || nFormatId == getDescriptorFormatId(sal_False) ) - return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor ); - - return sal_False; - } - - //-------------------------------------------------------------------- - sal_Bool OComponentTransferable::canExtractComponentDescriptor(const DataFlavorExVector& _rFlavors,sal_Bool _bForm ) - { - DataFlavorExVector::const_iterator aEnd = _rFlavors.end(); - for ( DataFlavorExVector::const_iterator aCheck = _rFlavors.begin(); - aCheck != aEnd; - ++aCheck - ) - { - if ( getDescriptorFormatId(_bForm) == aCheck->mnSotId ) - return sal_True; - } - - return sal_False; - } - - //-------------------------------------------------------------------- - ODataAccessDescriptor OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData) - { - sal_Bool bForm = _rData.HasFormat(getDescriptorFormatId(sal_True)); - if ( bForm || _rData.HasFormat(getDescriptorFormatId(sal_False)) ) - { - // the object has a real descriptor object (not just the old compatible format) - - // extract the any from the transferable - DataFlavor aFlavor; -#if OSL_DEBUG_LEVEL > 0 - sal_Bool bSuccess = -#endif - SotExchange::GetFormatDataFlavor(getDescriptorFormatId(bForm), aFlavor); - OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid data format (no flavor)!"); - - Any aDescriptor = _rData.GetAny(aFlavor); - - // extract the property value sequence - Sequence< PropertyValue > aDescriptorProps; -#if OSL_DEBUG_LEVEL > 0 - bSuccess = -#endif - aDescriptor >>= aDescriptorProps; - OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid clipboard format!"); - - // build the real descriptor - return ODataAccessDescriptor(aDescriptorProps); - } - - return ODataAccessDescriptor(); - } - - //-------------------------------------------------------------------- - sal_Bool OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData - ,sal_Bool _bExtractForm - , ::rtl::OUString& _rDatasourceOrLocation - , ::com::sun::star::uno::Reference< XContent>& _xContent) - { - if ( _rData.HasFormat( getDescriptorFormatId(_bExtractForm)) ) - { - ODataAccessDescriptor aDescriptor = extractComponentDescriptor(_rData); - _rDatasourceOrLocation = aDescriptor.getDataSource(); - aDescriptor[daComponent] >>= _xContent; - return sal_True; - } - - return sal_False; - } -//........................................................................ -} // namespace svx -//........................................................................ - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/fmcomp/fmgridcl.cxx b/svx/source/fmcomp/fmgridcl.cxx deleted file mode 100644 index 0de0841280..0000000000 --- a/svx/source/fmcomp/fmgridcl.cxx +++ /dev/null @@ -1,2138 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svx.hxx" - -#include "svx/dbexch.hrc" -#include "svx/fmgridif.hxx" -#include "fmitems.hxx" -#include "fmprop.hrc" -#include "svx/fmtools.hxx" -#include "svx/fmresids.hrc" -#include "fmservs.hxx" -#include "fmurl.hxx" -#include "formcontrolfactory.hxx" -#include "gridcell.hxx" -#include "gridcols.hxx" -#include "svx/dbaexchange.hxx" -#include "svx/dialmgr.hxx" -#include "svx/dialogs.hrc" -#include "svx/fmgridcl.hxx" -#include "svx/svxdlg.hxx" -#include "svx/svxids.hrc" -#include "trace.hxx" - -#include <com/sun/star/form/XConfirmDeleteListener.hpp> -#include <com/sun/star/form/XFormComponent.hpp> -#include <com/sun/star/form/XGridColumnFactory.hpp> -#include <com/sun/star/io/XPersistObject.hpp> -#include <com/sun/star/sdb/CommandType.hpp> -#include <com/sun/star/sdb/RowChangeAction.hpp> -#include <com/sun/star/sdb/XQueriesSupplier.hpp> -#include <com/sun/star/sdbc/DataType.hpp> -#include <com/sun/star/sdbc/XPreparedStatement.hpp> -#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> -#include <com/sun/star/sdbcx/XDeleteRows.hpp> -#include <com/sun/star/sdbcx/XTablesSupplier.hpp> -#include <com/sun/star/uno/XNamingService.hpp> -#include <com/sun/star/util/XNumberFormats.hpp> -#include <com/sun/star/util/XNumberFormatsSupplier.hpp> -#include <com/sun/star/util/XURLTransformer.hpp> -#include <com/sun/star/view/XSelectionSupplier.hpp> - -#ifndef _SVSTDARR_STRINGSDTOR -#define _SVSTDARR_STRINGSDTOR -#define _SVSTDARR_ULONGS -#include <svl/svstdarr.hxx> -#endif - -#include <comphelper/extract.hxx> -#include <comphelper/numbers.hxx> -#include <comphelper/processfactory.hxx> -#include <comphelper/property.hxx> -#include <connectivity/dbtools.hxx> -#include <sfx2/dispatch.hxx> -#include <sfx2/viewfrm.hxx> -#include <svl/eitem.hxx> -#include <svtools/fmtfield.hxx> -#include <svl/numuno.hxx> -#include <tools/multisel.hxx> -#include <tools/shl.hxx> -#include <tools/diagnose_ex.h> -#include <vcl/help.hxx> -#include <vcl/image.hxx> -#include <vcl/longcurr.hxx> -#include <vcl/menu.hxx> - -#include <math.h> - -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::view; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::sdb; -using namespace ::com::sun::star::form; -using namespace ::com::sun::star::util; -using namespace ::com::sun::star::container; -using namespace ::cppu; -using namespace ::svxform; -using namespace ::svx; - -//============================================================================== -//------------------------------------------------------------------------------ -::rtl::OUString FieldServiceFromId(sal_Int32 nID) -{ - switch (nID) - { - case SID_FM_EDIT : return FM_COL_TEXTFIELD; - case SID_FM_COMBOBOX : return FM_COL_COMBOBOX; - case SID_FM_LISTBOX : return FM_COL_LISTBOX; - case SID_FM_CHECKBOX : return FM_COL_CHECKBOX; - case SID_FM_DATEFIELD : return FM_COL_DATEFIELD; - case SID_FM_TIMEFIELD : return FM_COL_TIMEFIELD; - case SID_FM_NUMERICFIELD : return FM_COL_NUMERICFIELD; - case SID_FM_CURRENCYFIELD : return FM_COL_CURRENCYFIELD; - case SID_FM_PATTERNFIELD : return FM_COL_PATTERNFIELD; - case SID_FM_FORMATTEDFIELD : return FM_COL_FORMATTEDFIELD; - } - return ::rtl::OUString(); -} - -//============================================================================== -struct FmGridHeaderData -{ - ODataAccessDescriptor aDropData; - Point aDropPosPixel; - sal_Int8 nDropAction; - Reference< XInterface > xDroppedStatement; - Reference< XInterface > xDroppedResultSet; -}; - -//============================================================================== -//------------------------------------------------------------------------------ -const sal_Int16 nChangeTypeOffset = 1000; -void SetMenuItem(const ImageList& rList, sal_uInt16 nID, Menu* pMenu, Menu& rNewMenu, sal_Bool bDesignMode = sal_True, sal_Int16 nOffset = nChangeTypeOffset) -{ - pMenu->SetItemImage(nID, rList.GetImage(nID)); - pMenu->EnableItem(nID, bDesignMode); - rNewMenu.InsertItem(nID + nOffset, pMenu->GetItemText(nID)); - rNewMenu.SetItemImage(nID + nOffset, rList.GetImage(nID)); - rNewMenu.SetHelpId(nID + nOffset, pMenu->GetHelpId(nID)); - rNewMenu.EnableItem(nID + nOffset, bDesignMode); -} - -//------------------------------------------------------------------------------ -FmGridHeader::FmGridHeader( BrowseBox* pParent, WinBits nWinBits) - :EditBrowserHeader(pParent, nWinBits) - ,DropTargetHelper(this) - ,m_pImpl(new FmGridHeaderData) -{ -} - -//------------------------------------------------------------------------------ -FmGridHeader::~FmGridHeader() -{ - delete m_pImpl; -} - -//------------------------------------------------------------------------------ -sal_uInt16 FmGridHeader::GetModelColumnPos(sal_uInt16 nId) const -{ - return static_cast<FmGridControl*>(GetParent())->GetModelColumnPos(nId); -} -//--------------------------------------------------------------------------------------- -void FmGridHeader::notifyColumnSelect(sal_uInt16 nColumnId) -{ - sal_uInt16 nPos = GetModelColumnPos(nColumnId); - Reference< XIndexAccess > xColumns(((FmGridControl*)GetParent())->GetPeer()->getColumns(), UNO_QUERY); - if ( nPos < xColumns->getCount() ) - { - Reference< XSelectionSupplier > xSelSupplier(xColumns, UNO_QUERY); - if ( xSelSupplier.is() ) - { - Reference< XPropertySet > xColumn; - xColumns->getByIndex(nPos) >>= xColumn; - xSelSupplier->select(makeAny(xColumn)); - } - } -} -//------------------------------------------------------------------------------ -void FmGridHeader::Select() -{ - EditBrowserHeader::Select(); - notifyColumnSelect(GetCurItemId()); -} - -//------------------------------------------------------------------------------ -void FmGridHeader::RequestHelp( const HelpEvent& rHEvt ) -{ - sal_uInt16 nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) ); - if ( nItemId ) - { - if ( rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON) ) - { - Rectangle aItemRect = GetItemRect( nItemId ); - Point aPt = OutputToScreenPixel( aItemRect.TopLeft() ); - aItemRect.Left() = aPt.X(); - aItemRect.Top() = aPt.Y(); - aPt = OutputToScreenPixel( aItemRect.BottomRight() ); - aItemRect.Right() = aPt.X(); - aItemRect.Bottom() = aPt.Y(); - - sal_uInt16 nPos = GetModelColumnPos(nItemId); - Reference< ::com::sun::star::container::XIndexContainer > xColumns(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns()); - try - { - Reference< ::com::sun::star::beans::XPropertySet > xColumn(xColumns->getByIndex(nPos),UNO_QUERY); - ::rtl::OUString aHelpText; - xColumn->getPropertyValue(FM_PROP_HELPTEXT) >>= aHelpText; - if ( !aHelpText.getLength() ) - xColumn->getPropertyValue(FM_PROP_DESCRIPTION) >>= aHelpText; - if ( aHelpText.getLength() ) - { - if ( rHEvt.GetMode() & HELPMODE_BALLOON ) - Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText ); - else - Help::ShowQuickHelp( this, aItemRect, aHelpText ); - return; - } - } - catch(Exception&) - { - return; - } - } - } - EditBrowserHeader::RequestHelp( rHEvt ); -} - -//------------------------------------------------------------------------------ -sal_Int8 FmGridHeader::AcceptDrop( const AcceptDropEvent& rEvt ) -{ - // drop allowed in design mode only - if (!static_cast<FmGridControl*>(GetParent())->IsDesignMode()) - return DND_ACTION_NONE; - - // search for recognized formats - const DataFlavorExVector& rFlavors = GetDataFlavorExVector(); - if (OColumnTransferable::canExtractColumnDescriptor(rFlavors, CTF_COLUMN_DESCRIPTOR | CTF_FIELD_DESCRIPTOR)) - return rEvt.mnAction; - - return DND_ACTION_NONE; -} - -//------------------------------------------------------------------------------ -sal_Int8 FmGridHeader::ExecuteDrop( const ExecuteDropEvent& _rEvt ) -{ - if (!static_cast<FmGridControl*>(GetParent())->IsDesignMode()) - return DND_ACTION_NONE; - - TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable); - - // check the formats - sal_Bool bColumnDescriptor = OColumnTransferable::canExtractColumnDescriptor(aDroppedData.GetDataFlavorExVector(), CTF_COLUMN_DESCRIPTOR); - sal_Bool bFieldDescriptor = OColumnTransferable::canExtractColumnDescriptor(aDroppedData.GetDataFlavorExVector(), CTF_FIELD_DESCRIPTOR); - if (!bColumnDescriptor && !bFieldDescriptor) - { - OSL_FAIL("FmGridHeader::ExecuteDrop: should never have reached this (no extractable format)!"); - return DND_ACTION_NONE; - } - - // extract the descriptor - ::rtl::OUString sDatasouce, sCommand, sFieldName,sDatabaseLocation,sConnnectionResource; - sal_Int32 nCommandType = CommandType::COMMAND; - Reference< XPreparedStatement > xStatement; - Reference< XResultSet > xResultSet; - Reference< XPropertySet > xField; - Reference< XConnection > xConnection; - - ODataAccessDescriptor aColumn = OColumnTransferable::extractColumnDescriptor(aDroppedData); - if (aColumn.has(daDataSource)) aColumn[daDataSource] >>= sDatasouce; - if (aColumn.has(daDatabaseLocation)) aColumn[daDatabaseLocation] >>= sDatabaseLocation; - if (aColumn.has(daConnectionResource)) aColumn[daConnectionResource] >>= sConnnectionResource; - if (aColumn.has(daCommand)) aColumn[daCommand] >>= sCommand; - if (aColumn.has(daCommandType)) aColumn[daCommandType] >>= nCommandType; - if (aColumn.has(daColumnName)) aColumn[daColumnName] >>= sFieldName; - if (aColumn.has(daColumnObject))aColumn[daColumnObject] >>= xField; - if (aColumn.has(daConnection)) aColumn[daConnection] >>= xConnection; - - if ( !sFieldName.getLength() - || !sCommand.getLength() - || ( !sDatasouce.getLength() - && !sDatabaseLocation.getLength() - && !xConnection.is() - ) - ) - { - OSL_FAIL( "FmGridHeader::ExecuteDrop: somebody started a nonsense drag operation!!" ); - return DND_ACTION_NONE; - } - - try - { - // need a connection - if (!xConnection.is()) - { // the transferable did not contain the connection -> build an own one - try - { - ::rtl::OUString sSignificantSource( sDatasouce.getLength() ? sDatasouce : sDatabaseLocation ); - xConnection = OStaticDataAccessTools().getConnection_withFeedback(sSignificantSource, ::rtl::OUString(),::rtl::OUString(),static_cast<FmGridControl*>(GetParent())->getServiceManager()); - } - catch(NoSuchElementException&) - { // allowed, means sDatasouce isn't a valid data source name .... - } - catch(Exception&) - { - OSL_FAIL("FmGridHeader::ExecuteDrop: could not retrieve the database access object !"); - } - - if (!xConnection.is()) - { - OSL_FAIL("FmGridHeader::ExecuteDrop: could not retrieve the database access object !"); - return DND_ACTION_NONE; - } - } - - // try to obtain the column object - if (!xField.is()) - { -#ifdef DBG_UTIL - Reference< XServiceInfo > xServiceInfo(xConnection, UNO_QUERY); - DBG_ASSERT(xServiceInfo.is() && xServiceInfo->supportsService(SRV_SDB_CONNECTION), "FmGridHeader::ExecuteDrop: invalid connection (no database access connection !)"); -#endif - - Reference< XNameAccess > xFields; - switch (nCommandType) - { - case CommandType::TABLE: - { - Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY); - Reference< XColumnsSupplier > xSupplyColumns; - xSupplyTables->getTables()->getByName(sCommand) >>= xSupplyColumns; - xFields = xSupplyColumns->getColumns(); - } - break; - case CommandType::QUERY: - { - Reference< XQueriesSupplier > xSupplyQueries(xConnection, UNO_QUERY); - Reference< XColumnsSupplier > xSupplyColumns; - xSupplyQueries->getQueries()->getByName(sCommand) >>= xSupplyColumns; - xFields = xSupplyColumns->getColumns(); - } - break; - default: - { - xStatement = xConnection->prepareStatement(sCommand); - // not interested in any results - - Reference< XPropertySet > xStatProps(xStatement,UNO_QUERY); - xStatProps->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MaxRows")), makeAny(sal_Int32(0))); - - xResultSet = xStatement->executeQuery(); - Reference< XColumnsSupplier > xSupplyCols(xResultSet, UNO_QUERY); - if (xSupplyCols.is()) - xFields = xSupplyCols->getColumns(); - } - } - - if (xFields.is() && xFields->hasByName(sFieldName)) - xFields->getByName(sFieldName) >>= xField; - - if (!xField.is()) - { - ::comphelper::disposeComponent(xStatement); - return DND_ACTION_NONE; - } - } - - // do the drop asynchronously - // (85957 - UI actions within the drop are not allowed, but we want to open a popup menu) - m_pImpl->aDropData = aColumn; - m_pImpl->aDropData[daConnection] <<= xConnection; - m_pImpl->aDropData[daColumnObject] <<= xField; - - m_pImpl->nDropAction = _rEvt.mnAction; - m_pImpl->aDropPosPixel = _rEvt.maPosPixel; - m_pImpl->xDroppedStatement = xStatement; - m_pImpl->xDroppedResultSet = xResultSet; - - PostUserEvent(LINK(this, FmGridHeader, OnAsyncExecuteDrop)); - } - catch (Exception&) - { - OSL_FAIL("FmGridHeader::ExecuteDrop: caught an exception while creatin' the column !"); - ::comphelper::disposeComponent(xStatement); - return sal_False; - } - - return DND_ACTION_LINK; -} - -//------------------------------------------------------------------------------ -IMPL_LINK( FmGridHeader, OnAsyncExecuteDrop, void*, /*NOTINTERESTEDIN*/ ) -{ - ::rtl::OUString sCommand, sFieldName,sURL; - sal_Int32 nCommandType = CommandType::COMMAND; - Reference< XPropertySet > xField; - Reference< XConnection > xConnection; - - ::rtl::OUString sDatasouce = m_pImpl->aDropData.getDataSource(); - if ( !sDatasouce.getLength() && m_pImpl->aDropData.has(daConnectionResource) ) - m_pImpl->aDropData[daConnectionResource] >>= sURL; - m_pImpl->aDropData[daCommand] >>= sCommand; - m_pImpl->aDropData[daCommandType] >>= nCommandType; - m_pImpl->aDropData[daColumnName] >>= sFieldName; - m_pImpl->aDropData[daConnection] >>= xConnection; - m_pImpl->aDropData[daColumnObject] >>= xField; - - try - { - // need number formats - Reference< XNumberFormatsSupplier > xSupplier = OStaticDataAccessTools().getNumberFormats(xConnection, sal_True); - Reference< XNumberFormats > xNumberFormats; - if (xSupplier.is()) - xNumberFormats = xSupplier->getNumberFormats(); - if (!xNumberFormats.is()) - { - ::comphelper::disposeComponent(m_pImpl->xDroppedResultSet); - ::comphelper::disposeComponent(m_pImpl->xDroppedStatement); - return 0L; - } - - // Vom Feld werden nun zwei Informationen benoetigt: - // a.) Name des Feldes fuer Label und ControlSource - // b.) FormatKey, um festzustellen, welches Feld erzeugt werden soll - sal_Int32 nDataType = 0; - xField->getPropertyValue(FM_PROP_FIELDTYPE) >>= nDataType; - // diese Datentypen koennen im Gridcontrol nicht verarbeitet werden - switch (nDataType) - { - case DataType::BLOB: - case DataType::LONGVARBINARY: - case DataType::BINARY: - case DataType::VARBINARY: - case DataType::OTHER: - ::comphelper::disposeComponent(m_pImpl->xDroppedResultSet); - ::comphelper::disposeComponent(m_pImpl->xDroppedStatement); - return 0L; - } - - // Erstellen der Column - Reference< XIndexContainer > xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns()); - Reference< XGridColumnFactory > xFactory(xCols, UNO_QUERY); - - sal_uInt16 nColId = GetItemId(m_pImpl->aDropPosPixel); - // EinfuegePosition, immer vor der aktuellen Spalte - sal_uInt16 nPos = GetModelColumnPos(nColId); - Reference< XPropertySet > xCol, xSecondCol; - - // erzeugen der Column in abhaengigkeit vom type, default textfeld - SvULongs aPossibleTypes; - switch (nDataType) - { - case DataType::BIT: - case DataType::BOOLEAN: - aPossibleTypes.Insert(SID_FM_CHECKBOX, aPossibleTypes.Count()); - break; - case DataType::TINYINT: - case DataType::SMALLINT: - case DataType::INTEGER: - aPossibleTypes.Insert(SID_FM_NUMERICFIELD, aPossibleTypes.Count()); - aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count()); - break; - case DataType::REAL: - case DataType::DOUBLE: - case DataType::NUMERIC: - case DataType::DECIMAL: - aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count()); - aPossibleTypes.Insert(SID_FM_NUMERICFIELD, aPossibleTypes.Count()); - break; - case DataType::TIMESTAMP: - aPossibleTypes.Insert(SID_FM_TWOFIELDS_DATE_N_TIME, aPossibleTypes.Count()); - aPossibleTypes.Insert(SID_FM_DATEFIELD, aPossibleTypes.Count()); - aPossibleTypes.Insert(SID_FM_TIMEFIELD, aPossibleTypes.Count()); - aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count()); - break; - case DataType::DATE: - aPossibleTypes.Insert(SID_FM_DATEFIELD, aPossibleTypes.Count()); - aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count()); - break; - case DataType::TIME: - aPossibleTypes.Insert(SID_FM_TIMEFIELD, aPossibleTypes.Count()); - aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count()); - break; - case DataType::CHAR: - case DataType::VARCHAR: - case DataType::LONGVARCHAR: - default: - aPossibleTypes.Insert(SID_FM_EDIT, aPossibleTypes.Count()); - aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count()); - break; - } - // if it's a currency field, a a "currency field" option - try - { - if ( ::comphelper::hasProperty(FM_PROP_ISCURRENCY, xField) - && ::comphelper::getBOOL(xField->getPropertyValue(FM_PROP_ISCURRENCY))) - aPossibleTypes.Insert(SID_FM_CURRENCYFIELD, 0); - } - catch(Exception&) - { - OSL_FAIL("FmGridHeader::ExecuteDrop: Exception occurred!"); - } - - sal_Bool bDateNTimeCol = sal_False; - if (aPossibleTypes.Count() != 0) - { - sal_Int32 nPreferedType = aPossibleTypes[0]; - if ((m_pImpl->nDropAction == DND_ACTION_LINK) && (aPossibleTypes.Count() > 1)) - { - ImageList aImageList( SVX_RES(RID_SVXIMGLIST_FMEXPL) ); - - PopupMenu aInsertMenu(SVX_RES(RID_SVXMNU_COLS)); - PopupMenu aTypeMenu; - PopupMenu* pMenu = aInsertMenu.GetPopupMenu(SID_FM_INSERTCOL); - for (sal_uInt32 i=0; i<aPossibleTypes.Count(); ++i) - SetMenuItem(aImageList, sal_uInt16(aPossibleTypes[(sal_uInt16)i]), pMenu, aTypeMenu, sal_True, 0); - nPreferedType = aTypeMenu.Execute(this, m_pImpl->aDropPosPixel); - } - - bDateNTimeCol = nPreferedType == SID_FM_TWOFIELDS_DATE_N_TIME; - sal_uInt16 nColCount = bDateNTimeCol ? 2 : 1; - ::rtl::OUString sFieldService; - while (nColCount--) - { - if (bDateNTimeCol) - nPreferedType = nColCount ? SID_FM_DATEFIELD : SID_FM_TIMEFIELD; - - sFieldService = FieldServiceFromId(nPreferedType); - Reference< XPropertySet > xThisRoundCol; - if ( sFieldService.getLength() ) - xThisRoundCol = xFactory->createColumn(sFieldService); - if (nColCount) - xSecondCol = xThisRoundCol; - else - xCol = xThisRoundCol; - } - } - - if (!xCol.is() || (bDateNTimeCol && !xSecondCol.is())) - { - ::comphelper::disposeComponent(xCol); // in case only the creation of the second column failed - ::comphelper::disposeComponent(m_pImpl->xDroppedResultSet); - ::comphelper::disposeComponent(m_pImpl->xDroppedStatement); - return 0L; - } - - if (bDateNTimeCol) - { - String sTimePostfix( SVX_RES( RID_STR_POSTFIX_TIME ) ); - xCol->setPropertyValue(FM_PROP_LABEL, makeAny( ::rtl::OUString( sFieldName + sTimePostfix ) ) ); - - String sDatePostfix( SVX_RES( RID_STR_POSTFIX_DATE ) ); - xSecondCol->setPropertyValue(FM_PROP_LABEL, makeAny( ::rtl::OUString( sFieldName + sDatePostfix ) ) ); - } - else - xCol->setPropertyValue(FM_PROP_LABEL, makeAny(sFieldName)); - - FormControlFactory aControlFactory( ::comphelper::getProcessServiceFactory() ); - aControlFactory.initializeControlModel( DocumentClassification::classifyHostDocument( xCols ), xCol ); - aControlFactory.initializeFieldDependentProperties( xField, xCol, xNumberFormats ); - - xCol->setPropertyValue(FM_PROP_CONTROLSOURCE, makeAny(sFieldName)); - if ( xSecondCol.is() ) - xSecondCol->setPropertyValue(FM_PROP_CONTROLSOURCE, makeAny(sFieldName)); - - if (bDateNTimeCol) - { - String sRealName,sPurePostfix; - - String aPostfix[] = { - String( SVX_RES( RID_STR_POSTFIX_DATE ) ), - String( SVX_RES( RID_STR_POSTFIX_TIME ) ) - }; - - for ( size_t i=0; i<2; ++i ) - { - sPurePostfix = aPostfix[i]; - sPurePostfix.EraseLeadingChars(' '); - sPurePostfix.EraseLeadingChars('('); - sPurePostfix.EraseTrailingChars(')'); - sRealName = sFieldName; - sRealName += '_'; - sRealName += sPurePostfix; - if (i) - xSecondCol->setPropertyValue(FM_PROP_NAME, makeAny(::rtl::OUString(sRealName))); - else - xCol->setPropertyValue(FM_PROP_NAME, makeAny(::rtl::OUString(sRealName))); - } - } - else - xCol->setPropertyValue(FM_PROP_NAME, makeAny(sFieldName)); - - // jetzt einfuegen - Any aElement; - aElement <<= xCol; - xCols->insertByIndex(nPos, aElement); - - if (bDateNTimeCol) - { - aElement <<= xSecondCol; - xCols->insertByIndex(nPos == (sal_uInt16)-1 ? nPos : ++nPos, aElement); - } - - // ist die component::Form an die Datenbankangebunden? - Reference< XFormComponent > xFormCp(xCols, UNO_QUERY); - Reference< XPropertySet > xForm(xFormCp->getParent(), UNO_QUERY); - if (xForm.is()) - { - if (!::comphelper::getString(xForm->getPropertyValue(FM_PROP_DATASOURCE)).getLength()) - { - if ( sDatasouce.getLength() ) - xForm->setPropertyValue(FM_PROP_DATASOURCE, makeAny(sDatasouce)); - else - xForm->setPropertyValue(FM_PROP_URL, makeAny(sURL)); - } - - if (!::comphelper::getString(xForm->getPropertyValue(FM_PROP_COMMAND)).getLength()) - { - xForm->setPropertyValue(FM_PROP_COMMAND, makeAny(sCommand)); - Any aCommandType; - switch (nCommandType) - { - case CommandType::TABLE: - aCommandType <<= (sal_Int32)CommandType::TABLE; - break; - case CommandType::QUERY: - aCommandType <<= (sal_Int32)CommandType::QUERY; - break; - default: - aCommandType <<= (sal_Int32)CommandType::COMMAND; - xForm->setPropertyValue(FM_PROP_ESCAPE_PROCESSING, bool2any((sal_Bool)(2 == nCommandType))); - break; - } - xForm->setPropertyValue(FM_PROP_COMMANDTYPE, aCommandType); - } - } - } - catch (Exception&) - { - OSL_FAIL("FmGridHeader::OnAsyncExecuteDrop: caught an exception while creatin' the column !"); - ::comphelper::disposeComponent(m_pImpl->xDroppedResultSet); - ::comphelper::disposeComponent(m_pImpl->xDroppedStatement); - return 0L; - } - - ::comphelper::disposeComponent(m_pImpl->xDroppedResultSet); - ::comphelper::disposeComponent(m_pImpl->xDroppedStatement); - return 1L; -} - -//------------------------------------------------------------------------------ -void FmGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMenu) -{ - sal_Bool bDesignMode = static_cast<FmGridControl*>(GetParent())->IsDesignMode(); - - Reference< ::com::sun::star::container::XIndexContainer > xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns()); - // Aufbau des Insert Menues - // mark the column if nColId != HEADERBAR_ITEM_NOTFOUND - if(nColId > 0) - { - sal_uInt16 nPos2 = GetModelColumnPos(nColId); - - Reference< ::com::sun::star::container::XIndexContainer > xColumns(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns()); - Reference< ::com::sun::star::beans::XPropertySet> xColumn; - ::cppu::extractInterface(xColumn, xColumns->getByIndex(nPos2)); - Reference< ::com::sun::star::view::XSelectionSupplier > xSelSupplier(xColumns, UNO_QUERY); - if (xSelSupplier.is()) - xSelSupplier->select(makeAny(xColumn)); - } - - // EinfuegePosition, immer vor der aktuellen Spalte - sal_uInt16 nPos = GetModelColumnPos(nColId); - sal_Bool bMarked = nColId && static_cast<FmGridControl*>(GetParent())->isColumnMarked(nColId); - - ImageList aImageList( SVX_RES(RID_SVXIMGLIST_FMEXPL) ); - PopupMenu* pControlMenu = new PopupMenu; - - PopupMenu* pMenu = rMenu.GetPopupMenu(SID_FM_INSERTCOL); - if (pMenu) - { - SetMenuItem(aImageList, SID_FM_EDIT, pMenu, *pControlMenu, bDesignMode); - SetMenuItem(aImageList, SID_FM_CHECKBOX, pMenu, *pControlMenu, bDesignMode); - SetMenuItem(aImageList, SID_FM_COMBOBOX, pMenu, *pControlMenu, bDesignMode); - SetMenuItem(aImageList, SID_FM_LISTBOX, pMenu, *pControlMenu, bDesignMode); - SetMenuItem(aImageList, SID_FM_DATEFIELD, pMenu, *pControlMenu, bDesignMode); - SetMenuItem(aImageList, SID_FM_TIMEFIELD, pMenu, *pControlMenu, bDesignMode); - SetMenuItem(aImageList, SID_FM_NUMERICFIELD, pMenu, *pControlMenu, bDesignMode); - SetMenuItem(aImageList, SID_FM_CURRENCYFIELD, pMenu, *pControlMenu, bDesignMode); - SetMenuItem(aImageList, SID_FM_PATTERNFIELD, pMenu, *pControlMenu, bDesignMode); - SetMenuItem(aImageList, SID_FM_FORMATTEDFIELD, pMenu, *pControlMenu, bDesignMode); - } - - if (pMenu && xCols.is() && nColId) - { - Reference< ::com::sun::star::beans::XPropertySet > xSet; - ::cppu::extractInterface(xSet, xCols->getByIndex(nPos)); - sal_Int16 nClassId; - xSet->getPropertyValue(FM_PROP_CLASSID) >>= nClassId; - - Reference< ::com::sun::star::io::XPersistObject > xServiceQuestion(xSet, UNO_QUERY); - sal_Int32 nColType = xServiceQuestion.is() ? getColumnTypeByModelName(xServiceQuestion->getServiceName()) : 0; - if (nColType == TYPE_TEXTFIELD) - { // edit fields and formatted fields have the same service name, thus getColumnTypeByModelName returns TYPE_TEXTFIELD - // in both cases. And as columns don't have an ::com::sun::star::lang::XServiceInfo interface, we have to distinguish both - // types via the existence of special properties - Reference< ::com::sun::star::beans::XPropertySet > xProps(xSet, UNO_QUERY); - if (xProps.is()) - { - Reference< ::com::sun::star::beans::XPropertySetInfo > xPropsInfo = xProps->getPropertySetInfo(); - if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(FM_PROP_FORMATSSUPPLIER)) - nColType = TYPE_FORMATTEDFIELD; - } - } - - pControlMenu->EnableItem(SID_FM_EDIT + nChangeTypeOffset, bDesignMode && (nColType != TYPE_TEXTFIELD)); - pControlMenu->EnableItem(SID_FM_COMBOBOX + nChangeTypeOffset, bDesignMode && (nColType != TYPE_COMBOBOX)); - pControlMenu->EnableItem(SID_FM_LISTBOX + nChangeTypeOffset, bDesignMode && (nColType != TYPE_LISTBOX)); - pControlMenu->EnableItem(SID_FM_CHECKBOX + nChangeTypeOffset, bDesignMode && (nColType != TYPE_CHECKBOX)); - pControlMenu->EnableItem(SID_FM_DATEFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_DATEFIELD)); - pControlMenu->EnableItem(SID_FM_NUMERICFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_NUMERICFIELD)); - pControlMenu->EnableItem(SID_FM_TIMEFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_TIMEFIELD)); - pControlMenu->EnableItem(SID_FM_CURRENCYFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_CURRENCYFIELD)); - pControlMenu->EnableItem(SID_FM_PATTERNFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_PATTERNFIELD)); - pControlMenu->EnableItem(SID_FM_FORMATTEDFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_FORMATTEDFIELD)); - rMenu.SetPopupMenu(SID_FM_CHANGECOL, pControlMenu); - } - - rMenu.EnableItem(SID_FM_INSERTCOL, bDesignMode && xCols.is()); - rMenu.EnableItem(SID_FM_DELETECOL, bDesignMode && bMarked && xCols.is()); - rMenu.EnableItem(SID_FM_CHANGECOL, bDesignMode && bMarked && xCols.is()); - rMenu.EnableItem(SID_FM_SHOW_PROPERTY_BROWSER, bDesignMode && bMarked && xCols.is()); - - PopupMenu* pShowColsMenu = rMenu.GetPopupMenu(SID_FM_SHOWCOLS); - sal_uInt16 nHiddenCols = 0; - if (pShowColsMenu) - { - if (xCols.is()) - { - // check for hidden cols - Reference< ::com::sun::star::beans::XPropertySet > xCurCol; - Any aHidden,aName; - for (sal_uInt16 i=0; i<xCols->getCount(); ++i) - { - ::cppu::extractInterface(xCurCol, xCols->getByIndex(i)); - DBG_ASSERT(xCurCol.is(), "FmGridHeader::PreExecuteColumnContextMenu : the Peer has invalid columns !"); - aHidden = xCurCol->getPropertyValue(FM_PROP_HIDDEN); - DBG_ASSERT(aHidden.getValueType().getTypeClass() == TypeClass_BOOLEAN, - "FmGridHeader::PreExecuteColumnContextMenu : the property 'hidden' should be boolean !"); - if (::comphelper::getBOOL(aHidden)) - { - // put the column name into the 'show col' menu - if (nHiddenCols < 16) - { // (only the first 16 items to keep the menu rather small) - aName = xCurCol->getPropertyValue(FM_PROP_LABEL); - pShowColsMenu->InsertItem(nHiddenCols + 1, ::comphelper::getString(aName), 0, nHiddenCols); - // the ID is arbitrary, but should be unique within the whole menu - } - ++nHiddenCols; - } - } - } - pShowColsMenu->EnableItem(SID_FM_SHOWCOLS_MORE, xCols.is() && (nHiddenCols > 16)); - pShowColsMenu->EnableItem(SID_FM_SHOWALLCOLS, xCols.is() && (nHiddenCols > 0)); - } - - // allow the 'hide column' item ? - sal_Bool bAllowHide = bMarked; // a column is marked - bAllowHide = bAllowHide || (!bDesignMode && (nPos != (sal_uInt16)-1)); // OR we are in alive mode and have hit a column - bAllowHide = bAllowHide && xCols.is(); // AND we have a column container - bAllowHide = bAllowHide && (xCols->getCount()-nHiddenCols > 1); // AND there are at least two visible columns - rMenu.EnableItem(SID_FM_HIDECOL, bAllowHide); - - sal_Bool bChecked = sal_False; - if (bMarked) - { - - SfxViewFrame* pCurrentFrame = SfxViewFrame::Current(); - SfxItemState eState = SFX_ITEM_UNKNOWN; - // ask the bindings of the current view frame (which should be the one we're residing in) for the state - if (pCurrentFrame) - { - SfxPoolItem* pItem = NULL; - eState = pCurrentFrame->GetBindings().QueryState(SID_FM_CTL_PROPERTIES, pItem); - - if (eState >= SFX_ITEM_AVAILABLE && pItem ) - { - bChecked = pItem->ISA(SfxBoolItem) && ((SfxBoolItem*)pItem)->GetValue(); - rMenu.CheckItem(SID_FM_SHOW_PROPERTY_BROWSER,bChecked); - } - delete pItem; - } - } -} - -enum InspectorAction { eOpenInspector, eCloseInspector, eUpdateInspector, eNone }; - -//------------------------------------------------------------------------------ -void FmGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMenu& rMenu, sal_uInt16 nExecutionResult) -{ - Reference< ::com::sun::star::container::XIndexContainer > xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns()); - sal_uInt16 nPos = GetModelColumnPos(nColId); - - // remove and delet the menu we inserted in PreExecuteColumnContextMenu - PopupMenu* pControlMenu = rMenu.GetPopupMenu(SID_FM_CHANGECOL); - delete pControlMenu; - - ::rtl::OUString aFieldType; - sal_Bool bReplace = sal_False; - InspectorAction eInspectorAction = eNone; - Reference< XPropertySet > xColumnToInspect; - switch (nExecutionResult) - { - case SID_FM_DELETECOL: - { - Reference< XInterface > xCol; - ::cppu::extractInterface(xCol, xCols->getByIndex(nPos)); - xCols->removeByIndex(nPos); - ::comphelper::disposeComponent(xCol); - } break; - case SID_FM_SHOW_PROPERTY_BROWSER: - eInspectorAction = rMenu.IsItemChecked( SID_FM_SHOW_PROPERTY_BROWSER ) ? eOpenInspector : eCloseInspector; - xColumnToInspect.set( xCols->getByIndex( nPos ), UNO_QUERY ); - break; - case SID_FM_EDIT + nChangeTypeOffset: - bReplace = sal_True; - case SID_FM_EDIT: - aFieldType = FM_COL_TEXTFIELD; - break; - case SID_FM_COMBOBOX + nChangeTypeOffset: - bReplace = sal_True; - case SID_FM_COMBOBOX: - aFieldType = FM_COL_COMBOBOX; - break; - case SID_FM_LISTBOX + nChangeTypeOffset: - bReplace = sal_True; - case SID_FM_LISTBOX: - aFieldType = FM_COL_LISTBOX; - break; - case SID_FM_CHECKBOX + nChangeTypeOffset: - bReplace = sal_True; - case SID_FM_CHECKBOX: - aFieldType = FM_COL_CHECKBOX; - break; - case SID_FM_DATEFIELD + nChangeTypeOffset: - bReplace = sal_True; - case SID_FM_DATEFIELD: - aFieldType = FM_COL_DATEFIELD; - break; - case SID_FM_TIMEFIELD + nChangeTypeOffset: - bReplace = sal_True; - case SID_FM_TIMEFIELD: - aFieldType = FM_COL_TIMEFIELD; - break; - case SID_FM_NUMERICFIELD + nChangeTypeOffset: - bReplace = sal_True; - case SID_FM_NUMERICFIELD: - aFieldType = FM_COL_NUMERICFIELD; - break; - case SID_FM_CURRENCYFIELD + nChangeTypeOffset: - bReplace = sal_True; - case SID_FM_CURRENCYFIELD: - aFieldType = FM_COL_CURRENCYFIELD; - break; - case SID_FM_PATTERNFIELD + nChangeTypeOffset: - bReplace = sal_True; - case SID_FM_PATTERNFIELD: - aFieldType = FM_COL_PATTERNFIELD; - break; - case SID_FM_FORMATTEDFIELD + nChangeTypeOffset: - bReplace = sal_True; - case SID_FM_FORMATTEDFIELD: - aFieldType = FM_COL_FORMATTEDFIELD; - break; - case SID_FM_HIDECOL: - { - Reference< ::com::sun::star::beans::XPropertySet > xCurCol; - ::cppu::extractInterface(xCurCol, xCols->getByIndex(nPos)); - xCurCol->setPropertyValue(FM_PROP_HIDDEN, makeAny((sal_Bool)sal_True)); - } - break; - case SID_FM_SHOWCOLS_MORE: - { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - if(pFact) - { - AbstractFmShowColsDialog* pDlg = pFact->CreateFmShowColsDialog(NULL); - DBG_ASSERT(pDlg, "Dialogdiet fail!"); - pDlg->SetColumns(xCols); - pDlg->Execute(); - delete pDlg; - } - - } - break; - case SID_FM_SHOWALLCOLS: - { - // just iterate through all the cols ... - Reference< ::com::sun::star::beans::XPropertySet > xCurCol; - for (sal_uInt16 i=0; i<xCols->getCount(); ++i) - { - ::cppu::extractInterface(xCurCol, xCols->getByIndex(i)); - xCurCol->setPropertyValue(FM_PROP_HIDDEN, makeAny((sal_Bool)sal_False)); - } - // TODO : there must be a more clever way to do this .... - // with the above the view is updated after every single model update ... - } - break; - default: - if (nExecutionResult>0 && nExecutionResult<=16) - { // it was a "show column/<colname>" command (there are at most 16 such items) - // search the nExecutionResult'th hidden col - Reference< ::com::sun::star::beans::XPropertySet > xCurCol; - for (sal_uInt16 i=0; i<xCols->getCount() && nExecutionResult; ++i) - { - ::cppu::extractInterface(xCurCol, xCols->getByIndex(i)); - Any aHidden = xCurCol->getPropertyValue(FM_PROP_HIDDEN); - if (::comphelper::getBOOL(aHidden)) - if (!--nExecutionResult) - { - xCurCol->setPropertyValue(FM_PROP_HIDDEN, makeAny((sal_Bool)sal_False)); - break; - } - } - } - break; - } - - if ( aFieldType.getLength() ) - { - try - { - Reference< XGridColumnFactory > xFactory( xCols, UNO_QUERY_THROW ); - Reference< XPropertySet > xNewCol( xFactory->createColumn( aFieldType ), UNO_SET_THROW ); - - if ( bReplace ) - { - // ein paar Properties hinueberretten - Reference< XPropertySet > xReplaced( xCols->getByIndex( nPos ), UNO_QUERY ); - - OStaticDataAccessTools().TransferFormComponentProperties( - xReplaced, xNewCol, Application::GetSettings().GetUILocale() ); - - xCols->replaceByIndex( nPos, makeAny( xNewCol ) ); - ::comphelper::disposeComponent( xReplaced ); - - eInspectorAction = eUpdateInspector; - xColumnToInspect = xNewCol; - } - else - { - FormControlFactory factory( ::comphelper::getProcessServiceFactory() ); - - ::rtl::OUString sLabel = factory.getDefaultUniqueName_ByComponentType( - Reference< XNameAccess >( xCols, UNO_QUERY_THROW ), xNewCol ); - xNewCol->setPropertyValue( FM_PROP_LABEL, makeAny( sLabel ) ); - xNewCol->setPropertyValue( FM_PROP_NAME, makeAny( sLabel ) ); - - factory.initializeControlModel( DocumentClassification::classifyHostDocument( xCols ), xNewCol ); - - xCols->insertByIndex( nPos, makeAny( xNewCol ) ); - } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - - SfxViewFrame* pCurrentFrame = SfxViewFrame::Current(); - OSL_ENSURE( pCurrentFrame, "FmGridHeader::PostExecuteColumnContextMenu: no view frame -> no bindings -> no property browser!" ); - if ( pCurrentFrame ) - { - if ( eInspectorAction == eUpdateInspector ) - { - if ( !pCurrentFrame->HasChildWindow( SID_FM_SHOW_PROPERTIES ) ) - eInspectorAction = eNone; - } - - if ( eInspectorAction != eNone ) - { - FmInterfaceItem aIFaceItem( SID_FM_SHOW_PROPERTY_BROWSER, xColumnToInspect ); - SfxBoolItem aShowItem( SID_FM_SHOW_PROPERTIES, eInspectorAction == eCloseInspector ? sal_False : sal_True ); - - pCurrentFrame->GetBindings().GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SFX_CALLMODE_ASYNCHRON, - &aIFaceItem, &aShowItem, 0L ); - } - } -} - -//------------------------------------------------------------------------------ -void FmGridHeader::triggerColumnContextMenu( const ::Point& _rPreferredPos ) -{ - // the affected col - sal_uInt16 nColId = GetItemId( _rPreferredPos ); - - // the menu - PopupMenu aContextMenu( SVX_RES( RID_SVXMNU_COLS ) ); - - // let derivees modify the menu - PreExecuteColumnContextMenu( nColId, aContextMenu ); - aContextMenu.RemoveDisabledEntries( sal_True, sal_True ); - - // execute the menu - sal_uInt16 nResult = aContextMenu.Execute( this, _rPreferredPos ); - - // let derivees handle the result - PostExecuteColumnContextMenu( nColId, aContextMenu, nResult ); -} - -//------------------------------------------------------------------------------ -void FmGridHeader::Command(const CommandEvent& rEvt) -{ - switch (rEvt.GetCommand()) - { - case COMMAND_CONTEXTMENU: - { - if (!rEvt.IsMouseEvent()) - return; - - triggerColumnContextMenu( rEvt.GetMousePosPixel() ); - } - break; - default: - EditBrowserHeader::Command(rEvt); - } -} - -//------------------------------------------------------------------------------ -FmGridControl::FmGridControl( - Reference< ::com::sun::star::lang::XMultiServiceFactory > _rxFactory, - Window* pParent, - FmXGridPeer* _pPeer, - WinBits nBits) - :DbGridControl(_rxFactory, pParent, nBits) - ,m_pPeer(_pPeer) - ,m_nCurrentSelectedColumn(-1) - ,m_nMarkedColumnId(BROWSER_INVALIDID) - ,m_bSelecting(sal_False) - ,m_bInColumnMove(sal_False) -{ - EnableInteractiveRowHeight( ); -} - -//------------------------------------------------------------------------------ -void FmGridControl::Command(const CommandEvent& _rEvt) -{ - if ( COMMAND_CONTEXTMENU == _rEvt.GetCommand() ) - { - FmGridHeader* pMyHeader = static_cast< FmGridHeader* >( GetHeaderBar() ); - if ( pMyHeader && !_rEvt.IsMouseEvent() ) - { // context menu requested by keyboard - if ( 1 == GetSelectColumnCount() || IsDesignMode() ) - { - sal_uInt16 nSelId = GetColumnId( - sal::static_int_cast< sal_uInt16 >( FirstSelectedColumn() ) ); - ::Rectangle aColRect( GetFieldRectPixel( 0, nSelId, sal_False ) ); - - Point aRelativePos( pMyHeader->ScreenToOutputPixel( OutputToScreenPixel( aColRect.TopCenter() ) ) ); - pMyHeader->triggerColumnContextMenu( aRelativePos, FmGridHeader::AccessControl() ); - - // handled - return; - } - } - } - - DbGridControl::Command( _rEvt ); -} - -// ::com::sun::star::beans::XPropertyChangeListener -//------------------------------------------------------------------------------ -void FmGridControl::propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt) -{ - if (evt.PropertyName == FM_PROP_ROWCOUNT) - { - // if we're not in the main thread call AdjustRows asynchronously - implAdjustInSolarThread(sal_True); - return; - } - - const DbGridRowRef& xRow = GetCurrentRow(); - // waehrend Positionierung wird kein abgleich der Properties vorgenommen - Reference<XPropertySet> xSet(evt.Source,UNO_QUERY); - if (xRow.Is() && (::cppu::any2bool(xSet->getPropertyValue(FM_PROP_ISNEW))|| CompareBookmark(getDataSource()->getBookmark(), xRow->GetBookmark()))) - { - if (evt.PropertyName == FM_PROP_ISMODIFIED) - { - // modified or clean ? - GridRowStatus eStatus = ::comphelper::getBOOL(evt.NewValue) ? GRS_MODIFIED : GRS_CLEAN; - if (eStatus != xRow->GetStatus()) - { - xRow->SetStatus(eStatus); - SolarMutexGuard aGuard; - RowModified(GetCurrentPos()); - } - } - } -} - -//------------------------------------------------------------------------------ -void FmGridControl::SetDesignMode(sal_Bool bMode) -{ - sal_Bool bOldMode = IsDesignMode(); - DbGridControl::SetDesignMode(bMode); - if (bOldMode != bMode) - { - if (!bMode) - { - // selection aufheben - markColumn(USHRT_MAX); - } - else - { - Reference< ::com::sun::star::container::XIndexContainer > xColumns(GetPeer()->getColumns()); - Reference< ::com::sun::star::view::XSelectionSupplier > xSelSupplier(xColumns, UNO_QUERY); - if (xSelSupplier.is()) - { - Any aSelection = xSelSupplier->getSelection(); - Reference< ::com::sun::star::beans::XPropertySet > xColumn; - if (aSelection.getValueType().getTypeClass() == TypeClass_INTERFACE) - ::cppu::extractInterface(xColumn, aSelection); - Reference< XInterface > xCurrent; - for (sal_uInt16 i=0; i<xColumns->getCount(); ++i) - { - ::cppu::extractInterface(xCurrent, xColumns->getByIndex(i)); - if (xCurrent == xColumn) - { - markColumn(GetColumnIdFromModelPos(i)); - break; - } - } - } - } - } -} - -//------------------------------------------------------------------------------ -void FmGridControl::DeleteSelectedRows() -{ - if (!m_pSeekCursor) - return; - - // how many rows are selected? - sal_Int32 nSelectedRows = GetSelectRowCount(); - - // the current line should be deleted but it is currently in edit mode - if ( IsCurrentAppending() ) - return; - // is the insert row selected - if (GetEmptyRow().Is() && IsRowSelected(GetRowCount() - 1)) - nSelectedRows -= 1; - - // nothing to do - if (nSelectedRows <= 0) - return; - - // try to confirm the delete - Reference< ::com::sun::star::frame::XDispatchProvider > xDispatcher = (::com::sun::star::frame::XDispatchProvider*)GetPeer(); - if (xDispatcher.is()) - { - ::com::sun::star::util::URL aUrl; - aUrl.Complete = FMURL_CONFIRM_DELETION; - // #100312# ------------ - Reference< ::com::sun::star::util::XURLTransformer > xTransformer( - ::comphelper::getProcessServiceFactory()->createInstance( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer"))), UNO_QUERY); - if( xTransformer.is() ) - xTransformer->parseStrict( aUrl ); - - Reference< ::com::sun::star::frame::XDispatch > xDispatch = xDispatcher->queryDispatch(aUrl, rtl::OUString(), 0); - Reference< ::com::sun::star::form::XConfirmDeleteListener > xConfirm(xDispatch, UNO_QUERY); - if (xConfirm.is()) - { - ::com::sun::star::sdb::RowChangeEvent aEvent; - aEvent.Source = (Reference< XInterface > )(*getDataSource()); - aEvent.Rows = nSelectedRows; - aEvent.Action = ::com::sun::star::sdb::RowChangeAction::DELETE; - if (!xConfirm->confirmDelete(aEvent)) - return; - } - } - - const MultiSelection* pRowSelection = GetSelection(); - if ( pRowSelection && pRowSelection->IsAllSelected() ) - { - BeginCursorAction(); - CursorWrapper* pCursor = getDataSource(); - Reference< XResultSetUpdate > xUpdateCursor((Reference< XInterface >)*pCursor, UNO_QUERY); - try - { - pCursor->beforeFirst(); - while( pCursor->next() ) - xUpdateCursor->deleteRow(); - - SetUpdateMode(sal_False); - SetNoSelection(); - - xUpdateCursor->moveToInsertRow(); - } - catch(const Exception&) - { - OSL_FAIL("Exception caught while deleting rows!"); - } - // An den DatenCursor anpassen - AdjustDataSource(sal_True); - EndCursorAction(); - SetUpdateMode(sal_True); - } - else - { - Reference< ::com::sun::star::sdbcx::XDeleteRows > xDeleteThem((Reference< XInterface >)*getDataSource(), UNO_QUERY); - - // colect the bookmarks of the selected rows - Sequence < Any> aBookmarks = getSelectionBookmarks(); - - // determine the next row to position after deletion - Any aBookmark; - sal_Bool bNewPos = sal_False; - // if the current row isn't selected we take the row as row after deletion - OSL_ENSURE( GetCurrentRow().Is(), "FmGridControl::DeleteSelectedRows: no current row here?" ); - // crash reports suggest it can happen we don't have a current row - how? - // #154303# / 2008-04-23 / frank.schoenheit@sun.com - if ( !IsRowSelected( GetCurrentPos() ) && !IsCurrentAppending() && GetCurrentRow().Is() ) - { - aBookmark = GetCurrentRow()->GetBookmark(); - bNewPos = sal_True; - } - else - { - // we look for the first row after the selected block for selection - long nIdx = LastSelectedRow() + 1; - if (nIdx < GetRowCount() - 1) - { - // there is a next row to position on - if (SeekCursor(nIdx)) - { - GetSeekRow()->SetState(m_pSeekCursor, sal_True); - - bNewPos = sal_True; - // if it's not the row for inserting we keep the bookmark - if (!IsInsertionRow(nIdx)) - aBookmark = m_pSeekCursor->getBookmark(); - } - } - else - { - // we look for the first row before the selected block for selection after deletion - nIdx = FirstSelectedRow() - 1; - if (nIdx >= 0 && SeekCursor(nIdx)) - { - GetSeekRow()->SetState(m_pSeekCursor, sal_True); - - bNewPos = sal_True; - aBookmark = m_pSeekCursor->getBookmark(); - } - } - } - - // Sind alle Zeilen Selectiert - // Zweite bedingung falls keine einguegeZeile existiert - sal_Bool bAllSelected = GetTotalCount() == nSelectedRows || GetRowCount() == nSelectedRows; - - BeginCursorAction(); - - // now delete the row - Sequence <sal_Int32> aDeletedRows; - SetUpdateMode( sal_False ); - try - { - aDeletedRows = xDeleteThem->deleteRows(aBookmarks); - } - catch(SQLException&) - { - } - SetUpdateMode( sal_True ); - - // how many rows are deleted? - sal_Int32 nDeletedRows = 0; - const sal_Int32* pSuccess = aDeletedRows.getConstArray(); - for (sal_Int32 i = 0; i < aDeletedRows.getLength(); i++) - { - if (pSuccess[i]) - ++nDeletedRows; - } - - // sind Zeilen geloescht worden? - if (nDeletedRows) - { - SetUpdateMode(sal_False); - SetNoSelection(); - try - { - // did we delete all the rows than try to move to the next possible row - if (nDeletedRows == aDeletedRows.getLength()) - { - // there exists a new position to move on - if (bNewPos) - { - if (aBookmark.hasValue()) - getDataSource()->moveToBookmark(aBookmark); - // no valid bookmark so move to the insert row - else - { - Reference< XResultSetUpdate > xUpdateCursor((Reference< XInterface >)*m_pDataCursor, UNO_QUERY); - xUpdateCursor->moveToInsertRow(); - } - } - else - { - Reference< ::com::sun::star::beans::XPropertySet > xSet((Reference< XInterface >)*m_pDataCursor, UNO_QUERY); - - sal_Int32 nRecordCount(0); - xSet->getPropertyValue(FM_PROP_ROWCOUNT) >>= nRecordCount; - if ( m_pDataCursor->rowDeleted() ) - --nRecordCount; - - // there are no rows left and we have an insert row - if (!nRecordCount && GetEmptyRow().Is()) - { - Reference< XResultSetUpdate > xUpdateCursor((Reference< XInterface >)*m_pDataCursor, UNO_QUERY); - xUpdateCursor->moveToInsertRow(); - } - else if (nRecordCount) - // move to the first row - getDataSource()->first(); - } - } - // not all the rows where deleted, so move to the first row which remained in the resultset - else - { - for (sal_Int32 i = 0; i < aDeletedRows.getLength(); i++) - { - if (!pSuccess[i]) - { - getDataSource()->moveToBookmark(aBookmarks.getConstArray()[i]); - break; - } - } - } - } - catch(const Exception&) - { - try - { - // positioning went wrong so try to move to the first row - getDataSource()->first(); - } - catch(const Exception&) - { - } - } - - // An den DatenCursor anpassen - AdjustDataSource(sal_True); - - // es konnten nicht alle Zeilen geloescht werden - // da nie nicht geloeschten wieder selektieren - if (nDeletedRows < nSelectedRows) - { - // waren alle selektiert - if (bAllSelected) - { - SelectAll(); - if (IsInsertionRow(GetRowCount() - 1)) // einfuegeZeile nicht - SelectRow(GetRowCount() - 1, sal_False); - } - else - { - // select the remaining rows - for (sal_Int32 i = 0; i < aDeletedRows.getLength(); i++) - { - try - { - if (!pSuccess[i]) - { - m_pSeekCursor->moveToBookmark(m_pDataCursor->getBookmark()); - SetSeekPos(m_pSeekCursor->getRow() - 1); - SelectRow(GetSeekPos()); - } - } - catch(const Exception&) - { - // keep the seekpos in all cases - SetSeekPos(m_pSeekCursor->getRow() - 1); - } - } - } - } - - EndCursorAction(); - SetUpdateMode(sal_True); - } - else // Zeile konnte nicht geloescht werden - { - EndCursorAction(); - try - { - // currentrow is the insert row? - if (!IsCurrentAppending()) - getDataSource()->refreshRow(); - } - catch(const Exception&) - { - } - } - } - - // if there is no selection anymore we can start editing - if (!GetSelectRowCount()) - ActivateCell(); -} - - -// XCurrentRecordListener -//------------------------------------------------------------------------------ -void FmGridControl::positioned(const ::com::sun::star::lang::EventObject& /*rEvent*/) -{ - TRACE_RANGE("FmGridControl::positioned"); - // position on the data source (force it to be done in the main thread) - implAdjustInSolarThread(sal_False); -} - -//------------------------------------------------------------------------------ -sal_Bool FmGridControl::commit() -{ - // Commit nur ausfuehren, wenn nicht bereits ein Update vom ::com::sun::star::form::component::GridControl ausgefuehrt - // wird - if (!IsUpdating()) - { - if (Controller().Is() && Controller()->IsModified()) - { - if (!SaveModified()) - return sal_False; - } - } - return sal_True; -} - -//------------------------------------------------------------------------------ -void FmGridControl::inserted(const ::com::sun::star::lang::EventObject& /*rEvent*/) -{ - const DbGridRowRef& xRow = GetCurrentRow(); - if (!xRow.Is()) - return; - - // Zeile ist eingefuegt worden, dann den status und mode zuruecksetzen - xRow->SetState(m_pDataCursor, sal_False); - xRow->SetNew(sal_False); - -} - -// XCancelUpdateRecordListener -//------------------------------------------------------------------------------ -void FmGridControl::restored(const ::com::sun::star::lang::EventObject& rEvent) -{ - if (!GetCurrentRow().Is()) - return; - - sal_Bool bAppending = GetCurrentRow()->IsNew(); - sal_Bool bDirty = GetCurrentRow()->IsModified(); - if (bAppending && (EditBrowseBox::IsModified() || bDirty)) - { - if (Controller().Is()) - Controller()->ClearModified(); - - // jetzt die Zeile herausnehmen - RowRemoved(GetRowCount() - 1, 1, sal_True); - GetNavigationBar().InvalidateAll(); - } - - positioned(rEvent); -} - -//------------------------------------------------------------------------------ -BrowserHeader* FmGridControl::imp_CreateHeaderBar(BrowseBox* pParent) -{ - DBG_ASSERT( pParent == this, "FmGridControl::imp_CreateHeaderBar: parent?" ); - return new FmGridHeader( pParent ); -} - -//------------------------------------------------------------------------------ -void FmGridControl::markColumn(sal_uInt16 nId) -{ - if (GetHeaderBar() && m_nMarkedColumnId != nId) - { - // deselektieren - if (m_nMarkedColumnId != BROWSER_INVALIDID) - { - HeaderBarItemBits aBits = GetHeaderBar()->GetItemBits(m_nMarkedColumnId) & ~HIB_FLAT; - GetHeaderBar()->SetItemBits(m_nMarkedColumnId, aBits); - } - - - if (nId != BROWSER_INVALIDID) - { - HeaderBarItemBits aBits = GetHeaderBar()->GetItemBits(nId) | HIB_FLAT; - GetHeaderBar()->SetItemBits(nId, aBits); - } - m_nMarkedColumnId = nId; - } -} - -//------------------------------------------------------------------------------ -sal_Bool FmGridControl::isColumnMarked(sal_uInt16 nId) const -{ - return m_nMarkedColumnId == nId; -} - -//------------------------------------------------------------------------------ -long FmGridControl::QueryMinimumRowHeight() -{ - long nMinimalLogicHeight = 20; // 0.2 cm - long nMinimalPixelHeight = LogicToPixel( Point( 0, nMinimalLogicHeight ), MAP_10TH_MM ).Y(); - return CalcZoom( nMinimalPixelHeight ); -} - -//------------------------------------------------------------------------------ -void FmGridControl::RowHeightChanged() -{ - DbGridControl::RowHeightChanged(); - - Reference< XPropertySet > xModel( GetPeer()->getColumns(), UNO_QUERY ); - DBG_ASSERT( xModel.is(), "FmGridControl::RowHeightChanged: no model!" ); - if ( xModel.is() ) - { - try - { - sal_Int32 nUnzoomedPixelHeight = CalcReverseZoom( GetDataRowHeight() ); - Any aProperty = makeAny( (sal_Int32)PixelToLogic( Point( 0, nUnzoomedPixelHeight ), MAP_10TH_MM ).Y() ); - xModel->setPropertyValue( FM_PROP_ROWHEIGHT, aProperty ); - } - catch( const Exception& ) - { - OSL_FAIL( "FmGridControl::RowHeightChanged: caught an exception!" ); - } - } -} - -//------------------------------------------------------------------------------ -void FmGridControl::ColumnResized(sal_uInt16 nId) -{ - DbGridControl::ColumnResized(nId); - - // Wert ans model uebergeben - DbGridColumn* pCol = DbGridControl::GetColumns().at( GetModelColumnPos(nId) ); - Reference< ::com::sun::star::beans::XPropertySet > xColModel(pCol->getModel()); - if (xColModel.is()) - { - Any aWidth; - sal_Int32 nColumnWidth = GetColumnWidth(nId); - nColumnWidth = CalcReverseZoom(nColumnWidth); - // Umrechnen in 10THMM - aWidth <<= (sal_Int32)PixelToLogic(Point(nColumnWidth,0),MAP_10TH_MM).X(); - xColModel->setPropertyValue(FM_PROP_WIDTH, aWidth); - } -} - -//------------------------------------------------------------------------------ -void FmGridControl::CellModified() -{ - DbGridControl::CellModified(); - GetPeer()->CellModified(); -} - -//------------------------------------------------------------------------------ -void FmGridControl::BeginCursorAction() -{ - DbGridControl::BeginCursorAction(); - m_pPeer->stopCursorListening(); -} - -//------------------------------------------------------------------------------ -void FmGridControl::EndCursorAction() -{ - m_pPeer->startCursorListening(); - DbGridControl::EndCursorAction(); -} - -//------------------------------------------------------------------------------ -void FmGridControl::ColumnMoved(sal_uInt16 nId) -{ - m_bInColumnMove = sal_True; - - DbGridControl::ColumnMoved(nId); - Reference< ::com::sun::star::container::XIndexContainer > xColumns(GetPeer()->getColumns()); - - if (xColumns.is()) - { - // suchen der Spalte und verschieben im Model - // ColumnPos holen - DbGridColumn* pCol = DbGridControl::GetColumns().at( GetModelColumnPos(nId) ); - Reference< ::com::sun::star::beans::XPropertySet > xCol; - - // Einfuegen muß sich an den Column Positionen orientieren - sal_Int32 i; - Reference< XInterface > xCurrent; - for (i = 0; !xCol.is() && i < xColumns->getCount(); i++) - { - ::cppu::extractInterface(xCurrent, xColumns->getByIndex(i)); - if (xCurrent == pCol->getModel()) - { - xCol = pCol->getModel(); - break; - } - } - - DBG_ASSERT(i < xColumns->getCount(), "Falscher ::com::sun::star::sdbcx::Index"); - xColumns->removeByIndex(i); - Any aElement; - aElement <<= xCol; - xColumns->insertByIndex(GetModelColumnPos(nId), aElement); - pCol->setModel(xCol); - // if the column which is shown here is selected ... - if ( isColumnSelected(nId,pCol) ) - markColumn(nId); // ... -> mark it - } - - m_bInColumnMove = sal_False; -} - -//------------------------------------------------------------------------------ -void FmGridControl::InitColumnsByModels(const Reference< ::com::sun::star::container::XIndexContainer >& xColumns) -{ - // Spalten wieder neu setzen - // wenn es nur eine HandleColumn gibt, dann nicht - if (GetModelColCount()) - { - RemoveColumns(); - InsertHandleColumn(); - } - - if (!xColumns.is()) - return; - - SetUpdateMode(sal_False); - - // Einfuegen mu� sich an den Column Positionen orientieren - sal_Int32 i; - String aName; - Any aWidth; - for (i = 0; i < xColumns->getCount(); ++i) - { - Reference< ::com::sun::star::beans::XPropertySet > xCol; - ::cppu::extractInterface(xCol, xColumns->getByIndex(i)); - - aName = (const sal_Unicode*)::comphelper::getString(xCol->getPropertyValue(FM_PROP_LABEL)); - - aWidth = xCol->getPropertyValue(FM_PROP_WIDTH); - sal_Int32 nWidth = 0; - if (aWidth >>= nWidth) - nWidth = LogicToPixel(Point(nWidth,0),MAP_10TH_MM).X(); - - AppendColumn(aName, (sal_uInt16)nWidth); - DbGridColumn* pCol = DbGridControl::GetColumns().at( i ); - pCol->setModel(xCol); - } - - // und jetzt noch die hidden columns rausnehmen - // (wir haben das nicht gleich in der oberen Schleife gemacht, da wir dann Probleme mit den - // IDs der Spalten bekommen haetten : AppendColumn vergibt die automatisch, die Spalte _nach_ - // einer versteckten braucht aber eine um eine erhoehte ID .... - Any aHidden; - for (i = 0; i < xColumns->getCount(); ++i) - { - Reference< ::com::sun::star::beans::XPropertySet > xCol; - ::cppu::extractInterface(xCol, xColumns->getByIndex(i)); - aHidden = xCol->getPropertyValue(FM_PROP_HIDDEN); - if (::comphelper::getBOOL(aHidden)) - HideColumn(GetColumnIdFromModelPos((sal_uInt16)i)); - } - - SetUpdateMode(sal_True); -} - -//------------------------------------------------------------------------------ -void FmGridControl::InitColumnByField( - DbGridColumn* _pColumn, const Reference< XPropertySet >& _rxColumnModel, - const Reference< XNameAccess >& _rxFieldsByNames, const Reference< XIndexAccess >& _rxFieldsByIndex ) -{ - DBG_ASSERT( _rxFieldsByNames == _rxFieldsByIndex, "FmGridControl::InitColumnByField: invalid container interfaces!" ); - - // lookup the column which belongs to the control source - ::rtl::OUString sFieldName; - _rxColumnModel->getPropertyValue( FM_PROP_CONTROLSOURCE ) >>= sFieldName; - Reference< XPropertySet > xField; - _rxColumnModel->getPropertyValue( FM_PROP_BOUNDFIELD ) >>= xField; - - - if ( !xField.is() && /*sFieldName.getLength() && */_rxFieldsByNames->hasByName( sFieldName ) ) // #i93452# do not check for name length - _rxFieldsByNames->getByName( sFieldName ) >>= xField; - - // determine the position of this column - sal_Int32 nFieldPos = -1; - if ( xField.is() ) - { - Reference< XPropertySet > xCheck; - sal_Int32 nFieldCount = _rxFieldsByIndex->getCount(); - for ( sal_Int32 i = 0; i < nFieldCount; ++i) - { - _rxFieldsByIndex->getByIndex( i ) >>= xCheck; - if ( xField.get() == xCheck.get() ) - { - nFieldPos = i; - break; - } - } - } - - if ( xField.is() && ( nFieldPos >= 0 ) ) - { - // some data types are not allowed - sal_Int32 nDataType = DataType::OTHER; - xField->getPropertyValue( FM_PROP_FIELDTYPE ) >>= nDataType; - - sal_Bool bIllegalType = sal_False; - switch ( nDataType ) - { - case DataType::BLOB: - case DataType::LONGVARBINARY: - case DataType::BINARY: - case DataType::VARBINARY: - case DataType::OTHER: - bIllegalType = sal_True; - break; - } - - if ( bIllegalType ) - { - _pColumn->SetObject( (sal_Int16)nFieldPos ); - return; - } - } - - // the control type is determined by the ColumnServiceName - static ::rtl::OUString s_sPropColumnServiceName( RTL_CONSTASCII_USTRINGPARAM( "ColumnServiceName" ) ); - if ( !::comphelper::hasProperty( s_sPropColumnServiceName, _rxColumnModel ) ) - return; - - _pColumn->setModel( _rxColumnModel ); - - ::rtl::OUString sColumnServiceName; - _rxColumnModel->getPropertyValue( s_sPropColumnServiceName ) >>= sColumnServiceName; - - sal_Int32 nTypeId = getColumnTypeByModelName( sColumnServiceName ); - _pColumn->CreateControl( nFieldPos, xField, nTypeId ); -} - -//------------------------------------------------------------------------------ -void FmGridControl::InitColumnsByFields(const Reference< ::com::sun::star::container::XIndexAccess >& _rxFields) -{ - if ( !_rxFields.is() ) - return; - - // Spalten initialisieren - Reference< XIndexContainer > xColumns( GetPeer()->getColumns() ); - Reference< XNameAccess > xFieldsAsNames( _rxFields, UNO_QUERY ); - - // Einfuegen muss sich an den Column Positionen orientieren - for (sal_Int32 i = 0; i < xColumns->getCount(); i++) - { - DbGridColumn* pCol = GetColumns().at( i ); - OSL_ENSURE(pCol,"No grid column!"); - if ( pCol ) - { - Reference< XPropertySet > xColumnModel; - ::cppu::extractInterface( xColumnModel, xColumns->getByIndex( i ) ); - - InitColumnByField( pCol, xColumnModel, xFieldsAsNames, _rxFields ); - } - } -} - -//------------------------------------------------------------------------------ -void FmGridControl::HideColumn(sal_uInt16 nId) -{ - DbGridControl::HideColumn(nId); - - sal_uInt16 nPos = GetModelColumnPos(nId); - if (nPos == (sal_uInt16)-1) - return; - - DbGridColumn* pColumn = GetColumns().at( nPos ); - if (pColumn->IsHidden()) - GetPeer()->columnHidden(pColumn); - - if (nId == m_nMarkedColumnId) - m_nMarkedColumnId = (sal_uInt16)-1; -} -// ----------------------------------------------------------------------------- -sal_Bool FmGridControl::isColumnSelected(sal_uInt16 /*nId*/,DbGridColumn* _pColumn) -{ - OSL_ENSURE(_pColumn,"Column can not be null!"); - sal_Bool bSelected = sal_False; - // if the column which is shown here is selected ... - Reference< ::com::sun::star::view::XSelectionSupplier > xSelSupplier(GetPeer()->getColumns(), UNO_QUERY); - if ( xSelSupplier.is() ) - { - Reference< ::com::sun::star::beans::XPropertySet > xColumn; - xSelSupplier->getSelection() >>= xColumn; - bSelected = (xColumn.get() == _pColumn->getModel().get()); - } - return bSelected; -} - -//------------------------------------------------------------------------------ -void FmGridControl::ShowColumn(sal_uInt16 nId) -{ - DbGridControl::ShowColumn(nId); - - sal_uInt16 nPos = GetModelColumnPos(nId); - if (nPos == (sal_uInt16)-1) - return; - - DbGridColumn* pColumn = GetColumns().at( nPos ); - if (!pColumn->IsHidden()) - GetPeer()->columnVisible(pColumn); - - // if the column which is shown here is selected ... - if ( isColumnSelected(nId,pColumn) ) - markColumn(nId); // ... -> mark it -} - -//------------------------------------------------------------------------------ -sal_Bool FmGridControl::selectBookmarks(const Sequence< Any >& _rBookmarks) -{ - SolarMutexGuard aGuard; - // need to lock the SolarMutex so that no paint call disturbs us ... - - if ( !m_pSeekCursor ) - { - OSL_FAIL( "FmGridControl::selectBookmarks: no seek cursor!" ); - return sal_False; - } - - const Any* pBookmark = _rBookmarks.getConstArray(); - const Any* pBookmarkEnd = pBookmark + _rBookmarks.getLength(); - - SetNoSelection(); - - sal_Bool bAllSuccessfull = sal_True; - try - { - for (; pBookmark != pBookmarkEnd; ++pBookmark) - { - // move the seek cursor to the row given - if (m_pSeekCursor->moveToBookmark(*pBookmark)) - SelectRow( m_pSeekCursor->getRow() - 1); - else - bAllSuccessfull = sal_False; - } - } - catch(Exception&) - { - OSL_FAIL("FmGridControl::selectBookmarks: could not move to one of the bookmarks!"); - return sal_False; - } - - return bAllSuccessfull; -} - -//------------------------------------------------------------------------------ -Sequence< Any> FmGridControl::getSelectionBookmarks() -{ - // lock our update so no paint-triggered seeks interfere ... - SetUpdateMode(sal_False); - - sal_Int32 nSelectedRows = GetSelectRowCount(), i = 0; - Sequence< Any> aBookmarks(nSelectedRows); - if ( nSelectedRows ) - { - Any* pBookmarks = (Any*)aBookmarks.getArray(); - - // (I'm not sure if the problem isn't deeper : The szenario : a large table displayed by a grid with a - // thread-safe cursor (dBase). On loading the sdb-cursor started a counting thread. While this counting progress - // was running, I tried do delete 3 records from within the grid. Deletion caused a SeekCursor, which did a - // m_pSeekCursor->moveRelative and a m_pSeekCursor->getPosition. - // Unfortunally the first call caused a propertyChanged(RECORDCOUNT) which resulted in a repaint of the - // navigation bar and the grid. The latter itself will result in SeekRow calls. So after (successfully) returning - // from the moveRelative the getPosition returns an invalid value. And so the SeekCursor fails. - // In the consequence ALL parts of code where two calls to the seek cursor are done, while the second call _relys_ on - // the first one, should be secured against recursion, with a broad-minded interpretion of "recursion" : if any of these - // code parts is executed, no other should be accessible. But this sounds very difficult to achieve .... - // ) - - // The next problem caused by the same behaviuor (SeekCursor causes a propertyChanged) : when adjusting rows we implicitly - // change our selection. So a "FirstSelected(); SeekCursor(); NextSelected();" may produce unpredictable results. - // That's why we _first_ collect the indicies of the selected rows and _then_ their bookmarks. - long nIdx = FirstSelectedRow(); - while (nIdx >= 0) - { - // (we misuse the bookmarks array for this ...) - pBookmarks[i++] <<= (sal_Int32)nIdx; - nIdx = NextSelectedRow(); - } - DBG_ASSERT(i == nSelectedRows, "FmGridControl::DeleteSelectedRows : could not collect the row indicies !"); - - for (i=0; i<nSelectedRows; ++i) - { - nIdx = ::comphelper::getINT32(pBookmarks[i]); - if (IsInsertionRow(nIdx)) - { - // leerzeile nicht loeschen - aBookmarks.realloc(--nSelectedRows); - SelectRow(nIdx,sal_False); // selection aufheben fuer leerzeile - break; - } - - // Zunaechst den DatenCursor auf den selektierten Satz pos. - if (SeekCursor(nIdx)) - { - GetSeekRow()->SetState(m_pSeekCursor, sal_True); - - pBookmarks[i] = m_pSeekCursor->getBookmark(); - } - #ifdef DBG_UTIL - else - OSL_FAIL("FmGridControl::DeleteSelectedRows : a bookmark could not be determined !"); - #endif - } - } - SetUpdateMode(sal_True); - - // if one of the SeekCursor-calls failed .... - aBookmarks.realloc(i); - - // (the alternative : while collecting the bookmarks lock our propertyChanged, this should resolve both our problems. - // but this would be incompatible as we need a locking flag, then ...) - - return aBookmarks; -} -// ----------------------------------------------------------------------------- -namespace -{ - ::rtl::OUString getColumnPropertyFromPeer(FmXGridPeer* _pPeer,sal_Int32 _nPosition,const ::rtl::OUString& _sPropName) - { - ::rtl::OUString sRetText; - if ( _pPeer && _nPosition != -1) - { - Reference<XIndexContainer> xIndex = _pPeer->getColumns(); - if ( xIndex.is() && xIndex->getCount() > _nPosition ) - { - Reference<XPropertySet> xProp; - xIndex->getByIndex( _nPosition ) >>= xProp; - if ( xProp.is() ) - xProp->getPropertyValue( _sPropName ) >>= sRetText; - } - } - return sRetText; - } -} -// Object data and state ------------------------------------------------------ -::rtl::OUString FmGridControl::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType _eObjType,sal_Int32 _nPosition ) const -{ - ::rtl::OUString sRetText; - switch( _eObjType ) - { - case ::svt::BBTYPE_BROWSEBOX: - if ( GetPeer() ) - { - Reference<XPropertySet> xProp(GetPeer()->getColumns(),UNO_QUERY); - if ( xProp.is() ) - xProp->getPropertyValue(FM_PROP_NAME) >>= sRetText; - } - break; - case ::svt::BBTYPE_COLUMNHEADERCELL: - sRetText = getColumnPropertyFromPeer( - GetPeer(), - GetModelColumnPos( - sal::static_int_cast< sal_uInt16 >(_nPosition)), - FM_PROP_LABEL); - break; - default: - sRetText = DbGridControl::GetAccessibleObjectName(_eObjType,_nPosition); - } - return sRetText; -} -// ----------------------------------------------------------------------------- - -::rtl::OUString FmGridControl::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eObjType,sal_Int32 _nPosition ) const -{ - ::rtl::OUString sRetText; - switch( _eObjType ) - { - case ::svt::BBTYPE_BROWSEBOX: - if ( GetPeer() ) - { - Reference<XPropertySet> xProp(GetPeer()->getColumns(),UNO_QUERY); - if ( xProp.is() ) - { - xProp->getPropertyValue(FM_PROP_HELPTEXT) >>= sRetText; - if ( !sRetText.getLength() ) - xProp->getPropertyValue(FM_PROP_DESCRIPTION) >>= sRetText; - } - } - break; - case ::svt::BBTYPE_COLUMNHEADERCELL: - sRetText = getColumnPropertyFromPeer( - GetPeer(), - GetModelColumnPos( - sal::static_int_cast< sal_uInt16 >(_nPosition)), - FM_PROP_HELPTEXT); - if ( !sRetText.getLength() ) - sRetText = getColumnPropertyFromPeer( - GetPeer(), - GetModelColumnPos( - sal::static_int_cast< sal_uInt16 >(_nPosition)), - FM_PROP_DESCRIPTION); - - break; - default: - sRetText = DbGridControl::GetAccessibleObjectDescription(_eObjType,_nPosition); - } - return sRetText; -} -// ----------------------------------------------------------------------------- -void FmGridControl::Select() -{ - DbGridControl::Select(); - // ... betrifft das unsere Spalten ? - const MultiSelection* pColumnSelection = GetColumnSelection(); - - sal_uInt16 nSelectedColumn = - pColumnSelection && pColumnSelection->GetSelectCount() - ? sal::static_int_cast< sal_uInt16 >( - ((MultiSelection*)pColumnSelection)->FirstSelected()) - : SAL_MAX_UINT16; - // die HandleColumn wird nicht selektiert - switch (nSelectedColumn) - { - case SAL_MAX_UINT16: break; // no selection - case 0 : nSelectedColumn = SAL_MAX_UINT16; break; - // handle col can't be seledted - default : - // get the model col pos instead of the view col pos - nSelectedColumn = GetModelColumnPos(GetColumnIdFromViewPos(nSelectedColumn - 1)); - break; - } - - if (nSelectedColumn != m_nCurrentSelectedColumn) - { - // VOR dem Aufruf des select am SelectionSupplier ! - m_nCurrentSelectedColumn = nSelectedColumn; - - if (!m_bSelecting) - { - m_bSelecting = sal_True; - - try - { - Reference< XIndexAccess > xColumns(GetPeer()->getColumns(), UNO_QUERY); - Reference< XSelectionSupplier > xSelSupplier(xColumns, UNO_QUERY); - if (xSelSupplier.is()) - { - if (nSelectedColumn != SAL_MAX_UINT16) - { - Reference< XPropertySet > xColumn; - ::cppu::extractInterface(xColumn,xColumns->getByIndex(nSelectedColumn)); - xSelSupplier->select(makeAny(xColumn)); - } - else - { - xSelSupplier->select(Any()); - } - } - } - catch(Exception&) - { - } - - - m_bSelecting = sal_False; - } - } -} -// ----------------------------------------------------------------------------- -sal_Int32 FmGridControl::GetSelectedColumn() const -{ - return m_nCurrentSelectedColumn; -} -// ----------------------------------------------------------------------------- -void FmGridControl::KeyInput( const KeyEvent& rKEvt ) -{ - sal_Bool bDone = sal_False; - const KeyCode& rKeyCode = rKEvt.GetKeyCode(); - if ( IsDesignMode() - && !rKeyCode.IsShift() - && !rKeyCode.IsMod1() - && !rKeyCode.IsMod2() - && GetParent() ) - { - switch ( rKeyCode.GetCode() ) - { - case KEY_ESCAPE: - GetParent()->GrabFocus(); - bDone = sal_True; - break; - case KEY_DELETE: - if ( GetSelectColumnCount() && GetPeer() && m_nCurrentSelectedColumn >= 0 ) - { - Reference< ::com::sun::star::container::XIndexContainer > xCols(GetPeer()->getColumns()); - if ( xCols.is() ) - { - try - { - if ( m_nCurrentSelectedColumn < xCols->getCount() ) - { - Reference< XInterface > xCol; - xCols->getByIndex(m_nCurrentSelectedColumn) >>= xCol; - xCols->removeByIndex(m_nCurrentSelectedColumn); - ::comphelper::disposeComponent(xCol); - } - } - catch(const Exception&) - { - OSL_FAIL("exception occurred while deleting a column"); - } - } - } - bDone = sal_True; - break; - } - } - if ( !bDone ) - DbGridControl::KeyInput( rKEvt ); -} -// ----------------------------------------------------------------------------- - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/fmcomp/fmgridif.cxx b/svx/source/fmcomp/fmgridif.cxx deleted file mode 100644 index 5d73f4af5b..0000000000 --- a/svx/source/fmcomp/fmgridif.cxx +++ /dev/null @@ -1,2961 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svx.hxx" - -#include "svx/fmgridif.hxx" -#include "fmprop.hrc" -#include "fmservs.hxx" -#include "svx/fmtools.hxx" -#include "fmurl.hxx" -#include "formcontrolfactory.hxx" -#include "gridcell.hxx" -#include "sdbdatacolumn.hxx" -#include "svx/fmgridcl.hxx" -#include "svx/svxids.hrc" -#include <tools/urlobj.hxx> - -/** === begin UNO includes === **/ -#include <com/sun/star/awt/PosSize.hpp> -#include <com/sun/star/beans/PropertyAttribute.hpp> -#include <com/sun/star/form/FormComponentType.hpp> -#include <com/sun/star/form/XFormComponent.hpp> -#include <com/sun/star/form/XLoadable.hpp> -#include <com/sun/star/lang/DisposedException.hpp> -#include <com/sun/star/sdbc/ResultSetType.hpp> -#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> -#include <com/sun/star/util/XURLTransformer.hpp> -#include <com/sun/star/view/XSelectionSupplier.hpp> -#include <com/sun/star/sdbcx/XRowLocate.hpp> -/** === end UNO includes === **/ - -#include <comphelper/container.hxx> -#include <comphelper/enumhelper.hxx> -#include <comphelper/extract.hxx> -#include <comphelper/processfactory.hxx> -#include <comphelper/property.hxx> -#include <comphelper/sequence.hxx> -#include <comphelper/servicehelper.hxx> -#include <comphelper/types.hxx> -#include <cppuhelper/typeprovider.hxx> -#include <toolkit/helper/vclunohelper.hxx> -#include <tools/diagnose_ex.h> -#include <sal/macros.h> - -using namespace ::svxform; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::sdb; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::view; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::form; -using namespace ::com::sun::star::util; -using namespace ::com::sun::star; - -using ::com::sun::star::sdbcx::XColumnsSupplier; -using ::com::sun::star::frame::XDispatchProviderInterceptor; -using ::com::sun::star::frame::XDispatchProvider; -using ::com::sun::star::accessibility::XAccessible; -using ::com::sun::star::accessibility::XAccessibleContext; -using ::com::sun::star::sdb::XRowSetSupplier; -using ::com::sun::star::awt::XVclWindowPeer; - - -//------------------------------------------------------------------ -::com::sun::star::awt::FontDescriptor ImplCreateFontDescriptor( const Font& rFont ) -{ - ::com::sun::star::awt::FontDescriptor aFD; - aFD.Name = rFont.GetName(); - aFD.StyleName = rFont.GetStyleName(); - aFD.Height = (sal_Int16)rFont.GetSize().Height(); - aFD.Width = (sal_Int16)rFont.GetSize().Width(); - aFD.Family = (sal_Int16)rFont.GetFamily(); - aFD.CharSet = rFont.GetCharSet(); - aFD.Pitch = (sal_Int16)rFont.GetPitch(); - aFD.CharacterWidth = VCLUnoHelper::ConvertFontWidth( rFont.GetWidthType() ); - aFD.Weight= VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() ); - aFD.Slant = (::com::sun::star::awt::FontSlant)rFont.GetItalic(); - aFD.Underline = (sal_Int16)rFont.GetUnderline(); - aFD.Strikeout = (sal_Int16)rFont.GetStrikeout(); - aFD.Orientation = rFont.GetOrientation(); - aFD.Kerning = rFont.IsKerning(); - aFD.WordLineMode = rFont.IsWordLineMode(); - aFD.Type = 0; // ??? => Nur an Metric... - return aFD; -} - -//------------------------------------------------------------------ -Font ImplCreateFont( const ::com::sun::star::awt::FontDescriptor& rDescr ) -{ - Font aFont; - aFont.SetName( rDescr.Name ); - aFont.SetStyleName( rDescr.StyleName ); - aFont.SetSize( ::Size( rDescr.Width, rDescr.Height ) ); - aFont.SetFamily( (FontFamily)rDescr.Family ); - aFont.SetCharSet( (CharSet)rDescr.CharSet ); - aFont.SetPitch( (FontPitch)rDescr.Pitch ); - aFont.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr.CharacterWidth ) ); - aFont.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr.Weight ) ); - aFont.SetItalic( (FontItalic)rDescr.Slant ); - aFont.SetUnderline( (::FontUnderline)rDescr.Underline ); - aFont.SetStrikeout( (::FontStrikeout)rDescr.Strikeout ); - aFont.SetOrientation( (sal_Int16)rDescr.Orientation ); - aFont.SetKerning( rDescr.Kerning ); - aFont.SetWordLineMode( rDescr.WordLineMode ); - return aFont; -} - -//================================================================== -//= FmXModifyMultiplexer -//================================================================== -//------------------------------------------------------------------ -FmXModifyMultiplexer::FmXModifyMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex ) - :OWeakSubObject( rSource ) - ,OInterfaceContainerHelper( _rMutex ) -{ -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXModifyMultiplexer::queryInterface(const Type& _rType) throw (RuntimeException) -{ - Any aReturn; - aReturn = ::cppu::queryInterface(_rType, - static_cast< ::com::sun::star::util::XModifyListener*>(this), - static_cast< XEventListener*>(this) - ); - - if (!aReturn.hasValue()) - aReturn = OWeakSubObject::queryInterface( _rType ); - - return aReturn; -} - -//------------------------------------------------------------------ -void FmXModifyMultiplexer::disposing(const EventObject& ) throw( RuntimeException ) -{ -} - -//------------------------------------------------------------------ -void FmXModifyMultiplexer::modified(const EventObject& e) throw( RuntimeException ) -{ - EventObject aMulti( e); - aMulti.Source = &m_rParent; - notifyEach( &XModifyListener::modified, aMulti ); -} - -//================================================================== -//= FmXUpdateMultiplexer -//================================================================== -//------------------------------------------------------------------ -FmXUpdateMultiplexer::FmXUpdateMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex ) - :OWeakSubObject( rSource ) - ,OInterfaceContainerHelper( _rMutex ) -{ -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXUpdateMultiplexer::queryInterface(const Type& _rType) throw (RuntimeException) -{ - Any aReturn; - aReturn = ::cppu::queryInterface(_rType, - static_cast< XUpdateListener*>(this), - static_cast< XEventListener*>(this) - ); - - if (!aReturn.hasValue()) - aReturn = OWeakSubObject::queryInterface( _rType ); - - return aReturn; -} - -//------------------------------------------------------------------ -void FmXUpdateMultiplexer::disposing(const EventObject& ) throw( RuntimeException ) -{ -} - -//------------------------------------------------------------------ -sal_Bool FmXUpdateMultiplexer::approveUpdate(const EventObject &e) throw( RuntimeException ) -{ - EventObject aMulti( e ); - aMulti.Source = &m_rParent; - - sal_Bool bResult = sal_True; - if (getLength()) - { - ::cppu::OInterfaceIteratorHelper aIter(*this); - while ( bResult && aIter.hasMoreElements() ) - bResult = static_cast< XUpdateListener* >( aIter.next() )->approveUpdate( aMulti ); - } - - return bResult; -} - -//------------------------------------------------------------------ -void FmXUpdateMultiplexer::updated(const EventObject &e) throw( RuntimeException ) -{ - EventObject aMulti( e ); - aMulti.Source = &m_rParent; - notifyEach( &XUpdateListener::updated, aMulti ); -} - - -//================================================================== -//= FmXSelectionMultiplexer -//================================================================== -//------------------------------------------------------------------ -FmXSelectionMultiplexer::FmXSelectionMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex ) - :OWeakSubObject( rSource ) - ,OInterfaceContainerHelper( _rMutex ) -{ -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXSelectionMultiplexer::queryInterface(const Type& _rType) throw (RuntimeException) -{ - Any aReturn; - aReturn = ::cppu::queryInterface(_rType, - static_cast< XSelectionChangeListener*>(this), - static_cast< XEventListener*>(this) - ); - - if (!aReturn.hasValue()) - aReturn = OWeakSubObject::queryInterface( _rType ); - - return aReturn; -} - -//------------------------------------------------------------------ -void FmXSelectionMultiplexer::disposing(const EventObject& ) throw( RuntimeException ) -{ -} - -//------------------------------------------------------------------ -void SAL_CALL FmXSelectionMultiplexer::selectionChanged( const EventObject& _rEvent ) throw (RuntimeException) -{ - EventObject aMulti(_rEvent); - aMulti.Source = &m_rParent; - notifyEach( &XSelectionChangeListener::selectionChanged, aMulti ); -} - -//================================================================== -//= FmXContainerMultiplexer -//================================================================== -//------------------------------------------------------------------ -FmXContainerMultiplexer::FmXContainerMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex ) - :OWeakSubObject( rSource ) - ,OInterfaceContainerHelper( _rMutex ) -{ -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXContainerMultiplexer::queryInterface(const Type& _rType) throw (RuntimeException) -{ - Any aReturn; - aReturn = ::cppu::queryInterface(_rType, - static_cast< XContainerListener*>(this), - static_cast< XEventListener*>(this) - ); - - if (!aReturn.hasValue()) - aReturn = OWeakSubObject::queryInterface( _rType ); - - return aReturn; -} - -//------------------------------------------------------------------ -void FmXContainerMultiplexer::disposing(const EventObject& ) throw( RuntimeException ) -{ -} -//------------------------------------------------------------------ -void FmXContainerMultiplexer::elementInserted(const ContainerEvent& e) throw( RuntimeException ) -{ - ContainerEvent aMulti( e ); - aMulti.Source = &m_rParent; - notifyEach( &XContainerListener::elementInserted, aMulti ); -} - -//------------------------------------------------------------------ -void FmXContainerMultiplexer::elementRemoved(const ContainerEvent& e) throw( RuntimeException ) -{ - ContainerEvent aMulti( e ); - aMulti.Source = &m_rParent; - notifyEach( &XContainerListener::elementRemoved, aMulti ); -} - - -//------------------------------------------------------------------ -void FmXContainerMultiplexer::elementReplaced(const ContainerEvent& e) throw( RuntimeException ) -{ - ContainerEvent aMulti( e ); - aMulti.Source = &m_rParent; - notifyEach( &XContainerListener::elementReplaced, aMulti ); -} - -//================================================================== -//= FmXGridControlMultiplexer -//================================================================== -//------------------------------------------------------------------ -FmXGridControlMultiplexer::FmXGridControlMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex ) - :OWeakSubObject( rSource ) - ,OInterfaceContainerHelper( _rMutex ) -{ -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXGridControlMultiplexer::queryInterface(const Type& _rType) throw (RuntimeException) -{ - Any aReturn; - aReturn = ::cppu::queryInterface( _rType, - static_cast< XGridControlListener*>(this) - ); - - if (!aReturn.hasValue()) - aReturn = OWeakSubObject::queryInterface( _rType ); - - return aReturn; -} - -//------------------------------------------------------------------ -void FmXGridControlMultiplexer::disposing( const EventObject& ) throw( RuntimeException ) -{ -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridControlMultiplexer::columnChanged( const EventObject& _event ) throw (RuntimeException) -{ - EventObject aForwardedEvent( _event ); - aForwardedEvent.Source = &m_rParent; - notifyEach( &XGridControlListener::columnChanged, aForwardedEvent ); -} - -//================================================================== -//= FmXGridControl -//================================================================== - -//------------------------------------------------------------------ -Reference< XInterface > SAL_CALL FmXGridControl_NewInstance_Impl(const Reference< XMultiServiceFactory>& _rxFactory) -{ - return *(new FmXGridControl(_rxFactory)); -} -DBG_NAME(FmXGridControl ) -//------------------------------------------------------------------------------ -FmXGridControl::FmXGridControl(const Reference< XMultiServiceFactory >& _rxFactory) - :UnoControl( _rxFactory) - ,m_aModifyListeners(*this, GetMutex()) - ,m_aUpdateListeners(*this, GetMutex()) - ,m_aContainerListeners(*this, GetMutex()) - ,m_aSelectionListeners(*this, GetMutex()) - ,m_aGridControlListeners(*this, GetMutex()) - ,m_nPeerCreationLevel(0) - ,m_bInDraw(sal_False) - ,m_xServiceFactory(_rxFactory) -{ - DBG_CTOR(FmXGridControl ,NULL); -} - -//------------------------------------------------------------------------------ -FmXGridControl::~FmXGridControl() -{ - DBG_DTOR(FmXGridControl ,NULL); -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXGridControl::queryAggregation(const Type& _rType) throw (RuntimeException) -{ - Any aReturn = FmXGridControl_BASE::queryInterface(_rType); - - if (!aReturn.hasValue()) - aReturn = UnoControl::queryAggregation( _rType ); - return aReturn; -} - -//------------------------------------------------------------------ -Sequence< Type> SAL_CALL FmXGridControl::getTypes( ) throw(RuntimeException) -{ - return comphelper::concatSequences(UnoControl::getTypes(),FmXGridControl_BASE::getTypes()); -} - -//------------------------------------------------------------------ -Sequence<sal_Int8> SAL_CALL FmXGridControl::getImplementationId( ) throw(RuntimeException) -{ - static ::cppu::OImplementationId* pId = 0; - if (! pId) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if (! pId) - { - static ::cppu::OImplementationId aId; - pId = &aId; - } - } - return pId->getImplementationId(); -} - -// XServiceInfo -//------------------------------------------------------------------------------ -sal_Bool SAL_CALL FmXGridControl::supportsService(const ::rtl::OUString& ServiceName) throw() -{ - ::comphelper::StringSequence aSupported = getSupportedServiceNames(); - const ::rtl::OUString * pArray = aSupported.getConstArray(); - for( sal_Int32 i = 0; i < aSupported.getLength(); i++ ) - if( pArray[i] == ServiceName ) - return sal_True; - return sal_False; -} - -//------------------------------------------------------------------------------ -::rtl::OUString SAL_CALL FmXGridControl::getImplementationName() throw() -{ - return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.FmXGridControl")); -} - -//------------------------------------------------------------------------------ -::comphelper::StringSequence SAL_CALL FmXGridControl::getSupportedServiceNames() throw() -{ - Sequence< ::rtl::OUString > aServiceNames(2); - aServiceNames[0] = FM_SUN_CONTROL_GRIDCONTROL; - aServiceNames[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControl")); - return aServiceNames; -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::dispose() throw( RuntimeException ) -{ - SolarMutexGuard aGuard; - - EventObject aEvt; - aEvt.Source = static_cast< ::cppu::OWeakObject* >(this); - m_aModifyListeners.disposeAndClear(aEvt); - m_aUpdateListeners.disposeAndClear(aEvt); - m_aContainerListeners.disposeAndClear(aEvt); - - UnoControl::dispose(); -} - -//------------------------------------------------------------------------------ -::rtl::OUString FmXGridControl::GetComponentServiceName() -{ - ::rtl::OUString aName(RTL_CONSTASCII_USTRINGPARAM("DBGrid")); - return aName; -} - -//------------------------------------------------------------------------------ -sal_Bool SAL_CALL FmXGridControl::setModel(const Reference< ::com::sun::star::awt::XControlModel >& rModel) throw( RuntimeException ) -{ - SolarMutexGuard aGuard; - - if (!UnoControl::setModel(rModel)) - return sal_False; - - Reference< XGridPeer > xGridPeer(getPeer(), UNO_QUERY); - if (xGridPeer.is()) - { - Reference< XIndexContainer > xCols(mxModel, UNO_QUERY); - xGridPeer->setColumns(xCols); - } - return sal_True; -} - -//------------------------------------------------------------------------------ -FmXGridPeer* FmXGridControl::imp_CreatePeer(Window* pParent) -{ - FmXGridPeer* pReturn = new FmXGridPeer(m_xServiceFactory); - - // translate properties into WinBits - WinBits nStyle = WB_TABSTOP; - Reference< XPropertySet > xModelSet(getModel(), UNO_QUERY); - if (xModelSet.is()) - { - try - { - if (::comphelper::getINT16(xModelSet->getPropertyValue(FM_PROP_BORDER))) - nStyle |= WB_BORDER; - } - catch(const Exception&) - { - OSL_ASSERT(!"Can not get style"); - } - } - - pReturn->Create(pParent, nStyle); - return pReturn; -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::createPeer(const Reference< ::com::sun::star::awt::XToolkit >& /*rToolkit*/, const Reference< ::com::sun::star::awt::XWindowPeer >& rParentPeer) throw( RuntimeException ) -{ - if ( !mxModel.is() ) - throw DisposedException( ::rtl::OUString(), *this ); - - DBG_ASSERT(/*(0 == m_nPeerCreationLevel) && */!mbCreatingPeer, "FmXGridControl::createPeer : recursion!"); - // I think this should never assert, now that we're using the base class' mbCreatingPeer in addition to - // our own m_nPeerCreationLevel - // But I'm not sure as I don't _fully_ understand the underlying toolkit implementations .... - // (if this asserts, we still need m_nPeerCreationLevel. If not, we could omit it ....) - // 14.05.2001 - 86836 - frank.schoenheit@germany.sun.com - - // TODO: why the hell this whole class does not use any mutex? - - if (!getPeer().is()) - { - mbCreatingPeer = sal_True; - // mbCreatingPeer is virtually the same as m_nPeerCreationLevel, but it's the base class' method - // to prevent recursion. - - Window* pParentWin = NULL; - if (rParentPeer.is()) - { - VCLXWindow* pParent = VCLXWindow::GetImplementation(rParentPeer); - if (pParent) - pParentWin = pParent->GetWindow(); - } - - FmXGridPeer* pPeer = imp_CreatePeer(pParentWin); - DBG_ASSERT(pPeer != NULL, "FmXGridControl::createPeer : imp_CreatePeer didn't return a peer !"); - setPeer( pPeer ); - - // lesen der properties aus dem model -// ++m_nPeerCreationLevel; - updateFromModel(); - - // folgendes unschoene Szenario : updateFromModel fuehrt zu einem propertiesChanged am Control, - // das stellt fest, dass sich eine 'kritische' Property geaendert hat (zum Beispiel "Border") und - // legt daraufhin eine neue Peer an, was wieder hier im createPeer landet, wir legen also eine - // zweite FmXGridPeer an und initialisieren die. Dann kommen wir in der ersten Inkarnation aus - // dem updsateFromModel raus und arbeiten dort weiter mit dem pPeer, das jetzt eigentlich schon - // veraltet ist (da ja in der zweiten Inkarnation eine andere Peer angelegt wurde). - // Deswegen also der Aufwand mit dem PeerCreationLevel, das stellt sicher, dass wir die in dem - // tiefsten Level angelegte Peer wirklich verwenden, sie aber erst im top-level - // initialisieren. -// if (--m_nPeerCreationLevel == 0) - { - DBG_ASSERT(getPeer().is(), "FmXGridControl::createPeer : something went wrong ... no top level peer !"); - pPeer = FmXGridPeer::getImplementation(getPeer()); - - setPosSize( maComponentInfos.nX, maComponentInfos.nY, maComponentInfos.nWidth, maComponentInfos.nHeight, ::com::sun::star::awt::PosSize::POSSIZE ); - - Reference< XIndexContainer > xColumns(getModel(), UNO_QUERY); - if (xColumns.is()) - pPeer->setColumns(xColumns); - - if (maComponentInfos.bVisible) - pPeer->setVisible(sal_True); - - if (!maComponentInfos.bEnable) - pPeer->setEnable(sal_False); - - if (maWindowListeners.getLength()) - pPeer->addWindowListener( &maWindowListeners ); - - if (maFocusListeners.getLength()) - pPeer->addFocusListener( &maFocusListeners ); - - if (maKeyListeners.getLength()) - pPeer->addKeyListener( &maKeyListeners ); - - if (maMouseListeners.getLength()) - pPeer->addMouseListener( &maMouseListeners ); - - if (maMouseMotionListeners.getLength()) - pPeer->addMouseMotionListener( &maMouseMotionListeners ); - - if (maPaintListeners.getLength()) - pPeer->addPaintListener( &maPaintListeners ); - - if (m_aModifyListeners.getLength()) - pPeer->addModifyListener( &m_aModifyListeners ); - - if (m_aUpdateListeners.getLength()) - pPeer->addUpdateListener( &m_aUpdateListeners ); - - if (m_aContainerListeners.getLength()) - pPeer->addContainerListener( &m_aContainerListeners ); - - // forward the design mode - sal_Bool bForceAlivePeer = m_bInDraw && !maComponentInfos.bVisible; - // (we force a alive-mode peer if we're in "draw", cause in this case the peer will be used for drawing in - // foreign devices. We ensure this with the visibility check as an living peer is assumed to be noncritical - // only if invisible) - Any aOldCursorBookmark; - if (!mbDesignMode || bForceAlivePeer) - { - Reference< XFormComponent > xComp(getModel(), UNO_QUERY); - if (xComp.is()) - { - Reference< XRowSet > xForm(xComp->getParent(), UNO_QUERY); - // is the form alive? - // we can see that if the form contains columns - Reference< ::com::sun::star::sdbcx::XColumnsSupplier > xColumnsSupplier(xForm, UNO_QUERY); - if (xColumnsSupplier.is()) - { - if (Reference< XIndexAccess > (xColumnsSupplier->getColumns(),UNO_QUERY)->getCount()) - { - // we get only a new bookmark if the resultset is not forwardonly - if (::comphelper::getINT32(Reference< XPropertySet > (xForm, UNO_QUERY)->getPropertyValue(FM_PROP_RESULTSET_TYPE)) != ResultSetType::FORWARD_ONLY) - { - // as the FmGridControl touches the data source it is connected to we have to remember the current - // cursor position (and restore afterwards) - // OJ: but only when we stand on a valid row - Reference< XResultSet > xResultSet(xForm, UNO_QUERY); - if ( !xResultSet->isBeforeFirst() && !xResultSet->isAfterLast() ) - { - try - { - aOldCursorBookmark = Reference< ::com::sun::star::sdbcx::XRowLocate > (xForm, UNO_QUERY)->getBookmark(); - } - catch( const Exception& e ) - { - DBG_UNHANDLED_EXCEPTION(); - (void)e; - } - } - } - } - } - pPeer->setRowSet(xForm); - } - } - pPeer->setDesignMode(mbDesignMode && !bForceAlivePeer); - - try - { - if (aOldCursorBookmark.hasValue()) - { // we have a valid bookmark, so we have to restore the cursor's position - Reference< XFormComponent > xComp(getModel(), UNO_QUERY); - Reference< ::com::sun::star::sdbcx::XRowLocate > xLocate(xComp->getParent(), UNO_QUERY); - xLocate->moveToBookmark(aOldCursorBookmark); - } - } - catch( const Exception& e ) - { - DBG_UNHANDLED_EXCEPTION(); - (void)e; - } - - Reference< ::com::sun::star::awt::XView > xPeerView(getPeer(), UNO_QUERY); - xPeerView->setZoom( maComponentInfos.nZoomX, maComponentInfos.nZoomY ); - xPeerView->setGraphics( mxGraphics ); - } - mbCreatingPeer = sal_False; - } -} - -//------------------------------------------------------------------------------ -void FmXGridControl::addModifyListener(const Reference< ::com::sun::star::util::XModifyListener >& l) throw( RuntimeException ) -{ - m_aModifyListeners.addInterface( l ); - if( getPeer().is() && m_aModifyListeners.getLength() == 1 ) - { - Reference< ::com::sun::star::util::XModifyBroadcaster > xGrid(getPeer(), UNO_QUERY); - xGrid->addModifyListener( &m_aModifyListeners); - } -} - -//------------------------------------------------------------------------------ -sal_Bool SAL_CALL FmXGridControl::select( const Any& _rSelection ) throw (IllegalArgumentException, RuntimeException) -{ - SolarMutexGuard aGuard; - Reference< XSelectionSupplier > xPeer(getPeer(), UNO_QUERY); - return xPeer->select(_rSelection); -} - -//------------------------------------------------------------------------------ -Any SAL_CALL FmXGridControl::getSelection( ) throw (RuntimeException) -{ - SolarMutexGuard aGuard; - Reference< XSelectionSupplier > xPeer(getPeer(), UNO_QUERY); - return xPeer->getSelection(); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::addSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException) -{ - m_aSelectionListeners.addInterface( _rxListener ); - if( getPeer().is() && 1 == m_aSelectionListeners.getLength() ) - { - Reference< XSelectionSupplier > xGrid(getPeer(), UNO_QUERY); - xGrid->addSelectionChangeListener( &m_aSelectionListeners); - } -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException) -{ - if( getPeer().is() && 1 == m_aSelectionListeners.getLength() ) - { - Reference< XSelectionSupplier > xGrid(getPeer(), UNO_QUERY); - xGrid->removeSelectionChangeListener( &m_aSelectionListeners); - } - m_aSelectionListeners.removeInterface( _rxListener ); -} - -//------------------------------------------------------------------------------ -Sequence< sal_Bool > SAL_CALL FmXGridControl::queryFieldDataType( const Type& xType ) throw(RuntimeException) -{ - if (getPeer().is()) - { - Reference< XGridFieldDataSupplier > xPeerSupplier(getPeer(), UNO_QUERY); - if (xPeerSupplier.is()) - return xPeerSupplier->queryFieldDataType(xType); - } - - return Sequence<sal_Bool>(); -} - -//------------------------------------------------------------------------------ -Sequence< Any > SAL_CALL FmXGridControl::queryFieldData( sal_Int32 nRow, const Type& xType ) throw(RuntimeException) -{ - if (getPeer().is()) - { - Reference< XGridFieldDataSupplier > xPeerSupplier(getPeer(), UNO_QUERY); - if (xPeerSupplier.is()) - return xPeerSupplier->queryFieldData(nRow, xType); - } - - return Sequence< Any>(); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::removeModifyListener(const Reference< ::com::sun::star::util::XModifyListener >& l) throw( RuntimeException ) -{ - if( getPeer().is() && m_aModifyListeners.getLength() == 1 ) - { - Reference< ::com::sun::star::util::XModifyBroadcaster > xGrid(getPeer(), UNO_QUERY); - xGrid->removeModifyListener( &m_aModifyListeners); - } - m_aModifyListeners.removeInterface( l ); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::draw( sal_Int32 x, sal_Int32 y ) throw( RuntimeException ) -{ - SolarMutexGuard aGuard; - m_bInDraw = sal_True; - UnoControl::draw(x, y); - m_bInDraw = sal_False; -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::setDesignMode(sal_Bool bOn) throw( RuntimeException ) -{ - ::com::sun::star::util::ModeChangeEvent aModeChangeEvent; - - // --- <mutex_lock> --- - { - SolarMutexGuard aGuard; - - Reference< XRowSetSupplier > xGrid(getPeer(), UNO_QUERY); - - if (xGrid.is() && (bOn != mbDesignMode || (!bOn && !xGrid->getRowSet().is()))) - { - if (bOn) - { - xGrid->setRowSet(Reference< XRowSet > ()); - } - else - { - Reference< XFormComponent > xComp(getModel(), UNO_QUERY); - if (xComp.is()) - { - Reference< XRowSet > xForm(xComp->getParent(), UNO_QUERY); - xGrid->setRowSet(xForm); - } - } - - mbDesignMode = bOn; - - Reference< XVclWindowPeer > xVclWindowPeer( getPeer(), UNO_QUERY ); - if (xVclWindowPeer.is()) - xVclWindowPeer->setDesignMode(bOn); - } - mbDesignMode = bOn; - - // dispose our current AccessibleContext, if we have one - // (changing the design mode implies having a new implementation for this context, - // so the old one must be declared DEFUNC) - disposeAccessibleContext(); - - // prepare firing an event - aModeChangeEvent.Source = *this; - aModeChangeEvent.NewMode = mbDesignMode ? ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "design" )) : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "alive" )); - } - - // --- </mutex_lock> --- - maModeChangeListeners.notifyEach( &XModeChangeListener::modeChanged, aModeChangeEvent ); -} - -// XBoundComponent -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::addUpdateListener(const Reference< XUpdateListener >& l) throw( RuntimeException ) -{ - m_aUpdateListeners.addInterface( l ); - if( getPeer().is() && m_aUpdateListeners.getLength() == 1 ) - { - Reference< XBoundComponent > xBound(getPeer(), UNO_QUERY); - xBound->addUpdateListener( &m_aUpdateListeners); - } -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::removeUpdateListener(const Reference< XUpdateListener >& l) throw( RuntimeException ) -{ - if( getPeer().is() && m_aUpdateListeners.getLength() == 1 ) - { - Reference< XBoundComponent > xBound(getPeer(), UNO_QUERY); - xBound->removeUpdateListener( &m_aUpdateListeners); - } - m_aUpdateListeners.removeInterface( l ); -} - -//------------------------------------------------------------------------------ -sal_Bool SAL_CALL FmXGridControl::commit() throw( RuntimeException ) -{ - Reference< XBoundComponent > xBound(getPeer(), UNO_QUERY); - if (xBound.is()) - return xBound->commit(); - else - return sal_True; -} - -// XContainer -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::addContainerListener(const Reference< XContainerListener >& l) throw( RuntimeException ) -{ - m_aContainerListeners.addInterface( l ); - if( getPeer().is() && m_aContainerListeners.getLength() == 1 ) - { - Reference< XContainer > xContainer(getPeer(), UNO_QUERY); - xContainer->addContainerListener( &m_aContainerListeners); - } -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::removeContainerListener(const Reference< XContainerListener >& l) throw( RuntimeException ) -{ - if( getPeer().is() && m_aContainerListeners.getLength() == 1 ) - { - Reference< XContainer > xContainer(getPeer(), UNO_QUERY); - xContainer->removeContainerListener( &m_aContainerListeners); - } - m_aContainerListeners.removeInterface( l ); -} - -//------------------------------------------------------------------------------ -Reference< ::com::sun::star::frame::XDispatch > SAL_CALL FmXGridControl::queryDispatch(const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException ) -{ - Reference< ::com::sun::star::frame::XDispatchProvider > xPeerProvider(getPeer(), UNO_QUERY); - if (xPeerProvider.is()) - return xPeerProvider->queryDispatch(aURL, aTargetFrameName, nSearchFlags); - else - return Reference< ::com::sun::star::frame::XDispatch > (); -} - -//------------------------------------------------------------------------------ -Sequence< Reference< ::com::sun::star::frame::XDispatch > > SAL_CALL FmXGridControl::queryDispatches(const Sequence< ::com::sun::star::frame::DispatchDescriptor>& aDescripts) throw( RuntimeException ) -{ - Reference< ::com::sun::star::frame::XDispatchProvider > xPeerProvider(getPeer(), UNO_QUERY); - if (xPeerProvider.is()) - return xPeerProvider->queryDispatches(aDescripts); - else - return Sequence< Reference< ::com::sun::star::frame::XDispatch > >(); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::registerDispatchProviderInterceptor(const Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& _xInterceptor) throw( RuntimeException ) -{ - Reference< ::com::sun::star::frame::XDispatchProviderInterception > xPeerInterception(getPeer(), UNO_QUERY); - if (xPeerInterception.is()) - xPeerInterception->registerDispatchProviderInterceptor(_xInterceptor); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::releaseDispatchProviderInterceptor(const Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& _xInterceptor) throw( RuntimeException ) -{ - Reference< ::com::sun::star::frame::XDispatchProviderInterception > xPeerInterception(getPeer(), UNO_QUERY); - if (xPeerInterception.is()) - xPeerInterception->releaseDispatchProviderInterceptor(_xInterceptor); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::addGridControlListener( const Reference< XGridControlListener >& _listener ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( GetMutex() ); - - m_aGridControlListeners.addInterface( _listener ); - if ( getPeer().is() && 1 == m_aGridControlListeners.getLength() ) - { - Reference< XGridControl > xPeerGrid( getPeer(), UNO_QUERY ); - if ( xPeerGrid.is() ) - xPeerGrid->addGridControlListener( &m_aGridControlListeners ); - } -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::removeGridControlListener( const Reference< XGridControlListener >& _listener ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( GetMutex() ); - - if( getPeer().is() && 1 == m_aGridControlListeners.getLength() ) - { - Reference< XGridControl > xPeerGrid( getPeer(), UNO_QUERY ); - if ( xPeerGrid.is() ) - xPeerGrid->removeGridControlListener( &m_aGridControlListeners ); - } - - m_aGridControlListeners.removeInterface( _listener ); -} - -//------------------------------------------------------------------------------ -sal_Int16 SAL_CALL FmXGridControl::getCurrentColumnPosition() throw( RuntimeException ) -{ - Reference< XGridControl > xGrid( getPeer(), UNO_QUERY ); - return xGrid.is() ? xGrid->getCurrentColumnPosition() : -1; -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::setCurrentColumnPosition(sal_Int16 nPos) throw( RuntimeException ) -{ - Reference< XGridControl > xGrid( getPeer(), UNO_QUERY ); - if ( xGrid.is() ) - { - SolarMutexGuard aGuard; - xGrid->setCurrentColumnPosition( nPos ); - } -} - -// XElementAccess -//------------------------------------------------------------------------------ -sal_Bool SAL_CALL FmXGridControl::hasElements() throw( RuntimeException ) -{ - Reference< XElementAccess > xPeer(getPeer(), UNO_QUERY); - return xPeer.is() ? xPeer->hasElements() : 0; -} - -//------------------------------------------------------------------------------ -Type SAL_CALL FmXGridControl::getElementType( ) throw(RuntimeException) -{ - return ::getCppuType((const Reference< ::com::sun::star::awt::XTextComponent >*)NULL); -} - -// XEnumerationAccess -//------------------------------------------------------------------------------ -Reference< XEnumeration > SAL_CALL FmXGridControl::createEnumeration() throw( RuntimeException ) -{ - Reference< XEnumerationAccess > xPeer(getPeer(), UNO_QUERY); - if (xPeer.is()) - return xPeer->createEnumeration(); - else - return new ::comphelper::OEnumerationByIndex(this); -} - -// XIndexAccess -//------------------------------------------------------------------------------ -sal_Int32 SAL_CALL FmXGridControl::getCount() throw( RuntimeException ) -{ - Reference< XIndexAccess > xPeer(getPeer(), UNO_QUERY); - return xPeer.is() ? xPeer->getCount() : 0; -} - -//------------------------------------------------------------------------------ -Any SAL_CALL FmXGridControl::getByIndex(sal_Int32 _nIndex) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) -{ - Reference< XIndexAccess > xPeer(getPeer(), UNO_QUERY); - if (!xPeer.is()) - throw IndexOutOfBoundsException(); - - return xPeer->getByIndex(_nIndex); -} - -// ::com::sun::star::util::XModeSelector -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridControl::setMode(const ::rtl::OUString& Mode) throw( NoSupportException, RuntimeException ) -{ - Reference< ::com::sun::star::util::XModeSelector > xPeer(getPeer(), UNO_QUERY); - if (!xPeer.is()) - throw NoSupportException(); - - xPeer->setMode(Mode); -} - -//------------------------------------------------------------------------------ -::rtl::OUString SAL_CALL FmXGridControl::getMode() throw( RuntimeException ) -{ - Reference< ::com::sun::star::util::XModeSelector > xPeer(getPeer(), UNO_QUERY); - return xPeer.is() ? xPeer->getMode() : ::rtl::OUString(); -} - -//------------------------------------------------------------------------------ -::comphelper::StringSequence SAL_CALL FmXGridControl::getSupportedModes() throw( RuntimeException ) -{ - Reference< ::com::sun::star::util::XModeSelector > xPeer(getPeer(), UNO_QUERY); - return xPeer.is() ? xPeer->getSupportedModes() : ::comphelper::StringSequence(); -} - -//------------------------------------------------------------------------------ -sal_Bool SAL_CALL FmXGridControl::supportsMode(const ::rtl::OUString& Mode) throw( RuntimeException ) -{ - Reference< ::com::sun::star::util::XModeSelector > xPeer(getPeer(), UNO_QUERY); - return xPeer.is() ? xPeer->supportsMode(Mode) : sal_False; -} - -//============================================================================== -//= FmXGridPeer -//============================================================================== -// helper class which prevents that in the peer's header the FmGridListener must be known -class FmXGridPeer::GridListenerDelegator : public FmGridListener -{ -protected: - FmXGridPeer* m_pPeer; - -public: - GridListenerDelegator( FmXGridPeer* _pPeer ); - -protected: - virtual void selectionChanged(); - virtual void columnChanged(); -}; - -//------------------------------------------------------------------ -FmXGridPeer::GridListenerDelegator::GridListenerDelegator(FmXGridPeer* _pPeer) - :m_pPeer(_pPeer) -{ - DBG_ASSERT(m_pPeer, "GridListenerDelegator::GridListenerDelegator"); -} - -//------------------------------------------------------------------ -void FmXGridPeer::GridListenerDelegator::selectionChanged() -{ - m_pPeer->selectionChanged(); -} - -//------------------------------------------------------------------ -void FmXGridPeer::GridListenerDelegator::columnChanged() -{ - m_pPeer->columnChanged(); -} - -//============================================================================== -//------------------------------------------------------------------ -Reference< XInterface > FmXGridPeer_CreateInstance(const Reference< XMultiServiceFactory>& _rxFactory) -{ - FmXGridPeer* pNewObject = new FmXGridPeer(_rxFactory); - pNewObject->Create(NULL, WB_TABSTOP); - return *pNewObject; -} - -//------------------------------------------------------------------ -Sequence< Type> SAL_CALL FmXGridPeer::getTypes( ) throw(RuntimeException) -{ - return comphelper::concatSequences( VCLXWindow::getTypes(), FmXGridPeer_BASE::getTypes() ); -} - -//------------------------------------------------------------------ -Sequence<sal_Int8> SAL_CALL FmXGridPeer::getImplementationId( ) throw(RuntimeException) -{ - static ::cppu::OImplementationId* pId = 0; - if (! pId) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if (! pId) - { - static ::cppu::OImplementationId aId; - pId = &aId; - } - } - return pId->getImplementationId(); -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXGridPeer::queryInterface(const Type& _rType) throw (RuntimeException) -{ - Any aReturn = FmXGridPeer_BASE::queryInterface(_rType); - - if (!aReturn.hasValue()) - aReturn = VCLXWindow::queryInterface( _rType ); - - return aReturn; -} - -//------------------------------------------------------------------ -void FmXGridPeer::selectionChanged() -{ - EventObject aSource; - aSource.Source = static_cast< ::cppu::OWeakObject* >(this); - m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aSource); -} - -//------------------------------------------------------------------ -void FmXGridPeer::columnChanged() -{ - EventObject aEvent( *this ); - m_aGridControlListeners.notifyEach( &XGridControlListener::columnChanged, aEvent ); -} - -//------------------------------------------------------------------ -namespace fmgridif -{ - const ::rtl::OUString getDataModeIdentifier() - { - static ::rtl::OUString s_sDataModeIdentifier = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DataMode" ) ); - return s_sDataModeIdentifier; - } -} -using namespace fmgridif; - -//------------------------------------------------------------------ -FmXGridPeer::FmXGridPeer(const Reference< XMultiServiceFactory >& _rxFactory) - :m_aModifyListeners(m_aMutex) - ,m_aUpdateListeners(m_aMutex) - ,m_aContainerListeners(m_aMutex) - ,m_aSelectionListeners(m_aMutex) - ,m_aGridControlListeners(m_aMutex) - ,m_aMode( getDataModeIdentifier() ) - ,m_nCursorListening(0) - ,m_bInterceptingDispatch(sal_False) - ,m_pStateCache(NULL) - ,m_pDispatchers(NULL) - ,m_pGridListener(NULL) - ,m_xServiceFactory(_rxFactory) -{ - // nach diesem Constructor muss Create gerufen werden ! - m_pGridListener = new GridListenerDelegator( this ); -} - -//------------------------------------------------------------------------------ -FmGridControl* FmXGridPeer::imp_CreateControl(Window* pParent, WinBits nStyle) -{ - return new FmGridControl(m_xServiceFactory, pParent, this, nStyle); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::Create(Window* pParent, WinBits nStyle) -{ - FmGridControl* pWin = imp_CreateControl(pParent, nStyle); - DBG_ASSERT(pWin != NULL, "FmXGridPeer::Create : imp_CreateControl didn't return a control !"); - - pWin->SetStateProvider(LINK(this, FmXGridPeer, OnQueryGridSlotState)); - pWin->SetSlotExecutor(LINK(this, FmXGridPeer, OnExecuteGridSlot)); - - // want to hear about row selections - pWin->setGridListener( m_pGridListener ); - - // Init muß immer aufgerufen werden - pWin->Init(); - pWin->SetComponentInterface(this); - - getSupportedURLs(); -} - -//------------------------------------------------------------------------------ -FmXGridPeer::~FmXGridPeer() -{ - setRowSet(Reference< XRowSet > ()); - setColumns(Reference< XIndexContainer > ()); - - delete m_pGridListener; -} - -namespace -{ - class theFmXGridPeerImplementationId : public rtl::Static< UnoTunnelIdInit, theFmXGridPeerImplementationId > {}; -} - -const Sequence< sal_Int8 >& FmXGridPeer::getUnoTunnelImplementationId() throw() -{ - return theFmXGridPeerImplementationId::get().getSeq(); -} - -//------------------------------------------------------------------------------ -FmXGridPeer* FmXGridPeer::getImplementation( const Reference< XInterface >& _rxIFace ) throw() -{ - FmXGridPeer* pReturn = NULL; - Reference< XUnoTunnel > xTunnel(_rxIFace, UNO_QUERY); - if (xTunnel.is()) - pReturn = reinterpret_cast<FmXGridPeer*>(xTunnel->getSomething(getUnoTunnelImplementationId())); - - return pReturn; -} - -//------------------------------------------------------------------------------ -sal_Int64 SAL_CALL FmXGridPeer::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException) -{ - sal_Int64 nReturn(0); - - if ( (_rIdentifier.getLength() == 16) - && (0 == rtl_compareMemory( getUnoTunnelImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 )) - ) - { - nReturn = reinterpret_cast<sal_Int64>(this); - } - else - nReturn = VCLXWindow::getSomething(_rIdentifier); - - return nReturn; -} - -// XEventListener -//------------------------------------------------------------------------------ -void FmXGridPeer::disposing(const EventObject& e) throw( RuntimeException ) -{ -using namespace ::com::sun::star::util; - bool bKnownSender = false; - - Reference< XIndexContainer > xCols( e.Source, UNO_QUERY ); - if ( xCols.is() ) - { - setColumns(Reference< XIndexContainer > ()); - bKnownSender = true; - } - - Reference< XRowSet > xCursor(e.Source, UNO_QUERY); - if (xCursor.is()) - { - setRowSet( m_xCursor ); - m_xCursor = NULL; - bKnownSender = true; - } - - - if ( !bKnownSender && m_pDispatchers ) - { - const Sequence< URL>& aSupportedURLs = getSupportedURLs(); - const URL* pSupportedURLs = aSupportedURLs.getConstArray(); - for ( sal_uInt16 i=0; i < ( aSupportedURLs.getLength() ) && !bKnownSender; ++i, ++pSupportedURLs ) - { - if ( m_pDispatchers[i] == e.Source ) - { - m_pDispatchers[i]->removeStatusListener( static_cast< ::com::sun::star::frame::XStatusListener* >( this ), *pSupportedURLs ); - m_pDispatchers[i] = NULL; - m_pStateCache[i] = 0; - bKnownSender = true; - } - } - } - - if ( !bKnownSender ) - VCLXWindow::disposing(e); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::addModifyListener(const Reference< ::com::sun::star::util::XModifyListener >& l) throw( RuntimeException ) -{ - m_aModifyListeners.addInterface( l ); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::removeModifyListener(const Reference< ::com::sun::star::util::XModifyListener >& l) throw( RuntimeException ) -{ - m_aModifyListeners.removeInterface( l ); -} - -//------------------------------------------------------------------------------ -#define LAST_KNOWN_TYPE FormComponentType::PATTERNFIELD -Sequence< sal_Bool > SAL_CALL FmXGridPeer::queryFieldDataType( const Type& xType ) throw(RuntimeException) -{ - // eine 'Konvertierungstabelle' - static sal_Bool bCanConvert[LAST_KNOWN_TYPE][4] = - { - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::CONTROL - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::COMMANDBUTTON - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::RADIOBUTTON - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::IMAGEBUTTON - { sal_False, sal_False, sal_False, sal_True }, // FormComponentType::CHECKBOX - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::LISTBOX - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::COMBOBOX - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::GROUPBOX - { sal_True , sal_False, sal_False, sal_False }, // FormComponentType::TEXTFIELD - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::FIXEDTEXT - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::GRIDCONTROL - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::FILECONTROL - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::HIDDENCONTROL - { sal_False, sal_False, sal_False, sal_False }, // FormComponentType::IMAGECONTROL - { sal_True , sal_True , sal_True , sal_False }, // FormComponentType::DATEFIELD - { sal_True , sal_True , sal_False, sal_False }, // FormComponentType::TIMEFIELD - { sal_True , sal_True , sal_False, sal_False }, // FormComponentType::NUMERICFIELD - { sal_True , sal_True , sal_False, sal_False }, // FormComponentType::CURRENCYFIELD - { sal_True , sal_False, sal_False, sal_False } // FormComponentType::PATTERNFIELD - }; - - - sal_Int16 nMapColumn = -1; - switch (xType.getTypeClass()) - { - case TypeClass_STRING : nMapColumn = 0; break; - case TypeClass_FLOAT: - case TypeClass_DOUBLE : nMapColumn = 1; break; - case TypeClass_SHORT: - case TypeClass_LONG: - case TypeClass_UNSIGNED_LONG: - case TypeClass_UNSIGNED_SHORT : nMapColumn = 2; break; - case TypeClass_BOOLEAN : nMapColumn = 3; break; - default: - break; - } - - Reference< XIndexContainer > xColumns = getColumns(); - - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - sal_Int32 nColumns = pGrid->GetViewColCount(); - - DbGridColumns aColumns = pGrid->GetColumns(); - - Sequence<sal_Bool> aReturnSequence(nColumns); - sal_Bool* pReturnArray = aReturnSequence.getArray(); - - sal_Bool bRequestedAsAny = (xType.getTypeClass() == TypeClass_ANY); - - DbGridColumn* pCol; - Reference< ::com::sun::star::sdb::XColumn > xFieldContent; - Reference< XPropertySet > xCurrentColumn; - for (sal_Int32 i=0; i<nColumns; ++i) - { - if (bRequestedAsAny) - { - pReturnArray[i] = sal_True; - continue; - } - - pReturnArray[i] = sal_False; - - sal_uInt16 nModelPos = pGrid->GetModelColumnPos(pGrid->GetColumnIdFromViewPos((sal_uInt16)i)); - DBG_ASSERT(nModelPos != (sal_uInt16)-1, "FmXGridPeer::queryFieldDataType : no model pos !"); - - pCol = aColumns[ nModelPos ]; - const DbGridRowRef xRow = pGrid->GetSeekRow(); - xFieldContent = (xRow.Is() && xRow->HasField(pCol->GetFieldPos())) ? xRow->GetField(pCol->GetFieldPos()).getColumn() : Reference< ::com::sun::star::sdb::XColumn > (); - if (!xFieldContent.is()) - // can't supply anything without a field content - // FS - 07.12.99 - 54391 - continue; - - xColumns->getByIndex(nModelPos) >>= xCurrentColumn; - if (!::comphelper::hasProperty(FM_PROP_CLASSID, xCurrentColumn)) - continue; - - sal_Int16 nClassId = sal_Int16(); - xCurrentColumn->getPropertyValue(FM_PROP_CLASSID) >>= nClassId; - if (nClassId>LAST_KNOWN_TYPE) - continue; - DBG_ASSERT(nClassId>0, "FmXGridPeer::queryFieldDataType : somebody changed the definition of the FormComponentType enum !"); - - if (nMapColumn != -1) - pReturnArray[i] = bCanConvert[nClassId-1][nMapColumn]; - } - - return aReturnSequence; -} - -//------------------------------------------------------------------------------ -Sequence< Any > SAL_CALL FmXGridPeer::queryFieldData( sal_Int32 nRow, const Type& xType ) throw(RuntimeException) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - DBG_ASSERT(pGrid && pGrid->IsOpen(), "FmXGridPeer::queryFieldData : have no valid grid window !"); - if (!pGrid || !pGrid->IsOpen()) - return Sequence< Any>(); - - // das Control zur angegebenen Row fahren - if (!pGrid->SeekRow(nRow)) - { - throw IllegalArgumentException(); - } - - // don't use GetCurrentRow as this isn't affected by the above SeekRow - // FS - 30.09.99 - 68644 - DbGridRowRef xPaintRow = pGrid->GetPaintRow(); - ENSURE_OR_THROW( xPaintRow.Is(), "invalid paint row" ); - - // die Columns des Controls brauche ich fuer GetFieldText - DbGridColumns aColumns = pGrid->GetColumns(); - - // und durch alle Spalten durch - sal_Int32 nColumnCount = pGrid->GetViewColCount(); - - Sequence< Any> aReturnSequence(nColumnCount); - Any* pReturnArray = aReturnSequence.getArray(); - - sal_Bool bRequestedAsAny = (xType.getTypeClass() == TypeClass_ANY); - Reference< ::com::sun::star::sdb::XColumn > xFieldContent; - DbGridColumn* pCol; - for (sal_Int32 i=0; i < nColumnCount; ++i) - { - sal_uInt16 nModelPos = pGrid->GetModelColumnPos(pGrid->GetColumnIdFromViewPos((sal_uInt16)i)); - DBG_ASSERT(nModelPos != (sal_uInt16)-1, "FmXGridPeer::queryFieldData : invalid model pos !"); - - // don't use GetCurrentFieldValue to determine the field content as this isn't affected by the above SeekRow - // FS - 30.09.99 - 68644 - pCol = aColumns[ nModelPos ]; - xFieldContent = xPaintRow->HasField( pCol->GetFieldPos() ) - ? xPaintRow->GetField( pCol->GetFieldPos() ).getColumn() - : Reference< XColumn > (); - - if ( !xFieldContent.is() ) - continue; - - if (bRequestedAsAny) - { - Reference< XPropertySet > xFieldSet(xFieldContent, UNO_QUERY); - pReturnArray[i] = xFieldSet->getPropertyValue(FM_PROP_VALUE); - } - else - { - switch (xType.getTypeClass()) - { - // Strings werden direkt ueber das GetFieldText abgehandelt - case TypeClass_STRING : - { - String sText = aColumns[ nModelPos ]->GetCellText( xPaintRow, pGrid->getNumberFormatter() ); - pReturnArray[i] <<= ::rtl::OUString(sText); - } - break; - // alles andere wird an der DatabaseVariant erfragt - case TypeClass_FLOAT : pReturnArray[i] <<= xFieldContent->getFloat(); break; - case TypeClass_DOUBLE : pReturnArray[i] <<= xFieldContent->getDouble(); break; - case TypeClass_SHORT : pReturnArray[i] <<= (sal_Int16)xFieldContent->getShort(); break; - case TypeClass_LONG : pReturnArray[i] <<= (sal_Int32)xFieldContent->getLong(); break; - case TypeClass_UNSIGNED_SHORT : pReturnArray[i] <<= (sal_uInt16)xFieldContent->getShort(); break; - case TypeClass_UNSIGNED_LONG : pReturnArray[i] <<= (sal_uInt32)xFieldContent->getLong(); break; - case TypeClass_BOOLEAN : ::comphelper::setBOOL(pReturnArray[i],xFieldContent->getBoolean()); break; - default: - { - throw IllegalArgumentException(); - } - } - } - } - return aReturnSequence; -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::CellModified() -{ - EventObject aEvt; - aEvt.Source = static_cast< ::cppu::OWeakObject* >(this); - m_aModifyListeners.notifyEach( &XModifyListener::modified, aEvt ); -} - -// XPropertyChangeListener -//------------------------------------------------------------------------------ -void FmXGridPeer::propertyChange(const PropertyChangeEvent& evt) throw( RuntimeException ) -{ - SolarMutexGuard aGuard; - // want to do a lot of VCL stuff here ... - // this should not be (deadlock) critical, as by definition, every component should release - // any own mutexes before notifying - - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - if (!pGrid) - return; - - // DatenbankEvent - Reference< XRowSet > xCursor(evt.Source, UNO_QUERY); - if (evt.PropertyName == FM_PROP_VALUE || m_xCursor == evt.Source) - pGrid->propertyChange(evt); - else if (pGrid && m_xColumns.is() && m_xColumns->hasElements()) - { - // zunaechst raussuchen welche Column sich geaendert hat - ::comphelper::InterfaceRef xCurrent; - sal_Int32 i; - - for ( i = 0; i < m_xColumns->getCount(); i++) - { - ::cppu::extractInterface(xCurrent, m_xColumns->getByIndex(i)); - if (evt.Source == xCurrent) - break; - } - - if (i >= m_xColumns->getCount()) - // this is valid because we are listening at the cursor, too (RecordCount, -status, edit mode) - return; - - sal_uInt16 nId = pGrid->GetColumnIdFromModelPos((sal_uInt16)i); - sal_Bool bInvalidateColumn = sal_False; - - if (evt.PropertyName == FM_PROP_LABEL) - { - String aName = ::comphelper::getString(evt.NewValue); - if (aName != pGrid->GetColumnTitle(nId)) - pGrid->SetColumnTitle(nId, aName); - } - else if (evt.PropertyName == FM_PROP_WIDTH) - { - sal_Int32 nWidth = 0; - if (evt.NewValue.getValueType().getTypeClass() == TypeClass_VOID) - nWidth = pGrid->GetDefaultColumnWidth(pGrid->GetColumnTitle(nId)); - // GetDefaultColumnWidth already considerd the zoom factor - else - { - sal_Int32 nTest = 0; - if (evt.NewValue >>= nTest) - { - nWidth = pGrid->LogicToPixel(Point(nTest,0),MAP_10TH_MM).X(); - // take the zoom factor into account - nWidth = pGrid->CalcZoom(nWidth); - } - } - if (nWidth != (sal_Int32(pGrid->GetColumnWidth(nId)))) - { - if (pGrid->IsEditing()) - { - pGrid->DeactivateCell(); - pGrid->ActivateCell(); - } - pGrid->SetColumnWidth(nId, nWidth); - } - } - else if (evt.PropertyName == FM_PROP_HIDDEN) - { - DBG_ASSERT(evt.NewValue.getValueType().getTypeClass() == TypeClass_BOOLEAN, - "FmXGridPeer::propertyChange : the property 'hidden' should be of type boolean !"); - if (::comphelper::getBOOL(evt.NewValue)) - pGrid->HideColumn(nId); - else - pGrid->ShowColumn(nId); - } - else if (evt.PropertyName == FM_PROP_ALIGN) - { - // it design mode it doesn't matter - if (!isDesignMode()) - { - DbGridColumn* pCol = pGrid->GetColumns().at( i ); - - pCol->SetAlignmentFromModel(-1); - bInvalidateColumn = sal_True; - } - } - else if (evt.PropertyName == FM_PROP_FORMATKEY) - { - if (!isDesignMode()) - bInvalidateColumn = sal_True; - } - - // need to invalidate the affected column ? - if (bInvalidateColumn) - { - sal_Bool bWasEditing = pGrid->IsEditing(); - if (bWasEditing) - pGrid->DeactivateCell(); - - ::Rectangle aColRect = pGrid->GetFieldRect(nId); - aColRect.Top() = 0; - aColRect.Bottom() = pGrid->GetSizePixel().Height(); - pGrid->Invalidate(aColRect); - - if (bWasEditing) - pGrid->ActivateCell(); - } - } -} - -// XBoundComponent -//------------------------------------------------------------------------------ -void FmXGridPeer::addUpdateListener(const Reference< XUpdateListener >& l) throw( RuntimeException ) -{ - m_aUpdateListeners.addInterface(l); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::removeUpdateListener(const Reference< XUpdateListener >& l) throw( RuntimeException ) -{ - m_aUpdateListeners.removeInterface(l); -} - -//------------------------------------------------------------------------------ -sal_Bool FmXGridPeer::commit() throw( RuntimeException ) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - if (!m_xCursor.is() || !pGrid) - return sal_True; - - EventObject aEvt(static_cast< ::cppu::OWeakObject* >(this)); - ::cppu::OInterfaceIteratorHelper aIter(m_aUpdateListeners); - sal_Bool bCancel = sal_False; - while (aIter.hasMoreElements() && !bCancel) - if ( !static_cast< XUpdateListener* >( aIter.next() )->approveUpdate( aEvt ) ) - bCancel = sal_True; - - if (!bCancel) - bCancel = !pGrid->commit(); - - if (!bCancel) - m_aUpdateListeners.notifyEach( &XUpdateListener::updated, aEvt ); - return !bCancel; -} - - -//------------------------------------------------------------------------------ -void FmXGridPeer::cursorMoved(const EventObject& _rEvent) throw( RuntimeException ) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - // we are not interested in move to insert row only in the resetted event - // which is fired after positioning an the insert row - if (pGrid && pGrid->IsOpen() && !::comphelper::getBOOL(Reference< XPropertySet > (_rEvent.Source, UNO_QUERY)->getPropertyValue(FM_PROP_ISNEW))) - pGrid->positioned(_rEvent); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::rowChanged(const EventObject& _rEvent) throw( RuntimeException ) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - if (pGrid && pGrid->IsOpen()) - { - if (m_xCursor->rowUpdated() && !pGrid->IsCurrentAppending()) - pGrid->RowModified(pGrid->GetCurrentPos()); - else if (m_xCursor->rowInserted()) - pGrid->inserted(_rEvent); - } -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::rowSetChanged(const EventObject& /*event*/) throw( RuntimeException ) -{ - // not interested in ... - // (our parent is a form which means we get a loaded or reloaded after this rowSetChanged) -} - -// XLoadListener -//------------------------------------------------------------------------------ -void FmXGridPeer::loaded(const EventObject& /*rEvent*/) throw( RuntimeException ) -{ - updateGrid(m_xCursor); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::unloaded(const EventObject& /*rEvent*/) throw( RuntimeException ) -{ - updateGrid( Reference< XRowSet > (NULL) ); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::reloading(const EventObject& /*aEvent*/) throw( RuntimeException ) -{ - // empty the grid - updateGrid( Reference< XRowSet > (NULL) ); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::unloading(const EventObject& /*aEvent*/) throw( RuntimeException ) -{ - // empty the grid - updateGrid( Reference< XRowSet > (NULL) ); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::reloaded(const EventObject& /*aEvent*/) throw( RuntimeException ) -{ - updateGrid(m_xCursor); -} - -// XGridPeer -//------------------------------------------------------------------------------ -Reference< XIndexContainer > FmXGridPeer::getColumns() throw( RuntimeException ) -{ - return m_xColumns; -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::addColumnListeners(const Reference< XPropertySet >& xCol) -{ - static const ::rtl::OUString aPropsListenedTo[] = - { - FM_PROP_LABEL, FM_PROP_WIDTH, FM_PROP_HIDDEN, FM_PROP_ALIGN, FM_PROP_FORMATKEY - }; - - // as not all properties have to be supported by all columns we have to check this - // before adding a listener - Reference< XPropertySetInfo > xInfo = xCol->getPropertySetInfo(); - Property aPropDesc; - const ::rtl::OUString* pProps = aPropsListenedTo; - const ::rtl::OUString* pPropsEnd = pProps + SAL_N_ELEMENTS( aPropsListenedTo ); - for (; pProps != pPropsEnd; ++pProps) - { - if ( xInfo->hasPropertyByName( *pProps ) ) - { - aPropDesc = xInfo->getPropertyByName( *pProps ); - if ( 0 != ( aPropDesc.Attributes & PropertyAttribute::BOUND ) ) - xCol->addPropertyChangeListener( *pProps, this ); - } - } -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::removeColumnListeners(const Reference< XPropertySet >& xCol) -{ - // the same props as in addColumnListeners ... linux has problems with global static UStrings, so - // we have to do it this way .... - static ::rtl::OUString aPropsListenedTo[] = - { - FM_PROP_LABEL, FM_PROP_WIDTH, FM_PROP_HIDDEN, FM_PROP_ALIGN, FM_PROP_FORMATKEY - }; - - Reference< XPropertySetInfo > xInfo = xCol->getPropertySetInfo(); - for (sal_uInt16 i=0; i < SAL_N_ELEMENTS(aPropsListenedTo); ++i) - if (xInfo->hasPropertyByName(aPropsListenedTo[i])) - xCol->removePropertyChangeListener(aPropsListenedTo[i], this); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::setColumns(const Reference< XIndexContainer >& Columns) throw( RuntimeException ) -{ - SolarMutexGuard aGuard; - - FmGridControl* pGrid = static_cast< FmGridControl* >( GetWindow() ); - - if (m_xColumns.is()) - { - Reference< XPropertySet > xCol; - for (sal_Int32 i = 0; i < m_xColumns->getCount(); i++) - { - ::cppu::extractInterface(xCol, m_xColumns->getByIndex(i)); - removeColumnListeners(xCol); - } - Reference< XContainer > xContainer(m_xColumns, UNO_QUERY); - xContainer->removeContainerListener(this); - - Reference< XSelectionSupplier > xSelSupplier(m_xColumns, UNO_QUERY); - xSelSupplier->removeSelectionChangeListener(this); - - Reference< XReset > xColumnReset(m_xColumns, UNO_QUERY); - if (xColumnReset.is()) - xColumnReset->removeResetListener((XResetListener*)this); - } - if (Columns.is()) - { - Reference< XContainer > xContainer(Columns, UNO_QUERY); - xContainer->addContainerListener(this); - - Reference< XSelectionSupplier > xSelSupplier(Columns, UNO_QUERY); - xSelSupplier->addSelectionChangeListener(this); - - Reference< XPropertySet > xCol; - for (sal_Int32 i = 0; i < Columns->getCount(); i++) - { - ::cppu::extractInterface(xCol, Columns->getByIndex(i)); - addColumnListeners(xCol); - } - - Reference< XReset > xColumnReset(Columns, UNO_QUERY); - if (xColumnReset.is()) - xColumnReset->addResetListener((XResetListener*)this); - } - m_xColumns = Columns; - if (pGrid) - { - pGrid->InitColumnsByModels(m_xColumns); - - if (m_xColumns.is()) - { - EventObject aEvt(m_xColumns); - selectionChanged(aEvt); - } - } -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::setDesignMode(sal_Bool bOn) throw( RuntimeException ) -{ - if (bOn != isDesignMode()) - { - Window* pWin = GetWindow(); - if (pWin) - ((FmGridControl*) pWin)->SetDesignMode(bOn); - } - - if (bOn) - DisConnectFromDispatcher(); - else - UpdateDispatches(); // will connect if not already connected and just update else -} - -//------------------------------------------------------------------------------ -sal_Bool FmXGridPeer::isDesignMode() throw( RuntimeException ) -{ - Window* pWin = GetWindow(); - if (pWin) - return ((FmGridControl*) pWin)->IsDesignMode(); - else - return sal_False; -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::elementInserted(const ContainerEvent& evt) throw( RuntimeException ) -{ - SolarMutexGuard aGuard; - - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - // Handle Column beruecksichtigen - if (!pGrid || !m_xColumns.is() || pGrid->IsInColumnMove() || m_xColumns->getCount() == ((sal_Int32)pGrid->GetModelColCount())) - return; - - Reference< XPropertySet > xSet; - ::cppu::extractInterface(xSet, evt.Element); - addColumnListeners(xSet); - - Reference< XPropertySet > xNewColumn(xSet); - String aName = ::comphelper::getString(xNewColumn->getPropertyValue(FM_PROP_LABEL)); - Any aWidth = xNewColumn->getPropertyValue(FM_PROP_WIDTH); - sal_Int32 nWidth = 0; - if (aWidth >>= nWidth) - nWidth = pGrid->LogicToPixel(Point(nWidth,0),MAP_10TH_MM).X(); - - pGrid->AppendColumn(aName, (sal_uInt16)nWidth, (sal_Int16)::comphelper::getINT32(evt.Accessor)); - - // jetzt die Spalte setzen - DbGridColumn* pCol = pGrid->GetColumns().at( ::comphelper::getINT32(evt.Accessor) ); - pCol->setModel(xNewColumn); - - Any aHidden = xNewColumn->getPropertyValue(FM_PROP_HIDDEN); - if (::comphelper::getBOOL(aHidden)) - pGrid->HideColumn(pCol->GetId()); - - FormControlFactory( m_xServiceFactory ).initializeTextFieldLineEnds( xNewColumn ); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::elementReplaced(const ContainerEvent& evt) throw( RuntimeException ) -{ - SolarMutexGuard aGuard; - - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - - // Handle Column beruecksichtigen - if (!pGrid || !m_xColumns.is() || pGrid->IsInColumnMove()) - return; - - Reference< XPropertySet > xNewColumn; - Reference< XPropertySet > xOldColumn; - ::cppu::extractInterface(xNewColumn, evt.Element); - ::cppu::extractInterface(xOldColumn, evt.ReplacedElement); - - sal_Bool bWasEditing = pGrid->IsEditing(); - if (bWasEditing) - pGrid->DeactivateCell(); - - pGrid->RemoveColumn(pGrid->GetColumnIdFromModelPos((sal_uInt16)::comphelper::getINT32(evt.Accessor))); - - removeColumnListeners(xOldColumn); - addColumnListeners(xNewColumn); - - String aName = ::comphelper::getString(xNewColumn->getPropertyValue(FM_PROP_LABEL)); - Any aWidth = xNewColumn->getPropertyValue(FM_PROP_WIDTH); - sal_Int32 nWidth = 0; - if (aWidth >>= nWidth) - nWidth = pGrid->LogicToPixel(Point(nWidth,0),MAP_10TH_MM).X(); - sal_uInt16 nNewId = pGrid->AppendColumn(aName, (sal_uInt16)nWidth, (sal_Int16)::comphelper::getINT32(evt.Accessor)); - sal_uInt16 nNewPos = pGrid->GetModelColumnPos(nNewId); - - // set the model of the new column - DbGridColumn* pCol = pGrid->GetColumns().at( nNewPos ); - - // for initializong this grid column, we need the fields of the grid's data source - Reference< XColumnsSupplier > xSuppColumns; - CursorWrapper* pGridDataSource = pGrid->getDataSource(); - if ( pGridDataSource ) - xSuppColumns = xSuppColumns.query( (Reference< XInterface >)( *pGridDataSource ) ); - Reference< XNameAccess > xColumnsByName; - if ( xSuppColumns.is() ) - xColumnsByName = xSuppColumns->getColumns(); - Reference< XIndexAccess > xColumnsByIndex( xColumnsByName, UNO_QUERY ); - - if ( xColumnsByIndex.is() ) - pGrid->InitColumnByField( pCol, xNewColumn, xColumnsByName, xColumnsByIndex ); - else - // the simple version, applies when the grid is not yet connected to a data source - pCol->setModel(xNewColumn); - - if (bWasEditing) - pGrid->ActivateCell(); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::elementRemoved(const ContainerEvent& evt) throw( RuntimeException ) -{ - SolarMutexGuard aGuard; - - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - - // Handle Column beruecksichtigen - if (!pGrid || !m_xColumns.is() || pGrid->IsInColumnMove() || m_xColumns->getCount() == ((sal_Int32)pGrid->GetModelColCount())) - return; - - pGrid->RemoveColumn(pGrid->GetColumnIdFromModelPos((sal_uInt16)::comphelper::getINT32(evt.Accessor))); - - Reference< XPropertySet > xOldColumn; - ::cppu::extractInterface(xOldColumn, evt.Element); - removeColumnListeners(xOldColumn); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::setProperty( const ::rtl::OUString& PropertyName, const Any& Value) throw( RuntimeException ) -{ - SolarMutexGuard aGuard; - - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - - sal_Bool bVoid = !Value.hasValue(); - - if ( 0 == PropertyName.compareTo( FM_PROP_TEXTLINECOLOR ) ) - { - ::Color aTextLineColor( bVoid ? COL_TRANSPARENT : ::comphelper::getINT32( Value ) ); - if (bVoid) - { - pGrid->SetTextLineColor(); - pGrid->GetDataWindow().SetTextLineColor(); - } - else - { - pGrid->SetTextLineColor(aTextLineColor); - pGrid->GetDataWindow().SetTextLineColor(aTextLineColor); - } - - // need to forward this to the columns - DbGridColumns& rColumns = const_cast<DbGridColumns&>(pGrid->GetColumns()); - for ( size_t i = 0, n = rColumns.size(); i < n; ++i ) - { - DbGridColumn* pLoop = rColumns[ i ]; - FmXGridCell* pXCell = pLoop->GetCell(); - if (pXCell) - { - if (bVoid) - pXCell->SetTextLineColor(); - else - pXCell->SetTextLineColor(aTextLineColor); - } - } - - if (isDesignMode()) - pGrid->Invalidate(); - } - else if ( 0 == PropertyName.compareTo( FM_PROP_FONTEMPHASISMARK ) ) - { - Font aGridFont = pGrid->GetControlFont(); - sal_Int16 nValue = ::comphelper::getINT16(Value); - aGridFont.SetEmphasisMark( nValue ); - pGrid->SetControlFont( aGridFont ); - } - else if ( 0 == PropertyName.compareTo( FM_PROP_FONTRELIEF ) ) - { - Font aGridFont = pGrid->GetControlFont(); - sal_Int16 nValue = ::comphelper::getINT16(Value); - aGridFont.SetRelief( (FontRelief)nValue ); - pGrid->SetControlFont( aGridFont ); - } - else if ( 0 == PropertyName.compareTo( FM_PROP_HELPURL ) ) - { - ::rtl::OUString sHelpURL; - OSL_VERIFY( Value >>= sHelpURL ); - INetURLObject aHID( sHelpURL ); - if ( aHID.GetProtocol() == INET_PROT_HID ) - sHelpURL = aHID.GetURLPath(); - pGrid->SetHelpId( rtl::OUStringToOString( sHelpURL, RTL_TEXTENCODING_UTF8 ) ); - } - else if ( 0 == PropertyName.compareTo( FM_PROP_DISPLAYSYNCHRON ) ) - { - pGrid->setDisplaySynchron(::comphelper::getBOOL(Value)); - } - else if ( 0 == PropertyName.compareTo( FM_PROP_CURSORCOLOR ) ) - { - if (bVoid) - pGrid->SetCursorColor(COL_TRANSPARENT); - else - pGrid->SetCursorColor( ::Color(::comphelper::getINT32(Value))); - if (isDesignMode()) - pGrid->Invalidate(); - } - else if ( 0 == PropertyName.compareTo( FM_PROP_ALWAYSSHOWCURSOR ) ) - { - pGrid->EnablePermanentCursor(::comphelper::getBOOL(Value)); - if (isDesignMode()) - pGrid->Invalidate(); - } - else if ( 0 == PropertyName.compareTo( FM_PROP_FONT ) ) - { - if ( bVoid ) - pGrid->SetControlFont( Font() ); - else - { - ::com::sun::star::awt::FontDescriptor aFont; - if (Value >>= aFont) - { - Font aNewVclFont; - if (::comphelper::operator!=(aFont, ::comphelper::getDefaultFont())) // ist das der Default - aNewVclFont = ImplCreateFont( aFont ); - - // need to add relief and emphasis (they're stored in a VCL-Font, but not in a FontDescriptor - Font aOldVclFont = pGrid->GetControlFont(); - aNewVclFont.SetRelief( aOldVclFont.GetRelief() ); - aNewVclFont.SetEmphasisMark( aOldVclFont.GetEmphasisMark() ); - - // now set it ... - pGrid->SetControlFont( aNewVclFont ); - - // if our row-height property is void (which means "calculate it font-dependent") we have - // to adjust the control's row height - Reference< XPropertySet > xModelSet(getColumns(), UNO_QUERY); - if (xModelSet.is() && ::comphelper::hasProperty(FM_PROP_ROWHEIGHT, xModelSet)) - { - Any aHeight = xModelSet->getPropertyValue(FM_PROP_ROWHEIGHT); - if (!aHeight.hasValue()) - pGrid->SetDataRowHeight(0); - } - - } - } - } - else if ( 0 == PropertyName.compareTo( FM_PROP_BACKGROUNDCOLOR ) ) - { - if ( bVoid ) - { - pGrid->SetControlBackground(); - } - else - { - ::Color aColor( ::comphelper::getINT32(Value) ); - pGrid->SetBackground( aColor ); - pGrid->SetControlBackground( aColor ); - } - } - else if ( 0 == PropertyName.compareTo( FM_PROP_TEXTCOLOR ) ) - { - if ( bVoid ) - { - pGrid->SetControlForeground(); - } - else - { - ::Color aColor( ::comphelper::getINT32(Value) ); - pGrid->SetTextColor( aColor ); - pGrid->SetControlForeground( aColor ); - } - } - else if ( 0 == PropertyName.compareTo( FM_PROP_ROWHEIGHT ) ) - { - sal_Int32 nLogHeight(0); - if (Value >>= nLogHeight) - { - sal_Int32 nHeight = pGrid->LogicToPixel(Point(0,nLogHeight),MAP_10TH_MM).Y(); - // take the zoom factor into account - nHeight = pGrid->CalcZoom(nHeight); - pGrid->SetDataRowHeight(nHeight); - } - else if (bVoid) - pGrid->SetDataRowHeight(0); - } - else if ( 0 == PropertyName.compareTo( FM_PROP_HASNAVIGATION ) ) - { - sal_Bool bValue( sal_True ); - OSL_VERIFY( Value >>= bValue ); - pGrid->EnableNavigationBar( bValue ); - } - else if ( 0 == PropertyName.compareTo( FM_PROP_RECORDMARKER ) ) - { - sal_Bool bValue( sal_True ); - OSL_VERIFY( Value >>= bValue ); - pGrid->EnableHandle( bValue ); - } - else if ( 0 == PropertyName.compareTo( FM_PROP_ENABLED ) ) - { - sal_Bool bValue( sal_True ); - OSL_VERIFY( Value >>= bValue ); - pGrid->EnableHandle( bValue ); - - // Im DesignModus nur das Datenfenster disablen - // Sonst kann das Control nicht mehr konfiguriert werden - if (isDesignMode()) - pGrid->GetDataWindow().Enable( bValue ); - else - pGrid->Enable( bValue ); - } - else - VCLXWindow::setProperty( PropertyName, Value ); -} - -//------------------------------------------------------------------------------ -Reference< XAccessibleContext > FmXGridPeer::CreateAccessibleContext() -{ - Reference< XAccessibleContext > xContext; - - // use the AccessibleContext provided by the VCL window - Window* pGrid = GetWindow(); - if ( pGrid ) - { - Reference< XAccessible > xAcc( pGrid->GetAccessible( sal_True ) ); - if ( xAcc.is() ) - xContext = xAcc->getAccessibleContext(); - // TODO: this has a slight conceptual problem: - // - // We know that the XAccessible and XAccessibleContext implementation of the browse - // box is the same (the class implements both interfaces), which, speaking strictly, - // is bad here (means when a browse box acts as UnoControl): We (the FmXGridPeer) are - // the XAccessible here, and the browse box should be able to provide us an XAccessibleContext, - // but it should _not_ be the XAccessible itself. - // However, as long as no client implementation uses dirty hacks such as querying an - // XAccessibleContext for XAccessible, this should not be a problem. - } - - if ( !xContext.is() ) - xContext = VCLXWindow::CreateAccessibleContext( ); - - return xContext; -} - -//------------------------------------------------------------------------------ -Any FmXGridPeer::getProperty( const ::rtl::OUString& _rPropertyName ) throw( RuntimeException ) -{ - Any aProp; - if (GetWindow()) - { - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - Window* pDataWindow = &pGrid->GetDataWindow(); - - if ( 0 == _rPropertyName.compareTo( FM_PROP_NAME ) ) - { - Font aFont = pDataWindow->GetControlFont(); - aProp <<= ImplCreateFontDescriptor( aFont ); - } - else if ( 0 == _rPropertyName.compareTo( FM_PROP_TEXTCOLOR ) ) - { - aProp <<= (sal_Int32)pDataWindow->GetControlForeground().GetColor(); - } - else if ( 0 == _rPropertyName.compareTo( FM_PROP_BACKGROUNDCOLOR ) ) - { - aProp <<= (sal_Int32)pDataWindow->GetControlBackground().GetColor(); - } - else if ( 0 == _rPropertyName.compareTo( FM_PROP_ROWHEIGHT ) ) - { - sal_Int32 nPixelHeight = pGrid->GetDataRowHeight(); - // take the zoom factor into account - nPixelHeight = pGrid->CalcReverseZoom(nPixelHeight); - aProp <<= (sal_Int32)pGrid->PixelToLogic(Point(0,nPixelHeight),MAP_10TH_MM).Y(); - } - else if ( 0 == _rPropertyName.compareTo( FM_PROP_HASNAVIGATION ) ) - { - sal_Bool bHasNavBar = pGrid->HasNavigationBar(); - aProp <<= (sal_Bool)bHasNavBar; - } - else if ( 0 == _rPropertyName.compareTo( FM_PROP_RECORDMARKER ) ) - { - sal_Bool bHasHandle = pGrid->HasHandle(); - aProp <<= (sal_Bool)bHasHandle; - } - else if ( 0 == _rPropertyName.compareTo( FM_PROP_ENABLED ) ) - { - aProp <<= (sal_Bool)pDataWindow->IsEnabled(); - } - else - aProp = VCLXWindow::getProperty( _rPropertyName ); - } - return aProp; -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::dispose() throw( RuntimeException ) -{ - EventObject aEvt; - aEvt.Source = static_cast< ::cppu::OWeakObject* >(this); - m_aModifyListeners.disposeAndClear(aEvt); - m_aUpdateListeners.disposeAndClear(aEvt); - m_aContainerListeners.disposeAndClear(aEvt); - VCLXWindow::dispose(); - - // release all interceptors - Reference< XDispatchProviderInterceptor > xInterceptor( m_xFirstDispatchInterceptor ); - m_xFirstDispatchInterceptor.clear(); - while ( xInterceptor.is() ) - { - // tell the interceptor it has a new (means no) predecessor - xInterceptor->setMasterDispatchProvider( NULL ); - - // ask for it's successor - Reference< XDispatchProvider > xSlave = xInterceptor->getSlaveDispatchProvider(); - // and give it the new (means no) successoert - xInterceptor->setSlaveDispatchProvider( NULL ); - - // start over with the next chain element - xInterceptor = xInterceptor.query( xSlave ); - } - - DisConnectFromDispatcher(); - setRowSet(Reference< XRowSet > ()); -} - -// XContainer -//------------------------------------------------------------------------------ -void FmXGridPeer::addContainerListener(const Reference< XContainerListener >& l) throw( RuntimeException ) -{ - m_aContainerListeners.addInterface( l ); -} -//------------------------------------------------------------------------------ -void FmXGridPeer::removeContainerListener(const Reference< XContainerListener >& l) throw( RuntimeException ) -{ - m_aContainerListeners.removeInterface( l ); -} - -// ::com::sun::star::data::XDatabaseCursorSupplier -//------------------------------------------------------------------------------ -void FmXGridPeer::startCursorListening() -{ - if (!m_nCursorListening) - { - Reference< XRowSet > xRowSet(m_xCursor, UNO_QUERY); - if (xRowSet.is()) - xRowSet->addRowSetListener(this); - - Reference< XReset > xReset(m_xCursor, UNO_QUERY); - if (xReset.is()) - xReset->addResetListener(this); - - // alle Listener anmelden - Reference< XPropertySet > xSet(m_xCursor, UNO_QUERY); - if (xSet.is()) - { - xSet->addPropertyChangeListener(FM_PROP_ISMODIFIED, this); - xSet->addPropertyChangeListener(FM_PROP_ROWCOUNT, this); - } - } - m_nCursorListening++; -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::stopCursorListening() -{ - if (!--m_nCursorListening) - { - Reference< XRowSet > xRowSet(m_xCursor, UNO_QUERY); - if (xRowSet.is()) - xRowSet->removeRowSetListener(this); - - Reference< XReset > xReset(m_xCursor, UNO_QUERY); - if (xReset.is()) - xReset->removeResetListener(this); - - Reference< XPropertySet > xSet(m_xCursor, UNO_QUERY); - if (xSet.is()) - { - xSet->removePropertyChangeListener(FM_PROP_ISMODIFIED, this); - xSet->removePropertyChangeListener(FM_PROP_ROWCOUNT, this); - } - } -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::updateGrid(const Reference< XRowSet >& _rxCursor) -{ - FmGridControl* pGrid = (FmGridControl*)GetWindow(); - if (pGrid) - pGrid->setDataSource(_rxCursor); -} - -//------------------------------------------------------------------------------ -Reference< XRowSet > FmXGridPeer::getRowSet() throw( RuntimeException ) -{ - return m_xCursor; -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::setRowSet(const Reference< XRowSet >& _rDatabaseCursor) throw( RuntimeException ) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - if (!pGrid || !m_xColumns.is() || !m_xColumns->getCount()) - return; - // alle Listener abmelden - if (m_xCursor.is()) - { - Reference< XLoadable > xLoadable(m_xCursor, UNO_QUERY); - // only if the form is loaded we set the rowset - if (xLoadable.is()) - { - stopCursorListening(); - xLoadable->removeLoadListener(this); - } - } - - m_xCursor = _rDatabaseCursor; - - if (pGrid) - { - Reference< XLoadable > xLoadable(m_xCursor, UNO_QUERY); - // only if the form is loaded we set the rowset - if (xLoadable.is() && xLoadable->isLoaded()) - pGrid->setDataSource(m_xCursor); - else - pGrid->setDataSource(Reference< XRowSet > ()); - - if (xLoadable.is()) - { - startCursorListening(); - xLoadable->addLoadListener(this); - } - } -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridPeer::addGridControlListener( const Reference< XGridControlListener >& _listener ) throw( RuntimeException ) -{ - m_aGridControlListeners.addInterface( _listener ); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridPeer::removeGridControlListener( const Reference< XGridControlListener >& _listener ) throw( RuntimeException ) -{ - m_aGridControlListeners.removeInterface( _listener ); -} - -//------------------------------------------------------------------------------ -sal_Int16 FmXGridPeer::getCurrentColumnPosition() throw( RuntimeException ) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - return pGrid ? pGrid->GetViewColumnPos(pGrid->GetCurColumnId()) : -1; -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::setCurrentColumnPosition(sal_Int16 nPos) throw( RuntimeException ) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - if (pGrid) - pGrid->GoToColumnId(pGrid->GetColumnIdFromViewPos(nPos)); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::selectionChanged(const EventObject& evt) throw( RuntimeException ) -{ - SolarMutexGuard aGuard; - - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - if (pGrid) - { - Reference< ::com::sun::star::view::XSelectionSupplier > xSelSupplier(evt.Source, UNO_QUERY); - Any aSelection = xSelSupplier->getSelection(); - DBG_ASSERT(aSelection.getValueType().getTypeClass() == TypeClass_INTERFACE, "FmXGridPeer::selectionChanged : invalid selection !"); - Reference< XPropertySet > xSelection; - aSelection >>= xSelection; - if (xSelection.is()) - { - Reference< XPropertySet > xCol; - sal_Int32 i = 0; - sal_Int32 nColCount = m_xColumns->getCount(); - - for (; i < nColCount; ++i) - { - m_xColumns->getByIndex(i) >>= xCol; - if ( xCol == xSelection ) - { - pGrid->markColumn(pGrid->GetColumnIdFromModelPos((sal_uInt16)i)); - break; - } - } - // fuer das VCL-Control muessen die Columns 1-basiert sein - // die Selektion an das VCL-Control weiterreichen, wenn noetig - if ( i != pGrid->GetSelectedColumn() ) - { // (wenn das nicht greift, wurde das selectionChanged implizit von dem Control selber ausgeloest - if ( i < nColCount ) - { - pGrid->SelectColumnPos(pGrid->GetViewColumnPos(pGrid->GetColumnIdFromModelPos( (sal_uInt16)i )) + 1, sal_True); - // SelectColumnPos hat wieder zu einem impliziten ActivateCell gefuehrt - if (pGrid->IsEditing()) - pGrid->DeactivateCell(); - } - else - pGrid->SetNoSelection(); - } - } - else - pGrid->markColumn(USHRT_MAX); - } -} - -// XElementAccess -//------------------------------------------------------------------------------ -sal_Bool FmXGridPeer::hasElements() throw( RuntimeException ) -{ - return getCount() != 0; -} - -//------------------------------------------------------------------------------ -Type SAL_CALL FmXGridPeer::getElementType( ) throw(RuntimeException) -{ - return ::getCppuType((Reference< ::com::sun::star::awt::XControl> *)NULL); -} - -// XEnumerationAccess -//------------------------------------------------------------------------------ -Reference< XEnumeration > FmXGridPeer::createEnumeration() throw( RuntimeException ) -{ - return new ::comphelper::OEnumerationByIndex(this); -} - -// XIndexAccess -//------------------------------------------------------------------------------ -sal_Int32 FmXGridPeer::getCount() throw( RuntimeException ) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - if (pGrid) - return pGrid->GetViewColCount(); - else - return 0; -} - -//------------------------------------------------------------------------------ -Any FmXGridPeer::getByIndex(sal_Int32 _nIndex) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - if (_nIndex < 0 || - _nIndex >= getCount() || !pGrid) - throw IndexOutOfBoundsException(); - - Any aElement; - // get the columnid - sal_uInt16 nId = pGrid->GetColumnIdFromViewPos((sal_uInt16)_nIndex); - // get the list position - sal_uInt16 nPos = pGrid->GetModelColumnPos(nId); - - DbGridColumn* pCol = pGrid->GetColumns().at( nPos ); - Reference< ::com::sun::star::awt::XControl > xControl(pCol->GetCell()); - aElement <<= xControl; - - return aElement; -} - -// ::com::sun::star::util::XModeSelector -//------------------------------------------------------------------------------ -void FmXGridPeer::setMode(const ::rtl::OUString& Mode) throw( NoSupportException, RuntimeException ) -{ - if (!supportsMode(Mode)) - throw NoSupportException(); - - if (Mode == m_aMode) - return; - - m_aMode = Mode; - - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - if ( Mode == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterMode" ) ) ) - pGrid->SetFilterMode(sal_True); - else - { - pGrid->SetFilterMode(sal_False); - pGrid->setDataSource(m_xCursor); - } -} - -//------------------------------------------------------------------------------ -::rtl::OUString FmXGridPeer::getMode() throw( RuntimeException ) -{ - return m_aMode; -} - -//------------------------------------------------------------------------------ -::comphelper::StringSequence FmXGridPeer::getSupportedModes() throw( RuntimeException ) -{ - static ::comphelper::StringSequence aModes; - if (!aModes.getLength()) - { - aModes.realloc(2); - ::rtl::OUString* pModes = aModes.getArray(); - pModes[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DataMode" ) ); - pModes[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterMode" ) ); - } - return aModes; -} - -//------------------------------------------------------------------------------ -sal_Bool FmXGridPeer::supportsMode(const ::rtl::OUString& Mode) throw( RuntimeException ) -{ - ::comphelper::StringSequence aModes(getSupportedModes()); - const ::rtl::OUString* pModes = aModes.getConstArray(); - for (sal_Int32 i = aModes.getLength(); i > 0; ) - { - if (pModes[--i] == Mode) - return sal_True; - } - return sal_False; -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::columnVisible(DbGridColumn* pColumn) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - - sal_Int32 _nIndex = pGrid->GetModelColumnPos(pColumn->GetId()); - Reference< ::com::sun::star::awt::XControl > xControl(pColumn->GetCell()); - ContainerEvent aEvt; - aEvt.Source = (XContainer*)this; - aEvt.Accessor <<= _nIndex; - aEvt.Element <<= xControl; - - m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvt ); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::columnHidden(DbGridColumn* pColumn) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - - sal_Int32 _nIndex = pGrid->GetModelColumnPos(pColumn->GetId()); - Reference< ::com::sun::star::awt::XControl > xControl(pColumn->GetCell()); - ContainerEvent aEvt; - aEvt.Source = (XContainer*)this; - aEvt.Accessor <<= _nIndex; - aEvt.Element <<= xControl; - - m_aContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvt ); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::draw( sal_Int32 x, sal_Int32 y ) throw( RuntimeException ) -{ - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - sal_Int32 nOldFlags = pGrid->GetBrowserFlags(); - pGrid->SetBrowserFlags(nOldFlags | EBBF_NOROWPICTURE); - - VCLXWindow::draw(x, y); - - pGrid->SetBrowserFlags(nOldFlags); -} - -//------------------------------------------------------------------------------ -Reference< ::com::sun::star::frame::XDispatch > FmXGridPeer::queryDispatch(const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException ) -{ - Reference< ::com::sun::star::frame::XDispatch > xResult; - - // first ask our interceptor chain - if (m_xFirstDispatchInterceptor.is() && !m_bInterceptingDispatch) - { - m_bInterceptingDispatch = sal_True; - // safety against recursion : as we are master of the first chain element and slave of the last one we would - // have an infinite loop without this if no dispatcher can fullfill the rewuest) - xResult = m_xFirstDispatchInterceptor->queryDispatch(aURL, aTargetFrameName, nSearchFlags); - m_bInterceptingDispatch = sal_False; - } - - // then ask ourself : we don't have any dispatches - return xResult; -} - -//------------------------------------------------------------------------------ -Sequence< Reference< ::com::sun::star::frame::XDispatch > > FmXGridPeer::queryDispatches(const Sequence< ::com::sun::star::frame::DispatchDescriptor>& aDescripts) throw( RuntimeException ) -{ - if (m_xFirstDispatchInterceptor.is()) - return m_xFirstDispatchInterceptor->queryDispatches(aDescripts); - - // then ask ourself : we don't have any dispatches - return Sequence< Reference< ::com::sun::star::frame::XDispatch > >(); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::registerDispatchProviderInterceptor(const Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& _xInterceptor) throw( RuntimeException ) -{ - if (_xInterceptor.is()) - { - if (m_xFirstDispatchInterceptor.is()) - { - Reference< ::com::sun::star::frame::XDispatchProvider > xFirstProvider(m_xFirstDispatchInterceptor, UNO_QUERY); - // there is already an interceptor; the new one will become its master - _xInterceptor->setSlaveDispatchProvider(xFirstProvider); - m_xFirstDispatchInterceptor->setMasterDispatchProvider(xFirstProvider); - } - else - { - // it is the first interceptor; set ourself as slave - _xInterceptor->setSlaveDispatchProvider((::com::sun::star::frame::XDispatchProvider*)this); - } - - // we are the master of the chain's first interceptor - m_xFirstDispatchInterceptor = _xInterceptor; - m_xFirstDispatchInterceptor->setMasterDispatchProvider((::com::sun::star::frame::XDispatchProvider*)this); - - // we have a new interceptor and we're alive ? - if (!isDesignMode()) - // -> check for new dispatchers - UpdateDispatches(); - } -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::releaseDispatchProviderInterceptor(const Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& _xInterceptor) throw( RuntimeException ) -{ - if (!_xInterceptor.is()) - return; - - Reference< ::com::sun::star::frame::XDispatchProviderInterceptor > xChainWalk(m_xFirstDispatchInterceptor); - - if (m_xFirstDispatchInterceptor == _xInterceptor) - { // our chain will have a new first element - Reference< ::com::sun::star::frame::XDispatchProviderInterceptor > xSlave(m_xFirstDispatchInterceptor->getSlaveDispatchProvider(), UNO_QUERY); - m_xFirstDispatchInterceptor = xSlave; - } - // do this before removing the interceptor from the chain as we won't know it's slave afterwards) - - while (xChainWalk.is()) - { - // walk along the chain of interceptors and look for the interceptor that has to be removed - Reference< ::com::sun::star::frame::XDispatchProviderInterceptor > xSlave(xChainWalk->getSlaveDispatchProvider(), UNO_QUERY); - - if (xChainWalk == _xInterceptor) - { - // old master may be an interceptor too - Reference< ::com::sun::star::frame::XDispatchProviderInterceptor > xMaster(xChainWalk->getMasterDispatchProvider(), UNO_QUERY); - - // unchain the interceptor that has to be removed - xChainWalk->setSlaveDispatchProvider(Reference< ::com::sun::star::frame::XDispatchProvider > ()); - xChainWalk->setMasterDispatchProvider(Reference< ::com::sun::star::frame::XDispatchProvider > ()); - - // reconnect the chain - if (xMaster.is()) - { - if (xSlave.is()) - xMaster->setSlaveDispatchProvider(Reference< ::com::sun::star::frame::XDispatchProvider >::query(xSlave)); - else - // it's the first interceptor of the chain, set ourself as slave - xMaster->setSlaveDispatchProvider((::com::sun::star::frame::XDispatchProvider*)this); - } - else - { - // the chain's first element was removed, set ourself as new master of the second one - if (xSlave.is()) - xSlave->setMasterDispatchProvider((::com::sun::star::frame::XDispatchProvider*)this); - } - } - - xChainWalk = xSlave; - } - // our interceptor chain has changed and we're alive ? - if (!isDesignMode()) - // -> check the dispatchers - UpdateDispatches(); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::statusChanged(const ::com::sun::star::frame::FeatureStateEvent& Event) throw( RuntimeException ) -{ - DBG_ASSERT(m_pStateCache, "FmXGridPeer::statusChanged : invalid call !"); - DBG_ASSERT(m_pDispatchers, "FmXGridPeer::statusChanged : invalid call !"); - - Sequence< ::com::sun::star::util::URL>& aUrls = getSupportedURLs(); - const ::com::sun::star::util::URL* pUrls = aUrls.getConstArray(); - - Sequence<sal_uInt16> aSlots = getSupportedGridSlots(); - const sal_uInt16* pSlots = aSlots.getConstArray(); - - sal_uInt16 i; - for (i=0; i<aUrls.getLength(); ++i, ++pUrls, ++pSlots) - { - if (pUrls->Main == Event.FeatureURL.Main) - { - DBG_ASSERT(m_pDispatchers[i] == Event.Source, "FmXGridPeer::statusChanged : the event source is a little bit suspect !"); - m_pStateCache[i] = Event.IsEnabled; - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - if (*pSlots != SID_FM_RECORD_UNDO) - pGrid->GetNavigationBar().InvalidateState(*pSlots); - break; - } - } - DBG_ASSERT(i<aUrls.getLength(), "FmXGridPeer::statusChanged : got a call for an unknown url !"); -} - -//------------------------------------------------------------------------------ -sal_Bool FmXGridPeer::approveReset(const EventObject& /*rEvent*/) throw( RuntimeException ) -{ - return sal_True; -} - -//------------------------------------------------------------------------------ -sal_Bool SAL_CALL FmXGridPeer::select( const Any& _rSelection ) throw (IllegalArgumentException, RuntimeException) -{ - Sequence< Any > aBookmarks; - if ( !( _rSelection >>= aBookmarks ) ) - throw IllegalArgumentException(); - - FmGridControl* pVclControl = static_cast<FmGridControl*>(GetWindow()); - return pVclControl->selectBookmarks(aBookmarks); - - // TODO: - // speaking strictly, we would have to adjust our model, as our ColumnSelection may have changed. - // Our model is a XSelectionSupplier, too, it handles the selection of single columns. - // This is somewhat strange, as selection should be a view (not a model) aspect. - // So for a clean solution, we should handle column selection ourself, and the model shouldn't - // deal with selection at all. -} - -//------------------------------------------------------------------------------ -Any SAL_CALL FmXGridPeer::getSelection( ) throw (RuntimeException) -{ - FmGridControl* pVclControl = static_cast<FmGridControl*>(GetWindow()); - Sequence< Any > aSelectionBookmarks = pVclControl->getSelectionBookmarks(); - return makeAny(aSelectionBookmarks); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridPeer::addSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException) -{ - m_aSelectionListeners.addInterface( _rxListener ); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXGridPeer::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException) -{ - m_aSelectionListeners.removeInterface( _rxListener ); -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::resetted(const EventObject& rEvent) throw( RuntimeException ) -{ - if (m_xColumns == rEvent.Source) - { // my model was reset -> refresh the grid content - FmGridControl* pGrid = (FmGridControl*)GetWindow(); - if (!pGrid) - return; - SolarMutexGuard aGuard; - pGrid->resetCurrentRow(); - } - // if the cursor fired a reset event we seem to be on the insert row - else if (m_xCursor == rEvent.Source) - { - SolarMutexGuard aGuard; - FmGridControl* pGrid = (FmGridControl*) GetWindow(); - if (pGrid && pGrid->IsOpen()) - pGrid->positioned(rEvent); - } -} - -//------------------------------------------------------------------------------ -Sequence<sal_uInt16>& FmXGridPeer::getSupportedGridSlots() -{ - static Sequence<sal_uInt16> aSupported; - if (aSupported.getLength() == 0) - { - sal_uInt16 nSupported[] = { - DbGridControl::NavigationBar::RECORD_FIRST, - DbGridControl::NavigationBar::RECORD_PREV, - DbGridControl::NavigationBar::RECORD_NEXT, - DbGridControl::NavigationBar::RECORD_LAST, - DbGridControl::NavigationBar::RECORD_NEW, - SID_FM_RECORD_UNDO - }; - aSupported.realloc(SAL_N_ELEMENTS(nSupported)); - sal_uInt16* pSupported = aSupported.getArray(); - for (sal_uInt16 i=0; i<aSupported.getLength(); ++i, ++pSupported) - *pSupported = nSupported[i]; - } - return aSupported; -} - -//------------------------------------------------------------------------------ -Sequence< ::com::sun::star::util::URL>& FmXGridPeer::getSupportedURLs() -{ - static Sequence< ::com::sun::star::util::URL> aSupported; - if (aSupported.getLength() == 0) - { - static ::rtl::OUString sSupported[] = { - FMURL_RECORD_MOVEFIRST, - FMURL_RECORD_MOVEPREV, - FMURL_RECORD_MOVENEXT, - FMURL_RECORD_MOVELAST, - FMURL_RECORD_MOVETONEW, - FMURL_RECORD_UNDO - }; - aSupported.realloc(SAL_N_ELEMENTS(sSupported)); - ::com::sun::star::util::URL* pSupported = aSupported.getArray(); - sal_uInt16 i; - - for ( i = 0; i < aSupported.getLength(); ++i, ++pSupported) - pSupported->Complete = sSupported[i]; - - // let an ::com::sun::star::util::URL-transformer normalize the URLs - Reference< ::com::sun::star::util::XURLTransformer > xTransformer( - ::comphelper::getProcessServiceFactory()->createInstance( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer"))), - UNO_QUERY); - pSupported = aSupported.getArray(); - if (xTransformer.is()) - { - for (i=0; i<aSupported.getLength(); ++i) - xTransformer->parseStrict(pSupported[i]); - } - } - - return aSupported; -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::UpdateDispatches() -{ - if (!m_pStateCache) - { // we don't have any dispatchers yet -> do the initial connect - ConnectToDispatcher(); - return; - } - - sal_uInt16 nDispatchersGot = 0; - const Sequence< ::com::sun::star::util::URL>& aSupportedURLs = getSupportedURLs(); - const ::com::sun::star::util::URL* pSupportedURLs = aSupportedURLs.getConstArray(); - Reference< ::com::sun::star::frame::XDispatch > xNewDispatch; - for (sal_uInt16 i=0; i<aSupportedURLs.getLength(); ++i, ++pSupportedURLs) - { - xNewDispatch = queryDispatch(*pSupportedURLs, rtl::OUString(), 0); - if (xNewDispatch != m_pDispatchers[i]) - { - if (m_pDispatchers[i].is()) - m_pDispatchers[i]->removeStatusListener((::com::sun::star::frame::XStatusListener*)this, *pSupportedURLs); - m_pDispatchers[i] = xNewDispatch; - if (m_pDispatchers[i].is()) - m_pDispatchers[i]->addStatusListener((::com::sun::star::frame::XStatusListener*)this, *pSupportedURLs); - } - if (m_pDispatchers[i].is()) - ++nDispatchersGot; - } - - if (!nDispatchersGot) - { - delete[] m_pStateCache; - delete[] m_pDispatchers; - m_pStateCache = NULL; - m_pDispatchers = NULL; - } -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::ConnectToDispatcher() -{ - DBG_ASSERT((m_pStateCache != NULL) == (m_pDispatchers != NULL), "FmXGridPeer::ConnectToDispatcher : inconsistent !"); - if (m_pStateCache) - { // already connected -> just do an update - UpdateDispatches(); - return; - } - - const Sequence< ::com::sun::star::util::URL>& aSupportedURLs = getSupportedURLs(); - - // _before_ adding the status listeners (as the add should result in a statusChanged-call) ! - m_pStateCache = new sal_Bool[aSupportedURLs.getLength()]; - m_pDispatchers = new Reference< ::com::sun::star::frame::XDispatch > [aSupportedURLs.getLength()]; - - sal_uInt16 nDispatchersGot = 0; - const ::com::sun::star::util::URL* pSupportedURLs = aSupportedURLs.getConstArray(); - for (sal_uInt16 i=0; i<aSupportedURLs.getLength(); ++i, ++pSupportedURLs) - { - m_pStateCache[i] = 0; - m_pDispatchers[i] = queryDispatch(*pSupportedURLs, rtl::OUString(), 0); - if (m_pDispatchers[i].is()) - { - m_pDispatchers[i]->addStatusListener((::com::sun::star::frame::XStatusListener*)this, *pSupportedURLs); - ++nDispatchersGot; - } - } - - if (!nDispatchersGot) - { - delete[] m_pStateCache; - delete[] m_pDispatchers; - m_pStateCache = NULL; - m_pDispatchers = NULL; - } -} - -//------------------------------------------------------------------------------ -void FmXGridPeer::DisConnectFromDispatcher() -{ - if (!m_pStateCache || !m_pDispatchers) - return; - // we're not connected - - const Sequence< ::com::sun::star::util::URL>& aSupportedURLs = getSupportedURLs(); - const ::com::sun::star::util::URL* pSupportedURLs = aSupportedURLs.getConstArray(); - for (sal_uInt16 i=0; i<aSupportedURLs.getLength(); ++i, ++pSupportedURLs) - { - if (m_pDispatchers[i].is()) - m_pDispatchers[i]->removeStatusListener((::com::sun::star::frame::XStatusListener*)this, *pSupportedURLs); - } - - delete[] m_pStateCache; - delete[] m_pDispatchers; - m_pStateCache = NULL; - m_pDispatchers = NULL; -} - -//------------------------------------------------------------------------------ -IMPL_LINK(FmXGridPeer, OnQueryGridSlotState, void*, pSlot) -{ - if (!m_pStateCache) - return -1; // unspecified - - sal_uInt16 nSlot = (sal_uInt16)(sal_uIntPtr)pSlot; - - // search the given slot with our supported sequence - Sequence<sal_uInt16>& aSupported = getSupportedGridSlots(); - const sal_uInt16* pSlots = aSupported.getConstArray(); - for (sal_uInt16 i=0; i<aSupported.getLength(); ++i) - { - if (pSlots[i] == nSlot) - { - if (!m_pDispatchers[i].is()) - return -1; // nothing known about this slot - else - return m_pStateCache[i]; - } - } - - return -1; -} - -//------------------------------------------------------------------------------ -IMPL_LINK(FmXGridPeer, OnExecuteGridSlot, void*, pSlot) -{ - if (!m_pDispatchers) - return 0; // not handled - - Sequence< ::com::sun::star::util::URL>& aUrls = getSupportedURLs(); - const ::com::sun::star::util::URL* pUrls = aUrls.getConstArray(); - - Sequence<sal_uInt16> aSlots = getSupportedGridSlots(); - const sal_uInt16* pSlots = aSlots.getConstArray(); - - DBG_ASSERT(aSlots.getLength() == aUrls.getLength(), "FmXGridPeer::OnExecuteGridSlot : inconstent data returned by getSupportedURLs/getSupportedGridSlots !"); - - sal_uInt16 nSlot = (sal_uInt16)(sal_uIntPtr)pSlot; - for (sal_uInt16 i=0; i<aSlots.getLength(); ++i, ++pUrls, ++pSlots) - { - if (*pSlots == nSlot) - { - if (m_pDispatchers[i].is()) - { - // commit any changes done so far, if it's not the undoRecord URL - if ( 0 == pUrls->Complete.compareTo( FMURL_RECORD_UNDO ) || commit() ) - m_pDispatchers[i]->dispatch(*pUrls, Sequence< PropertyValue>()); - - return 1; // handled - } - } - } - - return 0; // not handled -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/fmcomp/gridcell.cxx b/svx/source/fmcomp/gridcell.cxx deleted file mode 100644 index 60229811ae..0000000000 --- a/svx/source/fmcomp/gridcell.cxx +++ /dev/null @@ -1,4838 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svx.hxx" - -#include <sal/macros.h> -#include "fmprop.hrc" -#include "svx/fmresids.hrc" -#include "svx/fmtools.hxx" -#include "gridcell.hxx" -#include "gridcols.hxx" -#include "sdbdatacolumn.hxx" - -#include <com/sun/star/awt/LineEndFormat.hpp> -#include <com/sun/star/awt/MouseWheelBehavior.hpp> -#include <com/sun/star/awt/VisualEffect.hpp> -#include <com/sun/star/container/XChild.hpp> -#include <com/sun/star/container/XNamed.hpp> -#include <com/sun/star/form/FormComponentType.hpp> -#include <com/sun/star/form/XBoundComponent.hpp> -#include <com/sun/star/script/XEventAttacherManager.hpp> -#include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> -#include <com/sun/star/sdbcx/XTablesSupplier.hpp> -#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> -#include <com/sun/star/sdbc/ColumnValue.hpp> -#include <com/sun/star/sdbc/DataType.hpp> -#include <com/sun/star/sdbc/XStatement.hpp> -#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> -#include <com/sun/star/util/NumberFormat.hpp> -#include <com/sun/star/util/XNumberFormatsSupplier.hpp> -#include <com/sun/star/util/XNumberFormatter.hpp> - -#include <comphelper/extract.hxx> -#include <comphelper/numbers.hxx> -#include <comphelper/property.hxx> -#include <comphelper/servicehelper.hxx> -#include <connectivity/formattedcolumnvalue.hxx> -#include <cppuhelper/typeprovider.hxx> -#include <i18npool/lang.h> - -#include <rtl/math.hxx> -#include <svtools/calendar.hxx> -#include <svtools/fmtfield.hxx> -#include <svl/numuno.hxx> -#include <svtools/svmedit.hxx> -#include <svx/dialmgr.hxx> -#include <toolkit/helper/vclunohelper.hxx> -#include <tools/diagnose_ex.h> -#include <tools/shl.hxx> -#include <vcl/longcurr.hxx> - -#include <math.h> -#include <stdio.h> - -using namespace ::connectivity; -using namespace ::connectivity::simple; -using namespace ::svxform; -using namespace ::comphelper; -using namespace ::svt; -using namespace ::com::sun::star; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdb; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::form; - -using ::com::sun::star::util::XNumberFormatter; -namespace MouseWheelBehavior = ::com::sun::star::awt::MouseWheelBehavior; - -String INVALIDTEXT = String::CreateFromAscii("###"); -String OBJECTTEXT = String::CreateFromAscii("<OBJECT>"); - // TODO: resource - -//================================================================== -//= helper -//================================================================== -namespace -{ - static LineEnd getModelLineEndSetting( const Reference< XPropertySet >& _rxModel ) - { - LineEnd eFormat = LINEEND_LF; - - try - { - sal_Int16 nLineEndFormat = awt::LineEndFormat::LINE_FEED; - - Reference< XPropertySetInfo > xPSI; - if ( _rxModel.is() ) - xPSI = _rxModel->getPropertySetInfo(); - - OSL_ENSURE( xPSI.is(), "getModelLineEndSetting: invalid column model!" ); - if ( xPSI.is() && xPSI->hasPropertyByName( FM_PROP_LINEENDFORMAT ) ) - { - OSL_VERIFY( _rxModel->getPropertyValue( FM_PROP_LINEENDFORMAT ) >>= nLineEndFormat ); - - switch ( nLineEndFormat ) - { - case awt::LineEndFormat::CARRIAGE_RETURN: eFormat = LINEEND_CR; break; - case awt::LineEndFormat::LINE_FEED: eFormat = LINEEND_LF; break; - case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED: eFormat = LINEEND_CRLF; break; - default: - OSL_FAIL( "getModelLineEndSetting: what's this?" ); - } - } - } - catch( const Exception& ) - { - OSL_FAIL( "getModelLineEndSetting: caught an exception!" ); - } - return eFormat; - } -} - -//================================================================== -//= DbGridColumn -//================================================================== -//------------------------------------------------------------------------------ -CellControllerRef DbGridColumn::s_xEmptyController; - -//------------------------------------------------------------------------------ -void DbGridColumn::CreateControl(sal_Int32 _nFieldPos, const Reference< ::com::sun::star::beans::XPropertySet >& xField, sal_Int32 nTypeId) -{ - Clear(); - - m_nTypeId = (sal_Int16)nTypeId; - if (xField != m_xField) - { - // Grundeinstellung - m_xField = xField; - xField->getPropertyValue(FM_PROP_FORMATKEY) >>= m_nFormatKey; - m_nFieldPos = (sal_Int16)_nFieldPos; - m_bReadOnly = ::comphelper::getBOOL(xField->getPropertyValue(FM_PROP_ISREADONLY)); - m_bAutoValue = ::comphelper::getBOOL(xField->getPropertyValue(FM_PROP_AUTOINCREMENT)); - m_nFieldType = (sal_Int16)::comphelper::getINT32(xField->getPropertyValue(FM_PROP_FIELDTYPE)); - - switch (m_nFieldType) - { - case DataType::DATE: - case DataType::TIME: - case DataType::TIMESTAMP: - m_bDateTime = sal_True; - - case DataType::BIT: - case DataType::BOOLEAN: - case DataType::TINYINT: - case DataType::SMALLINT: - case DataType::INTEGER: - case DataType::BIGINT: - case DataType::FLOAT: - case DataType::REAL: - case DataType::DOUBLE: - case DataType::NUMERIC: - case DataType::DECIMAL: - m_nAlign = ::com::sun::star::awt::TextAlign::RIGHT; - m_bNumeric = sal_True; - break; - default: - m_nAlign = ::com::sun::star::awt::TextAlign::LEFT; - break; - } - } - - DbCellControl* pCellControl = NULL; - if (m_rParent.IsFilterMode()) - { - pCellControl = new DbFilterField(m_rParent.getServiceManager(),*this); - } - else - { - - switch (nTypeId) - { - case TYPE_CHECKBOX: pCellControl = new DbCheckBox(*this); break; - case TYPE_COMBOBOX: pCellControl = new DbComboBox(*this); break; - case TYPE_CURRENCYFIELD: pCellControl = new DbCurrencyField(*this); break; - case TYPE_DATEFIELD: pCellControl = new DbDateField(*this); break; - case TYPE_LISTBOX: pCellControl = new DbListBox(*this); break; - case TYPE_NUMERICFIELD: pCellControl = new DbNumericField(*this); break; - case TYPE_PATTERNFIELD: pCellControl = new DbPatternField( *this, ::comphelper::ComponentContext( m_rParent.getServiceManager() ) ); break; - case TYPE_TEXTFIELD: pCellControl = new DbTextField(*this); break; - case TYPE_TIMEFIELD: pCellControl = new DbTimeField(*this); break; - case TYPE_FORMATTEDFIELD: pCellControl = new DbFormattedField(*this); break; - default: - OSL_FAIL("DbGridColumn::CreateControl: Unknown Column"); - return; - } - - } - Reference< XRowSet > xCur; - if (m_rParent.getDataSource()) - xCur = Reference< XRowSet > ((Reference< XInterface >)*m_rParent.getDataSource(), UNO_QUERY); - // TODO : the cursor wrapper should use an XRowSet interface, too - - pCellControl->Init( m_rParent.GetDataWindow(), xCur ); - - // now create the control wrapper - if (m_rParent.IsFilterMode()) - m_pCell = new FmXFilterCell(this, pCellControl); - else - { - switch (nTypeId) - { - case TYPE_CHECKBOX: m_pCell = new FmXCheckBoxCell( this, *pCellControl ); break; - case TYPE_LISTBOX: m_pCell = new FmXListBoxCell( this, *pCellControl ); break; - case TYPE_COMBOBOX: m_pCell = new FmXComboBoxCell( this, *pCellControl ); break; - default: - m_pCell = new FmXEditCell( this, *pCellControl ); - } - } - m_pCell->acquire(); - m_pCell->init(); - - impl_toggleScriptManager_nothrow( true ); - - // only if we use have a bound field, we use a a controller for displaying the - // window in the grid - if (m_xField.is()) - m_xController = pCellControl->CreateController(); -} - -//------------------------------------------------------------------------------ -void DbGridColumn::impl_toggleScriptManager_nothrow( bool _bAttach ) -{ - try - { - Reference< container::XChild > xChild( m_xModel, UNO_QUERY_THROW ); - Reference< script::XEventAttacherManager > xManager( xChild->getParent(), UNO_QUERY_THROW ); - Reference< container::XIndexAccess > xContainer( xChild->getParent(), UNO_QUERY_THROW ); - - sal_Int32 nIndexInParent( getElementPos( xContainer, m_xModel ) ); - - Reference< XInterface > xCellInterface( *m_pCell, UNO_QUERY ); - if ( _bAttach ) - xManager->attach( nIndexInParent, xCellInterface, makeAny( xCellInterface ) ); - else - xManager->detach( nIndexInParent, xCellInterface ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } -} - -//------------------------------------------------------------------------------ -void DbGridColumn::UpdateFromField(const DbGridRow* pRow, const Reference< XNumberFormatter >& xFormatter) -{ - if (m_pCell && m_pCell->ISA(FmXFilterCell)) - PTR_CAST(FmXFilterCell, m_pCell)->Update(); - else if (pRow && pRow->IsValid() && m_nFieldPos >= 0 && m_pCell && pRow->HasField(m_nFieldPos)) - { - PTR_CAST(FmXDataCell, m_pCell)->UpdateFromField( pRow->GetField( m_nFieldPos ).getColumn(), xFormatter ); - } -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridColumn::Commit() -{ - sal_Bool bResult = sal_True; - if (!m_bInSave && m_pCell) - { - m_bInSave = sal_True; - bResult = m_pCell->Commit(); - - // store the data into the model - FmXDataCell* pDataCell = PTR_CAST(FmXDataCell, m_pCell); - if (bResult && pDataCell) - { - Reference< ::com::sun::star::form::XBoundComponent > xComp(m_xModel, UNO_QUERY); - if (xComp.is()) - bResult = xComp->commit(); - } - m_bInSave = sal_False; - } - return bResult; -} - -//------------------------------------------------------------------------------ -DbGridColumn::~DbGridColumn() -{ - Clear(); -} - -//------------------------------------------------------------------------------ -void DbGridColumn::setModel(::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > _xModel) -{ - if ( m_pCell ) - impl_toggleScriptManager_nothrow( false ); - - m_xModel = _xModel; - - if ( m_pCell ) - impl_toggleScriptManager_nothrow( true ); -} - -//------------------------------------------------------------------------------ -void DbGridColumn::Clear() -{ - if ( m_pCell ) - { - impl_toggleScriptManager_nothrow( false ); - - m_pCell->dispose(); - m_pCell->release(); - m_pCell = NULL; - } - - m_xController = NULL; - m_xField = NULL; - - m_nFormatKey = 0; - m_nFieldPos = -1; - m_bReadOnly = sal_True; - m_bAutoValue = sal_False; - m_nFieldType = DataType::OTHER; -} - -//------------------------------------------------------------------------------ -sal_Int16 DbGridColumn::SetAlignment(sal_Int16 _nAlign) -{ - if (_nAlign == -1) - { // 'Standard' - if (m_xField.is()) - { - sal_Int32 nType = 0; - m_xField->getPropertyValue(FM_PROP_FIELDTYPE) >>= nType; - - switch (nType) - { - case DataType::NUMERIC: - case DataType::DECIMAL: - case DataType::DOUBLE: - case DataType::REAL: - case DataType::BIGINT: - case DataType::INTEGER: - case DataType::SMALLINT: - case DataType::TINYINT: - case DataType::DATE: - case DataType::TIME: - case DataType::TIMESTAMP: - _nAlign = ::com::sun::star::awt::TextAlign::RIGHT; - break; - case DataType::BIT: - case DataType::BOOLEAN: - _nAlign = ::com::sun::star::awt::TextAlign::CENTER; - break; - default: - _nAlign = ::com::sun::star::awt::TextAlign::LEFT; - break; - } - } - else - _nAlign = ::com::sun::star::awt::TextAlign::LEFT; - } - - m_nAlign = _nAlign; - if (m_pCell && m_pCell->isAlignedController()) - m_pCell->AlignControl(m_nAlign); - - return m_nAlign; -} - -//------------------------------------------------------------------------------ -sal_Int16 DbGridColumn::SetAlignmentFromModel(sal_Int16 nStandardAlign) -{ - Any aAlign( m_xModel->getPropertyValue(FM_PROP_ALIGN)); - if (aAlign.hasValue()) - { - sal_Int16 nTest = sal_Int16(); - if (aAlign >>= nTest) - nStandardAlign = nTest; - } - return SetAlignment(nStandardAlign); -} - -//------------------------------------------------------------------------------ -void DbGridColumn::setLock(sal_Bool _bLock) -{ - if (m_bLocked == _bLock) - return; - m_bLocked = _bLock; - - // is the column we represent active ? - if (m_bHidden) - return; // no, it isn't (or at least it shouldn't be ...) - - if (m_rParent.GetCurColumnId() == m_nId) - { - m_rParent.DeactivateCell(); - m_rParent.ActivateCell(m_rParent.GetCurRow(), m_rParent.GetCurColumnId()); - } -} - -//------------------------------------------------------------------------------ -String DbGridColumn::GetCellText(const DbGridRow* pRow, const Reference< XNumberFormatter >& xFormatter) const -{ - String aText; - if (m_pCell && m_pCell->ISA(FmXFilterCell)) - return aText; - - if (!pRow || !pRow->IsValid()) - aText = INVALIDTEXT; - else if (pRow->HasField(m_nFieldPos)) - { - aText = GetCellText( pRow->GetField( m_nFieldPos ).getColumn(), xFormatter ); - } - return aText; -} - -//------------------------------------------------------------------------------ -String DbGridColumn::GetCellText(const Reference< ::com::sun::star::sdb::XColumn >& xField, const Reference< XNumberFormatter >& xFormatter) const -{ - String aText; - if (xField.is()) - { - FmXTextCell* pTextCell = PTR_CAST(FmXTextCell, m_pCell); - if (pTextCell) - aText = pTextCell->GetText(xField, xFormatter); - else if (m_bObject) - aText = OBJECTTEXT; - } - return aText; -} - -//------------------------------------------------------------------------------ -Reference< ::com::sun::star::sdb::XColumn > DbGridColumn::GetCurrentFieldValue() const -{ - Reference< ::com::sun::star::sdb::XColumn > xField; - const DbGridRowRef xRow = m_rParent.GetCurrentRow(); - if (xRow.Is() && xRow->HasField(m_nFieldPos)) - { - xField = xRow->GetField(m_nFieldPos).getColumn(); - } - return xField; -} - -//------------------------------------------------------------------------------ -void DbGridColumn::Paint(OutputDevice& rDev, - const Rectangle& rRect, - const DbGridRow* pRow, - const Reference< XNumberFormatter >& xFormatter) -{ - bool bEnabled = ( rDev.GetOutDevType() != OUTDEV_WINDOW ) - || ( static_cast< Window& >( rDev ).IsEnabled() ); - - FmXDataCell* pDataCell = PTR_CAST(FmXDataCell, m_pCell); - if (pDataCell) - { - if (!pRow || !pRow->IsValid()) - { - sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_CENTER; - if ( !bEnabled ) - nStyle |= TEXT_DRAW_DISABLE; - - rDev.DrawText(rRect, INVALIDTEXT, nStyle); - } - else if (m_bAutoValue && pRow->IsNew()) - { - static String aAutoText(SVX_RES(RID_STR_AUTOFIELD)); - sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_VCENTER; - if ( !bEnabled ) - nStyle |= TEXT_DRAW_DISABLE; - - switch (GetAlignment()) - { - case ::com::sun::star::awt::TextAlign::RIGHT: - nStyle |= TEXT_DRAW_RIGHT; - break; - case ::com::sun::star::awt::TextAlign::CENTER: - nStyle |= TEXT_DRAW_CENTER; - break; - default: - nStyle |= TEXT_DRAW_LEFT; - } - - rDev.DrawText(rRect, aAutoText , nStyle); - } - else if (pRow->HasField(m_nFieldPos)) - { - pDataCell->PaintFieldToCell(rDev, rRect, pRow->GetField( m_nFieldPos ).getColumn(), xFormatter); - } - } - else if (!m_pCell) - { - if (!pRow || !pRow->IsValid()) - { - sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_CENTER; - if ( !bEnabled ) - nStyle |= TEXT_DRAW_DISABLE; - - rDev.DrawText(rRect, INVALIDTEXT, nStyle); - } - else if (pRow->HasField(m_nFieldPos) && m_bObject) - { - sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_CENTER; - if ( !bEnabled ) - nStyle |= TEXT_DRAW_DISABLE; - rDev.DrawText(rRect, OBJECTTEXT, nStyle); - } - } - else if ( m_pCell->ISA( FmXFilterCell ) ) - static_cast< FmXFilterCell* >( m_pCell )->PaintCell( rDev, rRect ); -} - -//------------------------------------------------------------------------------ -void DbGridColumn::ImplInitWindow( Window& rParent, const InitWindowFacet _eInitWhat ) -{ - if ( m_pCell ) - m_pCell->ImplInitWindow( rParent, _eInitWhat ); -} - -//============================================================================== -//= cell controls -//============================================================================== -TYPEINIT0( DbCellControl ) -TYPEINIT1( DbLimitedLengthField, DbCellControl ) -TYPEINIT1( DbTextField, DbLimitedLengthField ) -TYPEINIT1( DbFormattedField, DbLimitedLengthField ) -TYPEINIT1( DbCheckBox, DbCellControl ) -TYPEINIT1( DbComboBox, DbCellControl ) -TYPEINIT1( DbListBox, DbCellControl ) -TYPEINIT1( DbPatternField, DbCellControl ) -TYPEINIT1( DbSpinField, DbCellControl ) -TYPEINIT1( DbDateField, DbSpinField ) -TYPEINIT1( DbTimeField, DbSpinField ) -TYPEINIT1( DbCurrencyField, DbSpinField ) -TYPEINIT1( DbNumericField, DbSpinField ) -TYPEINIT1( DbFilterField, DbCellControl ) - -//------------------------------------------------------------------------------ -DbCellControl::DbCellControl( DbGridColumn& _rColumn, sal_Bool /*_bText*/ ) - :OPropertyChangeListener(m_aMutex) - ,m_pFieldChangeBroadcaster(NULL) - ,m_bTransparent( sal_False ) - ,m_bAlignedController( sal_True ) - ,m_bAccessingValueProperty( sal_False ) - ,m_rColumn( _rColumn ) - ,m_pPainter( NULL ) - ,m_pWindow( NULL ) -{ - Reference< XPropertySet > xColModelProps( _rColumn.getModel(), UNO_QUERY ); - if ( xColModelProps.is() ) - { - // if our model's format key changes we want to propagate the new value to our windows - m_pModelChangeBroadcaster = new ::comphelper::OPropertyChangeMultiplexer(this, Reference< ::com::sun::star::beans::XPropertySet > (_rColumn.getModel(), UNO_QUERY)); - m_pModelChangeBroadcaster->acquire(); - - // be listener for some common properties - implDoPropertyListening( FM_PROP_READONLY, sal_False ); - implDoPropertyListening( FM_PROP_ENABLED, sal_False ); - - // add as listener for all know "value" properties - implDoPropertyListening( FM_PROP_VALUE, sal_False ); - implDoPropertyListening( FM_PROP_STATE, sal_False ); - implDoPropertyListening( FM_PROP_TEXT, sal_False ); - implDoPropertyListening( FM_PROP_EFFECTIVE_VALUE, sal_False ); - - // be listener at the bound field as well - try - { - Reference< XPropertySetInfo > xPSI( xColModelProps->getPropertySetInfo(), UNO_SET_THROW ); - if ( xPSI->hasPropertyByName( FM_PROP_BOUNDFIELD ) ) - { - Reference< XPropertySet > xField; - xColModelProps->getPropertyValue( FM_PROP_BOUNDFIELD ) >>= xField; - if ( xField.is() ) - { - m_pFieldChangeBroadcaster = new ::comphelper::OPropertyChangeMultiplexer(this, xField); - m_pFieldChangeBroadcaster->acquire(); - m_pFieldChangeBroadcaster->addProperty( FM_PROP_ISREADONLY ); - } - } - } - catch( const Exception& ) - { - OSL_FAIL( "DbCellControl::doPropertyListening: caught an exception!" ); - } - } -} - -//------------------------------------------------------------------------------ -void DbCellControl::implDoPropertyListening( const ::rtl::OUString& _rPropertyName, sal_Bool _bWarnIfNotExistent ) -{ - try - { - Reference< XPropertySet > xColModelProps( m_rColumn.getModel(), UNO_QUERY ); - Reference< XPropertySetInfo > xPSI; - if ( xColModelProps.is() ) - xPSI = xColModelProps->getPropertySetInfo(); - - DBG_ASSERT( !_bWarnIfNotExistent || ( xPSI.is() && xPSI->hasPropertyByName( _rPropertyName ) ), - "DbCellControl::doPropertyListening: no property set info or non-existent property!" ); - (void)_bWarnIfNotExistent; - - if ( xPSI.is() && xPSI->hasPropertyByName( _rPropertyName ) ) - m_pModelChangeBroadcaster->addProperty( _rPropertyName ); - } - catch( const Exception& ) - { - OSL_FAIL( "DbCellControl::doPropertyListening: caught an exception!" ); - } -} - -//------------------------------------------------------------------------------ -void DbCellControl::doPropertyListening( const ::rtl::OUString& _rPropertyName ) -{ - implDoPropertyListening( _rPropertyName ); -} -//------------------------------------------------------------------------------ -void lcl_clearBroadCaster(::comphelper::OPropertyChangeMultiplexer*& _pBroadcaster) -{ - if ( _pBroadcaster ) - { - _pBroadcaster->dispose(); - _pBroadcaster->release(); - _pBroadcaster = NULL; - // no delete, this is done implicitly - } -} -//------------------------------------------------------------------------------ -DbCellControl::~DbCellControl() -{ - lcl_clearBroadCaster(m_pModelChangeBroadcaster); - lcl_clearBroadCaster(m_pFieldChangeBroadcaster); - - delete m_pWindow; - delete m_pPainter; -} - -//------------------------------------------------------------------------------ -void DbCellControl::implValuePropertyChanged( ) -{ - OSL_ENSURE( !isValuePropertyLocked(), - "DbCellControl::implValuePropertyChanged: not to be called with the value property locked!" ); - - if ( m_pWindow ) - { - if ( m_rColumn.getModel().is() ) - updateFromModel( m_rColumn.getModel() ); - } -} - -//------------------------------------------------------------------------------ -void DbCellControl::implAdjustGenericFieldSetting( const Reference< XPropertySet >& /*_rxModel*/ ) -{ - // nothing to to here -} - -//------------------------------------------------------------------------------ -void DbCellControl::_propertyChanged(const PropertyChangeEvent& _rEvent) throw(RuntimeException) -{ - SolarMutexGuard aGuard; - - Reference< XPropertySet > xSourceProps( _rEvent.Source, UNO_QUERY ); - - if ( _rEvent.PropertyName.equals( FM_PROP_VALUE ) - || _rEvent.PropertyName.equals( FM_PROP_STATE ) - || _rEvent.PropertyName.equals( FM_PROP_TEXT ) - || _rEvent.PropertyName.equals( FM_PROP_EFFECTIVE_VALUE ) - ) - { // it was one of the known "value" properties - if ( !isValuePropertyLocked() ) - { - implValuePropertyChanged( ); - } - } - else if ( _rEvent.PropertyName.equals( FM_PROP_READONLY ) ) - { - implAdjustReadOnly( xSourceProps, true); - } - else if ( _rEvent.PropertyName.equals( FM_PROP_ISREADONLY ) ) - { - sal_Bool bReadOnly = sal_True; - _rEvent.NewValue >>= bReadOnly; - m_rColumn.SetReadOnly(bReadOnly); - implAdjustReadOnly( xSourceProps, false); - } - else if ( _rEvent.PropertyName.equals( FM_PROP_ENABLED ) ) - { - implAdjustEnabled( xSourceProps ); - } - else - implAdjustGenericFieldSetting( xSourceProps ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbCellControl::Commit() -{ - // lock the listening for value property changes - lockValueProperty(); - // commit the content of the control into the model's value property - sal_Bool bReturn = sal_False; - try - { - bReturn = commitControl(); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - // unlock the listening for value property changes - unlockValueProperty(); - // outta here - return bReturn; -} - -//------------------------------------------------------------------------------ -void DbCellControl::ImplInitWindow( Window& rParent, const InitWindowFacet _eInitWhat ) -{ - Window* pWindows[] = { m_pPainter, m_pWindow }; - - if ( ( _eInitWhat & InitWritingMode ) != 0 ) - { - for ( size_t i=0; i < SAL_N_ELEMENTS( pWindows ); ++i ) - { - if ( pWindows[i] ) - pWindows[i]->EnableRTL( rParent.IsRTLEnabled() ); - } - } - - if ( ( _eInitWhat & InitFont ) != 0 ) - { - for (size_t i=0; i < SAL_N_ELEMENTS(pWindows); ++i) - { - if ( !pWindows[i] ) - continue; - - pWindows[i]->SetZoom( rParent.GetZoom() ); - - const StyleSettings& rStyleSettings = pWindows[i]->GetSettings().GetStyleSettings(); - Font aFont = rStyleSettings.GetFieldFont(); - aFont.SetTransparent( isTransparent() ); - - if ( rParent.IsControlFont() ) - { - pWindows[i]->SetControlFont( rParent.GetControlFont() ); - aFont.Merge( rParent.GetControlFont() ); - } - else - pWindows[i]->SetControlFont(); - - pWindows[i]->SetZoomedPointFont( aFont ); - } - } - - if ( ( ( _eInitWhat & InitFont ) != 0 ) - || ( ( _eInitWhat & InitForeground ) != 0 ) - ) - { - Color aTextColor( rParent.IsControlForeground() ? rParent.GetControlForeground() : rParent.GetTextColor() ); - - sal_Bool bTextLineColor = rParent.IsTextLineColor(); - Color aTextLineColor( rParent.GetTextLineColor() ); - - for (size_t i=0; i < SAL_N_ELEMENTS(pWindows); ++i) - { - if ( pWindows[i] ) - { - pWindows[i]->SetTextColor(aTextColor); - if (rParent.IsControlForeground()) - pWindows[i]->SetControlForeground(aTextColor); - - if (bTextLineColor) - pWindows[i]->SetTextLineColor(); - else - pWindows[i]->SetTextLineColor(aTextLineColor); - } - } - } - - if ( ( _eInitWhat & InitBackground ) != 0 ) - { - if (rParent.IsControlBackground()) - { - Color aColor( rParent.GetControlBackground()); - for (size_t i=0; i < SAL_N_ELEMENTS(pWindows); ++i) - { - if ( pWindows[i] ) - { - if ( isTransparent() ) - pWindows[i]->SetBackground(); - else - { - pWindows[i]->SetBackground(aColor); - pWindows[i]->SetControlBackground(aColor); - } - pWindows[i]->SetFillColor(aColor); - } - } - } - else - { - if (m_pPainter) - { - if ( isTransparent() ) - m_pPainter->SetBackground(); - else - m_pPainter->SetBackground(rParent.GetBackground()); - m_pPainter->SetFillColor(rParent.GetFillColor()); - } - - if (m_pWindow) - { - if ( isTransparent() ) - m_pWindow->SetBackground(rParent.GetBackground()); - else - m_pWindow->SetFillColor(rParent.GetFillColor()); - } - } - } -} - -//------------------------------------------------------------------------------ -void DbCellControl::implAdjustReadOnly( const Reference< XPropertySet >& _rxModel,bool i_bReadOnly ) -{ - DBG_ASSERT( m_pWindow, "DbCellControl::implAdjustReadOnly: not to be called without window!" ); - DBG_ASSERT( _rxModel.is(), "DbCellControl::implAdjustReadOnly: invalid model!" ); - if ( m_pWindow && _rxModel.is() ) - { - Edit* pEditWindow = dynamic_cast< Edit* >( m_pWindow ); - if ( pEditWindow ) - { - sal_Bool bReadOnly = m_rColumn.IsReadOnly(); - if ( !bReadOnly ) - { - _rxModel->getPropertyValue( i_bReadOnly ? FM_PROP_READONLY : FM_PROP_ISREADONLY) >>= bReadOnly; - } - static_cast< Edit* >( m_pWindow )->SetReadOnly( bReadOnly ); - } - } -} - -//------------------------------------------------------------------------------ -void DbCellControl::implAdjustEnabled( const Reference< XPropertySet >& _rxModel ) -{ - DBG_ASSERT( m_pWindow, "DbCellControl::implAdjustEnabled: not to be called without window!" ); - DBG_ASSERT( _rxModel.is(), "DbCellControl::implAdjustEnabled: invalid model!" ); - if ( m_pWindow && _rxModel.is() ) - { - sal_Bool bEnable = sal_True; - _rxModel->getPropertyValue( FM_PROP_ENABLED ) >>= bEnable; - m_pWindow->Enable( bEnable ); - } -} - -//------------------------------------------------------------------------------ -void DbCellControl::Init( Window& rParent, const Reference< XRowSet >& _rxCursor ) -{ - ImplInitWindow( rParent, InitAll ); - - if ( m_pWindow ) - { - // align the control - if ( isAlignedController() ) - AlignControl( m_rColumn.GetAlignment() ); - - try - { - // some other common properties - Reference< XPropertySet > xModel( m_rColumn.getModel(), UNO_SET_THROW ); - Reference< XPropertySetInfo > xModelPSI( xModel->getPropertySetInfo(), UNO_SET_THROW ); - - if ( xModelPSI->hasPropertyByName( FM_PROP_READONLY ) ) - { - implAdjustReadOnly( xModel,true ); - } - - if ( xModelPSI->hasPropertyByName( FM_PROP_ENABLED ) ) - { - implAdjustEnabled( xModel ); - } - - if ( xModelPSI->hasPropertyByName( FM_PROP_MOUSE_WHEEL_BEHAVIOR ) ) - { - sal_Int16 nWheelBehavior = MouseWheelBehavior::SCROLL_FOCUS_ONLY; - OSL_VERIFY( xModel->getPropertyValue( FM_PROP_MOUSE_WHEEL_BEHAVIOR ) >>= nWheelBehavior ); - sal_uInt16 nVclSetting = MOUSE_WHEEL_FOCUS_ONLY; - switch ( nWheelBehavior ) - { - case MouseWheelBehavior::SCROLL_DISABLED: nVclSetting = MOUSE_WHEEL_DISABLE; break; - case MouseWheelBehavior::SCROLL_FOCUS_ONLY: nVclSetting = MOUSE_WHEEL_FOCUS_ONLY; break; - case MouseWheelBehavior::SCROLL_ALWAYS: nVclSetting = MOUSE_WHEEL_ALWAYS; break; - default: - OSL_FAIL( "DbCellControl::Init: invalid MouseWheelBehavior!" ); - break; - } - - AllSettings aSettings = m_pWindow->GetSettings(); - MouseSettings aMouseSettings = aSettings.GetMouseSettings(); - aMouseSettings.SetWheelBehavior( nVclSetting ); - aSettings.SetMouseSettings( aMouseSettings ); - m_pWindow->SetSettings( aSettings, sal_True ); - } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - m_xCursor = _rxCursor; -} - -//------------------------------------------------------------------------------ -void DbCellControl::SetTextLineColor() -{ - if (m_pWindow) - m_pWindow->SetTextLineColor(); - if (m_pPainter) - m_pPainter->SetTextLineColor(); -} - -//------------------------------------------------------------------------------ -void DbCellControl::SetTextLineColor(const Color& _rColor) -{ - if (m_pWindow) - m_pWindow->SetTextLineColor(_rColor); - if (m_pPainter) - m_pPainter->SetTextLineColor(_rColor); -} - -namespace -{ - static void lcl_implAlign( Window* _pWindow, WinBits _nAlignmentBit ) - { - WinBits nStyle = _pWindow->GetStyle(); - nStyle &= ~(WB_LEFT | WB_RIGHT | WB_CENTER); - _pWindow->SetStyle( nStyle | _nAlignmentBit ); - } -} - -//------------------------------------------------------------------------------ -void DbCellControl::AlignControl(sal_Int16 nAlignment) -{ - WinBits nAlignmentBit = 0; - switch (nAlignment) - { - case ::com::sun::star::awt::TextAlign::RIGHT: - nAlignmentBit = WB_RIGHT; - break; - case ::com::sun::star::awt::TextAlign::CENTER: - nAlignmentBit = WB_CENTER; - break; - default: - nAlignmentBit = WB_LEFT; - break; - } - lcl_implAlign( m_pWindow, nAlignmentBit ); - if ( m_pPainter ) - lcl_implAlign( m_pPainter, nAlignmentBit ); -} - -//------------------------------------------------------------------------------ -void DbCellControl::PaintCell( OutputDevice& _rDev, const Rectangle& _rRect ) -{ - if ( m_pPainter->GetParent() == &_rDev ) - { - m_pPainter->SetPaintTransparent( sal_True ); - m_pPainter->SetBackground( ); - m_pPainter->SetControlBackground( _rDev.GetFillColor() ); - m_pPainter->SetControlForeground( _rDev.GetTextColor() ); - m_pPainter->SetTextColor( _rDev.GetTextColor() ); - m_pPainter->SetTextFillColor( _rDev.GetTextColor() ); - - Font aFont( _rDev.GetFont() ); - aFont.SetTransparent( sal_True ); - m_pPainter->SetFont( aFont ); - - m_pPainter->SetPosSizePixel( _rRect.TopLeft(), _rRect.GetSize() ); - m_pPainter->Show(); - m_pPainter->Update(); - m_pPainter->SetParentUpdateMode( sal_False ); - m_pPainter->Hide(); - m_pPainter->SetParentUpdateMode( sal_True ); - } - else - m_pPainter->Draw( &_rDev, _rRect.TopLeft(), _rRect.GetSize(), 0 ); -} - -//------------------------------------------------------------------------------ -void DbCellControl::PaintFieldToCell( OutputDevice& _rDev, const Rectangle& _rRect, const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter ) -{ - m_pPainter->SetText( GetFormatText( _rxField, _rxFormatter ) ); - PaintCell( _rDev, _rRect ); -} - -//------------------------------------------------------------------------------ -double DbCellControl::GetValue(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter) const -{ - double fValue = 0; - if (m_rColumn.IsNumeric()) - { - try - { - fValue = _rxField->getDouble(); - } - catch(const Exception&) { } - } - else - { - sal_Bool bSuccess = sal_False; - try - { - fValue = _rxField->getDouble(); - bSuccess = sal_True; - } - catch(const Exception&) { } - if (!bSuccess) - { - try - { - fValue = xFormatter->convertStringToNumber(m_rColumn.GetKey(), _rxField->getString()); - } - catch(const Exception&) { } - } - } - return fValue; -} - -//------------------------------------------------------------------------------ -void DbCellControl::invalidatedController() -{ - m_rColumn.GetParent().refreshController(m_rColumn.GetId(), DbGridControl::GrantControlAccess()); -} - -/*************************************************************************/ -// CellModels -/*************************************************************************/ - -//============================================================================== -//= DbLimitedLengthField -//============================================================================== -//------------------------------------------------------------------------------ -DbLimitedLengthField::DbLimitedLengthField( DbGridColumn& _rColumn ) - :DbCellControl( _rColumn ) -{ - doPropertyListening( FM_PROP_MAXTEXTLEN ); -} - -//------------------------------------------------------------------------------ -void DbLimitedLengthField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel ) -{ - DBG_ASSERT( m_pWindow, "DbLimitedLengthField::implAdjustGenericFieldSetting: not to be called without window!" ); - DBG_ASSERT( _rxModel.is(), "DbLimitedLengthField::implAdjustGenericFieldSetting: invalid model!" ); - if ( m_pWindow && _rxModel.is() ) - { - sal_Int16 nMaxLen = 0; - _rxModel->getPropertyValue( FM_PROP_MAXTEXTLEN ) >>= nMaxLen; - implSetMaxTextLen( nMaxLen ); - } -} - -//------------------------------------------------------------------------------ -void DbLimitedLengthField::implSetEffectiveMaxTextLen( sal_Int16 _nMaxLen ) -{ - dynamic_cast< Edit* >( m_pWindow )->SetMaxTextLen( _nMaxLen ); - if ( m_pPainter ) - dynamic_cast< Edit* >( m_pPainter )->SetMaxTextLen( _nMaxLen ); -} - -//============================================================================== -//= DbTextField -//============================================================================== -//------------------------------------------------------------------------------ -DbTextField::DbTextField(DbGridColumn& _rColumn) - :DbLimitedLengthField(_rColumn) - ,m_pEdit( NULL ) - ,m_pPainterImplementation( NULL ) - ,m_nKeyType(::com::sun::star::util::NumberFormat::TEXT) - ,m_bIsSimpleEdit( sal_True ) -{ -} - -//------------------------------------------------------------------------------ -DbTextField::~DbTextField( ) -{ - DELETEZ( m_pPainterImplementation ); - DELETEZ( m_pEdit ); -} - -//------------------------------------------------------------------------------ -void DbTextField::Init( Window& rParent, const Reference< XRowSet >& xCursor) -{ - sal_Int16 nAlignment = m_rColumn.SetAlignmentFromModel(-1); - - Reference< XPropertySet > xModel( m_rColumn.getModel() ); - - WinBits nStyle = WB_LEFT; - switch (nAlignment) - { - case awt::TextAlign::RIGHT: - nStyle = WB_RIGHT; - break; - - case awt::TextAlign::CENTER: - nStyle = WB_CENTER; - break; - } - - // is this a multi-line field? - sal_Bool bIsMultiLine = sal_False; - try - { - if ( xModel.is() ) - { - OSL_VERIFY( xModel->getPropertyValue( FM_PROP_MULTILINE ) >>= bIsMultiLine ); - } - } - catch( const Exception& ) - { - OSL_FAIL( "DbTextField::Init: caught an exception while determining the multi-line capabilities!" ); - } - - m_bIsSimpleEdit = !bIsMultiLine; - if ( bIsMultiLine ) - { - m_pWindow = new MultiLineTextCell( &rParent, nStyle ); - m_pEdit = new MultiLineEditImplementation( *static_cast< MultiLineTextCell* >( m_pWindow ) ); - - m_pPainter = new MultiLineTextCell( &rParent, nStyle ); - m_pPainterImplementation = new MultiLineEditImplementation( *static_cast< MultiLineTextCell* >( m_pPainter ) ); - } - else - { - m_pWindow = new Edit( &rParent, nStyle ); - m_pEdit = new EditImplementation( *static_cast< Edit* >( m_pWindow ) ); - - m_pPainter = new Edit( &rParent, nStyle ); - m_pPainterImplementation = new EditImplementation( *static_cast< Edit* >( m_pPainter ) ); - } - - if ( WB_LEFT == nStyle ) - { - // this is so that when getting the focus, the selection is oriented left-to-right - AllSettings aSettings = m_pWindow->GetSettings(); - StyleSettings aStyleSettings = aSettings.GetStyleSettings(); - aStyleSettings.SetSelectionOptions( - aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST); - aSettings.SetStyleSettings(aStyleSettings); - m_pWindow->SetSettings(aSettings); - } - - implAdjustGenericFieldSetting( xModel ); - - if (m_rColumn.GetParent().getNumberFormatter().is() && m_rColumn.GetKey()) - m_nKeyType = comphelper::getNumberFormatType(m_rColumn.GetParent().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(), m_rColumn.GetKey()); - - DbLimitedLengthField::Init( rParent, xCursor ); -} - -//------------------------------------------------------------------------------ -CellControllerRef DbTextField::CreateController() const -{ - return new EditCellController( m_pEdit ); -} - -//------------------------------------------------------------------------------ -void DbTextField::PaintFieldToCell( OutputDevice& _rDev, const Rectangle& _rRect, const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter ) -{ - if ( m_pPainterImplementation ) - m_pPainterImplementation->SetText( GetFormatText( _rxField, _rxFormatter, NULL ) ); - - DbLimitedLengthField::PaintFieldToCell( _rDev, _rRect, _rxField, _rxFormatter ); -} - -//------------------------------------------------------------------------------ -String DbTextField::GetFormatText(const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter, Color** /*ppColor*/) -{ - ::rtl::OUString aString; - if ( _rxField.is() ) - try - { - aString = getFormattedValue( _rxField, xFormatter, m_rColumn.GetParent().getNullDate(), m_rColumn.GetKey(), m_nKeyType); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - - return aString; -} - -//------------------------------------------------------------------------------ -void DbTextField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter) -{ - m_pEdit->SetText( GetFormatText( _rxField, xFormatter ) ); - m_pEdit->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) ); -} - -//------------------------------------------------------------------------------ -void DbTextField::updateFromModel( Reference< XPropertySet > _rxModel ) -{ - OSL_ENSURE( _rxModel.is() && m_pWindow, "DbTextField::updateFromModel: invalid call!" ); - - ::rtl::OUString sText; - _rxModel->getPropertyValue( FM_PROP_TEXT ) >>= sText; - - xub_StrLen nMaxTextLen = m_pEdit->GetMaxTextLen(); - if ( EDIT_NOLIMIT != nMaxTextLen && sText.getLength() > nMaxTextLen ) - { - sal_Int32 nDiff = sText.getLength() - nMaxTextLen; - sText = sText.replaceAt(sText.getLength() - nDiff,nDiff,::rtl::OUString()); - } - - - m_pEdit->SetText( sText ); - m_pEdit->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbTextField::commitControl() -{ - ::rtl::OUString aText( m_pEdit->GetText( getModelLineEndSetting( m_rColumn.getModel() ) ) ); - // we have to check if the length before we can decide if the value was modified - xub_StrLen nMaxTextLen = m_pEdit->GetMaxTextLen(); - if ( EDIT_NOLIMIT != nMaxTextLen ) - { - ::rtl::OUString sOldValue; - m_rColumn.getModel()->getPropertyValue( FM_PROP_TEXT ) >>= sOldValue; - // if the new value didn't change we must set the old long value again - if ( sOldValue.getLength() > nMaxTextLen && sOldValue.compareTo(aText,nMaxTextLen) == 0 ) - aText = sOldValue; - } - m_rColumn.getModel()->setPropertyValue( FM_PROP_TEXT, makeAny( aText ) ); - return sal_True; -} - -//------------------------------------------------------------------------------ -void DbTextField::implSetEffectiveMaxTextLen( sal_Int16 _nMaxLen ) -{ - if ( m_pEdit ) - m_pEdit->SetMaxTextLen( _nMaxLen ); - if ( m_pPainterImplementation ) - m_pPainterImplementation->SetMaxTextLen( _nMaxLen ); -} - -//============================================================================== -//= DbFormattedField -//============================================================================== -DBG_NAME(DbFormattedField); -//------------------------------------------------------------------------------ -DbFormattedField::DbFormattedField(DbGridColumn& _rColumn) - :DbLimitedLengthField(_rColumn) - ,m_nKeyType(::com::sun::star::util::NumberFormat::UNDEFINED) -{ - DBG_CTOR(DbFormattedField,NULL); - - // if our model's format key changes we want to propagate the new value to our windows - doPropertyListening( FM_PROP_FORMATKEY ); -} - -//------------------------------------------------------------------------------ -DbFormattedField::~DbFormattedField() -{ - DBG_DTOR(DbFormattedField,NULL); -} - -//------------------------------------------------------------------------------ -void DbFormattedField::Init( Window& rParent, const Reference< XRowSet >& xCursor) -{ - sal_Int16 nAlignment = m_rColumn.SetAlignmentFromModel(-1); - - Reference< ::com::sun::star::beans::XPropertySet > xUnoModel = m_rColumn.getModel(); - - switch (nAlignment) - { - case ::com::sun::star::awt::TextAlign::RIGHT: - m_pWindow = new FormattedField( &rParent, WB_RIGHT ); - m_pPainter = new FormattedField( &rParent, WB_RIGHT ); - break; - - case ::com::sun::star::awt::TextAlign::CENTER: - m_pWindow = new FormattedField( &rParent, WB_CENTER ); - m_pPainter = new FormattedField( &rParent, WB_CENTER ); - break; - default: - m_pWindow = new FormattedField( &rParent, WB_LEFT ); - m_pPainter = new FormattedField( &rParent, WB_LEFT ); - - // Alles nur damit die Selektion bei Focuserhalt von rechts nach links geht - AllSettings aSettings = m_pWindow->GetSettings(); - StyleSettings aStyleSettings = aSettings.GetStyleSettings(); - aStyleSettings.SetSelectionOptions( - aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST); - aSettings.SetStyleSettings(aStyleSettings); - m_pWindow->SetSettings(aSettings); - } - - implAdjustGenericFieldSetting( xUnoModel ); - - static_cast< FormattedField* >( m_pWindow )->SetStrictFormat( sal_False ); - static_cast< FormattedField* >( m_pPainter )->SetStrictFormat( sal_False ); - // wenn man _irgendeine_ Formatierung zulaesst, kann man da sowieso keine Eingabe-Ueberpruefung - // machen (das FormattedField unterstuetzt das sowieso nicht, nur abgeleitete Klassen) - - // von dem Uno-Model den Formatter besorgen - // (Ich koennte theoretisch auch ueber den ::com::sun::star::util::NumberFormatter gehen, den mir der Cursor bestimmt - // liefern wuerde. Das Problem dabei ist, dass ich mich eigentlich nicht darauf verlassen - // kann, dass die beiden Formatter die selben sind, sauber ist das Ganze, wenn ich ueber das - // UNO-Model gehe.) - sal_Int32 nFormatKey = -1; - - // mal sehen, ob das Model einen hat ... - DBG_ASSERT(::comphelper::hasProperty(FM_PROP_FORMATSSUPPLIER, xUnoModel), "DbFormattedField::Init : invalid UNO model !"); - Any aSupplier( xUnoModel->getPropertyValue(FM_PROP_FORMATSSUPPLIER)); - if (aSupplier.hasValue()) - { - ::cppu::extractInterface(m_xSupplier, aSupplier); - if (m_xSupplier.is()) - { - // wenn wir den Supplier vom Model nehmen, dann auch den Key - Any aFmtKey( xUnoModel->getPropertyValue(FM_PROP_FORMATKEY)); - if (aFmtKey.hasValue()) - { - DBG_ASSERT(aFmtKey.getValueType().getTypeClass() == TypeClass_LONG, "DbFormattedField::Init : invalid format key property (no sal_Int32) !"); - nFormatKey = ::comphelper::getINT32(aFmtKey); - } - else - { - DBG_WARNING("DbFormattedField::Init : my uno-model has no format-key, but a formats supplier !"); - // the OFormattedModel which we usually are working with ensures that the model has a format key - // as soon as the form is loaded. Unfortunally this method here is called from within loaded, too. - // So if our LoadListener is called before the LoadListener of the model, this "else case" is - // allowed. - // Of course our property listener for the FormatKey property will notify us if the prop is changed, - // so this here isn't really bad .... - nFormatKey = 0; - } - } - } - - // nein ? vielleicht die ::com::sun::star::form::component::Form hinter dem Cursor ? - if (!m_xSupplier.is()) - { - Reference< XRowSet > xCursorForm(xCursor, UNO_QUERY); - if (xCursorForm.is()) - { // wenn wir vom Cursor den Formatter nehmen, dann auch den Key vom Feld, an das wir gebunden sind - m_xSupplier = getNumberFormats(getRowSetConnection(xCursorForm), sal_False); - - if (m_rColumn.GetField().is()) - nFormatKey = ::comphelper::getINT32(m_rColumn.GetField()->getPropertyValue(FM_PROP_FORMATKEY)); - } - } - - SvNumberFormatter* pFormatterUsed = NULL; - if (m_xSupplier.is()) - { - SvNumberFormatsSupplierObj* pImplmentation = SvNumberFormatsSupplierObj::getImplementation(m_xSupplier); - if (pImplmentation) - pFormatterUsed = pImplmentation->GetNumberFormatter(); - else - // alles hingfaellig : der Supplier ist vom falschen Typ, dann koennen wir uns auch nicht darauf verlassen, dass - // ein Standard-Formatter den (eventuell nicht-Standard-)Key kennt. - nFormatKey = -1; - } - - // einen Standard-Formatter ... - if (pFormatterUsed == NULL) - { - pFormatterUsed = ((FormattedField*)m_pWindow)->StandardFormatter(); - DBG_ASSERT(pFormatterUsed != NULL, "DbFormattedField::Init : no standard formatter given by the numeric field !"); - } - // ... und einen Standard-Key - if (nFormatKey == -1) - nFormatKey = 0; - - m_nKeyType = comphelper::getNumberFormatType(m_xSupplier->getNumberFormats(), nFormatKey); - - ((FormattedField*)m_pWindow)->SetFormatter(pFormatterUsed); - ((FormattedField*)m_pPainter)->SetFormatter(pFormatterUsed); - - ((FormattedField*)m_pWindow)->SetFormatKey(nFormatKey); - ((FormattedField*)m_pPainter)->SetFormatKey(nFormatKey); - - ((FormattedField*)m_pWindow)->TreatAsNumber(m_rColumn.IsNumeric()); - ((FormattedField*)m_pPainter)->TreatAsNumber(m_rColumn.IsNumeric()); - - // Min- und Max-Werte - if (m_rColumn.IsNumeric()) - { - sal_Bool bClearMin = sal_True; - if (::comphelper::hasProperty(FM_PROP_EFFECTIVE_MIN, xUnoModel)) - { - Any aMin( xUnoModel->getPropertyValue(FM_PROP_EFFECTIVE_MIN)); - if (aMin.getValueType().getTypeClass() != TypeClass_VOID) - { - DBG_ASSERT(aMin.getValueType().getTypeClass() == TypeClass_DOUBLE, "DbFormattedField::Init : the model has an invalid min value !"); - double dMin = ::comphelper::getDouble(aMin); - ((FormattedField*)m_pWindow)->SetMinValue(dMin); - ((FormattedField*)m_pPainter)->SetMinValue(dMin); - bClearMin = sal_False; - } - } - if (bClearMin) - { - ((FormattedField*)m_pWindow)->ClearMinValue(); - ((FormattedField*)m_pPainter)->ClearMinValue(); - } - sal_Bool bClearMax = sal_True; - if (::comphelper::hasProperty(FM_PROP_EFFECTIVE_MAX, xUnoModel)) - { - Any aMin( xUnoModel->getPropertyValue(FM_PROP_EFFECTIVE_MAX)); - if (aMin.getValueType().getTypeClass() != TypeClass_VOID) - { - DBG_ASSERT(aMin.getValueType().getTypeClass() == TypeClass_DOUBLE, "DbFormattedField::Init : the model has an invalid max value !"); - double dMin = ::comphelper::getDouble(aMin); - ((FormattedField*)m_pWindow)->SetMaxValue(dMin); - ((FormattedField*)m_pPainter)->SetMaxValue(dMin); - bClearMax = sal_False; - } - } - if (bClearMax) - { - ((FormattedField*)m_pWindow)->ClearMaxValue(); - ((FormattedField*)m_pPainter)->ClearMaxValue(); - } - } - - // den Default-Wert - Any aDefault( xUnoModel->getPropertyValue(FM_PROP_EFFECTIVE_DEFAULT)); - if (aDefault.hasValue()) - { // das Ding kann ein double oder ein String sein - switch (aDefault.getValueType().getTypeClass()) - { - case TypeClass_DOUBLE: - if (m_rColumn.IsNumeric()) - { - ((FormattedField*)m_pWindow)->SetDefaultValue(::comphelper::getDouble(aDefault)); - ((FormattedField*)m_pPainter)->SetDefaultValue(::comphelper::getDouble(aDefault)); - } - else - { - String sConverted; - Color* pDummy; - pFormatterUsed->GetOutputString(::comphelper::getDouble(aDefault), 0, sConverted, &pDummy); - ((FormattedField*)m_pWindow)->SetDefaultText(sConverted); - ((FormattedField*)m_pPainter)->SetDefaultText(sConverted); - } - break; - case TypeClass_STRING: - { - String sDefault( ::comphelper::getString(aDefault) ); - if (m_rColumn.IsNumeric()) - { - double dVal; - sal_uInt32 nTestFormat(0); - if (pFormatterUsed->IsNumberFormat(sDefault, nTestFormat, dVal)) - { - ((FormattedField*)m_pWindow)->SetDefaultValue(dVal); - ((FormattedField*)m_pPainter)->SetDefaultValue(dVal); - } - } - else - { - ((FormattedField*)m_pWindow)->SetDefaultText(sDefault); - ((FormattedField*)m_pPainter)->SetDefaultText(sDefault); - } - } - default: - OSL_FAIL( "DbFormattedField::Init: unexpected value type!" ); - break; - } - } - DbLimitedLengthField::Init( rParent, xCursor ); -} - -//------------------------------------------------------------------------------ -CellControllerRef DbFormattedField::CreateController() const -{ - return new ::svt::FormattedFieldCellController( static_cast< FormattedField* >( m_pWindow ) ); -} - -//------------------------------------------------------------------------------ -void DbFormattedField::_propertyChanged( const PropertyChangeEvent& _rEvent ) throw( RuntimeException ) -{ - if (_rEvent.PropertyName.compareTo(FM_PROP_FORMATKEY) == COMPARE_EQUAL) - { - sal_Int32 nNewKey = _rEvent.NewValue.hasValue() ? ::comphelper::getINT32(_rEvent.NewValue) : 0; - m_nKeyType = comphelper::getNumberFormatType(m_xSupplier->getNumberFormats(), nNewKey); - - DBG_ASSERT(m_pWindow && m_pPainter, "DbFormattedField::_propertyChanged : where are my windows ?"); - if (m_pWindow) - static_cast< FormattedField* >( m_pWindow )->SetFormatKey( nNewKey ); - if (m_pPainter) - static_cast< FormattedField* >( m_pPainter )->SetFormatKey( nNewKey ); - } - else - { - DbLimitedLengthField::_propertyChanged( _rEvent ); - } -} - -//------------------------------------------------------------------------------ -String DbFormattedField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/, Color** ppColor) -{ - // defaultmaessig keine Farb-Angabe - if (ppColor != NULL) - *ppColor = NULL; - - // NULL-Wert -> leerer Text - if (!_rxField.is()) - return String(); - - String aText; - try - { - if (m_rColumn.IsNumeric()) - { - // das IsNumeric an der Column sagt nichts aus ueber die Klasse des benutzen Formates, sondern - // ueber die des an die Column gebundenen Feldes. Wenn man also eine FormattedField-Spalte an - // ein double-Feld bindet und als Text formatiert, liefert m_rColumn.IsNumeric() sal_True. Das heisst - // also einfach, dass ich den Inhalt der Variant mittels getDouble abfragen kann, und dann kann - // ich den Rest (die Formatierung) dem FormattedField ueberlassen. - double dValue = getValue( _rxField, m_rColumn.GetParent().getNullDate() ); - if (_rxField->wasNull()) - return aText; - ((FormattedField*)m_pPainter)->SetValue(dValue); - } - else - { - // Hier kann ich nicht mit einem double arbeiten, da das Feld mir keines liefern kann. - // Also einfach den Text vom ::com::sun::star::util::NumberFormatter in die richtige ::com::sun::star::form::component::Form brinden lassen. - aText = (const sal_Unicode*)_rxField->getString(); - if (_rxField->wasNull()) - return aText; - ((FormattedField*)m_pPainter)->SetTextFormatted(aText); - } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - - aText = m_pPainter->GetText(); - if (ppColor != NULL) - *ppColor = ((FormattedField*)m_pPainter)->GetLastOutputColor(); - - return aText; -} - -//------------------------------------------------------------------------------ -void DbFormattedField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/) -{ - try - { - FormattedField* pFormattedWindow = static_cast<FormattedField*>(m_pWindow); - if (!_rxField.is()) - { // NULL-Wert -> leerer Text - m_pWindow->SetText(String()); - } - else if (m_rColumn.IsNumeric()) - { - // das IsNumeric an der Column sagt nichts aus ueber die Klasse des benutzen Formates, sondern - // ueber die des an die Column gebundenen Feldes. Wenn man also eine FormattedField-Spalte an - // ein double-Feld bindet und als Text formatiert, liefert m_rColumn.IsNumeric() sal_True. Das heisst - // also einfach, dass ich den Inhalt der Variant mittels getDouble abfragen kann, und dann kann - // ich den Rest (die Formatierung) dem FormattedField ueberlassen. - double dValue = getValue( _rxField, m_rColumn.GetParent().getNullDate() ); - if (_rxField->wasNull()) - m_pWindow->SetText(String()); - else - pFormattedWindow->SetValue(dValue); - } - else - { - // Hier kann ich nicht mit einem double arbeiten, da das Feld mir keines liefern kann. - // Also einfach den Text vom ::com::sun::star::util::NumberFormatter in die richtige ::com::sun::star::form::component::Form brinden lassen. - String sText( _rxField->getString()); - - pFormattedWindow->SetTextFormatted( sText ); - pFormattedWindow->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) ); - } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } -} - -//------------------------------------------------------------------------------ -void DbFormattedField::updateFromModel( Reference< XPropertySet > _rxModel ) -{ - OSL_ENSURE( _rxModel.is() && m_pWindow, "DbFormattedField::updateFromModel: invalid call!" ); - - FormattedField* pFormattedWindow = static_cast< FormattedField* >( m_pWindow ); - - ::rtl::OUString sText; - Any aValue = _rxModel->getPropertyValue( FM_PROP_EFFECTIVE_VALUE ); - if ( aValue >>= sText ) - { // our effective value is transfered as string - pFormattedWindow->SetTextFormatted( sText ); - pFormattedWindow->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) ); - } - else - { - double dValue = 0; - aValue >>= dValue; - pFormattedWindow->SetValue(dValue); - } -} - -//------------------------------------------------------------------------------ -sal_Bool DbFormattedField::commitControl() -{ - Any aNewVal; - FormattedField& rField = *(FormattedField*)m_pWindow; - DBG_ASSERT(&rField == m_pWindow, "DbFormattedField::commitControl : can't work with a window other than my own !"); - if (m_rColumn.IsNumeric()) - { - if (rField.GetText().Len() != 0) - aNewVal <<= rField.GetValue(); - // ein LeerString wird erst mal standardmaessig als void weitergereicht - } - else - aNewVal <<= ::rtl::OUString(rField.GetTextValue()); - - m_rColumn.getModel()->setPropertyValue(FM_PROP_EFFECTIVE_VALUE, aNewVal); - return sal_True; -} - -//============================================================================== -//= DbCheckBox -//============================================================================== -//------------------------------------------------------------------------------ -DbCheckBox::DbCheckBox( DbGridColumn& _rColumn ) - :DbCellControl( _rColumn, sal_True ) -{ - setAlignedController( sal_False ); -} - -namespace -{ - void setCheckBoxStyle( Window* _pWindow, bool bMono ) - { - AllSettings aSettings = _pWindow->GetSettings(); - StyleSettings aStyleSettings = aSettings.GetStyleSettings(); - if( bMono ) - aStyleSettings.SetOptions( aStyleSettings.GetOptions() | STYLE_OPTION_MONO ); - else - aStyleSettings.SetOptions( aStyleSettings.GetOptions() & (~STYLE_OPTION_MONO) ); - aSettings.SetStyleSettings( aStyleSettings ); - _pWindow->SetSettings( aSettings ); - } -} - -//------------------------------------------------------------------------------ -void DbCheckBox::Init( Window& rParent, const Reference< XRowSet >& xCursor ) -{ - setTransparent( sal_True ); - - m_pWindow = new CheckBoxControl( &rParent ); - m_pPainter = new CheckBoxControl( &rParent ); - - m_pWindow->SetPaintTransparent( sal_True ); - m_pPainter->SetPaintTransparent( sal_True ); - - m_pPainter->SetBackground(); - - try - { - Reference< XPropertySet > xModel( m_rColumn.getModel(), UNO_SET_THROW ); - - sal_Int16 nStyle = awt::VisualEffect::LOOK3D; - OSL_VERIFY( xModel->getPropertyValue( FM_PROP_VISUALEFFECT ) >>= nStyle ); - - setCheckBoxStyle( m_pWindow, nStyle == awt::VisualEffect::FLAT ); - setCheckBoxStyle( m_pPainter, nStyle == awt::VisualEffect::FLAT ); - - sal_Bool bTristate = sal_True; - OSL_VERIFY( xModel->getPropertyValue( FM_PROP_TRISTATE ) >>= bTristate ); - static_cast< CheckBoxControl* >( m_pWindow )->GetBox().EnableTriState( bTristate ); - static_cast< CheckBoxControl* >( m_pPainter )->GetBox().EnableTriState( bTristate ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - - DbCellControl::Init( rParent, xCursor ); -} - -//------------------------------------------------------------------------------ -CellControllerRef DbCheckBox::CreateController() const -{ - return new CheckBoxCellController((CheckBoxControl*)m_pWindow); -} -//------------------------------------------------------------------------------ -static void lcl_setCheckBoxState( const Reference< ::com::sun::star::sdb::XColumn >& _rxField, - CheckBoxControl* _pCheckBoxControl ) -{ - TriState eState = STATE_DONTKNOW; - if (_rxField.is()) - { - try - { - sal_Bool bValue = _rxField->getBoolean(); - if (!_rxField->wasNull()) - eState = bValue ? STATE_CHECK : STATE_NOCHECK; - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - _pCheckBoxControl->GetBox().SetState(eState); -} - -//------------------------------------------------------------------------------ -void DbCheckBox::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/) -{ - lcl_setCheckBoxState( _rxField, static_cast<CheckBoxControl*>(m_pWindow) ); -} - -//------------------------------------------------------------------------------ -void DbCheckBox::PaintFieldToCell(OutputDevice& rDev, const Rectangle& rRect, - const Reference< ::com::sun::star::sdb::XColumn >& _rxField, - const Reference< XNumberFormatter >& xFormatter) -{ - lcl_setCheckBoxState( _rxField, static_cast<CheckBoxControl*>(m_pPainter) ); - DbCellControl::PaintFieldToCell( rDev, rRect, _rxField, xFormatter ); -} - -//------------------------------------------------------------------------------ -void DbCheckBox::updateFromModel( Reference< XPropertySet > _rxModel ) -{ - OSL_ENSURE( _rxModel.is() && m_pWindow, "DbCheckBox::updateFromModel: invalid call!" ); - - sal_Int16 nState = STATE_DONTKNOW; - _rxModel->getPropertyValue( FM_PROP_STATE ) >>= nState; - static_cast< CheckBoxControl* >( m_pWindow )->GetBox().SetState( static_cast< TriState >( nState ) ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbCheckBox::commitControl() -{ -#if OSL_DEBUG_LEVEL > 0 - Any aVal = makeAny( (sal_Int16)( static_cast< CheckBoxControl* >( m_pWindow )->GetBox().GetState() ) ); -#endif - m_rColumn.getModel()->setPropertyValue( FM_PROP_STATE, - makeAny( (sal_Int16)( static_cast< CheckBoxControl* >( m_pWindow )->GetBox().GetState() ) ) ); - return sal_True; -} - -//------------------------------------------------------------------------------ -XubString DbCheckBox::GetFormatText(const Reference< XColumn >& /*_rxField*/, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/) -{ - return XubString(); -} - -//============================================================================== -//= DbPatternField -//------------------------------------------------------------------------------ -DbPatternField::DbPatternField( DbGridColumn& _rColumn, const ::comphelper::ComponentContext& _rContext ) - :DbCellControl( _rColumn ) - ,m_aContext( _rContext ) -{ - doPropertyListening( FM_PROP_LITERALMASK ); - doPropertyListening( FM_PROP_EDITMASK ); - doPropertyListening( FM_PROP_STRICTFORMAT ); -} - -//------------------------------------------------------------------------------ -void DbPatternField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel ) -{ - DBG_ASSERT( m_pWindow, "DbPatternField::implAdjustGenericFieldSetting: not to be called without window!" ); - DBG_ASSERT( _rxModel.is(), "DbPatternField::implAdjustGenericFieldSetting: invalid model!" ); - if ( m_pWindow && _rxModel.is() ) - { - ::rtl::OUString aLitMask; - ::rtl::OUString aEditMask; - sal_Bool bStrict = sal_False; - - _rxModel->getPropertyValue( FM_PROP_LITERALMASK ) >>= aLitMask; - _rxModel->getPropertyValue( FM_PROP_EDITMASK ) >>= aEditMask; - _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) >>= bStrict; - - ByteString aAsciiEditMask( aEditMask.getStr(), RTL_TEXTENCODING_ASCII_US ); - - static_cast< PatternField* >( m_pWindow )->SetMask( aAsciiEditMask, aLitMask ); - static_cast< PatternField* >( m_pPainter )->SetMask( aAsciiEditMask, aLitMask ); - static_cast< PatternField* >( m_pWindow )->SetStrictFormat( bStrict ); - static_cast< PatternField* >( m_pPainter )->SetStrictFormat( bStrict ); - } -} - -//------------------------------------------------------------------------------ -void DbPatternField::Init( Window& rParent, const Reference< XRowSet >& xCursor) -{ - m_rColumn.SetAlignmentFromModel(-1); - - m_pWindow = new PatternField( &rParent, 0 ); - m_pPainter= new PatternField( &rParent, 0 ); - - Reference< XPropertySet > xModel( m_rColumn.getModel() ); - implAdjustGenericFieldSetting( xModel ); - - DbCellControl::Init( rParent, xCursor ); -} - -//------------------------------------------------------------------------------ -CellControllerRef DbPatternField::CreateController() const -{ - return new SpinCellController( static_cast< PatternField* >( m_pWindow ) ); -} - -//------------------------------------------------------------------------------ -String DbPatternField::impl_formatText( const String& _rText ) -{ - m_pPainter->SetText( _rText ); - static_cast< PatternField* >( m_pPainter )->ReformatAll(); - return m_pPainter->GetText(); -} - -//------------------------------------------------------------------------------ -String DbPatternField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/) -{ - bool bIsForPaint = _rxField != m_rColumn.GetField(); - ::std::auto_ptr< ::dbtools::FormattedColumnValue >& rpFormatter = bIsForPaint ? m_pPaintFormatter : m_pValueFormatter; - - if ( !rpFormatter.get() ) - { - DBToolsObjectFactory aFactory; - rpFormatter = aFactory.createFormattedColumnValue( - m_aContext, getCursor(), Reference< XPropertySet >( _rxField, UNO_QUERY ) ); - OSL_ENSURE( rpFormatter.get(), "DbPatternField::Init: no value formatter!" ); - } - else - OSL_ENSURE( rpFormatter->getColumn() == _rxField, "DbPatternField::GetFormatText: my value formatter is working for another field ...!" ); - // re-creating the value formatter here everytime would be quite expensive ... - - String sText; - if ( rpFormatter.get() ) - sText = rpFormatter->getFormattedValue(); - - return impl_formatText( sText ); -} - -//------------------------------------------------------------------------------ -void DbPatternField::UpdateFromField( const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter ) -{ - static_cast< Edit* >( m_pWindow )->SetText( GetFormatText( _rxField, _rxFormatter ) ); - static_cast< Edit* >( m_pWindow )->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) ); -} - -//------------------------------------------------------------------------------ -void DbPatternField::updateFromModel( Reference< XPropertySet > _rxModel ) -{ - OSL_ENSURE( _rxModel.is() && m_pWindow, "DbPatternField::updateFromModel: invalid call!" ); - - ::rtl::OUString sText; - _rxModel->getPropertyValue( FM_PROP_TEXT ) >>= sText; - - static_cast< Edit* >( m_pWindow )->SetText( impl_formatText( sText ) ); - static_cast< Edit* >( m_pWindow )->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbPatternField::commitControl() -{ - String aText(m_pWindow->GetText()); - m_rColumn.getModel()->setPropertyValue(FM_PROP_TEXT, makeAny(::rtl::OUString(aText))); - return sal_True; -} - -//============================================================================== -//= DbSpinField -//============================================================================== -//------------------------------------------------------------------------------ -DbSpinField::DbSpinField( DbGridColumn& _rColumn, sal_Int16 _nStandardAlign ) - :DbCellControl( _rColumn ) - ,m_nStandardAlign( _nStandardAlign ) -{ -} - -//------------------------------------------------------------------------------ -void DbSpinField::Init( Window& _rParent, const Reference< XRowSet >& _rxCursor ) -{ - m_rColumn.SetAlignmentFromModel( m_nStandardAlign ); - - Reference< XPropertySet > xModel( m_rColumn.getModel() ); - - // determine the WinBits for the field - WinBits nFieldStyle = 0; - if ( ::comphelper::getBOOL( xModel->getPropertyValue( FM_PROP_SPIN ) ) ) - nFieldStyle = WB_REPEAT | WB_SPIN; - // create the fields - m_pWindow = createField( &_rParent, nFieldStyle, xModel ); - m_pPainter = createField( &_rParent, nFieldStyle, xModel ); - - // adjust all other settings which depend on the property values - implAdjustGenericFieldSetting( xModel ); - - // call the base class - DbCellControl::Init( _rParent, _rxCursor ); -} - -//------------------------------------------------------------------------------ -CellControllerRef DbSpinField::CreateController() const -{ - return new SpinCellController( static_cast< SpinField* >( m_pWindow ) ); -} - -//============================================================================== -//= DbNumericField -//============================================================================== -//------------------------------------------------------------------------------ -DbNumericField::DbNumericField( DbGridColumn& _rColumn ) - :DbSpinField( _rColumn ) -{ - doPropertyListening( FM_PROP_DECIMAL_ACCURACY ); - doPropertyListening( FM_PROP_VALUEMIN ); - doPropertyListening( FM_PROP_VALUEMAX ); - doPropertyListening( FM_PROP_VALUESTEP ); - doPropertyListening( FM_PROP_STRICTFORMAT ); - doPropertyListening( FM_PROP_SHOWTHOUSANDSEP ); -} - -//------------------------------------------------------------------------------ -void DbNumericField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel ) -{ - DBG_ASSERT( m_pWindow, "DbNumericField::implAdjustGenericFieldSetting: not to be called without window!" ); - DBG_ASSERT( _rxModel.is(), "DbNumericField::implAdjustGenericFieldSetting: invalid model!" ); - if ( m_pWindow && _rxModel.is() ) - { - sal_Int32 nMin = (sal_Int32)getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMIN ) ); - sal_Int32 nMax = (sal_Int32)getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMAX ) ); - sal_Int32 nStep = (sal_Int32)getDouble( _rxModel->getPropertyValue( FM_PROP_VALUESTEP ) ); - sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) ); - sal_Int16 nScale = getINT16( _rxModel->getPropertyValue( FM_PROP_DECIMAL_ACCURACY ) ); - sal_Bool bThousand = getBOOL( _rxModel->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP ) ); - - static_cast< DoubleNumericField* >( m_pWindow )->SetMinValue(nMin); - static_cast< DoubleNumericField* >( m_pWindow )->SetMaxValue(nMax); - static_cast< DoubleNumericField* >( m_pWindow )->SetSpinSize(nStep); - static_cast< DoubleNumericField* >( m_pWindow )->SetStrictFormat(bStrict); - - static_cast< DoubleNumericField* >( m_pPainter )->SetMinValue(nMin); - static_cast< DoubleNumericField* >( m_pPainter )->SetMaxValue(nMax); - static_cast< DoubleNumericField* >( m_pPainter )->SetStrictFormat(bStrict); - - - // dem Field und dem Painter einen Formatter spendieren - // zuerst testen, ob ich von dem Service hinter einer Connection bekommen kann - Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier; - Reference< XRowSet > xForm; - if ( m_rColumn.GetParent().getDataSource() ) - xForm = Reference< XRowSet >( ( Reference< XInterface > )*m_rColumn.GetParent().getDataSource(), UNO_QUERY ); - if ( xForm.is() ) - xSupplier = getNumberFormats( getRowSetConnection( xForm ), sal_True ); - SvNumberFormatter* pFormatterUsed = NULL; - if ( xSupplier.is() ) - { - SvNumberFormatsSupplierObj* pImplmentation = SvNumberFormatsSupplierObj::getImplementation( xSupplier ); - pFormatterUsed = pImplmentation ? pImplmentation->GetNumberFormatter() : NULL; - } - if ( NULL == pFormatterUsed ) - { // der Cursor fuehrte nicht zum Erfolg -> Standard - pFormatterUsed = static_cast< DoubleNumericField* >( m_pWindow )->StandardFormatter(); - DBG_ASSERT( pFormatterUsed != NULL, "DbNumericField::implAdjustGenericFieldSetting: no standard formatter given by the numeric field !" ); - } - static_cast< DoubleNumericField* >( m_pWindow )->SetFormatter( pFormatterUsed ); - static_cast< DoubleNumericField* >( m_pPainter )->SetFormatter( pFormatterUsed ); - - // und dann ein Format generieren, dass die gewuenschten Nachkommastellen usw. hat - String sFormatString; - LanguageType aAppLanguage = Application::GetSettings().GetUILanguage(); - pFormatterUsed->GenerateFormat( sFormatString, 0, aAppLanguage, bThousand, sal_False, nScale ); - - static_cast< DoubleNumericField* >( m_pWindow )->SetFormat( sFormatString, aAppLanguage ); - static_cast< DoubleNumericField* >( m_pPainter )->SetFormat( sFormatString, aAppLanguage ); - } -} - -//------------------------------------------------------------------------------ -SpinField* DbNumericField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& /*_rxModel*/ ) -{ - return new DoubleNumericField( _pParent, _nFieldStyle ); -} - -namespace -{ - //-------------------------------------------------------------------------- - static String lcl_setFormattedNumeric_nothrow( DoubleNumericField& _rField, const DbCellControl& _rControl, - const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter ) - { - String sValue; - if ( _rxField.is() ) - { - try - { - double fValue = _rControl.GetValue( _rxField, _rxFormatter ); - if ( !_rxField->wasNull() ) - { - _rField.SetValue( fValue ); - sValue = _rField.GetText(); - } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - return sValue; - } -} - -//------------------------------------------------------------------------------ -String DbNumericField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, Color** /*ppColor*/) -{ - return lcl_setFormattedNumeric_nothrow( *dynamic_cast< DoubleNumericField* >( m_pPainter ), *this, _rxField, _rxFormatter ); -} - -//------------------------------------------------------------------------------ -void DbNumericField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter) -{ - lcl_setFormattedNumeric_nothrow( *dynamic_cast< DoubleNumericField* >( m_pWindow ), *this, _rxField, _rxFormatter ); -} - -//------------------------------------------------------------------------------ -void DbNumericField::updateFromModel( Reference< XPropertySet > _rxModel ) -{ - OSL_ENSURE( _rxModel.is() && m_pWindow, "DbNumericField::updateFromModel: invalid call!" ); - - double dValue = 0; - if ( _rxModel->getPropertyValue( FM_PROP_VALUE ) >>= dValue ) - static_cast< DoubleNumericField* >( m_pWindow )->SetValue( dValue ); - else - m_pWindow->SetText( String() ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbNumericField::commitControl() -{ - String aText( m_pWindow->GetText()); - Any aVal; - - if (aText.Len() != 0) // nicht null - { - double fValue = ((DoubleNumericField*)m_pWindow)->GetValue(); - aVal <<= (double)fValue; - } - m_rColumn.getModel()->setPropertyValue(FM_PROP_VALUE, aVal); - return sal_True; -} - -//============================================================================== -//= DbCurrencyField -//============================================================================== -//------------------------------------------------------------------------------ -DbCurrencyField::DbCurrencyField(DbGridColumn& _rColumn) - :DbSpinField( _rColumn ) - ,m_nScale( 0 ) -{ - doPropertyListening( FM_PROP_DECIMAL_ACCURACY ); - doPropertyListening( FM_PROP_VALUEMIN ); - doPropertyListening( FM_PROP_VALUEMAX ); - doPropertyListening( FM_PROP_VALUESTEP ); - doPropertyListening( FM_PROP_STRICTFORMAT ); - doPropertyListening( FM_PROP_SHOWTHOUSANDSEP ); - doPropertyListening( FM_PROP_CURRENCYSYMBOL ); -} - -//------------------------------------------------------------------------------ -void DbCurrencyField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel ) -{ - DBG_ASSERT( m_pWindow, "DbCurrencyField::implAdjustGenericFieldSetting: not to be called without window!" ); - DBG_ASSERT( _rxModel.is(), "DbCurrencyField::implAdjustGenericFieldSetting: invalid model!" ); - if ( m_pWindow && _rxModel.is() ) - { - m_nScale = getINT16( _rxModel->getPropertyValue( FM_PROP_DECIMAL_ACCURACY ) ); - double nMin = getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMIN ) ); - double nMax = getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMAX ) ); - double nStep = getDouble( _rxModel->getPropertyValue( FM_PROP_VALUESTEP ) ); - sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) ); - sal_Bool bThousand = getBOOL( _rxModel->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP ) ); - ::rtl::OUString aStr( getString( _rxModel->getPropertyValue(FM_PROP_CURRENCYSYMBOL ) ) ); - - static_cast< LongCurrencyField* >( m_pWindow )->SetUseThousandSep( bThousand ); - static_cast< LongCurrencyField* >( m_pWindow )->SetDecimalDigits( m_nScale ); - static_cast< LongCurrencyField* >( m_pWindow )->SetCurrencySymbol( aStr ); - static_cast< LongCurrencyField* >( m_pWindow )->SetFirst( nMin ); - static_cast< LongCurrencyField* >( m_pWindow )->SetLast( nMax ); - static_cast< LongCurrencyField* >( m_pWindow )->SetMin( nMin ); - static_cast< LongCurrencyField* >( m_pWindow )->SetMax( nMax ); - static_cast< LongCurrencyField* >( m_pWindow )->SetSpinSize( nStep ); - static_cast< LongCurrencyField* >( m_pWindow )->SetStrictFormat( bStrict ); - - static_cast< LongCurrencyField* >( m_pPainter )->SetUseThousandSep( bThousand ); - static_cast< LongCurrencyField* >( m_pPainter )->SetDecimalDigits( m_nScale ); - static_cast< LongCurrencyField* >( m_pPainter )->SetCurrencySymbol( aStr ); - static_cast< LongCurrencyField* >( m_pPainter )->SetFirst( nMin ); - static_cast< LongCurrencyField* >( m_pPainter )->SetLast( nMax ); - static_cast< LongCurrencyField* >( m_pPainter )->SetMin( nMin ); - static_cast< LongCurrencyField* >( m_pPainter )->SetMax( nMax ); - static_cast< LongCurrencyField* >( m_pPainter )->SetStrictFormat( bStrict ); - } -} - -//------------------------------------------------------------------------------ -SpinField* DbCurrencyField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& /*_rxModel*/ ) -{ - return new LongCurrencyField( _pParent, _nFieldStyle ); -} - -//------------------------------------------------------------------------------ -double DbCurrencyField::GetCurrency(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter) const -{ - double fValue = GetValue(_rxField, xFormatter); - if (m_nScale) - { - // OSL_TRACE("double = %.64f ",fValue); - fValue = ::rtl::math::pow10Exp(fValue, m_nScale); - fValue = ::rtl::math::round(fValue, 0); - } - return fValue; -} - -namespace -{ - //-------------------------------------------------------------------------- - static String lcl_setFormattedCurrency_nothrow( LongCurrencyField& _rField, const DbCurrencyField& _rControl, - const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter ) - { - String sValue; - if ( _rxField.is() ) - { - try - { - double fValue = _rControl.GetCurrency( _rxField, _rxFormatter ); - if ( !_rxField->wasNull() ) - { - _rField.SetValue( fValue ); - BigInt aValue = _rField.GetCorrectedValue(); - sValue = aValue.GetString(); - sValue = _rField.GetText(); - } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - return sValue; - } -} - -//------------------------------------------------------------------------------ -String DbCurrencyField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, Color** /*ppColor*/) -{ - return lcl_setFormattedCurrency_nothrow( *dynamic_cast< LongCurrencyField* >( m_pPainter ), *this, _rxField, _rxFormatter ); -} - -//------------------------------------------------------------------------------ -void DbCurrencyField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter) -{ - lcl_setFormattedCurrency_nothrow( *dynamic_cast< LongCurrencyField* >( m_pWindow ), *this, _rxField, _rxFormatter ); -} - -//------------------------------------------------------------------------------ -void DbCurrencyField::updateFromModel( Reference< XPropertySet > _rxModel ) -{ - OSL_ENSURE( _rxModel.is() && m_pWindow, "DbCurrencyField::updateFromModel: invalid call!" ); - - double dValue = 0; - if ( _rxModel->getPropertyValue( FM_PROP_VALUE ) >>= dValue ) - { - if ( m_nScale ) - { - dValue = ::rtl::math::pow10Exp( dValue, m_nScale ); - dValue = ::rtl::math::round(dValue, 0); - } - - static_cast< LongCurrencyField* >( m_pWindow )->SetValue( dValue ); - } - else - m_pWindow->SetText( String() ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbCurrencyField::commitControl() -{ - String aText( m_pWindow->GetText()); - Any aVal; - if (aText.Len() != 0) // nicht null - { - double fValue = ((LongCurrencyField*)m_pWindow)->GetValue(); - if (m_nScale) - { - fValue /= ::rtl::math::pow10Exp(1.0, m_nScale); - //fValue = ::rtl::math::round(fValue, m_nScale); - } - aVal <<= (double)fValue; - } - m_rColumn.getModel()->setPropertyValue(FM_PROP_VALUE, aVal); - return sal_True; -} - -//============================================================================== -//= DbDateField -//============================================================================== -//------------------------------------------------------------------------------ -DbDateField::DbDateField( DbGridColumn& _rColumn ) - :DbSpinField( _rColumn ) -{ - doPropertyListening( FM_PROP_DATEFORMAT ); - doPropertyListening( FM_PROP_DATEMIN ); - doPropertyListening( FM_PROP_DATEMAX ); - doPropertyListening( FM_PROP_STRICTFORMAT ); - doPropertyListening( FM_PROP_DATE_SHOW_CENTURY ); -} - -//------------------------------------------------------------------------------ -SpinField* DbDateField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& _rxModel ) -{ - // check if there is a DropDown property set to TRUE - sal_Bool bDropDown = !hasProperty( FM_PROP_DROPDOWN, _rxModel ) - || getBOOL( _rxModel->getPropertyValue( FM_PROP_DROPDOWN ) ); - if ( bDropDown ) - _nFieldStyle |= WB_DROPDOWN; - - CalendarField* pField = new CalendarField( _pParent, _nFieldStyle ); - - pField->EnableToday(); - pField->EnableNone(); - - return pField; -} - -//------------------------------------------------------------------------------ -void DbDateField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel ) -{ - DBG_ASSERT( m_pWindow, "DbDateField::implAdjustGenericFieldSetting: not to be called without window!" ); - DBG_ASSERT( _rxModel.is(), "DbDateField::implAdjustGenericFieldSetting: invalid model!" ); - if ( m_pWindow && _rxModel.is() ) - { - sal_Int16 nFormat = getINT16( _rxModel->getPropertyValue( FM_PROP_DATEFORMAT ) ); - sal_Int32 nMin = getINT32( _rxModel->getPropertyValue( FM_PROP_DATEMIN ) ); - sal_Int32 nMax = getINT32( _rxModel->getPropertyValue( FM_PROP_DATEMAX ) ); - sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) ); - - Any aCentury = _rxModel->getPropertyValue( FM_PROP_DATE_SHOW_CENTURY ); - if ( aCentury.getValueType().getTypeClass() != TypeClass_VOID ) - { - sal_Bool bShowDateCentury = getBOOL( aCentury ); - - static_cast<DateField*>( m_pWindow )->SetShowDateCentury( bShowDateCentury ); - static_cast<DateField*>( m_pPainter )->SetShowDateCentury( bShowDateCentury ); - } - - static_cast< DateField* >( m_pWindow )->SetExtDateFormat( (ExtDateFieldFormat)nFormat ); - static_cast< DateField* >( m_pWindow )->SetMin( nMin ); - static_cast< DateField* >( m_pWindow )->SetMax( nMax ); - static_cast< DateField* >( m_pWindow )->SetStrictFormat( bStrict ); - static_cast< DateField* >( m_pWindow )->EnableEmptyFieldValue( sal_True ); - - static_cast< DateField* >( m_pPainter )->SetExtDateFormat( (ExtDateFieldFormat)nFormat ); - static_cast< DateField* >( m_pPainter )->SetMin( nMin ); - static_cast< DateField* >( m_pPainter )->SetMax( nMax ); - static_cast< DateField* >( m_pPainter )->SetStrictFormat( bStrict ); - static_cast< DateField* >( m_pPainter )->EnableEmptyFieldValue( sal_True ); - } -} - -namespace -{ - //-------------------------------------------------------------------------- - static String lcl_setFormattedDate_nothrow( DateField& _rField, const Reference< XColumn >& _rxField ) - { - String sDate; - if ( _rxField.is() ) - { - try - { - ::com::sun::star::util::Date aValue = _rxField->getDate(); - if ( _rxField->wasNull() ) - _rField.SetText( sDate ); - else - { - _rField.SetDate( ::Date( aValue.Day, aValue.Month, aValue.Year ) ); - sDate = _rField.GetText(); - } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - return sDate; - } -} -//------------------------------------------------------------------------------ -String DbDateField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/) -{ - return lcl_setFormattedDate_nothrow( *dynamic_cast< DateField* >( m_pPainter ), _rxField ); -} - -//------------------------------------------------------------------------------ -void DbDateField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/) -{ - lcl_setFormattedDate_nothrow( *dynamic_cast< DateField* >( m_pWindow ), _rxField ); -} - -//------------------------------------------------------------------------------ -void DbDateField::updateFromModel( Reference< XPropertySet > _rxModel ) -{ - OSL_ENSURE( _rxModel.is() && m_pWindow, "DbDateField::updateFromModel: invalid call!" ); - - sal_Int32 nDate = 0; - if ( _rxModel->getPropertyValue( FM_PROP_DATE ) >>= nDate ) - static_cast< DateField* >( m_pWindow )->SetDate( ::Date( nDate ) ); - else - static_cast< DateField* >( m_pWindow )->SetText( String() ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbDateField::commitControl() -{ - String aText( m_pWindow->GetText()); - Any aVal; - if (aText.Len() != 0) - aVal <<= (sal_Int32)static_cast<DateField*>(m_pWindow)->GetDate().GetDate(); - else - aVal.clear(); - - m_rColumn.getModel()->setPropertyValue(FM_PROP_DATE, aVal); - return sal_True; -} - -//============================================================================== -//= DbTimeField -//============================================================================== -//------------------------------------------------------------------------------ -DbTimeField::DbTimeField( DbGridColumn& _rColumn ) - :DbSpinField( _rColumn, ::com::sun::star::awt::TextAlign::LEFT ) -{ - doPropertyListening( FM_PROP_TIMEFORMAT ); - doPropertyListening( FM_PROP_TIMEMIN ); - doPropertyListening( FM_PROP_TIMEMAX ); - doPropertyListening( FM_PROP_STRICTFORMAT ); -} - -//------------------------------------------------------------------------------ -SpinField* DbTimeField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& /*_rxModel*/ ) -{ - return new TimeField( _pParent, _nFieldStyle ); -} - -//------------------------------------------------------------------------------ -void DbTimeField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel ) -{ - DBG_ASSERT( m_pWindow, "DbTimeField::implAdjustGenericFieldSetting: not to be called without window!" ); - DBG_ASSERT( _rxModel.is(), "DbTimeField::implAdjustGenericFieldSetting: invalid model!" ); - if ( m_pWindow && _rxModel.is() ) - { - sal_Int16 nFormat = getINT16( _rxModel->getPropertyValue( FM_PROP_TIMEFORMAT ) ); - sal_Int32 nMin = getINT32( _rxModel->getPropertyValue( FM_PROP_TIMEMIN ) ); - sal_Int32 nMax = getINT32( _rxModel->getPropertyValue( FM_PROP_TIMEMAX ) ); - sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) ); - - static_cast< TimeField* >( m_pWindow )->SetExtFormat( (ExtTimeFieldFormat)nFormat ); - static_cast< TimeField* >( m_pWindow )->SetMin( nMin ); - static_cast< TimeField* >( m_pWindow )->SetMax( nMax ); - static_cast< TimeField* >( m_pWindow )->SetStrictFormat( bStrict ); - static_cast< TimeField* >( m_pWindow )->EnableEmptyFieldValue( sal_True ); - - static_cast< TimeField* >( m_pPainter )->SetExtFormat( (ExtTimeFieldFormat)nFormat ); - static_cast< TimeField* >( m_pPainter )->SetMin( nMin ); - static_cast< TimeField* >( m_pPainter )->SetMax( nMax ); - static_cast< TimeField* >( m_pPainter )->SetStrictFormat( bStrict ); - static_cast< TimeField* >( m_pPainter )->EnableEmptyFieldValue( sal_True ); - } -} - -namespace -{ - //-------------------------------------------------------------------------- - static String lcl_setFormattedTime_nothrow( TimeField& _rField, const Reference< XColumn >& _rxField ) - { - String sTime; - if ( _rxField.is() ) - { - try - { - ::com::sun::star::util::Time aValue = _rxField->getTime(); - if ( _rxField->wasNull() ) - _rField.SetText( sTime ); - else - { - _rField.SetTime( ::Time( aValue.Hours, aValue.Minutes, aValue.Seconds, aValue.HundredthSeconds ) ); - sTime = _rField.GetText(); - } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - return sTime; - } -} -//------------------------------------------------------------------------------ -String DbTimeField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/) -{ - return lcl_setFormattedTime_nothrow( *static_cast< TimeField* >( m_pPainter ), _rxField ); -} - -//------------------------------------------------------------------------------ -void DbTimeField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/) -{ - lcl_setFormattedTime_nothrow( *static_cast< TimeField* >( m_pWindow ), _rxField ); -} - -//------------------------------------------------------------------------------ -void DbTimeField::updateFromModel( Reference< XPropertySet > _rxModel ) -{ - OSL_ENSURE( _rxModel.is() && m_pWindow, "DbTimeField::updateFromModel: invalid call!" ); - - sal_Int32 nTime = 0; - if ( _rxModel->getPropertyValue( FM_PROP_DATE ) >>= nTime ) - static_cast< TimeField* >( m_pWindow )->SetTime( ::Time( nTime ) ); - else - static_cast< TimeField* >( m_pWindow )->SetText( String() ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbTimeField::commitControl() -{ - String aText( m_pWindow->GetText()); - Any aVal; - if (aText.Len() != 0) - aVal <<= (sal_Int32)static_cast<TimeField*>(m_pWindow)->GetTime().GetTime(); - else - aVal.clear(); - - m_rColumn.getModel()->setPropertyValue(FM_PROP_TIME, aVal); - return sal_True; -} - -//============================================================================== -//= DbComboBox -//============================================================================== -//------------------------------------------------------------------------------ -DbComboBox::DbComboBox(DbGridColumn& _rColumn) - :DbCellControl(_rColumn) - ,m_nKeyType(::com::sun::star::util::NumberFormat::UNDEFINED) -{ - setAlignedController( sal_False ); - - doPropertyListening( FM_PROP_STRINGITEMLIST ); - doPropertyListening( FM_PROP_LINECOUNT ); -} - -//------------------------------------------------------------------------------ -void DbComboBox::_propertyChanged( const PropertyChangeEvent& _rEvent ) throw( RuntimeException ) -{ - if ( _rEvent.PropertyName.equals( FM_PROP_STRINGITEMLIST ) ) - { - SetList(_rEvent.NewValue); - } - else - { - DbCellControl::_propertyChanged( _rEvent ) ; - } -} - -//------------------------------------------------------------------------------ -void DbComboBox::SetList(const Any& rItems) -{ - ComboBoxControl* pField = (ComboBoxControl*)m_pWindow; - pField->Clear(); - - ::comphelper::StringSequence aTest; - if (rItems >>= aTest) - { - const ::rtl::OUString* pStrings = aTest.getConstArray(); - sal_Int32 nItems = aTest.getLength(); - for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings ) - pField->InsertEntry(*pStrings, LISTBOX_APPEND); - - // tell the grid control that this controller is invalid and has to be re-initialized - invalidatedController(); - } -} - -//------------------------------------------------------------------------------ -void DbComboBox::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel ) -{ - DBG_ASSERT( m_pWindow, "DbComboBox::implAdjustGenericFieldSetting: not to be called without window!" ); - DBG_ASSERT( _rxModel.is(), "DbComboBox::implAdjustGenericFieldSetting: invalid model!" ); - if ( m_pWindow && _rxModel.is() ) - { - sal_Int16 nLines = getINT16( _rxModel->getPropertyValue( FM_PROP_LINECOUNT ) ); - static_cast< ComboBoxControl* >( m_pWindow )->SetDropDownLineCount( nLines ); - } -} - -//------------------------------------------------------------------------------ -void DbComboBox::Init( Window& rParent, const Reference< XRowSet >& xCursor ) -{ - m_rColumn.SetAlignmentFromModel(::com::sun::star::awt::TextAlign::LEFT); - - m_pWindow = new ComboBoxControl( &rParent ); - - // selection von rechts nach links - AllSettings aSettings = m_pWindow->GetSettings(); - StyleSettings aStyleSettings = aSettings.GetStyleSettings(); - aStyleSettings.SetSelectionOptions( - aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST); - aSettings.SetStyleSettings(aStyleSettings); - m_pWindow->SetSettings(aSettings, sal_True); - - // some initial properties - Reference< XPropertySet > xModel(m_rColumn.getModel()); - SetList( xModel->getPropertyValue( FM_PROP_STRINGITEMLIST ) ); - implAdjustGenericFieldSetting( xModel ); - - if (m_rColumn.GetParent().getNumberFormatter().is()) - m_nKeyType = comphelper::getNumberFormatType(m_rColumn.GetParent().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(), m_rColumn.GetKey()); - - DbCellControl::Init( rParent, xCursor ); -} - -//------------------------------------------------------------------------------ -CellControllerRef DbComboBox::CreateController() const -{ - return new ComboBoxCellController((ComboBoxControl*)m_pWindow); -} - -//------------------------------------------------------------------------------ -String DbComboBox::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter, Color** /*ppColor*/) -{ - ::rtl::OUString aString; - if (_rxField.is()) - try - { - aString = getFormattedValue( _rxField, xFormatter, m_rColumn.GetParent().getNullDate(), m_rColumn.GetKey(), m_nKeyType ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - return aString; -} - -//------------------------------------------------------------------------------ -void DbComboBox::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter) -{ - m_pWindow->SetText(GetFormatText(_rxField, xFormatter)); -} - -//------------------------------------------------------------------------------ -void DbComboBox::updateFromModel( Reference< XPropertySet > _rxModel ) -{ - OSL_ENSURE( _rxModel.is() && m_pWindow, "DbComboBox::updateFromModel: invalid call!" ); - - ::rtl::OUString sText; - _rxModel->getPropertyValue( FM_PROP_TEXT ) >>= sText; - - static_cast< ComboBox* >( m_pWindow )->SetText( sText ); - static_cast< ComboBox* >( m_pWindow )->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbComboBox::commitControl() -{ - String aText( m_pWindow->GetText()); - m_rColumn.getModel()->setPropertyValue(FM_PROP_TEXT, makeAny(::rtl::OUString(aText))); - return sal_True; -} - -//------------------------------------------------------------------------------ -DbListBox::DbListBox(DbGridColumn& _rColumn) - :DbCellControl(_rColumn) - ,m_bBound(sal_False) -{ - setAlignedController( sal_False ); - - doPropertyListening( FM_PROP_STRINGITEMLIST ); - doPropertyListening( FM_PROP_LINECOUNT ); -} - -//------------------------------------------------------------------------------ -void DbListBox::_propertyChanged( const ::com::sun::star::beans::PropertyChangeEvent& _rEvent ) throw( RuntimeException ) -{ - if ( _rEvent.PropertyName.equals( FM_PROP_STRINGITEMLIST ) ) - { - SetList(_rEvent.NewValue); - } - else - { - DbCellControl::_propertyChanged( _rEvent ) ; - } -} - -//------------------------------------------------------------------------------ -void DbListBox::SetList(const Any& rItems) -{ - ListBoxControl* pField = (ListBoxControl*)m_pWindow; - - pField->Clear(); - m_bBound = sal_False; - - ::comphelper::StringSequence aTest; - if (rItems >>= aTest) - { - const ::rtl::OUString* pStrings = aTest.getConstArray(); - sal_Int32 nItems = aTest.getLength(); - if (nItems) - { - for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings ) - pField->InsertEntry(*pStrings, LISTBOX_APPEND); - - m_rColumn.getModel()->getPropertyValue(FM_PROP_VALUE_SEQ) >>= m_aValueList; - m_bBound = m_aValueList.getLength() > 0; - - // tell the grid control that this controller is invalid and has to be re-initialized - invalidatedController(); - } - } -} - -//------------------------------------------------------------------------------ -void DbListBox::Init( Window& rParent, const Reference< XRowSet >& xCursor) -{ - m_rColumn.SetAlignment(::com::sun::star::awt::TextAlign::LEFT); - - m_pWindow = new ListBoxControl( &rParent ); - - // some initial properties - Reference< XPropertySet > xModel( m_rColumn.getModel() ); - SetList( xModel->getPropertyValue( FM_PROP_STRINGITEMLIST ) ); - implAdjustGenericFieldSetting( xModel ); - - DbCellControl::Init( rParent, xCursor ); -} - -//------------------------------------------------------------------------------ -void DbListBox::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel ) -{ - DBG_ASSERT( m_pWindow, "DbListBox::implAdjustGenericFieldSetting: not to be called without window!" ); - DBG_ASSERT( _rxModel.is(), "DbListBox::implAdjustGenericFieldSetting: invalid model!" ); - if ( m_pWindow && _rxModel.is() ) - { - sal_Int16 nLines = getINT16( _rxModel->getPropertyValue( FM_PROP_LINECOUNT ) ); - static_cast< ListBoxControl* >( m_pWindow )->SetDropDownLineCount( nLines ); - } -} - -//------------------------------------------------------------------------------ -CellControllerRef DbListBox::CreateController() const -{ - return new ListBoxCellController((ListBoxControl*)m_pWindow); -} - -//------------------------------------------------------------------------------ -String DbListBox::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/) -{ - String sText; - if ( _rxField.is() ) - { - try - { - sText = _rxField->getString(); - if ( m_bBound ) - { - Sequence< sal_Int16 > aPosSeq = ::comphelper::findValue( m_aValueList, sText, sal_True ); - if ( aPosSeq.getLength() ) - sText = static_cast<ListBox*>(m_pWindow)->GetEntry(aPosSeq.getConstArray()[0]); - else - sText = String(); - } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - return sText; -} - -//------------------------------------------------------------------------------ -void DbListBox::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter) -{ - String sFormattedText( GetFormatText( _rxField, xFormatter ) ); - if ( sFormattedText.Len() ) - static_cast< ListBox* >( m_pWindow )->SelectEntry( sFormattedText ); - else - static_cast< ListBox* >( m_pWindow )->SetNoSelection(); -} - -//------------------------------------------------------------------------------ -void DbListBox::updateFromModel( Reference< XPropertySet > _rxModel ) -{ - OSL_ENSURE( _rxModel.is() && m_pWindow, "DbListBox::updateFromModel: invalid call!" ); - - Sequence< sal_Int16 > aSelection; - _rxModel->getPropertyValue( FM_PROP_SELECT_SEQ ); - - sal_Int16 nSelection = -1; - if ( aSelection.getLength() > 0 ) - nSelection = aSelection[ 0 ]; - - ListBox* pListBox = static_cast< ListBox* >( m_pWindow ); - - if ( ( nSelection >= 0 ) && ( nSelection < pListBox->GetEntryCount() ) ) - pListBox->SelectEntryPos( nSelection ); - else - pListBox->SetNoSelection( ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbListBox::commitControl() -{ - Any aVal; - Sequence<sal_Int16> aSelectSeq; - if (static_cast<ListBox*>(m_pWindow)->GetSelectEntryCount()) - { - aSelectSeq.realloc(1); - *(sal_Int16 *)aSelectSeq.getArray() = (sal_Int16)static_cast<ListBox*>(m_pWindow)->GetSelectEntryPos(); - } - aVal <<= aSelectSeq; - m_rColumn.getModel()->setPropertyValue(FM_PROP_SELECT_SEQ, aVal); - return sal_True; -} - - -DBG_NAME(DbFilterField); -/*************************************************************************/ -DbFilterField::DbFilterField(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,DbGridColumn& _rColumn) - :DbCellControl(_rColumn) - ,OSQLParserClient(_rxORB) - ,m_nControlClass(::com::sun::star::form::FormComponentType::TEXTFIELD) - ,m_bFilterList(sal_False) - ,m_bFilterListFilled(sal_False) - ,m_bBound(sal_False) -{ - DBG_CTOR(DbFilterField,NULL); - - setAlignedController( sal_False ); -} - -//------------------------------------------------------------------------------ -DbFilterField::~DbFilterField() -{ - if (m_nControlClass == ::com::sun::star::form::FormComponentType::CHECKBOX) - ((CheckBoxControl*)m_pWindow)->SetClickHdl( Link() ); - - DBG_DTOR(DbFilterField,NULL); -} - -//------------------------------------------------------------------------------ -void DbFilterField::PaintCell(OutputDevice& rDev, const Rectangle& rRect) -{ - static sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_VCENTER | TEXT_DRAW_LEFT; - switch (m_nControlClass) - { - case FormComponentType::CHECKBOX: - DbCellControl::PaintCell( rDev, rRect ); - break; - case FormComponentType::LISTBOX: - rDev.DrawText(rRect, static_cast<ListBox*>(m_pWindow)->GetSelectEntry(), nStyle); - break; - default: - rDev.DrawText(rRect, m_aText, nStyle); - } -} - -//------------------------------------------------------------------------------ -void DbFilterField::SetList(const Any& rItems, sal_Bool bComboBox) -{ - ::comphelper::StringSequence aTest; - rItems >>= aTest; - const ::rtl::OUString* pStrings = aTest.getConstArray(); - sal_Int32 nItems = aTest.getLength(); - if (nItems) - { - if (bComboBox) - { - ComboBox* pField = (ComboBox*)m_pWindow; - for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings ) - pField->InsertEntry(*pStrings, LISTBOX_APPEND); - } - else - { - ListBox* pField = (ListBox*)m_pWindow; - for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings ) - pField->InsertEntry(*pStrings, LISTBOX_APPEND); - - m_rColumn.getModel()->getPropertyValue(FM_PROP_VALUE_SEQ) >>= m_aValueList; - m_bBound = m_aValueList.getLength() > 0; - } - } -} - -//------------------------------------------------------------------------------ -void DbFilterField::CreateControl(Window* pParent, const Reference< ::com::sun::star::beans::XPropertySet >& xModel) -{ - switch (m_nControlClass) - { - case ::com::sun::star::form::FormComponentType::CHECKBOX: - m_pWindow = new CheckBoxControl(pParent); - m_pWindow->SetPaintTransparent( sal_True ); - ((CheckBoxControl*)m_pWindow)->SetClickHdl( LINK( this, DbFilterField, OnClick ) ); - - m_pPainter = new CheckBoxControl(pParent); - m_pPainter->SetPaintTransparent( sal_True ); - m_pPainter->SetBackground(); - break; - case ::com::sun::star::form::FormComponentType::LISTBOX: - { - m_pWindow = new ListBoxControl(pParent); - sal_Int16 nLines = ::comphelper::getINT16(xModel->getPropertyValue(FM_PROP_LINECOUNT)); - Any aItems = xModel->getPropertyValue(FM_PROP_STRINGITEMLIST); - SetList(aItems, m_nControlClass == ::com::sun::star::form::FormComponentType::COMBOBOX); - static_cast<ListBox*>(m_pWindow)->SetDropDownLineCount(nLines); - } break; - case ::com::sun::star::form::FormComponentType::COMBOBOX: - { - m_pWindow = new ComboBoxControl(pParent); - - AllSettings aSettings = m_pWindow->GetSettings(); - StyleSettings aStyleSettings = aSettings.GetStyleSettings(); - aStyleSettings.SetSelectionOptions( - aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST); - aSettings.SetStyleSettings(aStyleSettings); - m_pWindow->SetSettings(aSettings, sal_True); - - if (!m_bFilterList) - { - sal_Int16 nLines = ::comphelper::getINT16(xModel->getPropertyValue(FM_PROP_LINECOUNT)); - Any aItems = xModel->getPropertyValue(FM_PROP_STRINGITEMLIST); - SetList(aItems, m_nControlClass == ::com::sun::star::form::FormComponentType::COMBOBOX); - ((ComboBox*)m_pWindow)->SetDropDownLineCount(nLines); - } - else - ((ComboBox*)m_pWindow)->SetDropDownLineCount(5); - - } break; - default: - { - m_pWindow = new Edit(pParent, WB_LEFT); - AllSettings aSettings = m_pWindow->GetSettings(); - StyleSettings aStyleSettings = aSettings.GetStyleSettings(); - aStyleSettings.SetSelectionOptions( - aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST); - aSettings.SetStyleSettings(aStyleSettings); - m_pWindow->SetSettings(aSettings, sal_True); - } - } -} - -//------------------------------------------------------------------------------ -void DbFilterField::Init( Window& rParent, const Reference< XRowSet >& xCursor ) -{ - Reference< ::com::sun::star::beans::XPropertySet > xModel(m_rColumn.getModel()); - m_rColumn.SetAlignment(::com::sun::star::awt::TextAlign::LEFT); - - if (xModel.is()) - { - m_bFilterList = ::comphelper::hasProperty(FM_PROP_FILTERPROPOSAL, xModel) && ::comphelper::getBOOL(xModel->getPropertyValue(FM_PROP_FILTERPROPOSAL)); - if (m_bFilterList) - m_nControlClass = ::com::sun::star::form::FormComponentType::COMBOBOX; - else - { - sal_Int16 nClassId = ::comphelper::getINT16(xModel->getPropertyValue(FM_PROP_CLASSID)); - switch (nClassId) - { - case FormComponentType::CHECKBOX: - case FormComponentType::LISTBOX: - case FormComponentType::COMBOBOX: - m_nControlClass = nClassId; - break; - default: - if (m_bFilterList) - m_nControlClass = FormComponentType::COMBOBOX; - else - m_nControlClass = FormComponentType::TEXTFIELD; - } - } - } - - CreateControl( &rParent, xModel ); - DbCellControl::Init( rParent, xCursor ); - - // filter cells are never readonly - Edit* pAsEdit = dynamic_cast< Edit* >( m_pWindow ); - if ( pAsEdit ) - pAsEdit->SetReadOnly( sal_False ); -} - -//------------------------------------------------------------------------------ -CellControllerRef DbFilterField::CreateController() const -{ - CellControllerRef xController; - switch (m_nControlClass) - { - case ::com::sun::star::form::FormComponentType::CHECKBOX: - xController = new CheckBoxCellController((CheckBoxControl*)m_pWindow); - break; - case ::com::sun::star::form::FormComponentType::LISTBOX: - xController = new ListBoxCellController((ListBoxControl*)m_pWindow); - break; - case ::com::sun::star::form::FormComponentType::COMBOBOX: - xController = new ComboBoxCellController((ComboBoxControl*)m_pWindow); - break; - default: - if (m_bFilterList) - xController = new ComboBoxCellController((ComboBoxControl*)m_pWindow); - else - xController = new EditCellController((Edit*)m_pWindow); - } - return xController; -} - -//------------------------------------------------------------------------------ -void DbFilterField::updateFromModel( Reference< XPropertySet > _rxModel ) -{ - OSL_ENSURE( _rxModel.is() && m_pWindow, "DbFilterField::updateFromModel: invalid call!" ); - (void)_rxModel; - - OSL_FAIL( "DbListBox::updateFromModel: not implemented yet (how the hell did you reach this?)!" ); - // TODO: implement this. - // remember: updateFromModel should be some kind of opposite of commitControl -} - -//------------------------------------------------------------------------------ -sal_Bool DbFilterField::commitControl() -{ - String aText(m_aText); - switch (m_nControlClass) - { - case ::com::sun::star::form::FormComponentType::CHECKBOX: - return sal_True; - case ::com::sun::star::form::FormComponentType::LISTBOX: - aText.Erase(); - if (static_cast<ListBox*>(m_pWindow)->GetSelectEntryCount()) - { - sal_Int16 nPos = (sal_Int16)static_cast<ListBox*>(m_pWindow)->GetSelectEntryPos(); - if ( ( nPos >= 0 ) && ( nPos < m_aValueList.getLength() ) ) - aText = (const sal_Unicode*)m_aValueList.getConstArray()[nPos]; - } - - if (m_aText != aText) - { - m_aText = aText; - m_aCommitLink.Call(this); - } - return sal_True; - default: - aText = m_pWindow->GetText(); - } - - if (m_aText != aText) - { - // check the text with the SQL-Parser - String aNewText(aText); - aNewText.EraseTrailingChars(); - if (aNewText.Len() != 0) - { - ::rtl::OUString aErrorMsg; - Reference< XNumberFormatter > xNumberFormatter(m_rColumn.GetParent().getNumberFormatter()); - - ::rtl::Reference< ISQLParseNode > xParseNode = predicateTree(aErrorMsg, aNewText,xNumberFormatter, m_rColumn.GetField()); - if (xParseNode.is()) - { - ::rtl::OUString aPreparedText; - - ::com::sun::star::lang::Locale aAppLocale = Application::GetSettings().GetUILocale(); - - Reference< XRowSet > xDataSourceRowSet( - (Reference< XInterface >)*m_rColumn.GetParent().getDataSource(), UNO_QUERY); - Reference< XConnection > xConnection(getRowSetConnection(xDataSourceRowSet)); - - xParseNode->parseNodeToPredicateStr(aPreparedText, - xConnection, - xNumberFormatter, - m_rColumn.GetField(),aAppLocale,'.', - getParseContext()); - m_aText = aPreparedText; - } - else - { - // display the error and return sal_False - String aTitle( SVX_RES(RID_STR_SYNTAXERROR) ); - - SQLException aError; - aError.Message = aErrorMsg; - displayException(aError, m_pWindow->GetParent()); - // TODO: transport the title - - return sal_False; - } - } - else - m_aText = aText; - - m_pWindow->SetText(m_aText); - m_aCommitLink.Call(this); - } - return sal_True; -} - -//------------------------------------------------------------------------------ -void DbFilterField::SetText(const String& rText) -{ - m_aText = rText; - switch (m_nControlClass) - { - case ::com::sun::star::form::FormComponentType::CHECKBOX: - { - TriState eState; - if (rText.EqualsAscii("1")) - eState = STATE_CHECK; - else if (rText.EqualsAscii("0")) - eState = STATE_NOCHECK; - else - eState = STATE_DONTKNOW; - - ((CheckBoxControl*)m_pWindow)->GetBox().SetState(eState); - ((CheckBoxControl*)m_pPainter)->GetBox().SetState(eState); - } break; - case ::com::sun::star::form::FormComponentType::LISTBOX: - { - String aText; - Sequence<sal_Int16> aPosSeq = ::comphelper::findValue(m_aValueList, m_aText, sal_True); - if (aPosSeq.getLength()) - static_cast<ListBox*>(m_pWindow)->SelectEntryPos(aPosSeq.getConstArray()[0], sal_True); - else - static_cast<ListBox*>(m_pWindow)->SetNoSelection(); - } break; - default: - m_pWindow->SetText(m_aText); - } - - // now force a repaint on the window - m_rColumn.GetParent().RowModified(0,m_rColumn.GetId()); -} - -//------------------------------------------------------------------------------ -void DbFilterField::Update() -{ - // should we fill the combobox with a filter proposal? - if (m_bFilterList && !m_bFilterListFilled) - { - m_bFilterListFilled = sal_True; - Reference< ::com::sun::star::beans::XPropertySet > xField = m_rColumn.GetField(); - if (!xField.is()) - return; - - ::rtl::OUString aName; - xField->getPropertyValue(FM_PROP_NAME) >>= aName; - - // the columnmodel - Reference< ::com::sun::star::container::XChild > xModelAsChild(m_rColumn.getModel(), UNO_QUERY); - // the grid model - xModelAsChild = Reference< ::com::sun::star::container::XChild > (xModelAsChild->getParent(),UNO_QUERY); - Reference< XRowSet > xForm(xModelAsChild->getParent(), UNO_QUERY); - if (!xForm.is()) - return; - - Reference<XPropertySet> xFormProp(xForm,UNO_QUERY); - Reference< XTablesSupplier > xSupTab; - xFormProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSupTab; - - Reference< XConnection > xConnection(getRowSetConnection(xForm)); - if (!xSupTab.is()) - return; - - // search the field - Reference< XColumnsSupplier > xSupCol(xSupTab,UNO_QUERY); - Reference< ::com::sun::star::container::XNameAccess > xFieldNames = xSupCol->getColumns(); - if (!xFieldNames->hasByName(aName)) - return; - - Reference< ::com::sun::star::container::XNameAccess > xTablesNames = xSupTab->getTables(); - Reference< ::com::sun::star::beans::XPropertySet > xComposerFieldAsSet(xFieldNames->getByName(aName),UNO_QUERY); - - if (xComposerFieldAsSet.is() && ::comphelper::hasProperty(FM_PROP_TABLENAME, xComposerFieldAsSet) && - ::comphelper::hasProperty(FM_PROP_FIELDSOURCE, xComposerFieldAsSet)) - { - ::rtl::OUString aFieldName; - ::rtl::OUString aTableName; - xComposerFieldAsSet->getPropertyValue(FM_PROP_FIELDSOURCE) >>= aFieldName; - xComposerFieldAsSet->getPropertyValue(FM_PROP_TABLENAME) >>= aTableName; - - // no possibility to create a select statement - // looking for the complete table name - if (!xTablesNames->hasByName(aTableName)) - return; - - // ein Statement aufbauen und abschicken als query - // Access to the connection - Reference< XStatement > xStatement; - Reference< XResultSet > xListCursor; - Reference< ::com::sun::star::sdb::XColumn > xDataField; - - try - { - Reference< XDatabaseMetaData > xMeta = xConnection->getMetaData(); - - String aQuote( xMeta->getIdentifierQuoteString()); - String aStatement; - aStatement.AssignAscii("SELECT DISTINCT "); - - aStatement += String(quoteName(aQuote, aName)); - if (aFieldName.getLength() && aName != aFieldName) - { - aStatement.AppendAscii(" AS "); - aStatement += quoteName(aQuote, aFieldName).getStr(); - } - - aStatement.AppendAscii(" FROM "); - - Reference< XPropertySet > xTableNameAccess( xTablesNames->getByName(aTableName), UNO_QUERY_THROW ); - aStatement += composeTableNameForSelect( xConnection, xTableNameAccess ).getStr(); - - xStatement = xConnection->createStatement(); - Reference< ::com::sun::star::beans::XPropertySet > xStatementProps(xStatement, UNO_QUERY); - xStatementProps->setPropertyValue(FM_PROP_ESCAPE_PROCESSING, makeAny((sal_Bool)sal_True)); - - xListCursor = xStatement->executeQuery(aStatement); - - Reference< ::com::sun::star::sdbcx::XColumnsSupplier > xSupplyCols(xListCursor, UNO_QUERY); - Reference< ::com::sun::star::container::XIndexAccess > xFields(xSupplyCols->getColumns(), UNO_QUERY); - ::cppu::extractInterface(xDataField, xFields->getByIndex(0)); - if (!xDataField.is()) - return; - } - catch(const Exception&) - { - ::comphelper::disposeComponent(xStatement); - return; - } - - sal_Int16 i = 0; - ::std::vector< ::rtl::OUString > aStringList; - aStringList.reserve(16); - ::rtl::OUString aStr; - com::sun::star::util::Date aNullDate = m_rColumn.GetParent().getNullDate(); - sal_Int32 nFormatKey = m_rColumn.GetKey(); - Reference< XNumberFormatter > xFormatter = m_rColumn.GetParent().getNumberFormatter(); - sal_Int16 nKeyType = ::comphelper::getNumberFormatType(xFormatter->getNumberFormatsSupplier()->getNumberFormats(), nFormatKey); - - while (!xListCursor->isAfterLast() && i++ < SHRT_MAX) // max anzahl eintraege - { - aStr = getFormattedValue(xDataField, xFormatter, aNullDate, nFormatKey, nKeyType); - aStringList.push_back(aStr); - xListCursor->next(); - } - - // filling the entries for the combobox - for (::std::vector< ::rtl::OUString >::const_iterator iter = aStringList.begin(); - iter != aStringList.end(); ++iter) - ((ComboBox*)m_pWindow)->InsertEntry(*iter, LISTBOX_APPEND); - } - } -} - -//------------------------------------------------------------------------------ -XubString DbFilterField::GetFormatText(const Reference< XColumn >& /*_rxField*/, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/) -{ - return XubString(); -} - -//------------------------------------------------------------------ -void DbFilterField::UpdateFromField(const Reference< XColumn >& /*_rxField*/, const Reference< XNumberFormatter >& /*xFormatter*/) -{ - OSL_FAIL( "DbFilterField::UpdateFromField: cannot update a filter control from a field!" ); -} - -//------------------------------------------------------------------ -IMPL_LINK( DbFilterField, OnClick, void*, EMPTYARG ) -{ - TriState eState = ((CheckBoxControl*)m_pWindow)->GetBox().GetState(); - String aText; - - switch (eState) - { - case STATE_CHECK: - aText.AssignAscii("1"); - break; - case STATE_NOCHECK: - aText.AssignAscii("0"); - break; - case STATE_DONTKNOW: - aText = String(); - break; - } - - if (m_aText != aText) - { - m_aText = aText; - m_aCommitLink.Call(this); - } - return 1; -} - -/*************************************************************************/ -TYPEINIT0(FmXGridCell); - - -DBG_NAME(FmXGridCell); -//----------------------------------------------------------------------------- -FmXGridCell::FmXGridCell( DbGridColumn* pColumn, DbCellControl* _pControl ) - :OComponentHelper(m_aMutex) - ,m_pColumn(pColumn) - ,m_pCellControl( _pControl ) - ,m_aWindowListeners( m_aMutex ) - ,m_aFocusListeners( m_aMutex ) - ,m_aKeyListeners( m_aMutex ) - ,m_aMouseListeners( m_aMutex ) - ,m_aMouseMotionListeners( m_aMutex ) -{ - DBG_CTOR(FmXGridCell,NULL); -} - -//----------------------------------------------------------------------------- -void FmXGridCell::init() -{ - Window* pEventWindow( getEventWindow() ); - if ( pEventWindow ) - pEventWindow->AddEventListener( LINK( this, FmXGridCell, OnWindowEvent ) ); -} - -//----------------------------------------------------------------------------- -Window* FmXGridCell::getEventWindow() const -{ - if ( m_pCellControl ) - return &m_pCellControl->GetWindow(); - return NULL; -} - -//----------------------------------------------------------------------------- -FmXGridCell::~FmXGridCell() -{ - if (!OComponentHelper::rBHelper.bDisposed) - { - acquire(); - dispose(); - } - - DBG_DTOR(FmXGridCell,NULL); -} - -//------------------------------------------------------------------ -void FmXGridCell::SetTextLineColor() -{ - if (m_pCellControl) - m_pCellControl->SetTextLineColor(); -} - -//------------------------------------------------------------------ -void FmXGridCell::SetTextLineColor(const Color& _rColor) -{ - if (m_pCellControl) - m_pCellControl->SetTextLineColor(_rColor); -} - -// XTypeProvider -//------------------------------------------------------------------ -Sequence< Type > SAL_CALL FmXGridCell::getTypes( ) throw (RuntimeException) -{ - Sequence< uno::Type > aTypes = ::comphelper::concatSequences( - ::cppu::OComponentHelper::getTypes(), - FmXGridCell_Base::getTypes() - ); - if ( m_pCellControl ) - aTypes = ::comphelper::concatSequences( - aTypes, - FmXGridCell_WindowBase::getTypes() - ); - return aTypes; -} - -//------------------------------------------------------------------ -IMPLEMENT_GET_IMPLEMENTATION_ID( FmXGridCell ) - -// OComponentHelper -//----------------------------------------------------------------------------- -void FmXGridCell::disposing() -{ - lang::EventObject aEvent( *this ); - m_aWindowListeners.disposeAndClear( aEvent ); - m_aFocusListeners.disposeAndClear( aEvent ); - m_aKeyListeners.disposeAndClear( aEvent ); - m_aMouseListeners.disposeAndClear( aEvent ); - m_aMouseMotionListeners.disposeAndClear( aEvent ); - - OComponentHelper::disposing(); - m_pColumn = NULL; - DELETEZ(m_pCellControl); -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXGridCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException) -{ - Any aReturn = OComponentHelper::queryAggregation( _rType ); - - if ( !aReturn.hasValue() ) - aReturn = FmXGridCell_Base::queryInterface( _rType ); - - if ( !aReturn.hasValue() && ( m_pCellControl != NULL ) ) - aReturn = FmXGridCell_WindowBase::queryInterface( _rType ); - - return aReturn; -} - -// ::com::sun::star::awt::XControl -//----------------------------------------------------------------------------- -Reference< XInterface > FmXGridCell::getContext() throw( RuntimeException ) -{ - return Reference< XInterface > (); -} - -//----------------------------------------------------------------------------- -Reference< ::com::sun::star::awt::XControlModel > FmXGridCell::getModel() throw( ::com::sun::star::uno::RuntimeException ) -{ - return Reference< ::com::sun::star::awt::XControlModel > (m_pColumn->getModel(), UNO_QUERY); -} - -// ::com::sun::star::form::XBoundControl -//------------------------------------------------------------------ -sal_Bool FmXGridCell::getLock() throw( RuntimeException ) -{ - return m_pColumn->isLocked(); -} - -//------------------------------------------------------------------ -void FmXGridCell::setLock(sal_Bool _bLock) throw( RuntimeException ) -{ - if (getLock() == _bLock) - return; - else - { - ::osl::MutexGuard aGuard(m_aMutex); - m_pColumn->setLock(_bLock); - } -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::setPosSize( ::sal_Int32 _XX, ::sal_Int32 _Y, ::sal_Int32 _Width, ::sal_Int32 _Height, ::sal_Int16 _Flags ) throw (RuntimeException) -{ - OSL_FAIL( "FmXGridCell::setPosSize: not implemented" ); - (void)_XX; - (void)_Y; - (void)_Width; - (void)_Height; - (void)_Flags; - // not allowed to tamper with this for a grid cell -} - -//------------------------------------------------------------------ -awt::Rectangle SAL_CALL FmXGridCell::getPosSize( ) throw (RuntimeException) -{ - OSL_FAIL( "FmXGridCell::getPosSize: not implemented" ); - return awt::Rectangle(); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::setVisible( ::sal_Bool _Visible ) throw (RuntimeException) -{ - OSL_FAIL( "FmXGridCell::setVisible: not implemented" ); - (void)_Visible; - // not allowed to tamper with this for a grid cell -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::setEnable( ::sal_Bool _Enable ) throw (RuntimeException) -{ - OSL_FAIL( "FmXGridCell::setEnable: not implemented" ); - (void)_Enable; - // not allowed to tamper with this for a grid cell -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::setFocus( ) throw (RuntimeException) -{ - OSL_FAIL( "FmXGridCell::setFocus: not implemented" ); - // not allowed to tamper with this for a grid cell -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::addWindowListener( const Reference< awt::XWindowListener >& _rxListener ) throw (RuntimeException) -{ - m_aWindowListeners.addInterface( _rxListener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::removeWindowListener( const Reference< awt::XWindowListener >& _rxListener ) throw (RuntimeException) -{ - m_aWindowListeners.removeInterface( _rxListener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::addFocusListener( const Reference< awt::XFocusListener >& _rxListener ) throw (RuntimeException) -{ - m_aFocusListeners.addInterface( _rxListener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::removeFocusListener( const Reference< awt::XFocusListener >& _rxListener ) throw (RuntimeException) -{ - m_aFocusListeners.removeInterface( _rxListener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::addKeyListener( const Reference< awt::XKeyListener >& _rxListener ) throw (RuntimeException) -{ - m_aKeyListeners.addInterface( _rxListener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::removeKeyListener( const Reference< awt::XKeyListener >& _rxListener ) throw (RuntimeException) -{ - m_aKeyListeners.removeInterface( _rxListener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::addMouseListener( const Reference< awt::XMouseListener >& _rxListener ) throw (RuntimeException) -{ - m_aMouseListeners.addInterface( _rxListener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::removeMouseListener( const Reference< awt::XMouseListener >& _rxListener ) throw (RuntimeException) -{ - m_aMouseListeners.removeInterface( _rxListener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::addMouseMotionListener( const Reference< awt::XMouseMotionListener >& _rxListener ) throw (RuntimeException) -{ - m_aMouseMotionListeners.addInterface( _rxListener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::removeMouseMotionListener( const Reference< awt::XMouseMotionListener >& _rxListener ) throw (RuntimeException) -{ - m_aMouseMotionListeners.removeInterface( _rxListener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::addPaintListener( const Reference< awt::XPaintListener >& _rxListener ) throw (RuntimeException) -{ - OSL_FAIL( "FmXGridCell::addPaintListener: not implemented" ); - (void)_rxListener; -} - -//------------------------------------------------------------------ -void SAL_CALL FmXGridCell::removePaintListener( const Reference< awt::XPaintListener >& _rxListener ) throw (RuntimeException) -{ - OSL_FAIL( "FmXGridCell::removePaintListener: not implemented" ); - (void)_rxListener; -} - -//------------------------------------------------------------------ -IMPL_LINK( FmXGridCell, OnWindowEvent, VclWindowEvent*, _pEvent ) -{ - ENSURE_OR_THROW( _pEvent, "illegal event pointer" ); - ENSURE_OR_THROW( _pEvent->GetWindow(), "illegal window" ); - onWindowEvent( _pEvent->GetId(), *_pEvent->GetWindow(), _pEvent->GetData() ); - return 1L; -} - -//------------------------------------------------------------------------------ -void FmXGridCell::onFocusGained( const awt::FocusEvent& _rEvent ) -{ - m_aFocusListeners.notifyEach( &awt::XFocusListener::focusGained, _rEvent ); -} - -//------------------------------------------------------------------------------ -void FmXGridCell::onFocusLost( const awt::FocusEvent& _rEvent ) -{ - m_aFocusListeners.notifyEach( &awt::XFocusListener::focusLost, _rEvent ); -} - -//------------------------------------------------------------------------------ -void FmXGridCell::onWindowEvent( const sal_uIntPtr _nEventId, const Window& _rWindow, const void* _pEventData ) -{ - switch ( _nEventId ) - { - case VCLEVENT_CONTROL_GETFOCUS: - case VCLEVENT_WINDOW_GETFOCUS: - case VCLEVENT_CONTROL_LOSEFOCUS: - case VCLEVENT_WINDOW_LOSEFOCUS: - { - if ( ( _rWindow.IsCompoundControl() - && ( _nEventId == VCLEVENT_CONTROL_GETFOCUS - || _nEventId == VCLEVENT_CONTROL_LOSEFOCUS - ) - ) - || ( !_rWindow.IsCompoundControl() - && ( _nEventId == VCLEVENT_WINDOW_GETFOCUS - || _nEventId == VCLEVENT_WINDOW_LOSEFOCUS - ) - ) - ) - { - if ( !m_aFocusListeners.getLength() ) - break; - - bool bFocusGained = ( _nEventId == VCLEVENT_CONTROL_GETFOCUS ) || ( _nEventId == VCLEVENT_WINDOW_GETFOCUS ); - - awt::FocusEvent aEvent; - aEvent.Source = *this; - aEvent.FocusFlags = _rWindow.GetGetFocusFlags(); - aEvent.Temporary = sal_False; - - if ( bFocusGained ) - onFocusGained( aEvent ); - else - onFocusLost( aEvent ); - } - } - break; - case VCLEVENT_WINDOW_MOUSEBUTTONDOWN: - case VCLEVENT_WINDOW_MOUSEBUTTONUP: - { - if ( !m_aMouseListeners.getLength() ) - break; - - const bool bButtonDown = ( _nEventId == VCLEVENT_WINDOW_MOUSEBUTTONDOWN ); - - awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *static_cast< const ::MouseEvent* >( _pEventData ), *this ) ); - m_aMouseListeners.notifyEach( bButtonDown ? &awt::XMouseListener::mousePressed : &awt::XMouseListener::mouseReleased, aEvent ); - } - break; - case VCLEVENT_WINDOW_MOUSEMOVE: - { - const MouseEvent& rMouseEvent = *static_cast< const ::MouseEvent* >( _pEventData ); - if ( rMouseEvent.IsEnterWindow() || rMouseEvent.IsLeaveWindow() ) - { - if ( m_aMouseListeners.getLength() != 0 ) - { - awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( rMouseEvent, *this ) ); - m_aMouseListeners.notifyEach( rMouseEvent.IsEnterWindow() ? &awt::XMouseListener::mouseEntered: &awt::XMouseListener::mouseExited, aEvent ); - } - } - else if ( !rMouseEvent.IsEnterWindow() && !rMouseEvent.IsLeaveWindow() ) - { - if ( m_aMouseMotionListeners.getLength() != 0 ) - { - awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( rMouseEvent, *this ) ); - aEvent.ClickCount = 0; - const bool bSimpleMove = ( ( rMouseEvent.GetMode() & MOUSE_SIMPLEMOVE ) != 0 ); - m_aMouseMotionListeners.notifyEach( bSimpleMove ? &awt::XMouseMotionListener::mouseMoved: &awt::XMouseMotionListener::mouseDragged, aEvent ); - } - } - } - break; - case VCLEVENT_WINDOW_KEYINPUT: - case VCLEVENT_WINDOW_KEYUP: - { - if ( !m_aKeyListeners.getLength() ) - break; - - const bool bKeyPressed = ( _nEventId == VCLEVENT_WINDOW_KEYINPUT ); - awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent( *static_cast< const ::KeyEvent* >( _pEventData ), *this ) ); - m_aKeyListeners.notifyEach( bKeyPressed ? &awt::XKeyListener::keyPressed: &awt::XKeyListener::keyReleased, aEvent ); - } - break; - } -} - -/*************************************************************************/ -TYPEINIT1(FmXDataCell, FmXGridCell); -//------------------------------------------------------------------------------ -void FmXDataCell::PaintFieldToCell(OutputDevice& rDev, const Rectangle& rRect, - const Reference< ::com::sun::star::sdb::XColumn >& _rxField, - const Reference< XNumberFormatter >& xFormatter) -{ - m_pCellControl->PaintFieldToCell( rDev, rRect, _rxField, xFormatter ); -} - -//------------------------------------------------------------------------------ -void FmXDataCell::UpdateFromColumn() -{ - Reference< ::com::sun::star::sdb::XColumn > xField(m_pColumn->GetCurrentFieldValue()); - if (xField.is()) - m_pCellControl->UpdateFromField(xField, m_pColumn->GetParent().getNumberFormatter()); -} - -/*************************************************************************/ -TYPEINIT1(FmXTextCell, FmXDataCell); - -FmXTextCell::FmXTextCell( DbGridColumn* pColumn, DbCellControl& _rControl ) - :FmXDataCell( pColumn, _rControl ) - ,m_bFastPaint( sal_True ) -{ -} - -//------------------------------------------------------------------------------ -void FmXTextCell::PaintFieldToCell(OutputDevice& rDev, - const Rectangle& rRect, - const Reference< ::com::sun::star::sdb::XColumn >& _rxField, - const Reference< XNumberFormatter >& xFormatter) -{ - if ( !m_bFastPaint ) - { - FmXDataCell::PaintFieldToCell( rDev, rRect, _rxField, xFormatter ); - return; - } - - sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_VCENTER; - if ( ( rDev.GetOutDevType() == OUTDEV_WINDOW ) && !static_cast< Window& >( rDev ).IsEnabled() ) - nStyle |= TEXT_DRAW_DISABLE; - - switch (m_pColumn->GetAlignment()) - { - case ::com::sun::star::awt::TextAlign::RIGHT: - nStyle |= TEXT_DRAW_RIGHT; - break; - case ::com::sun::star::awt::TextAlign::CENTER: - nStyle |= TEXT_DRAW_CENTER; - break; - default: - nStyle |= TEXT_DRAW_LEFT; - } - - Color* pColor = NULL; - String aText = GetText(_rxField, xFormatter, &pColor); - if (pColor != NULL) - { - Color aOldTextColor( rDev.GetTextColor() ); - rDev.SetTextColor( *pColor ); - rDev.DrawText(rRect, aText, nStyle); - rDev.SetTextColor( aOldTextColor ); - } - else - rDev.DrawText(rRect, aText, nStyle); -} - - -/*************************************************************************/ - -DBG_NAME(FmXEditCell); -//------------------------------------------------------------------------------ -FmXEditCell::FmXEditCell( DbGridColumn* pColumn, DbCellControl& _rControl ) - :FmXTextCell( pColumn, _rControl ) - ,m_aTextListeners(m_aMutex) - ,m_aChangeListeners( m_aMutex ) - ,m_pEditImplementation( NULL ) - ,m_bOwnEditImplementation( false ) -{ - DBG_CTOR(FmXEditCell,NULL); - - DbTextField* pTextField = PTR_CAST( DbTextField, &_rControl ); - if ( pTextField ) - { - - m_pEditImplementation = pTextField->GetEditImplementation(); - if ( !pTextField->IsSimpleEdit() ) - m_bFastPaint = sal_False; - } - else - { - m_pEditImplementation = new EditImplementation( static_cast< Edit& >( _rControl.GetWindow() ) ); - m_bOwnEditImplementation = true; - } -} - -//------------------------------------------------------------------ -FmXEditCell::~FmXEditCell() -{ - if (!OComponentHelper::rBHelper.bDisposed) - { - acquire(); - dispose(); - } - - - DBG_DTOR(FmXEditCell,NULL); -} - -// OComponentHelper -//----------------------------------------------------------------------------- -void FmXEditCell::disposing() -{ - ::com::sun::star::lang::EventObject aEvt(*this); - m_aTextListeners.disposeAndClear(aEvt); - m_aChangeListeners.disposeAndClear(aEvt); - - m_pEditImplementation->SetModifyHdl( Link() ); - if ( m_bOwnEditImplementation ) - delete m_pEditImplementation; - m_pEditImplementation = NULL; - - FmXDataCell::disposing(); -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXEditCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException) -{ - Any aReturn = FmXTextCell::queryAggregation( _rType ); - - if ( !aReturn.hasValue() ) - aReturn = FmXEditCell_Base::queryInterface( _rType ); - - return aReturn; -} - -//------------------------------------------------------------------------- -Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXEditCell::getTypes( ) throw(RuntimeException) -{ - return ::comphelper::concatSequences( - FmXTextCell::getTypes(), - FmXEditCell_Base::getTypes() - ); -} - -//------------------------------------------------------------------------------ -IMPLEMENT_GET_IMPLEMENTATION_ID( FmXEditCell ) - -// ::com::sun::star::awt::XTextComponent -//------------------------------------------------------------------------------ -void SAL_CALL FmXEditCell::addTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException ) -{ - m_aTextListeners.addInterface( l ); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXEditCell::removeTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException ) -{ - m_aTextListeners.removeInterface( l ); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXEditCell::setText( const ::rtl::OUString& aText ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pEditImplementation ) - { - m_pEditImplementation->SetText( aText ); - - // In JAVA wird auch ein textChanged ausgeloest, in VCL nicht. - // ::com::sun::star::awt::Toolkit soll JAVA-komform sein... - onTextChanged(); - } -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXEditCell::insertText(const ::com::sun::star::awt::Selection& rSel, const ::rtl::OUString& aText) throw(RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pEditImplementation ) - { - m_pEditImplementation->SetSelection( Selection( rSel.Min, rSel.Max ) ); - m_pEditImplementation->ReplaceSelected( aText ); - } -} - -//------------------------------------------------------------------------------ -::rtl::OUString SAL_CALL FmXEditCell::getText() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - ::rtl::OUString aText; - if ( m_pEditImplementation ) - { - if ( m_pEditImplementation->GetControl().IsVisible() && m_pColumn->GetParent().getDisplaySynchron()) - { - // if the display isn't sync with the cursor we can't ask the edit field - LineEnd eLineEndFormat = m_pColumn ? getModelLineEndSetting( m_pColumn->getModel() ) : LINEEND_LF; - aText = m_pEditImplementation->GetText( eLineEndFormat ); - } - else - { - Reference< ::com::sun::star::sdb::XColumn > xField(m_pColumn->GetCurrentFieldValue()); - if (xField.is()) - aText = GetText(xField, m_pColumn->GetParent().getNumberFormatter()); - } - } - return aText; -} - -//------------------------------------------------------------------------------ -::rtl::OUString SAL_CALL FmXEditCell::getSelectedText( void ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - ::rtl::OUString aText; - if ( m_pEditImplementation ) - { - LineEnd eLineEndFormat = m_pColumn ? getModelLineEndSetting( m_pColumn->getModel() ) : LINEEND_LF; - aText = m_pEditImplementation->GetSelected( eLineEndFormat ); - } - return aText; -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXEditCell::setSelection( const ::com::sun::star::awt::Selection& aSelection ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pEditImplementation ) - m_pEditImplementation->SetSelection( Selection( aSelection.Min, aSelection.Max ) ); -} - -//------------------------------------------------------------------------------ -::com::sun::star::awt::Selection SAL_CALL FmXEditCell::getSelection( void ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - Selection aSel; - if ( m_pEditImplementation ) - aSel = m_pEditImplementation->GetSelection(); - - return ::com::sun::star::awt::Selection(aSel.Min(), aSel.Max()); -} - -//------------------------------------------------------------------------------ -sal_Bool SAL_CALL FmXEditCell::isEditable( void ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - return ( m_pEditImplementation && !m_pEditImplementation->IsReadOnly() && m_pEditImplementation->GetControl().IsEnabled() ) ? sal_True : sal_False; -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXEditCell::setEditable( sal_Bool bEditable ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pEditImplementation ) - m_pEditImplementation->SetReadOnly( !bEditable ); -} - -//------------------------------------------------------------------------------ -sal_Int16 SAL_CALL FmXEditCell::getMaxTextLen() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - return m_pEditImplementation ? m_pEditImplementation->GetMaxTextLen() : 0; -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXEditCell::setMaxTextLen( sal_Int16 nLen ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pEditImplementation ) - m_pEditImplementation->SetMaxTextLen( nLen ); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXEditCell::addChangeListener( const Reference< form::XChangeListener >& _Listener ) throw (RuntimeException) -{ - m_aChangeListeners.addInterface( _Listener ); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXEditCell::removeChangeListener( const Reference< form::XChangeListener >& _Listener ) throw (RuntimeException) -{ - m_aChangeListeners.removeInterface( _Listener ); -} - -//------------------------------------------------------------------------------ -void FmXEditCell::onTextChanged() -{ - ::com::sun::star::awt::TextEvent aEvent; - aEvent.Source = *this; - m_aTextListeners.notifyEach( &awt::XTextListener::textChanged, aEvent ); -} - -//------------------------------------------------------------------------------ -void FmXEditCell::onFocusGained( const awt::FocusEvent& _rEvent ) -{ - FmXTextCell::onFocusGained( _rEvent ); - m_sValueOnEnter = getText(); -} - -//------------------------------------------------------------------------------ -void FmXEditCell::onFocusLost( const awt::FocusEvent& _rEvent ) -{ - FmXTextCell::onFocusLost( _rEvent ); - - if ( getText() != m_sValueOnEnter ) - { - lang::EventObject aEvent( *this ); - m_aChangeListeners.notifyEach( &XChangeListener::changed, aEvent ); - } -} - -//------------------------------------------------------------------------------ -void FmXEditCell::onWindowEvent( const sal_uIntPtr _nEventId, const Window& _rWindow, const void* _pEventData ) -{ - switch ( _nEventId ) - { - case VCLEVENT_EDIT_MODIFY: - { - if ( m_pEditImplementation && m_aTextListeners.getLength() ) - onTextChanged(); - return; - } - } - - FmXTextCell::onWindowEvent( _nEventId, _rWindow, _pEventData ); -} - -/*************************************************************************/ -DBG_NAME(FmXCheckBoxCell); -//------------------------------------------------------------------------------ -FmXCheckBoxCell::FmXCheckBoxCell( DbGridColumn* pColumn, DbCellControl& _rControl ) - :FmXDataCell( pColumn, _rControl ) - ,m_aItemListeners(m_aMutex) - ,m_aActionListeners( m_aMutex ) - ,m_pBox( & static_cast< CheckBoxControl& >( _rControl.GetWindow() ).GetBox() ) -{ - DBG_CTOR(FmXCheckBoxCell,NULL); -} - -//------------------------------------------------------------------ -FmXCheckBoxCell::~FmXCheckBoxCell() -{ - if (!OComponentHelper::rBHelper.bDisposed) - { - acquire(); - dispose(); - } - - DBG_DTOR(FmXCheckBoxCell,NULL); -} - -// OComponentHelper -//----------------------------------------------------------------------------- -void FmXCheckBoxCell::disposing() -{ - ::com::sun::star::lang::EventObject aEvt(*this); - m_aItemListeners.disposeAndClear(aEvt); - m_aActionListeners.disposeAndClear(aEvt); - - static_cast< CheckBoxControl& >( m_pCellControl->GetWindow() ).SetClickHdl(Link()); - m_pBox = NULL; - - FmXDataCell::disposing(); -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXCheckBoxCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException) -{ - Any aReturn = FmXDataCell::queryAggregation( _rType ); - - if ( !aReturn.hasValue() ) - aReturn = FmXCheckBoxCell_Base::queryInterface( _rType ); - - return aReturn; -} - -//------------------------------------------------------------------------- -Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXCheckBoxCell::getTypes( ) throw(RuntimeException) -{ - return ::comphelper::concatSequences( - FmXDataCell::getTypes(), - FmXCheckBoxCell_Base::getTypes() - ); -} - -//------------------------------------------------------------------------------ -IMPLEMENT_GET_IMPLEMENTATION_ID( FmXCheckBoxCell ) - -//------------------------------------------------------------------ -void SAL_CALL FmXCheckBoxCell::addItemListener( const Reference< ::com::sun::star::awt::XItemListener >& l ) throw( RuntimeException ) -{ - m_aItemListeners.addInterface( l ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXCheckBoxCell::removeItemListener( const Reference< ::com::sun::star::awt::XItemListener >& l ) throw( RuntimeException ) -{ - m_aItemListeners.removeInterface( l ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXCheckBoxCell::setState( short n ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (m_pBox) - { - UpdateFromColumn(); - m_pBox->SetState( (TriState)n ); - } -} - -//------------------------------------------------------------------ -short SAL_CALL FmXCheckBoxCell::getState() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (m_pBox) - { - UpdateFromColumn(); - return (short)m_pBox->GetState(); - } - return STATE_DONTKNOW; -} - -//------------------------------------------------------------------ -void SAL_CALL FmXCheckBoxCell::enableTriState( sal_Bool b ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (m_pBox) - m_pBox->EnableTriState( b ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXCheckBoxCell::addActionListener( const Reference< awt::XActionListener >& _Listener ) throw (RuntimeException) -{ - m_aActionListeners.addInterface( _Listener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXCheckBoxCell::removeActionListener( const Reference< awt::XActionListener >& _Listener ) throw (RuntimeException) -{ - m_aActionListeners.removeInterface( _Listener ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXCheckBoxCell::setLabel( const ::rtl::OUString& _Label ) throw (RuntimeException) -{ - SolarMutexGuard aGuard; - if ( m_pColumn ) - { - DbGridControl& rGrid( m_pColumn->GetParent() ); - rGrid.SetColumnTitle( rGrid.GetColumnId( m_pColumn->GetFieldPos() ), _Label ); - } -} - -//------------------------------------------------------------------ -void SAL_CALL FmXCheckBoxCell::setActionCommand( const ::rtl::OUString& _Command ) throw (RuntimeException) -{ - m_aActionCommand = _Command; -} - -//------------------------------------------------------------------ -Window* FmXCheckBoxCell::getEventWindow() const -{ - return m_pBox; -} - -//------------------------------------------------------------------ -void FmXCheckBoxCell::onWindowEvent( const sal_uIntPtr _nEventId, const Window& _rWindow, const void* _pEventData ) -{ - switch ( _nEventId ) - { - case VCLEVENT_CHECKBOX_TOGGLE: - { - // check boxes are to be committed immediately (this holds for ordinary check box controls in - // documents, and this must hold for check boxes in grid columns, too - // 91210 - 22.08.2001 - frank.schoenheit@sun.com - m_pCellControl->Commit(); - - Reference< XWindow > xKeepAlive( this ); - if ( m_aItemListeners.getLength() && m_pBox ) - { - awt::ItemEvent aEvent; - aEvent.Source = *this; - aEvent.Highlighted = sal_False; - aEvent.Selected = m_pBox->GetState(); - m_aItemListeners.notifyEach( &awt::XItemListener::itemStateChanged, aEvent ); - } - if ( m_aActionListeners.getLength() ) - { - awt::ActionEvent aEvent; - aEvent.Source = *this; - aEvent.ActionCommand = m_aActionCommand; - m_aActionListeners.notifyEach( &awt::XActionListener::actionPerformed, aEvent ); - } - } - break; - - default: - FmXDataCell::onWindowEvent( _nEventId, _rWindow, _pEventData ); - break; - } -} - -/*************************************************************************/ - -DBG_NAME(FmXListBoxCell); -//------------------------------------------------------------------------------ -FmXListBoxCell::FmXListBoxCell(DbGridColumn* pColumn, DbCellControl& _rControl) - :FmXTextCell( pColumn, _rControl ) - ,m_aItemListeners(m_aMutex) - ,m_aActionListeners(m_aMutex) - ,m_pBox( &static_cast< ListBox& >( _rControl.GetWindow() ) ) -{ - DBG_CTOR(FmXListBoxCell,NULL); - - m_pBox->SetDoubleClickHdl( LINK( this, FmXListBoxCell, OnDoubleClick ) ); -} - -//------------------------------------------------------------------ -FmXListBoxCell::~FmXListBoxCell() -{ - if (!OComponentHelper::rBHelper.bDisposed) - { - acquire(); - dispose(); - } - - DBG_DTOR(FmXListBoxCell,NULL); -} - -// OComponentHelper -//----------------------------------------------------------------------------- -void FmXListBoxCell::disposing() -{ - ::com::sun::star::lang::EventObject aEvt(*this); - m_aItemListeners.disposeAndClear(aEvt); - m_aActionListeners.disposeAndClear(aEvt); - - m_pBox->SetSelectHdl( Link() ); - m_pBox->SetDoubleClickHdl( Link() ); - m_pBox = NULL; - - FmXTextCell::disposing(); -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXListBoxCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException) -{ - Any aReturn = FmXTextCell::queryAggregation(_rType); - - if ( !aReturn.hasValue() ) - aReturn = FmXListBoxCell_Base::queryInterface( _rType ); - - return aReturn; -} - -//------------------------------------------------------------------------- -Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXListBoxCell::getTypes( ) throw(RuntimeException) -{ - return ::comphelper::concatSequences( - FmXTextCell::getTypes(), - FmXListBoxCell_Base::getTypes() - ); -} - -//------------------------------------------------------------------------------ -IMPLEMENT_GET_IMPLEMENTATION_ID( FmXListBoxCell ) - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::addItemListener(const Reference< ::com::sun::star::awt::XItemListener >& l) throw( RuntimeException ) -{ - m_aItemListeners.addInterface( l ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::removeItemListener(const Reference< ::com::sun::star::awt::XItemListener >& l) throw( RuntimeException ) -{ - m_aItemListeners.removeInterface( l ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::addActionListener(const Reference< ::com::sun::star::awt::XActionListener >& l) throw( RuntimeException ) -{ - m_aActionListeners.addInterface( l ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::removeActionListener(const Reference< ::com::sun::star::awt::XActionListener >& l) throw( RuntimeException ) -{ - m_aActionListeners.removeInterface( l ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::addItem(const ::rtl::OUString& aItem, sal_Int16 nPos) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if (m_pBox) - m_pBox->InsertEntry( aItem, nPos ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::addItems(const ::comphelper::StringSequence& aItems, sal_Int16 nPos) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if (m_pBox) - { - sal_uInt16 nP = nPos; - for ( sal_uInt16 n = 0; n < aItems.getLength(); n++ ) - { - m_pBox->InsertEntry( aItems.getConstArray()[n], nP ); - if ( nPos != -1 ) // Nicht wenn 0xFFFF, weil LIST_APPEND - nP++; - } - } -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::removeItems(sal_Int16 nPos, sal_Int16 nCount) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if ( m_pBox ) - { - for ( sal_uInt16 n = nCount; n; ) - m_pBox->RemoveEntry( nPos + (--n) ); - } -} - -//------------------------------------------------------------------ -sal_Int16 SAL_CALL FmXListBoxCell::getItemCount() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - return m_pBox ? m_pBox->GetEntryCount() : 0; -} - -//------------------------------------------------------------------ -::rtl::OUString SAL_CALL FmXListBoxCell::getItem(sal_Int16 nPos) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - String aItem; - if (m_pBox) - aItem = m_pBox->GetEntry( nPos ); - return aItem; -} -//------------------------------------------------------------------ -::comphelper::StringSequence SAL_CALL FmXListBoxCell::getItems() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - ::comphelper::StringSequence aSeq; - if (m_pBox) - { - sal_uInt16 nEntries = m_pBox ->GetEntryCount(); - aSeq = ::comphelper::StringSequence( nEntries ); - for ( sal_uInt16 n = nEntries; n; ) - { - --n; - aSeq.getArray()[n] = m_pBox ->GetEntry( n ); - } - } - return aSeq; -} - -//------------------------------------------------------------------ -sal_Int16 SAL_CALL FmXListBoxCell::getSelectedItemPos() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if (m_pBox) - { - UpdateFromColumn(); - return m_pBox->GetSelectEntryPos(); - } - return 0; -} - -//------------------------------------------------------------------ -Sequence< sal_Int16 > SAL_CALL FmXListBoxCell::getSelectedItemsPos() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - Sequence<sal_Int16> aSeq; - - if (m_pBox) - { - UpdateFromColumn(); - sal_uInt16 nSelEntries = m_pBox->GetSelectEntryCount(); - aSeq = Sequence<sal_Int16>( nSelEntries ); - for ( sal_uInt16 n = 0; n < nSelEntries; n++ ) - aSeq.getArray()[n] = m_pBox->GetSelectEntryPos( n ); - } - return aSeq; -} -//------------------------------------------------------------------ -::rtl::OUString SAL_CALL FmXListBoxCell::getSelectedItem() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - String aItem; - if (m_pBox) - { - UpdateFromColumn(); - aItem = m_pBox->GetSelectEntry(); - } - - return aItem; -} - -//------------------------------------------------------------------ -::comphelper::StringSequence SAL_CALL FmXListBoxCell::getSelectedItems() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - ::comphelper::StringSequence aSeq; - - if (m_pBox) - { - UpdateFromColumn(); - sal_uInt16 nSelEntries = m_pBox->GetSelectEntryCount(); - aSeq = ::comphelper::StringSequence( nSelEntries ); - for ( sal_uInt16 n = 0; n < nSelEntries; n++ ) - aSeq.getArray()[n] = m_pBox->GetSelectEntry( n ); - } - return aSeq; -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::selectItemPos(sal_Int16 nPos, sal_Bool bSelect) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (m_pBox) - m_pBox->SelectEntryPos( nPos, bSelect ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::selectItemsPos(const Sequence< sal_Int16 >& aPositions, sal_Bool bSelect) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (m_pBox) - { - for ( sal_uInt16 n = (sal_uInt16)aPositions.getLength(); n; ) - m_pBox->SelectEntryPos( (sal_uInt16) aPositions.getConstArray()[--n], bSelect ); - } -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::selectItem(const ::rtl::OUString& aItem, sal_Bool bSelect) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (m_pBox) - m_pBox->SelectEntry( aItem, bSelect ); -} - -//------------------------------------------------------------------ -sal_Bool SAL_CALL FmXListBoxCell::isMutipleMode() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Bool bMulti = sal_False; - if (m_pBox) - bMulti = m_pBox->IsMultiSelectionEnabled(); - return bMulti; -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::setMultipleMode(sal_Bool bMulti) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (m_pBox) - m_pBox->EnableMultiSelection( bMulti ); -} - -//------------------------------------------------------------------ -sal_Int16 SAL_CALL FmXListBoxCell::getDropDownLineCount() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int16 nLines = 0; - if (m_pBox) - nLines = m_pBox->GetDropDownLineCount(); - - return nLines; -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::setDropDownLineCount(sal_Int16 nLines) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (m_pBox) - m_pBox->SetDropDownLineCount( nLines ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXListBoxCell::makeVisible(sal_Int16 nEntry) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if (m_pBox) - m_pBox->SetTopEntry( nEntry ); -} - -//------------------------------------------------------------------ -void FmXListBoxCell::onWindowEvent( const sal_uIntPtr _nEventId, const Window& _rWindow, const void* _pEventData ) -{ - if ( ( &_rWindow == m_pBox ) - && ( _nEventId == VCLEVENT_LISTBOX_SELECT ) - ) - { - OnDoubleClick( NULL ); - - ::com::sun::star::awt::ItemEvent aEvent; - aEvent.Source = *this; - aEvent.Highlighted = sal_False; - - // Bei Mehrfachselektion 0xFFFF, sonst die ID - aEvent.Selected = (m_pBox->GetSelectEntryCount() == 1 ) - ? m_pBox->GetSelectEntryPos() : 0xFFFF; - - m_aItemListeners.notifyEach( &awt::XItemListener::itemStateChanged, aEvent ); - return; - } - - FmXTextCell::onWindowEvent( _nEventId, _rWindow, _pEventData ); -} - - -//------------------------------------------------------------------ -IMPL_LINK( FmXListBoxCell, OnDoubleClick, void*, EMPTYARG ) -{ - if (m_pBox) - { - ::cppu::OInterfaceIteratorHelper aIt( m_aActionListeners ); - - ::com::sun::star::awt::ActionEvent aEvent; - aEvent.Source = *this; - aEvent.ActionCommand = m_pBox->GetSelectEntry(); - - while( aIt.hasMoreElements() ) - ((::com::sun::star::awt::XActionListener *)aIt.next())->actionPerformed( aEvent ); - } - return 1; -} - - -/*************************************************************************/ - -DBG_NAME( FmXComboBoxCell ); - -//------------------------------------------------------------------------------ -FmXComboBoxCell::FmXComboBoxCell( DbGridColumn* pColumn, DbCellControl& _rControl ) - :FmXTextCell( pColumn, _rControl ) - ,m_aItemListeners( m_aMutex ) - ,m_aActionListeners( m_aMutex ) - ,m_pComboBox( &static_cast< ComboBox& >( _rControl.GetWindow() ) ) -{ - DBG_CTOR( FmXComboBoxCell, NULL ); -} - -//------------------------------------------------------------------------------ -FmXComboBoxCell::~FmXComboBoxCell() -{ - if ( !OComponentHelper::rBHelper.bDisposed ) - { - acquire(); - dispose(); - } - - DBG_DTOR( FmXComboBoxCell, NULL ); -} - -//----------------------------------------------------------------------------- -void FmXComboBoxCell::disposing() -{ - ::com::sun::star::lang::EventObject aEvt(*this); - m_aItemListeners.disposeAndClear(aEvt); - m_aActionListeners.disposeAndClear(aEvt); - - FmXTextCell::disposing(); -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXComboBoxCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException) -{ - Any aReturn = FmXTextCell::queryAggregation(_rType); - - if ( !aReturn.hasValue() ) - aReturn = FmXComboBoxCell_Base::queryInterface( _rType ); - - return aReturn; -} - -//------------------------------------------------------------------------- -Sequence< Type > SAL_CALL FmXComboBoxCell::getTypes( ) throw(RuntimeException) -{ - return ::comphelper::concatSequences( - FmXTextCell::getTypes(), - FmXComboBoxCell_Base::getTypes() - ); -} - -//------------------------------------------------------------------------------ -IMPLEMENT_GET_IMPLEMENTATION_ID( FmXComboBoxCell ) - -//------------------------------------------------------------------ -void SAL_CALL FmXComboBoxCell::addItemListener(const Reference< awt::XItemListener >& l) throw( RuntimeException ) -{ - m_aItemListeners.addInterface( l ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXComboBoxCell::removeItemListener(const Reference< awt::XItemListener >& l) throw( RuntimeException ) -{ - m_aItemListeners.removeInterface( l ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXComboBoxCell::addActionListener(const Reference< awt::XActionListener >& l) throw( RuntimeException ) -{ - m_aActionListeners.addInterface( l ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXComboBoxCell::removeActionListener(const Reference< awt::XActionListener >& l) throw( RuntimeException ) -{ - m_aActionListeners.removeInterface( l ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXComboBoxCell::addItem( const ::rtl::OUString& _Item, sal_Int16 _Pos ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if ( m_pComboBox ) - m_pComboBox->InsertEntry( _Item, _Pos ); -} - -//------------------------------------------------------------------ -void SAL_CALL FmXComboBoxCell::addItems( const Sequence< ::rtl::OUString >& _Items, sal_Int16 _Pos ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if ( m_pComboBox ) - { - sal_uInt16 nP = _Pos; - for ( sal_uInt16 n = 0; n < _Items.getLength(); n++ ) - { - m_pComboBox->InsertEntry( _Items.getConstArray()[n], nP ); - if ( _Pos != -1 ) - nP++; - } - } -} - -//------------------------------------------------------------------ -void SAL_CALL FmXComboBoxCell::removeItems( sal_Int16 _Pos, sal_Int16 _Count ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if ( m_pComboBox ) - { - for ( sal_uInt16 n = _Count; n; ) - m_pComboBox->RemoveEntry( _Pos + (--n) ); - } -} - -//------------------------------------------------------------------ -sal_Int16 SAL_CALL FmXComboBoxCell::getItemCount() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - return m_pComboBox ? m_pComboBox->GetEntryCount() : 0; -} - -//------------------------------------------------------------------ -::rtl::OUString SAL_CALL FmXComboBoxCell::getItem( sal_Int16 _Pos ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - String sItem; - if ( m_pComboBox ) - sItem = m_pComboBox->GetEntry( _Pos ); - return sItem; -} -//------------------------------------------------------------------ -Sequence< ::rtl::OUString > SAL_CALL FmXComboBoxCell::getItems() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - Sequence< ::rtl::OUString > aItems; - if ( m_pComboBox ) - { - sal_uInt16 nEntries = m_pComboBox->GetEntryCount(); - aItems.realloc( nEntries ); - ::rtl::OUString* pItem = aItems.getArray(); - for ( sal_uInt16 n=0; n<nEntries; ++n, ++pItem ) - *pItem = m_pComboBox->GetEntry( n ); - } - return aItems; -} - -//------------------------------------------------------------------ -sal_Int16 SAL_CALL FmXComboBoxCell::getDropDownLineCount() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int16 nLines = 0; - if ( m_pComboBox ) - nLines = m_pComboBox->GetDropDownLineCount(); - - return nLines; -} - -//------------------------------------------------------------------ -void SAL_CALL FmXComboBoxCell::setDropDownLineCount(sal_Int16 nLines) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if ( m_pComboBox ) - m_pComboBox->SetDropDownLineCount( nLines ); -} - -//------------------------------------------------------------------------------ -void FmXComboBoxCell::onWindowEvent( const sal_uIntPtr _nEventId, const Window& _rWindow, const void* _pEventData ) -{ - - switch ( _nEventId ) - { - case VCLEVENT_COMBOBOX_SELECT: - { - awt::ItemEvent aEvent; - aEvent.Source = *this; - aEvent.Highlighted = sal_False; - - // Bei Mehrfachselektion 0xFFFF, sonst die ID - aEvent.Selected = ( m_pComboBox->GetSelectEntryCount() == 1 ) - ? m_pComboBox->GetSelectEntryPos() - : 0xFFFF; - m_aItemListeners.notifyEach( &awt::XItemListener::itemStateChanged, aEvent ); - } - break; - - default: - FmXTextCell::onWindowEvent( _nEventId, _rWindow, _pEventData ); - break; - } -} - -/*************************************************************************/ -TYPEINIT1(FmXFilterCell, FmXGridCell); - -//------------------------------------------------------------------------------ -Reference< XInterface > FmXFilterCell_CreateInstance(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& /*_rxFactory*/) -{ - return *new FmXFilterCell(); -} - -DBG_NAME(FmXFilterCell); -//------------------------------------------------------------------------------ -FmXFilterCell::FmXFilterCell(DbGridColumn* pColumn, DbCellControl* pControl ) - :FmXGridCell( pColumn, pControl ) - ,m_aTextListeners(m_aMutex) -{ - DBG_CTOR(FmXFilterCell,NULL); - - DBG_ASSERT( m_pCellControl->ISA( DbFilterField ), "FmXFilterCell::FmXFilterCell: invalid cell control!" ); - static_cast< DbFilterField* >( m_pCellControl )->SetCommitHdl( LINK( this, FmXFilterCell, OnCommit ) ); -} - -//------------------------------------------------------------------ -FmXFilterCell::~FmXFilterCell() -{ - if (!OComponentHelper::rBHelper.bDisposed) - { - acquire(); - dispose(); - } - - DBG_DTOR(FmXFilterCell,NULL); -} - -// XUnoTunnel -//------------------------------------------------------------------------------ -sal_Int64 SAL_CALL FmXFilterCell::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException) -{ - sal_Int64 nReturn(0); - - if ( (_rIdentifier.getLength() == 16) - && (0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), _rIdentifier.getConstArray(), 16 )) - ) - { - nReturn = reinterpret_cast<sal_Int64>(this); - } - - return nReturn; -} - -namespace -{ - class theFmXFilterCellUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theFmXFilterCellUnoTunnelId > {}; -} - -const Sequence<sal_Int8>& FmXFilterCell::getUnoTunnelId() -{ - return theFmXFilterCellUnoTunnelId::get().getSeq(); -} - -//------------------------------------------------------------------------------ -FmXFilterCell* FmXFilterCell::getImplementation(const Reference< ::com::sun::star::awt::XControl >& _rxObject) -{ - Reference< ::com::sun::star::lang::XUnoTunnel > xTunnel( - _rxObject, UNO_QUERY); - if (xTunnel.is()) - return reinterpret_cast<FmXFilterCell*>(xTunnel->getSomething(getUnoTunnelId())); - return NULL; -} - -//------------------------------------------------------------------------------ -void FmXFilterCell::PaintCell( OutputDevice& rDev, const Rectangle& rRect ) -{ - static_cast< DbFilterField* >( m_pCellControl )->PaintCell( rDev, rRect ); -} - -// OComponentHelper -//----------------------------------------------------------------------------- -void FmXFilterCell::disposing() -{ - ::com::sun::star::lang::EventObject aEvt(*this); - m_aTextListeners.disposeAndClear(aEvt); - - ((DbFilterField*)m_pCellControl)->SetCommitHdl(Link()); - - FmXGridCell::disposing(); -} - -//------------------------------------------------------------------ -Any SAL_CALL FmXFilterCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException) -{ - Any aReturn = FmXGridCell::queryAggregation(_rType); - - if ( !aReturn.hasValue() ) - aReturn = FmXFilterCell_Base::queryInterface( _rType ); - - return aReturn; -} - -//------------------------------------------------------------------------- -Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXFilterCell::getTypes( ) throw(RuntimeException) -{ - return ::comphelper::concatSequences( - FmXGridCell::getTypes(), - FmXFilterCell_Base::getTypes() - ); -} - -//------------------------------------------------------------------------------ -IMPLEMENT_GET_IMPLEMENTATION_ID( FmXFilterCell ) - -// ::com::sun::star::awt::XTextComponent -//------------------------------------------------------------------------------ -void SAL_CALL FmXFilterCell::addTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException ) -{ - m_aTextListeners.addInterface( l ); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXFilterCell::removeTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException ) -{ - m_aTextListeners.removeInterface( l ); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXFilterCell::setText( const ::rtl::OUString& aText ) throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - ((DbFilterField*)m_pCellControl)->SetText(aText); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXFilterCell::insertText( const ::com::sun::star::awt::Selection& /*rSel*/, const ::rtl::OUString& /*aText*/ ) throw( RuntimeException ) -{ -} - -//------------------------------------------------------------------------------ -::rtl::OUString SAL_CALL FmXFilterCell::getText() throw( RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - return ((DbFilterField*)m_pCellControl)->GetText(); -} - -//------------------------------------------------------------------------------ -::rtl::OUString SAL_CALL FmXFilterCell::getSelectedText( void ) throw( RuntimeException ) -{ - return getText(); -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXFilterCell::setSelection( const ::com::sun::star::awt::Selection& /*aSelection*/ ) throw( RuntimeException ) -{ -} - -//------------------------------------------------------------------------------ -::com::sun::star::awt::Selection SAL_CALL FmXFilterCell::getSelection( void ) throw( RuntimeException ) -{ - return ::com::sun::star::awt::Selection(); -} - -//------------------------------------------------------------------------------ -sal_Bool SAL_CALL FmXFilterCell::isEditable( void ) throw( RuntimeException ) -{ - return sal_True; -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXFilterCell::setEditable( sal_Bool /*bEditable*/ ) throw( RuntimeException ) -{ -} - -//------------------------------------------------------------------------------ -sal_Int16 SAL_CALL FmXFilterCell::getMaxTextLen() throw( RuntimeException ) -{ - return 0; -} - -//------------------------------------------------------------------------------ -void SAL_CALL FmXFilterCell::setMaxTextLen( sal_Int16 /*nLen*/ ) throw( RuntimeException ) -{ -} - -//------------------------------------------------------------------------------ -IMPL_LINK( FmXFilterCell, OnCommit, void*, EMPTYARG ) -{ - ::cppu::OInterfaceIteratorHelper aIt( m_aTextListeners ); - ::com::sun::star::awt::TextEvent aEvt; - aEvt.Source = *this; - while( aIt.hasMoreElements() ) - ((::com::sun::star::awt::XTextListener *)aIt.next())->textChanged( aEvt ); - return 1; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/fmcomp/gridcols.cxx b/svx/source/fmcomp/gridcols.cxx deleted file mode 100644 index 737aeba95c..0000000000 --- a/svx/source/fmcomp/gridcols.cxx +++ /dev/null @@ -1,109 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svx.hxx" -#include "gridcols.hxx" -#include <tools/debug.hxx> -#include <comphelper/types.hxx> -#include "fmservs.hxx" -#include "svx/fmtools.hxx" -using namespace ::com::sun::star::uno; - -//------------------------------------------------------------------------------ -const ::comphelper::StringSequence& getColumnTypes() -{ - static ::comphelper::StringSequence aColumnTypes(10); - if (!aColumnTypes.getConstArray()[0].getLength()) - { - ::rtl::OUString* pNames = aColumnTypes.getArray(); - pNames[TYPE_CHECKBOX] = FM_COL_CHECKBOX; - pNames[TYPE_COMBOBOX] = FM_COL_COMBOBOX; - pNames[TYPE_CURRENCYFIELD] = FM_COL_CURRENCYFIELD; - pNames[TYPE_DATEFIELD] = FM_COL_DATEFIELD; - pNames[TYPE_FORMATTEDFIELD] = FM_COL_FORMATTEDFIELD; - pNames[TYPE_LISTBOX] = FM_COL_LISTBOX; - pNames[TYPE_NUMERICFIELD] = FM_COL_NUMERICFIELD; - pNames[TYPE_PATTERNFIELD] = FM_COL_PATTERNFIELD; - pNames[TYPE_TEXTFIELD] = FM_COL_TEXTFIELD; - pNames[TYPE_TIMEFIELD] = FM_COL_TIMEFIELD; - } - return aColumnTypes; -} - -//------------------------------------------------------------------ -// Vergleichen von PropertyInfo -extern "C" int SAL_CALL NameCompare(const void* pFirst, const void* pSecond) -{ - return ((::rtl::OUString*)pFirst)->compareTo(*(::rtl::OUString*)pSecond); -} - -namespace -{ - //------------------------------------------------------------------------------ - sal_Int32 lcl_findPos(const ::rtl::OUString& aStr, const Sequence< ::rtl::OUString>& rList) - { - const ::rtl::OUString* pStrList = rList.getConstArray(); - ::rtl::OUString* pResult = (::rtl::OUString*) bsearch(&aStr, (void*)pStrList, rList.getLength(), sizeof(::rtl::OUString), - &NameCompare); - - if (pResult) - return (pResult - pStrList); - else - return -1; - } -} - -//------------------------------------------------------------------------------ -sal_Int32 getColumnTypeByModelName(const ::rtl::OUString& aModelName) -{ - const ::rtl::OUString aModelPrefix(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.")); - const ::rtl::OUString aCompatibleModelPrefix(RTL_CONSTASCII_USTRINGPARAM("stardiv.one.form.component.")); - - sal_Int32 nTypeId = -1; - if (aModelName == FM_COMPONENT_EDIT) - nTypeId = TYPE_TEXTFIELD; - else - { - sal_Int32 nPrefixPos = aModelName.indexOf(aModelPrefix); -#ifdef DBG_UTIL - sal_Int32 nCompatiblePrefixPos = aModelName.indexOf(aCompatibleModelPrefix); - DBG_ASSERT( (nPrefixPos != -1) || (nCompatiblePrefixPos != -1), "::getColumnTypeByModelName() : wrong servivce !"); -#endif - - ::rtl::OUString aColumnType = (nPrefixPos != -1) - ? aModelName.copy(aModelPrefix.getLength()) - : aModelName.copy(aCompatibleModelPrefix.getLength()); - - const ::comphelper::StringSequence& rColumnTypes = getColumnTypes(); - nTypeId = lcl_findPos(aColumnType, rColumnTypes); - } - return nTypeId; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/fmcomp/gridctrl.cxx b/svx/source/fmcomp/gridctrl.cxx deleted file mode 100644 index aaac150523..0000000000 --- a/svx/source/fmcomp/gridctrl.cxx +++ /dev/null @@ -1,3927 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svx.hxx" - -#include <sal/macros.h> -#include "fmhelp.hrc" -#include <svx/gridctrl.hxx> -#include "gridcell.hxx" -#include "svx/dbtoolsclient.hxx" -#include "svx/fmtools.hxx" -#include <svtools/stringtransfer.hxx> - -#include "fmprop.hrc" -#include <svtools/stringtransfer.hxx> -#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> -#include <com/sun/star/accessibility/XAccessible.hpp> -#include <com/sun/star/sdb/XResultSetAccess.hpp> -#include <com/sun/star/sdb/RowChangeAction.hpp> -#include <com/sun/star/sdb/XRowsChangeBroadcaster.hpp> -#include <com/sun/star/sdbc/XResultSetUpdate.hpp> -#include <com/sun/star/sdbcx/Privilege.hpp> -#include <com/sun/star/container/XChild.hpp> -#include <com/sun/star/util/XNumberFormatter.hpp> -#include <com/sun/star/util/XNumberFormatsSupplier.hpp> -#include <com/sun/star/util/XCloneable.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/beans/PropertyChangeEvent.hpp> -#include <comphelper/extract.hxx> -#include <tools/resid.hxx> -#include <tools/diagnose_ex.h> -#include <vcl/sound.hxx> -#include <vcl/menu.hxx> - -#include "svx/fmresids.hrc" - -#include <svx/svxids.hrc> -#include <tools/shl.hxx> -#include <svx/dialmgr.hxx> -#include "fmservs.hxx" -#include "sdbdatacolumn.hxx" - -#define HANDLE_ID 0 - -#include <comphelper/stl_types.hxx> -#include <comphelper/property.hxx> -#include "trace.hxx" - -#include <algorithm> - -using namespace ::svxform; -using namespace ::svt; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdb; -using namespace ::com::sun::star::datatransfer; -using namespace ::com::sun::star::container; -using namespace com::sun::star::accessibility; - -#define ROWSTATUS(row) !row.Is() ? "NULL" : row->GetStatus() == GRS_CLEAN ? "CLEAN" : row->GetStatus() == GRS_MODIFIED ? "MODIFIED" : row->GetStatus() == GRS_DELETED ? "DELETED" : "INVALID" - - -#define DEFAULT_BROWSE_MODE \ - BROWSER_COLUMNSELECTION \ - | BROWSER_MULTISELECTION \ - | BROWSER_KEEPSELECTION \ - | BROWSER_TRACKING_TIPS \ - | BROWSER_HLINESFULL \ - | BROWSER_VLINESFULL \ - | BROWSER_HEADERBAR_NEW \ - -class RowSetEventListener : public ::cppu::WeakImplHelper1<XRowsChangeListener> -{ - DbGridControl* m_pControl; -public: - RowSetEventListener(DbGridControl* i_pControl) : m_pControl(i_pControl) - { - } -private: - // XEventListener - virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& /*i_aEvt*/) throw ( RuntimeException ) - { - } - virtual void SAL_CALL rowsChanged(const ::com::sun::star::sdb::RowsChangeEvent& i_aEvt) throw ( RuntimeException ) - { - if ( i_aEvt.Action == RowChangeAction::UPDATE ) - { - ::DbGridControl::GrantControlAccess aAccess; - CursorWrapper* pSeek = m_pControl->GetSeekCursor(aAccess); - const DbGridRowRef& rSeekRow = m_pControl->GetSeekRow(aAccess); - const Any* pIter = i_aEvt.Bookmarks.getConstArray(); - const Any* pEnd = pIter + i_aEvt.Bookmarks.getLength(); - for(;pIter != pEnd;++pIter) - { - pSeek->moveToBookmark(*pIter); - // get the data - rSeekRow->SetState(pSeek, sal_True); - sal_Int32 nSeekPos = pSeek->getRow() - 1; - m_pControl->SetSeekPos(nSeekPos,aAccess); - m_pControl->RowModified(nSeekPos); - } - } - } -}; -//============================================================================== - -class GridFieldValueListener; -DECLARE_STL_MAP(sal_uInt16, GridFieldValueListener*, ::std::less<sal_uInt16>, ColumnFieldValueListeners); - -//============================================================================== - -DBG_NAME(GridFieldValueListener) -class GridFieldValueListener : protected ::comphelper::OPropertyChangeListener -{ - osl::Mutex m_aMutex; - DbGridControl& m_rParent; - ::comphelper::OPropertyChangeMultiplexer* m_pRealListener; - sal_uInt16 m_nId; - sal_Int16 m_nSuspended; - sal_Bool m_bDisposed : 1; - -public: - GridFieldValueListener(DbGridControl& _rParent, const Reference< XPropertySet >& xField, sal_uInt16 _nId); - virtual ~GridFieldValueListener(); - - virtual void _propertyChanged(const PropertyChangeEvent& evt) throw( RuntimeException ); - - void suspend() { ++m_nSuspended; } - void resume() { --m_nSuspended; } - - void dispose(); -}; -//------------------------------------------------------------------------------ -GridFieldValueListener::GridFieldValueListener(DbGridControl& _rParent, const Reference< XPropertySet >& _rField, sal_uInt16 _nId) - :OPropertyChangeListener(m_aMutex) - ,m_rParent(_rParent) - ,m_pRealListener(NULL) - ,m_nId(_nId) - ,m_nSuspended(0) - ,m_bDisposed(sal_False) -{ - DBG_CTOR(GridFieldValueListener, NULL); - if (_rField.is()) - { - m_pRealListener = new ::comphelper::OPropertyChangeMultiplexer(this, _rField); - m_pRealListener->addProperty(FM_PROP_VALUE); - m_pRealListener->acquire(); - } -} - -//------------------------------------------------------------------------------ -GridFieldValueListener::~GridFieldValueListener() -{ - DBG_DTOR(GridFieldValueListener, NULL); - dispose(); -} - -//------------------------------------------------------------------------------ -void GridFieldValueListener::_propertyChanged(const PropertyChangeEvent& _evt) throw( RuntimeException ) -{ - DBG_ASSERT(m_nSuspended>=0, "GridFieldValueListener::_propertyChanged : resume > suspend !"); - if (m_nSuspended <= 0) - m_rParent.FieldValueChanged(m_nId, _evt); -} - -//------------------------------------------------------------------------------ -void GridFieldValueListener::dispose() -{ - if (m_bDisposed) - { - DBG_ASSERT(m_pRealListener == NULL, "GridFieldValueListener::dispose : inconsistent !"); - return; - } - - if (m_pRealListener) - { - m_pRealListener->dispose(); - m_pRealListener->release(); - m_pRealListener = NULL; - } - - m_bDisposed = sal_True; - m_rParent.FieldListenerDisposing(m_nId); -} - -//============================================================================== - -class DisposeListenerGridBridge : public FmXDisposeListener -{ - osl::Mutex m_aMutex; - DbGridControl& m_rParent; - FmXDisposeMultiplexer* m_pRealListener; - -public: - DisposeListenerGridBridge( DbGridControl& _rParent, const Reference< XComponent >& _rxObject, sal_Int16 _rId = -1); - virtual ~DisposeListenerGridBridge(); - - virtual void disposing(const EventObject& _rEvent, sal_Int16 _nId) throw( RuntimeException ) { m_rParent.disposing(_nId, _rEvent); } -}; - -//============================================================================== - - -DBG_NAME(DisposeListenerGridBridge) -//------------------------------------------------------------------------------ -DisposeListenerGridBridge::DisposeListenerGridBridge(DbGridControl& _rParent, const Reference< XComponent >& _rxObject, sal_Int16 _rId) - :FmXDisposeListener(m_aMutex) - ,m_rParent(_rParent) - ,m_pRealListener(NULL) -{ - DBG_CTOR(DisposeListenerGridBridge,NULL); - - if (_rxObject.is()) - { - m_pRealListener = new FmXDisposeMultiplexer(this, _rxObject, _rId); - m_pRealListener->acquire(); - } -} - -//------------------------------------------------------------------------------ -DisposeListenerGridBridge::~DisposeListenerGridBridge() -{ - if (m_pRealListener) - { - m_pRealListener->dispose(); - m_pRealListener->release(); - m_pRealListener = NULL; - } - - DBG_DTOR(DisposeListenerGridBridge,NULL); -} - -//============================================================================== - -static sal_uInt16 ControlMap[] = - { - DbGridControl::NavigationBar::RECORD_TEXT, - DbGridControl::NavigationBar::RECORD_ABSOLUTE, - DbGridControl::NavigationBar::RECORD_OF, - DbGridControl::NavigationBar::RECORD_COUNT, - DbGridControl::NavigationBar::RECORD_FIRST, - DbGridControl::NavigationBar::RECORD_NEXT, - DbGridControl::NavigationBar::RECORD_PREV, - DbGridControl::NavigationBar::RECORD_LAST, - DbGridControl::NavigationBar::RECORD_NEW, - 0 - }; - -//------------------------------------------------------------------------------ -sal_Bool CompareBookmark(const Any& aLeft, const Any& aRight) -{ - return ::comphelper::compare(aLeft, aRight); -} - -//============================================================================== -class FmXGridSourcePropListener : public ::comphelper::OPropertyChangeListener -{ - DbGridControl* m_pParent; - - // a DbGridControl has no mutex, so we use our own as the base class expects one - osl::Mutex m_aMutex; - sal_Int16 m_nSuspended; - -public: - FmXGridSourcePropListener(DbGridControl* _pParent); - - void suspend() { ++m_nSuspended; } - void resume() { --m_nSuspended; } - - virtual void _propertyChanged(const PropertyChangeEvent& evt) throw( RuntimeException ); -}; - -//------------------------------------------------------------------------------ -FmXGridSourcePropListener::FmXGridSourcePropListener(DbGridControl* _pParent) - :OPropertyChangeListener(m_aMutex) - ,m_pParent(_pParent) - ,m_nSuspended(0) -{ - DBG_ASSERT(m_pParent, "FmXGridSourcePropListener::FmXGridSourcePropListener : invalid parent !"); -} - -//------------------------------------------------------------------------------ -void FmXGridSourcePropListener::_propertyChanged(const PropertyChangeEvent& evt) throw( RuntimeException ) -{ - DBG_ASSERT(m_nSuspended>=0, "FmXGridSourcePropListener::_propertyChanged : resume > suspend !"); - if (m_nSuspended <= 0) - m_pParent->DataSourcePropertyChanged(evt); -} - -//============================================================================== -//------------------------------------------------------------------------------ -DbGridControl::NavigationBar::AbsolutePos::AbsolutePos(Window* pParent, WinBits nStyle) - :NumericField(pParent, nStyle) -{ - SetMin(1); - SetFirst(1); - SetSpinSize(1); - - SetDecimalDigits(0); - SetStrictFormat(sal_True); -} - -//------------------------------------------------------------------------------ -void DbGridControl::NavigationBar::AbsolutePos::KeyInput(const KeyEvent& rEvt) -{ - if (rEvt.GetKeyCode() == KEY_RETURN && GetText().Len()) - { - sal_Int64 nRecord = GetValue(); - if (nRecord < GetMin() || nRecord > GetMax()) - return; - else - ((NavigationBar*)GetParent())->PositionDataSource(static_cast<sal_Int32>(nRecord)); - } - else if (rEvt.GetKeyCode() == KEY_TAB) - GetParent()->GetParent()->GrabFocus(); - else - NumericField::KeyInput(rEvt); -} - -//------------------------------------------------------------------------------ -void DbGridControl::NavigationBar::AbsolutePos::LoseFocus() -{ - NumericField::LoseFocus(); - sal_Int64 nRecord = GetValue(); - if (nRecord < GetMin() || nRecord > GetMax()) - return; - else - { - ((NavigationBar*)GetParent())->PositionDataSource(static_cast<sal_Int32>(nRecord)); - ((NavigationBar*)GetParent())->InvalidateState(NavigationBar::RECORD_ABSOLUTE); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::NavigationBar::PositionDataSource(sal_Int32 nRecord) -{ - if (m_bPositioning) - return; - // the MoveToPosition may cause a LoseFocus which would lead to a second MoveToPosition, so protect agains this - // recursion - // 68167 - 13.08.99 - FS - m_bPositioning = sal_True; - ((DbGridControl*)GetParent())->MoveToPosition(nRecord - 1); - m_bPositioning = sal_False; -} - -//------------------------------------------------------------------------------ -DbGridControl::NavigationBar::NavigationBar(Window* pParent, WinBits nStyle) - :Control(pParent, nStyle) - ,m_aRecordText(this, WB_VCENTER) - ,m_aAbsolute(this, WB_VCENTER) - ,m_aRecordOf(this, WB_VCENTER) - ,m_aRecordCount(this, WB_CENTER | WB_VCENTER) - ,m_aFirstBtn(this, WB_RECTSTYLE|WB_NOPOINTERFOCUS) - ,m_aPrevBtn(this, WB_REPEAT|WB_RECTSTYLE|WB_NOPOINTERFOCUS) - ,m_aNextBtn(this, WB_REPEAT|WB_RECTSTYLE|WB_NOPOINTERFOCUS) - ,m_aLastBtn(this, WB_RECTSTYLE|WB_NOPOINTERFOCUS) - ,m_aNewBtn(this, WB_RECTSTYLE|WB_NOPOINTERFOCUS) - ,m_nDefaultWidth(0) - ,m_nCurrentPos(-1) - ,m_bPositioning(sal_False) -{ - m_aFirstBtn.SetSymbol(SYMBOL_FIRST); - m_aPrevBtn.SetSymbol(SYMBOL_PREV); - m_aNextBtn.SetSymbol(SYMBOL_NEXT); - m_aLastBtn.SetSymbol(SYMBOL_LAST); - m_aNewBtn.SetModeImage(((DbGridControl*)pParent)->GetImage(DbGridControl_Base::NEW)); - - m_aFirstBtn.SetHelpId(HID_GRID_TRAVEL_FIRST); - m_aPrevBtn.SetHelpId(HID_GRID_TRAVEL_PREV); - m_aNextBtn.SetHelpId(HID_GRID_TRAVEL_NEXT); - m_aLastBtn.SetHelpId(HID_GRID_TRAVEL_LAST); - m_aNewBtn.SetHelpId(HID_GRID_TRAVEL_NEW); - m_aAbsolute.SetHelpId(HID_GRID_TRAVEL_ABSOLUTE); - m_aRecordCount.SetHelpId(HID_GRID_NUMBEROFRECORDS); - - // Handler fuer Buttons einrichten - m_aFirstBtn.SetClickHdl(LINK(this,NavigationBar,OnClick)); - m_aPrevBtn.SetClickHdl(LINK(this,NavigationBar,OnClick)); - m_aNextBtn.SetClickHdl(LINK(this,NavigationBar,OnClick)); - m_aLastBtn.SetClickHdl(LINK(this,NavigationBar,OnClick)); - m_aNewBtn.SetClickHdl(LINK(this,NavigationBar,OnClick)); - - m_aRecordText.SetText(XubString(SVX_RES(RID_STR_REC_TEXT))); - m_aRecordOf.SetText(XubString(SVX_RES(RID_STR_REC_FROM_TEXT))); - m_aRecordCount.SetText('?'); - - m_nDefaultWidth = ArrangeControls(); - - m_aFirstBtn.Disable(); - m_aPrevBtn.Disable(); - m_aNextBtn.Disable(); - m_aLastBtn.Disable(); - m_aNewBtn.Disable(); - m_aRecordText.Disable(); - m_aRecordOf.Disable(); - m_aRecordCount.Disable(); - m_aAbsolute.Disable(); - - AllSettings aSettings = m_aNextBtn.GetSettings(); - MouseSettings aMouseSettings = aSettings.GetMouseSettings(); - aMouseSettings.SetButtonRepeat(aMouseSettings.GetButtonRepeat() / 4); - aSettings.SetMouseSettings(aMouseSettings); - m_aNextBtn.SetSettings(aSettings, sal_True); - m_aPrevBtn.SetSettings(aSettings, sal_True); - - m_aFirstBtn.Show(); - m_aPrevBtn.Show(); - m_aNextBtn.Show(); - m_aLastBtn.Show(); - m_aNewBtn.Show(); - m_aRecordText.Show(); - m_aRecordOf.Show(); - m_aRecordCount.Show(); - m_aAbsolute.Show(); -} - -namespace -{ - void SetPosAndSize(Button& _rButton,Point& _rPos,const Size& _rSize) - { - _rButton.SetPosPixel( _rPos ); - _rButton.SetSizePixel( _rSize ); - _rPos.X() += (sal_uInt16)_rSize.Width(); - } -} -//------------------------------------------------------------------------------ -sal_uInt16 DbGridControl::NavigationBar::ArrangeControls() -{ - // Positionierung der Controls - // Basisgroessen ermitteln - sal_uInt16 nX = 0; - sal_uInt16 nY = 0; - Rectangle aRect(((DbGridControl*)GetParent())->GetControlArea()); - const long nH = aRect.GetSize().Height(); - Size aBorder = LogicToPixel(Size(3, 3),MAP_APPFONT); - aBorder = Size(CalcZoom(aBorder.Width()), CalcZoom(aBorder.Height())); - - // Controls Groessen und Positionen setzen - // - XubString aText = m_aRecordText.GetText(); - long nTextWidth = m_aRecordText.GetTextWidth(aText); - m_aRecordText.SetPosPixel(Point(nX,nY) ); - m_aRecordText.SetSizePixel(Size(nTextWidth,nH)); - nX = sal::static_int_cast< sal_uInt16 >(nX + nTextWidth + aBorder.Width()); - - m_aAbsolute.SetPosPixel( Point(nX,nY)); - m_aAbsolute.SetSizePixel( Size(3*nH,aRect.GetSize().Height()) ); // Heuristik XXXXXXX - nX = sal::static_int_cast< sal_uInt16 >(nX + (3*nH) + aBorder.Width()); - - aText = m_aRecordOf.GetText(); - nTextWidth = m_aRecordOf.GetTextWidth(aText); - m_aRecordOf.SetPosPixel(Point(nX,nY) ); - m_aRecordOf.SetSizePixel(Size(nTextWidth,nH)); - nX = sal::static_int_cast< sal_uInt16 >(nX + nTextWidth + aBorder.Width()); - - nTextWidth = m_aRecordCount.GetTextWidth( String::CreateFromAscii("0000000 (00000) *") ); - m_aRecordCount.SetPosPixel(Point(nX,nY) ); - m_aRecordCount.SetSizePixel(Size(nTextWidth,nH)); - nX = sal::static_int_cast< sal_uInt16 >(nX + nTextWidth + aBorder.Width()); - - Point aButtonPos(nX,nY); - Size aButtonSize(nH,nH); - SetPosAndSize(m_aFirstBtn, aButtonPos, aButtonSize); - SetPosAndSize(m_aPrevBtn, aButtonPos, aButtonSize); - SetPosAndSize(m_aNextBtn, aButtonPos, aButtonSize); - SetPosAndSize(m_aLastBtn, aButtonPos, aButtonSize); - SetPosAndSize(m_aNewBtn, aButtonPos, aButtonSize); - - nX = sal::static_int_cast< sal_uInt16 >( - aButtonPos.X() + (sal_uInt16)(nH + aBorder.Width())); - - // Ist der Font des Edits groesser als das Feld? - Font aOutputFont = m_aAbsolute.GetFont(); - if (aOutputFont.GetSize().Height() > nH) - { - Font aApplFont = OutputDevice::GetDefaultFont( - DEFAULTFONT_SANS_UNICODE, - Application::GetSettings().GetUILanguage(), - DEFAULTFONT_FLAGS_ONLYONE, - this - ); - aApplFont.SetSize( Size( 0, nH - 2 ) ); - m_aAbsolute.SetControlFont( aApplFont ); - - aApplFont.SetTransparent( sal_True ); - m_aRecordText.SetControlFont( aApplFont ); - m_aRecordOf.SetControlFont( aApplFont ); - m_aRecordCount.SetControlFont( aApplFont ); - } - return nX; -} - -//------------------------------------------------------------------------------ -IMPL_LINK(DbGridControl::NavigationBar, OnClick, Button *, pButton ) -{ - DbGridControl* pParent = (DbGridControl*)GetParent(); - - if (pParent->m_aMasterSlotExecutor.IsSet()) - { - long lResult = 0; - if (pButton == &m_aFirstBtn) - lResult = pParent->m_aMasterSlotExecutor.Call((void*)RECORD_FIRST); - else if( pButton == &m_aPrevBtn ) - lResult = pParent->m_aMasterSlotExecutor.Call((void*)RECORD_PREV); - else if( pButton == &m_aNextBtn ) - lResult = pParent->m_aMasterSlotExecutor.Call((void*)RECORD_NEXT); - else if( pButton == &m_aLastBtn ) - lResult = pParent->m_aMasterSlotExecutor.Call((void*)RECORD_LAST); - else if( pButton == &m_aNewBtn ) - lResult = pParent->m_aMasterSlotExecutor.Call((void*)RECORD_NEW); - - if (lResult) - // the link already handled it - return 0; - } - - if (pButton == &m_aFirstBtn) - pParent->MoveToFirst(); - else if( pButton == &m_aPrevBtn ) - pParent->MoveToPrev(); - else if( pButton == &m_aNextBtn ) - pParent->MoveToNext(); - else if( pButton == &m_aLastBtn ) - pParent->MoveToLast(); - else if( pButton == &m_aNewBtn ) - pParent->AppendNew(); - return 0; -} - -//------------------------------------------------------------------------------ -void DbGridControl::NavigationBar::InvalidateAll(sal_Int32 nCurrentPos, sal_Bool bAll) -{ - if (m_nCurrentPos != nCurrentPos || nCurrentPos < 0 || bAll) - { - DbGridControl* pParent = (DbGridControl*)GetParent(); - - sal_Int32 nAdjustedRowCount = pParent->GetRowCount() - ((pParent->GetOptions() & DbGridControl::OPT_INSERT) ? 2 : 1); - - // Wann mu� alles invalidiert werden - bAll = bAll || m_nCurrentPos <= 0; - bAll = bAll || nCurrentPos <= 0; - bAll = bAll || m_nCurrentPos >= nAdjustedRowCount; - bAll = bAll || nCurrentPos >= nAdjustedRowCount; - - if ( bAll ) - { - m_nCurrentPos = nCurrentPos; - int i = 0; - while (ControlMap[i]) - SetState(ControlMap[i++]); - } - else // befindet sich in der Mitte - { - m_nCurrentPos = nCurrentPos; - SetState(NavigationBar::RECORD_COUNT); - SetState(NavigationBar::RECORD_ABSOLUTE); - } - } -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::NavigationBar::GetState(sal_uInt16 nWhich) const -{ - DbGridControl* pParent = (DbGridControl*)GetParent(); - - if (!pParent->IsOpen() || pParent->IsDesignMode() || !pParent->IsEnabled() - || pParent->IsFilterMode() ) - return sal_False; - else - { - // check if we have a master state provider - if (pParent->m_aMasterStateProvider.IsSet()) - { - long nState = pParent->m_aMasterStateProvider.Call(reinterpret_cast< void* >( nWhich ) ); - if (nState>=0) - return (nState>0); - } - - sal_Bool bAvailable = sal_True; - - switch (nWhich) - { - case NavigationBar::RECORD_FIRST: - case NavigationBar::RECORD_PREV: - bAvailable = m_nCurrentPos > 0; - break; - case NavigationBar::RECORD_NEXT: - if(pParent->m_bRecordCountFinal) - { - bAvailable = m_nCurrentPos < pParent->GetRowCount() - 1; - if (!bAvailable && pParent->GetOptions() & DbGridControl::OPT_INSERT) - bAvailable = (m_nCurrentPos == pParent->GetRowCount() - 2) && pParent->IsModified(); - } - break; - case NavigationBar::RECORD_LAST: - if(pParent->m_bRecordCountFinal) - { - if (pParent->GetOptions() & DbGridControl::OPT_INSERT) - bAvailable = pParent->IsCurrentAppending() ? pParent->GetRowCount() > 1 : - m_nCurrentPos != pParent->GetRowCount() - 2; - else - bAvailable = m_nCurrentPos != pParent->GetRowCount() - 1; - } - break; - case NavigationBar::RECORD_NEW: - bAvailable = (pParent->GetOptions() & DbGridControl::OPT_INSERT) && pParent->GetRowCount() && m_nCurrentPos < pParent->GetRowCount() - 1; - break; - case NavigationBar::RECORD_ABSOLUTE: - bAvailable = pParent->GetRowCount() > 0; - break; - } - return bAvailable; - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::NavigationBar::SetState(sal_uInt16 nWhich) -{ - sal_Bool bAvailable = GetState(nWhich); - DbGridControl* pParent = (DbGridControl*)GetParent(); - Window* pWnd = NULL; - switch (nWhich) - { - case NavigationBar::RECORD_FIRST: - pWnd = &m_aFirstBtn; - break; - case NavigationBar::RECORD_PREV: - pWnd = &m_aPrevBtn; - break; - case NavigationBar::RECORD_NEXT: - pWnd = &m_aNextBtn; - break; - case NavigationBar::RECORD_LAST: - pWnd = &m_aLastBtn; - break; - case NavigationBar::RECORD_NEW: - pWnd = &m_aNewBtn; - break; - case NavigationBar::RECORD_ABSOLUTE: - pWnd = &m_aAbsolute; - if (bAvailable) - { - if (pParent->m_nTotalCount >= 0) - { - if (pParent->IsCurrentAppending()) - m_aAbsolute.SetMax(pParent->m_nTotalCount + 1); - else - m_aAbsolute.SetMax(pParent->m_nTotalCount); - } - else - m_aAbsolute.SetMax(LONG_MAX); - - m_aAbsolute.SetValue(m_nCurrentPos + 1); - } - else - m_aAbsolute.SetText(String()); - break; - case NavigationBar::RECORD_TEXT: - pWnd = &m_aRecordText; - break; - case NavigationBar::RECORD_OF: - pWnd = &m_aRecordOf; - break; - case NavigationBar::RECORD_COUNT: - { - pWnd = &m_aRecordCount; - String aText; - if (bAvailable) - { - if (pParent->GetOptions() & DbGridControl::OPT_INSERT) - { - if (pParent->IsCurrentAppending() && !pParent->IsModified()) - aText = String::CreateFromInt32(pParent->GetRowCount()); - else - aText = String::CreateFromInt32(pParent->GetRowCount() - 1); - } - else - aText = String::CreateFromInt32(pParent->GetRowCount()); - if(!pParent->m_bRecordCountFinal) - aText += String::CreateFromAscii(" *"); - } - else - aText = String(); - - // add the number of selected rows, if applicable - if (pParent->GetSelectRowCount()) - { - String aExtendedInfo(aText); - aExtendedInfo.AppendAscii(" ("); - aExtendedInfo += String::CreateFromInt32(pParent->GetSelectRowCount()); - aExtendedInfo += ')'; - pWnd->SetText(aExtendedInfo); - } - else - pWnd->SetText(aText); - - pParent->SetRealRowCount(aText); - } break; - } - DBG_ASSERT(pWnd, "kein Fenster"); - if (pWnd && (pWnd->IsEnabled() != bAvailable)) - // this "pWnd->IsEnabled() != bAvailable" is a little hack : Window::Enable always generates a user - // event (ImplGenerateMouseMove) even if nothing happened. This may lead to some unwanted effects, so we - // do this check. - // For further explanation see Bug 69900. - pWnd->Enable(bAvailable); -} - -//------------------------------------------------------------------------------ -void DbGridControl::NavigationBar::Resize() -{ - Control::Resize(); - ArrangeControls(); -} - -//------------------------------------------------------------------------------ -void DbGridControl::NavigationBar::Paint(const Rectangle& rRect) -{ - Control::Paint(rRect); - Point aAbsolutePos = m_aAbsolute.GetPosPixel(); - Size aAbsoluteSize = m_aAbsolute.GetSizePixel(); - - DrawLine(Point(aAbsolutePos.X() - 1, 0 ), - Point(aAbsolutePos.X() - 1, aAbsolutePos.Y() + aAbsoluteSize.Height())); - - DrawLine(Point(aAbsolutePos.X() + aAbsoluteSize.Width() + 1, 0 ), - Point(aAbsolutePos.X() + aAbsoluteSize.Width() + 1, aAbsolutePos.Y() + aAbsoluteSize.Height())); -} - -//------------------------------------------------------------------------------ -void DbGridControl::NavigationBar::StateChanged( StateChangedType nType ) -{ - Control::StateChanged( nType ); - - Window* pWindows[] = { &m_aRecordText, - &m_aAbsolute, - &m_aRecordOf, - &m_aRecordCount, - &m_aFirstBtn, - &m_aPrevBtn, - &m_aNextBtn, - &m_aLastBtn, - &m_aNewBtn - }; - - switch ( nType ) - { - case STATE_CHANGE_MIRRORING: - { - sal_Bool bIsRTLEnabled = IsRTLEnabled(); - for ( size_t i=0; i < SAL_N_ELEMENTS( pWindows ); ++i ) - pWindows[i]->EnableRTL( bIsRTLEnabled ); - } - break; - - case STATE_CHANGE_ZOOM: - { - Fraction aZoom = GetZoom(); - - // not all of these controls need to know the new zoom, but to be sure ... - Font aFont( GetSettings().GetStyleSettings().GetFieldFont() ); - if ( IsControlFont() ) - aFont.Merge( GetControlFont() ); - - for (size_t i=0; i < SAL_N_ELEMENTS(pWindows); ++i) - { - pWindows[i]->SetZoom(aZoom); - pWindows[i]->SetZoomedPointFont(aFont); - } - - SetZoomedPointFont( aFont ); - - // rearrange the controls - m_nDefaultWidth = ArrangeControls(); - } - break; - } -} - -//------------------------------------------------------------------------------ -DbGridRow::DbGridRow(CursorWrapper* pCur, sal_Bool bPaintCursor) - :m_bIsNew(sal_False) -{ - - if (pCur && pCur->Is()) - { - Reference< XIndexAccess > xColumns(pCur->getColumns(), UNO_QUERY); - DataColumn* pColumn; - for (sal_Int32 i = 0; i < xColumns->getCount(); ++i) - { - Reference< XPropertySet > xColSet; - ::cppu::extractInterface(xColSet, xColumns->getByIndex(i)); - pColumn = new DataColumn(xColSet); - m_aVariants.push_back( pColumn ); - } - - if (pCur->rowDeleted()) - m_eStatus = GRS_DELETED; - else - { - if (bPaintCursor) - m_eStatus = (pCur->isAfterLast() || pCur->isBeforeFirst()) ? GRS_INVALID : GRS_CLEAN; - else - { - Reference< XPropertySet > xSet = pCur->getPropertySet(); - if (xSet.is()) - { - m_bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISNEW)); - if (!m_bIsNew && (pCur->isAfterLast() || pCur->isBeforeFirst())) - m_eStatus = GRS_INVALID; - else if (::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISMODIFIED))) - m_eStatus = GRS_MODIFIED; - else - m_eStatus = GRS_CLEAN; - } - else - m_eStatus = GRS_INVALID; - } - } - if (!m_bIsNew && IsValid()) - m_aBookmark = pCur->getBookmark(); - else - m_aBookmark = Any(); - } - else - m_eStatus = GRS_INVALID; -} - -//------------------------------------------------------------------------------ -DbGridRow::~DbGridRow() -{ - for ( size_t i = 0, n = m_aVariants.size(); i < n; ++i ) - delete m_aVariants[ i ]; - m_aVariants.clear(); -} - -//------------------------------------------------------------------------------ -void DbGridRow::SetState(CursorWrapper* pCur, sal_Bool bPaintCursor) -{ - if (pCur && pCur->Is()) - { - if (pCur->rowDeleted()) - { - m_eStatus = GRS_DELETED; - m_bIsNew = sal_False; - } - else - { - m_eStatus = GRS_CLEAN; - if (!bPaintCursor) - { - Reference< XPropertySet > xSet = pCur->getPropertySet(); - DBG_ASSERT(xSet.is(), "DbGridRow::SetState : invalid cursor !"); - - if (::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISMODIFIED))) - m_eStatus = GRS_MODIFIED; - m_bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISNEW)); - } - else - m_bIsNew = sal_False; - } - - try - { - if (!m_bIsNew && IsValid()) - m_aBookmark = pCur->getBookmark(); - else - m_aBookmark = Any(); - } - catch(SQLException&) - { - DBG_UNHANDLED_EXCEPTION(); - m_aBookmark = Any(); - m_eStatus = GRS_INVALID; - m_bIsNew = sal_False; - } - } - else - { - m_aBookmark = Any(); - m_eStatus = GRS_INVALID; - m_bIsNew = sal_False; - } -} - -DBG_NAME(DbGridControl); -//------------------------------------------------------------------------------ -DbGridControl::DbGridControl( - Reference< XMultiServiceFactory > _rxFactory, - Window* pParent, - WinBits nBits) - :DbGridControl_Base(pParent, EBBF_NONE, nBits, DEFAULT_BROWSE_MODE ) - ,m_xServiceFactory(_rxFactory) - ,m_aBar(this) - ,m_nAsynAdjustEvent(0) - ,m_pDataSourcePropMultiplexer(NULL) - ,m_pDataSourcePropListener(NULL) - ,m_pFieldListeners(NULL) - ,m_pCursorDisposeListener(NULL) - ,m_pGridListener(NULL) - ,m_pDataCursor(NULL) - ,m_pSeekCursor(NULL) - ,m_nSeekPos(-1) - ,m_nTotalCount(-1) - ,m_aNullDate(OTypeConversionClient().getStandardDate()) - ,m_nMode(DEFAULT_BROWSE_MODE) - ,m_nCurrentPos(-1) - ,m_nDeleteEvent(0) - ,m_nOptions(OPT_READONLY) - ,m_nOptionMask(OPT_INSERT | OPT_UPDATE | OPT_DELETE) - ,m_nLastColId((sal_uInt16)-1) - ,m_nLastRowId(-1) - ,m_bDesignMode(sal_False) - ,m_bRecordCountFinal(sal_False) - ,m_bMultiSelection(sal_True) - ,m_bNavigationBar(sal_True) - ,m_bSynchDisplay(sal_True) - ,m_bForceROController(sal_False) - ,m_bHandle(sal_True) - ,m_bFilterMode(sal_False) - ,m_bWantDestruction(sal_False) - ,m_bInAdjustDataSource(sal_False) - ,m_bPendingAdjustRows(sal_False) - ,m_bHideScrollbars( sal_False ) - ,m_bUpdating(sal_False) -{ - DBG_CTOR(DbGridControl,NULL); - - String sName(SVX_RES(RID_STR_NAVIGATIONBAR)); - m_aBar.SetAccessibleName(sName); - m_aBar.Show(); - ImplInitWindow( InitAll ); -} - -//------------------------------------------------------------------------------ -void DbGridControl::InsertHandleColumn() -{ - // Handle Column einfuegen - // Da die BrowseBox ohne handleColums Paintprobleme hat - // wird diese versteckt - if (HasHandle()) - BrowseBox::InsertHandleColumn(GetDefaultColumnWidth(String())); - else - BrowseBox::InsertHandleColumn(0); -} - -//------------------------------------------------------------------------------ -void DbGridControl::Init() -{ - BrowserHeader* pNewHeader = CreateHeaderBar(this); - pHeader->SetMouseTransparent(sal_False); - - SetHeaderBar(pNewHeader); - SetMode(m_nMode); - SetCursorColor(Color(0xFF, 0, 0)); - - InsertHandleColumn(); -} - -//------------------------------------------------------------------------------ -DbGridControl::~DbGridControl() -{ - RemoveColumns(); - - { - m_bWantDestruction = sal_True; - osl::MutexGuard aGuard(m_aDestructionSafety); - if (m_pFieldListeners) - DisconnectFromFields(); - if (m_pCursorDisposeListener) - { - delete m_pCursorDisposeListener; - m_pCursorDisposeListener = NULL; - } - } - - if (m_nDeleteEvent) - Application::RemoveUserEvent(m_nDeleteEvent); - - if (m_pDataSourcePropMultiplexer) - { - m_pDataSourcePropMultiplexer->dispose(); - m_pDataSourcePropMultiplexer->release(); // this should delete the multiplexer - delete m_pDataSourcePropListener; - m_pDataSourcePropMultiplexer = NULL; - m_pDataSourcePropListener = NULL; - } - m_xRowSetListener.clear(); - - delete m_pDataCursor; - delete m_pSeekCursor; - - DBG_DTOR(DbGridControl,NULL); -} - -//------------------------------------------------------------------------------ -void DbGridControl::StateChanged( StateChangedType nType ) -{ - DbGridControl_Base::StateChanged( nType ); - - switch (nType) - { - case STATE_CHANGE_MIRRORING: - ImplInitWindow( InitWritingMode ); - Invalidate(); - break; - - case STATE_CHANGE_ZOOM: - { - ImplInitWindow( InitFont ); - - // and give it a chance to rearrange - Point aPoint = GetControlArea().TopLeft(); - sal_uInt16 nX = (sal_uInt16)aPoint.X(); - ArrangeControls(nX, (sal_uInt16)aPoint.Y()); - ReserveControlArea((sal_uInt16)nX); - } - break; - case STATE_CHANGE_CONTROLFONT: - ImplInitWindow( InitFont ); - Invalidate(); - break; - case STATE_CHANGE_CONTROLFOREGROUND: - ImplInitWindow( InitForeground ); - Invalidate(); - break; - case STATE_CHANGE_CONTROLBACKGROUND: - ImplInitWindow( InitBackground ); - Invalidate(); - break; - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::DataChanged( const DataChangedEvent& rDCEvt ) -{ - DbGridControl_Base::DataChanged( rDCEvt ); - if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS ) && - (rDCEvt.GetFlags() & SETTINGS_STYLE) ) - { - ImplInitWindow( InitAll ); - Invalidate(); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::Select() -{ - DbGridControl_Base::Select(); - - // as the selected rows may have changed, udate the according display in our navigation bar - m_aBar.InvalidateState(NavigationBar::RECORD_COUNT); - - if (m_pGridListener) - m_pGridListener->selectionChanged(); -} - -//------------------------------------------------------------------------------ -void DbGridControl::ImplInitWindow( const InitWindowFacet _eInitWhat ) -{ - for ( size_t i = 0; i < m_aColumns.size(); ++i ) - { - DbGridColumn* pCol = m_aColumns[ i ]; - if (pCol) - pCol->ImplInitWindow( GetDataWindow(), _eInitWhat ); - } - - if ( ( _eInitWhat & InitWritingMode ) != 0 ) - { - if ( m_bNavigationBar ) - { - m_aBar.EnableRTL( IsRTLEnabled() ); - } - } - - if ( ( _eInitWhat & InitFont ) != 0 ) - { - if ( m_bNavigationBar ) - { - Font aFont = m_aBar.GetSettings().GetStyleSettings().GetFieldFont(); - if ( IsControlFont() ) - m_aBar.SetControlFont( GetControlFont() ); - else - m_aBar.SetControlFont(); - - m_aBar.SetZoom( GetZoom() ); - } - } - - if ( ( _eInitWhat & InitBackground ) != 0 ) - { - if (IsControlBackground()) - { - GetDataWindow().SetBackground(GetControlBackground()); - GetDataWindow().SetControlBackground(GetControlBackground()); - GetDataWindow().SetFillColor(GetControlBackground()); - } - else - { - GetDataWindow().SetControlBackground(); - GetDataWindow().SetFillColor(GetFillColor()); - } - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::RemoveRows(sal_Bool bNewCursor) -{ - // Hat sich der DatenCursor verandert ? - if (!bNewCursor) - { - DELETEZ(m_pSeekCursor); - m_xPaintRow = m_xDataRow = m_xEmptyRow = m_xCurrentRow = m_xSeekRow = NULL; - m_nCurrentPos = m_nSeekPos = -1; - m_nOptions = OPT_READONLY; - - RowRemoved(0, GetRowCount(), sal_False); - m_nTotalCount = -1; - } - else - { - RemoveRows(); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::RemoveRows() -{ - // we're going to remove all columns and all row, so deactivate the current cell - if (IsEditing()) - DeactivateCell(); - - // alle Columns deinitialisieren - // existieren Spalten, dann alle Controller freigeben - for (size_t i = 0; i < m_aColumns.size(); i++) - m_aColumns[ i ]->Clear(); - - DELETEZ(m_pSeekCursor); - DELETEZ(m_pDataCursor); - - m_xPaintRow = m_xDataRow = m_xEmptyRow = m_xCurrentRow = m_xSeekRow = NULL; - m_nCurrentPos = m_nSeekPos = m_nTotalCount = -1; - m_nOptions = OPT_READONLY; - - // Anzahl Saetze im Browser auf 0 zuruecksetzen - DbGridControl_Base::RemoveRows(); - m_aBar.InvalidateAll(m_nCurrentPos, sal_True); -} - -//------------------------------------------------------------------------------ -void DbGridControl::ArrangeControls(sal_uInt16& nX, sal_uInt16 nY) -{ - // Positionierung der Controls - if (m_bNavigationBar) - { - nX = m_aBar.GetDefaultWidth(); - Rectangle aRect(GetControlArea()); - m_aBar.SetPosSizePixel(Point(0,nY + 1), Size(nX, aRect.GetSize().Height() - 1)); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::EnableHandle(sal_Bool bEnable) -{ - if (m_bHandle == bEnable) - return; - - // HandleColumn wird nur ausgeblendet, - // da es sonst etliche Probleme mit dem Zeichnen gibt - RemoveColumn(0); - m_bHandle = bEnable; - InsertHandleColumn(); -} - -//------------------------------------------------------------------------------ -namespace -{ - bool adjustModeForScrollbars( BrowserMode& _rMode, sal_Bool _bNavigationBar, sal_Bool _bHideScrollbars ) - { - BrowserMode nOldMode = _rMode; - - if ( !_bNavigationBar ) - { - _rMode &= ~BROWSER_AUTO_HSCROLL; - } - - if ( _bHideScrollbars ) - { - _rMode |= ( BROWSER_NO_HSCROLL | BROWSER_NO_VSCROLL ); - _rMode &= ~( BROWSER_AUTO_HSCROLL | BROWSER_AUTO_VSCROLL ); - } - else - { - _rMode |= ( BROWSER_AUTO_HSCROLL | BROWSER_AUTO_VSCROLL ); - _rMode &= ~( BROWSER_NO_HSCROLL | BROWSER_NO_VSCROLL ); - } - - // note: if we have a navigation bar, we always have a AUTO_HSCROLL. In particular, - // _bHideScrollbars is ignored then - if ( _bNavigationBar ) - { - _rMode |= BROWSER_AUTO_HSCROLL; - _rMode &= ~BROWSER_NO_HSCROLL; - } - - return nOldMode != _rMode; - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::EnableNavigationBar(sal_Bool bEnable) -{ - if (m_bNavigationBar == bEnable) - return; - - m_bNavigationBar = bEnable; - - if (bEnable) - { - m_aBar.Show(); - m_aBar.Enable(); - m_aBar.InvalidateAll(m_nCurrentPos, sal_True); - - if ( adjustModeForScrollbars( m_nMode, m_bNavigationBar, m_bHideScrollbars ) ) - SetMode( m_nMode ); - - // liefert die Groe�e der Reserved ControlArea - Point aPoint = GetControlArea().TopLeft(); - sal_uInt16 nX = (sal_uInt16)aPoint.X(); - - ArrangeControls(nX, (sal_uInt16)aPoint.Y()); - ReserveControlArea((sal_uInt16)nX); - } - else - { - m_aBar.Hide(); - m_aBar.Disable(); - - if ( adjustModeForScrollbars( m_nMode, m_bNavigationBar, m_bHideScrollbars ) ) - SetMode( m_nMode ); - - ReserveControlArea(); - } -} - -//------------------------------------------------------------------------------ -sal_uInt16 DbGridControl::SetOptions(sal_uInt16 nOpt) -{ - DBG_ASSERT(!m_xCurrentRow || !m_xCurrentRow->IsModified(), - "DbGridControl::SetOptions : please do not call when editing a record (things are much easier this way ;) !"); - - // for the next setDataSource (which is triggered by a refresh, for instance) - m_nOptionMask = nOpt; - - // normalize the new options - Reference< XPropertySet > xDataSourceSet = m_pDataCursor->getPropertySet(); - if (xDataSourceSet.is()) - { - // feststellen welche Updatem�glichkeiten bestehen - sal_Int32 nPrivileges = 0; - xDataSourceSet->getPropertyValue(FM_PROP_PRIVILEGES) >>= nPrivileges; - if ((nPrivileges & Privilege::INSERT) == 0) - nOpt &= ~OPT_INSERT; - if ((nPrivileges & Privilege::UPDATE) == 0) - nOpt &= ~OPT_UPDATE; - if ((nPrivileges & Privilege::DELETE) == 0) - nOpt &= ~OPT_DELETE; - } - else - nOpt = OPT_READONLY; - - // need to do something after that ? - if (nOpt == m_nOptions) - return m_nOptions; - - // the 'update' option only affects our BrowserMode (with or w/o focus rect) - BrowserMode nNewMode = m_nMode; - if ((m_nMode & BROWSER_CURSOR_WO_FOCUS) == 0) - { - if (nOpt & OPT_UPDATE) - nNewMode |= BROWSER_HIDECURSOR; - else - nNewMode &= ~BROWSER_HIDECURSOR; - } - else - nNewMode &= ~BROWSER_HIDECURSOR; - // should not be neccessary if EnablePermanentCursor is used to change the cursor behaviour, but to be sure ... - - if (nNewMode != m_nMode) - { - SetMode(nNewMode); - m_nMode = nNewMode; - } - - // _after_ setting the mode because this results in an ActivateCell - DeactivateCell(); - - sal_Bool bInsertChanged = (nOpt & OPT_INSERT) != (m_nOptions & OPT_INSERT); - m_nOptions = nOpt; - // we need to set this before the code below because it indirectly uses m_nOptions - - // the 'insert' option affects our empty row - if (bInsertChanged) - { - if (m_nOptions & OPT_INSERT) - { // the insert option is to be set - m_xEmptyRow = new DbGridRow(); - RowInserted(GetRowCount(), 1, sal_True); - } - else - { // the insert option is to be reset - m_xEmptyRow = NULL; - if ((GetCurRow() == GetRowCount() - 1) && (GetCurRow() > 0)) - GoToRowColumnId(GetCurRow() - 1, GetCurColumnId()); - RowRemoved(GetRowCount(), 1, sal_True); - } - } - - // the 'delete' options has no immediate consequences - - ActivateCell(); - Invalidate(); - return m_nOptions; -} - -//------------------------------------------------------------------------------ -void DbGridControl::ForceHideScrollbars( sal_Bool _bForce ) -{ - if ( m_bHideScrollbars == _bForce ) - return; - - m_bHideScrollbars = _bForce; - - if ( adjustModeForScrollbars( m_nMode, m_bNavigationBar, m_bHideScrollbars ) ) - SetMode( m_nMode ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::IsForceHideScrollbars() const -{ - return m_bHideScrollbars; -} - -//------------------------------------------------------------------------------ -void DbGridControl::EnablePermanentCursor(sal_Bool bEnable) -{ - if (IsPermanentCursorEnabled() == bEnable) - return; - - if (bEnable) - { - m_nMode &= ~BROWSER_HIDECURSOR; // without this BROWSER_CURSOR_WO_FOCUS won't have any affect - m_nMode |= BROWSER_CURSOR_WO_FOCUS; - } - else - { - if (m_nOptions & OPT_UPDATE) - m_nMode |= BROWSER_HIDECURSOR; // no cursor at all - else - m_nMode &= ~BROWSER_HIDECURSOR; // at least the "non-permanent" cursor - - m_nMode &= ~BROWSER_CURSOR_WO_FOCUS; - } - SetMode(m_nMode); - - sal_Bool bWasEditing = IsEditing(); - DeactivateCell(); - if (bWasEditing) - ActivateCell(); -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::IsPermanentCursorEnabled() const -{ - return ((m_nMode & BROWSER_CURSOR_WO_FOCUS) != 0) && ((m_nMode & BROWSER_HIDECURSOR) == 0); -} - -//------------------------------------------------------------------------------ -void DbGridControl::refreshController(sal_uInt16 _nColId, GrantControlAccess /*_aAccess*/) -{ - if ((GetCurColumnId() == _nColId) && IsEditing()) - { // the controller which is currently active needs to be refreshed - DeactivateCell(); - ActivateCell(); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::SetMultiSelection(sal_Bool bMulti) -{ - m_bMultiSelection = bMulti; - if (m_bMultiSelection) - m_nMode |= BROWSER_MULTISELECTION; - else - m_nMode &= ~BROWSER_MULTISELECTION; - - SetMode(m_nMode); -} - -//------------------------------------------------------------------------------ -void DbGridControl::setDataSource(const Reference< XRowSet >& _xCursor, sal_uInt16 nOpts) -{ - if (!_xCursor.is() && !m_pDataCursor) - return; - - if (m_pDataSourcePropMultiplexer) - { - m_pDataSourcePropMultiplexer->dispose(); - m_pDataSourcePropMultiplexer->release(); // this should delete the multiplexer - delete m_pDataSourcePropListener; - m_pDataSourcePropMultiplexer = NULL; - m_pDataSourcePropListener = NULL; - } - m_xRowSetListener.clear(); - - // is the new cursor valid ? - // the cursor is only valid if it contains some columns - // if there is no cursor or the cursor is not valid we have to clean up an leave - if (!_xCursor.is() || !Reference< XColumnsSupplier > (_xCursor, UNO_QUERY)->getColumns()->hasElements()) - { - RemoveRows(); - return; - } - - // Hat sich der DatenCursor verandert ? - sal_uInt16 nCurPos = GetColumnPos(GetCurColumnId()); - - SetUpdateMode(sal_False); - RemoveRows(); - DisconnectFromFields(); - - DELETEZ(m_pCursorDisposeListener); - - { - ::osl::MutexGuard aGuard(m_aAdjustSafety); - if (m_nAsynAdjustEvent) - { - // the adjust was thought to work with the old cursor which we don't have anymore - RemoveUserEvent(m_nAsynAdjustEvent); - m_nAsynAdjustEvent = 0; - } - } - - // get a new formatter and data cursor - m_xFormatter = NULL; - OStaticDataAccessTools aStaticTools; - Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = aStaticTools.getNumberFormats(aStaticTools.getRowSetConnection(_xCursor), sal_True); - if (xSupplier.is() && m_xServiceFactory.is()) - { - m_xFormatter = Reference< ::com::sun::star::util::XNumberFormatter >( - m_xServiceFactory->createInstance(FM_NUMBER_FORMATTER), - UNO_QUERY); - if (m_xFormatter.is()) - { - m_xFormatter->attachNumberFormatsSupplier(xSupplier); - - // retrieve the datebase of the Numberformatter - try - { - xSupplier->getNumberFormatSettings()->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NullDate"))) >>= m_aNullDate; - } - catch(Exception&) - { - } - } - } - - m_pDataCursor = new CursorWrapper(_xCursor); - - // now create a cursor for painting rows - // we need that cursor only if we are not in insert only mode - Reference< XResultSet > xClone; - Reference< XResultSetAccess > xAccess( _xCursor, UNO_QUERY ); - try - { - xClone = xAccess.is() ? xAccess->createResultSet() : Reference< XResultSet > (); - } - catch(Exception&) - { - } - if (xClone.is()) - m_pSeekCursor = new CursorWrapper(xClone); - - // property listening on the data source - // (Normally one class would be sufficient : the multiplexer which could forward the property change to us. - // But for that we would have been derived from ::comphelper::OPropertyChangeListener, which isn't exported. - // So we introduce a second class, which is a ::comphelper::OPropertyChangeListener (in the implementation file we know this class) - // and forwards the property changes to a our special method "DataSourcePropertyChanged".) - if (m_pDataCursor) - { - m_pDataSourcePropListener = new FmXGridSourcePropListener(this); - m_pDataSourcePropMultiplexer = new ::comphelper::OPropertyChangeMultiplexer(m_pDataSourcePropListener, m_pDataCursor->getPropertySet() ); - m_pDataSourcePropMultiplexer->acquire(); - m_pDataSourcePropMultiplexer->addProperty(FM_PROP_ISMODIFIED); - m_pDataSourcePropMultiplexer->addProperty(FM_PROP_ISNEW); - } - - BrowserMode nOldMode = m_nMode; - if (m_pSeekCursor) - { - try - { - Reference< XPropertySet > xSet(_xCursor, UNO_QUERY); - if (xSet.is()) - { - // feststellen welche Updatemoeglichkeiten bestehen - sal_Int32 nConcurrency = ResultSetConcurrency::READ_ONLY; - xSet->getPropertyValue(FM_PROP_RESULTSET_CONCURRENCY) >>= nConcurrency; - - if ( ResultSetConcurrency::UPDATABLE == nConcurrency ) - { - sal_Int32 nPrivileges = 0; - xSet->getPropertyValue(FM_PROP_PRIVILEGES) >>= nPrivileges; - - // Insert Option should be set if insert only otherwise you won't see any rows - // and no insertion is possible - if ((m_nOptionMask & OPT_INSERT) && ((nPrivileges & Privilege::INSERT) == Privilege::INSERT) && (nOpts & OPT_INSERT)) - m_nOptions |= OPT_INSERT; - if ((m_nOptionMask & OPT_UPDATE) && ((nPrivileges & Privilege::UPDATE) == Privilege::UPDATE) && (nOpts & OPT_UPDATE)) - m_nOptions |= OPT_UPDATE; - if ((m_nOptionMask & OPT_DELETE) && ((nPrivileges & Privilege::DELETE) == Privilege::DELETE) && (nOpts & OPT_DELETE)) - m_nOptions |= OPT_DELETE; - } - } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - - sal_Bool bPermanentCursor = IsPermanentCursorEnabled(); - m_nMode = DEFAULT_BROWSE_MODE; - - if ( bPermanentCursor ) - { - m_nMode |= BROWSER_CURSOR_WO_FOCUS; - m_nMode &= ~BROWSER_HIDECURSOR; - } - else - { - // Duerfen Updates gemacht werden, kein Focus-RechtEck - if ( m_nOptions & OPT_UPDATE ) - m_nMode |= BROWSER_HIDECURSOR; - } - - if ( m_bMultiSelection ) - m_nMode |= BROWSER_MULTISELECTION; - else - m_nMode &= ~BROWSER_MULTISELECTION; - - adjustModeForScrollbars( m_nMode, m_bNavigationBar, m_bHideScrollbars ); - - Reference< XColumnsSupplier > xSupplyColumns(_xCursor, UNO_QUERY); - if (xSupplyColumns.is()) - InitColumnsByFields(Reference< XIndexAccess > (xSupplyColumns->getColumns(), UNO_QUERY)); - - ConnectToFields(); - } - - sal_uInt32 nRecordCount(0); - - if (m_pSeekCursor) - { - Reference< XPropertySet > xSet = m_pDataCursor->getPropertySet(); - xSet->getPropertyValue(FM_PROP_ROWCOUNT) >>= nRecordCount; - m_bRecordCountFinal = ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ROWCOUNTFINAL)); - - m_xRowSetListener = new RowSetEventListener(this); - Reference< XRowsChangeBroadcaster> xChangeBroad(xSet,UNO_QUERY); - if ( xChangeBroad.is( ) ) - xChangeBroad->addRowsChangeListener(m_xRowSetListener); - - - // insert the currently known rows - // and one row if we are able to insert rows - if (m_nOptions & OPT_INSERT) - { - // insert the empty row for insertion - m_xEmptyRow = new DbGridRow(); - ++nRecordCount; - } - if (nRecordCount) - { - m_xPaintRow = m_xSeekRow = new DbGridRow(m_pSeekCursor, sal_True); - m_xDataRow = new DbGridRow(m_pDataCursor, sal_False); - RowInserted(0, nRecordCount, sal_False); - - if (m_xSeekRow->IsValid()) - try - { - m_nSeekPos = m_pSeekCursor->getRow() - 1; - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - m_nSeekPos = -1; - } - } - else - { - // no rows so we don't need a seekcursor - DELETEZ(m_pSeekCursor); - } - } - - // Zur alten Spalte gehen - if (!nCurPos || nCurPos >= ColCount()) - nCurPos = 1; - - // there are rows so go to the selected current column - if (nRecordCount) - GoToRowColumnId(0, GetColumnId(nCurPos)); - // else stop the editing if neccessary - else if (IsEditing()) - DeactivateCell(); - - // now reset the mode - if (m_nMode != nOldMode) - SetMode(m_nMode); - - // beim Resizen wird RecalcRows gerufen - if (!IsResizing() && GetRowCount()) - RecalcRows(GetTopRow(), GetVisibleRows(), sal_True); - - m_aBar.InvalidateAll(m_nCurrentPos, sal_True); - SetUpdateMode(sal_True); - - // start listening on the seek cursor - if (m_pSeekCursor) - m_pCursorDisposeListener = new DisposeListenerGridBridge(*this, Reference< XComponent > ((Reference< XInterface >)*m_pSeekCursor, UNO_QUERY), 0); -} - -//------------------------------------------------------------------------------ -void DbGridControl::RemoveColumns() -{ - if ( IsEditing() ) - DeactivateCell(); - - for (size_t i = 0, n = m_aColumns.size(); i < n; i++) - delete m_aColumns[ i ]; - m_aColumns.clear(); - - DbGridControl_Base::RemoveColumns(); -} - -//------------------------------------------------------------------------------ -DbGridColumn* DbGridControl::CreateColumn(sal_uInt16 nId) const -{ - return new DbGridColumn(nId, *(DbGridControl*)this); -} - -//------------------------------------------------------------------------------ -sal_uInt16 DbGridControl::AppendColumn(const XubString& rName, sal_uInt16 nWidth, sal_uInt16 nModelPos, sal_uInt16 nId) -{ - DBG_ASSERT(nId == (sal_uInt16)-1, "DbGridControl::AppendColumn : I want to set the ID myself ..."); - sal_uInt16 nRealPos = nModelPos; - if (nModelPos != HEADERBAR_APPEND) - { - // calc the view pos. we can't use our converting functions because the new column - // has no VCL-representation, yet. - sal_Int16 nViewPos = nModelPos; - while (nModelPos--) - { - if ( m_aColumns[ nModelPos ]->IsHidden() ) - --nViewPos; - } - // restore nModelPos, we need it later - nModelPos = nRealPos; - // the position the base class gets is the view pos + 1 (because of the handle column) - nRealPos = nViewPos + 1; - } - - // calculate the new id - for (nId=1; (GetModelColumnPos(nId) != GRID_COLUMN_NOT_FOUND) && (nId <= m_aColumns.size()); ++nId) - ; - DBG_ASSERT(GetViewColumnPos(nId) == (sal_uInt16)-1, "DbGridControl::AppendColumn : inconsistent internal state !"); - // my column's models say "there is no column with id nId", but the view (the base class) says "there is a column ..." - - DbGridControl_Base::AppendColumn(rName, nWidth, nRealPos, nId); - if (nModelPos == HEADERBAR_APPEND) - m_aColumns.push_back( CreateColumn(nId) ); - else - { - DbGridColumns::iterator it = m_aColumns.begin(); - ::std::advance( it, nModelPos ); - m_aColumns.insert( it, CreateColumn(nId) ); - } - - return nId; -} - -//------------------------------------------------------------------------------ -void DbGridControl::RemoveColumn(sal_uInt16 nId) -{ - const sal_uInt16 nIndex = GetModelColumnPos(nId); - if(nIndex != GRID_COLUMN_NOT_FOUND) - { - DbGridControl_Base::RemoveColumn(nId); - delete m_aColumns[nIndex]; - m_aColumns.erase( m_aColumns.begin()+nIndex ); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::ColumnMoved(sal_uInt16 nId) -{ - DbGridControl_Base::ColumnMoved(nId); - - // remove the col from the model - sal_uInt16 nOldModelPos = GetModelColumnPos(nId); -#ifdef DBG_UTIL - DbGridColumn* pCol = m_aColumns[ (sal_uInt32)nOldModelPos ]; - DBG_ASSERT(!pCol->IsHidden(), "DbGridControl::ColumnMoved : moved a hidden col ? how this ?"); -#endif - - // for the new model pos we can't use GetModelColumnPos because we are altering the model at the moment - // so the method won't work (in fact it would return the old model pos) - - // the new view pos is calculated easily - sal_uInt16 nNewViewPos = GetViewColumnPos(nId); - - // from that we can compute the new model pos - sal_uInt16 nNewModelPos; - for (nNewModelPos = 0; nNewModelPos < m_aColumns.size(); ++nNewModelPos) - { - if (!m_aColumns[ nNewModelPos ]->IsHidden()) - { - if (!nNewViewPos) - break; - else - --nNewViewPos; - } - } - DBG_ASSERT( nNewModelPos < m_aColumns.size(), "DbGridControl::ColumnMoved : could not find the new model position !"); - - // this will work. of course the model isn't fully consistent with our view right now, but let's - // look at the situation : a column has been moved with in the VIEW from pos m to n, say m<n (in the - // other case we can use analogue arguments). - // All cols k with m<k<=n have been shifted left on pos, the former col m now has pos n. - // In the model this affects a range of cols x to y, where x<=m and y<=n. And the number of hidden cols - // within this range is constant, so we may calculate the view pos from the model pos in the above way. - // - // for instance, let's look at a grid with six columns where the third one is hidden. this will - // initially look like this : - // - // +---+---+---+---+---+---+ - // model pos | 0 | 1 |*2*| 3 | 4 | 5 | - // +---+---+---+---+---+---+ - // ID | 1 | 2 | 3 | 4 | 5 | 6 | - // +---+---+---+---+---+---+ - // view pos | 0 | 1 | - | 2 | 3 | 4 | - // +---+---+---+---+---+---+ - // - // if we move the column at (view) pos 1 to (view) pos 3 we have : - // - // +---+---+---+---+---+---+ - // model pos | 0 | 3 |*2*| 4 | 1 | 5 | // not reflecting the changes, yet - // +---+---+---+---+---+---+ - // ID | 1 | 4 | 3 | 5 | 2 | 6 | // already reflecting the changes - // +---+---+---+---+---+---+ - // view pos | 0 | 1 | - | 2 | 3 | 4 | - // +---+---+---+---+---+---+ - // - // or, sorted by the out-of-date model positions : - // - // +---+---+---+---+---+---+ - // model pos | 0 | 1 |*2*| 3 | 4 | 5 | - // +---+---+---+---+---+---+ - // ID | 1 | 2 | 3 | 4 | 5 | 6 | - // +---+---+---+---+---+---+ - // view pos | 0 | 3 | - | 1 | 2 | 4 | - // +---+---+---+---+---+---+ - // - // We know the new view pos (3) of the moved column because our base class tells us. So we look at our - // model for the 4th (the pos is zero-based) visible column, it is at (model) position 4. And this is - // exactly the pos where we have to re-insert our column's model, so it looks ike this : - // - // +---+---+---+---+---+---+ - // model pos | 0 |*1*| 2 | 3 | 4 | 5 | - // +---+---+---+---+---+---+ - // ID | 1 | 3 | 4 | 5 | 2 | 6 | - // +---+---+---+---+---+---+ - // view pos | 0 | - | 1 | 2 | 3 | 4 | - // +---+---+---+---+---+---+ - // - // Now, all is consistent again. - // (except of the hidden column : The cycling of the cols occurred on the model, not on the view. maybe - // the user expected the latter but there really is no good argument against our method ;) ...) - // - // And no, this large explanation isn't just because I wanted to play a board game or something like - // that. It's because it took me a while to see it myself, and the whole theme (hidden cols, model col - // positions, view col positions) is really painful (at least for me) so the above pictures helped me a lot ;) - - - DbGridColumn* temp = m_aColumns[ nOldModelPos ]; - - DbGridColumns::iterator it = m_aColumns.begin(); - ::std::advance( it, nOldModelPos ); - m_aColumns.erase( it ); - - it = m_aColumns.begin(); - ::std::advance( it, nNewModelPos ); - m_aColumns.insert( it, temp ); -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::SeekRow(long nRow) -{ - // in filter mode or in insert only mode we don't have any cursor! - if ( !SeekCursor( nRow ) ) - return sal_False; - - if ( IsFilterMode() ) - { - DBG_ASSERT( IsFilterRow( nRow ), "DbGridControl::SeekRow(): No filter row, wrong mode" ); - m_xPaintRow = m_xEmptyRow; - } - else - { - // on the current position we have to take the current row for display as we want - // to have the most recent values for display - if ( ( nRow == m_nCurrentPos ) && getDisplaySynchron() ) - m_xPaintRow = m_xCurrentRow; - // seek to the empty insert row - else if ( IsInsertionRow( nRow ) ) - m_xPaintRow = m_xEmptyRow; - else - { - m_xSeekRow->SetState( m_pSeekCursor, sal_True ); - m_xPaintRow = m_xSeekRow; - } - } - - DbGridControl_Base::SeekRow(nRow); - - return m_nSeekPos >= 0; -} -//------------------------------------------------------------------------------ -// Wird aufgerufen, wenn die dargestellte Datenmenge sich aendert -//------------------------------------------------------------------------------ -void DbGridControl::VisibleRowsChanged( long nNewTopRow, sal_uInt16 nLinesOnScreen ) -{ - RecalcRows(nNewTopRow, nLinesOnScreen , sal_False); -} - -//------------------------------------------------------------------------------ -void DbGridControl::RecalcRows(long nNewTopRow, sal_uInt16 nLinesOnScreen, sal_Bool bUpdateCursor) -{ - DBG_CHKTHIS( DbGridControl, NULL ); - // Wenn kein Cursor -> keine Rows im Browser. - if (!m_pSeekCursor) - { - DBG_ASSERT(GetRowCount() == 0,"DbGridControl: ohne Cursor darf es keine Rows geben"); - return; - } - - // ignore any updates implicit made - sal_Bool bDisablePaint = !bUpdateCursor && IsPaintEnabled(); - if (bDisablePaint) - EnablePaint(sal_False); - - // Cache an den sichtbaren Bereich anpassen - Reference< XPropertySet > xSet = m_pSeekCursor->getPropertySet(); - sal_Int32 nCacheSize = 0; - xSet->getPropertyValue(FM_PROP_FETCHSIZE) >>= nCacheSize; - sal_Bool bCacheAligned = sal_False; - // Nach der Initialisierung (m_nSeekPos < 0) keine Cursorbewegung, da bereits auf den ersten - // Satz positioniert - long nDelta = nNewTopRow - GetTopRow(); - // Limit fuer relative Positionierung - long nLimit = (nCacheSize) ? nCacheSize / 2 : 0; - - // mehr Zeilen auf dem Bildschirm als im Cache - if (nLimit < nLinesOnScreen) - { - Any aCacheSize; - aCacheSize <<= sal_Int32(nLinesOnScreen*2); - xSet->setPropertyValue(FM_PROP_FETCHSIZE, aCacheSize); - // jetzt auf alle Faelle den Cursor anpassen - bUpdateCursor = sal_True; - bCacheAligned = sal_True; - nLimit = nLinesOnScreen; - } - - // Im folgenden werden die Positionierungen so vorgenommen, da� sichergestellt ist - // da� ausreichend Zeilen im DatenCache vorhanden sind - - // Fenster geht nach unten, weniger als zwei Fenster Differenz - // oder Cache angepasst und noch kein Rowcount - if (nDelta < nLimit && (nDelta > 0 - || (bCacheAligned && m_nTotalCount < 0)) ) - SeekCursor(nNewTopRow + nLinesOnScreen - 1, sal_False); - else if (nDelta < 0 && Abs(nDelta) < nLimit) - SeekCursor(nNewTopRow, sal_False); - else if (nDelta != 0 || bUpdateCursor) - SeekCursor(nNewTopRow, sal_True); - - AdjustRows(); - - // ignore any updates implicit made - EnablePaint(sal_True); -} - -//------------------------------------------------------------------------------ -void DbGridControl::RowInserted(long nRow, long nNumRows, sal_Bool bDoPaint, sal_Bool bKeepSelection) -{ - if (nNumRows) - { - if (m_bRecordCountFinal && m_nTotalCount < 0) - { - // if we have an insert row we have to reduce to count by 1 - // as the total count reflects only the existing rows in database - m_nTotalCount = GetRowCount() + nNumRows; - if (m_xEmptyRow.Is()) - --m_nTotalCount; - } - else if (m_nTotalCount >= 0) - m_nTotalCount += nNumRows; - - DbGridControl_Base::RowInserted(nRow, nNumRows, bDoPaint, bKeepSelection); - m_aBar.InvalidateState(NavigationBar::RECORD_COUNT); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::RowRemoved(long nRow, long nNumRows, sal_Bool bDoPaint) -{ - if (nNumRows) - { - if (m_bRecordCountFinal && m_nTotalCount < 0) - { - m_nTotalCount = GetRowCount() - nNumRows; - // if we have an insert row reduce by 1 - if (m_xEmptyRow.Is()) - --m_nTotalCount; - } - else if (m_nTotalCount >= 0) - m_nTotalCount -= nNumRows; - - DbGridControl_Base::RowRemoved(nRow, nNumRows, bDoPaint); - m_aBar.InvalidateState(NavigationBar::RECORD_COUNT); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::AdjustRows() -{ - if (!m_pSeekCursor) - return; - - Reference< XPropertySet > xSet = m_pDataCursor->getPropertySet(); - - // Aktualisieren des RecordCounts - sal_Int32 nRecordCount = 0; - xSet->getPropertyValue(FM_PROP_ROWCOUNT) >>= nRecordCount; - if (!m_bRecordCountFinal) - m_bRecordCountFinal = ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ROWCOUNTFINAL)); - - // hat sich die aktuelle Anzahl Rows veraendert - // hierbei muss auch beruecksichtigt werden, - // das eine zusaetzliche Zeile zum einfuegen von Datensaetzen vorhanden sein kann - - // zusaetzliche AppendRow fuers einfuegen - if (m_nOptions & OPT_INSERT) - ++nRecordCount; - - // wird gerade eingefuegt, dann gehoert die gerade hinzuzufuegende - // Zeile nicht zum RecordCount und die Appendrow ebenfalls nicht - if (!IsUpdating() && m_bRecordCountFinal && IsModified() && m_xCurrentRow != m_xEmptyRow && - m_xCurrentRow->IsNew()) - ++nRecordCount; - // das ist mit !m_bUpdating abgesichert : innerhalb von SaveRow (m_bUpdating == sal_True) wuerde sonst der Datensatz, den ich editiere - // (und den SaveRow gerade angefuegt hat, wodurch diese Methode hier getriggert wurde), doppelt zaehlen : einmal ist er schon - // in dem normalen RecordCount drin, zum zweiten wuerde er hier gezaehlt werden (60787 - FS) - - if (nRecordCount != GetRowCount()) - { - long nDelta = GetRowCount() - (long)nRecordCount; - if (nDelta > 0) // zuviele - { - RowRemoved(GetRowCount() - nDelta, nDelta, sal_False); - // es sind Zeilen weggefallen, dann ab der aktuellen Position neu zeichen - Invalidate(); - - sal_Int32 nNewPos = AlignSeekCursor(); - if (m_bSynchDisplay) - DbGridControl_Base::GoToRow(nNewPos); - - SetCurrent(nNewPos); - // there are rows so go to the selected current column - if (nRecordCount) - GoToRowColumnId(nNewPos, GetColumnId(GetCurColumnId())); - if (!IsResizing() && GetRowCount()) - RecalcRows(GetTopRow(), GetVisibleRows(), sal_True); - m_aBar.InvalidateAll(m_nCurrentPos, sal_True); - } - else // zuwenig - RowInserted(GetRowCount(), -nDelta, sal_True); - } - - if (m_bRecordCountFinal && m_nTotalCount < 0) - { - if (m_nOptions & OPT_INSERT) - m_nTotalCount = GetRowCount() - 1; - else - m_nTotalCount = GetRowCount(); - } - m_aBar.InvalidateState(NavigationBar::RECORD_COUNT); -} - -//------------------------------------------------------------------------------ -DbGridControl_Base::RowStatus DbGridControl::GetRowStatus(long nRow) const -{ - if (IsFilterRow(nRow)) - return DbGridControl_Base::FILTER; - else if (m_nCurrentPos >= 0 && nRow == m_nCurrentPos) - { - // neue Zeile - if (!IsValid(m_xCurrentRow)) - return DbGridControl_Base::DELETED; - else if (IsModified()) - return DbGridControl_Base::MODIFIED; - else if (m_xCurrentRow->IsNew()) - return DbGridControl_Base::CURRENTNEW; - else - return DbGridControl_Base::CURRENT; - } - else if (IsInsertionRow(nRow)) - return DbGridControl_Base::NEW; - else if (!IsValid(m_xSeekRow)) - return DbGridControl_Base::DELETED; - else - return DbGridControl_Base::CLEAN; -} - -//------------------------------------------------------------------------------ -void DbGridControl::PaintStatusCell(OutputDevice& rDev, const Rectangle& rRect) const -{ - DbGridControl_Base::PaintStatusCell(rDev, rRect); -} - -//------------------------------------------------------------------------------ -void DbGridControl::PaintCell(OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId) const -{ - if (!IsValid(m_xPaintRow)) - return; - - size_t Location = GetModelColumnPos(nColumnId); - DbGridColumn* pColumn = (Location < m_aColumns.size() ) ? m_aColumns[ Location ] : NULL; - if (pColumn) - { - Rectangle aArea(rRect); - if ((GetMode() & BROWSER_CURSOR_WO_FOCUS) == BROWSER_CURSOR_WO_FOCUS) - { - aArea.Top() += 1; - aArea.Bottom() -= 1; - } - pColumn->Paint(rDev, aArea, m_xPaintRow, getNumberFormatter()); - } -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::CursorMoving(long nNewRow, sal_uInt16 nNewCol) -{ - DBG_CHKTHIS( DbGridControl, NULL ); - - DeactivateCell( sal_False ); - - if ( m_pDataCursor - && ( m_nCurrentPos != nNewRow ) - && !SetCurrent( nNewRow ) - ) - { - ActivateCell(); - return sal_False; - } - - if ( !DbGridControl_Base::CursorMoving( nNewRow, nNewCol ) ) - return sal_False; - - return sal_True; -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::SetCurrent(long nNewRow) -{ - // Each movement of the datacursor must start with BeginCursorAction and end with - // EndCursorAction to block all notifications during the movement - BeginCursorAction(); - - try - { - // Abgleichen der Positionen - if (SeekCursor(nNewRow)) - { - if (IsFilterRow(nNewRow)) // special mode for filtering - { - m_xCurrentRow = m_xDataRow = m_xPaintRow = m_xEmptyRow; - m_nCurrentPos = nNewRow; - } - else - { - sal_Bool bNewRowInserted = sal_False; - // Should we go to the insertrow ? - if (IsInsertionRow(nNewRow)) - { - // to we need to move the cursor to the insert row? - // we need to insert the if the current row isn't the insert row or if the - // cursor triggered the move by itselt and we need a reinitialization of the row - Reference< XPropertySet > xCursorProps = m_pDataCursor->getPropertySet(); - if ( !::comphelper::getBOOL(xCursorProps->getPropertyValue(FM_PROP_ISNEW)) ) - { - Reference< XResultSetUpdate > xUpdateCursor((Reference< XInterface >)*m_pDataCursor, UNO_QUERY); - xUpdateCursor->moveToInsertRow(); - } - bNewRowInserted = sal_True; - } - else - { - - if ( !m_pSeekCursor->isBeforeFirst() && !m_pSeekCursor->isAfterLast() ) - { - Any aBookmark = m_pSeekCursor->getBookmark(); - if (!m_xCurrentRow || m_xCurrentRow->IsNew() || !CompareBookmark(aBookmark, m_pDataCursor->getBookmark())) - { - // adjust the cursor to the new desired row - if (!m_pDataCursor->moveToBookmark(aBookmark)) - { - EndCursorAction(); - return sal_False; - } - } - } - } - m_xDataRow->SetState(m_pDataCursor, sal_False); - m_xCurrentRow = m_xDataRow; - - long nPaintPos = -1; - // do we have to repaint the last regular row in case of setting defaults or autovalues - if (m_nCurrentPos >= 0 && m_nCurrentPos >= (GetRowCount() - 2)) - nPaintPos = m_nCurrentPos; - - m_nCurrentPos = nNewRow; - - // repaint the new row to display all defaults - if (bNewRowInserted) - RowModified(m_nCurrentPos); - if (nPaintPos >= 0) - RowModified(nPaintPos); - } - } - else - { - OSL_FAIL("DbGridControl::SetCurrent : SeekRow failed !"); - EndCursorAction(); - return sal_False; - } - } - catch ( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - EndCursorAction(); - return sal_False; - } - - EndCursorAction(); - return sal_True; -} - -//------------------------------------------------------------------------------ -void DbGridControl::CursorMoved() -{ - DBG_CHKTHIS( DbGridControl, NULL ); - - // CursorBewegung durch loeschen oder einfuegen von Zeilen - if (m_pDataCursor && m_nCurrentPos != GetCurRow()) - { - DeactivateCell(sal_True); - SetCurrent(GetCurRow()); - } - - DbGridControl_Base::CursorMoved(); - m_aBar.InvalidateAll(m_nCurrentPos); - - // select the new column when they moved - if ( IsDesignMode() && GetSelectedColumnCount() > 0 && GetCurColumnId() ) - { - SelectColumnId( GetCurColumnId() ); - } - - if ( m_nLastColId != GetCurColumnId() ) - onColumnChange(); - m_nLastColId = GetCurColumnId(); - - if ( m_nLastRowId != GetCurRow() ) - onRowChange(); - m_nLastRowId = GetCurRow(); -} - -//------------------------------------------------------------------------------ -void DbGridControl::onRowChange() -{ - // not interested in -} - -//------------------------------------------------------------------------------ -void DbGridControl::onColumnChange() -{ - if ( m_pGridListener ) - m_pGridListener->columnChanged(); -} - -//------------------------------------------------------------------------------ -void DbGridControl::setDisplaySynchron(sal_Bool bSync) -{ - if (bSync != m_bSynchDisplay) - { - m_bSynchDisplay = bSync; - if (m_bSynchDisplay) - AdjustDataSource(sal_False); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::forceSyncDisplay() -{ - sal_Bool bOld = getDisplaySynchron(); - setDisplaySynchron(sal_True); - if (!bOld) - setDisplaySynchron(bOld); -} - -//------------------------------------------------------------------------------ -void DbGridControl::forceROController(sal_Bool bForce) -{ - if (m_bForceROController == bForce) - return; - - m_bForceROController = bForce; - // alle Columns durchgehen und denen Bescheid geben - for ( size_t i=0; i < m_aColumns.size(); ++i ) - { - DbGridColumn* pColumn = m_aColumns[ i ]; - if (!pColumn) - continue; - - CellController* pReturn = &pColumn->GetController(); - if (!pReturn) - continue; - - // nur wenn es eine Edit-Zeile ist, kann ich ihr das forced read-only mitgeben - if (!pReturn->ISA(EditCellController) && !pReturn->ISA(SpinCellController)) - continue; - - Edit& rEdit = (Edit&)pReturn->GetWindow(); - rEdit.SetReadOnly(m_bForceROController); - if (m_bForceROController) - rEdit.SetStyle(rEdit.GetStyle() | WB_NOHIDESELECTION); - else - rEdit.SetStyle(rEdit.GetStyle() & ~WB_NOHIDESELECTION); - } - - // die aktive Zelle erneut aktivieren, da sich ihr Controller geaendert haben kann - if (IsEditing()) - DeactivateCell(); - ActivateCell(); -} - - -//------------------------------------------------------------------------------ -void DbGridControl::AdjustDataSource(sal_Bool bFull) -{ - TRACE_RANGE("DbGridControl::AdjustDataSource"); - SolarMutexGuard aGuard; - // wird die aktuelle Zeile gerade neu bestimmt, - // wird kein abgleich vorgenommen - - if (bFull) - m_xCurrentRow = NULL; - // if we are on the same row only repaint - // but this is only possible for rows which are not inserted, in that case the comparision result - // may not be correct - else - if ( m_xCurrentRow.Is() - && !m_xCurrentRow->IsNew() - && !m_pDataCursor->isBeforeFirst() - && !m_pDataCursor->isAfterLast() - && !m_pDataCursor->rowDeleted() - ) - { - sal_Bool bEqualBookmarks = CompareBookmark( m_xCurrentRow->GetBookmark(), m_pDataCursor->getBookmark() ); - - sal_Bool bDataCursorIsOnNew = sal_False; - m_pDataCursor->getPropertySet()->getPropertyValue( FM_PROP_ISNEW ) >>= bDataCursorIsOnNew; - - if ( bEqualBookmarks && !bDataCursorIsOnNew ) - { - // position of my data cursor is the same as the position our current row points tpo - // sync the status, repaint, done - DBG_ASSERT(m_xDataRow == m_xCurrentRow, "Fehler in den Datenzeilen"); - TRACE_RANGE_MESSAGE1("same position, new state : %s", ROWSTATUS(m_xCurrentRow)); - RowModified(m_nCurrentPos); - return; - } - } - - // weg von der Row des DatenCursors - if (m_xPaintRow == m_xCurrentRow) - m_xPaintRow = m_xSeekRow; - - // keine aktuelle Zeile dann komplett anpassen - if (!m_xCurrentRow) - AdjustRows(); - - sal_Int32 nNewPos = AlignSeekCursor(); - if (nNewPos < 0) // keine Position gefunden - return; - - m_bInAdjustDataSource = sal_True; - if (nNewPos != m_nCurrentPos) - { - if (m_bSynchDisplay) - DbGridControl_Base::GoToRow(nNewPos); - - if (!m_xCurrentRow.Is()) - // das tritt zum Beispiel auf, wenn man die n (n>1) letzten Datensaetze geloescht hat, waehrend der Cursor auf dem letzten - // steht : AdjustRows entfernt dann zwei Zeilen aus der BrowseBox, wodurch diese ihre CurrentRow um zwei nach unten - // korrigiert, so dass dann das GoToRow in's Leere laeuft (da wir uns ja angeblich schon an der richtigen Position - // befinden) - SetCurrent(nNewPos); - } - else - { - SetCurrent(nNewPos); - RowModified(nNewPos); - } - m_bInAdjustDataSource = sal_False; - - // Wird der DatenCursor von aussen bewegt, wird die selektion aufgehoben - SetNoSelection(); - m_aBar.InvalidateAll(m_nCurrentPos, m_xCurrentRow.Is()); -} - -//------------------------------------------------------------------------------ -sal_Int32 DbGridControl::AlignSeekCursor() -{ - DBG_CHKTHIS( DbGridControl, NULL ); - // Positioniert den SeekCursor auf den DatenCursor, Daten werden nicht uebertragen - - if (!m_pSeekCursor) - return -1; - - Reference< XPropertySet > xSet = m_pDataCursor->getPropertySet(); - - // jetzt den seekcursor an den DatenCursor angleichen - if (::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISNEW))) - m_nSeekPos = GetRowCount() - 1; - else - { - try - { - if ( m_pDataCursor->isBeforeFirst() ) - { - // this is somewhat strange, but can nevertheless happen - DBG_WARNING( "DbGridControl::AlignSeekCursor: nobody should tamper with my cursor this way (before first)!" ); - m_pSeekCursor->first(); - m_pSeekCursor->previous(); - m_nSeekPos = -1; - } - else if ( m_pDataCursor->isAfterLast() ) - { - DBG_WARNING( "DbGridControl::AlignSeekCursor: nobody should tamper with my cursor this way (after last)!" ); - m_pSeekCursor->last(); - m_pSeekCursor->next(); - m_nSeekPos = -1; - } - else - { - m_pSeekCursor->moveToBookmark(m_pDataCursor->getBookmark()); - if (!CompareBookmark(m_pDataCursor->getBookmark(), m_pSeekCursor->getBookmark())) - // dummerweise kann das moveToBookmark indirekt dazu fuehren, dass der Seek-Cursor wieder neu positoniert wird (wenn - // naemlich das mit all seinen zu feuernden Events relativ komplexe moveToBookmark irgendwo ein Update ausloest), - // also muss ich es nochmal versuchen - m_pSeekCursor->moveToBookmark(m_pDataCursor->getBookmark()); - // Nicht dass das jetzt nicht auch schief gegangen sein koennte, aber es ist zumindest unwahrscheinlicher geworden. - // Und die Alternative waere eine Schleife so lange bis es stimmt, und das kann auch nicht die Loesung sein - m_nSeekPos = m_pSeekCursor->getRow() - 1; - } - } - catch(Exception&) - { - } - } - return m_nSeekPos; -} -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::SeekCursor(long nRow, sal_Bool bAbsolute) -{ - DBG_CHKTHIS( DbGridControl, NULL ); - // Positioniert den SeekCursor, Daten werden nicht uebertragen - - // additions for the filtermode - if (IsFilterRow(nRow)) - { - m_nSeekPos = 0; - return sal_True; - } - - if (!m_pSeekCursor) - return sal_False; - - // Befinden wir uns gerade beim Einfuegen - if (IsValid(m_xCurrentRow) && m_xCurrentRow->IsNew() && - nRow >= m_nCurrentPos) - { - // dann darf auf alle Faelle nicht weiter nach unten gescrollt werden - // da der letzte Datensatz bereits erreicht wurde! - if (nRow == m_nCurrentPos) - { - // auf die aktuelle Zeile bewegt, dann muß kein abgleich gemacht werden, wenn - // gerade ein Datensatz eingefuegt wird - m_nSeekPos = nRow; - } - else if (IsInsertionRow(nRow)) // Leerzeile zum Einfuegen von Datensaetzen - m_nSeekPos = nRow; - } - else if (IsInsertionRow(nRow)) // Leerzeile zum Einfuegen von Datensaetzen - m_nSeekPos = nRow; - else if ((-1 == nRow) && (GetRowCount() == ((m_nOptions & OPT_INSERT) ? 1 : 0)) && m_pSeekCursor->isAfterLast()) - m_nSeekPos = nRow; - else - { - - sal_Bool bSuccess=sal_False; - long nSteps = 0; - try - { - if ( m_pSeekCursor->rowDeleted() ) - { - // somebody deleted the current row of the seek cursor. Move it away from this row. - m_pSeekCursor->next(); - if ( m_pSeekCursor->isAfterLast() || m_pSeekCursor->isBeforeFirst() ) - bAbsolute = sal_True; - } - - if ( !bAbsolute ) - { - DBG_ASSERT( !m_pSeekCursor->isAfterLast() && !m_pSeekCursor->isBeforeFirst(), - "DbGridControl::SeekCursor: how did the seek cursor get to this position?!" ); - nSteps = nRow - (m_pSeekCursor->getRow() - 1); - bAbsolute = bAbsolute || (abs(nSteps) > 100); - } - - if ( bAbsolute ) - { - bSuccess = m_pSeekCursor->absolute(nRow + 1); - if (bSuccess) - m_nSeekPos = nRow; - } - else - { - if (nSteps > 0) // auf den letzten benoetigten Datensatz positionieren - { - if (m_pSeekCursor->isAfterLast()) - bSuccess = sal_False; - else if (m_pSeekCursor->isBeforeFirst()) - bSuccess = m_pSeekCursor->absolute(nSteps); - else - bSuccess = m_pSeekCursor->relative(nSteps); - } - else if (nSteps < 0) - { - if (m_pSeekCursor->isBeforeFirst()) - bSuccess = sal_False; - else if (m_pSeekCursor->isAfterLast()) - bSuccess = m_pSeekCursor->absolute(nSteps); - else - bSuccess = m_pSeekCursor->relative(nSteps); - } - else - { - m_nSeekPos = nRow; - return sal_True; - } - } - } - catch(Exception&) - { - OSL_FAIL("DbGridControl::SeekCursor : failed ..."); - } - - try - { - if (!bSuccess) - { - if (bAbsolute || nSteps > 0) - bSuccess = m_pSeekCursor->last(); - else - bSuccess = m_pSeekCursor->first(); - } - - if (bSuccess) - m_nSeekPos = m_pSeekCursor->getRow() - 1; - else - m_nSeekPos = -1; - } - catch(Exception&) - { - OSL_FAIL("DbGridControl::SeekCursor : failed ..."); - m_nSeekPos = -1; // kein Datensatz mehr vorhanden - } - } - return m_nSeekPos == nRow; -} -//------------------------------------------------------------------------------ -void DbGridControl::MoveToFirst() -{ - if (m_pSeekCursor && (GetCurRow() != 0)) - MoveToPosition(0); -} - -//------------------------------------------------------------------------------ -void DbGridControl::MoveToLast() -{ - if (!m_pSeekCursor) - return; - - if (m_nTotalCount < 0) // RecordCount steht noch nicht fest - { - try - { - sal_Bool bRes = m_pSeekCursor->last(); - - if (bRes) - { - m_nSeekPos = m_pSeekCursor->getRow() - 1; - AdjustRows(); - } - } - catch(Exception&) - { - } - } - - // auf den letzen Datensatz positionieren, nicht auf die Leerzeile - if (m_nOptions & OPT_INSERT) - { - if ((GetRowCount() - 1) > 0) - MoveToPosition(GetRowCount() - 2); - } - else if (GetRowCount()) - MoveToPosition(GetRowCount() - 1); -} - -//------------------------------------------------------------------------------ -void DbGridControl::MoveToPrev() -{ - long nNewRow = std::max(GetCurRow() - 1L, 0L); - if (GetCurRow() != nNewRow) - MoveToPosition(nNewRow); -} - -//------------------------------------------------------------------------------ -void DbGridControl::MoveToNext() -{ - if (!m_pSeekCursor) - return; - - if (m_nTotalCount > 0) - { - // move the data cursor to the right position - long nNewRow = std::min(GetRowCount() - 1, GetCurRow() + 1); - if (GetCurRow() != nNewRow) - MoveToPosition(nNewRow); - } - else - { - sal_Bool bOk = sal_False; - try - { - // try to move to next row - // when not possible our paint cursor is already on the last row - // then we must be sure that the data cursor is on the position - // we call ourself again - bOk = m_pSeekCursor->next(); - if (bOk) - { - m_nSeekPos = m_pSeekCursor->getRow() - 1; - MoveToPosition(GetCurRow() + 1); - } - } - catch(SQLException &) - { - DBG_UNHANDLED_EXCEPTION(); - } - - if(!bOk) - { - AdjustRows(); - if (m_nTotalCount > 0) // only to avoid infinte recursion - MoveToNext(); - } - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::MoveToPosition(sal_uInt32 nPos) -{ - if (!m_pSeekCursor) - return; - - if (m_nTotalCount < 0 && (long)nPos >= GetRowCount()) - { - try - { - if (!m_pSeekCursor->absolute(nPos + 1)) - { - AdjustRows(); - Sound::Beep(); - return; - } - else - { - m_nSeekPos = m_pSeekCursor->getRow() - 1; - AdjustRows(); - } - } - catch(Exception&) - { - return; - } - } - DbGridControl_Base::GoToRow(nPos); - m_aBar.InvalidateAll(m_nCurrentPos); -} - -//------------------------------------------------------------------------------ -void DbGridControl::AppendNew() -{ - if (!m_pSeekCursor || !(m_nOptions & OPT_INSERT)) - return; - - if (m_nTotalCount < 0) // RecordCount steht noch nicht fest - { - try - { - sal_Bool bRes = m_pSeekCursor->last(); - - if (bRes) - { - m_nSeekPos = m_pSeekCursor->getRow() - 1; - AdjustRows(); - } - } - catch(Exception&) - { - return; - } - } - - long nNewRow = m_nTotalCount + 1; - if (nNewRow > 0 && GetCurRow() != nNewRow) - MoveToPosition(nNewRow - 1); -} - -//------------------------------------------------------------------------------ -void DbGridControl::SetDesignMode(sal_Bool bMode) -{ - if (IsDesignMode() != bMode) - { - // Enable/Disable f�r den Designmode anpassen damit die Headerbar konfigurierbar bleibt - if (bMode) - { - if (!IsEnabled()) - { - Enable(); - GetDataWindow().Disable(); - } - } - else - { - // komplett disablen - if (!GetDataWindow().IsEnabled()) - Disable(); - } - - m_bDesignMode = bMode; - GetDataWindow().SetMouseTransparent(bMode); - SetMouseTransparent(bMode); - - m_aBar.InvalidateAll(m_nCurrentPos, sal_True); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::SetFilterMode(sal_Bool bMode) -{ - if (IsFilterMode() != bMode) - { - m_bFilterMode = bMode; - - if (bMode) - { - SetUpdateMode(sal_False); - - // es gibt kein Cursor mehr - if (IsEditing()) - DeactivateCell(); - RemoveRows(sal_False); - - m_xEmptyRow = new DbGridRow(); - - // setting the new filter controls - for ( size_t i = 0; i < m_aColumns.size(); ++i ) - { - DbGridColumn* pCurCol = m_aColumns[ i ]; - if (!pCurCol->IsHidden()) - pCurCol->UpdateControl(); - } - - // one row for filtering - RowInserted(0, 1, sal_True); - SetUpdateMode(sal_True); - } - else - setDataSource(Reference< XRowSet > ()); - } -} -// ----------------------------------------------------------------------------- -String DbGridControl::GetCellText(long _nRow, sal_uInt16 _nColId) const -{ - size_t Location = GetModelColumnPos( _nColId ); - DbGridColumn* pColumn = ( Location < m_aColumns.size() ) ? m_aColumns[ Location ] : NULL; - String sRet; - if ( const_cast<DbGridControl*>(this)->SeekRow(_nRow) ) - sRet = GetCurrentRowCellText(pColumn, m_xPaintRow); - return sRet; -} -//------------------------------------------------------------------------------ -XubString DbGridControl::GetCurrentRowCellText(DbGridColumn* pColumn,const DbGridRowRef& _rRow) const -{ - // Ausgabe des Textes fuer eine Zelle - XubString aText; - if ( pColumn && IsValid(m_xPaintRow) ) - aText = pColumn->GetCellText(_rRow, m_xFormatter); - return aText; -} - -//------------------------------------------------------------------------------ -sal_uInt32 DbGridControl::GetTotalCellWidth(long nRow, sal_uInt16 nColId) -{ - if (SeekRow(nRow)) - { - size_t Location = GetModelColumnPos( nColId ); - DbGridColumn* pColumn = ( Location < m_aColumns.size() ) ? m_aColumns[ Location ] : NULL; - return GetDataWindow().GetTextWidth(GetCurrentRowCellText(pColumn,m_xPaintRow)); - } - else - return 30; //xxxx -} - -//------------------------------------------------------------------------------ -void DbGridControl::PreExecuteRowContextMenu(sal_uInt16 /*nRow*/, PopupMenu& rMenu) -{ - sal_Bool bDelete = (m_nOptions & OPT_DELETE) && GetSelectRowCount() && !IsCurrentAppending(); - // ist nur die Leerzeile selektiert, dann nicht loeschen - bDelete = bDelete && !((m_nOptions & OPT_INSERT) && GetSelectRowCount() == 1 && IsRowSelected(GetRowCount() - 1)); - - rMenu.EnableItem(SID_FM_DELETEROWS, bDelete); - rMenu.EnableItem(SID_FM_RECORD_SAVE, IsModified()); - - // the undo is more difficult - sal_Bool bCanUndo = IsModified(); - long nState = -1; - if (m_aMasterStateProvider.IsSet()) - nState = m_aMasterStateProvider.Call((void*)SID_FM_RECORD_UNDO); - bCanUndo &= ( 0 != nState ); - - rMenu.EnableItem(SID_FM_RECORD_UNDO, bCanUndo); -} - -//------------------------------------------------------------------------------ -void DbGridControl::PostExecuteRowContextMenu(sal_uInt16 /*nRow*/, const PopupMenu& /*rMenu*/, sal_uInt16 nExecutionResult) -{ - switch (nExecutionResult) - { - case SID_FM_DELETEROWS: - // delete asynchron - if (m_nDeleteEvent) - Application::RemoveUserEvent(m_nDeleteEvent); - m_nDeleteEvent = Application::PostUserEvent(LINK(this,DbGridControl,OnDelete)); - break; - case SID_FM_RECORD_UNDO: - Undo(); - break; - case SID_FM_RECORD_SAVE: - SaveRow(); - break; - default: - break; - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::DataSourcePropertyChanged(const PropertyChangeEvent& evt) throw( RuntimeException ) -{ - TRACE_RANGE("DbGridControl::DataSourcePropertyChanged"); - SolarMutexGuard aGuard; - // prop "IsModified" changed ? - // during update don't care about the modified state - if (!IsUpdating() && evt.PropertyName.compareTo(FM_PROP_ISMODIFIED) == COMPARE_EQUAL) - { - Reference< XPropertySet > xSource(evt.Source, UNO_QUERY); - DBG_ASSERT( xSource.is(), "DbGridControl::DataSourcePropertyChanged: invalid event source!" ); - sal_Bool bIsNew = sal_False; - if (xSource.is()) - bIsNew = ::comphelper::getBOOL(xSource->getPropertyValue(FM_PROP_ISNEW)); - - if (bIsNew && m_xCurrentRow.Is()) - { - DBG_ASSERT(::comphelper::getBOOL(xSource->getPropertyValue(FM_PROP_ROWCOUNTFINAL)), "DbGridControl::DataSourcePropertyChanged : somebody moved the form to a new record before the row count was final !"); - sal_Int32 nRecordCount = 0; - xSource->getPropertyValue(FM_PROP_ROWCOUNT) >>= nRecordCount; - if (::comphelper::getBOOL(evt.NewValue)) - { // modified state changed from sal_False to sal_True and we're on a insert row - // -> we've to add a new grid row - if ((nRecordCount == GetRowCount() - 1) && m_xCurrentRow->IsNew()) - { - RowInserted(GetRowCount(), 1, sal_True); - InvalidateStatusCell(m_nCurrentPos); - m_aBar.InvalidateAll(m_nCurrentPos); - } - } - else - { // modified state changed from sal_True to sal_False and we're on a insert row - // we have two "new row"s at the moment : the one we're editing currently (where the current - // column is the only dirty element) and a "new new" row which is completely clean. As the first - // one is about to be cleaned, too, the second one is obsolet now. - if (m_xCurrentRow->IsNew() && nRecordCount == (GetRowCount() - 2)) - { - RowRemoved(GetRowCount() - 1, 1, sal_True); - InvalidateStatusCell(m_nCurrentPos); - m_aBar.InvalidateAll(m_nCurrentPos); - } - } - } - if (m_xCurrentRow.Is()) - { - m_xCurrentRow->SetStatus(::comphelper::getBOOL(evt.NewValue) ? GRS_MODIFIED : GRS_CLEAN); - m_xCurrentRow->SetNew( bIsNew ); - InvalidateStatusCell(m_nCurrentPos); - TRACE_RANGE_MESSAGE1("modified flag changed, new state : %s", ROWSTATUS(m_xCurrentRow)); - } - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::StartDrag( sal_Int8 /*nAction*/, const Point& rPosPixel ) -{ - if (!m_pSeekCursor || IsResizing()) - return; - - sal_uInt16 nColId = GetColumnAtXPosPixel(rPosPixel.X()); - long nRow = GetRowAtYPosPixel(rPosPixel.Y()); - if (nColId != HANDLE_ID && nRow >= 0) - { - if (GetDataWindow().IsMouseCaptured()) - GetDataWindow().ReleaseMouse(); - - size_t Location = GetModelColumnPos( nColId ); - DbGridColumn* pColumn = ( Location < m_aColumns.size() ) ? m_aColumns[ Location ] : NULL; - OStringTransferable* pTransferable = new OStringTransferable(GetCurrentRowCellText(pColumn,m_xPaintRow)); - Reference< XTransferable > xEnsureDelete(pTransferable); - pTransferable->StartDrag(this, DND_ACTION_COPY); - } -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::canCopyCellText(sal_Int32 _nRow, sal_Int16 _nColId) -{ - return (_nRow >= 0) - && (_nRow < GetRowCount()) - && (_nColId > HANDLE_ID) - && (_nColId <= ColCount()); -} - -//------------------------------------------------------------------------------ -void DbGridControl::copyCellText(sal_Int32 _nRow, sal_Int16 _nColId) -{ - DBG_ASSERT(canCopyCellText(_nRow, _nColId), "DbGridControl::copyCellText: invalid call!"); - DbGridColumn* pColumn = m_aColumns[ GetModelColumnPos(_nColId) ]; - SeekRow(_nRow); - OStringTransfer::CopyString( GetCurrentRowCellText( pColumn,m_xPaintRow ), this ); -} - -//------------------------------------------------------------------------------ -void DbGridControl::executeRowContextMenu( long _nRow, const Point& _rPreferredPos ) -{ - PopupMenu aContextMenu( SVX_RES( RID_SVXMNU_ROWS ) ); - - PreExecuteRowContextMenu( (sal_uInt16)_nRow, aContextMenu ); - aContextMenu.RemoveDisabledEntries( sal_True, sal_True ); - PostExecuteRowContextMenu( (sal_uInt16)_nRow, aContextMenu, aContextMenu.Execute( this, _rPreferredPos ) ); - - // TODO: why this weird cast to sal_uInt16? What if we really have more than 65535 lines? - // -> change this to sal_uInt32 -} - -//------------------------------------------------------------------------------ -void DbGridControl::Command(const CommandEvent& rEvt) -{ - switch (rEvt.GetCommand()) - { - case COMMAND_CONTEXTMENU: - { - if ( !m_pSeekCursor ) - { - DbGridControl_Base::Command(rEvt); - return; - } - - if ( !rEvt.IsMouseEvent() ) - { // context menu requested by keyboard - if ( GetSelectRowCount() ) - { - long nRow = FirstSelectedRow( ); - - ::Rectangle aRowRect( GetRowRectPixel( nRow, sal_True ) ); - executeRowContextMenu( nRow, aRowRect.LeftCenter() ); - - // handled - return; - } - } - - sal_uInt16 nColId = GetColumnAtXPosPixel(rEvt.GetMousePosPixel().X()); - long nRow = GetRowAtYPosPixel(rEvt.GetMousePosPixel().Y()); - - if (nColId == HANDLE_ID) - { - executeRowContextMenu( nRow, rEvt.GetMousePosPixel() ); - } - else if (canCopyCellText(nRow, nColId)) - { - PopupMenu aContextMenu(SVX_RES(RID_SVXMNU_CELL)); - aContextMenu.RemoveDisabledEntries(sal_True, sal_True); - switch (aContextMenu.Execute(this, rEvt.GetMousePosPixel())) - { - case SID_COPY: - copyCellText(nRow, nColId); - break; - } - } - else - { - DbGridControl_Base::Command(rEvt); - return; - } - } - default: - DbGridControl_Base::Command(rEvt); - } -} - -//------------------------------------------------------------------------------ -IMPL_LINK(DbGridControl, OnDelete, void*, /*EMPTYTAG*/ ) -{ - DBG_CHKTHIS(DbGridControl, NULL ); - m_nDeleteEvent = 0; - DeleteSelectedRows(); - return 0; -} - -//------------------------------------------------------------------------------ -void DbGridControl::DeleteSelectedRows() -{ - DBG_ASSERT(GetSelection(), "keine selection!!!"); - - if (!m_pSeekCursor) - return; - -/* Application::EnterWait(); - Reference< XPropertySet > xSet = (XPropertySet*)xSeekCursor->queryInterface(XPropertySet::getSmartUik()); - - // wenn mehr als 25 Datensaetze geloescht werden, wird der Cache abgeschaltet - // da das loeschen ansonsten zu langsam wird - sal_uInt16 nCacheSize = 0; - if (GetSelectRowCount() > 25) - { - // CacheSize merken und Cache zuruecksetzen - nCacheSize = xSet->getPropertyValue(L"CacheSize").getUINT16(); - if (nCacheSize) - xSet->setPropertyValue(L"CacheSize", Any(sal_uInt16(0))); - } */ - - - /* - // mu� der Cache wiederhergestellt werden? - if (nCacheSize) - { - // Cache wieder einschalten - xSet->setPropertyValue(L"CacheSize", Any(sal_uInt16(nCacheSize))); - - // Browser neu einstellen - RecalcRows(GetTopRow(), GetVisibleRows(), sal_True); - - // aktuelle Zeile aktualisieren - SeekCursor(GetCurRow()); - if (IsAppendRow(m_nSeekPos)) - xDataCursor->addRecord(); - else - { - Any aBookmark = xSeekCursor->getBookmark(); - xDataCursor->moveToBookmark(aBookmark); - } - m_xCurrentRow = new DbGridRow(xDataCursor); - m_nCurrentPos = m_nSeekPos; - - // complett invalidieren - Invalidate(); - } - else - // Browser neu einstellen - RecalcRows(GetTopRow(), GetVisibleRows(), sal_True); - - // gibt es keine Selection mehr? - if (!GetSelectRowCount()) - ActivateCell(); - - m_aBar.InvalidateAll(); - Application::LeaveWait(); - - m_bUpdating = sal_False; -*/ -} - -//------------------------------------------------------------------------------ -CellController* DbGridControl::GetController(long /*nRow*/, sal_uInt16 nColumnId) -{ - if (!IsValid(m_xCurrentRow) || !IsEnabled()) - return NULL; - - size_t Location = GetModelColumnPos(nColumnId); - DbGridColumn* pColumn = ( Location < m_aColumns.size() ) ? m_aColumns[ Location ] : NULL; - if (!pColumn) - return NULL; - - CellController* pReturn = NULL; - if (IsFilterMode()) - pReturn = &pColumn->GetController(); - else - { - if (::comphelper::hasProperty(FM_PROP_ENABLED, pColumn->getModel())) - { - if (!::comphelper::getBOOL(pColumn->getModel()->getPropertyValue(FM_PROP_ENABLED))) - return NULL; - } - - sal_Bool bInsert = (m_xCurrentRow->IsNew() && (m_nOptions & OPT_INSERT)); - sal_Bool bUpdate = (!m_xCurrentRow->IsNew() && (m_nOptions & OPT_UPDATE)); - - if ((bInsert && !pColumn->IsAutoValue()) || bUpdate || m_bForceROController) - { - pReturn = &pColumn->GetController(); - if (pReturn) - { - // wenn es eine Edit-Zeile ist, kann ich ihr das forced read-only mitgeben - if (!pReturn->ISA(EditCellController) && !pReturn->ISA(SpinCellController)) - // ich konnte den Controller in forceROController nicht auf ReadOnly setzen - if (!bInsert && !bUpdate) - // ich bin nur hier, da m_bForceROController gesetzt war - // -> lieber kein Controller als einer ohne RO - pReturn = NULL; - } - } - } - return pReturn; -} - -//------------------------------------------------------------------------------ -void DbGridControl::InitController(CellControllerRef& /*rController*/, long /*nRow*/, sal_uInt16 nColumnId) -{ - size_t Location = GetModelColumnPos(nColumnId); - DbGridColumn* pColumn = ( Location < m_aColumns.size() ) ? m_aColumns[ Location ] : NULL; - if (pColumn) - pColumn->UpdateFromField(m_xCurrentRow, m_xFormatter); -} - -//------------------------------------------------------------------------------ -void DbGridControl::CellModified() -{ - TRACE_RANGE("DbGridControl::CellModified"); - - { - ::osl::MutexGuard aGuard(m_aAdjustSafety); - if (m_nAsynAdjustEvent) - { - TRACE_RANGE_MESSAGE1("forcing a synchron call to ", m_bPendingAdjustRows ? "AdjustRows" : "AdustDataSource"); - RemoveUserEvent(m_nAsynAdjustEvent); - m_nAsynAdjustEvent = 0; - - // force the call : this should be no problem as we're probably running in the solar thread here - // (cell modified is triggered by user actions) - if (m_bPendingAdjustRows) - AdjustRows(); - else - AdjustDataSource(); - } - } - - if (!IsFilterMode() && IsValid(m_xCurrentRow) && !m_xCurrentRow->IsModified()) - { - // Einschalten des Editiermodus - // Datensatz soll eingefuegt werden - if (m_xCurrentRow->IsNew()) - { - m_xCurrentRow->SetStatus(GRS_MODIFIED); - TRACE_RANGE_MESSAGE("current row is new, new state : MODIFIED"); - // wenn noch keine Zeile hinzugefuegt wurde, dann neue hinzunehmen - if (m_nCurrentPos == GetRowCount() - 1) - { - // RowCount um einen erhoehen - RowInserted(GetRowCount(), 1, sal_True); - InvalidateStatusCell(m_nCurrentPos); - m_aBar.InvalidateAll(m_nCurrentPos); - } - } - else if (m_xCurrentRow->GetStatus() != GRS_MODIFIED) - { - m_xCurrentRow->SetState(m_pDataCursor, sal_False); - TRACE_RANGE_MESSAGE1("current row is not new, after SetState, new state : %s", ROWSTATUS(m_xCurrentRow)); - m_xCurrentRow->SetStatus(GRS_MODIFIED); - TRACE_RANGE_MESSAGE("current row is not new, new state : MODIFIED"); - InvalidateStatusCell(m_nCurrentPos); - } - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::Dispatch(sal_uInt16 nId) -{ - if (nId == BROWSER_CURSORENDOFFILE) - { - if (m_nOptions & OPT_INSERT) - AppendNew(); - else - MoveToLast(); - } - else - DbGridControl_Base::Dispatch(nId); -} - -//------------------------------------------------------------------------------ -void DbGridControl::Undo() -{ - if (!IsFilterMode() && IsValid(m_xCurrentRow) && IsModified()) - { - // check if we have somebody doin' the UNDO for us - long nState = -1; - if (m_aMasterStateProvider.IsSet()) - nState = m_aMasterStateProvider.Call((void*)SID_FM_RECORD_UNDO); - if (nState>0) - { // yes, we have, and the slot is enabled - DBG_ASSERT(m_aMasterSlotExecutor.IsSet(), "DbGridControl::Undo : a state, but no execute link ?"); - long lResult = m_aMasterSlotExecutor.Call((void*)SID_FM_RECORD_UNDO); - if (lResult) - // handled - return; - } - else if (nState == 0) - // yes, we have, and the slot is disabled - return; - - BeginCursorAction(); - - sal_Bool bAppending = m_xCurrentRow->IsNew(); - sal_Bool bDirty = m_xCurrentRow->IsModified(); - - try - { - // Editieren abbrechen - Reference< XResultSetUpdate > xUpdateCursor((Reference< XInterface >)*m_pDataCursor, UNO_QUERY); - // no effects if we're not updating currently - if (bAppending) - // just refresh the row - xUpdateCursor->moveToInsertRow(); - else - xUpdateCursor->cancelRowUpdates(); - - } - catch(Exception&) - { - DBG_UNHANDLED_EXCEPTION(); - } - - EndCursorAction(); - - m_xDataRow->SetState(m_pDataCursor, sal_False); - if (&m_xPaintRow == &m_xCurrentRow) - m_xPaintRow = m_xCurrentRow = m_xDataRow; - else - m_xCurrentRow = m_xDataRow; - - if (bAppending && (DbGridControl_Base::IsModified() || bDirty)) - // remove the row - if (m_nCurrentPos == GetRowCount() - 2) - { // maybe we already removed it (in resetCurrentRow, called if the above moveToInsertRow - // caused our data source form to be reset - which should be the usual case ....) - RowRemoved(GetRowCount() - 1, 1, sal_True); - m_aBar.InvalidateAll(m_nCurrentPos); - } - - RowModified(m_nCurrentPos); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::resetCurrentRow() -{ - if (IsModified()) - { - // scenario : we're on the insert row, the row is dirty, and thus there exists a "second" insert row (which - // is clean). Normally in DataSourcePropertyChanged we would remove this second row if the modified state of - // the insert row changes from sal_True to sal_False. But if our current cell is the only modified element (means the - // data source isn't modified) and we're reset this DataSourcePropertyChanged would never be called, so we - // would never delete the obsolet "second insert row". Thus in this special case this method here - // is the only possibility to determine the redundance of the row (resetCurrentRow is called when the - // "first insert row" is about to be cleaned, so of course the "second insert row" is redundant now) - Reference< XPropertySet > xDataSource = getDataSource()->getPropertySet(); - if (xDataSource.is() && !::comphelper::getBOOL(xDataSource->getPropertyValue(FM_PROP_ISMODIFIED))) - { - // are we on a new row currently ? - if (m_xCurrentRow->IsNew()) - { - if (m_nCurrentPos == GetRowCount() - 2) - { - RowRemoved(GetRowCount() - 1, 1, sal_True); - m_aBar.InvalidateAll(m_nCurrentPos); - } - } - } - - // update the rows - m_xDataRow->SetState(m_pDataCursor, sal_False); - if (&m_xPaintRow == &m_xCurrentRow) - m_xPaintRow = m_xCurrentRow = m_xDataRow; - else - m_xCurrentRow = m_xDataRow; - } - - RowModified(GetCurRow()); // will update the current controller if affected -} - -//------------------------------------------------------------------------------ -void DbGridControl::RowModified( long nRow, sal_uInt16 /*nColId*/ ) -{ - if (nRow == m_nCurrentPos && IsEditing()) - { - CellControllerRef aTmpRef = Controller(); - aTmpRef->ClearModified(); - InitController(aTmpRef, m_nCurrentPos, GetCurColumnId()); - } - DbGridControl_Base::RowModified(nRow); -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::IsModified() const -{ - return !IsFilterMode() && IsValid(m_xCurrentRow) && (m_xCurrentRow->IsModified() || DbGridControl_Base::IsModified()); -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::IsCurrentAppending() const -{ - return m_xCurrentRow.Is() && m_xCurrentRow->IsNew(); -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::IsInsertionRow(long nRow) const -{ - return (m_nOptions & OPT_INSERT) && m_nTotalCount >= 0 && (nRow == GetRowCount() - 1); -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::SaveModified() -{ - TRACE_RANGE("DbGridControl::SaveModified"); - DBG_ASSERT(IsValid(m_xCurrentRow), "GridControl:: Invalid row"); - if (!IsValid(m_xCurrentRow)) - return sal_True; - - // Uebernimmt die Dateneingabe fuer das Feld - // Hat es aenderungen im aktuellen Eingabefeld gegeben ? - if (!DbGridControl_Base::IsModified()) - return sal_True; - - size_t Location = GetModelColumnPos( GetCurColumnId() ); - DbGridColumn* pColumn = ( Location < m_aColumns.size() ) ? m_aColumns[ Location ] : NULL; - sal_Bool bOK = pColumn->Commit(); - DBG_ASSERT( Controller().Is(), "DbGridControl::SaveModified: was modified, by have no controller?!" ); - if ( !Controller().Is() ) - // this might happen if the callbacks implicitly triggered by Commit - // fiddled with the form or the control ... - // (Note that this here is a workaround, at most. We need a general concept how - // to treat this, you can imagine an arbitrary number of scenarios where a callback - // triggers something which leaves us in an expected state.) - // #i67147# / 2006-07-17 / frank.schoenheit@sun.com - return bOK; - - if (bOK) - { - Controller()->ClearModified(); - - if ( IsValid(m_xCurrentRow) ) - { - m_xCurrentRow->SetState(m_pDataCursor, sal_False); - TRACE_RANGE_MESSAGE1("explicit SetState, new state : %s", ROWSTATUS(m_xCurrentRow)); - InvalidateStatusCell( m_nCurrentPos ); - } -#ifdef DBG_UTIL - else - { - TRACE_RANGE_MESSAGE1("no SetState, new state : %s", ROWSTATUS(m_xCurrentRow)); - } -#endif - } - else - { - // reset the modified flag .... - Controller()->SetModified(); - } - - return bOK; -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::SaveRow() -{ - TRACE_RANGE("DbGridControl::SaveRow"); - // gueltige Zeile - if (!IsValid(m_xCurrentRow) || !IsModified()) - return sal_True; - // Wert des Controllers noch nicht gespeichert - else if (Controller().Is() && Controller()->IsModified()) - { - if (!SaveModified()) - return sal_False; - } - m_bUpdating = sal_True; - - BeginCursorAction(); - sal_Bool bAppending = m_xCurrentRow->IsNew(); - sal_Bool bSuccess = sal_False; - try - { - Reference< XResultSetUpdate > xUpdateCursor((Reference< XInterface >)*m_pDataCursor, UNO_QUERY); - if (bAppending) - xUpdateCursor->insertRow(); - else - xUpdateCursor->updateRow(); - bSuccess = sal_True; - } - catch(SQLException& e) - { - (void)e; // make compiler happy - EndCursorAction(); - m_bUpdating = sal_False; - return sal_False; - } - - try - { - if (bSuccess) - { - // if we are appending we still sit on the insert row - // we don't move just clear the flags not to move on the current row - m_xCurrentRow->SetState(m_pDataCursor, sal_False); - TRACE_RANGE_MESSAGE1("explicit SetState after a successfull update, new state : %s", ROWSTATUS(m_xCurrentRow)); - m_xCurrentRow->SetNew(sal_False); - - // adjust the seekcursor if it is on the same position as the datacursor - if (m_nSeekPos == m_nCurrentPos || bAppending) - { - // get the bookmark to refetch the data - // in insert mode we take the new bookmark of the data cursor - Any aBookmark = bAppending ? m_pDataCursor->getBookmark() : m_pSeekCursor->getBookmark(); - m_pSeekCursor->moveToBookmark(aBookmark); - // get the data - m_xSeekRow->SetState(m_pSeekCursor, sal_True); - m_nSeekPos = m_pSeekCursor->getRow() - 1; - } - } - // and repaint the row - RowModified(m_nCurrentPos); - } - catch(Exception&) - { - } - - m_bUpdating = sal_False; - EndCursorAction(); - - // The old code returned (nRecords != 0) here. - // Me thinks this is wrong : If something goes wrong while update the record, an exception will be thrown, - // which results in a "return sal_False" (see above). If no exception is thrown, everything is fine. If nRecords - // is zero, this simply means all fields had their original values. - // FS - 06.12.99 - 70502 - return sal_True; -} - -//------------------------------------------------------------------------------ -long DbGridControl::PreNotify(NotifyEvent& rEvt) -{ - // keine Events der Navbar behandeln - if (m_aBar.IsWindowOrChild(rEvt.GetWindow())) - return BrowseBox::PreNotify(rEvt); - - switch (rEvt.GetType()) - { - case EVENT_KEYINPUT: - { - const KeyEvent* pKeyEvent = rEvt.GetKeyEvent(); - - sal_uInt16 nCode = pKeyEvent->GetKeyCode().GetCode(); - sal_Bool bShift = pKeyEvent->GetKeyCode().IsShift(); - sal_Bool bCtrl = pKeyEvent->GetKeyCode().IsMod1(); - sal_Bool bAlt = pKeyEvent->GetKeyCode().IsMod2(); - if ( ( KEY_TAB == nCode ) && bCtrl && !bAlt ) - { - // Ctrl-Tab is used to step out of the control, without traveling to the - // remaining cells first - // -> build a new key event without the Ctrl-key, and let the very base class handle it - KeyCode aNewCode( KEY_TAB, bShift, sal_False, sal_False, sal_False ); - KeyEvent aNewEvent( pKeyEvent->GetCharCode(), aNewCode ); - - // call the Control - our direct base class will interpret this in a way we do not want (and do - // a cell traveling) - Control::KeyInput( aNewEvent ); - return 1; - } - - if ( !bShift && !bCtrl && ( KEY_ESCAPE == nCode ) ) - { - if (IsModified()) - { - Undo(); - return 1; - } - } - else if ( ( KEY_DELETE == nCode ) && !bShift && !bCtrl ) // delete rows - { - if ((m_nOptions & OPT_DELETE) && GetSelectRowCount()) - { - // delete asynchron - if (m_nDeleteEvent) - Application::RemoveUserEvent(m_nDeleteEvent); - m_nDeleteEvent = Application::PostUserEvent(LINK(this,DbGridControl,OnDelete)); - return 1; - } - } - } // kein break! - default: - return DbGridControl_Base::PreNotify(rEvt); - } -} - -//------------------------------------------------------------------------------ -sal_Bool DbGridControl::IsTabAllowed(sal_Bool bRight) const -{ - if (bRight) - // Tab nur wenn nicht auf der letzten Zelle - return GetCurRow() < (GetRowCount() - 1) || !m_bRecordCountFinal || - GetViewColumnPos(GetCurColumnId()) < (GetViewColCount() - 1); - else - { - // Tab nur wenn nicht auf der ersten Zelle - return GetCurRow() > 0 || (GetCurColumnId() && GetViewColumnPos(GetCurColumnId()) > 0); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::KeyInput( const KeyEvent& rEvt ) -{ - if (rEvt.GetKeyCode().GetFunction() == KEYFUNC_COPY) - { - long nRow = GetCurRow(); - sal_uInt16 nColId = GetCurColumnId(); - if (nRow >= 0 && nRow < GetRowCount() && nColId < ColCount()) - { - size_t Location = GetModelColumnPos( nColId ); - DbGridColumn* pColumn = ( Location < m_aColumns.size() ) ? m_aColumns[ Location ] : NULL; - OStringTransfer::CopyString( GetCurrentRowCellText( pColumn,m_xPaintRow ), this ); - return; - } - } - DbGridControl_Base::KeyInput(rEvt); -} - -//------------------------------------------------------------------------------ -void DbGridControl::HideColumn(sal_uInt16 nId) -{ - DeactivateCell(); - - // determine the col for the focus to set to after removal - sal_uInt16 nPos = GetViewColumnPos(nId); - sal_uInt16 nNewColId = nPos == (ColCount()-1) - ? GetColumnIdFromViewPos(nPos-1) // last col is to be removed -> take the previous - : GetColumnIdFromViewPos(nPos+1); // take the next - - long lCurrentWidth = GetColumnWidth(nId); - DbGridControl_Base::RemoveColumn(nId); - // don't use my own RemoveColumn, this would remove it from m_aColumns, too - - // update my model - size_t Location = GetModelColumnPos( nId ); - DbGridColumn* pColumn = ( Location < m_aColumns.size() ) ? m_aColumns[ Location ] : NULL; - DBG_ASSERT(pColumn, "DbGridControl::HideColumn : somebody did hide a nonexistent column !"); - if (pColumn) - { - pColumn->m_bHidden = sal_True; - pColumn->m_nLastVisibleWidth = CalcReverseZoom(lCurrentWidth); - } - - // and reset the focus - if ( nId == GetCurColumnId() ) - GoToColumnId( nNewColId ); -} - -//------------------------------------------------------------------------------ -void DbGridControl::ShowColumn(sal_uInt16 nId) -{ - sal_uInt16 nPos = GetModelColumnPos(nId); - DBG_ASSERT(nPos != (sal_uInt16)-1, "DbGridControl::ShowColumn : invalid argument !"); - if (nPos == (sal_uInt16)-1) - return; - - DbGridColumn* pColumn = m_aColumns[ nPos ]; - if (!pColumn->IsHidden()) - { - DBG_ASSERT(GetViewColumnPos(nId) != (sal_uInt16)-1, "DbGridControl::ShowColumn : inconsistent internal state !"); - // if the column isn't marked as hidden, it should be visible, shouldn't it ? - return; - } - DBG_ASSERT(GetViewColumnPos(nId) == (sal_uInt16)-1, "DbGridControl::ShowColumn : inconsistent internal state !"); - // the opposite situation ... - - // to determine the new view position we need an adjacent non-hidden column - sal_uInt16 nNextNonHidden = (sal_uInt16)-1; - // first search the cols to the right - for ( size_t i = nPos + 1; i < m_aColumns.size(); ++i ) - { - DbGridColumn* pCurCol = m_aColumns[ i ]; - if (!pCurCol->IsHidden()) - { - nNextNonHidden = i; - break; - } - } - if ((nNextNonHidden == (sal_uInt16)-1) && (nPos > 0)) - { - // then to the left - for ( size_t i = nPos; i > 0; --i ) - { - DbGridColumn* pCurCol = m_aColumns[ i-1 ]; - if (!pCurCol->IsHidden()) - { - nNextNonHidden = i-1; - break; - } - } - } - sal_uInt16 nNewViewPos = (nNextNonHidden == (sal_uInt16)-1) - ? 1 // there is no visible column -> insert behinde the handle col - : GetViewColumnPos( m_aColumns[ nNextNonHidden ]->GetId() ) + 1; - // the first non-handle col has "view pos" 0, but the pos arg for InsertDataColumn expects - // a position 1 for the first non-handle col -> +1 - DBG_ASSERT(nNewViewPos != (sal_uInt16)-1, "DbGridControl::ShowColumn : inconsistent internal state !"); - // we found a col marked as visible but got no view pos for it ... - - if ((nNextNonHidden<nPos) && (nNextNonHidden != (sal_uInt16)-1)) - // nNextNonHidden is a column to the left, so we want to insert the new col _right_ beside it's pos - ++nNewViewPos; - - DeactivateCell(); - - ::rtl::OUString aName; - pColumn->getModel()->getPropertyValue(FM_PROP_LABEL) >>= aName; - InsertDataColumn(nId, aName, CalcZoom(pColumn->m_nLastVisibleWidth), HIB_CENTER | HIB_VCENTER | HIB_CLICKABLE, nNewViewPos); - pColumn->m_bHidden = sal_False; - - ActivateCell(); - Invalidate(); -} - -//------------------------------------------------------------------------------ -sal_uInt16 DbGridControl::GetColumnIdFromModelPos( sal_uInt16 nPos ) const -{ - if (nPos >= m_aColumns.size()) - { - OSL_FAIL("DbGridControl::GetColumnIdFromModelPos : invalid argument !"); - return (sal_uInt16)-1; - } - - DbGridColumn* pCol = m_aColumns[ nPos ]; -#if (OSL_DEBUG_LEVEL > 0) || defined DBG_UTIL - // in der Debug-Version rechnen wir die ModelPos in eine ViewPos um und vergleichen das mit dem Wert, - // den wir zurueckliefern werden (nId an der entsprechenden Col in m_aColumns) - - if (!pCol->IsHidden()) - { // macht nur Sinn, wenn die Spalte sichtbar ist - sal_uInt16 nViewPos = nPos; - for ( size_t i = 0; i < m_aColumns.size() && i < nPos; ++i) - if ( m_aColumns[ i ]->IsHidden()) - --nViewPos; - - DBG_ASSERT(pCol && GetColumnIdFromViewPos(nViewPos) == pCol->GetId(), - "DbGridControl::GetColumnIdFromModelPos : this isn't consistent .... did I misunderstand something ?"); - } -#endif - return pCol->GetId(); -} - -//------------------------------------------------------------------------------ -sal_uInt16 DbGridControl::GetModelColumnPos( sal_uInt16 nId ) const -{ - for ( size_t i = 0; i < m_aColumns.size(); ++i ) - if ( m_aColumns[ i ]->GetId() == nId ) - return i; - - return GRID_COLUMN_NOT_FOUND; -} - -//------------------------------------------------------------------------------ -void DbGridControl::implAdjustInSolarThread(sal_Bool _bRows) -{ - TRACE_RANGE("DbGridControl::implAdjustInSolarThread"); - ::osl::MutexGuard aGuard(m_aAdjustSafety); - if (::osl::Thread::getCurrentIdentifier() != Application::GetMainThreadIdentifier()) - { - m_nAsynAdjustEvent = PostUserEvent(LINK(this, DbGridControl, OnAsyncAdjust), reinterpret_cast< void* >( _bRows )); - m_bPendingAdjustRows = _bRows; -#ifdef DBG_UTIL - if (_bRows) - TRACE_RANGE_MESSAGE("posting an AdjustRows") - else - TRACE_RANGE_MESSAGE("posting an AdjustDataSource") -#endif - } - else - { -#ifdef DBG_UTIL - if (_bRows) - TRACE_RANGE_MESSAGE("doing an AdjustRows") - else - TRACE_RANGE_MESSAGE("doing an AdjustDataSource") -#endif - // always adjust the rows before adjusting the data source - // If this is not necessary (because the row count did not change), nothing is done - // The problem is that we can't rely on the order of which the calls come in: If the cursor was moved - // to a position behind row count know 'til now, the cursorMoved notification may come before the - // RowCountChanged notification - // 94093 - 02.11.2001 - frank.schoenheit@sun.com - AdjustRows(); - - if ( !_bRows ) - AdjustDataSource(); - } -} - -//------------------------------------------------------------------------------ -IMPL_LINK(DbGridControl, OnAsyncAdjust, void*, pAdjustWhat) -{ - m_nAsynAdjustEvent = 0; - - AdjustRows(); - // see implAdjustInSolarThread for a comment why we do this every time - - if ( !pAdjustWhat ) - AdjustDataSource(); - - return 0L; -} - -//------------------------------------------------------------------------------ -void DbGridControl::BeginCursorAction() -{ - if (m_pFieldListeners) - { - ColumnFieldValueListeners* pListeners = (ColumnFieldValueListeners*)m_pFieldListeners; - ConstColumnFieldValueListenersIterator aIter = pListeners->begin(); - while (aIter != pListeners->end()) - { - GridFieldValueListener* pCurrent = (*aIter).second; - if (pCurrent) - pCurrent->suspend(); - ++aIter; - } - } - - if (m_pDataSourcePropListener) - m_pDataSourcePropListener->suspend(); -} - -//------------------------------------------------------------------------------ -void DbGridControl::EndCursorAction() -{ - if (m_pFieldListeners) - { - ColumnFieldValueListeners* pListeners = (ColumnFieldValueListeners*)m_pFieldListeners; - ConstColumnFieldValueListenersIterator aIter = pListeners->begin(); - while (aIter != pListeners->end()) - { - GridFieldValueListener* pCurrent = (*aIter).second; - if (pCurrent) - pCurrent->resume(); - ++aIter; - } - } - - if (m_pDataSourcePropListener) - m_pDataSourcePropListener->resume(); -} - -//------------------------------------------------------------------------------ -void DbGridControl::ConnectToFields() -{ - ColumnFieldValueListeners* pListeners = (ColumnFieldValueListeners*)m_pFieldListeners; - DBG_ASSERT(!pListeners || pListeners->size() == 0, "DbGridControl::ConnectToFields : please call DisconnectFromFields first !"); - - if (!pListeners) - { - pListeners = new ColumnFieldValueListeners; - m_pFieldListeners = pListeners; - } - - for ( size_t i = 0; i < m_aColumns.size(); ++i ) - { - DbGridColumn* pCurrent = m_aColumns[ i ]; - sal_uInt16 nViewPos = pCurrent ? GetViewColumnPos(pCurrent->GetId()) : (sal_uInt16)-1; - if ((sal_uInt16)-1 == nViewPos) - continue; - - Reference< XPropertySet > xField = pCurrent->GetField(); - if (!xField.is()) - continue; - - // column is visible and bound here - GridFieldValueListener*& rpListener = (*pListeners)[pCurrent->GetId()]; - DBG_ASSERT(!rpListener, "DbGridControl::ConnectToFields : already a listener for this column ?!"); - rpListener = new GridFieldValueListener(*this, xField, pCurrent->GetId()); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::DisconnectFromFields() -{ - if (!m_pFieldListeners) - return; - - ColumnFieldValueListeners* pListeners = (ColumnFieldValueListeners*)m_pFieldListeners; - while (pListeners->size()) - { -#ifdef DBG_UTIL - sal_Int32 nOldSize = pListeners->size(); -#endif - pListeners->begin()->second->dispose(); - DBG_ASSERT(nOldSize > (sal_Int32)pListeners->size(), "DbGridControl::DisconnectFromFields : dispose on a listener should result in a removal from my list !"); - } - - delete pListeners; - m_pFieldListeners = NULL; -} - -//------------------------------------------------------------------------------ -void DbGridControl::FieldValueChanged(sal_uInt16 _nId, const PropertyChangeEvent& /*_evt*/) -{ - osl::MutexGuard aPreventDestruction(m_aDestructionSafety); - // needed as this may run in a thread other than the main one - if (GetRowStatus(GetCurRow()) != DbGridControl_Base::MODIFIED) - // all other cases are handled elsewhere - return; - - size_t Location = GetModelColumnPos( _nId ); - DbGridColumn* pColumn = ( Location < m_aColumns.size() ) ? m_aColumns[ Location ] : NULL; - if (pColumn) - { - sal_Bool bAcquiredPaintSafety = sal_False; - while (!m_bWantDestruction && !bAcquiredPaintSafety) - bAcquiredPaintSafety = Application::GetSolarMutex().tryToAcquire(); - - if (m_bWantDestruction) - { // at this moment, within another thread, our destructor tries to destroy the listener which called this method - // => don't do anything - // 73365 - 23.02.00 - FS - if (bAcquiredPaintSafety) - // though the above while-loop suggests that (m_bWantDestruction && bAcquiredPaintSafety) is impossible, - // it isnt't, as m_bWantDestruction isn't protected with any mutex - Application::GetSolarMutex().release(); - return; - } - // here we got the solar mutex, transfer it to a guard for safety reasons - SolarMutexGuard aPaintSafety; - Application::GetSolarMutex().release(); - - // and finally do the update ... - pColumn->UpdateFromField(m_xCurrentRow, m_xFormatter); - RowModified(GetCurRow(), _nId); - } -} - -//------------------------------------------------------------------------------ -void DbGridControl::FieldListenerDisposing(sal_uInt16 _nId) -{ - ColumnFieldValueListeners* pListeners = (ColumnFieldValueListeners*)m_pFieldListeners; - if (!pListeners) - { - OSL_FAIL("DbGridControl::FieldListenerDisposing : invalid call (have no listener array) !"); - return; - } - - ColumnFieldValueListenersIterator aPos = pListeners->find(_nId); - if (aPos == pListeners->end()) - { - OSL_FAIL("DbGridControl::FieldListenerDisposing : invalid call (did not find the listener) !"); - return; - } - - delete aPos->second; - - pListeners->erase(aPos); -} - -//------------------------------------------------------------------------------ -void DbGridControl::disposing(sal_uInt16 _nId, const EventObject& /*_rEvt*/) -{ - if (_nId == 0) - { // the seek cursor is beeing disposed - ::osl::MutexGuard aGuard(m_aAdjustSafety); - setDataSource(NULL,0); // our clone was disposed so we set our datasource to null to avoid later acces to it - if (m_nAsynAdjustEvent) - { - RemoveUserEvent(m_nAsynAdjustEvent); - m_nAsynAdjustEvent = 0; - } - } -} -// ----------------------------------------------------------------------------- -sal_Int32 DbGridControl::GetAccessibleControlCount() const -{ - return DbGridControl_Base::GetAccessibleControlCount() + 1; // the navigation control -} -// ----------------------------------------------------------------------------- -Reference<XAccessible > DbGridControl::CreateAccessibleControl( sal_Int32 _nIndex ) -{ - Reference<XAccessible > xRet; - if ( _nIndex == DbGridControl_Base::GetAccessibleControlCount() ) - { - xRet = m_aBar.GetAccessible(); - } - else - xRet = DbGridControl_Base::CreateAccessibleControl( _nIndex ); - return xRet; -} -// ----------------------------------------------------------------------------- -Reference< XAccessible > DbGridControl::CreateAccessibleCell( sal_Int32 _nRow, sal_uInt16 _nColumnPos ) -{ - sal_uInt16 nColumnId = GetColumnId( _nColumnPos ); - size_t Location = GetModelColumnPos(nColumnId); - DbGridColumn* pColumn = ( Location < m_aColumns.size() ) ? m_aColumns[ Location ] : NULL; - if ( pColumn ) - { - Reference< ::com::sun::star::awt::XControl> xInt(pColumn->GetCell()); - Reference< ::com::sun::star::awt::XCheckBox> xBox(xInt,UNO_QUERY); - if ( xBox.is() ) - { - TriState eValue = STATE_NOCHECK; - switch( xBox->getState() ) - { - case 0: - eValue = STATE_NOCHECK; - break; - case 1: - eValue = STATE_CHECK; - break; - case 2: - eValue = STATE_DONTKNOW; - break; - } - return DbGridControl_Base::CreateAccessibleCheckBoxCell( _nRow, _nColumnPos,eValue,sal_True ); - } - } - return DbGridControl_Base::CreateAccessibleCell( _nRow, _nColumnPos ); -} -// ----------------------------------------------------------------------------- - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/fmcomp/gridctrl.src b/svx/source/fmcomp/gridctrl.src deleted file mode 100644 index b29af062de..0000000000 --- a/svx/source/fmcomp/gridctrl.src +++ /dev/null @@ -1,259 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include "svx/fmresids.hrc" -#include <svx/svxids.hrc> -#include "globlmn_tmpl.hrc" -#include "fmhelp.hrc" -#include <svx/svxcommands.h> - -Menu RID_SVXMNU_ROWS -{ - ItemList = - { - MenuItem - { - Identifier = SID_FM_DELETEROWS ; - HelpId = HID_FM_DELETEROWS ; - Text [ en-US ] = "Delete Rows" ; - }; - MenuItem - { - Identifier = SID_FM_RECORD_SAVE ; - HelpId = CMD_SID_FM_RECORD_SAVE ; - Text [ en-US ] = "Save Record" ; - }; - MenuItem - { - Identifier = SID_FM_RECORD_UNDO ; - HelpId = CMD_SID_FM_RECORD_UNDO ; - Text [ en-US ] = "Undo: Data entry" ; - }; - }; -}; -Menu RID_SVXMNU_COLS -{ - ItemList = - { - MenuItem - { - Identifier = SID_FM_INSERTCOL ; - HelpId = HID_FM_INSERTCOL ; - Text [ en-US ] = "Insert ~Column" ; - SubMenu = Menu - { - ItemList = - { - MenuItem - { - Identifier = SID_FM_EDIT ; - HelpId = CMD_SID_FM_EDIT ; - Text [ en-US ] = "Text Box" ; - }; - MenuItem - { - Identifier = SID_FM_CHECKBOX ; - HelpId = CMD_SID_FM_CHECKBOX ; - Text [ en-US ] = "Check Box" ; - }; - MenuItem - { - Identifier = SID_FM_COMBOBOX ; - HelpId = CMD_SID_FM_COMBOBOX ; - Text [ en-US ] = "Combo Box" ; - }; - MenuItem - { - Identifier = SID_FM_LISTBOX ; - HelpId = CMD_SID_FM_LISTBOX ; - Text [ en-US ] = "List Box" ; - }; - MenuItem - { - Identifier = SID_FM_DATEFIELD ; - HelpId = CMD_SID_FM_DATEFIELD ; - Text [ en-US ] = "Date Field" ; - }; - MenuItem - { - Identifier = SID_FM_TIMEFIELD ; - HelpId = CMD_SID_FM_TIMEFIELD ; - Text [ en-US ] = "Time Field" ; - }; - MenuItem - { - Identifier = SID_FM_NUMERICFIELD ; - HelpId = CMD_SID_FM_NUMERICFIELD ; - Text [ en-US ] = "Numeric Field" ; - }; - MenuItem - { - Identifier = SID_FM_CURRENCYFIELD ; - HelpId = CMD_SID_FM_CURRENCYFIELD ; - Text [ en-US ] = "Currency Field" ; - }; - MenuItem - { - Identifier = SID_FM_PATTERNFIELD ; - HelpId = CMD_SID_FM_PATTERNFIELD ; - Text [ en-US ] = "Pattern Field" ; - }; - MenuItem - { - Identifier = SID_FM_FORMATTEDFIELD ; - HelpId = CMD_SID_FM_FORMATTEDFIELD ; - Text [ en-US ] = "Formatted Field" ; - }; - MenuItem - { - // this is a dummy which is never used herein but for copy to newly built menus - Identifier = SID_FM_TWOFIELDS_DATE_N_TIME; - HelpId = HID_CONTROLS_DATE_N_TIME; - Text [ en-US ] = "Date and Time Field" ; - Disable = True; - }; - }; - }; - }; - MenuItem - { - Identifier = SID_FM_CHANGECOL ; - HelpId = HID_FM_CHANGECOL ; - Text [ en-US ] = "~Replace with" ; - }; - MenuItem - { - Identifier = SID_FM_DELETECOL ; - HelpId = HID_FM_DELETECOL ; - Text [ en-US ] = "Delete Column" ; - }; - MenuItem - { - Identifier = SID_FM_HIDECOL ; - HelpId = HID_FM_HIDECOL ; - Text [ en-US ] = "~Hide Column"; - }; - MenuItem - { - Identifier = SID_FM_SHOWCOLS ; - HelpId = HID_FM_SHOWCOLS ; - SubMenu = Menu - { - ItemList = - { - MenuItem - { - Identifier = SID_FM_SHOWCOLS_MORE ; - HelpId = HID_FM_SHOWCOLS_MORE ; - Text [ en-US ] = "~More..."; - }; - MenuItem - { - Separator = TRUE ; - }; - MenuItem - { - Identifier = SID_FM_SHOWALLCOLS ; - HelpId = HID_FM_SHOWALLCOLS ; - Text [ en-US ] = "~All"; - }; - }; - }; - Text [ en-US ] = "~Show Columns"; - }; - MenuItem - { - Identifier = SID_FM_SHOW_PROPERTY_BROWSER ; - HelpId = CMD_SID_FM_SHOW_PROPERTY_BROWSER ; - Text [ en-US ] = "Column..." ; - }; - }; -}; - -Menu RID_SVXMNU_CELL -{ - ItemList = - { - MenuItem - { - ITEM_EDIT_COPY - }; - }; -}; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/svx/source/fmcomp/trace.cxx b/svx/source/fmcomp/trace.cxx deleted file mode 100644 index 53c4eac489..0000000000 --- a/svx/source/fmcomp/trace.cxx +++ /dev/null @@ -1,116 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svx.hxx" -#include "trace.hxx" -#include <tools/debug.hxx> -#include <rtl/strbuf.hxx> - -#if defined(DBG_UTIL) - -//============================================================================== - -//------------------------------------------------------------------------------ -::osl::Mutex Tracer::s_aMapSafety; -::std::map< ::oslThreadIdentifier, sal_Int32, ::std::less< oslThreadIdentifier > > - Tracer::s_aThreadIndents; - -//------------------------------------------------------------------------------ -Tracer::Tracer(const char* _pBlockDescription) - :m_sBlockDescription(_pBlockDescription) -{ - ::osl::MutexGuard aGuard(s_aMapSafety); - sal_uInt32 nIndent = s_aThreadIndents[ ::osl::Thread::getCurrentIdentifier() ]++; - - rtl::OStringBuffer sMessage; - sMessage.append(static_cast<sal_Int32>( - ::osl::Thread::getCurrentIdentifier())); - sMessage.append('\t'); - while (nIndent--) - sMessage.append('\t'); - sMessage.append(m_sBlockDescription); - sMessage.append(RTL_CONSTASCII_STRINGPARAM(" {")); - OSL_TRACE(sMessage.getStr()); -} - -//------------------------------------------------------------------------------ -Tracer::~Tracer() -{ - ::osl::MutexGuard aGuard(s_aMapSafety); - sal_Int32 nIndent = --s_aThreadIndents[ ::osl::Thread::getCurrentIdentifier() ]; - - rtl::OStringBuffer sMessage; - sMessage.append(static_cast<sal_Int32>( - ::osl::Thread::getCurrentIdentifier())); - sMessage.append('\t'); - while (nIndent--) - sMessage.append('\t'); - sMessage.append(RTL_CONSTASCII_STRINGPARAM("} // ")); - sMessage.append(m_sBlockDescription); - OSL_TRACE(sMessage.getStr()); -} - -//------------------------------------------------------------------------------ -void Tracer::TraceString(const char* _pMessage) -{ - ::osl::MutexGuard aGuard(s_aMapSafety); - sal_Int32 nIndent = s_aThreadIndents[ ::osl::Thread::getCurrentIdentifier() ]; - - rtl::OStringBuffer sMessage; - sMessage.append(static_cast<sal_Int32>( - ::osl::Thread::getCurrentIdentifier())); - sMessage.append('\t'); - while (nIndent--) - sMessage.append('\t'); - sMessage.append(m_sBlockDescription); - sMessage.append(RTL_CONSTASCII_STRINGPARAM(": ")); - sMessage.append(_pMessage); - OSL_TRACE(sMessage.getStr()); -} - -//------------------------------------------------------------------------------ -void Tracer::TraceString1StringParam(const char* _pMessage, const char* _pParam) -{ - ::osl::MutexGuard aGuard(s_aMapSafety); - sal_Int32 nIndent = s_aThreadIndents[ ::osl::Thread::getCurrentIdentifier() ]; - - rtl::OStringBuffer sMessage; - sMessage.append(static_cast<sal_Int32>( - ::osl::Thread::getCurrentIdentifier())); - sMessage.append('\t'); - while (nIndent--) - sMessage.append('\t'); - sMessage.append(m_sBlockDescription); - sMessage.append(RTL_CONSTASCII_STRINGPARAM(": ")); - sMessage.append(_pMessage); - OSL_TRACE(sMessage.getStr(), _pParam); -} -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/fmcomp/xmlexchg.cxx b/svx/source/fmcomp/xmlexchg.cxx deleted file mode 100644 index a04aedb430..0000000000 --- a/svx/source/fmcomp/xmlexchg.cxx +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_svx.hxx" -#include "svx/xmlexchg.hxx" -#include <sot/formats.hxx> -#include <sot/exchange.hxx> -#include <tools/debug.hxx> - -//........................................................................ -namespace svx -{ -//........................................................................ - - using namespace ::com::sun::star::datatransfer; - - //==================================================================== - //= OXFormsTransferable - //==================================================================== - //-------------------------------------------------------------------- - OXFormsTransferable::OXFormsTransferable( const OXFormsDescriptor &rhs ) : - m_aDescriptor(rhs) - { - } - //-------------------------------------------------------------------- - sal_uInt32 OXFormsTransferable::getDescriptorFormatId() - { - static sal_uInt32 s_nFormat = (sal_uInt32)-1; - if ((sal_uInt32)-1 == s_nFormat) - { - s_nFormat = SotExchange::RegisterFormatName( String::CreateFromAscii("application/x-openoffice;windows_formatname=\"???\"") ); - OSL_ENSURE( (sal_uInt32)-1 != s_nFormat, "OXFormsTransferable::getDescriptorFormatId: bad exchange id!" ); - } - return s_nFormat; - } - //-------------------------------------------------------------------- - void OXFormsTransferable::AddSupportedFormats() - { - AddFormat( SOT_FORMATSTR_ID_XFORMS ); - } - //-------------------------------------------------------------------- - sal_Bool OXFormsTransferable::GetData( const DataFlavor& _rFlavor ) - { - const sal_uInt32 nFormatId = SotExchange::GetFormat( _rFlavor ); - if ( SOT_FORMATSTR_ID_XFORMS == nFormatId ) - { - return SetString( ::rtl::OUString( String::CreateFromAscii("XForms-Transferable") ), _rFlavor ); - } - return sal_False; - } - //-------------------------------------------------------------------- - const OXFormsDescriptor &OXFormsTransferable::extractDescriptor( const TransferableDataHelper &_rData ) { - - using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::datatransfer; - Reference<XTransferable> &transfer = const_cast<Reference<XTransferable> &>(_rData.GetTransferable()); - XTransferable *pInterface = transfer.get(); - OXFormsTransferable *pThis = dynamic_cast<OXFormsTransferable *>(pInterface); - DBG_ASSERT(pThis,"XTransferable is NOT an OXFormsTransferable???"); - return pThis->m_aDescriptor; - } - - -//........................................................................ -} // namespace svx -//........................................................................ - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |