1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sfx2/signaturestate.hxx>
26 #include <sfx2/app.hxx>
27 #include <sfx2/module.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/objsh.hxx>
30 #include <sfx2/sfxsids.hrc>
32 #include <svl/intitem.hxx>
34 #include <svl/eitem.hxx>
36 #include <svx/strings.hrc>
37 #include <svx/dialmgr.hxx>
38 #include <svx/xmlsecctrl.hxx>
39 #include <tools/urlobj.hxx>
40 #include <bitmaps.hlst>
42 SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl
, SfxUInt16Item
);
44 struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
46 SignatureState mnState
;
49 Image maImageNotValidated
;
53 XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId
, sal_uInt16 _nId
, StatusBar
& _rStb
)
54 :SfxStatusBarControl( _nSlotId
, _nId
, _rStb
)
55 ,mpImpl( new XmlSecStatusBarControl_Impl
)
57 mpImpl
->mnState
= SignatureState::UNKNOWN
;
59 mpImpl
->maImage
= Image(BitmapEx(RID_SVXBMP_SIGNET
));
60 mpImpl
->maImageBroken
= Image(BitmapEx(RID_SVXBMP_SIGNET_BROKEN
));
61 mpImpl
->maImageNotValidated
= Image(BitmapEx(RID_SVXBMP_SIGNET_NOTVALIDATED
));
64 XmlSecStatusBarControl::~XmlSecStatusBarControl()
68 void XmlSecStatusBarControl::StateChanged( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
70 if( SfxItemState::DEFAULT
!= eState
)
72 mpImpl
->mnState
= SignatureState::UNKNOWN
;
74 else if( auto pUint16Item
= dynamic_cast< const SfxUInt16Item
* >(pState
) )
76 mpImpl
->mnState
= static_cast<SignatureState
>(pUint16Item
->GetValue());
80 SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
81 mpImpl
->mnState
= SignatureState::UNKNOWN
;
84 if( GetStatusBar().AreItemsVisible() ) // necessary ?
85 GetStatusBar().SetItemData( GetId(), nullptr );
87 GetStatusBar().SetItemText( GetId(), "" ); // necessary ?
89 const char* 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 VclBuilder
aBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "svx/ui/xmlsecstatmenu.ui", "");
107 VclPtr
<PopupMenu
> aPopupMenu(aBuilder
.get_menu("menu"));
108 if (aPopupMenu
->Execute(&GetStatusBar(), rCEvt
.GetMousePosPixel()))
111 SfxUInt16Item
aState( GetSlotId(), 0 );
112 INetURLObject
aObj( m_aCommandURL
);
114 css::uno::Sequence
< css::beans::PropertyValue
> aArgs( 1 );
115 aArgs
[0].Name
= aObj
.GetURLPath();
116 aState
.QueryValue( a
);
123 SfxStatusBarControl::Command( rCEvt
);
126 void XmlSecStatusBarControl::Paint( const UserDrawEvent
& rUsrEvt
)
128 vcl::RenderContext
* pDev
= rUsrEvt
.GetRenderContext();
130 tools::Rectangle aRect
= rUsrEvt
.GetRect();
131 Color aOldLineColor
= pDev
->GetLineColor();
132 Color aOldFillColor
= pDev
->GetFillColor();
134 pDev
->SetLineColor();
135 pDev
->SetFillColor( pDev
->GetBackground().GetColor() );
137 long yOffset
= (aRect
.GetHeight() - mpImpl
->maImage
.GetSizePixel().Height()) / 2;
139 if( mpImpl
->mnState
== SignatureState::OK
)
141 aRect
.Top() += yOffset
;
142 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImage
);
144 else if( mpImpl
->mnState
== SignatureState::BROKEN
)
146 aRect
.Top() += yOffset
;
147 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImageBroken
);
149 else if( mpImpl
->mnState
== SignatureState::NOTVALIDATED
150 || mpImpl
->mnState
== SignatureState::PARTIAL_OK
)
152 aRect
.Top() += yOffset
;
153 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImageNotValidated
);
156 pDev
->DrawRect( aRect
);
158 pDev
->SetLineColor( aOldLineColor
);
159 pDev
->SetFillColor( aOldFillColor
);
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */