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 10cdf0e10cSrcweir * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 "formcontrolling.hxx" 28cdf0e10cSrcweir #include "fmurl.hxx" 29cdf0e10cSrcweir #include "svx/svxids.hrc" 30cdf0e10cSrcweir #include "fmprop.hrc" 31cdf0e10cSrcweir #include "svx/fmtools.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir /** === begin UNO includes === **/ 34cdf0e10cSrcweir #include <com/sun/star/form/runtime/FormOperations.hpp> 35cdf0e10cSrcweir #include <com/sun/star/form/runtime/FormFeature.hpp> 36cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 37cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLErrorBroadcaster.hpp> 38cdf0e10cSrcweir /** === end UNO includes === **/ 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <tools/diagnose_ex.h> 41cdf0e10cSrcweir #include <comphelper/anytostring.hxx> 42cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 43cdf0e10cSrcweir #include <osl/diagnose.h> 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include <functional> 46cdf0e10cSrcweir #include <algorithm> 47cdf0e10cSrcweir 48cdf0e10cSrcweir //........................................................................ 49cdf0e10cSrcweir namespace svx 50cdf0e10cSrcweir { 51cdf0e10cSrcweir //........................................................................ 52cdf0e10cSrcweir 53cdf0e10cSrcweir /** === begin UNO using === **/ 54cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 55cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory; 56cdf0e10cSrcweir using ::com::sun::star::form::runtime::XFormController; 57cdf0e10cSrcweir using ::com::sun::star::form::XForm; 58cdf0e10cSrcweir using ::com::sun::star::form::runtime::FormOperations; 59cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 60cdf0e10cSrcweir using ::com::sun::star::sdbc::XRowSet; 61cdf0e10cSrcweir using ::com::sun::star::form::runtime::FeatureState; 62cdf0e10cSrcweir using ::com::sun::star::uno::Any; 63cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 64cdf0e10cSrcweir using ::com::sun::star::beans::NamedValue; 65cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 66cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 67cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 68cdf0e10cSrcweir using ::com::sun::star::sdbc::SQLException; 69cdf0e10cSrcweir using ::com::sun::star::sdb::XSQLErrorBroadcaster; 70cdf0e10cSrcweir using ::com::sun::star::sdb::SQLErrorEvent; 71cdf0e10cSrcweir using ::com::sun::star::lang::EventObject; 72cdf0e10cSrcweir /** === end UNO using === **/ 73cdf0e10cSrcweir namespace FormFeature = ::com::sun::star::form::runtime::FormFeature; 74cdf0e10cSrcweir 75cdf0e10cSrcweir //==================================================================== 76cdf0e10cSrcweir //= FeatureSlotTranslation 77cdf0e10cSrcweir //==================================================================== 78cdf0e10cSrcweir namespace 79cdf0e10cSrcweir { 80cdf0e10cSrcweir struct FeatureDescription 81cdf0e10cSrcweir { 82cdf0e10cSrcweir ::rtl::OUString sURL; // the URL 83cdf0e10cSrcweir sal_Int32 nSlotId; // the SFX-compatible slot ID 84cdf0e10cSrcweir sal_Int16 nFormFeature; // the css.form.runtime.FormFeature ID 85cdf0e10cSrcweir }; 86cdf0e10cSrcweir typedef ::std::vector< FeatureDescription > FeatureDescriptions; 87cdf0e10cSrcweir 88cdf0e10cSrcweir //................................................................ getFeatureDescriptions()89cdf0e10cSrcweir const FeatureDescriptions& getFeatureDescriptions() 90cdf0e10cSrcweir { 91cdf0e10cSrcweir static FeatureDescriptions s_aFeatureDescriptions; 92cdf0e10cSrcweir if ( s_aFeatureDescriptions.empty() ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 95cdf0e10cSrcweir if ( s_aFeatureDescriptions.empty() ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir FeatureDescription aDescriptions[] = { 98cdf0e10cSrcweir { FMURL_FORM_POSITION, SID_FM_RECORD_ABSOLUTE, FormFeature::MoveAbsolute }, 99cdf0e10cSrcweir { FMURL_FORM_RECORDCOUNT, SID_FM_RECORD_TOTAL, FormFeature::TotalRecords }, 100cdf0e10cSrcweir { FMURL_RECORD_MOVEFIRST, SID_FM_RECORD_FIRST, FormFeature::MoveToFirst }, 101cdf0e10cSrcweir { FMURL_RECORD_MOVEPREV, SID_FM_RECORD_PREV, FormFeature::MoveToPrevious }, 102cdf0e10cSrcweir { FMURL_RECORD_MOVENEXT, SID_FM_RECORD_NEXT, FormFeature::MoveToNext }, 103cdf0e10cSrcweir { FMURL_RECORD_MOVELAST, SID_FM_RECORD_LAST, FormFeature::MoveToLast }, 104cdf0e10cSrcweir { FMURL_RECORD_MOVETONEW, SID_FM_RECORD_NEW, FormFeature::MoveToInsertRow }, 105cdf0e10cSrcweir { FMURL_RECORD_SAVE, SID_FM_RECORD_SAVE, FormFeature::SaveRecordChanges }, 106cdf0e10cSrcweir { FMURL_RECORD_DELETE, SID_FM_RECORD_DELETE, FormFeature::DeleteRecord }, 107cdf0e10cSrcweir { FMURL_FORM_REFRESH, SID_FM_REFRESH, FormFeature::ReloadForm }, 108cdf0e10cSrcweir { FMURL_FORM_REFRESH_CURRENT_CONTROL, 109cdf0e10cSrcweir SID_FM_REFRESH_FORM_CONTROL,FormFeature::RefreshCurrentControl }, 110cdf0e10cSrcweir { FMURL_RECORD_UNDO, SID_FM_RECORD_UNDO, FormFeature::UndoRecordChanges }, 111cdf0e10cSrcweir { FMURL_FORM_SORT_UP, SID_FM_SORTUP, FormFeature::SortAscending }, 112cdf0e10cSrcweir { FMURL_FORM_SORT_DOWN, SID_FM_SORTDOWN, FormFeature::SortDescending }, 113cdf0e10cSrcweir { FMURL_FORM_SORT, SID_FM_ORDERCRIT, FormFeature::InteractiveSort }, 114cdf0e10cSrcweir { FMURL_FORM_AUTO_FILTER, SID_FM_AUTOFILTER, FormFeature::AutoFilter }, 115cdf0e10cSrcweir { FMURL_FORM_FILTER, SID_FM_FILTERCRIT, FormFeature::InteractiveFilter }, 116cdf0e10cSrcweir { FMURL_FORM_APPLY_FILTER, SID_FM_FORM_FILTERED, FormFeature::ToggleApplyFilter }, 117cdf0e10cSrcweir { FMURL_FORM_REMOVE_FILTER, SID_FM_REMOVE_FILTER_SORT, FormFeature::RemoveFilterAndSort } 118cdf0e10cSrcweir }; 119cdf0e10cSrcweir for ( size_t i=0; i<sizeof(aDescriptions)/sizeof(aDescriptions[0]); ++i ) 120cdf0e10cSrcweir s_aFeatureDescriptions.push_back( aDescriptions[i] ); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir }; 123cdf0e10cSrcweir return s_aFeatureDescriptions; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir //-------------------------------------------------------------------- 128cdf0e10cSrcweir namespace 129cdf0e10cSrcweir { 130cdf0e10cSrcweir //................................................................ 131cdf0e10cSrcweir struct MatchFeatureDescriptionByURL : public ::std::unary_function< FeatureDescription, bool > 132cdf0e10cSrcweir { 133cdf0e10cSrcweir const ::rtl::OUString& m_rURL; MatchFeatureDescriptionByURLsvx::__anon333d53510211::MatchFeatureDescriptionByURL134cdf0e10cSrcweir MatchFeatureDescriptionByURL( const ::rtl::OUString& _rURL ) :m_rURL( _rURL ) { } 135cdf0e10cSrcweir operator ()svx::__anon333d53510211::MatchFeatureDescriptionByURL136cdf0e10cSrcweir bool operator()( const FeatureDescription& _compare ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir return m_rURL == _compare.sURL; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir }; 141cdf0e10cSrcweir 142cdf0e10cSrcweir //................................................................ 143cdf0e10cSrcweir struct MatchFeatureDescriptionBySlotId : public ::std::unary_function< FeatureDescription, bool > 144cdf0e10cSrcweir { 145cdf0e10cSrcweir sal_Int32 m_nSlotId; MatchFeatureDescriptionBySlotIdsvx::__anon333d53510211::MatchFeatureDescriptionBySlotId146cdf0e10cSrcweir MatchFeatureDescriptionBySlotId( sal_Int32 _nSlotId ) :m_nSlotId( _nSlotId ) { } 147cdf0e10cSrcweir operator ()svx::__anon333d53510211::MatchFeatureDescriptionBySlotId148cdf0e10cSrcweir bool operator()( const FeatureDescription& _compare ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir return m_nSlotId == _compare.nSlotId; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir }; 153cdf0e10cSrcweir 154cdf0e10cSrcweir //................................................................ 155cdf0e10cSrcweir struct MatchFeatureDescriptionByFormFeature : public ::std::unary_function< FeatureDescription, bool > 156cdf0e10cSrcweir { 157cdf0e10cSrcweir sal_Int32 m_nFormFeature; MatchFeatureDescriptionByFormFeaturesvx::__anon333d53510211::MatchFeatureDescriptionByFormFeature158cdf0e10cSrcweir MatchFeatureDescriptionByFormFeature( sal_Int32 _nFormFeature ) :m_nFormFeature( _nFormFeature ) { } 159cdf0e10cSrcweir operator ()svx::__anon333d53510211::MatchFeatureDescriptionByFormFeature160cdf0e10cSrcweir bool operator()( const FeatureDescription& _compare ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir return m_nFormFeature == _compare.nFormFeature; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir }; 165cdf0e10cSrcweir 166cdf0e10cSrcweir //................................................................ 167cdf0e10cSrcweir struct FormFeatureToSlotId : public ::std::unary_function< sal_Int16, sal_Int32 > 168cdf0e10cSrcweir { operator ()svx::__anon333d53510211::FormFeatureToSlotId169cdf0e10cSrcweir sal_Int32 operator()( sal_Int16 _FormFeature ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir return FeatureSlotTranslation::getSlotIdForFormFeature( _FormFeature ); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir }; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir //-------------------------------------------------------------------- getControllerFeatureSlotIdForURL(const::rtl::OUString & _rMainURL)177cdf0e10cSrcweir sal_Int32 FeatureSlotTranslation::getControllerFeatureSlotIdForURL( const ::rtl::OUString& _rMainURL ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir const FeatureDescriptions& rDescriptions( getFeatureDescriptions() ); 180cdf0e10cSrcweir FeatureDescriptions::const_iterator pos = ::std::find_if( rDescriptions.begin(), rDescriptions.end(), MatchFeatureDescriptionByURL( _rMainURL ) ); 181cdf0e10cSrcweir return ( pos != rDescriptions.end() ) ? pos->nSlotId : -1; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir //-------------------------------------------------------------------- getControllerFeatureURLForSlotId(sal_Int32 _nSlotId)185cdf0e10cSrcweir ::rtl::OUString FeatureSlotTranslation::getControllerFeatureURLForSlotId( sal_Int32 _nSlotId ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir const FeatureDescriptions& rDescriptions( getFeatureDescriptions() ); 188cdf0e10cSrcweir FeatureDescriptions::const_iterator pos = ::std::find_if( rDescriptions.begin(), rDescriptions.end(), MatchFeatureDescriptionBySlotId( _nSlotId ) ); 189cdf0e10cSrcweir OSL_ENSURE( pos != rDescriptions.end(), "FeatureSlotTranslation::getControllerFeatureURLForSlotId: not found!" ); 190cdf0e10cSrcweir return ( pos != rDescriptions.end() ) ? pos->sURL : ::rtl::OUString(); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir //-------------------------------------------------------------------- isFeatureURL(const::rtl::OUString & _rMainURL)194cdf0e10cSrcweir sal_Bool FeatureSlotTranslation::isFeatureURL( const ::rtl::OUString& _rMainURL ) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir return ( _rMainURL.indexOf( FMURL_FORMSLOTS_PREFIX ) == 0 ); 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir //-------------------------------------------------------------------- getFormFeatureForSlotId(sal_Int32 _nSlotId)200cdf0e10cSrcweir sal_Int16 FeatureSlotTranslation::getFormFeatureForSlotId( sal_Int32 _nSlotId ) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir const FeatureDescriptions& rDescriptions( getFeatureDescriptions() ); 203cdf0e10cSrcweir FeatureDescriptions::const_iterator pos = ::std::find_if( rDescriptions.begin(), rDescriptions.end(), MatchFeatureDescriptionBySlotId( _nSlotId ) ); 204cdf0e10cSrcweir OSL_ENSURE( pos != rDescriptions.end(), "FeatureSlotTranslation::getFormFeatureForSlotId: not found!" ); 205cdf0e10cSrcweir return ( pos != rDescriptions.end() ) ? pos->nFormFeature : -1; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir //-------------------------------------------------------------------- getSlotIdForFormFeature(sal_Int16 _nFormFeature)209cdf0e10cSrcweir sal_Int32 FeatureSlotTranslation::getSlotIdForFormFeature( sal_Int16 _nFormFeature ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir const FeatureDescriptions& rDescriptions( getFeatureDescriptions() ); 212cdf0e10cSrcweir FeatureDescriptions::const_iterator pos = ::std::find_if( rDescriptions.begin(), rDescriptions.end(), MatchFeatureDescriptionByFormFeature( _nFormFeature ) ); 213cdf0e10cSrcweir OSL_ENSURE( pos != rDescriptions.end(), "FeatureSlotTranslation::getSlotIdForFormFeature: not found!" ); 214cdf0e10cSrcweir return ( pos != rDescriptions.end() ) ? pos->nSlotId : -1; 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir //==================================================================== 218cdf0e10cSrcweir //= ControllerFeatures 219cdf0e10cSrcweir //==================================================================== 220cdf0e10cSrcweir //-------------------------------------------------------------------- ControllerFeatures(const Reference<XMultiServiceFactory> & _rxORB,IControllerFeatureInvalidation * _pInvalidationCallback)221cdf0e10cSrcweir ControllerFeatures::ControllerFeatures( const Reference< XMultiServiceFactory >& _rxORB, IControllerFeatureInvalidation* _pInvalidationCallback ) 222cdf0e10cSrcweir :m_aContext( _rxORB ) 223cdf0e10cSrcweir ,m_pInvalidationCallback( _pInvalidationCallback ) 224cdf0e10cSrcweir ,m_pImpl( NULL ) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir //-------------------------------------------------------------------- ControllerFeatures(const Reference<XMultiServiceFactory> & _rxORB,const Reference<XFormController> & _rxController,IControllerFeatureInvalidation * _pInvalidationCallback)229cdf0e10cSrcweir ControllerFeatures::ControllerFeatures( const Reference< XMultiServiceFactory >& _rxORB, 230cdf0e10cSrcweir const Reference< XFormController >& _rxController, IControllerFeatureInvalidation* _pInvalidationCallback ) 231cdf0e10cSrcweir :m_aContext( _rxORB ) 232cdf0e10cSrcweir ,m_pInvalidationCallback( _pInvalidationCallback ) 233cdf0e10cSrcweir ,m_pImpl( NULL ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir assign( _rxController ); 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir //-------------------------------------------------------------------- ControllerFeatures(const Reference<XMultiServiceFactory> & _rxORB,const Reference<XForm> & _rxForm,IControllerFeatureInvalidation * _pInvalidationCallback)239cdf0e10cSrcweir ControllerFeatures::ControllerFeatures( const Reference< XMultiServiceFactory >& _rxORB, 240cdf0e10cSrcweir const Reference< XForm >& _rxForm, IControllerFeatureInvalidation* _pInvalidationCallback ) 241cdf0e10cSrcweir :m_aContext( _rxORB ) 242cdf0e10cSrcweir ,m_pInvalidationCallback( _pInvalidationCallback ) 243cdf0e10cSrcweir ,m_pImpl( NULL ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir assign( _rxForm ); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir //-------------------------------------------------------------------- assign(const Reference<XFormController> & _rxController)249cdf0e10cSrcweir void ControllerFeatures::assign( const Reference< XFormController >& _rxController ) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir dispose(); 252cdf0e10cSrcweir m_pImpl = new FormControllerHelper( m_aContext, _rxController, m_pInvalidationCallback ); 253cdf0e10cSrcweir m_pImpl->acquire(); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir //-------------------------------------------------------------------- assign(const Reference<XForm> & _rxForm)257cdf0e10cSrcweir void ControllerFeatures::assign( const Reference< XForm >& _rxForm ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir dispose(); 260cdf0e10cSrcweir m_pImpl = new FormControllerHelper( m_aContext, _rxForm, m_pInvalidationCallback ); 261cdf0e10cSrcweir m_pImpl->acquire(); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir 264cdf0e10cSrcweir //-------------------------------------------------------------------- ~ControllerFeatures()265cdf0e10cSrcweir ControllerFeatures::~ControllerFeatures() 266cdf0e10cSrcweir { 267cdf0e10cSrcweir dispose(); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir //-------------------------------------------------------------------- dispose()271cdf0e10cSrcweir void ControllerFeatures::dispose() 272cdf0e10cSrcweir { 273cdf0e10cSrcweir if ( m_pImpl ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir m_pImpl->dispose(); 276cdf0e10cSrcweir m_pImpl->release(); 277cdf0e10cSrcweir m_pImpl = NULL; 278cdf0e10cSrcweir } 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir //==================================================================== 282cdf0e10cSrcweir //= FormControllerHelper 283cdf0e10cSrcweir //==================================================================== 284cdf0e10cSrcweir //-------------------------------------------------------------------- FormControllerHelper(const::comphelper::ComponentContext & _rContext,const Reference<XFormController> & _rxController,IControllerFeatureInvalidation * _pInvalidationCallback)285cdf0e10cSrcweir FormControllerHelper::FormControllerHelper( const ::comphelper::ComponentContext& _rContext, 286cdf0e10cSrcweir const Reference< XFormController >& _rxController, IControllerFeatureInvalidation* _pInvalidationCallback ) 287cdf0e10cSrcweir :m_aContext( _rContext ) 288cdf0e10cSrcweir ,m_pInvalidationCallback( _pInvalidationCallback ) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 291cdf0e10cSrcweir try 292cdf0e10cSrcweir { 293cdf0e10cSrcweir m_xFormOperations = FormOperations::createWithFormController( m_aContext.getUNOContext(), _rxController ); 294cdf0e10cSrcweir if ( m_xFormOperations.is() ) 295cdf0e10cSrcweir m_xFormOperations->setFeatureInvalidation( this ); 296cdf0e10cSrcweir 297cdf0e10cSrcweir // to prevent the controller from displaying any error messages which happen while we operate on it, 298cdf0e10cSrcweir // we add ourself as XSQLErrorListener. By contract, a FormController displays errors if and only if 299cdf0e10cSrcweir // no SQLErrorListeners are registered. 300cdf0e10cSrcweir Reference< XSQLErrorBroadcaster > xErrorBroadcast( _rxController, UNO_QUERY_THROW ); 301cdf0e10cSrcweir xErrorBroadcast->addSQLErrorListener( this ); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir catch( const Exception& ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 306cdf0e10cSrcweir } 307cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir //-------------------------------------------------------------------- FormControllerHelper(const::comphelper::ComponentContext & _rContext,const Reference<XForm> & _rxForm,IControllerFeatureInvalidation * _pInvalidationCallback)311cdf0e10cSrcweir FormControllerHelper::FormControllerHelper( const ::comphelper::ComponentContext& _rContext, 312cdf0e10cSrcweir const Reference< XForm >& _rxForm, IControllerFeatureInvalidation* _pInvalidationCallback ) 313cdf0e10cSrcweir :m_aContext( _rContext ) 314cdf0e10cSrcweir ,m_pInvalidationCallback( _pInvalidationCallback ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 317cdf0e10cSrcweir try 318cdf0e10cSrcweir { 319cdf0e10cSrcweir m_xFormOperations = FormOperations::createWithForm( m_aContext.getUNOContext(), _rxForm ); 320cdf0e10cSrcweir if ( m_xFormOperations.is() ) 321cdf0e10cSrcweir m_xFormOperations->setFeatureInvalidation( this ); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir catch( const Exception& ) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 328cdf0e10cSrcweir } 329cdf0e10cSrcweir 330cdf0e10cSrcweir //-------------------------------------------------------------------- ~FormControllerHelper()331cdf0e10cSrcweir FormControllerHelper::~FormControllerHelper( ) 332cdf0e10cSrcweir { 333cdf0e10cSrcweir try 334cdf0e10cSrcweir { 335cdf0e10cSrcweir acquire(); 336cdf0e10cSrcweir dispose(); 337cdf0e10cSrcweir } 338cdf0e10cSrcweir catch( const Exception& ) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir //-------------------------------------------------------------------- dispose()345cdf0e10cSrcweir void FormControllerHelper::dispose() 346cdf0e10cSrcweir { 347cdf0e10cSrcweir if ( m_xFormOperations.is() ) 348cdf0e10cSrcweir m_xFormOperations->dispose(); 349cdf0e10cSrcweir m_xFormOperations.clear(); 350cdf0e10cSrcweir } 351cdf0e10cSrcweir 352cdf0e10cSrcweir //-------------------------------------------------------------------- isEnabled(sal_Int32 _nSlotId) const353cdf0e10cSrcweir sal_Bool FormControllerHelper::isEnabled( sal_Int32 _nSlotId ) const 354cdf0e10cSrcweir { 355cdf0e10cSrcweir if ( !m_xFormOperations.is() ) 356cdf0e10cSrcweir return sal_False; 357cdf0e10cSrcweir return m_xFormOperations->isEnabled( FeatureSlotTranslation::getFormFeatureForSlotId( _nSlotId ) ); 358cdf0e10cSrcweir } 359cdf0e10cSrcweir 360cdf0e10cSrcweir //-------------------------------------------------------------------- getCursor() const361cdf0e10cSrcweir Reference< XRowSet > FormControllerHelper::getCursor() const 362cdf0e10cSrcweir { 363cdf0e10cSrcweir Reference< XRowSet > xCursor; 364cdf0e10cSrcweir if ( m_xFormOperations.is() ) 365cdf0e10cSrcweir xCursor = m_xFormOperations->getCursor(); 366cdf0e10cSrcweir return xCursor; 367cdf0e10cSrcweir } 368cdf0e10cSrcweir 369cdf0e10cSrcweir //-------------------------------------------------------------------- getState(sal_Int32 _nSlotId,FeatureState & _rState) const370cdf0e10cSrcweir void FormControllerHelper::getState( sal_Int32 _nSlotId, FeatureState& _rState ) const 371cdf0e10cSrcweir { 372cdf0e10cSrcweir if ( m_xFormOperations.is() ) 373cdf0e10cSrcweir _rState = m_xFormOperations->getState( FeatureSlotTranslation::getFormFeatureForSlotId( _nSlotId ) ); 374cdf0e10cSrcweir } 375cdf0e10cSrcweir 376cdf0e10cSrcweir //-------------------------------------------------------------------- commitCurrentControl() const377cdf0e10cSrcweir sal_Bool FormControllerHelper::commitCurrentControl( ) const 378cdf0e10cSrcweir { 379cdf0e10cSrcweir return impl_operateForm_nothrow( COMMIT_CONTROL ); 380cdf0e10cSrcweir } 381cdf0e10cSrcweir 382cdf0e10cSrcweir //-------------------------------------------------------------------- commitCurrentRecord() const383cdf0e10cSrcweir sal_Bool FormControllerHelper::commitCurrentRecord() const 384cdf0e10cSrcweir { 385cdf0e10cSrcweir return impl_operateForm_nothrow( COMMIT_RECORD ); 386cdf0e10cSrcweir } 387cdf0e10cSrcweir 388cdf0e10cSrcweir //-------------------------------------------------------------------- moveRight() const389cdf0e10cSrcweir bool FormControllerHelper::moveRight( ) const 390cdf0e10cSrcweir { 391cdf0e10cSrcweir return impl_operateForm_nothrow( FormFeature::MoveToNext ); 392cdf0e10cSrcweir } 393cdf0e10cSrcweir 394cdf0e10cSrcweir //-------------------------------------------------------------------- moveLeft() const395cdf0e10cSrcweir bool FormControllerHelper::moveLeft( ) const 396cdf0e10cSrcweir { 397cdf0e10cSrcweir return impl_operateForm_nothrow( FormFeature::MoveToPrevious ); 398cdf0e10cSrcweir } 399cdf0e10cSrcweir 400cdf0e10cSrcweir //-------------------------------------------------------------------- execute(sal_Int32 _nSlotId,const::rtl::OUString & _rParamName,const Any & _rParamValue) const401cdf0e10cSrcweir void FormControllerHelper::execute( sal_Int32 _nSlotId, const ::rtl::OUString& _rParamName, const Any& _rParamValue ) const 402cdf0e10cSrcweir { 403cdf0e10cSrcweir Sequence< NamedValue > aArguments(1); 404cdf0e10cSrcweir aArguments[0].Name = _rParamName; 405cdf0e10cSrcweir aArguments[0].Value = _rParamValue; 406cdf0e10cSrcweir 407cdf0e10cSrcweir impl_operateForm_nothrow( EXECUTE_ARGS, FeatureSlotTranslation::getFormFeatureForSlotId( _nSlotId ), aArguments ); 408cdf0e10cSrcweir } 409cdf0e10cSrcweir 410cdf0e10cSrcweir //-------------------------------------------------------------------- impl_operateForm_nothrow(const FormOperation _eWhat,const sal_Int16 _nFeature,const Sequence<NamedValue> & _rArguments) const411cdf0e10cSrcweir bool FormControllerHelper::impl_operateForm_nothrow( const FormOperation _eWhat, const sal_Int16 _nFeature, 412cdf0e10cSrcweir const Sequence< NamedValue >& _rArguments ) const 413cdf0e10cSrcweir { 414cdf0e10cSrcweir if ( !m_xFormOperations.is() ) 415cdf0e10cSrcweir return false; 416cdf0e10cSrcweir 417cdf0e10cSrcweir Any aError; 418cdf0e10cSrcweir bool bSuccess = false; 419cdf0e10cSrcweir const_cast< FormControllerHelper* >( this )->m_aOperationError.clear(); 420cdf0e10cSrcweir try 421cdf0e10cSrcweir { 422cdf0e10cSrcweir switch ( _eWhat ) 423cdf0e10cSrcweir { 424cdf0e10cSrcweir case COMMIT_CONTROL: 425cdf0e10cSrcweir bSuccess = m_xFormOperations->commitCurrentControl(); 426cdf0e10cSrcweir break; 427cdf0e10cSrcweir 428cdf0e10cSrcweir case COMMIT_RECORD: 429cdf0e10cSrcweir { 430cdf0e10cSrcweir sal_Bool bDummy( sal_False ); 431cdf0e10cSrcweir bSuccess = m_xFormOperations->commitCurrentRecord( bDummy ); 432cdf0e10cSrcweir } 433cdf0e10cSrcweir break; 434cdf0e10cSrcweir 435cdf0e10cSrcweir case EXECUTE: 436cdf0e10cSrcweir m_xFormOperations->execute( _nFeature ); 437cdf0e10cSrcweir bSuccess = true; 438cdf0e10cSrcweir break; 439cdf0e10cSrcweir 440cdf0e10cSrcweir case EXECUTE_ARGS: 441cdf0e10cSrcweir m_xFormOperations->executeWithArguments( _nFeature, _rArguments ); 442cdf0e10cSrcweir bSuccess = true; 443cdf0e10cSrcweir break; 444cdf0e10cSrcweir } 445cdf0e10cSrcweir } 446cdf0e10cSrcweir catch ( const SQLException& ) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir aError = ::cppu::getCaughtException(); 449cdf0e10cSrcweir } 450cdf0e10cSrcweir catch( const Exception& ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir SQLException aFallbackError; 453cdf0e10cSrcweir aFallbackError.Message = ::comphelper::anyToString( ::cppu::getCaughtException() ); 454cdf0e10cSrcweir aError <<= aFallbackError; 455cdf0e10cSrcweir } 456cdf0e10cSrcweir 457cdf0e10cSrcweir if ( bSuccess ) 458cdf0e10cSrcweir return true; 459cdf0e10cSrcweir 460cdf0e10cSrcweir // display the error. Prefer the one reported in errorOccured over the one caught. 461cdf0e10cSrcweir if ( m_aOperationError.hasValue() ) 462cdf0e10cSrcweir displayException( m_aOperationError ); 463cdf0e10cSrcweir else if ( aError.hasValue() ) 464cdf0e10cSrcweir displayException( aError ); 465cdf0e10cSrcweir else 466cdf0e10cSrcweir OSL_ENSURE( false, "FormControllerHelper::impl_operateForm_nothrow: no success, but no error?" ); 467cdf0e10cSrcweir 468cdf0e10cSrcweir return false; 469cdf0e10cSrcweir } 470cdf0e10cSrcweir 471cdf0e10cSrcweir //-------------------------------------------------------------------- execute(sal_Int32 _nSlotId) const472cdf0e10cSrcweir void FormControllerHelper::execute( sal_Int32 _nSlotId ) const 473cdf0e10cSrcweir { 474cdf0e10cSrcweir impl_operateForm_nothrow( EXECUTE, FeatureSlotTranslation::getFormFeatureForSlotId( _nSlotId ), 475cdf0e10cSrcweir Sequence< NamedValue >() ); 476cdf0e10cSrcweir } 477cdf0e10cSrcweir 478cdf0e10cSrcweir //-------------------------------------------------------------------- invalidateFeatures(const Sequence<::sal_Int16> & _Features)479cdf0e10cSrcweir void SAL_CALL FormControllerHelper::invalidateFeatures( const Sequence< ::sal_Int16 >& _Features ) throw (RuntimeException) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir if ( !m_pInvalidationCallback ) 482cdf0e10cSrcweir // nobody's interested in ... 483cdf0e10cSrcweir return; 484cdf0e10cSrcweir 485cdf0e10cSrcweir ::std::vector< sal_Int32 > aFeatures( _Features.getLength() ); 486cdf0e10cSrcweir ::std::transform( 487cdf0e10cSrcweir _Features.getConstArray(), 488cdf0e10cSrcweir _Features.getConstArray() + _Features.getLength(), 489cdf0e10cSrcweir aFeatures.begin(), 490cdf0e10cSrcweir FormFeatureToSlotId() 491cdf0e10cSrcweir ); 492cdf0e10cSrcweir 493cdf0e10cSrcweir m_pInvalidationCallback->invalidateFeatures( aFeatures ); 494cdf0e10cSrcweir } 495cdf0e10cSrcweir 496cdf0e10cSrcweir //-------------------------------------------------------------------- invalidateAllFeatures()497cdf0e10cSrcweir void SAL_CALL FormControllerHelper::invalidateAllFeatures() throw (RuntimeException) 498cdf0e10cSrcweir { 499cdf0e10cSrcweir if ( !m_pInvalidationCallback ) 500cdf0e10cSrcweir // nobody's interested in ... 501cdf0e10cSrcweir return; 502cdf0e10cSrcweir 503cdf0e10cSrcweir // actually, it's a little bit more than the supported features, 504cdf0e10cSrcweir // but on the medium term, we are to support everything listed 505cdf0e10cSrcweir // here 506cdf0e10cSrcweir ::std::vector< sal_Int32 > aSupportedFeatures; 507cdf0e10cSrcweir sal_Int32 pSupportedFeatures[] = 508cdf0e10cSrcweir { 509cdf0e10cSrcweir SID_FM_RECORD_FIRST, 510cdf0e10cSrcweir SID_FM_RECORD_NEXT, 511cdf0e10cSrcweir SID_FM_RECORD_PREV, 512cdf0e10cSrcweir SID_FM_RECORD_LAST, 513cdf0e10cSrcweir SID_FM_RECORD_NEW, 514cdf0e10cSrcweir SID_FM_RECORD_DELETE, 515cdf0e10cSrcweir SID_FM_RECORD_ABSOLUTE, 516cdf0e10cSrcweir SID_FM_RECORD_TOTAL, 517cdf0e10cSrcweir SID_FM_RECORD_SAVE, 518cdf0e10cSrcweir SID_FM_RECORD_UNDO, 519cdf0e10cSrcweir SID_FM_REMOVE_FILTER_SORT, 520cdf0e10cSrcweir SID_FM_SORTUP, 521cdf0e10cSrcweir SID_FM_SORTDOWN, 522cdf0e10cSrcweir SID_FM_ORDERCRIT, 523cdf0e10cSrcweir SID_FM_AUTOFILTER, 524cdf0e10cSrcweir SID_FM_FILTERCRIT, 525cdf0e10cSrcweir SID_FM_FORM_FILTERED, 526cdf0e10cSrcweir SID_FM_REFRESH, 527cdf0e10cSrcweir SID_FM_REFRESH_FORM_CONTROL, 528cdf0e10cSrcweir SID_FM_SEARCH, 529cdf0e10cSrcweir SID_FM_FILTER_START, 530cdf0e10cSrcweir SID_FM_VIEW_AS_GRID 531cdf0e10cSrcweir }; 532cdf0e10cSrcweir sal_Int32 nFeatureCount = sizeof( pSupportedFeatures ) / sizeof( pSupportedFeatures[ 0 ] ); 533cdf0e10cSrcweir aSupportedFeatures.resize( nFeatureCount ); 534cdf0e10cSrcweir ::std::copy( pSupportedFeatures, pSupportedFeatures + nFeatureCount, aSupportedFeatures.begin() ); 535cdf0e10cSrcweir 536cdf0e10cSrcweir m_pInvalidationCallback->invalidateFeatures( aSupportedFeatures ); 537cdf0e10cSrcweir } 538cdf0e10cSrcweir 539cdf0e10cSrcweir //-------------------------------------------------------------------- errorOccured(const SQLErrorEvent & _Event)540cdf0e10cSrcweir void SAL_CALL FormControllerHelper::errorOccured( const SQLErrorEvent& _Event ) throw (RuntimeException) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir OSL_ENSURE( !m_aOperationError.hasValue(), "FormControllerHelper::errorOccured: two errors during one operation?" ); 543cdf0e10cSrcweir m_aOperationError = _Event.Reason; 544cdf0e10cSrcweir } 545cdf0e10cSrcweir 546cdf0e10cSrcweir //-------------------------------------------------------------------- disposing(const EventObject &)547cdf0e10cSrcweir void SAL_CALL FormControllerHelper::disposing( const EventObject& /*_Source*/ ) throw (RuntimeException) 548cdf0e10cSrcweir { 549cdf0e10cSrcweir // not interested in 550cdf0e10cSrcweir } 551cdf0e10cSrcweir 552cdf0e10cSrcweir //-------------------------------------------------------------------- isInsertionRow() const553cdf0e10cSrcweir sal_Bool FormControllerHelper::isInsertionRow() const 554cdf0e10cSrcweir { 555cdf0e10cSrcweir sal_Bool bIs = sal_False; 556cdf0e10cSrcweir if ( m_xFormOperations.is() ) 557cdf0e10cSrcweir bIs = m_xFormOperations->isInsertionRow(); 558cdf0e10cSrcweir return bIs; 559cdf0e10cSrcweir } 560cdf0e10cSrcweir 561cdf0e10cSrcweir //-------------------------------------------------------------------- isModifiedRow() const562cdf0e10cSrcweir sal_Bool FormControllerHelper::isModifiedRow() const 563cdf0e10cSrcweir { 564cdf0e10cSrcweir sal_Bool bIs = sal_False; 565cdf0e10cSrcweir if ( m_xFormOperations.is() ) 566cdf0e10cSrcweir bIs = m_xFormOperations->isModifiedRow(); 567cdf0e10cSrcweir return bIs; 568cdf0e10cSrcweir } 569cdf0e10cSrcweir //-------------------------------------------------------------------- canDoFormFilter() const570cdf0e10cSrcweir bool FormControllerHelper::canDoFormFilter() const 571cdf0e10cSrcweir { 572cdf0e10cSrcweir if ( !m_xFormOperations.is() ) 573cdf0e10cSrcweir return false; 574cdf0e10cSrcweir 575cdf0e10cSrcweir bool bCanDo = false; 576cdf0e10cSrcweir try 577cdf0e10cSrcweir { 578cdf0e10cSrcweir Reference< XPropertySet > xCursorProperties( m_xFormOperations->getCursor(), UNO_QUERY_THROW ); 579cdf0e10cSrcweir 580cdf0e10cSrcweir bool bEscapeProcessing( false ); 581cdf0e10cSrcweir OSL_VERIFY( xCursorProperties->getPropertyValue( FM_PROP_ESCAPE_PROCESSING ) >>= bEscapeProcessing ); 582cdf0e10cSrcweir 583cdf0e10cSrcweir ::rtl::OUString sActiveCommand; 584cdf0e10cSrcweir OSL_VERIFY( xCursorProperties->getPropertyValue( FM_PROP_ACTIVECOMMAND ) >>= sActiveCommand ); 585cdf0e10cSrcweir 586cdf0e10cSrcweir bool bInsertOnlyForm( false ); 587cdf0e10cSrcweir OSL_VERIFY( xCursorProperties->getPropertyValue( FM_PROP_INSERTONLY ) >>= bInsertOnlyForm ); 588cdf0e10cSrcweir 589cdf0e10cSrcweir bCanDo = bEscapeProcessing && ( sActiveCommand.getLength() > 0 ) && !bInsertOnlyForm; 590cdf0e10cSrcweir } 591cdf0e10cSrcweir catch( const Exception& ) 592cdf0e10cSrcweir { 593cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 594cdf0e10cSrcweir } 595cdf0e10cSrcweir return bCanDo; 596cdf0e10cSrcweir } 597cdf0e10cSrcweir 598cdf0e10cSrcweir //........................................................................ 599cdf0e10cSrcweir } // namespace svx 600cdf0e10cSrcweir //........................................................................ 601