1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
28 #include "bibview.hxx"
29 #include "bibresid.hxx"
31 #include <toolkit/helper/vclunohelper.hxx>
32 #include "bibconfig.hxx"
33 #include <cppuhelper/implbase.hxx>
34 #include <vcl/svapp.hxx>
35 #include "bibliography.hrc"
36 #include <comphelper/processfactory.hxx>
37 #include <com/sun/star/form/XConfirmDeleteListener.hpp>
38 #include <com/sun/star/form/runtime/XFormController.hpp>
39 #include <com/sun/star/beans/PropertyState.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
42 #include <com/sun/star/sdbcx/Privilege.hpp>
43 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
44 #include <com/sun/star/sdb/FilterDialog.hpp>
45 #include <com/sun/star/sdb/RowChangeAction.hpp>
46 #include <com/sun/star/frame/CommandGroup.hpp>
47 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
48 #include <cppuhelper/interfacecontainer.hxx>
49 #include <cppuhelper/supportsservice.hxx>
50 #include <sot/exchange.hxx>
51 #include <sot/formats.hxx>
52 #include <vcl/edit.hxx>
53 #include <osl/mutex.hxx>
54 #include <o3tl/make_unique.hxx>
56 #include <unordered_map>
60 using namespace com::sun::star::sdbc
;
61 using namespace com::sun::star::frame
;
62 using namespace com::sun::star::uno
;
63 using namespace com::sun::star
;
70 bool bActiveConnection
;
73 struct CacheDispatchInfo
76 bool bActiveConnection
;
79 // Attention: commands must be sorted by command groups. Implementation is dependent
81 static const DispatchInfo SupportedCommandsArray
[] =
83 { ".uno:Undo" , frame::CommandGroup::EDIT
, false },
84 { ".uno:Cut" , frame::CommandGroup::EDIT
, false },
85 { ".uno:Copy" , frame::CommandGroup::EDIT
, false },
86 { ".uno:Paste" , frame::CommandGroup::EDIT
, false },
87 { ".uno:SelectAll" , frame::CommandGroup::EDIT
, false },
88 { ".uno:CloseDoc" , frame::CommandGroup::DOCUMENT
, false },
89 { ".uno:StatusBarVisible" , frame::CommandGroup::VIEW
, false },
90 { ".uno:AvailableToolbars" , frame::CommandGroup::VIEW
, false },
91 { ".uno:Bib/standardFilter" , frame::CommandGroup::DATA
, true },
92 { ".uno:Bib/DeleteRecord" , frame::CommandGroup::DATA
, true },
93 { ".uno:Bib/InsertRecord" , frame::CommandGroup::DATA
, true },
94 { ".uno:Bib/query" , frame::CommandGroup::DATA
, true },
95 { ".uno:Bib/autoFilter" , frame::CommandGroup::DATA
, true },
96 { ".uno:Bib/source" , frame::CommandGroup::DATA
, true },
97 { ".uno:Bib/removeFilter" , frame::CommandGroup::DATA
, true },
98 { ".uno:Bib/sdbsource" , frame::CommandGroup::DATA
, true },
99 { ".uno:Bib/Mapping" , frame::CommandGroup::DATA
, true },
100 { nullptr , 0 , false }
103 typedef std::unordered_map
< OUString
, CacheDispatchInfo
, OUStringHash
> CmdToInfoCache
;
105 const CmdToInfoCache
& GetCommandToInfoCache()
107 static bool bCacheInitialized
= false;
108 static CmdToInfoCache aCmdToInfoCache
;
110 if ( !bCacheInitialized
)
112 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
113 if ( !bCacheInitialized
)
116 while ( SupportedCommandsArray
[i
].pCommand
!= nullptr )
118 OUString
aCommand( OUString::createFromAscii( SupportedCommandsArray
[i
].pCommand
));
120 CacheDispatchInfo aDispatchInfo
;
121 aDispatchInfo
.nGroupId
= SupportedCommandsArray
[i
].nGroupId
;
122 aDispatchInfo
.bActiveConnection
= SupportedCommandsArray
[i
].bActiveConnection
;
123 aCmdToInfoCache
.insert( CmdToInfoCache::value_type( aCommand
, aDispatchInfo
));
126 bCacheInitialized
= true;
130 return aCmdToInfoCache
;
134 class BibFrameCtrl_Impl
: public cppu::WeakImplHelper
< XFrameActionListener
>
138 OMultiTypeInterfaceContainerHelper aLC
;
140 BibFrameController_Impl
* pController
;
144 , pController(nullptr)
147 virtual void SAL_CALL
frameAction(const FrameActionEvent
& aEvent
) override
;
148 virtual void SAL_CALL
disposing( const lang::EventObject
& Source
) override
;
151 void BibFrameCtrl_Impl::frameAction(const FrameActionEvent
& )
155 void BibFrameCtrl_Impl::disposing( const lang::EventObject
& /*Source*/ )
157 ::SolarMutexGuard aGuard
;
159 pController
->getFrame()->removeFrameActionListener( this );
162 BibFrameController_Impl::BibFrameController_Impl( const uno::Reference
< awt::XWindow
> & xComponent
,
163 BibDataManager
* pDataManager
)
164 :xWindow( xComponent
)
165 ,m_xDatMan( pDataManager
)
170 mxImpl
= new BibFrameCtrl_Impl
;
171 mxImpl
->pController
= this;
174 BibFrameController_Impl::~BibFrameController_Impl()
176 mxImpl
->pController
= nullptr;
179 CloseBibModul(pBibMod
);
182 OUString SAL_CALL
BibFrameController_Impl::getImplementationName()
184 return OUString("com.sun.star.comp.extensions.Bibliography");
187 sal_Bool SAL_CALL
BibFrameController_Impl::supportsService( const OUString
& sServiceName
)
189 return cppu::supportsService( this, sServiceName
);
192 css::uno::Sequence
< OUString
> SAL_CALL
BibFrameController_Impl::getSupportedServiceNames()
194 // return only top level services ...
195 // base services are included there and should be asked by uno-rtti.
196 css::uno::Sequence
< OUString
> lNames
{ "com.sun.star.frame.Bibliography" };
200 void BibFrameController_Impl::attachFrame( const uno::Reference
< XFrame
> & xArg
)
203 xFrame
->addFrameActionListener( mxImpl
.get() );
206 sal_Bool
BibFrameController_Impl::attachModel( const uno::Reference
< XModel
> & /*xModel*/ )
211 sal_Bool
BibFrameController_Impl::suspend( sal_Bool bSuspend
)
214 getFrame()->removeFrameActionListener( mxImpl
.get() );
216 getFrame()->addFrameActionListener( mxImpl
.get() );
220 uno::Any
BibFrameController_Impl::getViewData()
225 void BibFrameController_Impl::restoreViewData( const uno::Any
& /*Value*/ )
229 uno::Reference
< XFrame
> BibFrameController_Impl::getFrame()
234 uno::Reference
< XModel
> BibFrameController_Impl::getModel()
236 return uno::Reference
< XModel
> ();
239 void BibFrameController_Impl::dispose()
242 lang::EventObject aObject
;
243 aObject
.Source
= static_cast<XController
*>(this);
244 mxImpl
->aLC
.disposeAndClear(aObject
);
246 aStatusListeners
.clear();
249 void BibFrameController_Impl::addEventListener( const uno::Reference
< lang::XEventListener
> & aListener
)
251 mxImpl
->aLC
.addInterface( cppu::UnoType
<lang::XEventListener
>::get(), aListener
);
254 void BibFrameController_Impl::removeEventListener( const uno::Reference
< lang::XEventListener
> & aListener
)
256 mxImpl
->aLC
.removeInterface( cppu::UnoType
<lang::XEventListener
>::get(), aListener
);
259 uno::Reference
< frame::XDispatch
> BibFrameController_Impl::queryDispatch( const util::URL
& aURL
, const OUString
& /*aTarget*/, sal_Int32
/*nSearchFlags*/ )
263 const CmdToInfoCache
& rCmdCache
= GetCommandToInfoCache();
264 CmdToInfoCache::const_iterator pIter
= rCmdCache
.find( aURL
.Complete
);
265 if ( pIter
!= rCmdCache
.end() )
267 if (( m_xDatMan
->HasActiveConnection() ) ||
268 ( !pIter
->second
.bActiveConnection
))
269 return static_cast<frame::XDispatch
*>(this);
273 return uno::Reference
< frame::XDispatch
> ();
276 uno::Sequence
<uno::Reference
< XDispatch
> > BibFrameController_Impl::queryDispatches( const uno::Sequence
<DispatchDescriptor
>& aDescripts
)
278 uno::Sequence
< uno::Reference
< XDispatch
> > aDispatches( aDescripts
.getLength() );
279 for ( sal_Int32 i
=0; i
<aDescripts
.getLength(); ++i
)
280 aDispatches
[i
] = queryDispatch( aDescripts
[i
].FeatureURL
, aDescripts
[i
].FrameName
, aDescripts
[i
].SearchFlags
);
284 uno::Sequence
< ::sal_Int16
> SAL_CALL
BibFrameController_Impl::getSupportedCommandGroups()
286 uno::Sequence
< ::sal_Int16
> aDispatchInfo( 4 );
288 aDispatchInfo
[0] = frame::CommandGroup::EDIT
;
289 aDispatchInfo
[1] = frame::CommandGroup::DOCUMENT
;
290 aDispatchInfo
[2] = frame::CommandGroup::DATA
;
291 aDispatchInfo
[3] = frame::CommandGroup::VIEW
;
293 return aDispatchInfo
;
296 uno::Sequence
< frame::DispatchInformation
> SAL_CALL
BibFrameController_Impl::getConfigurableDispatchInformation( ::sal_Int16 nCommandGroup
)
298 const CmdToInfoCache
& rCmdCache
= GetCommandToInfoCache();
300 frame::DispatchInformation aDispatchInfo
;
301 std::list
< frame::DispatchInformation
> aDispatchInfoList
;
303 if (( nCommandGroup
== frame::CommandGroup::EDIT
) ||
304 ( nCommandGroup
== frame::CommandGroup::DOCUMENT
) ||
305 ( nCommandGroup
== frame::CommandGroup::DATA
) ||
306 ( nCommandGroup
== frame::CommandGroup::VIEW
))
308 bool bGroupFound
= false;
309 CmdToInfoCache::const_iterator pIter
= rCmdCache
.begin();
310 while ( pIter
!= rCmdCache
.end() )
312 if ( pIter
->second
.nGroupId
== nCommandGroup
)
315 aDispatchInfo
.Command
= pIter
->first
;
316 aDispatchInfo
.GroupId
= pIter
->second
.nGroupId
;
317 aDispatchInfoList
.push_back( aDispatchInfo
);
319 else if ( bGroupFound
)
326 return comphelper::containerToSequence( aDispatchInfoList
);
329 bool canInsertRecords(const Reference
< beans::XPropertySet
>& _rxCursorSet
)
332 _rxCursorSet
->getPropertyValue("Privileges") >>= nPriv
;
333 return ((_rxCursorSet
.is() && (nPriv
& sdbcx::Privilege::INSERT
) != 0));
336 bool BibFrameController_Impl::SaveModified(const Reference
< form::runtime::XFormController
>& xController
)
338 if (!xController
.is())
341 Reference
< XResultSetUpdate
> _xCursor(xController
->getModel(), UNO_QUERY
);
346 Reference
< beans::XPropertySet
> _xSet(_xCursor
, UNO_QUERY
);
351 bool bIsNew
= ::comphelper::getBOOL(_xSet
->getPropertyValue("IsNew"));
352 bool bIsModified
= ::comphelper::getBOOL(_xSet
->getPropertyValue("IsModified"));
353 bool bResult
= !bIsModified
;
359 _xCursor
->insertRow();
361 _xCursor
->updateRow();
364 catch(const Exception
&)
366 OSL_FAIL("SaveModified: Exception occurred!");
372 static vcl::Window
* lcl_GetFocusChild( vcl::Window
* pParent
)
374 sal_uInt16 nChildren
= pParent
->GetChildCount();
375 for( sal_uInt16 nChild
= 0; nChild
< nChildren
; ++nChild
)
377 vcl::Window
* pChild
= pParent
->GetChild( nChild
);
378 if(pChild
->HasFocus())
380 vcl::Window
* pSubChild
= lcl_GetFocusChild( pChild
);
388 void BibFrameController_Impl::dispatch(const util::URL
& _rURL
, const uno::Sequence
< beans::PropertyValue
>& aArgs
)
392 ::SolarMutexGuard aGuard
;
393 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow( xWindow
);
394 WaitObject
aWaitObject( pParent
);
396 OUString
aCommand( _rURL
.Path
);
397 if(aCommand
== "Bib/Mapping")
399 m_xDatMan
->CreateMappingDialog(pParent
);
401 else if(aCommand
== "Bib/source")
403 ChangeDataSource(aArgs
);
405 else if(aCommand
== "Bib/sdbsource")
407 OUString aURL
= m_xDatMan
->CreateDBChangeDialog(pParent
);
412 uno::Sequence
< beans::PropertyValue
> aNewDataSource(2);
413 beans::PropertyValue
* pProps
= aNewDataSource
.getArray();
414 pProps
[0].Value
<<= OUString();
415 pProps
[1].Value
<<= aURL
;
416 ChangeDataSource(aNewDataSource
);
418 catch(const Exception
&)
420 OSL_FAIL("Exception catched while changing the data source");
424 else if(aCommand
== "Bib/autoFilter")
426 sal_uInt16 nCount
= aStatusListeners
.size();
427 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
429 BibStatusDispatch
*pObj
= aStatusListeners
[n
].get();
430 if ( pObj
->aURL
.Path
== "Bib/removeFilter" )
432 FeatureStateEvent aEvent
;
433 aEvent
.FeatureURL
= pObj
->aURL
;
434 aEvent
.IsEnabled
= true;
435 aEvent
.Requery
= false;
436 aEvent
.Source
= static_cast<XDispatch
*>(this);
437 pObj
->xListener
->statusChanged( aEvent
);
438 //break; because there are more than one
442 const beans::PropertyValue
* pPropertyValue
= aArgs
.getConstArray();
443 uno::Any aValue
=pPropertyValue
[0].Value
;
447 aValue
=pPropertyValue
[1].Value
;
448 OUString aQueryField
;
449 aValue
>>= aQueryField
;
450 BibConfig
* pConfig
= BibModul::GetConfig();
451 pConfig
->setQueryField(aQueryField
);
452 m_xDatMan
->startQueryWith(aQuery
);
454 else if(aCommand
== "Bib/standardFilter")
458 uno::Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
460 // create the dialog object
461 uno::Reference
< ui::dialogs::XExecutableDialog
> xDialog
= sdb::FilterDialog::createWithQuery(xContext
, m_xDatMan
->getParser(),
462 Reference
<sdbc::XRowSet
>(m_xDatMan
->getForm(), uno::UNO_QUERY_THROW
), xWindow
);
464 if ( xDialog
->execute( ) )
466 // the dialog has been executed successfully, and the filter on the query composer
468 OUString sNewFilter
= m_xDatMan
->getParser()->getFilter();
469 m_xDatMan
->setFilter( sNewFilter
);
472 catch( const uno::Exception
& )
474 OSL_FAIL( "BibFrameController_Impl::dispatch: caught an exception!" );
477 sal_uInt16 nCount
= aStatusListeners
.size();
478 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
480 BibStatusDispatch
*pObj
= aStatusListeners
[n
].get();
481 if ( pObj
->aURL
.Path
== "Bib/removeFilter" && m_xDatMan
->getParser().is())
483 FeatureStateEvent aEvent
;
484 aEvent
.FeatureURL
= pObj
->aURL
;
485 aEvent
.IsEnabled
= !m_xDatMan
->getParser()->getFilter().isEmpty();
486 aEvent
.Requery
= false;
487 aEvent
.Source
= static_cast<XDispatch
*>(this);
488 pObj
->xListener
->statusChanged( aEvent
);
492 else if(aCommand
== "Bib/removeFilter")
496 else if( _rURL
.Complete
== "slot:5503" || aCommand
== "CloseDoc" )
498 Application::PostUserEvent( LINK( this, BibFrameController_Impl
,
502 else if(aCommand
== "Bib/InsertRecord")
504 Reference
<form::runtime::XFormController
> xFormCtrl
= m_xDatMan
->GetFormController();
505 if(SaveModified(xFormCtrl
))
509 Reference
< sdbc::XResultSet
> xCursor( m_xDatMan
->getForm(), UNO_QUERY
);
512 Reference
< XResultSetUpdate
> xUpdateCursor( m_xDatMan
->getForm(), UNO_QUERY
);
513 xUpdateCursor
->moveToInsertRow();
515 catch(const Exception
&)
517 OSL_FAIL("Exception in last() or moveToInsertRow()");
521 else if(aCommand
== "Bib/DeleteRecord")
523 Reference
< css::sdbc::XResultSet
> xCursor(m_xDatMan
->getForm(), UNO_QUERY
);
524 Reference
< XResultSetUpdate
> xUpdateCursor(xCursor
, UNO_QUERY
);
525 Reference
< beans::XPropertySet
> xSet(m_xDatMan
->getForm(), UNO_QUERY
);
526 bool bIsNew
= ::comphelper::getBOOL(xSet
->getPropertyValue("IsNew"));
529 sal_uInt32 nCount
= 0;
530 xSet
->getPropertyValue("RowCount") >>= nCount
;
531 // determine next position
532 bool bSuccess
= false;
537 bLeft
= xCursor
->isLast() && nCount
> 1;
538 bRight
= !xCursor
->isLast();
539 // ask for confirmation
540 Reference
< frame::XController
> xCtrl
= mxImpl
->pController
;
541 Reference
< form::XConfirmDeleteListener
> xConfirm(m_xDatMan
->GetFormController(),UNO_QUERY
);
544 sdb::RowChangeEvent aEvent
;
545 aEvent
.Source
.set(xCursor
, UNO_QUERY
);
546 aEvent
.Action
= sdb::RowChangeAction::DELETE
;
548 bSuccess
= xConfirm
->confirmDelete(aEvent
);
553 xUpdateCursor
->deleteRow();
555 catch(const Exception
&)
562 xCursor
->relative(bRight
? 1 : -1);
565 bool bCanInsert
= canInsertRecords(xSet
);
566 // can another entry be inserted?
570 xUpdateCursor
->moveToInsertRow();
572 // move data entry to reset state
575 catch(const Exception
&)
577 OSL_FAIL("DeleteRecord: exception caught!");
583 else if(aCommand
== "Cut")
585 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
588 KeyEvent
aEvent( 0, KeyFuncType::CUT
);
589 pChild
->KeyInput( aEvent
);
592 else if(aCommand
== "Copy")
594 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
597 KeyEvent
aEvent( 0, KeyFuncType::COPY
);
598 pChild
->KeyInput( aEvent
);
601 else if(aCommand
== "Paste")
603 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
606 KeyEvent
aEvent( 0, KeyFuncType::PASTE
);
607 pChild
->KeyInput( aEvent
);
612 IMPL_LINK_NOARG( BibFrameController_Impl
, DisposeHdl
, void*, void )
617 void BibFrameController_Impl::addStatusListener(
618 const uno::Reference
< frame::XStatusListener
> & aListener
,
619 const util::URL
& aURL
)
621 BibConfig
* pConfig
= BibModul::GetConfig();
622 // create a new Reference and insert into listener array
623 aStatusListeners
.push_back( o3tl::make_unique
<BibStatusDispatch
>( aURL
, aListener
) );
625 // send first status synchronously
626 FeatureStateEvent aEvent
;
627 aEvent
.FeatureURL
= aURL
;
628 aEvent
.Requery
= false;
629 aEvent
.Source
= static_cast<XDispatch
*>(this);
630 if ( aURL
.Path
== "StatusBarVisible" )
632 aEvent
.IsEnabled
= false;
633 aEvent
.State
<<= false;
635 else if ( aURL
.Path
== "Bib/hierarchical" )
637 aEvent
.IsEnabled
= true;
638 const char* pHier
= bHierarchical
? "" : "*" ;
639 aEvent
.State
<<= OUString::createFromAscii(pHier
);
641 else if(aURL
.Path
== "Bib/MenuFilter")
643 aEvent
.IsEnabled
= true;
644 aEvent
.FeatureDescriptor
=m_xDatMan
->getQueryField();
646 aEvent
.State
<<= m_xDatMan
->getQueryFields();
649 else if ( aURL
.Path
== "Bib/source")
651 aEvent
.IsEnabled
= true;
652 aEvent
.FeatureDescriptor
=m_xDatMan
->getActiveDataTable();
654 aEvent
.State
<<= m_xDatMan
->getDataSources();
656 else if( aURL
.Path
== "Bib/sdbsource" ||
657 aURL
.Path
== "Bib/Mapping" ||
658 aURL
.Path
== "Bib/autoFilter" ||
659 aURL
.Path
== "Bib/standardFilter" )
661 aEvent
.IsEnabled
= true;
663 else if(aURL
.Path
== "Bib/query")
665 aEvent
.IsEnabled
= true;
666 aEvent
.State
<<= pConfig
->getQueryText();
668 else if (aURL
.Path
== "Bib/removeFilter" )
670 OUString aFilterStr
=m_xDatMan
->getFilter();
671 aEvent
.IsEnabled
= !aFilterStr
.isEmpty();
673 else if(aURL
.Path
== "Cut")
675 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
676 Edit
* pEdit
= dynamic_cast<Edit
*>( pChild
);
678 aEvent
.IsEnabled
= !pEdit
->IsReadOnly() && pEdit
->GetSelection().Len();
680 if(aURL
.Path
== "Copy")
682 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
683 Edit
* pEdit
= dynamic_cast<Edit
*>( pChild
);
685 aEvent
.IsEnabled
= pEdit
->GetSelection().Len() > 0;
687 else if(aURL
.Path
== "Paste" )
689 aEvent
.IsEnabled
= false;
690 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
693 uno::Reference
< datatransfer::clipboard::XClipboard
> xClip
= pChild
->GetClipboard();
696 uno::Reference
< datatransfer::XTransferable
> xDataObj
;
700 SolarMutexReleaser aReleaser
;
701 xDataObj
= xClip
->getContents();
703 catch( const uno::Exception
& )
709 datatransfer::DataFlavor aFlavor
;
710 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING
, aFlavor
);
713 uno::Any aData
= xDataObj
->getTransferData( aFlavor
);
716 aEvent
.IsEnabled
= !aText
.isEmpty();
718 catch( const uno::Exception
& )
725 else if(aURL
.Path
== "Bib/DeleteRecord")
727 Reference
< beans::XPropertySet
> xSet(m_xDatMan
->getForm(), UNO_QUERY
);
728 bool bIsNew
= ::comphelper::getBOOL(xSet
->getPropertyValue("IsNew"));
731 sal_uInt32 nCount
= 0;
732 xSet
->getPropertyValue("RowCount") >>= nCount
;
733 aEvent
.IsEnabled
= nCount
> 0;
736 else if (aURL
.Path
== "Bib/InsertRecord")
738 Reference
< beans::XPropertySet
> xSet(m_xDatMan
->getForm(), UNO_QUERY
);
739 aEvent
.IsEnabled
= canInsertRecords(xSet
);
741 aListener
->statusChanged( aEvent
);
744 void BibFrameController_Impl::removeStatusListener(
745 const uno::Reference
< frame::XStatusListener
> & aObject
, const util::URL
& aURL
)
747 // search listener array for given listener
748 // for checking equality always "cast" to XInterface
751 sal_uInt16 nCount
= aStatusListeners
.size();
752 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
754 BibStatusDispatch
*pObj
= aStatusListeners
[n
].get();
755 bool bFlag
=pObj
->xListener
.is();
756 if (!bFlag
|| (pObj
->xListener
== aObject
&&
757 ( aURL
.Complete
.isEmpty() || pObj
->aURL
.Path
== aURL
.Path
)))
759 aStatusListeners
.erase( aStatusListeners
.begin() + n
);
766 void BibFrameController_Impl::RemoveFilter()
769 m_xDatMan
->startQueryWith(aQuery
);
771 sal_uInt16 nCount
= aStatusListeners
.size();
773 bool bRemoveFilter
=false;
774 bool bQueryText
=false;
776 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
778 BibStatusDispatch
*pObj
= aStatusListeners
[n
].get();
779 if ( pObj
->aURL
.Path
== "Bib/removeFilter" )
781 FeatureStateEvent aEvent
;
782 aEvent
.FeatureURL
= pObj
->aURL
;
783 aEvent
.IsEnabled
= false;
784 aEvent
.Requery
= false;
785 aEvent
.Source
= static_cast<XDispatch
*>(this);
786 pObj
->xListener
->statusChanged( aEvent
);
789 else if(pObj
->aURL
.Path
== "Bib/query")
791 FeatureStateEvent aEvent
;
792 aEvent
.FeatureURL
= pObj
->aURL
;
793 aEvent
.IsEnabled
= true;
794 aEvent
.Requery
= false;
795 aEvent
.Source
= static_cast<XDispatch
*>(this);
796 aEvent
.State
<<= aQuery
;
797 pObj
->xListener
->statusChanged( aEvent
);
801 if(bRemoveFilter
&& bQueryText
)
807 void BibFrameController_Impl::ChangeDataSource(const uno::Sequence
< beans::PropertyValue
>& aArgs
)
809 const beans::PropertyValue
* pPropertyValue
= aArgs
.getConstArray();
810 uno::Any aValue
=pPropertyValue
[0].Value
;
811 OUString aDBTableName
;
812 aValue
>>= aDBTableName
;
815 if(aArgs
.getLength() > 1)
817 uno::Any aDB
= pPropertyValue
[1].Value
;
820 m_xDatMan
->setActiveDataSource(aURL
);
821 aDBTableName
= m_xDatMan
->getActiveDataTable();
825 Reference
<css::form::XLoadable
> xLoadable(m_xDatMan
.get());
827 m_xDatMan
->setActiveDataTable(aDBTableName
);
828 m_xDatMan
->updateGridModel();
833 sal_uInt16 nCount
= aStatusListeners
.size();
835 bool bMenuFilter
=false;
836 bool bQueryText
=false;
837 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
839 BibStatusDispatch
*pObj
= aStatusListeners
[n
].get();
840 if (pObj
->aURL
.Path
== "Bib/MenuFilter")
842 FeatureStateEvent aEvent
;
843 aEvent
.FeatureURL
= pObj
->aURL
;
844 aEvent
.IsEnabled
= true;
845 aEvent
.Requery
= false;
846 aEvent
.Source
= static_cast<XDispatch
*>(this);
847 aEvent
.FeatureDescriptor
=m_xDatMan
->getQueryField();
849 uno::Sequence
<OUString
> aStringSeq
=m_xDatMan
->getQueryFields();
850 aEvent
.State
<<= aStringSeq
;
852 pObj
->xListener
->statusChanged( aEvent
);
855 else if (pObj
->aURL
.Path
== "Bib/query")
857 FeatureStateEvent aEvent
;
858 aEvent
.FeatureURL
= pObj
->aURL
;
859 aEvent
.IsEnabled
= true;
860 aEvent
.Requery
= false;
861 aEvent
.Source
= static_cast<XDispatch
*>(this);
862 BibConfig
* pConfig
= BibModul::GetConfig();
863 aEvent
.State
<<= pConfig
->getQueryText();
864 pObj
->xListener
->statusChanged( aEvent
);
868 if (bMenuFilter
&& bQueryText
)
874 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */