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 
48 ::rtl::OUString SAL_CALL OStatusbarController::getImplementationName() throw( RuntimeException )
49 {
50 	return getImplementationName_Static();
51 }
52 
53 //------------------------------------------------------------------------------
54 ::rtl::OUString OStatusbarController::getImplementationName_Static() throw( RuntimeException )
55 {
56 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.comp.StatusbarController"));
57 }
58 //------------------------------------------------------------------------------
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 // -----------------------------------------------------------------------------
66 ::sal_Bool SAL_CALL OStatusbarController::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException)
67 {
68     return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_Static());
69 }
70 //-------------------------------------------------------------------------
71 Sequence< ::rtl::OUString> SAL_CALL OStatusbarController::getSupportedServiceNames() throw(RuntimeException)
72 {
73 	return getSupportedServiceNames_Static();
74 }
75 // -------------------------------------------------------------------------
76 Reference< XInterface > OStatusbarController::create(Reference< XComponentContext > const & xContext)
77 {
78 	return *(new OStatusbarController(Reference< XMultiServiceFactory >(xContext->getServiceManager(),UNO_QUERY)));
79 }
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 // -----------------------------------------------------------------------------
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         if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
109         {
110             m_pController = TStatusbarHelper::createFromQuery(new SvxZoomSliderControl(m_nSlotId = SID_ATTR_ZOOMSLIDER,m_nId,*pStatusBar));
111         } // if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
112         else if ( m_aCommandURL.equalsAscii(".uno:Zoom") )
113         {
114             m_pController = TStatusbarHelper::createFromQuery(new SvxZoomStatusBarControl(m_nSlotId = SID_ATTR_ZOOM,m_nId,*pStatusBar));
115         }
116 
117         if ( m_pController.is() )
118         {
119 	        m_pController->initialize(_rArguments);
120             m_pController->update();
121         }
122 
123         addStatusListener(m_aCommandURL);
124         update();
125     }
126 }
127 // XStatusListener
128 void SAL_CALL OStatusbarController::statusChanged( const FeatureStateEvent& _aEvent)throw ( RuntimeException )
129 {
130     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
131     ::osl::MutexGuard aGuard(m_aMutex);
132 
133     if ( m_pController.is() )
134     {
135         if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
136         {
137             Sequence< PropertyValue > aSeq;
138             if ( (_aEvent.State >>= aSeq) && aSeq.getLength() == 2 )
139             {
140                 SvxZoomSliderItem aZoomSlider(100,20,400);
141                 aZoomSlider.PutValue(_aEvent.State);
142                 static_cast<SvxZoomSliderControl*>(m_pController.get())->StateChanged(m_nSlotId,SFX_ITEM_AVAILABLE,&aZoomSlider);
143             }
144         } // if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
145         else if ( m_aCommandURL.equalsAscii(".uno:Zoom") )
146         {
147             Sequence< PropertyValue > aSeq;
148             if ( (_aEvent.State >>= aSeq) && aSeq.getLength() == 3 )
149             {
150                 SvxZoomItem aZoom;
151                 aZoom.PutValue(_aEvent.State);
152                 static_cast<SvxZoomStatusBarControl*>(m_pController.get())->StateChanged(m_nSlotId,SFX_ITEM_AVAILABLE,&aZoom);
153             }
154         }
155     }
156 }
157 
158 // XStatusbarController
159 ::sal_Bool SAL_CALL OStatusbarController::mouseButtonDown(const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
160 {
161     return m_pController.is() && m_pController.getRef()->mouseButtonDown(_aEvent);
162 }
163 
164 ::sal_Bool SAL_CALL OStatusbarController::mouseMove(    const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
165 {
166     return m_pController.is() && m_pController.getRef()->mouseMove(_aEvent);
167 }
168 
169 ::sal_Bool SAL_CALL OStatusbarController::mouseButtonUp(    const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
170 {
171     return m_pController.is() && m_pController.getRef()->mouseButtonUp(_aEvent);
172 }
173 
174 void SAL_CALL OStatusbarController::command(
175     const ::com::sun::star::awt::Point& aPos,
176     ::sal_Int32 nCommand,
177     ::sal_Bool bMouseEvent,
178     const ::com::sun::star::uno::Any& aData )
179 throw (::com::sun::star::uno::RuntimeException)
180 {
181     if ( m_pController.is() )
182         m_pController.getRef()->command( aPos, nCommand, bMouseEvent, aData );
183 }
184 
185 void SAL_CALL OStatusbarController::paint(
186     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >& xGraphics,
187     const ::com::sun::star::awt::Rectangle& rOutputRectangle,
188     ::sal_Int32 nItemId,
189     ::sal_Int32 nStyle )
190 throw (::com::sun::star::uno::RuntimeException)
191 {
192     if ( m_pController.is() )
193         m_pController.getRef()->paint( xGraphics, rOutputRectangle, nItemId, nStyle );
194 }
195 
196 void SAL_CALL OStatusbarController::click() throw (::com::sun::star::uno::RuntimeException)
197 {
198     if ( m_pController.is() )
199         m_pController.getRef()->click();
200 }
201 
202 void SAL_CALL OStatusbarController::doubleClick() throw (::com::sun::star::uno::RuntimeException)
203 {
204     if ( m_pController.is() )
205         m_pController.getRef()->doubleClick();
206 }
207 // -----------------------------------------------------------------------------
208 void SAL_CALL OStatusbarController::update() throw ( RuntimeException )
209 {
210     ::svt::StatusbarController::update();
211     Reference< XUpdatable > xUp(m_pController.getRef(),UNO_QUERY);
212     if ( xUp.is() )
213         xUp->update();
214 }
215 // -----------------------------------------------------------------------------
216 // XComponent
217 void SAL_CALL OStatusbarController::dispose() throw (::com::sun::star::uno::RuntimeException)
218 {
219     Reference< XComponent > xComp( m_pController.getRef(), UNO_QUERY );
220     ::comphelper::disposeComponent(xComp);
221     m_pController.dispose();
222     svt::StatusbarController::dispose();
223 }
224 // =============================================================================
225 } // rptui
226 // =============================================================================
227