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>
50#include <osl/mutex.hxx>
52#include <unordered_map>
67 bool bActiveConnection;
70struct CacheDispatchInfo
73 bool bActiveConnection;
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 },
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;
136 virtual void SAL_CALL
frameAction(
const FrameActionEvent& aEvent)
override;
137 virtual void SAL_CALL
disposing(
const lang::EventObject& Source )
override;
153 :m_xWindow(
std::move( xComponent ))
154 ,m_xDatMan( pDataManager )
163 m_xImpl->pController =
nullptr;
169 return "com.sun.star.comp.extensions.Bibliography";
181 return {
"com.sun.star.frame.Bibliography" };
220 return uno::Reference< XModel > ();
226 lang::EventObject aObject;
232 aObject.Source =
static_cast<XController*
>(
this);
233 m_xImpl->aLC.disposeAndClear(aObject);
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 > ();
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 );
277 uno::Sequence< ::sal_Int16 > aDispatchInfo{ frame::CommandGroup::EDIT,
278 frame::CommandGroup::DOCUMENT,
279 frame::CommandGroup::DATA,
280 frame::CommandGroup::VIEW };
282 return aDispatchInfo;
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 )
318 _rxCursorSet->getPropertyValue(
"Privileges") >>= nPriv;
319 return _rxCursorSet.is() && (nPriv & sdbcx::Privilege::INSERT) != 0;
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();
361 for( sal_uInt16 nChild = 0; nChild < nChildren; ++nChild)
392 else if(
aCommand ==
"Bib/sdbsource")
399 uno::Sequence< beans::PropertyValue > aNewDataSource
409 "Exception caught while changing the data source");
413 else if(
aCommand ==
"Bib/autoFilter")
419 if ( pObj->
aURL.Path ==
"Bib/removeFilter" )
425 aEvent.Source =
static_cast<XDispatch *
>(
this);
431 const beans::PropertyValue* pPropertyValue = aArgs.getConstArray();
436 aValue=pPropertyValue[1].
Value;
437 OUString aQueryField;
438 aValue >>= aQueryField;
443 else if(
aCommand ==
"Bib/standardFilter")
447 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
450 uno::Reference< ui::dialogs::XExecutableDialog > xDialog = sdb::FilterDialog::createWithQuery(xContext,
m_xDatMan->getParser(),
453 if ( xDialog->execute( ) )
457 OUString sNewFilter =
m_xDatMan->getParser()->getFilter();
461 catch(
const uno::Exception& )
470 if ( pObj->
aURL.Path ==
"Bib/removeFilter" &&
m_xDatMan->getParser().is())
476 aEvent.Source =
static_cast<XDispatch *
>(
this);
481 else if(
aCommand ==
"Bib/removeFilter")
485 else if( _rURL.Complete ==
".uno:CloseDoc" ||
aCommand ==
"CloseDoc" )
491 else if(
aCommand ==
"Bib/InsertRecord")
502 xUpdateCursor->moveToInsertRow();
507 "Exception in last() or moveToInsertRow()");
511 else if(
aCommand ==
"Bib/DeleteRecord")
516 bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(
"IsNew"));
520 xSet->getPropertyValue(
"RowCount") >>=
nCount;
522 bool bSuccess =
false;
527 bLeft = xCursor->isLast() &&
nCount > 1;
528 bRight= !xCursor->isLast();
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();
551 xCursor->relative(bRight ? 1 : -1);
559 xUpdateCursor->moveToInsertRow();
567 "DeleteRecord: exception caught!");
608 const uno::Reference< frame::XStatusListener > & aListener,
609 const util::URL& aURL)
619 aEvent.Source =
static_cast<XDispatch *
>(
this);
620 if (
aURL.Path ==
"StatusBarVisible" )
625 else if (
aURL.Path ==
"Bib/hierarchical" )
628 aEvent.State <<= OUString();
630 else if(
aURL.Path ==
"Bib/MenuFilter")
638 else if (
aURL.Path ==
"Bib/source")
645 else if(
aURL.Path ==
"Bib/sdbsource" ||
646 aURL.Path ==
"Bib/Mapping" ||
647 aURL.Path ==
"Bib/autoFilter" ||
648 aURL.Path ==
"Bib/standardFilter" )
652 else if(
aURL.Path ==
"Bib/query")
657 else if (
aURL.Path ==
"Bib/removeFilter" )
659 OUString aFilterStr=
m_xDatMan->getFilter();
660 aEvent.IsEnabled = !aFilterStr.isEmpty();
662 else if(
aURL.Path ==
"Cut")
668 aEvent.IsEnabled = xEdit && xEdit->isEditable() && !xEdit->getSelectedText().isEmpty();
671 if(
aURL.Path ==
"Copy")
677 aEvent.IsEnabled = xEdit && !xEdit->getSelectedText().isEmpty();
680 else if(
aURL.Path ==
"Paste" )
687 if (xEdit && !xEdit->isEditable())
692 uno::Reference< datatransfer::XTransferable > xDataObj;
697 xDataObj = xClip->getContents();
699 catch(
const uno::Exception& )
705 datatransfer::DataFlavor aFlavor;
712 aEvent.IsEnabled = !aText.isEmpty();
714 catch(
const uno::Exception& )
722 else if(
aURL.Path ==
"Bib/DeleteRecord")
725 bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(
"IsNew"));
729 xSet->getPropertyValue(
"RowCount") >>=
nCount;
733 else if (
aURL.Path ==
"Bib/InsertRecord")
738 aListener->statusChanged(
aEvent );
742 const uno::Reference< frame::XStatusListener > & aObject,
const util::URL& aURL)
754 if (!bFlag || (pObj->
xListener == aObject &&
755 (
aURL.Complete.isEmpty() || pObj->
aURL.Path ==
aURL.Path )))
770 bool bRemoveFilter=
false;
771 bool bQueryText=
false;
776 if ( pObj->
aURL.Path ==
"Bib/removeFilter" )
782 aEvent.Source =
static_cast<XDispatch *
>(
this);
786 else if(pObj->
aURL.Path ==
"Bib/query")
792 aEvent.Source =
static_cast<XDispatch *
>(
this);
798 if(bRemoveFilter && bQueryText)
806 const beans::PropertyValue* pPropertyValue = aArgs.getConstArray();
808 OUString aDBTableName;
809 aValue >>= aDBTableName;
812 if(aArgs.getLength() > 1)
818 aDBTableName =
m_xDatMan->getActiveDataTable();
824 m_xDatMan->setActiveDataTable(aDBTableName);
832 bool bMenuFilter=
false;
833 bool bQueryText=
false;
837 if (pObj->
aURL.Path ==
"Bib/MenuFilter")
843 aEvent.Source =
static_cast<XDispatch *
>(
this);
846 uno::Sequence<OUString> aStringSeq=
m_xDatMan->getQueryFields();
847 aEvent.State <<= aStringSeq;
852 else if (pObj->
aURL.Path ==
"Bib/query")
858 aEvent.Source =
static_cast<XDispatch *
>(
this);
865 if (bMenuFilter && bQueryText)
constexpr OUStringLiteral sServiceName
css::uno::Reference< css::lang::XComponent > m_xFrame
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
void setQueryField(const OUString &rSet)
rtl::Reference< BibFrameCtrl_Impl > m_xImpl
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
void ChangeDataSource(const css::uno::Sequence< css::beans::PropertyValue > &aArgs)
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &aURL, const OUString &aTargetFrameName, sal_Int32 nSearchFlags) override
VclPtr< vcl::Window > m_xLastQueriedFocusWin
virtual void SAL_CALL attachFrame(const css::uno::Reference< css::frame::XFrame > &xFrame) override
virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getFrame() override
virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL dispose() override
css::uno::Reference< css::awt::XWindow > m_xWindow
css::uno::Reference< css::frame::XFrame > m_xFrame
virtual css::uno::Reference< css::frame::XModel > SAL_CALL getModel() override
virtual ~BibFrameController_Impl() override
virtual css::uno::Sequence< ::sal_Int16 > SAL_CALL getSupportedCommandGroups() override
virtual css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation(::sal_Int16 CommandGroup) override
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &aDescripts) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
friend class BibFrameCtrl_Impl
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
rtl::Reference< BibDataManager > m_xDatMan
virtual css::uno::Any SAL_CALL getViewData() override
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
virtual sal_Bool SAL_CALL attachModel(const css::uno::Reference< css::frame::XModel > &xModel) override
BibFrameController_Impl(css::uno::Reference< css::awt::XWindow > xComponent, BibDataManager *pDatMan)
BibStatusDispatchArr m_aStatusListeners
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual void SAL_CALL restoreViewData(const css::uno::Any &Value) override
static bool SaveModified(const css::uno::Reference< css::form::runtime::XFormController > &xController)
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
comphelper::OMultiTypeInterfaceContainerHelper2 aLC
virtual void SAL_CALL disposing(const lang::EventObject &Source) override
virtual void SAL_CALL frameAction(const FrameActionEvent &aEvent) override
BibFrameController_Impl * pController
static BibConfig * GetConfig()
css::uno::Reference< css::frame::XStatusListener > xListener
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
reference_type * get() const
sal_uInt16 GetChildCount() const
virtual void KeyInput(const KeyEvent &rKEvt)
vcl::Window * GetChild(sal_uInt16 nChild) const
#define TOOLS_WARN_EXCEPTION(area, stream)
IMPL_LINK_NOARG(BibFrameController_Impl, DisposeHdl, void *, void)
std::unordered_map< OUString, CacheDispatchInfo > CmdToInfoCache
static vcl::Window * lcl_GetFocusChild(vcl::Window const *pParent)
const DispatchInfo SupportedCommandsArray[]
static const CmdToInfoCache & GetCommandToInfoCache()
static bool canInsertRecords(const Reference< beans::XPropertySet > &_rxCursorSet)
#define LINK(Instance, Class, Member)
constexpr OUStringLiteral aData
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)
Reference< XController > xController
Reference< XFrame > xFrame