1*f8e07b45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f8e07b45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f8e07b45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f8e07b45SAndrew Rist  * distributed with this work for additional information
6*f8e07b45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f8e07b45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f8e07b45SAndrew Rist  * "License"); you may not use this file except in compliance
9*f8e07b45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f8e07b45SAndrew Rist  *
11*f8e07b45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f8e07b45SAndrew Rist  *
13*f8e07b45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f8e07b45SAndrew Rist  * software distributed under the License is distributed on an
15*f8e07b45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f8e07b45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f8e07b45SAndrew Rist  * specific language governing permissions and limitations
18*f8e07b45SAndrew Rist  * under the License.
19*f8e07b45SAndrew Rist  *
20*f8e07b45SAndrew Rist  *************************************************************/
21*f8e07b45SAndrew Rist 
22*f8e07b45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_TOOLBARMERGER_HXX_
25cdf0e10cSrcweir #define __FRAMEWORK_UIELEMENT_TOOLBARMERGER_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <uielement/comboboxtoolbarcontroller.hxx>
28cdf0e10cSrcweir #include <uielement/imagebuttontoolbarcontroller.hxx>
29cdf0e10cSrcweir #include <uielement/togglebuttontoolbarcontroller.hxx>
30cdf0e10cSrcweir #include <uielement/buttontoolbarcontroller.hxx>
31cdf0e10cSrcweir #include <uielement/spinfieldtoolbarcontroller.hxx>
32cdf0e10cSrcweir #include <uielement/edittoolbarcontroller.hxx>
33cdf0e10cSrcweir #include <uielement/dropdownboxtoolbarcontroller.hxx>
34cdf0e10cSrcweir #include <uielement/commandinfo.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <svtools/toolboxcontroller.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <rtl/ustring.hxx>
41cdf0e10cSrcweir #include <vcl/toolbox.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir namespace framework
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 
46cdf0e10cSrcweir struct AddonsParams
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     ::rtl::OUString aImageId;
49cdf0e10cSrcweir     ::rtl::OUString aTarget;
50cdf0e10cSrcweir     ::rtl::OUString aControlType;
51cdf0e10cSrcweir };
52cdf0e10cSrcweir 
53cdf0e10cSrcweir struct AddonToolbarItem
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     ::rtl::OUString aCommandURL;
56cdf0e10cSrcweir     ::rtl::OUString aLabel;
57cdf0e10cSrcweir     ::rtl::OUString aImageIdentifier;
58cdf0e10cSrcweir     ::rtl::OUString aTarget;
59cdf0e10cSrcweir     ::rtl::OUString aContext;
60cdf0e10cSrcweir     ::rtl::OUString aControlType;
61cdf0e10cSrcweir     sal_uInt16      nWidth;
62cdf0e10cSrcweir };
63cdf0e10cSrcweir 
64cdf0e10cSrcweir typedef ::std::vector< AddonToolbarItem > AddonToolbarItemContainer;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir struct ReferenceToolbarPathInfo
67cdf0e10cSrcweir {
68cdf0e10cSrcweir     ToolBox*           pToolbar;
69cdf0e10cSrcweir     sal_uInt16         nPos;
70cdf0e10cSrcweir     bool               bResult;
71cdf0e10cSrcweir };
72cdf0e10cSrcweir 
73cdf0e10cSrcweir class ToolBarMerger
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     public:
76cdf0e10cSrcweir         static bool       IsCorrectContext( const ::rtl::OUString& aContext, const ::rtl::OUString& aModuleIdentifier );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         static bool       ConvertSeqSeqToVector( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > rSequence,
79cdf0e10cSrcweir                                                  AddonToolbarItemContainer& rContainer );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir         static void       ConvertSequenceToValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > rSequence,
82cdf0e10cSrcweir                                                    ::rtl::OUString& rCommandURL,
83cdf0e10cSrcweir                                                    ::rtl::OUString& rLabel,
84cdf0e10cSrcweir                                                    ::rtl::OUString& rImageIdentifier,
85cdf0e10cSrcweir                                                    ::rtl::OUString& rTarget,
86cdf0e10cSrcweir                                                    ::rtl::OUString& rContext,
87cdf0e10cSrcweir                                                    ::rtl::OUString& rControlType,
88cdf0e10cSrcweir                                                    sal_uInt16&      rWidth );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         static ReferenceToolbarPathInfo FindReferencePoint( ToolBox*               pToolbar,
91cdf0e10cSrcweir                                                             const ::rtl::OUString& rReferencePoint );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         static bool       ProcessMergeOperation( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
94cdf0e10cSrcweir                                                  ToolBox*                         pToolbar,
95cdf0e10cSrcweir                                                  sal_uInt16                       nPos,
96cdf0e10cSrcweir                                                  sal_uInt16&                      rItemId,
97cdf0e10cSrcweir                                                  CommandToInfoMap&                rCommandMap,
98cdf0e10cSrcweir                                                  const ::rtl::OUString&           rModuleIdentifier,
99cdf0e10cSrcweir                                                  const ::rtl::OUString&           rMergeCommand,
100cdf0e10cSrcweir                                                  const ::rtl::OUString&           rMergeCommandParameter,
101cdf0e10cSrcweir                                                  const AddonToolbarItemContainer& rItems );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         static bool       ProcessMergeFallback( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
104cdf0e10cSrcweir                                                 ToolBox*                         pToolbar,
105cdf0e10cSrcweir                                                 sal_uInt16                       nPos,
106cdf0e10cSrcweir                                                 sal_uInt16&                      rItemId,
107cdf0e10cSrcweir                                                 CommandToInfoMap&                rCommandMap,
108cdf0e10cSrcweir                                                 const ::rtl::OUString&           rModuleIdentifier,
109cdf0e10cSrcweir                                                 const ::rtl::OUString&           rMergeCommand,
110cdf0e10cSrcweir                                                 const ::rtl::OUString&           rMergeFallback,
111cdf0e10cSrcweir                                                 const AddonToolbarItemContainer& rItems );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         static bool       MergeItems( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
114cdf0e10cSrcweir                                       ToolBox*                  pToolbar,
115cdf0e10cSrcweir                                       sal_uInt16                nPos,
116cdf0e10cSrcweir                                       sal_uInt16                nModIndex,
117cdf0e10cSrcweir                                       sal_uInt16&               rItemId,
118cdf0e10cSrcweir                                       CommandToInfoMap&         rCommandMap,
119cdf0e10cSrcweir                                       const ::rtl::OUString&    rModuleIdentifier,
120cdf0e10cSrcweir                                       const AddonToolbarItemContainer& rAddonToolbarItems );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         static bool       ReplaceItem( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
123cdf0e10cSrcweir                                        ToolBox*                  pToolbar,
124cdf0e10cSrcweir                                        sal_uInt16                nPos,
125cdf0e10cSrcweir                                        sal_uInt16&               rItemId,
126cdf0e10cSrcweir                                        CommandToInfoMap&         rCommandMap,
127cdf0e10cSrcweir                                        const ::rtl::OUString&    rModuleIdentifier,
128cdf0e10cSrcweir                                        const AddonToolbarItemContainer& rAddonToolbarItems );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         static bool       RemoveItems( ToolBox*                  pToolbar,
131cdf0e10cSrcweir                                        sal_uInt16                nPos,
132cdf0e10cSrcweir                                        const ::rtl::OUString&    rMergeCommandParameter );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         static ::cppu::OWeakObject* CreateController(
135cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMGR,
136cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame,
137cdf0e10cSrcweir             ToolBox*               pToolbar,
138cdf0e10cSrcweir             const ::rtl::OUString& rCommandURL,
139cdf0e10cSrcweir             sal_uInt16             nId,
140cdf0e10cSrcweir             sal_uInt16             nWidth,
141cdf0e10cSrcweir             const ::rtl::OUString& rControlType );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         static void CreateToolbarItem( ToolBox* pToolbox,
144cdf0e10cSrcweir                                        CommandToInfoMap& rCommandMap,
145cdf0e10cSrcweir                                        sal_uInt16 nPos,
146cdf0e10cSrcweir                                        sal_uInt16 nItemId,
147cdf0e10cSrcweir                                        const AddonToolbarItem& rAddonToolbarItem );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     private:
150cdf0e10cSrcweir         ToolBarMerger();
151cdf0e10cSrcweir         ToolBarMerger( const ToolBarMerger& );
152cdf0e10cSrcweir         ToolBarMerger& operator=( const ToolBarMerger& );
153cdf0e10cSrcweir };
154cdf0e10cSrcweir 
155cdf0e10cSrcweir } // namespace framework
156cdf0e10cSrcweir 
157cdf0e10cSrcweir #endif // __FRAMEWORK_UIELEMENT_TOOLBARMERGER_HXX_
158