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