Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/status.hxx>
30 : : #include <vcl/image.hxx>
31 : : #include <vcl/timer.hxx>
32 : : #include <svl/eitem.hxx>
33 : : #include <sfx2/app.hxx>
34 : :
35 : : #include <svx/dialogs.hrc>
36 : : #include <svx/modctrl.hxx>
37 : : #include <svx/dialmgr.hxx>
38 : :
39 : : #include <com/sun/star/beans/PropertyValue.hpp>
40 : :
41 : : using ::com::sun::star::uno::Sequence;
42 : : using ::com::sun::star::beans::PropertyValue;
43 : : using ::rtl::OUString;
44 : :
45 [ + - ]: 1312 : SFX_IMPL_STATUSBAR_CONTROL(SvxModifyControl, SfxBoolItem);
46 : :
47 : :
48 : : namespace
49 : : {
50 : : const unsigned _FEEDBACK_TIMEOUT = 3000;
51 : : }
52 : :
53 : :
54 : : // class SvxModifyControl ------------------------------------------------
55 : :
56 [ + - ][ + + ]: 4572 : struct SvxModifyControl::ImplData
[ + - ]
57 : : {
58 : : enum ModificationState
59 : : {
60 : : MODIFICATION_STATE_NO = 0,
61 : : MODIFICATION_STATE_YES,
62 : : MODIFICATION_STATE_FEEDBACK,
63 : : MODIFICATION_STATE_SIZE
64 : : };
65 : :
66 : : Timer maTimer;
67 : : Image maImages[MODIFICATION_STATE_SIZE];
68 : :
69 : : ModificationState mnModState;
70 : :
71 : 1143 : ImplData():
72 [ + - ][ + + : 4572 : mnModState(MODIFICATION_STATE_NO)
# # # # ]
73 : : {
74 [ + - ][ + - ]: 1143 : maImages[MODIFICATION_STATE_NO] = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_NO));
[ + - ][ + - ]
75 [ + - ][ + - ]: 1143 : maImages[MODIFICATION_STATE_YES] = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_YES));
[ + - ][ + - ]
76 [ + - ][ + - ]: 1143 : maImages[MODIFICATION_STATE_FEEDBACK] = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_FEEDBACK));
[ + - ][ + - ]
77 [ + - ]: 1143 : maTimer.SetTimeout(_FEEDBACK_TIMEOUT);
78 [ # # # # ]: 1143 : }
79 : : };
80 : :
81 : 1143 : SvxModifyControl::SvxModifyControl( sal_uInt16 _nSlotId,
82 : : sal_uInt16 _nId,
83 : : StatusBar& rStb ) :
84 : :
85 : : SfxStatusBarControl( _nSlotId, _nId, rStb ),
86 [ + - ][ + - ]: 1143 : mpImpl(new ImplData)
[ + - ]
87 : : {
88 [ + - ]: 1143 : mpImpl->maTimer.SetTimeoutHdl( LINK(this, SvxModifyControl, OnTimer) );
89 : 1143 : }
90 : :
91 : : // -----------------------------------------------------------------------
92 : :
93 : 1917 : void SvxModifyControl::StateChanged( sal_uInt16, SfxItemState eState,
94 : : const SfxPoolItem* pState )
95 : : {
96 [ - + ]: 1917 : if ( SFX_ITEM_AVAILABLE != eState )
97 : 1917 : return;
98 : :
99 : : DBG_ASSERT( pState->ISA( SfxBoolItem ), "invalid item type" );
100 : 1917 : SfxBoolItem* pItem = (SfxBoolItem*)pState;
101 : 1917 : mpImpl->maTimer.Stop();
102 : :
103 : 1917 : bool modified = pItem->GetValue();
104 [ + + ][ + + ]: 1917 : bool start = ( !modified && mpImpl->mnModState == ImplData::MODIFICATION_STATE_YES); // should timer be started and feedback image displayed ?
105 : :
106 [ + + ][ + + ]: 1917 : mpImpl->mnModState = (start ? ImplData::MODIFICATION_STATE_FEEDBACK : (modified ? ImplData::MODIFICATION_STATE_YES : ImplData::MODIFICATION_STATE_NO));
107 : :
108 : 1917 : _repaint();
109 : :
110 [ + + ]: 1917 : int nResId = modified ? RID_SVXSTR_DOC_MODIFIED_YES : RID_SVXSTR_DOC_MODIFIED_NO;
111 [ + - ][ + - ]: 1917 : GetStatusBar().SetQuickHelpText(GetId(), SVX_RESSTR(nResId));
[ + - ][ + - ]
112 : :
113 [ + + ]: 1917 : if ( start )
114 : 4 : mpImpl->maTimer.Start();
115 : : }
116 : :
117 : : // -----------------------------------------------------------------------
118 : :
119 : 0 : IMPL_LINK( SvxModifyControl, OnTimer, Timer *, pTimer )
120 : : {
121 [ # # ]: 0 : if (pTimer == 0)
122 : 0 : return 0;
123 : :
124 : 0 : pTimer->Stop();
125 : 0 : mpImpl->mnModState = ImplData::MODIFICATION_STATE_NO;
126 : :
127 : 0 : _repaint();
128 : :
129 : 0 : return 0;
130 : : }
131 : :
132 : : // -----------------------------------------------------------------------
133 : :
134 : 1917 : void SvxModifyControl::_repaint()
135 : : {
136 [ + - ]: 1917 : if ( GetStatusBar().AreItemsVisible() )
137 : 1917 : GetStatusBar().SetItemData( GetId(), 0 ); // force repaint
138 : 1917 : }
139 : :
140 : : // -----------------------------------------------------------------------
141 : :
142 : : namespace {
143 : :
144 : : /**
145 : : * Given a bounding rectangle and an image, determine the top-left position
146 : : * of the image so that the image would look centered both horizontally and
147 : : * vertically.
148 : : *
149 : : * @param rBoundingRect bounding rectangle
150 : : * @param rImg image
151 : : *
152 : : * @return Point top-left corner of the centered image position
153 : : */
154 : 2804 : Point centerImage(const Rectangle& rBoundingRect, const Image& rImg)
155 : : {
156 [ + - ]: 2804 : Size aImgSize = rImg.GetSizePixel();
157 [ + - ]: 2804 : Size aRectSize = rBoundingRect.GetSize();
158 : 2804 : long nXOffset = (aRectSize.getWidth() - aImgSize.getWidth())/2;
159 : 2804 : long nYOffset = (aRectSize.getHeight() - aImgSize.getHeight())/2;
160 : 2804 : Point aPt = rBoundingRect.TopLeft();
161 : 2804 : aPt += Point(nXOffset, nYOffset);
162 : 2804 : return aPt;
163 : : }
164 : :
165 : : }
166 : :
167 : :
168 : 2804 : void SvxModifyControl::Paint( const UserDrawEvent& rUsrEvt )
169 : : {
170 : 2804 : OutputDevice* pDev = rUsrEvt.GetDevice();
171 : 2804 : Rectangle aRect = rUsrEvt.GetRect();
172 : :
173 : 2804 : ImplData::ModificationState state = mpImpl->mnModState;
174 [ + - ]: 2804 : Point aPt = centerImage(aRect, mpImpl->maImages[state]);
175 [ + - ]: 2804 : pDev->DrawImage(aPt, mpImpl->maImages[state]);
176 : 2804 : }
177 : :
178 : 0 : void SvxModifyControl::DoubleClick()
179 : : {
180 [ # # ]: 0 : if (mpImpl->mnModState != ImplData::MODIFICATION_STATE_YES)
181 : : // document not modified. nothing to do here.
182 : 0 : return;
183 : :
184 [ # # ]: 0 : Sequence<PropertyValue> aArgs;
185 [ # # ][ # # ]: 0 : execute(OUString(".uno:Save"), aArgs);
186 : : }
187 : :
188 : :
189 : :
190 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|