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/status.hxx>
22 #include <vcl/builder.hxx>
23 #include <vcl/menu.hxx>
24 #include <vcl/image.hxx>
25 #include <vcl/commandevent.hxx>
26 #include <vcl/event.hxx>
27 #include <sfx2/signaturestate.hxx>
28 #include <sfx2/app.hxx>
29 #include <sfx2/module.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include <sfx2/objsh.hxx>
32 #include <sfx2/sfxsids.hrc>
33 
34 #include <svl/intitem.hxx>
35 
36 #include <svl/eitem.hxx>
37 
38 #include <svx/strings.hrc>
39 #include <svx/dialmgr.hxx>
40 #include <svx/xmlsecctrl.hxx>
41 #include <tools/urlobj.hxx>
42 #include <bitmaps.hlst>
43 #include <sal/log.hxx>
44 
45 #include <com/sun/star/beans/PropertyValue.hpp>
46 
48 
50 {
55 };
56 
57 
58 XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& _rStb )
59  :SfxStatusBarControl( _nSlotId, _nId, _rStb )
60  ,mpImpl( new XmlSecStatusBarControl_Impl )
61 {
62  mpImpl->mnState = SignatureState::UNKNOWN;
63 
64  mpImpl->maImage = Image(StockImage::Yes, RID_SVXBMP_SIGNET);
65  mpImpl->maImageBroken = Image(StockImage::Yes, RID_SVXBMP_SIGNET_BROKEN);
66  mpImpl->maImageNotValidated = Image(StockImage::Yes, RID_SVXBMP_SIGNET_NOTVALIDATED);
67 }
68 
70 {
71 }
72 
73 void XmlSecStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
74 {
75  if( SfxItemState::DEFAULT != eState )
76  {
77  mpImpl->mnState = SignatureState::UNKNOWN;
78  }
79  else if( auto pUint16Item = dynamic_cast< const SfxUInt16Item* >(pState) )
80  {
81  mpImpl->mnState = static_cast<SignatureState>(pUint16Item->GetValue());
82  }
83  else
84  {
85  SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
86  mpImpl->mnState = SignatureState::UNKNOWN;
87  }
88 
89  GetStatusBar().SetItemData( GetId(), nullptr ); // necessary ?
90 
91  GetStatusBar().SetItemText( GetId(), "" ); // necessary ?
92 
93  const char* pResId = RID_SVXSTR_XMLSEC_NO_SIG;
94  if ( mpImpl->mnState == SignatureState::OK )
95  pResId = RID_SVXSTR_XMLSEC_SIG_OK;
96  else if ( mpImpl->mnState == SignatureState::BROKEN )
97  pResId = RID_SVXSTR_XMLSEC_SIG_NOT_OK;
98  else if ( mpImpl->mnState == SignatureState::NOTVALIDATED )
99  pResId = RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY;
100  else if ( mpImpl->mnState == SignatureState::PARTIAL_OK )
101  pResId = RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG;
102 
104 }
105 
107 {
108  if( rCEvt.GetCommand() == CommandEventId::ContextMenu )
109  {
110  VclBuilder aBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "svx/ui/xmlsecstatmenu.ui", "");
111  VclPtr<PopupMenu> aPopupMenu(aBuilder.get_menu("menu"));
112  if (aPopupMenu->Execute(&GetStatusBar(), rCEvt.GetMousePosPixel()))
113  {
114  css::uno::Any a;
115  SfxUInt16Item aState( GetSlotId(), 0 );
116  INetURLObject aObj( m_aCommandURL );
117 
118  css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
119  aArgs[0].Name = aObj.GetURLPath();
120  aState.QueryValue( a );
121  aArgs[0].Value = a;
122 
123  execute( aArgs );
124  }
125  }
126  else
128 }
129 
131 {
132  vcl::RenderContext* pDev = rUsrEvt.GetRenderContext();
133 
134  tools::Rectangle aRect = rUsrEvt.GetRect();
135  Color aOldLineColor = pDev->GetLineColor();
136  Color aOldFillColor = pDev->GetFillColor();
137 
138  pDev->SetLineColor();
139  pDev->SetFillColor( pDev->GetBackground().GetColor() );
140 
141  long yOffset = (aRect.GetHeight() - mpImpl->maImage.GetSizePixel().Height()) / 2;
142 
143  if( mpImpl->mnState == SignatureState::OK )
144  {
145  aRect.AdjustTop(yOffset );
146  pDev->DrawImage( aRect.TopLeft(), mpImpl->maImage );
147  }
148  else if( mpImpl->mnState == SignatureState::BROKEN )
149  {
150  aRect.AdjustTop(yOffset );
151  pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageBroken );
152  }
153  else if( mpImpl->mnState == SignatureState::NOTVALIDATED
154  || mpImpl->mnState == SignatureState::PARTIAL_OK)
155  {
156  aRect.AdjustTop(yOffset );
157  pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageNotValidated );
158  }
159  else
160  pDev->DrawRect( aRect );
161 
162  pDev->SetLineColor( aOldLineColor );
163  pDev->SetFillColor( aOldFillColor );
164 }
165 
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point TopLeft() const
const Wallpaper & GetBackground() const
sal_uInt16 GetSlotId() const
long GetHeight() const
XmlSecStatusBarControl(sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar &_rStb)
Definition: xmlsecctrl.cxx:58
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
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: xmlsecctrl.cxx:73
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
virtual void Command(const CommandEvent &rCEvt) override
Definition: xmlsecctrl.cxx:106
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
void SetItemData(sal_uInt16 nItemId, void *pNewData)
void DrawRect(const tools::Rectangle &rRect)
sal_uInt16 GetId() const
void SetLineColor()
vcl::RenderContext * GetRenderContext() const
uno_Any a
const Color & GetColor() const
void SetFillColor()
const Color & GetLineColor() const
CommandEventId GetCommand() const
virtual ~XmlSecStatusBarControl() override
Definition: xmlsecctrl.cxx:69
static OUString getUIRootDir()
SignatureState
const Point & GetMousePosPixel() const
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
SfxItemState
virtual void Command(const CommandEvent &rCEvt)
StatusBar & GetStatusBar() const
long AdjustTop(long nVertMoveDelta)
PopupMenu * get_menu(const OString &sID)
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: xmlsecctrl.cxx:130
#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