From 57352dce995c98d1282484d02c38ed2132b091f5 Mon Sep 17 00:00:00 2001 From: Deepanshu Sharma <129deepanshusharma@gmail.com> Date: Sat, 22 Mar 2025 15:50:02 +0530 Subject: [PATCH] tdf#56676 disable form properties when they are not available for change Change-Id: I0f1b8f1a2b4ed93fc59849e0b2b66a1a9af7af8b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183219 Tested-by: Jenkins Reviewed-by: Sahil Gautam --- .../source/propctrlr/formcomponenthandler.cxx | 71 ++++++++++++++++++- .../source/propctrlr/formcomponenthandler.hxx | 2 +- extensions/source/propctrlr/formstrings.hxx | 1 + 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/extensions/source/propctrlr/formcomponenthandler.cxx b/extensions/source/propctrlr/formcomponenthandler.cxx index 4b44f69757c3..195a08e0b81d 100644 --- a/extensions/source/propctrlr/formcomponenthandler.cxx +++ b/extensions/source/propctrlr/formcomponenthandler.cxx @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -1513,6 +1514,9 @@ namespace pcr if ( !_bFirstTimeInit && m_bHaveCommand ) lcl_rebuildAndResetCommand( _rxInspectorUI, this ); aDependentProperties.push_back( PROPERTY_ID_COMMAND ); + aDependentProperties.push_back(PROPERTY_ID_ALLOWADDITIONS); + aDependentProperties.push_back(PROPERTY_ID_ALLOWEDITS); + aDependentProperties.push_back(PROPERTY_ID_ALLOWDELETIONS); break; // case PROPERTY_ID_COMMANDTYPE // ----- DataSourceName ----- @@ -1536,6 +1540,9 @@ namespace pcr case PROPERTY_ID_COMMAND: aDependentProperties.push_back( PROPERTY_ID_FILTER ); aDependentProperties.push_back( PROPERTY_ID_SORT ); + aDependentProperties.push_back(PROPERTY_ID_ALLOWADDITIONS); + aDependentProperties.push_back(PROPERTY_ID_ALLOWEDITS); + aDependentProperties.push_back(PROPERTY_ID_ALLOWDELETIONS); if ( m_bComponentIsSubForm ) aDependentProperties.push_back( PROPERTY_ID_DETAILFIELDS ); break; @@ -1785,7 +1792,7 @@ namespace pcr } } - void FormComponentPropertyHandler::impl_updateDependentProperty_nothrow( PropertyId _nPropId, const Reference< XObjectInspectorUI >& _rxInspectorUI ) const + void FormComponentPropertyHandler::impl_updateDependentProperty_nothrow( PropertyId _nPropId, const Reference< XObjectInspectorUI >& _rxInspectorUI ) { try { @@ -1819,6 +1826,68 @@ namespace pcr } break; // case PROPERTY_ID_STRINGITEMLIST + case PROPERTY_ID_ALLOWADDITIONS: + { + bool bEnable = false; + sal_Int32 nPrivileges = 0; + if (m_xComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_PRIVILEGES)) + { + m_xComponent->getPropertyValue(PROPERTY_PRIVILEGES) >>= nPrivileges; + bEnable = (nPrivileges & css::sdbcx::Privilege::INSERT) != 0; + } + _rxInspectorUI->enablePropertyUI( + impl_getPropertyNameFromId_nothrow(PROPERTY_ID_ALLOWADDITIONS), + bEnable + ); + // Set value to false if disabled + if (!bEnable) + { + setPropertyValue(impl_getPropertyNameFromId_nothrow(PROPERTY_ID_ALLOWADDITIONS), Any(false)); + } + } + break; + + case PROPERTY_ID_ALLOWEDITS: + { + bool bEnable = false; + sal_Int32 nPrivileges = 0; + if (m_xComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_PRIVILEGES)) + { + m_xComponent->getPropertyValue(PROPERTY_PRIVILEGES) >>= nPrivileges; + bEnable = (nPrivileges & css::sdbcx::Privilege::UPDATE) != 0; + } + _rxInspectorUI->enablePropertyUI( + impl_getPropertyNameFromId_nothrow(PROPERTY_ID_ALLOWEDITS), + bEnable + ); + // Set value to false if disabled + if (!bEnable) + { + setPropertyValue(impl_getPropertyNameFromId_nothrow(PROPERTY_ID_ALLOWEDITS), Any(false)); + } + } + break; + + case PROPERTY_ID_ALLOWDELETIONS: + { + bool bEnable = false; + sal_Int32 nPrivileges = 0; + if (m_xComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_PRIVILEGES)) + { + m_xComponent->getPropertyValue(PROPERTY_PRIVILEGES) >>= nPrivileges; + bEnable = (nPrivileges & css::sdbcx::Privilege::DELETE) != 0; + } + _rxInspectorUI->enablePropertyUI( + impl_getPropertyNameFromId_nothrow(PROPERTY_ID_ALLOWDELETIONS), + bEnable + ); + // Set value to false if disabled + if (!bEnable) + { + setPropertyValue(impl_getPropertyNameFromId_nothrow(PROPERTY_ID_ALLOWDELETIONS), Any(false)); + } + } + break; // ----- TypedItemList ----- case PROPERTY_ID_TYPEDITEMLIST: { diff --git a/extensions/source/propctrlr/formcomponenthandler.hxx b/extensions/source/propctrlr/formcomponenthandler.hxx index bc7367abbeae..81bb4b934f86 100644 --- a/extensions/source/propctrlr/formcomponenthandler.hxx +++ b/extensions/source/propctrlr/formcomponenthandler.hxx @@ -393,7 +393,7 @@ namespace pcr @param _rxInspectorUI provides access to the property browser UI. Must not be . */ - void impl_updateDependentProperty_nothrow( PropertyId _nPropId, const css::uno::Reference< css::inspection::XObjectInspectorUI >& _rxInspectorUI ) const; + void impl_updateDependentProperty_nothrow( PropertyId _nPropId, const css::uno::Reference< css::inspection::XObjectInspectorUI >& _rxInspectorUI ); /** determines whether the given form has a valid data source signature. diff --git a/extensions/source/propctrlr/formstrings.hxx b/extensions/source/propctrlr/formstrings.hxx index 495e178f842e..d37cc98c226c 100644 --- a/extensions/source/propctrlr/formstrings.hxx +++ b/extensions/source/propctrlr/formstrings.hxx @@ -114,6 +114,7 @@ inline constexpr OUString PROPERTY_SHOW_SCROLLBARS = u"ShowScrollbars"_ustr; inline constexpr OUString PROPERTY_TABSTOP = u"Tabstop"_ustr; inline constexpr OUString PROPERTY_AUTOCOMPLETE = u"Autocomplete"_ustr; inline constexpr OUString PROPERTY_PRINTABLE = u"Printable"_ustr; +inline constexpr OUString PROPERTY_PRIVILEGES = u"Privileges"_ustr; inline constexpr OUString PROPERTY_ECHO_CHAR = u"EchoChar"_ustr; inline constexpr OUString PROPERTY_ROWHEIGHT = u"RowHeight"_ustr; inline constexpr OUString PROPERTY_HELPTEXT = u"HelpText"_ustr;