LCOV - code coverage report
Current view: top level - svx/source/stbctrls - modctrl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 46 62 74.2 %
Date: 2015-06-13 12:38:46 Functions: 9 12 75.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             : #include <vcl/status.hxx>
      21             : #include <vcl/image.hxx>
      22             : #include <vcl/timer.hxx>
      23             : #include <vcl/idle.hxx>
      24             : #include <svl/eitem.hxx>
      25             : #include <sfx2/app.hxx>
      26             : 
      27             : #include <svx/dialogs.hrc>
      28             : #include <svx/modctrl.hxx>
      29             : #include <svx/dialmgr.hxx>
      30             : 
      31             : #include <com/sun/star/beans/PropertyValue.hpp>
      32             : #include "modctrl_internal.hxx"
      33             : 
      34             : using ::com::sun::star::uno::Sequence;
      35             : using ::com::sun::star::beans::PropertyValue;
      36             : 
      37         748 : SFX_IMPL_STATUSBAR_CONTROL(SvxModifyControl, SfxBoolItem);
      38             : 
      39         588 : struct SvxModifyControl::ImplData
      40             : {
      41             :     enum ModificationState
      42             :     {
      43             :         MODIFICATION_STATE_NO = 0,
      44             :         MODIFICATION_STATE_YES,
      45             :         MODIFICATION_STATE_FEEDBACK,
      46             :         MODIFICATION_STATE_SIZE
      47             :     };
      48             : 
      49             :     Idle  maIdle;
      50             :     Image maImages[MODIFICATION_STATE_SIZE];
      51             : 
      52             :     ModificationState mnModState;
      53             : 
      54         588 :     ImplData():
      55         588 :         mnModState(MODIFICATION_STATE_NO)
      56             :     {
      57         588 :         maImages[MODIFICATION_STATE_NO]       = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_NO));
      58         588 :         maImages[MODIFICATION_STATE_YES]      = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_YES));
      59         588 :         maImages[MODIFICATION_STATE_FEEDBACK] = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_FEEDBACK));
      60             : 
      61         588 :         maIdle.SetPriority(SchedulerPriority::LOWEST);
      62         588 :     }
      63             : };
      64             : 
      65         588 : SvxModifyControl::SvxModifyControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb ) :
      66             :     SfxStatusBarControl( _nSlotId, _nId, rStb ),
      67         588 :     mxImpl(new ImplData)
      68             : {
      69             : //#ifndef MACOSX
      70         588 :     if ( rStb.GetDPIScaleFactor() > 1 )
      71             :     {
      72           0 :         for (int i = 0; i < mxImpl->MODIFICATION_STATE_SIZE; i++)
      73             :         {
      74           0 :             BitmapEx b = mxImpl->maImages[i].GetBitmapEx();
      75           0 :             b.Scale(rStb.GetDPIScaleFactor(), rStb.GetDPIScaleFactor(), BmpScaleFlag::Fast);
      76           0 :             mxImpl->maImages[i] = Image(b);
      77           0 :         }
      78             :     }
      79             : //#endif
      80         588 :     mxImpl->maIdle.SetIdleHdl( LINK(this, SvxModifyControl, OnTimer) );
      81         588 : }
      82             : 
      83             : 
      84             : 
      85        1033 : void SvxModifyControl::StateChanged( sal_uInt16, SfxItemState eState,
      86             :                                      const SfxPoolItem* pState )
      87             : {
      88        1033 :     if ( SfxItemState::DEFAULT != eState )
      89        1033 :         return;
      90             : 
      91             :     DBG_ASSERT( pState->ISA( SfxBoolItem ), "invalid item type" );
      92        1033 :     const SfxBoolItem* pItem = static_cast<const SfxBoolItem*>(pState);
      93        1033 :     mxImpl->maIdle.Stop();
      94             : 
      95        1033 :     bool modified = pItem->GetValue();
      96        1033 :     bool start = ( !modified && mxImpl->mnModState == ImplData::MODIFICATION_STATE_YES);  // should timer be started and feedback image displayed ?
      97             : 
      98        1033 :     mxImpl->mnModState = (start ? ImplData::MODIFICATION_STATE_FEEDBACK : (modified ? ImplData::MODIFICATION_STATE_YES : ImplData::MODIFICATION_STATE_NO));
      99             : 
     100        1033 :     _repaint();
     101             : 
     102        1033 :     int nResId = modified ? RID_SVXSTR_DOC_MODIFIED_YES : RID_SVXSTR_DOC_MODIFIED_NO;
     103        1033 :     GetStatusBar().SetQuickHelpText(GetId(), SVX_RESSTR(nResId));
     104             : 
     105        1033 :     if ( start )
     106          10 :         mxImpl->maIdle.Start();
     107             : }
     108             : 
     109             : 
     110             : 
     111           0 : IMPL_LINK_TYPED( SvxModifyControl, OnTimer, Idle *, pTimer, void )
     112             : {
     113           0 :     if (pTimer == 0)
     114           0 :         return;
     115             : 
     116           0 :     pTimer->Stop();
     117           0 :     mxImpl->mnModState = ImplData::MODIFICATION_STATE_NO;
     118             : 
     119           0 :     _repaint();
     120             : }
     121             : 
     122             : 
     123             : 
     124        1033 : void SvxModifyControl::_repaint()
     125             : {
     126        1033 :     if ( GetStatusBar().AreItemsVisible() )
     127        1033 :         GetStatusBar().SetItemData( GetId(), 0 );    // force repaint
     128        1033 : }
     129             : 
     130             : /**
     131             :  * Given a bounding rectangle and an image, determine the top-left position
     132             :  * of the image so that the image would look centered both horizontally and
     133             :  * vertically.
     134             :  *
     135             :  * @param rBoundingRect bounding rectangle
     136             :  * @param rImg image
     137             :  *
     138             :  * @return Point top-left corner of the centered image position
     139             :  */
     140        4328 : Point centerImage(const Rectangle& rBoundingRect, const Image& rImg)
     141             : {
     142        4328 :     Size aImgSize = rImg.GetSizePixel();
     143        4328 :     Size aRectSize = rBoundingRect.GetSize();
     144        4328 :     long nXOffset = (aRectSize.getWidth() - aImgSize.getWidth())/2;
     145        4328 :     long nYOffset = (aRectSize.getHeight() - aImgSize.getHeight())/2;
     146        4328 :     Point aPt = rBoundingRect.TopLeft();
     147        4328 :     aPt += Point(nXOffset, nYOffset);
     148        4328 :     return aPt;
     149             : }
     150             : 
     151        4085 : void SvxModifyControl::Paint( const UserDrawEvent& rUsrEvt )
     152             : {
     153        4085 :     OutputDevice*       pDev =  rUsrEvt.GetDevice();
     154        4085 :     Rectangle           aRect = rUsrEvt.GetRect();
     155             : 
     156        4085 :     ImplData::ModificationState state = mxImpl->mnModState;
     157        4085 :     Point aPt = centerImage(aRect, mxImpl->maImages[state]);
     158        4085 :     pDev->DrawImage(aPt, mxImpl->maImages[state]);
     159        4085 : }
     160             : 
     161           0 : void SvxModifyControl::Click()
     162             : {
     163           0 :     if (mxImpl->mnModState != ImplData::MODIFICATION_STATE_YES)
     164             :         // document not modified.  nothing to do here.
     165           0 :         return;
     166             : 
     167           0 :     Sequence<PropertyValue> aArgs;
     168           0 :     execute(OUString(".uno:Save"), aArgs);
     169             : }
     170             : 
     171             : 
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11