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_xmlsecurity.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/app.hxx>
44 #include <sfx2/module.hxx>
45 #include <sfx2/dispatch.hxx>
46 #include <sfx2/objsh.hxx>
47 
48 #include <svl/eitem.hxx>
49 
50 
51 #include <xmlsecurity/stbcontrl.hxx>
52 
53 #define PAINT_OFFSET	5
54 
55 //#include "sizeitem.hxx"
56 //#include "dialmgr.hxx"
57 //#include "dlgutil.hxx"
58 //#include "stbctrls.h"
59 
60 //#include "dialogs.hrc"
61 
62 /*#ifndef _UNOTOOLS_LOCALEDATAWRAPPER_HXX
63 #include <unotools/localedatawrapper.hxx>
64 #endif
65 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
66 #include <comphelper/processfactory.hxx>
67 #endif*/
68 
69 
70 
71 SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxBoolItem );
72 
73 /*
74 class FunctionPopup_Impl : public PopupMenu
75 {
76 public:
77 	FunctionPopup_Impl( sal_uInt16 nCheck );
78 
79 	sal_uInt16			GetSelected() const { return nSelected; }
80 
81 private:
82 	sal_uInt16			nSelected;
83 
84 	virtual void    Select();
85 };
86 
87 // -----------------------------------------------------------------------
88 
89 FunctionPopup_Impl::FunctionPopup_Impl( sal_uInt16 nCheck ) :
90 	PopupMenu( ResId( RID_SVXMNU_PSZ_FUNC, DIALOG_MGR() ) ),
91 	nSelected( 0 )
92 {
93 	if (nCheck)
94 		CheckItem( nCheck );
95 }
96 
97 // -----------------------------------------------------------------------
98 
99 void FunctionPopup_Impl::Select()
100 {
101 	nSelected = GetCurItemId();
102 }
103 */
104 
105 
106 
107 struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
108 {
109 	Point		maPos;
110 	Size		maSize;
111 	bool		mbSigned;
112 	Image		maImage;
113 };
114 
115 
116 XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nId, StatusBar& _rStb, SfxBindings& _rBind )
117 	:SfxStatusBarControl( _nId, _rStb, _rBind )
118 
119 	,mpImpl( new XmlSecStatusBarControl_Impl )
120 {
121 	mpImpl->mbSigned = false;
122 //	pImp->maImage = Image( ResId( RID_SVXBMP_POSITION, DIALOG_MGR() ) );
123 }
124 
125 XmlSecStatusBarControl::~XmlSecStatusBarControl()
126 {
127 	delete mpImpl;
128 }
129 
130 void XmlSecStatusBarControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
131 {
132 	GetStatusBar().SetHelpText( GetId(), String() );	// necessary ?
133 	GetStatusBar().SetHelpId( GetId(), nSID );			// necessary ?
134 
135 	if( SFX_ITEM_AVAILABLE != eState )
136 	{
137 		mpImpl->mbSigned = false;
138 	}
139 	else if( pState->ISA( SfxBoolItem ) )
140 	{
141 		mpImpl->mbSigned = ( ( SfxBoolItem* ) pState )->GetValue();
142 	}
143 	else
144 	{
145 		DBG_ERRORFILE( "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
146 		mpImpl->mbSigned = false;
147 	}
148 
149 	if( GetStatusBar().AreItemsVisible() )				// necessary ?
150 		GetStatusBar().SetItemData( GetId(), 0 );
151 
152 	GetStatusBar().SetItemText( GetId(), String() );	// necessary ?
153 }
154 
155 void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt )
156 {
157 	// can / has to be done when integrated in Office!
158 //	if( rCEvt.GetCommand() == .... )
159 	if( false )
160 	{
161 //		GetBindings().GetDispatcher()->Execute( SID_PSZ_FUNCTION, SFX_CALLMODE_RECORD, &aItem, 0L );
162 	}
163 	else
164 		SfxStatusBarControl::Command( rCEvt );
165 }
166 
167 void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt )
168 {
169 	OutputDevice*		pDev = rUsrEvt.GetDevice();
170 	DBG_ASSERT( pDev, "-XmlSecStatusBarControl::Paint(): no Output Device... this will lead to nirvana..." );
171 	const Rectangle&	rRect = rUsrEvt.GetRect();
172 	StatusBar&			rBar = GetStatusBar();
173 	Point				aItemPos = rBar.GetItemTextPos( GetId() );
174 	Color				aOldLineColor = pDev->GetLineColor();
175 	Color				aOldFillColor = pDev->GetFillColor();
176 
177 	// just 4 testing until we've got a bitmap
178 	pDev->SetLineColor();
179 	pDev->SetFillColor( pDev->GetBackground().GetColor() );
180 
181 	String				s( String::CreateFromAscii( mpImpl->mbSigned? "X" : "-" ) );
182 	pDev->DrawRect( rRect );
183 	pDev->DrawText( Point( rRect.Left() + rRect.GetWidth() / 2 - pDev->GetTextWidth( s ) / 2, aItemPos.Y() ), s );
184 
185 	pDev->SetLineColor( aOldLineColor );
186 	pDev->SetFillColor( aOldFillColor );
187 }
188 
189