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#include <sal/config.h>
21
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>
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
44
46{
51};
52
53
54XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& _rStb )
55 :SfxStatusBarControl( _nSlotId, _nId, _rStb )
56 ,mpImpl( new XmlSecStatusBarControl_Impl )
57{
58 mpImpl->mnState = SignatureState::UNKNOWN;
59
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);
63}
64
66{
67}
68
70{
71 if( SfxItemState::DEFAULT != eState )
72 {
73 mpImpl->mnState = SignatureState::UNKNOWN;
74 }
75 else if( auto pUint16Item = dynamic_cast< const SfxUInt16Item* >(pState) )
76 {
77 mpImpl->mnState = static_cast<SignatureState>(pUint16Item->GetValue());
78 }
79 else
80 {
81 SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChangedAtStatusBarControl(): invalid item type" );
82 mpImpl->mnState = SignatureState::UNKNOWN;
83 }
84
85 GetStatusBar().SetItemData( GetId(), nullptr ); // necessary ?
86
87 GetStatusBar().SetItemText( GetId(), "" ); // necessary ?
88
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;
98
100}
101
103{
104 if( rCEvt.GetCommand() == CommandEventId::ContextMenu )
105 {
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, "svx/ui/xmlsecstatmenu.ui"));
109 std::unique_ptr<weld::Menu> xPopMenu(xBuilder->weld_menu("menu"));
110 if (!xPopMenu->popup_at_rect(pPopupParent, aRect).isEmpty())
111 {
112 css::uno::Any a;
113 SfxUInt16Item aState( GetSlotId(), 0 );
114 aState.QueryValue( a );
115 INetURLObject aObj( m_aCommandURL );
116
117 css::uno::Sequence< css::beans::PropertyValue > aArgs{ comphelper::makePropertyValue(
118 aObj.GetURLPath(), a) };
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: */
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
OUString GetURLPath(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
void DrawRect(const tools::Rectangle &rRect)
const Wallpaper & GetBackground() const
void SetLineColor()
void DrawImage(const Point &rPos, const Image &rImage, DrawImageFlags nStyle=DrawImageFlags::NONE)
void SetFillColor()
const Color & GetLineColor() const
const Color & GetFillColor() const
StatusBar & GetStatusBar() const
virtual void Command(const CommandEvent &rCEvt)
sal_uInt16 GetId() const
sal_uInt16 GetSlotId() const
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
void SetItemData(sal_uInt16 nItemId, void *pNewData)
vcl::RenderContext * GetRenderContext() const
const tools::Rectangle & GetRect() const
const Color & GetColor() const
std::unique_ptr< XmlSecStatusBarControl_Impl > mpImpl
Definition: xmlsecctrl.hxx:31
virtual ~XmlSecStatusBarControl() override
Definition: xmlsecctrl.cxx:65
virtual void StateChangedAtStatusBarControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: xmlsecctrl.cxx:69
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: xmlsecctrl.cxx:126
XmlSecStatusBarControl(sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar &_rStb)
Definition: xmlsecctrl.cxx:54
virtual void Command(const CommandEvent &rCEvt) override
Definition: xmlsecctrl.cxx:102
constexpr Point TopLeft() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
constexpr tools::Long GetHeight() const
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
uno_Any a
#define SAL_WARN(area, stream)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
long Long
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
SfxItemState
SignatureState
SFX_IMPL_STATUSBAR_CONTROL(XmlSecStatusBarControl, SfxUInt16Item)