LibreOffice Module svx (master)  1
xmlsecctrl.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 
21 #include <vcl/commandevent.hxx>
22 #include <vcl/image.hxx>
23 #include <vcl/event.hxx>
24 #include <vcl/status.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/weldutils.hxx>
27 #include <sfx2/signaturestate.hxx>
28 #include <sfx2/module.hxx>
29 
30 #include <svl/intitem.hxx>
31 
32 #include <svx/strings.hrc>
33 #include <svx/dialmgr.hxx>
34 #include <svx/xmlsecctrl.hxx>
35 #include <tools/urlobj.hxx>
36 #include <bitmaps.hlst>
37 #include <sal/log.hxx>
38 
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 
42 
44 {
49 };
50 
51 
52 XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& _rStb )
53  :SfxStatusBarControl( _nSlotId, _nId, _rStb )
54  ,mpImpl( new XmlSecStatusBarControl_Impl )
55 {
56  mpImpl->mnState = SignatureState::UNKNOWN;
57 
58  mpImpl->maImage = Image(StockImage::Yes, RID_SVXBMP_SIGNET);
59  mpImpl->maImageBroken = Image(StockImage::Yes, RID_SVXBMP_SIGNET_BROKEN);
60  mpImpl->maImageNotValidated = Image(StockImage::Yes, RID_SVXBMP_SIGNET_NOTVALIDATED);
61 }
62 
64 {
65 }
66 
68 {
69  if( SfxItemState::DEFAULT != eState )
70  {
71  mpImpl->mnState = SignatureState::UNKNOWN;
72  }
73  else if( auto pUint16Item = dynamic_cast< const SfxUInt16Item* >(pState) )
74  {
75  mpImpl->mnState = static_cast<SignatureState>(pUint16Item->GetValue());
76  }
77  else
78  {
79  SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChangedAtStatusBarControl(): invalid item type" );
80  mpImpl->mnState = SignatureState::UNKNOWN;
81  }
82 
83  GetStatusBar().SetItemData( GetId(), nullptr ); // necessary ?
84 
85  GetStatusBar().SetItemText( GetId(), "" ); // necessary ?
86 
87  const char* pResId = RID_SVXSTR_XMLSEC_NO_SIG;
88  if ( mpImpl->mnState == SignatureState::OK )
89  pResId = RID_SVXSTR_XMLSEC_SIG_OK;
90  else if ( mpImpl->mnState == SignatureState::BROKEN )
91  pResId = RID_SVXSTR_XMLSEC_SIG_NOT_OK;
92  else if ( mpImpl->mnState == SignatureState::NOTVALIDATED )
93  pResId = RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY;
94  else if ( mpImpl->mnState == SignatureState::PARTIAL_OK )
95  pResId = RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG;
96 
98 }
99 
101 {
102  if( rCEvt.GetCommand() == CommandEventId::ContextMenu )
103  {
104  tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
105  weld::Window* pPopupParent = weld::GetPopupParent(GetStatusBar(), aRect);
106  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pPopupParent, "svx/ui/xmlsecstatmenu.ui"));
107  std::unique_ptr<weld::Menu> xPopMenu(xBuilder->weld_menu("menu"));
108  if (!xPopMenu->popup_at_rect(pPopupParent, aRect).isEmpty())
109  {
110  css::uno::Any a;
111  SfxUInt16Item aState( GetSlotId(), 0 );
112  INetURLObject aObj( m_aCommandURL );
113 
114  css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
115  aArgs[0].Name = aObj.GetURLPath();
116  aState.QueryValue( a );
117  aArgs[0].Value = a;
118 
119  execute( aArgs );
120  }
121  }
122  else
124 }
125 
127 {
128  vcl::RenderContext* pDev = rUsrEvt.GetRenderContext();
129 
130  tools::Rectangle aRect = rUsrEvt.GetRect();
131  Color aOldLineColor = pDev->GetLineColor();
132  Color aOldFillColor = pDev->GetFillColor();
133 
134  pDev->SetLineColor();
135  pDev->SetFillColor( pDev->GetBackground().GetColor() );
136 
137  tools::Long yOffset = (aRect.GetHeight() - mpImpl->maImage.GetSizePixel().Height()) / 2;
138 
139  if( mpImpl->mnState == SignatureState::OK )
140  {
141  aRect.AdjustTop(yOffset );
142  pDev->DrawImage( aRect.TopLeft(), mpImpl->maImage );
143  }
144  else if( mpImpl->mnState == SignatureState::BROKEN )
145  {
146  aRect.AdjustTop(yOffset );
147  pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageBroken );
148  }
149  else if( mpImpl->mnState == SignatureState::NOTVALIDATED
150  || mpImpl->mnState == SignatureState::PARTIAL_OK)
151  {
152  aRect.AdjustTop(yOffset );
153  pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageNotValidated );
154  }
155  else
156  pDev->DrawRect( aRect );
157 
158  pDev->SetLineColor( aOldLineColor );
159  pDev->SetFillColor( aOldFillColor );
160 }
161 
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const Wallpaper & GetBackground() const
sal_uInt16 GetSlotId() const
XmlSecStatusBarControl(sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar &_rStb)
Definition: xmlsecctrl.cxx:52
void DrawImage(const Point &rPos, const Image &rImage, DrawImageFlags nStyle=DrawImageFlags::NONE)
const tools::Rectangle & GetRect() const
OUString GetURLPath(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
long Long
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false)
virtual void Command(const CommandEvent &rCEvt) override
Definition: xmlsecctrl.cxx:100
void SetItemData(sal_uInt16 nItemId, void *pNewData)
void DrawRect(const tools::Rectangle &rRect)
sal_uInt16 GetId() const
void SetLineColor()
OUString SvxResId(std::string_view aId)
Definition: dialmgr.cxx:25
vcl::RenderContext * GetRenderContext() const
uno_Any a
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
const Color & GetColor() const
void SetFillColor()
const Color & GetLineColor() const
CommandEventId GetCommand() const
virtual ~XmlSecStatusBarControl() override
Definition: xmlsecctrl.cxx:63
SignatureState
constexpr Point TopLeft() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
const Point & GetMousePosPixel() const
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
SfxItemState
virtual void Command(const CommandEvent &rCEvt)
StatusBar & GetStatusBar() const
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: xmlsecctrl.cxx:126
#define SAL_WARN(area, stream)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
SFX_IMPL_STATUSBAR_CONTROL(XmlSecStatusBarControl, SfxUInt16Item)
std::unique_ptr< XmlSecStatusBarControl_Impl > mpImpl
Definition: xmlsecctrl.hxx:31
const Color & GetFillColor() const
constexpr tools::Long GetHeight() const
virtual void StateChangedAtStatusBarControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: xmlsecctrl.cxx:67