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 #ifndef __FRAMEWORK_UIELEMENT_TOOLBARMERGER_HXX_
25 #define __FRAMEWORK_UIELEMENT_TOOLBARMERGER_HXX_
26 
27 #include <uielement/comboboxtoolbarcontroller.hxx>
28 #include <uielement/imagebuttontoolbarcontroller.hxx>
29 #include <uielement/togglebuttontoolbarcontroller.hxx>
30 #include <uielement/buttontoolbarcontroller.hxx>
31 #include <uielement/spinfieldtoolbarcontroller.hxx>
32 #include <uielement/edittoolbarcontroller.hxx>
33 #include <uielement/dropdownboxtoolbarcontroller.hxx>
34 #include <uielement/commandinfo.hxx>
35 
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 
38 #include <svtools/toolboxcontroller.hxx>
39 
40 #include <rtl/ustring.hxx>
41 #include <vcl/toolbox.hxx>
42 
43 namespace framework
44 {
45 
46 struct AddonsParams
47 {
48     ::rtl::OUString aImageId;
49     ::rtl::OUString aTarget;
50     ::rtl::OUString aControlType;
51 };
52 
53 struct AddonToolbarItem
54 {
55     ::rtl::OUString aCommandURL;
56     ::rtl::OUString aLabel;
57     ::rtl::OUString aImageIdentifier;
58     ::rtl::OUString aTarget;
59     ::rtl::OUString aContext;
60     ::rtl::OUString aControlType;
61     sal_uInt16      nWidth;
62 };
63 
64 typedef ::std::vector< AddonToolbarItem > AddonToolbarItemContainer;
65 
66 struct ReferenceToolbarPathInfo
67 {
68     ToolBox*           pToolbar;
69     sal_uInt16         nPos;
70     bool               bResult;
71 };
72 
73 class ToolBarMerger
74 {
75     public:
76         static bool       IsCorrectContext( const ::rtl::OUString& aContext, const ::rtl::OUString& aModuleIdentifier );
77 
78         static bool       ConvertSeqSeqToVector( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > rSequence,
79                                                  AddonToolbarItemContainer& rContainer );
80 
81         static void       ConvertSequenceToValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > rSequence,
82                                                    ::rtl::OUString& rCommandURL,
83                                                    ::rtl::OUString& rLabel,
84                                                    ::rtl::OUString& rImageIdentifier,
85                                                    ::rtl::OUString& rTarget,
86                                                    ::rtl::OUString& rContext,
87                                                    ::rtl::OUString& rControlType,
88                                                    sal_uInt16&      rWidth );
89 
90         static ReferenceToolbarPathInfo FindReferencePoint( ToolBox*               pToolbar,
91                                                             const ::rtl::OUString& rReferencePoint );
92 
93         static bool       ProcessMergeOperation( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
94                                                  ToolBox*                         pToolbar,
95                                                  sal_uInt16                       nPos,
96                                                  sal_uInt16&                      rItemId,
97                                                  CommandToInfoMap&                rCommandMap,
98                                                  const ::rtl::OUString&           rModuleIdentifier,
99                                                  const ::rtl::OUString&           rMergeCommand,
100                                                  const ::rtl::OUString&           rMergeCommandParameter,
101                                                  const AddonToolbarItemContainer& rItems );
102 
103         static bool       ProcessMergeFallback( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
104                                                 ToolBox*                         pToolbar,
105                                                 sal_uInt16                       nPos,
106                                                 sal_uInt16&                      rItemId,
107                                                 CommandToInfoMap&                rCommandMap,
108                                                 const ::rtl::OUString&           rModuleIdentifier,
109                                                 const ::rtl::OUString&           rMergeCommand,
110                                                 const ::rtl::OUString&           rMergeFallback,
111                                                 const AddonToolbarItemContainer& rItems );
112 
113         static bool       MergeItems( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
114                                       ToolBox*                  pToolbar,
115                                       sal_uInt16                nPos,
116                                       sal_uInt16                nModIndex,
117                                       sal_uInt16&               rItemId,
118                                       CommandToInfoMap&         rCommandMap,
119                                       const ::rtl::OUString&    rModuleIdentifier,
120                                       const AddonToolbarItemContainer& rAddonToolbarItems );
121 
122         static bool       ReplaceItem( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
123                                        ToolBox*                  pToolbar,
124                                        sal_uInt16                nPos,
125                                        sal_uInt16&               rItemId,
126                                        CommandToInfoMap&         rCommandMap,
127                                        const ::rtl::OUString&    rModuleIdentifier,
128                                        const AddonToolbarItemContainer& rAddonToolbarItems );
129 
130         static bool       RemoveItems( ToolBox*                  pToolbar,
131                                        sal_uInt16                nPos,
132                                        const ::rtl::OUString&    rMergeCommandParameter );
133 
134         static ::cppu::OWeakObject* CreateController(
135             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMGR,
136             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame,
137             ToolBox*               pToolbar,
138             const ::rtl::OUString& rCommandURL,
139             sal_uInt16             nId,
140             sal_uInt16             nWidth,
141             const ::rtl::OUString& rControlType );
142 
143         static void CreateToolbarItem( ToolBox* pToolbox,
144                                        CommandToInfoMap& rCommandMap,
145                                        sal_uInt16 nPos,
146                                        sal_uInt16 nItemId,
147                                        const AddonToolbarItem& rAddonToolbarItem );
148 
149     private:
150         ToolBarMerger();
151         ToolBarMerger( const ToolBarMerger& );
152         ToolBarMerger& operator=( const ToolBarMerger& );
153 };
154 
155 } // namespace framework
156 
157 #endif // __FRAMEWORK_UIELEMENT_TOOLBARMERGER_HXX_
158