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
*/
void addButton(PushButton* pButton);
// Colors
static basegfx::BColor getSuccessColor();
static basegfx::BColor getDangerColor();
static basegfx::BColor getWarningColor();
private:
DECL_LINK( CloseHandler, Button*, void );
};
enum class InfoBarType {
Info,
Success,
Warning,
Danger
};
class SfxInfoBarContainerWindow : public vcl::Window
{
private:
......@@ -89,6 +92,10 @@ class SfxInfoBarContainerWindow : public vcl::Window
virtual ~SfxInfoBarContainerWindow( ) override;
virtual void dispose() override;
VclPtr<SfxInfoBarWindow> appendInfoBar(const OUString& sId,
const OUString& sMessage,
InfoBarType aInfoBarType,
WinBits nMessageStyle);
VclPtr<SfxInfoBarWindow> appendInfoBar(const OUString& sId,
const OUString& sMessage,
const basegfx::BColor* pBackgroundColor,
......
......@@ -48,6 +48,7 @@ class Point;
class Size;
class SfxChildWindow;
class SfxInfoBarWindow;
enum class InfoBarType;
namespace sfx2
{
......@@ -170,6 +171,10 @@ 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.
*/
VclPtr<SfxInfoBarWindow> AppendInfoBar(const OUString& sId,
const OUString& sMessage,
InfoBarType aInfoBarType,
WinBits nMessageStyle = 0);
VclPtr<SfxInfoBarWindow> AppendInfoBar(const OUString& sId,
const OUString& sMessage,
const basegfx::BColor* pBackgroundColor = nullptr,
......
......@@ -254,24 +254,6 @@ void SfxInfoBarWindow::Resize()
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)
{
static_cast<SfxInfoBarContainerWindow*>(GetParent())->removeInfoBar(this);
......@@ -297,6 +279,39 @@ void SfxInfoBarContainerWindow::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,
const OUString& sMessage,
const basegfx::BColor* pBackgroundColor,
......
......@@ -1180,23 +1180,22 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
rBind.Invalidate( SID_EDITDOC );
SignatureState nSignatureState = GetObjectShell()->GetDocumentSignatureState();
basegfx::BColor aBackgroundColor;
basegfx::BColor aForegroundColor(1.0, 1.0, 1.0);
InfoBarType aInfoBarType(InfoBarType::Info);
OUString sMessage("");
switch (nSignatureState)
{
case SignatureState::BROKEN:
sMessage = SfxResId(STR_SIGNATURE_BROKEN);
aBackgroundColor = SfxInfoBarWindow::getDangerColor();
aInfoBarType = InfoBarType::Danger;
break;
case SignatureState::NOTVALIDATED:
sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED);
aBackgroundColor = SfxInfoBarWindow::getWarningColor();
aInfoBarType = InfoBarType::Warning;
break;
case SignatureState::PARTIAL_OK:
sMessage = SfxResId(STR_SIGNATURE_PARTIAL_OK);
aBackgroundColor = SfxInfoBarWindow::getWarningColor();
aInfoBarType = InfoBarType::Warning;
break;
default:
break;
......@@ -1204,7 +1203,7 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
if (!sMessage.isEmpty())
{
auto pInfoBar = AppendInfoBar("signature", sMessage, &aBackgroundColor, &aForegroundColor);
auto pInfoBar = AppendInfoBar("signature", sMessage, aInfoBarType);
VclPtrInstance<PushButton> xBtn(&GetWindow());
xBtn->SetText(SfxResId(STR_SIGNATURE_SHOW));
xBtn->SetSizePixel(xBtn->GetOptimalSize());
......@@ -3098,6 +3097,21 @@ void SfxViewFrame::SetViewFrame( SfxViewFrame* 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,
const OUString& sMessage,
const basegfx::BColor* pBackgroundColor,
......@@ -3105,21 +3119,14 @@ VclPtr<SfxInfoBarWindow> SfxViewFrame::AppendInfoBar( const OUString& sId,
const basegfx::BColor* pMessageColor,
WinBits nMessageStyle )
{
const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId();
// Make sure the InfoBar container is visible
if (!HasChildWindow(nId))
ToggleChildWindow(nId);
SfxChildWindow* pChild = GetChildWindow(SfxInfoBarContainerChild::GetChildWindowId());
if (!pChild)
return nullptr;
SfxChildWindow* pChild = GetChildWindow(nId);
if (pChild)
{
SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow());
auto pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage, pBackgroundColor, pForegroundColor, pMessageColor, nMessageStyle);
ShowChildWindow(nId);
return pInfoBar;
}
return nullptr;
SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow());
auto pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage, pBackgroundColor, pForegroundColor, pMessageColor, nMessageStyle);
ShowChildWindow(SfxInfoBarContainerChild::GetChildWindowId());
return pInfoBar;
}
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