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/menu.hxx>
23 #include <vcl/image.hxx>
24 #include <sfx2/signaturestate.hxx>
25 #include <sfx2/app.hxx>
26 #include <sfx2/module.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <sfx2/objsh.hxx>
29 #include <sfx2/sfxsids.hrc>
31 #include <svl/intitem.hxx>
33 #include <svl/eitem.hxx>
35 #include <svx/dialogs.hrc>
36 #include <svx/dialmgr.hxx>
37 #include "svx/xmlsecctrl.hxx"
38 #include <tools/urlobj.hxx>
40 SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl
, SfxUInt16Item
);
42 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( SVX_RES( RID_SVXBMP_SIGNET
) );
60 mpImpl
->maImageBroken
= Image( SVX_RES( RID_SVXBMP_SIGNET_BROKEN
) );
61 mpImpl
->maImageNotValidated
= Image( SVX_RES( RID_SVXBMP_SIGNET_NOTVALIDATED
) );
63 if (_rStb
.GetDPIScaleFactor() > 1)
65 Image arr
[3] = {mpImpl
->maImage
, mpImpl
->maImageBroken
, mpImpl
->maImageNotValidated
};
67 for (int i
= 0; i
< 3; i
++)
69 BitmapEx b
= arr
[i
].GetBitmapEx();
70 b
.Scale(_rStb
.GetDPIScaleFactor(), _rStb
.GetDPIScaleFactor(), BmpScaleFlag::Fast
);
74 mpImpl
->maImage
= arr
[0];
75 mpImpl
->maImageBroken
= arr
[1];
76 mpImpl
->maImageNotValidated
= arr
[2];
81 XmlSecStatusBarControl::~XmlSecStatusBarControl()
86 void XmlSecStatusBarControl::StateChanged( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
88 if( SfxItemState::DEFAULT
!= eState
)
90 mpImpl
->mnState
= SignatureState::UNKNOWN
;
92 else if( pState
->ISA( SfxUInt16Item
) )
94 mpImpl
->mnState
= static_cast<SignatureState
>(static_cast<const SfxUInt16Item
*>(pState
)->GetValue());
98 SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
99 mpImpl
->mnState
= SignatureState::UNKNOWN
;
102 if( GetStatusBar().AreItemsVisible() ) // necessary ?
103 GetStatusBar().SetItemData( GetId(), 0 );
105 GetStatusBar().SetItemText( GetId(), "" ); // necessary ?
107 sal_uInt16 nResId
= RID_SVXSTR_XMLSEC_NO_SIG
;
108 if ( mpImpl
->mnState
== SignatureState::OK
)
109 nResId
= RID_SVXSTR_XMLSEC_SIG_OK
;
110 else if ( mpImpl
->mnState
== SignatureState::BROKEN
)
111 nResId
= RID_SVXSTR_XMLSEC_SIG_NOT_OK
;
112 else if ( mpImpl
->mnState
== SignatureState::NOTVALIDATED
)
113 nResId
= RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY
;
114 else if ( mpImpl
->mnState
== SignatureState::PARTIAL_OK
)
115 nResId
= RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG
;
117 GetStatusBar().SetQuickHelpText( GetId(), SVX_RESSTR( nResId
) );
120 void XmlSecStatusBarControl::Command( const CommandEvent
& rCEvt
)
122 if( rCEvt
.GetCommand() == CommandEventId::ContextMenu
)
124 PopupMenu
aPopupMenu( ResId( RID_SVXMNU_XMLSECSTATBAR
, DIALOG_MGR() ) );
125 if( aPopupMenu
.Execute( &GetStatusBar(), rCEvt
.GetMousePosPixel() ) )
127 ::com::sun::star::uno::Any a
;
128 SfxUInt16Item
aState( GetSlotId(), 0 );
129 INetURLObject
aObj( m_aCommandURL
);
131 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs( 1 );
132 aArgs
[0].Name
= aObj
.GetURLPath();
133 aState
.QueryValue( a
);
140 SfxStatusBarControl::Command( rCEvt
);
143 void XmlSecStatusBarControl::Paint( const UserDrawEvent
& rUsrEvt
)
145 vcl::RenderContext
* pDev
= rUsrEvt
.GetRenderContext();
147 Rectangle aRect
= rUsrEvt
.GetRect();
148 Color aOldLineColor
= pDev
->GetLineColor();
149 Color aOldFillColor
= pDev
->GetFillColor();
151 pDev
->SetLineColor();
152 pDev
->SetFillColor( pDev
->GetBackground().GetColor() );
154 long yOffset
= (aRect
.GetHeight() - mpImpl
->maImage
.GetSizePixel().Height()) / 2;
156 if( mpImpl
->mnState
== SignatureState::OK
)
158 aRect
.Top() += yOffset
;
159 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImage
);
161 else if( mpImpl
->mnState
== SignatureState::BROKEN
)
163 aRect
.Top() += yOffset
;
164 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImageBroken
);
166 else if( mpImpl
->mnState
== SignatureState::NOTVALIDATED
167 || mpImpl
->mnState
== SignatureState::PARTIAL_OK
)
169 aRect
.Top() += yOffset
;
170 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImageNotValidated
);
173 pDev
->DrawRect( aRect
);
175 pDev
->SetLineColor( aOldLineColor
);
176 pDev
->SetFillColor( aOldFillColor
);
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */