1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: modctrl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
36 #include "modctrl.hxx"
38 #include <vcl/status.hxx>
39 #include <vcl/image.hxx>
40 #include <svtools/eitem.hxx>
41 #include <sfx2/app.hxx>
44 #include <svx/dialogs.hrc>
45 #include <svx/dialmgr.hxx>
47 #include <com/sun/star/beans/PropertyValue.hpp>
49 using ::com::sun::star::uno::Sequence
;
50 using ::com::sun::star::beans::PropertyValue
;
51 using ::rtl::OUString
;
53 SFX_IMPL_STATUSBAR_CONTROL(SvxModifyControl
, SfxBoolItem
);
55 // class SvxModifyControl ------------------------------------------------
57 struct SvxModifyControl::ImplData
59 Image maModifiedButton
;
60 Image maNonModifiedButton
;
65 maModifiedButton( SVX_RES(RID_SVXBMP_DOC_MODIFIED_YES
) ),
66 maNonModifiedButton( SVX_RES(RID_SVXBMP_DOC_MODIFIED_NO
) ),
72 SvxModifyControl::SvxModifyControl( USHORT _nSlotId
,
76 SfxStatusBarControl( _nSlotId
, _nId
, rStb
),
81 // -----------------------------------------------------------------------
83 void SvxModifyControl::StateChanged( USHORT
, SfxItemState eState
,
84 const SfxPoolItem
* pState
)
86 if ( SFX_ITEM_AVAILABLE
!= eState
)
89 DBG_ASSERT( pState
->ISA( SfxBoolItem
), "invalid item type" );
90 SfxBoolItem
* pItem
= (SfxBoolItem
*)pState
;
91 mpImpl
->mbModified
= pItem
->GetValue();
93 if ( GetStatusBar().AreItemsVisible() )
94 GetStatusBar().SetItemData( GetId(), 0 ); // force repaint
96 int nResId
= mpImpl
->mbModified
? RID_SVXSTR_DOC_MODIFIED_YES
: RID_SVXSTR_DOC_MODIFIED_NO
;
97 GetStatusBar().SetQuickHelpText(GetId(), SVX_RESSTR(nResId
));
100 // -----------------------------------------------------------------------
105 * Given a bounding rectangle and an image, determine the top-left position
106 * of the image so that the image would look centered both horizontally and
109 * @param rBoundingRect bounding rectangle
112 * @return Point top-left corner of the centered image position
114 Point
centerImage(const Rectangle
& rBoundingRect
, const Image
& rImg
)
116 Size aImgSize
= rImg
.GetSizePixel();
117 Size aRectSize
= rBoundingRect
.GetSize();
118 long nXOffset
= (aRectSize
.getWidth() - aImgSize
.getWidth())/2;
119 long nYOffset
= (aRectSize
.getHeight() - aImgSize
.getHeight())/2;
120 Point aPt
= rBoundingRect
.TopLeft();
121 aPt
+= Point(nXOffset
, nYOffset
);
126 void SvxModifyControl::Paint( const UserDrawEvent
& rUsrEvt
)
128 const Rectangle aControlRect
= getControlRect();
129 OutputDevice
* pDev
= rUsrEvt
.GetDevice();
130 Rectangle aRect
= rUsrEvt
.GetRect();
132 if (mpImpl
->mbModified
)
134 Point aPt
= centerImage(aRect
, mpImpl
->maModifiedButton
);
135 pDev
->DrawImage(aPt
, mpImpl
->maModifiedButton
);
139 Point aPt
= centerImage(aRect
, mpImpl
->maNonModifiedButton
);
140 pDev
->DrawImage(aPt
, mpImpl
->maNonModifiedButton
);
144 void SvxModifyControl::DoubleClick()
146 if (!mpImpl
->mbModified
)
147 // document not modified. nothing to do here.
150 Sequence
<PropertyValue
> aArgs
;
151 execute(OUString::createFromAscii(".uno:Save"), aArgs
);
154 ULONG
SvxModifyControl::GetDefItemWidth(const StatusBar
& rStb
)
156 return rStb
.GetTextWidth(String::CreateFromAscii("XX"));