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

Generated by: LCOV version 1.10