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 <comphelper/types.hxx>
21 #include <comphelper/propertyvalue.hxx>
22 #include <comphelper/sequence.hxx>
23 #include "framectr.hxx"
25 #include <toolkit/helper/vclunohelper.hxx>
26 #include "bibconfig.hxx"
27 #include <cppuhelper/implbase.hxx>
29 #include <vcl/event.hxx>
30 #include <vcl/svapp.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <com/sun/star/awt/XTextComponent.hpp>
33 #include <com/sun/star/awt/XVclWindowPeer.hpp>
34 #include <com/sun/star/form/XConfirmDeleteListener.hpp>
35 #include <com/sun/star/form/runtime/XFormController.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
38 #include <com/sun/star/sdbcx/Privilege.hpp>
39 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
40 #include <com/sun/star/sdb/FilterDialog.hpp>
41 #include <com/sun/star/sdb/RowChangeAction.hpp>
42 #include <com/sun/star/frame/CommandGroup.hpp>
43 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
44 #include <comphelper/multicontainer2.hxx>
45 #include <cppuhelper/supportsservice.hxx>
46 #include <sot/exchange.hxx>
47 #include <sot/formats.hxx>
48 #include <comphelper/diagnose_ex.hxx>
49 #include <vcl/weld.hxx>
50 #include <osl/mutex.hxx>
52 #include <unordered_map>
56 using namespace com::sun::star::sdbc
;
57 using namespace com::sun::star::frame
;
58 using namespace com::sun::star::uno
;
59 using namespace com::sun::star
;
67 bool bActiveConnection
;
70 struct CacheDispatchInfo
73 bool bActiveConnection
;
78 // Attention: commands must be sorted by command groups. Implementation is dependent
80 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 },
101 typedef std::unordered_map
< OUString
, CacheDispatchInfo
> CmdToInfoCache
;
103 static const CmdToInfoCache
& GetCommandToInfoCache()
105 static CmdToInfoCache aCmdToInfoCache
= []() {
106 CmdToInfoCache aCache
;
107 for (const auto& command
: SupportedCommandsArray
)
109 OUString
aCommand(OUString::createFromAscii(command
.pCommand
));
111 CacheDispatchInfo aDispatchInfo
;
112 aDispatchInfo
.nGroupId
= command
.nGroupId
;
113 aDispatchInfo
.bActiveConnection
= command
.bActiveConnection
;
114 aCache
.emplace(aCommand
, aDispatchInfo
);
119 return aCmdToInfoCache
;
123 class BibFrameCtrl_Impl
: public cppu::WeakImplHelper
< XFrameActionListener
>
127 comphelper::OMultiTypeInterfaceContainerHelper2 aLC
;
129 BibFrameController_Impl
* pController
;
133 , pController(nullptr)
136 virtual void SAL_CALL
frameAction(const FrameActionEvent
& aEvent
) override
;
137 virtual void SAL_CALL
disposing( const lang::EventObject
& Source
) override
;
140 void BibFrameCtrl_Impl::frameAction(const FrameActionEvent
& )
144 void BibFrameCtrl_Impl::disposing( const lang::EventObject
& /*Source*/ )
146 ::SolarMutexGuard aGuard
;
148 pController
->getFrame()->removeFrameActionListener( this );
151 BibFrameController_Impl::BibFrameController_Impl( uno::Reference
< awt::XWindow
> xComponent
,
152 BibDataManager
* pDataManager
)
153 :m_xWindow(std::move( xComponent
))
154 ,m_xDatMan( pDataManager
)
156 m_bDisposing
= false;
157 m_xImpl
= new BibFrameCtrl_Impl
;
158 m_xImpl
->pController
= this;
161 BibFrameController_Impl::~BibFrameController_Impl()
163 m_xImpl
->pController
= nullptr;
167 OUString SAL_CALL
BibFrameController_Impl::getImplementationName()
169 return "com.sun.star.comp.extensions.Bibliography";
172 sal_Bool SAL_CALL
BibFrameController_Impl::supportsService( const OUString
& sServiceName
)
174 return cppu::supportsService( this, sServiceName
);
177 css::uno::Sequence
< OUString
> SAL_CALL
BibFrameController_Impl::getSupportedServiceNames()
179 // return only top level services ...
180 // base services are included there and should be asked by uno-rtti.
181 return { "com.sun.star.frame.Bibliography" };
184 void BibFrameController_Impl::attachFrame( const uno::Reference
< XFrame
> & xArg
)
187 m_xFrame
->addFrameActionListener( m_xImpl
);
190 sal_Bool
BibFrameController_Impl::attachModel( const uno::Reference
< XModel
> & /*xModel*/ )
195 sal_Bool
BibFrameController_Impl::suspend( sal_Bool bSuspend
)
198 getFrame()->removeFrameActionListener( m_xImpl
);
200 getFrame()->addFrameActionListener( m_xImpl
);
204 uno::Any
BibFrameController_Impl::getViewData()
209 void BibFrameController_Impl::restoreViewData( const uno::Any
& /*Value*/ )
213 uno::Reference
< XFrame
> BibFrameController_Impl::getFrame()
218 uno::Reference
< XModel
> BibFrameController_Impl::getModel()
220 return uno::Reference
< XModel
> ();
223 void BibFrameController_Impl::dispose()
226 lang::EventObject aObject
;
227 uno::Reference
< XFrame
> xFrame
= getFrame();
230 xFrame
->removeFrameActionListener( m_xImpl
);
232 aObject
.Source
= static_cast<XController
*>(this);
233 m_xImpl
->aLC
.disposeAndClear(aObject
);
235 m_aStatusListeners
.clear();
236 m_xLastQueriedFocusWin
.clear();
239 void BibFrameController_Impl::addEventListener( const uno::Reference
< lang::XEventListener
> & aListener
)
241 m_xImpl
->aLC
.addInterface( cppu::UnoType
<lang::XEventListener
>::get(), aListener
);
244 void BibFrameController_Impl::removeEventListener( const uno::Reference
< lang::XEventListener
> & aListener
)
246 m_xImpl
->aLC
.removeInterface( cppu::UnoType
<lang::XEventListener
>::get(), aListener
);
249 uno::Reference
< frame::XDispatch
> BibFrameController_Impl::queryDispatch( const util::URL
& aURL
, const OUString
& /*aTarget*/, sal_Int32
/*nSearchFlags*/ )
253 const CmdToInfoCache
& rCmdCache
= GetCommandToInfoCache();
254 CmdToInfoCache::const_iterator pIter
= rCmdCache
.find( aURL
.Complete
);
255 if ( pIter
!= rCmdCache
.end() )
257 if (( m_xDatMan
->HasActiveConnection() ) ||
258 ( !pIter
->second
.bActiveConnection
))
259 return static_cast<frame::XDispatch
*>(this);
263 return uno::Reference
< frame::XDispatch
> ();
266 uno::Sequence
<uno::Reference
< XDispatch
> > BibFrameController_Impl::queryDispatches( const uno::Sequence
<DispatchDescriptor
>& aDescripts
)
268 uno::Sequence
< uno::Reference
< XDispatch
> > aDispatches( aDescripts
.getLength() );
269 auto aDispatchesRange
= asNonConstRange(aDispatches
);
270 for ( sal_Int32 i
=0; i
<aDescripts
.getLength(); ++i
)
271 aDispatchesRange
[i
] = queryDispatch( aDescripts
[i
].FeatureURL
, aDescripts
[i
].FrameName
, aDescripts
[i
].SearchFlags
);
275 uno::Sequence
< ::sal_Int16
> SAL_CALL
BibFrameController_Impl::getSupportedCommandGroups()
277 uno::Sequence
< ::sal_Int16
> aDispatchInfo
{ frame::CommandGroup::EDIT
,
278 frame::CommandGroup::DOCUMENT
,
279 frame::CommandGroup::DATA
,
280 frame::CommandGroup::VIEW
};
282 return aDispatchInfo
;
285 uno::Sequence
< frame::DispatchInformation
> SAL_CALL
BibFrameController_Impl::getConfigurableDispatchInformation( ::sal_Int16 nCommandGroup
)
287 const CmdToInfoCache
& rCmdCache
= GetCommandToInfoCache();
289 frame::DispatchInformation aDispatchInfo
;
290 std::vector
< frame::DispatchInformation
> aDispatchInfoVector
;
292 if (( nCommandGroup
== frame::CommandGroup::EDIT
) ||
293 ( nCommandGroup
== frame::CommandGroup::DOCUMENT
) ||
294 ( nCommandGroup
== frame::CommandGroup::DATA
) ||
295 ( nCommandGroup
== frame::CommandGroup::VIEW
))
297 bool bGroupFound
= false;
298 for (auto const& item
: rCmdCache
)
300 if ( item
.second
.nGroupId
== nCommandGroup
)
303 aDispatchInfo
.Command
= item
.first
;
304 aDispatchInfo
.GroupId
= item
.second
.nGroupId
;
305 aDispatchInfoVector
.push_back( aDispatchInfo
);
307 else if ( bGroupFound
)
312 return comphelper::containerToSequence( aDispatchInfoVector
);
315 static bool canInsertRecords(const Reference
< beans::XPropertySet
>& _rxCursorSet
)
318 _rxCursorSet
->getPropertyValue("Privileges") >>= nPriv
;
319 return _rxCursorSet
.is() && (nPriv
& sdbcx::Privilege::INSERT
) != 0;
322 bool BibFrameController_Impl::SaveModified(const Reference
< form::runtime::XFormController
>& xController
)
324 if (!xController
.is())
327 Reference
< XResultSetUpdate
> _xCursor(xController
->getModel(), UNO_QUERY
);
332 Reference
< beans::XPropertySet
> _xSet(_xCursor
, UNO_QUERY
);
337 bool bIsNew
= ::comphelper::getBOOL(_xSet
->getPropertyValue("IsNew"));
338 bool bIsModified
= ::comphelper::getBOOL(_xSet
->getPropertyValue("IsModified"));
339 bool bResult
= !bIsModified
;
345 _xCursor
->insertRow();
347 _xCursor
->updateRow();
350 catch(const Exception
&)
352 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
358 static vcl::Window
* lcl_GetFocusChild( vcl::Window
const * pParent
)
360 sal_uInt16 nChildren
= pParent
->GetChildCount();
361 for( sal_uInt16 nChild
= 0; nChild
< nChildren
; ++nChild
)
363 vcl::Window
* pChild
= pParent
->GetChild( nChild
);
364 if(pChild
->HasFocus())
366 vcl::Window
* pSubChild
= lcl_GetFocusChild( pChild
);
374 void BibFrameController_Impl::dispatch(const util::URL
& _rURL
, const uno::Sequence
< beans::PropertyValue
>& aArgs
)
379 ::SolarMutexGuard aGuard
;
380 weld::Window
* pParent
= Application::GetFrameWeld(m_xWindow
);
381 weld::WaitObject
aWaitObject(pParent
);
383 OUString
aCommand( _rURL
.Path
);
384 if(aCommand
== "Bib/Mapping")
386 m_xDatMan
->CreateMappingDialog(pParent
);
388 else if(aCommand
== "Bib/source")
390 ChangeDataSource(aArgs
);
392 else if(aCommand
== "Bib/sdbsource")
394 OUString aURL
= m_xDatMan
->CreateDBChangeDialog(pParent
);
399 uno::Sequence
< beans::PropertyValue
> aNewDataSource
401 comphelper::makePropertyValue( {}, OUString() ),
402 comphelper::makePropertyValue( {}, aURL
)
404 ChangeDataSource(aNewDataSource
);
406 catch(const Exception
&)
408 TOOLS_WARN_EXCEPTION("extensions.biblio",
409 "Exception caught while changing the data source");
413 else if(aCommand
== "Bib/autoFilter")
415 sal_uInt16 nCount
= m_aStatusListeners
.size();
416 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
418 BibStatusDispatch
*pObj
= m_aStatusListeners
[n
].get();
419 if ( pObj
->aURL
.Path
== "Bib/removeFilter" )
421 FeatureStateEvent aEvent
;
422 aEvent
.FeatureURL
= pObj
->aURL
;
423 aEvent
.IsEnabled
= true;
424 aEvent
.Requery
= false;
425 aEvent
.Source
= static_cast<XDispatch
*>(this);
426 pObj
->xListener
->statusChanged( aEvent
);
427 //break; because there are more than one
431 const beans::PropertyValue
* pPropertyValue
= aArgs
.getConstArray();
432 uno::Any aValue
=pPropertyValue
[0].Value
;
436 aValue
=pPropertyValue
[1].Value
;
437 OUString aQueryField
;
438 aValue
>>= aQueryField
;
439 BibConfig
* pConfig
= BibModul::GetConfig();
440 pConfig
->setQueryField(aQueryField
);
441 m_xDatMan
->startQueryWith(aQuery
);
443 else if(aCommand
== "Bib/standardFilter")
447 uno::Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
449 // create the dialog object
450 uno::Reference
< ui::dialogs::XExecutableDialog
> xDialog
= sdb::FilterDialog::createWithQuery(xContext
, m_xDatMan
->getParser(),
451 Reference
<sdbc::XRowSet
>(m_xDatMan
->getForm(), uno::UNO_QUERY_THROW
), m_xWindow
);
453 if ( xDialog
->execute( ) )
455 // the dialog has been executed successfully, and the filter on the query composer
457 OUString sNewFilter
= m_xDatMan
->getParser()->getFilter();
458 m_xDatMan
->setFilter( sNewFilter
);
461 catch( const uno::Exception
& )
463 TOOLS_WARN_EXCEPTION( "extensions.biblio", "BibFrameController_Impl::dispatch" );
466 sal_uInt16 nCount
= m_aStatusListeners
.size();
467 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
469 BibStatusDispatch
*pObj
= m_aStatusListeners
[n
].get();
470 if ( pObj
->aURL
.Path
== "Bib/removeFilter" && m_xDatMan
->getParser().is())
472 FeatureStateEvent aEvent
;
473 aEvent
.FeatureURL
= pObj
->aURL
;
474 aEvent
.IsEnabled
= !m_xDatMan
->getParser()->getFilter().isEmpty();
475 aEvent
.Requery
= false;
476 aEvent
.Source
= static_cast<XDispatch
*>(this);
477 pObj
->xListener
->statusChanged( aEvent
);
481 else if(aCommand
== "Bib/removeFilter")
485 else if( _rURL
.Complete
== ".uno:CloseDoc" || aCommand
== "CloseDoc" )
487 Application::PostUserEvent( LINK( this, BibFrameController_Impl
,
491 else if(aCommand
== "Bib/InsertRecord")
493 Reference
<form::runtime::XFormController
> xFormCtrl
= m_xDatMan
->GetFormController();
494 if(SaveModified(xFormCtrl
))
498 Reference
< sdbc::XResultSet
> xCursor( m_xDatMan
->getForm(), UNO_QUERY
);
501 Reference
< XResultSetUpdate
> xUpdateCursor( m_xDatMan
->getForm(), UNO_QUERY
);
502 xUpdateCursor
->moveToInsertRow();
504 catch(const Exception
&)
506 TOOLS_WARN_EXCEPTION("extensions.biblio",
507 "Exception in last() or moveToInsertRow()");
511 else if(aCommand
== "Bib/DeleteRecord")
513 Reference
< css::sdbc::XResultSet
> xCursor(m_xDatMan
->getForm(), UNO_QUERY
);
514 Reference
< XResultSetUpdate
> xUpdateCursor(xCursor
, UNO_QUERY
);
515 Reference
< beans::XPropertySet
> xSet(m_xDatMan
->getForm(), UNO_QUERY
);
516 bool bIsNew
= ::comphelper::getBOOL(xSet
->getPropertyValue("IsNew"));
519 sal_uInt32 nCount
= 0;
520 xSet
->getPropertyValue("RowCount") >>= nCount
;
521 // determine next position
522 bool bSuccess
= false;
527 bLeft
= xCursor
->isLast() && nCount
> 1;
528 bRight
= !xCursor
->isLast();
529 // ask for confirmation
530 Reference
< form::XConfirmDeleteListener
> xConfirm(m_xDatMan
->GetFormController(),UNO_QUERY
);
533 sdb::RowChangeEvent aEvent
;
534 aEvent
.Source
.set(xCursor
, UNO_QUERY
);
535 aEvent
.Action
= sdb::RowChangeAction::DELETE
;
537 bSuccess
= xConfirm
->confirmDelete(aEvent
);
542 xUpdateCursor
->deleteRow();
544 catch(const Exception
&)
551 xCursor
->relative(bRight
? 1 : -1);
554 bool bCanInsert
= canInsertRecords(xSet
);
555 // can another entry be inserted?
559 xUpdateCursor
->moveToInsertRow();
561 // move data entry to reset state
564 catch(const Exception
&)
566 TOOLS_WARN_EXCEPTION("extensions.biblio",
567 "DeleteRecord: exception caught!");
573 else if(aCommand
== "Cut")
575 vcl::Window
* pChild
= m_xLastQueriedFocusWin
.get();
578 KeyEvent
aEvent( 0, KeyFuncType::CUT
);
579 pChild
->KeyInput( aEvent
);
582 else if(aCommand
== "Copy")
584 vcl::Window
* pChild
= m_xLastQueriedFocusWin
.get();
587 KeyEvent
aEvent( 0, KeyFuncType::COPY
);
588 pChild
->KeyInput( aEvent
);
591 else if(aCommand
== "Paste")
593 vcl::Window
* pChild
= m_xLastQueriedFocusWin
.get();
596 KeyEvent
aEvent( 0, KeyFuncType::PASTE
);
597 pChild
->KeyInput( aEvent
);
601 IMPL_LINK_NOARG( BibFrameController_Impl
, DisposeHdl
, void*, void )
607 void BibFrameController_Impl::addStatusListener(
608 const uno::Reference
< frame::XStatusListener
> & aListener
,
609 const util::URL
& aURL
)
611 BibConfig
* pConfig
= BibModul::GetConfig();
612 // create a new Reference and insert into listener array
613 m_aStatusListeners
.push_back( std::make_unique
<BibStatusDispatch
>( aURL
, aListener
) );
615 // send first status synchronously
616 FeatureStateEvent aEvent
;
617 aEvent
.FeatureURL
= aURL
;
618 aEvent
.Requery
= false;
619 aEvent
.Source
= static_cast<XDispatch
*>(this);
620 if ( aURL
.Path
== "StatusBarVisible" )
622 aEvent
.IsEnabled
= false;
623 aEvent
.State
<<= false;
625 else if ( aURL
.Path
== "Bib/hierarchical" )
627 aEvent
.IsEnabled
= true;
628 aEvent
.State
<<= OUString();
630 else if(aURL
.Path
== "Bib/MenuFilter")
632 aEvent
.IsEnabled
= true;
633 aEvent
.FeatureDescriptor
=m_xDatMan
->getQueryField();
635 aEvent
.State
<<= m_xDatMan
->getQueryFields();
638 else if ( aURL
.Path
== "Bib/source")
640 aEvent
.IsEnabled
= true;
641 aEvent
.FeatureDescriptor
=m_xDatMan
->getActiveDataTable();
643 aEvent
.State
<<= m_xDatMan
->getDataSources();
645 else if( aURL
.Path
== "Bib/sdbsource" ||
646 aURL
.Path
== "Bib/Mapping" ||
647 aURL
.Path
== "Bib/autoFilter" ||
648 aURL
.Path
== "Bib/standardFilter" )
650 aEvent
.IsEnabled
= true;
652 else if(aURL
.Path
== "Bib/query")
654 aEvent
.IsEnabled
= true;
655 aEvent
.State
<<= pConfig
->getQueryText();
657 else if (aURL
.Path
== "Bib/removeFilter" )
659 OUString aFilterStr
=m_xDatMan
->getFilter();
660 aEvent
.IsEnabled
= !aFilterStr
.isEmpty();
662 else if(aURL
.Path
== "Cut")
664 m_xLastQueriedFocusWin
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( m_xWindow
) );
665 if (m_xLastQueriedFocusWin
)
667 Reference
<css::awt::XTextComponent
> xEdit(m_xLastQueriedFocusWin
->GetComponentInterface(), css::uno::UNO_QUERY
);
668 aEvent
.IsEnabled
= xEdit
&& xEdit
->isEditable() && !xEdit
->getSelectedText().isEmpty();
671 if(aURL
.Path
== "Copy")
673 m_xLastQueriedFocusWin
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( m_xWindow
) );
674 if (m_xLastQueriedFocusWin
)
676 Reference
<css::awt::XTextComponent
> xEdit(m_xLastQueriedFocusWin
->GetComponentInterface(), css::uno::UNO_QUERY
);
677 aEvent
.IsEnabled
= xEdit
&& !xEdit
->getSelectedText().isEmpty();
680 else if(aURL
.Path
== "Paste" )
682 aEvent
.IsEnabled
= false;
683 m_xLastQueriedFocusWin
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( m_xWindow
) );
684 if (m_xLastQueriedFocusWin
)
686 Reference
<css::awt::XTextComponent
> xEdit(m_xLastQueriedFocusWin
->GetComponentInterface(), css::uno::UNO_QUERY
);
687 if (xEdit
&& !xEdit
->isEditable())
689 uno::Reference
< datatransfer::clipboard::XClipboard
> xClip
= m_xLastQueriedFocusWin
->GetClipboard();
692 uno::Reference
< datatransfer::XTransferable
> xDataObj
;
696 SolarMutexReleaser aReleaser
;
697 xDataObj
= xClip
->getContents();
699 catch( const uno::Exception
& )
705 datatransfer::DataFlavor aFlavor
;
706 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING
, aFlavor
);
709 uno::Any aData
= xDataObj
->getTransferData( aFlavor
);
712 aEvent
.IsEnabled
= !aText
.isEmpty();
714 catch( const uno::Exception
& )
722 else if(aURL
.Path
== "Bib/DeleteRecord")
724 Reference
< beans::XPropertySet
> xSet(m_xDatMan
->getForm(), UNO_QUERY
);
725 bool bIsNew
= ::comphelper::getBOOL(xSet
->getPropertyValue("IsNew"));
728 sal_uInt32 nCount
= 0;
729 xSet
->getPropertyValue("RowCount") >>= nCount
;
730 aEvent
.IsEnabled
= nCount
> 0;
733 else if (aURL
.Path
== "Bib/InsertRecord")
735 Reference
< beans::XPropertySet
> xSet(m_xDatMan
->getForm(), UNO_QUERY
);
736 aEvent
.IsEnabled
= canInsertRecords(xSet
);
738 aListener
->statusChanged( aEvent
);
741 void BibFrameController_Impl::removeStatusListener(
742 const uno::Reference
< frame::XStatusListener
> & aObject
, const util::URL
& aURL
)
744 // search listener array for given listener
745 // for checking equality always "cast" to XInterface
749 sal_uInt16 nCount
= m_aStatusListeners
.size();
750 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
752 BibStatusDispatch
*pObj
= m_aStatusListeners
[n
].get();
753 bool bFlag
=pObj
->xListener
.is();
754 if (!bFlag
|| (pObj
->xListener
== aObject
&&
755 ( aURL
.Complete
.isEmpty() || pObj
->aURL
.Path
== aURL
.Path
)))
757 m_aStatusListeners
.erase( m_aStatusListeners
.begin() + n
);
763 void BibFrameController_Impl::RemoveFilter()
766 m_xDatMan
->startQueryWith(aQuery
);
768 sal_uInt16 nCount
= m_aStatusListeners
.size();
770 bool bRemoveFilter
=false;
771 bool bQueryText
=false;
773 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
775 BibStatusDispatch
*pObj
= m_aStatusListeners
[n
].get();
776 if ( pObj
->aURL
.Path
== "Bib/removeFilter" )
778 FeatureStateEvent aEvent
;
779 aEvent
.FeatureURL
= pObj
->aURL
;
780 aEvent
.IsEnabled
= false;
781 aEvent
.Requery
= false;
782 aEvent
.Source
= static_cast<XDispatch
*>(this);
783 pObj
->xListener
->statusChanged( aEvent
);
786 else if(pObj
->aURL
.Path
== "Bib/query")
788 FeatureStateEvent aEvent
;
789 aEvent
.FeatureURL
= pObj
->aURL
;
790 aEvent
.IsEnabled
= true;
791 aEvent
.Requery
= false;
792 aEvent
.Source
= static_cast<XDispatch
*>(this);
793 aEvent
.State
<<= aQuery
;
794 pObj
->xListener
->statusChanged( aEvent
);
798 if(bRemoveFilter
&& bQueryText
)
804 void BibFrameController_Impl::ChangeDataSource(const uno::Sequence
< beans::PropertyValue
>& aArgs
)
806 const beans::PropertyValue
* pPropertyValue
= aArgs
.getConstArray();
807 uno::Any aValue
=pPropertyValue
[0].Value
;
808 OUString aDBTableName
;
809 aValue
>>= aDBTableName
;
812 if(aArgs
.getLength() > 1)
814 uno::Any aDB
= pPropertyValue
[1].Value
;
817 m_xDatMan
->setActiveDataSource(aURL
);
818 aDBTableName
= m_xDatMan
->getActiveDataTable();
822 Reference
<css::form::XLoadable
> xLoadable(m_xDatMan
);
824 m_xDatMan
->setActiveDataTable(aDBTableName
);
825 m_xDatMan
->updateGridModel();
830 sal_uInt16 nCount
= m_aStatusListeners
.size();
832 bool bMenuFilter
=false;
833 bool bQueryText
=false;
834 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
836 BibStatusDispatch
*pObj
= m_aStatusListeners
[n
].get();
837 if (pObj
->aURL
.Path
== "Bib/MenuFilter")
839 FeatureStateEvent aEvent
;
840 aEvent
.FeatureURL
= pObj
->aURL
;
841 aEvent
.IsEnabled
= true;
842 aEvent
.Requery
= false;
843 aEvent
.Source
= static_cast<XDispatch
*>(this);
844 aEvent
.FeatureDescriptor
=m_xDatMan
->getQueryField();
846 uno::Sequence
<OUString
> aStringSeq
=m_xDatMan
->getQueryFields();
847 aEvent
.State
<<= aStringSeq
;
849 pObj
->xListener
->statusChanged( aEvent
);
852 else if (pObj
->aURL
.Path
== "Bib/query")
854 FeatureStateEvent aEvent
;
855 aEvent
.FeatureURL
= pObj
->aURL
;
856 aEvent
.IsEnabled
= true;
857 aEvent
.Requery
= false;
858 aEvent
.Source
= static_cast<XDispatch
*>(this);
859 BibConfig
* pConfig
= BibModul::GetConfig();
860 aEvent
.State
<<= pConfig
->getQueryText();
861 pObj
->xListener
->statusChanged( aEvent
);
865 if (bMenuFilter
&& bQueryText
)
871 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */