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_framework.hxx" 30 31 #include <uielement/toolbarmerger.hxx> 32 #include <uielement/generictoolbarcontroller.hxx> 33 #include <framework/imageproducer.hxx> 34 35 #include <svtools/miscopt.hxx> 36 37 namespace framework 38 { 39 40 static const char MERGE_TOOLBAR_URL[] = "URL"; 41 static const sal_uInt32 MERGE_TOOLBAR_URL_LEN = 3; 42 static const char MERGE_TOOLBAR_TITLE[] = "Title"; 43 static const sal_uInt32 MERGE_TOOLBAR_TITLE_LEN = 5; 44 static const char MERGE_TOOLBAR_IMAGEID[] = "ImageIdentifier"; 45 static const sal_uInt32 MERGE_TOOLBAR_IMAGEID_LEN = 15; 46 static const char MERGE_TOOLBAR_CONTEXT[] = "Context"; 47 static const sal_uInt32 MERGE_TOOLBAR_CONTEXT_LEN = 7; 48 static const char MERGE_TOOLBAR_TARGET[] = "Target"; 49 static const sal_uInt32 MERGE_TOOLBAR_TARGET_LEN = 6; 50 static const char MERGE_TOOLBAR_CONTROLTYPE[] = "ControlType"; 51 static const char MERGE_TOOLBAR_CONTROLTYPE_LEN = 11; 52 static const char MERGE_TOOLBAR_WIDTH[] = "Width"; 53 static const char MERGE_TOOLBAR_WIDTH_LEN = 5; 54 55 static const char MERGECOMMAND_ADDAFTER[] = "AddAfter"; 56 static const sal_uInt32 MERGECOMMAND_ADDAFTER_LEN = 8; 57 static const char MERGECOMMAND_ADDBEFORE[] = "AddBefore"; 58 static const sal_uInt32 MERGECOMMAND_ADDBEFORE_LEN = 9; 59 static const char MERGECOMMAND_REPLACE[] = "Replace"; 60 static const sal_uInt32 MERGECOMMAND_REPLACE_LEN = 7; 61 static const char MERGECOMMAND_REMOVE[] = "Remove"; 62 static const sal_uInt32 MERGECOMMAND_REMOVE_LEN = 6; 63 64 static const char MERGEFALLBACK_ADDLAST[] = "AddLast"; 65 static const char MERGEFALLBACK_ADDLAST_LEN = 7; 66 static const char MERGEFALLBACK_ADDFIRST[] = "AddFirst"; 67 static const char MERGEFALLBACK_ADDFIRST_LEN = 8; 68 static const char MERGEFALLBACK_IGNORE[] = "Ignore"; 69 static const char MERGEFALLBACK_IGNORE_LEN = 6; 70 71 static const char TOOLBARCONTROLLER_BUTTON[] = "Button"; 72 static const sal_uInt32 TOOLBARCONTROLLER_BUTTON_LEN = 6; 73 static const char TOOLBARCONTROLLER_COMBOBOX[] = "Combobox"; 74 static const sal_uInt32 TOOLBARCONTROLLER_COMBOBOX_LEN = 8; 75 static const char TOOLBARCONTROLLER_EDIT[] = "Editfield"; 76 static const sal_uInt32 TOOLBARCONTROLLER_EDIT_LEN = 9; 77 static const char TOOLBARCONTROLLER_SPINFIELD[] = "Spinfield"; 78 static const sal_uInt32 TOOLBARCONTROLLER_SPINFIELD_LEN = 9; 79 static const char TOOLBARCONTROLLER_IMGBUTTON[] = "ImageButton"; 80 static const sal_uInt32 TOOLBARCONTROLLER_IMGBUTTON_LEN = 11; 81 static const char TOOLBARCONTROLLER_DROPDOWNBOX[] = "Dropdownbox"; 82 static const sal_uInt32 TOOLBARCONTROLLER_DROPDOWNBOX_LEN = 11; 83 static const char TOOLBARCONTROLLER_DROPDOWNBTN[] = "DropdownButton"; 84 static const sal_uInt32 TOOLBARCONTROLLER_DROPDOWNBTN_LEN = 14; 85 static const char TOOLBARCONTROLLER_TOGGLEDDBTN[] = "ToggleDropdownButton"; 86 static const sal_uInt32 TOOLBARCONTROLLER_TOGGLEDDBTN_LEN = 20; 87 88 static const char TOOLBOXITEM_SEPARATOR_STR[] = "private:separator"; 89 static const sal_uInt16 TOOLBOXITEM_SEPARATOR_STR_LEN = sizeof( TOOLBOXITEM_SEPARATOR_STR )-1; 90 91 using namespace ::com::sun::star; 92 93 /** 94 Check whether a module identifier is part of a context 95 defined by a colon separated list of module identifier. 96 97 @param 98 rContext 99 100 Describes a context string list where all contexts 101 are delimited by a colon. For more information about 102 the module identifier used as context strings see the 103 IDL description of com::sun::star::frame::XModuleManager 104 105 @param 106 rModuleIdentifier 107 108 A string describing a module identifier. See IDL 109 description of com::sun::star::frame::XModuleManager. 110 111 @result 112 The result is true if the rContext is an empty string 113 or rModuleIdentifier is part of the context string. 114 115 */ 116 bool ToolBarMerger::IsCorrectContext( 117 const ::rtl::OUString& rContext, 118 const ::rtl::OUString& rModuleIdentifier ) 119 { 120 return (( rContext.getLength() == 0 ) || ( rContext.indexOf( rModuleIdentifier ) >= 0 )); 121 } 122 123 /** 124 Converts a sequence, sequence of property values to 125 a vector of structs. 126 127 @param 128 rSequence 129 130 Provides a sequence, sequence of property values. 131 132 @param 133 rContainer 134 135 A vector of AddonToolbarItems which will hold the 136 conversion from the rSequence argument. 137 138 @result 139 The result is true if the sequence, sequence of property 140 values could be converted to a vector of structs. 141 142 */ 143 bool ToolBarMerger::ConvertSeqSeqToVector( 144 const uno::Sequence< uno::Sequence< beans::PropertyValue > > rSequence, 145 AddonToolbarItemContainer& rContainer ) 146 { 147 sal_Int32 nLen( rSequence.getLength() ); 148 for ( sal_Int32 i = 0; i < nLen; i++ ) 149 { 150 AddonToolbarItem aAddonToolbarItem; 151 ConvertSequenceToValues( rSequence[i], 152 aAddonToolbarItem.aCommandURL, 153 aAddonToolbarItem.aLabel, 154 aAddonToolbarItem.aImageIdentifier, 155 aAddonToolbarItem.aTarget, 156 aAddonToolbarItem.aContext, 157 aAddonToolbarItem.aControlType, 158 aAddonToolbarItem.nWidth ); 159 rContainer.push_back( aAddonToolbarItem ); 160 } 161 162 return true; 163 } 164 165 /** 166 Converts a sequence of property values to single 167 values. 168 169 @param 170 rSequence 171 172 Provides a sequence of property values. 173 174 @param 175 rCommandURL 176 177 Contains the value of the property with 178 Name="CommandURL". 179 180 @param 181 rLabel 182 183 Contains the value of the property with 184 Name="Title" 185 186 @param 187 rImageIdentifier 188 189 Contains the value of the property with 190 Name="ImageIdentifier" 191 192 @param 193 rTarget 194 195 Contains the value of the property with 196 Name="Target" 197 198 @param 199 rContext 200 201 Contains the value of the property with 202 Name="Context" 203 204 @param 205 rControlType 206 207 Contains the value of the property with 208 Name="ControlType" 209 210 @result 211 All possible mapping between sequence of property 212 values and the single values are done. 213 214 */ 215 void ToolBarMerger::ConvertSequenceToValues( 216 const uno::Sequence< beans::PropertyValue > rSequence, 217 ::rtl::OUString& rCommandURL, 218 ::rtl::OUString& rLabel, 219 ::rtl::OUString& rImageIdentifier, 220 ::rtl::OUString& rTarget, 221 ::rtl::OUString& rContext, 222 ::rtl::OUString& rControlType, 223 sal_uInt16& rWidth ) 224 { 225 for ( sal_Int32 i = 0; i < rSequence.getLength(); i++ ) 226 { 227 if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_URL, MERGE_TOOLBAR_URL_LEN )) 228 rSequence[i].Value >>= rCommandURL; 229 else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_TITLE, MERGE_TOOLBAR_TITLE_LEN )) 230 rSequence[i].Value >>= rLabel; 231 else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_IMAGEID, MERGE_TOOLBAR_IMAGEID_LEN )) 232 rSequence[i].Value >>= rImageIdentifier; 233 else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_CONTEXT, MERGE_TOOLBAR_CONTEXT_LEN )) 234 rSequence[i].Value >>= rContext; 235 else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_TARGET, MERGE_TOOLBAR_TARGET_LEN )) 236 rSequence[i].Value >>= rTarget; 237 else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_CONTROLTYPE, MERGE_TOOLBAR_CONTROLTYPE_LEN )) 238 rSequence[i].Value >>= rControlType; 239 else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_WIDTH, MERGE_TOOLBAR_WIDTH_LEN )) 240 { 241 sal_Int32 aValue = 0; 242 rSequence[i].Value >>= aValue; 243 rWidth = sal_uInt16( aValue ); 244 } 245 } 246 } 247 248 /** 249 Tries to find the reference point provided and delivers 250 position and result of the search process. 251 252 @param 253 pToolbar 254 255 Must be a valid pointer to a toolbar with items which 256 should be searched. 257 258 @param 259 rReferencePoint 260 261 A command URL which should be the reference point for 262 the coming merge operation. 263 264 @result 265 Provides information about the search result, the 266 position of the reference point and the toolbar used. 267 */ 268 ReferenceToolbarPathInfo ToolBarMerger::FindReferencePoint( 269 ToolBox* pToolbar, 270 const ::rtl::OUString& rReferencePoint ) 271 { 272 ReferenceToolbarPathInfo aResult; 273 aResult.bResult = false; 274 aResult.pToolbar = pToolbar; 275 aResult.nPos = TOOLBOX_ITEM_NOTFOUND; 276 277 const sal_uInt16 nSize( pToolbar->GetItemCount() ); 278 279 for ( sal_uInt16 i = 0; i < nSize; i++ ) 280 { 281 const sal_uInt16 nItemId = pToolbar->GetItemId( i ); 282 if ( nItemId > 0 ) 283 { 284 const ::rtl::OUString rCmd = pToolbar->GetItemCommand( nItemId ); 285 if ( rCmd == rReferencePoint ) 286 { 287 aResult.bResult = true; 288 aResult.nPos = i; 289 return aResult; 290 } 291 } 292 } 293 294 return aResult; 295 } 296 297 /** 298 Processes a merge operation. 299 300 @param 301 xFrame 302 303 Must be a valid reference to a frame. 304 305 @param 306 pToolbar 307 308 A valid pointer to the toolbar where the merge 309 operation is applied to. 310 311 @param 312 nPos 313 314 The reference position of the toolbar item for 315 the merge operation. Value must be between 316 0 and number of toolbar items - 1. 317 318 @param 319 rItemId 320 321 A unique item ID. 322 323 @param 324 rModuleIdentifier 325 326 The current application module context. 327 328 @param 329 rMergeCommand 330 331 A merge command. 332 333 @param 334 rMergeCommandParameter. 335 336 An optional argument for the merge command. 337 338 @param 339 rItems 340 341 Toolbar items which are associated to the merge 342 command. 343 344 @result 345 Returns true for a successful operation otherwise 346 false. 347 */ 348 bool ToolBarMerger::ProcessMergeOperation( 349 const uno::Reference< frame::XFrame >& xFrame, 350 ToolBox* pToolbar, 351 sal_uInt16 nPos, 352 sal_uInt16& rItemId, 353 CommandToInfoMap& rCommandMap, 354 const ::rtl::OUString& rModuleIdentifier, 355 const ::rtl::OUString& rMergeCommand, 356 const ::rtl::OUString& rMergeCommandParameter, 357 const AddonToolbarItemContainer& rItems ) 358 { 359 if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDAFTER, MERGECOMMAND_ADDAFTER_LEN )) 360 return MergeItems( xFrame, pToolbar, nPos, 1, rItemId, rCommandMap, rModuleIdentifier, rItems ); 361 else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDBEFORE, MERGECOMMAND_ADDBEFORE_LEN )) 362 return MergeItems( xFrame, pToolbar, nPos, 0, rItemId, rCommandMap, rModuleIdentifier, rItems ); 363 else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REPLACE, MERGECOMMAND_REPLACE_LEN )) 364 return ReplaceItem( xFrame, pToolbar, nPos, rItemId, rCommandMap, rModuleIdentifier, rItems ); 365 else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REMOVE, MERGECOMMAND_REMOVE_LEN )) 366 return RemoveItems( pToolbar, nPos, rMergeCommandParameter ); 367 368 return false; 369 } 370 371 /** 372 Processes a merge fallback operation. 373 374 @param 375 xFrame 376 377 Must be a valid reference to a frame. 378 379 @param 380 pToolbar 381 382 A valid pointer to the toolbar where the merge 383 fall back operation is applied to. 384 385 @param 386 nPos 387 388 The reference position of the toolbar item for 389 the merge operation. Value must be between 390 0 and number of toolbar items - 1. 391 392 @param 393 rItemId 394 395 A unique item ID. 396 397 @param 398 rModuleIdentifier 399 400 The current application module context. 401 402 @param 403 rMergeCommand 404 405 A merge command. 406 407 @param 408 rItems 409 410 Toolbar items which are associated to the merge 411 command. 412 413 @result 414 Returns true for a successful operation otherwise 415 false. 416 */ 417 bool ToolBarMerger::ProcessMergeFallback( 418 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, 419 ToolBox* pToolbar, 420 sal_uInt16 /*nPos*/, 421 sal_uInt16& rItemId, 422 CommandToInfoMap& rCommandMap, 423 const ::rtl::OUString& rModuleIdentifier, 424 const ::rtl::OUString& rMergeCommand, 425 const ::rtl::OUString& rMergeFallback, 426 const AddonToolbarItemContainer& rItems ) 427 { 428 if (( rMergeFallback.equalsAsciiL( MERGEFALLBACK_IGNORE, MERGEFALLBACK_IGNORE_LEN )) || 429 ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REPLACE, MERGECOMMAND_REPLACE_LEN )) || 430 ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REMOVE, MERGECOMMAND_REMOVE_LEN )) ) 431 { 432 return true; 433 } 434 else if (( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDBEFORE, MERGECOMMAND_ADDBEFORE_LEN )) || 435 ( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDAFTER, MERGECOMMAND_ADDAFTER_LEN )) ) 436 { 437 if ( rMergeFallback.equalsAsciiL( MERGEFALLBACK_ADDFIRST, MERGEFALLBACK_ADDFIRST_LEN )) 438 return MergeItems( xFrame, pToolbar, 0, 0, rItemId, rCommandMap, rModuleIdentifier, rItems ); 439 else if ( rMergeFallback.equalsAsciiL( MERGEFALLBACK_ADDLAST, MERGEFALLBACK_ADDLAST_LEN )) 440 return MergeItems( xFrame, pToolbar, TOOLBOX_APPEND, 0, rItemId, rCommandMap, rModuleIdentifier, rItems ); 441 } 442 443 return false; 444 } 445 446 /** 447 Merges (adds) toolbar items into an existing toolbar. 448 449 @param 450 xFrame 451 452 Must be a valid reference to a frame. 453 454 @param 455 pToolbar 456 457 A valid pointer to the toolbar where the merge 458 fall back operation is applied to. 459 460 @param 461 nPos 462 463 The reference position of the toolbar item for 464 the merge operation. Value must be between 465 0 and number of toolbar items - 1. 466 467 @param 468 rItemId 469 470 A unique item ID. 471 472 @param 473 rModuleIdentifier 474 475 The current application module context. 476 477 @param 478 rItems 479 480 Toolbar items which are associated to the merge 481 command. 482 483 @result 484 Returns true for a successful operation otherwise 485 false. 486 */ 487 bool ToolBarMerger::MergeItems( 488 const uno::Reference< frame::XFrame >& rFrame, 489 ToolBox* pToolbar, 490 sal_uInt16 nPos, 491 sal_uInt16 nModIndex, 492 sal_uInt16& rItemId, 493 CommandToInfoMap& rCommandMap, 494 const ::rtl::OUString& rModuleIdentifier, 495 const AddonToolbarItemContainer& rAddonToolbarItems ) 496 { 497 const sal_Int32 nSize( rAddonToolbarItems.size() ); 498 499 uno::Reference< frame::XFrame > xFrame( rFrame ); 500 501 sal_uInt16 nIndex( 0 ); 502 for ( sal_Int32 i = 0; i < nSize; i++ ) 503 { 504 const AddonToolbarItem& rItem = rAddonToolbarItems[i]; 505 if ( IsCorrectContext( rItem.aContext, rModuleIdentifier )) 506 { 507 sal_Int32 nInsPos = nPos+nModIndex+i; 508 if ( nInsPos > sal_Int32( pToolbar->GetItemCount() )) 509 nInsPos = TOOLBOX_APPEND; 510 511 if ( rItem.aCommandURL.equalsAsciiL( TOOLBOXITEM_SEPARATOR_STR, TOOLBOXITEM_SEPARATOR_STR_LEN )) 512 pToolbar->InsertSeparator( sal_uInt16( nInsPos )); 513 else 514 { 515 CommandToInfoMap::iterator pIter = rCommandMap.find( rItem.aCommandURL ); 516 if ( pIter == rCommandMap.end()) 517 { 518 CommandInfo aCmdInfo; 519 aCmdInfo.nId = rItemId; 520 rCommandMap.insert( CommandToInfoMap::value_type( rItem.aCommandURL, aCmdInfo )); 521 } 522 else 523 { 524 pIter->second.aIds.push_back( rItemId ); 525 } 526 527 ToolBarMerger::CreateToolbarItem( pToolbar, rCommandMap, sal_uInt16( nInsPos ), rItemId, rItem ); 528 } 529 530 ++nIndex; 531 ++rItemId; 532 } 533 } 534 535 return true; 536 } 537 538 /** 539 Replaces a toolbar item with new items for an 540 existing toolbar. 541 542 @param 543 xFrame 544 545 Must be a valid reference to a frame. 546 547 @param 548 pToolbar 549 550 A valid pointer to the toolbar where the merge 551 fall back operation is applied to. 552 553 @param 554 nPos 555 556 The reference position of the toolbar item for 557 the merge operation. Value must be between 558 0 and number of toolbar items - 1. 559 560 @param 561 rItemId 562 563 A unique item ID. 564 565 @param 566 rModuleIdentifier 567 568 The current application module context. 569 570 @param 571 rItems 572 573 Toolbar items which are associated to the merge 574 command. 575 576 @result 577 Returns true for a successful operation otherwise 578 false. 579 */ 580 bool ToolBarMerger::ReplaceItem( 581 const uno::Reference< frame::XFrame >& xFrame, 582 ToolBox* pToolbar, 583 sal_uInt16 nPos, 584 sal_uInt16& rItemId, 585 CommandToInfoMap& rCommandMap, 586 const ::rtl::OUString& rModuleIdentifier, 587 const AddonToolbarItemContainer& rAddonToolbarItems ) 588 { 589 pToolbar->RemoveItem( nPos ); 590 return MergeItems( xFrame, pToolbar, nPos, 0, rItemId, rCommandMap, rModuleIdentifier, rAddonToolbarItems ); 591 } 592 593 /** 594 Removes toolbar items from an existing toolbar. 595 596 @param 597 pToolbar 598 599 A valid pointer to the toolbar where the merge 600 fall back operation is applied to. 601 602 @param 603 nPos 604 605 The reference position of the toolbar item for 606 the merge operation. Value must be between 607 0 and number of toolbar items - 1. 608 609 @param 610 rMergeCommandParameter. 611 612 An optional argument for the merge command. 613 614 @result 615 Returns true for a successful operation otherwise 616 false. 617 */ 618 bool ToolBarMerger::RemoveItems( 619 ToolBox* pToolbar, 620 sal_uInt16 nPos, 621 const ::rtl::OUString& rMergeCommandParameter ) 622 { 623 sal_Int32 nCount = rMergeCommandParameter.toInt32(); 624 if ( nCount > 0 ) 625 { 626 for ( sal_Int32 i = 0; i < nCount; i++ ) 627 { 628 if ( nPos < pToolbar->GetItemCount() ) 629 pToolbar->RemoveItem( nPos ); 630 } 631 } 632 return true; 633 } 634 635 /** 636 Removes toolbar items from an existing toolbar. 637 638 @param 639 pToolbar 640 641 A valid pointer to the toolbar where the merge 642 fall back operation is applied to. 643 644 @param 645 nPos 646 647 The reference position of the toolbar item for 648 the merge operation. Value must be between 649 0 and number of toolbar items - 1. 650 651 @param 652 rMergeCommandParameter. 653 654 An optional argument for the merge command. 655 656 @result 657 Returns true for a successful operation otherwise 658 false. 659 */ 660 ::cppu::OWeakObject* ToolBarMerger::CreateController( 661 uno::Reference< lang::XMultiServiceFactory > xSMGR, 662 uno::Reference< frame::XFrame > xFrame, 663 ToolBox* pToolbar, 664 const ::rtl::OUString& rCommandURL, 665 sal_uInt16 nId, 666 sal_uInt16 nWidth, 667 const ::rtl::OUString& rControlType ) 668 { 669 ::cppu::OWeakObject* pResult( 0 ); 670 671 if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_BUTTON, TOOLBARCONTROLLER_BUTTON_LEN )) 672 pResult = new ButtonToolbarController( xSMGR, pToolbar, rCommandURL ); 673 else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_COMBOBOX, TOOLBARCONTROLLER_COMBOBOX_LEN )) 674 pResult = new ComboboxToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL ); 675 else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_EDIT, TOOLBARCONTROLLER_EDIT_LEN )) 676 pResult = new EditToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL ); 677 else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_SPINFIELD, TOOLBARCONTROLLER_SPINFIELD_LEN )) 678 pResult = new SpinfieldToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL ); 679 else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_IMGBUTTON, TOOLBARCONTROLLER_IMGBUTTON_LEN )) 680 pResult = new ImageButtonToolbarController( xSMGR, xFrame, pToolbar, nId, rCommandURL ); 681 else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_DROPDOWNBOX, TOOLBARCONTROLLER_DROPDOWNBOX_LEN )) 682 pResult = new DropdownToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL ); 683 else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_DROPDOWNBTN, TOOLBARCONTROLLER_DROPDOWNBTN_LEN )) 684 pResult = new ToggleButtonToolbarController( xSMGR, xFrame, pToolbar, nId, 685 ToggleButtonToolbarController::STYLE_DROPDOWNBUTTON, rCommandURL ); 686 else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_TOGGLEDDBTN, TOOLBARCONTROLLER_TOGGLEDDBTN_LEN )) 687 pResult = new ToggleButtonToolbarController( xSMGR, xFrame, pToolbar, nId, 688 ToggleButtonToolbarController::STYLE_TOGGLE_DROPDOWNBUTTON, rCommandURL ); 689 else 690 pResult = new GenericToolbarController( xSMGR, xFrame, pToolbar, nId, rCommandURL ); 691 692 return pResult; 693 } 694 695 void ToolBarMerger::CreateToolbarItem( ToolBox* pToolbar, CommandToInfoMap& rCommandMap, sal_uInt16 nPos, sal_uInt16 nItemId, const AddonToolbarItem& rItem ) 696 { 697 pToolbar->InsertItem( nItemId, rItem.aLabel, 0, nPos ); 698 pToolbar->SetItemCommand( nItemId, rItem.aCommandURL ); 699 pToolbar->SetQuickHelpText( nItemId, rItem.aLabel ); 700 pToolbar->SetItemText( nItemId, rItem.aLabel ); 701 pToolbar->EnableItem( nItemId, sal_True ); 702 pToolbar->SetItemState( nItemId, STATE_NOCHECK ); 703 704 CommandToInfoMap::iterator pIter = rCommandMap.find( rItem.aCommandURL ); 705 if ( pIter != rCommandMap.end() ) 706 pIter->second.nWidth = rItem.nWidth; 707 708 // Use the user data to store add-on specific data with the toolbar item 709 AddonsParams* pAddonParams = new AddonsParams; 710 pAddonParams->aImageId = rItem.aImageIdentifier; 711 pAddonParams->aTarget = rItem.aTarget; 712 pAddonParams->aControlType = rItem.aControlType; 713 pToolbar->SetItemData( nItemId, pAddonParams ); 714 } 715 716 } // namespace framework 717