1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svx.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // include --------------------------------------------------------------- 32*cdf0e10cSrcweir #include <tools/shl.hxx> 33*cdf0e10cSrcweir #ifndef _STATUS_HXX //autogen 34*cdf0e10cSrcweir #include <vcl/status.hxx> 35*cdf0e10cSrcweir #endif 36*cdf0e10cSrcweir #ifndef _MENU_HXX //autogen 37*cdf0e10cSrcweir #include <vcl/menu.hxx> 38*cdf0e10cSrcweir #endif 39*cdf0e10cSrcweir #include <vcl/image.hxx> 40*cdf0e10cSrcweir //#ifndef _SFXITEMPOOL_HXX 41*cdf0e10cSrcweir //#include <svl/itempool.hxx> 42*cdf0e10cSrcweir //#endif 43*cdf0e10cSrcweir #include <sfx2/signaturestate.hxx> 44*cdf0e10cSrcweir #include <sfx2/app.hxx> 45*cdf0e10cSrcweir #include <sfx2/module.hxx> 46*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 47*cdf0e10cSrcweir #include <sfx2/objsh.hxx> 48*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #include <svl/intitem.hxx> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #include <svl/eitem.hxx> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #include <svx/dialogs.hrc> 55*cdf0e10cSrcweir #include <svx/dialmgr.hxx> 56*cdf0e10cSrcweir #include "svx/xmlsecctrl.hxx" 57*cdf0e10cSrcweir #include <tools/urlobj.hxx> 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir #define PAINT_OFFSET 5 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir //#include <editeng/sizeitem.hxx> 62*cdf0e10cSrcweir //#include <svx/dialmgr.hxx> 63*cdf0e10cSrcweir //#include "svx/dlgutil.hxx" 64*cdf0e10cSrcweir //#include "stbctrls.h" 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir //#include <svx/dialogs.hrc> 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir /*#ifndef _UNOTOOLS_LOCALEDATAWRAPPER_HXX 69*cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx> 70*cdf0e10cSrcweir #endif 71*cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX 72*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 73*cdf0e10cSrcweir #endif*/ 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxUInt16Item ); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir Point maPos; 82*cdf0e10cSrcweir Size maSize; 83*cdf0e10cSrcweir sal_uInt16 mnState; 84*cdf0e10cSrcweir Image maImage; 85*cdf0e10cSrcweir Image maImageBroken; 86*cdf0e10cSrcweir Image maImageNotValidated; 87*cdf0e10cSrcweir }; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& _rStb ) 91*cdf0e10cSrcweir :SfxStatusBarControl( _nSlotId, _nId, _rStb ) 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir ,mpImpl( new XmlSecStatusBarControl_Impl ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir mpImpl->mnState = (sal_uInt16)SIGNATURESTATE_UNKNOWN; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir sal_Bool bHC = GetStatusBar().GetSettings().GetStyleSettings().GetHighContrastMode(); 98*cdf0e10cSrcweir mpImpl->maImage = Image( SVX_RES( bHC ? RID_SVXBMP_SIGNET_H : RID_SVXBMP_SIGNET ) ); 99*cdf0e10cSrcweir mpImpl->maImageBroken = 100*cdf0e10cSrcweir Image( SVX_RES( bHC ? RID_SVXBMP_SIGNET_BROKEN_H : RID_SVXBMP_SIGNET_BROKEN ) ); 101*cdf0e10cSrcweir mpImpl->maImageNotValidated = 102*cdf0e10cSrcweir Image( SVX_RES( bHC ? RID_SVXBMP_SIGNET_NOTVALIDATED_H : RID_SVXBMP_SIGNET_NOTVALIDATED ) ); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir XmlSecStatusBarControl::~XmlSecStatusBarControl() 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir delete mpImpl; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir void XmlSecStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir if( SFX_ITEM_AVAILABLE != eState ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir mpImpl->mnState = (sal_uInt16)SIGNATURESTATE_UNKNOWN; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir else if( pState->ISA( SfxUInt16Item ) ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir // mpImpl->mbSigned = ( ( SfxUInt16Item* ) pState )->GetValue() == 1 /* SIGNED*/ ; 119*cdf0e10cSrcweir mpImpl->mnState = ( ( SfxUInt16Item* ) pState )->GetValue(); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir else 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir DBG_ERRORFILE( "+XmlSecStatusBarControl::StateChanged(): invalid item type" ); 124*cdf0e10cSrcweir mpImpl->mnState = (sal_uInt16)SIGNATURESTATE_UNKNOWN; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir if( GetStatusBar().AreItemsVisible() ) // necessary ? 128*cdf0e10cSrcweir GetStatusBar().SetItemData( GetId(), 0 ); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), String() ); // necessary ? 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir sal_uInt16 nResId = RID_SVXSTR_XMLSEC_NO_SIG; 133*cdf0e10cSrcweir if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_OK ) 134*cdf0e10cSrcweir nResId = RID_SVXSTR_XMLSEC_SIG_OK; 135*cdf0e10cSrcweir else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_BROKEN ) 136*cdf0e10cSrcweir nResId = RID_SVXSTR_XMLSEC_SIG_NOT_OK; 137*cdf0e10cSrcweir else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED ) 138*cdf0e10cSrcweir nResId = RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY; 139*cdf0e10cSrcweir else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK ) 140*cdf0e10cSrcweir nResId = RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir GetStatusBar().SetQuickHelpText( GetId(), SVX_RESSTR( nResId ) ); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir PopupMenu aPopupMenu( ResId( RID_SVXMNU_XMLSECSTATBAR, DIALOG_MGR() ) ); 150*cdf0e10cSrcweir if( aPopupMenu.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel() ) ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir ::com::sun::star::uno::Any a; 153*cdf0e10cSrcweir SfxUInt16Item aState( GetSlotId(), 0 ); 154*cdf0e10cSrcweir INetURLObject aObj( m_aCommandURL ); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 ); 157*cdf0e10cSrcweir aArgs[0].Name = aObj.GetURLPath(); 158*cdf0e10cSrcweir aState.QueryValue( a ); 159*cdf0e10cSrcweir aArgs[0].Value = a; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir execute( aArgs ); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir else 165*cdf0e10cSrcweir SfxStatusBarControl::Command( rCEvt ); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt ) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir OutputDevice* pDev = rUsrEvt.GetDevice(); 171*cdf0e10cSrcweir DBG_ASSERT( pDev, "-XmlSecStatusBarControl::Paint(): no Output Device... this will lead to nirvana..." ); 172*cdf0e10cSrcweir Rectangle aRect = rUsrEvt.GetRect(); 173*cdf0e10cSrcweir StatusBar& rBar = GetStatusBar(); 174*cdf0e10cSrcweir Point aItemPos = rBar.GetItemTextPos( GetId() ); 175*cdf0e10cSrcweir Color aOldLineColor = pDev->GetLineColor(); 176*cdf0e10cSrcweir Color aOldFillColor = pDev->GetFillColor(); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir pDev->SetLineColor(); 179*cdf0e10cSrcweir pDev->SetFillColor( pDev->GetBackground().GetColor() ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_OK ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir ++aRect.Top(); 184*cdf0e10cSrcweir pDev->DrawImage( aRect.TopLeft(), mpImpl->maImage ); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir else if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_BROKEN ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir ++aRect.Top(); 189*cdf0e10cSrcweir pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageBroken ); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir else if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED 192*cdf0e10cSrcweir || mpImpl->mnState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir ++aRect.Top(); 195*cdf0e10cSrcweir pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageNotValidated ); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir else 198*cdf0e10cSrcweir pDev->DrawRect( aRect ); 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir pDev->SetLineColor( aOldLineColor ); 201*cdf0e10cSrcweir pDev->SetFillColor( aOldFillColor ); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir long XmlSecStatusBarControl::GetDefItemWidth( StatusBar& ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir return 16; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209