Kaydet (Commit) e78be1c1 authored tarafından Samuel Mehrbrodt's avatar Samuel Mehrbrodt

InfoBar: Introduce different types

Makes it easier to push various infobars without specifiying the
colors manually.

Change-Id: I0f861ba02409a42ba2ae767a1ca7634eaf0e7aef
Reviewed-on: https://gerrit.libreoffice.org/33777Reviewed-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
üst bbd34216
...@@ -69,15 +69,18 @@ class SfxInfoBarWindow : public vcl::Window ...@@ -69,15 +69,18 @@ class SfxInfoBarWindow : public vcl::Window
*/ */
void addButton(PushButton* pButton); void addButton(PushButton* pButton);
// Colors
static basegfx::BColor getSuccessColor();
static basegfx::BColor getDangerColor();
static basegfx::BColor getWarningColor();
private: private:
DECL_LINK( CloseHandler, Button*, void ); DECL_LINK( CloseHandler, Button*, void );
}; };
enum class InfoBarType {
Info,
Success,
Warning,
Danger
};
class SfxInfoBarContainerWindow : public vcl::Window class SfxInfoBarContainerWindow : public vcl::Window
{ {
private: private:
...@@ -89,6 +92,10 @@ class SfxInfoBarContainerWindow : public vcl::Window ...@@ -89,6 +92,10 @@ class SfxInfoBarContainerWindow : public vcl::Window
virtual ~SfxInfoBarContainerWindow( ) override; virtual ~SfxInfoBarContainerWindow( ) override;
virtual void dispose() override; virtual void dispose() override;
VclPtr<SfxInfoBarWindow> appendInfoBar(const OUString& sId,
const OUString& sMessage,
InfoBarType aInfoBarType,
WinBits nMessageStyle);
VclPtr<SfxInfoBarWindow> appendInfoBar(const OUString& sId, VclPtr<SfxInfoBarWindow> appendInfoBar(const OUString& sId,
const OUString& sMessage, const OUString& sMessage,
const basegfx::BColor* pBackgroundColor, const basegfx::BColor* pBackgroundColor,
......
...@@ -48,6 +48,7 @@ class Point; ...@@ -48,6 +48,7 @@ class Point;
class Size; class Size;
class SfxChildWindow; class SfxChildWindow;
class SfxInfoBarWindow; class SfxInfoBarWindow;
enum class InfoBarType;
namespace sfx2 namespace sfx2
{ {
...@@ -170,6 +171,10 @@ public: ...@@ -170,6 +171,10 @@ public:
The buttons will be added from Right to Left at the right of the info bar. The parent, size 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. and position of each button will be changed: only the width will remain unchanged.
*/ */
VclPtr<SfxInfoBarWindow> AppendInfoBar(const OUString& sId,
const OUString& sMessage,
InfoBarType aInfoBarType,
WinBits nMessageStyle = 0);
VclPtr<SfxInfoBarWindow> AppendInfoBar(const OUString& sId, VclPtr<SfxInfoBarWindow> AppendInfoBar(const OUString& sId,
const OUString& sMessage, const OUString& sMessage,
const basegfx::BColor* pBackgroundColor = nullptr, const basegfx::BColor* pBackgroundColor = nullptr,
......
...@@ -254,24 +254,6 @@ void SfxInfoBarWindow::Resize() ...@@ -254,24 +254,6 @@ void SfxInfoBarWindow::Resize()
m_pMessage->SetPosSizePixel(aMessagePosition, aMessageSize); m_pMessage->SetPosSizePixel(aMessagePosition, aMessageSize);
} }
basegfx::BColor SfxInfoBarWindow::getSuccessColor()
{
// Green
return basegfx::BColor(0.0, 0.5, 0.0);
}
basegfx::BColor SfxInfoBarWindow::getWarningColor()
{
// Orange
return basegfx::BColor(1.0, 0.5, 0.0);
}
basegfx::BColor SfxInfoBarWindow::getDangerColor()
{
// Red
return basegfx::BColor(0.5, 0.0, 0.0);
}
IMPL_LINK_NOARG(SfxInfoBarWindow, CloseHandler, Button*, void) IMPL_LINK_NOARG(SfxInfoBarWindow, CloseHandler, Button*, void)
{ {
static_cast<SfxInfoBarContainerWindow*>(GetParent())->removeInfoBar(this); static_cast<SfxInfoBarContainerWindow*>(GetParent())->removeInfoBar(this);
...@@ -297,6 +279,39 @@ void SfxInfoBarContainerWindow::dispose() ...@@ -297,6 +279,39 @@ void SfxInfoBarContainerWindow::dispose()
Window::dispose(); Window::dispose();
} }
VclPtr<SfxInfoBarWindow> SfxInfoBarContainerWindow::appendInfoBar(const OUString& sId,
const OUString& sMessage,
InfoBarType aInfoBarType,
WinBits nMessageStyle)
{
basegfx::BColor pBackgroundColor;
basegfx::BColor pForegroundColor;
basegfx::BColor pMessageColor;
switch (aInfoBarType)
{
case InfoBarType::Info: // yellow
pBackgroundColor = constLightColor;
// Use defaults for foreground & message color
break;
case InfoBarType::Success: // green
pBackgroundColor = basegfx::BColor(0.0, 0.5, 0.0);
pForegroundColor = basegfx::BColor(1.0, 1.0, 1.0);
pMessageColor = basegfx::BColor(1.0, 1.0, 01.0);
break;
case InfoBarType::Warning: // orange
pBackgroundColor = basegfx::BColor(1.0, 0.5, 0.0);
pForegroundColor = basegfx::BColor(1.0, 1.0, 1.0);
pMessageColor = basegfx::BColor(1.0, 1.0, 01.0);
break;
case InfoBarType::Danger: // red
pBackgroundColor = basegfx::BColor(0.5, 0.0, 0.0);
pForegroundColor = basegfx::BColor(1.0, 1.0, 1.0);
pMessageColor = basegfx::BColor(1.0, 1.0, 01.0);
break;
}
return appendInfoBar(sId, sMessage, &pBackgroundColor, &pForegroundColor, &pMessageColor, nMessageStyle);
}
VclPtr<SfxInfoBarWindow> SfxInfoBarContainerWindow::appendInfoBar(const OUString& sId, VclPtr<SfxInfoBarWindow> SfxInfoBarContainerWindow::appendInfoBar(const OUString& sId,
const OUString& sMessage, const OUString& sMessage,
const basegfx::BColor* pBackgroundColor, const basegfx::BColor* pBackgroundColor,
......
...@@ -1180,23 +1180,22 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) ...@@ -1180,23 +1180,22 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
rBind.Invalidate( SID_EDITDOC ); rBind.Invalidate( SID_EDITDOC );
SignatureState nSignatureState = GetObjectShell()->GetDocumentSignatureState(); SignatureState nSignatureState = GetObjectShell()->GetDocumentSignatureState();
basegfx::BColor aBackgroundColor; InfoBarType aInfoBarType(InfoBarType::Info);
basegfx::BColor aForegroundColor(1.0, 1.0, 1.0);
OUString sMessage(""); OUString sMessage("");
switch (nSignatureState) switch (nSignatureState)
{ {
case SignatureState::BROKEN: case SignatureState::BROKEN:
sMessage = SfxResId(STR_SIGNATURE_BROKEN); sMessage = SfxResId(STR_SIGNATURE_BROKEN);
aBackgroundColor = SfxInfoBarWindow::getDangerColor(); aInfoBarType = InfoBarType::Danger;
break; break;
case SignatureState::NOTVALIDATED: case SignatureState::NOTVALIDATED:
sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED); sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED);
aBackgroundColor = SfxInfoBarWindow::getWarningColor(); aInfoBarType = InfoBarType::Warning;
break; break;
case SignatureState::PARTIAL_OK: case SignatureState::PARTIAL_OK:
sMessage = SfxResId(STR_SIGNATURE_PARTIAL_OK); sMessage = SfxResId(STR_SIGNATURE_PARTIAL_OK);
aBackgroundColor = SfxInfoBarWindow::getWarningColor(); aInfoBarType = InfoBarType::Warning;
break; break;
default: default:
break; break;
...@@ -1204,7 +1203,7 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) ...@@ -1204,7 +1203,7 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
if (!sMessage.isEmpty()) if (!sMessage.isEmpty())
{ {
auto pInfoBar = AppendInfoBar("signature", sMessage, &aBackgroundColor, &aForegroundColor); auto pInfoBar = AppendInfoBar("signature", sMessage, aInfoBarType);
VclPtrInstance<PushButton> xBtn(&GetWindow()); VclPtrInstance<PushButton> xBtn(&GetWindow());
xBtn->SetText(SfxResId(STR_SIGNATURE_SHOW)); xBtn->SetText(SfxResId(STR_SIGNATURE_SHOW));
xBtn->SetSizePixel(xBtn->GetOptimalSize()); xBtn->SetSizePixel(xBtn->GetOptimalSize());
...@@ -3098,6 +3097,21 @@ void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame ) ...@@ -3098,6 +3097,21 @@ void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame )
SfxGetpApp()->SetViewFrame_Impl( pFrame ); SfxGetpApp()->SetViewFrame_Impl( pFrame );
} }
VclPtr<SfxInfoBarWindow> SfxViewFrame::AppendInfoBar(const OUString& sId,
const OUString& sMessage,
InfoBarType aInfoBarType,
WinBits nMessageStyle)
{
SfxChildWindow* pChild = GetChildWindow(SfxInfoBarContainerChild::GetChildWindowId());
if (!pChild)
return nullptr;
SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow());
auto pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage, aInfoBarType, nMessageStyle);
ShowChildWindow(SfxInfoBarContainerChild::GetChildWindowId());
return pInfoBar;
}
VclPtr<SfxInfoBarWindow> SfxViewFrame::AppendInfoBar( const OUString& sId, VclPtr<SfxInfoBarWindow> SfxViewFrame::AppendInfoBar( const OUString& sId,
const OUString& sMessage, const OUString& sMessage,
const basegfx::BColor* pBackgroundColor, const basegfx::BColor* pBackgroundColor,
...@@ -3105,21 +3119,14 @@ VclPtr<SfxInfoBarWindow> SfxViewFrame::AppendInfoBar( const OUString& sId, ...@@ -3105,21 +3119,14 @@ VclPtr<SfxInfoBarWindow> SfxViewFrame::AppendInfoBar( const OUString& sId,
const basegfx::BColor* pMessageColor, const basegfx::BColor* pMessageColor,
WinBits nMessageStyle ) WinBits nMessageStyle )
{ {
const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId(); SfxChildWindow* pChild = GetChildWindow(SfxInfoBarContainerChild::GetChildWindowId());
if (!pChild)
// Make sure the InfoBar container is visible return nullptr;
if (!HasChildWindow(nId))
ToggleChildWindow(nId);
SfxChildWindow* pChild = GetChildWindow(nId); SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow());
if (pChild) auto pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage, pBackgroundColor, pForegroundColor, pMessageColor, nMessageStyle);
{ ShowChildWindow(SfxInfoBarContainerChild::GetChildWindowId());
SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow()); return pInfoBar;
auto pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage, pBackgroundColor, pForegroundColor, pMessageColor, nMessageStyle);
ShowChildWindow(nId);
return pInfoBar;
}
return nullptr;
} }
void SfxViewFrame::RemoveInfoBar( const OUString& sId ) void SfxViewFrame::RemoveInfoBar( const OUString& sId )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment