Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / querydesign / limitboxcontroller.cxx
blob54a682e774825d0aaa436b0215e3edd8307a8d1c
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"
11 #include "uiservices.hxx"
13 #include <com/sun/star/frame/XDispatchProvider.hpp>
14 #include <com/sun/star/beans/PropertyValue.hpp>
16 #include <vcl/svapp.hxx>
17 #include <vcl/window.hxx>
18 #include <toolkit/helper/vclunohelper.hxx>
19 #include <osl/mutex.hxx>
20 #include <cppuhelper/queryinterface.hxx>
21 #include <comphelper/processfactory.hxx>
23 #include "LimitBox.hxx"
24 #include "dbu_reghelper.hxx"
25 #include "moduledbu.hxx"
28 using namespace ::com::sun::star;
30 namespace dbaui
33 class LimitBoxImpl: public LimitBox
35 public:
36 LimitBoxImpl( vcl::Window* pParent, LimitBoxController* pCtrl );
38 virtual bool Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
40 private:
41 LimitBoxController* m_pControl;
44 LimitBoxImpl::LimitBoxImpl( vcl::Window* pParent, LimitBoxController* pCtrl )
45 : LimitBox( pParent, WinBits( WB_DROPDOWN | WB_VSCROLL) )
46 , m_pControl( pCtrl )
50 bool LimitBoxImpl::Notify( NotifyEvent& rNEvt )
52 bool nHandled = false;
53 switch ( rNEvt.GetType() )
55 case MouseNotifyEvent::LOSEFOCUS:
57 nHandled = LimitBox::Notify( rNEvt );
58 uno::Sequence< beans::PropertyValue > aArgs( 1 );
59 aArgs[0].Name = "DBLimit.Value";
60 aArgs[0].Value = uno::makeAny( GetValue() );
61 m_pControl->dispatchCommand( aArgs );
62 break;
64 case MouseNotifyEvent::KEYINPUT:
66 const sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
67 switch ( nCode )
69 case KEY_ESCAPE:
70 Undo();
71 // fall-through
72 case KEY_RETURN:
73 GrabFocusToDocument();
74 nHandled = true;
75 break;
76 case KEY_TAB:
77 Select();
78 break;
80 break;
82 default:
83 break;
85 return nHandled || LimitBox::Notify( rNEvt );
89 LimitBoxController::LimitBoxController(
90 const uno::Reference< uno::XComponentContext >& rxContext ) :
91 svt::ToolboxController( rxContext,
92 uno::Reference< frame::XFrame >(),
93 OUString( ".uno:DBLimit" ) ),
94 m_pLimitBox( NULL )
98 LimitBoxController::~LimitBoxController()
102 /// XInterface
103 uno::Any SAL_CALL LimitBoxController::queryInterface( const uno::Type& aType )
104 throw (uno::RuntimeException, std::exception)
106 uno::Any a = ToolboxController::queryInterface( aType );
107 if ( a.hasValue() )
108 return a;
110 return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
113 void SAL_CALL LimitBoxController::acquire() throw ()
115 ToolboxController::acquire();
118 void SAL_CALL LimitBoxController::release() throw ()
120 ToolboxController::release();
124 /// XServiceInfo
125 IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(LimitBoxController, "org.libreoffice.comp.dbu.LimitBoxController")
126 IMPLEMENT_SERVICE_INFO_SUPPORTS(LimitBoxController)
127 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(LimitBoxController, "com.sun.star.frame.ToolbarController")
129 uno::Reference< uno::XInterface >
130 SAL_CALL LimitBoxController::Create(const uno::Reference< css::lang::XMultiServiceFactory >& _rxORB)
132 return static_cast< XServiceInfo* >(new LimitBoxController( comphelper::getComponentContext(_rxORB) ));
135 /// XComponent
136 void SAL_CALL LimitBoxController::dispose()
137 throw (uno::RuntimeException, std::exception)
139 svt::ToolboxController::dispose();
141 SolarMutexGuard aSolarMutexGuard;
142 m_pLimitBox.disposeAndClear();
145 /// XStatusListener
146 void SAL_CALL LimitBoxController::statusChanged(
147 const frame::FeatureStateEvent& rEvent )
148 throw ( uno::RuntimeException, std::exception )
150 if ( m_pLimitBox )
152 SolarMutexGuard aSolarMutexGuard;
153 if ( rEvent.FeatureURL.Path == "DBLimit" )
155 if ( rEvent.IsEnabled )
157 m_pLimitBox->Enable();
158 sal_Int64 nLimit = 0;
159 if ( (rEvent.State >>= nLimit) )
161 m_pLimitBox->SetValue( nLimit );
164 else
165 m_pLimitBox->Disable();
170 /// XToolbarController
171 void SAL_CALL LimitBoxController::execute( sal_Int16 /*KeyModifier*/ )
172 throw (uno::RuntimeException, std::exception)
176 void SAL_CALL LimitBoxController::click()
177 throw (uno::RuntimeException, std::exception)
181 void SAL_CALL LimitBoxController::doubleClick()
182 throw (uno::RuntimeException, std::exception)
186 uno::Reference< awt::XWindow > SAL_CALL LimitBoxController::createPopupWindow()
187 throw (uno::RuntimeException, std::exception)
189 return uno::Reference< awt::XWindow >();
192 uno::Reference< awt::XWindow > SAL_CALL LimitBoxController::createItemWindow(
193 const uno::Reference< awt::XWindow >& Parent )
194 throw (uno::RuntimeException, std::exception)
196 uno::Reference< awt::XWindow > xItemWindow;
197 uno::Reference< awt::XWindow > xParent( Parent );
199 vcl::Window* pParent = VCLUnoHelper::GetWindow( xParent );
200 if ( pParent )
202 SolarMutexGuard aSolarMutexGuard;
203 m_pLimitBox = VclPtr<LimitBoxImpl>::Create(pParent, this);
204 m_pLimitBox->SetSizePixel(m_pLimitBox->CalcBlockSize(6,1));
205 xItemWindow = VCLUnoHelper::GetInterface( m_pLimitBox );
208 return xItemWindow;
211 void LimitBoxController::dispatchCommand(
212 const uno::Sequence< beans::PropertyValue >& rArgs )
214 uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
215 if ( xDispatchProvider.is() )
217 util::URL aURL;
218 uno::Reference< frame::XDispatch > xDispatch;
219 uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
221 aURL.Complete = ".uno:DBLimit";
222 xURLTransformer->parseStrict( aURL );
223 xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
224 if ( xDispatch.is() )
225 xDispatch->dispatch( aURL, rArgs );
229 } ///dbaui namespace
231 extern "C" void SAL_CALL createRegistryInfo_LimitBoxController()
233 static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::LimitBoxController > aAutoRegistration;
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */