1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_reportdesign.hxx"
26 #include "statusbarcontroller.hxx"
27 
28 #include <svx/zoomsliderctrl.hxx>
29 #include <svx/zoomctrl.hxx>
30 #include <svx/svxids.hrc>
31 #include <svx/zoomitem.hxx>
32 #include <svx/zoomslideritem.hxx>
33 
34 #include <vcl/svapp.hxx>
35 #include <vcl/status.hxx>
36 #include <vos/mutex.hxx>
37 #include <toolkit/helper/vclunohelper.hxx>
38 
39 namespace rptui
40 {
41 	using namespace svt;
42 	using namespace com::sun::star::uno;
43 	using namespace com::sun::star::beans;
44 	using namespace com::sun::star::lang;
45 	using namespace ::com::sun::star::frame;
46 	using namespace ::com::sun::star::util;
47 
getImplementationName()48 ::rtl::OUString SAL_CALL OStatusbarController::getImplementationName() throw( RuntimeException )
49 {
50 	return getImplementationName_Static();
51 }
52 
53 //------------------------------------------------------------------------------
getImplementationName_Static()54 ::rtl::OUString OStatusbarController::getImplementationName_Static() throw( RuntimeException )
55 {
56 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.comp.StatusbarController"));
57 }
58 //------------------------------------------------------------------------------
getSupportedServiceNames_Static(void)59 Sequence< ::rtl::OUString> OStatusbarController::getSupportedServiceNames_Static(void) throw( RuntimeException )
60 {
61 	Sequence< ::rtl::OUString> aSupported(1);
62 	aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.StatusbarController"));
63 	return aSupported;
64 }
65 // -----------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)66 ::sal_Bool SAL_CALL OStatusbarController::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException)
67 {
68     return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_Static());
69 }
70 //-------------------------------------------------------------------------
getSupportedServiceNames()71 Sequence< ::rtl::OUString> SAL_CALL OStatusbarController::getSupportedServiceNames() throw(RuntimeException)
72 {
73 	return getSupportedServiceNames_Static();
74 }
75 // -------------------------------------------------------------------------
create(Reference<XComponentContext> const & xContext)76 Reference< XInterface > OStatusbarController::create(Reference< XComponentContext > const & xContext)
77 {
78 	return *(new OStatusbarController(Reference< XMultiServiceFactory >(xContext->getServiceManager(),UNO_QUERY)));
79 }
IMPLEMENT_FORWARD_XINTERFACE2(OStatusbarController,::svt::StatusbarController,OStatusbarController_BASE)80 IMPLEMENT_FORWARD_XINTERFACE2(OStatusbarController, ::svt::StatusbarController,OStatusbarController_BASE)
81 
82 OStatusbarController::OStatusbarController(const Reference< XMultiServiceFactory >& _rxORB)
83 : m_nSlotId(0)
84 ,m_nId(1)
85 {
86     m_xServiceManager = _rxORB;
87 }
88 // -----------------------------------------------------------------------------
initialize(const Sequence<Any> & _rArguments)89 void SAL_CALL OStatusbarController::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException)
90 {
91 	StatusbarController::initialize(_rArguments);
92 	vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
93 	::osl::MutexGuard aGuard(m_aMutex);
94 
95     StatusBar* pStatusBar = static_cast<StatusBar*>(VCLUnoHelper::GetWindow(m_xParentWindow));
96     if ( pStatusBar )
97     {
98         const sal_uInt16 nCount = pStatusBar->GetItemCount();
99 	    for (sal_uInt16 nPos = 0; nPos < nCount; ++nPos)
100 	    {
101 		    const sal_uInt16 nItemId = pStatusBar->GetItemId(nPos);
102 		    if ( pStatusBar->GetItemCommand(nItemId) == String(m_aCommandURL) )
103 		    {
104 			    m_nId = nItemId;
105 			    break;
106 		    }
107 	    }
108 
109 	    SfxStatusBarControl *pController = 0;
110         if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
111         {
112             pController = new SvxZoomSliderControl(m_nSlotId = SID_ATTR_ZOOMSLIDER,m_nId,*pStatusBar);
113         } // if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
114         else if ( m_aCommandURL.equalsAscii(".uno:Zoom") )
115         {
116             pController = new SvxZoomStatusBarControl(m_nSlotId = SID_ATTR_ZOOM,m_nId,*pStatusBar);
117         }
118 
119         if ( pController )
120         {
121             m_rController.set( pController );
122             if ( m_rController.is() )
123             {
124                 m_rController->initialize(_rArguments);
125                 m_rController->update();
126             }
127         }
128 
129         addStatusListener(m_aCommandURL);
130         update();
131     }
132 }
133 // XStatusListener
statusChanged(const FeatureStateEvent & _aEvent)134 void SAL_CALL OStatusbarController::statusChanged( const FeatureStateEvent& _aEvent)throw ( RuntimeException )
135 {
136     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
137     ::osl::MutexGuard aGuard(m_aMutex);
138 
139     if ( m_rController.is() )
140     {
141         if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
142         {
143             Sequence< PropertyValue > aSeq;
144             if ( (_aEvent.State >>= aSeq) && aSeq.getLength() == 2 )
145             {
146                 SvxZoomSliderItem aZoomSlider(100,20,400);
147                 aZoomSlider.PutValue(_aEvent.State);
148                 static_cast<SvxZoomSliderControl*>(m_rController.get())->StateChanged(m_nSlotId,SFX_ITEM_AVAILABLE,&aZoomSlider);
149             }
150         } // if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
151         else if ( m_aCommandURL.equalsAscii(".uno:Zoom") )
152         {
153             Sequence< PropertyValue > aSeq;
154             if ( (_aEvent.State >>= aSeq) && aSeq.getLength() == 3 )
155             {
156                 SvxZoomItem aZoom;
157                 aZoom.PutValue(_aEvent.State);
158                 static_cast<SvxZoomStatusBarControl*>(m_rController.get())->StateChanged(m_nSlotId,SFX_ITEM_AVAILABLE,&aZoom);
159             }
160         }
161     }
162 }
163 
164 // XStatusbarController
mouseButtonDown(const::com::sun::star::awt::MouseEvent & _aEvent)165 ::sal_Bool SAL_CALL OStatusbarController::mouseButtonDown(const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
166 {
167     return m_rController.is() && m_rController->mouseButtonDown(_aEvent);
168 }
169 
mouseMove(const::com::sun::star::awt::MouseEvent & _aEvent)170 ::sal_Bool SAL_CALL OStatusbarController::mouseMove(    const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
171 {
172     return m_rController.is() && m_rController->mouseMove(_aEvent);
173 }
174 
mouseButtonUp(const::com::sun::star::awt::MouseEvent & _aEvent)175 ::sal_Bool SAL_CALL OStatusbarController::mouseButtonUp(    const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
176 {
177     return m_rController.is() && m_rController->mouseButtonUp(_aEvent);
178 }
179 
command(const::com::sun::star::awt::Point & aPos,::sal_Int32 nCommand,::sal_Bool bMouseEvent,const::com::sun::star::uno::Any & aData)180 void SAL_CALL OStatusbarController::command(
181     const ::com::sun::star::awt::Point& aPos,
182     ::sal_Int32 nCommand,
183     ::sal_Bool bMouseEvent,
184     const ::com::sun::star::uno::Any& aData )
185 throw (::com::sun::star::uno::RuntimeException)
186 {
187     if ( m_rController.is() )
188         m_rController->command( aPos, nCommand, bMouseEvent, aData );
189 }
190 
paint(const::com::sun::star::uno::Reference<::com::sun::star::awt::XGraphics> & xGraphics,const::com::sun::star::awt::Rectangle & rOutputRectangle,::sal_Int32 nStyle)191 void SAL_CALL OStatusbarController::paint(
192     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >& xGraphics,
193     const ::com::sun::star::awt::Rectangle& rOutputRectangle,
194     ::sal_Int32 nStyle )
195 throw (::com::sun::star::uno::RuntimeException)
196 {
197     if ( m_rController.is() )
198         m_rController->paint( xGraphics, rOutputRectangle, nStyle );
199 }
200 
click(const::com::sun::star::awt::Point & aPos)201 void SAL_CALL OStatusbarController::click(
202     const ::com::sun::star::awt::Point& aPos )
203 throw (::com::sun::star::uno::RuntimeException)
204 {
205     if ( m_rController.is() )
206         m_rController->click( aPos );
207 }
208 
doubleClick(const::com::sun::star::awt::Point & aPos)209 void SAL_CALL OStatusbarController::doubleClick(
210     const ::com::sun::star::awt::Point& aPos )
211 throw (::com::sun::star::uno::RuntimeException)
212 {
213     if ( m_rController.is() )
214         m_rController->doubleClick( aPos );
215 }
216 // -----------------------------------------------------------------------------
update()217 void SAL_CALL OStatusbarController::update() throw ( RuntimeException )
218 {
219     ::svt::StatusbarController::update();
220     if ( m_rController.is() )
221         m_rController->update();
222 }
223 // -----------------------------------------------------------------------------
224 // XComponent
dispose()225 void SAL_CALL OStatusbarController::dispose() throw (::com::sun::star::uno::RuntimeException)
226 {
227     if ( m_rController.is() )
228         ::comphelper::disposeComponent( m_rController );
229 
230     svt::StatusbarController::dispose();
231 }
232 // =============================================================================
233 } // rptui
234 // =============================================================================
235