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

Generated by: LCOV version 1.10