diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2019-11-18 09:08:03 +0100 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2019-11-22 14:29:04 +0100 |
commit | fa070a798536d4017baada1e8f036b0e18dad9c7 (patch) | |
tree | 3e34754fb883a8d46cc8e42e8c0f494f5a26f977 /sfx2/source/view | |
parent | 54239c99b7f9d82ec14492aff29e450abdafc61d (diff) |
tdf#97926 Add UNO API for Infobar
This allows creating, updating and removing infobars from macros/extensions.
It also extends the infobar with a primary and a secondary text, so there can
be a bold summary at the beginning at the infobar with a longer text following
in normal letters.
Macro sample:
------------------------------------------------------------
Sub AddInfobar
dim buttons(1) as new com.sun.star.beans.StringPair
buttons(0).first = "Close doc"
buttons(0).second = ".uno:CloseDoc"
buttons(1).first = "Paste into doc"
buttons(1).second = ".uno:Paste"
ThisComponent.getCurrentController().appendInfobar("my", "Hello world", "Things happened. What now?", com.sun.star.frame.InfobarType.INFO, buttons, true)
End Sub
Sub UpdateInfobar
ThisComponent.getCurrentController().updateInfobar("my", "WARNING","Do not read this message.", com.sun.star.frame.InfobarType.WARNING)
End Sub
Sub RemoveInfobar
ThisComponent.getCurrentController().removeInfobar("my")
End Sub
------------------------------------------------------------
Change-Id: I5d0a223525845d23ffab17acdaa431e0eb783fec
Reviewed-on: https://gerrit.libreoffice.org/29816
Reviewed-by: Serge Krot (CIB) <Serge.Krot@cib.de>
Tested-by: Serge Krot (CIB) <Serge.Krot@cib.de>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
(cherry picked from commit 9e3ba7c3036c4d21e01d6f75ed29a1e8c4208141)
Reviewed-on: https://gerrit.libreoffice.org/83405
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sfx2/source/view')
-rw-r--r-- | sfx2/source/view/classificationhelper.cxx | 22 | ||||
-rw-r--r-- | sfx2/source/view/sfxbasecontroller.cxx | 64 | ||||
-rw-r--r-- | sfx2/source/view/viewfrm.cxx | 23 |
3 files changed, 86 insertions, 23 deletions
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx index 57c6a50df38f..66d27a07375c 100644 --- a/sfx2/source/view/classificationhelper.cxx +++ b/sfx2/source/view/classificationhelper.cxx @@ -693,11 +693,11 @@ bool SfxClassificationHelper::HasDocumentFooter() return it != rCategory.m_aLabels.end() && !it->second.isEmpty(); } -InfoBarType SfxClassificationHelper::GetImpactLevelType() +InfobarType SfxClassificationHelper::GetImpactLevelType() { - InfoBarType aRet; + InfobarType aRet; - aRet = InfoBarType::Warning; + aRet = InfobarType::WARNING; auto itCategory = m_pImpl->m_aCategory.find(SfxClassificationPolicyType::IntellectualProperty); if (itCategory == m_pImpl->m_aCategory.end()) @@ -718,22 +718,22 @@ InfoBarType SfxClassificationHelper::GetImpactLevelType() if (aScale == "UK-Cabinet") { if (aLevel == "0") - aRet = InfoBarType::Success; + aRet = InfobarType::SUCCESS; else if (aLevel == "1") - aRet = InfoBarType::Warning; + aRet = InfobarType::WARNING; else if (aLevel == "2") - aRet = InfoBarType::Warning; + aRet = InfobarType::WARNING; else if (aLevel == "3") - aRet = InfoBarType::Danger; + aRet = InfobarType::DANGER; } else if (aScale == "FIPS-199") { if (aLevel == "Low") - aRet = InfoBarType::Success; + aRet = InfobarType::SUCCESS; else if (aLevel == "Moderate") - aRet = InfoBarType::Warning; + aRet = InfobarType::WARNING; else if (aLevel == "High") - aRet = InfoBarType::Danger; + aRet = InfobarType::DANGER; } return aRet; } @@ -890,7 +890,7 @@ void SfxClassificationHelper::UpdateInfobar(SfxViewFrame& rViewFrame) aMessage = aMessage.replaceFirst("%1", aBACName); rViewFrame.RemoveInfoBar("classification"); - rViewFrame.AppendInfoBar("classification", aMessage, GetImpactLevelType()); + rViewFrame.AppendInfoBar("classification", "", aMessage, GetImpactLevelType()); } } diff --git a/sfx2/source/view/sfxbasecontroller.cxx b/sfx2/source/view/sfxbasecontroller.cxx index 7812b560de2a..f4cf6768a8b3 100644 --- a/sfx2/source/view/sfxbasecontroller.cxx +++ b/sfx2/source/view/sfxbasecontroller.cxx @@ -99,6 +99,7 @@ using ::com::sun::star::frame::XDispatchProvider; using ::com::sun::star::document::XViewDataSupplier; using ::com::sun::star::container::XIndexAccess; using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::beans::StringPair; using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::UNO_QUERY; using ::com::sun::star::uno::Exception; @@ -1395,7 +1396,8 @@ void SfxBaseController::ShowInfoBars( ) // Get the Frame and show the InfoBar if not checked out SfxViewFrame* pViewFrame = m_pData->m_pViewShell->GetFrame(); - auto pInfoBar = pViewFrame->AppendInfoBar( "checkout", SfxResId( STR_NONCHECKEDOUT_DOCUMENT ), InfoBarType::Warning); + auto pInfoBar = pViewFrame->AppendInfoBar("checkout", "", SfxResId(STR_NONCHECKEDOUT_DOCUMENT), + InfobarType::WARNING); if (pInfoBar) { VclPtrInstance<PushButton> xBtn(&pViewFrame->GetWindow()); @@ -1469,4 +1471,64 @@ void SfxBaseController::initialize( const css::uno::Sequence< css::uno::Any >& / { } +void SAL_CALL SfxBaseController::appendInfobar(const OUString& sId, const OUString& sPrimaryMessage, + const OUString& sSecondaryMessage, + sal_Int32 aInfobarType, + const Sequence<StringPair>& actionButtons, + sal_Bool bShowCloseButton) +{ + if (aInfobarType < static_cast<sal_Int32>(InfobarType::INFO) + || aInfobarType > static_cast<sal_Int32>(InfobarType::DANGER)) + throw lang::IllegalArgumentException("Undefined InfobarType: " + + OUString::number(aInfobarType), + static_cast<::cppu::OWeakObject*>(this), 0); + SfxViewFrame* pViewFrame = m_pData->m_pViewShell->GetFrame(); + if (pViewFrame->HasInfoBarWithID(sId)) + throw lang::IllegalArgumentException("Infobar with ID '" + sId + "' already existing.", + static_cast<::cppu::OWeakObject*>(this), 0); + + auto pInfoBar + = pViewFrame->AppendInfoBar(sId, sPrimaryMessage, sSecondaryMessage, + static_cast<InfobarType>(aInfobarType), bShowCloseButton); + if (!pInfoBar) + throw uno::RuntimeException("Could not create Infobar"); + + auto vActionButtons = comphelper::sequenceToContainer<std::vector<StringPair>>(actionButtons); + for (auto& actionButton : vActionButtons) + { + if (actionButton.First.isEmpty() || actionButton.Second.isEmpty()) + continue; + VclPtrInstance<PushButton> xBtn(&pViewFrame->GetWindow()); + xBtn->SetText(actionButton.First); + xBtn->SetSizePixel(xBtn->GetOptimalSize()); + xBtn->SetCommandHandler(actionButton.Second); + pInfoBar->addButton(xBtn); + } +} + +void SAL_CALL SfxBaseController::updateInfobar(const OUString& sId, const OUString& sPrimaryMessage, + const OUString& sSecondaryMessage, + sal_Int32 aInfobarType) +{ + if (aInfobarType < static_cast<sal_Int32>(InfobarType::INFO) + || aInfobarType > static_cast<sal_Int32>(InfobarType::DANGER)) + throw lang::IllegalArgumentException("Undefined InfobarType: " + + OUString::number(aInfobarType), + static_cast<::cppu::OWeakObject*>(this), 0); + SfxViewFrame* pViewFrame = m_pData->m_pViewShell->GetFrame(); + if (!pViewFrame->HasInfoBarWithID(sId)) + throw css::container::NoSuchElementException("Infobar with ID '" + sId + "' not found."); + + pViewFrame->UpdateInfoBar(sId, sPrimaryMessage, sSecondaryMessage, + static_cast<InfobarType>(aInfobarType)); +} + +void SAL_CALL SfxBaseController::removeInfobar(const OUString& sId) +{ + SfxViewFrame* pViewFrame = m_pData->m_pViewShell->GetFrame(); + if (!pViewFrame->HasInfoBarWithID(sId)) + throw css::container::NoSuchElementException("Infobar with ID '" + sId + "' not found."); + pViewFrame->RemoveInfoBar(sId); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 6dccb522c14b..80d66831f0bb 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1300,7 +1300,7 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) sal_Int32 iLast = sLastVersion.getToken(0,'.').toInt32() * 10 + sLastVersion.getToken(1,'.').toInt32(); if ((iCurrent > iLast) && !Application::IsHeadlessModeEnabled() && !bIsUITest) { - VclPtr<SfxInfoBarWindow> pInfoBar = AppendInfoBar("whatsnew", SfxResId(STR_WHATSNEW_TEXT), InfoBarType::Info); + VclPtr<SfxInfoBarWindow> pInfoBar = AppendInfoBar("whatsnew", "", SfxResId(STR_WHATSNEW_TEXT), InfobarType::INFO); if (pInfoBar) { VclPtrInstance<PushButton> xWhatsNewButton(&GetWindow()); @@ -1342,7 +1342,7 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) { bUpdateLastTimeGetInvolvedShown = true; - VclPtr<SfxInfoBarWindow> pInfoBar = AppendInfoBar("getinvolved", SfxResId(STR_GET_INVOLVED_TEXT), InfoBarType::Info); + VclPtr<SfxInfoBarWindow> pInfoBar = AppendInfoBar("getinvolved", "", SfxResId(STR_GET_INVOLVED_TEXT), InfobarType::INFO); VclPtrInstance<PushButton> xGetInvolvedButton(&GetWindow()); xGetInvolvedButton->SetText(SfxResId(STR_GET_INVOLVED_BUTTON)); @@ -1369,7 +1369,7 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) { bUpdateLastTimeDonateShown = true; - VclPtr<SfxInfoBarWindow> pInfoBar = AppendInfoBar("donate", SfxResId(STR_DONATE_TEXT), InfoBarType::Info); + VclPtr<SfxInfoBarWindow> pInfoBar = AppendInfoBar("donate", "", SfxResId(STR_DONATE_TEXT), InfobarType::INFO); VclPtrInstance<PushButton> xDonateButton(&GetWindow()); xDonateButton->SetText(SfxResId(STR_DONATE_BUTTON)); @@ -1396,7 +1396,7 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) { bool bSignPDF = IsSignPDF(m_xObjSh); - auto pInfoBar = AppendInfoBar("readonly", SfxResId(bSignPDF ? STR_READONLY_PDF : STR_READONLY_DOCUMENT), InfoBarType::Info); + auto pInfoBar = AppendInfoBar("readonly", "", SfxResId(bSignPDF ? STR_READONLY_PDF : STR_READONLY_DOCUMENT), InfobarType::INFO); if (pInfoBar) { if (bSignPDF) @@ -3283,22 +3283,23 @@ void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame ) } VclPtr<SfxInfoBarWindow> SfxViewFrame::AppendInfoBar(const OUString& sId, - const OUString& sMessage, - InfoBarType aInfoBarType) + const OUString& sPrimaryMessage, + const OUString& sSecondaryMessage, + InfobarType aInfobarType, bool bShowCloseButton) { SfxChildWindow* pChild = GetChildWindow(SfxInfoBarContainerChild::GetChildWindowId()); if (!pChild) return nullptr; SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow()); - auto pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage, aInfoBarType, WB_LEFT | WB_VCENTER); + auto pInfoBar = pInfoBarContainer->appendInfoBar(sId, sPrimaryMessage, sSecondaryMessage, + aInfobarType, WB_LEFT | WB_VCENTER, bShowCloseButton); ShowChildWindow(SfxInfoBarContainerChild::GetChildWindowId()); return pInfoBar; } -void SfxViewFrame::UpdateInfoBar( const OUString& sId, - const OUString& sMessage, - InfoBarType eType ) +void SfxViewFrame::UpdateInfoBar(const OUString& sId, const OUString& sPrimaryMessage, + const OUString& sSecondaryMessage, InfobarType eType) { const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId(); @@ -3313,7 +3314,7 @@ void SfxViewFrame::UpdateInfoBar( const OUString& sId, auto pInfoBar = pInfoBarContainer->getInfoBar(sId); if (pInfoBar) - pInfoBar->Update(sMessage, eType); + pInfoBar->Update(sPrimaryMessage, sSecondaryMessage, eType); } } |