1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_reportdesign.hxx"
30 #include "statusbarcontroller.hxx"
31 
32 #include <svx/zoomsliderctrl.hxx>
33 #include <svx/zoomctrl.hxx>
34 #include <svx/svxids.hrc>
35 #include <svx/zoomitem.hxx>
36 #include <svx/zoomslideritem.hxx>
37 
38 #include <vcl/svapp.hxx>
39 #include <vcl/status.hxx>
40 #include <vos/mutex.hxx>
41 #include <toolkit/helper/vclunohelper.hxx>
42 
43 namespace rptui
44 {
45 	using namespace svt;
46 	using namespace com::sun::star::uno;
47 	using namespace com::sun::star::beans;
48 	using namespace com::sun::star::lang;
49 	using namespace ::com::sun::star::frame;
50 	using namespace ::com::sun::star::util;
51 
52 ::rtl::OUString SAL_CALL OStatusbarController::getImplementationName() throw( RuntimeException )
53 {
54 	return getImplementationName_Static();
55 }
56 
57 //------------------------------------------------------------------------------
58 ::rtl::OUString OStatusbarController::getImplementationName_Static() throw( RuntimeException )
59 {
60 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.comp.StatusbarController"));
61 }
62 //------------------------------------------------------------------------------
63 Sequence< ::rtl::OUString> OStatusbarController::getSupportedServiceNames_Static(void) throw( RuntimeException )
64 {
65 	Sequence< ::rtl::OUString> aSupported(1);
66 	aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.StatusbarController"));
67 	return aSupported;
68 }
69 // -----------------------------------------------------------------------------
70 ::sal_Bool SAL_CALL OStatusbarController::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException)
71 {
72     return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_Static());
73 }
74 //-------------------------------------------------------------------------
75 Sequence< ::rtl::OUString> SAL_CALL OStatusbarController::getSupportedServiceNames() throw(RuntimeException)
76 {
77 	return getSupportedServiceNames_Static();
78 }
79 // -------------------------------------------------------------------------
80 Reference< XInterface > OStatusbarController::create(Reference< XComponentContext > const & xContext)
81 {
82 	return *(new OStatusbarController(Reference< XMultiServiceFactory >(xContext->getServiceManager(),UNO_QUERY)));
83 }
84 IMPLEMENT_FORWARD_XINTERFACE2(OStatusbarController, ::svt::StatusbarController,OStatusbarController_BASE)
85 
86 OStatusbarController::OStatusbarController(const Reference< XMultiServiceFactory >& _rxORB)
87 : m_nSlotId(0)
88 ,m_nId(1)
89 {
90     m_xServiceManager = _rxORB;
91 }
92 // -----------------------------------------------------------------------------
93 void SAL_CALL OStatusbarController::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException)
94 {
95 	StatusbarController::initialize(_rArguments);
96 	vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
97 	::osl::MutexGuard aGuard(m_aMutex);
98 
99     StatusBar* pStatusBar = static_cast<StatusBar*>(VCLUnoHelper::GetWindow(m_xParentWindow));
100     if ( pStatusBar )
101     {
102         const sal_uInt16 nCount = pStatusBar->GetItemCount();
103 	    for (sal_uInt16 nPos = 0; nPos < nCount; ++nPos)
104 	    {
105 		    const sal_uInt16 nItemId = pStatusBar->GetItemId(nPos);
106 		    if ( pStatusBar->GetItemCommand(nItemId) == String(m_aCommandURL) )
107 		    {
108 			    m_nId = nItemId;
109 			    break;
110 		    }
111 	    }
112         if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
113         {
114             m_pController = TStatusbarHelper::createFromQuery(new SvxZoomSliderControl(m_nSlotId = SID_ATTR_ZOOMSLIDER,m_nId,*pStatusBar));
115         } // if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
116         else if ( m_aCommandURL.equalsAscii(".uno:Zoom") )
117         {
118             m_pController = TStatusbarHelper::createFromQuery(new SvxZoomStatusBarControl(m_nSlotId = SID_ATTR_ZOOM,m_nId,*pStatusBar));
119         }
120 
121         if ( m_pController.is() )
122         {
123 	        m_pController->initialize(_rArguments);
124             m_pController->update();
125         }
126 
127         addStatusListener(m_aCommandURL);
128         update();
129     }
130 }
131 // XStatusListener
132 void SAL_CALL OStatusbarController::statusChanged( const FeatureStateEvent& _aEvent)throw ( RuntimeException )
133 {
134     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
135     ::osl::MutexGuard aGuard(m_aMutex);
136 
137     if ( m_pController.is() )
138     {
139         if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
140         {
141             Sequence< PropertyValue > aSeq;
142             if ( (_aEvent.State >>= aSeq) && aSeq.getLength() == 2 )
143             {
144                 SvxZoomSliderItem aZoomSlider(100,20,400);
145                 aZoomSlider.PutValue(_aEvent.State);
146                 static_cast<SvxZoomSliderControl*>(m_pController.get())->StateChanged(m_nSlotId,SFX_ITEM_AVAILABLE,&aZoomSlider);
147             }
148         } // if ( m_aCommandURL.equalsAscii(".uno:ZoomSlider") )
149         else if ( m_aCommandURL.equalsAscii(".uno:Zoom") )
150         {
151             Sequence< PropertyValue > aSeq;
152             if ( (_aEvent.State >>= aSeq) && aSeq.getLength() == 3 )
153             {
154                 SvxZoomItem aZoom;
155                 aZoom.PutValue(_aEvent.State);
156                 static_cast<SvxZoomStatusBarControl*>(m_pController.get())->StateChanged(m_nSlotId,SFX_ITEM_AVAILABLE,&aZoom);
157             }
158         }
159     }
160 }
161 
162 // XStatusbarController
163 ::sal_Bool SAL_CALL OStatusbarController::mouseButtonDown(const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
164 {
165     return m_pController.is() && m_pController.getRef()->mouseButtonDown(_aEvent);
166 }
167 
168 ::sal_Bool SAL_CALL OStatusbarController::mouseMove(    const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
169 {
170     return m_pController.is() && m_pController.getRef()->mouseMove(_aEvent);
171 }
172 
173 ::sal_Bool SAL_CALL OStatusbarController::mouseButtonUp(    const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
174 {
175     return m_pController.is() && m_pController.getRef()->mouseButtonUp(_aEvent);
176 }
177 
178 void SAL_CALL OStatusbarController::command(
179     const ::com::sun::star::awt::Point& aPos,
180     ::sal_Int32 nCommand,
181     ::sal_Bool bMouseEvent,
182     const ::com::sun::star::uno::Any& aData )
183 throw (::com::sun::star::uno::RuntimeException)
184 {
185     if ( m_pController.is() )
186         m_pController.getRef()->command( aPos, nCommand, bMouseEvent, aData );
187 }
188 
189 void SAL_CALL OStatusbarController::paint(
190     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >& xGraphics,
191     const ::com::sun::star::awt::Rectangle& rOutputRectangle,
192     ::sal_Int32 nItemId,
193     ::sal_Int32 nStyle )
194 throw (::com::sun::star::uno::RuntimeException)
195 {
196     if ( m_pController.is() )
197         m_pController.getRef()->paint( xGraphics, rOutputRectangle, nItemId, nStyle );
198 }
199 
200 void SAL_CALL OStatusbarController::click() throw (::com::sun::star::uno::RuntimeException)
201 {
202     if ( m_pController.is() )
203         m_pController.getRef()->click();
204 }
205 
206 void SAL_CALL OStatusbarController::doubleClick() throw (::com::sun::star::uno::RuntimeException)
207 {
208     if ( m_pController.is() )
209         m_pController.getRef()->doubleClick();
210 }
211 // -----------------------------------------------------------------------------
212 void SAL_CALL OStatusbarController::update() throw ( RuntimeException )
213 {
214     ::svt::StatusbarController::update();
215     Reference< XUpdatable > xUp(m_pController.getRef(),UNO_QUERY);
216     if ( xUp.is() )
217         xUp->update();
218 }
219 // -----------------------------------------------------------------------------
220 // XComponent
221 void SAL_CALL OStatusbarController::dispose() throw (::com::sun::star::uno::RuntimeException)
222 {
223     Reference< XComponent > xComp( m_pController.getRef(), UNO_QUERY );
224     ::comphelper::disposeComponent(xComp);
225     m_pController.dispose();
226     svt::StatusbarController::dispose();
227 }
228 // =============================================================================
229 } // rptui
230 // =============================================================================
231