1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlsecctrl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <tools/shl.hxx>
36 #ifndef _STATUS_HXX //autogen
37 #include <vcl/status.hxx>
39 #ifndef _MENU_HXX //autogen
40 #include <vcl/menu.hxx>
42 #include <vcl/image.hxx>
43 //#ifndef _SFXITEMPOOL_HXX
44 //#include <svtools/itempool.hxx>
46 #include <sfx2/signaturestate.hxx>
47 #include <sfx2/app.hxx>
48 #include <sfx2/module.hxx>
49 #include <sfx2/dispatch.hxx>
50 #include <sfx2/objsh.hxx>
51 #include <sfx2/sfxsids.hrc>
53 #include <svtools/intitem.hxx>
55 #include <svtools/eitem.hxx>
57 #include <svx/dialogs.hrc>
58 #include <svx/dialmgr.hxx>
59 #include "xmlsecctrl.hxx"
60 #include <tools/urlobj.hxx>
62 #define PAINT_OFFSET 5
64 //#include <svx/sizeitem.hxx>
65 //#include <svx/dialmgr.hxx>
66 //#include "dlgutil.hxx"
67 //#include "stbctrls.h"
69 //#include <svx/dialogs.hrc>
71 /*#ifndef _UNOTOOLS_LOCALEDATAWRAPPER_HXX
72 #include <unotools/localedatawrapper.hxx>
74 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
75 #include <comphelper/processfactory.hxx>
80 SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl
, SfxUInt16Item
);
82 struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
89 Image maImageNotValidated
;
93 XmlSecStatusBarControl::XmlSecStatusBarControl( USHORT _nSlotId
, USHORT _nId
, StatusBar
& _rStb
)
94 :SfxStatusBarControl( _nSlotId
, _nId
, _rStb
)
96 ,mpImpl( new XmlSecStatusBarControl_Impl
)
98 mpImpl
->mnState
= (UINT16
)SIGNATURESTATE_UNKNOWN
;
100 sal_Bool bIsDark
= GetStatusBar().GetBackground().GetColor().IsDark();
101 mpImpl
->maImage
= Image( SVX_RES( bIsDark
? RID_SVXBMP_SIGNET_H
: RID_SVXBMP_SIGNET
) );
102 mpImpl
->maImageBroken
=
103 Image( SVX_RES( bIsDark
? RID_SVXBMP_SIGNET_BROKEN_H
: RID_SVXBMP_SIGNET_BROKEN
) );
104 mpImpl
->maImageNotValidated
=
105 Image( SVX_RES( bIsDark
? RID_SVXBMP_SIGNET_NOTVALIDATED_H
: RID_SVXBMP_SIGNET_NOTVALIDATED
) );
108 XmlSecStatusBarControl::~XmlSecStatusBarControl()
113 void XmlSecStatusBarControl::StateChanged( USHORT nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
115 GetStatusBar().SetHelpText( GetId(), String() );// necessary ?
117 GetStatusBar().SetHelpId( GetId(), nSID
); // necessary ?
119 if( SFX_ITEM_AVAILABLE
!= eState
)
121 mpImpl
->mnState
= (UINT16
)SIGNATURESTATE_UNKNOWN
;
123 else if( pState
->ISA( SfxUInt16Item
) )
125 // mpImpl->mbSigned = ( ( SfxUInt16Item* ) pState )->GetValue() == 1 /* SIGNED*/ ;
126 mpImpl
->mnState
= ( ( SfxUInt16Item
* ) pState
)->GetValue();
130 DBG_ERRORFILE( "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
131 mpImpl
->mnState
= (UINT16
)SIGNATURESTATE_UNKNOWN
;
134 if( GetStatusBar().AreItemsVisible() ) // necessary ?
135 GetStatusBar().SetItemData( GetId(), 0 );
137 GetStatusBar().SetItemText( GetId(), String() ); // necessary ?
139 USHORT nResId
= RID_SVXSTR_XMLSEC_NO_SIG
;
140 if ( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_OK
)
141 nResId
= RID_SVXSTR_XMLSEC_SIG_OK
;
142 else if ( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_BROKEN
)
143 nResId
= RID_SVXSTR_XMLSEC_SIG_NOT_OK
;
144 else if ( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_NOTVALIDATED
)
145 nResId
= RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY
;
146 else if ( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_PARTIAL_OK
)
147 nResId
= RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG
;
149 GetStatusBar().SetQuickHelpText( GetId(), SVX_RESSTR( nResId
) );
152 void XmlSecStatusBarControl::Command( const CommandEvent
& rCEvt
)
154 if( rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
)
156 PopupMenu
aPopupMenu( ResId( RID_SVXMNU_XMLSECSTATBAR
, DIALOG_MGR() ) );
157 if( aPopupMenu
.Execute( &GetStatusBar(), rCEvt
.GetMousePosPixel() ) )
159 ::com::sun::star::uno::Any a
;
160 SfxUInt16Item
aState( GetSlotId(), 0 );
161 INetURLObject
aObj( m_aCommandURL
);
163 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs( 1 );
164 aArgs
[0].Name
= aObj
.GetURLPath();
165 aState
.QueryValue( a
);
172 SfxStatusBarControl::Command( rCEvt
);
175 void XmlSecStatusBarControl::Paint( const UserDrawEvent
& rUsrEvt
)
177 OutputDevice
* pDev
= rUsrEvt
.GetDevice();
178 DBG_ASSERT( pDev
, "-XmlSecStatusBarControl::Paint(): no Output Device... this will lead to nirvana..." );
179 Rectangle aRect
= rUsrEvt
.GetRect();
180 StatusBar
& rBar
= GetStatusBar();
181 Point aItemPos
= rBar
.GetItemTextPos( GetId() );
182 Color aOldLineColor
= pDev
->GetLineColor();
183 Color aOldFillColor
= pDev
->GetFillColor();
185 pDev
->SetLineColor();
186 pDev
->SetFillColor( pDev
->GetBackground().GetColor() );
188 if( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_OK
)
191 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImage
);
193 else if( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_BROKEN
)
196 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImageBroken
);
198 else if( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_NOTVALIDATED
199 || mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_PARTIAL_OK
)
202 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImageNotValidated
);
205 pDev
->DrawRect( aRect
);
207 pDev
->SetLineColor( aOldLineColor
);
208 pDev
->SetFillColor( aOldFillColor
);
211 long XmlSecStatusBarControl::GetDefItemWidth( StatusBar
& )