bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / ui / querydesign / limitboxcontroller.cxx
blob63724e5a4d31a4a3568abadea08fad48d6e9f244
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "limitboxcontroller.hxx"
12 #include <com/sun/star/frame/XDispatchProvider.hpp>
13 #include <com/sun/star/beans/PropertyValue.hpp>
15 #include <vcl/svapp.hxx>
16 #include <vcl/window.hxx>
17 #include <toolkit/helper/vclunohelper.hxx>
18 #include <osl/mutex.hxx>
19 #include <comphelper/processfactory.hxx>
21 #include "LimitBox.hxx"
22 #include "dbu_reghelper.hxx"
23 #include "moduledbu.hxx"
26 using namespace ::com::sun::star;
28 namespace dbaui
31 class LimitBoxImpl: public LimitBox
33 public:
34 LimitBoxImpl( Window* pParent, LimitBoxController* pCtrl );
35 virtual ~LimitBoxImpl();
37 virtual long Notify( NotifyEvent& rNEvt );
39 private:
40 LimitBoxController* m_pControl;
43 LimitBoxImpl::LimitBoxImpl( Window* pParent, LimitBoxController* pCtrl )
44 : LimitBox( pParent, WinBits( WB_DROPDOWN | WB_VSCROLL) )
45 , m_pControl( pCtrl )
49 LimitBoxImpl::~LimitBoxImpl()
53 long LimitBoxImpl::Notify( NotifyEvent& rNEvt )
55 long nHandled = 0;
56 switch ( rNEvt.GetType() )
58 case EVENT_LOSEFOCUS:
60 nHandled = LimitBox::Notify( rNEvt );
61 uno::Sequence< beans::PropertyValue > aArgs( 1 );
62 aArgs[0].Name = OUString( "DBLimit.Value" );
63 aArgs[0].Value = uno::makeAny( GetValue() );
64 m_pControl->dispatchCommand( aArgs );
65 break;
67 case EVENT_KEYINPUT:
69 const sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
70 switch ( nCode )
72 case KEY_ESCAPE:
74 Undo();
76 case KEY_RETURN:
78 GrabFocusToDocument();
79 nHandled = 1;
80 break;
82 case KEY_TAB:
84 Select();
85 break;
88 break;
91 return nHandled ? nHandled : LimitBox::Notify( rNEvt );
95 LimitBoxController::LimitBoxController(
96 const uno::Reference< uno::XComponentContext >& rxContext ) :
97 svt::ToolboxController( rxContext,
98 uno::Reference< frame::XFrame >(),
99 OUString( ".uno:DBLimit" ) ),
100 m_pLimitBox( NULL )
104 LimitBoxController::~LimitBoxController()
108 /// XInterface
109 uno::Any SAL_CALL LimitBoxController::queryInterface( const uno::Type& aType )
110 throw (uno::RuntimeException)
112 uno::Any a = ToolboxController::queryInterface( aType );
113 if ( a.hasValue() )
114 return a;
116 return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
119 void SAL_CALL LimitBoxController::acquire() throw ()
121 ToolboxController::acquire();
124 void SAL_CALL LimitBoxController::release() throw ()
126 ToolboxController::release();
130 /// XServiceInfo
131 IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(LimitBoxController, "org.libreoffice.comp.dbu.LimitBoxController")
132 IMPLEMENT_SERVICE_INFO_SUPPORTS(LimitBoxController)
133 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(LimitBoxController, "com.sun.star.frame.ToolboxController")
135 uno::Reference< uno::XInterface >
136 SAL_CALL LimitBoxController::Create(const uno::Reference< css::lang::XMultiServiceFactory >& _rxORB)
138 return static_cast< XServiceInfo* >(new LimitBoxController( comphelper::getComponentContext(_rxORB) ));
141 /// XComponent
142 void SAL_CALL LimitBoxController::dispose()
143 throw (uno::RuntimeException)
145 svt::ToolboxController::dispose();
147 SolarMutexGuard aSolarMutexGuard;
148 delete m_pLimitBox;
149 m_pLimitBox = 0;
152 /// XStatusListener
153 void SAL_CALL LimitBoxController::statusChanged(
154 const frame::FeatureStateEvent& rEvent )
155 throw ( uno::RuntimeException )
157 if ( m_pLimitBox )
159 SolarMutexGuard aSolarMutexGuard;
160 if ( rEvent.FeatureURL.Path == "DBLimit" )
162 if ( rEvent.IsEnabled )
164 m_pLimitBox->Enable();
165 sal_Int64 nLimit = 0;
166 if ( (rEvent.State >>= nLimit) )
168 m_pLimitBox->SetValue( nLimit );
171 else
172 m_pLimitBox->Disable();
177 /// XToolbarController
178 void SAL_CALL LimitBoxController::execute( sal_Int16 /*KeyModifier*/ )
179 throw (uno::RuntimeException)
183 void SAL_CALL LimitBoxController::click()
184 throw (uno::RuntimeException)
188 void SAL_CALL LimitBoxController::doubleClick()
189 throw (uno::RuntimeException)
193 uno::Reference< awt::XWindow > SAL_CALL LimitBoxController::createPopupWindow()
194 throw (uno::RuntimeException)
196 return uno::Reference< awt::XWindow >();
199 uno::Reference< awt::XWindow > SAL_CALL LimitBoxController::createItemWindow(
200 const uno::Reference< awt::XWindow >& Parent )
201 throw (uno::RuntimeException)
203 uno::Reference< awt::XWindow > xItemWindow;
204 uno::Reference< awt::XWindow > xParent( Parent );
206 Window* pParent = VCLUnoHelper::GetWindow( xParent );
207 if ( pParent )
209 SolarMutexGuard aSolarMutexGuard;
210 m_pLimitBox = new LimitBoxImpl(pParent, this);
211 m_pLimitBox->SetSizePixel(m_pLimitBox->CalcSize(6,1));
212 xItemWindow = VCLUnoHelper::GetInterface( m_pLimitBox );
215 return xItemWindow;
218 void LimitBoxController::dispatchCommand(
219 const uno::Sequence< beans::PropertyValue >& rArgs )
221 uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
222 if ( xDispatchProvider.is() )
224 util::URL aURL;
225 uno::Reference< frame::XDispatch > xDispatch;
226 uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
228 aURL.Complete = OUString( ".uno:DBLimit" );
229 xURLTransformer->parseStrict( aURL );
230 xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
231 if ( xDispatch.is() )
232 xDispatch->dispatch( aURL, rArgs );
236 } ///dbaui namespace
238 extern "C" void SAL_CALL createRegistryInfo_LimitBoxController()
240 static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::LimitBoxController > aAutoRegistration;
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */