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_forms.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "formoperations.hxx" 32*cdf0e10cSrcweir #include "frm_strings.hxx" 33*cdf0e10cSrcweir #include "frm_resource.hxx" 34*cdf0e10cSrcweir #include "frm_resource.hrc" 35*cdf0e10cSrcweir #include "frm_module.hxx" 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir /** === begin UNO includes === **/ 38*cdf0e10cSrcweir #include <com/sun/star/ucb/AlreadyInitializedException.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/form/runtime/FormFeature.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/form/XGrid.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/form/XBoundControl.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/form/XBoundComponent.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XRowLocate.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/form/XConfirmDeleteListener.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/sdb/RowChangeEvent.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/sdb/RowChangeAction.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLFilterOperator.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/form/XReset.hpp> 54*cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp> 55*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 56*cdf0e10cSrcweir #include <com/sun/star/util/XRefreshable.hpp> 57*cdf0e10cSrcweir /** === end UNO includes === **/ 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir #include <connectivity/dbtools.hxx> 60*cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 61*cdf0e10cSrcweir #include <vcl/svapp.hxx> 62*cdf0e10cSrcweir #include <vcl/stdtext.hxx> 63*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 64*cdf0e10cSrcweir #include <vcl/waitobj.hxx> 65*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 66*cdf0e10cSrcweir #include <comphelper/container.hxx> 67*cdf0e10cSrcweir #include <comphelper/property.hxx> 68*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx> 69*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 70*cdf0e10cSrcweir #include <vos/mutex.hxx> 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir //-------------------------------------------------------------------------- 73*cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_FormOperations() 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir static ::frm::OMultiInstanceAutoRegistration< ::frm::FormOperations > aAutoRegistration; 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir //........................................................................ 79*cdf0e10cSrcweir namespace frm 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir //........................................................................ 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir using ::dbtools::SQLExceptionInfo; 84*cdf0e10cSrcweir /** === begin UNO using === **/ 85*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 86*cdf0e10cSrcweir using ::com::sun::star::uno::XComponentContext; 87*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 88*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 89*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 90*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 91*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 92*cdf0e10cSrcweir using ::com::sun::star::sdbc::XRowSet; 93*cdf0e10cSrcweir using ::com::sun::star::sdbc::XResultSetUpdate; 94*cdf0e10cSrcweir using ::com::sun::star::form::runtime::XFormController; 95*cdf0e10cSrcweir using ::com::sun::star::form::runtime::XFeatureInvalidation; 96*cdf0e10cSrcweir using ::com::sun::star::form::runtime::FeatureState; 97*cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException; 98*cdf0e10cSrcweir using ::com::sun::star::sdbc::SQLException; 99*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 100*cdf0e10cSrcweir using ::com::sun::star::form::XForm; 101*cdf0e10cSrcweir using ::com::sun::star::ucb::AlreadyInitializedException; 102*cdf0e10cSrcweir using ::com::sun::star::util::XModifyBroadcaster; 103*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 104*cdf0e10cSrcweir using ::com::sun::star::lang::EventObject; 105*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyChangeEvent; 106*cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory; 107*cdf0e10cSrcweir using ::com::sun::star::lang::DisposedException; 108*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 109*cdf0e10cSrcweir using ::com::sun::star::awt::XControl; 110*cdf0e10cSrcweir using ::com::sun::star::form::XGrid; 111*cdf0e10cSrcweir using ::com::sun::star::container::XIndexAccess; 112*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 113*cdf0e10cSrcweir using ::com::sun::star::form::XBoundControl; 114*cdf0e10cSrcweir using ::com::sun::star::form::XBoundComponent; 115*cdf0e10cSrcweir using ::com::sun::star::sdbcx::XRowLocate; 116*cdf0e10cSrcweir using ::com::sun::star::form::XConfirmDeleteListener; 117*cdf0e10cSrcweir using ::com::sun::star::sdb::RowChangeEvent; 118*cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 119*cdf0e10cSrcweir using ::com::sun::star::form::XReset; 120*cdf0e10cSrcweir using ::com::sun::star::beans::XMultiPropertySet; 121*cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 122*cdf0e10cSrcweir using ::com::sun::star::lang::WrappedTargetException; 123*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue; 124*cdf0e10cSrcweir using ::com::sun::star::ui::dialogs::XExecutableDialog; 125*cdf0e10cSrcweir using ::com::sun::star::beans::NamedValue; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir using ::com::sun::star::util::XRefreshable; 128*cdf0e10cSrcweir using ::com::sun::star::awt::XControlModel; 129*cdf0e10cSrcweir /** === end UNO using === **/ 130*cdf0e10cSrcweir namespace FormFeature = ::com::sun::star::form::runtime::FormFeature; 131*cdf0e10cSrcweir namespace RowChangeAction = ::com::sun::star::sdb::RowChangeAction; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir //==================================================================== 134*cdf0e10cSrcweir //= FormOperations 135*cdf0e10cSrcweir //==================================================================== 136*cdf0e10cSrcweir //-------------------------------------------------------------------- 137*cdf0e10cSrcweir FormOperations::FormOperations( const Reference< XMultiServiceFactory >& _rxContext ) 138*cdf0e10cSrcweir :FormOperations_Base( m_aMutex ) 139*cdf0e10cSrcweir ,m_aContext( _rxContext ) 140*cdf0e10cSrcweir ,m_bInitializedParser( false ) 141*cdf0e10cSrcweir ,m_bActiveControlModified( false ) 142*cdf0e10cSrcweir ,m_bConstructed( false ) 143*cdf0e10cSrcweir #ifdef DBG_UTIL 144*cdf0e10cSrcweir ,m_nMethodNestingLevel( false ) 145*cdf0e10cSrcweir #endif 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir //-------------------------------------------------------------------- 150*cdf0e10cSrcweir FormOperations::~FormOperations() 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir //-------------------------------------------------------------------- 155*cdf0e10cSrcweir ::rtl::OUString FormOperations::getImplementationName_Static( ) throw(RuntimeException) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.forms.FormOperations" ) ); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //-------------------------------------------------------------------- 161*cdf0e10cSrcweir Sequence< ::rtl::OUString > FormOperations::getSupportedServiceNames_Static( ) throw(RuntimeException) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames(1); 164*cdf0e10cSrcweir aNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.runtime.FormOperations" ) ); 165*cdf0e10cSrcweir return aNames; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir //-------------------------------------------------------------------- 169*cdf0e10cSrcweir Reference< XInterface > SAL_CALL FormOperations::Create(const Reference< XMultiServiceFactory >& _rxFactory ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir return *new FormOperations( _rxFactory ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir //-------------------------------------------------------------------- 175*cdf0e10cSrcweir void SAL_CALL FormOperations::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir if ( m_bConstructed ) 178*cdf0e10cSrcweir throw AlreadyInitializedException(); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir if ( _arguments.getLength() == 1 ) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir Reference< XFormController > xController; 183*cdf0e10cSrcweir Reference< XForm > xForm; 184*cdf0e10cSrcweir if ( _arguments[0] >>= xController ) 185*cdf0e10cSrcweir createWithFormController( xController ); 186*cdf0e10cSrcweir else if ( _arguments[0] >>= xForm ) 187*cdf0e10cSrcweir createWithForm( xForm ); 188*cdf0e10cSrcweir else 189*cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); 190*cdf0e10cSrcweir return; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir //-------------------------------------------------------------------- 197*cdf0e10cSrcweir ::rtl::OUString SAL_CALL FormOperations::getImplementationName( ) throw (RuntimeException) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir return getImplementationName_Static(); 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir //-------------------------------------------------------------------- 203*cdf0e10cSrcweir ::sal_Bool SAL_CALL FormOperations::supportsService( const ::rtl::OUString& _ServiceName ) throw (RuntimeException) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupportedServiceNames( getSupportedServiceNames() ); 206*cdf0e10cSrcweir const ::rtl::OUString* pBegin = aSupportedServiceNames.getConstArray(); 207*cdf0e10cSrcweir const ::rtl::OUString* pEnd = aSupportedServiceNames.getConstArray() + aSupportedServiceNames.getLength(); 208*cdf0e10cSrcweir return ::std::find( pBegin, pEnd, _ServiceName ) != pEnd; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir //-------------------------------------------------------------------- 212*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL FormOperations::getSupportedServiceNames( ) throw (RuntimeException) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir return getSupportedServiceNames_Static(); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir //-------------------------------------------------------------------- 218*cdf0e10cSrcweir Reference< XRowSet > SAL_CALL FormOperations::getCursor() throw (RuntimeException) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir MethodGuard aGuard( *this ); 221*cdf0e10cSrcweir return m_xCursor; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir //-------------------------------------------------------------------- 225*cdf0e10cSrcweir Reference< XResultSetUpdate > SAL_CALL FormOperations::getUpdateCursor() throw (RuntimeException) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir MethodGuard aGuard( *this ); 228*cdf0e10cSrcweir return m_xUpdateCursor; 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir //-------------------------------------------------------------------- 232*cdf0e10cSrcweir Reference< XFormController > SAL_CALL FormOperations::getController() throw (RuntimeException) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir MethodGuard aGuard( *this ); 235*cdf0e10cSrcweir return m_xController; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir //-------------------------------------------------------------------- 239*cdf0e10cSrcweir Reference< XFeatureInvalidation > SAL_CALL FormOperations::getFeatureInvalidation() throw (RuntimeException) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir MethodGuard aGuard( *this ); 242*cdf0e10cSrcweir return m_xFeatureInvalidation; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir //-------------------------------------------------------------------- 246*cdf0e10cSrcweir void SAL_CALL FormOperations::setFeatureInvalidation( const Reference< XFeatureInvalidation > & _rxFeatureInvalidation ) throw (RuntimeException) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir MethodGuard aGuard( *this ); 249*cdf0e10cSrcweir m_xFeatureInvalidation = _rxFeatureInvalidation; 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir //-------------------------------------------------------------------- 253*cdf0e10cSrcweir FeatureState SAL_CALL FormOperations::getState( ::sal_Int16 _nFeature ) throw (RuntimeException) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir MethodGuard aGuard( *this ); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir FeatureState aState; 258*cdf0e10cSrcweir aState.Enabled = sal_False; 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir try 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir // some checks for basic pre-requisites 263*cdf0e10cSrcweir if ( !m_xLoadableForm.is() 264*cdf0e10cSrcweir || !m_xLoadableForm->isLoaded() 265*cdf0e10cSrcweir || !m_xCursorProperties.is() 266*cdf0e10cSrcweir ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir return aState; 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir switch ( _nFeature ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir case FormFeature::MoveToFirst: 274*cdf0e10cSrcweir case FormFeature::MoveToPrevious: 275*cdf0e10cSrcweir aState.Enabled = impl_canMoveLeft_throw( ); 276*cdf0e10cSrcweir break; 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir case FormFeature::MoveToNext: 279*cdf0e10cSrcweir aState.Enabled = impl_canMoveRight_throw(); 280*cdf0e10cSrcweir break; 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir case FormFeature::MoveToLast: 283*cdf0e10cSrcweir aState.Enabled = impl_getRowCount_throw() && ( !m_xCursor->isLast() || impl_isInsertionRow_throw() ); 284*cdf0e10cSrcweir break; 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir case FormFeature::DeleteRecord: 287*cdf0e10cSrcweir // already deleted ? 288*cdf0e10cSrcweir if ( m_xCursor->rowDeleted() ) 289*cdf0e10cSrcweir aState.Enabled = sal_False; 290*cdf0e10cSrcweir else 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir // allowed to delete the row ? 293*cdf0e10cSrcweir aState.Enabled = !impl_isInsertionRow_throw() && ::dbtools::canDelete( m_xCursorProperties ); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir break; 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir case FormFeature::MoveToInsertRow: 298*cdf0e10cSrcweir // if we are inserting we can move to the next row if the current record or control is modified 299*cdf0e10cSrcweir aState.Enabled = impl_isInsertionRow_throw() 300*cdf0e10cSrcweir ? impl_isModifiedRow_throw() || m_bActiveControlModified 301*cdf0e10cSrcweir : ::dbtools::canInsert( m_xCursorProperties ); 302*cdf0e10cSrcweir break; 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir case FormFeature::ReloadForm: 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir // there must be an active connection 307*cdf0e10cSrcweir Reference< XRowSet > xCursorRowSet( m_xCursor, UNO_QUERY ); 308*cdf0e10cSrcweir aState.Enabled = ::dbtools::getConnection( xCursorRowSet ).is(); 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir // and an active command 311*cdf0e10cSrcweir ::rtl::OUString sActiveCommand; 312*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_ACTIVECOMMAND ) >>= sActiveCommand; 313*cdf0e10cSrcweir aState.Enabled &= sActiveCommand.getLength() > 0; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir break; 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir case FormFeature::RefreshCurrentControl: 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir Reference< XRefreshable > xControlModelRefresh( impl_getCurrentControlModel_throw(), UNO_QUERY ); 320*cdf0e10cSrcweir aState.Enabled = xControlModelRefresh.is(); 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir break; 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir case FormFeature::SaveRecordChanges: 325*cdf0e10cSrcweir case FormFeature::UndoRecordChanges: 326*cdf0e10cSrcweir aState.Enabled = impl_isModifiedRow_throw() || m_bActiveControlModified; 327*cdf0e10cSrcweir break; 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir case FormFeature::RemoveFilterAndSort: 330*cdf0e10cSrcweir if ( impl_isParseable_throw() && impl_hasFilterOrOrder_throw() ) 331*cdf0e10cSrcweir aState.Enabled = !impl_isInsertOnlyForm_throw(); 332*cdf0e10cSrcweir break; 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir case FormFeature::SortAscending: 335*cdf0e10cSrcweir case FormFeature::SortDescending: 336*cdf0e10cSrcweir case FormFeature::AutoFilter: 337*cdf0e10cSrcweir if ( m_xController.is() && impl_isParseable_throw() ) 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir sal_Bool bIsDeleted = m_xCursor->rowDeleted(); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir if ( !bIsDeleted && !impl_isInsertOnlyForm_throw() ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir Reference< XPropertySet > xBoundField = impl_getCurrentBoundField_nothrow( ); 344*cdf0e10cSrcweir if ( xBoundField.is() ) 345*cdf0e10cSrcweir xBoundField->getPropertyValue( PROPERTY_SEARCHABLE ) >>= aState.Enabled; 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir break; 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir case FormFeature::InteractiveSort: 351*cdf0e10cSrcweir case FormFeature::InteractiveFilter: 352*cdf0e10cSrcweir if ( impl_isParseable_throw() ) 353*cdf0e10cSrcweir aState.Enabled = !impl_isInsertOnlyForm_throw(); 354*cdf0e10cSrcweir break; 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir case FormFeature::ToggleApplyFilter: 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir ::rtl::OUString sFilter; 359*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_FILTER ) >>= sFilter; 360*cdf0e10cSrcweir if ( sFilter.getLength() ) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir aState.State = m_xCursorProperties->getPropertyValue( PROPERTY_APPLYFILTER ); 363*cdf0e10cSrcweir aState.Enabled = !impl_isInsertOnlyForm_throw(); 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir else 366*cdf0e10cSrcweir aState.State <<= (sal_Bool)sal_False; 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir break; 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir case FormFeature::MoveAbsolute: 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir sal_Int32 nPosition = m_xCursor->getRow(); 373*cdf0e10cSrcweir sal_Bool bIsNew = impl_isInsertionRow_throw(); 374*cdf0e10cSrcweir sal_Int32 nCount = impl_getRowCount_throw(); 375*cdf0e10cSrcweir sal_Bool bFinalCount = impl_isRowCountFinal_throw(); 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir if ( ( nPosition >= 0 ) || bIsNew ) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir if ( bFinalCount ) 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir // special case: there are no records at all, and we 382*cdf0e10cSrcweir // can't insert records -> disabled 383*cdf0e10cSrcweir if ( !nCount && !::dbtools::canInsert( m_xCursorProperties ) ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir aState.Enabled = sal_False; 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir else 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir if ( bIsNew ) 390*cdf0e10cSrcweir nPosition = ++nCount; 391*cdf0e10cSrcweir aState.State <<= (sal_Int32)nPosition; 392*cdf0e10cSrcweir aState.Enabled = sal_True; 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir else 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir aState.State <<= (sal_Int32)nPosition; 398*cdf0e10cSrcweir aState.Enabled = sal_True; 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir break; 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir case FormFeature::TotalRecords: 405*cdf0e10cSrcweir { 406*cdf0e10cSrcweir sal_Bool bIsNew = impl_isInsertionRow_throw(); 407*cdf0e10cSrcweir sal_Int32 nCount = impl_getRowCount_throw(); 408*cdf0e10cSrcweir sal_Bool bFinalCount = impl_isRowCountFinal_throw(); 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir if ( bIsNew ) 411*cdf0e10cSrcweir ++nCount; 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir ::rtl::OUString sValue = ::rtl::OUString::valueOf( sal_Int32( nCount ) ); 414*cdf0e10cSrcweir if ( !bFinalCount ) 415*cdf0e10cSrcweir sValue += ::rtl::OUString::createFromAscii( " *" ); 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir aState.State <<= sValue; 418*cdf0e10cSrcweir aState.Enabled = sal_True; 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir break; 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir default: 423*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormOperations::getState: unknown feature id!" ); 424*cdf0e10cSrcweir break; 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir catch( const Exception& ) 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormOperations::getState: caught an exception!" ); 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir return aState; 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir //-------------------------------------------------------------------- 436*cdf0e10cSrcweir ::sal_Bool SAL_CALL FormOperations::isEnabled( ::sal_Int16 _nFeature ) throw (RuntimeException) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir MethodGuard aGuard( *this ); 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir FeatureState aState( getState( _nFeature ) ); 441*cdf0e10cSrcweir return aState.Enabled; 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir //-------------------------------------------------------------------- 445*cdf0e10cSrcweir namespace 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir static bool lcl_needConfirmCommit( sal_Int32 _nFeature ) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir return ( ( _nFeature == FormFeature::ReloadForm ) 450*cdf0e10cSrcweir || ( _nFeature == FormFeature::RemoveFilterAndSort ) 451*cdf0e10cSrcweir || ( _nFeature == FormFeature::ToggleApplyFilter ) 452*cdf0e10cSrcweir || ( _nFeature == FormFeature::SortAscending ) 453*cdf0e10cSrcweir || ( _nFeature == FormFeature::SortDescending ) 454*cdf0e10cSrcweir || ( _nFeature == FormFeature::AutoFilter ) 455*cdf0e10cSrcweir || ( _nFeature == FormFeature::InteractiveSort ) 456*cdf0e10cSrcweir || ( _nFeature == FormFeature::InteractiveFilter ) 457*cdf0e10cSrcweir ); 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir static bool lcl_requiresArguments( sal_Int32 _nFeature ) 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir return ( _nFeature == FormFeature::MoveAbsolute ); 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir static bool lcl_isExecutableFeature( sal_Int32 _nFeature ) 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir return ( _nFeature != FormFeature::TotalRecords ); 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir //-------------------------------------------------------------------- 470*cdf0e10cSrcweir void SAL_CALL FormOperations::execute( ::sal_Int16 _nFeature ) throw (RuntimeException, IllegalArgumentException, SQLException, WrappedTargetException) 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 473*cdf0e10cSrcweir MethodGuard aGuard( *this ); 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir if ( ( _nFeature != FormFeature::DeleteRecord ) && ( _nFeature != FormFeature::UndoRecordChanges ) ) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir // if we have a controller, commit the current control 478*cdf0e10cSrcweir if ( m_xController.is() ) 479*cdf0e10cSrcweir if ( !impl_commitCurrentControl_throw() ) 480*cdf0e10cSrcweir return; 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir // commit the current record 483*cdf0e10cSrcweir bool bCommitCurrentRecord = true; 484*cdf0e10cSrcweir // (but before, let the user confirm if necessary) 485*cdf0e10cSrcweir if ( impl_isModifiedRow_throw() ) 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir if ( lcl_needConfirmCommit( _nFeature ) ) 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir // TODO: shouldn't this be done with an interaction handler? 490*cdf0e10cSrcweir QueryBox aQuery( NULL, WB_YES_NO_CANCEL | WB_DEF_YES, FRM_RES_STRING( RID_STR_QUERY_SAVE_MODIFIED_ROW ) ); 491*cdf0e10cSrcweir switch ( aQuery.Execute() ) 492*cdf0e10cSrcweir { 493*cdf0e10cSrcweir case RET_NO: bCommitCurrentRecord = false; break; 494*cdf0e10cSrcweir case RET_CANCEL: return; 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir if ( bCommitCurrentRecord && !impl_commitCurrentRecord_throw() ) 500*cdf0e10cSrcweir return; 501*cdf0e10cSrcweir } 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir try 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir switch ( _nFeature ) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir case FormFeature::MoveToFirst: 508*cdf0e10cSrcweir m_xCursor->first(); 509*cdf0e10cSrcweir break; 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir case FormFeature::MoveToNext: 512*cdf0e10cSrcweir impl_moveRight_throw( ); 513*cdf0e10cSrcweir break; 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir case FormFeature::MoveToPrevious: 516*cdf0e10cSrcweir impl_moveLeft_throw( ); 517*cdf0e10cSrcweir break; 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir case FormFeature::MoveToLast: 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir /* 522*cdf0e10cSrcweir // TODO: re-implement this ..... 523*cdf0e10cSrcweir // run in an own thread if ... 524*cdf0e10cSrcweir // ... the data source is thread safe ... 525*cdf0e10cSrcweir sal_Bool bAllowOwnThread = sal_False; 526*cdf0e10cSrcweir if ( ::comphelper::hasProperty( PROPERTY_THREADSAFE, m_xCursorProperties ) ) 527*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_THREADSAFE ) >>= bAllowOwnThread; 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir // ... the record count is unknown 530*cdf0e10cSrcweir sal_Bool bNeedOwnThread sal_False; 531*cdf0e10cSrcweir if ( ::comphelper::hasProperty( PROPERTY_ROWCOUNTFINAL, m_xCursorProperties ) ) 532*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_ROWCOUNTFINAL ) >>= bNeedOwnThread; 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir if ( bNeedOwnThread && bAllowOwnThread ) 535*cdf0e10cSrcweir ; 536*cdf0e10cSrcweir else 537*cdf0e10cSrcweir */ 538*cdf0e10cSrcweir m_xCursor->last(); 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir break; 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir case FormFeature::ReloadForm: 543*cdf0e10cSrcweir if ( m_xLoadableForm.is() ) 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir WaitObject aWO( NULL ); 546*cdf0e10cSrcweir m_xLoadableForm->reload(); 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir // refresh all controls in the form (and sub forms) which can be refreshed 549*cdf0e10cSrcweir // #i90914# / 2008-07-02 / frank.schoenheit@sun.com 550*cdf0e10cSrcweir ::comphelper::IndexAccessIterator aIter( m_xLoadableForm ); 551*cdf0e10cSrcweir Reference< XInterface > xElement( aIter.Next() ); 552*cdf0e10cSrcweir while ( xElement.is() ) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir Reference< XRefreshable > xRefresh( xElement, UNO_QUERY ); 555*cdf0e10cSrcweir if ( xRefresh.is() ) 556*cdf0e10cSrcweir xRefresh->refresh(); 557*cdf0e10cSrcweir xElement = aIter.Next(); 558*cdf0e10cSrcweir } 559*cdf0e10cSrcweir } 560*cdf0e10cSrcweir break; 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir case FormFeature::RefreshCurrentControl: 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir Reference< XRefreshable > xControlModelRefresh( impl_getCurrentControlModel_throw(), UNO_QUERY ); 565*cdf0e10cSrcweir OSL_ENSURE( xControlModelRefresh.is(), "FormOperations::execute: how did you reach this?" ); 566*cdf0e10cSrcweir if ( xControlModelRefresh.is() ) 567*cdf0e10cSrcweir xControlModelRefresh->refresh(); 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir break; 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir case FormFeature::DeleteRecord: 572*cdf0e10cSrcweir { 573*cdf0e10cSrcweir sal_uInt32 nCount = impl_getRowCount_throw(); 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir // next position 576*cdf0e10cSrcweir sal_Bool bLeft = m_xCursor->isLast() && ( nCount > 1 ); 577*cdf0e10cSrcweir sal_Bool bRight= !m_xCursor->isLast(); 578*cdf0e10cSrcweir sal_Bool bSuccess = sal_False; 579*cdf0e10cSrcweir try 580*cdf0e10cSrcweir { 581*cdf0e10cSrcweir // ask for confirmation 582*cdf0e10cSrcweir Reference< XConfirmDeleteListener > xConfirmDelete( m_xController, UNO_QUERY ); 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir if ( xConfirmDelete.is() ) 585*cdf0e10cSrcweir { 586*cdf0e10cSrcweir RowChangeEvent aEvent; 587*cdf0e10cSrcweir aEvent.Source = Reference< XInterface >( m_xCursor, UNO_QUERY ); 588*cdf0e10cSrcweir aEvent.Action = RowChangeAction::DELETE; 589*cdf0e10cSrcweir aEvent.Rows = 1; 590*cdf0e10cSrcweir bSuccess = xConfirmDelete->confirmDelete( aEvent ); 591*cdf0e10cSrcweir } 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir // delete it 594*cdf0e10cSrcweir if ( bSuccess ) 595*cdf0e10cSrcweir m_xUpdateCursor->deleteRow(); 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir catch( const Exception& ) 598*cdf0e10cSrcweir { 599*cdf0e10cSrcweir bSuccess = sal_False; 600*cdf0e10cSrcweir } 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir if ( bSuccess ) 603*cdf0e10cSrcweir { 604*cdf0e10cSrcweir if ( bLeft || bRight ) 605*cdf0e10cSrcweir m_xCursor->relative( bRight ? 1 : -1 ); 606*cdf0e10cSrcweir else 607*cdf0e10cSrcweir { 608*cdf0e10cSrcweir sal_Bool bCanInsert = ::dbtools::canInsert( m_xCursorProperties ); 609*cdf0e10cSrcweir // is it possible to insert another record? 610*cdf0e10cSrcweir if ( bCanInsert ) 611*cdf0e10cSrcweir m_xUpdateCursor->moveToInsertRow(); 612*cdf0e10cSrcweir else 613*cdf0e10cSrcweir // move record to update stati 614*cdf0e10cSrcweir m_xCursor->first(); 615*cdf0e10cSrcweir } 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir break; 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir case FormFeature::SaveRecordChanges: 621*cdf0e10cSrcweir case FormFeature::UndoRecordChanges: 622*cdf0e10cSrcweir { 623*cdf0e10cSrcweir sal_Bool bInserting = impl_isInsertionRow_throw(); 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir if ( FormFeature::UndoRecordChanges == _nFeature ) 626*cdf0e10cSrcweir { 627*cdf0e10cSrcweir if ( !bInserting ) 628*cdf0e10cSrcweir m_xUpdateCursor->cancelRowUpdates(); 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir // reset all controls for this form 631*cdf0e10cSrcweir impl_resetAllControls_nothrow( ); 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir if ( bInserting ) // back to insertion mode for this form 634*cdf0e10cSrcweir m_xUpdateCursor->moveToInsertRow(); 635*cdf0e10cSrcweir } 636*cdf0e10cSrcweir else 637*cdf0e10cSrcweir { 638*cdf0e10cSrcweir if ( bInserting ) 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir m_xUpdateCursor->insertRow(); 641*cdf0e10cSrcweir m_xCursor->last(); 642*cdf0e10cSrcweir } 643*cdf0e10cSrcweir else 644*cdf0e10cSrcweir m_xUpdateCursor->updateRow(); 645*cdf0e10cSrcweir } 646*cdf0e10cSrcweir } 647*cdf0e10cSrcweir break; 648*cdf0e10cSrcweir 649*cdf0e10cSrcweir case FormFeature::MoveToInsertRow: 650*cdf0e10cSrcweir // move to the last row before moving to the insert row 651*cdf0e10cSrcweir // 21.01.2002 - 96480 - fs@openoffice.org 652*cdf0e10cSrcweir m_xCursor->last(); 653*cdf0e10cSrcweir m_xUpdateCursor->moveToInsertRow(); 654*cdf0e10cSrcweir break; 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir case FormFeature::RemoveFilterAndSort: 657*cdf0e10cSrcweir { 658*cdf0e10cSrcweir // simultaneously reset Filter and Order property 659*cdf0e10cSrcweir Reference< XMultiPropertySet > xProperties( m_xCursorProperties, UNO_QUERY ); 660*cdf0e10cSrcweir OSL_ENSURE( xProperties.is(), "FormOperations::execute: no multi property access!" ); 661*cdf0e10cSrcweir if ( xProperties.is() ) 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames( 2 ); 664*cdf0e10cSrcweir aNames[0] = PROPERTY_FILTER; 665*cdf0e10cSrcweir aNames[1] = PROPERTY_SORT; 666*cdf0e10cSrcweir 667*cdf0e10cSrcweir Sequence< Any> aValues( 2 ); 668*cdf0e10cSrcweir aValues[0] <<= ::rtl::OUString(); 669*cdf0e10cSrcweir aValues[1] <<= ::rtl::OUString(); 670*cdf0e10cSrcweir 671*cdf0e10cSrcweir WaitObject aWO( NULL ); 672*cdf0e10cSrcweir xProperties->setPropertyValues( aNames, aValues ); 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir if ( m_xLoadableForm.is() ) 675*cdf0e10cSrcweir m_xLoadableForm->reload(); 676*cdf0e10cSrcweir } 677*cdf0e10cSrcweir } 678*cdf0e10cSrcweir break; 679*cdf0e10cSrcweir 680*cdf0e10cSrcweir case FormFeature::ToggleApplyFilter: 681*cdf0e10cSrcweir if ( impl_commitCurrentControl_throw() && impl_commitCurrentRecord_throw() ) 682*cdf0e10cSrcweir { 683*cdf0e10cSrcweir // simply toggle the value 684*cdf0e10cSrcweir sal_Bool bApplied = sal_False; 685*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_APPLYFILTER ) >>= bApplied; 686*cdf0e10cSrcweir m_xCursorProperties->setPropertyValue( PROPERTY_APPLYFILTER, makeAny( (sal_Bool)!bApplied ) ); 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir // and reload 689*cdf0e10cSrcweir WaitObject aWO( NULL ); 690*cdf0e10cSrcweir m_xLoadableForm->reload(); 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir break; 693*cdf0e10cSrcweir 694*cdf0e10cSrcweir case FormFeature::SortAscending: 695*cdf0e10cSrcweir impl_executeAutoSort_throw( true ); 696*cdf0e10cSrcweir break; 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir case FormFeature::SortDescending: 699*cdf0e10cSrcweir impl_executeAutoSort_throw( false ); 700*cdf0e10cSrcweir break; 701*cdf0e10cSrcweir 702*cdf0e10cSrcweir case FormFeature::AutoFilter: 703*cdf0e10cSrcweir impl_executeAutoFilter_throw(); 704*cdf0e10cSrcweir break; 705*cdf0e10cSrcweir 706*cdf0e10cSrcweir case FormFeature::InteractiveSort: 707*cdf0e10cSrcweir impl_executeFilterOrSort_throw( false ); 708*cdf0e10cSrcweir break; 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir case FormFeature::InteractiveFilter: 711*cdf0e10cSrcweir impl_executeFilterOrSort_throw( true ); 712*cdf0e10cSrcweir break; 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir default: 715*cdf0e10cSrcweir { 716*cdf0e10cSrcweir sal_uInt16 nErrorResourceId = RID_STR_FEATURE_UNKNOWN; 717*cdf0e10cSrcweir if ( lcl_requiresArguments( _nFeature ) ) 718*cdf0e10cSrcweir nErrorResourceId = RID_STR_FEATURE_REQUIRES_PARAMETERS; 719*cdf0e10cSrcweir else if ( !lcl_isExecutableFeature( _nFeature ) ) 720*cdf0e10cSrcweir nErrorResourceId = RID_STR_FEATURE_NOT_EXECUTABLE; 721*cdf0e10cSrcweir throw IllegalArgumentException( FRM_RES_STRING( nErrorResourceId ), *this, 1 ); 722*cdf0e10cSrcweir } 723*cdf0e10cSrcweir } // switch 724*cdf0e10cSrcweir } 725*cdf0e10cSrcweir catch( const RuntimeException& ) { throw; } 726*cdf0e10cSrcweir catch( const SQLException& ) { throw; } 727*cdf0e10cSrcweir catch( const IllegalArgumentException& ) { throw; } 728*cdf0e10cSrcweir catch( const Exception& ) 729*cdf0e10cSrcweir { 730*cdf0e10cSrcweir throw WrappedTargetException( ::rtl::OUString(), *const_cast< FormOperations* >( this ), ::cppu::getCaughtException() ); 731*cdf0e10cSrcweir } 732*cdf0e10cSrcweir 733*cdf0e10cSrcweir impl_invalidateAllSupportedFeatures_nothrow( aGuard ); 734*cdf0e10cSrcweir } 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir //-------------------------------------------------------------------- 737*cdf0e10cSrcweir void SAL_CALL FormOperations::executeWithArguments( ::sal_Int16 _nFeature, const Sequence< NamedValue >& _rArguments ) throw (RuntimeException, IllegalArgumentException, SQLException, WrappedTargetException) 738*cdf0e10cSrcweir { 739*cdf0e10cSrcweir if ( !lcl_requiresArguments( _nFeature ) ) 740*cdf0e10cSrcweir { 741*cdf0e10cSrcweir execute( _nFeature ); 742*cdf0e10cSrcweir return; 743*cdf0e10cSrcweir } 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 746*cdf0e10cSrcweir MethodGuard aGuard( *this ); 747*cdf0e10cSrcweir 748*cdf0e10cSrcweir // at the moment we have only one feature which supports execution parameters 749*cdf0e10cSrcweir if ( !lcl_isExecutableFeature( _nFeature ) ) 750*cdf0e10cSrcweir throw IllegalArgumentException( FRM_RES_STRING( RID_STR_FEATURE_NOT_EXECUTABLE ), *this, 1 ); 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir switch ( _nFeature ) 753*cdf0e10cSrcweir { 754*cdf0e10cSrcweir case FormFeature::MoveAbsolute: 755*cdf0e10cSrcweir { 756*cdf0e10cSrcweir sal_Int32 nPosition = -1; 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir ::comphelper::NamedValueCollection aArguments( _rArguments ); 759*cdf0e10cSrcweir aArguments.get_ensureType( "Position", nPosition ); 760*cdf0e10cSrcweir 761*cdf0e10cSrcweir if ( nPosition < 1 ) 762*cdf0e10cSrcweir nPosition = 1; 763*cdf0e10cSrcweir 764*cdf0e10cSrcweir try 765*cdf0e10cSrcweir { 766*cdf0e10cSrcweir // commit before doing anything else 767*cdf0e10cSrcweir if ( m_xController.is() && !impl_commitCurrentControl_throw() ) 768*cdf0e10cSrcweir return; 769*cdf0e10cSrcweir if ( !impl_commitCurrentRecord_throw() ) 770*cdf0e10cSrcweir return; 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir sal_Int32 nCount = impl_getRowCount_throw(); 773*cdf0e10cSrcweir sal_Bool bFinalCount = impl_isRowCountFinal_throw(); 774*cdf0e10cSrcweir 775*cdf0e10cSrcweir if ( bFinalCount && ( (sal_Int32)nPosition > nCount ) ) 776*cdf0e10cSrcweir nPosition = nCount; 777*cdf0e10cSrcweir 778*cdf0e10cSrcweir m_xCursor->absolute( nPosition ); 779*cdf0e10cSrcweir } 780*cdf0e10cSrcweir catch( const RuntimeException& ) { throw; } 781*cdf0e10cSrcweir catch( const SQLException& ) { throw; } 782*cdf0e10cSrcweir catch( const Exception& ) 783*cdf0e10cSrcweir { 784*cdf0e10cSrcweir throw WrappedTargetException( ::rtl::OUString(), *this, ::cppu::getCaughtException() ); 785*cdf0e10cSrcweir } 786*cdf0e10cSrcweir } 787*cdf0e10cSrcweir break; 788*cdf0e10cSrcweir default: 789*cdf0e10cSrcweir throw IllegalArgumentException( FRM_RES_STRING( RID_STR_FEATURE_UNKNOWN ), *this, 1 ); 790*cdf0e10cSrcweir } // switch 791*cdf0e10cSrcweir } 792*cdf0e10cSrcweir 793*cdf0e10cSrcweir //-------------------------------------------------------------------- 794*cdf0e10cSrcweir ::sal_Bool SAL_CALL FormOperations::commitCurrentRecord( ::sal_Bool& _out_rRecordInserted ) throw (RuntimeException, SQLException) 795*cdf0e10cSrcweir { 796*cdf0e10cSrcweir MethodGuard aGuard( *this ); 797*cdf0e10cSrcweir _out_rRecordInserted = sal_False; 798*cdf0e10cSrcweir 799*cdf0e10cSrcweir return impl_commitCurrentRecord_throw( &_out_rRecordInserted ); 800*cdf0e10cSrcweir } 801*cdf0e10cSrcweir 802*cdf0e10cSrcweir //-------------------------------------------------------------------- 803*cdf0e10cSrcweir bool FormOperations::impl_commitCurrentRecord_throw( ::sal_Bool* _pRecordInserted ) const 804*cdf0e10cSrcweir { 805*cdf0e10cSrcweir DBG_ASSERT( m_nMethodNestingLevel, "FormOperations::impl_commitCurrentRecord_throw: to be called within a MethodGuard'ed section only!" ); 806*cdf0e10cSrcweir 807*cdf0e10cSrcweir if ( !impl_hasCursor_nothrow() ) 808*cdf0e10cSrcweir return false; 809*cdf0e10cSrcweir 810*cdf0e10cSrcweir // nothing to do if the record is not modified 811*cdf0e10cSrcweir sal_Bool bResult = !impl_isModifiedRow_throw(); 812*cdf0e10cSrcweir if ( !bResult ) 813*cdf0e10cSrcweir { 814*cdf0e10cSrcweir // insert respectively update the row 815*cdf0e10cSrcweir if ( impl_isInsertionRow_throw() ) 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir m_xUpdateCursor->insertRow(); 818*cdf0e10cSrcweir if ( _pRecordInserted ) 819*cdf0e10cSrcweir *_pRecordInserted = sal_True; 820*cdf0e10cSrcweir } 821*cdf0e10cSrcweir else 822*cdf0e10cSrcweir m_xUpdateCursor->updateRow(); 823*cdf0e10cSrcweir bResult = true; 824*cdf0e10cSrcweir } 825*cdf0e10cSrcweir return bResult; 826*cdf0e10cSrcweir } 827*cdf0e10cSrcweir 828*cdf0e10cSrcweir //-------------------------------------------------------------------- 829*cdf0e10cSrcweir ::sal_Bool SAL_CALL FormOperations::commitCurrentControl() throw (RuntimeException, SQLException) 830*cdf0e10cSrcweir { 831*cdf0e10cSrcweir MethodGuard aGuard( *this ); 832*cdf0e10cSrcweir return impl_commitCurrentControl_throw(); 833*cdf0e10cSrcweir } 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir //-------------------------------------------------------------------- 836*cdf0e10cSrcweir bool FormOperations::impl_commitCurrentControl_throw() const 837*cdf0e10cSrcweir { 838*cdf0e10cSrcweir DBG_ASSERT( m_nMethodNestingLevel, "FormOperations::impl_commitCurrentRecord_throw: to be called within a MethodGuard'ed section only!" ); 839*cdf0e10cSrcweir OSL_PRECOND( m_xController.is(), "FormOperations::commitCurrentControl: no controller!" ); 840*cdf0e10cSrcweir if ( !m_xController.is() ) 841*cdf0e10cSrcweir return false; 842*cdf0e10cSrcweir 843*cdf0e10cSrcweir bool bSuccess = false; 844*cdf0e10cSrcweir try 845*cdf0e10cSrcweir { 846*cdf0e10cSrcweir Reference< XControl > xCurrentControl( m_xController->getCurrentControl() ); 847*cdf0e10cSrcweir 848*cdf0e10cSrcweir // check whether the control is locked 849*cdf0e10cSrcweir Reference< XBoundControl > xCheckLock( xCurrentControl, UNO_QUERY ); 850*cdf0e10cSrcweir sal_Bool bControlIsLocked = xCheckLock.is() && xCheckLock->getLock(); 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir // commit if necessary 853*cdf0e10cSrcweir bSuccess = true; 854*cdf0e10cSrcweir if ( xCurrentControl.is() && !bControlIsLocked ) 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir // both the control and it's model can be committable, so try both 857*cdf0e10cSrcweir Reference< XBoundComponent > xBound( xCurrentControl, UNO_QUERY ); 858*cdf0e10cSrcweir if ( !xBound.is() ) 859*cdf0e10cSrcweir xBound = xBound.query( xCurrentControl->getModel() ); 860*cdf0e10cSrcweir // and now really commit 861*cdf0e10cSrcweir if ( xBound.is() ) 862*cdf0e10cSrcweir bSuccess = xBound->commit(); 863*cdf0e10cSrcweir } 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir } 866*cdf0e10cSrcweir catch( const RuntimeException& ) { throw; } 867*cdf0e10cSrcweir catch( const SQLException& ) { throw; } 868*cdf0e10cSrcweir catch( const Exception& ) 869*cdf0e10cSrcweir { 870*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 871*cdf0e10cSrcweir bSuccess = false; 872*cdf0e10cSrcweir } 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir return bSuccess; 875*cdf0e10cSrcweir } 876*cdf0e10cSrcweir 877*cdf0e10cSrcweir //-------------------------------------------------------------------- 878*cdf0e10cSrcweir ::sal_Bool SAL_CALL FormOperations::isInsertionRow() throw (RuntimeException, WrappedTargetException) 879*cdf0e10cSrcweir { 880*cdf0e10cSrcweir sal_Bool bIs = sal_False; 881*cdf0e10cSrcweir try 882*cdf0e10cSrcweir { 883*cdf0e10cSrcweir bIs = impl_isInsertionRow_throw(); 884*cdf0e10cSrcweir } 885*cdf0e10cSrcweir catch( const RuntimeException& ) { throw; } 886*cdf0e10cSrcweir catch( const Exception& ) 887*cdf0e10cSrcweir { 888*cdf0e10cSrcweir throw WrappedTargetException( ::rtl::OUString(), *this, ::cppu::getCaughtException() ); 889*cdf0e10cSrcweir } 890*cdf0e10cSrcweir return bIs; 891*cdf0e10cSrcweir } 892*cdf0e10cSrcweir 893*cdf0e10cSrcweir //-------------------------------------------------------------------- 894*cdf0e10cSrcweir ::sal_Bool SAL_CALL FormOperations::isModifiedRow() throw (RuntimeException, WrappedTargetException) 895*cdf0e10cSrcweir { 896*cdf0e10cSrcweir sal_Bool bIs = sal_False; 897*cdf0e10cSrcweir try 898*cdf0e10cSrcweir { 899*cdf0e10cSrcweir bIs = impl_isModifiedRow_throw(); 900*cdf0e10cSrcweir } 901*cdf0e10cSrcweir catch( const RuntimeException& ) { throw; } 902*cdf0e10cSrcweir catch( const Exception& ) 903*cdf0e10cSrcweir { 904*cdf0e10cSrcweir throw WrappedTargetException( ::rtl::OUString(), *this, ::cppu::getCaughtException() ); 905*cdf0e10cSrcweir } 906*cdf0e10cSrcweir return bIs; 907*cdf0e10cSrcweir } 908*cdf0e10cSrcweir 909*cdf0e10cSrcweir //-------------------------------------------------------------------- 910*cdf0e10cSrcweir void SAL_CALL FormOperations::cursorMoved( const EventObject& /*_Event*/ ) throw (RuntimeException) 911*cdf0e10cSrcweir { 912*cdf0e10cSrcweir MethodGuard aGuard( *this ); 913*cdf0e10cSrcweir m_bActiveControlModified = sal_False; 914*cdf0e10cSrcweir 915*cdf0e10cSrcweir impl_invalidateAllSupportedFeatures_nothrow( aGuard ); 916*cdf0e10cSrcweir } 917*cdf0e10cSrcweir 918*cdf0e10cSrcweir //-------------------------------------------------------------------- 919*cdf0e10cSrcweir void SAL_CALL FormOperations::rowChanged( const EventObject& /*_Event*/ ) throw (RuntimeException) 920*cdf0e10cSrcweir { 921*cdf0e10cSrcweir // not interested in 922*cdf0e10cSrcweir } 923*cdf0e10cSrcweir 924*cdf0e10cSrcweir //-------------------------------------------------------------------- 925*cdf0e10cSrcweir void SAL_CALL FormOperations::rowSetChanged( const EventObject& /*_Event*/ ) throw (RuntimeException) 926*cdf0e10cSrcweir { 927*cdf0e10cSrcweir // not interested in 928*cdf0e10cSrcweir } 929*cdf0e10cSrcweir 930*cdf0e10cSrcweir //-------------------------------------------------------------------- 931*cdf0e10cSrcweir void SAL_CALL FormOperations::modified( const EventObject& /*_Source*/ ) throw( RuntimeException ) 932*cdf0e10cSrcweir { 933*cdf0e10cSrcweir MethodGuard aGuard( *this ); 934*cdf0e10cSrcweir 935*cdf0e10cSrcweir OSL_ENSURE( m_xCursor.is(), "FormOperations::modified: already disposed!" ); 936*cdf0e10cSrcweir if ( !m_bActiveControlModified ) 937*cdf0e10cSrcweir { 938*cdf0e10cSrcweir m_bActiveControlModified = sal_True; 939*cdf0e10cSrcweir impl_invalidateModifyDependentFeatures_nothrow( aGuard ); 940*cdf0e10cSrcweir } 941*cdf0e10cSrcweir } 942*cdf0e10cSrcweir 943*cdf0e10cSrcweir //-------------------------------------------------------------------- 944*cdf0e10cSrcweir void SAL_CALL FormOperations::propertyChange( const PropertyChangeEvent& _rEvent ) throw (RuntimeException) 945*cdf0e10cSrcweir { 946*cdf0e10cSrcweir MethodGuard aGuard( *this ); 947*cdf0e10cSrcweir 948*cdf0e10cSrcweir if ( m_xCursor.is() && ( m_xCursor == _rEvent.Source ) ) 949*cdf0e10cSrcweir { 950*cdf0e10cSrcweir sal_Bool bIs = sal_False; 951*cdf0e10cSrcweir if ( ( _rEvent.PropertyName == PROPERTY_ISMODIFIED ) 952*cdf0e10cSrcweir || ( _rEvent.PropertyName == PROPERTY_ISNEW ) 953*cdf0e10cSrcweir ) 954*cdf0e10cSrcweir { 955*cdf0e10cSrcweir if ( ( _rEvent.NewValue >>= bIs ) && !bIs ) 956*cdf0e10cSrcweir m_bActiveControlModified = sal_False; 957*cdf0e10cSrcweir } 958*cdf0e10cSrcweir impl_invalidateAllSupportedFeatures_nothrow( aGuard ); 959*cdf0e10cSrcweir } 960*cdf0e10cSrcweir 961*cdf0e10cSrcweir if ( m_xParser.is() && ( m_xCursor == _rEvent.Source ) ) 962*cdf0e10cSrcweir { 963*cdf0e10cSrcweir try 964*cdf0e10cSrcweir { 965*cdf0e10cSrcweir ::rtl::OUString sNewValue; 966*cdf0e10cSrcweir _rEvent.NewValue >>= sNewValue; 967*cdf0e10cSrcweir if ( _rEvent.PropertyName == PROPERTY_ACTIVECOMMAND ) 968*cdf0e10cSrcweir { 969*cdf0e10cSrcweir m_xParser->setElementaryQuery( sNewValue ); 970*cdf0e10cSrcweir } 971*cdf0e10cSrcweir else if ( _rEvent.PropertyName == PROPERTY_FILTER ) 972*cdf0e10cSrcweir { 973*cdf0e10cSrcweir if ( m_xParser->getFilter() != sNewValue ) 974*cdf0e10cSrcweir m_xParser->setFilter( sNewValue ); 975*cdf0e10cSrcweir } 976*cdf0e10cSrcweir else if ( _rEvent.PropertyName == PROPERTY_SORT ) 977*cdf0e10cSrcweir { 978*cdf0e10cSrcweir _rEvent.NewValue >>= sNewValue; 979*cdf0e10cSrcweir if ( m_xParser->getOrder() != sNewValue ) 980*cdf0e10cSrcweir m_xParser->setOrder( sNewValue ); 981*cdf0e10cSrcweir } 982*cdf0e10cSrcweir } 983*cdf0e10cSrcweir catch( Exception& ) 984*cdf0e10cSrcweir { 985*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormOperations::propertyChange: caught an exception while updating the parser!" ); 986*cdf0e10cSrcweir } 987*cdf0e10cSrcweir impl_invalidateAllSupportedFeatures_nothrow( aGuard ); 988*cdf0e10cSrcweir } 989*cdf0e10cSrcweir } 990*cdf0e10cSrcweir 991*cdf0e10cSrcweir //-------------------------------------------------------------------- 992*cdf0e10cSrcweir void SAL_CALL FormOperations::disposing( const EventObject& /*_Source*/ ) throw (RuntimeException) 993*cdf0e10cSrcweir { 994*cdf0e10cSrcweir // TODO: should we react on this? Or is this the responsibility of our owner to dispose us? 995*cdf0e10cSrcweir } 996*cdf0e10cSrcweir 997*cdf0e10cSrcweir //-------------------------------------------------------------------- 998*cdf0e10cSrcweir void SAL_CALL FormOperations::disposing() 999*cdf0e10cSrcweir { 1000*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1001*cdf0e10cSrcweir 1002*cdf0e10cSrcweir impl_disposeParser_nothrow(); 1003*cdf0e10cSrcweir 1004*cdf0e10cSrcweir try 1005*cdf0e10cSrcweir { 1006*cdf0e10cSrcweir // revoke various listeners 1007*cdf0e10cSrcweir if ( m_xCursor.is() ) 1008*cdf0e10cSrcweir m_xCursor->removeRowSetListener( this ); 1009*cdf0e10cSrcweir 1010*cdf0e10cSrcweir if ( m_xCursorProperties.is() ) 1011*cdf0e10cSrcweir { 1012*cdf0e10cSrcweir m_xCursorProperties->removePropertyChangeListener( PROPERTY_ISMODIFIED,this ); 1013*cdf0e10cSrcweir m_xCursorProperties->removePropertyChangeListener( PROPERTY_ISNEW, this ); 1014*cdf0e10cSrcweir } 1015*cdf0e10cSrcweir 1016*cdf0e10cSrcweir Reference< XModifyBroadcaster > xBroadcaster( m_xController, UNO_QUERY ); 1017*cdf0e10cSrcweir if ( xBroadcaster.is() ) 1018*cdf0e10cSrcweir xBroadcaster->removeModifyListener( this ); 1019*cdf0e10cSrcweir } 1020*cdf0e10cSrcweir catch( const Exception& ) 1021*cdf0e10cSrcweir { 1022*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1023*cdf0e10cSrcweir } 1024*cdf0e10cSrcweir 1025*cdf0e10cSrcweir m_xController.clear(); 1026*cdf0e10cSrcweir m_xCursor.clear(); 1027*cdf0e10cSrcweir m_xUpdateCursor.clear(); 1028*cdf0e10cSrcweir m_xCursorProperties.clear(); 1029*cdf0e10cSrcweir m_xLoadableForm.clear(); 1030*cdf0e10cSrcweir m_xFeatureInvalidation.clear(); 1031*cdf0e10cSrcweir 1032*cdf0e10cSrcweir m_bActiveControlModified = true; 1033*cdf0e10cSrcweir } 1034*cdf0e10cSrcweir 1035*cdf0e10cSrcweir //-------------------------------------------------------------------- 1036*cdf0e10cSrcweir void FormOperations::impl_checkDisposed_throw() const 1037*cdf0e10cSrcweir { 1038*cdf0e10cSrcweir if ( impl_isDisposed_nothrow() ) 1039*cdf0e10cSrcweir throw DisposedException( ::rtl::OUString(), *const_cast< FormOperations* >( this ) ); 1040*cdf0e10cSrcweir } 1041*cdf0e10cSrcweir 1042*cdf0e10cSrcweir //-------------------------------------------------------------------- 1043*cdf0e10cSrcweir void FormOperations::impl_initFromController_throw() 1044*cdf0e10cSrcweir { 1045*cdf0e10cSrcweir OSL_PRECOND( m_xController.is(), "FormOperations::impl_initFromController_throw: invalid controller!" ); 1046*cdf0e10cSrcweir m_xCursor = m_xCursor.query( m_xController->getModel() ); 1047*cdf0e10cSrcweir if ( !m_xCursor.is() ) 1048*cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 1049*cdf0e10cSrcweir 1050*cdf0e10cSrcweir impl_initFromForm_throw(); 1051*cdf0e10cSrcweir 1052*cdf0e10cSrcweir Reference< XModifyBroadcaster > xBroadcaster( m_xController, UNO_QUERY ); 1053*cdf0e10cSrcweir if ( xBroadcaster.is() ) 1054*cdf0e10cSrcweir xBroadcaster->addModifyListener( this ); 1055*cdf0e10cSrcweir } 1056*cdf0e10cSrcweir 1057*cdf0e10cSrcweir //-------------------------------------------------------------------- 1058*cdf0e10cSrcweir void FormOperations::impl_initFromForm_throw() 1059*cdf0e10cSrcweir { 1060*cdf0e10cSrcweir OSL_PRECOND( m_xCursor.is(), "FormOperations::impl_initFromForm_throw: invalid form!" ); 1061*cdf0e10cSrcweir m_xCursorProperties = m_xCursorProperties.query ( m_xCursor ); 1062*cdf0e10cSrcweir m_xUpdateCursor = m_xUpdateCursor.query ( m_xCursor ); 1063*cdf0e10cSrcweir m_xLoadableForm = m_xLoadableForm.query ( m_xCursor ); 1064*cdf0e10cSrcweir 1065*cdf0e10cSrcweir if ( !m_xCursor.is() || !m_xCursorProperties.is() || !m_xLoadableForm.is() ) 1066*cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 1067*cdf0e10cSrcweir 1068*cdf0e10cSrcweir m_xCursor->addRowSetListener( this ); 1069*cdf0e10cSrcweir m_xCursorProperties->addPropertyChangeListener( PROPERTY_ISMODIFIED,this ); 1070*cdf0e10cSrcweir m_xCursorProperties->addPropertyChangeListener( PROPERTY_ISNEW, this ); 1071*cdf0e10cSrcweir } 1072*cdf0e10cSrcweir 1073*cdf0e10cSrcweir //-------------------------------------------------------------------- 1074*cdf0e10cSrcweir void FormOperations::createWithFormController( const Reference< XFormController >& _rxController ) 1075*cdf0e10cSrcweir { 1076*cdf0e10cSrcweir m_xController = _rxController; 1077*cdf0e10cSrcweir if ( !m_xController.is() ) 1078*cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 1079*cdf0e10cSrcweir 1080*cdf0e10cSrcweir impl_initFromController_throw(); 1081*cdf0e10cSrcweir 1082*cdf0e10cSrcweir m_bConstructed = true; 1083*cdf0e10cSrcweir } 1084*cdf0e10cSrcweir 1085*cdf0e10cSrcweir //-------------------------------------------------------------------- 1086*cdf0e10cSrcweir void FormOperations::createWithForm( const Reference< XForm >& _rxForm ) 1087*cdf0e10cSrcweir { 1088*cdf0e10cSrcweir m_xCursor = m_xCursor.query( _rxForm ); 1089*cdf0e10cSrcweir if ( !m_xCursor.is() ) 1090*cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 1091*cdf0e10cSrcweir 1092*cdf0e10cSrcweir impl_initFromForm_throw(); 1093*cdf0e10cSrcweir 1094*cdf0e10cSrcweir m_bConstructed = true; 1095*cdf0e10cSrcweir } 1096*cdf0e10cSrcweir 1097*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1098*cdf0e10cSrcweir void FormOperations::impl_invalidateAllSupportedFeatures_nothrow( MethodGuard& _rClearForCallback ) const 1099*cdf0e10cSrcweir { 1100*cdf0e10cSrcweir if ( !m_xFeatureInvalidation.is() ) 1101*cdf0e10cSrcweir // nobody's interested in ... 1102*cdf0e10cSrcweir return; 1103*cdf0e10cSrcweir 1104*cdf0e10cSrcweir Reference< XFeatureInvalidation > xInvalidation = m_xFeatureInvalidation; 1105*cdf0e10cSrcweir _rClearForCallback.clear(); 1106*cdf0e10cSrcweir xInvalidation->invalidateAllFeatures(); 1107*cdf0e10cSrcweir } 1108*cdf0e10cSrcweir 1109*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1110*cdf0e10cSrcweir void FormOperations::impl_invalidateModifyDependentFeatures_nothrow( MethodGuard& _rClearForCallback ) const 1111*cdf0e10cSrcweir { 1112*cdf0e10cSrcweir if ( !m_xFeatureInvalidation.is() ) 1113*cdf0e10cSrcweir // nobody's interested in ... 1114*cdf0e10cSrcweir return; 1115*cdf0e10cSrcweir 1116*cdf0e10cSrcweir static Sequence< sal_Int16 > s_aModifyDependentFeatures; 1117*cdf0e10cSrcweir if ( s_aModifyDependentFeatures.getLength() == 0 ) 1118*cdf0e10cSrcweir { 1119*cdf0e10cSrcweir sal_Int16 pModifyDependentFeatures[] = 1120*cdf0e10cSrcweir { 1121*cdf0e10cSrcweir FormFeature::MoveToNext, 1122*cdf0e10cSrcweir FormFeature::MoveToInsertRow, 1123*cdf0e10cSrcweir FormFeature::SaveRecordChanges, 1124*cdf0e10cSrcweir FormFeature::UndoRecordChanges 1125*cdf0e10cSrcweir }; 1126*cdf0e10cSrcweir size_t nFeatureCount = sizeof( pModifyDependentFeatures ) / sizeof( pModifyDependentFeatures[ 0 ] ); 1127*cdf0e10cSrcweir s_aModifyDependentFeatures = Sequence< sal_Int16 >( pModifyDependentFeatures, nFeatureCount ); 1128*cdf0e10cSrcweir } 1129*cdf0e10cSrcweir 1130*cdf0e10cSrcweir Reference< XFeatureInvalidation > xInvalidation = m_xFeatureInvalidation; 1131*cdf0e10cSrcweir _rClearForCallback.clear(); 1132*cdf0e10cSrcweir 1133*cdf0e10cSrcweir xInvalidation->invalidateFeatures( s_aModifyDependentFeatures ); 1134*cdf0e10cSrcweir } 1135*cdf0e10cSrcweir 1136*cdf0e10cSrcweir //-------------------------------------------------------------------- 1137*cdf0e10cSrcweir void FormOperations::impl_ensureInitializedParser_nothrow() 1138*cdf0e10cSrcweir { 1139*cdf0e10cSrcweir OSL_PRECOND( m_xCursorProperties.is(), "FormOperations::impl_ensureInitializedParser_nothrow: we're disposed!" ); 1140*cdf0e10cSrcweir if ( m_bInitializedParser ) 1141*cdf0e10cSrcweir return; 1142*cdf0e10cSrcweir 1143*cdf0e10cSrcweir try 1144*cdf0e10cSrcweir { 1145*cdf0e10cSrcweir sal_Bool bUseEscapeProcessing = sal_False; 1146*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bUseEscapeProcessing; 1147*cdf0e10cSrcweir if ( bUseEscapeProcessing ) 1148*cdf0e10cSrcweir { 1149*cdf0e10cSrcweir Reference< XMultiServiceFactory > xFactory( ::dbtools::getConnection( m_xCursor ), UNO_QUERY ); 1150*cdf0e10cSrcweir if ( xFactory.is() ) 1151*cdf0e10cSrcweir { 1152*cdf0e10cSrcweir m_xParser.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.SingleSelectQueryComposer" ) ) ), UNO_QUERY ); 1153*cdf0e10cSrcweir OSL_ENSURE( m_xParser.is(), "FormOperations::impl_ensureInitializedParser_nothrow: factory did not create a parser for us!" ); 1154*cdf0e10cSrcweir } 1155*cdf0e10cSrcweir } 1156*cdf0e10cSrcweir 1157*cdf0e10cSrcweir if ( m_xParser.is() ) 1158*cdf0e10cSrcweir { 1159*cdf0e10cSrcweir if ( m_xLoadableForm.is() && m_xLoadableForm->isLoaded() ) 1160*cdf0e10cSrcweir { 1161*cdf0e10cSrcweir ::rtl::OUString sStatement; 1162*cdf0e10cSrcweir ::rtl::OUString sFilter; 1163*cdf0e10cSrcweir ::rtl::OUString sSort; 1164*cdf0e10cSrcweir 1165*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_ACTIVECOMMAND ) >>= sStatement; 1166*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_FILTER ) >>= sFilter; 1167*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_SORT ) >>= sSort; 1168*cdf0e10cSrcweir 1169*cdf0e10cSrcweir m_xParser->setElementaryQuery( sStatement ); 1170*cdf0e10cSrcweir m_xParser->setFilter ( sFilter ); 1171*cdf0e10cSrcweir m_xParser->setOrder ( sSort ); 1172*cdf0e10cSrcweir } 1173*cdf0e10cSrcweir 1174*cdf0e10cSrcweir // start listening at the order/sort properties at the form, so 1175*cdf0e10cSrcweir // we can keep our parser in sync 1176*cdf0e10cSrcweir m_xCursorProperties->addPropertyChangeListener( PROPERTY_ACTIVECOMMAND, this ); 1177*cdf0e10cSrcweir m_xCursorProperties->addPropertyChangeListener( PROPERTY_FILTER, this ); 1178*cdf0e10cSrcweir m_xCursorProperties->addPropertyChangeListener( PROPERTY_SORT, this ); 1179*cdf0e10cSrcweir } 1180*cdf0e10cSrcweir } 1181*cdf0e10cSrcweir catch( const Exception& ) 1182*cdf0e10cSrcweir { 1183*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormOperations::impl_ensureInitializedParser_nothrow: caught an exception!" ); 1184*cdf0e10cSrcweir } 1185*cdf0e10cSrcweir 1186*cdf0e10cSrcweir m_bInitializedParser = true; 1187*cdf0e10cSrcweir } 1188*cdf0e10cSrcweir 1189*cdf0e10cSrcweir //-------------------------------------------------------------------- 1190*cdf0e10cSrcweir void FormOperations::impl_disposeParser_nothrow() 1191*cdf0e10cSrcweir { 1192*cdf0e10cSrcweir try 1193*cdf0e10cSrcweir { 1194*cdf0e10cSrcweir // if we have a parser (and a cursor), then we're listening at the cursor's 1195*cdf0e10cSrcweir // properties to keep the parser in sync with the cursor 1196*cdf0e10cSrcweir if ( m_xParser.is() && m_xCursorProperties.is() ) 1197*cdf0e10cSrcweir { 1198*cdf0e10cSrcweir m_xCursorProperties->removePropertyChangeListener( PROPERTY_FILTER, this ); 1199*cdf0e10cSrcweir m_xCursorProperties->removePropertyChangeListener( PROPERTY_ACTIVECOMMAND, this ); 1200*cdf0e10cSrcweir m_xCursorProperties->removePropertyChangeListener( PROPERTY_SORT, this ); 1201*cdf0e10cSrcweir } 1202*cdf0e10cSrcweir 1203*cdf0e10cSrcweir Reference< XComponent > xParserComp( m_xParser, UNO_QUERY ); 1204*cdf0e10cSrcweir if ( xParserComp.is() ) 1205*cdf0e10cSrcweir xParserComp->dispose(); 1206*cdf0e10cSrcweir m_xParser.clear(); 1207*cdf0e10cSrcweir 1208*cdf0e10cSrcweir m_bInitializedParser = false; 1209*cdf0e10cSrcweir } 1210*cdf0e10cSrcweir catch( const Exception& ) 1211*cdf0e10cSrcweir { 1212*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormOperations::impl_disposeParser_nothrow: caught an exception!" ); 1213*cdf0e10cSrcweir } 1214*cdf0e10cSrcweir } 1215*cdf0e10cSrcweir 1216*cdf0e10cSrcweir //-------------------------------------------------------------------- 1217*cdf0e10cSrcweir bool FormOperations::impl_canMoveLeft_throw( ) const 1218*cdf0e10cSrcweir { 1219*cdf0e10cSrcweir if ( !impl_hasCursor_nothrow() ) 1220*cdf0e10cSrcweir return false; 1221*cdf0e10cSrcweir 1222*cdf0e10cSrcweir return impl_getRowCount_throw() && ( !m_xCursor->isFirst() || impl_isInsertionRow_throw() ); 1223*cdf0e10cSrcweir } 1224*cdf0e10cSrcweir 1225*cdf0e10cSrcweir //-------------------------------------------------------------------- 1226*cdf0e10cSrcweir bool FormOperations::impl_canMoveRight_throw( ) const 1227*cdf0e10cSrcweir { 1228*cdf0e10cSrcweir if ( !impl_hasCursor_nothrow() ) 1229*cdf0e10cSrcweir return false; 1230*cdf0e10cSrcweir 1231*cdf0e10cSrcweir bool bIsNew = impl_isInsertionRow_throw(); 1232*cdf0e10cSrcweir 1233*cdf0e10cSrcweir if ( impl_getRowCount_throw() && !m_xCursor->isLast() && !bIsNew ) 1234*cdf0e10cSrcweir return true; 1235*cdf0e10cSrcweir 1236*cdf0e10cSrcweir if ( ::dbtools::canInsert( m_xCursorProperties ) ) 1237*cdf0e10cSrcweir if ( !bIsNew || impl_isModifiedRow_throw() ) 1238*cdf0e10cSrcweir return true; 1239*cdf0e10cSrcweir 1240*cdf0e10cSrcweir if ( bIsNew && m_bActiveControlModified ) 1241*cdf0e10cSrcweir return true; 1242*cdf0e10cSrcweir 1243*cdf0e10cSrcweir return false; 1244*cdf0e10cSrcweir } 1245*cdf0e10cSrcweir 1246*cdf0e10cSrcweir //-------------------------------------------------------------------- 1247*cdf0e10cSrcweir namespace 1248*cdf0e10cSrcweir { 1249*cdf0e10cSrcweir template < typename TYPE > 1250*cdf0e10cSrcweir TYPE lcl_safeGetPropertyValue_throw( const Reference< XPropertySet >& _rxProperties, const ::rtl::OUString& _rPropertyName, TYPE _Default ) 1251*cdf0e10cSrcweir { 1252*cdf0e10cSrcweir TYPE value( _Default ); 1253*cdf0e10cSrcweir OSL_PRECOND( _rxProperties.is(), "FormOperations::<foo>: no cursor (already disposed?)!" ); 1254*cdf0e10cSrcweir if ( _rxProperties.is() ) 1255*cdf0e10cSrcweir OSL_VERIFY( _rxProperties->getPropertyValue( _rPropertyName ) >>= value ); 1256*cdf0e10cSrcweir return value; 1257*cdf0e10cSrcweir } 1258*cdf0e10cSrcweir } 1259*cdf0e10cSrcweir 1260*cdf0e10cSrcweir //-------------------------------------------------------------------- 1261*cdf0e10cSrcweir bool FormOperations::impl_isInsertionRow_throw() const 1262*cdf0e10cSrcweir { 1263*cdf0e10cSrcweir return lcl_safeGetPropertyValue_throw( m_xCursorProperties, PROPERTY_ISNEW, false ); 1264*cdf0e10cSrcweir } 1265*cdf0e10cSrcweir 1266*cdf0e10cSrcweir //-------------------------------------------------------------------- 1267*cdf0e10cSrcweir sal_Int32 FormOperations::impl_getRowCount_throw() const 1268*cdf0e10cSrcweir { 1269*cdf0e10cSrcweir return lcl_safeGetPropertyValue_throw( m_xCursorProperties, PROPERTY_ROWCOUNT, (sal_Int32)0 ); 1270*cdf0e10cSrcweir } 1271*cdf0e10cSrcweir //-------------------------------------------------------------------- 1272*cdf0e10cSrcweir bool FormOperations::impl_isRowCountFinal_throw() const 1273*cdf0e10cSrcweir { 1274*cdf0e10cSrcweir return lcl_safeGetPropertyValue_throw( m_xCursorProperties, PROPERTY_ROWCOUNTFINAL, false ); 1275*cdf0e10cSrcweir } 1276*cdf0e10cSrcweir 1277*cdf0e10cSrcweir //-------------------------------------------------------------------- 1278*cdf0e10cSrcweir bool FormOperations::impl_isModifiedRow_throw() const 1279*cdf0e10cSrcweir { 1280*cdf0e10cSrcweir return lcl_safeGetPropertyValue_throw( m_xCursorProperties, PROPERTY_ISMODIFIED, false ); 1281*cdf0e10cSrcweir } 1282*cdf0e10cSrcweir 1283*cdf0e10cSrcweir //-------------------------------------------------------------------- 1284*cdf0e10cSrcweir bool FormOperations::impl_isParseable_throw() const 1285*cdf0e10cSrcweir { 1286*cdf0e10cSrcweir const_cast< FormOperations* >( this )->impl_ensureInitializedParser_nothrow(); 1287*cdf0e10cSrcweir return m_xParser.is() && m_xParser->getQuery().getLength(); 1288*cdf0e10cSrcweir } 1289*cdf0e10cSrcweir 1290*cdf0e10cSrcweir //-------------------------------------------------------------------- 1291*cdf0e10cSrcweir bool FormOperations::impl_hasFilterOrOrder_throw() const 1292*cdf0e10cSrcweir { 1293*cdf0e10cSrcweir return impl_isParseable_throw() && ( m_xParser->getFilter().getLength() || m_xParser->getOrder().getLength() ); 1294*cdf0e10cSrcweir } 1295*cdf0e10cSrcweir 1296*cdf0e10cSrcweir //-------------------------------------------------------------------- 1297*cdf0e10cSrcweir bool FormOperations::impl_isInsertOnlyForm_throw() const 1298*cdf0e10cSrcweir { 1299*cdf0e10cSrcweir return lcl_safeGetPropertyValue_throw( m_xCursorProperties, PROPERTY_INSERTONLY, true ); 1300*cdf0e10cSrcweir } 1301*cdf0e10cSrcweir 1302*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1303*cdf0e10cSrcweir Reference< XControlModel > FormOperations::impl_getCurrentControlModel_throw() const 1304*cdf0e10cSrcweir { 1305*cdf0e10cSrcweir Reference< XControl > xControl( m_xController->getCurrentControl() ); 1306*cdf0e10cSrcweir 1307*cdf0e10cSrcweir // special handling for grid controls 1308*cdf0e10cSrcweir Reference< XGrid > xGrid( xControl, UNO_QUERY ); 1309*cdf0e10cSrcweir Reference< XControlModel > xControlModel; 1310*cdf0e10cSrcweir 1311*cdf0e10cSrcweir if ( xGrid.is() ) 1312*cdf0e10cSrcweir { 1313*cdf0e10cSrcweir Reference< XIndexAccess > xColumns( xControl->getModel(), UNO_QUERY_THROW ); 1314*cdf0e10cSrcweir sal_Int16 nCurrentPos = xGrid->getCurrentColumnPosition(); 1315*cdf0e10cSrcweir nCurrentPos = impl_gridView2ModelPos_nothrow( xColumns, nCurrentPos ); 1316*cdf0e10cSrcweir 1317*cdf0e10cSrcweir if ( nCurrentPos != (sal_Int16)-1 ) 1318*cdf0e10cSrcweir xColumns->getByIndex( nCurrentPos ) >>= xControlModel; 1319*cdf0e10cSrcweir } 1320*cdf0e10cSrcweir else if ( xControl.is() ) 1321*cdf0e10cSrcweir { 1322*cdf0e10cSrcweir xControlModel = xControl->getModel(); 1323*cdf0e10cSrcweir } 1324*cdf0e10cSrcweir return xControlModel; 1325*cdf0e10cSrcweir } 1326*cdf0e10cSrcweir 1327*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1328*cdf0e10cSrcweir Reference< XPropertySet > FormOperations::impl_getCurrentBoundField_nothrow( ) const 1329*cdf0e10cSrcweir { 1330*cdf0e10cSrcweir OSL_PRECOND( m_xController.is(), "FormOperations::impl_getCurrentBoundField_nothrow: no controller -> no control!" ); 1331*cdf0e10cSrcweir if ( !m_xController.is() ) 1332*cdf0e10cSrcweir return NULL; 1333*cdf0e10cSrcweir 1334*cdf0e10cSrcweir Reference< XPropertySet > xField; 1335*cdf0e10cSrcweir try 1336*cdf0e10cSrcweir { 1337*cdf0e10cSrcweir Reference< XPropertySet > xControlModel( impl_getCurrentControlModel_throw(), UNO_QUERY ); 1338*cdf0e10cSrcweir 1339*cdf0e10cSrcweir if ( xControlModel.is() && ::comphelper::hasProperty( PROPERTY_BOUNDFIELD, xControlModel ) ) 1340*cdf0e10cSrcweir xControlModel->getPropertyValue( PROPERTY_BOUNDFIELD ) >>= xField; 1341*cdf0e10cSrcweir 1342*cdf0e10cSrcweir } 1343*cdf0e10cSrcweir catch( const Exception& ) 1344*cdf0e10cSrcweir { 1345*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1346*cdf0e10cSrcweir } 1347*cdf0e10cSrcweir 1348*cdf0e10cSrcweir return xField; 1349*cdf0e10cSrcweir } 1350*cdf0e10cSrcweir 1351*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1352*cdf0e10cSrcweir sal_Int16 FormOperations::impl_gridView2ModelPos_nothrow( const Reference< XIndexAccess >& _rxColumns, sal_Int16 _nViewPos ) const 1353*cdf0e10cSrcweir { 1354*cdf0e10cSrcweir OSL_PRECOND( _rxColumns.is(), "FormOperations::impl_gridView2ModelPos_nothrow: invalid columns container!" ); 1355*cdf0e10cSrcweir try 1356*cdf0e10cSrcweir { 1357*cdf0e10cSrcweir // loop through all columns 1358*cdf0e10cSrcweir sal_Int16 col = 0; 1359*cdf0e10cSrcweir Reference< XPropertySet > xCol; 1360*cdf0e10cSrcweir bool bHidden( false ); 1361*cdf0e10cSrcweir for ( col = 0; col < _rxColumns->getCount(); ++col ) 1362*cdf0e10cSrcweir { 1363*cdf0e10cSrcweir _rxColumns->getByIndex( col ) >>= xCol; 1364*cdf0e10cSrcweir OSL_VERIFY( xCol->getPropertyValue( PROPERTY_HIDDEN ) >>= bHidden ); 1365*cdf0e10cSrcweir if ( bHidden ) 1366*cdf0e10cSrcweir continue; 1367*cdf0e10cSrcweir 1368*cdf0e10cSrcweir // for every visible col : if nViewPos is greater zero, decrement it, else we 1369*cdf0e10cSrcweir // have found the model position 1370*cdf0e10cSrcweir if ( !_nViewPos ) 1371*cdf0e10cSrcweir break; 1372*cdf0e10cSrcweir else 1373*cdf0e10cSrcweir --_nViewPos; 1374*cdf0e10cSrcweir } 1375*cdf0e10cSrcweir if ( col < _rxColumns->getCount() ) 1376*cdf0e10cSrcweir return col; 1377*cdf0e10cSrcweir } 1378*cdf0e10cSrcweir catch( const Exception& ) 1379*cdf0e10cSrcweir { 1380*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1381*cdf0e10cSrcweir } 1382*cdf0e10cSrcweir return (sal_Int16)-1; 1383*cdf0e10cSrcweir } 1384*cdf0e10cSrcweir 1385*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1386*cdf0e10cSrcweir bool FormOperations::impl_moveLeft_throw( ) const 1387*cdf0e10cSrcweir { 1388*cdf0e10cSrcweir OSL_PRECOND( impl_hasCursor_nothrow(), "FormOperations::impl_moveLeft_throw: no cursor!" ); 1389*cdf0e10cSrcweir if ( !impl_hasCursor_nothrow() ) 1390*cdf0e10cSrcweir return false; 1391*cdf0e10cSrcweir 1392*cdf0e10cSrcweir sal_Bool bRecordInserted = sal_False; 1393*cdf0e10cSrcweir sal_Bool bSuccess = impl_commitCurrentRecord_throw( &bRecordInserted ); 1394*cdf0e10cSrcweir 1395*cdf0e10cSrcweir if ( !bSuccess ) 1396*cdf0e10cSrcweir return false; 1397*cdf0e10cSrcweir 1398*cdf0e10cSrcweir if ( bRecordInserted ) 1399*cdf0e10cSrcweir { 1400*cdf0e10cSrcweir // retrieve the bookmark of the new record and move to the record preceding this bookmark 1401*cdf0e10cSrcweir Reference< XRowLocate > xLocate( m_xCursor, UNO_QUERY ); 1402*cdf0e10cSrcweir OSL_ENSURE( xLocate.is(), "FormOperations::impl_moveLeft_throw: no XRowLocate!" ); 1403*cdf0e10cSrcweir if ( xLocate.is() ) 1404*cdf0e10cSrcweir xLocate->moveRelativeToBookmark( xLocate->getBookmark(), -1 ); 1405*cdf0e10cSrcweir } 1406*cdf0e10cSrcweir else 1407*cdf0e10cSrcweir { 1408*cdf0e10cSrcweir if ( impl_isInsertionRow_throw() ) 1409*cdf0e10cSrcweir { 1410*cdf0e10cSrcweir // we assume that the inserted record is now the last record in the 1411*cdf0e10cSrcweir // result set 1412*cdf0e10cSrcweir m_xCursor->last(); 1413*cdf0e10cSrcweir } 1414*cdf0e10cSrcweir else 1415*cdf0e10cSrcweir m_xCursor->previous(); 1416*cdf0e10cSrcweir } 1417*cdf0e10cSrcweir 1418*cdf0e10cSrcweir return true; 1419*cdf0e10cSrcweir } 1420*cdf0e10cSrcweir 1421*cdf0e10cSrcweir //-------------------------------------------------------------------- 1422*cdf0e10cSrcweir bool FormOperations::impl_moveRight_throw( ) const 1423*cdf0e10cSrcweir { 1424*cdf0e10cSrcweir OSL_PRECOND( impl_hasCursor_nothrow(), "FormOperations::impl_moveRight_throw: no cursor!" ); 1425*cdf0e10cSrcweir if ( !impl_hasCursor_nothrow() ) 1426*cdf0e10cSrcweir return false; 1427*cdf0e10cSrcweir 1428*cdf0e10cSrcweir sal_Bool bRecordInserted = sal_False; 1429*cdf0e10cSrcweir sal_Bool bSuccess = impl_commitCurrentRecord_throw( &bRecordInserted ); 1430*cdf0e10cSrcweir 1431*cdf0e10cSrcweir if ( !bSuccess ) 1432*cdf0e10cSrcweir return false; 1433*cdf0e10cSrcweir 1434*cdf0e10cSrcweir if ( bRecordInserted ) 1435*cdf0e10cSrcweir { 1436*cdf0e10cSrcweir // go to insert row 1437*cdf0e10cSrcweir m_xUpdateCursor->moveToInsertRow(); 1438*cdf0e10cSrcweir } 1439*cdf0e10cSrcweir else 1440*cdf0e10cSrcweir { 1441*cdf0e10cSrcweir if ( m_xCursor->isLast() ) 1442*cdf0e10cSrcweir m_xUpdateCursor->moveToInsertRow(); 1443*cdf0e10cSrcweir else 1444*cdf0e10cSrcweir m_xCursor->next(); 1445*cdf0e10cSrcweir } 1446*cdf0e10cSrcweir 1447*cdf0e10cSrcweir return true; 1448*cdf0e10cSrcweir } 1449*cdf0e10cSrcweir 1450*cdf0e10cSrcweir //-------------------------------------------------------------------- 1451*cdf0e10cSrcweir void FormOperations::impl_resetAllControls_nothrow() const 1452*cdf0e10cSrcweir { 1453*cdf0e10cSrcweir Reference< XIndexAccess > xContainer( m_xCursor, UNO_QUERY ); 1454*cdf0e10cSrcweir if ( !xContainer.is() ) 1455*cdf0e10cSrcweir return; 1456*cdf0e10cSrcweir 1457*cdf0e10cSrcweir try 1458*cdf0e10cSrcweir { 1459*cdf0e10cSrcweir Reference< XReset > xReset; 1460*cdf0e10cSrcweir sal_Int32 nCount( xContainer->getCount() ); 1461*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i ) 1462*cdf0e10cSrcweir { 1463*cdf0e10cSrcweir if ( xContainer->getByIndex( i ) >>= xReset ) 1464*cdf0e10cSrcweir { 1465*cdf0e10cSrcweir // no resets on sub forms 1466*cdf0e10cSrcweir Reference< XForm > xAsForm( xReset, UNO_QUERY ); 1467*cdf0e10cSrcweir if ( !xAsForm.is() ) 1468*cdf0e10cSrcweir xReset->reset(); 1469*cdf0e10cSrcweir } 1470*cdf0e10cSrcweir } 1471*cdf0e10cSrcweir } 1472*cdf0e10cSrcweir catch( const Exception& ) 1473*cdf0e10cSrcweir { 1474*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1475*cdf0e10cSrcweir } 1476*cdf0e10cSrcweir } 1477*cdf0e10cSrcweir 1478*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1479*cdf0e10cSrcweir void FormOperations::impl_executeAutoSort_throw( bool _bUp ) const 1480*cdf0e10cSrcweir { 1481*cdf0e10cSrcweir OSL_PRECOND( m_xController.is(), "FormOperations::impl_executeAutoSort_throw: need a controller for this!" ); 1482*cdf0e10cSrcweir OSL_PRECOND( impl_hasCursor_nothrow(), "FormOperations::impl_executeAutoSort_throw: need a cursor for this!" ); 1483*cdf0e10cSrcweir OSL_PRECOND( impl_isParseable_throw(), "FormOperations::impl_executeAutoSort_throw: need a parseable statement for this!" ); 1484*cdf0e10cSrcweir if ( !m_xController.is() || !impl_hasCursor_nothrow() || !impl_isParseable_throw() ) 1485*cdf0e10cSrcweir return; 1486*cdf0e10cSrcweir 1487*cdf0e10cSrcweir try 1488*cdf0e10cSrcweir { 1489*cdf0e10cSrcweir Reference< XControl > xControl = m_xController->getCurrentControl(); 1490*cdf0e10cSrcweir if ( !xControl.is() || !impl_commitCurrentControl_throw() || !impl_commitCurrentRecord_throw() ) 1491*cdf0e10cSrcweir return; 1492*cdf0e10cSrcweir 1493*cdf0e10cSrcweir Reference< XPropertySet > xBoundField( impl_getCurrentBoundField_nothrow() ); 1494*cdf0e10cSrcweir if ( !xBoundField.is() ) 1495*cdf0e10cSrcweir return; 1496*cdf0e10cSrcweir 1497*cdf0e10cSrcweir ::rtl::OUString sOriginalSort; 1498*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_SORT ) >>= sOriginalSort; 1499*cdf0e10cSrcweir 1500*cdf0e10cSrcweir // automatic sort by field is expected to always resets the previous sort order 1501*cdf0e10cSrcweir m_xParser->setOrder( ::rtl::OUString() ); 1502*cdf0e10cSrcweir 1503*cdf0e10cSrcweir param_appendOrderByColumn aParam; 1504*cdf0e10cSrcweir aParam.xField = xBoundField; 1505*cdf0e10cSrcweir aParam.bUp = _bUp; 1506*cdf0e10cSrcweir impl_doActionInSQLContext_throw( 1507*cdf0e10cSrcweir (Action)&FormOperations::impl_appendOrderByColumn_throw, 1508*cdf0e10cSrcweir static_cast< const void* >( &aParam ), 1509*cdf0e10cSrcweir (sal_uInt16)RID_STR_COULD_NOT_SET_ORDER 1510*cdf0e10cSrcweir ); 1511*cdf0e10cSrcweir 1512*cdf0e10cSrcweir WaitObject aWO( NULL ); 1513*cdf0e10cSrcweir try 1514*cdf0e10cSrcweir { 1515*cdf0e10cSrcweir m_xCursorProperties->setPropertyValue( PROPERTY_SORT, makeAny( m_xParser->getOrder() ) ); 1516*cdf0e10cSrcweir m_xLoadableForm->reload(); 1517*cdf0e10cSrcweir } 1518*cdf0e10cSrcweir catch( const Exception& ) 1519*cdf0e10cSrcweir { 1520*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormOperations::impl_executeAutoSort_throw: caught an exception while setting the parser properties!" ); 1521*cdf0e10cSrcweir } 1522*cdf0e10cSrcweir 1523*cdf0e10cSrcweir 1524*cdf0e10cSrcweir if ( !m_xLoadableForm->isLoaded() ) 1525*cdf0e10cSrcweir { // something went wrong -> restore the original state 1526*cdf0e10cSrcweir try 1527*cdf0e10cSrcweir { 1528*cdf0e10cSrcweir m_xParser->setOrder( sOriginalSort ); 1529*cdf0e10cSrcweir m_xCursorProperties->setPropertyValue( PROPERTY_SORT, makeAny( m_xParser->getOrder() ) ); 1530*cdf0e10cSrcweir m_xLoadableForm->reload(); 1531*cdf0e10cSrcweir } 1532*cdf0e10cSrcweir catch( const Exception& ) 1533*cdf0e10cSrcweir { 1534*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormOperations::impl_executeAutoSort_throw: could not reset the form to it's original state!" ); 1535*cdf0e10cSrcweir } 1536*cdf0e10cSrcweir 1537*cdf0e10cSrcweir } 1538*cdf0e10cSrcweir } 1539*cdf0e10cSrcweir catch( const RuntimeException& ) { throw; } 1540*cdf0e10cSrcweir catch( const SQLException& ) { throw; } 1541*cdf0e10cSrcweir catch( const Exception& ) 1542*cdf0e10cSrcweir { 1543*cdf0e10cSrcweir throw WrappedTargetException( ::rtl::OUString(), *const_cast< FormOperations* >( this ), ::cppu::getCaughtException() ); 1544*cdf0e10cSrcweir } 1545*cdf0e10cSrcweir } 1546*cdf0e10cSrcweir 1547*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1548*cdf0e10cSrcweir void FormOperations::impl_executeAutoFilter_throw( ) const 1549*cdf0e10cSrcweir { 1550*cdf0e10cSrcweir OSL_PRECOND( m_xController.is(), "FormOperations::impl_executeAutoFilter_throw: need a controller for this!" ); 1551*cdf0e10cSrcweir OSL_PRECOND( impl_hasCursor_nothrow(), "FormOperations::impl_executeAutoFilter_throw: need a cursor for this!" ); 1552*cdf0e10cSrcweir OSL_PRECOND( impl_isParseable_throw(), "FormOperations::impl_executeAutoFilter_throw: need a parseable statement for this!" ); 1553*cdf0e10cSrcweir if ( !m_xController.is() || !impl_hasCursor_nothrow() || !impl_isParseable_throw() ) 1554*cdf0e10cSrcweir return; 1555*cdf0e10cSrcweir 1556*cdf0e10cSrcweir try 1557*cdf0e10cSrcweir { 1558*cdf0e10cSrcweir Reference< XControl > xControl = m_xController->getCurrentControl(); 1559*cdf0e10cSrcweir if ( !xControl.is() || !impl_commitCurrentControl_throw() || !impl_commitCurrentRecord_throw() ) 1560*cdf0e10cSrcweir return; 1561*cdf0e10cSrcweir 1562*cdf0e10cSrcweir Reference< XPropertySet > xBoundField( impl_getCurrentBoundField_nothrow() ); 1563*cdf0e10cSrcweir if ( !xBoundField.is() ) 1564*cdf0e10cSrcweir return; 1565*cdf0e10cSrcweir 1566*cdf0e10cSrcweir ::rtl::OUString sOriginalFilter; 1567*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_FILTER ) >>= sOriginalFilter; 1568*cdf0e10cSrcweir sal_Bool bApplied = sal_True; 1569*cdf0e10cSrcweir m_xCursorProperties->getPropertyValue( PROPERTY_APPLYFILTER ) >>= bApplied; 1570*cdf0e10cSrcweir 1571*cdf0e10cSrcweir // if we have a filter, but it's not applied, then we have to overwrite it, else append one 1572*cdf0e10cSrcweir if ( !bApplied ) 1573*cdf0e10cSrcweir m_xParser->setFilter( ::rtl::OUString() ); 1574*cdf0e10cSrcweir 1575*cdf0e10cSrcweir param_appendFilterByColumn aParam; 1576*cdf0e10cSrcweir aParam.xField = xBoundField; 1577*cdf0e10cSrcweir impl_doActionInSQLContext_throw( 1578*cdf0e10cSrcweir (Action)&FormOperations::impl_appendFilterByColumn_throw, 1579*cdf0e10cSrcweir static_cast< const void* >( &aParam ), 1580*cdf0e10cSrcweir (sal_uInt16)RID_STR_COULD_NOT_SET_FILTER 1581*cdf0e10cSrcweir ); 1582*cdf0e10cSrcweir 1583*cdf0e10cSrcweir WaitObject aWO( NULL ); 1584*cdf0e10cSrcweir try 1585*cdf0e10cSrcweir { 1586*cdf0e10cSrcweir m_xCursorProperties->setPropertyValue( PROPERTY_FILTER, makeAny( m_xParser->getFilter() ) ); 1587*cdf0e10cSrcweir m_xCursorProperties->setPropertyValue( PROPERTY_APPLYFILTER, makeAny( (sal_Bool)sal_True ) ); 1588*cdf0e10cSrcweir 1589*cdf0e10cSrcweir m_xLoadableForm->reload(); 1590*cdf0e10cSrcweir } 1591*cdf0e10cSrcweir catch( const Exception& ) 1592*cdf0e10cSrcweir { 1593*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormOperations::impl_executeAutoFilter_throw: caught an exception while setting the parser properties!" ); 1594*cdf0e10cSrcweir } 1595*cdf0e10cSrcweir 1596*cdf0e10cSrcweir 1597*cdf0e10cSrcweir if ( !m_xLoadableForm->isLoaded() ) 1598*cdf0e10cSrcweir { // something went wrong -> restore the original state 1599*cdf0e10cSrcweir try 1600*cdf0e10cSrcweir { 1601*cdf0e10cSrcweir m_xParser->setOrder( sOriginalFilter ); 1602*cdf0e10cSrcweir m_xCursorProperties->setPropertyValue( PROPERTY_APPLYFILTER, makeAny( (sal_Bool)bApplied ) ); 1603*cdf0e10cSrcweir m_xCursorProperties->setPropertyValue( PROPERTY_FILTER, makeAny( m_xParser->getFilter() ) ); 1604*cdf0e10cSrcweir m_xLoadableForm->reload(); 1605*cdf0e10cSrcweir } 1606*cdf0e10cSrcweir catch( const Exception& ) 1607*cdf0e10cSrcweir { 1608*cdf0e10cSrcweir OSL_ENSURE( sal_False, "FormOperations::impl_executeAutoFilter_throw: could not reset the form to it's original state!" ); 1609*cdf0e10cSrcweir } 1610*cdf0e10cSrcweir 1611*cdf0e10cSrcweir } 1612*cdf0e10cSrcweir } 1613*cdf0e10cSrcweir catch( const RuntimeException& ) { throw; } 1614*cdf0e10cSrcweir catch( const SQLException& ) { throw; } 1615*cdf0e10cSrcweir catch( const Exception& ) 1616*cdf0e10cSrcweir { 1617*cdf0e10cSrcweir throw WrappedTargetException( ::rtl::OUString(), *const_cast< FormOperations* >( this ), ::cppu::getCaughtException() ); 1618*cdf0e10cSrcweir } 1619*cdf0e10cSrcweir } 1620*cdf0e10cSrcweir 1621*cdf0e10cSrcweir //-------------------------------------------------------------------- 1622*cdf0e10cSrcweir void FormOperations::impl_executeFilterOrSort_throw( bool _bFilter ) const 1623*cdf0e10cSrcweir { 1624*cdf0e10cSrcweir OSL_PRECOND( m_xController.is(), "FormOperations::impl_executeFilterOrSort_throw: need a controller for this!" ); 1625*cdf0e10cSrcweir OSL_PRECOND( impl_hasCursor_nothrow(), "FormOperations::impl_executeFilterOrSort_throw: need a cursor for this!" ); 1626*cdf0e10cSrcweir OSL_PRECOND( impl_isParseable_throw(), "FormOperations::impl_executeFilterOrSort_throw: need a parseable statement for this!" ); 1627*cdf0e10cSrcweir if ( !m_xController.is() || !impl_hasCursor_nothrow() || !impl_isParseable_throw() ) 1628*cdf0e10cSrcweir return; 1629*cdf0e10cSrcweir 1630*cdf0e10cSrcweir if ( !impl_commitCurrentControl_throw() || !impl_commitCurrentRecord_throw() ) 1631*cdf0e10cSrcweir return; 1632*cdf0e10cSrcweir try 1633*cdf0e10cSrcweir { 1634*cdf0e10cSrcweir PropertyValue aFirst; 1635*cdf0e10cSrcweir aFirst.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "QueryComposer" ) ); 1636*cdf0e10cSrcweir aFirst.Value <<= m_xParser; 1637*cdf0e10cSrcweir 1638*cdf0e10cSrcweir PropertyValue aSecond; 1639*cdf0e10cSrcweir aSecond.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RowSet" ) ); 1640*cdf0e10cSrcweir aSecond.Value <<= m_xCursorProperties; 1641*cdf0e10cSrcweir 1642*cdf0e10cSrcweir Sequence<Any> aInit(2); 1643*cdf0e10cSrcweir aInit[0] <<= aFirst; 1644*cdf0e10cSrcweir aInit[1] <<= aSecond; 1645*cdf0e10cSrcweir 1646*cdf0e10cSrcweir ::rtl::OUString sDialogServiceName; 1647*cdf0e10cSrcweir if ( _bFilter ) 1648*cdf0e10cSrcweir sDialogServiceName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.FilterDialog" ) ); 1649*cdf0e10cSrcweir else 1650*cdf0e10cSrcweir sDialogServiceName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.OrderDialog" ) ); 1651*cdf0e10cSrcweir 1652*cdf0e10cSrcweir Reference< XExecutableDialog> xDialog; 1653*cdf0e10cSrcweir m_aContext.createComponentWithArguments( sDialogServiceName, aInit, xDialog ); 1654*cdf0e10cSrcweir 1655*cdf0e10cSrcweir if ( !xDialog.is() ) 1656*cdf0e10cSrcweir { 1657*cdf0e10cSrcweir ShowServiceNotAvailableError( NULL, sDialogServiceName, sal_True ); 1658*cdf0e10cSrcweir return; 1659*cdf0e10cSrcweir } 1660*cdf0e10cSrcweir 1661*cdf0e10cSrcweir if ( RET_OK == xDialog->execute() ) 1662*cdf0e10cSrcweir { 1663*cdf0e10cSrcweir WaitObject aWO( NULL ); 1664*cdf0e10cSrcweir if ( _bFilter ) 1665*cdf0e10cSrcweir m_xCursorProperties->setPropertyValue( PROPERTY_FILTER, makeAny( m_xParser->getFilter() ) ); 1666*cdf0e10cSrcweir else 1667*cdf0e10cSrcweir m_xCursorProperties->setPropertyValue( PROPERTY_SORT, makeAny( m_xParser->getOrder() ) ); 1668*cdf0e10cSrcweir m_xLoadableForm->reload(); 1669*cdf0e10cSrcweir } 1670*cdf0e10cSrcweir 1671*cdf0e10cSrcweir } 1672*cdf0e10cSrcweir catch( const RuntimeException& ) { throw; } 1673*cdf0e10cSrcweir catch( const SQLException& ) { throw; } 1674*cdf0e10cSrcweir catch( const Exception& ) 1675*cdf0e10cSrcweir { 1676*cdf0e10cSrcweir throw WrappedTargetException( ::rtl::OUString(), *const_cast< FormOperations* >( this ), ::cppu::getCaughtException() ); 1677*cdf0e10cSrcweir } 1678*cdf0e10cSrcweir } 1679*cdf0e10cSrcweir 1680*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1681*cdf0e10cSrcweir void FormOperations::impl_appendOrderByColumn_throw( const void* _pActionParam ) const 1682*cdf0e10cSrcweir { 1683*cdf0e10cSrcweir const param_appendOrderByColumn* pParam = static_cast< const param_appendOrderByColumn* >( _pActionParam ); 1684*cdf0e10cSrcweir m_xParser->appendOrderByColumn( pParam->xField, pParam->bUp ); 1685*cdf0e10cSrcweir } 1686*cdf0e10cSrcweir 1687*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1688*cdf0e10cSrcweir void FormOperations::impl_appendFilterByColumn_throw( const void* _pActionParam ) const 1689*cdf0e10cSrcweir { 1690*cdf0e10cSrcweir const param_appendFilterByColumn* pParam = static_cast< const param_appendFilterByColumn* >( _pActionParam ); 1691*cdf0e10cSrcweir sal_Int32 nOp = SQLFilterOperator::EQUAL; 1692*cdf0e10cSrcweir if ( pParam->xField.is() ) 1693*cdf0e10cSrcweir { 1694*cdf0e10cSrcweir sal_Int32 nType = 0; 1695*cdf0e10cSrcweir pParam->xField->getPropertyValue(PROPERTY_FIELDTYPE) >>= nType; 1696*cdf0e10cSrcweir switch(nType) 1697*cdf0e10cSrcweir { 1698*cdf0e10cSrcweir case DataType::VARCHAR: 1699*cdf0e10cSrcweir case DataType::CHAR: 1700*cdf0e10cSrcweir case DataType::LONGVARCHAR: 1701*cdf0e10cSrcweir nOp = SQLFilterOperator::LIKE; 1702*cdf0e10cSrcweir break; 1703*cdf0e10cSrcweir default: 1704*cdf0e10cSrcweir nOp = SQLFilterOperator::EQUAL; 1705*cdf0e10cSrcweir } 1706*cdf0e10cSrcweir } 1707*cdf0e10cSrcweir m_xParser->appendFilterByColumn( pParam->xField, sal_True,nOp ); 1708*cdf0e10cSrcweir } 1709*cdf0e10cSrcweir 1710*cdf0e10cSrcweir //------------------------------------------------------------------------------ 1711*cdf0e10cSrcweir void FormOperations::impl_doActionInSQLContext_throw( Action _pAction, const void* _pParam, sal_uInt16 _nErrorResourceId ) const 1712*cdf0e10cSrcweir { 1713*cdf0e10cSrcweir try 1714*cdf0e10cSrcweir { 1715*cdf0e10cSrcweir (this->*_pAction)( _pParam ); 1716*cdf0e10cSrcweir } 1717*cdf0e10cSrcweir catch( const SQLException& e ) 1718*cdf0e10cSrcweir { 1719*cdf0e10cSrcweir (void)e; 1720*cdf0e10cSrcweir if ( !_nErrorResourceId ) 1721*cdf0e10cSrcweir // no information to prepend 1722*cdf0e10cSrcweir throw; 1723*cdf0e10cSrcweir 1724*cdf0e10cSrcweir SQLExceptionInfo aInfo( ::cppu::getCaughtException() ); 1725*cdf0e10cSrcweir ::rtl::OUString sAdditionalError( FRM_RES_STRING( _nErrorResourceId ) ); 1726*cdf0e10cSrcweir aInfo.prepend( sAdditionalError ); 1727*cdf0e10cSrcweir aInfo.doThrow(); 1728*cdf0e10cSrcweir } 1729*cdf0e10cSrcweir catch( const RuntimeException& ) { throw; } 1730*cdf0e10cSrcweir catch( const Exception& ) 1731*cdf0e10cSrcweir { 1732*cdf0e10cSrcweir ::rtl::OUString sAdditionalError( FRM_RES_STRING( _nErrorResourceId ) ); 1733*cdf0e10cSrcweir throw WrappedTargetException( sAdditionalError, *const_cast< FormOperations* >( this ), ::cppu::getCaughtException() ); 1734*cdf0e10cSrcweir } 1735*cdf0e10cSrcweir } 1736*cdf0e10cSrcweir 1737*cdf0e10cSrcweir //........................................................................ 1738*cdf0e10cSrcweir } // namespace frm 1739*cdf0e10cSrcweir //........................................................................ 1740