summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-12-09 17:12:47 +0000
committerCaolán McNamara <caolanm@redhat.com>2022-12-12 16:00:14 +0000
commit72136773c452513e49358c8b27866cb4169f86cf (patch)
tree75a07753ecf6becea65d3d93c21f09d2a126df3d /sfx2
parentafa81be4b2bf36193b338979b6707e5eb48892c8 (diff)
tdf#152266 add an infobar with indicators for macro-like content in doc
Show "macros" and "events" for now if we know that are present so they can be investigated by the user. There are other things which could potentially be added in the future. Change-Id: I981ee7a8e22791cd15405894f30fee659ba0b7ba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143965 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/sdi/sfx.sdi2
-rw-r--r--sfx2/source/appl/app.cxx10
-rw-r--r--sfx2/source/appl/appserv.cxx17
-rw-r--r--sfx2/source/view/viewfrm.cxx81
4 files changed, 98 insertions, 12 deletions
diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi
index c56b80a65fc8..400746d8d77a 100644
--- a/sfx2/sdi/sfx.sdi
+++ b/sfx2/sdi/sfx.sdi
@@ -2341,7 +2341,7 @@ SfxScriptOrganizerItem ScriptOrganizer SID_SCRIPTORGANIZER
SfxScriptOrganizerItem MacroOrganizer SID_MACROORGANIZER
-(SfxUInt16Item TabId SID_MACROORGANIZER)
+(SfxUInt16Item TabId SID_MACROORGANIZER, SfxBoolItem CurrentDocument FN_PARAM_2)
[
AutoUpdate = FALSE,
FastCall = TRUE,
diff --git a/sfx2/source/appl/app.cxx b/sfx2/source/appl/app.cxx
index 760ab1ca9cb1..4b5adbdf8a2b 100644
--- a/sfx2/source/appl/app.cxx
+++ b/sfx2/source/appl/app.cxx
@@ -383,12 +383,12 @@ void SfxApplication::Invalidate( sal_uInt16 nId )
#ifndef DISABLE_DYNLOADING
typedef long (*basicide_handle_basic_error)(void const *);
-typedef void (*basicide_macro_organizer)(void *, sal_Int16);
+typedef void (*basicide_macro_organizer)(void *, void *, sal_Int16);
#else
extern "C" long basicide_handle_basic_error(void const*);
-extern "C" void basicide_macro_organizer(void*, sal_Int16);
+extern "C" void basicide_macro_organizer(void*, void*, sal_Int16);
#endif
@@ -500,7 +500,7 @@ SfxApplication::ChooseScript(weld::Window *pParent)
return aScriptURL;
}
-void SfxApplication::MacroOrganizer(weld::Window* pParent, sal_Int16 nTabId)
+void SfxApplication::MacroOrganizer(weld::Window* pParent, const uno::Reference<frame::XFrame>& xDocFrame, sal_Int16 nTabId)
{
#if !HAVE_FEATURE_SCRIPTING
(void) pParent;
@@ -511,11 +511,11 @@ void SfxApplication::MacroOrganizer(weld::Window* pParent, sal_Int16 nTabId)
basicide_macro_organizer pSymbol = reinterpret_cast<basicide_macro_organizer>(sfx2::getBasctlFunction("basicide_macro_organizer"));
// call basicide_macro_organizer in basctl
- pSymbol(pParent, nTabId);
+ pSymbol(pParent, xDocFrame.get(), nTabId);
#else
- basicide_macro_organizer(pParent, nTabId);
+ basicide_macro_organizer(pParent, xDocFrame.get(), nTabId);
#endif
diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx
index d20d8c54200d..31d12cd43520 100644
--- a/sfx2/source/appl/appserv.cxx
+++ b/sfx2/source/appl/appserv.cxx
@@ -1544,14 +1544,21 @@ void SfxApplication::OfaExec_Impl( SfxRequest& rReq )
{
SAL_INFO("sfx.appl", "handling SID_MACROORGANIZER");
const SfxItemSet* pArgs = rReq.GetArgs();
- const SfxUInt16Item* pItem;
sal_Int16 nTabId = 0;
- if(pArgs && (pItem = pArgs->GetItemIfSet(SID_MACROORGANIZER, false) ))
+ Reference <XFrame> xFrame;
+ if (pArgs)
{
- nTabId = pItem->GetValue();
+ if (const SfxUInt16Item* pItem = pArgs->GetItemIfSet(SID_MACROORGANIZER, false))
+ nTabId = pItem->GetValue();
+ if (const SfxBoolItem* pItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_2))
+ {
+ // if set then default to showing the macros of the document associated
+ // with this frame
+ if (pItem->GetValue())
+ xFrame = GetRequestFrame(rReq);
+ }
}
-
- SfxApplication::MacroOrganizer(rReq.GetFrameWeld(), nTabId);
+ SfxApplication::MacroOrganizer(rReq.GetFrameWeld(), xFrame, nTabId);
rReq.Done();
}
break;
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index 813c92d99fc1..68ea4a3f8933 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -1283,6 +1283,63 @@ void SfxViewFrame::AppendReadOnlyInfobar()
}
}
+void SfxViewFrame::AppendContainsMacrosInfobar()
+{
+ auto pInfoBar = AppendInfoBar("macro", SfxResId(RID_SECURITY_WARNING_TITLE), SfxResId(STR_CONTAINS_MACROS), InfobarType::WARNING);
+ if (!pInfoBar)
+ return;
+
+ SfxObjectShell_Impl* pObjImpl = m_xObjSh->Get_Impl();
+
+ // what's the difference between pObjImpl->documentStorageHasMacros() and pObjImpl->aMacroMode.hasMacroLibrary() ?
+ if (pObjImpl->aMacroMode.hasMacroLibrary())
+ {
+ weld::Button& rMacroButton = pInfoBar->addButton();
+ rMacroButton.set_label(SfxResId(STR_MACROS));
+ rMacroButton.connect_clicked(LINK(this, SfxViewFrame, MacroButtonHandler));
+ }
+
+ Reference<XModel> xModel = m_xObjSh->GetModel();
+ uno::Reference<document::XEventsSupplier> xSupplier(xModel, uno::UNO_QUERY);
+ bool bHasBoundConfigEvents(false);
+ if (xSupplier.is())
+ {
+ css::uno::Reference<css::container::XNameReplace> xDocumentEvents = xSupplier->getEvents();
+
+ Sequence<OUString> eventNames = xDocumentEvents->getElementNames();
+ sal_Int32 nEventCount = eventNames.getLength();
+ for (sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent)
+ {
+ OUString url;
+ try
+ {
+ Any aAny(xDocumentEvents->getByName(eventNames[nEvent]));
+ Sequence<beans::PropertyValue> props;
+ if (aAny >>= props)
+ {
+ ::comphelper::NamedValueCollection aProps(props);
+ url = aProps.getOrDefault("Script", url);
+ }
+ }
+ catch (const Exception&)
+ {
+ }
+ if (!url.isEmpty())
+ {
+ bHasBoundConfigEvents = true;
+ break;
+ }
+ }
+ }
+
+ if (bHasBoundConfigEvents)
+ {
+ weld::Button& rEventButton = pInfoBar->addButton();
+ rEventButton.set_label(SfxResId(STR_EVENTS));
+ rEventButton.connect_clicked(LINK(this, SfxViewFrame, EventButtonHandler));
+ }
+}
+
namespace
{
css::uno::Reference<css::frame::XLayoutManager> getLayoutManager(const SfxFrame& rFrame)
@@ -1472,17 +1529,22 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
}
}
+ const bool bEmbedded = m_xObjSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED;
+
// read-only infobar if necessary
const SfxViewShell *pVSh;
const SfxShell *pFSh;
if ( m_xObjSh->IsReadOnly() &&
! m_xObjSh->IsSecurityOptOpenReadOnly() &&
- ( m_xObjSh->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ||
+ ( !bEmbedded ||
(( pVSh = m_xObjSh->GetViewShell()) && (pFSh = pVSh->GetFormShell()) && pFSh->IsDesignMode())))
{
AppendReadOnlyInfobar();
}
+ if (!bEmbedded && m_xObjSh->Get_Impl()->getCurrentMacroExecMode() == css::document::MacroExecMode::NEVER_EXECUTE)
+ AppendContainsMacrosInfobar();
+
if (vcl::CommandInfoProvider::GetModuleIdentifier(GetFrame().GetFrameInterface()) == "com.sun.star.text.TextDocument")
sfx2::SfxNotebookBar::ReloadNotebookBar(u"modules/swriter/ui/");
@@ -1698,6 +1760,23 @@ IMPL_LINK_NOARG(SfxViewFrame, HyphenationMissingHandler, weld::Button&, void)
RemoveInfoBar(u"hyphenationmissing");
}
+IMPL_LINK_NOARG(SfxViewFrame, MacroButtonHandler, weld::Button&, void)
+{
+ // start with tab 0 displayed
+ SfxUInt16Item aTabItem(SID_MACROORGANIZER, 0);
+ SfxBoolItem aCurrentDocItem(FN_PARAM_2, true);
+ SfxUnoFrameItem aDocFrame(SID_FILLFRAME, GetFrame().GetFrameInterface());
+ GetDispatcher()->ExecuteList(SID_MACROORGANIZER, SfxCallMode::ASYNCHRON,
+ { &aTabItem, &aCurrentDocItem }, { &aDocFrame });
+}
+
+IMPL_LINK_NOARG(SfxViewFrame, EventButtonHandler, weld::Button&, void)
+{
+ SfxUnoFrameItem aDocFrame(SID_FILLFRAME, GetFrame().GetFrameInterface());
+ GetDispatcher()->ExecuteList(SID_CONFIGEVENT, SfxCallMode::ASYNCHRON,
+ {}, { &aDocFrame });
+}
+
IMPL_LINK_NOARG(SfxViewFrame, RefreshMasterPasswordHdl, weld::Button&, void)
{
bool bChanged = false;