1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svx.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "fmprop.hrc" 32*cdf0e10cSrcweir #include "fmservs.hxx" 33*cdf0e10cSrcweir #include "svx/fmtools.hxx" 34*cdf0e10cSrcweir #include "svx/dbtoolsclient.hxx" 35*cdf0e10cSrcweir #include "svx/fmglob.hxx" 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir /** === begin UNO includes === **/ 38*cdf0e10cSrcweir #include <com/sun/star/awt/LineEndFormat.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/beans/XIntrospection.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/form/XForm.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/form/XFormComponent.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/form/XGridColumnFactory.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/io/XObjectInputStream.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/io/XObjectOutputStream.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/io/XPersistObject.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/sdb/ErrorCondition.hpp> 54*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp> 55*cdf0e10cSrcweir #include <com/sun/star/sdb/XCompletedConnection.hpp> 56*cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp> 57*cdf0e10cSrcweir #include <com/sun/star/sdb/XResultSetAccess.hpp> 58*cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp> 59*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp> 60*cdf0e10cSrcweir #include <com/sun/star/sdbcx/Privilege.hpp> 61*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp> 62*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 63*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 64*cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp> 65*cdf0e10cSrcweir #include <com/sun/star/util/Language.hpp> 66*cdf0e10cSrcweir #include <com/sun/star/util/NumberFormat.hpp> 67*cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp> 68*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatTypes.hpp> 69*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormats.hpp> 70*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp> 71*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatter.hpp> 72*cdf0e10cSrcweir /** === end UNO includes === **/ 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir #include <basic/sbxvar.hxx> 75*cdf0e10cSrcweir #include <svl/eitem.hxx> 76*cdf0e10cSrcweir #include <svl/stritem.hxx> 77*cdf0e10cSrcweir #include <comphelper/container.hxx> 78*cdf0e10cSrcweir #include <comphelper/extract.hxx> 79*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 80*cdf0e10cSrcweir #include <comphelper/property.hxx> 81*cdf0e10cSrcweir #include <comphelper/sequence.hxx> 82*cdf0e10cSrcweir #include <comphelper/types.hxx> 83*cdf0e10cSrcweir #include <comphelper/uno3.hxx> 84*cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 85*cdf0e10cSrcweir #include <connectivity/dbtools.hxx> 86*cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx> 87*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 88*cdf0e10cSrcweir #include <rtl/logfile.hxx> 89*cdf0e10cSrcweir #include <rtl/math.hxx> 90*cdf0e10cSrcweir #include <sfx2/bindings.hxx> 91*cdf0e10cSrcweir #include <svl/eitem.hxx> 92*cdf0e10cSrcweir #include <svl/stritem.hxx> 93*cdf0e10cSrcweir #include <toolkit/unohlp.hxx> 94*cdf0e10cSrcweir #include <tools/debug.hxx> 95*cdf0e10cSrcweir #include <tools/string.hxx> 96*cdf0e10cSrcweir #include <vcl/stdtext.hxx> 97*cdf0e10cSrcweir #include <vcl/svapp.hxx> 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir #include <algorithm> 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 102*cdf0e10cSrcweir using namespace ::com::sun::star::util; 103*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 104*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 105*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 106*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 107*cdf0e10cSrcweir using namespace ::com::sun::star::container; 108*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 109*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 110*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 111*cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 112*cdf0e10cSrcweir using namespace ::com::sun::star::task; 113*cdf0e10cSrcweir using namespace ::com::sun::star::form; 114*cdf0e10cSrcweir using namespace ::svxform; 115*cdf0e10cSrcweir using namespace ::connectivity::simple; 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 118*cdf0e10cSrcweir namespace 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir static bool lcl_shouldDisplayError( const Any& _rError ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir SQLException aError; 123*cdf0e10cSrcweir if ( !( _rError >>= aError ) ) 124*cdf0e10cSrcweir return true; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir if ( aError.Message.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "[OOoBase]" ) ) != 0 ) 127*cdf0e10cSrcweir // it is an exception *not* thrown by an OOo Base core component 128*cdf0e10cSrcweir return true; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir // the only exception we do not display ATM is a RowSetVetoException, which 131*cdf0e10cSrcweir // has been raised because an XRowSetApprovalListener vetoed a change 132*cdf0e10cSrcweir if ( aError.ErrorCode + ErrorCondition::ROW_SET_OPERATION_VETOED == 0 ) 133*cdf0e10cSrcweir return false; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // everything else is to be displayed 136*cdf0e10cSrcweir return true; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 141*cdf0e10cSrcweir void displayException(const Any& _rExcept, Window* _pParent) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::displayException" ); 144*cdf0e10cSrcweir // check whether we need to display it 145*cdf0e10cSrcweir if ( !lcl_shouldDisplayError( _rExcept ) ) 146*cdf0e10cSrcweir return; 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir try 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir // the parent window 151*cdf0e10cSrcweir Window* pParentWindow = _pParent ? _pParent : GetpApp()->GetDefDialogParent(); 152*cdf0e10cSrcweir Reference< XWindow > xParentWindow = VCLUnoHelper::GetInterface(pParentWindow); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir Sequence< Any > aArgs(2); 155*cdf0e10cSrcweir aArgs[0] <<= PropertyValue(::rtl::OUString::createFromAscii("SQLException"), 0, _rExcept, PropertyState_DIRECT_VALUE); 156*cdf0e10cSrcweir aArgs[1] <<= PropertyValue(::rtl::OUString::createFromAscii("ParentWindow"), 0, makeAny(xParentWindow), PropertyState_DIRECT_VALUE); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir static ::rtl::OUString s_sDialogServiceName = ::rtl::OUString::createFromAscii("com.sun.star.sdb.ErrorMessageDialog"); 159*cdf0e10cSrcweir Reference< XExecutableDialog > xErrorDialog( 160*cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()->createInstanceWithArguments(s_sDialogServiceName, aArgs), UNO_QUERY); 161*cdf0e10cSrcweir if (xErrorDialog.is()) 162*cdf0e10cSrcweir xErrorDialog->execute(); 163*cdf0e10cSrcweir else 164*cdf0e10cSrcweir ShowServiceNotAvailableError(pParentWindow, s_sDialogServiceName, sal_True); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir catch(Exception&) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir OSL_ENSURE(sal_False, "displayException: could not display the error message!"); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 173*cdf0e10cSrcweir void displayException(const ::com::sun::star::sdbc::SQLException& _rExcept, Window* _pParent) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir displayException(makeAny(_rExcept), _pParent); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 179*cdf0e10cSrcweir void displayException(const ::com::sun::star::sdbc::SQLWarning& _rExcept, Window* _pParent) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir displayException(makeAny(_rExcept), _pParent); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 185*cdf0e10cSrcweir void displayException(const ::com::sun::star::sdb::SQLContext& _rExcept, Window* _pParent) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir displayException(makeAny(_rExcept), _pParent); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 191*cdf0e10cSrcweir void displayException(const ::com::sun::star::sdb::SQLErrorEvent& _rEvent, Window* _pParent) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir displayException(_rEvent.Reason, _pParent); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir //------------------------------------------------------------------------------ 197*cdf0e10cSrcweir sal_Int32 getElementPos(const Reference< ::com::sun::star::container::XIndexAccess>& xCont, const Reference< XInterface >& xElement) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir sal_Int32 nIndex = -1; 200*cdf0e10cSrcweir if (!xCont.is()) 201*cdf0e10cSrcweir return nIndex; 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir Reference< XInterface > xNormalized( xElement, UNO_QUERY ); 205*cdf0e10cSrcweir DBG_ASSERT( xNormalized.is(), "getElementPos: invalid element!" ); 206*cdf0e10cSrcweir if ( xNormalized.is() ) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir // Feststellen an welcher Position sich das Kind befindet 209*cdf0e10cSrcweir nIndex = xCont->getCount(); 210*cdf0e10cSrcweir while (nIndex--) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir try 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir Reference< XInterface > xCurrent(xCont->getByIndex( nIndex ),UNO_QUERY); 215*cdf0e10cSrcweir DBG_ASSERT( xCurrent.get() == Reference< XInterface >( xCurrent, UNO_QUERY ).get(), 216*cdf0e10cSrcweir "getElementPos: container element not normalized!" ); 217*cdf0e10cSrcweir if ( xNormalized.get() == xCurrent.get() ) 218*cdf0e10cSrcweir break; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir catch(Exception&) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir DBG_ERROR( "getElementPos: caught an exception!" ); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir return nIndex; 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir //------------------------------------------------------------------ 231*cdf0e10cSrcweir ::rtl::OUString getLabelName(const Reference< ::com::sun::star::beans::XPropertySet>& xControlModel) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::getLabelName" ); 234*cdf0e10cSrcweir if (!xControlModel.is()) 235*cdf0e10cSrcweir return ::rtl::OUString(); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir if (::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xControlModel)) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySet> xLabelSet; 240*cdf0e10cSrcweir xControlModel->getPropertyValue(FM_PROP_CONTROLLABEL) >>= xLabelSet; 241*cdf0e10cSrcweir if (xLabelSet.is() && ::comphelper::hasProperty(FM_PROP_LABEL, xLabelSet)) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir Any aLabel( xLabelSet->getPropertyValue(FM_PROP_LABEL) ); 244*cdf0e10cSrcweir if ((aLabel.getValueTypeClass() == TypeClass_STRING) && ::comphelper::getString(aLabel).getLength()) 245*cdf0e10cSrcweir return ::comphelper::getString(aLabel); 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir return ::comphelper::getString(xControlModel->getPropertyValue(FM_PROP_CONTROLSOURCE)); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir //======================================================================== 253*cdf0e10cSrcweir // = CursorWrapper 254*cdf0e10cSrcweir //------------------------------------------------------------------------ 255*cdf0e10cSrcweir CursorWrapper::CursorWrapper(const Reference< ::com::sun::star::sdbc::XRowSet>& _rxCursor, sal_Bool bUseCloned) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir ImplConstruct(Reference< ::com::sun::star::sdbc::XResultSet>(_rxCursor, UNO_QUERY), bUseCloned); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir //------------------------------------------------------------------------ 261*cdf0e10cSrcweir CursorWrapper::CursorWrapper(const Reference< ::com::sun::star::sdbc::XResultSet>& _rxCursor, sal_Bool bUseCloned) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir ImplConstruct(_rxCursor, bUseCloned); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir //------------------------------------------------------------------------ 267*cdf0e10cSrcweir void CursorWrapper::ImplConstruct(const Reference< ::com::sun::star::sdbc::XResultSet>& _rxCursor, sal_Bool bUseCloned) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir if (bUseCloned) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir Reference< ::com::sun::star::sdb::XResultSetAccess> xAccess(_rxCursor, UNO_QUERY); 272*cdf0e10cSrcweir try 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir m_xMoveOperations = xAccess.is() ? xAccess->createResultSet() : Reference< ::com::sun::star::sdbc::XResultSet>(); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir catch(Exception&) 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir else 281*cdf0e10cSrcweir m_xMoveOperations = _rxCursor; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir m_xBookmarkOperations = m_xBookmarkOperations.query( m_xMoveOperations ); 284*cdf0e10cSrcweir m_xColumnsSupplier = m_xColumnsSupplier.query( m_xMoveOperations ); 285*cdf0e10cSrcweir m_xPropertyAccess = m_xPropertyAccess.query( m_xMoveOperations ); 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir if ( !m_xMoveOperations.is() || !m_xBookmarkOperations.is() || !m_xColumnsSupplier.is() || !m_xPropertyAccess.is() ) 288*cdf0e10cSrcweir { // all or nothing !! 289*cdf0e10cSrcweir m_xMoveOperations = NULL; 290*cdf0e10cSrcweir m_xBookmarkOperations = NULL; 291*cdf0e10cSrcweir m_xColumnsSupplier = NULL; 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir else 294*cdf0e10cSrcweir m_xGeneric = m_xMoveOperations.get(); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir //------------------------------------------------------------------------ 298*cdf0e10cSrcweir const CursorWrapper& CursorWrapper::operator=(const Reference< ::com::sun::star::sdbc::XRowSet>& _rxCursor) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir m_xMoveOperations = Reference< ::com::sun::star::sdbc::XResultSet>(_rxCursor, UNO_QUERY); 301*cdf0e10cSrcweir m_xBookmarkOperations = Reference< ::com::sun::star::sdbcx::XRowLocate>(_rxCursor, UNO_QUERY); 302*cdf0e10cSrcweir m_xColumnsSupplier = Reference< ::com::sun::star::sdbcx::XColumnsSupplier>(_rxCursor, UNO_QUERY); 303*cdf0e10cSrcweir if (!m_xMoveOperations.is() || !m_xBookmarkOperations.is() || !m_xColumnsSupplier.is()) 304*cdf0e10cSrcweir { // all or nothing !! 305*cdf0e10cSrcweir m_xMoveOperations = NULL; 306*cdf0e10cSrcweir m_xBookmarkOperations = NULL; 307*cdf0e10cSrcweir m_xColumnsSupplier = NULL; 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir return *this; 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir //------------------------------------------------------------------------------ 313*cdf0e10cSrcweir FmXDisposeListener::~FmXDisposeListener() 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir setAdapter(NULL); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir //------------------------------------------------------------------------------ 319*cdf0e10cSrcweir void FmXDisposeListener::setAdapter(FmXDisposeMultiplexer* pAdapter) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir if (m_pAdapter) 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_rMutex); 324*cdf0e10cSrcweir m_pAdapter->release(); 325*cdf0e10cSrcweir m_pAdapter = NULL; 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir if (pAdapter) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_rMutex); 331*cdf0e10cSrcweir m_pAdapter = pAdapter; 332*cdf0e10cSrcweir m_pAdapter->acquire(); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir //============================================================================== 337*cdf0e10cSrcweir DBG_NAME(FmXDisposeMultiplexer); 338*cdf0e10cSrcweir //------------------------------------------------------------------------------ 339*cdf0e10cSrcweir FmXDisposeMultiplexer::FmXDisposeMultiplexer(FmXDisposeListener* _pListener, const Reference< ::com::sun::star::lang::XComponent>& _rxObject, sal_Int16 _nId) 340*cdf0e10cSrcweir :m_xObject(_rxObject) 341*cdf0e10cSrcweir ,m_pListener(_pListener) 342*cdf0e10cSrcweir ,m_nId(_nId) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir DBG_CTOR(FmXDisposeMultiplexer, NULL); 345*cdf0e10cSrcweir m_pListener->setAdapter(this); 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir if (m_xObject.is()) 348*cdf0e10cSrcweir m_xObject->addEventListener(this); 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir //------------------------------------------------------------------------------ 352*cdf0e10cSrcweir FmXDisposeMultiplexer::~FmXDisposeMultiplexer() 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir DBG_DTOR(FmXDisposeMultiplexer, NULL); 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir // ::com::sun::star::lang::XEventListener 358*cdf0e10cSrcweir //------------------------------------------------------------------ 359*cdf0e10cSrcweir void FmXDisposeMultiplexer::disposing(const ::com::sun::star::lang::EventObject& _Source) throw( RuntimeException ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir Reference< ::com::sun::star::lang::XEventListener> xPreventDelete(this); 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir if (m_pListener) 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir m_pListener->disposing(_Source, m_nId); 366*cdf0e10cSrcweir m_pListener->setAdapter(NULL); 367*cdf0e10cSrcweir m_pListener = NULL; 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir m_xObject = NULL; 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir //------------------------------------------------------------------ 373*cdf0e10cSrcweir void FmXDisposeMultiplexer::dispose() 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir if (m_xObject.is()) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir Reference< ::com::sun::star::lang::XEventListener> xPreventDelete(this); 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir m_xObject->removeEventListener(this); 380*cdf0e10cSrcweir m_xObject = NULL; 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir m_pListener->setAdapter(NULL); 383*cdf0e10cSrcweir m_pListener = NULL; 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir //============================================================================== 388*cdf0e10cSrcweir //------------------------------------------------------------------------------ 389*cdf0e10cSrcweir sal_Int16 getControlTypeByObject(const Reference< ::com::sun::star::lang::XServiceInfo>& _rxObject) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::getControlTypeByObject" ); 392*cdf0e10cSrcweir // ask for the persistent service name 393*cdf0e10cSrcweir Reference< ::com::sun::star::io::XPersistObject> xPersistence(_rxObject, UNO_QUERY); 394*cdf0e10cSrcweir DBG_ASSERT(xPersistence.is(), "::getControlTypeByObject : argument shold be an ::com::sun::star::io::XPersistObject !"); 395*cdf0e10cSrcweir if (!xPersistence.is()) 396*cdf0e10cSrcweir return OBJ_FM_CONTROL; 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir ::rtl::OUString sPersistentServiceName = xPersistence->getServiceName(); 399*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_EDIT)) // 5.0-Name 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir // may be a simple edit field or a formatted field, dependent of the supported services 402*cdf0e10cSrcweir if (_rxObject->supportsService(FM_SUN_COMPONENT_FORMATTEDFIELD)) 403*cdf0e10cSrcweir return OBJ_FM_FORMATTEDFIELD; 404*cdf0e10cSrcweir return OBJ_FM_EDIT; 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_TEXTFIELD)) 407*cdf0e10cSrcweir return OBJ_FM_EDIT; 408*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_COMMANDBUTTON)) 409*cdf0e10cSrcweir return OBJ_FM_BUTTON; 410*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_FIXEDTEXT)) 411*cdf0e10cSrcweir return OBJ_FM_FIXEDTEXT; 412*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_LISTBOX)) 413*cdf0e10cSrcweir return OBJ_FM_LISTBOX; 414*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_CHECKBOX)) 415*cdf0e10cSrcweir return OBJ_FM_CHECKBOX; 416*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_RADIOBUTTON)) 417*cdf0e10cSrcweir return OBJ_FM_RADIOBUTTON; 418*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_GROUPBOX)) 419*cdf0e10cSrcweir return OBJ_FM_GROUPBOX; 420*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_COMBOBOX)) 421*cdf0e10cSrcweir return OBJ_FM_COMBOBOX; 422*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_GRID)) // 5.0-Name 423*cdf0e10cSrcweir return OBJ_FM_GRID; 424*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_GRIDCONTROL)) 425*cdf0e10cSrcweir return OBJ_FM_GRID; 426*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_IMAGEBUTTON)) 427*cdf0e10cSrcweir return OBJ_FM_IMAGEBUTTON; 428*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_FILECONTROL)) 429*cdf0e10cSrcweir return OBJ_FM_FILECONTROL; 430*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_DATEFIELD)) 431*cdf0e10cSrcweir return OBJ_FM_DATEFIELD; 432*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_TIMEFIELD)) 433*cdf0e10cSrcweir return OBJ_FM_TIMEFIELD; 434*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_NUMERICFIELD)) 435*cdf0e10cSrcweir return OBJ_FM_NUMERICFIELD; 436*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_CURRENCYFIELD)) 437*cdf0e10cSrcweir return OBJ_FM_CURRENCYFIELD; 438*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_PATTERNFIELD)) 439*cdf0e10cSrcweir return OBJ_FM_PATTERNFIELD; 440*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_HIDDEN)) // 5.0-Name 441*cdf0e10cSrcweir return OBJ_FM_HIDDEN; 442*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_HIDDENCONTROL)) 443*cdf0e10cSrcweir return OBJ_FM_HIDDEN; 444*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_IMAGECONTROL)) 445*cdf0e10cSrcweir return OBJ_FM_IMAGECONTROL; 446*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_COMPONENT_FORMATTEDFIELD)) 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir DBG_ERROR("::getControlTypeByObject : suspicious persistent service name (formatted field) !"); 449*cdf0e10cSrcweir // objects with that service name should exist as they aren't compatible with older versions 450*cdf0e10cSrcweir return OBJ_FM_FORMATTEDFIELD; 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir if ( sPersistentServiceName.equals( FM_SUN_COMPONENT_SCROLLBAR ) ) 453*cdf0e10cSrcweir return OBJ_FM_SCROLLBAR; 454*cdf0e10cSrcweir if ( sPersistentServiceName.equals( FM_SUN_COMPONENT_SPINBUTTON) ) 455*cdf0e10cSrcweir return OBJ_FM_SPINBUTTON; 456*cdf0e10cSrcweir if (sPersistentServiceName.equals(FM_SUN_COMPONENT_NAVIGATIONBAR)) 457*cdf0e10cSrcweir return OBJ_FM_NAVIGATIONBAR; 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir DBG_ERROR("::getControlTypeByObject : unknown object type !"); 460*cdf0e10cSrcweir return OBJ_FM_CONTROL; 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir //------------------------------------------------------------------------------ 464*cdf0e10cSrcweir void setConnection(const Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet, const Reference< ::com::sun::star::sdbc::XConnection>& _rxConn) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::setConnection" ); 467*cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySet> xRowSetProps(_rxRowSet, UNO_QUERY); 468*cdf0e10cSrcweir if (xRowSetProps.is()) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir try 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir Any aConn(makeAny(_rxConn)); 473*cdf0e10cSrcweir xRowSetProps->setPropertyValue(FM_PROP_ACTIVE_CONNECTION, aConn); 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir catch(Exception&) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir DBG_ERROR("::setConnection : could not set the connection !"); 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir //------------------------------------------------------------------------------ 483*cdf0e10cSrcweir sal_Bool isRowSetAlive(const Reference< XInterface >& _rxRowSet) 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::isRowSetAlive" ); 486*cdf0e10cSrcweir sal_Bool bIsAlive = sal_False; 487*cdf0e10cSrcweir Reference< ::com::sun::star::sdbcx::XColumnsSupplier> xSupplyCols(_rxRowSet, UNO_QUERY); 488*cdf0e10cSrcweir Reference< ::com::sun::star::container::XIndexAccess> xCols; 489*cdf0e10cSrcweir if (xSupplyCols.is()) 490*cdf0e10cSrcweir xCols = Reference< ::com::sun::star::container::XIndexAccess>(xSupplyCols->getColumns(), UNO_QUERY); 491*cdf0e10cSrcweir if (xCols.is() && (xCols->getCount() > 0)) 492*cdf0e10cSrcweir bIsAlive = sal_True; 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir return bIsAlive; 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir 497