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