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