1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __FRAMEWORK_UIELEMENT_TOOLBARMERGER_HXX_
29 #define __FRAMEWORK_UIELEMENT_TOOLBARMERGER_HXX_
30 
31 #include <uielement/comboboxtoolbarcontroller.hxx>
32 #include <uielement/imagebuttontoolbarcontroller.hxx>
33 #include <uielement/togglebuttontoolbarcontroller.hxx>
34 #include <uielement/buttontoolbarcontroller.hxx>
35 #include <uielement/spinfieldtoolbarcontroller.hxx>
36 #include <uielement/edittoolbarcontroller.hxx>
37 #include <uielement/dropdownboxtoolbarcontroller.hxx>
38 #include <uielement/commandinfo.hxx>
39 
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 
42 #include <svtools/toolboxcontroller.hxx>
43 
44 #include <rtl/ustring.hxx>
45 #include <vcl/toolbox.hxx>
46 
47 namespace framework
48 {
49 
50 struct AddonsParams
51 {
52     ::rtl::OUString aImageId;
53     ::rtl::OUString aTarget;
54     ::rtl::OUString aControlType;
55 };
56 
57 struct AddonToolbarItem
58 {
59     ::rtl::OUString aCommandURL;
60     ::rtl::OUString aLabel;
61     ::rtl::OUString aImageIdentifier;
62     ::rtl::OUString aTarget;
63     ::rtl::OUString aContext;
64     ::rtl::OUString aControlType;
65     sal_uInt16      nWidth;
66 };
67 
68 typedef ::std::vector< AddonToolbarItem > AddonToolbarItemContainer;
69 
70 struct ReferenceToolbarPathInfo
71 {
72     ToolBox*           pToolbar;
73     sal_uInt16         nPos;
74     bool               bResult;
75 };
76 
77 class ToolBarMerger
78 {
79     public:
80         static bool       IsCorrectContext( const ::rtl::OUString& aContext, const ::rtl::OUString& aModuleIdentifier );
81 
82         static bool       ConvertSeqSeqToVector( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > rSequence,
83                                                  AddonToolbarItemContainer& rContainer );
84 
85         static void       ConvertSequenceToValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > rSequence,
86                                                    ::rtl::OUString& rCommandURL,
87                                                    ::rtl::OUString& rLabel,
88                                                    ::rtl::OUString& rImageIdentifier,
89                                                    ::rtl::OUString& rTarget,
90                                                    ::rtl::OUString& rContext,
91                                                    ::rtl::OUString& rControlType,
92                                                    sal_uInt16&      rWidth );
93 
94         static ReferenceToolbarPathInfo FindReferencePoint( ToolBox*               pToolbar,
95                                                             const ::rtl::OUString& rReferencePoint );
96 
97         static bool       ProcessMergeOperation( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
98                                                  ToolBox*                         pToolbar,
99                                                  sal_uInt16                       nPos,
100                                                  sal_uInt16&                      rItemId,
101                                                  CommandToInfoMap&                rCommandMap,
102                                                  const ::rtl::OUString&           rModuleIdentifier,
103                                                  const ::rtl::OUString&           rMergeCommand,
104                                                  const ::rtl::OUString&           rMergeCommandParameter,
105                                                  const AddonToolbarItemContainer& rItems );
106 
107         static bool       ProcessMergeFallback( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
108                                                 ToolBox*                         pToolbar,
109                                                 sal_uInt16                       nPos,
110                                                 sal_uInt16&                      rItemId,
111                                                 CommandToInfoMap&                rCommandMap,
112                                                 const ::rtl::OUString&           rModuleIdentifier,
113                                                 const ::rtl::OUString&           rMergeCommand,
114                                                 const ::rtl::OUString&           rMergeFallback,
115                                                 const AddonToolbarItemContainer& rItems );
116 
117         static bool       MergeItems( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
118                                       ToolBox*                  pToolbar,
119                                       sal_uInt16                nPos,
120                                       sal_uInt16                nModIndex,
121                                       sal_uInt16&               rItemId,
122                                       CommandToInfoMap&         rCommandMap,
123                                       const ::rtl::OUString&    rModuleIdentifier,
124                                       const AddonToolbarItemContainer& rAddonToolbarItems );
125 
126         static bool       ReplaceItem( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
127                                        ToolBox*                  pToolbar,
128                                        sal_uInt16                nPos,
129                                        sal_uInt16&               rItemId,
130                                        CommandToInfoMap&         rCommandMap,
131                                        const ::rtl::OUString&    rModuleIdentifier,
132                                        const AddonToolbarItemContainer& rAddonToolbarItems );
133 
134         static bool       RemoveItems( ToolBox*                  pToolbar,
135                                        sal_uInt16                nPos,
136                                        const ::rtl::OUString&    rMergeCommandParameter );
137 
138         static ::cppu::OWeakObject* CreateController(
139             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMGR,
140             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame,
141             ToolBox*               pToolbar,
142             const ::rtl::OUString& rCommandURL,
143             sal_uInt16             nId,
144             sal_uInt16             nWidth,
145             const ::rtl::OUString& rControlType );
146 
147         static void CreateToolbarItem( ToolBox* pToolbox,
148                                        CommandToInfoMap& rCommandMap,
149                                        sal_uInt16 nPos,
150                                        sal_uInt16 nItemId,
151                                        const AddonToolbarItem& rAddonToolbarItem );
152 
153     private:
154         ToolBarMerger();
155         ToolBarMerger( const ToolBarMerger& );
156         ToolBarMerger& operator=( const ToolBarMerger& );
157 };
158 
159 } // namespace framework
160 
161 #endif // __FRAMEWORK_UIELEMENT_TOOLBARMERGER_HXX_
162