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 "frm_module.hxx"
24 #include "FormComponent.hxx"
25 #include "componenttools.hxx"
26 #include "navtoolbar.hxx"
27 #include "commandimageprovider.hxx"
28 #include "commanddescriptionprovider.hxx"
30 #include <com/sun/star/awt/XView.hpp>
31 #include <com/sun/star/awt/PosSize.hpp>
32 #include <com/sun/star/form/runtime/FormFeature.hpp>
33 #include <com/sun/star/awt/XControlModel.hpp>
34 #include <com/sun/star/graphic/XGraphic.hpp>
36 #include <comphelper/processfactory.hxx>
37 #include <tools/debug.hxx>
38 #include <tools/diagnose_ex.h>
39 #include <vcl/svapp.hxx>
41 //--------------------------------------------------------------------------
42 extern "C" void SAL_CALL
createRegistryInfo_ONavigationBarControl()
44 static ::frm::OMultiInstanceAutoRegistration
< ::frm::ONavigationBarControl
> aAutoRegistration
;
47 //.........................................................................
50 //.........................................................................
52 using namespace ::com::sun::star::uno
;
53 using namespace ::com::sun::star::beans
;
54 using namespace ::com::sun::star::awt
;
55 using namespace ::com::sun::star::lang
;
56 using namespace ::com::sun::star::frame
;
57 using namespace ::com::sun::star::graphic
;
58 namespace FormFeature
= ::com::sun::star::form::runtime::FormFeature
;
60 #define FORWARD_TO_PEER_1( unoInterface, method, param1 ) \
61 Reference< unoInterface > xTypedPeer( getPeer(), UNO_QUERY ); \
62 if ( xTypedPeer.is() ) \
64 xTypedPeer->method( param1 ); \
67 //==================================================================
68 // ONavigationBarControl
69 //==================================================================
70 DBG_NAME( ONavigationBarControl
)
71 //------------------------------------------------------------------
72 ONavigationBarControl::ONavigationBarControl( const Reference
< XComponentContext
>& _rxORB
)
73 :UnoControl(), m_xContext(_rxORB
)
75 DBG_CTOR( ONavigationBarControl
, NULL
);
78 //------------------------------------------------------------------
79 ONavigationBarControl::~ONavigationBarControl()
81 DBG_DTOR( ONavigationBarControl
, NULL
);
84 //------------------------------------------------------------------
85 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarControl
, UnoControl
, ONavigationBarControl_Base
)
87 //------------------------------------------------------------------
88 Any SAL_CALL
ONavigationBarControl::queryAggregation( const Type
& _rType
) throw ( RuntimeException
)
90 Any aReturn
= UnoControl::queryAggregation( _rType
);
92 if ( !aReturn
.hasValue() )
93 aReturn
= ONavigationBarControl_Base::queryInterface( _rType
);
98 //------------------------------------------------------------------
101 //..............................................................
102 static WinBits
lcl_getWinBits_nothrow( const Reference
< XControlModel
>& _rxModel
)
107 Reference
< XPropertySet
> xProps( _rxModel
, UNO_QUERY
);
110 sal_Int16 nBorder
= 0;
111 xProps
->getPropertyValue( PROPERTY_BORDER
) >>= nBorder
;
115 sal_Bool bTabStop
= sal_False
;
116 if ( xProps
->getPropertyValue( PROPERTY_TABSTOP
) >>= bTabStop
)
117 nBits
|= ( bTabStop
? WB_TABSTOP
: WB_NOTABSTOP
);
120 catch( const Exception
& )
122 DBG_UNHANDLED_EXCEPTION();
128 //------------------------------------------------------------------
129 void SAL_CALL
ONavigationBarControl::createPeer( const Reference
< XToolkit
>& /*_rToolkit*/, const Reference
< XWindowPeer
>& _rParentPeer
) throw( RuntimeException
)
131 SolarMutexGuard aGuard
;
135 mbCreatingPeer
= sal_True
;
137 // determine the VLC window for the parent
138 Window
* pParentWin
= NULL
;
139 if ( _rParentPeer
.is() )
141 VCLXWindow
* pParentXWin
= VCLXWindow::GetImplementation( _rParentPeer
);
143 pParentWin
= pParentXWin
->GetWindow();
144 DBG_ASSERT( pParentWin
, "ONavigationBarControl::createPeer: could not obtain the VCL-level parent window!" );
148 ONavigationBarPeer
* pPeer
= ONavigationBarPeer::Create( Reference
<XMultiServiceFactory
>(m_xContext
->getServiceManager(), UNO_QUERY_THROW
), pParentWin
, getModel() );
149 DBG_ASSERT( pPeer
, "ONavigationBarControl::createPeer: invalid peer returned!" );
151 // by definition, the returned component is aquired once
154 // announce the peer to the base class
157 // initialize ourself (and thus the peer) with the model properties
160 Reference
< XView
> xPeerView( getPeer(), UNO_QUERY
);
161 if ( xPeerView
.is() )
163 xPeerView
->setZoom( maComponentInfos
.nZoomX
, maComponentInfos
.nZoomY
);
164 xPeerView
->setGraphics( mxGraphics
);
167 // a lot of initial settings from our component infos
168 setPosSize( maComponentInfos
.nX
, maComponentInfos
.nY
, maComponentInfos
.nWidth
, maComponentInfos
.nHeight
, PosSize::POSSIZE
);
170 pPeer
->setVisible ( maComponentInfos
.bVisible
&& !mbDesignMode
);
171 pPeer
->setEnable ( maComponentInfos
.bEnable
);
172 pPeer
->setDesignMode( mbDesignMode
);
176 mbCreatingPeer
= sal_False
;
178 OControl::initFormControlPeer( getPeer() );
182 //------------------------------------------------------------------
183 OUString SAL_CALL
ONavigationBarControl::getImplementationName() throw( RuntimeException
)
185 return getImplementationName_Static();
188 //------------------------------------------------------------------
189 Sequence
< OUString
> SAL_CALL
ONavigationBarControl::getSupportedServiceNames() throw( RuntimeException
)
191 return getSupportedServiceNames_Static();
194 //------------------------------------------------------------------
195 OUString SAL_CALL
ONavigationBarControl::getImplementationName_Static()
197 return OUString( "com.sun.star.comp.form.ONavigationBarControl" );
200 //------------------------------------------------------------------
201 Sequence
< OUString
> SAL_CALL
ONavigationBarControl::getSupportedServiceNames_Static()
203 Sequence
< OUString
> aServices( 2 );
204 aServices
[ 0 ] = OUString( "com.sun.star.awt.UnoControl" );
205 aServices
[ 1 ] = OUString( "com.sun.star.form.control.NavigationToolBar" );
209 //------------------------------------------------------------------
210 Reference
< XInterface
> SAL_CALL
ONavigationBarControl::Create( const Reference
< XMultiServiceFactory
>& _rxFactory
)
212 return *( new ONavigationBarControl( comphelper::getComponentContext(_rxFactory
) ) );
215 //------------------------------------------------------------------
216 void SAL_CALL
ONavigationBarControl::registerDispatchProviderInterceptor( const Reference
< XDispatchProviderInterceptor
>& _rxInterceptor
) throw (RuntimeException
)
218 FORWARD_TO_PEER_1( XDispatchProviderInterception
, registerDispatchProviderInterceptor
, _rxInterceptor
);
221 //------------------------------------------------------------------
222 void SAL_CALL
ONavigationBarControl::releaseDispatchProviderInterceptor( const Reference
< XDispatchProviderInterceptor
>& _rxInterceptor
) throw (RuntimeException
)
224 FORWARD_TO_PEER_1( XDispatchProviderInterception
, releaseDispatchProviderInterceptor
, _rxInterceptor
);
227 //------------------------------------------------------------------
228 void SAL_CALL
ONavigationBarControl::setDesignMode( sal_Bool _bOn
) throw( RuntimeException
)
230 UnoControl::setDesignMode( _bOn
);
231 FORWARD_TO_PEER_1( XVclWindowPeer
, setDesignMode
, _bOn
);
234 //==================================================================
235 // ONavigationBarPeer
236 //==================================================================
237 DBG_NAME( ONavigationBarPeer
)
238 //------------------------------------------------------------------
239 ONavigationBarPeer
* ONavigationBarPeer::Create( const Reference
< XMultiServiceFactory
>& _rxORB
,
240 Window
* _pParentWindow
, const Reference
< XControlModel
>& _rxModel
)
242 DBG_TESTSOLARMUTEX();
245 ONavigationBarPeer
* pPeer
= new ONavigationBarPeer( _rxORB
);
246 pPeer
->acquire(); // by definition, the returned object is aquired once
248 // the VCL control for the peer
249 Reference
< XModel
> xContextDocument( getXModel( _rxModel
) );
250 NavigationToolBar
* pNavBar
= new NavigationToolBar(
252 lcl_getWinBits_nothrow( _rxModel
),
253 createDocumentCommandImageProvider( _rxORB
, xContextDocument
),
254 createDocumentCommandDescriptionProvider( comphelper::getComponentContext(_rxORB
), xContextDocument
)
258 pNavBar
->setDispatcher( pPeer
);
259 pNavBar
->SetComponentInterface( pPeer
);
261 // we want a faster repeating rate for the slots in this
263 AllSettings aSettings
= pNavBar
->GetSettings();
264 MouseSettings aMouseSettings
= aSettings
.GetMouseSettings();
265 aMouseSettings
.SetButtonRepeat( 10 );
266 aSettings
.SetMouseSettings( aMouseSettings
);
267 pNavBar
->SetSettings( aSettings
, sal_True
);
273 //------------------------------------------------------------------
274 ONavigationBarPeer::ONavigationBarPeer( const Reference
< XMultiServiceFactory
>& _rxORB
)
275 :OFormNavigationHelper( _rxORB
)
277 DBG_CTOR( ONavigationBarPeer
, NULL
);
280 //------------------------------------------------------------------
281 ONavigationBarPeer::~ONavigationBarPeer()
283 DBG_DTOR( ONavigationBarPeer
, NULL
);
286 //------------------------------------------------------------------
287 IMPLEMENT_FORWARD_XINTERFACE2( ONavigationBarPeer
, VCLXWindow
, OFormNavigationHelper
)
289 //------------------------------------------------------------------
290 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarPeer
, VCLXWindow
, OFormNavigationHelper
)
292 //------------------------------------------------------------------
293 void SAL_CALL
ONavigationBarPeer::dispose( ) throw( RuntimeException
)
295 VCLXWindow::dispose();
296 OFormNavigationHelper::dispose();
299 //------------------------------------------------------------------
300 void SAL_CALL
ONavigationBarPeer::setProperty( const OUString
& _rPropertyName
, const Any
& _rValue
) throw( RuntimeException
)
302 SolarMutexGuard aGuard
;
304 NavigationToolBar
* pNavBar
= static_cast< NavigationToolBar
* >( GetWindow() );
307 VCLXWindow::setProperty( _rPropertyName
, _rValue
);
311 bool bVoid
= !_rValue
.hasValue();
313 sal_Bool bBoolValue
= sal_False
;
314 sal_Int32 nColor
= COL_TRANSPARENT
;
316 // TODO: more generic mechanisms for this (the grid control implementation,
317 // when used herein, will do the same stuff for lot of these)
319 if ( _rPropertyName
.equals( PROPERTY_BACKGROUNDCOLOR
) )
321 Wallpaper aTest
= pNavBar
->GetBackground();
324 pNavBar
->SetBackground( pNavBar
->GetSettings().GetStyleSettings().GetFaceColor() );
325 pNavBar
->SetControlBackground();
329 OSL_VERIFY( _rValue
>>= nColor
);
330 Color
aColor( nColor
);
331 pNavBar
->SetBackground( aColor
);
332 pNavBar
->SetControlBackground( aColor
);
335 else if ( _rPropertyName
.equals( PROPERTY_TEXTLINECOLOR
) )
339 pNavBar
->SetTextLineColor();
343 OSL_VERIFY( _rValue
>>= nColor
);
344 pNavBar
->SetTextLineColor( nColor
);
347 else if ( _rPropertyName
.equals( PROPERTY_ICONSIZE
) )
349 sal_Int16 nInt16Value
= 0;
350 OSL_VERIFY( _rValue
>>= nInt16Value
);
351 pNavBar
->SetImageSize( nInt16Value
? NavigationToolBar::eLarge
: NavigationToolBar::eSmall
);
353 else if ( _rPropertyName
.equals( PROPERTY_SHOW_POSITION
) )
355 OSL_VERIFY( _rValue
>>= bBoolValue
);
356 pNavBar
->ShowFunctionGroup( NavigationToolBar::ePosition
, bBoolValue
);
358 else if ( _rPropertyName
.equals( PROPERTY_SHOW_NAVIGATION
) )
360 OSL_VERIFY( _rValue
>>= bBoolValue
);
361 pNavBar
->ShowFunctionGroup( NavigationToolBar::eNavigation
, bBoolValue
);
363 else if ( _rPropertyName
.equals( PROPERTY_SHOW_RECORDACTIONS
) )
365 OSL_VERIFY( _rValue
>>= bBoolValue
);
366 pNavBar
->ShowFunctionGroup( NavigationToolBar::eRecordActions
, bBoolValue
);
368 else if ( _rPropertyName
.equals( PROPERTY_SHOW_FILTERSORT
) )
370 OSL_VERIFY( _rValue
>>= bBoolValue
);
371 pNavBar
->ShowFunctionGroup( NavigationToolBar::eFilterSort
, bBoolValue
);
375 VCLXWindow::setProperty( _rPropertyName
, _rValue
);
379 //------------------------------------------------------------------
380 Any SAL_CALL
ONavigationBarPeer::getProperty( const OUString
& _rPropertyName
) throw( RuntimeException
)
382 SolarMutexGuard aGuard
;
385 NavigationToolBar
* pNavBar
= static_cast< NavigationToolBar
* >( GetWindow() );
387 if ( _rPropertyName
.equals( PROPERTY_BACKGROUNDCOLOR
) )
389 aReturn
<<= (sal_Int32
)pNavBar
->GetControlBackground().GetColor();
391 else if ( _rPropertyName
.equals( PROPERTY_TEXTLINECOLOR
) )
393 aReturn
<<= (sal_Int32
)pNavBar
->GetTextLineColor().GetColor();
395 else if ( _rPropertyName
.equals( PROPERTY_ICONSIZE
) )
397 sal_Int16 nIconType
= ( NavigationToolBar::eLarge
== pNavBar
->GetImageSize() )
399 aReturn
<<= nIconType
;
401 else if ( _rPropertyName
.equals( PROPERTY_SHOW_POSITION
) )
403 aReturn
<<= (sal_Bool
)( pNavBar
->IsFunctionGroupVisible( NavigationToolBar::ePosition
) );
405 else if ( _rPropertyName
.equals( PROPERTY_SHOW_NAVIGATION
) )
407 aReturn
<<= (sal_Bool
)( pNavBar
->IsFunctionGroupVisible( NavigationToolBar::eNavigation
) );
409 else if ( _rPropertyName
.equals( PROPERTY_SHOW_RECORDACTIONS
) )
411 aReturn
<<= (sal_Bool
)( pNavBar
->IsFunctionGroupVisible( NavigationToolBar::eRecordActions
) );
413 else if ( _rPropertyName
.equals( PROPERTY_SHOW_FILTERSORT
) )
415 aReturn
<<= (sal_Bool
)( pNavBar
->IsFunctionGroupVisible( NavigationToolBar::eFilterSort
) );
418 aReturn
= VCLXWindow::getProperty( _rPropertyName
);
423 //------------------------------------------------------------------
424 void ONavigationBarPeer::interceptorsChanged( )
426 if ( isDesignMode() )
427 // not interested in if we're in design mode
430 OFormNavigationHelper::interceptorsChanged();
433 //------------------------------------------------------------------
434 void ONavigationBarPeer::featureStateChanged( sal_Int16 _nFeatureId
, sal_Bool _bEnabled
)
436 // enable this button on the toolbox
437 NavigationToolBar
* pNavBar
= static_cast< NavigationToolBar
* >( GetWindow() );
440 pNavBar
->enableFeature( _nFeatureId
, _bEnabled
);
442 // is it a feature with additional state information?
443 if ( _nFeatureId
== FormFeature::ToggleApplyFilter
)
444 { // additional boolean state
445 pNavBar
->checkFeature( _nFeatureId
, getBooleanState( _nFeatureId
) );
447 else if ( _nFeatureId
== FormFeature::TotalRecords
)
449 pNavBar
->setFeatureText( _nFeatureId
, getStringState( _nFeatureId
) );
451 else if ( _nFeatureId
== FormFeature::MoveAbsolute
)
453 pNavBar
->setFeatureText( _nFeatureId
, OUString::valueOf(getIntegerState(_nFeatureId
)) );
458 OFormNavigationHelper::featureStateChanged( _nFeatureId
, _bEnabled
);
461 //------------------------------------------------------------------
462 void ONavigationBarPeer::allFeatureStatesChanged( )
464 // force the control to update it's states
465 NavigationToolBar
* pNavBar
= static_cast< NavigationToolBar
* >( GetWindow() );
467 pNavBar
->setDispatcher( this );
470 OFormNavigationHelper::allFeatureStatesChanged( );
473 //------------------------------------------------------------------
474 bool ONavigationBarPeer::isEnabled( sal_Int16 _nFeatureId
) const
476 if ( const_cast< ONavigationBarPeer
* >( this )->isDesignMode() )
479 return OFormNavigationHelper::isEnabled( _nFeatureId
);
482 //------------------------------------------------------------------
483 void SAL_CALL
ONavigationBarPeer::setDesignMode( sal_Bool _bOn
) throw( RuntimeException
)
485 VCLXWindow::setDesignMode( _bOn
);
488 disconnectDispatchers();
490 connectDispatchers();
491 // this will connect if not already connected and just update else
494 //------------------------------------------------------------------
495 void SAL_CALL
ONavigationBarPeer::disposing( const EventObject
& _rSource
) throw (RuntimeException
)
497 VCLXWindow::disposing( _rSource
);
498 OFormNavigationHelper::disposing( _rSource
);
501 //------------------------------------------------------------------
502 void ONavigationBarPeer::getSupportedFeatures( ::std::vector
< sal_Int16
>& _rFeatureIds
)
504 _rFeatureIds
.push_back( FormFeature::MoveAbsolute
);
505 _rFeatureIds
.push_back( FormFeature::TotalRecords
);
506 _rFeatureIds
.push_back( FormFeature::MoveToFirst
);
507 _rFeatureIds
.push_back( FormFeature::MoveToPrevious
);
508 _rFeatureIds
.push_back( FormFeature::MoveToNext
);
509 _rFeatureIds
.push_back( FormFeature::MoveToLast
);
510 _rFeatureIds
.push_back( FormFeature::SaveRecordChanges
);
511 _rFeatureIds
.push_back( FormFeature::UndoRecordChanges
);
512 _rFeatureIds
.push_back( FormFeature::MoveToInsertRow
);
513 _rFeatureIds
.push_back( FormFeature::DeleteRecord
);
514 _rFeatureIds
.push_back( FormFeature::ReloadForm
);
515 _rFeatureIds
.push_back( FormFeature::RefreshCurrentControl
);
516 _rFeatureIds
.push_back( FormFeature::SortAscending
);
517 _rFeatureIds
.push_back( FormFeature::SortDescending
);
518 _rFeatureIds
.push_back( FormFeature::InteractiveSort
);
519 _rFeatureIds
.push_back( FormFeature::AutoFilter
);
520 _rFeatureIds
.push_back( FormFeature::InteractiveFilter
);
521 _rFeatureIds
.push_back( FormFeature::ToggleApplyFilter
);
522 _rFeatureIds
.push_back( FormFeature::RemoveFilterAndSort
);
525 //.........................................................................
527 //.........................................................................
529 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */