Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
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"
29 :
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>
35 :
36 : #include <comphelper/processfactory.hxx>
37 : #include <tools/debug.hxx>
38 : #include <tools/diagnose_ex.h>
39 : #include <vcl/svapp.hxx>
40 : #include <vcl/settings.hxx>
41 :
42 :
43 0 : extern "C" void SAL_CALL createRegistryInfo_ONavigationBarControl()
44 : {
45 0 : static ::frm::OMultiInstanceAutoRegistration< ::frm::ONavigationBarControl > aAutoRegistration;
46 0 : }
47 :
48 :
49 : namespace frm
50 : {
51 :
52 :
53 : using namespace ::com::sun::star::uno;
54 : using namespace ::com::sun::star::beans;
55 : using namespace ::com::sun::star::awt;
56 : using namespace ::com::sun::star::lang;
57 : using namespace ::com::sun::star::frame;
58 : using namespace ::com::sun::star::graphic;
59 : namespace FormFeature = ::com::sun::star::form::runtime::FormFeature;
60 :
61 : #define FORWARD_TO_PEER_1( unoInterface, method, param1 ) \
62 : Reference< unoInterface > xTypedPeer( getPeer(), UNO_QUERY ); \
63 : if ( xTypedPeer.is() ) \
64 : { \
65 : xTypedPeer->method( param1 ); \
66 : }
67 :
68 :
69 : // ONavigationBarControl
70 :
71 :
72 0 : ONavigationBarControl::ONavigationBarControl( const Reference< XComponentContext >& _rxORB)
73 0 : :UnoControl(), m_xContext(_rxORB)
74 : {
75 0 : }
76 :
77 :
78 0 : ONavigationBarControl::~ONavigationBarControl()
79 : {
80 0 : }
81 :
82 :
83 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarControl, UnoControl, ONavigationBarControl_Base )
84 :
85 :
86 0 : Any SAL_CALL ONavigationBarControl::queryAggregation( const Type& _rType ) throw ( RuntimeException, std::exception )
87 : {
88 0 : Any aReturn = UnoControl::queryAggregation( _rType );
89 :
90 0 : if ( !aReturn.hasValue() )
91 0 : aReturn = ONavigationBarControl_Base::queryInterface( _rType );
92 :
93 0 : return aReturn;
94 : }
95 :
96 :
97 : namespace
98 : {
99 :
100 0 : static WinBits lcl_getWinBits_nothrow( const Reference< XControlModel >& _rxModel )
101 : {
102 0 : WinBits nBits = 0;
103 : try
104 : {
105 0 : Reference< XPropertySet > xProps( _rxModel, UNO_QUERY );
106 0 : if ( xProps.is() )
107 : {
108 0 : sal_Int16 nBorder = 0;
109 0 : xProps->getPropertyValue( PROPERTY_BORDER ) >>= nBorder;
110 0 : if ( nBorder )
111 0 : nBits |= WB_BORDER;
112 :
113 0 : sal_Bool bTabStop = sal_False;
114 0 : if ( xProps->getPropertyValue( PROPERTY_TABSTOP ) >>= bTabStop )
115 0 : nBits |= ( bTabStop ? WB_TABSTOP : WB_NOTABSTOP );
116 0 : }
117 : }
118 0 : catch( const Exception& )
119 : {
120 : DBG_UNHANDLED_EXCEPTION();
121 : }
122 0 : return nBits;
123 : }
124 : }
125 :
126 :
127 0 : void SAL_CALL ONavigationBarControl::createPeer( const Reference< XToolkit >& /*_rToolkit*/, const Reference< XWindowPeer >& _rParentPeer ) throw( RuntimeException, std::exception )
128 : {
129 0 : SolarMutexGuard aGuard;
130 :
131 0 : if (!getPeer().is())
132 : {
133 0 : mbCreatingPeer = true;
134 :
135 : // determine the VLC window for the parent
136 0 : Window* pParentWin = NULL;
137 0 : if ( _rParentPeer.is() )
138 : {
139 0 : VCLXWindow* pParentXWin = VCLXWindow::GetImplementation( _rParentPeer );
140 0 : if ( pParentXWin )
141 0 : pParentWin = pParentXWin->GetWindow();
142 : DBG_ASSERT( pParentWin, "ONavigationBarControl::createPeer: could not obtain the VCL-level parent window!" );
143 : }
144 :
145 : // create the peer
146 0 : ONavigationBarPeer* pPeer = ONavigationBarPeer::Create( m_xContext, pParentWin, getModel() );
147 : DBG_ASSERT( pPeer, "ONavigationBarControl::createPeer: invalid peer returned!" );
148 0 : if ( pPeer )
149 : // by definition, the returned component is aquired once
150 0 : pPeer->release();
151 :
152 : // announce the peer to the base class
153 0 : setPeer( pPeer );
154 :
155 : // initialize ourself (and thus the peer) with the model properties
156 0 : updateFromModel();
157 :
158 0 : Reference< XView > xPeerView( getPeer(), UNO_QUERY );
159 0 : if ( xPeerView.is() )
160 : {
161 0 : xPeerView->setZoom( maComponentInfos.nZoomX, maComponentInfos.nZoomY );
162 0 : xPeerView->setGraphics( mxGraphics );
163 : }
164 :
165 : // a lot of initial settings from our component infos
166 0 : setPosSize( maComponentInfos.nX, maComponentInfos.nY, maComponentInfos.nWidth, maComponentInfos.nHeight, PosSize::POSSIZE );
167 :
168 0 : pPeer->setVisible ( maComponentInfos.bVisible && !mbDesignMode );
169 0 : pPeer->setEnable ( maComponentInfos.bEnable );
170 0 : pPeer->setDesignMode( mbDesignMode );
171 :
172 0 : peerCreated();
173 :
174 0 : mbCreatingPeer = false;
175 :
176 0 : OControl::initFormControlPeer( getPeer() );
177 0 : }
178 0 : }
179 :
180 :
181 0 : OUString SAL_CALL ONavigationBarControl::getImplementationName() throw( RuntimeException, std::exception )
182 : {
183 0 : return getImplementationName_Static();
184 : }
185 :
186 :
187 0 : Sequence< OUString > SAL_CALL ONavigationBarControl::getSupportedServiceNames() throw( RuntimeException, std::exception )
188 : {
189 0 : return getSupportedServiceNames_Static();
190 : }
191 :
192 :
193 0 : OUString SAL_CALL ONavigationBarControl::getImplementationName_Static()
194 : {
195 0 : return OUString( "com.sun.star.comp.form.ONavigationBarControl" );
196 : }
197 :
198 :
199 0 : Sequence< OUString > SAL_CALL ONavigationBarControl::getSupportedServiceNames_Static()
200 : {
201 0 : Sequence< OUString > aServices( 2 );
202 0 : aServices[ 0 ] = "com.sun.star.awt.UnoControl";
203 0 : aServices[ 1 ] = "com.sun.star.form.control.NavigationToolBar";
204 0 : return aServices;
205 : }
206 :
207 :
208 0 : Reference< XInterface > SAL_CALL ONavigationBarControl::Create( const Reference< XMultiServiceFactory >& _rxFactory )
209 : {
210 0 : return *( new ONavigationBarControl( comphelper::getComponentContext(_rxFactory) ) );
211 : }
212 :
213 :
214 0 : void SAL_CALL ONavigationBarControl::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException, std::exception)
215 : {
216 0 : FORWARD_TO_PEER_1( XDispatchProviderInterception, registerDispatchProviderInterceptor, _rxInterceptor );
217 0 : }
218 :
219 :
220 0 : void SAL_CALL ONavigationBarControl::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException, std::exception)
221 : {
222 0 : FORWARD_TO_PEER_1( XDispatchProviderInterception, releaseDispatchProviderInterceptor, _rxInterceptor );
223 0 : }
224 :
225 :
226 0 : void SAL_CALL ONavigationBarControl::setDesignMode( sal_Bool _bOn ) throw( RuntimeException, std::exception )
227 : {
228 0 : UnoControl::setDesignMode( _bOn );
229 0 : FORWARD_TO_PEER_1( XVclWindowPeer, setDesignMode, _bOn );
230 0 : }
231 :
232 :
233 : // ONavigationBarPeer
234 :
235 :
236 0 : ONavigationBarPeer* ONavigationBarPeer::Create( const Reference< XComponentContext >& _rxORB,
237 : Window* _pParentWindow, const Reference< XControlModel >& _rxModel )
238 : {
239 : DBG_TESTSOLARMUTEX();
240 :
241 : // the peer itself
242 0 : ONavigationBarPeer* pPeer = new ONavigationBarPeer( _rxORB );
243 0 : pPeer->acquire(); // by definition, the returned object is aquired once
244 :
245 : // the VCL control for the peer
246 0 : Reference< XModel > xContextDocument( getXModel( _rxModel ) );
247 : NavigationToolBar* pNavBar = new NavigationToolBar(
248 : _pParentWindow,
249 : lcl_getWinBits_nothrow( _rxModel ),
250 : createDocumentCommandImageProvider( _rxORB, xContextDocument ),
251 : createDocumentCommandDescriptionProvider( _rxORB, xContextDocument )
252 0 : );
253 :
254 : // some knittings
255 0 : pNavBar->setDispatcher( pPeer );
256 0 : pNavBar->SetComponentInterface( pPeer );
257 :
258 : // we want a faster repeating rate for the slots in this
259 : // toolbox
260 0 : AllSettings aSettings = pNavBar->GetSettings();
261 0 : MouseSettings aMouseSettings = aSettings.GetMouseSettings();
262 0 : aMouseSettings.SetButtonRepeat( 10 );
263 0 : aSettings.SetMouseSettings( aMouseSettings );
264 0 : pNavBar->SetSettings( aSettings, true );
265 :
266 : // outta here
267 0 : return pPeer;
268 : }
269 :
270 :
271 0 : ONavigationBarPeer::ONavigationBarPeer( const Reference< XComponentContext >& _rxORB )
272 0 : :OFormNavigationHelper( _rxORB )
273 : {
274 0 : }
275 :
276 :
277 0 : ONavigationBarPeer::~ONavigationBarPeer()
278 : {
279 0 : }
280 :
281 :
282 0 : IMPLEMENT_FORWARD_XINTERFACE2( ONavigationBarPeer, VCLXWindow, OFormNavigationHelper )
283 :
284 :
285 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarPeer, VCLXWindow, OFormNavigationHelper )
286 :
287 :
288 0 : void SAL_CALL ONavigationBarPeer::dispose( ) throw( RuntimeException, std::exception )
289 : {
290 0 : VCLXWindow::dispose();
291 0 : OFormNavigationHelper::dispose();
292 0 : }
293 :
294 :
295 0 : void SAL_CALL ONavigationBarPeer::setProperty( const OUString& _rPropertyName, const Any& _rValue ) throw( RuntimeException, std::exception )
296 : {
297 0 : SolarMutexGuard aGuard;
298 :
299 0 : NavigationToolBar* pNavBar = static_cast< NavigationToolBar* >( GetWindow() );
300 0 : if ( !pNavBar )
301 : {
302 0 : VCLXWindow::setProperty( _rPropertyName, _rValue );
303 0 : return;
304 : }
305 :
306 0 : bool bVoid = !_rValue.hasValue();
307 :
308 0 : sal_Bool bBoolValue = sal_False;
309 0 : sal_Int32 nColor = COL_TRANSPARENT;
310 :
311 : // TODO: more generic mechanisms for this (the grid control implementation,
312 : // when used herein, will do the same stuff for lot of these)
313 :
314 0 : if ( _rPropertyName.equals( PROPERTY_BACKGROUNDCOLOR ) )
315 : {
316 0 : Wallpaper aTest = pNavBar->GetBackground();
317 0 : if ( bVoid )
318 : {
319 0 : pNavBar->SetBackground( pNavBar->GetSettings().GetStyleSettings().GetFaceColor() );
320 0 : pNavBar->SetControlBackground();
321 : }
322 : else
323 : {
324 0 : OSL_VERIFY( _rValue >>= nColor );
325 0 : Color aColor( nColor );
326 0 : pNavBar->SetBackground( aColor );
327 0 : pNavBar->SetControlBackground( aColor );
328 0 : }
329 : }
330 0 : else if ( _rPropertyName.equals( PROPERTY_TEXTLINECOLOR ) )
331 : {
332 0 : if ( bVoid )
333 : {
334 0 : pNavBar->SetTextLineColor();
335 : }
336 : else
337 : {
338 0 : OSL_VERIFY( _rValue >>= nColor );
339 0 : pNavBar->SetTextLineColor( nColor );
340 : }
341 : }
342 0 : else if ( _rPropertyName.equals( PROPERTY_ICONSIZE ) )
343 : {
344 0 : sal_Int16 nInt16Value = 0;
345 0 : OSL_VERIFY( _rValue >>= nInt16Value );
346 0 : pNavBar->SetImageSize( nInt16Value ? NavigationToolBar::eLarge : NavigationToolBar::eSmall );
347 : }
348 0 : else if ( _rPropertyName.equals( PROPERTY_SHOW_POSITION ) )
349 : {
350 0 : OSL_VERIFY( _rValue >>= bBoolValue );
351 0 : pNavBar->ShowFunctionGroup( NavigationToolBar::ePosition, bBoolValue );
352 : }
353 0 : else if ( _rPropertyName.equals( PROPERTY_SHOW_NAVIGATION ) )
354 : {
355 0 : OSL_VERIFY( _rValue >>= bBoolValue );
356 0 : pNavBar->ShowFunctionGroup( NavigationToolBar::eNavigation, bBoolValue );
357 : }
358 0 : else if ( _rPropertyName.equals( PROPERTY_SHOW_RECORDACTIONS ) )
359 : {
360 0 : OSL_VERIFY( _rValue >>= bBoolValue );
361 0 : pNavBar->ShowFunctionGroup( NavigationToolBar::eRecordActions, bBoolValue );
362 : }
363 0 : else if ( _rPropertyName.equals( PROPERTY_SHOW_FILTERSORT ) )
364 : {
365 0 : OSL_VERIFY( _rValue >>= bBoolValue );
366 0 : pNavBar->ShowFunctionGroup( NavigationToolBar::eFilterSort, bBoolValue );
367 : }
368 : else
369 : {
370 0 : VCLXWindow::setProperty( _rPropertyName, _rValue );
371 0 : }
372 : }
373 :
374 :
375 0 : Any SAL_CALL ONavigationBarPeer::getProperty( const OUString& _rPropertyName ) throw( RuntimeException, std::exception )
376 : {
377 0 : SolarMutexGuard aGuard;
378 :
379 0 : Any aReturn;
380 0 : NavigationToolBar* pNavBar = static_cast< NavigationToolBar* >( GetWindow() );
381 :
382 0 : if ( _rPropertyName.equals( PROPERTY_BACKGROUNDCOLOR ) )
383 : {
384 0 : aReturn <<= (sal_Int32)pNavBar->GetControlBackground().GetColor();
385 : }
386 0 : else if ( _rPropertyName.equals( PROPERTY_TEXTLINECOLOR ) )
387 : {
388 0 : aReturn <<= (sal_Int32)pNavBar->GetTextLineColor().GetColor();
389 : }
390 0 : else if ( _rPropertyName.equals( PROPERTY_ICONSIZE ) )
391 : {
392 0 : sal_Int16 nIconType = ( NavigationToolBar::eLarge == pNavBar->GetImageSize() )
393 0 : ? 1 : 0;
394 0 : aReturn <<= nIconType;
395 : }
396 0 : else if ( _rPropertyName.equals( PROPERTY_SHOW_POSITION ) )
397 : {
398 0 : aReturn <<= (sal_Bool)( pNavBar->IsFunctionGroupVisible( NavigationToolBar::ePosition ) );
399 : }
400 0 : else if ( _rPropertyName.equals( PROPERTY_SHOW_NAVIGATION ) )
401 : {
402 0 : aReturn <<= (sal_Bool)( pNavBar->IsFunctionGroupVisible( NavigationToolBar::eNavigation ) );
403 : }
404 0 : else if ( _rPropertyName.equals( PROPERTY_SHOW_RECORDACTIONS ) )
405 : {
406 0 : aReturn <<= (sal_Bool)( pNavBar->IsFunctionGroupVisible( NavigationToolBar::eRecordActions ) );
407 : }
408 0 : else if ( _rPropertyName.equals( PROPERTY_SHOW_FILTERSORT ) )
409 : {
410 0 : aReturn <<= (sal_Bool)( pNavBar->IsFunctionGroupVisible( NavigationToolBar::eFilterSort ) );
411 : }
412 : else
413 0 : aReturn = VCLXWindow::getProperty( _rPropertyName );
414 :
415 0 : return aReturn;
416 : }
417 :
418 :
419 0 : void ONavigationBarPeer::interceptorsChanged( )
420 : {
421 0 : if ( isDesignMode() )
422 : // not interested in if we're in design mode
423 0 : return;
424 :
425 0 : OFormNavigationHelper::interceptorsChanged();
426 : }
427 :
428 :
429 0 : void ONavigationBarPeer::featureStateChanged( sal_Int16 _nFeatureId, sal_Bool _bEnabled )
430 : {
431 : // enable this button on the toolbox
432 0 : NavigationToolBar* pNavBar = static_cast< NavigationToolBar* >( GetWindow() );
433 0 : if ( pNavBar )
434 : {
435 0 : pNavBar->enableFeature( _nFeatureId, _bEnabled );
436 :
437 : // is it a feature with additional state information?
438 0 : if ( _nFeatureId == FormFeature::ToggleApplyFilter )
439 : { // additional boolean state
440 0 : pNavBar->checkFeature( _nFeatureId, getBooleanState( _nFeatureId ) );
441 : }
442 0 : else if ( _nFeatureId == FormFeature::TotalRecords )
443 : {
444 0 : pNavBar->setFeatureText( _nFeatureId, getStringState( _nFeatureId ) );
445 : }
446 0 : else if ( _nFeatureId == FormFeature::MoveAbsolute )
447 : {
448 0 : pNavBar->setFeatureText( _nFeatureId, OUString::number(getIntegerState(_nFeatureId)) );
449 : }
450 : }
451 :
452 : // base class
453 0 : OFormNavigationHelper::featureStateChanged( _nFeatureId, _bEnabled );
454 0 : }
455 :
456 :
457 0 : void ONavigationBarPeer::allFeatureStatesChanged( )
458 : {
459 : // force the control to update it's states
460 0 : NavigationToolBar* pNavBar = static_cast< NavigationToolBar* >( GetWindow() );
461 0 : if ( pNavBar )
462 0 : pNavBar->setDispatcher( this );
463 :
464 : // base class
465 0 : OFormNavigationHelper::allFeatureStatesChanged( );
466 0 : }
467 :
468 :
469 0 : bool ONavigationBarPeer::isEnabled( sal_Int16 _nFeatureId ) const
470 : {
471 0 : if ( const_cast< ONavigationBarPeer* >( this )->isDesignMode() )
472 0 : return false;
473 :
474 0 : return OFormNavigationHelper::isEnabled( _nFeatureId );
475 : }
476 :
477 :
478 0 : void SAL_CALL ONavigationBarPeer::setDesignMode( sal_Bool _bOn ) throw( RuntimeException, std::exception )
479 : {
480 0 : VCLXWindow::setDesignMode( _bOn );
481 :
482 0 : if ( _bOn )
483 0 : disconnectDispatchers();
484 : else
485 0 : connectDispatchers();
486 : // this will connect if not already connected and just update else
487 0 : }
488 :
489 :
490 0 : void SAL_CALL ONavigationBarPeer::disposing( const EventObject& _rSource ) throw (RuntimeException, std::exception)
491 : {
492 0 : VCLXWindow::disposing( _rSource );
493 0 : OFormNavigationHelper::disposing( _rSource );
494 0 : }
495 :
496 :
497 0 : void ONavigationBarPeer::getSupportedFeatures( ::std::vector< sal_Int16 >& _rFeatureIds )
498 : {
499 0 : _rFeatureIds.push_back( FormFeature::MoveAbsolute );
500 0 : _rFeatureIds.push_back( FormFeature::TotalRecords );
501 0 : _rFeatureIds.push_back( FormFeature::MoveToFirst );
502 0 : _rFeatureIds.push_back( FormFeature::MoveToPrevious );
503 0 : _rFeatureIds.push_back( FormFeature::MoveToNext );
504 0 : _rFeatureIds.push_back( FormFeature::MoveToLast );
505 0 : _rFeatureIds.push_back( FormFeature::SaveRecordChanges );
506 0 : _rFeatureIds.push_back( FormFeature::UndoRecordChanges );
507 0 : _rFeatureIds.push_back( FormFeature::MoveToInsertRow );
508 0 : _rFeatureIds.push_back( FormFeature::DeleteRecord );
509 0 : _rFeatureIds.push_back( FormFeature::ReloadForm );
510 0 : _rFeatureIds.push_back( FormFeature::RefreshCurrentControl );
511 0 : _rFeatureIds.push_back( FormFeature::SortAscending );
512 0 : _rFeatureIds.push_back( FormFeature::SortDescending );
513 0 : _rFeatureIds.push_back( FormFeature::InteractiveSort );
514 0 : _rFeatureIds.push_back( FormFeature::AutoFilter );
515 0 : _rFeatureIds.push_back( FormFeature::InteractiveFilter );
516 0 : _rFeatureIds.push_back( FormFeature::ToggleApplyFilter );
517 0 : _rFeatureIds.push_back( FormFeature::RemoveFilterAndSort );
518 0 : }
519 :
520 :
521 : } // namespace frm
522 :
523 :
524 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|