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