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/implbase1.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>
55 #include <unordered_map>
59 using namespace com::sun::star::sdbc
;
60 using namespace com::sun::star::frame
;
61 using namespace com::sun::star::uno
;
62 using namespace com::sun::star
;
69 bool bActiveConnection
;
72 struct CacheDispatchInfo
75 bool bActiveConnection
;
78 // Attention: commands must be sorted by command groups. Implementation is dependent
80 static const DispatchInfo SupportedCommandsArray
[] =
82 { ".uno:Undo" , frame::CommandGroup::EDIT
, false },
83 { ".uno:Cut" , frame::CommandGroup::EDIT
, false },
84 { ".uno:Copy" , frame::CommandGroup::EDIT
, false },
85 { ".uno:Paste" , frame::CommandGroup::EDIT
, false },
86 { ".uno:SelectAll" , frame::CommandGroup::EDIT
, false },
87 { ".uno:CloseDoc" , frame::CommandGroup::DOCUMENT
, false },
88 { ".uno:StatusBarVisible" , frame::CommandGroup::VIEW
, false },
89 { ".uno:AvailableToolbars" , frame::CommandGroup::VIEW
, false },
90 { ".uno:Bib/standardFilter" , frame::CommandGroup::DATA
, true },
91 { ".uno:Bib/DeleteRecord" , frame::CommandGroup::DATA
, true },
92 { ".uno:Bib/InsertRecord" , frame::CommandGroup::DATA
, true },
93 { ".uno:Bib/query" , frame::CommandGroup::DATA
, true },
94 { ".uno:Bib/autoFilter" , frame::CommandGroup::DATA
, true },
95 { ".uno:Bib/source" , frame::CommandGroup::DATA
, true },
96 { ".uno:Bib/removeFilter" , frame::CommandGroup::DATA
, true },
97 { ".uno:Bib/sdbsource" , frame::CommandGroup::DATA
, true },
98 { ".uno:Bib/Mapping" , frame::CommandGroup::DATA
, true },
102 typedef std::unordered_map
< OUString
, CacheDispatchInfo
, OUStringHash
, ::std::equal_to
< OUString
> > CmdToInfoCache
;
104 const CmdToInfoCache
& GetCommandToInfoCache()
106 static bool bCacheInitialized
= false;
107 static CmdToInfoCache aCmdToInfoCache
;
109 if ( !bCacheInitialized
)
111 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
112 if ( !bCacheInitialized
)
115 while ( SupportedCommandsArray
[i
].pCommand
!= 0 )
117 OUString
aCommand( OUString::createFromAscii( SupportedCommandsArray
[i
].pCommand
));
119 CacheDispatchInfo aDispatchInfo
;
120 aDispatchInfo
.nGroupId
= SupportedCommandsArray
[i
].nGroupId
;
121 aDispatchInfo
.bActiveConnection
= SupportedCommandsArray
[i
].bActiveConnection
;
122 aCmdToInfoCache
.insert( CmdToInfoCache::value_type( aCommand
, aDispatchInfo
));
125 bCacheInitialized
= true;
129 return aCmdToInfoCache
;
133 class BibFrameCtrl_Impl
: public cppu::WeakImplHelper1
< XFrameActionListener
>
137 OMultiTypeInterfaceContainerHelper aLC
;
139 BibFrameController_Impl
* pController
;
146 virtual ~BibFrameCtrl_Impl();
148 virtual void SAL_CALL
frameAction(const FrameActionEvent
& aEvent
) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
149 virtual void SAL_CALL
disposing( const lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
153 BibFrameCtrl_Impl::~BibFrameCtrl_Impl()
157 void BibFrameCtrl_Impl::frameAction(const FrameActionEvent
& ) throw( uno::RuntimeException
, std::exception
)
161 void BibFrameCtrl_Impl::disposing( const lang::EventObject
& /*Source*/ )
162 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
164 ::SolarMutexGuard aGuard
;
166 pController
->getFrame()->removeFrameActionListener( this );
169 BibFrameController_Impl::BibFrameController_Impl( const uno::Reference
< awt::XWindow
> & xComponent
,
170 BibDataManager
* pDataManager
)
171 :xWindow( xComponent
)
172 ,m_xDatMan( pDataManager
)
173 ,pDatMan( pDataManager
)
176 vcl::Window
* pParent
= VCLUnoHelper::GetWindow( xWindow
);
177 pParent
->SetUniqueId(UID_BIB_FRAME_WINDOW
);
180 pImp
= new BibFrameCtrl_Impl
;
181 pImp
->pController
= this;
185 BibFrameController_Impl::~BibFrameController_Impl()
187 pImp
->pController
= NULL
;
191 CloseBibModul(pBibMod
);
194 OUString SAL_CALL
BibFrameController_Impl::getImplementationName() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
196 return OUString("com.sun.star.comp.extensions.Bibliography");
199 sal_Bool SAL_CALL
BibFrameController_Impl::supportsService( const OUString
& sServiceName
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
201 return cppu::supportsService( this, sServiceName
);
204 ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
BibFrameController_Impl::getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
206 // return only top level services ...
207 // base services are included there and should be asked by uno-rtti.
208 ::com::sun::star::uno::Sequence
< OUString
> lNames(1);
209 lNames
[0] = "com.sun.star.frame.Bibliography";
213 void BibFrameController_Impl::attachFrame( const uno::Reference
< XFrame
> & xArg
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
216 xFrame
->addFrameActionListener( pImp
);
219 sal_Bool
BibFrameController_Impl::attachModel( const uno::Reference
< XModel
> & /*xModel*/ ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
224 sal_Bool
BibFrameController_Impl::suspend( sal_Bool bSuspend
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
227 getFrame()->removeFrameActionListener( pImp
);
229 getFrame()->addFrameActionListener( pImp
);
233 uno::Any
BibFrameController_Impl::getViewData() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
238 void BibFrameController_Impl::restoreViewData( const uno::Any
& /*Value*/ ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
242 uno::Reference
< XFrame
> BibFrameController_Impl::getFrame() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
247 uno::Reference
< XModel
> BibFrameController_Impl::getModel() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
249 return uno::Reference
< XModel
> ();
252 void BibFrameController_Impl::dispose() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
255 lang::EventObject aObject
;
256 aObject
.Source
= (XController
*)this;
257 pImp
->aLC
.disposeAndClear(aObject
);
260 aStatusListeners
.clear();
263 void BibFrameController_Impl::addEventListener( const uno::Reference
< lang::XEventListener
> & aListener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
265 pImp
->aLC
.addInterface( cppu::UnoType
<lang::XEventListener
>::get(), aListener
);
268 void BibFrameController_Impl::removeEventListener( const uno::Reference
< lang::XEventListener
> & aListener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
270 pImp
->aLC
.removeInterface( cppu::UnoType
<lang::XEventListener
>::get(), aListener
);
273 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
)
277 const CmdToInfoCache
& rCmdCache
= GetCommandToInfoCache();
278 CmdToInfoCache::const_iterator pIter
= rCmdCache
.find( aURL
.Complete
);
279 if ( pIter
!= rCmdCache
.end() )
281 if (( pDatMan
->HasActiveConnection() ) ||
282 ( !pIter
->second
.bActiveConnection
))
283 return (frame::XDispatch
*) this;
287 return uno::Reference
< frame::XDispatch
> ();
290 uno::Sequence
<uno::Reference
< XDispatch
> > BibFrameController_Impl::queryDispatches( const uno::Sequence
<DispatchDescriptor
>& aDescripts
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
292 uno::Sequence
< uno::Reference
< XDispatch
> > aDispatches( aDescripts
.getLength() );
293 for ( sal_Int32 i
=0; i
<aDescripts
.getLength(); ++i
)
294 aDispatches
[i
] = queryDispatch( aDescripts
[i
].FeatureURL
, aDescripts
[i
].FrameName
, aDescripts
[i
].SearchFlags
);
298 uno::Sequence
< ::sal_Int16
> SAL_CALL
BibFrameController_Impl::getSupportedCommandGroups()
299 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
301 uno::Sequence
< ::sal_Int16
> aDispatchInfo( 4 );
303 aDispatchInfo
[0] = frame::CommandGroup::EDIT
;
304 aDispatchInfo
[1] = frame::CommandGroup::DOCUMENT
;
305 aDispatchInfo
[2] = frame::CommandGroup::DATA
;
306 aDispatchInfo
[3] = frame::CommandGroup::VIEW
;
308 return aDispatchInfo
;
311 uno::Sequence
< frame::DispatchInformation
> SAL_CALL
BibFrameController_Impl::getConfigurableDispatchInformation( ::sal_Int16 nCommandGroup
)
312 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
314 const CmdToInfoCache
& rCmdCache
= GetCommandToInfoCache();
316 frame::DispatchInformation aDispatchInfo
;
317 std::list
< frame::DispatchInformation
> aDispatchInfoList
;
319 if (( nCommandGroup
== frame::CommandGroup::EDIT
) ||
320 ( nCommandGroup
== frame::CommandGroup::DOCUMENT
) ||
321 ( nCommandGroup
== frame::CommandGroup::DATA
) ||
322 ( nCommandGroup
== frame::CommandGroup::VIEW
))
324 bool bGroupFound
= false;
325 CmdToInfoCache::const_iterator pIter
= rCmdCache
.begin();
326 while ( pIter
!= rCmdCache
.end() )
328 if ( pIter
->second
.nGroupId
== nCommandGroup
)
331 aDispatchInfo
.Command
= pIter
->first
;
332 aDispatchInfo
.GroupId
= pIter
->second
.nGroupId
;
333 aDispatchInfoList
.push_back( aDispatchInfo
);
335 else if ( bGroupFound
)
342 ::com::sun::star::uno::Sequence
< ::com::sun::star::frame::DispatchInformation
> aSeq
=
343 comphelper::containerToSequence
< ::com::sun::star::frame::DispatchInformation
, std::list
< ::com::sun::star::frame::DispatchInformation
> >( aDispatchInfoList
);
348 bool canInsertRecords(const Reference
< beans::XPropertySet
>& _rxCursorSet
)
351 _rxCursorSet
->getPropertyValue("Privileges") >>= nPriv
;
352 return ((_rxCursorSet
.is() && (nPriv
& sdbcx::Privilege::INSERT
) != 0));
355 bool BibFrameController_Impl::SaveModified(const Reference
< form::runtime::XFormController
>& xController
)
357 if (!xController
.is())
360 Reference
< XResultSetUpdate
> _xCursor
= Reference
< XResultSetUpdate
>(xController
->getModel(), UNO_QUERY
);
365 Reference
< beans::XPropertySet
> _xSet
= Reference
< beans::XPropertySet
>(_xCursor
, UNO_QUERY
);
370 bool bIsNew
= ::comphelper::getBOOL(_xSet
->getPropertyValue("IsNew"));
371 bool bIsModified
= ::comphelper::getBOOL(_xSet
->getPropertyValue("IsModified"));
372 bool bResult
= !bIsModified
;
378 _xCursor
->insertRow();
380 _xCursor
->updateRow();
383 catch(const Exception
&)
385 OSL_FAIL("SaveModified: Exception occurred!");
391 static vcl::Window
* lcl_GetFocusChild( vcl::Window
* pParent
)
393 sal_uInt16 nChildren
= pParent
->GetChildCount();
394 for( sal_uInt16 nChild
= 0; nChild
< nChildren
; ++nChild
)
396 vcl::Window
* pChild
= pParent
->GetChild( nChild
);
397 if(pChild
->HasFocus())
399 vcl::Window
* pSubChild
= lcl_GetFocusChild( pChild
);
407 void BibFrameController_Impl::dispatch(const util::URL
& _rURL
, const uno::Sequence
< beans::PropertyValue
>& aArgs
)
408 throw (::com::sun::star::uno::RuntimeException
,
413 ::SolarMutexGuard aGuard
;
414 vcl::Window
* pParent
= VCLUnoHelper::GetWindow( xWindow
);
415 WaitObject
aWaitObject( pParent
);
417 OUString
aCommand( _rURL
.Path
);
418 if(aCommand
== "Bib/Mapping")
420 pDatMan
->CreateMappingDialog(pParent
);
422 else if(aCommand
== "Bib/source")
424 ChangeDataSource(aArgs
);
426 else if(aCommand
== "Bib/sdbsource")
428 OUString aURL
= pDatMan
->CreateDBChangeDialog(pParent
);
433 uno::Sequence
< beans::PropertyValue
> aNewDataSource(2);
434 beans::PropertyValue
* pProps
= aNewDataSource
.getArray();
435 pProps
[0].Value
<<= OUString();
436 pProps
[1].Value
<<= aURL
;
437 ChangeDataSource(aNewDataSource
);
439 catch(const Exception
&)
441 OSL_FAIL("Exception catched while changing the data source");
445 else if(aCommand
== "Bib/autoFilter")
447 sal_uInt16 nCount
= aStatusListeners
.size();
448 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
450 BibStatusDispatch
*pObj
= &aStatusListeners
[n
];
451 if ( pObj
->aURL
.Path
== "Bib/removeFilter" )
453 FeatureStateEvent aEvent
;
454 aEvent
.FeatureURL
= pObj
->aURL
;
455 aEvent
.IsEnabled
= sal_True
;
456 aEvent
.Requery
= sal_False
;
457 aEvent
.Source
= (XDispatch
*) this;
458 pObj
->xListener
->statusChanged( aEvent
);
459 //break; because there are more than one
463 const beans::PropertyValue
* pPropertyValue
= aArgs
.getConstArray();
464 uno::Any aValue
=pPropertyValue
[0].Value
;
468 aValue
=pPropertyValue
[1].Value
;
469 OUString aQueryField
;
470 aValue
>>= aQueryField
;
471 BibConfig
* pConfig
= BibModul::GetConfig();
472 pConfig
->setQueryField(aQueryField
);
473 pDatMan
->startQueryWith(aQuery
);
475 else if(aCommand
== "Bib/standardFilter")
479 uno::Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
481 // create the dialog object
482 uno::Reference
< ui::dialogs::XExecutableDialog
> xDialog
= sdb::FilterDialog::createWithQuery(xContext
, pDatMan
->getParser(),
483 Reference
<sdbc::XRowSet
>(pDatMan
->getForm(), uno::UNO_QUERY_THROW
), xWindow
);
485 if ( xDialog
->execute( ) )
487 // the dialog has been executed successfully, and the filter on the query composer
489 OUString sNewFilter
= pDatMan
->getParser()->getFilter();
490 pDatMan
->setFilter( sNewFilter
);
493 catch( const uno::Exception
& )
495 OSL_FAIL( "BibFrameController_Impl::dispatch: caught an exception!" );
498 sal_uInt16 nCount
= aStatusListeners
.size();
499 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
501 BibStatusDispatch
*pObj
= &aStatusListeners
[n
];
502 if ( pObj
->aURL
.Path
== "Bib/removeFilter" && pDatMan
->getParser().is())
504 FeatureStateEvent aEvent
;
505 aEvent
.FeatureURL
= pObj
->aURL
;
506 aEvent
.IsEnabled
= !pDatMan
->getParser()->getFilter().isEmpty();
507 aEvent
.Requery
= sal_False
;
508 aEvent
.Source
= (XDispatch
*) this;
509 pObj
->xListener
->statusChanged( aEvent
);
513 else if(aCommand
== "Bib/removeFilter")
517 else if( _rURL
.Complete
== "slot:5503" || aCommand
== "CloseDoc" )
519 Application::PostUserEvent( LINK( this, BibFrameController_Impl
,
523 else if(aCommand
== "Bib/InsertRecord")
525 Reference
<form::runtime::XFormController
> xFormCtrl
= pDatMan
->GetFormController();
526 if(SaveModified(xFormCtrl
))
530 Reference
< sdbc::XResultSet
> xCursor( pDatMan
->getForm(), UNO_QUERY
);
533 Reference
< XResultSetUpdate
> xUpdateCursor( pDatMan
->getForm(), UNO_QUERY
);
534 xUpdateCursor
->moveToInsertRow();
536 catch(const Exception
&)
538 OSL_FAIL("Exception in last() or moveToInsertRow()");
542 else if(aCommand
== "Bib/DeleteRecord")
544 Reference
< ::com::sun::star::sdbc::XResultSet
> xCursor(pDatMan
->getForm(), UNO_QUERY
);
545 Reference
< XResultSetUpdate
> xUpdateCursor(xCursor
, UNO_QUERY
);
546 Reference
< beans::XPropertySet
> xSet(pDatMan
->getForm(), UNO_QUERY
);
547 bool bIsNew
= ::comphelper::getBOOL(xSet
->getPropertyValue("IsNew"));
550 sal_uInt32 nCount
= 0;
551 xSet
->getPropertyValue("RowCount") >>= nCount
;
552 // determine next position
553 bool bSuccess
= false;
558 bLeft
= xCursor
->isLast() && nCount
> 1;
559 bRight
= !xCursor
->isLast();
560 // ask for confirmation
561 Reference
< frame::XController
> xCtrl
= pImp
->pController
;
562 Reference
< form::XConfirmDeleteListener
> xConfirm(pDatMan
->GetFormController(),UNO_QUERY
);
565 sdb::RowChangeEvent aEvent
;
566 aEvent
.Source
= Reference
< XInterface
> (xCursor
, UNO_QUERY
);
567 aEvent
.Action
= sdb::RowChangeAction::DELETE
;
569 bSuccess
= xConfirm
->confirmDelete(aEvent
);
574 xUpdateCursor
->deleteRow();
576 catch(const Exception
&)
583 xCursor
->relative(bRight
? 1 : -1);
586 bool bCanInsert
= canInsertRecords(xSet
);
587 // can another entry be inserted?
591 xUpdateCursor
->moveToInsertRow();
593 // move data entry to reset state
596 catch(const Exception
&)
598 OSL_FAIL("DeleteRecord: exception caught!");
604 else if(aCommand
== "Cut")
606 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
609 KeyEvent
aEvent( 0, KeyFuncType::CUT
);
610 pChild
->KeyInput( aEvent
);
613 else if(aCommand
== "Copy")
615 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
618 KeyEvent
aEvent( 0, KeyFuncType::COPY
);
619 pChild
->KeyInput( aEvent
);
622 else if(aCommand
== "Paste")
624 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
627 KeyEvent
aEvent( 0, KeyFuncType::PASTE
);
628 pChild
->KeyInput( aEvent
);
633 IMPL_LINK_NOARG( BibFrameController_Impl
, DisposeHdl
)
639 void BibFrameController_Impl::addStatusListener(
640 const uno::Reference
< frame::XStatusListener
> & aListener
,
641 const util::URL
& aURL
)
642 throw (::com::sun::star::uno::RuntimeException
,
645 BibConfig
* pConfig
= BibModul::GetConfig();
646 // create a new Reference and insert into listener array
647 aStatusListeners
.push_back( new BibStatusDispatch( aURL
, aListener
) );
649 // send first status synchronously
650 FeatureStateEvent aEvent
;
651 aEvent
.FeatureURL
= aURL
;
652 aEvent
.Requery
= sal_False
;
653 aEvent
.Source
= (XDispatch
*) this;
654 if ( aURL
.Path
== "StatusBarVisible" )
656 aEvent
.IsEnabled
= sal_False
;
657 aEvent
.State
<<= false;
659 else if ( aURL
.Path
== "Bib/hierarchical" )
661 aEvent
.IsEnabled
= sal_True
;
662 const char* pHier
= bHierarchical
? "" : "*" ;
663 aEvent
.State
<<= OUString::createFromAscii(pHier
);
665 else if(aURL
.Path
== "Bib/MenuFilter")
667 aEvent
.IsEnabled
= sal_True
;
668 aEvent
.FeatureDescriptor
=pDatMan
->getQueryField();
670 uno::Sequence
<OUString
> aStringSeq
=pDatMan
->getQueryFields();
671 aEvent
.State
.setValue(&aStringSeq
,cppu::UnoType
<uno::Sequence
<OUString
>>::get());
674 else if ( aURL
.Path
== "Bib/source")
676 aEvent
.IsEnabled
= sal_True
;
677 aEvent
.FeatureDescriptor
=pDatMan
->getActiveDataTable();
679 uno::Sequence
<OUString
> aStringSeq
=pDatMan
->getDataSources();
680 aEvent
.State
.setValue(&aStringSeq
,cppu::UnoType
<uno::Sequence
<OUString
>>::get());
682 else if( aURL
.Path
== "Bib/sdbsource" ||
683 aURL
.Path
== "Bib/Mapping" ||
684 aURL
.Path
== "Bib/autoFilter" ||
685 aURL
.Path
== "Bib/standardFilter" )
687 aEvent
.IsEnabled
= sal_True
;
689 else if(aURL
.Path
== "Bib/query")
691 aEvent
.IsEnabled
= sal_True
;
692 aEvent
.State
<<= pConfig
->getQueryText();
694 else if (aURL
.Path
== "Bib/removeFilter" )
696 OUString aFilterStr
=pDatMan
->getFilter();
697 aEvent
.IsEnabled
= !aFilterStr
.isEmpty();
699 else if(aURL
.Path
== "Cut")
701 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
702 Edit
* pEdit
= dynamic_cast<Edit
*>( pChild
);
704 aEvent
.IsEnabled
= !pEdit
->IsReadOnly() && pEdit
->GetSelection().Len();
706 if(aURL
.Path
== "Copy")
708 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
709 Edit
* pEdit
= dynamic_cast<Edit
*>( pChild
);
711 aEvent
.IsEnabled
= pEdit
->GetSelection().Len() > 0;
713 else if(aURL
.Path
== "Paste" )
715 aEvent
.IsEnabled
= sal_False
;
716 vcl::Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
719 uno::Reference
< datatransfer::clipboard::XClipboard
> xClip
= pChild
->GetClipboard();
722 uno::Reference
< datatransfer::XTransferable
> xDataObj
;
726 SolarMutexReleaser aReleaser
;
727 xDataObj
= xClip
->getContents();
729 catch( const uno::Exception
& )
735 datatransfer::DataFlavor aFlavor
;
736 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING
, aFlavor
);
739 uno::Any aData
= xDataObj
->getTransferData( aFlavor
);
742 aEvent
.IsEnabled
= !aText
.isEmpty();
744 catch( const uno::Exception
& )
749 uno::Reference
< datatransfer::XTransferable
> xContents
= xClip
->getContents( );
752 else if(aURL
.Path
== "Bib/DeleteRecord")
754 Reference
< ::com::sun::star::sdbc::XResultSet
> xCursor(pDatMan
->getForm(), UNO_QUERY
);
755 Reference
< XResultSetUpdate
> xUpdateCursor(xCursor
, UNO_QUERY
);
756 Reference
< beans::XPropertySet
> xSet(pDatMan
->getForm(), UNO_QUERY
);
757 bool bIsNew
= ::comphelper::getBOOL(xSet
->getPropertyValue("IsNew"));
760 sal_uInt32 nCount
= 0;
761 xSet
->getPropertyValue("RowCount") >>= nCount
;
762 aEvent
.IsEnabled
= nCount
> 0;
765 else if (aURL
.Path
== "Bib/InsertRecord")
767 Reference
< beans::XPropertySet
> xSet(pDatMan
->getForm(), UNO_QUERY
);
768 aEvent
.IsEnabled
= canInsertRecords(xSet
);
770 aListener
->statusChanged( aEvent
);
773 void BibFrameController_Impl::removeStatusListener(
774 const uno::Reference
< frame::XStatusListener
> & aObject
, const util::URL
& aURL
)
775 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
777 // search listener array for given listener
778 // for checking equality always "cast" to XInterface
781 sal_uInt16 nCount
= aStatusListeners
.size();
782 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
784 BibStatusDispatch
*pObj
= &aStatusListeners
[n
];
785 bool bFlag
=pObj
->xListener
.is();
786 if (!bFlag
|| (pObj
->xListener
== aObject
&&
787 ( aURL
.Complete
.isEmpty() || pObj
->aURL
.Path
== aURL
.Path
)))
789 aStatusListeners
.erase( aStatusListeners
.begin() + n
);
796 void BibFrameController_Impl::RemoveFilter()
799 pDatMan
->startQueryWith(aQuery
);
801 sal_uInt16 nCount
= aStatusListeners
.size();
803 bool bRemoveFilter
=false;
804 bool bQueryText
=false;
806 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
808 BibStatusDispatch
*pObj
= &aStatusListeners
[n
];
809 if ( pObj
->aURL
.Path
== "Bib/removeFilter" )
811 FeatureStateEvent aEvent
;
812 aEvent
.FeatureURL
= pObj
->aURL
;
813 aEvent
.IsEnabled
= sal_False
;
814 aEvent
.Requery
= sal_False
;
815 aEvent
.Source
= (XDispatch
*) this;
816 pObj
->xListener
->statusChanged( aEvent
);
819 else if(pObj
->aURL
.Path
== "Bib/query")
821 FeatureStateEvent aEvent
;
822 aEvent
.FeatureURL
= pObj
->aURL
;
823 aEvent
.IsEnabled
= sal_True
;
824 aEvent
.Requery
= sal_False
;
825 aEvent
.Source
= (XDispatch
*) this;
826 aEvent
.State
<<= aQuery
;
827 pObj
->xListener
->statusChanged( aEvent
);
831 if(bRemoveFilter
&& bQueryText
)
837 void BibFrameController_Impl::ChangeDataSource(const uno::Sequence
< beans::PropertyValue
>& aArgs
)
839 const beans::PropertyValue
* pPropertyValue
= aArgs
.getConstArray();
840 uno::Any aValue
=pPropertyValue
[0].Value
;
841 OUString aDBTableName
;
842 aValue
>>= aDBTableName
;
845 if(aArgs
.getLength() > 1)
847 uno::Any aDB
= pPropertyValue
[1].Value
;
850 pDatMan
->setActiveDataSource(aURL
);
851 aDBTableName
= pDatMan
->getActiveDataTable();
856 pDatMan
->setActiveDataTable(aDBTableName
);
857 pDatMan
->updateGridModel();
862 sal_uInt16 nCount
= aStatusListeners
.size();
864 bool bMenuFilter
=false;
865 bool bQueryText
=false;
866 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
868 BibStatusDispatch
*pObj
= &aStatusListeners
[n
];
869 if (pObj
->aURL
.Path
== "Bib/MenuFilter")
871 FeatureStateEvent aEvent
;
872 aEvent
.FeatureURL
= pObj
->aURL
;
873 aEvent
.IsEnabled
= sal_True
;
874 aEvent
.Requery
= sal_False
;
875 aEvent
.Source
= (XDispatch
*) this;
876 aEvent
.FeatureDescriptor
=pDatMan
->getQueryField();
878 uno::Sequence
<OUString
> aStringSeq
=pDatMan
->getQueryFields();
879 aEvent
.State
= makeAny( aStringSeq
);
881 pObj
->xListener
->statusChanged( aEvent
);
884 else if (pObj
->aURL
.Path
== "Bib/query")
886 FeatureStateEvent aEvent
;
887 aEvent
.FeatureURL
= pObj
->aURL
;
888 aEvent
.IsEnabled
= sal_True
;
889 aEvent
.Requery
= sal_False
;
890 aEvent
.Source
= (XDispatch
*) this;
891 BibConfig
* pConfig
= BibModul::GetConfig();
892 aEvent
.State
<<= pConfig
->getQueryText();
893 pObj
->xListener
->statusChanged( aEvent
);
897 if (bMenuFilter
&& bQueryText
)
903 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */