Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <uielement/toolbarmerger.hxx>
31 : : #include <uielement/generictoolbarcontroller.hxx>
32 : : #include <framework/imageproducer.hxx>
33 : :
34 : : #include <svtools/miscopt.hxx>
35 : :
36 : : namespace framework
37 : : {
38 : :
39 : : static const char MERGE_TOOLBAR_URL[] = "URL";
40 : : static const sal_uInt32 MERGE_TOOLBAR_URL_LEN = 3;
41 : : static const char MERGE_TOOLBAR_TITLE[] = "Title";
42 : : static const sal_uInt32 MERGE_TOOLBAR_TITLE_LEN = 5;
43 : : static const char MERGE_TOOLBAR_IMAGEID[] = "ImageIdentifier";
44 : : static const sal_uInt32 MERGE_TOOLBAR_IMAGEID_LEN = 15;
45 : : static const char MERGE_TOOLBAR_CONTEXT[] = "Context";
46 : : static const sal_uInt32 MERGE_TOOLBAR_CONTEXT_LEN = 7;
47 : : static const char MERGE_TOOLBAR_TARGET[] = "Target";
48 : : static const sal_uInt32 MERGE_TOOLBAR_TARGET_LEN = 6;
49 : : static const char MERGE_TOOLBAR_CONTROLTYPE[] = "ControlType";
50 : : static const char MERGE_TOOLBAR_CONTROLTYPE_LEN = 11;
51 : : static const char MERGE_TOOLBAR_WIDTH[] = "Width";
52 : : static const char MERGE_TOOLBAR_WIDTH_LEN = 5;
53 : :
54 : : static const char MERGECOMMAND_ADDAFTER[] = "AddAfter";
55 : : static const sal_uInt32 MERGECOMMAND_ADDAFTER_LEN = 8;
56 : : static const char MERGECOMMAND_ADDBEFORE[] = "AddBefore";
57 : : static const sal_uInt32 MERGECOMMAND_ADDBEFORE_LEN = 9;
58 : : static const char MERGECOMMAND_REPLACE[] = "Replace";
59 : : static const sal_uInt32 MERGECOMMAND_REPLACE_LEN = 7;
60 : : static const char MERGECOMMAND_REMOVE[] = "Remove";
61 : : static const sal_uInt32 MERGECOMMAND_REMOVE_LEN = 6;
62 : :
63 : : static const char MERGEFALLBACK_ADDLAST[] = "AddLast";
64 : : static const char MERGEFALLBACK_ADDLAST_LEN = 7;
65 : : static const char MERGEFALLBACK_ADDFIRST[] = "AddFirst";
66 : : static const char MERGEFALLBACK_ADDFIRST_LEN = 8;
67 : : static const char MERGEFALLBACK_IGNORE[] = "Ignore";
68 : : static const char MERGEFALLBACK_IGNORE_LEN = 6;
69 : :
70 : : static const char TOOLBARCONTROLLER_BUTTON[] = "Button";
71 : : static const sal_uInt32 TOOLBARCONTROLLER_BUTTON_LEN = 6;
72 : : static const char TOOLBARCONTROLLER_COMBOBOX[] = "Combobox";
73 : : static const sal_uInt32 TOOLBARCONTROLLER_COMBOBOX_LEN = 8;
74 : : static const char TOOLBARCONTROLLER_EDIT[] = "Editfield";
75 : : static const sal_uInt32 TOOLBARCONTROLLER_EDIT_LEN = 9;
76 : : static const char TOOLBARCONTROLLER_SPINFIELD[] = "Spinfield";
77 : : static const sal_uInt32 TOOLBARCONTROLLER_SPINFIELD_LEN = 9;
78 : : static const char TOOLBARCONTROLLER_IMGBUTTON[] = "ImageButton";
79 : : static const sal_uInt32 TOOLBARCONTROLLER_IMGBUTTON_LEN = 11;
80 : : static const char TOOLBARCONTROLLER_DROPDOWNBOX[] = "Dropdownbox";
81 : : static const sal_uInt32 TOOLBARCONTROLLER_DROPDOWNBOX_LEN = 11;
82 : : static const char TOOLBARCONTROLLER_DROPDOWNBTN[] = "DropdownButton";
83 : : static const sal_uInt32 TOOLBARCONTROLLER_DROPDOWNBTN_LEN = 14;
84 : : static const char TOOLBARCONTROLLER_TOGGLEDDBTN[] = "ToggleDropdownButton";
85 : : static const sal_uInt32 TOOLBARCONTROLLER_TOGGLEDDBTN_LEN = 20;
86 : :
87 : : static const char TOOLBOXITEM_SEPARATOR_STR[] = "private:separator";
88 : : static const sal_uInt16 TOOLBOXITEM_SEPARATOR_STR_LEN = sizeof( TOOLBOXITEM_SEPARATOR_STR )-1;
89 : :
90 : : using namespace ::com::sun::star;
91 : :
92 : : /**
93 : : Check whether a module identifier is part of a context
94 : : defined by a colon separated list of module identifier.
95 : :
96 : : @param
97 : : rContext
98 : :
99 : : Describes a context string list where all contexts
100 : : are delimited by a colon. For more information about
101 : : the module identifier used as context strings see the
102 : : IDL description of com::sun::star::frame::XModuleManager
103 : :
104 : : @param
105 : : rModuleIdentifier
106 : :
107 : : A string describing a module identifier. See IDL
108 : : description of com::sun::star::frame::XModuleManager.
109 : :
110 : : @result
111 : : The result is true if the rContext is an empty string
112 : : or rModuleIdentifier is part of the context string.
113 : :
114 : : */
115 : 0 : bool ToolBarMerger::IsCorrectContext(
116 : : const ::rtl::OUString& rContext,
117 : : const ::rtl::OUString& rModuleIdentifier )
118 : : {
119 [ # # ][ # # ]: 0 : return ( rContext.isEmpty() || ( rContext.indexOf( rModuleIdentifier ) >= 0 ));
120 : : }
121 : :
122 : : /**
123 : : Converts a sequence, sequence of property values to
124 : : a vector of structs.
125 : :
126 : : @param
127 : : rSequence
128 : :
129 : : Provides a sequence, sequence of property values.
130 : :
131 : : @param
132 : : rContainer
133 : :
134 : : A vector of AddonToolbarItems which will hold the
135 : : conversion from the rSequence argument.
136 : :
137 : : @result
138 : : The result is true if the sequence, sequence of property
139 : : values could be converted to a vector of structs.
140 : :
141 : : */
142 : 0 : bool ToolBarMerger::ConvertSeqSeqToVector(
143 : : const uno::Sequence< uno::Sequence< beans::PropertyValue > > rSequence,
144 : : AddonToolbarItemContainer& rContainer )
145 : : {
146 : 0 : sal_Int32 nLen( rSequence.getLength() );
147 [ # # ]: 0 : for ( sal_Int32 i = 0; i < nLen; i++ )
148 : : {
149 : 0 : AddonToolbarItem aAddonToolbarItem;
150 : 0 : ConvertSequenceToValues( rSequence[i],
151 : : aAddonToolbarItem.aCommandURL,
152 : : aAddonToolbarItem.aLabel,
153 : : aAddonToolbarItem.aImageIdentifier,
154 : : aAddonToolbarItem.aTarget,
155 : : aAddonToolbarItem.aContext,
156 : : aAddonToolbarItem.aControlType,
157 [ # # ][ # # ]: 0 : aAddonToolbarItem.nWidth );
[ # # ]
158 [ # # ]: 0 : rContainer.push_back( aAddonToolbarItem );
159 : 0 : }
160 : :
161 : 0 : return true;
162 : : }
163 : :
164 : : /**
165 : : Converts a sequence of property values to single
166 : : values.
167 : :
168 : : @param
169 : : rSequence
170 : :
171 : : Provides a sequence of property values.
172 : :
173 : : @param
174 : : rCommandURL
175 : :
176 : : Contains the value of the property with
177 : : Name="CommandURL".
178 : :
179 : : @param
180 : : rLabel
181 : :
182 : : Contains the value of the property with
183 : : Name="Title"
184 : :
185 : : @param
186 : : rImageIdentifier
187 : :
188 : : Contains the value of the property with
189 : : Name="ImageIdentifier"
190 : :
191 : : @param
192 : : rTarget
193 : :
194 : : Contains the value of the property with
195 : : Name="Target"
196 : :
197 : : @param
198 : : rContext
199 : :
200 : : Contains the value of the property with
201 : : Name="Context"
202 : :
203 : : @param
204 : : rControlType
205 : :
206 : : Contains the value of the property with
207 : : Name="ControlType"
208 : :
209 : : @result
210 : : All possible mapping between sequence of property
211 : : values and the single values are done.
212 : :
213 : : */
214 : 0 : void ToolBarMerger::ConvertSequenceToValues(
215 : : const uno::Sequence< beans::PropertyValue > rSequence,
216 : : ::rtl::OUString& rCommandURL,
217 : : ::rtl::OUString& rLabel,
218 : : ::rtl::OUString& rImageIdentifier,
219 : : ::rtl::OUString& rTarget,
220 : : ::rtl::OUString& rContext,
221 : : ::rtl::OUString& rControlType,
222 : : sal_uInt16& rWidth )
223 : : {
224 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rSequence.getLength(); i++ )
225 : : {
226 [ # # ]: 0 : if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_URL, MERGE_TOOLBAR_URL_LEN ))
227 : 0 : rSequence[i].Value >>= rCommandURL;
228 [ # # ]: 0 : else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_TITLE, MERGE_TOOLBAR_TITLE_LEN ))
229 : 0 : rSequence[i].Value >>= rLabel;
230 [ # # ]: 0 : else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_IMAGEID, MERGE_TOOLBAR_IMAGEID_LEN ))
231 : 0 : rSequence[i].Value >>= rImageIdentifier;
232 [ # # ]: 0 : else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_CONTEXT, MERGE_TOOLBAR_CONTEXT_LEN ))
233 : 0 : rSequence[i].Value >>= rContext;
234 [ # # ]: 0 : else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_TARGET, MERGE_TOOLBAR_TARGET_LEN ))
235 : 0 : rSequence[i].Value >>= rTarget;
236 [ # # ]: 0 : else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_CONTROLTYPE, MERGE_TOOLBAR_CONTROLTYPE_LEN ))
237 : 0 : rSequence[i].Value >>= rControlType;
238 [ # # ]: 0 : else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_WIDTH, MERGE_TOOLBAR_WIDTH_LEN ))
239 : : {
240 : 0 : sal_Int32 aValue = 0;
241 : 0 : rSequence[i].Value >>= aValue;
242 : 0 : rWidth = sal_uInt16( aValue );
243 : : }
244 : : }
245 : 0 : }
246 : :
247 : : /**
248 : : Tries to find the reference point provided and delivers
249 : : position and result of the search process.
250 : :
251 : : @param
252 : : pToolbar
253 : :
254 : : Must be a valid pointer to a toolbar with items which
255 : : should be searched.
256 : :
257 : : @param
258 : : rReferencePoint
259 : :
260 : : A command URL which should be the reference point for
261 : : the coming merge operation.
262 : :
263 : : @result
264 : : Provides information about the search result, the
265 : : position of the reference point and the toolbar used.
266 : : */
267 : 0 : ReferenceToolbarPathInfo ToolBarMerger::FindReferencePoint(
268 : : ToolBox* pToolbar,
269 : : const ::rtl::OUString& rReferencePoint )
270 : : {
271 : : ReferenceToolbarPathInfo aResult;
272 : 0 : aResult.bResult = false;
273 : 0 : aResult.pToolbar = pToolbar;
274 : 0 : aResult.nPos = TOOLBOX_ITEM_NOTFOUND;
275 : :
276 : 0 : const sal_uInt16 nSize( pToolbar->GetItemCount() );
277 : :
278 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nSize; i++ )
279 : : {
280 : 0 : const sal_uInt16 nItemId = pToolbar->GetItemId( i );
281 [ # # ]: 0 : if ( nItemId > 0 )
282 : : {
283 [ # # ][ # # ]: 0 : const ::rtl::OUString rCmd = pToolbar->GetItemCommand( nItemId );
284 [ # # ]: 0 : if ( rCmd == rReferencePoint )
285 : : {
286 : 0 : aResult.bResult = true;
287 : 0 : aResult.nPos = i;
288 : : return aResult;
289 [ # # ]: 0 : }
290 : : }
291 : : }
292 : :
293 : 0 : return aResult;
294 : : }
295 : :
296 : : /**
297 : : Processes a merge operation.
298 : :
299 : : @param
300 : : xFrame
301 : :
302 : : Must be a valid reference to a frame.
303 : :
304 : : @param
305 : : pToolbar
306 : :
307 : : A valid pointer to the toolbar where the merge
308 : : operation is applied to.
309 : :
310 : : @param
311 : : nPos
312 : :
313 : : The reference position of the toolbar item for
314 : : the merge operation. Value must be between
315 : : 0 and number of toolbar items - 1.
316 : :
317 : : @param
318 : : rItemId
319 : :
320 : : A unique item ID.
321 : :
322 : : @param
323 : : rModuleIdentifier
324 : :
325 : : The current application module context.
326 : :
327 : : @param
328 : : rMergeCommand
329 : :
330 : : A merge command.
331 : :
332 : : @param
333 : : rMergeCommandParameter.
334 : :
335 : : An optional argument for the merge command.
336 : :
337 : : @param
338 : : rItems
339 : :
340 : : Toolbar items which are associated to the merge
341 : : command.
342 : :
343 : : @result
344 : : Returns true for a successful operation otherwise
345 : : false.
346 : : */
347 : 0 : bool ToolBarMerger::ProcessMergeOperation(
348 : : const uno::Reference< frame::XFrame >& xFrame,
349 : : ToolBox* pToolbar,
350 : : sal_uInt16 nPos,
351 : : sal_uInt16& rItemId,
352 : : CommandToInfoMap& rCommandMap,
353 : : const ::rtl::OUString& rModuleIdentifier,
354 : : const ::rtl::OUString& rMergeCommand,
355 : : const ::rtl::OUString& rMergeCommandParameter,
356 : : const AddonToolbarItemContainer& rItems )
357 : : {
358 [ # # ]: 0 : if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDAFTER, MERGECOMMAND_ADDAFTER_LEN ))
359 : 0 : return MergeItems( xFrame, pToolbar, nPos, 1, rItemId, rCommandMap, rModuleIdentifier, rItems );
360 [ # # ]: 0 : else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDBEFORE, MERGECOMMAND_ADDBEFORE_LEN ))
361 : 0 : return MergeItems( xFrame, pToolbar, nPos, 0, rItemId, rCommandMap, rModuleIdentifier, rItems );
362 [ # # ]: 0 : else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REPLACE, MERGECOMMAND_REPLACE_LEN ))
363 : 0 : return ReplaceItem( xFrame, pToolbar, nPos, rItemId, rCommandMap, rModuleIdentifier, rItems );
364 [ # # ]: 0 : else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REMOVE, MERGECOMMAND_REMOVE_LEN ))
365 : 0 : return RemoveItems( pToolbar, nPos, rMergeCommandParameter );
366 : :
367 : 0 : return false;
368 : : }
369 : :
370 : : /**
371 : : Processes a merge fallback operation.
372 : :
373 : : @param
374 : : xFrame
375 : :
376 : : Must be a valid reference to a frame.
377 : :
378 : : @param
379 : : pToolbar
380 : :
381 : : A valid pointer to the toolbar where the merge
382 : : fall back operation is applied to.
383 : :
384 : : @param
385 : : nPos
386 : :
387 : : The reference position of the toolbar item for
388 : : the merge operation. Value must be between
389 : : 0 and number of toolbar items - 1.
390 : :
391 : : @param
392 : : rItemId
393 : :
394 : : A unique item ID.
395 : :
396 : : @param
397 : : rModuleIdentifier
398 : :
399 : : The current application module context.
400 : :
401 : : @param
402 : : rMergeCommand
403 : :
404 : : A merge command.
405 : :
406 : : @param
407 : : rItems
408 : :
409 : : Toolbar items which are associated to the merge
410 : : command.
411 : :
412 : : @result
413 : : Returns true for a successful operation otherwise
414 : : false.
415 : : */
416 : 0 : bool ToolBarMerger::ProcessMergeFallback(
417 : : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
418 : : ToolBox* pToolbar,
419 : : sal_uInt16 /*nPos*/,
420 : : sal_uInt16& rItemId,
421 : : CommandToInfoMap& rCommandMap,
422 : : const ::rtl::OUString& rModuleIdentifier,
423 : : const ::rtl::OUString& rMergeCommand,
424 : : const ::rtl::OUString& rMergeFallback,
425 : : const AddonToolbarItemContainer& rItems )
426 : : {
427 [ # # # # : 0 : if (( rMergeFallback.equalsAsciiL( MERGEFALLBACK_IGNORE, MERGEFALLBACK_IGNORE_LEN )) ||
# # ][ # # ]
428 : 0 : ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REPLACE, MERGECOMMAND_REPLACE_LEN )) ||
429 : 0 : ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REMOVE, MERGECOMMAND_REMOVE_LEN )) )
430 : : {
431 : 0 : return true;
432 : : }
433 [ # # # # ]: 0 : else if (( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDBEFORE, MERGECOMMAND_ADDBEFORE_LEN )) ||
[ # # ]
434 : 0 : ( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDAFTER, MERGECOMMAND_ADDAFTER_LEN )) )
435 : : {
436 [ # # ]: 0 : if ( rMergeFallback.equalsAsciiL( MERGEFALLBACK_ADDFIRST, MERGEFALLBACK_ADDFIRST_LEN ))
437 : 0 : return MergeItems( xFrame, pToolbar, 0, 0, rItemId, rCommandMap, rModuleIdentifier, rItems );
438 [ # # ]: 0 : else if ( rMergeFallback.equalsAsciiL( MERGEFALLBACK_ADDLAST, MERGEFALLBACK_ADDLAST_LEN ))
439 : 0 : return MergeItems( xFrame, pToolbar, TOOLBOX_APPEND, 0, rItemId, rCommandMap, rModuleIdentifier, rItems );
440 : : }
441 : :
442 : 0 : return false;
443 : : }
444 : :
445 : : /**
446 : : Merges (adds) toolbar items into an existing toolbar.
447 : :
448 : : @param
449 : : xFrame
450 : :
451 : : Must be a valid reference to a frame.
452 : :
453 : : @param
454 : : pToolbar
455 : :
456 : : A valid pointer to the toolbar where the merge
457 : : fall back operation is applied to.
458 : :
459 : : @param
460 : : nPos
461 : :
462 : : The reference position of the toolbar item for
463 : : the merge operation. Value must be between
464 : : 0 and number of toolbar items - 1.
465 : :
466 : : @param
467 : : rItemId
468 : :
469 : : A unique item ID.
470 : :
471 : : @param
472 : : rModuleIdentifier
473 : :
474 : : The current application module context.
475 : :
476 : : @param
477 : : rItems
478 : :
479 : : Toolbar items which are associated to the merge
480 : : command.
481 : :
482 : : @result
483 : : Returns true for a successful operation otherwise
484 : : false.
485 : : */
486 : 0 : bool ToolBarMerger::MergeItems(
487 : : const uno::Reference< frame::XFrame >& rFrame,
488 : : ToolBox* pToolbar,
489 : : sal_uInt16 nPos,
490 : : sal_uInt16 nModIndex,
491 : : sal_uInt16& rItemId,
492 : : CommandToInfoMap& rCommandMap,
493 : : const ::rtl::OUString& rModuleIdentifier,
494 : : const AddonToolbarItemContainer& rAddonToolbarItems )
495 : : {
496 : 0 : const sal_Int32 nSize( rAddonToolbarItems.size() );
497 : :
498 : 0 : uno::Reference< frame::XFrame > xFrame( rFrame );
499 : :
500 : 0 : sal_uInt16 nIndex( 0 );
501 [ # # ]: 0 : for ( sal_Int32 i = 0; i < nSize; i++ )
502 : : {
503 : 0 : const AddonToolbarItem& rItem = rAddonToolbarItems[i];
504 [ # # ]: 0 : if ( IsCorrectContext( rItem.aContext, rModuleIdentifier ))
505 : : {
506 : 0 : sal_Int32 nInsPos = nPos+nModIndex+i;
507 [ # # ][ # # ]: 0 : if ( nInsPos > sal_Int32( pToolbar->GetItemCount() ))
508 : 0 : nInsPos = TOOLBOX_APPEND;
509 : :
510 [ # # ]: 0 : if ( rItem.aCommandURL.equalsAsciiL( TOOLBOXITEM_SEPARATOR_STR, TOOLBOXITEM_SEPARATOR_STR_LEN ))
511 [ # # ]: 0 : pToolbar->InsertSeparator( sal_uInt16( nInsPos ));
512 : : else
513 : : {
514 [ # # ]: 0 : CommandToInfoMap::iterator pIter = rCommandMap.find( rItem.aCommandURL );
515 [ # # ][ # # ]: 0 : if ( pIter == rCommandMap.end())
516 : : {
517 [ # # ]: 0 : CommandInfo aCmdInfo;
518 : 0 : aCmdInfo.nId = rItemId;
519 [ # # ]: 0 : const CommandToInfoMap::value_type aValue( rItem.aCommandURL, aCmdInfo );
520 [ # # ]: 0 : rCommandMap.insert( aValue );
521 : : }
522 : : else
523 : : {
524 [ # # ][ # # ]: 0 : pIter->second.aIds.push_back( rItemId );
525 : : }
526 : :
527 [ # # ]: 0 : ToolBarMerger::CreateToolbarItem( pToolbar, rCommandMap, sal_uInt16( nInsPos ), rItemId, rItem );
528 : : }
529 : :
530 : 0 : ++nIndex;
531 : 0 : ++rItemId;
532 : : }
533 : : }
534 : :
535 : 0 : 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 : 0 : 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 : 0 : pToolbar->RemoveItem( nPos );
590 : 0 : 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 : 0 : bool ToolBarMerger::RemoveItems(
619 : : ToolBox* pToolbar,
620 : : sal_uInt16 nPos,
621 : : const ::rtl::OUString& rMergeCommandParameter )
622 : : {
623 : 0 : sal_Int32 nCount = rMergeCommandParameter.toInt32();
624 [ # # ]: 0 : if ( nCount > 0 )
625 : : {
626 [ # # ]: 0 : for ( sal_Int32 i = 0; i < nCount; i++ )
627 : : {
628 [ # # ]: 0 : if ( nPos < pToolbar->GetItemCount() )
629 : 0 : pToolbar->RemoveItem( nPos );
630 : : }
631 : : }
632 : 0 : 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 : 0 : ::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 : 0 : ::cppu::OWeakObject* pResult( 0 );
670 : :
671 [ # # ]: 0 : if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_BUTTON, TOOLBARCONTROLLER_BUTTON_LEN ))
672 [ # # ][ # # ]: 0 : pResult = new ButtonToolbarController( xSMGR, pToolbar, rCommandURL );
673 [ # # ]: 0 : else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_COMBOBOX, TOOLBARCONTROLLER_COMBOBOX_LEN ))
674 [ # # ][ # # ]: 0 : pResult = new ComboboxToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL );
675 [ # # ]: 0 : else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_EDIT, TOOLBARCONTROLLER_EDIT_LEN ))
676 [ # # ][ # # ]: 0 : pResult = new EditToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL );
677 [ # # ]: 0 : else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_SPINFIELD, TOOLBARCONTROLLER_SPINFIELD_LEN ))
678 [ # # ][ # # ]: 0 : pResult = new SpinfieldToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL );
679 [ # # ]: 0 : else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_IMGBUTTON, TOOLBARCONTROLLER_IMGBUTTON_LEN ))
680 [ # # ][ # # ]: 0 : pResult = new ImageButtonToolbarController( xSMGR, xFrame, pToolbar, nId, rCommandURL );
681 [ # # ]: 0 : else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_DROPDOWNBOX, TOOLBARCONTROLLER_DROPDOWNBOX_LEN ))
682 [ # # ][ # # ]: 0 : pResult = new DropdownToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL );
683 [ # # ]: 0 : else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_DROPDOWNBTN, TOOLBARCONTROLLER_DROPDOWNBTN_LEN ))
684 : : pResult = new ToggleButtonToolbarController( xSMGR, xFrame, pToolbar, nId,
685 [ # # ][ # # ]: 0 : ToggleButtonToolbarController::STYLE_DROPDOWNBUTTON, rCommandURL );
686 [ # # ]: 0 : else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_TOGGLEDDBTN, TOOLBARCONTROLLER_TOGGLEDDBTN_LEN ))
687 : : pResult = new ToggleButtonToolbarController( xSMGR, xFrame, pToolbar, nId,
688 [ # # ][ # # ]: 0 : ToggleButtonToolbarController::STYLE_TOGGLE_DROPDOWNBUTTON, rCommandURL );
689 : : else
690 [ # # ][ # # ]: 0 : pResult = new GenericToolbarController( xSMGR, xFrame, pToolbar, nId, rCommandURL );
691 : :
692 : 0 : return pResult;
693 : : }
694 : :
695 : 0 : void ToolBarMerger::CreateToolbarItem( ToolBox* pToolbar, CommandToInfoMap& rCommandMap, sal_uInt16 nPos, sal_uInt16 nItemId, const AddonToolbarItem& rItem )
696 : : {
697 [ # # ][ # # ]: 0 : pToolbar->InsertItem( nItemId, rItem.aLabel, 0, nPos );
[ # # ]
698 [ # # ][ # # ]: 0 : pToolbar->SetItemCommand( nItemId, rItem.aCommandURL );
[ # # ]
699 [ # # ][ # # ]: 0 : pToolbar->SetQuickHelpText( nItemId, rItem.aLabel );
[ # # ]
700 [ # # ][ # # ]: 0 : pToolbar->SetItemText( nItemId, rItem.aLabel );
[ # # ]
701 [ # # ]: 0 : pToolbar->EnableItem( nItemId, sal_True );
702 [ # # ]: 0 : pToolbar->SetItemState( nItemId, STATE_NOCHECK );
703 : :
704 [ # # ]: 0 : CommandToInfoMap::iterator pIter = rCommandMap.find( rItem.aCommandURL );
705 [ # # ][ # # ]: 0 : if ( pIter != rCommandMap.end() )
706 [ # # ]: 0 : pIter->second.nWidth = rItem.nWidth;
707 : :
708 : : // Use the user data to store add-on specific data with the toolbar item
709 [ # # ]: 0 : AddonsParams* pAddonParams = new AddonsParams;
710 : 0 : pAddonParams->aImageId = rItem.aImageIdentifier;
711 : 0 : pAddonParams->aTarget = rItem.aTarget;
712 : 0 : pAddonParams->aControlType = rItem.aControlType;
713 [ # # ]: 0 : pToolbar->SetItemData( nItemId, pAddonParams );
714 : 0 : }
715 : :
716 : : } // namespace framework
717 : :
718 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|