Bump version to 6.4.7.2.M8
[LibreOffice.git] / svx / source / stbctrls / xmlsecctrl.cxx
blob92807494e8e022b7a98f682a49a6397f07fe9ff3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
34 #include <svl/intitem.hxx>
36 #include <svl/eitem.hxx>
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>
45 #include <com/sun/star/beans/PropertyValue.hpp>
47 SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxUInt16Item );
49 struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
51 SignatureState mnState;
52 Image maImage;
53 Image maImageBroken;
54 Image maImageNotValidated;
58 XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& _rStb )
59 :SfxStatusBarControl( _nSlotId, _nId, _rStb )
60 ,mpImpl( new XmlSecStatusBarControl_Impl )
62 mpImpl->mnState = SignatureState::UNKNOWN;
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);
69 XmlSecStatusBarControl::~XmlSecStatusBarControl()
73 void XmlSecStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
75 if( SfxItemState::DEFAULT != eState )
77 mpImpl->mnState = SignatureState::UNKNOWN;
79 else if( auto pUint16Item = dynamic_cast< const SfxUInt16Item* >(pState) )
81 mpImpl->mnState = static_cast<SignatureState>(pUint16Item->GetValue());
83 else
85 SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
86 mpImpl->mnState = SignatureState::UNKNOWN;
89 GetStatusBar().SetItemData( GetId(), nullptr ); // necessary ?
91 GetStatusBar().SetItemText( GetId(), "" ); // necessary ?
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;
103 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(pResId));
106 void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt )
108 if( rCEvt.GetCommand() == CommandEventId::ContextMenu )
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()))
114 css::uno::Any a;
115 SfxUInt16Item aState( GetSlotId(), 0 );
116 INetURLObject aObj( m_aCommandURL );
118 css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
119 aArgs[0].Name = aObj.GetURLPath();
120 aState.QueryValue( a );
121 aArgs[0].Value = a;
123 execute( aArgs );
126 else
127 SfxStatusBarControl::Command( rCEvt );
130 void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt )
132 vcl::RenderContext* pDev = rUsrEvt.GetRenderContext();
134 tools::Rectangle aRect = rUsrEvt.GetRect();
135 Color aOldLineColor = pDev->GetLineColor();
136 Color aOldFillColor = pDev->GetFillColor();
138 pDev->SetLineColor();
139 pDev->SetFillColor( pDev->GetBackground().GetColor() );
141 long yOffset = (aRect.GetHeight() - mpImpl->maImage.GetSizePixel().Height()) / 2;
143 if( mpImpl->mnState == SignatureState::OK )
145 aRect.AdjustTop(yOffset );
146 pDev->DrawImage( aRect.TopLeft(), mpImpl->maImage );
148 else if( mpImpl->mnState == SignatureState::BROKEN )
150 aRect.AdjustTop(yOffset );
151 pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageBroken );
153 else if( mpImpl->mnState == SignatureState::NOTVALIDATED
154 || mpImpl->mnState == SignatureState::PARTIAL_OK)
156 aRect.AdjustTop(yOffset );
157 pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageNotValidated );
159 else
160 pDev->DrawRect( aRect );
162 pDev->SetLineColor( aOldLineColor );
163 pDev->SetFillColor( aOldFillColor );
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */