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