1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <tools/shl.hxx>
31 #include <vcl/status.hxx>
32 #include <vcl/menu.hxx>
33 #include <vcl/image.hxx>
34 #include <sfx2/signaturestate.hxx>
35 #include <sfx2/app.hxx>
36 #include <sfx2/module.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <sfx2/objsh.hxx>
39 #include <sfx2/sfxsids.hrc>
41 #include <svl/intitem.hxx>
43 #include <svl/eitem.hxx>
45 #include <svx/dialogs.hrc>
46 #include <svx/dialmgr.hxx>
47 #include "svx/xmlsecctrl.hxx"
48 #include <tools/urlobj.hxx>
50 SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl
, SfxUInt16Item
);
52 struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
59 Image maImageNotValidated
;
63 XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId
, sal_uInt16 _nId
, StatusBar
& _rStb
)
64 :SfxStatusBarControl( _nSlotId
, _nId
, _rStb
)
65 ,mpImpl( new XmlSecStatusBarControl_Impl
)
67 mpImpl
->mnState
= (sal_uInt16
)SIGNATURESTATE_UNKNOWN
;
69 mpImpl
->maImage
= Image( SVX_RES( RID_SVXBMP_SIGNET
) );
70 mpImpl
->maImageBroken
= Image( SVX_RES( RID_SVXBMP_SIGNET_BROKEN
) );
71 mpImpl
->maImageNotValidated
= Image( SVX_RES( RID_SVXBMP_SIGNET_NOTVALIDATED
) );
74 XmlSecStatusBarControl::~XmlSecStatusBarControl()
79 void XmlSecStatusBarControl::StateChanged( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
81 if( SFX_ITEM_AVAILABLE
!= eState
)
83 mpImpl
->mnState
= (sal_uInt16
)SIGNATURESTATE_UNKNOWN
;
85 else if( pState
->ISA( SfxUInt16Item
) )
87 mpImpl
->mnState
= ( ( SfxUInt16Item
* ) pState
)->GetValue();
91 SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
92 mpImpl
->mnState
= (sal_uInt16
)SIGNATURESTATE_UNKNOWN
;
95 if( GetStatusBar().AreItemsVisible() ) // necessary ?
96 GetStatusBar().SetItemData( GetId(), 0 );
98 GetStatusBar().SetItemText( GetId(), String() ); // necessary ?
100 sal_uInt16 nResId
= RID_SVXSTR_XMLSEC_NO_SIG
;
101 if ( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_OK
)
102 nResId
= RID_SVXSTR_XMLSEC_SIG_OK
;
103 else if ( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_BROKEN
)
104 nResId
= RID_SVXSTR_XMLSEC_SIG_NOT_OK
;
105 else if ( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_NOTVALIDATED
)
106 nResId
= RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY
;
107 else if ( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_PARTIAL_OK
)
108 nResId
= RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG
;
110 GetStatusBar().SetQuickHelpText( GetId(), SVX_RESSTR( nResId
) );
113 void XmlSecStatusBarControl::Command( const CommandEvent
& rCEvt
)
115 if( rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
)
117 PopupMenu
aPopupMenu( ResId( RID_SVXMNU_XMLSECSTATBAR
, DIALOG_MGR() ) );
118 if( aPopupMenu
.Execute( &GetStatusBar(), rCEvt
.GetMousePosPixel() ) )
120 ::com::sun::star::uno::Any a
;
121 SfxUInt16Item
aState( GetSlotId(), 0 );
122 INetURLObject
aObj( m_aCommandURL
);
124 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs( 1 );
125 aArgs
[0].Name
= aObj
.GetURLPath();
126 aState
.QueryValue( a
);
133 SfxStatusBarControl::Command( rCEvt
);
136 void XmlSecStatusBarControl::Paint( const UserDrawEvent
& rUsrEvt
)
138 OutputDevice
* pDev
= rUsrEvt
.GetDevice();
139 DBG_ASSERT( pDev
, "-XmlSecStatusBarControl::Paint(): no Output Device... this will lead to nirvana..." );
140 Rectangle aRect
= rUsrEvt
.GetRect();
141 Color aOldLineColor
= pDev
->GetLineColor();
142 Color aOldFillColor
= pDev
->GetFillColor();
144 pDev
->SetLineColor();
145 pDev
->SetFillColor( pDev
->GetBackground().GetColor() );
147 if( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_OK
)
150 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImage
);
152 else if( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_BROKEN
)
155 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImageBroken
);
157 else if( mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_NOTVALIDATED
158 || mpImpl
->mnState
== SIGNATURESTATE_SIGNATURES_PARTIAL_OK
)
161 pDev
->DrawImage( aRect
.TopLeft(), mpImpl
->maImageNotValidated
);
164 pDev
->DrawRect( aRect
);
166 pDev
->SetLineColor( aOldLineColor
);
167 pDev
->SetFillColor( aOldFillColor
);
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */