Kaydet (Commit) 43459bac authored tarafından Katarina Behrens's avatar Katarina Behrens

tdf#117039: update infobar instead of removing and re-adding it

Apparently AppendInfoBar ends up calling back into SID_SIGNATURE
status function at some point, creating an endless recursion. I'm
too lazy to debug why so I'm cowardly avoiding it

Change-Id: Ib1e4b7f12fea197887b099e9a9f03b4e58884ec1
Reviewed-on: https://gerrit.libreoffice.org/53519Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarKatarina Behrens <Katarina.Behrens@cib.de>
üst a0329f7c
...@@ -50,11 +50,14 @@ class SFX2_DLLPUBLIC SfxInfoBarWindow : public vcl::Window ...@@ -50,11 +50,14 @@ class SFX2_DLLPUBLIC SfxInfoBarWindow : public vcl::Window
{ {
private: private:
OUString m_sId; OUString m_sId;
InfoBarType m_eType;
VclPtr<FixedImage> m_pImage; VclPtr<FixedImage> m_pImage;
VclPtr<FixedText> m_pMessage; VclPtr<FixedText> m_pMessage;
VclPtr<Button> m_pCloseBtn; VclPtr<Button> m_pCloseBtn;
std::vector< VclPtr<PushButton> > m_aActionBtns; std::vector< VclPtr<PushButton> > m_aActionBtns;
void SetForeAndBackgroundColors( InfoBarType eType );
public: public:
SfxInfoBarWindow( vcl::Window* parent, const OUString& sId, SfxInfoBarWindow( vcl::Window* parent, const OUString& sId,
const OUString& sMessage, const OUString& sMessage,
...@@ -66,6 +69,7 @@ class SFX2_DLLPUBLIC SfxInfoBarWindow : public vcl::Window ...@@ -66,6 +69,7 @@ class SFX2_DLLPUBLIC SfxInfoBarWindow : public vcl::Window
const OUString& getId() const { return m_sId; } const OUString& getId() const { return m_sId; }
virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override; virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override;
virtual void Resize( ) override; virtual void Resize( ) override;
void Update( const OUString& sNewMessage, InfoBarType eType );
basegfx::BColor m_aBackgroundColor; basegfx::BColor m_aBackgroundColor;
basegfx::BColor m_aForegroundColor; basegfx::BColor m_aForegroundColor;
......
...@@ -173,6 +173,8 @@ public: ...@@ -173,6 +173,8 @@ public:
const OUString& sMessage, const OUString& sMessage,
InfoBarType aInfoBarType); InfoBarType aInfoBarType);
void RemoveInfoBar(const OUString& sId); void RemoveInfoBar(const OUString& sId);
void UpdateInfoBar(const OUString& sId,
const OUString& sMessage, InfoBarType eType);
bool HasInfoBarWithID(const OUString& sId); bool HasInfoBarWithID(const OUString& sId);
SAL_DLLPRIVATE void GetDocNumber_Impl(); SAL_DLLPRIVATE void GetDocNumber_Impl();
......
...@@ -172,19 +172,13 @@ SfxInfoBarWindow::SfxInfoBarWindow(vcl::Window* pParent, const OUString& sId, ...@@ -172,19 +172,13 @@ SfxInfoBarWindow::SfxInfoBarWindow(vcl::Window* pParent, const OUString& sId,
WinBits nMessageStyle = WB_LEFT|WB_VCENTER) : WinBits nMessageStyle = WB_LEFT|WB_VCENTER) :
Window(pParent, 0), Window(pParent, 0),
m_sId(sId), m_sId(sId),
m_eType(ibType),
m_pImage(VclPtr<FixedImage>::Create(this, nMessageStyle)), m_pImage(VclPtr<FixedImage>::Create(this, nMessageStyle)),
m_pMessage(VclPtr<FixedText>::Create(this, nMessageStyle)), m_pMessage(VclPtr<FixedText>::Create(this, nMessageStyle)),
m_pCloseBtn(VclPtr<SfxCloseButton>::Create(this)), m_pCloseBtn(VclPtr<SfxCloseButton>::Create(this)),
m_aActionBtns() m_aActionBtns()
{ {
basegfx::BColor aBackgroundColor; SetForeAndBackgroundColors(m_eType);
basegfx::BColor aForegroundColor;
basegfx::BColor aMessageColor;
GetInfoBarColors(ibType,aBackgroundColor,aForegroundColor,aMessageColor);
static_cast<SfxCloseButton*>(m_pCloseBtn.get())->setBackgroundColor(aBackgroundColor);
static_cast<SfxCloseButton*>(m_pCloseBtn.get())->setForegroundColor(aForegroundColor);
m_pMessage->SetControlForeground(Color(aMessageColor));
float fScaleFactor = GetDPIScaleFactor(); float fScaleFactor = GetDPIScaleFactor();
long nWidth = pParent->GetSizePixel().getWidth(); long nWidth = pParent->GetSizePixel().getWidth();
SetPosSizePixel(Point(0, 0), Size(nWidth, INFO_BAR_BASE_HEIGHT * fScaleFactor)); SetPosSizePixel(Point(0, 0), Size(nWidth, INFO_BAR_BASE_HEIGHT * fScaleFactor));
...@@ -216,6 +210,16 @@ SfxInfoBarWindow::~SfxInfoBarWindow() ...@@ -216,6 +210,16 @@ SfxInfoBarWindow::~SfxInfoBarWindow()
disposeOnce(); disposeOnce();
} }
void SfxInfoBarWindow::SetForeAndBackgroundColors(InfoBarType eType)
{
basegfx::BColor aMessageColor;
GetInfoBarColors(eType,m_aBackgroundColor,m_aForegroundColor,aMessageColor);
static_cast<SfxCloseButton*>(m_pCloseBtn.get())->setBackgroundColor(m_aBackgroundColor);
static_cast<SfxCloseButton*>(m_pCloseBtn.get())->setForegroundColor(m_aForegroundColor);
m_pMessage->SetControlForeground(Color(aMessageColor));
}
void SfxInfoBarWindow::dispose() void SfxInfoBarWindow::dispose()
{ {
for ( auto it = m_aActionBtns.begin( ); it != m_aActionBtns.end( ); ++it ) for ( auto it = m_aActionBtns.begin( ); it != m_aActionBtns.end( ); ++it )
...@@ -295,6 +299,20 @@ void SfxInfoBarWindow::Resize() ...@@ -295,6 +299,20 @@ void SfxInfoBarWindow::Resize()
} }
void SfxInfoBarWindow::Update( const OUString &sNewMessage, InfoBarType eType )
{
if (m_eType != eType)
{
m_eType = eType;
SetForeAndBackgroundColors(m_eType);
m_pImage->SetImage(Image(BitmapEx(GetInfoBarIconName(eType))));
}
m_pMessage->SetText( sNewMessage );
Resize();
Invalidate();
}
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);
......
...@@ -1058,21 +1058,28 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet) ...@@ -1058,21 +1058,28 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet)
break; break;
} }
if ( pFrame->HasInfoBarWithID("signature") ) // new info bar
pFrame->RemoveInfoBar("signature"); if ( !pFrame->HasInfoBarWithID("signature") )
{
if ( eState != SignatureState::NOSIGNATURES ) if ( !sMessage.isEmpty() )
{
auto pInfoBar = pFrame->AppendInfoBar("signature", sMessage, aInfoBarType);
if (pInfoBar == nullptr)
return;
VclPtrInstance<PushButton> xBtn(&(pFrame->GetWindow()));
xBtn->SetText(SfxResId(STR_SIGNATURE_SHOW));
xBtn->SetSizePixel(xBtn->GetOptimalSize());
xBtn->SetClickHdl(LINK(this, SfxObjectShell, SignDocumentHandler));
pInfoBar->addButton(xBtn);
}
}
else // info bar exists already
{ {
auto pInfoBar = pFrame->AppendInfoBar("signature", sMessage, aInfoBarType); if ( eState == SignatureState::NOSIGNATURES )
if (pInfoBar == nullptr) pFrame->RemoveInfoBar("signature");
return; else
VclPtrInstance<PushButton> xBtn(&(pFrame->GetWindow())); pFrame->UpdateInfoBar("signature", sMessage, aInfoBarType);
xBtn->SetText(SfxResId(STR_SIGNATURE_SHOW));
xBtn->SetSizePixel(xBtn->GetOptimalSize());
xBtn->SetClickHdl(LINK(this, SfxObjectShell, SignDocumentHandler));
pInfoBar->addButton(xBtn);
} }
} }
rSet.Put( SfxUInt16Item( SID_SIGNATURE, static_cast<sal_uInt16>(GetDocumentSignatureState()) ) ); rSet.Put( SfxUInt16Item( SID_SIGNATURE, static_cast<sal_uInt16>(GetDocumentSignatureState()) ) );
......
...@@ -3095,6 +3095,27 @@ VclPtr<SfxInfoBarWindow> SfxViewFrame::AppendInfoBar(const OUString& sId, ...@@ -3095,6 +3095,27 @@ VclPtr<SfxInfoBarWindow> SfxViewFrame::AppendInfoBar(const OUString& sId,
return pInfoBar; return pInfoBar;
} }
void SfxViewFrame::UpdateInfoBar( const OUString& sId,
const OUString& sMessage,
InfoBarType eType )
{
const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId();
// Make sure the InfoBar container is visible
if (!HasChildWindow(nId))
ToggleChildWindow(nId);
SfxChildWindow* pChild = GetChildWindow(nId);
if (pChild)
{
SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow());
auto pInfoBar = pInfoBarContainer->getInfoBar(sId);
if (pInfoBar)
pInfoBar->Update(sMessage, eType);
}
}
void SfxViewFrame::RemoveInfoBar( const OUString& sId ) void SfxViewFrame::RemoveInfoBar( const OUString& sId )
{ {
const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId(); const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId();
......
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