/src/libreoffice/svx/source/stbctrls/xmlsecctrl.cxx
Line | Count | Source |
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 | | #include <sal/config.h> |
21 | | |
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/weld/weldutils.hxx> |
29 | | #include <sfx2/signaturestate.hxx> |
30 | | #include <sfx2/module.hxx> |
31 | | |
32 | | #include <svl/intitem.hxx> |
33 | | |
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> |
40 | | |
41 | | #include <com/sun/star/beans/PropertyValue.hpp> |
42 | | |
43 | | SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxUInt16Item ); |
44 | | |
45 | | struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl |
46 | | { |
47 | | SignatureState mnState; |
48 | | Image maImage; |
49 | | Image maImageBroken; |
50 | | Image maImageNotValidated; |
51 | | }; |
52 | | |
53 | | |
54 | | XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& _rStb ) |
55 | 0 | :SfxStatusBarControl( _nSlotId, _nId, _rStb ) |
56 | 0 | ,mpImpl( new XmlSecStatusBarControl_Impl ) |
57 | 0 | { |
58 | 0 | mpImpl->mnState = SignatureState::UNKNOWN; |
59 | |
|
60 | 0 | mpImpl->maImage = Image(StockImage::Yes, RID_SVXBMP_SIGNET); |
61 | 0 | mpImpl->maImageBroken = Image(StockImage::Yes, RID_SVXBMP_SIGNET_BROKEN); |
62 | 0 | mpImpl->maImageNotValidated = Image(StockImage::Yes, RID_SVXBMP_SIGNET_NOTVALIDATED); |
63 | 0 | } |
64 | | |
65 | | XmlSecStatusBarControl::~XmlSecStatusBarControl() |
66 | 0 | { |
67 | 0 | } |
68 | | |
69 | | void XmlSecStatusBarControl::StateChangedAtStatusBarControl( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState ) |
70 | 0 | { |
71 | 0 | if( SfxItemState::DEFAULT != eState ) |
72 | 0 | { |
73 | 0 | mpImpl->mnState = SignatureState::UNKNOWN; |
74 | 0 | } |
75 | 0 | else if( auto pUint16Item = dynamic_cast< const SfxUInt16Item* >(pState) ) |
76 | 0 | { |
77 | 0 | mpImpl->mnState = static_cast<SignatureState>(pUint16Item->GetValue()); |
78 | 0 | } |
79 | 0 | else |
80 | 0 | { |
81 | 0 | SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChangedAtStatusBarControl(): invalid item type" ); |
82 | 0 | mpImpl->mnState = SignatureState::UNKNOWN; |
83 | 0 | } |
84 | | |
85 | 0 | GetStatusBar().SetItemData( GetId(), nullptr ); // necessary ? |
86 | |
|
87 | 0 | GetStatusBar().SetItemText( GetId(), u""_ustr ); // necessary ? |
88 | |
|
89 | 0 | TranslateId pResId = RID_SVXSTR_XMLSEC_NO_SIG; |
90 | 0 | if ( mpImpl->mnState == SignatureState::OK ) |
91 | 0 | pResId = RID_SVXSTR_XMLSEC_SIG_OK; |
92 | 0 | else if ( mpImpl->mnState == SignatureState::BROKEN ) |
93 | 0 | pResId = RID_SVXSTR_XMLSEC_SIG_NOT_OK; |
94 | 0 | else if ( mpImpl->mnState == SignatureState::NOTVALIDATED ) |
95 | 0 | pResId = RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY; |
96 | 0 | else if ( mpImpl->mnState == SignatureState::PARTIAL_OK ) |
97 | 0 | pResId = RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG; |
98 | |
|
99 | 0 | GetStatusBar().SetQuickHelpText(GetId(), SvxResId(pResId)); |
100 | 0 | } |
101 | | |
102 | | void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt ) |
103 | 0 | { |
104 | 0 | if( rCEvt.GetCommand() == CommandEventId::ContextMenu ) |
105 | 0 | { |
106 | 0 | tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1)); |
107 | 0 | weld::Window* pPopupParent = weld::GetPopupParent(GetStatusBar(), aRect); |
108 | 0 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pPopupParent, u"svx/ui/xmlsecstatmenu.ui"_ustr)); |
109 | 0 | std::unique_ptr<weld::Menu> xPopMenu(xBuilder->weld_menu(u"menu"_ustr)); |
110 | 0 | if (!xPopMenu->popup_at_rect(pPopupParent, aRect).isEmpty()) |
111 | 0 | { |
112 | 0 | css::uno::Any a; |
113 | 0 | SfxUInt16Item aState( GetSlotId(), 0 ); |
114 | 0 | aState.QueryValue( a ); |
115 | 0 | INetURLObject aObj( m_aCommandURL ); |
116 | |
|
117 | 0 | css::uno::Sequence< css::beans::PropertyValue > aArgs{ comphelper::makePropertyValue( |
118 | 0 | aObj.GetURLPath(), a) }; |
119 | 0 | execute( aArgs ); |
120 | 0 | } |
121 | 0 | } |
122 | 0 | else |
123 | 0 | SfxStatusBarControl::Command( rCEvt ); |
124 | 0 | } |
125 | | |
126 | | void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt ) |
127 | 0 | { |
128 | 0 | vcl::RenderContext* pDev = rUsrEvt.GetRenderContext(); |
129 | |
|
130 | 0 | tools::Rectangle aRect = rUsrEvt.GetRect(); |
131 | 0 | auto popIt = pDev->ScopedPush(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR); |
132 | |
|
133 | 0 | pDev->SetLineColor(); |
134 | 0 | pDev->SetFillColor( pDev->GetBackground().GetColor() ); |
135 | |
|
136 | 0 | tools::Long yOffset = (aRect.GetHeight() - mpImpl->maImage.GetSizePixel().Height()) / 2; |
137 | |
|
138 | 0 | if( mpImpl->mnState == SignatureState::OK ) |
139 | 0 | { |
140 | 0 | aRect.AdjustTop(yOffset ); |
141 | 0 | pDev->DrawImage( aRect.TopLeft(), mpImpl->maImage ); |
142 | 0 | } |
143 | 0 | else if( mpImpl->mnState == SignatureState::BROKEN ) |
144 | 0 | { |
145 | 0 | aRect.AdjustTop(yOffset ); |
146 | 0 | pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageBroken ); |
147 | 0 | } |
148 | 0 | else if( mpImpl->mnState == SignatureState::NOTVALIDATED |
149 | 0 | || mpImpl->mnState == SignatureState::PARTIAL_OK) |
150 | 0 | { |
151 | 0 | aRect.AdjustTop(yOffset ); |
152 | 0 | pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageNotValidated ); |
153 | 0 | } |
154 | 0 | else |
155 | 0 | pDev->DrawRect( aRect ); |
156 | 0 | } |
157 | | |
158 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |