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