Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "statusbarcontroller.hxx"
21 :
22 : #include <svx/zoomsliderctrl.hxx>
23 : #include <svx/zoomctrl.hxx>
24 : #include <svx/svxids.hrc>
25 : #include <sfx2/zoomitem.hxx>
26 : #include <svx/zoomslideritem.hxx>
27 :
28 : #include <vcl/svapp.hxx>
29 : #include <vcl/status.hxx>
30 : #include <osl/mutex.hxx>
31 : #include <toolkit/helper/vclunohelper.hxx>
32 :
33 : namespace rptui
34 : {
35 : using namespace svt;
36 : using namespace com::sun::star::uno;
37 : using namespace com::sun::star::beans;
38 : using namespace com::sun::star::lang;
39 : using namespace ::com::sun::star::frame;
40 : using namespace ::com::sun::star::util;
41 :
42 0 : ::rtl::OUString SAL_CALL OStatusbarController::getImplementationName() throw( RuntimeException )
43 : {
44 0 : return getImplementationName_Static();
45 : }
46 :
47 : //------------------------------------------------------------------------------
48 0 : ::rtl::OUString OStatusbarController::getImplementationName_Static() throw( RuntimeException )
49 : {
50 0 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.comp.StatusbarController"));
51 : }
52 : //------------------------------------------------------------------------------
53 0 : Sequence< ::rtl::OUString> OStatusbarController::getSupportedServiceNames_Static(void) throw( RuntimeException )
54 : {
55 0 : Sequence< ::rtl::OUString> aSupported(1);
56 0 : aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.StatusbarController"));
57 0 : return aSupported;
58 : }
59 : // -----------------------------------------------------------------------------
60 0 : ::sal_Bool SAL_CALL OStatusbarController::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException)
61 : {
62 0 : return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_Static());
63 : }
64 : //-------------------------------------------------------------------------
65 0 : Sequence< ::rtl::OUString> SAL_CALL OStatusbarController::getSupportedServiceNames() throw(RuntimeException)
66 : {
67 0 : return getSupportedServiceNames_Static();
68 : }
69 : // -------------------------------------------------------------------------
70 0 : Reference< XInterface > OStatusbarController::create(Reference< XComponentContext > const & xContext)
71 : {
72 0 : return *(new OStatusbarController(Reference< XMultiServiceFactory >(xContext->getServiceManager(),UNO_QUERY)));
73 : }
74 0 : IMPLEMENT_FORWARD_XINTERFACE2(OStatusbarController, ::svt::StatusbarController,OStatusbarController_BASE)
75 :
76 0 : OStatusbarController::OStatusbarController(const Reference< XMultiServiceFactory >& _rxORB)
77 : : m_nSlotId(0)
78 0 : ,m_nId(1)
79 : {
80 0 : m_xServiceManager = _rxORB;
81 0 : }
82 : // -----------------------------------------------------------------------------
83 0 : void SAL_CALL OStatusbarController::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException)
84 : {
85 0 : StatusbarController::initialize(_rArguments);
86 0 : SolarMutexGuard aSolarMutexGuard;
87 0 : ::osl::MutexGuard aGuard(m_aMutex);
88 :
89 0 : StatusBar* pStatusBar = static_cast<StatusBar*>(VCLUnoHelper::GetWindow(m_xParentWindow));
90 0 : if ( pStatusBar )
91 : {
92 0 : const sal_uInt16 nCount = pStatusBar->GetItemCount();
93 0 : for (sal_uInt16 nPos = 0; nPos < nCount; ++nPos)
94 : {
95 0 : const sal_uInt16 nItemId = pStatusBar->GetItemId(nPos);
96 0 : if ( pStatusBar->GetItemCommand(nItemId) == String(m_aCommandURL) )
97 : {
98 0 : m_nId = nItemId;
99 0 : break;
100 : }
101 : }
102 0 : if ( m_aCommandURL == ".uno:ZoomSlider" )
103 : {
104 0 : m_pController = TStatusbarHelper::createFromQuery(new SvxZoomSliderControl(m_nSlotId = SID_ATTR_ZOOMSLIDER,m_nId,*pStatusBar));
105 : }
106 0 : else if ( m_aCommandURL == ".uno:Zoom" )
107 : {
108 0 : m_pController = TStatusbarHelper::createFromQuery(new SvxZoomStatusBarControl(m_nSlotId = SID_ATTR_ZOOM,m_nId,*pStatusBar));
109 : }
110 :
111 0 : if ( m_pController.is() )
112 : {
113 0 : m_pController->initialize(_rArguments);
114 0 : m_pController->update();
115 : }
116 :
117 0 : addStatusListener(m_aCommandURL);
118 0 : update();
119 0 : }
120 0 : }
121 : // XStatusListener
122 0 : void SAL_CALL OStatusbarController::statusChanged( const FeatureStateEvent& _aEvent)throw ( RuntimeException )
123 : {
124 0 : SolarMutexGuard aSolarGuard;
125 0 : ::osl::MutexGuard aGuard(m_aMutex);
126 :
127 0 : if ( m_pController.is() )
128 : {
129 0 : if ( m_aCommandURL == ".uno:ZoomSlider" )
130 : {
131 0 : Sequence< PropertyValue > aSeq;
132 0 : if ( (_aEvent.State >>= aSeq) && aSeq.getLength() == 2 )
133 : {
134 0 : SvxZoomSliderItem aZoomSlider(100,20,400);
135 0 : aZoomSlider.PutValue(_aEvent.State);
136 0 : static_cast<SvxZoomSliderControl*>(m_pController.get())->StateChanged(m_nSlotId,SFX_ITEM_AVAILABLE,&aZoomSlider);
137 0 : }
138 : }
139 0 : else if ( m_aCommandURL == ".uno:Zoom" )
140 : {
141 0 : Sequence< PropertyValue > aSeq;
142 0 : if ( (_aEvent.State >>= aSeq) && aSeq.getLength() == 3 )
143 : {
144 0 : SvxZoomItem aZoom;
145 0 : aZoom.PutValue(_aEvent.State);
146 0 : static_cast<SvxZoomStatusBarControl*>(m_pController.get())->StateChanged(m_nSlotId,SFX_ITEM_AVAILABLE,&aZoom);
147 0 : }
148 : }
149 0 : }
150 0 : }
151 :
152 : // XStatusbarController
153 0 : ::sal_Bool SAL_CALL OStatusbarController::mouseButtonDown(const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
154 : {
155 0 : return m_pController.is() && m_pController.getRef()->mouseButtonDown(_aEvent);
156 : }
157 :
158 0 : ::sal_Bool SAL_CALL OStatusbarController::mouseMove( const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
159 : {
160 0 : return m_pController.is() && m_pController.getRef()->mouseMove(_aEvent);
161 : }
162 :
163 0 : ::sal_Bool SAL_CALL OStatusbarController::mouseButtonUp( const ::com::sun::star::awt::MouseEvent& _aEvent)throw (::com::sun::star::uno::RuntimeException)
164 : {
165 0 : return m_pController.is() && m_pController.getRef()->mouseButtonUp(_aEvent);
166 : }
167 :
168 0 : void SAL_CALL OStatusbarController::command(
169 : const ::com::sun::star::awt::Point& aPos,
170 : ::sal_Int32 nCommand,
171 : ::sal_Bool bMouseEvent,
172 : const ::com::sun::star::uno::Any& aData )
173 : throw (::com::sun::star::uno::RuntimeException)
174 : {
175 0 : if ( m_pController.is() )
176 0 : m_pController.getRef()->command( aPos, nCommand, bMouseEvent, aData );
177 0 : }
178 :
179 0 : void SAL_CALL OStatusbarController::paint(
180 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >& xGraphics,
181 : const ::com::sun::star::awt::Rectangle& rOutputRectangle,
182 : ::sal_Int32 nItemId,
183 : ::sal_Int32 nStyle )
184 : throw (::com::sun::star::uno::RuntimeException)
185 : {
186 0 : if ( m_pController.is() )
187 0 : m_pController.getRef()->paint( xGraphics, rOutputRectangle, nItemId, nStyle );
188 0 : }
189 :
190 0 : void SAL_CALL OStatusbarController::click() throw (::com::sun::star::uno::RuntimeException)
191 : {
192 0 : if ( m_pController.is() )
193 0 : m_pController.getRef()->click();
194 0 : }
195 :
196 0 : void SAL_CALL OStatusbarController::doubleClick() throw (::com::sun::star::uno::RuntimeException)
197 : {
198 0 : if ( m_pController.is() )
199 0 : m_pController.getRef()->doubleClick();
200 0 : }
201 : // -----------------------------------------------------------------------------
202 0 : void SAL_CALL OStatusbarController::update() throw ( RuntimeException )
203 : {
204 0 : ::svt::StatusbarController::update();
205 0 : Reference< XUpdatable > xUp(m_pController.getRef(),UNO_QUERY);
206 0 : if ( xUp.is() )
207 0 : xUp->update();
208 0 : }
209 : // -----------------------------------------------------------------------------
210 : // XComponent
211 0 : void SAL_CALL OStatusbarController::dispose() throw (::com::sun::star::uno::RuntimeException)
212 : {
213 0 : Reference< XComponent > xComp( m_pController.getRef(), UNO_QUERY );
214 0 : ::comphelper::disposeComponent(xComp);
215 0 : m_pController.dispose();
216 0 : svt::StatusbarController::dispose();
217 0 : }
218 : // =============================================================================
219 : } // rptui
220 : // =============================================================================
221 :
222 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|