xref: /aoo41x/main/svx/source/stbctrls/xmlsecctrl.cxx (revision f6e50924)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir #include <tools/shl.hxx>
29cdf0e10cSrcweir #ifndef _STATUS_HXX //autogen
30cdf0e10cSrcweir #include <vcl/status.hxx>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #ifndef _MENU_HXX //autogen
33cdf0e10cSrcweir #include <vcl/menu.hxx>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #include <vcl/image.hxx>
36cdf0e10cSrcweir //#ifndef _SFXITEMPOOL_HXX
37cdf0e10cSrcweir //#include <svl/itempool.hxx>
38cdf0e10cSrcweir //#endif
39cdf0e10cSrcweir #include <sfx2/signaturestate.hxx>
40cdf0e10cSrcweir #include <sfx2/app.hxx>
41cdf0e10cSrcweir #include <sfx2/module.hxx>
42cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
43cdf0e10cSrcweir #include <sfx2/objsh.hxx>
44cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <svl/intitem.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <svl/eitem.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include <svx/dialogs.hrc>
51cdf0e10cSrcweir #include <svx/dialmgr.hxx>
52cdf0e10cSrcweir #include "svx/xmlsecctrl.hxx"
53cdf0e10cSrcweir #include <tools/urlobj.hxx>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #define PAINT_OFFSET	5
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //#include <editeng/sizeitem.hxx>
58cdf0e10cSrcweir //#include <svx/dialmgr.hxx>
59cdf0e10cSrcweir //#include "svx/dlgutil.hxx"
60cdf0e10cSrcweir //#include "stbctrls.h"
61cdf0e10cSrcweir 
62cdf0e10cSrcweir //#include <svx/dialogs.hrc>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir /*#ifndef _UNOTOOLS_LOCALEDATAWRAPPER_HXX
65cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
66cdf0e10cSrcweir #endif
67cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
68cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
69cdf0e10cSrcweir #endif*/
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxUInt16Item );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	Point		maPos;
78cdf0e10cSrcweir 	Size		maSize;
79cdf0e10cSrcweir 	sal_uInt16		mnState;
80cdf0e10cSrcweir 	Image		maImage;
81cdf0e10cSrcweir     Image       maImageBroken;
82cdf0e10cSrcweir     Image       maImageNotValidated;
83cdf0e10cSrcweir };
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
XmlSecStatusBarControl(sal_uInt16 _nSlotId,sal_uInt16 _nId,StatusBar & _rStb)86cdf0e10cSrcweir XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId,  sal_uInt16 _nId, StatusBar& _rStb )
87cdf0e10cSrcweir     :SfxStatusBarControl( _nSlotId, _nId, _rStb )
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	,mpImpl( new XmlSecStatusBarControl_Impl )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	mpImpl->mnState = (sal_uInt16)SIGNATURESTATE_UNKNOWN;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     sal_Bool bHC = GetStatusBar().GetSettings().GetStyleSettings().GetHighContrastMode();
94cdf0e10cSrcweir     mpImpl->maImage = Image( SVX_RES( bHC ? RID_SVXBMP_SIGNET_H : RID_SVXBMP_SIGNET ) );
95cdf0e10cSrcweir     mpImpl->maImageBroken =
96cdf0e10cSrcweir         Image( SVX_RES( bHC ? RID_SVXBMP_SIGNET_BROKEN_H : RID_SVXBMP_SIGNET_BROKEN ) );
97cdf0e10cSrcweir     mpImpl->maImageNotValidated =
98cdf0e10cSrcweir         Image( SVX_RES( bHC ? RID_SVXBMP_SIGNET_NOTVALIDATED_H : RID_SVXBMP_SIGNET_NOTVALIDATED ) );
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
~XmlSecStatusBarControl()101cdf0e10cSrcweir XmlSecStatusBarControl::~XmlSecStatusBarControl()
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	delete mpImpl;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)106cdf0e10cSrcweir void XmlSecStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	if( SFX_ITEM_AVAILABLE != eState )
109cdf0e10cSrcweir 	{
110cdf0e10cSrcweir 		mpImpl->mnState = (sal_uInt16)SIGNATURESTATE_UNKNOWN;
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir 	else if( pState->ISA( SfxUInt16Item ) )
113cdf0e10cSrcweir 	{
114cdf0e10cSrcweir //		mpImpl->mbSigned = ( ( SfxUInt16Item* ) pState )->GetValue() == 1 /* SIGNED*/ ;
115cdf0e10cSrcweir 		mpImpl->mnState = ( ( SfxUInt16Item* ) pState )->GetValue();
116cdf0e10cSrcweir 	}
117cdf0e10cSrcweir 	else
118cdf0e10cSrcweir 	{
119cdf0e10cSrcweir 		DBG_ERRORFILE( "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
120cdf0e10cSrcweir 		mpImpl->mnState = (sal_uInt16)SIGNATURESTATE_UNKNOWN;
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	if( GetStatusBar().AreItemsVisible() )				// necessary ?
124cdf0e10cSrcweir 		GetStatusBar().SetItemData( GetId(), 0 );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     GetStatusBar().SetItemText( GetId(), String() );    // necessary ?
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     sal_uInt16 nResId = RID_SVXSTR_XMLSEC_NO_SIG;
129cdf0e10cSrcweir     if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_OK )
130cdf0e10cSrcweir         nResId = RID_SVXSTR_XMLSEC_SIG_OK;
131cdf0e10cSrcweir     else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_BROKEN )
132cdf0e10cSrcweir         nResId = RID_SVXSTR_XMLSEC_SIG_NOT_OK;
133cdf0e10cSrcweir     else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
134cdf0e10cSrcweir         nResId = RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY;
135cdf0e10cSrcweir     else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK )
136cdf0e10cSrcweir         nResId = RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     GetStatusBar().SetQuickHelpText( GetId(), SVX_RESSTR( nResId ) );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
Command(const CommandEvent & rCEvt)141cdf0e10cSrcweir void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
144cdf0e10cSrcweir 	{
145cdf0e10cSrcweir 		PopupMenu aPopupMenu( ResId( RID_SVXMNU_XMLSECSTATBAR, DIALOG_MGR() ) );
146cdf0e10cSrcweir 		if( aPopupMenu.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel() ) )
147cdf0e10cSrcweir 		{
148cdf0e10cSrcweir             ::com::sun::star::uno::Any a;
149cdf0e10cSrcweir             SfxUInt16Item aState( GetSlotId(), 0 );
150cdf0e10cSrcweir             INetURLObject aObj( m_aCommandURL );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
153cdf0e10cSrcweir             aArgs[0].Name  = aObj.GetURLPath();
154cdf0e10cSrcweir             aState.QueryValue( a );
155cdf0e10cSrcweir             aArgs[0].Value = a;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir             execute( aArgs );
158cdf0e10cSrcweir 		}
159cdf0e10cSrcweir 	}
160cdf0e10cSrcweir 	else
161cdf0e10cSrcweir 		SfxStatusBarControl::Command( rCEvt );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
Paint(const UserDrawEvent & rUsrEvt)164cdf0e10cSrcweir void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir 	OutputDevice*		pDev = rUsrEvt.GetDevice();
167cdf0e10cSrcweir 	DBG_ASSERT( pDev, "-XmlSecStatusBarControl::Paint(): no Output Device... this will lead to nirvana..." );
168cdf0e10cSrcweir 	Rectangle			aRect = rUsrEvt.GetRect();
169cdf0e10cSrcweir 	StatusBar&			rBar = GetStatusBar();
170cdf0e10cSrcweir 	Point				aItemPos = rBar.GetItemTextPos( GetId() );
171cdf0e10cSrcweir 	Color				aOldLineColor = pDev->GetLineColor();
172cdf0e10cSrcweir 	Color				aOldFillColor = pDev->GetFillColor();
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	pDev->SetLineColor();
175cdf0e10cSrcweir 	pDev->SetFillColor( pDev->GetBackground().GetColor() );
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_OK )
178cdf0e10cSrcweir 	{
179cdf0e10cSrcweir 		++aRect.Top();
180cdf0e10cSrcweir 		pDev->DrawImage( aRect.TopLeft(), mpImpl->maImage );
181cdf0e10cSrcweir 	}
182cdf0e10cSrcweir     else if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_BROKEN )
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         ++aRect.Top();
185cdf0e10cSrcweir         pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageBroken );
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir     else if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED
188cdf0e10cSrcweir         || mpImpl->mnState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK)
189cdf0e10cSrcweir     {
190cdf0e10cSrcweir         ++aRect.Top();
191cdf0e10cSrcweir         pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageNotValidated );
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir 	else
194cdf0e10cSrcweir 		pDev->DrawRect( aRect );
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 	pDev->SetLineColor( aOldLineColor );
197cdf0e10cSrcweir 	pDev->SetFillColor( aOldFillColor );
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
GetDefItemWidth(StatusBar &)200cdf0e10cSrcweir long XmlSecStatusBarControl::GetDefItemWidth( StatusBar& )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir 	return 16;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205