1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/idle.hxx>
24 #include <svl/eitem.hxx>
25 #include <sfx2/app.hxx>
27 #include <svx/dialogs.hrc>
28 #include <svx/modctrl.hxx>
29 #include <svx/dialmgr.hxx>
31 #include <com/sun/star/beans/PropertyValue.hpp>
32 #include "modctrl_internal.hxx"
34 using ::com::sun::star::uno::Sequence
;
35 using ::com::sun::star::beans::PropertyValue
;
37 SFX_IMPL_STATUSBAR_CONTROL(SvxModifyControl
, SfxBoolItem
);
39 struct SvxModifyControl::ImplData
41 enum ModificationState
43 MODIFICATION_STATE_NO
= 0,
44 MODIFICATION_STATE_YES
,
45 MODIFICATION_STATE_FEEDBACK
,
46 MODIFICATION_STATE_SIZE
50 Image maImages
[MODIFICATION_STATE_SIZE
];
52 ModificationState mnModState
;
55 mnModState(MODIFICATION_STATE_NO
)
57 maImages
[MODIFICATION_STATE_NO
] = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_NO
));
58 maImages
[MODIFICATION_STATE_YES
] = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_YES
));
59 maImages
[MODIFICATION_STATE_FEEDBACK
] = Image(SVX_RES(RID_SVXBMP_DOC_MODIFIED_FEEDBACK
));
61 maIdle
.SetPriority(SchedulerPriority::LOWEST
);
65 SvxModifyControl::SvxModifyControl( sal_uInt16 _nSlotId
, sal_uInt16 _nId
, StatusBar
& rStb
) :
66 SfxStatusBarControl( _nSlotId
, _nId
, rStb
),
70 if ( rStb
.GetDPIScaleFactor() > 1 )
72 for (int i
= 0; i
< mxImpl
->MODIFICATION_STATE_SIZE
; i
++)
74 BitmapEx b
= mxImpl
->maImages
[i
].GetBitmapEx();
75 b
.Scale(rStb
.GetDPIScaleFactor(), rStb
.GetDPIScaleFactor(), BmpScaleFlag::Fast
);
76 mxImpl
->maImages
[i
] = Image(b
);
80 mxImpl
->maIdle
.SetIdleHdl( LINK(this, SvxModifyControl
, OnTimer
) );
85 void SvxModifyControl::StateChanged( sal_uInt16
, SfxItemState eState
,
86 const SfxPoolItem
* pState
)
88 if ( SfxItemState::DEFAULT
!= eState
)
91 DBG_ASSERT( pState
->ISA( SfxBoolItem
), "invalid item type" );
92 const SfxBoolItem
* pItem
= static_cast<const SfxBoolItem
*>(pState
);
93 mxImpl
->maIdle
.Stop();
95 bool modified
= pItem
->GetValue();
96 bool start
= ( !modified
&& mxImpl
->mnModState
== ImplData::MODIFICATION_STATE_YES
); // should timer be started and feedback image displayed ?
98 mxImpl
->mnModState
= (start
? ImplData::MODIFICATION_STATE_FEEDBACK
: (modified
? ImplData::MODIFICATION_STATE_YES
: ImplData::MODIFICATION_STATE_NO
));
102 int nResId
= modified
? RID_SVXSTR_DOC_MODIFIED_YES
: RID_SVXSTR_DOC_MODIFIED_NO
;
103 GetStatusBar().SetQuickHelpText(GetId(), SVX_RESSTR(nResId
));
106 mxImpl
->maIdle
.Start();
111 IMPL_LINK_TYPED( SvxModifyControl
, OnTimer
, Idle
*, pTimer
, void )
117 mxImpl
->mnModState
= ImplData::MODIFICATION_STATE_NO
;
124 void SvxModifyControl::_repaint()
126 if ( GetStatusBar().AreItemsVisible() )
127 GetStatusBar().SetItemData( GetId(), 0 ); // force repaint
131 * Given a bounding rectangle and an image, determine the top-left position
132 * of the image so that the image would look centered both horizontally and
135 * @param rBoundingRect bounding rectangle
138 * @return Point top-left corner of the centered image position
140 Point
centerImage(const Rectangle
& rBoundingRect
, const Image
& rImg
)
142 Size aImgSize
= rImg
.GetSizePixel();
143 Size aRectSize
= rBoundingRect
.GetSize();
144 long nXOffset
= (aRectSize
.getWidth() - aImgSize
.getWidth())/2;
145 long nYOffset
= (aRectSize
.getHeight() - aImgSize
.getHeight())/2;
146 Point aPt
= rBoundingRect
.TopLeft();
147 aPt
+= Point(nXOffset
, nYOffset
);
151 void SvxModifyControl::Paint( const UserDrawEvent
& rUsrEvt
)
153 vcl::RenderContext
* pDev
= rUsrEvt
.GetRenderContext();
154 Rectangle
aRect(rUsrEvt
.GetRect());
156 ImplData::ModificationState state
= mxImpl
->mnModState
;
157 Point aPt
= centerImage(aRect
, mxImpl
->maImages
[state
]);
158 pDev
->DrawImage(aPt
, mxImpl
->maImages
[state
]);
161 void SvxModifyControl::Click()
163 if (mxImpl
->mnModState
!= ImplData::MODIFICATION_STATE_YES
)
164 // document not modified. nothing to do here.
167 Sequence
<PropertyValue
> aArgs
;
168 execute(OUString(".uno:Save"), aArgs
);
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */