tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / extensions / source / bibliography / framectr.cxx
blob8a5ce26e7e74b2d6177ad45ea5dded9c4b72cbe3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
24 #include "datman.hxx"
25 #include <toolkit/helper/vclunohelper.hxx>
26 #include "bibconfig.hxx"
27 #include <cppuhelper/implbase.hxx>
28 #include <utility>
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>
54 using namespace osl;
55 using namespace cppu;
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;
61 namespace {
63 struct DispatchInfo
65 const char* pCommand;
66 sal_Int16 nGroupId;
67 bool bActiveConnection;
70 struct CacheDispatchInfo
72 sal_Int16 nGroupId;
73 bool bActiveConnection;
78 // Attention: commands must be sorted by command groups. Implementation is dependent
79 // on this!!
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);
116 return aCache;
117 }();
119 return aCmdToInfoCache;
123 class BibFrameCtrl_Impl : public cppu::WeakImplHelper < XFrameActionListener >
125 public:
126 Mutex aMutex;
127 comphelper::OMultiTypeInterfaceContainerHelper2 aLC;
129 BibFrameController_Impl* pController;
131 BibFrameCtrl_Impl()
132 : aLC( aMutex )
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;
147 if ( pController )
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;
164 m_xDatMan.clear();
167 OUString SAL_CALL BibFrameController_Impl::getImplementationName()
169 return u"com.sun.star.comp.extensions.Bibliography"_ustr;
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 { u"com.sun.star.frame.Bibliography"_ustr };
184 void BibFrameController_Impl::attachFrame( const uno::Reference< XFrame > & xArg )
186 m_xFrame = xArg;
187 m_xFrame->addFrameActionListener( m_xImpl );
190 sal_Bool BibFrameController_Impl::attachModel( const uno::Reference< XModel > & /*xModel*/ )
192 return false;
195 sal_Bool BibFrameController_Impl::suspend( sal_Bool bSuspend )
197 if ( bSuspend )
198 getFrame()->removeFrameActionListener( m_xImpl );
199 else
200 getFrame()->addFrameActionListener( m_xImpl );
201 return true;
204 uno::Any BibFrameController_Impl::getViewData()
206 return uno::Any();
209 void BibFrameController_Impl::restoreViewData( const uno::Any& /*Value*/ )
213 uno::Reference< XFrame > BibFrameController_Impl::getFrame()
215 return m_xFrame;
218 uno::Reference< XModel > BibFrameController_Impl::getModel()
220 return uno::Reference< XModel > ();
223 void BibFrameController_Impl::dispose()
225 m_bDisposing = true;
226 lang::EventObject aObject;
227 uno::Reference< XFrame > xFrame = getFrame();
229 if (xFrame.is())
230 xFrame->removeFrameActionListener( m_xImpl );
231 m_xFrame.clear();
233 aObject.Source = static_cast<XController*>(this);
234 m_xImpl->aLC.disposeAndClear(aObject);
235 m_xDatMan.clear();
236 m_aStatusListeners.clear();
237 m_xLastQueriedFocusWin.clear();
238 m_xWindow.clear();
239 m_xImpl.clear();
242 void BibFrameController_Impl::addEventListener( const uno::Reference< lang::XEventListener > & aListener )
244 m_xImpl->aLC.addInterface( cppu::UnoType<lang::XEventListener>::get(), aListener );
247 void BibFrameController_Impl::removeEventListener( const uno::Reference< lang::XEventListener > & aListener )
249 m_xImpl->aLC.removeInterface( cppu::UnoType<lang::XEventListener>::get(), aListener );
252 uno::Reference< frame::XDispatch > BibFrameController_Impl::queryDispatch( const util::URL& aURL, const OUString& /*aTarget*/, sal_Int32 /*nSearchFlags*/ )
254 if ( !m_bDisposing )
256 const CmdToInfoCache& rCmdCache = GetCommandToInfoCache();
257 CmdToInfoCache::const_iterator pIter = rCmdCache.find( aURL.Complete );
258 if ( pIter != rCmdCache.end() )
260 if (( m_xDatMan->HasActiveConnection() ) ||
261 ( !pIter->second.bActiveConnection ))
262 return static_cast<frame::XDispatch*>(this);
266 return uno::Reference< frame::XDispatch > ();
269 uno::Sequence<uno::Reference< XDispatch > > BibFrameController_Impl::queryDispatches( const uno::Sequence<DispatchDescriptor>& aDescripts )
271 uno::Sequence< uno::Reference< XDispatch > > aDispatches( aDescripts.getLength() );
272 auto aDispatchesRange = asNonConstRange(aDispatches);
273 for ( sal_Int32 i=0; i<aDescripts.getLength(); ++i )
274 aDispatchesRange[i] = queryDispatch( aDescripts[i].FeatureURL, aDescripts[i].FrameName, aDescripts[i].SearchFlags );
275 return aDispatches;
278 uno::Sequence< ::sal_Int16 > SAL_CALL BibFrameController_Impl::getSupportedCommandGroups()
280 uno::Sequence< ::sal_Int16 > aDispatchInfo{ frame::CommandGroup::EDIT,
281 frame::CommandGroup::DOCUMENT,
282 frame::CommandGroup::DATA,
283 frame::CommandGroup::VIEW };
285 return aDispatchInfo;
288 uno::Sequence< frame::DispatchInformation > SAL_CALL BibFrameController_Impl::getConfigurableDispatchInformation( ::sal_Int16 nCommandGroup )
290 const CmdToInfoCache& rCmdCache = GetCommandToInfoCache();
292 frame::DispatchInformation aDispatchInfo;
293 std::vector< frame::DispatchInformation > aDispatchInfoVector;
295 if (( nCommandGroup == frame::CommandGroup::EDIT ) ||
296 ( nCommandGroup == frame::CommandGroup::DOCUMENT ) ||
297 ( nCommandGroup == frame::CommandGroup::DATA ) ||
298 ( nCommandGroup == frame::CommandGroup::VIEW ))
300 bool bGroupFound = false;
301 for (auto const& item : rCmdCache)
303 if ( item.second.nGroupId == nCommandGroup )
305 bGroupFound = true;
306 aDispatchInfo.Command = item.first;
307 aDispatchInfo.GroupId = item.second.nGroupId;
308 aDispatchInfoVector.push_back( aDispatchInfo );
310 else if ( bGroupFound )
311 break;
315 return comphelper::containerToSequence( aDispatchInfoVector );
318 static bool canInsertRecords(const Reference< beans::XPropertySet>& _rxCursorSet)
320 sal_Int32 nPriv = 0;
321 _rxCursorSet->getPropertyValue(u"Privileges"_ustr) >>= nPriv;
322 return _rxCursorSet.is() && (nPriv & sdbcx::Privilege::INSERT) != 0;
325 bool BibFrameController_Impl::SaveModified(const Reference< form::runtime::XFormController>& xController)
327 if (!xController.is())
328 return false;
330 Reference< XResultSetUpdate> _xCursor(xController->getModel(), UNO_QUERY);
332 if (!_xCursor.is())
333 return false;
335 Reference< beans::XPropertySet> _xSet(_xCursor, UNO_QUERY);
336 if (!_xSet.is())
337 return false;
339 // need to save?
340 bool bIsNew = ::comphelper::getBOOL(_xSet->getPropertyValue(u"IsNew"_ustr));
341 bool bIsModified = ::comphelper::getBOOL(_xSet->getPropertyValue(u"IsModified"_ustr));
342 bool bResult = !bIsModified;
343 if (bIsModified)
347 if (bIsNew)
348 _xCursor->insertRow();
349 else
350 _xCursor->updateRow();
351 bResult = true;
353 catch(const Exception&)
355 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
358 return bResult;
361 static vcl::Window* lcl_GetFocusChild( vcl::Window const * pParent )
363 sal_uInt16 nChildren = pParent->GetChildCount();
364 for( sal_uInt16 nChild = 0; nChild < nChildren; ++nChild)
366 vcl::Window* pChild = pParent->GetChild( nChild );
367 if(pChild->HasFocus())
368 return pChild;
369 vcl::Window* pSubChild = lcl_GetFocusChild( pChild );
370 if(pSubChild)
371 return pSubChild;
373 return nullptr;
376 //class XDispatch
377 void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequence< beans::PropertyValue >& aArgs)
379 if ( m_bDisposing )
380 return;
382 ::SolarMutexGuard aGuard;
383 weld::Window* pParent = Application::GetFrameWeld(m_xWindow);
384 weld::WaitObject aWaitObject(pParent);
386 OUString aCommand( _rURL.Path);
387 if(aCommand == "Bib/Mapping")
389 m_xDatMan->CreateMappingDialog(pParent);
391 else if(aCommand == "Bib/source")
393 ChangeDataSource(aArgs);
395 else if(aCommand == "Bib/sdbsource")
397 OUString aURL = m_xDatMan->CreateDBChangeDialog(pParent);
398 if(!aURL.isEmpty())
402 uno::Sequence< beans::PropertyValue > aNewDataSource
404 comphelper::makePropertyValue( {}, OUString() ),
405 comphelper::makePropertyValue( {}, aURL )
407 ChangeDataSource(aNewDataSource);
409 catch(const Exception&)
411 TOOLS_WARN_EXCEPTION("extensions.biblio",
412 "Exception caught while changing the data source");
416 else if(aCommand == "Bib/autoFilter")
418 sal_uInt16 nCount = m_aStatusListeners.size();
419 for ( sal_uInt16 n=0; n<nCount; n++ )
421 BibStatusDispatch *pObj = m_aStatusListeners[n].get();
422 if ( pObj->aURL.Path == "Bib/removeFilter" )
424 FeatureStateEvent aEvent;
425 aEvent.FeatureURL = pObj->aURL;
426 aEvent.IsEnabled = true;
427 aEvent.Requery = false;
428 aEvent.Source = static_cast<XDispatch *>(this);
429 pObj->xListener->statusChanged( aEvent );
430 //break; because there are more than one
434 OUString aQuery;
435 aArgs[0].Value >>= aQuery;
437 OUString aQueryField;
438 aArgs[1].Value >>= aQueryField;
439 BibConfig* pConfig = BibModul::GetConfig();
440 pConfig->setQueryField(aQueryField);
441 m_xDatMan->startQueryWith(aQuery);
443 else if(aCommand == "Bib/standardFilter")
447 const 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);
452 // execute it
453 if ( xDialog->execute( ) )
455 // the dialog has been executed successfully, and the filter on the query composer
456 // has been changed
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")
483 RemoveFilter();
485 else if( _rURL.Complete == ".uno:CloseDoc" || aCommand == "CloseDoc" )
487 Application::PostUserEvent( LINK( this, BibFrameController_Impl,
488 DisposeHdl ) );
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 );
499 xCursor->last();
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(u"IsNew"_ustr));
517 if(!bIsNew)
519 sal_uInt32 nCount = 0;
520 xSet->getPropertyValue(u"RowCount"_ustr) >>= nCount;
521 // determine next position
522 bool bSuccess = false;
523 bool bLeft = false;
524 bool bRight = 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);
531 if (xConfirm.is())
533 sdb::RowChangeEvent aEvent;
534 aEvent.Source.set(xCursor, UNO_QUERY);
535 aEvent.Action = sdb::RowChangeAction::DELETE;
536 aEvent.Rows = 1;
537 bSuccess = xConfirm->confirmDelete(aEvent);
540 // delete it
541 if (bSuccess)
542 xUpdateCursor->deleteRow();
544 catch(const Exception&)
546 bSuccess = false;
548 if (bSuccess)
550 if (bLeft || bRight)
551 xCursor->relative(bRight ? 1 : -1);
552 else
554 bool bCanInsert = canInsertRecords(xSet);
555 // can another entry be inserted?
558 if (bCanInsert)
559 xUpdateCursor->moveToInsertRow();
560 else
561 // move data entry to reset state
562 xCursor->first();
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();
576 if(pChild)
578 KeyEvent aEvent( 0, KeyFuncType::CUT );
579 pChild->KeyInput( aEvent );
582 else if(aCommand == "Copy")
584 vcl::Window* pChild = m_xLastQueriedFocusWin.get();
585 if(pChild)
587 KeyEvent aEvent( 0, KeyFuncType::COPY );
588 pChild->KeyInput( aEvent );
591 else if(aCommand == "Paste")
593 vcl::Window* pChild = m_xLastQueriedFocusWin.get();
594 if(pChild)
596 KeyEvent aEvent( 0, KeyFuncType::PASTE );
597 pChild->KeyInput( aEvent );
601 IMPL_LINK_NOARG( BibFrameController_Impl, DisposeHdl, void*, void )
603 if (m_xFrame.is())
604 m_xFrame->dispose();
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();
690 if(xClip.is())
692 uno::Reference< datatransfer::XTransferable > xDataObj;
696 SolarMutexReleaser aReleaser;
697 xDataObj = xClip->getContents();
699 catch( const uno::Exception& )
703 if ( xDataObj.is() )
705 datatransfer::DataFlavor aFlavor;
706 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aFlavor );
709 uno::Any aData = xDataObj->getTransferData( aFlavor );
710 OUString aText;
711 aData >>= aText;
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(u"IsNew"_ustr));
726 if(!bIsNew)
728 sal_uInt32 nCount = 0;
729 xSet->getPropertyValue(u"RowCount"_ustr) >>= 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
746 if ( m_bDisposing )
747 return;
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 );
758 break;
763 void BibFrameController_Impl::RemoveFilter()
765 OUString aQuery;
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 );
784 bRemoveFilter=true;
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 );
795 bQueryText=true;
798 if(bRemoveFilter && bQueryText)
799 break;
804 void BibFrameController_Impl::ChangeDataSource(const uno::Sequence< beans::PropertyValue >& aArgs)
806 uno::Any aValue = aArgs[0].Value;
807 OUString aDBTableName;
808 aValue >>= aDBTableName;
811 if(aArgs.getLength() > 1)
813 uno::Any aDB = aArgs[1].Value;
814 OUString aURL;
815 aDB >>= aURL;
816 m_xDatMan->setActiveDataSource(aURL);
817 aDBTableName = m_xDatMan->getActiveDataTable();
819 else
821 Reference<css::form::XLoadable> xLoadable(m_xDatMan);
822 xLoadable->unload();
823 m_xDatMan->setActiveDataTable(aDBTableName);
824 m_xDatMan->updateGridModel();
825 xLoadable->load();
829 sal_uInt16 nCount = m_aStatusListeners.size();
831 bool bMenuFilter=false;
832 bool bQueryText=false;
833 for ( sal_uInt16 n=0; n<nCount; n++ )
835 BibStatusDispatch *pObj = m_aStatusListeners[n].get();
836 if (pObj->aURL.Path == "Bib/MenuFilter")
838 FeatureStateEvent aEvent;
839 aEvent.FeatureURL = pObj->aURL;
840 aEvent.IsEnabled = true;
841 aEvent.Requery = false;
842 aEvent.Source = static_cast<XDispatch *>(this);
843 aEvent.FeatureDescriptor=m_xDatMan->getQueryField();
845 uno::Sequence<OUString> aStringSeq=m_xDatMan->getQueryFields();
846 aEvent.State <<= aStringSeq;
848 pObj->xListener->statusChanged( aEvent );
849 bMenuFilter=true;
851 else if (pObj->aURL.Path == "Bib/query")
853 FeatureStateEvent aEvent;
854 aEvent.FeatureURL = pObj->aURL;
855 aEvent.IsEnabled = true;
856 aEvent.Requery = false;
857 aEvent.Source = static_cast<XDispatch *>(this);
858 BibConfig* pConfig = BibModul::GetConfig();
859 aEvent.State <<= pConfig->getQueryText();
860 pObj->xListener->statusChanged( aEvent );
861 bQueryText=true;
864 if (bMenuFilter && bQueryText)
865 break;
870 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */