1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
;
31 class LimitBoxImpl
: public LimitBox
34 LimitBoxImpl( Window
* pParent
, LimitBoxController
* pCtrl
);
35 virtual ~LimitBoxImpl();
37 virtual long Notify( NotifyEvent
& rNEvt
);
40 LimitBoxController
* m_pControl
;
43 LimitBoxImpl::LimitBoxImpl( Window
* pParent
, LimitBoxController
* pCtrl
)
44 : LimitBox( pParent
, WinBits( WB_DROPDOWN
| WB_VSCROLL
) )
49 LimitBoxImpl::~LimitBoxImpl()
53 long LimitBoxImpl::Notify( NotifyEvent
& rNEvt
)
56 switch ( rNEvt
.GetType() )
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
);
69 const sal_uInt16 nCode
= rNEvt
.GetKeyEvent()->GetKeyCode().GetCode();
78 GrabFocusToDocument();
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" ) ),
104 LimitBoxController::~LimitBoxController()
109 uno::Any SAL_CALL
LimitBoxController::queryInterface( const uno::Type
& aType
)
110 throw (uno::RuntimeException
)
112 uno::Any a
= ToolboxController::queryInterface( aType
);
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();
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
) ));
142 void SAL_CALL
LimitBoxController::dispose()
143 throw (uno::RuntimeException
)
145 svt::ToolboxController::dispose();
147 SolarMutexGuard aSolarMutexGuard
;
153 void SAL_CALL
LimitBoxController::statusChanged(
154 const frame::FeatureStateEvent
& rEvent
)
155 throw ( uno::RuntimeException
)
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
);
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
);
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
);
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() )
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
);
238 extern "C" void SAL_CALL
createRegistryInfo_LimitBoxController()
240 static ::dbaui::OMultiInstanceAutoRegistration
< ::dbaui::LimitBoxController
> aAutoRegistration
;
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */