LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/stbctrls - modctrl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 46 58 79.3 %
Date: 2013-07-09 Functions: 11 14 78.6 %
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         712 : 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         623 : 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         623 :     ImplData():
      62         623 :         mnModState(MODIFICATION_STATE_NO)
      63             :     {
      64         623 :         maImages[MODIFICATION_STATE_NO]       = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_NO));
      65         623 :         maImages[MODIFICATION_STATE_YES]      = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_YES));
      66         623 :         maImages[MODIFICATION_STATE_FEEDBACK] = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_FEEDBACK));
      67         623 :         maTimer.SetTimeout(_FEEDBACK_TIMEOUT);
      68         623 :     }
      69             : };
      70             : 
      71         623 : SvxModifyControl::SvxModifyControl( sal_uInt16 _nSlotId,
      72             :                                     sal_uInt16 _nId,
      73             :                                     StatusBar& rStb ) :
      74             : 
      75             :     SfxStatusBarControl( _nSlotId, _nId, rStb ),
      76         623 :     mpImpl(new ImplData)
      77             : {
      78         623 :     mpImpl->maTimer.SetTimeoutHdl( LINK(this, SvxModifyControl, OnTimer) );
      79         623 : }
      80             : 
      81             : // -----------------------------------------------------------------------
      82             : 
      83         988 : void SvxModifyControl::StateChanged( sal_uInt16, SfxItemState eState,
      84             :                                      const SfxPoolItem* pState )
      85             : {
      86         988 :     if ( SFX_ITEM_AVAILABLE != eState )
      87         988 :         return;
      88             : 
      89             :     DBG_ASSERT( pState->ISA( SfxBoolItem ), "invalid item type" );
      90         988 :     SfxBoolItem* pItem = (SfxBoolItem*)pState;
      91         988 :     mpImpl->maTimer.Stop();
      92             : 
      93         988 :     bool modified = pItem->GetValue();
      94         988 :     bool start = ( !modified && mpImpl->mnModState == ImplData::MODIFICATION_STATE_YES);  // should timer be started and feedback image displayed ?
      95             : 
      96         988 :     mpImpl->mnModState = (start ? ImplData::MODIFICATION_STATE_FEEDBACK : (modified ? ImplData::MODIFICATION_STATE_YES : ImplData::MODIFICATION_STATE_NO));
      97             : 
      98         988 :     _repaint();
      99             : 
     100         988 :     int nResId = modified ? RID_SVXSTR_DOC_MODIFIED_YES : RID_SVXSTR_DOC_MODIFIED_NO;
     101         988 :     GetStatusBar().SetQuickHelpText(GetId(), SVX_RESSTR(nResId));
     102             : 
     103         988 :     if ( start )
     104           3 :         mpImpl->maTimer.Start();
     105             : }
     106             : 
     107             : // -----------------------------------------------------------------------
     108             : 
     109           0 : IMPL_LINK( SvxModifyControl, OnTimer, Timer *, pTimer )
     110             : {
     111           0 :     if (pTimer == 0)
     112           0 :         return 0;
     113             : 
     114           0 :     pTimer->Stop();
     115           0 :     mpImpl->mnModState = ImplData::MODIFICATION_STATE_NO;
     116             : 
     117           0 :     _repaint();
     118             : 
     119           0 :     return 0;
     120             : }
     121             : 
     122             : // -----------------------------------------------------------------------
     123             : 
     124         988 : void SvxModifyControl::_repaint()
     125             : {
     126         988 :     if ( GetStatusBar().AreItemsVisible() )
     127         988 :         GetStatusBar().SetItemData( GetId(), 0 );    // force repaint
     128         988 : }
     129             : 
     130             : // -----------------------------------------------------------------------
     131             : 
     132             : namespace {
     133             : 
     134             : /**
     135             :  * Given a bounding rectangle and an image, determine the top-left position
     136             :  * of the image so that the image would look centered both horizontally and
     137             :  * vertically.
     138             :  *
     139             :  * @param rBoundingRect bounding rectangle
     140             :  * @param rImg image
     141             :  *
     142             :  * @return Point top-left corner of the centered image position
     143             :  */
     144        1550 : Point centerImage(const Rectangle& rBoundingRect, const Image& rImg)
     145             : {
     146        1550 :     Size aImgSize = rImg.GetSizePixel();
     147        1550 :     Size aRectSize = rBoundingRect.GetSize();
     148        1550 :     long nXOffset = (aRectSize.getWidth() - aImgSize.getWidth())/2;
     149        1550 :     long nYOffset = (aRectSize.getHeight() - aImgSize.getHeight())/2;
     150        1550 :     Point aPt = rBoundingRect.TopLeft();
     151        1550 :     aPt += Point(nXOffset, nYOffset);
     152        1550 :     return aPt;
     153             : }
     154             : 
     155             : }
     156             : 
     157             : 
     158        1550 : void SvxModifyControl::Paint( const UserDrawEvent& rUsrEvt )
     159             : {
     160        1550 :     OutputDevice*       pDev =  rUsrEvt.GetDevice();
     161        1550 :     Rectangle           aRect = rUsrEvt.GetRect();
     162             : 
     163        1550 :     ImplData::ModificationState state = mpImpl->mnModState;
     164        1550 :     Point aPt = centerImage(aRect, mpImpl->maImages[state]);
     165        1550 :     pDev->DrawImage(aPt, mpImpl->maImages[state]);
     166        1550 : }
     167             : 
     168           0 : void SvxModifyControl::DoubleClick()
     169             : {
     170           0 :     if (mpImpl->mnModState != ImplData::MODIFICATION_STATE_YES)
     171             :         // document not modified.  nothing to do here.
     172           0 :         return;
     173             : 
     174           0 :     Sequence<PropertyValue> aArgs;
     175           0 :     execute(OUString(".uno:Save"), aArgs);
     176         216 : }
     177             : 
     178             : 
     179             : 
     180             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10