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 #ifndef __FRAMEWORK_CLASSES_ADDONSOPTIONS_HXX_
24 #define __FRAMEWORK_CLASSES_ADDONSOPTIONS_HXX_
25 
26 //_________________________________________________________________________________________________________________
27 //  includes
28 //_________________________________________________________________________________________________________________
29 
30 #include <sal/types.h>
31 #include <osl/mutex.hxx>
32 #include <vcl/image.hxx>
33 #include <vcl/bitmap.hxx>
34 #include <vcl/svapp.hxx>
35 #include <com/sun/star/uno/Sequence.h>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <framework/fwedllapi.h>
38 //_________________________________________________________________________________________________________________
39 //  types, enums, ...
40 //_________________________________________________________________________________________________________________
41 
42 /*-************************************************************************************************************//**
43     @descr          The method GetAddonsMenu() returns a list of property values.
44                     Use follow defines to seperate values by names.
45 *//*-*************************************************************************************************************/
46 #define ADDONSMENUITEM_STRING_URL                       "URL"
47 #define ADDONSMENUITEM_STRING_TITLE                     "Title"
48 #define ADDONSMENUITEM_STRING_TARGET                    "Target"
49 #define ADDONSMENUITEM_STRING_IMAGEIDENTIFIER           "ImageIdentifier"
50 #define ADDONSMENUITEM_STRING_CONTEXT                   "Context"
51 #define ADDONSMENUITEM_STRING_SUBMENU                   "Submenu"
52 #define ADDONSMENUITEM_STRING_CONTROLTYPE               "ControlType"
53 #define ADDONSMENUITEM_STRING_WIDTH                     "Width"
54 
55 #define ADDONSMENUITEM_URL_LEN                          3
56 #define ADDONSMENUITEM_TITLE_LEN                        5
57 #define ADDONSMENUITEM_TARGET_LEN                       6
58 #define ADDONSMENUITEM_SUBMENU_LEN                      7
59 #define ADDONSMENUITEM_CONTEXT_LEN                      7
60 #define ADDONSMENUITEM_IMAGEIDENTIFIER_LEN              15
61 
62 #define ADDONSMENUITEM_PROPERTYNAME_URL                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_URL             ))
63 #define ADDONSMENUITEM_PROPERTYNAME_TITLE               ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_TITLE           ))
64 #define ADDONSMENUITEM_PROPERTYNAME_TARGET              ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_TARGET          ))
65 #define ADDONSMENUITEM_PROPERTYNAME_IMAGEIDENTIFIER     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_IMAGEIDENTIFIER ))
66 #define ADDONSMENUITEM_PROPERTYNAME_CONTEXT             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_CONTEXT         ))
67 #define ADDONSMENUITEM_PROPERTYNAME_SUBMENU             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_SUBMENU         ))
68 #define ADDONSMENUITEM_PROPERTYNAME_CONTROLTYPE         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_CONTROLTYPE     ))
69 #define ADDONSMENUITEM_PROPERTYNAME_WIDTH               ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_WIDTH           ))
70 
71 #define ADDONSPOPUPMENU_URL_PREFIX_STR                  "private:menu/Addon"
72 
73 #define ADDONSPOPUPMENU_URL_PREFIX                      ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ADDONSPOPUPMENU_URL_PREFIX_STR ))
74 
75 namespace framework
76 {
77 
78 typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > MergeMenuDefinition;
79 
80 struct FWE_DLLPUBLIC MergeMenuInstruction
81 {
82     ::rtl::OUString     aMergePoint;
83     ::rtl::OUString     aMergeCommand;
84     ::rtl::OUString     aMergeCommandParameter;
85     ::rtl::OUString     aMergeFallback;
86     ::rtl::OUString     aMergeContext;
87     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > aMergeMenu;
88 };
89 typedef ::std::vector< MergeMenuInstruction > MergeMenuInstructionContainer;
90 
91 struct FWE_DLLPUBLIC MergeToolbarInstruction
92 {
93     ::rtl::OUString     aMergeToolbar;
94     ::rtl::OUString     aMergePoint;
95     ::rtl::OUString     aMergeCommand;
96     ::rtl::OUString     aMergeCommandParameter;
97     ::rtl::OUString     aMergeFallback;
98     ::rtl::OUString     aMergeContext;
99     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > aMergeToolbarItems;
100 };
101 
102 typedef ::std::vector< MergeToolbarInstruction > MergeToolbarInstructionContainer;
103 
104 //_________________________________________________________________________________________________________________
105 //  forward declarations
106 //_________________________________________________________________________________________________________________
107 
108 /*-************************************************************************************************************//**
109     @short          forward declaration to our private date container implementation
110     @descr          We use these class as internal member to support small memory requirements.
111                     You can create the container if it is neccessary. The class which use these mechanism
112                     is faster and smaller then a complete implementation!
113 *//*-*************************************************************************************************************/
114 
115 class AddonsOptions_Impl;
116 
117 //_________________________________________________________________________________________________________________
118 //  declarations
119 //_________________________________________________________________________________________________________________
120 
121 /*-************************************************************************************************************//**
122     @short          collect informations about menu features
123     @descr          -
124 
125     @implements     -
126     @base           -
127 
128     @devstatus      ready to use
129 *//*-*************************************************************************************************************/
130 
131 class FWE_DLLPUBLIC AddonsOptions
132 {
133     //-------------------------------------------------------------------------------------------------------------
134     //  public methods
135     //-------------------------------------------------------------------------------------------------------------
136 
137     public:
138         //---------------------------------------------------------------------------------------------------------
139         //  constructor / destructor
140         //---------------------------------------------------------------------------------------------------------
141 
142         /*-****************************************************************************************************//**
143             @short      standard constructor and destructor
144             @descr      This will initialize an instance with default values.
145                         We implement these class with a refcount mechanism! Every instance of this class increase it
146                         at create and decrease it at delete time - but all instances use the same data container!
147                         He is implemented as a static member ...
148 
149             @seealso    member m_nRefCount
150             @seealso    member m_pDataContainer
151 
152             @param      -
153             @return     -
154 
155             @onerror    -
156         *//*-*****************************************************************************************************/
157 
158          AddonsOptions();
159         ~AddonsOptions();
160 
161         //---------------------------------------------------------------------------------------------------------
162         //  interface
163         //---------------------------------------------------------------------------------------------------------
164 
165         /*-****************************************************************************************************//**
166             @short      clears completely the addons menu
167             @descr      Call this methods to clear the addons menu
168                         To fill it again use AppendItem().
169 
170             @seealso    -
171 
172             @param      "eMenu" select right menu to clear.
173             @return     -
174 
175             @onerror    -
176         *//*-*****************************************************************************************************/
177 
178         void Clear();
179 
180         /*-****************************************************************************************************//**
181             @short      returns if an addons menu is available
182             @descr      Call to retrieve if a addons menu is available
183 
184 
185             @return     sal_True if there is a menu otherwise sal_False
186         *//*-*****************************************************************************************************/
187 
188         sal_Bool    HasAddonsMenu() const;
189 
190         /*-****************************************************************************************************//**
191             @short      returns if an addons help menu is available
192             @descr      Call to retrieve if a addons menu is available
193 
194 
195             @return     sal_True if there is a menu otherwise sal_False
196         *//*-*****************************************************************************************************/
197 
198         sal_Bool    HasAddonsHelpMenu() const;
199 
200         /*-****************************************************************************************************//**
201             @short      returns number of addons toolbars
202             @descr      Call to retrieve the number of addons toolbars
203 
204 
205             @return     number of addons toolbars
206         *//*-*****************************************************************************************************/
207         sal_Int32   GetAddonsToolBarCount() const ;
208 
209         /*-****************************************************************************************************//**
210             @short      returns the  complete addons menu
211             @descr      Call it to get all entries of the addon menu.
212                         We return a list of all nodes with his names and properties.
213 
214             @seealso    -
215 
216             @return     A list of menu items is returned.
217 
218             @onerror    We return an empty list.
219         *//*-*****************************************************************************************************/
220 
221         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& GetAddonsMenu() const;
222 
223         /*-****************************************************************************************************//**
224             @short      Gets the menu bar part of all addon components registered
225             @descr      -
226 
227             @seealso    -
228 
229             @return     A complete
230 
231             @onerror    We return sal_False
232         *//*-*****************************************************************************************************/
233 
234         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& GetAddonsMenuBarPart() const;
235 
236         /*-****************************************************************************************************//**
237             @short      Gets a toolbar part of an single addon
238             @descr      -
239 
240             @seealso    -
241 
242             @return     A complete
243 
244             @onerror    We return sal_False
245         *//*-*****************************************************************************************************/
246 
247         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& GetAddonsToolBarPart( sal_uInt32 nIndex ) const;
248 
249         /*-****************************************************************************************************//**
250             @short      Gets a unique toolbar resource name of an single addon
251             @descr      -
252 
253             @seealso    -
254 
255             @return     A complete
256 
257             @onerror    We return sal_False
258         *//*-*****************************************************************************************************/
259 
260         const ::rtl::OUString GetAddonsToolbarResourceName( sal_uInt32 nIndex ) const;
261 
262         /*-****************************************************************************************************//**
263             @short      Retrieves all available merge instructions for the Office menu bar
264             @descr      -
265 
266             @seealso    -
267 
268             @return     The filled MergeMenuDefinitionContaier
269 
270             @onerror    We return sal_False
271         *//*-*****************************************************************************************************/
272 
273         const MergeMenuInstructionContainer& GetMergeMenuInstructions() const;
274 
275         /*-****************************************************************************************************//**
276             @short      Retrieves all available merge instructions for a single toolbar
277             @descr      -
278 
279             @seealso    -
280 
281             @return     The filled
282 
283             @onerror    We return sal_False
284         *//*-*****************************************************************************************************/
285         bool GetMergeToolbarInstructions( const ::rtl::OUString& rToolbarName, MergeToolbarInstructionContainer& rToolbar ) const;
286 
287         /*-****************************************************************************************************//**
288             @short      Gets the Add-On help menu part of all addon components registered
289             @descr      -
290 
291             @seealso    -
292 
293             @return     A complete
294 
295             @onerror    We return sal_False
296         *//*-*****************************************************************************************************/
297         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& GetAddonsHelpMenu() const;
298 
299         /*-****************************************************************************************************//**
300             @short      Retrieve an image for a command URL which is defined inside the addon menu configuration
301             @descr      Call it to retrieve an image for a command URL which is defined inside the addon menu configuration
302 
303             @seealso    -
304 
305             @return     An image which was defined in the configuration for the menu item. The image can be empty
306                         no bitmap was defined for the request image properties.
307 
308             @onerror    An empty image
309         *//*-*****************************************************************************************************/
310 
311         Image GetImageFromURL( const rtl::OUString& aURL, sal_Bool bBig, sal_Bool bHiContrast, sal_Bool bNoScale ) const;
312 
313         Image GetImageFromURL( const rtl::OUString& aURL, sal_Bool bBig, sal_Bool bHiContrast ) const;
314     //-------------------------------------------------------------------------------------------------------------
315     //  private methods
316     //-------------------------------------------------------------------------------------------------------------
317 
318         /*-****************************************************************************************************//**
319             @short      return a reference to a static mutex
320             @descr      These class is partially threadsafe (for de-/initialization only).
321                         All access methods are'nt safe!
322                         We create a static mutex only for one ime and use at different times.
323 
324             @seealso    -
325 
326             @param      -
327             @return     A reference to a static mutex member.
328 
329             @onerror    -
330         *//*-*****************************************************************************************************/
331 
332         static ::osl::Mutex& GetOwnStaticMutex();
333 
334         /*-****************************************************************************************************//**
335             @short      return a reference to a static mutex
336             @descr      These class is partially threadsafe (for de-/initialization only).
337                         All access methods are'nt safe!
338                         We create a static mutex only for one ime and use at different times.
339 
340             @seealso    -
341 
342             @param      -
343             @return     A reference to a static mutex member.
344 
345             @onerror    -
346         *//*-*****************************************************************************************************/
347         DECL_STATIC_LINK( AddonsOptions, Notify, void* );
348 
349     //-------------------------------------------------------------------------------------------------------------
350     //  private member
351     //-------------------------------------------------------------------------------------------------------------
352 
353     private:
354 
355         /*Attention
356 
357             Don't initialize these static member in these header!
358             a) Double dfined symbols will be detected ...
359             b) and unresolved externals exist at linking time.
360             Do it in your source only.
361          */
362 
363         static AddonsOptions_Impl*  m_pDataContainer    ;   /// impl. data container as dynamic pointer for smaller memory requirements!
364         static sal_Int32            m_nRefCount         ;   /// internal ref count mechanism
365 
366 };      // class SvtMenuOptions
367 
368 }
369 
370 #endif  // #ifndef __FRAMEWORK_CLASSES_ADDONSOPTIONS_HXX_
371