LibreOffice Module extensions (master) 1
framectr.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <comphelper/types.hxx>
23#include "framectr.hxx"
24#include "datman.hxx"
26#include "bibconfig.hxx"
28#include <utility>
29#include <vcl/event.hxx>
30#include <vcl/svapp.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>
46#include <sot/exchange.hxx>
47#include <sot/formats.hxx>
49#include <vcl/weld.hxx>
50#include <osl/mutex.hxx>
51
52#include <unordered_map>
53
54using namespace osl;
55using namespace cppu;
56using namespace com::sun::star::sdbc;
57using namespace com::sun::star::frame;
58using namespace com::sun::star::uno;
59using namespace com::sun::star;
60
61namespace {
62
63struct DispatchInfo
64{
65 const char* pCommand;
66 sal_Int16 nGroupId;
67 bool bActiveConnection;
68};
69
70struct CacheDispatchInfo
71{
72 sal_Int16 nGroupId;
73 bool bActiveConnection;
74};
75
76}
77
78// Attention: commands must be sorted by command groups. Implementation is dependent
79// on this!!
80const DispatchInfo SupportedCommandsArray[] =
81{
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 },
99};
100
101typedef std::unordered_map< OUString, CacheDispatchInfo > CmdToInfoCache;
102
104{
105 static CmdToInfoCache aCmdToInfoCache = []() {
106 CmdToInfoCache aCache;
107 for (const auto& command : SupportedCommandsArray)
108 {
109 OUString aCommand(OUString::createFromAscii(command.pCommand));
110
111 CacheDispatchInfo aDispatchInfo;
112 aDispatchInfo.nGroupId = command.nGroupId;
113 aDispatchInfo.bActiveConnection = command.bActiveConnection;
114 aCache.emplace(aCommand, aDispatchInfo);
115 }
116 return aCache;
117 }();
118
119 return aCmdToInfoCache;
120}
121
122
123class BibFrameCtrl_Impl : public cppu::WeakImplHelper < XFrameActionListener >
124{
125public:
126 Mutex aMutex;
128
130
132 : aLC( aMutex )
133 , pController(nullptr)
134 {}
135
136 virtual void SAL_CALL frameAction(const FrameActionEvent& aEvent) override;
137 virtual void SAL_CALL disposing( const lang::EventObject& Source ) override;
138};
139
140void BibFrameCtrl_Impl::frameAction(const FrameActionEvent& )
141{
142}
143
144void BibFrameCtrl_Impl::disposing( const lang::EventObject& /*Source*/ )
145{
146 ::SolarMutexGuard aGuard;
147 if ( pController )
148 pController->getFrame()->removeFrameActionListener( this );
149}
150
151BibFrameController_Impl::BibFrameController_Impl( uno::Reference< awt::XWindow > xComponent,
152 BibDataManager* pDataManager)
153 :m_xWindow(std::move( xComponent ))
154 ,m_xDatMan( pDataManager )
155{
156 m_bDisposing = false;
158 m_xImpl->pController = this;
159}
160
162{
163 m_xImpl->pController = nullptr;
164 m_xDatMan.clear();
165}
166
168{
169 return "com.sun.star.comp.extensions.Bibliography";
170}
171
172sal_Bool SAL_CALL BibFrameController_Impl::supportsService( const OUString& sServiceName )
173{
174 return cppu::supportsService( this, sServiceName );
175}
176
177css::uno::Sequence< OUString > SAL_CALL BibFrameController_Impl::getSupportedServiceNames()
178{
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" };
182}
183
184void BibFrameController_Impl::attachFrame( const uno::Reference< XFrame > & xArg )
185{
186 m_xFrame = xArg;
187 m_xFrame->addFrameActionListener( m_xImpl );
188}
189
190sal_Bool BibFrameController_Impl::attachModel( const uno::Reference< XModel > & /*xModel*/ )
191{
192 return false;
193}
194
196{
197 if ( bSuspend )
198 getFrame()->removeFrameActionListener( m_xImpl );
199 else
200 getFrame()->addFrameActionListener( m_xImpl );
201 return true;
202}
203
205{
206 return uno::Any();
207}
208
210{
211}
212
213uno::Reference< XFrame > BibFrameController_Impl::getFrame()
214{
215 return m_xFrame;
216}
217
218uno::Reference< XModel > BibFrameController_Impl::getModel()
219{
220 return uno::Reference< XModel > ();
221}
222
224{
225 m_bDisposing = true;
226 lang::EventObject aObject;
227 uno::Reference< XFrame > xFrame = getFrame();
228
229 if (xFrame.is())
230 xFrame->removeFrameActionListener( m_xImpl );
231
232 aObject.Source = static_cast<XController*>(this);
233 m_xImpl->aLC.disposeAndClear(aObject);
234 m_xDatMan.clear();
235 m_aStatusListeners.clear();
237}
238
239void BibFrameController_Impl::addEventListener( const uno::Reference< lang::XEventListener > & aListener )
240{
241 m_xImpl->aLC.addInterface( cppu::UnoType<lang::XEventListener>::get(), aListener );
242}
243
244void BibFrameController_Impl::removeEventListener( const uno::Reference< lang::XEventListener > & aListener )
245{
246 m_xImpl->aLC.removeInterface( cppu::UnoType<lang::XEventListener>::get(), aListener );
247}
248
249uno::Reference< frame::XDispatch > BibFrameController_Impl::queryDispatch( const util::URL& aURL, const OUString& /*aTarget*/, sal_Int32 /*nSearchFlags*/ )
250{
251 if ( !m_bDisposing )
252 {
253 const CmdToInfoCache& rCmdCache = GetCommandToInfoCache();
254 CmdToInfoCache::const_iterator pIter = rCmdCache.find( aURL.Complete );
255 if ( pIter != rCmdCache.end() )
256 {
257 if (( m_xDatMan->HasActiveConnection() ) ||
258 ( !pIter->second.bActiveConnection ))
259 return static_cast<frame::XDispatch*>(this);
260 }
261 }
262
263 return uno::Reference< frame::XDispatch > ();
264}
265
266uno::Sequence<uno::Reference< XDispatch > > BibFrameController_Impl::queryDispatches( const uno::Sequence<DispatchDescriptor>& aDescripts )
267{
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 );
272 return aDispatches;
273}
274
275uno::Sequence< ::sal_Int16 > SAL_CALL BibFrameController_Impl::getSupportedCommandGroups()
276{
277 uno::Sequence< ::sal_Int16 > aDispatchInfo{ frame::CommandGroup::EDIT,
278 frame::CommandGroup::DOCUMENT,
279 frame::CommandGroup::DATA,
280 frame::CommandGroup::VIEW };
281
282 return aDispatchInfo;
283}
284
285uno::Sequence< frame::DispatchInformation > SAL_CALL BibFrameController_Impl::getConfigurableDispatchInformation( ::sal_Int16 nCommandGroup )
286{
287 const CmdToInfoCache& rCmdCache = GetCommandToInfoCache();
288
289 frame::DispatchInformation aDispatchInfo;
290 std::vector< frame::DispatchInformation > aDispatchInfoVector;
291
292 if (( nCommandGroup == frame::CommandGroup::EDIT ) ||
293 ( nCommandGroup == frame::CommandGroup::DOCUMENT ) ||
294 ( nCommandGroup == frame::CommandGroup::DATA ) ||
295 ( nCommandGroup == frame::CommandGroup::VIEW ))
296 {
297 bool bGroupFound = false;
298 for (auto const& item : rCmdCache)
299 {
300 if ( item.second.nGroupId == nCommandGroup )
301 {
302 bGroupFound = true;
303 aDispatchInfo.Command = item.first;
304 aDispatchInfo.GroupId = item.second.nGroupId;
305 aDispatchInfoVector.push_back( aDispatchInfo );
306 }
307 else if ( bGroupFound )
308 break;
309 }
310 }
311
312 return comphelper::containerToSequence( aDispatchInfoVector );
313}
314
315static bool canInsertRecords(const Reference< beans::XPropertySet>& _rxCursorSet)
316{
317 sal_Int32 nPriv = 0;
318 _rxCursorSet->getPropertyValue("Privileges") >>= nPriv;
319 return _rxCursorSet.is() && (nPriv & sdbcx::Privilege::INSERT) != 0;
320}
321
323{
324 if (!xController.is())
325 return false;
326
327 Reference< XResultSetUpdate> _xCursor(xController->getModel(), UNO_QUERY);
328
329 if (!_xCursor.is())
330 return false;
331
332 Reference< beans::XPropertySet> _xSet(_xCursor, UNO_QUERY);
333 if (!_xSet.is())
334 return false;
335
336 // need to save?
337 bool bIsNew = ::comphelper::getBOOL(_xSet->getPropertyValue("IsNew"));
338 bool bIsModified = ::comphelper::getBOOL(_xSet->getPropertyValue("IsModified"));
339 bool bResult = !bIsModified;
340 if (bIsModified)
341 {
342 try
343 {
344 if (bIsNew)
345 _xCursor->insertRow();
346 else
347 _xCursor->updateRow();
348 bResult = true;
349 }
350 catch(const Exception&)
351 {
352 TOOLS_WARN_EXCEPTION("extensions.biblio", "");
353 }
354 }
355 return bResult;
356}
357
358static vcl::Window* lcl_GetFocusChild( vcl::Window const * pParent )
359{
360 sal_uInt16 nChildren = pParent->GetChildCount();
361 for( sal_uInt16 nChild = 0; nChild < nChildren; ++nChild)
362 {
363 vcl::Window* pChild = pParent->GetChild( nChild );
364 if(pChild->HasFocus())
365 return pChild;
366 vcl::Window* pSubChild = lcl_GetFocusChild( pChild );
367 if(pSubChild)
368 return pSubChild;
369 }
370 return nullptr;
371}
372
373//class XDispatch
374void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequence< beans::PropertyValue >& aArgs)
375{
376 if ( m_bDisposing )
377 return;
378
379 ::SolarMutexGuard aGuard;
381 weld::WaitObject aWaitObject(pParent);
382
383 OUString aCommand( _rURL.Path);
384 if(aCommand == "Bib/Mapping")
385 {
386 m_xDatMan->CreateMappingDialog(pParent);
387 }
388 else if(aCommand == "Bib/source")
389 {
390 ChangeDataSource(aArgs);
391 }
392 else if(aCommand == "Bib/sdbsource")
393 {
394 OUString aURL = m_xDatMan->CreateDBChangeDialog(pParent);
395 if(!aURL.isEmpty())
396 {
397 try
398 {
399 uno::Sequence< beans::PropertyValue > aNewDataSource
400 {
401 comphelper::makePropertyValue( {}, OUString() ),
403 };
404 ChangeDataSource(aNewDataSource);
405 }
406 catch(const Exception&)
407 {
408 TOOLS_WARN_EXCEPTION("extensions.biblio",
409 "Exception caught while changing the data source");
410 }
411 }
412 }
413 else if(aCommand == "Bib/autoFilter")
414 {
415 sal_uInt16 nCount = m_aStatusListeners.size();
416 for ( sal_uInt16 n=0; n<nCount; n++ )
417 {
419 if ( pObj->aURL.Path == "Bib/removeFilter" )
420 {
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
428 }
429 }
430
431 const beans::PropertyValue* pPropertyValue = aArgs.getConstArray();
432 uno::Any aValue=pPropertyValue[0].Value;
433 OUString aQuery;
434 aValue >>= aQuery;
435
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);
442 }
443 else if(aCommand == "Bib/standardFilter")
444 {
445 try
446 {
447 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
448
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( ) )
454 {
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 );
459 }
460 }
461 catch( const uno::Exception& )
462 {
463 TOOLS_WARN_EXCEPTION( "extensions.biblio", "BibFrameController_Impl::dispatch" );
464 }
465
466 sal_uInt16 nCount = m_aStatusListeners.size();
467 for ( sal_uInt16 n=0; n<nCount; n++ )
468 {
470 if ( pObj->aURL.Path == "Bib/removeFilter" && m_xDatMan->getParser().is())
471 {
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 );
478 }
479 }
480 }
481 else if(aCommand == "Bib/removeFilter")
482 {
483 RemoveFilter();
484 }
485 else if( _rURL.Complete == ".uno:CloseDoc" || aCommand == "CloseDoc" )
486 {
488 DisposeHdl ) );
489
490 }
491 else if(aCommand == "Bib/InsertRecord")
492 {
493 Reference<form::runtime::XFormController > xFormCtrl = m_xDatMan->GetFormController();
494 if(SaveModified(xFormCtrl))
495 {
496 try
497 {
498 Reference< sdbc::XResultSet > xCursor( m_xDatMan->getForm(), UNO_QUERY );
499 xCursor->last();
500
501 Reference< XResultSetUpdate > xUpdateCursor( m_xDatMan->getForm(), UNO_QUERY );
502 xUpdateCursor->moveToInsertRow();
503 }
504 catch(const Exception&)
505 {
506 TOOLS_WARN_EXCEPTION("extensions.biblio",
507 "Exception in last() or moveToInsertRow()");
508 }
509 }
510 }
511 else if(aCommand == "Bib/DeleteRecord")
512 {
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"));
517 if(!bIsNew)
518 {
519 sal_uInt32 nCount = 0;
520 xSet->getPropertyValue("RowCount") >>= nCount;
521 // determine next position
522 bool bSuccess = false;
523 bool bLeft = false;
524 bool bRight = false;
525 try
526 {
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())
532 {
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);
538 }
539
540 // delete it
541 if (bSuccess)
542 xUpdateCursor->deleteRow();
543 }
544 catch(const Exception&)
545 {
546 bSuccess = false;
547 }
548 if (bSuccess)
549 {
550 if (bLeft || bRight)
551 xCursor->relative(bRight ? 1 : -1);
552 else
553 {
554 bool bCanInsert = canInsertRecords(xSet);
555 // can another entry be inserted?
556 try
557 {
558 if (bCanInsert)
559 xUpdateCursor->moveToInsertRow();
560 else
561 // move data entry to reset state
562 xCursor->first();
563 }
564 catch(const Exception&)
565 {
566 TOOLS_WARN_EXCEPTION("extensions.biblio",
567 "DeleteRecord: exception caught!");
568 }
569 }
570 }
571 }
572 }
573 else if(aCommand == "Cut")
574 {
576 if(pChild)
577 {
578 KeyEvent aEvent( 0, KeyFuncType::CUT );
579 pChild->KeyInput( aEvent );
580 }
581 }
582 else if(aCommand == "Copy")
583 {
585 if(pChild)
586 {
587 KeyEvent aEvent( 0, KeyFuncType::COPY );
588 pChild->KeyInput( aEvent );
589 }
590 }
591 else if(aCommand == "Paste")
592 {
594 if(pChild)
595 {
596 KeyEvent aEvent( 0, KeyFuncType::PASTE );
597 pChild->KeyInput( aEvent );
598 }
599 }
600}
601IMPL_LINK_NOARG( BibFrameController_Impl, DisposeHdl, void*, void )
602{
603 if (m_xFrame.is())
604 m_xFrame->dispose();
605};
606
608 const uno::Reference< frame::XStatusListener > & aListener,
609 const util::URL& aURL)
610{
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 ) );
614
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" )
621 {
622 aEvent.IsEnabled = false;
623 aEvent.State <<= false;
624 }
625 else if ( aURL.Path == "Bib/hierarchical" )
626 {
627 aEvent.IsEnabled = true;
628 aEvent.State <<= OUString();
629 }
630 else if(aURL.Path == "Bib/MenuFilter")
631 {
632 aEvent.IsEnabled = true;
633 aEvent.FeatureDescriptor=m_xDatMan->getQueryField();
634
635 aEvent.State <<= m_xDatMan->getQueryFields();
636
637 }
638 else if ( aURL.Path == "Bib/source")
639 {
640 aEvent.IsEnabled = true;
641 aEvent.FeatureDescriptor=m_xDatMan->getActiveDataTable();
642
643 aEvent.State <<= m_xDatMan->getDataSources();
644 }
645 else if( aURL.Path == "Bib/sdbsource" ||
646 aURL.Path == "Bib/Mapping" ||
647 aURL.Path == "Bib/autoFilter" ||
648 aURL.Path == "Bib/standardFilter" )
649 {
650 aEvent.IsEnabled = true;
651 }
652 else if(aURL.Path == "Bib/query")
653 {
654 aEvent.IsEnabled = true;
655 aEvent.State <<= pConfig->getQueryText();
656 }
657 else if (aURL.Path == "Bib/removeFilter" )
658 {
659 OUString aFilterStr=m_xDatMan->getFilter();
660 aEvent.IsEnabled = !aFilterStr.isEmpty();
661 }
662 else if(aURL.Path == "Cut")
663 {
666 {
667 Reference<css::awt::XTextComponent> xEdit(m_xLastQueriedFocusWin->GetComponentInterface(), css::uno::UNO_QUERY);
668 aEvent.IsEnabled = xEdit && xEdit->isEditable() && !xEdit->getSelectedText().isEmpty();
669 }
670 }
671 if(aURL.Path == "Copy")
672 {
675 {
676 Reference<css::awt::XTextComponent> xEdit(m_xLastQueriedFocusWin->GetComponentInterface(), css::uno::UNO_QUERY);
677 aEvent.IsEnabled = xEdit && !xEdit->getSelectedText().isEmpty();
678 }
679 }
680 else if(aURL.Path == "Paste" )
681 {
682 aEvent.IsEnabled = false;
685 {
686 Reference<css::awt::XTextComponent> xEdit(m_xLastQueriedFocusWin->GetComponentInterface(), css::uno::UNO_QUERY);
687 if (xEdit && !xEdit->isEditable())
688 {
689 uno::Reference< datatransfer::clipboard::XClipboard > xClip = m_xLastQueriedFocusWin->GetClipboard();
690 if(xClip.is())
691 {
692 uno::Reference< datatransfer::XTransferable > xDataObj;
693
694 try
695 {
696 SolarMutexReleaser aReleaser;
697 xDataObj = xClip->getContents();
698 }
699 catch( const uno::Exception& )
700 {
701 }
702
703 if ( xDataObj.is() )
704 {
705 datatransfer::DataFlavor aFlavor;
706 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aFlavor );
707 try
708 {
709 uno::Any aData = xDataObj->getTransferData( aFlavor );
710 OUString aText;
711 aData >>= aText;
712 aEvent.IsEnabled = !aText.isEmpty();
713 }
714 catch( const uno::Exception& )
715 {
716 }
717 }
718 }
719 }
720 }
721 }
722 else if(aURL.Path == "Bib/DeleteRecord")
723 {
724 Reference< beans::XPropertySet > xSet(m_xDatMan->getForm(), UNO_QUERY);
725 bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue("IsNew"));
726 if(!bIsNew)
727 {
728 sal_uInt32 nCount = 0;
729 xSet->getPropertyValue("RowCount") >>= nCount;
730 aEvent.IsEnabled = nCount > 0;
731 }
732 }
733 else if (aURL.Path == "Bib/InsertRecord")
734 {
735 Reference< beans::XPropertySet > xSet(m_xDatMan->getForm(), UNO_QUERY);
736 aEvent.IsEnabled = canInsertRecords(xSet);
737 }
738 aListener->statusChanged( aEvent );
739}
740
742 const uno::Reference< frame::XStatusListener > & aObject, const util::URL& aURL)
743{
744 // search listener array for given listener
745 // for checking equality always "cast" to XInterface
746 if ( m_bDisposing )
747 return;
748
749 sal_uInt16 nCount = m_aStatusListeners.size();
750 for ( sal_uInt16 n=0; n<nCount; n++ )
751 {
753 bool bFlag=pObj->xListener.is();
754 if (!bFlag || (pObj->xListener == aObject &&
755 ( aURL.Complete.isEmpty() || pObj->aURL.Path == aURL.Path )))
756 {
757 m_aStatusListeners.erase( m_aStatusListeners.begin() + n );
758 break;
759 }
760 }
761}
762
764{
765 OUString aQuery;
766 m_xDatMan->startQueryWith(aQuery);
767
768 sal_uInt16 nCount = m_aStatusListeners.size();
769
770 bool bRemoveFilter=false;
771 bool bQueryText=false;
772
773 for ( sal_uInt16 n=0; n<nCount; n++ )
774 {
776 if ( pObj->aURL.Path == "Bib/removeFilter" )
777 {
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;
785 }
786 else if(pObj->aURL.Path == "Bib/query")
787 {
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;
796 }
797
798 if(bRemoveFilter && bQueryText)
799 break;
800
801 }
802}
803
804void BibFrameController_Impl::ChangeDataSource(const uno::Sequence< beans::PropertyValue >& aArgs)
805{
806 const beans::PropertyValue* pPropertyValue = aArgs.getConstArray();
807 uno::Any aValue=pPropertyValue[0].Value;
808 OUString aDBTableName;
809 aValue >>= aDBTableName;
810
811
812 if(aArgs.getLength() > 1)
813 {
814 uno::Any aDB = pPropertyValue[1].Value;
815 OUString aURL;
816 aDB >>= aURL;
817 m_xDatMan->setActiveDataSource(aURL);
818 aDBTableName = m_xDatMan->getActiveDataTable();
819 }
820 else
821 {
823 xLoadable->unload();
824 m_xDatMan->setActiveDataTable(aDBTableName);
825 m_xDatMan->updateGridModel();
826 xLoadable->load();
827 }
828
829
830 sal_uInt16 nCount = m_aStatusListeners.size();
831
832 bool bMenuFilter=false;
833 bool bQueryText=false;
834 for ( sal_uInt16 n=0; n<nCount; n++ )
835 {
837 if (pObj->aURL.Path == "Bib/MenuFilter")
838 {
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();
845
846 uno::Sequence<OUString> aStringSeq=m_xDatMan->getQueryFields();
847 aEvent.State <<= aStringSeq;
848
849 pObj->xListener->statusChanged( aEvent );
850 bMenuFilter=true;
851 }
852 else if (pObj->aURL.Path == "Bib/query")
853 {
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 );
862 bQueryText=true;
863 }
864
865 if (bMenuFilter && bQueryText)
866 break;
867
868 }
869}
870
871/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
css::uno::Reference< css::lang::XComponent > m_xFrame
AnyEventRef aEvent
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
const OUString & getQueryText() const
Definition: bibconfig.hxx:133
void setQueryField(const OUString &rSet)
Definition: bibconfig.hxx:131
rtl::Reference< BibFrameCtrl_Impl > m_xImpl
Definition: framectr.hxx:65
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
Definition: framectr.cxx:607
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
Definition: framectr.cxx:239
void ChangeDataSource(const css::uno::Sequence< css::beans::PropertyValue > &aArgs)
Definition: framectr.cxx:804
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &aURL, const OUString &aTargetFrameName, sal_Int32 nSearchFlags) override
Definition: framectr.cxx:249
VclPtr< vcl::Window > m_xLastQueriedFocusWin
Definition: framectr.hxx:71
virtual void SAL_CALL attachFrame(const css::uno::Reference< css::frame::XFrame > &xFrame) override
Definition: framectr.cxx:184
virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getFrame() override
Definition: framectr.cxx:213
virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) override
Definition: framectr.cxx:195
virtual OUString SAL_CALL getImplementationName() override
Definition: framectr.cxx:167
virtual void SAL_CALL dispose() override
Definition: framectr.cxx:223
css::uno::Reference< css::awt::XWindow > m_xWindow
Definition: framectr.hxx:67
css::uno::Reference< css::frame::XFrame > m_xFrame
Definition: framectr.hxx:68
virtual css::uno::Reference< css::frame::XModel > SAL_CALL getModel() override
Definition: framectr.cxx:218
virtual ~BibFrameController_Impl() override
Definition: framectr.cxx:161
virtual css::uno::Sequence< ::sal_Int16 > SAL_CALL getSupportedCommandGroups() override
Definition: framectr.cxx:275
virtual css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation(::sal_Int16 CommandGroup) override
Definition: framectr.cxx:285
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &aDescripts) override
Definition: framectr.cxx:266
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: framectr.cxx:177
friend class BibFrameCtrl_Impl
Definition: framectr.hxx:64
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
Definition: framectr.cxx:172
rtl::Reference< BibDataManager > m_xDatMan
Definition: framectr.hxx:70
virtual css::uno::Any SAL_CALL getViewData() override
Definition: framectr.cxx:204
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
Definition: framectr.cxx:374
virtual sal_Bool SAL_CALL attachModel(const css::uno::Reference< css::frame::XModel > &xModel) override
Definition: framectr.cxx:190
BibFrameController_Impl(css::uno::Reference< css::awt::XWindow > xComponent, BibDataManager *pDatMan)
Definition: framectr.cxx:151
BibStatusDispatchArr m_aStatusListeners
Definition: framectr.hxx:66
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
Definition: framectr.cxx:244
virtual void SAL_CALL restoreViewData(const css::uno::Any &Value) override
Definition: framectr.cxx:209
static bool SaveModified(const css::uno::Reference< css::form::runtime::XFormController > &xController)
Definition: framectr.cxx:322
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
Definition: framectr.cxx:741
comphelper::OMultiTypeInterfaceContainerHelper2 aLC
Definition: framectr.cxx:127
virtual void SAL_CALL disposing(const lang::EventObject &Source) override
Definition: framectr.cxx:144
virtual void SAL_CALL frameAction(const FrameActionEvent &aEvent) override
Definition: framectr.cxx:140
BibFrameController_Impl * pController
Definition: framectr.cxx:129
static BibConfig * GetConfig()
Definition: bibmod.cxx:82
css::uno::Reference< css::frame::XStatusListener > xListener
Definition: framectr.hxx:47
css::util::URL aURL
Definition: framectr.hxx:46
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
void clear()
reference_type * get() const
sal_uInt16 GetChildCount() const
bool HasFocus() const
virtual void KeyInput(const KeyEvent &rKEvt)
vcl::Window * GetChild(sal_uInt16 nChild) const
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
URL aURL
IMPL_LINK_NOARG(BibFrameController_Impl, DisposeHdl, void *, void)
Definition: framectr.cxx:601
std::unordered_map< OUString, CacheDispatchInfo > CmdToInfoCache
Definition: framectr.cxx:101
static vcl::Window * lcl_GetFocusChild(vcl::Window const *pParent)
Definition: framectr.cxx:358
const DispatchInfo SupportedCommandsArray[]
Definition: framectr.cxx:80
static const CmdToInfoCache & GetCommandToInfoCache()
Definition: framectr.cxx:103
static bool canInsertRecords(const Reference< beans::XPropertySet > &_rxCursorSet)
Definition: framectr.cxx:315
sal_Int64 n
constexpr OUStringLiteral aData
@ Exception
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
Object Value
Reference< XController > xController
Reference< XFrame > xFrame
OUString aCommand
unsigned char sal_Bool