1*2a97ec55SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2a97ec55SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2a97ec55SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2a97ec55SAndrew Rist * distributed with this work for additional information 6*2a97ec55SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2a97ec55SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2a97ec55SAndrew Rist * "License"); you may not use this file except in compliance 9*2a97ec55SAndrew Rist * with the License. You may obtain a copy of the License at 10*2a97ec55SAndrew Rist * 11*2a97ec55SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2a97ec55SAndrew Rist * 13*2a97ec55SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2a97ec55SAndrew Rist * software distributed under the License is distributed on an 15*2a97ec55SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2a97ec55SAndrew Rist * KIND, either express or implied. See the License for the 17*2a97ec55SAndrew Rist * specific language governing permissions and limitations 18*2a97ec55SAndrew Rist * under the License. 19*2a97ec55SAndrew Rist * 20*2a97ec55SAndrew Rist *************************************************************/ 21*2a97ec55SAndrew Rist 22*2a97ec55SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_extensions.hxx" 26cdf0e10cSrcweir #include <vcl/waitobj.hxx> 27cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 28cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp> 29cdf0e10cSrcweir #include <osl/mutex.hxx> 30cdf0e10cSrcweir #include <vcl/msgbox.hxx> 31cdf0e10cSrcweir #include <tools/debug.hxx> 32cdf0e10cSrcweir #include <vcl/stdtext.hxx> 33cdf0e10cSrcweir #include <comphelper/types.hxx> 34cdf0e10cSrcweir #include <comphelper/sequence.hxx> 35cdf0e10cSrcweir #include "framectr.hxx" 36cdf0e10cSrcweir #include "datman.hxx" 37cdf0e10cSrcweir #include "bibresid.hxx" 38cdf0e10cSrcweir #include "bib.hrc" 39cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 40cdf0e10cSrcweir #include "bibconfig.hxx" 41cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> // helper for implementations 42cdf0e10cSrcweir #include <vcl/svapp.hxx> 43cdf0e10cSrcweir #include "bibliography.hrc" 44cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 45cdf0e10cSrcweir #include <com/sun/star/form/XConfirmDeleteListener.hpp> 46cdf0e10cSrcweir #include <com/sun/star/form/runtime/XFormController.hpp> 47cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp> 48cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 49cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 50cdf0e10cSrcweir #include <com/sun/star/sdbcx/Privilege.hpp> 51cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetUpdate.hpp> 52cdf0e10cSrcweir #include <com/sun/star/sdb/RowChangeAction.hpp> 53cdf0e10cSrcweir #include <com/sun/star/frame/CommandGroup.hpp> 54cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> 55cdf0e10cSrcweir #include <sot/exchange.hxx> 56cdf0e10cSrcweir #include <sot/formats.hxx> 57cdf0e10cSrcweir #include <vcl/edit.hxx> 58cdf0e10cSrcweir #include <vos/mutex.hxx> 59cdf0e10cSrcweir 60cdf0e10cSrcweir #include <hash_map> 61cdf0e10cSrcweir 62cdf0e10cSrcweir using namespace osl; 63cdf0e10cSrcweir using namespace cppu; 64cdf0e10cSrcweir using namespace rtl; 65cdf0e10cSrcweir using namespace com::sun::star::sdbc; 66cdf0e10cSrcweir using namespace com::sun::star::frame; 67cdf0e10cSrcweir using namespace com::sun::star::uno; 68cdf0e10cSrcweir using namespace com::sun::star; 69cdf0e10cSrcweir 70cdf0e10cSrcweir #define C2U(cChar) OUString::createFromAscii(cChar) 71cdf0e10cSrcweir 72cdf0e10cSrcweir struct DispatchInfo 73cdf0e10cSrcweir { 74cdf0e10cSrcweir const char* pCommand; 75cdf0e10cSrcweir sal_Int16 nGroupId; 76cdf0e10cSrcweir sal_Bool bActiveConnection; 77cdf0e10cSrcweir }; 78cdf0e10cSrcweir 79cdf0e10cSrcweir struct CacheDispatchInfo 80cdf0e10cSrcweir { 81cdf0e10cSrcweir sal_Int16 nGroupId; 82cdf0e10cSrcweir sal_Bool bActiveConnection; 83cdf0e10cSrcweir }; 84cdf0e10cSrcweir 85cdf0e10cSrcweir // Attention: commands must be sorted by command groups. Implementation is dependent 86cdf0e10cSrcweir // on this!! 87cdf0e10cSrcweir static DispatchInfo SupportedCommandsArray[] = 88cdf0e10cSrcweir { 89cdf0e10cSrcweir { ".uno:Undo" , frame::CommandGroup::EDIT , sal_False }, 90cdf0e10cSrcweir { ".uno:Cut" , frame::CommandGroup::EDIT , sal_False }, 91cdf0e10cSrcweir { ".uno:Copy" , frame::CommandGroup::EDIT , sal_False }, 92cdf0e10cSrcweir { ".uno:Paste" , frame::CommandGroup::EDIT , sal_False }, 93cdf0e10cSrcweir { ".uno:SelectAll" , frame::CommandGroup::EDIT , sal_False }, 94cdf0e10cSrcweir { ".uno:CloseDoc" , frame::CommandGroup::DOCUMENT , sal_False }, 95cdf0e10cSrcweir { ".uno:StatusBarVisible" , frame::CommandGroup::VIEW , sal_False }, 96cdf0e10cSrcweir { ".uno:AvailableToolbars" , frame::CommandGroup::VIEW , sal_False }, 97cdf0e10cSrcweir { ".uno:Bib/standardFilter" , frame::CommandGroup::DATA , sal_True }, 98cdf0e10cSrcweir { ".uno:Bib/DeleteRecord" , frame::CommandGroup::DATA , sal_True }, 99cdf0e10cSrcweir { ".uno:Bib/InsertRecord" , frame::CommandGroup::DATA , sal_True }, 100cdf0e10cSrcweir { ".uno:Bib/query" , frame::CommandGroup::DATA , sal_True }, 101cdf0e10cSrcweir { ".uno:Bib/autoFilter" , frame::CommandGroup::DATA , sal_True }, 102cdf0e10cSrcweir { ".uno:Bib/source" , frame::CommandGroup::DATA , sal_True }, 103cdf0e10cSrcweir { ".uno:Bib/removeFilter" , frame::CommandGroup::DATA , sal_True }, 104cdf0e10cSrcweir { ".uno:Bib/sdbsource" , frame::CommandGroup::DATA , sal_True }, 105cdf0e10cSrcweir { ".uno:Bib/Mapping" , frame::CommandGroup::DATA , sal_True }, 106cdf0e10cSrcweir { 0 , 0 , sal_False } 107cdf0e10cSrcweir }; 108cdf0e10cSrcweir 109cdf0e10cSrcweir typedef ::std::hash_map< ::rtl::OUString, CacheDispatchInfo, rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > CmdToInfoCache; 110cdf0e10cSrcweir 111cdf0e10cSrcweir SV_IMPL_PTRARR( BibStatusDispatchArr, BibStatusDispatchPtr ); 112cdf0e10cSrcweir 113cdf0e10cSrcweir const CmdToInfoCache& GetCommandToInfoCache() 114cdf0e10cSrcweir { 115cdf0e10cSrcweir static sal_Bool bCacheInitialized = sal_False; 116cdf0e10cSrcweir static CmdToInfoCache aCmdToInfoCache; 117cdf0e10cSrcweir 118cdf0e10cSrcweir if ( !bCacheInitialized ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 121cdf0e10cSrcweir if ( !bCacheInitialized ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir sal_Int32 i( 0 ); 124cdf0e10cSrcweir while ( SupportedCommandsArray[i].pCommand != 0 ) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir rtl::OUString aCommand( rtl::OUString::createFromAscii( SupportedCommandsArray[i].pCommand )); 127cdf0e10cSrcweir 128cdf0e10cSrcweir CacheDispatchInfo aDispatchInfo; 129cdf0e10cSrcweir aDispatchInfo.nGroupId = SupportedCommandsArray[i].nGroupId; 130cdf0e10cSrcweir aDispatchInfo.bActiveConnection = SupportedCommandsArray[i].bActiveConnection; 131cdf0e10cSrcweir aCmdToInfoCache.insert( CmdToInfoCache::value_type( aCommand, aDispatchInfo )); 132cdf0e10cSrcweir ++i; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir bCacheInitialized = sal_True; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir return aCmdToInfoCache; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir 142cdf0e10cSrcweir class BibFrameCtrl_Impl : public cppu::WeakImplHelper1 < XFrameActionListener > 143cdf0e10cSrcweir { 144cdf0e10cSrcweir public: 145cdf0e10cSrcweir Mutex aMutex; 146cdf0e10cSrcweir OMultiTypeInterfaceContainerHelper aLC; 147cdf0e10cSrcweir 148cdf0e10cSrcweir BibFrameController_Impl* pController; 149cdf0e10cSrcweir 150cdf0e10cSrcweir BibFrameCtrl_Impl() 151cdf0e10cSrcweir : aLC( aMutex ) 152cdf0e10cSrcweir , pController(0) 153cdf0e10cSrcweir {} 154cdf0e10cSrcweir 155cdf0e10cSrcweir ~BibFrameCtrl_Impl(); 156cdf0e10cSrcweir 157cdf0e10cSrcweir virtual void SAL_CALL frameAction(const FrameActionEvent& aEvent) throw( RuntimeException ); 158cdf0e10cSrcweir virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); 159cdf0e10cSrcweir }; 160cdf0e10cSrcweir 161cdf0e10cSrcweir 162cdf0e10cSrcweir BibFrameCtrl_Impl::~BibFrameCtrl_Impl() 163cdf0e10cSrcweir { 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir void BibFrameCtrl_Impl::frameAction(const FrameActionEvent& aEvent) throw( uno::RuntimeException ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir if ( pController && aEvent.Frame == pController->getFrame()) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir if(aEvent.Action == FrameAction_FRAME_ACTIVATED) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir pController->activate(); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir else if(aEvent.Action == FrameAction_FRAME_DEACTIVATING) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir pController->deactivate(); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir } 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir void BibFrameCtrl_Impl::disposing( const lang::EventObject& /*Source*/ ) 182cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir vos::OGuard aGuard(Application::GetSolarMutex()); 185cdf0e10cSrcweir if ( pController ) 186cdf0e10cSrcweir pController->getFrame()->removeFrameActionListener( this ); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir BibFrameController_Impl::BibFrameController_Impl( const uno::Reference< awt::XWindow > & xComponent, 190cdf0e10cSrcweir BibDataManager* pDataManager) 191cdf0e10cSrcweir :xWindow( xComponent ) 192cdf0e10cSrcweir ,m_xDatMan( pDataManager ) 193cdf0e10cSrcweir ,pDatMan( pDataManager ) 194cdf0e10cSrcweir ,pBibMod(NULL) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir Window* pParent = VCLUnoHelper::GetWindow( xWindow ); 197cdf0e10cSrcweir pParent->SetUniqueId(UID_BIB_FRAME_WINDOW); 198cdf0e10cSrcweir bDisposing=sal_False; 199cdf0e10cSrcweir bHierarchical=sal_True; 200cdf0e10cSrcweir pImp = new BibFrameCtrl_Impl; 201cdf0e10cSrcweir pImp->pController = this; 202cdf0e10cSrcweir pImp->acquire(); 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir BibFrameController_Impl::~BibFrameController_Impl() 206cdf0e10cSrcweir { 207cdf0e10cSrcweir pImp->pController = NULL; 208cdf0e10cSrcweir pImp->release(); 209cdf0e10cSrcweir delete pDatMan; 210cdf0e10cSrcweir if(pBibMod) 211cdf0e10cSrcweir CloseBibModul(pBibMod); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir ::rtl::OUString SAL_CALL BibFrameController_Impl::getImplementationName() throw (::com::sun::star::uno::RuntimeException) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.comp.extensions.Bibliography"); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir sal_Bool SAL_CALL BibFrameController_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (::com::sun::star::uno::RuntimeException) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir return ( 222cdf0e10cSrcweir sServiceName.equalsAscii("com.sun.star.frame.Bibliography") || 223cdf0e10cSrcweir sServiceName.equalsAscii("com.sun.star.frame.Controller") 224cdf0e10cSrcweir ); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL BibFrameController_Impl::getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir // return only top level services ... 230cdf0e10cSrcweir // base services are included there and should be asked by uno-rtti. 231cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > lNames(1); 232cdf0e10cSrcweir lNames[0] = ::rtl::OUString::createFromAscii("com.sun.star.frame.Bibliography"); 233cdf0e10cSrcweir return lNames; 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir void BibFrameController_Impl::attachFrame( const uno::Reference< XFrame > & xArg ) throw (::com::sun::star::uno::RuntimeException) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir xFrame = xArg; 239cdf0e10cSrcweir xFrame->addFrameActionListener( pImp ); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir sal_Bool BibFrameController_Impl::attachModel( const uno::Reference< XModel > & /*xModel*/ ) throw (::com::sun::star::uno::RuntimeException) 243cdf0e10cSrcweir { 244cdf0e10cSrcweir return sal_False; 245cdf0e10cSrcweir } 246cdf0e10cSrcweir 247cdf0e10cSrcweir sal_Bool BibFrameController_Impl::suspend( sal_Bool bSuspend ) throw (::com::sun::star::uno::RuntimeException) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir if ( bSuspend ) 250cdf0e10cSrcweir getFrame()->removeFrameActionListener( pImp ); 251cdf0e10cSrcweir else 252cdf0e10cSrcweir getFrame()->addFrameActionListener( pImp ); 253cdf0e10cSrcweir return sal_True; 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir uno::Any BibFrameController_Impl::getViewData() throw (::com::sun::star::uno::RuntimeException) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir return uno::Any(); 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir void BibFrameController_Impl::restoreViewData( const uno::Any& /*Value*/ ) throw (::com::sun::star::uno::RuntimeException) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir uno::Reference< XFrame > BibFrameController_Impl::getFrame() throw (::com::sun::star::uno::RuntimeException) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir return xFrame; 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir uno::Reference< XModel > BibFrameController_Impl::getModel() throw (::com::sun::star::uno::RuntimeException) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir return uno::Reference< XModel > (); 273cdf0e10cSrcweir } 274cdf0e10cSrcweir 275cdf0e10cSrcweir void BibFrameController_Impl::dispose() throw (::com::sun::star::uno::RuntimeException) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir bDisposing = sal_True; 278cdf0e10cSrcweir lang::EventObject aObject; 279cdf0e10cSrcweir aObject.Source = (XController*)this; 280cdf0e10cSrcweir pImp->aLC.disposeAndClear(aObject); 281cdf0e10cSrcweir m_xDatMan = 0; 282cdf0e10cSrcweir pDatMan = 0; 283cdf0e10cSrcweir aStatusListeners.DeleteAndDestroy( 0, aStatusListeners.Count() ); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir void BibFrameController_Impl::addEventListener( const uno::Reference< lang::XEventListener > & aListener ) throw (::com::sun::star::uno::RuntimeException) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir pImp->aLC.addInterface( ::getCppuType((const Reference< lang::XEventListener >*)0), aListener ); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir void BibFrameController_Impl::removeEventListener( const uno::Reference< lang::XEventListener > & aListener ) throw (::com::sun::star::uno::RuntimeException) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir pImp->aLC.removeInterface( ::getCppuType((const Reference< lang::XEventListener >*)0), aListener ); 294cdf0e10cSrcweir } 295cdf0e10cSrcweir 296cdf0e10cSrcweir uno::Reference< frame::XDispatch > BibFrameController_Impl::queryDispatch( const util::URL& aURL, const rtl::OUString& /*aTarget*/, sal_Int32 /*nSearchFlags*/ ) throw (::com::sun::star::uno::RuntimeException) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir if ( !bDisposing ) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir const CmdToInfoCache& rCmdCache = GetCommandToInfoCache(); 301cdf0e10cSrcweir CmdToInfoCache::const_iterator pIter = rCmdCache.find( aURL.Complete ); 302cdf0e10cSrcweir if ( pIter != rCmdCache.end() ) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir if (( pDatMan->HasActiveConnection() ) || 305cdf0e10cSrcweir ( !pIter->second.bActiveConnection )) 306cdf0e10cSrcweir return (frame::XDispatch*) this; 307cdf0e10cSrcweir } 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir return uno::Reference< frame::XDispatch > (); 311cdf0e10cSrcweir } 312cdf0e10cSrcweir 313cdf0e10cSrcweir uno::Sequence<uno::Reference< XDispatch > > BibFrameController_Impl::queryDispatches( const uno::Sequence<DispatchDescriptor>& aDescripts ) throw (::com::sun::star::uno::RuntimeException) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir uno::Sequence< uno::Reference< XDispatch > > aDispatches( aDescripts.getLength() ); 316cdf0e10cSrcweir for ( sal_Int32 i=0; i<aDescripts.getLength(); ++i ) 317cdf0e10cSrcweir aDispatches[i] = queryDispatch( aDescripts[i].FeatureURL, aDescripts[i].FrameName, aDescripts[i].SearchFlags ); 318cdf0e10cSrcweir return aDispatches; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 321cdf0e10cSrcweir uno::Sequence< ::sal_Int16 > SAL_CALL BibFrameController_Impl::getSupportedCommandGroups() 322cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir uno::Sequence< ::sal_Int16 > aDispatchInfo( 4 ); 325cdf0e10cSrcweir 326cdf0e10cSrcweir aDispatchInfo[0] = frame::CommandGroup::EDIT; 327cdf0e10cSrcweir aDispatchInfo[1] = frame::CommandGroup::DOCUMENT; 328cdf0e10cSrcweir aDispatchInfo[2] = frame::CommandGroup::DATA; 329cdf0e10cSrcweir aDispatchInfo[3] = frame::CommandGroup::VIEW; 330cdf0e10cSrcweir 331cdf0e10cSrcweir return aDispatchInfo; 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir uno::Sequence< frame::DispatchInformation > SAL_CALL BibFrameController_Impl::getConfigurableDispatchInformation( ::sal_Int16 nCommandGroup ) 335cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir const CmdToInfoCache& rCmdCache = GetCommandToInfoCache(); 338cdf0e10cSrcweir 339cdf0e10cSrcweir sal_Bool bGroupFound( sal_False ); 340cdf0e10cSrcweir frame::DispatchInformation aDispatchInfo; 341cdf0e10cSrcweir std::list< frame::DispatchInformation > aDispatchInfoList; 342cdf0e10cSrcweir 343cdf0e10cSrcweir if (( nCommandGroup == frame::CommandGroup::EDIT ) || 344cdf0e10cSrcweir ( nCommandGroup == frame::CommandGroup::DOCUMENT ) || 345cdf0e10cSrcweir ( nCommandGroup == frame::CommandGroup::DATA ) || 346cdf0e10cSrcweir ( nCommandGroup == frame::CommandGroup::VIEW )) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir CmdToInfoCache::const_iterator pIter = rCmdCache.begin(); 349cdf0e10cSrcweir while ( pIter != rCmdCache.end() ) 350cdf0e10cSrcweir { 351cdf0e10cSrcweir if ( pIter->second.nGroupId == nCommandGroup ) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir bGroupFound = sal_True; 354cdf0e10cSrcweir aDispatchInfo.Command = pIter->first; 355cdf0e10cSrcweir aDispatchInfo.GroupId = pIter->second.nGroupId; 356cdf0e10cSrcweir aDispatchInfoList.push_back( aDispatchInfo ); 357cdf0e10cSrcweir } 358cdf0e10cSrcweir else if ( bGroupFound ) 359cdf0e10cSrcweir break; 360cdf0e10cSrcweir 361cdf0e10cSrcweir ++pIter; 362cdf0e10cSrcweir } 363cdf0e10cSrcweir } 364cdf0e10cSrcweir 365cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > aSeq = 366cdf0e10cSrcweir comphelper::containerToSequence< ::com::sun::star::frame::DispatchInformation, std::list< ::com::sun::star::frame::DispatchInformation > >( aDispatchInfoList ); 367cdf0e10cSrcweir 368cdf0e10cSrcweir return aSeq; 369cdf0e10cSrcweir } 370cdf0e10cSrcweir 371cdf0e10cSrcweir sal_Bool canInsertRecords(const Reference< beans::XPropertySet>& _rxCursorSet) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir sal_Int32 nPriv = 0; 374cdf0e10cSrcweir _rxCursorSet->getPropertyValue(C2U("Privileges")) >>= nPriv; 375cdf0e10cSrcweir return ((_rxCursorSet.is() && (nPriv & sdbcx::Privilege::INSERT) != 0)); 376cdf0e10cSrcweir } 377cdf0e10cSrcweir /* -----------------------------08.05.2002 08:58------------------------------ 378cdf0e10cSrcweir 379cdf0e10cSrcweir ---------------------------------------------------------------------------*/ 380cdf0e10cSrcweir sal_Bool BibFrameController_Impl::SaveModified(const Reference< form::runtime::XFormController>& xController) 381cdf0e10cSrcweir { 382cdf0e10cSrcweir if (!xController.is()) 383cdf0e10cSrcweir return sal_False; 384cdf0e10cSrcweir sal_Bool bInserted = sal_False; 385cdf0e10cSrcweir 386cdf0e10cSrcweir Reference< XResultSetUpdate> _xCursor = Reference< XResultSetUpdate>(xController->getModel(), UNO_QUERY); 387cdf0e10cSrcweir 388cdf0e10cSrcweir if (!_xCursor.is()) 389cdf0e10cSrcweir return sal_False; 390cdf0e10cSrcweir 391cdf0e10cSrcweir Reference< beans::XPropertySet> _xSet = Reference< beans::XPropertySet>(_xCursor, UNO_QUERY); 392cdf0e10cSrcweir if (!_xSet.is()) 393cdf0e10cSrcweir return sal_False; 394cdf0e10cSrcweir 395cdf0e10cSrcweir // mu� gespeichert werden ? 396cdf0e10cSrcweir sal_Bool bIsNew = ::comphelper::getBOOL(_xSet->getPropertyValue(C2U("IsNew"))); 397cdf0e10cSrcweir sal_Bool bIsModified = ::comphelper::getBOOL(_xSet->getPropertyValue(C2U("IsModified"))); 398cdf0e10cSrcweir sal_Bool bResult = !bIsModified; 399cdf0e10cSrcweir if (bIsModified) 400cdf0e10cSrcweir { 401cdf0e10cSrcweir try 402cdf0e10cSrcweir { 403cdf0e10cSrcweir if (bIsNew) 404cdf0e10cSrcweir _xCursor->insertRow(); 405cdf0e10cSrcweir else 406cdf0e10cSrcweir _xCursor->updateRow(); 407cdf0e10cSrcweir bResult = sal_True; 408cdf0e10cSrcweir } 409cdf0e10cSrcweir catch(Exception&) 410cdf0e10cSrcweir { 411cdf0e10cSrcweir DBG_ERROR("SaveModified: Exception occured!"); 412cdf0e10cSrcweir } 413cdf0e10cSrcweir 414cdf0e10cSrcweir bInserted = bIsNew && bResult; 415cdf0e10cSrcweir } 416cdf0e10cSrcweir return bResult; 417cdf0e10cSrcweir } 418cdf0e10cSrcweir 419cdf0e10cSrcweir Window* lcl_GetFocusChild( Window* pParent ) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir sal_uInt16 nChildren = pParent->GetChildCount(); 422cdf0e10cSrcweir for( sal_uInt16 nChild = 0; nChild < nChildren; ++nChild) 423cdf0e10cSrcweir { 424cdf0e10cSrcweir Window* pChild = pParent->GetChild( nChild ); 425cdf0e10cSrcweir if(pChild->HasFocus()) 426cdf0e10cSrcweir return pChild; 427cdf0e10cSrcweir Window* pSubChild = lcl_GetFocusChild( pChild ); 428cdf0e10cSrcweir if(pSubChild) 429cdf0e10cSrcweir return pSubChild; 430cdf0e10cSrcweir } 431cdf0e10cSrcweir return 0; 432cdf0e10cSrcweir } 433cdf0e10cSrcweir 434cdf0e10cSrcweir //class XDispatch 435cdf0e10cSrcweir void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequence< beans::PropertyValue >& aArgs) throw (::com::sun::star::uno::RuntimeException) 436cdf0e10cSrcweir { 437cdf0e10cSrcweir if ( !bDisposing ) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir vos::OGuard aGuard(Application::GetSolarMutex()); 440cdf0e10cSrcweir Window* pParent = VCLUnoHelper::GetWindow( xWindow ); 441cdf0e10cSrcweir WaitObject aWaitObject( pParent ); 442cdf0e10cSrcweir 443cdf0e10cSrcweir String aCommand( _rURL.Path); 444cdf0e10cSrcweir if(aCommand.EqualsAscii("Bib/Mapping")) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir pDatMan->CreateMappingDialog(pParent); 447cdf0e10cSrcweir } 448cdf0e10cSrcweir else if(aCommand.EqualsAscii("Bib/source")) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir ChangeDataSource(aArgs); 451cdf0e10cSrcweir } 452cdf0e10cSrcweir else if(aCommand.EqualsAscii("Bib/sdbsource")) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir rtl::OUString aURL = pDatMan->CreateDBChangeDialog(pParent); 455cdf0e10cSrcweir if(aURL.getLength()) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir try 458cdf0e10cSrcweir { 459cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aNewDataSource(2); 460cdf0e10cSrcweir beans::PropertyValue* pProps = aNewDataSource.getArray(); 461cdf0e10cSrcweir pProps[0].Value <<= rtl::OUString(); 462cdf0e10cSrcweir pProps[1].Value <<= aURL; 463cdf0e10cSrcweir ChangeDataSource(aNewDataSource); 464cdf0e10cSrcweir } 465cdf0e10cSrcweir catch(const Exception&) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir DBG_ERROR("Exception catched while changing the data source"); 468cdf0e10cSrcweir } 469cdf0e10cSrcweir } 470cdf0e10cSrcweir } 471cdf0e10cSrcweir else if(aCommand.EqualsAscii("Bib/autoFilter")) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir sal_uInt16 nCount = aStatusListeners.Count(); 474cdf0e10cSrcweir for ( sal_uInt16 n=0; n<nCount; n++ ) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir BibStatusDispatch *pObj = aStatusListeners[n]; 477cdf0e10cSrcweir if ( pObj->aURL.Path == C2U("Bib/removeFilter") ) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir FeatureStateEvent aEvent; 480cdf0e10cSrcweir aEvent.FeatureURL = pObj->aURL; 481cdf0e10cSrcweir aEvent.IsEnabled = sal_True; 482cdf0e10cSrcweir aEvent.Requery = sal_False; 483cdf0e10cSrcweir aEvent.Source = (XDispatch *) this; 484cdf0e10cSrcweir pObj->xListener->statusChanged( aEvent ); 485cdf0e10cSrcweir //break; because there are more than one 486cdf0e10cSrcweir } 487cdf0e10cSrcweir } 488cdf0e10cSrcweir 489cdf0e10cSrcweir const beans::PropertyValue* pPropertyValue = aArgs.getConstArray(); 490cdf0e10cSrcweir uno::Any aValue=pPropertyValue[0].Value; 491cdf0e10cSrcweir rtl::OUString aQuery; 492cdf0e10cSrcweir aValue >>= aQuery; 493cdf0e10cSrcweir 494cdf0e10cSrcweir aValue=pPropertyValue[1].Value; 495cdf0e10cSrcweir rtl::OUString aQueryField; 496cdf0e10cSrcweir aValue >>= aQueryField; 497cdf0e10cSrcweir BibConfig* pConfig = BibModul::GetConfig(); 498cdf0e10cSrcweir pConfig->setQueryField(aQueryField); 499cdf0e10cSrcweir pDatMan->startQueryWith(aQuery); 500cdf0e10cSrcweir } 501cdf0e10cSrcweir else if(aCommand.EqualsAscii("Bib/standardFilter")) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir try 504cdf0e10cSrcweir { 505cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory(); 506cdf0e10cSrcweir 507cdf0e10cSrcweir // build the arguments for the filter dialog to be created 508cdf0e10cSrcweir Sequence< Any > aDialogCreationArgs( 3 ); 509cdf0e10cSrcweir Any* pDialogCreationArgs = aDialogCreationArgs.getArray(); 510cdf0e10cSrcweir // the query composer 511cdf0e10cSrcweir *pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "QueryComposer" ), 512cdf0e10cSrcweir -1, 513cdf0e10cSrcweir makeAny( pDatMan->getParser() ), 514cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE 515cdf0e10cSrcweir ); 516cdf0e10cSrcweir 517cdf0e10cSrcweir // the rowset 518cdf0e10cSrcweir *pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "RowSet" ), 519cdf0e10cSrcweir -1, 520cdf0e10cSrcweir makeAny( pDatMan->getForm() ), 521cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE 522cdf0e10cSrcweir ); 523cdf0e10cSrcweir // the parent window for the dialog 524cdf0e10cSrcweir *pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "ParentWindow" ), 525cdf0e10cSrcweir -1, 526cdf0e10cSrcweir makeAny( xWindow ), 527cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE 528cdf0e10cSrcweir ); 529cdf0e10cSrcweir 530cdf0e10cSrcweir // create the dialog object 531cdf0e10cSrcweir const ::rtl::OUString sDialogServiceName = ::rtl::OUString::createFromAscii( "com.sun.star.sdb.FilterDialog" ); 532cdf0e10cSrcweir uno::Reference< uno::XInterface > xDialog = xORB->createInstanceWithArguments( 533cdf0e10cSrcweir sDialogServiceName, 534cdf0e10cSrcweir aDialogCreationArgs 535cdf0e10cSrcweir ); 536cdf0e10cSrcweir if ( !xDialog.is() ) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir ShowServiceNotAvailableError( VCLUnoHelper::GetWindow( xWindow ), sDialogServiceName, sal_True ); 539cdf0e10cSrcweir } 540cdf0e10cSrcweir else 541cdf0e10cSrcweir { 542cdf0e10cSrcweir // execute it 543cdf0e10cSrcweir uno::Reference< ui::dialogs::XExecutableDialog > xExec( xDialog, UNO_QUERY ); 544cdf0e10cSrcweir DBG_ASSERT( xExec.is(), "BibFrameController_Impl::dispatch: missing an interface on the dialog!" ); 545cdf0e10cSrcweir if ( xExec.is() ) 546cdf0e10cSrcweir if ( xExec->execute( ) ) 547cdf0e10cSrcweir { 548cdf0e10cSrcweir // the dialog has been executed successfully, and the filter on the query composer 549cdf0e10cSrcweir // has been changed 550cdf0e10cSrcweir ::rtl::OUString sNewFilter = pDatMan->getParser()->getFilter(); 551cdf0e10cSrcweir pDatMan->setFilter( sNewFilter ); 552cdf0e10cSrcweir } 553cdf0e10cSrcweir } 554cdf0e10cSrcweir } 555cdf0e10cSrcweir catch( const uno::Exception& ) 556cdf0e10cSrcweir { 557cdf0e10cSrcweir DBG_ERROR( "BibFrameController_Impl::dispatch: caught an exception!" ); 558cdf0e10cSrcweir } 559cdf0e10cSrcweir 560cdf0e10cSrcweir sal_uInt16 nCount = aStatusListeners.Count(); 561cdf0e10cSrcweir for ( sal_uInt16 n=0; n<nCount; n++ ) 562cdf0e10cSrcweir { 563cdf0e10cSrcweir BibStatusDispatch *pObj = aStatusListeners[n]; 564cdf0e10cSrcweir if ( pObj->aURL.Path == C2U("Bib/removeFilter") && pDatMan->getParser().is()) 565cdf0e10cSrcweir { 566cdf0e10cSrcweir FeatureStateEvent aEvent; 567cdf0e10cSrcweir aEvent.FeatureURL = pObj->aURL; 568cdf0e10cSrcweir aEvent.IsEnabled = 0 != pDatMan->getParser()->getFilter().getLength(); 569cdf0e10cSrcweir aEvent.Requery = sal_False; 570cdf0e10cSrcweir aEvent.Source = (XDispatch *) this; 571cdf0e10cSrcweir pObj->xListener->statusChanged( aEvent ); 572cdf0e10cSrcweir } 573cdf0e10cSrcweir } 574cdf0e10cSrcweir } 575cdf0e10cSrcweir else if(aCommand.EqualsAscii("Bib/removeFilter")) 576cdf0e10cSrcweir { 577cdf0e10cSrcweir RemoveFilter(); 578cdf0e10cSrcweir } 579cdf0e10cSrcweir else if(_rURL.Complete.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("slot:5503")) || 580cdf0e10cSrcweir aCommand.EqualsAscii("CloseDoc")) 581cdf0e10cSrcweir { 582cdf0e10cSrcweir Application::PostUserEvent( STATIC_LINK( this, BibFrameController_Impl, 583cdf0e10cSrcweir DisposeHdl ), 0 ); 584cdf0e10cSrcweir 585cdf0e10cSrcweir } 586cdf0e10cSrcweir else if(aCommand.EqualsAscii("Bib/InsertRecord")) 587cdf0e10cSrcweir { 588cdf0e10cSrcweir Reference<form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController(); 589cdf0e10cSrcweir if(SaveModified(xFormCtrl)) 590cdf0e10cSrcweir { 591cdf0e10cSrcweir try 592cdf0e10cSrcweir { 593cdf0e10cSrcweir Reference< sdbc::XResultSet > xCursor( pDatMan->getForm(), UNO_QUERY ); 594cdf0e10cSrcweir xCursor->last(); 595cdf0e10cSrcweir 596cdf0e10cSrcweir Reference< XResultSetUpdate > xUpdateCursor( pDatMan->getForm(), UNO_QUERY ); 597cdf0e10cSrcweir xUpdateCursor->moveToInsertRow(); 598cdf0e10cSrcweir } 599cdf0e10cSrcweir catch(Exception&) 600cdf0e10cSrcweir { 601cdf0e10cSrcweir DBG_ERROR("Exception in last() or moveToInsertRow()"); 602cdf0e10cSrcweir } 603cdf0e10cSrcweir } 604cdf0e10cSrcweir } 605cdf0e10cSrcweir else if(aCommand.EqualsAscii("Bib/DeleteRecord")) 606cdf0e10cSrcweir { 607cdf0e10cSrcweir Reference< ::com::sun::star::sdbc::XResultSet > xCursor(pDatMan->getForm(), UNO_QUERY); 608cdf0e10cSrcweir Reference< XResultSetUpdate > xUpdateCursor(xCursor, UNO_QUERY); 609cdf0e10cSrcweir Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY); 610cdf0e10cSrcweir sal_Bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(C2U("IsNew"))); 611cdf0e10cSrcweir if(!bIsNew) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir sal_uInt32 nCount = 0; 614cdf0e10cSrcweir xSet->getPropertyValue(C2U("RowCount")) >>= nCount; 615cdf0e10cSrcweir // naechste position festellen 616cdf0e10cSrcweir sal_Bool bSuccess = sal_False; 617cdf0e10cSrcweir sal_Bool bLeft = sal_False; 618cdf0e10cSrcweir sal_Bool bRight = sal_False; 619cdf0e10cSrcweir try 620cdf0e10cSrcweir { 621cdf0e10cSrcweir bLeft = xCursor->isLast() && nCount > 1; 622cdf0e10cSrcweir bRight= !xCursor->isLast(); 623cdf0e10cSrcweir // ask for confirmation 624cdf0e10cSrcweir Reference< frame::XController > xCtrl = pImp->pController; 625cdf0e10cSrcweir Reference< form::XConfirmDeleteListener > xConfirm(pDatMan->GetFormController(),UNO_QUERY); 626cdf0e10cSrcweir if (xConfirm.is()) 627cdf0e10cSrcweir { 628cdf0e10cSrcweir sdb::RowChangeEvent aEvent; 629cdf0e10cSrcweir aEvent.Source = Reference< XInterface > (xCursor, UNO_QUERY); 630cdf0e10cSrcweir aEvent.Action = sdb::RowChangeAction::DELETE; 631cdf0e10cSrcweir aEvent.Rows = 1; 632cdf0e10cSrcweir bSuccess = xConfirm->confirmDelete(aEvent); 633cdf0e10cSrcweir } 634cdf0e10cSrcweir 635cdf0e10cSrcweir // das Ding loeschen 636cdf0e10cSrcweir if (bSuccess) 637cdf0e10cSrcweir xUpdateCursor->deleteRow(); 638cdf0e10cSrcweir } 639cdf0e10cSrcweir catch(Exception&) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir bSuccess = sal_False; 642cdf0e10cSrcweir } 643cdf0e10cSrcweir if (bSuccess) 644cdf0e10cSrcweir { 645cdf0e10cSrcweir if (bLeft || bRight) 646cdf0e10cSrcweir xCursor->relative(bRight ? 1 : -1); 647cdf0e10cSrcweir else 648cdf0e10cSrcweir { 649cdf0e10cSrcweir sal_Bool bCanInsert = canInsertRecords(xSet); 650cdf0e10cSrcweir // kann noch ein Datensatz eingefuegt weden 651cdf0e10cSrcweir try 652cdf0e10cSrcweir { 653cdf0e10cSrcweir if (bCanInsert) 654cdf0e10cSrcweir xUpdateCursor->moveToInsertRow(); 655cdf0e10cSrcweir else 656cdf0e10cSrcweir // Datensatz bewegen um Stati neu zu setzen 657cdf0e10cSrcweir xCursor->first(); 658cdf0e10cSrcweir } 659cdf0e10cSrcweir catch(Exception&) 660cdf0e10cSrcweir { 661cdf0e10cSrcweir DBG_ERROR("DeleteRecord : exception caught !"); 662cdf0e10cSrcweir } 663cdf0e10cSrcweir } 664cdf0e10cSrcweir } 665cdf0e10cSrcweir } 666cdf0e10cSrcweir } 667cdf0e10cSrcweir else if(aCommand.EqualsAscii("Cut")) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) ); 670cdf0e10cSrcweir if(pChild) 671cdf0e10cSrcweir { 672cdf0e10cSrcweir KeyEvent aEvent( 0, KEYFUNC_CUT ); 673cdf0e10cSrcweir pChild->KeyInput( aEvent ); 674cdf0e10cSrcweir } 675cdf0e10cSrcweir } 676cdf0e10cSrcweir else if(aCommand.EqualsAscii("Copy")) 677cdf0e10cSrcweir { 678cdf0e10cSrcweir Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) ); 679cdf0e10cSrcweir if(pChild) 680cdf0e10cSrcweir { 681cdf0e10cSrcweir KeyEvent aEvent( 0, KEYFUNC_COPY ); 682cdf0e10cSrcweir pChild->KeyInput( aEvent ); 683cdf0e10cSrcweir } 684cdf0e10cSrcweir } 685cdf0e10cSrcweir else if(aCommand.EqualsAscii("Paste")) 686cdf0e10cSrcweir { 687cdf0e10cSrcweir Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) ); 688cdf0e10cSrcweir if(pChild) 689cdf0e10cSrcweir { 690cdf0e10cSrcweir KeyEvent aEvent( 0, KEYFUNC_PASTE ); 691cdf0e10cSrcweir pChild->KeyInput( aEvent ); 692cdf0e10cSrcweir } 693cdf0e10cSrcweir } 694cdf0e10cSrcweir } 695cdf0e10cSrcweir } 696cdf0e10cSrcweir IMPL_STATIC_LINK( BibFrameController_Impl, DisposeHdl, void*, EMPTYARG ) 697cdf0e10cSrcweir { 698cdf0e10cSrcweir pThis->xFrame->dispose(); 699cdf0e10cSrcweir return 0; 700cdf0e10cSrcweir }; 701cdf0e10cSrcweir 702cdf0e10cSrcweir //----------------------------------------------------------------------------- 703cdf0e10cSrcweir void BibFrameController_Impl::addStatusListener( 704cdf0e10cSrcweir const uno::Reference< frame::XStatusListener > & aListener, 705cdf0e10cSrcweir const util::URL& aURL) 706cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 707cdf0e10cSrcweir { 708cdf0e10cSrcweir BibConfig* pConfig = BibModul::GetConfig(); 709cdf0e10cSrcweir // create a new Reference and insert into listener array 710cdf0e10cSrcweir aStatusListeners.Insert( new BibStatusDispatch( aURL, aListener ), aStatusListeners.Count() ); 711cdf0e10cSrcweir 712cdf0e10cSrcweir // den ersten Status synchron zusenden 713cdf0e10cSrcweir FeatureStateEvent aEvent; 714cdf0e10cSrcweir aEvent.FeatureURL = aURL; 715cdf0e10cSrcweir aEvent.Requery = sal_False; 716cdf0e10cSrcweir aEvent.Source = (XDispatch *) this; 717cdf0e10cSrcweir if ( aURL.Path == C2U("StatusBarVisible") ) 718cdf0e10cSrcweir { 719cdf0e10cSrcweir aEvent.IsEnabled = sal_False; 720cdf0e10cSrcweir aEvent.State <<= sal_Bool( sal_False ); 721cdf0e10cSrcweir } 722cdf0e10cSrcweir else if ( aURL.Path == C2U("Bib/hierarchical") ) 723cdf0e10cSrcweir { 724cdf0e10cSrcweir aEvent.IsEnabled = sal_True; 725cdf0e10cSrcweir const char* pHier = bHierarchical? "" : "*" ; 726cdf0e10cSrcweir aEvent.State <<= rtl::OUString::createFromAscii(pHier); 727cdf0e10cSrcweir } 728cdf0e10cSrcweir else if(aURL.Path == C2U("Bib/MenuFilter")) 729cdf0e10cSrcweir { 730cdf0e10cSrcweir aEvent.IsEnabled = sal_True; 731cdf0e10cSrcweir aEvent.FeatureDescriptor=pDatMan->getQueryField(); 732cdf0e10cSrcweir 733cdf0e10cSrcweir uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getQueryFields(); 734cdf0e10cSrcweir aEvent.State.setValue(&aStringSeq,::getCppuType((uno::Sequence<rtl::OUString>*)0)); 735cdf0e10cSrcweir 736cdf0e10cSrcweir } 737cdf0e10cSrcweir else if ( aURL.Path == C2U("Bib/source")) 738cdf0e10cSrcweir { 739cdf0e10cSrcweir aEvent.IsEnabled = sal_True; 740cdf0e10cSrcweir aEvent.FeatureDescriptor=pDatMan->getActiveDataTable(); 741cdf0e10cSrcweir 742cdf0e10cSrcweir uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getDataSources(); 743cdf0e10cSrcweir aEvent.State.setValue(&aStringSeq,::getCppuType((uno::Sequence<rtl::OUString>*)0)); 744cdf0e10cSrcweir } 745cdf0e10cSrcweir else if(aURL.Path == C2U("Bib/sdbsource") || 746cdf0e10cSrcweir aURL.Path == C2U("Bib/Mapping") || 747cdf0e10cSrcweir aURL.Path == C2U("Bib/autoFilter") || 748cdf0e10cSrcweir aURL.Path.equalsAscii("Bib/standardFilter")) 749cdf0e10cSrcweir { 750cdf0e10cSrcweir aEvent.IsEnabled = sal_True; 751cdf0e10cSrcweir } 752cdf0e10cSrcweir else if(aURL.Path == C2U("Bib/query")) 753cdf0e10cSrcweir { 754cdf0e10cSrcweir aEvent.IsEnabled = sal_True; 755cdf0e10cSrcweir aEvent.State <<= pConfig->getQueryText(); 756cdf0e10cSrcweir } 757cdf0e10cSrcweir else if (aURL.Path == C2U("Bib/removeFilter") ) 758cdf0e10cSrcweir { 759cdf0e10cSrcweir rtl::OUString aFilterStr=pDatMan->getFilter(); 760cdf0e10cSrcweir aEvent.IsEnabled = (aFilterStr.getLength() > 0); 761cdf0e10cSrcweir } 762cdf0e10cSrcweir else if(aURL.Path == C2U("Cut")) 763cdf0e10cSrcweir { 764cdf0e10cSrcweir Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) ); 765cdf0e10cSrcweir Edit* pEdit = dynamic_cast<Edit*>( pChild ); 766cdf0e10cSrcweir if( pEdit ) 767cdf0e10cSrcweir aEvent.IsEnabled = !pEdit->IsReadOnly() && pEdit->GetSelection().Len(); 768cdf0e10cSrcweir } 769cdf0e10cSrcweir if(aURL.Path == C2U("Copy")) 770cdf0e10cSrcweir { 771cdf0e10cSrcweir Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) ); 772cdf0e10cSrcweir Edit* pEdit = dynamic_cast<Edit*>( pChild ); 773cdf0e10cSrcweir if( pEdit ) 774cdf0e10cSrcweir aEvent.IsEnabled = pEdit->GetSelection().Len() > 0; 775cdf0e10cSrcweir } 776cdf0e10cSrcweir else if(aURL.Path == C2U("Paste") ) 777cdf0e10cSrcweir { 778cdf0e10cSrcweir aEvent.IsEnabled = sal_False; 779cdf0e10cSrcweir Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) ); 780cdf0e10cSrcweir if(pChild) 781cdf0e10cSrcweir { 782cdf0e10cSrcweir uno::Reference< datatransfer::clipboard::XClipboard > xClip = pChild->GetClipboard(); 783cdf0e10cSrcweir if(xClip.is()) 784cdf0e10cSrcweir { 785cdf0e10cSrcweir uno::Reference< datatransfer::XTransferable > xDataObj; 786cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 787cdf0e10cSrcweir try 788cdf0e10cSrcweir { 789cdf0e10cSrcweir xDataObj = xClip->getContents(); 790cdf0e10cSrcweir } 791cdf0e10cSrcweir catch( const uno::Exception& ) 792cdf0e10cSrcweir { 793cdf0e10cSrcweir } 794cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 795cdf0e10cSrcweir 796cdf0e10cSrcweir if ( xDataObj.is() ) 797cdf0e10cSrcweir { 798cdf0e10cSrcweir datatransfer::DataFlavor aFlavor; 799cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor ); 800cdf0e10cSrcweir try 801cdf0e10cSrcweir { 802cdf0e10cSrcweir uno::Any aData = xDataObj->getTransferData( aFlavor ); 803cdf0e10cSrcweir ::rtl::OUString aText; 804cdf0e10cSrcweir aData >>= aText; 805cdf0e10cSrcweir aEvent.IsEnabled = aText.getLength() > 0; 806cdf0e10cSrcweir } 807cdf0e10cSrcweir catch( const uno::Exception& ) 808cdf0e10cSrcweir { 809cdf0e10cSrcweir } 810cdf0e10cSrcweir } 811cdf0e10cSrcweir } 812cdf0e10cSrcweir uno::Reference< datatransfer::XTransferable > xContents = xClip->getContents( ); 813cdf0e10cSrcweir } 814cdf0e10cSrcweir } 815cdf0e10cSrcweir else if(aURL.Path == C2U("Bib/DeleteRecord")) 816cdf0e10cSrcweir { 817cdf0e10cSrcweir Reference< ::com::sun::star::sdbc::XResultSet > xCursor(pDatMan->getForm(), UNO_QUERY); 818cdf0e10cSrcweir Reference< XResultSetUpdate > xUpdateCursor(xCursor, UNO_QUERY); 819cdf0e10cSrcweir Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY); 820cdf0e10cSrcweir sal_Bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(C2U("IsNew"))); 821cdf0e10cSrcweir if(!bIsNew) 822cdf0e10cSrcweir { 823cdf0e10cSrcweir sal_uInt32 nCount = 0; 824cdf0e10cSrcweir xSet->getPropertyValue(C2U("RowCount")) >>= nCount; 825cdf0e10cSrcweir aEvent.IsEnabled = nCount > 0; 826cdf0e10cSrcweir } 827cdf0e10cSrcweir } 828cdf0e10cSrcweir else if (aURL.Path == C2U("Bib/InsertRecord")) 829cdf0e10cSrcweir { 830cdf0e10cSrcweir Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY); 831cdf0e10cSrcweir aEvent.IsEnabled = canInsertRecords(xSet); 832cdf0e10cSrcweir } 833cdf0e10cSrcweir aListener->statusChanged( aEvent ); 834cdf0e10cSrcweir } 835cdf0e10cSrcweir //----------------------------------------------------------------------------- 836cdf0e10cSrcweir void BibFrameController_Impl::removeStatusListener( 837cdf0e10cSrcweir const uno::Reference< frame::XStatusListener > & aObject, const util::URL& aURL) 838cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 839cdf0e10cSrcweir { 840cdf0e10cSrcweir // search listener array for given listener 841cdf0e10cSrcweir // for checking equality always "cast" to XInterface 842cdf0e10cSrcweir if ( !bDisposing ) 843cdf0e10cSrcweir { 844cdf0e10cSrcweir sal_uInt16 nCount = aStatusListeners.Count(); 845cdf0e10cSrcweir for ( sal_uInt16 n=0; n<nCount; n++ ) 846cdf0e10cSrcweir { 847cdf0e10cSrcweir BibStatusDispatch *pObj = aStatusListeners[n]; 848cdf0e10cSrcweir sal_Bool bFlag=pObj->xListener.is(); 849cdf0e10cSrcweir if (!bFlag || (pObj->xListener == aObject && 850cdf0e10cSrcweir ( !aURL.Complete.getLength() || pObj->aURL.Path == aURL.Path ))) 851cdf0e10cSrcweir { 852cdf0e10cSrcweir aStatusListeners.DeleteAndDestroy( n ); 853cdf0e10cSrcweir break; 854cdf0e10cSrcweir } 855cdf0e10cSrcweir } 856cdf0e10cSrcweir } 857cdf0e10cSrcweir } 858cdf0e10cSrcweir //----------------------------------------------------------------------------- 859cdf0e10cSrcweir void BibFrameController_Impl::RemoveFilter() 860cdf0e10cSrcweir { 861cdf0e10cSrcweir rtl::OUString aQuery; 862cdf0e10cSrcweir pDatMan->startQueryWith(aQuery); 863cdf0e10cSrcweir 864cdf0e10cSrcweir sal_uInt16 nCount = aStatusListeners.Count(); 865cdf0e10cSrcweir 866cdf0e10cSrcweir sal_Bool bRemoveFilter=sal_False; 867cdf0e10cSrcweir sal_Bool bQueryText=sal_False; 868cdf0e10cSrcweir 869cdf0e10cSrcweir for ( sal_uInt16 n=0; n<nCount; n++ ) 870cdf0e10cSrcweir { 871cdf0e10cSrcweir BibStatusDispatch *pObj = aStatusListeners[n]; 872cdf0e10cSrcweir if ( pObj->aURL.Path == C2U("Bib/removeFilter") ) 873cdf0e10cSrcweir { 874cdf0e10cSrcweir FeatureStateEvent aEvent; 875cdf0e10cSrcweir aEvent.FeatureURL = pObj->aURL; 876cdf0e10cSrcweir aEvent.IsEnabled = sal_False; 877cdf0e10cSrcweir aEvent.Requery = sal_False; 878cdf0e10cSrcweir aEvent.Source = (XDispatch *) this; 879cdf0e10cSrcweir pObj->xListener->statusChanged( aEvent ); 880cdf0e10cSrcweir bRemoveFilter=sal_True; 881cdf0e10cSrcweir } 882cdf0e10cSrcweir else if(pObj->aURL.Path == C2U("Bib/query")) 883cdf0e10cSrcweir { 884cdf0e10cSrcweir FeatureStateEvent aEvent; 885cdf0e10cSrcweir aEvent.FeatureURL = pObj->aURL; 886cdf0e10cSrcweir aEvent.IsEnabled = sal_True; 887cdf0e10cSrcweir aEvent.Requery = sal_False; 888cdf0e10cSrcweir aEvent.Source = (XDispatch *) this; 889cdf0e10cSrcweir aEvent.State <<= aQuery; 890cdf0e10cSrcweir pObj->xListener->statusChanged( aEvent ); 891cdf0e10cSrcweir bQueryText=sal_True; 892cdf0e10cSrcweir } 893cdf0e10cSrcweir 894cdf0e10cSrcweir if(bRemoveFilter && bQueryText) 895cdf0e10cSrcweir break; 896cdf0e10cSrcweir 897cdf0e10cSrcweir } 898cdf0e10cSrcweir } 899cdf0e10cSrcweir //----------------------------------------------------------------------------- 900cdf0e10cSrcweir void BibFrameController_Impl::ChangeDataSource(const uno::Sequence< beans::PropertyValue >& aArgs) 901cdf0e10cSrcweir { 902cdf0e10cSrcweir const beans::PropertyValue* pPropertyValue = aArgs.getConstArray(); 903cdf0e10cSrcweir uno::Any aValue=pPropertyValue[0].Value; 904cdf0e10cSrcweir rtl::OUString aDBTableName; 905cdf0e10cSrcweir aValue >>= aDBTableName; 906cdf0e10cSrcweir 907cdf0e10cSrcweir 908cdf0e10cSrcweir if(aArgs.getLength() > 1) 909cdf0e10cSrcweir { 910cdf0e10cSrcweir uno::Any aDB = pPropertyValue[1].Value; 911cdf0e10cSrcweir rtl::OUString aURL; 912cdf0e10cSrcweir aDB >>= aURL; 913cdf0e10cSrcweir pDatMan->setActiveDataSource(aURL); 914cdf0e10cSrcweir aDBTableName = pDatMan->getActiveDataTable(); 915cdf0e10cSrcweir } 916cdf0e10cSrcweir else 917cdf0e10cSrcweir { 918cdf0e10cSrcweir m_xDatMan->unload(); 919cdf0e10cSrcweir pDatMan->setActiveDataTable(aDBTableName); 920cdf0e10cSrcweir pDatMan->updateGridModel(); 921cdf0e10cSrcweir m_xDatMan->load(); 922cdf0e10cSrcweir } 923cdf0e10cSrcweir 924cdf0e10cSrcweir 925cdf0e10cSrcweir sal_uInt16 nCount = aStatusListeners.Count(); 926cdf0e10cSrcweir 927cdf0e10cSrcweir sal_Bool bMenuFilter=sal_False; 928cdf0e10cSrcweir sal_Bool bQueryText=sal_False; 929cdf0e10cSrcweir for ( sal_uInt16 n=0; n<nCount; n++ ) 930cdf0e10cSrcweir { 931cdf0e10cSrcweir BibStatusDispatch *pObj = aStatusListeners[n]; 932cdf0e10cSrcweir if(COMPARE_EQUAL == pObj->aURL.Path.compareToAscii("Bib/MenuFilter")) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir FeatureStateEvent aEvent; 935cdf0e10cSrcweir aEvent.FeatureURL = pObj->aURL; 936cdf0e10cSrcweir aEvent.IsEnabled = sal_True; 937cdf0e10cSrcweir aEvent.Requery = sal_False; 938cdf0e10cSrcweir aEvent.Source = (XDispatch *) this; 939cdf0e10cSrcweir aEvent.FeatureDescriptor=pDatMan->getQueryField(); 940cdf0e10cSrcweir 941cdf0e10cSrcweir uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getQueryFields(); 942cdf0e10cSrcweir aEvent.State = makeAny( aStringSeq ); 943cdf0e10cSrcweir 944cdf0e10cSrcweir pObj->xListener->statusChanged( aEvent ); 945cdf0e10cSrcweir bMenuFilter=sal_True; 946cdf0e10cSrcweir } 947cdf0e10cSrcweir else if(COMPARE_EQUAL == pObj->aURL.Path.compareToAscii("Bib/query")) 948cdf0e10cSrcweir { 949cdf0e10cSrcweir FeatureStateEvent aEvent; 950cdf0e10cSrcweir aEvent.FeatureURL = pObj->aURL; 951cdf0e10cSrcweir aEvent.IsEnabled = sal_True; 952cdf0e10cSrcweir aEvent.Requery = sal_False; 953cdf0e10cSrcweir aEvent.Source = (XDispatch *) this; 954cdf0e10cSrcweir BibConfig* pConfig = BibModul::GetConfig(); 955cdf0e10cSrcweir aEvent.State <<= pConfig->getQueryText(); 956cdf0e10cSrcweir pObj->xListener->statusChanged( aEvent ); 957cdf0e10cSrcweir bQueryText=sal_True; 958cdf0e10cSrcweir } 959cdf0e10cSrcweir 960cdf0e10cSrcweir if (bMenuFilter && bQueryText) 961cdf0e10cSrcweir break; 962cdf0e10cSrcweir 963cdf0e10cSrcweir } 964cdf0e10cSrcweir } 965cdf0e10cSrcweir 966cdf0e10cSrcweir void BibFrameController_Impl::activate() 967cdf0e10cSrcweir { 968cdf0e10cSrcweir } 969cdf0e10cSrcweir void BibFrameController_Impl::deactivate() 970cdf0e10cSrcweir { 971cdf0e10cSrcweir } 972cdf0e10cSrcweir 973cdf0e10cSrcweir 974