Files
loongoffice/svx/source/stbctrls/xmlsecctrl.cxx
2004-09-13 07:47:04 +00:00

232 lines
7.0 KiB
C++

/*************************************************************************
*
* $RCSfile: xmlsecctrl.cxx,v $
*
* $Revision: 1.3 $
*
* last change: $Author: obo $ $Date: 2004-09-13 08:43:49 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc..
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
// include ---------------------------------------------------------------
#ifndef _SHL_HXX //autogen
#include <tools/shl.hxx>
#endif
#ifndef _STATUS_HXX //autogen
#include <vcl/status.hxx>
#endif
#ifndef _MENU_HXX //autogen
#include <vcl/menu.hxx>
#endif
#ifndef _SV_IMAGE_HXX
#include <vcl/image.hxx>
#endif
//#ifndef _SFXITEMPOOL_HXX
//#include <svtools/itempool.hxx>
//#endif
#ifndef _SFXAPP_HXX
#include <sfx2/app.hxx>
#endif
#ifndef _SFXMODULE_HXX
#include <sfx2/module.hxx>
#endif
#ifndef _SFXDISPATCH_HXX //autogen
#include <sfx2/dispatch.hxx>
#endif
#ifndef _SFX_OBJSH_HXX //autogen
#include <sfx2/objsh.hxx>
#endif
#ifndef _SFXSIDS_HRC
#include <sfx2/sfxsids.hrc>
#endif
#include <svtools/intitem.hxx>
#include <svtools/eitem.hxx>
#include "dialogs.hrc"
#include "dialmgr.hxx"
#include "xmlsecctrl.hxx"
#include <tools/urlobj.hxx>
#define PAINT_OFFSET 5
//#include "sizeitem.hxx"
//#include "dialmgr.hxx"
//#include "dlgutil.hxx"
//#include "stbctrls.h"
//#include "dialogs.hrc"
/*#ifndef _UNOTOOLS_LOCALEDATAWRAPPER_HXX
#include <unotools/localedatawrapper.hxx>
#endif
#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
#include <comphelper/processfactory.hxx>
#endif*/
SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxUInt16Item );
struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
{
Point maPos;
Size maSize;
UINT16 mnState;
Image maImage;
Image maImageBroken;
};
XmlSecStatusBarControl::XmlSecStatusBarControl( USHORT _nSlotId, USHORT _nId, StatusBar& _rStb )
:SfxStatusBarControl( _nSlotId, _nId, _rStb )
,mpImpl( new XmlSecStatusBarControl_Impl )
{
mpImpl->mnState = SIGNATURESTATE_UNKNOWN;
mpImpl->maImage = Image( ResId( RID_SVXBMP_SIGNET, DIALOG_MGR() ) );
mpImpl->maImageBroken = Image( ResId( RID_SVXBMP_SIGNET_BROKEN, DIALOG_MGR() ) );
}
XmlSecStatusBarControl::~XmlSecStatusBarControl()
{
delete mpImpl;
}
void XmlSecStatusBarControl::StateChanged( USHORT nSID, SfxItemState eState, const SfxPoolItem* pState )
{
GetStatusBar().SetHelpText( GetId(), String() ); // necessary ?
GetStatusBar().SetHelpId( GetId(), nSID ); // necessary ?
if( SFX_ITEM_AVAILABLE != eState )
{
mpImpl->mnState = SIGNATURESTATE_UNKNOWN;
}
else if( pState->ISA( SfxUInt16Item ) )
{
// mpImpl->mbSigned = ( ( SfxUInt16Item* ) pState )->GetValue() == 1 /* SIGNED*/ ;
mpImpl->mnState = ( ( SfxUInt16Item* ) pState )->GetValue();
}
else
{
DBG_ERRORFILE( "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
mpImpl->mnState = SIGNATURESTATE_UNKNOWN;
}
if( GetStatusBar().AreItemsVisible() ) // necessary ?
GetStatusBar().SetItemData( GetId(), 0 );
GetStatusBar().SetItemText( GetId(), String() ); // necessary ?
}
void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt )
{
if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
{
PopupMenu aPopupMenu( ResId( RID_SVXMNU_XMLSECSTATBAR, DIALOG_MGR() ) );
if( aPopupMenu.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel() ) )
{
::com::sun::star::uno::Any a;
SfxUInt16Item aState( GetSlotId(), 0 );
INetURLObject aObj( m_aCommandURL );
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
aArgs[0].Name = aObj.GetURLPath();
aState.QueryValue( a );
aArgs[0].Value = a;
execute( aArgs );
}
}
else
SfxStatusBarControl::Command( rCEvt );
}
void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt )
{
OutputDevice* pDev = rUsrEvt.GetDevice();
DBG_ASSERT( pDev, "-XmlSecStatusBarControl::Paint(): no Output Device... this will lead to nirvana..." );
Rectangle aRect = rUsrEvt.GetRect();
StatusBar& rBar = GetStatusBar();
Point aItemPos = rBar.GetItemTextPos( GetId() );
Color aOldLineColor = pDev->GetLineColor();
Color aOldFillColor = pDev->GetFillColor();
pDev->SetLineColor();
pDev->SetFillColor( pDev->GetBackground().GetColor() );
if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_OK )
{
++aRect.Top();
pDev->DrawImage( aRect.TopLeft(), mpImpl->maImage );
}
else if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_BROKEN )
{
++aRect.Top();
pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageBroken );
}
else
pDev->DrawRect( aRect );
pDev->SetLineColor( aOldLineColor );
pDev->SetFillColor( aOldFillColor );
}
long XmlSecStatusBarControl::GetDefItemWidth( StatusBar& _rStatusBar )
{
return 16;
}