LCOV - code coverage report
Current view: top level - svx/source/stbctrls - xmlsecctrl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 43 79 54.4 %
Date: 2015-06-13 12:38:46 Functions: 9 10 90.0 %
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         734 : SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxUInt16Item );
      41             : 
      42        1176 : struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
      43             : {
      44             :     Point       maPos;
      45             :     Size        maSize;
      46             :     SignatureState  mnState;
      47             :     Image       maImage;
      48             :     Image       maImageBroken;
      49             :     Image       maImageNotValidated;
      50             : };
      51             : 
      52             : 
      53         588 : XmlSecStatusBarControl::XmlSecStatusBarControl( sal_uInt16 _nSlotId,  sal_uInt16 _nId, StatusBar& _rStb )
      54             :     :SfxStatusBarControl( _nSlotId, _nId, _rStb )
      55         588 :     ,mpImpl( new XmlSecStatusBarControl_Impl )
      56             : {
      57         588 :     mpImpl->mnState = SignatureState::UNKNOWN;
      58             : 
      59         588 :     mpImpl->maImage             = Image( SVX_RES( RID_SVXBMP_SIGNET              ) );
      60         588 :     mpImpl->maImageBroken       = Image( SVX_RES( RID_SVXBMP_SIGNET_BROKEN       ) );
      61         588 :     mpImpl->maImageNotValidated = Image( SVX_RES( RID_SVXBMP_SIGNET_NOTVALIDATED ) );
      62             : 
      63         588 :     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(), BmpScaleFlag::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         588 : }
      80             : 
      81        1764 : XmlSecStatusBarControl::~XmlSecStatusBarControl()
      82             : {
      83         588 :     delete mpImpl;
      84        1176 : }
      85             : 
      86         994 : void XmlSecStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
      87             : {
      88         994 :     if( SfxItemState::DEFAULT != eState )
      89             :     {
      90           0 :         mpImpl->mnState = SignatureState::UNKNOWN;
      91             :     }
      92         994 :     else if( pState->ISA( SfxUInt16Item ) )
      93             :     {
      94         994 :         mpImpl->mnState = static_cast<SignatureState>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
      95             :     }
      96             :     else
      97             :     {
      98             :         SAL_WARN( "svx.stbcrtls", "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
      99           0 :         mpImpl->mnState = SignatureState::UNKNOWN;
     100             :     }
     101             : 
     102         994 :     if( GetStatusBar().AreItemsVisible() )              // necessary ?
     103         994 :         GetStatusBar().SetItemData( GetId(), 0 );
     104             : 
     105         994 :     GetStatusBar().SetItemText( GetId(), "" );    // necessary ?
     106             : 
     107         994 :     sal_uInt16 nResId = RID_SVXSTR_XMLSEC_NO_SIG;
     108         994 :     if ( mpImpl->mnState == SignatureState::OK )
     109           0 :         nResId = RID_SVXSTR_XMLSEC_SIG_OK;
     110         994 :     else if ( mpImpl->mnState == SignatureState::BROKEN )
     111           0 :         nResId = RID_SVXSTR_XMLSEC_SIG_NOT_OK;
     112         994 :     else if ( mpImpl->mnState == SignatureState::NOTVALIDATED )
     113           0 :         nResId = RID_SVXSTR_XMLSEC_SIG_OK_NO_VERIFY;
     114         994 :     else if ( mpImpl->mnState == SignatureState::PARTIAL_OK )
     115           0 :         nResId = RID_SVXSTR_XMLSEC_SIG_CERT_OK_PARTIAL_SIG;
     116             : 
     117         994 :     GetStatusBar().SetQuickHelpText( GetId(), SVX_RESSTR( nResId ) );
     118         994 : }
     119             : 
     120           0 : void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt )
     121             : {
     122           0 :     if( rCEvt.GetCommand() == CommandEventId::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        4085 : void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt )
     144             : {
     145        4085 :     OutputDevice*       pDev = rUsrEvt.GetDevice();
     146             :     DBG_ASSERT( pDev, "-XmlSecStatusBarControl::Paint(): no Output Device... this will lead to nirvana..." );
     147        4085 :     Rectangle           aRect = rUsrEvt.GetRect();
     148        4085 :     Color               aOldLineColor = pDev->GetLineColor();
     149        4085 :     Color               aOldFillColor = pDev->GetFillColor();
     150             : 
     151        4085 :     pDev->SetLineColor();
     152        4085 :     pDev->SetFillColor( pDev->GetBackground().GetColor() );
     153             : 
     154        4085 :     long yOffset = (aRect.GetHeight() - mpImpl->maImage.GetSizePixel().Height()) / 2;
     155             : 
     156        4085 :     if( mpImpl->mnState == SignatureState::OK )
     157             :     {
     158           0 :         aRect.Top() += yOffset;
     159           0 :         pDev->DrawImage( aRect.TopLeft(), mpImpl->maImage );
     160             :     }
     161        4085 :     else if( mpImpl->mnState == SignatureState::BROKEN )
     162             :     {
     163           0 :         aRect.Top() += yOffset;
     164           0 :         pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageBroken );
     165             :     }
     166        4085 :     else if( mpImpl->mnState == SignatureState::NOTVALIDATED
     167        4085 :         || mpImpl->mnState == SignatureState::PARTIAL_OK)
     168             :     {
     169           0 :         aRect.Top() += yOffset;
     170           0 :         pDev->DrawImage( aRect.TopLeft(), mpImpl->maImageNotValidated );
     171             :     }
     172             :     else
     173        4085 :         pDev->DrawRect( aRect );
     174             : 
     175        4085 :     pDev->SetLineColor( aOldLineColor );
     176        4085 :     pDev->SetFillColor( aOldFillColor );
     177        4085 : }
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11