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_dbaccess.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #ifndef _SBA_EXTCTRLR_HXX 32*cdf0e10cSrcweir #include "exsrcbrw.hxx" 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FORM_FORMCOMPONENTTYPE_HPP_ 35*cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp> 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_XURLTRANSFORMER_HPP_ 38*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FORM_XGRIDCOLUMNFACTORY_HPP_ 41*cdf0e10cSrcweir #include <com/sun/star/form/XGridColumnFactory.hpp> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FORM_XLOADABLE_HPP_ 44*cdf0e10cSrcweir #include <com/sun/star/form/XLoadable.hpp> 45*cdf0e10cSrcweir #endif 46*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_ 47*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp> 48*cdf0e10cSrcweir #endif 49*cdf0e10cSrcweir #ifndef _SBA_FORMADAPTER_HXX 50*cdf0e10cSrcweir #include "formadapter.hxx" 51*cdf0e10cSrcweir #endif 52*cdf0e10cSrcweir #ifndef _COMPHELPER_PROCESSFACTORY_HXX_ 53*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 54*cdf0e10cSrcweir #endif 55*cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC 56*cdf0e10cSrcweir #include "dbustrings.hrc" 57*cdf0e10cSrcweir #endif 58*cdf0e10cSrcweir #ifndef _DBU_REGHELPER_HXX_ 59*cdf0e10cSrcweir #include "dbu_reghelper.hxx" 60*cdf0e10cSrcweir #endif 61*cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H 62*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 63*cdf0e10cSrcweir #endif 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 66*cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 67*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 68*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 69*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 70*cdf0e10cSrcweir using namespace ::com::sun::star::container; 71*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 72*cdf0e10cSrcweir using namespace ::com::sun::star::form; 73*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 74*cdf0e10cSrcweir using namespace dbaui; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir //============================================================================== 77*cdf0e10cSrcweir //= SbaExternalSourceBrowser 78*cdf0e10cSrcweir //============================================================================== 79*cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_OFormGridView() 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir static OMultiInstanceAutoRegistration< SbaExternalSourceBrowser > aAutoRegistration; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir //------------------------------------------------------------------------------ 84*cdf0e10cSrcweir Any SAL_CALL SbaExternalSourceBrowser::queryInterface(const Type& _rType) throw (RuntimeException) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir Any aRet = SbaXDataBrowserController::queryInterface(_rType); 87*cdf0e10cSrcweir if(!aRet.hasValue()) 88*cdf0e10cSrcweir aRet = ::cppu::queryInterface(_rType, 89*cdf0e10cSrcweir (::com::sun::star::util::XModifyBroadcaster*)this, 90*cdf0e10cSrcweir (::com::sun::star::form::XLoadListener*)this); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir return aRet; 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir DBG_NAME(SbaExternalSourceBrowser) 95*cdf0e10cSrcweir //------------------------------------------------------------------------------ 96*cdf0e10cSrcweir SbaExternalSourceBrowser::SbaExternalSourceBrowser(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM) 97*cdf0e10cSrcweir :SbaXDataBrowserController(_rM) 98*cdf0e10cSrcweir ,m_aModifyListeners(getMutex()) 99*cdf0e10cSrcweir ,m_pDataSourceImpl(NULL) 100*cdf0e10cSrcweir ,m_bInQueryDispatch( sal_False ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir DBG_CTOR(SbaExternalSourceBrowser,NULL); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir //------------------------------------------------------------------------------ 107*cdf0e10cSrcweir SbaExternalSourceBrowser::~SbaExternalSourceBrowser() 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir DBG_DTOR(SbaExternalSourceBrowser,NULL); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir //------------------------------------------------------------------------- 114*cdf0e10cSrcweir ::comphelper::StringSequence SAL_CALL SbaExternalSourceBrowser::getSupportedServiceNames() throw(RuntimeException) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir return getSupportedServiceNames_Static(); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir // ------------------------------------------------------------------------- 119*cdf0e10cSrcweir ::rtl::OUString SbaExternalSourceBrowser::getImplementationName_Static() throw(RuntimeException) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.OFormGridView")); 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir //------------------------------------------------------------------------- 124*cdf0e10cSrcweir ::comphelper::StringSequence SbaExternalSourceBrowser::getSupportedServiceNames_Static() throw(RuntimeException) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir ::comphelper::StringSequence aSupported(1); 127*cdf0e10cSrcweir aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.FormGridView")); 128*cdf0e10cSrcweir return aSupported; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir //------------------------------------------------------------------------- 131*cdf0e10cSrcweir Reference< XInterface > SAL_CALL SbaExternalSourceBrowser::Create(const Reference<XMultiServiceFactory >& _rxFactory) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir return *(new SbaExternalSourceBrowser(_rxFactory)); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir //------------------------------------------------------------------------- 136*cdf0e10cSrcweir ::rtl::OUString SAL_CALL SbaExternalSourceBrowser::getImplementationName() throw(RuntimeException) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir return getImplementationName_Static(); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir //------------------------------------------------------------------------------ 141*cdf0e10cSrcweir Reference< XRowSet > SbaExternalSourceBrowser::CreateForm() 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir m_pDataSourceImpl = new SbaXFormAdapter(); 144*cdf0e10cSrcweir return m_pDataSourceImpl; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir //------------------------------------------------------------------------------ 148*cdf0e10cSrcweir sal_Bool SbaExternalSourceBrowser::InitializeForm(const Reference< XPropertySet > & /*i_formProperties*/) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir return sal_True; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir //------------------------------------------------------------------ 154*cdf0e10cSrcweir sal_Bool SbaExternalSourceBrowser::LoadForm() 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir // as we don't have a main form (yet), we have nothing to do 157*cdf0e10cSrcweir // we don't call FormLoaded, because this expects a working data source 158*cdf0e10cSrcweir return sal_True; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir //------------------------------------------------------------------ 163*cdf0e10cSrcweir void SbaExternalSourceBrowser::modified(const ::com::sun::star::lang::EventObject& aEvent) throw( RuntimeException ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir SbaXDataBrowserController::modified(aEvent); 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir // multiplex this event to all my listeners 168*cdf0e10cSrcweir ::com::sun::star::lang::EventObject aEvt(*this); 169*cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper aIt(m_aModifyListeners); 170*cdf0e10cSrcweir while (aIt.hasMoreElements()) 171*cdf0e10cSrcweir ((::com::sun::star::util::XModifyListener*)aIt.next())->modified(aEvt); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir //------------------------------------------------------------------ 175*cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::dispatch(const ::com::sun::star::util::URL& aURL, const Sequence< ::com::sun::star::beans::PropertyValue>& aArgs) throw(::com::sun::star::uno::RuntimeException) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir const ::com::sun::star::beans::PropertyValue* pArguments = aArgs.getConstArray(); 178*cdf0e10cSrcweir if (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/AddGridColumn"))) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir // search the argument describing the column to create 181*cdf0e10cSrcweir ::rtl::OUString sControlType; 182*cdf0e10cSrcweir sal_Int32 nControlPos = -1; 183*cdf0e10cSrcweir Sequence< ::com::sun::star::beans::PropertyValue> aControlProps; 184*cdf0e10cSrcweir sal_uInt16 i; 185*cdf0e10cSrcweir for ( i = 0; i < aArgs.getLength(); ++i, ++pArguments ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir if (pArguments->Name.equals(::rtl::OUString::createFromAscii("ColumnType"))) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir sal_Bool bCorrectType = pArguments->Value.getValueType().equals(::getCppuType((const ::rtl::OUString*)0)); 190*cdf0e10cSrcweir OSL_ENSURE(bCorrectType, "invalid type for argument \"ColumnType\" !"); 191*cdf0e10cSrcweir if (bCorrectType) 192*cdf0e10cSrcweir sControlType = ::comphelper::getString(pArguments->Value); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir else if (pArguments->Name.equals(::rtl::OUString::createFromAscii("ColumnPosition"))) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir sal_Bool bCorrectType = pArguments->Value.getValueType().equals(::getCppuType((const sal_Int16*)0)); 197*cdf0e10cSrcweir OSL_ENSURE(bCorrectType, "invalid type for argument \"ColumnPosition\" !"); 198*cdf0e10cSrcweir if (bCorrectType) 199*cdf0e10cSrcweir nControlPos = ::comphelper::getINT16(pArguments->Value); 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir else if (pArguments->Name.equals(::rtl::OUString::createFromAscii("ColumnProperties"))) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir sal_Bool bCorrectType = pArguments->Value.getValueType().equals(::getCppuType((const Sequence< ::com::sun::star::beans::PropertyValue>*)0)); 204*cdf0e10cSrcweir OSL_ENSURE(bCorrectType, "invalid type for argument \"ColumnProperties\" !"); 205*cdf0e10cSrcweir if (bCorrectType) 206*cdf0e10cSrcweir aControlProps = *(Sequence< ::com::sun::star::beans::PropertyValue>*)pArguments->Value.getValue(); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir else 209*cdf0e10cSrcweir OSL_ENSURE(sal_False, ((ByteString("SbaExternalSourceBrowser::dispatch(AddGridColumn) : unknown argument (") += ByteString((const sal_Unicode*)pArguments->Name, gsl_getSystemTextEncoding()).GetBuffer()) += ") !").GetBuffer()); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir if (!sControlType.getLength()) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir OSL_ENSURE(sal_False, "SbaExternalSourceBrowser::dispatch(AddGridColumn) : missing argument (ColumnType) !"); 214*cdf0e10cSrcweir sControlType = ::rtl::OUString::createFromAscii("TextField"); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir OSL_ENSURE(aControlProps.getLength(), "SbaExternalSourceBrowser::dispatch(AddGridColumn) : missing argument (ColumnProperties) !"); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir // create the col 219*cdf0e10cSrcweir Reference< ::com::sun::star::form::XGridColumnFactory > xColFactory(getControlModel(), UNO_QUERY); 220*cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySet > xNewCol = xColFactory->createColumn(sControlType); 221*cdf0e10cSrcweir Reference< XPropertySetInfo > xNewColProperties; 222*cdf0e10cSrcweir if (xNewCol.is()) 223*cdf0e10cSrcweir xNewColProperties = xNewCol->getPropertySetInfo(); 224*cdf0e10cSrcweir // set it's properties 225*cdf0e10cSrcweir if (xNewColProperties.is()) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir const ::com::sun::star::beans::PropertyValue* pControlProps = aControlProps.getConstArray(); 228*cdf0e10cSrcweir for (i=0; i<aControlProps.getLength(); ++i, ++pControlProps) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir try 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir if (xNewColProperties->hasPropertyByName(pControlProps->Name)) 233*cdf0e10cSrcweir xNewCol->setPropertyValue(pControlProps->Name, pControlProps->Value); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir catch(Exception&) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir OSL_ENSURE(sal_False, 238*cdf0e10cSrcweir ( ByteString("SbaExternalSourceBrowser::dispatch : could not set a column property (") 239*cdf0e10cSrcweir += ByteString(pControlProps->Name.getStr(), (sal_uInt16)pControlProps->Name.getLength(), RTL_TEXTENCODING_ASCII_US) 240*cdf0e10cSrcweir += ByteString(")!")).GetBuffer()); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir // correct the position 246*cdf0e10cSrcweir Reference< ::com::sun::star::container::XIndexContainer > xColContainer(getControlModel(), UNO_QUERY); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir if (nControlPos > xColContainer->getCount()) 249*cdf0e10cSrcweir nControlPos = xColContainer->getCount(); 250*cdf0e10cSrcweir if (nControlPos < 0) 251*cdf0e10cSrcweir nControlPos = 0; 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir // append the column 254*cdf0e10cSrcweir xColContainer->insertByIndex(nControlPos, makeAny(xNewCol)); 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir else if (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/ClearView"))) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir ClearView(); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir else if (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/AttachToForm"))) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir if (!m_pDataSourceImpl) 263*cdf0e10cSrcweir return; 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir Reference< XRowSet > xMasterForm; 266*cdf0e10cSrcweir // search the arguments for he master form 267*cdf0e10cSrcweir for (sal_uInt16 i=0; i<aArgs.getLength(); ++i, ++pArguments) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir if ((pArguments->Name.equals(::rtl::OUString::createFromAscii("MasterForm"))) && (pArguments->Value.getValueTypeClass() == TypeClass_INTERFACE)) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir xMasterForm = Reference< XRowSet > (*(Reference< XInterface > *)pArguments->Value.getValue(), UNO_QUERY); 272*cdf0e10cSrcweir break; 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir if (!xMasterForm.is()) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir OSL_ENSURE(sal_False, "SbaExternalSourceBrowser::dispatch(FormSlots/AttachToForm) : please specify a form to attach to as argument !"); 278*cdf0e10cSrcweir return; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir Attach(xMasterForm); 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir else 284*cdf0e10cSrcweir SbaXDataBrowserController::dispatch(aURL, aArgs); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir //------------------------------------------------------------------ 288*cdf0e10cSrcweir Reference< ::com::sun::star::frame::XDispatch > SAL_CALL SbaExternalSourceBrowser::queryDispatch(const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException ) 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir Reference< ::com::sun::star::frame::XDispatch > xReturn; 291*cdf0e10cSrcweir if (m_bInQueryDispatch) 292*cdf0e10cSrcweir return xReturn; 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir m_bInQueryDispatch = sal_True; 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir if ( (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/AttachToForm"))) 297*cdf0e10cSrcweir // attach a new external form 298*cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/AddGridColumn"))) 299*cdf0e10cSrcweir // add a column to the grid 300*cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/ClearView"))) 301*cdf0e10cSrcweir // clear the grid 302*cdf0e10cSrcweir ) 303*cdf0e10cSrcweir xReturn = (::com::sun::star::frame::XDispatch*)this; 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir if ( !xReturn.is() 306*cdf0e10cSrcweir && ( (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/moveToFirst"))) 307*cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/moveToPrev"))) 308*cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/moveToNext"))) 309*cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/moveToLast"))) 310*cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/moveToNew"))) 311*cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/undoRecord"))) 312*cdf0e10cSrcweir ) 313*cdf0e10cSrcweir ) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir OSL_ENSURE(aURL.Mark.getLength() == 0, "SbaExternalSourceBrowser::queryDispatch : the ::com::sun::star::util::URL shouldn't have a mark !"); 316*cdf0e10cSrcweir ::com::sun::star::util::URL aNewUrl = aURL; 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir // split the ::com::sun::star::util::URL 319*cdf0e10cSrcweir OSL_ENSURE( m_xUrlTransformer.is(), "SbaExternalSourceBrowser::queryDispatch : could not create an URLTransformer !" ); 320*cdf0e10cSrcweir if ( m_xUrlTransformer.is() ) 321*cdf0e10cSrcweir m_xUrlTransformer->parseStrict( aNewUrl ); 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir // set a new mark 324*cdf0e10cSrcweir aNewUrl.Mark = ::rtl::OUString::createFromAscii("DB/FormGridView"); 325*cdf0e10cSrcweir // this controller is instantiated when somebody dispatches the ".component:DB/FormGridView" in any 326*cdf0e10cSrcweir // frame, so we use "FormGridView" as mark that a dispatch request came from this view 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir if (m_xUrlTransformer.is()) 329*cdf0e10cSrcweir m_xUrlTransformer->assemble(aNewUrl); 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir Reference< XDispatchProvider > xFrameDispatcher( getFrame(), UNO_QUERY ); 332*cdf0e10cSrcweir if (xFrameDispatcher.is()) 333*cdf0e10cSrcweir xReturn = xFrameDispatcher->queryDispatch(aNewUrl, aTargetFrameName, FrameSearchFlag::PARENT); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir if (!xReturn.is()) 338*cdf0e10cSrcweir xReturn = SbaXDataBrowserController::queryDispatch(aURL, aTargetFrameName, nSearchFlags); 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir m_bInQueryDispatch = sal_False; 341*cdf0e10cSrcweir return xReturn; 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir //------------------------------------------------------------------ 345*cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::disposing() 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir // say our modify listeners goodbye 348*cdf0e10cSrcweir ::com::sun::star::lang::EventObject aEvt; 349*cdf0e10cSrcweir aEvt.Source = (XWeak*) this; 350*cdf0e10cSrcweir m_aModifyListeners.disposeAndClear(aEvt); 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir stopListening(); 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir SbaXDataBrowserController::disposing(); 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir //------------------------------------------------------------------ 358*cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::addModifyListener(const Reference< ::com::sun::star::util::XModifyListener > & aListener) throw( RuntimeException ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir m_aModifyListeners.addInterface(aListener); 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir //------------------------------------------------------------------ 364*cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::removeModifyListener(const Reference< ::com::sun::star::util::XModifyListener > & aListener) throw( RuntimeException ) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir m_aModifyListeners.removeInterface(aListener); 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir //------------------------------------------------------------------ 370*cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::unloading(const ::com::sun::star::lang::EventObject& aEvent) throw( RuntimeException ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir if (m_pDataSourceImpl && (m_pDataSourceImpl->getAttachedForm() == aEvent.Source)) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir ClearView(); 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir SbaXDataBrowserController::unloading(aEvent); 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir //------------------------------------------------------------------ 381*cdf0e10cSrcweir void SbaExternalSourceBrowser::Attach(const Reference< XRowSet > & xMaster) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir Any aOldPos; 384*cdf0e10cSrcweir sal_Bool bWasInsertRow = sal_False; 385*cdf0e10cSrcweir sal_Bool bBeforeFirst = sal_True; 386*cdf0e10cSrcweir sal_Bool bAfterLast = sal_True; 387*cdf0e10cSrcweir Reference< XResultSet > xResultSet(xMaster, UNO_QUERY); 388*cdf0e10cSrcweir Reference< XRowLocate > xCursor(xMaster, UNO_QUERY); 389*cdf0e10cSrcweir Reference< XPropertySet > xMasterProps(xMaster, UNO_QUERY); 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir try 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir // switch the control to design mode 394*cdf0e10cSrcweir if (getBrowserView() && getBrowserView()->getGridControl().is()) 395*cdf0e10cSrcweir getBrowserView()->getGridControl()->setDesignMode(sal_True); 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir // the grid will move the form's cursor to the first record, but we want the form to remain unchanged 398*cdf0e10cSrcweir // restore the old position 399*cdf0e10cSrcweir if (xCursor.is() && xResultSet.is()) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir bBeforeFirst = xResultSet->isBeforeFirst(); 402*cdf0e10cSrcweir bAfterLast = xResultSet->isAfterLast(); 403*cdf0e10cSrcweir if(!bBeforeFirst && !bAfterLast) 404*cdf0e10cSrcweir aOldPos = xCursor->getBookmark(); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir if (xMasterProps.is()) 408*cdf0e10cSrcweir xMasterProps->getPropertyValue(PROPERTY_ISNEW) >>= bWasInsertRow; 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir catch( const Exception& ) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir onStartLoading( Reference< XLoadable >( xMaster, UNO_QUERY ) ); 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir stopListening(); 418*cdf0e10cSrcweir m_pDataSourceImpl->AttachForm(xMaster); 419*cdf0e10cSrcweir startListening(); 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir if (xMaster.is()) 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir // at this point we have to reset the formatter for the new form 424*cdf0e10cSrcweir initFormatter(); 425*cdf0e10cSrcweir // assume that the master form is already loaded 426*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 427*cdf0e10cSrcweir { 428*cdf0e10cSrcweir Reference< XLoadable > xLoadable( xMaster, UNO_QUERY ); 429*cdf0e10cSrcweir OSL_ENSURE( xLoadable.is() && xLoadable->isLoaded(), "SbaExternalSourceBrowser::Attach: master is not loaded!" ); 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir #endif 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir LoadFinished(sal_True); 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir Reference< XResultSetUpdate > xUpdate(xMaster, UNO_QUERY); 436*cdf0e10cSrcweir try 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir if (bWasInsertRow && xUpdate.is()) 439*cdf0e10cSrcweir xUpdate->moveToInsertRow(); 440*cdf0e10cSrcweir else if (xCursor.is() && aOldPos.hasValue()) 441*cdf0e10cSrcweir xCursor->moveToBookmark(aOldPos); 442*cdf0e10cSrcweir else if(bBeforeFirst && xResultSet.is()) 443*cdf0e10cSrcweir xResultSet->beforeFirst(); 444*cdf0e10cSrcweir else if(bAfterLast && xResultSet.is()) 445*cdf0e10cSrcweir xResultSet->afterLast(); 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir catch(Exception&) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir OSL_ENSURE(sal_False, "SbaExternalSourceBrowser::Attach : couldn't restore the cursor position !"); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir //------------------------------------------------------------------ 456*cdf0e10cSrcweir void SbaExternalSourceBrowser::ClearView() 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir // set a new (empty) datasource 459*cdf0e10cSrcweir Attach(Reference< XRowSet > ()); 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir // clear all cols in the grid 463*cdf0e10cSrcweir Reference< ::com::sun::star::container::XIndexContainer > xColContainer(getControlModel(), UNO_QUERY); 464*cdf0e10cSrcweir while (xColContainer->getCount() > 0) 465*cdf0e10cSrcweir xColContainer->removeByIndex(0); 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir //------------------------------------------------------------------ 469*cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::disposing(const ::com::sun::star::lang::EventObject& Source) throw( RuntimeException ) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir if (m_pDataSourceImpl && (m_pDataSourceImpl->getAttachedForm() == Source.Source)) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir ClearView(); 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir SbaXDataBrowserController::disposing(Source); 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir //------------------------------------------------------------------ 480*cdf0e10cSrcweir void SbaExternalSourceBrowser::startListening() 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir if (m_pDataSourceImpl && m_pDataSourceImpl->getAttachedForm().is()) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir Reference< ::com::sun::star::form::XLoadable > xLoadable(m_pDataSourceImpl->getAttachedForm(), UNO_QUERY); 485*cdf0e10cSrcweir xLoadable->addLoadListener((::com::sun::star::form::XLoadListener*)this); 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir } 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir //------------------------------------------------------------------ 490*cdf0e10cSrcweir void SbaExternalSourceBrowser::stopListening() 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir if (m_pDataSourceImpl && m_pDataSourceImpl->getAttachedForm().is()) 493*cdf0e10cSrcweir { 494*cdf0e10cSrcweir Reference< ::com::sun::star::form::XLoadable > xLoadable(m_pDataSourceImpl->getAttachedForm(), UNO_QUERY); 495*cdf0e10cSrcweir xLoadable->removeLoadListener((::com::sun::star::form::XLoadListener*)this); 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir //================================================================== 500*cdf0e10cSrcweir //================================================================== 501