bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / stbctrls / xmlsecctrl.cxx
blob45b1f9668793710a5d035bec98d6b55cfdbe7a39
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 .
21 #include <tools/shl.hxx>
22 #include <vcl/status.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/dialogs.hrc>
37 #include <svx/dialmgr.hxx>
38 #include "svx/xmlsecctrl.hxx"
39 #include <tools/urlobj.hxx>
41 SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxUInt16Item );
43 struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
45 Point maPos;
46 Size maSize;
47 sal_uInt16 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 = (sal_uInt16)SIGNATURESTATE_UNKNOWN;
60 mpImpl->maImage = Image( SVX_RES( RID_SVXBMP_SIGNET ) );
61 mpImpl->maImageBroken = Image( SVX_RES( RID_SVXBMP_SIGNET_BROKEN ) );
62 mpImpl->maImageNotValidated = Image( SVX_RES( RID_SVXBMP_SIGNET_NOTVALIDATED ) );
65 XmlSecStatusBarControl::~XmlSecStatusBarControl()
67 delete mpImpl;
70 void XmlSecStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
72 if( SFX_ITEM_AVAILABLE != eState )
74 mpImpl->mnState = (sal_uInt16)SIGNATURESTATE_UNKNOWN;
76 else if( pState->ISA( SfxUInt16Item ) )
78 mpImpl->mnState = ( ( SfxUInt16Item* ) pState )->GetValue();
80 else
82 SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
83 mpImpl->mnState = (sal_uInt16)SIGNATURESTATE_UNKNOWN;
86 if( GetStatusBar().AreItemsVisible() ) // necessary ?
87 GetStatusBar().SetItemData( GetId(), 0 );
89 GetStatusBar().SetItemText( GetId(), String() ); // necessary ?
91 sal_uInt16 nResId = RID_SVXSTR_XMLSEC_NO_SIG;
92 if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_OK )
93 nResId = RID_SVXSTR_XMLSEC_SIG_OK;
94 else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_BROKEN )
95 nResId = RID_SVXSTR_XMLSEC_SIG_NOT_OK;
96 else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
97 nResId = RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY;
98 else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK )
99 nResId = RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG;
101 GetStatusBar().SetQuickHelpText( GetId(), SVX_RESSTR( nResId ) );
104 void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt )
106 if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
108 PopupMenu aPopupMenu( ResId( RID_SVXMNU_XMLSECSTATBAR, DIALOG_MGR() ) );
109 if( aPopupMenu.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel() ) )
111 ::com::sun::star::uno::Any a;
112 SfxUInt16Item aState( GetSlotId(), 0 );
113 INetURLObject aObj( m_aCommandURL );
115 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
116 aArgs[0].Name = aObj.GetURLPath();
117 aState.QueryValue( a );
118 aArgs[0].Value = a;
120 execute( aArgs );
123 else
124 SfxStatusBarControl::Command( rCEvt );
127 void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt )
129 OutputDevice* pDev = rUsrEvt.GetDevice();
130 DBG_ASSERT( pDev, "-XmlSecStatusBarControl::Paint(): no Output Device... this will lead to nirvana..." );
131 Rectangle aRect = rUsrEvt.GetRect();
132 Color aOldLineColor = pDev->GetLineColor();
133 Color aOldFillColor = pDev->GetFillColor();
135 pDev->SetLineColor();
136 pDev->SetFillColor( pDev->GetBackground().GetColor() );
138 if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_OK )
140 ++aRect.Top();
141 pDev->DrawImage( aRect.TopLeft(), mpImpl->maImage );
143 else if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_BROKEN )
145 ++aRect.Top();
146 pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageBroken );
148 else if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED
149 || mpImpl->mnState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK)
151 ++aRect.Top();
152 pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageNotValidated );
154 else
155 pDev->DrawRect( aRect );
157 pDev->SetLineColor( aOldLineColor );
158 pDev->SetFillColor( aOldFillColor );
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */