Revert "Revert "Revert "stronger typing for SwClient::GetRegisteredIn"" and fix SwIte...
[LibreOffice.git] / svx / source / stbctrls / xmlsecctrl.cxx
blobce852da13e62afb3d97470b81d7b20a05d57ca10
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 .
20 #include <sal/config.h>
22 #include <comphelper/propertyvalue.hxx>
23 #include <vcl/commandevent.hxx>
24 #include <vcl/image.hxx>
25 #include <vcl/event.hxx>
26 #include <vcl/status.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/weldutils.hxx>
29 #include <sfx2/signaturestate.hxx>
30 #include <sfx2/module.hxx>
32 #include <svl/intitem.hxx>
34 #include <svx/strings.hrc>
35 #include <svx/dialmgr.hxx>
36 #include <svx/xmlsecctrl.hxx>
37 #include <tools/urlobj.hxx>
38 #include <bitmaps.hlst>
39 #include <sal/log.hxx>
41 #include <com/sun/star/beans/PropertyValue.hpp>
43 SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxUInt16Item );
45 struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
47 SignatureState mnState;
48 Image maImage;
49 Image maImageBroken;
50 Image maImageNotValidated;
54 XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& _rStb )
55 :SfxStatusBarControl( _nSlotId, _nId, _rStb )
56 ,mpImpl( new XmlSecStatusBarControl_Impl )
58 mpImpl->mnState = SignatureState::UNKNOWN;
60 mpImpl->maImage = Image(StockImage::Yes, RID_SVXBMP_SIGNET);
61 mpImpl->maImageBroken = Image(StockImage::Yes, RID_SVXBMP_SIGNET_BROKEN);
62 mpImpl->maImageNotValidated = Image(StockImage::Yes, RID_SVXBMP_SIGNET_NOTVALIDATED);
65 XmlSecStatusBarControl::~XmlSecStatusBarControl()
69 void XmlSecStatusBarControl::StateChangedAtStatusBarControl( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
71 if( SfxItemState::DEFAULT != eState )
73 mpImpl->mnState = SignatureState::UNKNOWN;
75 else if( auto pUint16Item = dynamic_cast< const SfxUInt16Item* >(pState) )
77 mpImpl->mnState = static_cast<SignatureState>(pUint16Item->GetValue());
79 else
81 SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChangedAtStatusBarControl(): invalid item type" );
82 mpImpl->mnState = SignatureState::UNKNOWN;
85 GetStatusBar().SetItemData( GetId(), nullptr ); // necessary ?
87 GetStatusBar().SetItemText( GetId(), u""_ustr ); // necessary ?
89 TranslateId pResId = RID_SVXSTR_XMLSEC_NO_SIG;
90 if ( mpImpl->mnState == SignatureState::OK )
91 pResId = RID_SVXSTR_XMLSEC_SIG_OK;
92 else if ( mpImpl->mnState == SignatureState::BROKEN )
93 pResId = RID_SVXSTR_XMLSEC_SIG_NOT_OK;
94 else if ( mpImpl->mnState == SignatureState::NOTVALIDATED )
95 pResId = RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY;
96 else if ( mpImpl->mnState == SignatureState::PARTIAL_OK )
97 pResId = RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG;
99 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(pResId));
102 void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt )
104 if( rCEvt.GetCommand() == CommandEventId::ContextMenu )
106 tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
107 weld::Window* pPopupParent = weld::GetPopupParent(GetStatusBar(), aRect);
108 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pPopupParent, u"svx/ui/xmlsecstatmenu.ui"_ustr));
109 std::unique_ptr<weld::Menu> xPopMenu(xBuilder->weld_menu(u"menu"_ustr));
110 if (!xPopMenu->popup_at_rect(pPopupParent, aRect).isEmpty())
112 css::uno::Any a;
113 SfxUInt16Item aState( GetSlotId(), 0 );
114 aState.QueryValue( a );
115 INetURLObject aObj( m_aCommandURL );
117 css::uno::Sequence< css::beans::PropertyValue > aArgs{ comphelper::makePropertyValue(
118 aObj.GetURLPath(), a) };
119 execute( aArgs );
122 else
123 SfxStatusBarControl::Command( rCEvt );
126 void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt )
128 vcl::RenderContext* pDev = rUsrEvt.GetRenderContext();
130 tools::Rectangle aRect = rUsrEvt.GetRect();
131 pDev->Push(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR);
133 pDev->SetLineColor();
134 pDev->SetFillColor( pDev->GetBackground().GetColor() );
136 tools::Long yOffset = (aRect.GetHeight() - mpImpl->maImage.GetSizePixel().Height()) / 2;
138 if( mpImpl->mnState == SignatureState::OK )
140 aRect.AdjustTop(yOffset );
141 pDev->DrawImage( aRect.TopLeft(), mpImpl->maImage );
143 else if( mpImpl->mnState == SignatureState::BROKEN )
145 aRect.AdjustTop(yOffset );
146 pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageBroken );
148 else if( mpImpl->mnState == SignatureState::NOTVALIDATED
149 || mpImpl->mnState == SignatureState::PARTIAL_OK)
151 aRect.AdjustTop(yOffset );
152 pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageNotValidated );
154 else
155 pDev->DrawRect( aRect );
157 pDev->Pop();
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */