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