LCOV - code coverage report
Current view: top level - extensions/source/bibliography - framectr.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 464 0.2 %
Date: 2014-11-03 Functions: 2 40 5.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10