LCOV - code coverage report
Current view: top level - svx/source/stbctrls - xmlsecctrl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 43 79 54.4 %
Date: 2014-11-03 Functions: 11 12 91.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <vcl/status.hxx>
      22             : #include <vcl/menu.hxx>
      23             : #include <vcl/image.hxx>
      24             : #include <sfx2/signaturestate.hxx>
      25             : #include <sfx2/app.hxx>
      26             : #include <sfx2/module.hxx>
      27             : #include <sfx2/dispatch.hxx>
      28             : #include <sfx2/objsh.hxx>
      29             : #include <sfx2/sfxsids.hrc>
      30             : 
      31             : #include <svl/intitem.hxx>
      32             : 
      33             : #include <svl/eitem.hxx>
      34             : 
      35             : #include <svx/dialogs.hrc>
      36             : #include <svx/dialmgr.hxx>
      37             : #include "svx/xmlsecctrl.hxx"
      38             : #include <tools/urlobj.hxx>
      39             : 
      40        1688 : SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxUInt16Item );
      41             : 
      42        2928 : struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
      43             : {
      44             :     Point       maPos;
      45             :     Size        maSize;
      46             :     sal_uInt16      mnState;
      47             :     Image       maImage;
      48             :     Image       maImageBroken;
      49             :     Image       maImageNotValidated;
      50             : };
      51             : 
      52             : 
      53        1464 : XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId,  sal_uInt16 _nId, StatusBar& _rStb )
      54             :     :SfxStatusBarControl( _nSlotId, _nId, _rStb )
      55        1464 :     ,mpImpl( new XmlSecStatusBarControl_Impl )
      56             : {
      57        1464 :     mpImpl->mnState = (sal_uInt16)SIGNATURESTATE_UNKNOWN;
      58             : 
      59        1464 :     mpImpl->maImage             = Image( SVX_RES( RID_SVXBMP_SIGNET              ) );
      60        1464 :     mpImpl->maImageBroken       = Image( SVX_RES( RID_SVXBMP_SIGNET_BROKEN       ) );
      61        1464 :     mpImpl->maImageNotValidated = Image( SVX_RES( RID_SVXBMP_SIGNET_NOTVALIDATED ) );
      62             : 
      63        1464 :     if (_rStb.GetDPIScaleFactor() > 1)
      64             :     {
      65           0 :         Image arr[3] = {mpImpl->maImage, mpImpl->maImageBroken, mpImpl->maImageNotValidated};
      66             : 
      67           0 :         for (int i = 0; i < 3; i++)
      68             :         {
      69           0 :             BitmapEx b = arr[i].GetBitmapEx();
      70           0 :             b.Scale(_rStb.GetDPIScaleFactor(), _rStb.GetDPIScaleFactor(), BMP_SCALE_FAST);
      71           0 :             arr[i] = Image(b);
      72           0 :         }
      73             : 
      74           0 :         mpImpl->maImage = arr[0];
      75           0 :         mpImpl->maImageBroken = arr[1];
      76           0 :         mpImpl->maImageNotValidated = arr[2];
      77             :     }
      78             : 
      79        1464 : }
      80             : 
      81        4392 : XmlSecStatusBarControl::~XmlSecStatusBarControl()
      82             : {
      83        1464 :     delete mpImpl;
      84        2928 : }
      85             : 
      86        1721 : void XmlSecStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
      87             : {
      88        1721 :     if( SfxItemState::DEFAULT != eState )
      89             :     {
      90           0 :         mpImpl->mnState = (sal_uInt16)SIGNATURESTATE_UNKNOWN;
      91             :     }
      92        1721 :     else if( pState->ISA( SfxUInt16Item ) )
      93             :     {
      94        1721 :         mpImpl->mnState = static_cast<const SfxUInt16Item*>(pState)->GetValue();
      95             :     }
      96             :     else
      97             :     {
      98             :         SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
      99           0 :         mpImpl->mnState = (sal_uInt16)SIGNATURESTATE_UNKNOWN;
     100             :     }
     101             : 
     102        1721 :     if( GetStatusBar().AreItemsVisible() )              // necessary ?
     103        1721 :         GetStatusBar().SetItemData( GetId(), 0 );
     104             : 
     105        1721 :     GetStatusBar().SetItemText( GetId(), "" );    // necessary ?
     106             : 
     107        1721 :     sal_uInt16 nResId = RID_SVXSTR_XMLSEC_NO_SIG;
     108        1721 :     if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_OK )
     109           0 :         nResId = RID_SVXSTR_XMLSEC_SIG_OK;
     110        1721 :     else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_BROKEN )
     111           0 :         nResId = RID_SVXSTR_XMLSEC_SIG_NOT_OK;
     112        1721 :     else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
     113           0 :         nResId = RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY;
     114        1721 :     else if ( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK )
     115           0 :         nResId = RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG;
     116             : 
     117        1721 :     GetStatusBar().SetQuickHelpText( GetId(), SVX_RESSTR( nResId ) );
     118        1721 : }
     119             : 
     120           0 : void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt )
     121             : {
     122           0 :     if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
     123             :     {
     124           0 :         PopupMenu aPopupMenu( ResId( RID_SVXMNU_XMLSECSTATBAR, DIALOG_MGR() ) );
     125           0 :         if( aPopupMenu.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel() ) )
     126             :         {
     127           0 :             ::com::sun::star::uno::Any a;
     128           0 :             SfxUInt16Item aState( GetSlotId(), 0 );
     129           0 :             INetURLObject aObj( m_aCommandURL );
     130             : 
     131           0 :             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
     132           0 :             aArgs[0].Name  = aObj.GetURLPath();
     133           0 :             aState.QueryValue( a );
     134           0 :             aArgs[0].Value = a;
     135             : 
     136           0 :             execute( aArgs );
     137           0 :         }
     138             :     }
     139             :     else
     140           0 :         SfxStatusBarControl::Command( rCEvt );
     141           0 : }
     142             : 
     143        2086 : void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt )
     144             : {
     145        2086 :     OutputDevice*       pDev = rUsrEvt.GetDevice();
     146             :     DBG_ASSERT( pDev, "-XmlSecStatusBarControl::Paint(): no Output Device... this will lead to nirvana..." );
     147        2086 :     Rectangle           aRect = rUsrEvt.GetRect();
     148        2086 :     Color               aOldLineColor = pDev->GetLineColor();
     149        2086 :     Color               aOldFillColor = pDev->GetFillColor();
     150             : 
     151        2086 :     pDev->SetLineColor();
     152        2086 :     pDev->SetFillColor( pDev->GetBackground().GetColor() );
     153             : 
     154        2086 :     long yOffset = (aRect.GetHeight() - mpImpl->maImage.GetSizePixel().Height()) / 2;
     155             : 
     156        2086 :     if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_OK )
     157             :     {
     158           0 :         aRect.Top() += yOffset;
     159           0 :         pDev->DrawImage( aRect.TopLeft(), mpImpl->maImage );
     160             :     }
     161        2086 :     else if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_BROKEN )
     162             :     {
     163           0 :         aRect.Top() += yOffset;
     164           0 :         pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageBroken );
     165             :     }
     166        2086 :     else if( mpImpl->mnState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED
     167        2086 :         || mpImpl->mnState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK)
     168             :     {
     169           0 :         aRect.Top() += yOffset;
     170           0 :         pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageNotValidated );
     171             :     }
     172             :     else
     173        2086 :         pDev->DrawRect( aRect );
     174             : 
     175        2086 :     pDev->SetLineColor( aOldLineColor );
     176        2086 :     pDev->SetFillColor( aOldFillColor );
     177        2680 : }
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10