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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "navbarcontrol.hxx"
22 #include <frm_strings.hxx>
23 #include <componenttools.hxx>
24 #include <navtoolbar.hxx>
25 #include <commandimageprovider.hxx>
27 #include <com/sun/star/awt/XView.hpp>
28 #include <com/sun/star/awt/PosSize.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/form/runtime/FormFeature.hpp>
31 #include <com/sun/star/awt/XControlModel.hpp>
32 #include <com/sun/star/frame/ModuleManager.hpp>
34 #include <tools/debug.hxx>
35 #include <comphelper/diagnose_ex.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/settings.hxx>
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::beans
;
45 using namespace ::com::sun::star::awt
;
46 using namespace ::com::sun::star::lang
;
47 using namespace ::com::sun::star::frame
;
48 using namespace ::com::sun::star::graphic
;
49 namespace FormFeature
= ::com::sun::star::form::runtime::FormFeature
;
51 ONavigationBarControl::ONavigationBarControl( const Reference
< XComponentContext
>& _rxORB
)
57 ONavigationBarControl::~ONavigationBarControl()
62 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarControl
, UnoControl
, ONavigationBarControl_Base
)
65 Any SAL_CALL
ONavigationBarControl::queryAggregation( const Type
& _rType
)
67 Any aReturn
= UnoControl::queryAggregation( _rType
);
69 if ( !aReturn
.hasValue() )
70 aReturn
= ONavigationBarControl_Base::queryInterface( _rType
);
79 WinBits
lcl_getWinBits_nothrow( const Reference
< XControlModel
>& _rxModel
)
84 Reference
< XPropertySet
> xProps( _rxModel
, UNO_QUERY
);
87 sal_Int16 nBorder
= 0;
88 xProps
->getPropertyValue( PROPERTY_BORDER
) >>= nBorder
;
92 bool bTabStop
= false;
93 if ( xProps
->getPropertyValue( PROPERTY_TABSTOP
) >>= bTabStop
)
94 nBits
|= ( bTabStop
? WB_TABSTOP
: WB_NOTABSTOP
);
97 catch( const Exception
& )
99 DBG_UNHANDLED_EXCEPTION("forms.component");
106 void SAL_CALL
ONavigationBarControl::createPeer( const Reference
< XToolkit
>& /*_rToolkit*/, const Reference
< XWindowPeer
>& _rParentPeer
)
108 SolarMutexGuard aGuard
;
113 mbCreatingPeer
= true;
115 // determine the VCL window for the parent
116 vcl::Window
* pParentWin
= nullptr;
117 if ( _rParentPeer
.is() )
119 VCLXWindow
* pParentXWin
= dynamic_cast<VCLXWindow
*>( _rParentPeer
.get() );
121 pParentWin
= pParentXWin
->GetWindow();
122 DBG_ASSERT( pParentWin
, "ONavigationBarControl::createPeer: could not obtain the VCL-level parent window!" );
126 rtl::Reference
<ONavigationBarPeer
> pPeer
= ONavigationBarPeer::Create( m_xContext
, pParentWin
, getModel() );
127 assert(pPeer
&& "ONavigationBarControl::createPeer: invalid peer returned!");
129 // announce the peer to the base class
132 // initialize ourself (and thus the peer) with the model properties
135 Reference
< XView
> xPeerView( getPeer(), UNO_QUERY
);
136 if ( xPeerView
.is() )
138 xPeerView
->setZoom( maComponentInfos
.nZoomX
, maComponentInfos
.nZoomY
);
139 xPeerView
->setGraphics( mxGraphics
);
142 // a lot of initial settings from our component infos
143 setPosSize( maComponentInfos
.nX
, maComponentInfos
.nY
, maComponentInfos
.nWidth
, maComponentInfos
.nHeight
, PosSize::POSSIZE
);
145 pPeer
->setVisible ( maComponentInfos
.bVisible
&& !mbDesignMode
);
146 pPeer
->setEnable ( maComponentInfos
.bEnable
);
147 pPeer
->setDesignMode( mbDesignMode
);
151 mbCreatingPeer
= false;
155 OUString SAL_CALL
ONavigationBarControl::getImplementationName()
157 return "com.sun.star.comp.form.ONavigationBarControl";
161 Sequence
< OUString
> SAL_CALL
ONavigationBarControl::getSupportedServiceNames()
163 return { "com.sun.star.awt.UnoControl",
164 "com.sun.star.form.control.NavigationToolBar" };
168 void SAL_CALL
ONavigationBarControl::registerDispatchProviderInterceptor( const Reference
< XDispatchProviderInterceptor
>& _rxInterceptor
)
170 Reference
< XDispatchProviderInterception
> xTypedPeer(getPeer(), UNO_QUERY
);
173 xTypedPeer
->registerDispatchProviderInterceptor(_rxInterceptor
);
178 void SAL_CALL
ONavigationBarControl::releaseDispatchProviderInterceptor( const Reference
< XDispatchProviderInterceptor
>& _rxInterceptor
)
180 Reference
< XDispatchProviderInterception
> xTypedPeer(getPeer(), UNO_QUERY
);
183 xTypedPeer
->releaseDispatchProviderInterceptor(_rxInterceptor
);
188 void SAL_CALL
ONavigationBarControl::setDesignMode( sal_Bool _bOn
)
190 UnoControl::setDesignMode( _bOn
);
191 Reference
< XVclWindowPeer
> xTypedPeer(getPeer(), UNO_QUERY
);
194 xTypedPeer
->setDesignMode(_bOn
);
199 // ONavigationBarPeer
202 rtl::Reference
<ONavigationBarPeer
> ONavigationBarPeer::Create( const Reference
< XComponentContext
>& _rxORB
,
203 vcl::Window
* _pParentWindow
, const Reference
< XControlModel
>& _rxModel
)
205 DBG_TESTSOLARMUTEX();
208 rtl::Reference
<ONavigationBarPeer
> pPeer(new ONavigationBarPeer( _rxORB
));
210 // the VCL control for the peer
211 Reference
< XModel
> xContextDocument( getXModel( _rxModel
) );
212 Reference
< XModuleManager2
> xModuleManager( ModuleManager::create(_rxORB
) );
213 OUString sModuleID
= xModuleManager
->identify( xContextDocument
);
215 VclPtrInstance
<NavigationToolBar
> pNavBar(
217 lcl_getWinBits_nothrow( _rxModel
),
218 std::make_shared
<DocumentCommandImageProvider
>( _rxORB
, xContextDocument
),
223 pNavBar
->setDispatcher( pPeer
.get() );
224 pNavBar
->SetComponentInterface( pPeer
);
226 // we want a faster repeating rate for the slots in this
228 AllSettings aSettings
= pNavBar
->GetSettings();
229 MouseSettings aMouseSettings
= aSettings
.GetMouseSettings();
230 aMouseSettings
.SetButtonRepeat( 10 );
231 aSettings
.SetMouseSettings( aMouseSettings
);
232 pNavBar
->SetSettings( aSettings
, true );
239 ONavigationBarPeer::ONavigationBarPeer( const Reference
< XComponentContext
>& _rxORB
)
240 :OFormNavigationHelper( _rxORB
)
245 ONavigationBarPeer::~ONavigationBarPeer()
250 IMPLEMENT_FORWARD_XINTERFACE2( ONavigationBarPeer
, VCLXWindow
, OFormNavigationHelper
)
253 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarPeer
, VCLXWindow
, OFormNavigationHelper
)
256 void SAL_CALL
ONavigationBarPeer::dispose( )
258 VCLXWindow::dispose();
259 OFormNavigationHelper::dispose();
263 void SAL_CALL
ONavigationBarPeer::setProperty( const OUString
& _rPropertyName
, const Any
& _rValue
)
265 SolarMutexGuard aGuard
;
267 VclPtr
< NavigationToolBar
> pNavBar
= GetAs
< NavigationToolBar
>();
270 VCLXWindow::setProperty( _rPropertyName
, _rValue
);
274 bool bVoid
= !_rValue
.hasValue();
276 bool bBoolValue
= false;
277 Color nColor
= COL_TRANSPARENT
;
279 // TODO: more generic mechanisms for this (the grid control implementation,
280 // when used herein, will do the same stuff for lot of these)
282 if ( _rPropertyName
== PROPERTY_BACKGROUNDCOLOR
)
286 pNavBar
->SetBackground( pNavBar
->GetSettings().GetStyleSettings().GetFaceColor() );
287 pNavBar
->SetControlBackground();
291 OSL_VERIFY( _rValue
>>= nColor
);
292 Color
aColor( nColor
);
293 pNavBar
->SetBackground( aColor
);
294 pNavBar
->SetControlBackground( aColor
);
297 else if ( _rPropertyName
== PROPERTY_TEXTLINECOLOR
)
301 pNavBar
->SetTextLineColor();
305 OSL_VERIFY( _rValue
>>= nColor
);
306 pNavBar
->SetTextLineColor( nColor
);
309 else if ( _rPropertyName
== PROPERTY_ICONSIZE
)
311 sal_Int16 nInt16Value
= 0;
312 OSL_VERIFY( _rValue
>>= nInt16Value
);
313 pNavBar
->SetImageSize( nInt16Value
? NavigationToolBar::eLarge
: NavigationToolBar::eSmall
);
315 else if ( _rPropertyName
== PROPERTY_SHOW_POSITION
)
317 OSL_VERIFY( _rValue
>>= bBoolValue
);
318 pNavBar
->ShowFunctionGroup( NavigationToolBar::ePosition
, bBoolValue
);
320 else if ( _rPropertyName
== PROPERTY_SHOW_NAVIGATION
)
322 OSL_VERIFY( _rValue
>>= bBoolValue
);
323 pNavBar
->ShowFunctionGroup( NavigationToolBar::eNavigation
, bBoolValue
);
325 else if ( _rPropertyName
== PROPERTY_SHOW_RECORDACTIONS
)
327 OSL_VERIFY( _rValue
>>= bBoolValue
);
328 pNavBar
->ShowFunctionGroup( NavigationToolBar::eRecordActions
, bBoolValue
);
330 else if ( _rPropertyName
== PROPERTY_SHOW_FILTERSORT
)
332 OSL_VERIFY( _rValue
>>= bBoolValue
);
333 pNavBar
->ShowFunctionGroup( NavigationToolBar::eFilterSort
, bBoolValue
);
337 VCLXWindow::setProperty( _rPropertyName
, _rValue
);
342 Any SAL_CALL
ONavigationBarPeer::getProperty( const OUString
& _rPropertyName
)
344 SolarMutexGuard aGuard
;
347 VclPtr
< NavigationToolBar
> pNavBar
= GetAs
< NavigationToolBar
>();
349 if ( _rPropertyName
== PROPERTY_BACKGROUNDCOLOR
)
351 aReturn
<<= pNavBar
->GetControlBackground();
353 else if ( _rPropertyName
== PROPERTY_TEXTLINECOLOR
)
355 aReturn
<<= pNavBar
->GetTextLineColor();
357 else if ( _rPropertyName
== PROPERTY_ICONSIZE
)
359 sal_Int16 nIconType
= ( NavigationToolBar::eLarge
== pNavBar
->GetImageSize() )
361 aReturn
<<= nIconType
;
363 else if ( _rPropertyName
== PROPERTY_SHOW_POSITION
)
365 aReturn
<<= pNavBar
->IsFunctionGroupVisible( NavigationToolBar::ePosition
);
367 else if ( _rPropertyName
== PROPERTY_SHOW_NAVIGATION
)
369 aReturn
<<= pNavBar
->IsFunctionGroupVisible( NavigationToolBar::eNavigation
);
371 else if ( _rPropertyName
== PROPERTY_SHOW_RECORDACTIONS
)
373 aReturn
<<= pNavBar
->IsFunctionGroupVisible( NavigationToolBar::eRecordActions
);
375 else if ( _rPropertyName
== PROPERTY_SHOW_FILTERSORT
)
377 aReturn
<<= pNavBar
->IsFunctionGroupVisible( NavigationToolBar::eFilterSort
);
380 aReturn
= VCLXWindow::getProperty( _rPropertyName
);
386 void ONavigationBarPeer::interceptorsChanged( )
388 if ( isDesignMode() )
389 // not interested in if we're in design mode
392 OFormNavigationHelper::interceptorsChanged();
396 void ONavigationBarPeer::featureStateChanged( sal_Int16 _nFeatureId
, bool _bEnabled
)
398 // enable this button on the toolbox
399 VclPtr
< NavigationToolBar
> pNavBar
= GetAs
< NavigationToolBar
>();
402 pNavBar
->enableFeature( _nFeatureId
, _bEnabled
);
404 // is it a feature with additional state information?
405 if ( _nFeatureId
== FormFeature::ToggleApplyFilter
)
406 { // additional boolean state
407 pNavBar
->checkFeature( _nFeatureId
, getBooleanState( _nFeatureId
) );
409 else if ( _nFeatureId
== FormFeature::TotalRecords
)
411 pNavBar
->setFeatureText( _nFeatureId
, getStringState( _nFeatureId
) );
413 else if ( _nFeatureId
== FormFeature::MoveAbsolute
)
415 pNavBar
->setFeatureText( _nFeatureId
, OUString::number(getIntegerState(_nFeatureId
)) );
420 OFormNavigationHelper::featureStateChanged( _nFeatureId
, _bEnabled
);
424 void ONavigationBarPeer::allFeatureStatesChanged( )
427 // force the control to update it's states
429 VclPtr
< NavigationToolBar
> pNavBar
= GetAs
< NavigationToolBar
>();
431 pNavBar
->setDispatcher( this );
435 OFormNavigationHelper::allFeatureStatesChanged( );
439 bool ONavigationBarPeer::isEnabled( sal_Int16 _nFeatureId
) const
441 if ( const_cast< ONavigationBarPeer
* >( this )->isDesignMode() )
444 return OFormNavigationHelper::isEnabled( _nFeatureId
);
448 void SAL_CALL
ONavigationBarPeer::setDesignMode( sal_Bool _bOn
)
450 VCLXWindow::setDesignMode( _bOn
);
453 disconnectDispatchers();
455 connectDispatchers();
456 // this will connect if not already connected and just update else
460 void SAL_CALL
ONavigationBarPeer::disposing( const EventObject
& _rSource
)
462 VCLXWindow::disposing( _rSource
);
463 OFormNavigationHelper::disposing( _rSource
);
467 void ONavigationBarPeer::getSupportedFeatures( ::std::vector
< sal_Int16
>& _rFeatureIds
)
469 _rFeatureIds
.push_back( FormFeature::MoveAbsolute
);
470 _rFeatureIds
.push_back( FormFeature::TotalRecords
);
471 _rFeatureIds
.push_back( FormFeature::MoveToFirst
);
472 _rFeatureIds
.push_back( FormFeature::MoveToPrevious
);
473 _rFeatureIds
.push_back( FormFeature::MoveToNext
);
474 _rFeatureIds
.push_back( FormFeature::MoveToLast
);
475 _rFeatureIds
.push_back( FormFeature::SaveRecordChanges
);
476 _rFeatureIds
.push_back( FormFeature::UndoRecordChanges
);
477 _rFeatureIds
.push_back( FormFeature::MoveToInsertRow
);
478 _rFeatureIds
.push_back( FormFeature::DeleteRecord
);
479 _rFeatureIds
.push_back( FormFeature::ReloadForm
);
480 _rFeatureIds
.push_back( FormFeature::RefreshCurrentControl
);
481 _rFeatureIds
.push_back( FormFeature::SortAscending
);
482 _rFeatureIds
.push_back( FormFeature::SortDescending
);
483 _rFeatureIds
.push_back( FormFeature::InteractiveSort
);
484 _rFeatureIds
.push_back( FormFeature::AutoFilter
);
485 _rFeatureIds
.push_back( FormFeature::InteractiveFilter
);
486 _rFeatureIds
.push_back( FormFeature::ToggleApplyFilter
);
487 _rFeatureIds
.push_back( FormFeature::RemoveFilterAndSort
);
493 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
494 com_sun_star_comp_form_ONavigationBarControl_get_implementation (css::uno::XComponentContext
* context
,
495 css::uno::Sequence
<css::uno::Any
> const &)
497 return cppu::acquire(new frm::ONavigationBarControl(context
));
500 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */