[Libreoffice-commits] core.git: 3 commits - include/sfx2 sfx2/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Feb 17 15:53:02 UTC 2016


 include/sfx2/classificationhelper.hxx     |    9 +++-
 include/sfx2/infobar.hxx                  |   11 ++++-
 include/sfx2/viewfrm.hxx                  |    7 ++-
 sfx2/source/dialog/infobar.cxx            |   17 ++++++-
 sfx2/source/view/classificationhelper.cxx |   64 +++++++++++++++++++++++++++---
 sfx2/source/view/viewfrm.cxx              |   17 +++++--
 6 files changed, 106 insertions(+), 19 deletions(-)

New commits:
commit 6bf7f9808ddbaea5db5ca1ae1eedfe808b142503
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Feb 17 16:01:50 2016 +0100

    sfx2 classification: color the infobar according to the impact level
    
    Change-Id: I43c6537290aa5ce8a9dcc034d4ff6776668cde0c

diff --git a/include/sfx2/classificationhelper.hxx b/include/sfx2/classificationhelper.hxx
index 8662742..c62ffac 100644
--- a/include/sfx2/classificationhelper.hxx
+++ b/include/sfx2/classificationhelper.hxx
@@ -16,6 +16,10 @@
 #include <sfx2/dllapi.h>
 
 class SfxObjectShell;
+namespace basegfx
+{
+class BColor;
+}
 
 /// Shared code to handle Business Authorization Identification and Labeling Scheme (BAILS) properties.
 class SFX2_DLLPUBLIC SfxClassificationHelper
@@ -30,8 +34,9 @@ public:
     SfxClassificationHelper(SfxObjectShell& rObjectShell);
     ~SfxClassificationHelper();
     OUString GetBACName();
-    /// Impact level is a string, as the scale can be integer-based, but can be also low/high.
-    OUString GetImpactLevel();
+    /// If GetImpactLevelColor() will return something meaningful.
+    bool HasImpactLevel();
+    basegfx::BColor GetImpactLevelColor();
 };
 
 #endif
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 7ad5cb3..9270c46 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -78,13 +78,67 @@ OUString SfxClassificationHelper::GetBACName()
     return OUString();
 }
 
-OUString SfxClassificationHelper::GetImpactLevel()
+bool SfxClassificationHelper::HasImpactLevel()
 {
-    std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:Impact:Level:Confidentiality");
-    if (it != m_pImpl->m_aLabels.end())
-        return it->second;
+    std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:Impact:Scale");
+    if (it == m_pImpl->m_aLabels.end())
+        return false;
 
-    return OUString();
+    it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:Impact:Level:Confidentiality");
+    if (it == m_pImpl->m_aLabels.end())
+        return false;
+
+    return true;
+}
+
+basegfx::BColor SfxClassificationHelper::GetImpactLevelColor()
+{
+    basegfx::BColor aRet;
+
+    std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:Impact:Scale");
+    if (it == m_pImpl->m_aLabels.end())
+        return aRet;
+    OUString aScale = it->second;
+
+    it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:Impact:Level:Confidentiality");
+    if (it == m_pImpl->m_aLabels.end())
+        return aRet;
+    OUString aLevel = it->second;
+
+    // The spec defines two valid scale values: FIPS-199 and UK-Cabinet.
+    if (aScale == "UK-Cabinet")
+    {
+        static std::map<OUString, basegfx::BColor> aColors;
+        if (aColors.empty())
+        {
+            // Green -> brown -> orange -> red.
+            aColors["0"] = basegfx::BColor(0.0, 0.5, 0.0);
+            aColors["1"] = basegfx::BColor(0.5, 0.5, 0.0);
+            aColors["2"] = basegfx::BColor(1.0, 0.5, 0.0);
+            aColors["3"] = basegfx::BColor(0.5, 0.0, 0.0);
+        }
+        std::map<OUString, basegfx::BColor>::iterator itColor = aColors.find(aLevel);
+        if (itColor == aColors.end())
+            return aRet;
+        aRet = itColor->second;
+    }
+    else if (aScale == "FIPS-199")
+    {
+        static std::map<OUString, basegfx::BColor> aColors;
+        if (aColors.empty())
+        {
+            // Green -> orange -> red.
+            aColors["Low"] = basegfx::BColor(0.0, 0.5, 0.0);
+            aColors["Moderate"] = basegfx::BColor(1.0, 0.5, 0.0);
+            aColors["High"] = basegfx::BColor(0.5, 0.0, 0.0);
+        }
+        std::map<OUString, basegfx::BColor>::iterator itColor = aColors.find(aLevel);
+        if (itColor == aColors.end())
+            return aRet;
+        aRet = itColor->second;
+    }
+
+    return aRet;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index 46a718c..f7315c7 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -1349,12 +1349,14 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
                     // Document has BAILS properties, display an infobar accordingly.
                     SfxClassificationHelper aHelper(*xObjSh.get());
                     OUString aBACName = aHelper.GetBACName();
-                    OUString aImpactLevel = aHelper.GetImpactLevel();
-                    if (!aBACName.isEmpty() && !aImpactLevel.isEmpty())
+                    bool bImpactLevel = aHelper.HasImpactLevel();
+                    if (!aBACName.isEmpty() && bImpactLevel)
                     {
                         OUString aMessage = SfxResId(STR_CLASSIFIED_DOCUMENT);
                         aMessage = aMessage.replaceFirst("%1", aBACName);
-                        AppendInfoBar("classification", aMessage);
+                        basegfx::BColor aBackgroundColor = aHelper.GetImpactLevelColor();
+                        basegfx::BColor aForegroundColor(1.0, 1.0, 1.0);
+                        AppendInfoBar("classification", aMessage, &aBackgroundColor, &aForegroundColor, &aForegroundColor, WB_CENTER);
                     }
                 }
 
commit 946e12ac87237a1885fd3996a5549f56cc7de3a3
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Feb 17 15:22:28 2016 +0100

    sfx2 infobar: allow setting the message style
    
    Change-Id: I73151a78d1b396179776847d6fbb2da1dd8755e8

diff --git a/include/sfx2/infobar.hxx b/include/sfx2/infobar.hxx
index 8d0fcbc..1e5a31e 100644
--- a/include/sfx2/infobar.hxx
+++ b/include/sfx2/infobar.hxx
@@ -54,7 +54,8 @@ class SfxInfoBarWindow : public vcl::Window
                           const OUString& sMessage,
                           const basegfx::BColor* pBackgroundColor,
                           const basegfx::BColor* pForegroundColor,
-                          const basegfx::BColor* pMessageColor );
+                          const basegfx::BColor* pMessageColor,
+                          WinBits nMessageStyle );
         virtual ~SfxInfoBarWindow( );
         virtual void dispose() override;
 
@@ -87,7 +88,8 @@ class SfxInfoBarContainerWindow : public vcl::Window
                                         const OUString& sMessage,
                                         const basegfx::BColor* pBackgroundColor,
                                         const basegfx::BColor* pForegroundColor,
-                                        const basegfx::BColor* pMessageColor);
+                                        const basegfx::BColor* pMessageColor,
+                                        WinBits nMessageStyle);
         SfxInfoBarWindow* getInfoBar(const OUString& sId);
         void removeInfoBar(SfxInfoBarWindow* pInfoBar);
 
diff --git a/include/sfx2/viewfrm.hxx b/include/sfx2/viewfrm.hxx
index 0c11c0c..9094293 100644
--- a/include/sfx2/viewfrm.hxx
+++ b/include/sfx2/viewfrm.hxx
@@ -184,7 +184,8 @@ public:
                                     const OUString& sMessage,
                                     const basegfx::BColor* pBackgroundColor = nullptr,
                                     const basegfx::BColor* pForegroundColor = nullptr,
-                                    const basegfx::BColor* pMessageColor = nullptr);
+                                    const basegfx::BColor* pMessageColor = nullptr,
+                                    WinBits nMessageStyle = 0);
     void              RemoveInfoBar(const OUString& sId);
 
     SAL_DLLPRIVATE void SetDowning_Impl();
diff --git a/sfx2/source/dialog/infobar.cxx b/sfx2/source/dialog/infobar.cxx
index b108d3b..e48aaaa 100644
--- a/sfx2/source/dialog/infobar.cxx
+++ b/sfx2/source/dialog/infobar.cxx
@@ -132,10 +132,11 @@ SfxInfoBarWindow::SfxInfoBarWindow(vcl::Window* pParent, const OUString& sId,
        const OUString& sMessage,
        const basegfx::BColor* pBackgroundColor,
        const basegfx::BColor* pForegroundColor,
-       const basegfx::BColor* pMessageColor ) :
+       const basegfx::BColor* pMessageColor,
+       WinBits nMessageStyle ) :
     Window(pParent, 0),
     m_sId(sId),
-    m_pMessage(VclPtr<FixedText>::Create(this, 0)),
+    m_pMessage(VclPtr<FixedText>::Create(this, nMessageStyle)),
     m_pCloseBtn(VclPtr<SfxCloseButton>::Create(this)),
     m_aActionBtns()
 {
@@ -284,11 +285,12 @@ SfxInfoBarWindow* SfxInfoBarContainerWindow::appendInfoBar(const OUString& sId,
                                                            const OUString& sMessage,
                                                            const basegfx::BColor* pBackgroundColor,
                                                            const basegfx::BColor* pForegroundColor,
-                                                           const basegfx::BColor* pMessageColor)
+                                                           const basegfx::BColor* pMessageColor,
+                                                           WinBits nMessageStyle)
 {
     Size aSize = GetSizePixel();
 
-    VclPtrInstance<SfxInfoBarWindow> pInfoBar(this, sId, sMessage, pBackgroundColor, pForegroundColor, pMessageColor);
+    VclPtrInstance<SfxInfoBarWindow> pInfoBar(this, sId, sMessage, pBackgroundColor, pForegroundColor, pMessageColor, nMessageStyle);
     pInfoBar->SetPosPixel(Point(0, aSize.getHeight()));
     pInfoBar->Show();
     m_pInfoBars.push_back(pInfoBar);
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index 65b8b0c..46a718c 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -3195,7 +3195,8 @@ SfxInfoBarWindow* SfxViewFrame::AppendInfoBar( const OUString& sId,
                                                const OUString& sMessage,
                                                const basegfx::BColor* pBackgroundColor,
                                                const basegfx::BColor* pForegroundColor,
-                                               const basegfx::BColor* pMessageColor )
+                                               const basegfx::BColor* pMessageColor,
+                                               WinBits nMessageStyle )
 {
     const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId();
 
@@ -3207,7 +3208,7 @@ SfxInfoBarWindow* SfxViewFrame::AppendInfoBar( const OUString& sId,
     if (pChild)
     {
         SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow());
-        SfxInfoBarWindow* pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage, pBackgroundColor, pForegroundColor, pMessageColor);
+        SfxInfoBarWindow* pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage, pBackgroundColor, pForegroundColor, pMessageColor, nMessageStyle);
         ShowChildWindow(nId);
         return pInfoBar;
     }
commit 9da5675de3ca8a047bf45fd601522a6337efb78e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Feb 17 15:08:48 2016 +0100

    sfx2 infobar: allow setting the message color
    
    Change-Id: I32bb73dfd8ecb78bb2eb9907b0c008e84fd2233a

diff --git a/include/sfx2/infobar.hxx b/include/sfx2/infobar.hxx
index 483c0f8..8d0fcbc 100644
--- a/include/sfx2/infobar.hxx
+++ b/include/sfx2/infobar.hxx
@@ -53,7 +53,8 @@ class SfxInfoBarWindow : public vcl::Window
         SfxInfoBarWindow( vcl::Window* parent, const OUString& sId,
                           const OUString& sMessage,
                           const basegfx::BColor* pBackgroundColor,
-                          const basegfx::BColor* pForegroundColor );
+                          const basegfx::BColor* pForegroundColor,
+                          const basegfx::BColor* pMessageColor );
         virtual ~SfxInfoBarWindow( );
         virtual void dispose() override;
 
@@ -82,7 +83,11 @@ class SfxInfoBarContainerWindow : public vcl::Window
         virtual ~SfxInfoBarContainerWindow( );
         virtual void dispose() override;
 
-        SfxInfoBarWindow* appendInfoBar(const OUString& sId, const OUString& sMessage, const basegfx::BColor* pBackgroundColor, const basegfx::BColor* pForegroundColor);
+        SfxInfoBarWindow* appendInfoBar(const OUString& sId,
+                                        const OUString& sMessage,
+                                        const basegfx::BColor* pBackgroundColor,
+                                        const basegfx::BColor* pForegroundColor,
+                                        const basegfx::BColor* pMessageColor);
         SfxInfoBarWindow* getInfoBar(const OUString& sId);
         void removeInfoBar(SfxInfoBarWindow* pInfoBar);
 
diff --git a/include/sfx2/viewfrm.hxx b/include/sfx2/viewfrm.hxx
index e960aec..0c11c0c 100644
--- a/include/sfx2/viewfrm.hxx
+++ b/include/sfx2/viewfrm.hxx
@@ -180,7 +180,11 @@ public:
         The buttons will be added from Right to Left at the right of the info bar. The parent, size
         and position of each button will be changed: only the width will remain unchanged.
       */
-    SfxInfoBarWindow* AppendInfoBar(const OUString& sId, const OUString& sMessage, const basegfx::BColor* pBackgroundColor = nullptr, const basegfx::BColor* pForegroundColor = nullptr);
+    SfxInfoBarWindow* AppendInfoBar(const OUString& sId,
+                                    const OUString& sMessage,
+                                    const basegfx::BColor* pBackgroundColor = nullptr,
+                                    const basegfx::BColor* pForegroundColor = nullptr,
+                                    const basegfx::BColor* pMessageColor = nullptr);
     void              RemoveInfoBar(const OUString& sId);
 
     SAL_DLLPRIVATE void SetDowning_Impl();
diff --git a/sfx2/source/dialog/infobar.cxx b/sfx2/source/dialog/infobar.cxx
index f34f23c..b108d3b 100644
--- a/sfx2/source/dialog/infobar.cxx
+++ b/sfx2/source/dialog/infobar.cxx
@@ -131,7 +131,8 @@ void SfxCloseButton::setForegroundColor(const basegfx::BColor& rColor)
 SfxInfoBarWindow::SfxInfoBarWindow(vcl::Window* pParent, const OUString& sId,
        const OUString& sMessage,
        const basegfx::BColor* pBackgroundColor,
-       const basegfx::BColor* pForegroundColor ) :
+       const basegfx::BColor* pForegroundColor,
+       const basegfx::BColor* pMessageColor ) :
     Window(pParent, 0),
     m_sId(sId),
     m_pMessage(VclPtr<FixedText>::Create(this, 0)),
@@ -149,6 +150,8 @@ SfxInfoBarWindow::SfxInfoBarWindow(vcl::Window* pParent, const OUString& sId,
         m_aForegroundColor = *pForegroundColor;
         static_cast<SfxCloseButton*>(m_pCloseBtn.get())->setForegroundColor(m_aForegroundColor);
     }
+    if (pMessageColor)
+        m_pMessage->SetControlForeground(Color(*pMessageColor));
 
     sal_Int32 nScaleFactor = GetDPIScaleFactor();
     long nWidth = pParent->GetSizePixel().getWidth();
@@ -277,11 +280,15 @@ void SfxInfoBarContainerWindow::dispose()
     Window::dispose();
 }
 
-SfxInfoBarWindow* SfxInfoBarContainerWindow::appendInfoBar(const OUString& sId, const OUString& sMessage, const basegfx::BColor* pBackgroundColor, const basegfx::BColor* pForegroundColor)
+SfxInfoBarWindow* SfxInfoBarContainerWindow::appendInfoBar(const OUString& sId,
+                                                           const OUString& sMessage,
+                                                           const basegfx::BColor* pBackgroundColor,
+                                                           const basegfx::BColor* pForegroundColor,
+                                                           const basegfx::BColor* pMessageColor)
 {
     Size aSize = GetSizePixel();
 
-    VclPtrInstance<SfxInfoBarWindow> pInfoBar(this, sId, sMessage, pBackgroundColor, pForegroundColor);
+    VclPtrInstance<SfxInfoBarWindow> pInfoBar(this, sId, sMessage, pBackgroundColor, pForegroundColor, pMessageColor);
     pInfoBar->SetPosPixel(Point(0, aSize.getHeight()));
     pInfoBar->Show();
     m_pInfoBars.push_back(pInfoBar);
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index 068bbcd..65b8b0c 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -3191,7 +3191,11 @@ void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame )
     SfxGetpApp()->SetViewFrame_Impl( pFrame );
 }
 
-SfxInfoBarWindow* SfxViewFrame::AppendInfoBar( const OUString& sId, const OUString& sMessage, const basegfx::BColor* pBackgroundColor, const basegfx::BColor* pForegroundColor )
+SfxInfoBarWindow* SfxViewFrame::AppendInfoBar( const OUString& sId,
+                                               const OUString& sMessage,
+                                               const basegfx::BColor* pBackgroundColor,
+                                               const basegfx::BColor* pForegroundColor,
+                                               const basegfx::BColor* pMessageColor )
 {
     const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId();
 
@@ -3203,7 +3207,7 @@ SfxInfoBarWindow* SfxViewFrame::AppendInfoBar( const OUString& sId, const OUStri
     if (pChild)
     {
         SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow());
-        SfxInfoBarWindow* pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage, pBackgroundColor, pForegroundColor);
+        SfxInfoBarWindow* pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage, pBackgroundColor, pForegroundColor, pMessageColor);
         ShowChildWindow(nId);
         return pInfoBar;
     }


More information about the Libreoffice-commits mailing list