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