fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / stbctrls / modctrl.cxx
blobda2d40f44688f144f06c8427852396965b98502c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
26 #include <svx/dialogs.hrc>
27 #include <svx/modctrl.hxx>
28 #include <svx/dialmgr.hxx>
30 #include <com/sun/star/beans/PropertyValue.hpp>
32 using ::com::sun::star::uno::Sequence;
33 using ::com::sun::star::beans::PropertyValue;
35 SFX_IMPL_STATUSBAR_CONTROL(SvxModifyControl, SfxBoolItem);
38 namespace
40 const unsigned _FEEDBACK_TIMEOUT = 3000;
44 // class SvxModifyControl ------------------------------------------------
46 struct SvxModifyControl::ImplData
48 enum ModificationState
50 MODIFICATION_STATE_NO = 0,
51 MODIFICATION_STATE_YES,
52 MODIFICATION_STATE_FEEDBACK,
53 MODIFICATION_STATE_SIZE
56 Timer maTimer;
57 Image maImages[MODIFICATION_STATE_SIZE];
59 ModificationState mnModState;
61 ImplData():
62 mnModState(MODIFICATION_STATE_NO)
64 maImages[MODIFICATION_STATE_NO] = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_NO));
65 maImages[MODIFICATION_STATE_YES] = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_YES));
66 maImages[MODIFICATION_STATE_FEEDBACK] = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_FEEDBACK));
67 maTimer.SetTimeout(_FEEDBACK_TIMEOUT);
71 SvxModifyControl::SvxModifyControl( sal_uInt16 _nSlotId,
72 sal_uInt16 _nId,
73 StatusBar& rStb ) :
75 SfxStatusBarControl( _nSlotId, _nId, rStb ),
76 mpImpl(new ImplData)
78 mpImpl->maTimer.SetTimeoutHdl( LINK(this, SvxModifyControl, OnTimer) );
81 // -----------------------------------------------------------------------
83 void SvxModifyControl::StateChanged( sal_uInt16, SfxItemState eState,
84 const SfxPoolItem* pState )
86 if ( SFX_ITEM_AVAILABLE != eState )
87 return;
89 DBG_ASSERT( pState->ISA( SfxBoolItem ), "invalid item type" );
90 SfxBoolItem* pItem = (SfxBoolItem*)pState;
91 mpImpl->maTimer.Stop();
93 bool modified = pItem->GetValue();
94 bool start = ( !modified && mpImpl->mnModState == ImplData::MODIFICATION_STATE_YES); // should timer be started and feedback image displayed ?
96 mpImpl->mnModState = (start ? ImplData::MODIFICATION_STATE_FEEDBACK : (modified ? ImplData::MODIFICATION_STATE_YES : ImplData::MODIFICATION_STATE_NO));
98 _repaint();
100 int nResId = modified ? RID_SVXSTR_DOC_MODIFIED_YES : RID_SVXSTR_DOC_MODIFIED_NO;
101 GetStatusBar().SetQuickHelpText(GetId(), SVX_RESSTR(nResId));
103 if ( start )
104 mpImpl->maTimer.Start();
107 // -----------------------------------------------------------------------
109 IMPL_LINK( SvxModifyControl, OnTimer, Timer *, pTimer )
111 if (pTimer == 0)
112 return 0;
114 pTimer->Stop();
115 mpImpl->mnModState = ImplData::MODIFICATION_STATE_NO;
117 _repaint();
119 return 0;
122 // -----------------------------------------------------------------------
124 void SvxModifyControl::_repaint()
126 if ( GetStatusBar().AreItemsVisible() )
127 GetStatusBar().SetItemData( GetId(), 0 ); // force repaint
130 // -----------------------------------------------------------------------
132 namespace {
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.
139 * @param rBoundingRect bounding rectangle
140 * @param rImg image
142 * @return Point top-left corner of the centered image position
144 Point centerImage(const Rectangle& rBoundingRect, const Image& rImg)
146 Size aImgSize = rImg.GetSizePixel();
147 Size aRectSize = rBoundingRect.GetSize();
148 long nXOffset = (aRectSize.getWidth() - aImgSize.getWidth())/2;
149 long nYOffset = (aRectSize.getHeight() - aImgSize.getHeight())/2;
150 Point aPt = rBoundingRect.TopLeft();
151 aPt += Point(nXOffset, nYOffset);
152 return aPt;
158 void SvxModifyControl::Paint( const UserDrawEvent& rUsrEvt )
160 OutputDevice* pDev = rUsrEvt.GetDevice();
161 Rectangle aRect = rUsrEvt.GetRect();
163 ImplData::ModificationState state = mpImpl->mnModState;
164 Point aPt = centerImage(aRect, mpImpl->maImages[state]);
165 pDev->DrawImage(aPt, mpImpl->maImages[state]);
168 void SvxModifyControl::DoubleClick()
170 if (mpImpl->mnModState != ImplData::MODIFICATION_STATE_YES)
171 // document not modified. nothing to do here.
172 return;
174 Sequence<PropertyValue> aArgs;
175 execute(OUString(".uno:Save"), aArgs);
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */