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 <statusbarcontroller.hxx>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <comphelper/types.hxx>
24 #include <svx/zoomsliderctrl.hxx>
25 #include <svx/zoomctrl.hxx>
26 #include <svx/svxids.hrc>
27 #include <sfx2/zoomitem.hxx>
28 #include <svx/zoomslideritem.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/status.hxx>
32 #include <osl/mutex.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <com/sun/star/beans/PropertyValue.hpp>
39 using namespace com::sun::star::uno
;
40 using namespace com::sun::star::beans
;
41 using namespace com::sun::star::lang
;
42 using namespace ::com::sun::star::frame
;
43 using namespace ::com::sun::star::util
;
45 OUString SAL_CALL
OStatusbarController::getImplementationName()
47 return getImplementationName_Static();
50 OUString
OStatusbarController::getImplementationName_Static()
52 return OUString("com.sun.star.report.comp.StatusbarController");
55 Sequence
< OUString
> OStatusbarController::getSupportedServiceNames_Static()
57 Sequence
<OUString
> aSupported
{ "com.sun.star.frame.StatusbarController" };
61 sal_Bool SAL_CALL
OStatusbarController::supportsService( const OUString
& ServiceName
)
63 return cppu::supportsService(this, ServiceName
);
66 Sequence
< OUString
> SAL_CALL
OStatusbarController::getSupportedServiceNames()
68 return getSupportedServiceNames_Static();
71 Reference
< XInterface
> OStatusbarController::create(Reference
< XComponentContext
> const & xContext
)
73 return *(new OStatusbarController(xContext
));
75 IMPLEMENT_FORWARD_XINTERFACE2(OStatusbarController
, ::svt::StatusbarController
,OStatusbarController_BASE
)
77 OStatusbarController::OStatusbarController(const Reference
< XComponentContext
>& rxContext
)
78 : ::svt::StatusbarController(rxContext
, Reference
< XFrame
>(), OUString(), 0)
84 void SAL_CALL
OStatusbarController::initialize( const Sequence
< Any
>& _rArguments
)
86 StatusbarController::initialize(_rArguments
);
87 SolarMutexGuard aSolarMutexGuard
;
88 ::osl::MutexGuard
aGuard(m_aMutex
);
90 VclPtr
< StatusBar
> pStatusBar
= static_cast<StatusBar
*>(VCLUnoHelper::GetWindow(m_xParentWindow
).get());
93 const sal_uInt16 nCount
= pStatusBar
->GetItemCount();
94 for (sal_uInt16 nPos
= 0; nPos
< nCount
; ++nPos
)
96 const sal_uInt16 nItemId
= pStatusBar
->GetItemId(nPos
);
97 if ( pStatusBar
->GetItemCommand(nItemId
) == m_aCommandURL
)
104 SfxStatusBarControl
*pController
= nullptr;
105 if ( m_aCommandURL
== ".uno:ZoomSlider" )
107 m_nSlotId
= SID_ATTR_ZOOMSLIDER
;
108 pController
= new SvxZoomSliderControl(m_nSlotId
,m_nId
,*pStatusBar
);
110 else if ( m_aCommandURL
== ".uno:Zoom" )
112 m_nSlotId
= SID_ATTR_ZOOM
;
113 pController
= new SvxZoomStatusBarControl(m_nSlotId
,m_nId
,*pStatusBar
);
118 m_rController
.set( pController
);
119 if ( m_rController
.is() )
121 m_rController
->initialize(_rArguments
);
122 m_rController
->update();
126 addStatusListener(m_aCommandURL
);
131 void SAL_CALL
OStatusbarController::statusChanged( const FeatureStateEvent
& _aEvent
)
133 SolarMutexGuard aSolarGuard
;
134 ::osl::MutexGuard
aGuard(m_aMutex
);
136 if ( m_rController
.is() )
138 if ( m_aCommandURL
== ".uno:ZoomSlider" )
140 Sequence
< PropertyValue
> aSeq
;
141 if ( (_aEvent
.State
>>= aSeq
) && aSeq
.getLength() == 2 )
143 SvxZoomSliderItem
aZoomSlider(100,20,400);
144 aZoomSlider
.PutValue(_aEvent
.State
, 0);
145 static_cast<SvxZoomSliderControl
*>(m_rController
.get())->StateChanged(m_nSlotId
,SfxItemState::DEFAULT
,&aZoomSlider
);
148 else if ( m_aCommandURL
== ".uno:Zoom" )
150 Sequence
< PropertyValue
> aSeq
;
151 if ( (_aEvent
.State
>>= aSeq
) && aSeq
.getLength() == 3 )
154 aZoom
.PutValue(_aEvent
.State
, 0 );
155 static_cast<SvxZoomStatusBarControl
*>(m_rController
.get())->StateChanged(m_nSlotId
,SfxItemState::DEFAULT
,&aZoom
);
161 // XStatusbarController
162 sal_Bool SAL_CALL
OStatusbarController::mouseButtonDown(const css::awt::MouseEvent
& _aEvent
)
164 return m_rController
.is() && m_rController
->mouseButtonDown(_aEvent
);
167 sal_Bool SAL_CALL
OStatusbarController::mouseMove( const css::awt::MouseEvent
& _aEvent
)
169 return m_rController
.is() && m_rController
->mouseMove(_aEvent
);
172 sal_Bool SAL_CALL
OStatusbarController::mouseButtonUp( const css::awt::MouseEvent
& _aEvent
)
174 return m_rController
.is() && m_rController
->mouseButtonUp(_aEvent
);
177 void SAL_CALL
OStatusbarController::command(
178 const css::awt::Point
& aPos
,
179 ::sal_Int32 nCommand
,
180 sal_Bool bMouseEvent
,
181 const css::uno::Any
& aData
)
183 if ( m_rController
.is() )
184 m_rController
->command( aPos
, nCommand
, bMouseEvent
, aData
);
187 void SAL_CALL
OStatusbarController::paint(
188 const css::uno::Reference
< css::awt::XGraphics
>& xGraphics
,
189 const css::awt::Rectangle
& rOutputRectangle
,
192 if ( m_rController
.is() )
193 m_rController
->paint( xGraphics
, rOutputRectangle
, nStyle
);
196 void SAL_CALL
OStatusbarController::click(
197 const css::awt::Point
& aPos
)
199 if ( m_rController
.is() )
200 m_rController
->click( aPos
);
203 void SAL_CALL
OStatusbarController::doubleClick(
204 const css::awt::Point
& aPos
)
206 if ( m_rController
.is() )
207 m_rController
->doubleClick( aPos
);
210 void SAL_CALL
OStatusbarController::update()
212 ::svt::StatusbarController::update();
213 if ( m_rController
.is() )
214 m_rController
->update();
218 void SAL_CALL
OStatusbarController::dispose()
220 if ( m_rController
.is() )
221 ::comphelper::disposeComponent( m_rController
);
223 svt::StatusbarController::dispose();
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */