1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_fpicker.hxx" 30 31 #include "OfficeControlAccess.hxx" 32 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 33 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> 34 #include <com/sun/star/ui/dialogs/ControlActions.hpp> 35 #include <vcl/lstbox.hxx> 36 #include <com/sun/star/uno/Sequence.hxx> 37 #include <tools/urlobj.hxx> 38 39 #include <algorithm> 40 #include <functional> 41 42 //......................................................................... 43 namespace svt 44 { 45 //......................................................................... 46 47 // helper ------------------------------------------------------------- 48 49 using namespace ::com::sun::star::uno; 50 using namespace ::com::sun::star::lang; 51 using namespace ::com::sun::star::ui::dialogs; 52 53 using namespace ExtendedFilePickerElementIds; 54 using namespace CommonFilePickerElementIds; 55 using namespace InternalFilePickerElementIds; 56 57 // -------------------------------------------------------------------- 58 namespace 59 { 60 // ---------------------------------------------------------------- 61 #define PROPERTY_FLAG_TEXT 0x00000001 62 #define PROPERTY_FLAG_ENDBALED 0x00000002 63 #define PROPERTY_FLAG_VISIBLE 0x00000004 64 #define PROPERTY_FLAG_HELPURL 0x00000008 65 #define PROPERTY_FLAG_LISTITEMS 0x00000010 66 #define PROPERTY_FLAG_SELECTEDITEM 0x00000020 67 #define PROPERTY_FLAG_SELECTEDITEMINDEX 0x00000040 68 #define PROPERTY_FLAG_CHECKED 0x00000080 69 70 // ---------------------------------------------------------------- 71 // ................................................................ 72 struct ControlDescription 73 { 74 const sal_Char* pControlName; 75 sal_Int16 nControlId; 76 sal_Int32 nPropertyFlags; 77 }; 78 79 // ................................................................ 80 typedef const ControlDescription* ControlDescIterator; 81 typedef ::std::pair< ControlDescIterator, ControlDescIterator > ControlDescRange; 82 83 // ...................................................................... 84 #define PROPERTY_FLAGS_COMMON ( PROPERTY_FLAG_ENDBALED | PROPERTY_FLAG_VISIBLE | PROPERTY_FLAG_HELPURL ) 85 #define PROPERTY_FLAGS_LISTBOX ( PROPERTY_FLAG_LISTITEMS | PROPERTY_FLAG_SELECTEDITEM | PROPERTY_FLAG_SELECTEDITEMINDEX ) 86 #define PROPERTY_FLAGS_CHECKBOX ( PROPERTY_FLAG_CHECKED | PROPERTY_FLAG_TEXT ) 87 88 // Note: this array MUST be sorted by name! 89 static const ControlDescription aDescriptions[] = { 90 { "AutoExtensionBox", CHECKBOX_AUTOEXTENSION, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, 91 { "CancelButton", PUSHBUTTON_CANCEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, 92 { "CurrentFolderText", FIXEDTEXT_CURRENTFOLDER, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, 93 { "DefaultLocationButton", TOOLBOXBUTOON_DEFAULT_LOCATION, PROPERTY_FLAGS_COMMON }, 94 { "FileURLEdit", EDIT_FILEURL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, 95 { "FileURLEditLabel", EDIT_FILEURL_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, 96 { "FileView", CONTROL_FILEVIEW, PROPERTY_FLAGS_COMMON }, 97 { "FilterList", LISTBOX_FILTER, PROPERTY_FLAGS_COMMON }, 98 { "FilterListLabel", LISTBOX_FILTER_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, 99 { "FilterOptionsBox", CHECKBOX_FILTEROPTIONS, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, 100 { "HelpButton", PUSHBUTTON_HELP, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, 101 { "ImageTemplateList", LISTBOX_IMAGE_TEMPLATE, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX }, 102 { "ImageTemplateListLabel", LISTBOX_IMAGE_TEMPLATE_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, 103 { "LevelUpButton", TOOLBOXBUTOON_LEVEL_UP, PROPERTY_FLAGS_COMMON }, 104 { "LinkBox", CHECKBOX_LINK, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, 105 { "NewFolderButton", TOOLBOXBUTOON_NEW_FOLDER, PROPERTY_FLAGS_COMMON }, 106 { "OkButton", PUSHBUTTON_OK , PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, 107 { "PasswordBox", CHECKBOX_PASSWORD, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, 108 { "PlayButton", PUSHBUTTON_PLAY, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, 109 { "PreviewBox", CHECKBOX_PREVIEW, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, 110 { "ReadOnlyBox", CHECKBOX_READONLY, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, 111 { "SelectionBox", CHECKBOX_SELECTION, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, 112 { "TemplateList", LISTBOX_TEMPLATE, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX }, 113 { "TemplateListLabel", LISTBOX_TEMPLATE_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, 114 { "VersionList", LISTBOX_VERSION, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX }, 115 { "VersionListLabel", LISTBOX_VERSION_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT } 116 }; 117 118 // ................................................................ 119 static const sal_Int32 s_nControlCount = sizeof( aDescriptions ) / sizeof( aDescriptions[0] ); 120 121 static ControlDescIterator s_pControls = aDescriptions; 122 static ControlDescIterator s_pControlsEnd = aDescriptions + s_nControlCount; 123 124 // ................................................................ 125 struct ControlDescriptionLookup 126 { 127 bool operator()( const ::rtl::OUString& _rLookup, const ControlDescription& _rDesc ) 128 { 129 return _rLookup.compareToAscii( _rDesc.pControlName ) < 0; 130 } 131 bool operator()( const ControlDescription& _rDesc, const ::rtl::OUString& _rLookup ) 132 { 133 return _rLookup.compareToAscii( _rDesc.pControlName ) > 0; 134 } 135 }; 136 137 // ................................................................ 138 struct ExtractControlName : public ::std::unary_function< ControlDescription, ::rtl::OUString > 139 { 140 ::rtl::OUString operator()( const ControlDescription& _rDesc ) 141 { 142 return ::rtl::OUString::createFromAscii( _rDesc.pControlName ); 143 } 144 }; 145 146 // ---------------------------------------------------------------- 147 // ................................................................ 148 struct ControlProperty 149 { 150 const sal_Char* pPropertyName; 151 sal_Int16 nPropertyId; 152 }; 153 154 typedef const ControlProperty* ControlPropertyIterator; 155 156 // ................................................................ 157 static const ControlProperty aProperties[] = { 158 { "Text", PROPERTY_FLAG_TEXT }, 159 { "Enabled", PROPERTY_FLAG_ENDBALED }, 160 { "Visible", PROPERTY_FLAG_VISIBLE }, 161 { "HelpURL", PROPERTY_FLAG_HELPURL }, 162 { "ListItems", PROPERTY_FLAG_LISTITEMS }, 163 { "SelectedItem", PROPERTY_FLAG_SELECTEDITEM }, 164 { "SelectedItemIndex", PROPERTY_FLAG_SELECTEDITEMINDEX }, 165 { "Checked", PROPERTY_FLAG_CHECKED } 166 }; 167 168 // ................................................................ 169 static const int s_nPropertyCount = sizeof( aProperties ) / sizeof( aProperties[0] ); 170 171 static ControlPropertyIterator s_pProperties = aProperties; 172 static ControlPropertyIterator s_pPropertiesEnd = aProperties + s_nPropertyCount; 173 174 // ................................................................ 175 struct ControlPropertyLookup 176 { 177 ::rtl::OUString m_sLookup; 178 ControlPropertyLookup( const ::rtl::OUString& _rLookup ) : m_sLookup( _rLookup ) { } 179 180 sal_Bool operator()( const ControlProperty& _rProp ) 181 { 182 return m_sLookup.equalsAscii( _rProp.pPropertyName ); 183 } 184 }; 185 186 //----------------------------------------------------------------- 187 void lcl_throwIllegalArgumentException( ) SAL_THROW( (IllegalArgumentException) ) 188 { 189 throw IllegalArgumentException(); 190 // TODO: error message in the exception 191 } 192 } 193 194 //--------------------------------------------------------------------- 195 OControlAccess::OControlAccess( IFilePickerController* _pController, SvtFileView* _pFileView ) 196 :m_pFilePickerController( _pController ) 197 ,m_pFileView( _pFileView ) 198 { 199 DBG_ASSERT( m_pFilePickerController, "OControlAccess::OControlAccess: invalid control locator!" ); 200 } 201 202 //--------------------------------------------------------------------- 203 void OControlAccess::setHelpURL( Window* _pControl, const ::rtl::OUString& sHelpURL, sal_Bool _bFileView ) 204 { 205 rtl::OUString sHelpID( sHelpURL ); 206 INetURLObject aHID( sHelpURL ); 207 if ( aHID.GetProtocol() == INET_PROT_HID ) 208 sHelpID = aHID.GetURLPath(); 209 210 // URLs should always be UTF8 encoded and escaped 211 rtl::OString sID( rtl::OUStringToOString( sHelpID, RTL_TEXTENCODING_UTF8 ) ); 212 if ( _bFileView ) 213 // the file view "overloaded" the SetHelpId 214 static_cast< SvtFileView* >( _pControl )->SetHelpId( sID ); 215 else 216 _pControl->SetHelpId( sID ); 217 } 218 219 //--------------------------------------------------------------------- 220 ::rtl::OUString OControlAccess::getHelpURL( Window* _pControl, sal_Bool _bFileView ) 221 { 222 rtl::OString aHelpId = _pControl->GetHelpId(); 223 if ( _bFileView ) 224 // the file view "overloaded" the SetHelpId 225 aHelpId = static_cast< SvtFileView* >( _pControl )->GetHelpId( ); 226 227 ::rtl::OUString sHelpURL; 228 ::rtl::OUString aTmp( rtl::OStringToOUString( aHelpId, RTL_TEXTENCODING_UTF8 ) ); 229 INetURLObject aHID( aTmp ); 230 if ( aHID.GetProtocol() == INET_PROT_NOT_VALID ) 231 sHelpURL = rtl::OUString::createFromAscii( INET_HID_SCHEME ); 232 sHelpURL += aTmp; 233 return sHelpURL; 234 } 235 236 // -------------------------------------------------------------------------- 237 Any OControlAccess::getControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty ) 238 { 239 // look up the control 240 sal_Int16 nControlId = -1; 241 sal_Int32 nPropertyMask = 0; 242 Control* pControl = implGetControl( _rControlName, &nControlId, &nPropertyMask ); 243 // will throw an IllegalArgumentException if the name is not valid 244 245 // look up the property 246 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) ); 247 if ( aPropDesc == s_pPropertiesEnd ) 248 // it's a completely unknown property 249 lcl_throwIllegalArgumentException(); 250 251 if ( 0 == ( nPropertyMask & aPropDesc->nPropertyId ) ) 252 // it's a property which is known, but not allowed for this control 253 lcl_throwIllegalArgumentException(); 254 255 return implGetControlProperty( pControl, aPropDesc->nPropertyId ); 256 } 257 258 //--------------------------------------------------------------------- 259 Control* OControlAccess::implGetControl( const ::rtl::OUString& _rControlName, sal_Int16* _pId, sal_Int32* _pPropertyMask ) const SAL_THROW( (IllegalArgumentException) ) 260 { 261 Control* pControl = NULL; 262 263 // translate the name into an id 264 ControlDescRange aFoundRange = ::std::equal_range( s_pControls, s_pControlsEnd, _rControlName, ControlDescriptionLookup() ); 265 if ( aFoundRange.first != aFoundRange.second ) 266 { 267 // get the VCL control determined by this id 268 pControl = m_pFilePickerController->getControl( aFoundRange.first->nControlId ); 269 } 270 271 // if not found 'til here, the name is invalid, or we do not have the control in the current mode 272 if ( !pControl ) 273 lcl_throwIllegalArgumentException(); 274 275 // out parameters and outta here 276 if ( _pId ) 277 *_pId = aFoundRange.first->nControlId; 278 if ( _pPropertyMask ) 279 *_pPropertyMask = aFoundRange.first->nPropertyFlags; 280 281 return pControl; 282 } 283 284 //--------------------------------------------------------------------- 285 void OControlAccess::setControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty, const ::com::sun::star::uno::Any& _rValue ) 286 { 287 // look up the control 288 sal_Int16 nControlId = -1; 289 Control* pControl = implGetControl( _rControlName, &nControlId ); 290 // will throw an IllegalArgumentException if the name is not valid 291 292 // look up the property 293 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) ); 294 if ( aPropDesc == s_pPropertiesEnd ) 295 lcl_throwIllegalArgumentException(); 296 297 // set the property 298 implSetControlProperty( nControlId, pControl, aPropDesc->nPropertyId, _rValue, sal_False ); 299 } 300 301 // -------------------------------------------------------------------------- 302 Sequence< ::rtl::OUString > OControlAccess::getSupportedControls( ) 303 { 304 Sequence< ::rtl::OUString > aControls( s_nControlCount ); 305 ::rtl::OUString* pControls = aControls.getArray(); 306 307 // collect the names of all _actually_existent_ controls 308 for ( ControlDescIterator aControl = s_pControls; aControl != s_pControlsEnd; ++aControl ) 309 { 310 if ( m_pFilePickerController->getControl( aControl->nControlId ) ) 311 *pControls++ = ::rtl::OUString::createFromAscii( aControl->pControlName ); 312 } 313 314 aControls.realloc( pControls - aControls.getArray() ); 315 return aControls; 316 } 317 318 // -------------------------------------------------------------------------- 319 Sequence< ::rtl::OUString > OControlAccess::getSupportedControlProperties( const ::rtl::OUString& _rControlName ) 320 { 321 sal_Int16 nControlId = -1; 322 sal_Int32 nPropertyMask = 0; 323 implGetControl( _rControlName, &nControlId, &nPropertyMask ); 324 // will throw an IllegalArgumentException if the name is not valid 325 326 // fill in the property names 327 Sequence< ::rtl::OUString > aProps( s_nPropertyCount ); 328 ::rtl::OUString* pProperty = aProps.getArray(); 329 330 for ( ControlPropertyIterator aProp = s_pProperties; aProp != s_pPropertiesEnd; ++aProp ) 331 if ( 0 != ( nPropertyMask & aProp->nPropertyId ) ) 332 *pProperty++ = ::rtl::OUString::createFromAscii( aProp->pPropertyName ); 333 334 aProps.realloc( pProperty - aProps.getArray() ); 335 return aProps; 336 } 337 338 // -------------------------------------------------------------------------- 339 sal_Bool OControlAccess::isControlSupported( const ::rtl::OUString& _rControlName ) 340 { 341 return ::std::binary_search( s_pControls, s_pControlsEnd, _rControlName, ControlDescriptionLookup() ); 342 } 343 344 // -------------------------------------------------------------------------- 345 sal_Bool OControlAccess::isControlPropertySupported( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty ) 346 { 347 // look up the control 348 sal_Int16 nControlId = -1; 349 sal_Int32 nPropertyMask = 0; 350 implGetControl( _rControlName, &nControlId, &nPropertyMask ); 351 // will throw an IllegalArgumentException if the name is not valid 352 353 // look up the property 354 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) ); 355 if ( aPropDesc == s_pPropertiesEnd ) 356 // it's a property which is completely unknown 357 return sal_False; 358 359 return 0 != ( aPropDesc->nPropertyId & nPropertyMask ); 360 } 361 362 //----------------------------------------------------------------------------- 363 void OControlAccess::setValue( sal_Int16 _nControlId, sal_Int16 _nControlAction, const Any& _rValue ) 364 { 365 Control* pControl = m_pFilePickerController->getControl( _nControlId ); 366 DBG_ASSERT( pControl, "OControlAccess::SetValue: don't have this control in the current mode!" ); 367 if ( pControl ) 368 { 369 sal_Int16 nPropertyId = -1; 370 if ( ControlActions::SET_HELP_URL == _nControlAction ) 371 { 372 nPropertyId = PROPERTY_FLAG_HELPURL; 373 } 374 else 375 { 376 switch ( _nControlId ) 377 { 378 case CHECKBOX_AUTOEXTENSION: 379 case CHECKBOX_PASSWORD: 380 case CHECKBOX_FILTEROPTIONS: 381 case CHECKBOX_READONLY: 382 case CHECKBOX_LINK: 383 case CHECKBOX_PREVIEW: 384 case CHECKBOX_SELECTION: 385 nPropertyId = PROPERTY_FLAG_CHECKED; 386 break; 387 388 case LISTBOX_FILTER: 389 DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" ); 390 break; 391 392 case LISTBOX_VERSION: 393 case LISTBOX_TEMPLATE: 394 case LISTBOX_IMAGE_TEMPLATE: 395 if ( ControlActions::SET_SELECT_ITEM == _nControlAction ) 396 { 397 nPropertyId = PROPERTY_FLAG_SELECTEDITEMINDEX; 398 } 399 else 400 { 401 DBG_ASSERT( WINDOW_LISTBOX == pControl->GetType(), "OControlAccess::SetValue: implGetControl returned nonsense!" ); 402 implDoListboxAction( static_cast< ListBox* >( pControl ), _nControlAction, _rValue ); 403 } 404 break; 405 } 406 } 407 408 if ( -1 != nPropertyId ) 409 implSetControlProperty( _nControlId, pControl, nPropertyId, _rValue ); 410 } 411 } 412 413 //----------------------------------------------------------------------------- 414 Any OControlAccess::getValue( sal_Int16 _nControlId, sal_Int16 _nControlAction ) const 415 { 416 Any aRet; 417 418 Control* pControl = m_pFilePickerController->getControl( _nControlId, sal_False ); 419 DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" ); 420 if ( pControl ) 421 { 422 sal_Int16 nPropertyId = -1; 423 if ( ControlActions::SET_HELP_URL == _nControlAction ) 424 { 425 nPropertyId = PROPERTY_FLAG_HELPURL; 426 } 427 else 428 { 429 switch ( _nControlId ) 430 { 431 case CHECKBOX_AUTOEXTENSION: 432 case CHECKBOX_PASSWORD: 433 case CHECKBOX_FILTEROPTIONS: 434 case CHECKBOX_READONLY: 435 case CHECKBOX_LINK: 436 case CHECKBOX_PREVIEW: 437 case CHECKBOX_SELECTION: 438 nPropertyId = PROPERTY_FLAG_CHECKED; 439 break; 440 441 case LISTBOX_FILTER: 442 if ( ControlActions::GET_SELECTED_ITEM == _nControlAction ) 443 { 444 aRet <<= ::rtl::OUString( m_pFilePickerController->getCurFilter() );; 445 } 446 else 447 { 448 DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" ); 449 } 450 break; 451 452 case LISTBOX_VERSION: 453 case LISTBOX_TEMPLATE: 454 case LISTBOX_IMAGE_TEMPLATE: 455 switch ( _nControlAction ) 456 { 457 case ControlActions::GET_SELECTED_ITEM: 458 nPropertyId = PROPERTY_FLAG_SELECTEDITEM; 459 break; 460 case ControlActions::GET_SELECTED_ITEM_INDEX: 461 nPropertyId = PROPERTY_FLAG_SELECTEDITEMINDEX; 462 break; 463 case ControlActions::GET_ITEMS: 464 nPropertyId = PROPERTY_FLAG_LISTITEMS; 465 break; 466 default: 467 DBG_ERRORFILE( "OControlAccess::GetValue: invalid control action for the listbox!" ); 468 break; 469 } 470 break; 471 } 472 } 473 474 if ( -1 != nPropertyId ) 475 aRet = implGetControlProperty( pControl, nPropertyId ); 476 } 477 478 return aRet; 479 } 480 481 //----------------------------------------------------------------------------- 482 void OControlAccess::setLabel( sal_Int16 nId, const ::rtl::OUString &rLabel ) 483 { 484 Control* pControl = m_pFilePickerController->getControl( nId, sal_True ); 485 DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" ); 486 if ( pControl ) 487 pControl->SetText( rLabel ); 488 } 489 490 //----------------------------------------------------------------------------- 491 ::rtl::OUString OControlAccess::getLabel( sal_Int16 nId ) const 492 { 493 ::rtl::OUString sLabel; 494 495 Control* pControl = m_pFilePickerController->getControl( nId, sal_True ); 496 DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" ); 497 if ( pControl ) 498 sLabel = pControl->GetText(); 499 500 return sLabel; 501 } 502 503 //----------------------------------------------------------------------------- 504 void OControlAccess::enableControl( sal_Int16 _nId, sal_Bool _bEnable ) 505 { 506 m_pFilePickerController->enableControl( _nId, _bEnable ); 507 } 508 509 // ----------------------------------------------------------------------- 510 void OControlAccess::implDoListboxAction( ListBox* _pListbox, sal_Int16 _nControlAction, const Any& _rValue ) 511 { 512 switch ( _nControlAction ) 513 { 514 case ControlActions::ADD_ITEM: 515 { 516 ::rtl::OUString aEntry; 517 _rValue >>= aEntry; 518 if ( aEntry.getLength() ) 519 _pListbox->InsertEntry( aEntry ); 520 } 521 break; 522 523 case ControlActions::ADD_ITEMS: 524 { 525 Sequence < ::rtl::OUString > aTemplateList; 526 _rValue >>= aTemplateList; 527 528 if ( aTemplateList.getLength() ) 529 { 530 for ( long i=0; i < aTemplateList.getLength(); i++ ) 531 _pListbox->InsertEntry( aTemplateList[i] ); 532 } 533 } 534 break; 535 536 case ControlActions::DELETE_ITEM: 537 { 538 sal_Int32 nPos = 0; 539 if ( _rValue >>= nPos ) 540 _pListbox->RemoveEntry( (sal_uInt16) nPos ); 541 } 542 break; 543 544 case ControlActions::DELETE_ITEMS: 545 _pListbox->Clear(); 546 break; 547 548 default: 549 DBG_ERRORFILE( "Wrong ControlAction for implDoListboxAction()" ); 550 } 551 } 552 553 //----------------------------------------------------------------------------- 554 void OControlAccess::implSetControlProperty( sal_Int16 _nControlId, Control* _pControl, sal_Int16 _nProperty, const Any& _rValue, sal_Bool _bIgnoreIllegalArgument ) 555 { 556 if ( !_pControl ) 557 _pControl = m_pFilePickerController->getControl( _nControlId ); 558 DBG_ASSERT( _pControl, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" ); 559 if ( !_pControl ) 560 return; 561 562 DBG_ASSERT( _pControl == m_pFilePickerController->getControl( _nControlId ), 563 "OControlAccess::implSetControlProperty: inconsistent parameters!" ); 564 565 switch ( _nProperty ) 566 { 567 case PROPERTY_FLAG_TEXT: 568 { 569 ::rtl::OUString sText; 570 if ( _rValue >>= sText ) 571 { 572 _pControl->SetText( sText ); 573 } 574 else if ( !_bIgnoreIllegalArgument ) 575 { 576 lcl_throwIllegalArgumentException(); 577 } 578 } 579 break; 580 581 case PROPERTY_FLAG_ENDBALED: 582 { 583 sal_Bool bEnabled = sal_False; 584 if ( _rValue >>= bEnabled ) 585 { 586 m_pFilePickerController->enableControl( _nControlId, bEnabled ); 587 } 588 else if ( !_bIgnoreIllegalArgument ) 589 { 590 lcl_throwIllegalArgumentException(); 591 } 592 } 593 break; 594 595 case PROPERTY_FLAG_VISIBLE: 596 { 597 sal_Bool bVisible = sal_False; 598 if ( _rValue >>= bVisible ) 599 { 600 _pControl->Show( bVisible ); 601 } 602 else if ( !_bIgnoreIllegalArgument ) 603 { 604 lcl_throwIllegalArgumentException(); 605 } 606 } 607 break; 608 609 case PROPERTY_FLAG_HELPURL: 610 { 611 ::rtl::OUString sHelpURL; 612 if ( _rValue >>= sHelpURL ) 613 { 614 setHelpURL( _pControl, sHelpURL, m_pFileView == _pControl ); 615 } 616 else if ( !_bIgnoreIllegalArgument ) 617 { 618 lcl_throwIllegalArgumentException(); 619 } 620 } 621 break; 622 623 case PROPERTY_FLAG_LISTITEMS: 624 { 625 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), 626 "OControlAccess::implSetControlProperty: invalid control/property combination!" ); 627 628 Sequence< ::rtl::OUString > aItems; 629 if ( _rValue >>= aItems ) 630 { 631 // remove all previous items 632 static_cast< ListBox* >( _pControl )->Clear(); 633 634 // add the new ones 635 const ::rtl::OUString* pItems = aItems.getConstArray(); 636 const ::rtl::OUString* pItemsEnd = aItems.getConstArray() + aItems.getLength(); 637 for ( const ::rtl::OUString* pItem = pItems; 638 pItem != pItemsEnd; 639 ++pItem 640 ) 641 { 642 static_cast< ListBox* >( _pControl )->InsertEntry( *pItem ); 643 } 644 645 } 646 else if ( !_bIgnoreIllegalArgument ) 647 { 648 lcl_throwIllegalArgumentException(); 649 } 650 } 651 break; 652 653 case PROPERTY_FLAG_SELECTEDITEM: 654 { 655 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), 656 "OControlAccess::implSetControlProperty: invalid control/property combination!" ); 657 658 ::rtl::OUString sSelected; 659 if ( _rValue >>= sSelected ) 660 { 661 static_cast< ListBox* >( _pControl )->SelectEntry( sSelected ); 662 } 663 else if ( !_bIgnoreIllegalArgument ) 664 { 665 lcl_throwIllegalArgumentException(); 666 } 667 } 668 break; 669 670 case PROPERTY_FLAG_SELECTEDITEMINDEX: 671 { 672 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), 673 "OControlAccess::implSetControlProperty: invalid control/property combination!" ); 674 675 sal_Int32 nPos = 0; 676 if ( _rValue >>= nPos ) 677 { 678 static_cast< ListBox* >( _pControl )->SelectEntryPos( (sal_uInt16) nPos ); 679 } 680 else if ( !_bIgnoreIllegalArgument ) 681 { 682 lcl_throwIllegalArgumentException(); 683 } 684 } 685 break; 686 687 case PROPERTY_FLAG_CHECKED: 688 { 689 DBG_ASSERT( WINDOW_CHECKBOX == _pControl->GetType(), 690 "OControlAccess::implSetControlProperty: invalid control/property combination!" ); 691 692 sal_Bool bChecked = sal_False; 693 if ( _rValue >>= bChecked ) 694 { 695 static_cast< CheckBox* >( _pControl )->Check( bChecked ); 696 } 697 else if ( !_bIgnoreIllegalArgument ) 698 { 699 lcl_throwIllegalArgumentException(); 700 } 701 } 702 break; 703 704 default: 705 DBG_ERROR( "OControlAccess::implSetControlProperty: invalid property id!" ); 706 } 707 } 708 709 //----------------------------------------------------------------------------- 710 Any OControlAccess::implGetControlProperty( Control* _pControl, sal_Int16 _nProperty ) const 711 { 712 DBG_ASSERT( _pControl, "OControlAccess::implGetControlProperty: invalid argument, this will crash!" ); 713 714 Any aReturn; 715 switch ( _nProperty ) 716 { 717 case PROPERTY_FLAG_TEXT: 718 aReturn <<= ::rtl::OUString( _pControl->GetText() ); 719 break; 720 721 case PROPERTY_FLAG_ENDBALED: 722 aReturn <<= (sal_Bool)_pControl->IsEnabled(); 723 break; 724 725 case PROPERTY_FLAG_VISIBLE: 726 aReturn <<= (sal_Bool)_pControl->IsVisible(); 727 break; 728 729 case PROPERTY_FLAG_HELPURL: 730 aReturn <<= getHelpURL( _pControl, m_pFileView == _pControl ); 731 break; 732 733 case PROPERTY_FLAG_LISTITEMS: 734 { 735 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), 736 "OControlAccess::implGetControlProperty: invalid control/property combination!" ); 737 738 Sequence< ::rtl::OUString > aItems( static_cast< ListBox* >( _pControl )->GetEntryCount() ); 739 ::rtl::OUString* pItems = aItems.getArray(); 740 for ( sal_uInt16 i=0; i<static_cast< ListBox* >( _pControl )->GetEntryCount(); ++i ) 741 *pItems++ = static_cast< ListBox* >( _pControl )->GetEntry( i ); 742 743 aReturn <<= aItems; 744 } 745 break; 746 747 case PROPERTY_FLAG_SELECTEDITEM: 748 { 749 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), 750 "OControlAccess::implGetControlProperty: invalid control/property combination!" ); 751 752 sal_uInt16 nSelected = static_cast< ListBox* >( _pControl )->GetSelectEntryPos(); 753 ::rtl::OUString sSelected; 754 if ( LISTBOX_ENTRY_NOTFOUND != nSelected ) 755 sSelected = static_cast< ListBox* >( _pControl )->GetSelectEntry(); 756 aReturn <<= sSelected; 757 } 758 break; 759 760 case PROPERTY_FLAG_SELECTEDITEMINDEX: 761 { 762 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), 763 "OControlAccess::implGetControlProperty: invalid control/property combination!" ); 764 765 sal_uInt16 nSelected = static_cast< ListBox* >( _pControl )->GetSelectEntryPos(); 766 if ( LISTBOX_ENTRY_NOTFOUND != nSelected ) 767 aReturn <<= (sal_Int32)static_cast< ListBox* >( _pControl )->GetSelectEntryPos(); 768 else 769 aReturn <<= (sal_Int32)-1; 770 } 771 break; 772 773 case PROPERTY_FLAG_CHECKED: 774 DBG_ASSERT( WINDOW_CHECKBOX == _pControl->GetType(), 775 "OControlAccess::implGetControlProperty: invalid control/property combination!" ); 776 777 aReturn <<= (sal_Bool)static_cast< CheckBox* >( _pControl )->IsChecked( ); 778 break; 779 780 default: 781 DBG_ERROR( "OControlAccess::implGetControlProperty: invalid property id!" ); 782 } 783 return aReturn; 784 } 785 786 //......................................................................... 787 } // namespace svt 788 //......................................................................... 789 790